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

#855 - Method ambiguities #857

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
92 changes: 56 additions & 36 deletions src/is_intersection_empty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,78 +121,85 @@ end
# --- AbstractSingleton ---


# common code for singletons
@inline function is_intersection_empty_helper(
S::AbstractSingleton{N}, X::LazySet{N}, witness::Bool=false
)::Union{Bool, Tuple{Bool,Vector{N}} } where N<:Real
empty_intersection = element(S) ∉ X
if witness
return (empty_intersection, empty_intersection ? N[] : element(S))
else
return empty_intersection
end
end

"""
is_intersection_empty(S::AbstractSingleton{N},
set::LazySet{N},
X::LazySet{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
)::Union{Bool,Tuple{Bool,Vector{N}}} where N<:Real

Check whether a singleton and a convex set do not intersect, and otherwise
optionally compute a witness.

### Input

- `S` -- singleton
- `set` -- convex set
- `S` -- singleton
- `X` -- convex set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output

* If `witness` option is deactivated: `true` iff ``S ∩ \\operatorname{set} = ∅``
* If `witness` option is deactivated: `true` iff ``S ∩ X = ∅``
* If `witness` option is activated:
* `(true, [])` iff ``S ∩ \\operatorname{set} = ∅``
* `(false, v)` iff ``S ∩ \\operatorname{set} ≠ ∅`` and
`v` = `element(S)` ``∈ S ∩ \\operatorname{set}``
* `(true, [])` iff ``S ∩ X = ∅``
* `(false, v)` iff ``S ∩ X ≠ ∅`` and
`v` = `element(S)` ``∈ S ∩ X``

### Algorithm

``S ∩ \\operatorname{set} = ∅`` iff `element(S)` ``∉ \\operatorname{set}``.
``S ∩ X = ∅`` iff `element(S)` ``∉ X``.
"""
function is_intersection_empty(S::AbstractSingleton{N},
set::LazySet{N},
X::LazySet{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
empty_intersection = element(S) ∉ set
if witness
return (empty_intersection, empty_intersection ? N[] : element(S))
else
return empty_intersection
end
)::Union{Bool,Tuple{Bool,Vector{N}}} where N<:Real
return is_intersection_empty_helper(S, X, witness)
end


"""
is_intersection_empty(set::LazySet{N},
is_intersection_empty(X::LazySet{N},
S::AbstractSingleton{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
)::Union{Bool,Tuple{Bool,Vector{N}}} where N<:Real

Check whether a convex set and a singleton do not intersect, and otherwise
optionally compute a witness.

### Input

- `set` -- convex set
- `S` -- singleton
- `X` -- convex set
- `S` -- singleton
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output

* If `witness` option is deactivated: `true` iff ``S ∩ \\operatorname{set} = ∅``
* If `witness` option is deactivated: `true` iff ``S ∩ X = ∅``
* If `witness` option is activated:
* `(true, [])` iff ``S ∩ \\operatorname{set} = ∅``
* `(false, v)` iff ``S ∩ \\operatorname{set} ≠ ∅`` and
`v` = `element(S)` ``∈ S ∩ \\operatorname{set}``
* `(true, [])` iff ``S ∩ X = ∅``
* `(false, v)` iff ``S ∩ X ≠ ∅`` and
`v` = `element(S)` ``∈ S ∩ X``

### Algorithm

``S ∩ \\operatorname{set} = ∅`` iff `element(S)` ``∉ \\operatorname{set}``.
``S ∩ X = ∅`` iff `element(S)` ``∉ X``.
"""
function is_intersection_empty(set::LazySet{N},
function is_intersection_empty(X::LazySet{N},
S::AbstractSingleton{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
return is_intersection_empty(S, set, witness)
)::Union{Bool,Tuple{Bool,Vector{N}}} where N<:Real
return is_intersection_empty_helper(S, X, witness)
end


Expand Down Expand Up @@ -265,12 +272,7 @@ function is_intersection_empty(H::AbstractHyperrectangle{N},
S::AbstractSingleton{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
empty_intersection = element(S) ∉ H
if witness
return (empty_intersection, empty_intersection ? N[] : element(S))
else
return empty_intersection
end
return is_intersection_empty_helper(S, H, witness)
end


Expand Down Expand Up @@ -304,7 +306,7 @@ function is_intersection_empty(S::AbstractSingleton{N},
H::AbstractHyperrectangle{N},
witness::Bool=false
)::Union{Bool,Tuple{Bool,Vector{N}}} where {N<:Real}
return is_intersection_empty(H, S, witness)
return is_intersection_empty_helper(S, H, witness)
end


Expand Down Expand Up @@ -817,6 +819,24 @@ function is_intersection_empty(hs1::HalfSpace{N},
end
end

# disambiguation
function is_intersection_empty(H::HalfSpace{N},
S::AbstractSingleton{N},
witness::Bool=false;
kwargs...
)::Union{Bool, Tuple{Bool,Vector{N}}} where N<:Real
return is_intersection_empty_helper(S, H, witness)
end

# symmetric method
function is_intersection_empty(S::AbstractSingleton{N},
H::HalfSpace{N},
witness::Bool=false;
kwargs...
)::Union{Bool, Tuple{Bool,Vector{N}}} where N<:Real
return is_intersection_empty_helper(S, H, witness)
end

"""
is_intersection_empty(X::LazySet{N},
P::Union{HPolyhedron{N}, HPolytope{N}, AbstractHPolygon{N}}
Expand Down
30 changes: 15 additions & 15 deletions src/is_subset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import Base.issubset
⊆(S::LazySet{N}, H::AbstractHyperrectangle{N}, [witness]::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}

Check whether a convex set is contained in a hyperrectangle, and if not,
Check whether a convex set is contained in a hyperrectangular set, and if not,
optionally compute a witness.

### Input

- `S` -- inner convex set
- `H` -- outer hyperrectangle
- `H` -- outer hyperrectangular set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output
Expand All @@ -39,13 +39,13 @@ end
⊆(P::AbstractPolytope{N}, H::AbstractHyperrectangle, [witness]::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}

Check whether a polytope is contained in a hyperrectangle, and if not,
Check whether a polytope is contained in a hyperrectangular set, and if not,
optionally compute a witness.

### Input

- `P` -- inner polytope
- `H` -- outer hyperrectangle
- `H` -- outer hyperrectangular set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output
Expand Down Expand Up @@ -93,13 +93,13 @@ end
[witness]::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}

Check whether a given hyperrectangle is contained in another hyperrectangle, and
if not, optionally compute a witness.
Check whether a given hyperrectangular set is contained in another
hyperrectangular set, and if not, optionally compute a witness.

### Input

- `H1` -- inner hyperrectangle
- `H2` -- outer hyperrectangle
- `H1` -- inner hyperrectangular set
- `H2` -- outer hyperrectangular set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output
Expand Down Expand Up @@ -237,13 +237,13 @@ end
[witness]::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}

Check whether a given set with a single value is contained in a hyperrectangle,
and if not, optionally compute a witness.
Check whether a given set with a single value is contained in a hyperrectangular
set, and if not, optionally compute a witness.

### Input

- `S` -- inner set with a single value
- `H` -- outer hyperrectangle
- `H` -- outer hyperrectangular set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output
Expand Down Expand Up @@ -441,16 +441,16 @@ end


"""
⊆(L::LineSegment{N}, H::Hyperrectangle{N}, [witness]::Bool=false
⊆(L::LineSegment{N}, H::AbstractHyperrectangle{N}, [witness]::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}

Check whether a line segment is contained in a hyperrectangle, and if not,
Check whether a line segment is contained in a hyperrectangular set, and if not,
optionally compute a witness.

### Input

- `L` -- inner line segment
- `H` -- outer hyperrectangle
- `H` -- outer hyperrectangular set
- `witness` -- (optional, default: `false`) compute a witness if activated

### Output
Expand All @@ -469,7 +469,7 @@ This copy-pasted method just exists to avoid method ambiguities.
Since ``H`` is convex, ``L ⊆ H`` iff ``p ∈ H`` and ``q ∈ H``, where ``p, q`` are
the end points of ``L``.
"""
function ⊆(L::LineSegment{N}, H::Hyperrectangle{N}, witness::Bool=false
function ⊆(L::LineSegment{N}, H::AbstractHyperrectangle{N}, witness::Bool=false
)::Union{Bool, Tuple{Bool, Vector{N}}} where {N<:Real}
p_in_H = ∈(L.p, H)
result = p_in_H && ∈(L.q, H)
Expand Down