MATLAB Answers

Energy storage optimisation problem - separate charge and discharge constraint

63 views (last 30 days)
James Cresswell
James Cresswell on 10 Aug 2020
Edited: NN on 12 Sep 2020
Hi all!
I am currently working on an optimization problem to maximize the revenue from a combined wind turbine and energy storage system. With the code below, the system charges and discharges simultaneously at certain times. I am able to change the charge and discharge variables to a single variable with the lowerbound as a negative and positive number corresponding to discharging and charging, respectively. But in doing this, I cannot accurately apply the charge and discharge efficiencies of the storage device.
prob = optimproblem;
% Decision variables
% Energy storage system decision variables
ESS_ch = optimvar('ESS_ch',T,'LowerBound',0,'UpperBound',ESS_Pmax);
ESS_disch = optimvar('ESS_disch',T,'LowerBound',0,'UpperBound',ESS_Pmax);
ESS_SOC = optimvar('ESS_SOC',T,'LowerBound',0,'UpperBound',ESS_Cmax);
% Output power to the grid variables
Grid_E = optimvar('Grid_E',T,'LowerBound',0);
% Energy storage operational constraints
prob.Constraints.energyStorage = optimconstr(T);
prob.Constraints.energyStorage(1) = ESS_SOC(1) == 10;
prob.Constraints.energyStorage(2:T) = ESS_SOC(2:T) == ESS_SOC(1:T-1)*(1-d) - ESS_disch(1:T-1)/eff + ESS_ch(1:T-1)*eff;
% Energy balance constraint (WT_E = wind turbine power output as vector of
% length T)
prob.Constraints.EnergyBalance = Grid_E == WT_E + ESS_disch - ESS_ch;
prob.ObjectiveSense = 'maximize';
prob.Objective = sum(Grid_E.*Price);
I have also attempted to apply a constraint that dictates the charge power multilied by the discharge power of the storage device is equal to zero at any single time step, see below.
prob.Constraints.chargeonoff = optimconstr(T);
for i = 1:T
prob.Constraints.chargeonoff(i) = ESS_disch(i)*ESS_ch(i) == 0;
However, when I add this the following error occurs.
Error using optim.problemdef.OptimizationProblem/solve
SOLVE requires a non-empty initial point structure to solve a nonlinear problem.
Any assistance or insight on how to force the program to either charge or discharge at each time step would be greatly appreciated.


Shehbaz Aslam
Shehbaz Aslam on 15 Aug 2020
Hope you are fine I need help on optimization toolbox.
James Cresswell
James Cresswell on 23 Aug 2020
Hi Shehbaz,
I am not especially experienced with the optimization toolbox and still figuring things out for myself, so unfortunately I don't think I will be able to help.
NN on 12 Sep 2020
Hi James,
I am working on microgrid optimization with solar and energy storage.I am also checking the Matlab example file Microgrid EMS optimization as a reference
There are some queries which I didn't understand. I request you all to help me to understand the code and then only I will be able to do my model. These are a few queries which I like to ask.
In the Matlab example, they load a file PvLoadPrice.I understand the load details are for variable load given in the system.PV has clear and cloudy data. Can I know how do we use such data?in which format? From which website we download it for research purposes?Also, how do we separate such data against each parameter? How do I forecast those data, say for the price how do I compare price details before and after a load variation(i have load fluctuation event in my model ) ? should I do forecasting of the price? I want to minimize the price of grid net exchange.plz advice. Can I have any resources to understand the code written in this example file?
The energy storage charges and discharges as per the power availability in the grid. So how can I model the optimization problem? and what should be the constraints? I have already modeled a microgrid with charging and discharging energy storage mechanism as per the load availability. So how can I link the model with the optimization code?
I request James, ALi and Alan Weiss to look into thsi matter and help .
Thanks in advance.

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 12 Aug 2020
The error message is spot on: when you multiply variables, the problem becomes nonlinear. However, I am sure that you would rather keep the problem linear if you can.
Choose a value M that upper bounds a nonnegative decision variable x. I mean x is ESS_disch or ESS_ch. Create a binary variable z_x that will indicate when x is positive. Set a linear constraint so that z tracks whether x is positive or not.
x <= M*z_x; % if x is positive, z_x has to be positive
Include z in the objective function, so the objective is minimized when z_x = 0.
Now to make the constraint that x and y cannot both be positive, create the linear constraint
z_x + z_y <= 1;
I may have some detail wrong, but I think that you see the idea. You are creating extra integer variables and linear constraints, and turning the problem from a linear programming problem to a mixed-integer linear programming problem. That keeps the problem out of the general nonlinear framework, which is a good thing.
Alan Weiss
MATLAB mathematical toolbox documentation


Show 4 older comments
Ali Almarzooqi
Ali Almarzooqi on 23 Aug 2020
Dear James,
I am working on a similar optimization problem except that my renewable source is Solar. I wrote my code in a different way, but it’s still not working correctly.
I would like to use your code if you don’t mind, and can I know what “d” represent in the SOC constraint?
Best regards,
James Cresswell
James Cresswell on 23 Aug 2020
Hi Ali,
I do not mind, I got a lot of inspiration from the matlab community example below anyway. It uses solar PV input so it might be quite applicable for you. In the example however, it assumes an ideal systme by representing charge/discharge as a single variable with positive and negative upper and lower bounds, respectively. Which doesn't allow for applying the charge/discharge efficiency.
"d" is a constant in my code for the standing losses (self-discharge) of the energy storage. Typically, this is <=5% per month for Li batteries, and then scale that down to what that is per hour or half-hour period of your system.
Ali Almarzooqi
Ali Almarzooqi on 24 Aug 2020
Hi James,
Thank you a lot for your clarification and support!! Appreciated.
Best regards,

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!