Problem-Based Optimisation - "Linprog stopped because it exceeded its allocated memory"
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mirco Beckhuis
el 2 de Mayo de 2021
Comentada: Mirco Beckhuis
el 4 de Mayo de 2021
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
0 comentarios
Respuesta aceptada
Alan Weiss
el 3 de Mayo de 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)
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);
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]')
Alan Weiss
MATLAB mathematical toolbox documentation
2 comentarios
Derya
el 3 de Mayo de 2021
The behavior with linprog-dual-simplex is a bug. A workaround is to provide finite lower bounds to the variables. We're currently investigating to fix the bug.
Thank you for reporting this issue, Mirco. I'm sorry for the inconvenience.
Kind Regards,
Derya
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!