0

I have an objective function with several hundreds of quadratic terms which I would like to minimize; in this case I try to minimize the absolute distance between several variables. So the structure of my problem looks like this (highly simplified):

Minimize
obj: [ a^2 - 2 a * b + b^2 ] / 2
Subject To
c1: a + b >= 10
c2: a <= 100
End

I use the Python API to solve the problem in the following way:

import cplex

cpx = cplex.Cplex()
cpx.read('quadratic_obj_so.lp')  
# use the dual simplex   
cpx.parameters.lpmethod.set(cpx.parameters.lpmethod.values.dual)
cpx.solve()
print cpx.solution.get_values()[0:15]
print cpx.solution.status[cpx.solution.get_status()]
print cpx.solution.get_objective_value()

And for the above example I then receive (showing only iterations 16-18):

Itn      Primal Obj        Dual Obj  Prim Inf Upper Inf  Dual Inf
  16   1.4492800e-19  -1.0579911e-07  3.81e-14  7.11e-15  5.17e-25
  17   9.0580247e-21  -2.6449779e-08  1.91e-14  3.55e-15  2.33e-25
  18   5.6612645e-22  -6.6124446e-09  5.45e-14  7.11e-15  6.46e-27

[73.11695794600045, 73.11695794603409]
optimal
0.0

so a and b are equal which makes sense since I try to minimize their distance and the constrains are clearly fulfilled.

However, my actual problem is far more complex and I receive:

Itn      Primal Obj        Dual Obj  Prim Inf Upper Inf  Dual Inf
92   1.4468496e+06   1.2138985e+06  1.80e+02  2.64e-12  5.17e-02
  93   1.4468523e+06   1.2138969e+06  2.23e+02  2.17e-12  1.08e-02
  94   1.4468541e+06   1.2138945e+06  2.93e+02  2.31e-12  5.62e-02
  *    1.4457132e+06   1.2138598e+06  7.75e+00  7.61e-09  2.76e-02

num_best
1445714.46525

I have now several questions regarding the output which are closely connected:

1) Clearly, it is not the objective value for the dual simplex printed. Why is that, since I set the solver to be the dual simplex?!

2) How do I now access the results for the dual simplex? As the objective value is smaller I would be more interested in these results.

3) Does the num_best status guarantee that all the constrains are met i.e. is the solution valid but just not guaranteed to be optimal?

4) Primal Obj and Dual Obj differ quite a lot. Is there any strategy to minimize their difference?

Cleb
  • 25,102
  • 20
  • 116
  • 151
  • I don't think this log is from dual simplex but rather from the barrier method. Note also that solving QPs is not normally done with a Simplex LP method. – Erwin Kalvelagen Apr 19 '16 at 09:14
  • @ErwinKalvelagen: thanks for your comment! What would you recommend instead? – Cleb Apr 19 '16 at 12:40
  • I would first look at some possible reformulations. Try to move as much as possible logic out of the objective into the linear constraints (e.g. (x+y)^2 can be written as z^2 with z=x+y). Also look at scaling. Try the Cplex option `numericalEmphasis`. – Erwin Kalvelagen Apr 19 '16 at 13:59
  • That's a good idea, thanks! – Cleb Apr 19 '16 at 14:36

1 Answers1

1
  1. To the best of my knowledge, get_objective_value always returns the best primal bound (regardless of the lpmethod).
  2. Information about the dual solution can be retrieved with get_dual_values.
  3. The num_best solution status means that a solution is available, but there is no proof of optimality (see here). This is probably the most important point with regards to the rest of the questions here.
  4. You could try turning on the numerical emphasis parameter to see if that helps. There are also various tolerances you can adjust (e.g., optimality tolerance).

Note that all of the links I've used above are for the C Callable Library (which the Python API calls internally) for CPLEX 12.6.3.

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • Thanks for this detailed reply (I upvoted it and accept later on)! Regarding point 3 just to make that sure: the returned solution is valid (none of the bounds is violated) but it cannot be proofed whether it is the optimal one. Is this correct? By now I think that it might be better to express the difference between the variables not as a `(x1 - x2)^2 + (x2-x3)^2 + ...` but as `abs(x1-x2) + abs(x2-x3) + ...`. Latter expression needs to be linearized, of course. Do you know any examples where the sum of absolute differences has been minimized? – Cleb Apr 18 '16 at 17:06
  • No, with the num_best solution status, I don't think you can assume that the solution is valid. If I understand correctly, you may find [this](http://orinanobworld.blogspot.com/2012/07/modeling-absolute-values.html) blog on absolute values interesting. In the object oriented API's (C++, Java, .NET) you can use the [abs](http://www.ibm.com/support/knowledgecenter/api/content/nl/en-us/SSSA5P_12.6.3/ilog.odms.cplex.help/refjavacplex/html/ilog/concert/IloModeler.html#abs(ilog.concert.IloIntExpr)) method. – rkersh Apr 18 '16 at 20:13
  • Ok, thanks, this blog entry is indeed helpful. Did you have time to check point 1) ? – Cleb Apr 19 '16 at 12:41
  • 1
    I asked around and did some testing with a callback and setting iteration limits. I believe point 1) is correct and I've made the statement a bit stronger there. – rkersh Apr 19 '16 at 18:00
  • The link to the `abs` method is broken. Are there any plans to incorporate this also to the Python API? – Cleb Jan 08 '19 at 09:46
  • 1
    The updated link for the `IloModeler.abs` method can be found [here](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.3/ilog.odms.cplex.help/refjavacplex/html/ilog/concert/IloModeler.html#abs(ilog.concert.IloIntExpr)). In case it goes stale again, it can be found by navigating to CPLEX Java Reference Manual > ilog.concert > Interfaces > IloModeler > abs. – rkersh Jan 08 '19 at 17:40
  • 1
    While `abs` is not available in the CPLEX Python API (a low level API), it _is_ available in [DOcplex](https://developer.ibm.com/docloud/documentation/optimization-modeling/modeling-for-python/) (a Python modeling language that lives on top of the CPLEX Python API, or that can be used to solve on the cloud). See the docplex.mp.model.abs method [here](https://cdn.rawgit.com/IBMDecisionOptimization/docplex-doc/master/docs/mp/docplex.mp.model.html?highlight=abs#docplex.mp.model.Model.abs). – rkersh Jan 08 '19 at 17:44
  • Thanks a lot for the links! `DOcplex` looks quite appealing at first glance, will take a look; might indeed simplify my current problem significantly. – Cleb Jan 09 '19 at 08:14