Hi !
I’m looking for another possibility to implement my elseif loop for my linear program.
The goal is to implement the following:
if q_out >= 9
eff == 0.75
elseif 7 <= q_out < 9
eff == 1
else
eff == 0.5
end
I have already implemented these lines of code (see an extract below).
set_optimizer_attribute(model, "NonConvex",2)
M = 10^(10) # parameter to select my binary variable
# definition of the variables
@variable(model, 0 <= q_out <= 15)
@variable(model, 0 <= eff <= 1)
@variable(model, 0 <= z_1 <= 1, binary=true)
@variable(model, 0 <= z_2 <= 1, binary=true)
# constraints
@constraint(model, q_out <= 7-0.1*10^(-1) + M * (1 - z_1))
@constraint(model, q_out >= 7-0.1*10^(-1) - M * z_1)
@constraint(model, q_out <= 9-0.1*10^(-1) + M * (1 - z_2))
@constraint(model, q_out >= 9-0.1*10^(-1) - M * z_2)
@constraint(model, eff == 0.75 * (1-z_2) + 1*z_2 + (0.5-1)*z_1 )
But I’m not convinced of its result.
When q_out
approaches the limit 9, for example q_out = 8.989999389648451
, my binary value z_2=0.9999999999999933
is no longer binary, which is problematic for the variable eff
.
Has somebody an idea of other possibilities to write my code to avoid this kind of problem?
Thank you in advance for your help!