assert_cuts_off: Improve performance

fs11_01
Alinson S. Xavier 2 months ago
parent bb59362571
commit 65a6024c36

@ -27,27 +27,19 @@ function assert_eq(a, b; atol = 1e-4)
end end
function assert_cuts_off(cuts::ConstraintSet, x::Vector{Float64}, tol = 1e-6) function assert_cuts_off(cuts::ConstraintSet, x::Vector{Float64}, tol = 1e-6)
vals = cuts.lhs * x
for i = 1:length(cuts.lb) for i = 1:length(cuts.lb)
val = cuts.lhs[i, :]' * x if (vals[i] <= cuts.ub[i] - tol) && (vals[i] >= cuts.lb[i] + tol)
if (val <= cuts.ub[i] - tol) && (val >= cuts.lb[i] + tol)
throw(ErrorException("inequality fails to cut off fractional solution")) throw(ErrorException("inequality fails to cut off fractional solution"))
end end
end end
end end
function assert_does_not_cut_off(cuts::ConstraintSet, x::Vector{Float64}; tol = 1e-6) function assert_does_not_cut_off(cuts::ConstraintSet, x::Vector{Float64}; tol = 1e-6)
vals = cuts.lhs * x
for i = 1:length(cuts.lb) for i = 1:length(cuts.lb)
val = cuts.lhs[i, :]' * x if (vals[i] >= cuts.ub[i]) || (vals[i] <= cuts.lb[i])
ub = cuts.ub[i] throw(ErrorException("inequality $i cuts off integer solution"))
lb = cuts.lb[i]
if (val >= ub) || (val <= lb)
@show cuts.lhs[i, :]
@show x[cuts.lhs[i, :].nzind]
throw(
ErrorException(
"inequality $i cuts off integer solution ($lb <= $val <= $ub)",
),
)
end end
end end
end end

Loading…
Cancel
Save