I'm trying to simulate scenario-based MPC problem using Mixed Integer Constraints. However, when I run the code, at some point Gurobi won't find a solution. And in case it finds a solution, the behavior of my object becomes really weird. The code is quite big, so I will just post the part of defining the objective and constraints.
Here I have 2 uncertain variables, w1 and w2 and N scenarios generated for each of them, K is my prediction horizon.
x = sdpvar(repmat(nx,1,K+1),ones(1,K+1));
y1 = sdpvar(repmat(ny,1,K),repmat(N,1,K));
y2 = sdpvar(repmat(ny,1,K),repmat(N,1,K));
r = sdpvar(repmat(ny,1,K+1),ones(1,K+1));
obs1=sdpvar(ny,2);
obs2=sdpvar(ny,2);
delta=0.04;
alpha=0.95;
cons=[];
objective = 0;
M=60;
za1=sdpvar(N,K);
z1 = sdpvar(1,K);
za2=sdpvar(N,K);
z2 = sdpvar(1,K);
dk1 = binvar(repmat(2*ny,1,K),repmat(N,1,K));
dk2 = binvar(repmat(2*ny,1,K),repmat(N,1,K));
e=0.01;
for k = 1:K
for i=1:N
cons=cons+[sum((C*x{k}-y1{k}(:,i)-sum(w1{i}(:,1:k),2)).^2)-z1(k)-za1(i,k)<=0];
cons=cons+[sum((C*x{k}-y2{k}(:,i)-sum(w2{i}(:,1:k),2)).^2)-z2(k)-za2(i,k)<=0];
end
cons=cons+[y1{k}(1,:)-obs1(1,1)+e<=M*dk1{k}(1,:),...
obs1(1,2)-y1{k}(1,:)+e<=M*dk1{k}(2,:),...
y1{k}(2,:)-obs1(2,1)+e<=M*dk1{k}(3,:),...
obs1(2,2)-y1{k}(2,:)+e<=M*dk1{k}(4,:),...
y1{k}(3,:)-obs1(3,1)+e<=M*dk1{k}(5,:),...
obs1(3,2)-y1{k}(3,:)+e<=M*dk1{k}(6,:),...
sum(dk1{k})<=5];
cons=cons+[y2{k}(1,:)-obs2(1,1)+e<=M*dk2{k}(1,:),...
obs2(1,2)-y2{k}(1,:)+e<=M*dk2{k}(2,:),...
y2{k}(2,:)-obs2(2,1)+e<=M*dk2{k}(3,:),...
obs2(2,2)-y2{k}(2,:)+e<=M*dk2{k}(4,:),...
y2{k}(3,:)-obs2(3,1)+e<=M*dk2{k}(5,:),...
obs2(3,2)-y2{k}(3,:)+e<=M*dk2{k}(6,:),...
sum(dk2{k})<=5];
objective = objective + (C*x{k}-r{k})'*(C*x{k}-r{k})+u{k}'*R*u{k};
cons = cons+[x{k+1} == A*x{k}+B*u{k},...
1/N*(z1(k)+za1(:,k)/(1-alpha))<=delta, za1(:,k)>=0, 1/N*(z2(k)+za2(:,k)/(1-alpha))<=delta, za2(:,k)>=0];