-
Notifications
You must be signed in to change notification settings - Fork 32
/
EmptySet.jl
565 lines (385 loc) · 9.6 KB
/
EmptySet.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
export EmptySet, ∅
"""
EmptySet{N} <: ConvexSet{N}
Type that represents the empty set, i.e., the set with no elements.
"""
struct EmptySet{N} <: ConvexSet{N}
dim::Int
end
# default constructor of type Float64
EmptySet(n::Int) = EmptySet{Float64}(n)
isoperationtype(::Type{<:EmptySet}) = false
isconvextype(::Type{<:EmptySet}) = true
"""
∅
Alias for `EmptySet{Float64}`.
"""
const ∅ = EmptySet{Float64}
"""
dim(∅::EmptySet)
Return the dimension of an empty set.
### Input
- `∅` -- an empty set
### Output
The dimension of the empty set.
"""
function dim(∅::EmptySet)
return ∅.dim
end
"""
σ(d::AbstractVector, ∅::EmptySet)
Return the support vector of an empty set.
### Input
- `d` -- direction
- `∅` -- empty set
### Output
An error.
"""
function σ(d::AbstractVector, ∅::EmptySet)
return error("the support vector of an empty set is undefined")
end
"""
ρ(d::AbstractVector, ∅::EmptySet)
Evaluate the support function of an empty set in a given direction.
### Input
- `d` -- direction
- `∅` -- empty set
### Output
An error.
"""
function ρ(d::AbstractVector, ∅::EmptySet)
return error("the support function of an empty set is undefined")
end
function isboundedtype(::Type{<:EmptySet})
return true
end
"""
isbounded(∅::EmptySet)
Check whether an empty set is bounded.
### Input
- `∅` -- empty set
### Output
`true`.
"""
function isbounded(::EmptySet)
return true
end
"""
isuniversal(∅::EmptySet{N}, [witness]::Bool=false) where {N}
Check whether an empty set is universal.
### Input
- `∅` -- empty set
- `witness` -- (optional, default: `false`) compute a witness if activated
### Output
* If `witness` option is deactivated: `false`
* If `witness` option is activated: `(false, v)` where ``v ∉ S``
"""
function isuniversal(∅::EmptySet{N}, witness::Bool=false) where {N}
if witness
return (false, zeros(N, dim(∅)))
else
return false
end
end
"""
∈(x::AbstractVector, ∅::EmptySet)
Check whether a given point is contained in an empty set.
### Input
- `x` -- point/vector
- `∅` -- empty set
### Output
`false`.
### Examples
```jldoctest
julia> [1.0, 0.0] ∈ ∅(2)
false
```
"""
function ∈(x::AbstractVector, ∅::EmptySet)
return false
end
"""
an_element(∅::EmptySet)
Return some element of an empty set.
### Input
- `∅` -- empty set
### Output
An error.
"""
function an_element(∅::EmptySet)
return error("an empty set does not contain any element")
end
"""
rand(::Type{EmptySet}; [N]::Type{<:Real}=Float64, [dim]::Int=2,
[rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing)
Create an empty set (note that there is nothing to randomize).
### Input
- `EmptySet` -- type for dispatch
- `N` -- (optional, default: `Float64`) numeric type
- `dim` -- (optional, default: 2) dimension
- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator
- `seed` -- (optional, default: `nothing`) seed for reseeding
### Output
The (only) empty set of the given numeric type and dimension.
"""
function rand(::Type{EmptySet};
N::Type{<:Real}=Float64,
dim::Int=2,
rng::AbstractRNG=GLOBAL_RNG,
seed::Union{Int,Nothing}=nothing)
rng = reseed!(rng, seed)
return EmptySet{N}(dim)
end
"""
isempty(∅::EmptySet)
Check if the empty set is empty.
### Input
- `∅` -- empty set
### Output
`true`.
"""
function isempty(∅::EmptySet)
return true
end
"""
norm(∅::EmptySet, [p]::Real=Inf)
Return the norm of an empty set.
It is the norm of the enclosing ball (of the given ``p``-norm) of minimal volume
that is centered in the origin.
### Input
- `∅` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function norm(∅::EmptySet, p::Real=Inf)
return error("the norm of an empty set is undefined")
end
"""
radius(∅::EmptySet, [p]::Real=Inf)
Return the radius of an empty set.
It is the radius of the enclosing ball (of the given ``p``-norm) of minimal
volume with the same center.
### Input
- `∅` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function radius(∅::EmptySet, p::Real=Inf)
return error("the radius of an empty set is undefined")
end
"""
diameter(∅::EmptySet, [p]::Real=Inf)
Return the diameter of an empty set.
It is the maximum distance between any two elements of the set or, equivalently,
the diameter of the enclosing ball (of the given ``p``-norm) of minimal volume
with the same center.
### Input
- `∅` -- empty set
- `p` -- (optional, default: `Inf`) norm
### Output
An error.
"""
function diameter(∅::EmptySet, p::Real=Inf)
return error("the diameter of an empty set is undefined")
end
"""
vertices(∅::EmptySet)
Construct an iterator over the vertices of an empty set.
### Input
- `∅` -- empty set
### Output
The empty iterator, as the empty set does not contain any vertices.
"""
function vertices(∅::EmptySet)
N = eltype(∅)
return EmptyIterator{Vector{N}}()
end
"""
vertices_list(∅::EmptySet)
Return the list of vertices of an empty set.
### Input
- `∅` -- empty set
### Output
The empty list of vertices, as the empty set does not contain any vertices.
"""
function vertices_list(∅::EmptySet)
N = eltype(∅)
return Vector{Vector{N}}()
end
"""
linear_map(M::AbstractMatrix{N}, ∅::EmptySet{N}) where {N}
Return the linear map of an empty set.
### Input
- `M` -- matrix
- `∅` -- empty set
### Output
An empty set.
"""
function linear_map(M::AbstractMatrix, ∅::EmptySet)
N = eltype(∅)
@assert size(M, 2) == dim(∅) "cannot apply a $(size(M))-dimensional " *
"matrix to a $(dim(∅))-dimensional set"
return EmptySet{N}(size(M, 1))
end
"""
translate(∅::EmptySet, v::AbstractVector)
Translate (i.e., shift) an empty set by a given vector.
### Input
- `∅` -- empty set
- `v` -- translation vector
### Output
The empty set.
"""
function translate(∅::EmptySet, v::AbstractVector)
return translate!(∅, v)
end
function translate!(∅::EmptySet, v::AbstractVector)
@assert length(v) == dim(∅) "cannot translate a $(dim(∅))-dimensional " *
"set by a $(length(v))-dimensional vector"
return ∅
end
"""
plot_recipe(∅::EmptySet{N}, [ε]=zero(N)) where {N}
Convert an empty set to a sequence of points for plotting.
In the special case of an empty set, the sequence is empty.
### Input
- `∅` -- empty set
- `ε` -- (optional, default: `0`) ignored, used for dispatch
### Output
An empty array.
"""
function plot_recipe(∅::EmptySet{N}, ε=zero(N)) where {N}
return []
end
"""
area(∅::EmptySet)
Return the area of an empty set.
### Input
- `∅` -- empty set
### Output
``0``.
"""
function area(∅::EmptySet)
N = eltype(∅)
return zero(N)
end
"""
volume(∅::EmptySet{N}) where {N}
Return the volume of an empty set.
### Input
- `∅` -- empty set
### Output
``0``.
"""
function volume(∅::EmptySet{N}) where {N}
return zero(N)
end
function project(∅::EmptySet{N}, block::AbstractVector{Int}; kwargs...) where {N}
return EmptySet{N}(length(block))
end
"""
chebyshev_center_radius(∅::EmptySet; [kwargs]...)
Compute the [Chebyshev center](https://en.wikipedia.org/wiki/Chebyshev_center)
and the corresponding radius of an empty set.
### Input
- `∅` -- empty set
- `kwargs` -- further keyword arguments (ignored)
### Output
An error.
"""
function chebyshev_center_radius(∅::EmptySet; kwargs...)
return error("the Chebyshev center and radius of an empty set are undefined")
end
"""
low(∅::EmptySet)
Return a vector with the lowest coordinates of an empty set in each canonical
direction.
### Input
- `∅` -- empty set
### Output
An error.
### Notes
See also [`low(∅::EmptySet, i::Int)`](@ref).
"""
function low(∅::EmptySet)
return error("the lower bound of an empty set is undefined")
end
"""
high(∅::EmptySet)
Return a vector with the highest coordinates of an empty set in each canonical
direction.
### Input
- `∅` -- empty set
### Output
An error.
### Notes
See also [`high(∅::EmptySet, i::Int)`](@ref).
"""
function high(∅::EmptySet)
return error("the upper bound of an empty set is undefined")
end
"""
low(∅::EmptySet, i::Int)
Return the lowest coordinate of an empty set in the given direction.
### Input
- `∅` -- empty set
- `i` -- dimension of interest
### Output
An error.
"""
function low(∅::EmptySet, i::Int)
return error("the lower bound of an empty set is undefined")
end
"""
high(∅::EmptySet, i::Int)
Return the highest coordinate of an empty set in the given direction.
### Input
- `∅` -- empty set
- `i` -- dimension of interest
### Output
An error.
"""
function high(∅::EmptySet, i::Int)
return error("the upper bound of an empty set is undefined")
end
"""
rectify(∅::EmptySet)
Concrete rectification of an empty set.
### Input
- `∅` -- empty set
### Output
The empty set.
"""
function rectify(∅::EmptySet)
return ∅
end
"""
complement(∅::EmptySet{N}) where {N}
Return the complement of an empty set.
### Input
- `∅` -- empty set
### Output
The universe of the same dimension.
"""
function complement(∅::EmptySet{N}) where {N}
return Universe{N}(dim(∅))
end
"""
reflect(∅::EmptySet)
Concrete reflection of an empty set.
### Input
- `∅` -- empty set
### Output
The same empty set.
"""
function reflect(∅::EmptySet)
return ∅
end
function scale(::Real, ∅::EmptySet)
return ∅
end
function scale!(::Real, ∅::EmptySet)
return ∅
end