How can I implement an "if" in optimization problem?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Alan Weiss
le 19 Oct 2021
Yoou might be able to find some techniques in the new documentation topic Integer and Logical Modeling.
Alan Weiss
MATLAB mathematical toolbox documentation
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!