New constraint in an optimization problem NEED HELP

1 回表示 (過去 30 日間)
gjashta
gjashta 2023 年 3 月 9 日
編集済み: gjashta 2023 年 3 月 10 日
Hi,
I'm using the optimization model from Matlab which you can see in https://www.mathworks.com/videos/optimization-in-energy-management-systems-1561902499222.html and I'm interested to change the loadBalance constraint to a load shifting constraint shown in the image attached but I'm struggling to change it as the optimization model doesn't work.
The codes related to constraints are the following:
function [Pgrid,Pbatt,Ebatt] = battSolarOptimizeW(N,dt,Ppv,WIND,Pload,Einit,Cost,FinalWeight,batteryMinMax)
% Minimize the cost of power from the grid while meeting load with power
% from PV, wind, battery and grid
prob = optimproblem;
% 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);
% Minimize cost of electricity from the grid
prob.ObjectiveSense = 'minimize';
prob.Objective = dt*Cost'*PgridV - FinalWeight*EbattV(N);
% 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;
% Satisfy power load with power from PV, grid and battery
prob.Constraints.loadBalance = Ppv + WIND+PgridV + PbattV == Pload;
%prob.Constraints.loadBalance = Ppv + WIND+PgridV + PbattV == Pload
%if Ppv + WIND+PgridV + PbattV == 0.8*Pload
% Pload
%else
% Ppv+WIND=0.8*Pload;
% Solve the linear program
options = optimoptions(prob.optimoptions,'Display','none');
[values,~,exitflag] = solve(prob,'Options',options);
% Parse optmization results
if exitflag <= 0
Pgrid = zeros(N,1);
Pbatt = zeros(N,1);
Ebatt = zeros(N,1);
else
Pgrid = values.PgridV;
Pbatt = values.PbattV;
Ebatt = values.EbattV;
end
I appreaciate any help!

回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by