ampl / mp

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

"Error: In SOS group" with x-gurobi #163

Closed fdabrandao closed 2 years ago

fdabrandao commented 2 years ago

The following model results in the error below with x-gurobi, but works with gurobi:

var x >= 0, <= 10000;
var y >= 0, <= 10000;

minimize obj: y;

s.t.
c0: x == 0.5;
c1:  y == << 1.0, 10000; 32.70723902177227, 0.0, 0.0 >> x;
#c1:  y == << 1.0; 32.70723902177227, 0.0>> x;

option presolve 0;
option solver "x-gurobi";
solve;

$ ampl test-x-gurobi.run Gurobi 9.5.0: Error: In SOS group 22, repeated weight 0 Error at _cmdno 3 executing "solve" command (file test.run, line 13, offset 234): can't open /var/folders/lc/kmnj4hgd7_qgjft0vlhjj0b40000gn/T/at5580.sol $ ampl test-gurobi.run gurobi (Darwin x86_64), licchk(20131021), ASL(20211109) Gurobi 9.5.0: optimal solution; objective 16.35361951 plus 1 simplex iteration for intbasis

glebbelov commented 2 years ago

Quick fix:

  option pl_linearize 0;

This sends the actual PL function, without linearizing it. The model Gurobi receives can be exported by

  option gurobi_options 'writeprob=sos_ref_pl.lp';
glebbelov commented 2 years ago

Just allowed equal SOS weights in x-gurobi, Gurobi 9.5 seems to accept them. A warning is printed when outlev=1.

It's weird AMPL linearizes PL and produces equal weights. In this example this is ok because the 2 slopes are both horizontal. However both gurobi and x-gurobi support PL natively (option pl_linearize 0;) and this seems more reliable. More so, because the old gurobi driver interprets the PL linearization as SOS1, while according to docu they are SOS2.