Skip to main content

Matlab: Add maximum constraints

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    The method you are using is a Python method. For MATLAB, you have to provide variable indices in the \(\texttt{genconmax}\) field, see the documentation of the MATLAB model argument for more details.

    An example of the min function which is handled equivalently to the max function can be found in the genconstr.m example.

    Best regards, 
    Jaromił

    0
  • Ahmed Abdelaziz Elsayed
    • Gurobi-versary
    • First Question
    • First Comment

    Dear Jaromil

     

    Thank you so much. Now I know how to add max constraints.

    The document describes how to make one decision variable equal a maximum set of decision variables. 

    However,  in my case, I want to make some operations first for example adding a constant or removing a constant. 

    EX; r=max(c1-x1, c2-x2, c3-x3.....etc)

    where c are predefined constants,  and r and x are the Gurobi optimization variables.

    I am thinking of adding new decision variables and setting equality constraints to these values to ensure they equal ci-xi. Then set the needed variable to be the maximum of the newly defined decision variables. 

    However, is there any simpler way to do it? 

    0
  • Jaromił Najman
    • Gurobi Staff

    I am thinking of adding new decision variables and setting equality constraints to these values to ensure they equal ci-xi. Then set the needed variable to be the maximum of the newly defined decision variables. 

    However, is there any simpler way to do it? 

    This is the correct and currently only way to implement your model. The general constraint fields only accept single optimization variables (indices) as argument and resultant variables.

    Best regards, 
    Jaromił

    0

Post is closed for comments.