Warning: You have unbounded variables in IFF leading to a lousy big-M relaxation.

252 views
Skip to first unread message

Martin Pichler

unread,
Jan 27, 2016, 7:41:18 AM1/27/16
to YALMIP
DEar Prof. Löfberg,

I get the nasty comment above and want to get rid of it.
I think I bounded everything which be the origin.

Now I gave up searching since I cannt see anything.
Please see the attached files.

Thanks a lot!
regards MArtin


function [controller]=mpc_bld_MLDbuiTheBat(SSM, N, f1, f2)


% Model data
A = SSM.a;
B = SSM.b;
nx = size(SSM.a,1);     % Number of states
nu = 1;                 % Number of inputs
nv = size(SSM.b,2)-nu;  % Number of (pred) disturbance variables
ny = 1;                 % Number of outputs

Np = N.pred;            % prediction horizon
Nc = N.ctr;             % control horizon

% weights
Q = sdpvar(1,1);
Qc = sdpvar(1,1);
R1 = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));
R2 = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));
Ru = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc)); % linear weight

% limits
ymin = sdpvar(repmat(1,1,Np+1),repmat(1,1,Np+1));
ymax = sdpvar(repmat(1,1,Np+1),repmat(1,1,Np+1));
ymin_c = sdpvar(repmat(1,1,Np+1),repmat(1,1,Np+1));
ymax_c = sdpvar(repmat(1,1,Np+1),repmat(1,1,Np+1));
u_min = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));
u_max = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));
u_fmin = sdpvar(repmat(1,1,1),repmat(1,1,1));

% tracking
utrack1 = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));
% tracking
utrack2 = sdpvar(repmat(1,1,Nc),repmat(1,1,Nc));

% states and manipulated variable
x = sdpvar(repmat(nx,1,Np+1),repmat(1,1,Np+1));
u = sdpvar(repmat(nu,1,Np),repmat(1,1,Np));
% input variables
v = sdpvar(repmat(nv,1,Np),repmat(1,1,Np));
p_ref = sdpvar(repmat(1,1,Np),repmat(1,1,Np));

% slack variables and temporary var
e = sdpvar(repmat(ny,1,Np+1),repmat(1,1,Np+1));
e_c = sdpvar(repmat(ny,1,Np+1),repmat(1,1,Np+1));
qs_1 = sdpvar(repmat(nu,1,Nc),repmat(1,1,Nc));
qs_2 = sdpvar(repmat(nu,1,Nc),repmat(1,1,Nc));

% slack variable and diverse bounds
e_bound=100 %
qs_bound=200 %

% auxiliary (output) variables
p_out = sdpvar(repmat(nu,1,Np),repmat(1,1,Np));

%% ##### Loop Cost fct. & constraints #####
Jfct = 0; constr = [];
for k = 1:Np
    Jfct = Jfct + e{k+1}*Q*e{k+1}
    Jfct = Jfct + e_c{k+1}*Qc*e_c{k+1}
   
    constr = [constr, x{k+1} == A*x{k} + B*[u{min(k,Nc)}; v{k}]];
    constr = [constr, ymin{k+1}-e{k+1}<=x{k+1}(2)<=ymax{k+1}+e{k+1}];           % inner
    constr = [constr, ymin_c{k+1}-e_c{k+1}<=x{k+1}(2)<=ymax_c{k+1}+e_c{k+1}];   % outer
    constr = [constr, 0<=e{k+1}<=e_bound];
    constr = [constr, 0<=e_c{k+1}<=e_bound];
   
    if k<=Nc
        Jfct = Jfct + Ru{k}*norm(u{k},1); %
               
        Jfct = Jfct + qs_1{k}*R1{k}*qs_1{k}
       
        qrefCOP=f1.d+f1.k*x{k}(3);
        constr = [constr, utrack1{k}-10*eps - qs_1{k} <= u{k} <=qrefCOP+10*eps + qs_1{k}];
        constr = [constr, 0<=qs_1{k}<=qs_bound];
        constr = [constr, implies(u{k}<=u_fmin, utrack1{k}==0)];
        constr = [constr, implies(u{k}<=u_fmin, u{k}==0)];
        constr = [constr, implies(u{k}>=u_fmin, utrack1{k}==qrefCOP)];
       
        Jfct = Jfct + qs_2{k}*R2{k}*qs_2{k}
        qrefPV=(p_ref{k}-f2.k1-f2.k3*25)/f2.k2;
        constr = [constr, qrefPV-10*eps - qs_2{k} <= u{k} <=qrefPV+10*eps + qs_2{k}];
        constr = [constr, 0<=qs_2{k}<=qs_bound];
                      
        % get rid of nasty YALMIP comments
        constr = [constr, -qs_bound<=u{k}<=qs_bound];              % important for big M reform. of next line
        constr = [constr, u_min{k}<=u{k}<=u_max{k}];           % important for big M reform. of next line
        constr = [constr, -qs_bound<=qrefCOP<=qs_bound];              % important for big M reform. of next line
        constr = [constr, -qs_bound<=utrack1{k}<=qs_bound];           % important for big M reform. of next line
        constr = [constr, -qs_bound<=qrefPV<=qs_bound];               % important for big M reform. of next line

    else
        constr = [constr, u{k}==u{Nc}];
    end
    % just for output
    constr = [constr, implies(u{k}<=u_fmin, -10*eps<=p_out{k}<=10*eps)];
    constr = [constr, implies(u{k}>=u_fmin, p_out{k}==f2.k1+f2.k2*abs(u{k})+f2.k3*x{k}(3))];
    constr = [constr, 0<=p_out{k}<=200];         % important for big M reform. of next line
   
    constr = [constr, 0<=p_ref{k}<=200];      % important for big M reform. of next line
    constr = [constr, 10<=x{k}(1)<=50];         % important for big M reform. of next line
    constr = [constr, 10<=x{k}(2)<=50];         % important for big M reform. of next line
    constr = [constr, 10<=x{k}(3)<=50];         % important for big M reform. of next line
 
end
    constr = [constr, 0<=u_fmin<=qs_bound];   % important for big M reform. of next line

    %% ##### optimizer inputs and outputs #####
para_in = {x{1} , [v{:}], [p_ref{:}], [Q], [Qc], [R1{:}], [R2{:}], [Ru{:}], ...
    [u_fmin], [u_min{:}], [u_max{:}], [ymin{:}], [ymax{:}], [ymin_c{:}], [ymax_c{:}]};
sol_out = {[u{:}], [x{:}],  [p_out{:}]};

%% # solver options
%ops =sdpsettings('solver','mosek');
ops =sdpsettings('solver','gurobi');
%ops =sdpsettings('solver','gurobi','verbose',2);
controller = optimizer(constr, Jfct, ops, para_in, sol_out);

end

mpc_4analysis.m
call_mpc_4analysis.m

Johan Löfberg

unread,
Jan 27, 2016, 7:50:52 AM1/27/16
to YALMIP
u{k} is not explicitly bounded for k>Nc

Martin Pichler

unread,
Jan 27, 2016, 8:55:06 AM1/27/16
to YALMIP
Thank you a lot.
Reply all
Reply to author
Forward
0 new messages