Skip to main content

Error when i run modelling (m.addconstr)

Answered

Comments

8 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Ehab,

    The syntax you used, is supported by the addQConstr function and is not supported by the addConstr function.

    You could either use

    m.addConstr( bat * int1 == netload[i], "c0" )

    or

    m.addQConstr( bat * int1, GRB.EQUAL, netload[i], "c0" )

    Best regards,
    Jaromił

    0
  • Ehab Issa
    • Gurobi-versary
    • Conversationalist
    • First Question
     

    Thank you for your response

    i try using two syntax now but still error

    but if i add term (bat+......)
    m.addQConstr( bat + bat * int1, GRB.EQUAL, netload[i], "c0" )

    The program works ؟

    0
  • Jaromił Najman
    • Gurobi Staff

    Could you post the error you get?

    0
  • Ehab Issa
    • Gurobi-versary
    • Conversationalist
    • First Question

    Jaromił Najman

    0
  • Jaromił Najman
    • Gurobi Staff

    The error you see has nothing to do with the syntax of the constraint you are adding. When you add the constraint

    bat * int1 == netload[i]

    your problem becomes infeasible. Thus, no feasible point is available after the optimization is finished. Therefore, you cannot access the X attribute of the variables. Apparently formulating this bilinear constraint as

    bat + bat * int1 == netload[i]

    seems to make your problem feasible.
    A proper way of avoiding such errors would be to check the optimization status first after the optimization has finished. For an example of this, see, e.g., line 30 of the lp.py example.

    To correct my previous message, the syntax

    m.addConstr( bat * int1, GRB.EQUAL, netload[i], "c0")

    is also accepted by \(\texttt{gurobipy}\).

    Best regards,
    Jaromił

    0
  • Ehab Issa
    • Gurobi-versary
    • Conversationalist
    • First Question

    Thank you sir ,

    I am grateful to you

    Jaromił Najman

    bat+bat *int1==netload[i]

    But if you use this syntax, it is considered correct and does not affect optimization  quality

     

    0
  • Jaromił Najman
    • Gurobi Staff

    Both syntax options

    m.addConstr(bat + bat * int1, GRB.EQUAL, netload[i], "c0")

    and

    m.addConstr(bat + bat * int1 == netload[i], "c0")

    are correct.

    The problem lies in the feasibility of your problem. When you use the

    bat * int1 == netload[i]

    equality, then no feasible point to your problem exists, i.e., there is no point satisfying all of your constraints at once. In case, you are interested in how to find what causes the infeasibility, you might want to have a look at the Knowledge Base article on How do I determine why my model is infeasible?

    0

Post is closed for comments.