modelling constraints

102 views
Skip to first unread message

Tommaso De Marco

unread,
Mar 19, 2018, 6:42:00 AM3/19/18
to YALMIP
Dear Professor,
I have an issue regarding the correct way to model constraints. I have a variable and I have to model its bounds. These bounds have to be valid for each timestep.
For instance:

AvL_capacity=sdpvar(1,Horizon) where Horizon is the number of timesteps
AvL_capacity >= 0 
AvL_capacity<= EES_capacity

If I write the constraint as above YALMIP sees the inequalities as "element wise inequality 24x1".

If I model the bounds using a for loop:

AvL_capacity_bounds = [];
for k=1:Horizon;
    AvL_capacity_bounds = [AvL_capacity_bounds,(AvL_capacity(k)>=0),(AvL_capacity(k)<=EES_capacity)];
end
 
YALMIP sees the inequalities as "element wise inequality 1x1".
(The same goes for bounds of the variable Pees_store).

The same doubt goes for the following balance constraint:

Phub_balance = [];
for k=1:Horizon;
    Phub_balance = [Phub_balance,Pgrid_phub(k) + Ppv_phub(k) + Pees_phub(k) - Pphub_ees(k) + Pchp_phub(k) == Pphub_eload(k)]; %balance equation
end

With a for loop YALMIP sees the constraint as "equality constraint 1x1". 
WIthout for loop YALMIP sees the constraint as "equality constraint 1x24":

Phub_balance = [(Pgrid_phub + Ppv_phub + Pees_phub - Pphub_ees + Pchp_phub == Pphub_eload)]; %balance equation

WHAT IS THE CORRECT WAY TO MODEL THESE INEQUALITY AND EQUALITY CONSTRAINTS IN ORDER, FOR EXAMPLE, TO HAVE THE POSITIVITY OF AvL_capacity AND THE VALIDITY OF THE BALANCE EQUATION IN EACH TIMESTEP OF THE OPTIMIZATION?

(Using the two ways I showed you i get different results:

file "prova_tuttoel.m" --->constraints without for loops
file "prova_tuttoel_mettotuttiforsudiseq.m"---->constraints with for loops)

Thank you very much!! Any help is really appreciated!
prova_tutto_el.m
prova_tuttoel_mettotuttiforsudiseq.m

Johan Löfberg

unread,
Mar 19, 2018, 8:06:22 AM3/19/18
to YALMIP
Not sure what you are asking about

The following two models are 100% the same once compiled down to solver format, just created in different ways (and for large models, a vectorized creation will of course run faster)

x = sdpvar(2,1);
Model1 = [x <= 0]
Model2 = [x(1) <= 0,x(2) <= 0]


Tommaso De Marco

unread,
Mar 19, 2018, 8:50:37 AM3/19/18
to YALMIP
The point is that the two files I attached model the same thing. The only difference between the two files is the way I modeled the constraints I showed you.
If, as you say, the two ways of creating the constraints are the same, why do I get different results when running the optimization?

Johan Löfberg

unread,
Mar 19, 2018, 11:49:43 AM3/19/18
to YALMIP
you are using xls file which isn't supplied so I cannot test and see 

Tommaso De Marco

unread,
Mar 19, 2018, 12:00:50 PM3/19/18
to YALMIP
I'm sorry, my bad.
The reproducible files are now attached.
prova_tutto_el.m
prova_tuttoel_mettotuttiforsudiseq.m

Johan Löfberg

unread,
Mar 19, 2018, 12:54:53 PM3/19/18
to YALMIP
You're not defining the same models. In one of them you have 1452 constraints, and in one of them you have 1454. Somewhere your're missing some constraint, or adding some you shouldn't. 

If you want me to make any educated guess on where the mistake is, you would have to make the difference in the code much more clear by creating one file with an option, and then in the file have the two alternatives next to each other
Reply all
Reply to author
Forward
0 new messages