Matlab: Add maximum constraints
回答済みHi
I'm using Matlab with Gurobi and I want to know how to model such a constrain that set one of the decision variables to the max value of other variables.
EX; r=max(c1-x1,c2-x2,c3-x3.....etc)
here c are constants,
r and x are Gurobi optimization variables.
I tried some thing like that, but it does not work.
model.addGenConstrMax(r, C-X, "maxconstr").
I look into all the Matlab examples, but could not find such a case.
I really appreciate any help.
-
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 -
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 -
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
サインインしてコメントを残してください。
コメント
3件のコメント