Skip to main content

How to get a more compacted version of some constraints?!

Answered

Comments

4 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?.
  • Xianbang Chen
    • Gurobi-versary
    • Conversationalist
    • Curious

    Dear Sabreen,

    Hello, I guess you are trying to export a compact formulation like A_1*x=b_1 & A_2x<b_2, right?

    If so, you can export the model structure variable to get the matrix A_1, A_2, b_1, and b_2, which are generally sparse matrixes in the model structure variable.

    In my case, I use YALMIP and MATLAB to call Gurobi, so I can directly use the command export() to get the matrixes. Maybe you can try my way.

    Thanks,
    Xianbang

     

    0
  • Jaromił Najman
    • Gurobi Staff

    Dear Sabreen,

    To me, the 4 \(\texttt{addConstrs}\) lines look already very compact. It is not bad to have a few lines more of code if the final code is understandable and can be easily maintained by you (and possibly others). I am sure there is a way to save a line or two but this will most likely result in a rather complex piece of code.

    Best regards,
    Jaromił

    0
  • Sabrin Rashwan
    • Gurobi-versary
    • Conversationalist
    • Investigator

    @Xianbang and @ Jaromił , thanks a lot for your prompt response. 

    Jaromił, thanks to your reply I paid attention to a specific point in my model in general. As Jaromił  has mentioned and by try and error the first two sets compacted to

    m.addConstrs((quicksum(z1[r,i,j] for i in Cr1[r] for j in Cr1[r] if i<j and b[r]==1 or i>j and b[r]==-1)==0 for r in R ),'20')

    Gurobi accepted this syntax and it worked fine.

    Best regards,

    Sabreen

    0

Post is closed for comments.