Multiplying linear expressions in Java

231 views
Skip to first unread message

Zhihao Chen

unread,
Oct 23, 2013, 12:50:53 AM10/23/13
to gur...@googlegroups.com
I was wondering if there was a way to create a quadratic expression by multiplying two linear expressions. I know in C++ you can simply multiply them

i.e. GRBQuadExpr = GRBLinExpr*GRBLinExpr

but is there a similar way to do this in Java?

Jakob Sch.

unread,
Oct 23, 2013, 4:20:07 AM10/23/13
to gur...@googlegroups.com
Hi Zhihao,

my guess would be that you have to use

GRBQuadExpr.addTerms()

see http://www.gurobi.com/documentation/5.6/reference-manual/java_grbquadexpr_addterms

Best regards,
Jakob

Zhihao Chen

unread,
Oct 23, 2013, 10:20:21 PM10/23/13
to gur...@googlegroups.com
Thanks for your reply Jakob! GRBQuadExpr.addTerms() only works if you have two GRBVars though.. I have a more complicated expression and was hoping of multiplying two GRBLinExprs instead of multiplying the expression by hand then using GRBQuadExpr.addTerms().

Zhihao

Greg Glockner

unread,
Oct 24, 2013, 1:05:59 AM10/24/13
to gur...@googlegroups.com
Create new variables that equal the GRBLinExpr terms, then multiply them. The overhead will be handled in presolve.

Zhihao Chen

unread,
Oct 24, 2013, 2:03:29 AM10/24/13
to gur...@googlegroups.com
Thank you, that solved the problem!

Zhihao
Reply all
Reply to author
Forward
0 new messages