I am making an MPC in simulink, and my dynamics are piecewise affine. I am getting the warning Warning: You have unbounded variables in IFF leading to a lousy big-M relaxation, but I cannot see which variables that are missing bounds in my program.
Here is the code: The vector x_dod is a large vector that consists of N 2x1 concatenated vectors. I do believe this is where the error lies, but I can't identify it. Even if I choose only N = 2, this program takes forever to run.
persistent Controller
if t == 0
%Number of inputs:
M = 2;
%Number of sites:
N = M;
eta_load = 0.8;
eta_gen = 0.7;
%Discrete system matrices:
Ac = [1 0; 0 0 ];
Ad = [0 0; 0 1];
Bc = [1;0];
Bd = [0;1];
%Prediction horizon:
L = 20;
q = 2;
Q_DOD = eye(2*M);
Q_SOC = 1;
R = 1;
u_min = -20;
u_max = 20;
C = 1200;
ref_SOC = 0.5;
SOC_max = 1;
SOC_min = 0.3;
yalmip('clear');
u = sdpvar(repmat(M,1,L),repmat(1,1,L));
x_dod = sdpvar(repmat(2*M,1,L+1),repmat(1,1,L+1));
x_soc = sdpvar(repmat(N,1,L+1),repmat(1,1,L+1));
sdpvar ref
constraints = [];
objective = 0;
for k = 1:L
objective = objective + norm(Q_DOD*x_dod{k},2) + norm(Q_SOC*(x_soc{k}-ref_SOC.*ones(2,1)),2) + norm(R*u{k},2);
for i = 1:M
Model_dod1 = [x_dod{k+1}(2*i-1:2*i) == Ad*x_dod{k}(2*i-1:2*i) + Bd*u{k}(i)./(C*eta_gen),-3*ones(M,1) <= x_dod{k}(2*i-1:2*i) <= zeros(M,1), u{k}(i) <= 0];
Model_dod2 = [x_dod{k+1}(2*i-1:2*i) == Ac*x_dod{k}(2*i-1:2*i) + eta_load.*Bc*u{k}(i)./C, zeros(M,1) <= x_dod{k}(2*i-1:2*i) <= 3*ones(M,1), u{k}(i) > 0];
Model_soc1 = [x_soc{k+1}(i) == x_soc{k}(i) + (u{k}(i))/(C*eta_gen), u{k}(i) <= 0];
Model_soc2 = [x_soc{k+1}(i) == x_soc{k}(i) + (eta_load*u{k}(i))/C, u{k}(i) > 0];
constraints = [constraints, Model_dod1 | Model_dod2,u_min <= u{k}(i) <= u_max];
constraints = [constraints, Model_soc1 | Model_soc2, SOC_min <= x_soc{k}(i) <= SOC_max];
end
constraints = [constraints, sum(u{k}) == ref];
end
for j = 1:M
constraints = [constraints,-3*ones(2,1) <= x_dod{k+1}(2*j-1:2*j) <= 3*ones(2,1)];
constraints = [constraints, SOC_min <= x_soc{k+1}(j) <= SOC_max];
end
Controller = optimizer(constraints,objective,[],{x_soc{1},x_dod{1},ref},u{1});
uout = Controller{{currentx_soc,[0;0;0;0],P_ref}}
else
uout = Controller{{currentx_soc,[0;0;0;0],P_ref}}
end