Skip to main content

Error: Malformed quadratic term in expression

Answered

Comments

5 comments

  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Dagm,

    The error is coming from constraint 'a22' in your example, as it contains a product of three variables.

    Modelling multilinear terms directly is not supported in Gurobi at present.  However, as explained in our Knowledge Base article "How do I model multilinear terms in Gurobi?", you can reformulate them into bilinear and quadratic terms.

    For your specific case, you can create a new variable Z and substitute constraint a22 with the following constraints in your LP file:

    c1 : Z - [ Y1 * Y3 ] = 0
    c2 : [ Z * Y4 ] <= 0

    Regards,

    Simran

     

    0
  • Dagm Abate
    Gurobi-versary
    First Question
    First Comment

    Hello Simran,

    Thank you so much for the suggestion. I corrected it accordingly and it works well. The challenge now is I have almost one million equations of that type and most of which have more than four variables in the term. E.g:
    Y1P_1: [ Y740_1 * Y6_1 * Y264_1 * Y265_1 * Y719_1 ] <= 0
    Y2P_1: [ Y514_1 * Y690_1 * Y691_1 * Y515_1 * Y284_1 * Y286_1 * Y111_1 ] <= 0
    Y3P_1: [ Y576_1 * Y578_1 * Y579_1 * Y42_1 * Y170_1 * Y597_1 * Y598_1 * Y572_1 * Y253_1 ] <= 0
    Y4P_1: [ Y33_1 * Y516_1 * Y294_1 * Y395_1 * Y722_1 * Y595_1 * Y634_1 * Y509_1 ] <= 0
    Y5P_1: [ Y518_1 * Y520_1 * Y396_1 * Y654_1 * Y15_1 * Y722_1 * Y595_1 * Y632_1 * Y634_1 * Y507_1 * Y509_1 ] <= 0
    Y6P_1: [ Y515_1 * Y292_1 * Y725_1 * Y759_1 * Y699_1 * Y687_1 ] <= 0

    [I am working on spatial optimization, and the original MIP problem can not be solved (as it is very large, with 90 thousand vars and one million constraints). So, I am exploring other 'exact' approaches, including this one].

    So, do you have any suggestion?

    Thanks again

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Dagm,

    In general, to model a product of n variables, you will need to add (n-1) auxiliary variables and constraints as described in How do I model multilinear terms in Gurobi?

    However, from your original post, it seems all "Y" variables in your model are binary. In this case, the constraint

    Y_1 * Y_2 * Y_3 *....* Y_n = 0 

    is equivalent to saying that at least one of the Y variables in the product must be zero, which is equivalent to saying that at most (n-1) of the Y variables in the product can be 1. So, we can model this constraint via the simple linear constraint

    Y_1 + Y_2 + Y_3 + .. + Y_n <= n-1

    I hope this helps!

    Regards,

    Simran

     

    0
  • Dagm Abate
    Gurobi-versary
    First Question
    First Comment

    Dear Simran,

    Thank you very much. 

    The constraint in my original MIP problem was actually formulated with linear equations similar to what you are suggesting me now (Y_1 + Y_2 + Y_3 + .. + Y_n <= n-1). The idea now is (as the original MIP problem couldn't be solved) to change the linear equations to quadratic and add a Lagrange penalization term to each constraint and include them in the objective function. So, changing the linear constraint into a quadratic one (that I am doing currently) is the first task. 

    That is my proposal, any different suggestions are very welcome, please.

    I thank you again

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Dagm,

    Assuming the rest of your model is linear, adding the constraints Y_1 + Y_2 + Y_3 + .. + Y_n <= n-1 and keeping the model linear should work better than making the model non-linear by adding the multilinear terms. 

    I am not sure by what you mean by the "original MIP problem couldn't be solved". Did you try using non-default values of Gurobi parameters? Our Parameter tuning tool can help you find parameter settings that improve the solver's performance for your model. You can also refer to our webinar on using the parameter tuning tool for more details.

    To answer your question on modelling the product of binary variables -  I did find out that the product of binary variables can also be modelled using Model.addGenConstrAnd(). You can read more about how to model logical constraints in our Knowledge Base article "How do I model logical and general expressions?"

    -Simran

    0

Please sign in to leave a comment.