MATLAB: Optimization result changes as soon as parts of the solution are inserted into the optimization

changing resultoptimization

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
%

Best Answer

Hey guys,
Thanks again for the help. I talked with my prof about this topic and his answer was, that it is not of bigger importance if the trajectory stays the same as long as all different solutions have an optimal objective function value. Therefore, no changes in the problem formulation/objective function are needed.
Thanks again!
Best Uwe