How does Gurobi handle the Piecewise Linear constraints inside its core program?

41 Views Asked by At

I am using gurobi to solve a Mixed Integer Linear Programming problem. Well, to be precise, the model is linear except a large number of piecewise linear constraints, which I know can be linearized using some other techniques. Knowing that gurobi supports this feature, I used m.addGenConstrPWL to code the constraint. But I noticed that it is not solved as a MILP. Instead, it shows logging information below with SOS constraints:

Optimize a model with 41360 rows, 27097 columns and 102646 nonzeros
Model fingerprint: 0xf9a5a2dd
Model has 5702 general constraints
Variable types: 22818 continuous, 4279 integer (4279 binary)
Coefficient statistics:
  Matrix range     [1e-05, 3e+07]
  Objective range  [1e+00, 1e+05]
  Bounds range     [1e+00, 1e+05]
  RHS range        [1e-05, 4e+04]
  PWLCon x range   [3e+01, 8e+04]
  PWLCon y range   [3e-02, 8e+01]
Warning: Model contains large matrix coefficient range

Compared with another MILP model I implemented using gurobi:

Optimize a model with 22818 rows, 8559 columns and 55590 nonzeros
Model fingerprint: 0x04ea8c4b
Variable types: 4280 continuous, 4279 integer (4279 binary)
Coefficient statistics:
  Matrix range     [1e-05, 3e+07]
  Objective range  [1e+00, 1e+00]
  Bounds range     [1e+00, 4e+02]
  RHS range        [1e-05, 1e+04]
Warning: Model contains large matrix coefficient range
  • My question is about how Gurobi handles piecewise linear constraints. If it uses the SOS (Special Ordered Sets) method, is there a way to directly convert these constraints into additional variables and other constraints? This would allow me to avoid extensive supplementary modeling and reduce the amount of work required when coding (such as dealing with a large number of variables and constraints).
  • and also, is it faster to use the built-in addGenConstrPWL or implement your own linearized version of SOS2 method?
1

There are 1 best solutions below

0
Greg Glockner On

Gurobi handles Piecewise Linear functions by converting them to Special Ordered Sets (SOS) type 2. Specifically, given points (x1, y1), (x2, y2), ... (xn, yn), it adds variables ai with constraints:

x = sum xi
y = sum yi
0 ≤ ai ≤ 1
ai in SOS-2

Next, Gurobi can apply an automatic translation from SOS to MIP when it is helpful; you can control this via parameters PreSOS2BigM and PreSOS2Encoding.

Whether it's better to use the Gurobi methods to add Piecewise Linear constraints or build it yourself, the answer is "it depends". It's easier to use Gurobi's methods, but some people prefer to control how it's implemented.