When I use the indicator constraint, I find that it sometimes causes the model to be infeasible, but I can solve the model when I set a feasible solution as a constraint.
I know that the indicator can only contain linear constraints, so I create a variable to represent the quadratic terms in it. juMP doesn’t report errors, but sometimes it doesn’t work and I’m confused.
My code is as follow:
indt = @variable(model, [1:pipeNum, 1:Horizon], binary=true)
for ij in setdiff(1:pipeNum, ijGC), t in 1:Horizon
x_M_t_avg = (x_M_t[ij, 1, t] + x_M_t[ij, 2, t]) / 2
i, j = idx2ft(GS_fnode, GS_tnode, ij)
term1 = @variable(model)
term2 = @variable(model)
term3 = @variable(model)
@constraints(model, begin
term1 == x_M_t_avg^2
term2 == x_p_t[i, t]^2
term3 == x_p_t[j, t]^2
end)
@constraints(model, begin
indt[ij, t] => {x_p_t[i, t] - x_p_t[j, t] >= 0}
indt[ij, t] => {x_M_t_avg >= 0}
indt[ij, t] => {term1 == GS_K2[ij] .* (term2 - term3)}
!indt[ij, t] => {x_p_t[i, t] - x_p_t[j, t] <= 0}
!indt[ij, t] => {x_M_t_avg <= 0}
!indt[ij, t] => {-term1 == GS_K2[ij] .* (term2 - term3)}
end)
end