How can I implement an "if" in optimization problem?
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Renewable Energy and Sustainability en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!