Fmincon - Out of memory Error

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 Comments

Matt J
Matt J on 23 Jul 2018
Edited: Matt J on 23 Jul 2018
To optimize responsiveness to your questions, you should Accept-click valid answers to your previous posts, or else reply to those responding to you why their answers are not what you're looking for.
Thanks for the hint! Done ;)
Matt J
Matt J on 23 Jul 2018
Edited: Matt J on 23 Jul 2018
If you attach "p", we would be able to run your code and more easily track the cause of the error.
Aside from the error, however, your nonlinear constraint function is non-differentiable at x(i)=0. This violates assumptions of fmincon. You should probably use ga() instead.
You will find p attached. Thanks for the hint.
Is it discontinuos? It should be sqrt(n) for all x => 0 and (1/sqrt(n)) for all x < 0. I thought that's what makes it nonlinear?
As you can now see, I have 8760 unknown variables... Do you see any promising solution?
Matt J
Matt J on 23 Jul 2018
Edited: Matt J on 23 Jul 2018
It is not discontinuous, but it is non-differentiable. The left derivative of E with respect to x(i) at x(i)=0 is 1/sqrt(n) and the right derivative is sqrt(n).
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
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?

Sign in to comment.

Answers (0)

Categories

Asked:

on 23 Jul 2018

Community Treasure Hunt

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

Start Hunting!