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
function assert_cuts_off(cuts::ConstraintSet, x::Vector{Float64}, tol = 1e-6)
vals = cuts.lhs * x
for i = 1:length(cuts.lb)
val = cuts.lhs[i, :]' * x
if (val <= cuts.ub[i] - tol) && (val >= cuts.lb[i] + tol)
if (vals[i] <= cuts.ub[i] - tol) && (vals[i] >= cuts.lb[i] + tol)
throw(ErrorException("inequality fails to cut off fractional solution"))
end
end
end
function assert_does_not_cut_off(cuts::ConstraintSet, x::Vector{Float64}; tol = 1e-6)
vals = cuts.lhs * x
for i = 1:length(cuts.lb)
val = cuts.lhs[i, :]' * x
ub = cuts.ub[i]
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)",
),
)
if (vals[i] >= cuts.ub[i]) || (vals[i] <= cuts.lb[i])
throw(ErrorException("inequality $i cuts off integer solution"))
end
end
end

Loading…
Cancel
Save