Clear Filters
Clear Filters

How to add minimum up time constraint for a home load into a MILP problem?

2 views (last 30 days)
I have written the code for the operation of the appliances for a minimum up time in a MILP problem.
The code I have written is based on the lines of the "optimal operation of thermal plants" tutorial video for MILP problem.Following is the link to it -
https://in.mathworks.com/videos/mixed-integer-linear-programming-in-matlab-91541.html
Following is my code -
if true
powerprob=optimproblem;
E=[3 2 3 5 2 3 ]; % Cost of electricity
P=[0.5 1 0.5]; % power rating of appliances
D=[2 2 3]; % Total duration oof operation
% For making the appliances operate within a fixed start and finish time
V=zeros(3,3);
TstartM=[2 3 1]; % Start time of each appliances
TfinishM=[5 5 4 ]; % Finish time
for jj=1:3
for kk=1:3 % total appliances
DurationM=[1 1 1];
if kk<TstartM(jj)
V(kk,jj)=0;
elseif kk>TfinishM(jj)
V(kk,jj)=0;
elseif kk>=TstartM(jj) && kk<=TfinishM(jj)
V(kk,jj)=DurationM(jj);
end
end
end
V
VV=cat(1,V,V) % Start and finish time window for appliances
Pgrid=optimvar('Pgrid',6,1,'LowerBound',0,'UpperBound',7); % Power Imported from the grid
A=optimvar('A',6,3,'Type','integer','LowerBound',0,'UpperBound',1); % ON/Off schedule of the appliances
HLD=((A.*VV)*P'); % Hourly Load
gridcost=sum((Pgrid).*E');
powerprob.Objective=gridcost;
% min up time for the appliances
powerprob.Constraints.D1=optimconstr(6,3);
for jj=1:3
for kk=1:6 % based on possible startups; no penalty at end for running over
MinUpTimeM=[2 1 1];
if kk>6-MinUpTimeM(jj)
sumidx=kk:6;
elseif kk<=6-MinUpTimeM(jj)
sumidx=kk:kk+MinUpTimeM(jj)-1;
end
powerprob.Constraints.D1(kk,jj)=...
A(kk,jj) - sum(A(sumidx,jj)/length(sumidx))<=0;
showconstr(powerprob.Constraints.D1) ;
end
end
powerprob.Constraints.C1=sum(A.*VV)==D; % For limiting the appliances operation for a particular number of hours
showconstr(powerprob.Constraints.C1(:,1:3))
powerprob.Constraints.C3=Pgrid==HLD;
% Options for the optimization algorithm, here we set the max time it can run for
options=optimoptions('intlinprog','Maxtime',10);
% Call the optimization solver to find the best solution
[sol,TotalCost,exitflag,output]=solve(powerprob,options);
sol
struct2table(sol)
A=sol.A
HLD=(sol.A)*P'
end
Although the code is generating a solution. But the solution is wrong as it is violating the appliances' duration constraint. For the first column of 'A' variable in the solution, the device is operating for 3 hours but its duration is only for 2 hours.
Any help would be very much appreciated. Thanks

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!