Linear Programming - Optimization Over One Year

Dear Community,
I am totally stuck on this problem and am really looking forward to your ideas:
I try to find a solution to a linear optimization problem. I want to maximize the total arbitrage value for one year. In each hour arbitrage can be defined as the product of price (Pt) and amount of energy (Et). The amount is positive when energy is bought and negative when energy is sold.
The optimization function can be defined as:
max (Pt*Et) summed over one year (t=1 to t=8670)
There are two constraints to this function:
0 <= St <= Smax (Smax = Energy Capacity, constant)
-Pmax <= Et <= Pmax (Pmax = Power Limit, constant)
The hourly state of charge (St) is defined as follows:
St = St-1 + Et * n , if Et => 0 (with St-1 being the state of charge from the previous hour)
St = St-1 + Et * m , if Et < 0
I want the program to return the amount of energy stored or discharged for each hour of the year (8670 hours) so that the maximum arbitrage value for that year was reached. Means, it shall not optimize for each day but rather optimize for one whole year. If this problem turns out to be too heavy computational wise, one could shrink the time frame to two weeks.
Having consulted this help page ( Link ) I could not come up with a solution to optimize for a set of interdependent time steps. Can you?
Thanks so much in advance, Mathias

 採用された回答

Alan Weiss
Alan Weiss 2018 年 7 月 18 日

2 投票

I think that you might find some enlightenment in these examples:
If you don't have a current version of the toolbox (R2017b or later) then use the solver-based examples linked from each of these problem-based examples.
Alan Weiss
MATLAB mathematical toolbox documentation

その他の回答 (1 件)

Mathias Dirksmeier
Mathias Dirksmeier 2018 年 7 月 18 日

0 投票

Hi Alan,
thanks for your reply. I also made a first, own attempt. Would you give me some feedback on this? I actually struggle a lot with the nonlinear constraint as I need to define the hourly state of charge, which is itself dependent on the energy sold or bought the period before.
fun = @(x)sum(x.*p);
a1(1:length(p)) = 1;
a2(1:length(p)) = -1;
A = [a1; a2]; % Linear inequality constraint: A*x ≤ b.
b = Pmax;
x0(1:length(p)) = 0; % Starting solution
Aeq = []; % Linear Equality constraint: Aeq*x = beq
beq = [];
lb = []; % Lower and upper bounds: lb ≤ x ≤ ub
ub = [];
nonlcon = @capacity; % Nonlinear inequalities or equalities: c(x) ≤ 0 and ceq(x) = 0
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon);
And the nonlinear constraint function:
function [c,ceq] = capacity(x)
S(0)= Smax/2;
for i = 1:length(x)
if x >= 0
c = Smax - S(i-1) - x * n;
S(i)=S(i-1) + x * n;
else
c = Smax - S(i-1) - x * m;
S(i)=S(i-1) + x * m;
end
end
ceq = [];
I am really curious for your take on this!

9 件のコメント

Alan Weiss
Alan Weiss 2018 年 7 月 18 日
Please look at the links I gave. This is not a nonlinear constraint, and you should not be using fmincon.
Alan Weiss
MATLAB mathematical toolbox documentation
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 7 月 19 日
Hi,
I am of course looking at the links. Could you elaborate on why not to use fmincon? It was recommended from another party. And why is is not nonlinear? Whether it's m or n (efficiency) is dependent on the sign of x.
Sorry for bothering you so much, but I am still very confused by the whole amount of information I am filtering through at the moment.
Alan Weiss
Alan Weiss 2018 年 7 月 19 日
I think that you should make an auxiliary binary variable yt that indicates whether Et is negative. I assume that there are positive constants m and M such that, for the times when Et is negative,
-M <= Et <= -m
In this case, you can construct yt automatically as done in several of the examples I linked, and then I think that you can make your objective function linear by using yt as part of the cost. If I am wrong and the objective function has to be quadratic, then I believe that you can use the technique in this example to model your problem.
Alan Weiss
MATLAB mathematical toolbox documentation
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 7 月 23 日
Hi Alan, I am trying this more modern approach now. Do you have an idea on how to include such a binary variable into the cost function?
Alan Weiss
Alan Weiss 2018 年 7 月 23 日
It is straightforward to include the binary variable into the cost function. Just take your expressions:
St = St-1 + Et * n , if Et => 0
St = St-1 + Et * m , if Et < 0
and write them in terms of yt, where yt = 1 indicates Et < 0:
St = St-1 + Et*n + yt*Et*(m - n)
This may not be the only way to incorporate the variable, but it is a correct way.
Alan Weiss
MATLAB mathematical toolbox documentation
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 7 月 23 日
編集済み: Mathias Dirksmeier 2018 年 7 月 23 日
Hi Alan,
I would disagree here. Since yt is binary but dependent on Et (with Et being decision variable) this would make the problem 'mixed integer', wouldn't it?
Alan Weiss
Alan Weiss 2018 年 7 月 23 日
It would. Is that a problem?
Alan Weiss
MATLAB mathematical toolbox documentation
Mathias Dirksmeier
Mathias Dirksmeier 2018 年 7 月 24 日
Well, wouldn't that make the problem even harder to solve? Is a MIP easier to solve than a Nonlinear Program?
Alan Weiss
Alan Weiss 2018 年 7 月 24 日
It depends on the MILP and the nonlinear program. There are a lot of tricks that can be used to solve an MILP because it is linear in the variables. Nonlinear problems are quite hard in general. But again, it depends on the problems.
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by