Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace is_feasible by distance_to_set #599

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/constraints/GenericConstraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ end

head(io::IO, c::GenericConstraint) = head(io, c.set)

# A default fallback that skips the feasibiltiy check.
is_feasible(f, ::MOI.AbstractSet, tol) = true

AbstractTrees.children(c::GenericConstraint) = (c.child,)

# A fallback. Define a new method if `MOI.Utilities.distance_to_set`
# is not defined.
function is_feasible(x, set, tol)
return MOI.Utilities.distance_to_set(x, set) <= tol
end

function is_feasible(x::Number, set::MOI.AbstractVectorSet, tol)
return is_feasible([x], set, tol)
end
odow marked this conversation as resolved.
Show resolved Hide resolved
vexity(c::GenericConstraint) = vexity(vexity(c.child), c.set)

function _add_constraint!(context::Context, c::GenericConstraint)
if vexity(c.child) == ConstVexity()
x = evaluate(c.child)
if !is_feasible(x, c.set, CONSTANT_CONSTRAINT_TOL[])
if !is_feasible(evaluate(c.child), c.set, CONSTANT_CONSTRAINT_TOL[])
context.detected_infeasible_during_formulation[] = true
end
return
Expand Down Expand Up @@ -81,8 +86,6 @@ end

head(io::IO, ::MOI.Nonnegatives) = print(io, "≥")

is_feasible(f, ::MOI.Nonnegatives, tol) = all(f .>= -tol)

function vexity(vex, ::MOI.Nonnegatives)
if vex == ConvexVexity()
return NotDcp()
Expand Down Expand Up @@ -117,8 +120,6 @@ end

head(io::IO, ::MOI.Nonpositives) = print(io, "≤")

is_feasible(f, ::MOI.Nonpositives, tol) = all(f .<= tol)

function vexity(vex, ::MOI.Nonpositives)
if vex == ConcaveVexity()
return NotDcp()
Expand Down Expand Up @@ -151,8 +152,6 @@ end

head(io::IO, ::MOI.Zeros) = print(io, "==")

is_feasible(f, ::MOI.Zeros, tol) = all(abs.(f) .<= tol)

function vexity(vex, ::MOI.Zeros)
if vex == ConvexVexity() || vex == ConcaveVexity()
return NotDcp()
Expand Down
Loading