Multiplication of multiple variables
AnsweredI’m currently using Gurobi optimizer for a cost optimization, but encounter a very annoying problem.
I would like to add constraints in which I multiply three variables, all binary, but results in a QuadExpr() error. Is there any way to overcome this issue?
Kind regards
Michiel
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Gurobi only supports products of pairs of variables, not triples. To overcome this issue, you need to introduce auxiliary variables and build the more complex expression using those. For example, in order to model
y = x1*x2*x3
you could write
z12 = x1*x2
y = z12*x3For binary variables, this should just work out of the box. For non-binary variables, this is only supported since Gurobi 9.0, and only if you set the "NonConvex" parameter to 2.
Regards,
Tobias
0 -
Is this still the only way to model prod() constraints?
e.g. a == x1*x2*x3? I'm looking for something like quicksum just for products.
Trying the solution above combined with https://support.gurobi.com/hc/en-us/community/posts/360057684331-invalid-expression-to-quad-expr-multiplication yields a quite ugly solution with a lot of dummy vars. Isn't there a simpler solution?
Thanks in advance.
0 -
Yes, unfortunately this is still the way to do it as of today.
0
Post is closed for comments.
Comments
4 comments