You omitted my innermost break
? Don’t quite understand.
I take your point on not using @build_constraint
.
It is a folklore that Dict
can be slow (here), therefore I thought use Array could be faster. (#undef
will not occupy my memory?)
And I use the name exists_violation
because I may execute many blocks of this lazy-cut (thus it is not necessarily feasible
after only one batch).
Finally, I suspect that findall
might be a bit lengthy
Therefore I think it might be better to loop directly.
In a 2-dimensional case, the revised code might look like this
is_cd_idle, cd_ref = trues(M, N), Matrix{JuMP.ConstraintRef}(undef, M, N)
while true
exists_violation = false
for i in 1:is_cd_idle.dims[1], j in 1:is_cd_idle.dims[2]
is_cd_idle[i, j] || continue
R_x[i, j] + DI[i] - DJ[j] < -COT || continue
exists_violation = true
is_cd_idle[i, j], cd_ref[i, j] = false, JuMP.@constraint(lpr, R_x[i, j] + lpr_DI[i] - lpr_DJ[j] >= 0)
solve_to_normality(lpr)
DI, DJ = JuMP.value.(lpr_DI), JuMP.value.(lpr_DJ)
break
end
exists_violation || break # add how many cuts = sum(.!(is_cd_idle))
end
@info "after adding $(count((.!is_cd_idle))) cuts, there is no more violation"