Optimization considering integral constraints (battery power system)

8 views (last 30 days)
Hello. I need to optimize one function in order to simulate a power system with a battery. The simplified version of the problem is:
  • t=[1:24] for the hours in a day,
  • L=SystemLoad(1:24) for the load in the system and
  • x=x1...x24 in which x is the battery power for each hour (in Watts)
I need to find in order to optimize my function cost, and they represent the power provided by the battery every hour in order to fulfill the load.
  • Objective function is f=(x*A) where A is the cost/watt at different hours (dot product).
  • Equality constraints are x*B=L where B are parameters which change depending on the hour (example: efficiencies).
The question for I which I am requesting your help is to know how to implement a constraint for the energy use every hour (watt-hour). Basically I would like a “cumulative integral” from x1 to x2, from x2 to x3, from x3 to x4 and so on, so I know how depleted is my battery (each cycle shall decrease my battery energy, until certain limit). Also I need to limit the derivative of the battery (watt/hour) so I can control the battery power ramp of the system under the specified levels.
What I want to especify as constraints is something as
  • InitialEnergy-Integral(x1-x2)>0,
  • InitialEnergy-Integral(x1-x3)>0,
  • InitialEnergy-Integral(x1-x4)>0 and so on
for the derivative it would look like:
  • d(x1-x2)/dt<1000,
  • d(x2-x3)/dt<1000,
  • d(x3-x4)/dt<1000 and so on.
I have thought about implementing these constraints with the type NONLCON option of the FMINCON but I do not know how to implement an "integral" and "derivative" constraints.
I have more equality and inequality constraints, but I have leaved them out to ease the explanation of my problem. Thanks!.

Accepted Answer

Hugo
Hugo on 28 Feb 2013
I figured out a way to solve the problem by numerical approximation using FMINCON and implementing the "integral" and "derivative" constraints with the NONLCON option.
The trick is to approximate the change in energy by adding or subtracting the area by using "cumtrapz" for each iteration (W-h), and "diff" for approximating the rate of change. Then it becomes easy to create the constraints:
function [c,ceq]=objectivestorage(x)
MaximumEnergy = 3;
MinimumEnergy = 0.5;
InitialEnergy=MaximumEnergy/2;
M=x(1:24); % Choosing just the variables of the battery
RemainingEnergy = InitialEnergy-cumtrapz(M); %%%<<<< energy remaining!!!
RateRamp=diff(M); %%%<<<< Watt/hour battery
c=[RemainingE-MaximumEnergy; %EnergyRemaining<MaximumEnergy
-RemainingE+MinimumEnergy; %EnergyRemaining>MinimumEnergy
M-3; %Power<MaximumPower
-M-3; %Power>MinimumPower
RateRamp-1000; %Rate<MaximumRate
-RateRamp-1000;]; %Rate<MinimumRate
ceq=[];
end
This has solved my problems of defining derivative and integral constraints for nonlinear optimization problems. The shorter the time frame the better the numerical approximation. I hope this helps someone!
  1 Comment
Sara
Sara on 3 Jul 2017
Hi Hugo, I am working on an optimal bidding strategy for battery systems, which means finding the optimal allocation of the battery capacity for supply or demand in the market. I am using fmincon too. I am wondering how should I define the state of charge constraint to make sure there is enough charge in a battery before each hourly discharging bidding. x(t) is the supply energy (discharge) and y(t) is the demand energy (charge). x1 = x(1:24); y1 = x(25:end); I defined the state of charge constraint as: x(1)<Initial charge+y(1), x(2)< Initial charge-x(1)+y(1)+y(2), x(3)<Initial charge-x(1)-x(2)+y(1)+y(2)+y(3), ... . I am not sure if it is the correct way of defining the state of charge constraint or not. Also, I need to define a constraint that battery cannot be in a charging and discharging mode at the same hour. I defined it as non-linear constraint (nonlcon) x*y=0: c=[]; ceq = [x(1)*x(25),x(2)*x(26),x(3)*x(27),x(4)*x(28),x(5)*x(29),x(6)*x(30),x(7)*x(31),x(8)*x(32),x(9)*x(33),x(10)*x(34),x(11)*x(35),x(12)*x(36),x(13)*x(37),x(14)*x(38),x(15)*x(39),x(16)*x(40),x(17)*x(41),x(18)*x(42),x(19)*x(43),x(20)*x(34),x(21)*x(35),x(22)*x(36),x(23)*x(37),x(24)*x(38)];
but after running the optimization I get value for both x(1:24) and y(x(25:end)) at the same time, which shows this constraint is ignored by the fmincon! Could you please guide me if you have any solution for these problems or advise how could you deal with these kind of constraints in your project? Thanks a lot!

Sign in to comment.

More Answers (1)

Alan Weiss
Alan Weiss on 26 Feb 2013
I believe that this is a linear programming problem. Use linprog, not fmincon, for its solution.
The formulation of the problem is fairly straightforward. Your vector x = x(1),...,x(24) is the set of control variables you are trying to optimize. You have
x(i) >= 0 % a lower bound constraint, lb = zeros(size(f))
A*x <= b
The matrices A and b in A*x <= b can incorporate all your other constraints. For example, if IE is the initial energy, then perhaps this represents your battery power ramp constraints are
A = [ 1 -1 0 0 ... 0;
1 -1 -1 0 ... 0;
1 -1 -1 -1 ... 0;
...
1 -1 -1 -1 ... -1];
I believe that this matrix A, along with a vector b whose value is IE for each component, takes the restriction into account.
You can write a similar extension of A and b to take the derivative into account. And the equality constraint x*B = L can be turned into an equality constraint matrix-vector combo, called Aeq and beq in the documentation.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Comments
Hugo
Hugo on 28 Feb 2013
Edited: Hugo on 28 Feb 2013
Hello Alan. Well I simplified the problem a lot! Sorry for that! I only mentioned the issues of the battery derivative and integrative constraints, in order to ease the problem formulation.
In reality I am trying to simulate a system which has other controllable energy elements, such as a transformer and a CHP, therefore the variables to optimize are:
  • x(1)...x(24) for the battery
  • x(25)...x(48) for the CHP and
  • x(49)...x(72) for the transformer
The combination of these variables makes my problem nonlinear, and multivariable, with a non convex solution space. But I have found a solution which I will share. Thanks for your input Alan!
li
li on 11 Mar 2014
Hi, Hugo, have you found a solution for this question? I am now studying the power system with batteries. And still impeded with charging/discharging behavior of batteries, can you share your outcome with me? Many thanks.

Sign in to comment.

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!