Fmincon - Out of memory Error

1 visualizzazione (ultimi 30 giorni)
Mathias Dirksmeier
Mathias Dirksmeier il 23 Lug 2018
Dear community,
We are trying to find an optimal solution to an arbitrage problem. That is, we know energy prices for over one year and a battery storage shall charge at low prices and discharge at high prices in order to maximize revenue. The only constraints being storage's capacity and max charge/discharge rates. Unfortunately, since charging and discharging has different efficiency losses this problem has nonlinear constraints. Using the fmincon, I get the following error:
Error using ldl
Out of memory. Type HELP MEMORY for your options.
Error in formAndFactorAugMatrix
Error in formAndFactorAugMatrix
Error in barrier
Error in fmincon (line 798)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in EnergyStorageDispatch_v1 (line 66)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
Here is my code:
% General Definitions
p = Data.RAW.Marginal_Prices;
Smax = 13.5;
Pmax = 5;
n = 0.92;
%%Wholesale Arbitrage
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; Pmax];
x0(1:length(p),1) = 1; % Starting solution
Aeq = []; % Linear Equality constraint: Aeq*x = beq
beq = [];
lb = []; % Lower and upper bounds: lb ? x ? ub
ub = [];
options = optimoptions('fmincon','Display','iter','Algorithm','interior-point');
nonlcon = @(x) capacity(x, n, Smax) ; % Nonlinear inequalities or equalities: c(x) ? 0 and ceq(x) = 0
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
function [c,ceq] = capacity(x,n,Smax)
E = sqrt(n)*x;
E(x<0) = (1/sqrt(n))*x(x<0);
S = cumsum([Smax/2; E]);
c1 = -S;
c2 = S - Smax;
c = [c1; c2];
ceq = [];
I know there is a more modern approach to this but I am really curious about where exactly the problem is with my code. As I am really new to optimization issues please be patient with me :)
Thank you very much, Mathias
  7 Commenti
Mathias Dirksmeier
Mathias Dirksmeier il 23 Lug 2018
Ok, and the ga() does not have issues in solving this?
I see three options here:
a) Define a smooth functional approximation (differentiable)
b) Apply ga() [How much would the solution suffer from this in terms of quality?]
c) Find a way to linearize as Alan Weiss recommended in that other post:
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 il 23 Lug 2018
Hi Matt,
I just tried to apply ga according to option b), see above. However, it seems that ga does only work with scalar inputs for objective functions. In this case, my objective function is a vector. Any idea how ga could still be valid for me and my problem?

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by