/
Complement.jl
107 lines (72 loc) · 2.03 KB
/
Complement.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import Base: ∈,
isempty
export Complement
"""
Complement{N<:Real, S<:LazySet{N}}
Type that represents the complement of a convex set.
### Fields
- `X` -- convex set
### Notes
Since `X` is assumed to be closed, unless `X` is empty or the universe, its
complement is open (i.e., not closed).
Since `X` is assumed to be closed, unless `X` is empty, the universe, or a
half-space, its complement is not convex.
The complement of the complement is the original set again.
### Examples
```jldoctest
julia> B = BallInf(zeros(2), 1.); C = Complement(B)
Complement{Float64,BallInf{Float64}}(BallInf{Float64}([0.0, 0.0], 1.0))
julia> Complement(C)
BallInf{Float64}([0.0, 0.0], 1.0)
```
"""
struct Complement{N<:Real, S<:LazySet{N}}
X::S
end
@static if VERSION < v"0.7"
# convenience constructor without type parameter
Complement(X::S) where {N<:Real, S<:LazySet{N}} = Complement{N, S}(X)
end
# the complement of the complement is the original set again
Complement(C::Complement) = C.X
"""
dim(C::Complement)
Return the dimension of the complement of a convex set.
### Input
- `C` -- complement of a convex set
### Output
The dimension of the complement of a convex set.
"""
function dim(C::Complement)::Int
return dim(C.X)
end
"""
∈(x::AbstractVector{N}, C::Complement{N})::Bool where {N<:Real}
Check whether a given point is contained in the complement of a convex set.
### Input
- `x` -- point/vector
- `C` -- complement of a convex set
### Output
`true` iff the vector is contained in the complement.
### Algorithm
```math
x ∈ X^C ⟺ x ∉ X
```
"""
function ∈(x::AbstractVector{N}, C::Complement{N})::Bool where {N<:Real}
@assert length(x) == dim(C)
return x ∉ C.X
end
"""
isempty(C::Complement)::Bool
Return if the complement of a convex set is empty or not.
### Input
- `C` -- complement of a convex set
### Output
`false` unless the original set is universal.
### Algorithm
We use the `isuniversal` method.
"""
function isempty(C::Complement)::Bool
return isuniversal(C.X)
end