python-3.xparameterscplexpyomoquadratic-programming

Setting optimalitytarget parameter in python for cplex solver pyomo


i am trying to optimize a quadratic objective function in pyomo with cplex solver and i get this CPLEX Error 5002: objective is not convex. QP with an indefinite objective can be solved to local optimality with optimality target 2, or to global optimality with optimality target 3. From IBM manual i got to know that we should Set optimalitytarget parameter in pythonI have this globalqpex1.py and now how can i set the parameter can someone explain how to set up this parameter

it is given that i can run python globalqpex1.py g global optimum but i dont have any .sav or .lp files and i dont know what they are...furthur more I found in the manual that I can solve this problem by seting parameters.optimalitytarget in python how and where should i add c.parameters.optimalitytarget.set(1)

this is the error i get CPLEX Error 5002: objective is not convex. QP with an indefinite objective can be solved to local optimality with optimality target 2, or to global optimality with optimality target 3. Presolve time = 0.00 sec. (0.00 ticks) Barrier time = 0.00 sec. (0.00 ticks)

Error termination, CPLEX Error 5002. Solution time = 0.00 sec. Deterministic time = 0.00 ticks (0.49 ticks/sec)

CPLEX> CPLEX Error 1217: No solution exists. No file written. CPLEX> [ 0.05] Pyomo Finished ERROR: Unexpected exception while loading model: Cannot load a SolverResults object with bad status: error


Solution

  • There are two different CPLEX interfaces in pyomo. There is one that shells out to the CPLEX interactive (cplex) and there is one that makes use of the CPLEX Python API (cplex_direct). Setting parameters looks to be slightly different between the two interfaces in some cases (e.g., when the parameter is more than one level deep in the hierarchy). In general, you set a parameter using the technique described here.

    In either case, for the optimality target parameter, you should be able to use the following:

    solver = SolverFactory('cplex')
    solver.options['optimalitytarget'] = 3
    

    Here's an example where we set the absolute MIP gap tolerance parameter and the syntax is slightly different between the two CPLEX interfaces:

    # Using the CPLEX interactive interface
    solver = SolverFactory('cplex')
    solver.options['mip tolerances absmipgap'] = 3
    
    # Using the CPLEX Python API interface (i.e., use underscores)
    solver = SolverFactory('cplex_direct')
    solver.options['mip_tolerances_absmipgap'] = 3