Re: Only one of the constraints is violated

84 views
Skip to first unread message
Message has been deleted

Johan Löfberg

unread,
Dec 29, 2015, 3:10:43 PM12/29/15
to YALMIP
you would have to simplify the code considerably for me to easily see what is wrong according to you. make an example which doesn't simulate the whole thing, but simply computes what ever you think is wrong, and show that explicitly in the code
Message has been deleted

Abel Mir

unread,
Dec 30, 2015, 11:50:36 PM12/30/15
to YALMIP
With 3 generators and N the horizon time of the MPC problem, I just noticed that if my binary constraints are redifined this way:

for i = 1:N
        % Binary constraints
   
    StartUp_diesel_gen_para(:,i+1)= 0.2;
    ShutDown_diesel_gen_para(:,i+1) =0.3;   
           
       % Continuous constraints
    ...
    ...
end

With these definitions, the problem is more visible. Let's assume the horizon time N is 12 and the total simulation time 96. In this case, StartUp_diesel_gen is [zeros(3,84),0.2*ones(3,12)] and ShutDown is [zeros(3,84),0.3*ones(3,12)]. The first 84 time steps, the binary constraints are not taken into account.
With the continuous constraints, the problem doesn't happen. 
Do you have any idea of why only the last 12 time steps respect the definition ?

Thanks for your time.





Johan Löfberg

unread,
Dec 31, 2015, 3:15:37 AM12/31/15
to YALMIP
When you use the solver option '+gurobi', you are saying "Trust me, I now this problem is solvable by gurobi". However, this

    con = con + (StartUp_diesel_gen_para(:,i+1)== OnOff_diesel_gen_para(:,i+1)-OnOff_diesel_gen_para(:,i+1).*OnOff_diesel_gen_para(:,i));
    con = con + (ShutDown_diesel_gen_para(:,i+1) ==OnOff_diesel_gen_para(:,i) -OnOff_diesel_gen_para(:,i+1).*OnOff_diesel_gen_para(:,i));   

is obviously not solvable by gurobi. Hence, you will get crap

Abel Mir

unread,
Jan 2, 2016, 1:29:50 PM1/2/16
to YALMIP
Dear Johan,
Thanks for the reply. Could you explain why the 2 constraints are not solvable ? 

con = con + (StartUp_diesel_gen_para(:,i+1)== OnOff_diesel_gen_para(:,i+1)-OnOff_diesel_gen_para(:,i+1).*OnOff_diesel_gen_para(:,i));
con = con + (ShutDown_diesel_gen_para(:,i+1) ==OnOff_diesel_gen_para(:,i) -OnOff_diesel_gen_para(:,i+1).*OnOff_diesel_gen_para(:,i));

How are they different from these equality constraints found in the first bloc of code here ? http://users.isy.liu.se/johanl/yalmip/pmwiki.php?n=Tutorials.AutomaticDualization 

Johan Löfberg

unread,
Jan 2, 2016, 3:15:03 PM1/2/16
to YALMIP
you are multiplying decision variables

Abel Mir

unread,
Jan 2, 2016, 9:33:16 PM1/2/16
to YALMIP
Dear Johan,
Thanks for the reply. I try here to minimize the cost of turning ON and OFF the generators.
OnOff_diesel_gen_para      =binvar(nb_diesel_generator,N+1,'full'); %1 if  ON, O if off
ShutDown_diesel_gen_para   =binvar(nb_diesel_generator,N+1,'full'); % 1 if just has been started up, 0 if not
StartUp_diesel_gen_para    =binvar(nb_diesel_generator,N+1,'full'); % 1 if just has been shut down, 0 if not

con = [];  
obj = 0;
cost_turn_ON=1*[1 1 1];    % $
cost_turn_OFF=1*[1 1 1];
for i=1:N 
    for j=1:nb_diesel_generator  
        if i==1
     StartUp_diesel_gen_para(j,i)= 22;
    ShutDown_diesel_gen_para(j,i) = 23;
        else
    con = con + (StartUp_diesel_gen_para(j,i)>= OnOff_diesel_gen_para(j,i)-OnOff_diesel_gen_para(j,i-1));     % Constraint #1
    con = con + (ShutDown_diesel_gen_para(j,i)>=OnOff_diesel_gen_para(j,i-1) -OnOff_diesel_gen_para(j,i));    % Constraint #2    
    con = con + (StartUp_diesel_gen_para(j,i)+ShutDown_diesel_gen_para(j,i)<=1);                              % Constraint #3
        end
    obj = obj + (StartUp_diesel_gen_para(j,i)*cost_turn_ON(j));       % obj #1
    obj = obj + (ShutDown_diesel_gen_para(j,i)*cost_turn_OFF(j));     % obj #2
    end
end

"OnOff_diesel_gen_para(j,i)"  is 1 when the generator j at time i is ON and 0 when OFF. Everything works fine when "cost_turn_ON" and "cost_turn_OFF"  are equal. It gets tricky when one is higher than the other. For instance, when "cost_turn_ON" is higher than "cost_turn_OFF" ,obj #1 is minimized by setting  "StartUp_diesel_gen_para(j,i)" to 0 but very often, while violating Constraint #1.
Did I miss a fourth constraint ?

How would you code that ?

Thanks for your help

Johan Löfberg

unread,
Jan 7, 2016, 4:48:46 AM1/7/16
to YALMIP
Not sure what the question is, but if you want to have w=x*y where x and y are binary, you have the cuts

[w<=x, w<=y,w>=x+y-1]


Reply all
Reply to author
Forward
0 new messages