ampl / mp

An open-source library for mathematical programming
https://mp.ampl.com
Other
227 stars 42 forks source link

Gurobi 11 differences in piecewise-linear approximation results #227

Open 4er4er4er opened 11 months ago

4er4er4er commented 11 months ago

Gurobi 10 and 11 give somewhat different results for piecewise-linear approximation of this simple test problem:

var x;
minimize f: 0.2*x^2 + 1/(1+exp(-x));
subj to bounds: -1 <= x <= 1;

Gurobi 10 with nonconvex=2 reports:

Gurobi 10.0.3:   qp:nonconvex = 2
Gurobi 10.0.3: optimal solution; objective 0.4262084321
3531 simplex iterations
168 branching nodes
absmipgap=1.57774e-06, relmipgap=3.70181e-06

f = 0.4262088256
x = -0.5766163358

Since this is a feasible solution to a minimization of a piecewise-linear approximation, it's expected that the objective will be greater than the true solution. But it only differs by 1 in the 7th digit from the "true" objective value of 0.4262087102 returned by Gurobi 11 with funcnonlinear=1 and also by Knitro.

Gurobi 11 with funcnonlinear=-1 reports the following:

Gurobi 11.0.0:   pre:funcnonlinear = -1
Gurobi 11.0.0: optimal solution; objective 0.4260218562
394 simplex iterations
35 branching nodes

------------ WARNINGS ------------
WARNING:  "Solution Check"
     [ sol:chk:feastol=1e-06, :feastolrel=1e-06, :inttol=1e-05,
       :round='', :prec='' ]
Algebraic expression violations:
  - 1 constraint(s) of type ':exp',
        up to 2E-03 (abs), up to 9E-04 (rel)

WARNING:  "Solution Check (Idealistic)"
     [ sol:chk:feastol=1e-06, :feastolrel=1e-06, :inttol=1e-05,
       :round='', :prec='' ]
Objective value violations:
  - 1 objective value(s) violated,
        up to 2E-04 (abs), up to 5E-04 (rel)
AMPL may evaluate constraints/objectives differently
than the solver, see mp.ampl.com/solution-check.html.

f = 0.4262241326
x = -0.584057913

So the result has changed. Maybe that is OK, but here are two questions to consider:

glebbelov commented 11 months ago
  1. The changed result might be due to different default setting, but also due to a bug in PL approximation, submitted to Gurobi (ticket 62337).
  2. Reporting solution to p-l approximation can be difficult. First, the default behavior may change in future. Second, user might have .global suffixes.

What about compacting solution check warnings? It can be a table as follows, with the lines appearing only when there are violations of the corr. type:

WARNING: Solution check  violations
Type                   Max               MaxRel                 [Name]
Var Bounds       ..............
Linear Cons       ..............
Nonlinear Cons    ..............
Logical Cons      ..............
Expression 'exp'     .............
Expression 'numberof'   ............
Objective(s)       ...............
Nonlinear Cons*   ..............
Logical Cons*     .............
Nonlinear Obj(s)*     ..............
*: AMPL may evaluate constraints/objectives differently
than the solver, see mp.ampl.com/solution-check.html.
glebbelov commented 11 months ago

Docu enhancement: https://mp.ampl.com/solution-check.html#warnings-format now contains a list of expressions.

But ideally we should have this list somewhere in the modeling guide?

glebbelov commented 10 months ago

@4er4er4er @fdabrandao I am experimenting with compact format #200 which reports the following for the above example:

Gurobi 11.0.0: optimal solution; objective 0.4260218562
425 simplex iteration(s)
48 branching node(s)

------------ WARNINGS ------------
WARNING:  "Tolerance violations"
  Type                         MaxAbs [Name]   MaxRel [Name]
  objective(s)                 2E-04           5E-04         
Documentation: mp.ampl.com/modeling-tools.html.
WARNING:  "Tolerance violations (solver model)"
  Type                         MaxAbs [Name]   MaxRel [Name]
  expr ':exp'                  2E-03           9E-04         

Let me know any comments.

glebbelov commented 10 months ago

Changing once more as follows:

WARNING:  "Tolerance violations"
  Type                         MaxAbs [Name]   MaxRel [Name]
  objective(s)                 2E-04           5E-04         
* expr ':exp'                  2E-03           9E-04         
*: Using the solver's aux variable values.
Documentation: mp.ampl.com/modeling-tools.html.