How can I implement an "if" in optimization problem?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Danny
el 19 de Oct. de 2021
In the example https://www.mathworks.com/matlabcentral/fileexchange/73139-microgrid-energy-management-system-ems-using-optimization?s_tid=srchtitle energy management optimization has been done in presence of an energy storage system. The optimproblem has been set as follow:
%% Define Decision variables
PgridV = optimvar('PgridV',N);
PbattV = optimvar('PbattV',N,'LowerBound',batteryMinMax.Pmin,'UpperBound',batteryMinMax.Pmax);
EbattV = optimvar('EbattV',N,'LowerBound',batteryMinMax.Emin,'UpperBound',batteryMinMax.Emax);
%% Objective Function
% Minimize cost of electricity from the grid
prob.ObjectiveSense = 'minimize';
% prob.Objective = dt*C'*PgridV - FinalWeight*EbattV(N);
prob.Objective = dt*C'*PgridV - FinalWeight*EbattV(N);
%% Constraints
% Power input/output to battery
prob.Constraints.energyBalance = optimconstr(N);
prob.Constraints.energyBalance(1) = EbattV(1) == Einit;
prob.Constraints.energyBalance(2:N) = EbattV(2:N) == EbattV(1:N-1) - PbattV(1:N-1)*dt;
Last line describes energy storage behaviour, without considering the efficiency. Setting eta_c and eta_d as charge and discharge efficiency rispectively, how can I implement an "if" problem in such a constraint? I mean something like:
if PbattV>0 prob.Constraints.energyBalance(2:N) = EbattV(2:N) == EbattV(1:N-1) - PbattV(1:N-1)*dt/eta_d;
if PbattV<0 prob.Constraints.energyBalance(2:N) = EbattV(2:N) == EbattV(1:N-1) - PbattV(1:N-1)*dt*eta_c;
I don't manage to figure it out because PbattV is an optimvar.
Please, do you have any advice?
0 comentarios
Respuesta aceptada
Alan Weiss
el 19 de Oct. de 2021
Yoou might be able to find some techniques in the new documentation topic Integer and Logical Modeling.
Alan Weiss
MATLAB mathematical toolbox documentation
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Programming and Mixed-Integer Linear Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!