1
+ """
2
+ AbstractDomain
3
+
4
+ Abstract supertype for domains.
5
+ """
6
+ abstract type AbstractDomain end
7
+
8
+ """
9
+ DomainIndex{D}
10
+
11
+ A type-safe wrapper for `Int64` for use in referencing domains.
12
+ The parameter `D` is the type of the domain.
13
+ """
14
+ struct DomainIndex{D}
15
+ value:: Int64
16
+ end
17
+
1
18
"""
2
19
supports_domain(
3
- model::MOI. ModelLike,
4
- ::Type{<:AbstractDomain },
5
- )::Bool
20
+ model::ModelLike,
21
+ ::Type{D },
22
+ ) where {D<:AbstractDomain}
6
23
7
- Returns true if a domain type is supported and false ortherwise .
24
+ Return a `Bool` indicating whether `model` supports domains of type `D` .
8
25
"""
9
- function supports_domain (
10
- :: MOI.ModelLike ,
11
- :: Type{<:AbstractDomain} )
26
+ function supports_domain (:: Model , :: Type{<:AbstractDomain} )
12
27
return false
13
28
end
14
29
15
30
"""
16
- FixedDomain{T} <: AbstractDomain
17
- initial::T
18
- final::T
31
+ struct UnsupportedDomain{D<:AbstractDomain} <: MOI.UnsupportedError
32
+ message::String
33
+ end
34
+
35
+ An error indicating that domains of type `D` are not supported by the model,
36
+ that is, that [`supports_domain`](@ref) returns `false`.
37
+ """
38
+ struct UnsupportedDomain{D<: AbstractDomain } <: MOI.UnsupportedError
39
+ message:: String
40
+ end
41
+
42
+ """
43
+ struct AddDomainNotAllowed{D<:AbstractDomain} <: MOI.NotAllowedError
44
+ message::String
45
+ end
46
+
47
+ An error indicating that domains of type `D` are supported but cannot be added
48
+ to the current state of the model.
49
+ """
50
+ struct AddDomainNotAllowed{D<: AbstractDomain } <: MOI.NotAllowedError
51
+ message:: String
52
+ end
53
+ AddDomainNotAllowed {D} () where {D} = AddDomainNotAllowed {D} (" " )
54
+
55
+ """
56
+ add_domain()
57
+
58
+ Add `domain` to the model. An [`UnsupportedDomain`](@ref) error is thrown if
59
+ `model` does not support
60
+ """
61
+ function add_domain (model:: MOI.ModelLike , domain:: AbstractDomain )
62
+ return throw_add_domain_error_fallback (model, domain)
63
+ end
64
+
65
+ function throw_add_domain_error_fallback (
66
+ model:: MOI.ModelLike ,
67
+ domain:: AbstractDomain ;
68
+ error_if_supported = AddDomainNotAllowed {typeof(domain)} (),
69
+ )
70
+ if supports_domain (model, typeof (domain))
71
+ throw (error_if_supported)
72
+ else
73
+ throw (UnsupportedConstraint {typeof(domain)} ())
74
+ end
75
+ end
76
+
77
+ """
78
+ struct Interval{T0, TF} <: AbstractDomain
79
+ t_0::T0
80
+ t_f::TF
19
81
end
20
82
21
- A domain type with fixed initial and final limits.
83
+ A one-dimensional domain where `t_0` and `t_f` may be real numbers or variable indices.
22
84
"""
23
- struct FixedDomain{T } <: AbstractDomain
24
- initial :: T
25
- final :: T
85
+ struct Interval{T0, TF } <: AbstractDomain
86
+ t_0 :: T0
87
+ t_f :: TF
26
88
end
0 commit comments