Optimization result changes as soon as parts of the solution are inserted into the optimization
Ältere Kommentare anzeigen
Hi Matlab-Team,
I am currently working on an optimization of a PV-battery system. The result of the optimization is a 24hr dispatch strategy for the battery. Input of the optimization are load and pv profiles as well as the system characteristics.
I want to simulate the operation of the program and, therefore, rerun the optimization every hour to handle deviations between forecast and occured data. To build the code without mistakes, I started with the easiest case, where the forecast data equal the occured data. The operation schedule of the battery will be an input of the repeating optimization so that the optimization will consider the charge/discharge made by the battery during the lapsed time.
Here starts the problem: Because there is no deviation between forecast and actual data (because they are equal in this case), the whole input doesn't change. The only thing which changes is the additional dispatch strategy of the battery, which equals the optimization results of the previous optimization runs.
When I am thinking logically, the result of the optimizatin should be equal through every time step bc the input is not changing. But in my case it is.
I added the code and a picture (y-axis = State of charge battery, x-axis = time steps) of the result to show the problem.
function [solution] = demand_limit_optimization_with_thresholdSOC...
(load_profile, pv_generation, C_bat, SOC_0, P_batMin, P_batMax, SOC_min, SOC_max, ...
eta_bat, threshold, hour, SOC_trajectory_day, dischargeLimitation, chargeLimitation)
%%Optimization for demand limit minimization
n = length(pv_generation);
prob = optimproblem('ObjectiveSense','minimize');
%Define variables, length of array (n) and upper/lower bounds
P_system = optimvar('P_system', n); %P_PV + P_bat
P_bat = optimvar('P_bat',n,'LowerBound',P_batMin,'UpperBound', P_batMax); %Max and Min power of the battery
SOC = optimvar('SOC', n,'LowerBound',SOC_min,'UpperBound',SOC_max); %SOC level
P_PV = optimvar('P_PV', n); %Forecasted PV generation
P_dmd = optimvar('P_dmd', n); %Forecasted load
threshold = optimvar('threshold', n, 'UpperBound', threshold); %added load threshold which cant be crossed
%%Define objective function
f = 0;
for t=1:n
if (pv_generation(t) < load_profile(t)) && (load_profile(t) >= 0)
f = f + (P_dmd(t) - P_system(t)); %P_dmd - (P_PV - P_PVcharge + discharge)
else
f = 0;
end
end
prob.Objective = f;
%%Define constraints
P_system_calculate = optimconstr(n,1); %Constraint to calculate the Power of the PV + Battery system
SOC_level = optimconstr(n,1); % Constraint to calculate the SOC level
initialCharge = optimconstr(n,1); %Constraint to define the inital SOC level
threshold_limitation = optimconstr(n,1);
PV_feed = optimconstr(n,1); %Constraint to implement input PV
load_profile_feed = optimconstr(n,1); %Constraint to implement input load
pvDischarge_limitation = optimconstr(n,1); %Constraint to battery discharge into grid
pvCharge_limitation = optimconstr(n,1);%Constraint to battery charge from grid
SOC_trajectory = optimconstr(n,1);%Constraint to assure, the optimization includes already made steps
%Time depending constraints (which need to be calculated in every time
%step)
for t=1:n
%1: Calculating the energy which flows from/into the PV-battery system
%P_system(t) = P_PV(t) + P_bat(t)
P_system_calculate(t) = P_PV(t) + P_bat(t) == P_system(t);
%2: Calculation of the time depending charging level SOC
if t>1
SOC_level(t) = SOC(t) == SOC(t-1) - ((P_bat(t) / 4) * eta_bat) / (C_bat / 4); %Devided by 4 bc 15 minutes
else
initialCharge = SOC(1) == SOC_0; %Initial charge level of the batter: SOC(1) = SOC_0;
end
%Threshold limitation
threshold_limitation(t) = threshold(t) >= P_dmd(t) - P_system(t);
%3&4: Setting the input data of the generation and the load profiles
PV_feed(t) = P_PV(t) == pv_generation(t);
load_profile_feed(t) = P_dmd(t) == load_profile(t);
%Constraint to forbid feed in charge
pvDischarge_limitation(t) = P_bat(t) <= P_dmd(t) - P_PV(t);
pvCharge_limitation(t) = - P_bat(t) <= P_PV(t);
end
for i=1:hour
SOC_trajectory((i-1)*4 + 1) = SOC((i-1)*4 + 1) == SOC_trajectory_day((i-1)*4 + 1);
SOC_trajectory((i-1)*4 + 2) = SOC((i-1)*4 + 2) == SOC_trajectory_day((i-1)*4 + 2);
SOC_trajectory((i-1)*4 + 3) = SOC((i-1)*4 + 3) == SOC_trajectory_day((i-1)*4 + 3);
SOC_trajectory((i-1)*4 + 4) = SOC((i-1)*4 + 4) == SOC_trajectory_day((i-1)*4 + 4);
end
%Add constraints to problem
prob.Constraints.P_system_calculate = P_system_calculate;
prob.Constraints.SOC_level = SOC_level;
prob.Constraints.PV_feed = PV_feed;
prob.Constraints.load_profile_feed = load_profile_feed;
prob.Constraints.initialCharge = initialCharge;
prob.Constraints.threshold_limitation = threshold_limitation;
prob.Constraints.SOC_trajectory = SOC_trajectory;
if dischargeLimitation
prob.Constraints.pvDischarge_limitation = pvDischarge_limitation;
end
if chargeLimitation
prob.Constraints.pvCharge_limitation = pvCharge_limitation;
end
%%solve optimization problem
solution = solve(prob);
%showproblem(prob) %See full optimization problem with all constraints and
%boundaries

%
3 Kommentare
rerun the optimization every hour to handle deviations between forecast and occured data.
If you are re-running the optimization, shouldn't you be calling solve() within some kind of loop? That doesn't seem to be the case in your code.
Regardless, it doesn't appear that it is a Matlab issue, but rather an issue with the problem data that you have provided to Matlab. You question why you are getting a particular solution, but it is the problem data that you have provided which determines that.
Nergiz Soyak
am 10 Mär. 2020
Bu kodun tamamını yollayabilirmisiniz çalışır halini
Akzeptierte Antwort
Weitere Antworten (2)
Alan Weiss
am 9 Jul. 2018
1 Stimme
It seems to me that your objective function is a sum of terms, (P_dmd(t) - P_system(t)), and these terms can be negative. In other words, your objective function might well not be minimized when all the terms are equal.
Generally, when you want to minimize deviations, you take the minimum sum of squares, not the minimum sum. Or you could take the minimum sum of absolute values of the terms.
Alan Weiss
MATLAB mathematical toolbox documentation
4 Kommentare
Uwe
am 9 Jul. 2018
It should be easy to convert what you've done to a form appropriate for lsqlin(). Just doing
S=prob2struct(prob)
will give you all the constraints in the requisite matrix form.
Uwe
am 9 Jul. 2018
Nergiz Soyak
am 10 Mär. 2020
ıt runs the full code.can you send it bank very urgent needed
Matt J
am 9 Jul. 2018
0 Stimmen
I think an implementation of a penality value could be the solution.
Or additional constraints... The constraints must be under-specified in some way, if they don't define a unique global minimum.
Kategorien
Mehr zu Linear Programming and Mixed-Integer Linear Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
