mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
assert_cuts_off: Improve performance
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user