strtok function takes linear optimization into an infinite loop

조회 수: 1 (최근 30일)
Edoardo
Edoardo 2024년 11월 12일
댓글: Swastik Sarkar 2024년 11월 20일
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?
  댓글 수: 2
Matt J
Matt J 2024년 11월 13일
Can't run your code. The input data is not provided.
Swastik Sarkar
Swastik Sarkar 2024년 11월 20일
Could the entire code be attached or shared so that we can reproduce it ?

댓글을 달려면 로그인하십시오.

답변 (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