Skip to content

Commit 9b40b6d

Browse files
committed
added domain-related functions and docs
1 parent 996102f commit 9b40b6d

File tree

4 files changed

+99
-20
lines changed

4 files changed

+99
-20
lines changed

docs/make.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ using Documenter
33

44
DocMeta.setdocmeta!(DynOptInterface, :DocTestSetup, :(using DynOptInterface); recursive=true)
55

6+
const _PAGES = [
7+
"API Reference" => [
8+
"reference/domains.md",
9+
],
10+
]
11+
612
makedocs(;
713
modules=[DynOptInterface],
814
authors="Eduardo M. G. Vila <72969764+e-duar-do@users.noreply.github.com> and contributors",
@@ -12,12 +18,10 @@ makedocs(;
1218
edit_link="dev",
1319
assets=String[],
1420
),
15-
pages=[
16-
"Home" => "index.md",
17-
],
21+
pages=_PAGES,
1822
)
1923

2024
deploydocs(;
2125
repo="github.com/JuDO-dev/DynOptInterface.jl",
2226
devbranch="dev",
23-
)
27+
)

docs/src/reference/domains.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```@meta
2+
CurrentModule = DynOptInterface
3+
```
4+
5+
# Domains
6+
7+
```@docs
8+
AbstractDomain
9+
DomainIndex
10+
supports_domain
11+
UnsupportedDomain
12+
AddDomainNotAllowed
13+
add_domain
14+
Interval
15+
```

src/DynOptInterface.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module DynOptInterface
22

33
import MathOptInterface as MOI
44

5-
abstract type AbstractDomain end
6-
75
include("domains.jl")
86

97
end

src/domains.jl

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,88 @@
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+
118
"""
219
supports_domain(
3-
model::MOI.ModelLike,
4-
::Type{<:AbstractDomain},
5-
)::Bool
20+
model::ModelLike,
21+
::Type{D},
22+
) where {D<:AbstractDomain}
623
7-
Returns true if a domain type is supported and false ortherwise.
24+
Return a `Bool` indicating whether `model` supports domains of type `D`.
825
"""
9-
function supports_domain(
10-
::MOI.ModelLike,
11-
::Type{<:AbstractDomain})
26+
function supports_domain(::Model, ::Type{<:AbstractDomain})
1227
return false
1328
end
1429

1530
"""
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
1981
end
2082
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.
2284
"""
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
2688
end

0 commit comments

Comments
 (0)