Can you create an array of Constraints in an Optimisation MILP problem?

8 Ansichten (letzte 30 Tage)
Humberto Lopez
Humberto Lopez am 13 Jun. 2019
Bearbeitet: Matt J am 14 Jun. 2019
Hello, I am modelling power plant capacity additions but because there would be alot of plants, I am trying to code the constraints with an array, I have tryed to input the following constraint code where Eih, Eil and Cinew are continuous variables.
for i = 1:252
NewPlantCapacityConstraint=Eih(i)+Eil(i);
c(i,1)=NewPlantCapacityConstraint;
MymodelRP.Constraints.NewEnergyAllocation=NewPlantCapacityConstraint(i)<=Cinew(i,1);
end
I get this error when runing the code "OptimizationVariables appearing in the same problem, constraint, or expression must have distinct "Name" properties.
Make a new variable with a different "Name" property, or retrieve the original variable using the Variables property.". Is this because I can only code one constraint at the time? Is there a way to code more than one constraint at the time? I would really appreciate some help on the matter
Thank you very much

Antworten (2)

Matt J
Matt J am 13 Jun. 2019
Bearbeitet: Matt J am 13 Jun. 2019
You can just write
I=1:252;
MymodelRP.Constraints.NewEnergyAllocation = ( Eih(I,1)+Eil(I,1)<=Cinew(I,1) );
  2 Kommentare
Humberto Lopez
Humberto Lopez am 13 Jun. 2019
Yes, I have tried that from the beginning but it doesn't work, I get this message:
"Warning: Existing constraints for this problem will be overwritten. To specify multiple constraints, assign constraints using labels. For example, PROB.Constraint.myCon = CONSTR."
I do not want MATLAB to overwrite the constraint but to store each constraint or to take in accont an array of constraints if that is possible somehow. It should take in account 252 constraints, one for each plant, when solving the objective function.
Thank you, hope you can help
Matt J
Matt J am 13 Jun. 2019
I would have to see more of your code to know why that's happening. There is nothing improper about defining vector-valued constraints. What version of Matlab is this?

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 13 Jun. 2019
Bearbeitet: Matt J am 13 Jun. 2019
The error message you are getting occurs when you do things like this,
x=optimvar('Xname',252,1);
y=optimvar('Xname',252,1);
prob=optimproblem;
prob.Constraints.xLessThany=(x<=y);
instead of this,
x=optimvar('Xname',252,1);
y=optimvar('Yname',252,1);
prob=optimproblem;
prob.Constraints.xLessThany=(x<=y);
It has nothing to do with whether the constraint called "xLessThany" is array-valued.
  3 Kommentare
Matt J
Matt J am 14 Jun. 2019
Bearbeitet: Matt J am 14 Jun. 2019
I think you should post your code here. However, the for-loop above makes no sense. The left hand side does not vary with j and is simply getting overwritten with every iteration of the loop. Also, as we've now established, it should be possible to avoid loops altogether and just give the constraint in vectorized form,
Mymodel.Constraints.xi = ( xiasist + xiasisCCS +xswitch +xswitchCCS <= 1 );
if that is indeed the intended constraint.
Mary Fenelon
Mary Fenelon am 14 Jun. 2019
Display the generated problem with showproblem to see if it matches what you intended.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by