Dear Johan,
I am trying to solve an optimisation problem where I want to find the price (f) that will maximise revenues from demmand (Di). I have a piecewise function of the price based on demmand. I did the formulation using implies, the problem I have is that when I want to maximize price*demand this does not seem to be working. It works when I just maximise f but this is not my calculation of my revenues though. I have tried to use FMINCON but it does not work either, unless I remove the implies and just substitute with the nonlinear equivalent equation.
Any help with this error would be highly appreciated.
Here is my code:
%DATA
y1=[28 23.5847];
x1=[0.1721 0.24];
m1 = (y1(1)-y1(2))/(x1(1)-x1(2));
y2=[23.5847 11.1145];
x2=[0.24 0.28];
m2 = (y2(1)-y2(2))/(x2(1)-x2(2));
y3=[11.1145 10];
x3=[0.28 0.3961];
m3 = (y3(1)-y3(2))/(x3(1)-x3(2));
f = sdpvar(1,24);
Di = sdpvar(1,24);
%CONSTRAINTS
Model = [];
%Model = [ Di(1)+Di(2)+Di(3)+Di(4)==0.5, Di(23)+Di(24)==0.5 ]
for t=1:24
d = binvar(3,1);
Model = [Model,
sum(d) == 1,
implies(d(1), [ 0.1721<= Di <= 0.24, f == m1*(Di-x1(1))+y1(1)]);
implies(d(2), [ 0.24 <= Di <= 0.28, f == m2*(Di-x2(1))+y2(1)]);
implies(d(3), [ 0.28 <= Di <= 0.3961, f == m3*(Di-x3(1))+y3(1)])];
end
Model = [Model, Di(3)+Di(4)+Di(5)==0.9 ]
Objective = sum(f.*Di,2)
options = sdpsettings('solver','gurobi');
sol = optimize(Model,-Objective,options);
% Analyze error flags
if sol.problem == 0
% Extract and display value
solution = value(Di)
solution2 = value(f)
else
display('Hmm, something went wrong!');
sol.info yalmiperror(sol.problem)
end
NOW CODE WITH FMINCON
%DATA INPUTS FOR MODEL
T=24; %work timeframe for EV charging station(think if it is a parking lot or charging station only, residential charging?)
%IMPORT DATA AND CREATE PARAMETERS
%param=[9.76584915402396,27.9904155442713,0.252459657607282,-39.8453332837601];
%DEFINE VARIABLES
M = sdpvar(1,T);
%Di = sdpvar(1,T);
Di = (70368744177664.*log(-(562949953421312.*M - 15757203126890695)./(562949953421312.*M - 5497684326377347)))./(2803866064518675*log(10)) + 4547908879704953/18014398509481984
Constraints = [10<=M(:)<=28, Di(2)+Di(3)+Di(4)==0.5];
Objective = sum(Di.*M,2);
options = sdpsettings('solver','fmincon');
sol = optimize(Constraints);
% Analyze error flags
if sol.problem == 0
% Extract and display value
solution = value(Di)
solution2 = value(M)
solution3 = value(Objective)
else
display('Hmm, something went wrong!');
sol.info yalmiperror(sol.problem)
end