strtok function takes linear optimization into an infinite loop

58 次查看(过去 30 天)
I wrote a linear optimization algorithm to find the optimal dispatch of a battery system:
Xdam_d = optimvar('Xdam_d',T,N,'LowerBound',0,'UpperBound', Xbatt,'Type','continuous');
Xdam_c = optimvar('Xdam_c',T,N,'LowerBound',0,'UpperBound', Xbatt,'Type','continuous');
Xidm_d = optimvar('Xidm_d',T,N,'LowerBound',0,'UpperBound', Xbatt,'Type','continuous');
Xidm_c = optimvar('Xidm_c',T,N,'LowerBound',0,'UpperBound', Xbatt,'Type','continuous');
SOC = optimvar('SOC',T+1,N,'LowerBound',SOCbatt_min,'UpperBound',SOCbatt_max,'Type','continuous');
chargecons1 = Xdam_c + Xidm_c <= Xbatt*u_c;
dischargecons1 = Xdam_d + Xidm_d <= Xbatt*(1 - u_c);
Pch_eq = Pch == Xdam_c + Xidm_c;% - Xfrc_ind_a_up;
Pdis_eq = Pdis == Xdam_d + Xidm_d;% - Xfrc_ind_a_down;
for d = 1:N
% loop on quarters of hours (t)
for t = 1:T
% Define the Income (R-C) for the battery on the multi-markets
Idam(t,d) = pdam(t,d).*(Xdam_d(t,d) - Xdam_c(t,d))*0.25; %Day_Ahead market
Iidm(t,d) = pidm(t,d).*(Xidm_d(t,d) - Xidm_c(t,d))*0.25; %Intraday
end
maxProfit = sum(Idam,'all') + sum(Iidm,'all');
prob.Objective = maxProfit;
Then I call the constraints and the solver..
but the problem came when I added equation State of Charge, defined as a constraint and shown below :
soc_constraints(1,1) = SOC(1,1) == SOC_0;
soc_constraints(2:T+1,:) = SOC(2:T+1,:) == SOC(1:T,:) + (Pch(1:T,:)*etabatt_ch-Pdis(1:T,:)/etabatt_dis)*(100/4*Ebatt);
If I run the algorithm, it does not converge, or rather it enters a loop that takes it to MaxTime. If I pause, I can see that the solver stops on the strtok function and particularly at this point:
if nargin < 1 || nargin > 2
Whereas if I remove one of the two contributions Xdam or Xidm from the SOC function (especially at the discharge side) the solver finds optimal solution.
Or similarly if I remove the percentage factor (*100) it works, but obviously the SOC calculation is not correct.
Where could the problem be?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by