Including logic in objective of MPC

41 views
Skip to first unread message

M. O. Kay

unread,
May 14, 2019, 4:56:04 AM5/14/19
to YALMIP
Hello,

I am trying to implement an objective function for MPC applied on a supply-demand matching problem of a microgrid (including battery). What I cannot get working is implementing different import/export prices and the profit of the battery usage in the objective of the problem (See code below, red). I have tried several manners to do this, including one method of the following tutorial, https://yalmip.github.io/modellingif. I hope one of you can help me with my question. 

for k = 1:N
     s = binvar(4,1);
     objective = objective + C{k} + W{k};
          
          Costs = [sum(s) ==1;
                   implies(s(1), [P_G{k}>=0, C{k} == 0.055*P_G{k}]);
                   implies(s(2), [P_G{k}<=0, C{k} == -0.0055/3*P_G{k}]);
                   implies(s(3), [P_G{k}==0, C{k} == 0]);
                   implies(s(4), [P_B{k}>=0, W{k} == -0.055*2*P_B{k}])];

               
    constraints = [constraints, x{k+1} == x{k}+P_B{k}];
    constraints = [constraints, P_G{k}+P_Pv(k)-d(k)-P_B{k}==0];
    constraints = [constraints, -500 <= P_B{k}<= 500, -300<= P_G{k}<=300, 150<=x{k}<=850];         
end


Johan Löfberg

unread,
May 14, 2019, 5:28:38 AM5/14/19
to yal...@googlegroups.com
W is undefined (i.e can be set to -inf) for the first 3 cases, and C is undefined for the last one....

Johan Löfberg

unread,
May 14, 2019, 5:37:28 AM5/14/19
to YALMIP
and if you are minimizing the objective, the C term is simply the convex LP-representable expression max(0.055*P_G{k},-0.0055/3*P_G{k}), and assuming you want W to be 0 for negative P_B, that term is the nonconvex MILP-represetable term min(0,-0.055*2*P_B{k}).

M. O. Kay

unread,
May 14, 2019, 6:06:55 AM5/14/19
to YALMIP
Thank you for this insight, however, I do not think this will work since I spotted the following mistake:
implies(s(2), [P_G{k}<=0, C{k} == 0.0055/3*P_G{k}]);
therefore, a max(.) will not suffice I am afraid. Regarding your first comment, I did not fully understand what you were trying to say.

M. O. Kay

unread,
May 14, 2019, 6:37:59 AM5/14/19
to YALMIP
Edit: The expressions you provided still hold, thank you.

Johan Löfberg

unread,
May 14, 2019, 8:04:18 AM5/14/19
to YALMIP
First comment: If s(1) , s(2) or s(3) is 1, what value do you think W will have...
Reply all
Reply to author
Forward
0 new messages