I am been trying to figure out the cause of infeasibility or unboundness in my programme since past few days but i couldn't take a lead. I have copied the matlab code below. Can you please look at it and say where might have i done wrong. With Objective function, the problem arises .
Thank you in advance.
%% optimzation
clc;
clear all;
load chargeLoad.mat; % load the data
stn_load1=chargeLoad(1,1:144);%per 10 minutes of load;
%% taking average of each 6 points 10 minutes to get per hour load
stn_load2=reshape(stn_load1,6,24);
temp=sum(stn_load2)./6; % average
temp1=repmat(temp,4,1);%per 15 minutes load
stn_load=reshape(temp1,1,[]); %making row vector of load per 15 minutes
P_buy_before=stn_load(1,41:64);
P_DR(5:24)=500;
%% power reduction during DR period
M_t1=zeros(1,4);
% for i=5:24
% M_t(1,i)=P_buy_before(1,i)-P_DR(1,i);
% end
M_temp=300+(450-300).*rand(1,20);
M_t=[M_t1 M_temp];
%% medium price range
M_price=[72.75 69.34 64.14 60.00 64.25 81.87 106.00 106 106 106 98.93 98.28 94.90 93.60 94.43 97.09 109.20 130.10 106.00 88.69 75.42 80.12 86.77 63.79]./1000;
price_temp=repmat(M_price,4,1);
price_temp1=reshape(price_temp,1,[]);
price_buy=price_temp1(1,41:64);
k=2; %k= 1 to 4
price_sell=price_buy*k;
price_DR(1:24)=0.2;
income_before=0;
for i=1:24;
income_before=income_before+P_buy_before(i)*(price_sell(i)-price_buy(i));
end
income_before;
%% optimization problem formulation using yalmip tools
horizon=24;
U_d=binvar(1,horizon);
U_c=binvar(1,horizon);
P_giveup=sdpvar(1,horizon);
P_buy_after=sdpvar(1,horizon);
P_discharge=sdpvar(1,horizon);
P_charge=sdpvar(1,horizon);
soc_bes=sdpvar(1,horizon+1);
P_reduce=sdpvar(1,horizon);
%equlity constraints
F=[];
C_bes=200;
dis_min=5;
dis_max=40;
ch_min=7;
ch_max=20;
for i=1:4
F=[F,P_buy_after(i)==P_buy_before(i),P_discharge(i)==0];
end
for i=5:24
F=[F,dis_min*U_d(1,i)<=P_discharge(1,i)<=dis_max*U_d(1,i)];
end
for i=1:horizon
F=[F,ch_min*U_c(1,i)<=P_charge(1,i)<=ch_max*U_c(1,i)];
F=[F,U_d(i)+U_c(i)==1];
end
for i=1:horizon
F=[F,P_reduce(i)==P_giveup(i)+P_discharge(i)-P_charge(i)];
F=[F,P_reduce(i)>=M_t(1,i)];
end
for i=1:24
F=[F,P_buy_after(i)==P_buy_before(i)-P_giveup(i)-P_discharge(i)+P_charge(i)];
end
%% BESS constraint
F=[F,soc_bes(1,1)==0.85];
for i=1:horizon
F=[F,soc_bes(1,i+1)==soc_bes(1,i)-1/4*(P_discharge(1,i)/(0.85*C_bes))+1/4*(P_charge(1,i)*0.85/C_bes)];
F=[F,0.2<=soc_bes(1,i+1)<=0.85];
end
% Objective=0;
% for i=1:24
% Objective=Objective-(1/4*(P_buy_after(i)+P_discharge(i))*price_sell(i));
% end
% for i=1:24
% Objective=Objective-1/4*(P_reduce(i)*0.25);
% end
% for i=1:24
% Objective=Objective+1/4*P_buy_after(i)*price_buy(i);
% end
ops=sdpsettings('solver','gurobi');
optimize(F);
% optimize(F,Objective,ops);
a=value(P_giveup)
b=value(P_buy_after)
value(P_discharge)
value(P_charge)
value(soc_bes)