I'm writing my master thesis about the economics of energy storages. Now I have the Problem, that for the two solver (cplex & gurobi) which I was told to use I get the error that they are not applicable for my problem of calculating the levelized cost of energy (objective possibility #3 at the end of the code), costs divided by the energy leaving the storage). But on the other hand both solvers can optimize the two input terms 'investment cost' and 'energy' individually (objective possibilities 1&2). I simplified the code so it is easier to read and hope one of you has an idea what to do as I am pretty inexperienced using matlab.
Thanks in advance for anybody who can help me with this.
--------------------------------------------------
clear
clc
ops=sdpsettings('solver','cplex');
T = 10; % # of periods
E_ex = randn(T,1)*100; % create random demand function (E_ex > 0: store, E_ex < 0: discharge).
eta = 0.9; % roundtrip efficiency
eta_in = eta^0.5; % efficiency of storing process (square root of roundtrip efficiency)
eta_out = eta^0.5; % efficiency of discharging process (square root of roundtrip efficiency)
sc_Pin = 10; % specific costs of charging-power ($/kW)
sc_Pout = 10; % specific costs of discharging-power ($/kW)
sc_E = 11; % specific costs of storage capacity ($/kWh)
E = sdpvar(T,1); % stored energy of each time step t. E(1,1) = initial stored Energy E_0
E_ex_rest = sdpvar(T,1); % energy that the storage can't store / demand the storage can't meet
E_out = sdpvar(T,1); % discharged energy in step t
E_in = sdpvar(T,1); % stored energy in step t
E_ex_eff_in = sdpvar(T,1); % the energy that the storage is absorbing from the grid.
E_ex_eff_out = sdpvar(T,1); % the energy that the storage is emitting to the grid.
CE_out_ex = sdpvar(1,1); %Sum of the emitted energy between t and T to calculate LCOE (Levelized Cost of Energy)
P_in = sdpvar(1,1); %charging-power
P_out = sdpvar(1,1); %discharging-power
E_max = sdpvar(1,1); %storage capacity
E_min = 0; %minimal storage level
C_inv = sdpvar(1,1); %investment costs
LCOE = sdpvar(1,1); %levelized cost of energy
t = 1;
constraints = [];
%Definittion of initial values
E(1,1) = 0;
E_in(1,1)=0;
E_out(1,1)=0;
E_ex_eff_out(1,1) %set initial value one to enable the emitted energy of the other time steps to become zero (otherwise maybe error due to LCOE = C_inv / sum(E_ex_eff_out))
for t = 2:T
% No demand from grid
if E_ex(t,1) == 0
E_ex_eff_in(t,1) = 0;
E_ex_eff_out(t,1) = 0;
E(t,1) = E(t-1,1);
E_out(t,1) = 0;
E_in(t,1) = 0;
E_ex_rest(t,1) = 0;
% grid offers energy -> store
elseif E_ex(t,1) > 0
E_ex_eff_in(t,1) = E_ex(t,1); %as the storage should be able to store all the energy offered, the absorbed energy is equal to the offered
E_in(t,1) = E_ex_eff_in(t,1) * eta_in; %Energy "arriving" in the storage
E(t,1) = E(t-1,1) + E_in(t,1); %New energy in the storage
E_ex_rest(t,1) = E_ex(t,1) - E_ex_eff_in(t,1); %residual energy that the storage can't store (in this case of full coverage = 0)
% demand for energy from grid -> discharge
else
E_ex_eff_out(t,1) = min([abs(E_ex(t,1)),P_out,(E(t-1,1)-E_min)*eta_out]); %the demand which the storage can meet can be defined by three possible 'bottlenecks': the external demand, the discharging power or the energy in the storage (technical efficiency is considered).
E_out(t,1) = E_ex_eff_out(t,1) / eta_out; % due to the efficiency the discharged energy is higher than the emitted
E(t,1) = E(t,1) - E_out(t,1); %new energy in the storage
E_ex_rest(t,1) = E_ex(t,1) + E_ex_eff_out(t,1); %energy demand that the storage can't meet
end
end
E_out(isnan(double(E_out))==1)=0;
E_ex_eff_out(isnan(double(E_ex_eff_out))==1)=0;
E_max = max(E); %installed capacity should be high enough to store all the offered energy
P_in = max(E_ex_eff_in); %the installed charging power should be high enough to store all the offered energy
CE_out_ex = sum(E_ex_eff_out); %sum of the emitted energy
C_inv = sc_Pin * P_in + sc_Pout * P_out + sc_E * E_max; %investment costs
LCOE = C_inv / CE_out_ex; %levelized cost of energy
constraints = [constraints, E(:)>=0];
constraints = [constraints, P_in>=0];
constraints = [constraints, P_out>=0];
constraint = [constraints, E_ex_eff_out(:)>=0];
constraints = [constraints, E_ex_rest(:)<=0]; % All energy must be stored
%objective = C_inv; %#1
%objective = -CE_out_ex; %#2
objective = LCOE; %#3
solve = optimize(constraints, objective,ops)