Search code examples
optimizationpyomogams-math

Optimization result is just the initial guess


I have an optimization problem which I've coded in pyomo as below:

import pyomo.environ as pyo   
import pandas as pd
opt = pyo.SolverFactory('ipopt')

model = pyo.ConcreteModel()

model.x = pyo.Var([1,2,3,4,5,6,7,8,9,10,11,12], domain=pyo.Reals)

model.y = pyo.Var([1,2,3,4,5,6,7,8,9], domain=pyo.NonNegativeReals)

model.OBJ = pyo.Objective(expr = model.x[1]**2 + model.x[2]**2 + model.x[3]**2 + model.x[4]**2 +
                          model.x[5]**2 + model.x[6]**2 + model.x[7]**2 + model.x[8]**2 +
                          model.x[9]**2 + model.x[10]**2 + model.x[11]**2 + model.x[12]**2)
                          
model.Constraint1 = pyo.Constraint(expr = model.y[1] + model.y[2] + model.y[3] + model.y[4] +
                                   model.y[5] + model.y[6] == 1)
model.Constraint2 = pyo.Constraint(expr = model.y[7] + model.x[1] == 0)
model.Constraint3 = pyo.Constraint(expr = model.y[5]*model.y[9] + model.y[3]*model.y[8] + model.y[7] + model.x[2] == 0)
model.Constraint4 = pyo.Constraint(expr = model.y[7] + model.y[5]*model.y[9] + model.x[3] ==0)
model.Constraint5 = pyo.Constraint(expr = model.y[7] + model.y[3]*model.y[8] + model.x[4] == 0)
model.Constraint6 = pyo.Constraint(expr = model.y[8] + model.x[5] == 9.6666)
model.Constraint7 = pyo.Constraint(expr= model.y[1]*model.y[7] + model.y[6]*model.y[9] + model.y[8] + model.x[6] == 17)
model.Constraint8 = pyo.Constraint(expr = model.y[8] + model.y[6]*model.y[9] + model.x[7] == 0)
model.Constraint9 = pyo.Constraint(expr = model.y[8] + model.y[1]*model.y[7] + model.x[8] == 3.28571)
model.Constraint10 = pyo.Constraint(expr = model.y[9] + model.x[9] == 0)
model.Constraint11 = pyo.Constraint(expr = model.y[2]*model.y[7] + model.y[4]*model.y[8] + model.y[9] + model.x[10] == 0)
model.Constraint12 = pyo.Constraint(expr = model.y[9] + model.y[4]*model.y[8] + model.x[11] == 0)
model.Constraint13 = pyo.Constraint(expr = model.y[9] + model.y[2]*model.y[7] + model.x[12] == 0)

opt.solve(model)

final_result = {}
for v in model.component_data_objects(pyo.Var):
  final_result[str(v)] = v.value

final_result = pd.DataFrame.from_dict(final_result,orient = 'index',columns = ['value']).reset_index()

I have solved it in pyomo with "ipopt" solver and I have tried a couple of solutions like "BARON","CONOPT","LGO" in Gams too, but I got same results which I guess it is just the initial guess. The result of pyomo is as below:

enter image description here

As I am new in optimization area I would appreciate if you could help. Cause I'm not sure that I got the correct result.


Solution

  • With Baron I see:

    Solution      = 163.31555232047  best solution found during preprocessing
    Best possible = 163.315552157
    Absolute gap  = 1.63470019742817E-7  optca = 1E-9
    Relative gap  = 1.00094582187766E-9  optcr = 1E-9
    

    Looks optimal to me.

    This is the complete solution:

    ---- VAR x  
    
              LOWER          LEVEL          UPPER         MARGINAL
    
    1         -INF           -1.0619        +INF             .          
    2         -INF           -1.0619        +INF             .          
    3         -INF           -1.0619        +INF             .          
    4         -INF           -1.0619        +INF             .          
    5         -INF            2.7095        +INF             .          
    6         -INF            8.9810        +INF             .          
    7         -INF           -6.9571        +INF             .          
    8         -INF           -4.7333        +INF             .          
    9         -INF             .            +INF             .          
    10        -INF             .            +INF             .          
    11        -INF             .            +INF             .          
    12        -INF             .            +INF             .          
    
    ---- VAR y  
    
             LOWER          LEVEL          UPPER         MARGINAL
    
    1          .             1.0000        +INF             .          
    2          .              .            +INF            9.0212      
    3          .              .            +INF           38.5726      
    4          .              .            +INF            9.0212      
    5          .              .            +INF            9.0212      
    6          .              .            +INF            9.0212      
    7          .             1.0619        +INF             .          
    8          .             6.9571        +INF             .          
    9          .              .            +INF             .          
    
                               LOWER          LEVEL          UPPER         MARGINAL
    
    ---- VAR z                 -INF          163.3156        +INF             .          
    

    A little bit more precise than IpOpt. If Baron says optimal it really almost always is. Note that "found during preprocessing" does not mean "initial guess". There is a bit more going on in that phase than just guessing.

    I also verified this solution using the global solvers Antigone and Gurobi. There is no reason whatsoever to believe there is a better solution out there.