Here is an example where the PuLP modeling tool goes berserk.
In standard linear programming, only ≥, = and ≤ constraints are supported. Some tools also allow ≠, which for MIP models needs to be reformulated into a disjunctive constraint. Here is an attempt to do this in PuLP [1]. PuLP does not support this relational operator in its constraints, so we would expect a meaningful error message.
#------------------------------------------- # funny behavior when using a != constraint # in a PuLP model #------------------------------------------- import pulp model = pulp.LpProblem("notequal") x = pulp.LpVariable("x",lowBound=0,cat=pulp.LpInteger) y = pulp.LpVariable("y",lowBound=0,cat=pulp.LpInteger) model += x+y # obj model += pulp.LpConstraint(x != y) print(model) # this is an alternative debugging tool: # model.writeLP("/tmp/notequal.lp") # note that # model += x != y # produces a different model!!
This prints:
notequal: MINIMIZE 1*x + 1*y + 0 SUBJECT TO _C1:0 = -1 VARIABLES 0 <= x Integer 0 <= y Integer
Obviously, this is a surprise: the generated LP is just nonsensical. Surprises are bad when it comes to programming. We want reliability and predictability. It goes without saying that we are not getting that here.
Example 1: Minizinc
var 0..5: x; var 0..7: y; constraint x != y; solve minimize x+y;
\ENCODING=ISO-8859-1 \Problem name: MIPCplexWrapper Minimize obj1: X_INTRODUCED_0_ Subject To p_lin_0: x - y + 6 X_INTRODUCED_7_ <= 5 p_lin_1: - x + y - 8 X_INTRODUCED_7_ <= -1 p_lin_2: x + y - X_INTRODUCED_0_ = 0 Bounds 0 <= x <= 5 0 <= y <= 7 0 <= X_INTRODUCED_0_ <= 12 0 <= X_INTRODUCED_7_ <= 1 Generals x y X_INTRODUCED_0_ X_INTRODUCED_7_ End
Example 2: GAMS
$onText Illustrates a problem with indicator constraints in GAMS $offText
integer variable x,y; variable z 'objective'; binary variable delta;
Equations Obj e1 e2 ;
Obj.. z =e= x+y; e1.. x =l= y - 1; e2.. x =g= y + 1;
$onEcho > cplex.opt indic e1$delta 1 indic e2$delta 0 $offEcho
model m /all/; * activate option file m.optfile=1; solve m minimizing z using mip; |
--- GMO setup time: 0.00sError: Column is not of type VariableOption record: indic e1$delta 1*** GMO ERROR: Failed calling GMO: get indicator map*** Contact support@gams.com for help.
Conclusion
References
- Unique values constraint in PuLP, https://or.stackexchange.com/questions/12004/unique-values-constraint-in-pulp
- PuLP mystery, https://yetanothermathprogrammingconsultant.blogspot.com/2020/10/pulp-mystery.html
No comments:
Post a Comment