Skip to main content

How to multiply two linear expressions in java

Answered

Comments

2 comments

  • Silke Horn
    Gurobi Staff Gurobi Staff

    Hi,

    You are right that GRBQuadExpr.addTerm only accepts variables, not complex expressions.

    There are two ways around this:

    • You expand the quadratic expression yourself, i.e., \((K+x+y)^2 = K^2 + x^2 + y^2 + 2Kx + 2Ky + 2xy\), and then build the resulting expression using addTerm.
    • You introduce an auxiliary variable, say \$a\$, and add a constraint that \(a == q\). Then you can use this variable to build our objective expression.
    0
  • WAFA NAFKHA
    First Question
    First Comment

    Hi,

    Thanks for your response.

    Before asking, I was using the first method, but in my thesis the objectif function will be more complicated and  I'm looking for better method.

    I'll implement your second solution, if i well understand :

    objectif function will be min a^2 , a is a variable and add a new constraint a == K + x + y

    Best regards

    0

Please sign in to leave a comment.