MATLAB Answers

Problem-Based Optimisation - "Linprog stopped because it exceeded its allocated memory"

2 views (last 30 days)
I am trying to solve a simple linear optimisation problem using the "Problem-Based Optimisation" approach. To solve the optimisation problem I use "linprog" and the "dual-simplex-algorithm".
The number of variables and constraints depends on the number of time steps T. The variable T in turn depends on the considered time period t and the duration of a single time step dt. I can solve the problem if I keep the number of time steps small enough or if I use the "Solver-Based Optimisation" approach. However, I must be able to solve the problem for a period of 24h with time steps of 15/60. This results in a number of T = 97 time steps. With this number of time steps, I recieive the following error message: "Linprog stopped because it exceeded its allocated memory". I don't understand why the "Problem-Based Optimisation" approach run out of memory for such a small problem.
Here is my code:
dt = 15/60;
t = [0:dt:24]; %Charging time 24h
T = length(t)
E_Batt = 22;
E_inital = 9;
E_min = 12;
P_max = 10;
P_min = 0;
E_1 = optimvar('E_1',T,"UpperBound",E_Batt);
P_1 = optimvar('P_1',T,"LowerBound",P_min,"UpperBound",P_max);
Charging_1 = optimproblem();
Charging_1.ObjectiveSense = 'maximize';
RowConstraints = optimconstr(T);
for n = 1:T
if n~=1
RowConstraints(n) = E_1(n-1) - E_1(n) + P_1(n)*dt == 0;
else
RowConstraints(n) = E_1(n) == E_inital;
end
end
Charging_1.Constraints.c = RowConstraints;
% show(Charging_1.Constraints.c);
objfun = sum(E_1);
Charging_1.Objective = objfun;
% show(Charging_1.Objective)
Schedule = solve(Charging_1);
Schedule.E_1
Schedule.P_1
figure(1)
plot(t,Schedule.E_1)
title('Ladezustand')
xlabel('Ladezeit [h]')
ylabel('SoC [%]')
figure(2)
bar(t,Schedule.P_1)
title('Ladeleistung')
xlabel('Ladezeit [h]')
ylabel('Leistung [kW]')
Is there any issue with my code?
Thank you

Accepted Answer

Alan Weiss
Alan Weiss on 3 May 2021
Sorry, I do not know why the default algorithm gives this error. The 'interior-point' algorithm solves it easily.
dt = 15/60;
t = [0:dt:24]; %Charging time 24h
T = length(t)
T = 97
E_Batt = 22;
E_inital = 9;
E_min = 12;
P_max = 10;
P_min = 0;
E_1 = optimvar('E_1',T,"UpperBound",E_Batt);
P_1 = optimvar('P_1',T,"LowerBound",P_min,"UpperBound",P_max);
Charging_1 = optimproblem();
Charging_1.ObjectiveSense = 'maximize';
RowConstraints = optimconstr(T);
% for n = 1:T
% if n~=1
% RowConstraints(n) = E_1(n-1) - E_1(n) + P_1(n)*dt == 0;
% else
% RowConstraints(n) = E_1(n) == E_inital;
% end
% end
n2 = 2:T;
RowConstraints(1) = E_1(1) == E_inital;
RowConstraints(n2) = E_1(n2) == E_1(n2-1) + P_1(n2)*dt;
Charging_1.Constraints.c = RowConstraints;
% show(Charging_1.Constraints.c);
options = optimoptions("linprog","Algorithm","interior-point");
objfun = sum(E_1);
Charging_1.Objective = objfun;
% show(Charging_1.Objective)
Schedule = solve(Charging_1,"Options",options);
Solving problem using linprog. Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the selected value of the function tolerance, and constraints are satisfied to within the selected value of the constraint tolerance.
Schedule.E_1
ans = 97×1
9.0000 11.5000 14.0000 16.5000 19.0000 21.5000 22.0000 22.0000 22.0000 22.0000
Schedule.P_1
ans = 97×1
0 10.0000 10.0000 10.0000 10.0000 10.0000 2.0000 0.0000 0.0000 0.0000
figure(1)
plot(t,Schedule.E_1)
title('Ladezustand')
xlabel('Ladezeit [h]')
ylabel('SoC [%]')
figure(2)
bar(t,Schedule.P_1)
title('Ladeleistung')
xlabel('Ladezeit [h]')
ylabel('Leistung [kW]')
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!