N=3;M=4;xx=[1,-2];a=[-1 5 -2 1];VA=sdpvar(1,N);Va=sdpvar(1,N);temb=binvar(1,N);tem=sdpvar(N,2);
Ca=binvar(N,M,'full');va=sdpvar(2,N,'full');CA=binvar(1,N);bb=sdpvar(1);
Model=[sum(CA)==1,binary(CA),binary(Ca),0<bb<=2,0<Va<50];
for n=1:N
Model=[Model,sum(Ca(n,:))==1];
for l=1:2
if l==1
for m=1:M
Model=[Model,implies(Ca(n,m),temb(n)==1)];
Model=[Model,implies(Ca(n,m),tem(n,l)==sum(a(1:m))*xx(l))];
end
else
for m=1:M
Model=[Model,implies(Ca(n,m),tem(n,l)==tem(n,l-1)*sum(a(1:m))*xx(l))];
end
end
end
Model=[Model,implies(temb(n),Va(n)==tem(n,2))];%tem(n,2)=sum(a(1:m)*xx(1)*sum(a(1:m)*xx(2), when Ca(n,m)==1
Model=[Model,implies(CA(n),n==ceil(bb))]; Model=[Model,implies(CA(n),VA(N-n+1:N)==Va(1:n))];
if n<N
Model=[Model,implies(CA(n),VA(1:N-n)==0)];
end
end
options=sdpsettings('solver','bnb','verbose',0,'debug',1);%Model=[Model,VA(N)>0];
opt=solvesdp(Model,sum(VA),options);
VA=double(VA)
Va=double(Va)
CA=double(CA)
Ca=double(Ca)
N=3;M=4;xx=[1,-2];a=[-1 5 -2 1];VA=sdpvar(1,N);Va=sdpvar(1,N);temb=binvar(1,N);tem=sdpvar(N,2);Ca=binvar(N,M,'full');va=sdpvar(2,N,'full');CA=binvar(1,N);bb=sdpvar(1);
slack = sdpvar(N,2,M);Model=[sum(CA)==1,binary(CA),binary(Ca),0<=bb<=2,0<=Va<=50, -1000 <= tem <= 1000,0<= slack <= 1000 ];
for n=1:N Model=[Model,sum(Ca(n,:))==1]; for l=1:2 if l==1 for m=1:M Model=[Model,implies(Ca(n,m),temb(n)==1)];
Model=[Model,implies(Ca(n,m),tem(n,l)==sum(a(1:m))*xx(l)+slack(n,l,m)) ];
end else for m=1:M
Model=[Model,implies(Ca(n,m),tem(n,l)==tem(n,l-1)*sum(a(1:m))*xx(l)+slack(n,l,m))];
end end end Model=[Model,implies(temb(n),Va(n)==tem(n,2))];
% Model=[Model,implies(CA(n),n==ceil(bb))]; Model=[Model,implies(CA(n),VA(N-n+1:N)==Va(1:n))]; % if n<N % Model=[Model,implies(CA(n),VA(1:N-n)==0)]; % endendopt=solvesdp(Model,max(slack(:)))value(slack)
Sorry to reply so late.
I find that whenever we have Model=[Model,implies(Ca(n,m),tem(n,l)==tem(n,l-1)*sum(a(1:m))*xx(l))]; the problem is infeasible. And once I remove this command, everything is fine. Also, I tested if we change it to Model=[Model,implies(Ca(n,m),tem(n,l)==sum(a(1:m))*xx(l))]; the problem is also feasible. I am wondering, there must be something wrong with tem(n,l)==tem(n,l-1)*sum(a(1:m))*xx(l)) in implies. But why? I just want to use the multiplication of tem(n,1),tem(n,2),…,tem(n,l-1). If not put in this way, how could I realize this?
Thank you so much!
N=3;M=4;xx=[1,-2];a=[-1 5 -2 1];
VA=sdpvar(1,N);
Va=sdpvar(1,N);
temb=binvar(1,N);tem=sdpvar(N,2);
Ca=binvar(N,M,'full');
va=sdpvar(2,N,'full');CA=binvar(1,N);bb=sdpvar(1);
% slack = sdpvar(N,2,M);
Model=[sum(CA)==1,0<=bb<=2,0<=Va<=50, -1000 <= tem <= 1000];%,0<= slack <= 1000 ];
for n=1:N
Model=[Model,sum(Ca(n,:))==1];
for l=1:2
if l==1
for m=1:M
Model=[Model,implies(Ca(n,m),temb(n)==1)];
Model=[Model,implies(Ca(n,m),tem(n,l)==sum(a(1:m))*xx(l))];
end
else
for m=1:M
Model=[Model,implies(Ca(n,m),tem(n,l)==sum(a(1:m))*xx(l)*tem(n,l-1))];
end
end
end
Model=[Model,implies(temb(n),Va(n)==tem(n,2))];
end
options=sdpsettings('solver','mosek','verbose',0,'debug',1);
opt=solvesdp(Model,-sum(Va),options)
value(Va)
Alright, but I don’t see why it is wrong. Could you please point out which constraint indicates it is wrong?
Thanks,
implies(a &&b,c)
implies(a| b,c)
implies(a,c)+implies(b,c)
>> implies(a & b,c==2)
+++++++++++++++++++++| ID| Constraint|+++++++++++++++++++++| #1| (implies)|+++++++++++++++++++++