How to solve "Conversion to logical from optim.problemdef.OptimizationInequality is not possible." for logical statement for variable.
12 views (last 30 days)
I have tried to find the optimal location (D) to install the renewables on the contact wire of the railway in which the lowest line losses are produced and lowest power from the grid is required (Pgrid). The objective function is to minimize sum(Pgrid). The error occured while calculated the contact wire loss (function: CW_calculation_1) due to logical operations of variable D.
Contact wire losses are calculated according to train location (left or right of D, train travels from left to right in this example).
xa(i) is train location at time i (Nx1vector), N is the number of time step. Ptr and Pres are parameters (Nx1 vector).
I have read all questions and answers in this community but still could not solve this problem. Is there any way to solve this issue? Please kindly advise. Thanks.
% Main optimization
% Decision variables
Pgrid = optimvar('Pgrid',N);
D = optimvar('D','LowerBound',0,'UpperBound',Dts);
% Minimize Contact wire loss
prob.ObjectiveSense = 'minimize';
prob.Objective = sum(Pgrid*DeltaT)
% Satisfy power load with power from PV, grid and battery
prob.Constraints.loadBalance = Pres + Pgrid == Ptr+CW(Ptr,Pres,Itr,Ires,xa,Dts,D,N,r);
Function CW below:
if A>0 %case2.1
if D-xa(i)>=0 % this creates error.
%calculate losses while train is on the left-hand side of D
%%calculate losses while train is on the right-hand side of D
Below is the error I encountered:
Conversion to logical from optim.problemdef.OptimizationInequality is not possible.
Error in CW_calculation_1 (line 30)
Alan Weiss on 9 Mar 2022
You need to take care of logical constraints using a roundabout sort of modeling construct. The documentation is here: Integer and Logical Modeling
An example here: Optimal Dispatch of Power Generators: Problem-Based
MATLAB mathematical toolbox documentation