From f8983970a246957397c7753164b7790eb03fa5b3 Mon Sep 17 00:00:00 2001 From: schillic Date: Tue, 16 Jul 2024 13:24:09 +0200 Subject: [PATCH] resolve submodule dependencies via Requires --- src/Sets/Ball1/Ball1Module.jl | 13 ++++++++----- src/Sets/Ball1/constraints_list.jl | 2 ++ src/Sets/Ball1/init.jl | 3 +++ src/Sets/Ball1/init_LazySets.jl | 1 + src/Sets/Ball2/Ball2Module.jl | 2 +- src/Sets/BallInf/BallInfModule.jl | 2 +- src/Sets/Ballp/Ballp.jl | 6 ++++++ src/Sets/Ballp/BallpModule.jl | 7 +++++-- src/Sets/Ballp/init.jl | 3 +++ src/Sets/Ballp/init_LazySets.jl | 3 +++ src/Sets/Ellipsoid/EllipsoidModule.jl | 4 ++-- src/Sets/EmptySet/EmptySetModule.jl | 10 ++++++---- src/Sets/EmptySet/complement.jl | 2 ++ src/Sets/EmptySet/init.jl | 3 +++ src/Sets/EmptySet/init_LazySets.jl | 1 + src/Sets/HParallelotope/HParallelotope.jl | 2 ++ src/Sets/HParallelotope/HParallelotopeModule.jl | 9 ++++++--- src/Sets/HParallelotope/init.jl | 3 +++ src/Sets/HParallelotope/init_LazySets.jl | 1 + src/Sets/HParallelotope/rand.jl | 2 ++ src/Sets/HPolygon/HPolygonModule.jl | 2 +- src/Sets/HPolyhedron/HPolyhedronModule.jl | 5 +++-- src/Sets/HPolytope/HPolytopeModule.jl | 7 ++++--- src/Sets/HPolytope/init_LazySets.jl | 1 + src/Sets/HPolytope/vertices_list.jl | 2 ++ src/Sets/HalfSpace/HalfSpaceModule.jl | 8 ++++---- src/Sets/Hyperplane/HyperplaneModule.jl | 8 ++++---- src/Sets/Hyperplane/constraints_list.jl | 2 ++ src/Sets/Hyperplane/init_LazySets.jl | 1 + src/Sets/Interval/IntervalModule.jl | 14 ++++++++------ src/Sets/Interval/complement.jl | 2 ++ src/Sets/Interval/constraints_list.jl | 2 ++ src/Sets/Interval/difference.jl | 2 ++ src/Sets/Interval/init.jl | 3 +++ src/Sets/Interval/init_LazySets.jl | 3 +++ src/Sets/Interval/intersection.jl | 2 ++ src/Sets/Interval/linear_map.jl | 2 ++ src/Sets/Interval/minkowski_difference.jl | 2 ++ src/Sets/Line/LineModule.jl | 9 +++++---- src/Sets/Line/constraints_list.jl | 2 ++ src/Sets/Line/init_LazySets.jl | 1 + src/Sets/Line2D/Line2DModule.jl | 2 +- src/Sets/LineSegment/LineSegmentModule.jl | 7 +++++-- src/Sets/LineSegment/init.jl | 3 +++ src/Sets/LineSegment/init_LazySets.jl | 3 +++ src/Sets/LineSegment/intersection.jl | 1 + src/Sets/Polygon/PolygonModule.jl | 8 +++++--- src/Sets/Polygon/convex_hull.jl | 2 ++ src/Sets/Polygon/init.jl | 3 +++ src/Sets/Polygon/init_LazySets.jl | 2 ++ src/Sets/Polygon/support_function.jl | 2 ++ src/Sets/Polygon/support_vector.jl | 2 ++ .../SimpleSparsePolynomialZonotopeModule.jl | 2 +- .../SparsePolynomialZonotopeModule.jl | 4 ++-- src/Sets/SparsePolynomialZonotope/init_LazySets.jl | 1 + src/Sets/SparsePolynomialZonotope/reduce_order.jl | 2 ++ src/Sets/Star/StarModule.jl | 5 +++-- src/Sets/Tetrahedron/TetrahedronModule.jl | 9 ++++++--- src/Sets/Tetrahedron/constraints_list.jl | 2 ++ src/Sets/Tetrahedron/init.jl | 3 +++ src/Sets/Tetrahedron/init_LazySets.jl | 1 + src/Sets/Tetrahedron/rand.jl | 2 ++ src/Sets/Tetrahedron/support_vector.jl | 6 ++++-- src/Sets/Universe/UniverseModule.jl | 4 ++-- src/Sets/Universe/constraints_list.jl | 2 ++ src/Sets/Universe/init_LazySets.jl | 1 + src/Sets/VPolygon/VPolygonModule.jl | 5 +++-- src/Sets/VPolytope/VPolytopeModule.jl | 9 ++++----- src/Sets/VPolytope/constraints_list.jl | 2 ++ src/Sets/VPolytope/init_LazySets.jl | 2 ++ src/Sets/VPolytope/project.jl | 3 +++ src/Sets/VPolytope/tohrep.jl | 2 ++ src/Sets/ZeroSet/ZeroSetModule.jl | 7 +++++-- src/Sets/ZeroSet/init.jl | 3 +++ src/Sets/ZeroSet/init_LazySets.jl | 1 + src/Sets/ZeroSet/translate.jl | 3 +++ src/Sets/Zonotope/ZonotopeModule.jl | 2 +- 77 files changed, 207 insertions(+), 70 deletions(-) create mode 100644 src/Sets/Ball1/init.jl create mode 100644 src/Sets/Ball1/init_LazySets.jl create mode 100644 src/Sets/Ballp/init.jl create mode 100644 src/Sets/Ballp/init_LazySets.jl create mode 100644 src/Sets/EmptySet/init.jl create mode 100644 src/Sets/EmptySet/init_LazySets.jl create mode 100644 src/Sets/HParallelotope/init.jl create mode 100644 src/Sets/HParallelotope/init_LazySets.jl create mode 100644 src/Sets/Interval/init.jl create mode 100644 src/Sets/Interval/init_LazySets.jl create mode 100644 src/Sets/LineSegment/init.jl create mode 100644 src/Sets/LineSegment/init_LazySets.jl create mode 100644 src/Sets/Polygon/init.jl create mode 100644 src/Sets/Polygon/init_LazySets.jl create mode 100644 src/Sets/Tetrahedron/init.jl create mode 100644 src/Sets/Tetrahedron/init_LazySets.jl create mode 100644 src/Sets/ZeroSet/init.jl create mode 100644 src/Sets/ZeroSet/init_LazySets.jl diff --git a/src/Sets/Ball1/Ball1Module.jl b/src/Sets/Ball1/Ball1Module.jl index f6e7488db9..33f7cc8ce0 100644 --- a/src/Sets/Ball1/Ball1Module.jl +++ b/src/Sets/Ball1/Ball1Module.jl @@ -1,19 +1,20 @@ module Ball1Module -using Reexport +using Reexport, Requires -using ..LazySets: AbstractCentrallySymmetricPolytope, HalfSpace +using ..LazySets: AbstractCentrallySymmetricPolytope, _high_AbstractBallp, + _low_AbstractBallp +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG -using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Arrays: argmaxabs -using LinearAlgebra: dot +using ReachabilityBase.Distribution: reseed! +using ReachabilityBase.Require: require @reexport import ..API: center, constraints_list, high, isoperationtype, low, rand, reflect, vertices_list, ∈, project, scale, ρ, σ, translate! @reexport import ..LazySets: ball_norm, radius_ball @reexport using ..API -using ..LazySets: _high_AbstractBallp, _low_AbstractBallp export Ball1 @@ -36,4 +37,6 @@ include("support_vector.jl") include("translate.jl") include("vertices_list.jl") +include("init.jl") + end # module diff --git a/src/Sets/Ball1/constraints_list.jl b/src/Sets/Ball1/constraints_list.jl index 779f59ec68..96f7a03d0d 100644 --- a/src/Sets/Ball1/constraints_list.jl +++ b/src/Sets/Ball1/constraints_list.jl @@ -22,6 +22,8 @@ The constraints can be defined as ``d_i^T (x-c) ≤ r`` for all ``d_i``, where all possible ``d_i``, the function `Iterators.product` is used. """ function constraints_list(B::Ball1) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + n = dim(B) c, r = B.center, B.radius N = eltype(B) diff --git a/src/Sets/Ball1/init.jl b/src/Sets/Ball1/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/Ball1/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/Ball1/init_LazySets.jl b/src/Sets/Ball1/init_LazySets.jl new file mode 100644 index 0000000000..1a2df2738e --- /dev/null +++ b/src/Sets/Ball1/init_LazySets.jl @@ -0,0 +1 @@ +using .LazySets.HalfSpaceModule: HalfSpace diff --git a/src/Sets/Ball2/Ball2Module.jl b/src/Sets/Ball2/Ball2Module.jl index f406623ab4..6ec966e8f0 100644 --- a/src/Sets/Ball2/Ball2Module.jl +++ b/src/Sets/Ball2/Ball2Module.jl @@ -3,11 +3,11 @@ module Ball2Module using Reexport, Requires using ..LazySets: AbstractBallp, _witness_result_empty +using LinearAlgebra: dot, axpby! using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Comparison: _leq, isapproxzero using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require -using LinearAlgebra: dot, axpby! @reexport import ..API: area, center, isoperationtype, rand, reflect, sample, volume, ∈, project, scale, ρ, σ, translate!, diff --git a/src/Sets/BallInf/BallInfModule.jl b/src/Sets/BallInf/BallInfModule.jl index 6f03c102ab..927f61e4a4 100644 --- a/src/Sets/BallInf/BallInfModule.jl +++ b/src/Sets/BallInf/BallInfModule.jl @@ -4,11 +4,11 @@ using Reexport, Requires using ..LazySets: AbstractHyperrectangle, _high_AbstractBallp, _low_AbstractBallp, _ρ_sev_hyperrectangle, _σ_sev_hyperrectangle +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: SingleEntryVector using ReachabilityBase.Comparison: isapproxzero using ReachabilityBase.Distribution: reseed! -using LinearAlgebra: dot @reexport import ..API: area, center, isoperationtype, high, low, radius, rand, reflect, volume, project, scale, ρ, σ, translate! diff --git a/src/Sets/Ballp/Ballp.jl b/src/Sets/Ballp/Ballp.jl index 3aedbaf6a7..ef69ca2337 100644 --- a/src/Sets/Ballp/Ballp.jl +++ b/src/Sets/Ballp/Ballp.jl @@ -59,10 +59,16 @@ struct Ballp{N<:AbstractFloat,VN<:AbstractVector{N}} <: AbstractBallp{N} @assert radius >= zero(N) "the radius must not be negative" @assert p >= one(N) "p must not be less than 1" if p == N(Inf) + require(@__MODULE__, :LazySets; fun_name="Ballp") + return BallInf(center, radius) elseif p == N(2) + require(@__MODULE__, :LazySets; fun_name="Ballp") + return Ball2(center, radius) elseif isone(p) + require(@__MODULE__, :LazySets; fun_name="Ballp") + return Ball1(center, radius) else return new{N,VN}(p, center, radius) diff --git a/src/Sets/Ballp/BallpModule.jl b/src/Sets/Ballp/BallpModule.jl index 6004373467..a57dbd922d 100644 --- a/src/Sets/Ballp/BallpModule.jl +++ b/src/Sets/Ballp/BallpModule.jl @@ -1,10 +1,11 @@ module BallpModule -using Reexport +using Reexport, Requires -using ..LazySets: AbstractBallp, Ball1, Ball2, BallInf +using ..LazySets: AbstractBallp using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! +using ReachabilityBase.Require: require @reexport import ..API: center, isoperationtype, rand, reflect, project, scale, translate! @@ -25,4 +26,6 @@ include("reflect.jl") include("scale.jl") include("translate.jl") +include("init.jl") + end # module diff --git a/src/Sets/Ballp/init.jl b/src/Sets/Ballp/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/Ballp/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/Ballp/init_LazySets.jl b/src/Sets/Ballp/init_LazySets.jl new file mode 100644 index 0000000000..9c43a8bf5e --- /dev/null +++ b/src/Sets/Ballp/init_LazySets.jl @@ -0,0 +1,3 @@ +using .LazySets.Ball1Module: Ball1 +using .LazySets.Ball2Module: Ball2 +using .LazySets.BallInfModule: BallInf diff --git a/src/Sets/Ellipsoid/EllipsoidModule.jl b/src/Sets/Ellipsoid/EllipsoidModule.jl index 066716f356..5b1b01ef98 100644 --- a/src/Sets/Ellipsoid/EllipsoidModule.jl +++ b/src/Sets/Ellipsoid/EllipsoidModule.jl @@ -3,10 +3,10 @@ module EllipsoidModule using Reexport using ..LazySets: AbstractCentrallySymmetric +using LinearAlgebra: dot, I, checksquare, isposdef using Random: AbstractRNG, GLOBAL_RNG -using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Arrays: inner -using LinearAlgebra: dot, I, checksquare, isposdef +using ReachabilityBase.Distribution: reseed! @reexport import ..API: center, isoperationtype, rand, affine_map, ∈, linear_map, ρ, σ, translate! diff --git a/src/Sets/EmptySet/EmptySetModule.jl b/src/Sets/EmptySet/EmptySetModule.jl index 772b39de79..cddde7837b 100644 --- a/src/Sets/EmptySet/EmptySetModule.jl +++ b/src/Sets/EmptySet/EmptySetModule.jl @@ -1,19 +1,19 @@ module EmptySetModule -using Reexport +using Reexport, Requires -using ..LazySets: LazySet, ConvexSet, Universe, _witness_result_empty +using ..LazySets: LazySet, ConvexSet, _witness_result_empty using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Iteration: EmptyIterator +using ReachabilityBase.Require: require @reexport import ..API: an_element, area, complement, diameter, dim, high, ∈, isbounded, isboundedtype, isconvextype, isempty, isoperationtype, isuniversal, linear_map, low, norm, project, radius, rand, rectify, reflect, scale, scale!, ρ, σ, translate, translate!, vertices, vertices_list, - volume, - convex_hull, intersection, isdisjoint, ⊆ + volume, convex_hull, intersection, isdisjoint, ⊆ @reexport import ..LazySets: chebyshev_center_radius, plot_recipe @reexport using ..API @@ -75,4 +75,6 @@ function plot_recipe(::EmptySet{N}, ε=zero(N)) where {N} return [] end +include("init.jl") + end # module diff --git a/src/Sets/EmptySet/complement.jl b/src/Sets/EmptySet/complement.jl index c0cc3a6142..321f3ce1b7 100644 --- a/src/Sets/EmptySet/complement.jl +++ b/src/Sets/EmptySet/complement.jl @@ -12,5 +12,7 @@ Return the complement of an empty set. The universe of the same dimension. """ function complement(∅::EmptySet{N}) where {N} + require(@__MODULE__, :LazySets; fun_name="complement") + return Universe{N}(dim(∅)) end diff --git a/src/Sets/EmptySet/init.jl b/src/Sets/EmptySet/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/EmptySet/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/EmptySet/init_LazySets.jl b/src/Sets/EmptySet/init_LazySets.jl new file mode 100644 index 0000000000..c196979555 --- /dev/null +++ b/src/Sets/EmptySet/init_LazySets.jl @@ -0,0 +1 @@ +using .LazySets.UniverseModule: Universe diff --git a/src/Sets/HParallelotope/HParallelotope.jl b/src/Sets/HParallelotope/HParallelotope.jl index d6e6313c14..dbdca1f6aa 100644 --- a/src/Sets/HParallelotope/HParallelotope.jl +++ b/src/Sets/HParallelotope/HParallelotope.jl @@ -65,6 +65,8 @@ struct HParallelotope{N,VN<:AbstractVector{N},MN<:AbstractMatrix{N}} <: Abstract "but they have sizes $(length(c)) and $(size(D)) respectively" if check_consistency + require(@__MODULE__, :LazySets; fun_name="HParallelotope") + P = HPolyhedron(_constraints_list_hparallelotope(D, c, N, VN)) if isempty(P) throw(ArgumentError("the constraints are contradictory")) diff --git a/src/Sets/HParallelotope/HParallelotopeModule.jl b/src/Sets/HParallelotope/HParallelotopeModule.jl index aeb91e8a97..754043d9b5 100644 --- a/src/Sets/HParallelotope/HParallelotopeModule.jl +++ b/src/Sets/HParallelotope/HParallelotopeModule.jl @@ -1,12 +1,13 @@ module HParallelotopeModule -using Reexport +using Reexport, Requires -using ..LazySets: AbstractZonotope, HalfSpace, HPolyhedron, generators_fallback +using ..LazySets: AbstractZonotope, HalfSpace, generators_fallback +using LinearAlgebra: checksquare, det using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: to_negative_vector using ReachabilityBase.Distribution: reseed! -using LinearAlgebra: checksquare, det +using ReachabilityBase.Require: require @reexport import ..API: center, constraints_list, dim, isoperationtype, rand, volume @@ -34,4 +35,6 @@ include("offset.jl") include("rand.jl") include("volume.jl") +include("init.jl") + end # module diff --git a/src/Sets/HParallelotope/init.jl b/src/Sets/HParallelotope/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/HParallelotope/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/HParallelotope/init_LazySets.jl b/src/Sets/HParallelotope/init_LazySets.jl new file mode 100644 index 0000000000..1b1dc17ef9 --- /dev/null +++ b/src/Sets/HParallelotope/init_LazySets.jl @@ -0,0 +1 @@ +using .LazySets.HPolyhedronModule: HPolyhedron diff --git a/src/Sets/HParallelotope/rand.jl b/src/Sets/HParallelotope/rand.jl index fc72cfd5d3..1a5759df05 100644 --- a/src/Sets/HParallelotope/rand.jl +++ b/src/Sets/HParallelotope/rand.jl @@ -34,6 +34,8 @@ function rand(::Type{HParallelotope}; dim::Int=2, rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int,Nothing}=nothing) + require(@__MODULE__, :LazySets; fun_name="rand") + rng = reseed!(rng, seed) while true diff --git a/src/Sets/HPolygon/HPolygonModule.jl b/src/Sets/HPolygon/HPolygonModule.jl index 2748082288..479460a3ab 100644 --- a/src/Sets/HPolygon/HPolygonModule.jl +++ b/src/Sets/HPolygon/HPolygonModule.jl @@ -5,7 +5,7 @@ using Reexport using ..LazySets: AbstractHPolygon, BINARY_SEARCH_THRESHOLD, addconstraint!, binary_search_constraints, constraints_list, element, isbounded, ⪯, _intersection_line2d -using ..LazySets.HalfSpaceModule: HalfSpace, _normal_Vector +using ..HalfSpaceModule: HalfSpace, _normal_Vector @reexport import ..API: isoperationtype, σ, translate @reexport using ..API diff --git a/src/Sets/HPolyhedron/HPolyhedronModule.jl b/src/Sets/HPolyhedron/HPolyhedronModule.jl index 826882fac6..aa59435766 100644 --- a/src/Sets/HPolyhedron/HPolyhedronModule.jl +++ b/src/Sets/HPolyhedron/HPolyhedronModule.jl @@ -2,18 +2,19 @@ module HPolyhedronModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, HalfSpace, default_lp_solver, +using ..LazySets: AbstractPolyhedron, default_lp_solver, default_polyhedra_backend, iscomplement, is_lp_infeasible, is_lp_optimal, is_lp_unbounded, has_lp_infeasibility_ray, linprog, tosimplehrep, _isempty_polyhedron, _normal_Vector +using ..HalfSpaceModule: HalfSpace using ..HPolytopeModule: HPolytope +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: to_negative_vector using ReachabilityBase.Basetype: basetype using ReachabilityBase.Comparison: isapproxzero using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: constraints_list, dim, isempty, isoperationtype, rand, permute, ρ, σ, translate diff --git a/src/Sets/HPolytope/HPolytopeModule.jl b/src/Sets/HPolytope/HPolytopeModule.jl index 0797c0df79..16507a884c 100644 --- a/src/Sets/HPolytope/HPolytopeModule.jl +++ b/src/Sets/HPolytope/HPolytopeModule.jl @@ -2,9 +2,10 @@ module HPolytopeModule using Reexport, Requires -using ..LazySets: AbstractPolytope, HalfSpace, HPolygon, - AbstractLinearMapAlgorithm, default_polyhedra_backend, - vertices_list_1d, _linear_map_hrep, _normal_Vector +using ..LazySets: AbstractPolytope, AbstractLinearMapAlgorithm, + default_polyhedra_backend, vertices_list_1d, _linear_map_hrep, + _normal_Vector +using ..HalfSpaceModule: HalfSpace using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Comparison: isapproxzero, _ztol diff --git a/src/Sets/HPolytope/init_LazySets.jl b/src/Sets/HPolytope/init_LazySets.jl index e1d13e9e0c..adca20c9ce 100644 --- a/src/Sets/HPolytope/init_LazySets.jl +++ b/src/Sets/HPolytope/init_LazySets.jl @@ -1 +1,2 @@ +using .LazySets.HPolygonModule: HPolygon using .LazySets.VPolytopeModule: VPolytope diff --git a/src/Sets/HPolytope/vertices_list.jl b/src/Sets/HPolytope/vertices_list.jl index 7472509371..9ce9ffb0e8 100644 --- a/src/Sets/HPolytope/vertices_list.jl +++ b/src/Sets/HPolytope/vertices_list.jl @@ -40,6 +40,8 @@ function vertices_list(P::HPolytope; backend=nothing, prune::Bool=true) if n == 1 return vertices_list_1d(P) elseif n == 2 + require(@__MODULE__, :LazySets; fun_name="vertices_list") + return vertices_list(convert(HPolygon, P; prune=prune)) end end diff --git a/src/Sets/HalfSpace/HalfSpaceModule.jl b/src/Sets/HalfSpace/HalfSpaceModule.jl index 7d99cc642c..8be1b1d47e 100644 --- a/src/Sets/HalfSpace/HalfSpaceModule.jl +++ b/src/Sets/HalfSpace/HalfSpaceModule.jl @@ -2,15 +2,15 @@ module HalfSpaceModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, LazySet, AbstractLinearMapAlgorithm, - @commutative +using ..LazySets: AbstractPolyhedron, LazySet, AbstractLinearMapAlgorithm +import LinearAlgebra +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: ismultiple, nonzero_indices, samedir +using ReachabilityBase.Commutative: @commutative using ReachabilityBase.Comparison: isapproxzero, _isapprox, _leq using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -import LinearAlgebra -using LinearAlgebra: dot @reexport import ..API: an_element, complement, constraints_list, dim, isbounded, isempty, isoperationtype, isuniversal, rand, diff --git a/src/Sets/Hyperplane/HyperplaneModule.jl b/src/Sets/Hyperplane/HyperplaneModule.jl index c6bec79531..6fe9bf08ec 100644 --- a/src/Sets/Hyperplane/HyperplaneModule.jl +++ b/src/Sets/Hyperplane/HyperplaneModule.jl @@ -2,15 +2,15 @@ module HyperplaneModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, HalfSpace, AbstractLinearMapAlgorithm, - @commutative, _linear_map_hrep, _non_element_halfspace, - _normalize_halfspace +using ..LazySets: AbstractPolyhedron, AbstractLinearMapAlgorithm, + _linear_map_hrep, _non_element_halfspace, _normalize_halfspace +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: nonzero_indices +using ReachabilityBase.Commutative: @commutative using ReachabilityBase.Comparison: _isapprox using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: an_element, constraints_list, dim, isbounded, isempty, isoperationtype, isuniversal, rand, reflect, distance, diff --git a/src/Sets/Hyperplane/constraints_list.jl b/src/Sets/Hyperplane/constraints_list.jl index 601f275c03..b8abdcec4b 100644 --- a/src/Sets/Hyperplane/constraints_list.jl +++ b/src/Sets/Hyperplane/constraints_list.jl @@ -17,5 +17,7 @@ end # internal helper function function _constraints_list_hyperplane(a::AbstractVector, b) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + return [HalfSpace(a, b), HalfSpace(-a, -b)] end diff --git a/src/Sets/Hyperplane/init_LazySets.jl b/src/Sets/Hyperplane/init_LazySets.jl index c196979555..b5742f883e 100644 --- a/src/Sets/Hyperplane/init_LazySets.jl +++ b/src/Sets/Hyperplane/init_LazySets.jl @@ -1 +1,2 @@ +using .LazySets.HalfSpaceModule: HalfSpace using .LazySets.UniverseModule: Universe diff --git a/src/Sets/Interval/IntervalModule.jl b/src/Sets/Interval/IntervalModule.jl index 2a1de2d198..24a938569d 100644 --- a/src/Sets/Interval/IntervalModule.jl +++ b/src/Sets/Interval/IntervalModule.jl @@ -1,16 +1,16 @@ module IntervalModule -using Reexport +using Reexport, Requires -using ..LazySets: AbstractHyperrectangle, LazySet, HalfSpace, Zonotope, UnionSet, +using ..LazySets: AbstractHyperrectangle, LazySet, UnionSet, _witness_result_empty -using ..LazySets.EmptySetModule: EmptySet using ..API: eltype, isconvextype, isempty +import IntervalArithmetic as IA using Random: AbstractRNG, GLOBAL_RNG -using ReachabilityBase.Arrays -using ReachabilityBase.Comparison +using ReachabilityBase.Arrays: SingleEntryVector +using ReachabilityBase.Comparison: isapproxzero, _isapprox, _leq using ReachabilityBase.Distribution: reseed! -import IntervalArithmetic as IA +using ReachabilityBase.Require: require @reexport import ..API: affine_map, an_element, center, complement, constraints_list, convex_hull, diameter, dim, exponential_map, extrema, high, ∈, @@ -167,4 +167,6 @@ function plot_recipe(x::Interval{N}, ε=zero(N)) where {N} return [min(x), max(x)], zeros(N, 2) end +include("init.jl") + end # module diff --git a/src/Sets/Interval/complement.jl b/src/Sets/Interval/complement.jl index 9d4f919b1f..51ede3d6ee 100644 --- a/src/Sets/Interval/complement.jl +++ b/src/Sets/Interval/complement.jl @@ -1,4 +1,6 @@ function complement(X::Interval) + require(@__MODULE__, :LazySets; fun_name="complement") + N = eltype(X) L = HalfSpace(SingleEntryVector(1, 1, one(N)), min(X)) H = HalfSpace(SingleEntryVector(1, 1, -one(N)), -max(X)) diff --git a/src/Sets/Interval/constraints_list.jl b/src/Sets/Interval/constraints_list.jl index d532a7f88b..b1b71e92ad 100644 --- a/src/Sets/Interval/constraints_list.jl +++ b/src/Sets/Interval/constraints_list.jl @@ -13,6 +13,8 @@ The list of constraints of the interval represented as two one-dimensional half-spaces. """ function constraints_list(x::Interval) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + N = eltype(x) constraints = Vector{HalfSpace{N,SingleEntryVector{N}}}(undef, 2) e₁ = SingleEntryVector(1, 1, one(N)) diff --git a/src/Sets/Interval/difference.jl b/src/Sets/Interval/difference.jl index 5a59876d2d..ad5c97a87d 100644 --- a/src/Sets/Interval/difference.jl +++ b/src/Sets/Interval/difference.jl @@ -60,6 +60,8 @@ function difference(X::Interval{N}, Y::Interval) where {N} flat_right = isflat(R) if flat_left && flat_right + require(@__MODULE__, :LazySets; fun_name="difference") + return EmptySet{N}(1) elseif flat_left && !flat_right return R diff --git a/src/Sets/Interval/init.jl b/src/Sets/Interval/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/Interval/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/Interval/init_LazySets.jl b/src/Sets/Interval/init_LazySets.jl new file mode 100644 index 0000000000..1237d48683 --- /dev/null +++ b/src/Sets/Interval/init_LazySets.jl @@ -0,0 +1,3 @@ +using .LazySets.EmptySetModule: EmptySet +using .LazySets.HalfSpaceModule: HalfSpace +using .LazySets.ZonotopeModule: Zonotope diff --git a/src/Sets/Interval/intersection.jl b/src/Sets/Interval/intersection.jl index 9f2357f5e9..691d2ecf23 100644 --- a/src/Sets/Interval/intersection.jl +++ b/src/Sets/Interval/intersection.jl @@ -17,6 +17,8 @@ function intersection(x::Interval, y::Interval) l = max(min(x), min(y)) h = min(max(x), max(y)) if l > h + require(@__MODULE__, :LazySets; fun_name="intersection") + N = promote_type(eltype(x), eltype(y)) return EmptySet{N}(1) else diff --git a/src/Sets/Interval/linear_map.jl b/src/Sets/Interval/linear_map.jl index 84776c9a69..53414b224b 100644 --- a/src/Sets/Interval/linear_map.jl +++ b/src/Sets/Interval/linear_map.jl @@ -35,6 +35,8 @@ function _linear_map_interval(M::AbstractMatrix, x::Interval) end function _linear_map_zonotope(M::AbstractMatrix, x::Interval) + require(@__MODULE__, :LazySets; fun_name="linear_map") + nout = size(M, 1) cx = _center(x) gx = cx - min(x) diff --git a/src/Sets/Interval/minkowski_difference.jl b/src/Sets/Interval/minkowski_difference.jl index d1d4a0687c..ef132c6a7f 100644 --- a/src/Sets/Interval/minkowski_difference.jl +++ b/src/Sets/Interval/minkowski_difference.jl @@ -17,6 +17,8 @@ function minkowski_difference(I1::Interval, I2::Interval) l = min(I1) - min(I2) h = max(I1) - max(I2) if h < l + require(@__MODULE__, :LazySets; fun_name="minkowski_difference") + N = promote_type(eltype(I1), eltype(I2)) return EmptySet{N}(1) end diff --git a/src/Sets/Line/LineModule.jl b/src/Sets/Line/LineModule.jl index bf161e59b6..81b3dc28df 100644 --- a/src/Sets/Line/LineModule.jl +++ b/src/Sets/Line/LineModule.jl @@ -2,20 +2,21 @@ module LineModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, HalfSpace, @commutative +using ..LazySets: AbstractPolyhedron +import LinearAlgebra +using LinearAlgebra: dot, nullspace using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: ismultiple using ReachabilityBase.Distribution: reseed! +using ReachabilityBase.Commutative: @commutative using ReachabilityBase.Comparison: _isapprox, isapproxzero using ReachabilityBase.Require -import LinearAlgebra -using LinearAlgebra: dot, nullspace @reexport import ..API: an_element, constraints_list, dim, isbounded, isempty, isoperationtype, isuniversal, project, rand, distance, ∈, linear_map, ρ, σ, translate! @reexport import ..LazySets: normalize -@reexport import ..LinearAlgebra: normalize! +@reexport import LinearAlgebra: normalize! @reexport using ..API export Line, diff --git a/src/Sets/Line/constraints_list.jl b/src/Sets/Line/constraints_list.jl index 0691fd6d5a..4cd1f76c3a 100644 --- a/src/Sets/Line/constraints_list.jl +++ b/src/Sets/Line/constraints_list.jl @@ -13,6 +13,8 @@ A list containing `2n-2` half-spaces whose intersection is `L`, where `n` is the ambient dimension of `L`. """ function constraints_list(L::Line) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + p = L.p n = length(p) d = reshape(L.d, 1, n) diff --git a/src/Sets/Line/init_LazySets.jl b/src/Sets/Line/init_LazySets.jl index 6aad752a32..5aeeaf0d12 100644 --- a/src/Sets/Line/init_LazySets.jl +++ b/src/Sets/Line/init_LazySets.jl @@ -1,2 +1,3 @@ +using .LazySets.HalfSpaceModule: HalfSpace using .LazySets.SingletonModule: Singleton using .LazySets.UniverseModule: Universe diff --git a/src/Sets/Line2D/Line2DModule.jl b/src/Sets/Line2D/Line2DModule.jl index 384ce6880b..78a1c33ded 100644 --- a/src/Sets/Line2D/Line2DModule.jl +++ b/src/Sets/Line2D/Line2DModule.jl @@ -5,12 +5,12 @@ using Reexport, Requires using ..LazySets: AbstractPolyhedron, AbstractLinearMapAlgorithm, _constraints_list_hyperplane, _linear_map_hrep, _non_element_halfspace, _σ_hyperplane_halfspace +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: nonzero_indices using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Comparison: _isapprox using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: an_element, constraints_list, dim, isbounded, isempty, isoperationtype, isuniversal, rand, ∈, project, σ, diff --git a/src/Sets/LineSegment/LineSegmentModule.jl b/src/Sets/LineSegment/LineSegmentModule.jl index 7fe7f1c8a6..9203c5fc89 100644 --- a/src/Sets/LineSegment/LineSegmentModule.jl +++ b/src/Sets/LineSegment/LineSegmentModule.jl @@ -1,13 +1,14 @@ module LineSegmentModule -using Reexport +using Reexport, Requires using ..LazySets: AbstractZonotope, Line2D, Singleton, EmptySet, right_turn +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Comparison: _isapprox, isapproxzero, _leq using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Iteration: EmptyIterator, SingletonIterator -using LinearAlgebra: dot +using ReachabilityBase.Require: require @reexport import ..API: an_element, center, constraints_list, dim, isoperationtype, rand, vertices_list, ∈, scale!, ρ, σ, @@ -41,4 +42,6 @@ include("intersection.jl") include("halfspace_left.jl") include("halfspace_right.jl") +include("init.jl") + end # module diff --git a/src/Sets/LineSegment/init.jl b/src/Sets/LineSegment/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/LineSegment/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/LineSegment/init_LazySets.jl b/src/Sets/LineSegment/init_LazySets.jl new file mode 100644 index 0000000000..14244a1651 --- /dev/null +++ b/src/Sets/LineSegment/init_LazySets.jl @@ -0,0 +1,3 @@ +using .LazySets.EmptySetModule: EmptySet +using .LazySets.Line2DModule: Line2D +using .LazySets.SingletonModule: Singleton diff --git a/src/Sets/LineSegment/intersection.jl b/src/Sets/LineSegment/intersection.jl index 9441831613..56835ab602 100644 --- a/src/Sets/LineSegment/intersection.jl +++ b/src/Sets/LineSegment/intersection.jl @@ -24,6 +24,7 @@ intersection. - Otherwise, if there is no intersection, an empty set is returned. """ function intersection(LS1::LineSegment, LS2::LineSegment) + require(@__MODULE__, :LazySets; fun_name="intersection") # cast each segment as a line L1 = Line2D(LS1.p, LS1.q) diff --git a/src/Sets/Polygon/PolygonModule.jl b/src/Sets/Polygon/PolygonModule.jl index 8246153ebd..0a776f1123 100644 --- a/src/Sets/Polygon/PolygonModule.jl +++ b/src/Sets/Polygon/PolygonModule.jl @@ -1,9 +1,9 @@ module PolygonModule -using Reexport +using Reexport, Requires -using ..LazySets: LazySet, VPolygon, _plot_recipe_2d_vlist -using ..LazySets.VPolytopeModule: _ρ_vertices, _σ_vertices +using ..LazySets: LazySet, _plot_recipe_2d_vlist +using ReachabilityBase.Require: require @reexport import ..API: convex_hull, dim, isconvextype, isbounded, isboundedtype, isempty, isoperationtype, ρ, σ @@ -29,4 +29,6 @@ function plot_recipe(P::Polygon{N}, ε=zero(N)) where {N} return _plot_recipe_2d_vlist(vlist, N) end +include("init.jl") + end # module diff --git a/src/Sets/Polygon/convex_hull.jl b/src/Sets/Polygon/convex_hull.jl index 564bcef317..59dd6cb01b 100644 --- a/src/Sets/Polygon/convex_hull.jl +++ b/src/Sets/Polygon/convex_hull.jl @@ -1,3 +1,5 @@ function convex_hull(P::Polygon) + require(@__MODULE__, :LazySets; fun_name="convex_hull") + return VPolygon(P.vertices) end diff --git a/src/Sets/Polygon/init.jl b/src/Sets/Polygon/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/Polygon/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/Polygon/init_LazySets.jl b/src/Sets/Polygon/init_LazySets.jl new file mode 100644 index 0000000000..2fd4c82a2e --- /dev/null +++ b/src/Sets/Polygon/init_LazySets.jl @@ -0,0 +1,2 @@ +using .LazySets.VPolygonModule: VPolygon +using .LazySets.VPolytopeModule: _ρ_vertices, _σ_vertices diff --git a/src/Sets/Polygon/support_function.jl b/src/Sets/Polygon/support_function.jl index 2a53596ea1..1f9bb4fa95 100644 --- a/src/Sets/Polygon/support_function.jl +++ b/src/Sets/Polygon/support_function.jl @@ -1,3 +1,5 @@ function ρ(d::AbstractVector, P::Polygon) + require(@__MODULE__, :LazySets; fun_name="ρ") + return _ρ_vertices(d, P.vertices) end diff --git a/src/Sets/Polygon/support_vector.jl b/src/Sets/Polygon/support_vector.jl index 73cbf9cbdd..b6ab8a6f8d 100644 --- a/src/Sets/Polygon/support_vector.jl +++ b/src/Sets/Polygon/support_vector.jl @@ -1,3 +1,5 @@ function σ(d::AbstractVector, P::Polygon) + require(@__MODULE__, :LazySets; fun_name="σ") + return _σ_vertices(d, P.vertices) end diff --git a/src/Sets/SimpleSparsePolynomialZonotope/SimpleSparsePolynomialZonotopeModule.jl b/src/Sets/SimpleSparsePolynomialZonotope/SimpleSparsePolynomialZonotopeModule.jl index 5db1ec4742..947b709af1 100644 --- a/src/Sets/SimpleSparsePolynomialZonotope/SimpleSparsePolynomialZonotopeModule.jl +++ b/src/Sets/SimpleSparsePolynomialZonotope/SimpleSparsePolynomialZonotopeModule.jl @@ -4,10 +4,10 @@ using Reexport using ..LazySets: AbstractSparsePolynomialZonotope, ngens_dep, nparams, _remove_redundant_generators_polyzono +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Comparison: isapproxzero -using LinearAlgebra: dot @reexport import ..API: convex_hull, center, isoperationtype, rand, linear_map @reexport import ..LazySets: expmat, genmat, genmat_dep, genmat_indep, ngens, diff --git a/src/Sets/SparsePolynomialZonotope/SparsePolynomialZonotopeModule.jl b/src/Sets/SparsePolynomialZonotope/SparsePolynomialZonotopeModule.jl index 1379109004..e3599ac82a 100644 --- a/src/Sets/SparsePolynomialZonotope/SparsePolynomialZonotopeModule.jl +++ b/src/Sets/SparsePolynomialZonotope/SparsePolynomialZonotopeModule.jl @@ -3,13 +3,13 @@ module SparsePolynomialZonotopeModule using Reexport, Requires using ..LazySets: AbstractSparsePolynomialZonotope, AbstractReductionMethod, - genmat, GIR05, order, Zonotope, _extrema_lowhigh, + genmat, GIR05, order, _extrema_lowhigh, _remove_redundant_generators_polyzono +import IntervalArithmetic as IA using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: remove_zero_columns using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -import IntervalArithmetic as IA @reexport import ..API: center, extrema, isoperationtype, rand, linear_map, ρ, translate diff --git a/src/Sets/SparsePolynomialZonotope/init_LazySets.jl b/src/Sets/SparsePolynomialZonotope/init_LazySets.jl index 0e18eb48d5..3c3aa3e2c0 100644 --- a/src/Sets/SparsePolynomialZonotope/init_LazySets.jl +++ b/src/Sets/SparsePolynomialZonotope/init_LazySets.jl @@ -1,2 +1,3 @@ using .LazySets.SimpleSparsePolynomialZonotopeModule: SimpleSparsePolynomialZonotope +using .LazySets.ZonotopeModule: Zonotope using .LazySets.Approximations: overapproximate diff --git a/src/Sets/SparsePolynomialZonotope/reduce_order.jl b/src/Sets/SparsePolynomialZonotope/reduce_order.jl index 405437c637..835a1ca9a9 100644 --- a/src/Sets/SparsePolynomialZonotope/reduce_order.jl +++ b/src/Sets/SparsePolynomialZonotope/reduce_order.jl @@ -31,6 +31,8 @@ function reduce_order(P::SparsePolynomialZonotope, r::Real, return P end + require(@__MODULE__, :LazySets; fun_name="reduce_order") + n = dim(P) h = ngens_dep(P) q = ngens_indep(P) diff --git a/src/Sets/Star/StarModule.jl b/src/Sets/Star/StarModule.jl index d78ed1fff6..7788c14903 100644 --- a/src/Sets/Star/StarModule.jl +++ b/src/Sets/Star/StarModule.jl @@ -2,12 +2,13 @@ module StarModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, HPolytope +using ..LazySets: AbstractPolyhedron +using ..HPolytopeModule: HPolytope +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: At_mul_B, to_matrix, DEFAULT_COND_TOL using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: an_element, center, constraints_list, dim, isbounded, isempty, isoperationtype, rand, vertices_list, diff --git a/src/Sets/Tetrahedron/TetrahedronModule.jl b/src/Sets/Tetrahedron/TetrahedronModule.jl index 176d4c92d4..a40701dce3 100644 --- a/src/Sets/Tetrahedron/TetrahedronModule.jl +++ b/src/Sets/Tetrahedron/TetrahedronModule.jl @@ -1,11 +1,12 @@ module TetrahedronModule -using Reexport +using Reexport, Requires -using ..LazySets: AbstractPolytope, VPolytope +using ..LazySets: AbstractPolytope +using LinearAlgebra: dot, cross using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Comparison: isapproxzero -using LinearAlgebra: dot, cross +using ReachabilityBase.Require: require @reexport import ..API: constraints_list, dim, isoperationtype, rand, ∈, σ @reexport using ..API @@ -21,4 +22,6 @@ include("rand.jl") include("in.jl") include("support_vector.jl") +include("init.jl") + end # module diff --git a/src/Sets/Tetrahedron/constraints_list.jl b/src/Sets/Tetrahedron/constraints_list.jl index 85bb0a4424..275fbcbd6d 100644 --- a/src/Sets/Tetrahedron/constraints_list.jl +++ b/src/Sets/Tetrahedron/constraints_list.jl @@ -1,3 +1,5 @@ function constraints_list(T::Tetrahedron) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + return constraints_list(convert(VPolytope, T)) end diff --git a/src/Sets/Tetrahedron/init.jl b/src/Sets/Tetrahedron/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/Tetrahedron/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/Tetrahedron/init_LazySets.jl b/src/Sets/Tetrahedron/init_LazySets.jl new file mode 100644 index 0000000000..e1d13e9e0c --- /dev/null +++ b/src/Sets/Tetrahedron/init_LazySets.jl @@ -0,0 +1 @@ +using .LazySets.VPolytopeModule: VPolytope diff --git a/src/Sets/Tetrahedron/rand.jl b/src/Sets/Tetrahedron/rand.jl index b2fef854b0..1749b2ead8 100644 --- a/src/Sets/Tetrahedron/rand.jl +++ b/src/Sets/Tetrahedron/rand.jl @@ -1,5 +1,7 @@ function rand(::Type{Tetrahedron}; N::Type{<:Real}=Float64, rng::AbstractRNG=GLOBAL_RNG, seed::Union{Int,Nothing}=nothing) + require(@__MODULE__, :LazySets; fun_name="rand") + P = rand(VPolytope; N=N, dim=3, rng=rng, seed=seed, num_vertices=4) vertices = P.vertices return Tetrahedron(vertices) diff --git a/src/Sets/Tetrahedron/support_vector.jl b/src/Sets/Tetrahedron/support_vector.jl index fd6e5ac5ce..edfbc8027e 100644 --- a/src/Sets/Tetrahedron/support_vector.jl +++ b/src/Sets/Tetrahedron/support_vector.jl @@ -1,12 +1,12 @@ """ - σ(d::AbstractVector, P::VPolytope) + σ(d::AbstractVector, T::Tetrahedron) Return a support vector of a tetrahedron in a given direction. ### Input - `d` -- direction -- `P` -- tetrahedron +- `T` -- tetrahedron ### Output @@ -17,5 +17,7 @@ A support vector in the given direction. Currently falls back to the `VPolytope` implementation. """ function σ(d::AbstractVector, T::Tetrahedron) + require(@__MODULE__, :LazySets; fun_name="σ") + return σ(d, convert(VPolytope, T)) end diff --git a/src/Sets/Universe/UniverseModule.jl b/src/Sets/Universe/UniverseModule.jl index df432b6655..7acdeb121e 100644 --- a/src/Sets/Universe/UniverseModule.jl +++ b/src/Sets/Universe/UniverseModule.jl @@ -2,11 +2,11 @@ module UniverseModule using Reexport, Requires -using ..LazySets: AbstractPolyhedron, HalfSpace, default_polyhedra_backend +using ..LazySets: AbstractPolyhedron, default_polyhedra_backend using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Iteration: EmptyIterator -using ReachabilityBase.Require +using ReachabilityBase.Require: require @reexport import ..API: an_element, complement, constraints, constraints_list, diameter, dim, isbounded, isboundedtype, isempty, diff --git a/src/Sets/Universe/constraints_list.jl b/src/Sets/Universe/constraints_list.jl index 820f1b6cbc..b301609447 100644 --- a/src/Sets/Universe/constraints_list.jl +++ b/src/Sets/Universe/constraints_list.jl @@ -12,5 +12,7 @@ Return the list of constraints defining a universe. The empty list of constraints, as the universe is unconstrained. """ function constraints_list(U::Universe{N}) where {N} + require(@__MODULE__, :LazySets; fun_name="constraints_list") + return HalfSpace{N,Vector{N}}[] end diff --git a/src/Sets/Universe/init_LazySets.jl b/src/Sets/Universe/init_LazySets.jl index e85bf07ec1..7a5d76f822 100644 --- a/src/Sets/Universe/init_LazySets.jl +++ b/src/Sets/Universe/init_LazySets.jl @@ -1,2 +1,3 @@ using .LazySets.EmptySetModule: EmptySet +using .LazySets.HalfSpaceModule: HalfSpace using .LazySets.ZeroSetModule: ZeroSet diff --git a/src/Sets/VPolygon/VPolygonModule.jl b/src/Sets/VPolygon/VPolygonModule.jl index b48c465cbe..db47faeeba 100644 --- a/src/Sets/VPolygon/VPolygonModule.jl +++ b/src/Sets/VPolygon/VPolygonModule.jl @@ -2,13 +2,14 @@ module VPolygonModule using Reexport, Requires -using ..LazySets: AbstractPolygon, AbstractHPolygon, HPolygon, convex_hull, +using ..LazySets: AbstractPolygon, AbstractHPolygon, convex_hull, halfspace_left, is_right_turn, _area_vlist, _linear_map_vrep +using ..HPolygonModule: HPolygon +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG, shuffle using ReachabilityBase.Arrays: isabove, rand_pos_neg_zerosum_vector using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: an_element, area, constraints_list, isoperationtype, rand, vertices_list, ∈, linear_map, permute, project, diff --git a/src/Sets/VPolytope/VPolytopeModule.jl b/src/Sets/VPolytope/VPolytopeModule.jl index 646cf6a30d..ac77ad84c1 100644 --- a/src/Sets/VPolytope/VPolytopeModule.jl +++ b/src/Sets/VPolytope/VPolytopeModule.jl @@ -2,16 +2,15 @@ module VPolytopeModule using Reexport, Requires -using ..LazySets: AbstractPolytope, HPolytope, VPolygon, LinearMapVRep, - default_lp_solver, default_lp_solver_polyhedra, - default_polyhedra_backend, is_lp_infeasible, is_lp_optimal, - linprog +using ..LazySets: AbstractPolytope, LinearMapVRep, default_lp_solver, + default_lp_solver_polyhedra, default_polyhedra_backend, + is_lp_infeasible, is_lp_optimal, linprog +using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: projection_matrix using ReachabilityBase.Comparison: _ztol using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: dot @reexport import ..API: constraints_list, dim, isoperationtype, rand, reflect, vertices_list, ∈, linear_map, permute, project, scale!, diff --git a/src/Sets/VPolytope/constraints_list.jl b/src/Sets/VPolytope/constraints_list.jl index a73b9babb2..236e126adf 100644 --- a/src/Sets/VPolytope/constraints_list.jl +++ b/src/Sets/VPolytope/constraints_list.jl @@ -16,6 +16,8 @@ A list of constraints of the polytope. We use `tohrep` to compute the constraint representation of `P`. """ function constraints_list(P::VPolytope) + require(@__MODULE__, :LazySets; fun_name="constraints_list") + n = dim(P) if n == 1 return constraints_list(convert(Interval, P)) diff --git a/src/Sets/VPolytope/init_LazySets.jl b/src/Sets/VPolytope/init_LazySets.jl index ffe7e8e76d..9e45899837 100644 --- a/src/Sets/VPolytope/init_LazySets.jl +++ b/src/Sets/VPolytope/init_LazySets.jl @@ -1,2 +1,4 @@ using .LazySets.IntervalModule: Interval +using .LazySets.HPolytopeModule: HPolytope +using .LazySets.VPolygonModule: VPolygon using .LazySets: convex_hull! diff --git a/src/Sets/VPolytope/project.jl b/src/Sets/VPolytope/project.jl index ec79c429f0..ee8b12395d 100644 --- a/src/Sets/VPolytope/project.jl +++ b/src/Sets/VPolytope/project.jl @@ -1,4 +1,6 @@ function project(P::VPolytope, block::AbstractVector{Int}; kwargs...) + require(@__MODULE__, :LazySets; fun_name="project") + if isempty(P.vertices) return P end @@ -13,6 +15,7 @@ function project(P::VPolytope, block::AbstractVector{Int}; kwargs...) πvertices = broadcast(v -> M * v, P.vertices) if m == 2 + return VPolygon(πvertices; apply_convex_hull=true) else return VPolytope(πvertices) diff --git a/src/Sets/VPolytope/tohrep.jl b/src/Sets/VPolytope/tohrep.jl index 40ceec3630..12908cf07c 100644 --- a/src/Sets/VPolytope/tohrep.jl +++ b/src/Sets/VPolytope/tohrep.jl @@ -26,6 +26,8 @@ function tohrep(P::VPolytope{N}; backend=default_polyhedra_backend(P)) where {N} @assert !isempty(P.vertices) "cannot convert an empty polytope in vertex " * "representation to constraint representation" + require(@__MODULE__, :LazySets; fun_name="tohrep") require(@__MODULE__, :Polyhedra; fun_name="tohrep") + return convert(HPolytope, polyhedron(P; backend=backend)) end diff --git a/src/Sets/ZeroSet/ZeroSetModule.jl b/src/Sets/ZeroSet/ZeroSetModule.jl index 8e45eb2b73..94e48f4794 100644 --- a/src/Sets/ZeroSet/ZeroSetModule.jl +++ b/src/Sets/ZeroSet/ZeroSetModule.jl @@ -1,10 +1,11 @@ module ZeroSetModule -using Reexport +using Reexport, Requires using ..LazySets: AbstractSingleton, Singleton using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! +using ReachabilityBase.Require: require @reexport import ..API: dim, isoperationtype, rand, rectify, reflect, ∈, linear_map, scale, scale!, ρ, translate, minkowski_sum @@ -26,8 +27,10 @@ include("scale.jl") include("support_function.jl") include("translate.jl") +include("minkowski_sum.jl") + include("element.jl") -include("minkowski_sum.jl") +include("init.jl") end # module diff --git a/src/Sets/ZeroSet/init.jl b/src/Sets/ZeroSet/init.jl new file mode 100644 index 0000000000..ddd845644b --- /dev/null +++ b/src/Sets/ZeroSet/init.jl @@ -0,0 +1,3 @@ +function __init__() + @require LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" include("init_LazySets.jl") +end diff --git a/src/Sets/ZeroSet/init_LazySets.jl b/src/Sets/ZeroSet/init_LazySets.jl new file mode 100644 index 0000000000..7cfe9eea9e --- /dev/null +++ b/src/Sets/ZeroSet/init_LazySets.jl @@ -0,0 +1 @@ +using .LazySets.SingletonModule: Singleton diff --git a/src/Sets/ZeroSet/translate.jl b/src/Sets/ZeroSet/translate.jl index dfe89e5ed3..866d95f327 100644 --- a/src/Sets/ZeroSet/translate.jl +++ b/src/Sets/ZeroSet/translate.jl @@ -13,7 +13,10 @@ Translate (i.e., shift) a zero set by a given vector. A singleton containing the vector `v`. """ function translate(Z::ZeroSet, v::AbstractVector) + require(@__MODULE__, :LazySets; fun_name="translate") + @assert length(v) == dim(Z) "cannot translate a $(dim(Z))-dimensional " * "set by a $(length(v))-dimensional vector" + return Singleton(v) end diff --git a/src/Sets/Zonotope/ZonotopeModule.jl b/src/Sets/Zonotope/ZonotopeModule.jl index abfc017e28..431be5bb48 100644 --- a/src/Sets/Zonotope/ZonotopeModule.jl +++ b/src/Sets/Zonotope/ZonotopeModule.jl @@ -4,12 +4,12 @@ using Reexport, Requires using ..LazySets: AbstractZonotope, generators_fallback, _vertices_list_zonotope_iterative +using LinearAlgebra: mul! using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: ismultiple, remove_zero_columns, to_matrix, vector_type using ReachabilityBase.Distribution: reseed! using ReachabilityBase.Require: require -using LinearAlgebra: mul! @reexport import ..API: center, high, isoperationtype, low, rand, vertices_list, permute, scale!, translate!