Skip to content

Commit 50345e7

Browse files
committed
move 'isfeasible' to util section
1 parent bb4b8e8 commit 50345e7

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

src/Interfaces/AbstractPolyhedron.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ function _linear_map_hrep_helper(M::AbstractMatrix, P::LazySet,
7878
end
7979

8080
# internal functions; defined here due to optional dependencies and submodules
81-
function isfeasible end
8281
function remove_redundant_constraints end
8382
function remove_redundant_constraints! end
8483
function _ishalfspace end

src/Interfaces/AbstractPolyhedron_functions.jl

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export constrained_dimensions,
22
remove_redundant_constraints,
33
remove_redundant_constraints!,
4-
isfeasible,
54
addconstraint!,
65
ishyperplanar
76

@@ -949,49 +948,6 @@ function _project_polyhedron(P::LazySet, block; kwargs...)
949948
return constraints_list(πP)
950949
end
951950

952-
"""
953-
isfeasible(A::AbstractMatrix, b::AbstractVector, [witness]::Bool=false;
954-
[solver]=nothing)
955-
956-
Check for feasibility of linear constraints given in matrix-vector form.
957-
958-
### Input
959-
960-
- `A` -- constraints matrix
961-
- `b` -- constraints vector
962-
- `witness` -- (optional; default: `false`) flag for witness production
963-
- `solver` -- (optional; default: `nothing`) LP solver
964-
965-
### Output
966-
967-
If `witness` is `false`, the result is a `Bool`.
968-
969-
If `witness` is `true`, the result is a pair `(res, w)` where `res` is a `Bool`
970-
and `w` is a witness point/vector.
971-
972-
### Algorithm
973-
974-
This implementation solves the corresponding feasibility linear program.
975-
"""
976-
function isfeasible(A::AbstractMatrix, b::AbstractVector, witness::Bool=false;
977-
solver=nothing)
978-
N = promote_type(eltype(A), eltype(b))
979-
# feasibility LP
980-
lbounds, ubounds = -Inf, Inf
981-
sense = '<'
982-
obj = zeros(N, size(A, 2))
983-
if isnothing(solver)
984-
solver = default_lp_solver(N)
985-
end
986-
lp = linprog(obj, A, sense, b, lbounds, ubounds, solver)
987-
if is_lp_optimal(lp.status)
988-
return witness ? (true, lp.sol) : true
989-
elseif is_lp_infeasible(lp.status)
990-
return witness ? (false, N[]) : false
991-
end
992-
return error("LP returned status $(lp.status) unexpectedly")
993-
end
994-
995951
# convenience function to invert the result of `isfeasible` while still including the witness result
996952
function _isinfeasible(constraints::AbstractVector{<:HalfSpace},
997953
witness::Bool=false; solver=nothing)

src/Sets/HalfSpace/isfeasible.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
isfeasible(constraints::AbstractVector{<:HalfSpace}, [witness]::Bool=false;
43
[solver]=nothing)

src/Utils/lp_solvers.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export isfeasible
2+
13
function default_lp_solver(::Type{T}) where {T}
24
key = task_local_lp_solver_key(T)
35
LP = get!(() -> JuMP.Model(default_lp_solver_factory(T)), task_local_storage(), key)
@@ -35,3 +37,46 @@ function default_lp_solver_polyhedra(N; kwargs...)
3537
require(@__MODULE__, :Polyhedra; fun_name="default_lp_solver_polyhedra")
3638
return error("no default solver for numeric type $N")
3739
end
40+
41+
"""
42+
isfeasible(A::AbstractMatrix, b::AbstractVector, [witness]::Bool=false;
43+
[solver]=nothing)
44+
45+
Check for feasibility of linear constraints given in matrix-vector form.
46+
47+
### Input
48+
49+
- `A` -- constraints matrix
50+
- `b` -- constraints vector
51+
- `witness` -- (optional; default: `false`) flag for witness production
52+
- `solver` -- (optional; default: `nothing`) LP solver
53+
54+
### Output
55+
56+
If `witness` is `false`, the result is a `Bool`.
57+
58+
If `witness` is `true`, the result is a pair `(res, w)` where `res` is a `Bool`
59+
and `w` is a witness point/vector.
60+
61+
### Algorithm
62+
63+
This implementation solves the corresponding feasibility linear program.
64+
"""
65+
function isfeasible(A::AbstractMatrix, b::AbstractVector, witness::Bool=false;
66+
solver=nothing)
67+
N = promote_type(eltype(A), eltype(b))
68+
# feasibility LP
69+
lbounds, ubounds = -Inf, Inf
70+
sense = '<'
71+
obj = zeros(N, size(A, 2))
72+
if isnothing(solver)
73+
solver = default_lp_solver(N)
74+
end
75+
lp = linprog(obj, A, sense, b, lbounds, ubounds, solver)
76+
if is_lp_optimal(lp.status)
77+
return witness ? (true, lp.sol) : true
78+
elseif is_lp_infeasible(lp.status)
79+
return witness ? (false, N[]) : false
80+
end
81+
return error("LP returned status $(lp.status) unexpectedly")
82+
end

0 commit comments

Comments
 (0)