Hello everybody.
I tried to solve my CP by cvx, but I don’t know why constraints do not work. at the end the answer is NAN and constraints are violated!!!
please help me.
T_1_l=9; T_1_u=23; N_a=3; E_1_max=1.5; E_1_min=0.2; eps_1=0.2;
T_2_l=12; T_2_u=22; Taw_2=4; E_2_min=0.2; E_2_0=[1 1 1 1]; eps_2=0.2;
T_3_l=1; T_3_u=18; Taw_3=3; E_3_0=[0.8 1.6 1.1]; E_3_min=0; eps_3=0.2;
T_4_l=8; T_4_u=23; E_4_max=4; E_4_min=0; a=0.9; B=-0.0095;
W_comf=75; W_des_min=70; W_des_max=79; Cc_1=0.1; Cc_2=0.1;
T_5_l=1; T_5_u=24; E_5_max=2.3; E_5_min=0;
D_max=0.2; R_5_l=-0.25; R_5_u=0.25; B_5_max=0.8; Gamma_5=0.5; B_5_ini= 0.4 % sahmi az charge battery k bayad akhar bemoone :)
lambda_1=1; lambda_2=1; lambda_3=1; %?????? az maghale bayad dar biad
eta_5_1=5*(exp(-7)); eta_5_2=4*(exp(-7)); eta_5_3=1; eta_5_4=0.2;
T_s_l=7; T_s_u=18;
P=[3 2.75 2.35 2.5 2.30 2.5 2.75 3.25 3.30 3.35 3.45 3.5 3.4 3.3 3.25 3.15 3.15 3.5 4.25 4.5 4 6.75 3.5 3.35];
W_out=[65 62 62 61 61 62 70 80 82 83 85 86 88 90 92 95 97 100 95 88 83 80 78 76];
n1=T_1_u-T_1_l+1;
n2=T_2_u-T_2_l-Taw_2+2; %=M_2
n3=T_3_u-T_3_l-Taw_3+2; %=M_3
n4=T_4_u-T_4_l+1;
n5=T_5_u-T_5_l+1;
cvx_begin
variable y_1(n1,1);
variable Lambda_2(1,n2);
variable Lambda_3(1,n3);
variable ee_4(n4,1);
variable d_5(n5,1);
variable b_5(n5,1);
expression e_1(24,1);
expression e_2(24,1);
expression e_3(24,1);
expression e_4(24,1);
expression e_5(24,1);
expression c_1(24,1);
expression c_2(24,1);
expression c_3(24,1);
expression c_4(24,1);
expression c_5(24,1);
expression c_5_b(24,1);
expression c_5_d(24,1);
expression W_in(24,1);
for t=1:24
if (T_1_l)<=t && t<=(T_1_u)
e_1(t)=E_1_max*y_1(t-T_1_l+1)+E_1_min*(1-y_1(t-T_1_l+1));
c_1(t)=(1+eps_1*t)*y_1(t-T_1_l+1);
else
e_1(t)=0;
c_1(t)=0;
end
e_1=e_1';
C_1=c_1';
%SA-UL1:a2
if (T_2_l)<=t && t<=(T_2_u)
for m=1:(T_2_u-T_2_l-Taw_2+2)
if (T_2_l+m)<=t && t<=(T_2_l+m+Taw_2-1);
E_2(m,t)=E_2_0(t-(T_2_l+m-1));
w_2(m,t)=1+eps_2*(T_2_l+m-1);
else
E_2(m,t)=0;
w_2(m,t)=0;
end
end
e_2=Lambda_2*E_2;
c_2=Lambda_2*w_2;
else
e_2(t)=0;
c_2(t)=0;
end
e_2=e_2';
C_2=c_2';
if (T_3_l)<=t && t<=(T_3_u)
for m=1:(T_3_u-T_3_l-Taw_3+2)
if (T_3_l+m)<=t && t<=(T_3_l+m+Taw_3-1);
E_3(m,t)=E_3_0(t-(T_3_l+m-1));
w_3(m,t)=1+eps_3*(T_3_l+m-1);
else
E_3(m,t)=0;
w_3(m,t)=0;
end
end
e_3=Lambda_3*E_3;
c_3=Lambda_3*w_3;
else
e_3(t)=0;
c_3(t)=0;
end
e_3=e_3';
C_3=c_3';
if (T_4_l)<=t && t<=(T_4_u)
if t==T_4_l
W_in(t)=70+a*(W_out(t)-70)+(1000*B)*ee_4(t-T_4_l+1);
e_4(t)=ee_4(t-T_4_l+1);
else
W_in(t)=W_in(t-1-T_4_l+1)+a*(W_out(t)-W_in(t-1-T_4_l+1))+(1000*B)*ee_4(t-T_4_l+1);
e_4(t)=ee_4(t-T_4_l+1);
end
c_4(t)=Cc_1*(square(W_in(t)-W_comf))-Cc_2;
else
e_4(t)=0;
c_4(t)=0;
end
e_4=e_4';
C_4=c_4';
if (T_s_l)<=t && t<=(T_s_u)
v_t(t)=0.2;
else
v_t(t)=0;
end
v_t=v_t';
end
uu=(e_1+e_2+e_3+e_4)-v_t;
u=max(0,uu);
C=(C_1+C_2'+C_3'+C_4)';
minimize (P*u+sum(C(:)))
subject to
0<= y_1 <=1;
0<= Lambda_2 <=1
0<= Lambda_3 <=1
E_4_min<= e_4 <=E_4_max
W_des_min<= W_in <=W_des_max
0<= d_5 <=D_max
R_5_l<= b_5 <=R_5_u
for t=1:24
0<= B_5_ini+sum(b_5(1:t)) <=B_5_max
end
cvx_end
I don’t know what is “preformatted text”, could you pleas explain for me?
for example, y_1 should be bounded by (0,1); but after running the code, it is out of bound!!!
also, this objective function has 4 parts, when I comment out 3 of them, the constrain for remain is ok, but for more than one, constraints are out of bound.
thank you so much