Skip to content

Commit 08aabf1

Browse files
committed
Upversioned julia to 1.10, updated dynamic variables
1 parent a0c3111 commit 08aabf1

4 files changed

Lines changed: 142 additions & 96 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
version:
26-
- '1.6'
26+
- '1.10'
2727
os:
2828
- ubuntu-latest
2929
arch:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
.vscode/
12
*.jl.*.cov
23
*.jl.cov
34
*.jl.mem
45
/Manifest.toml
56
/docs/Manifest.toml
6-
/docs/build/
7+
/docs/build/
Lines changed: 90 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,172 @@
11
"""
2-
DynamicVariableIndex(value::Int64, phase::DynamicVariableIndex)
2+
DynamicVariableIndex(value::Int64, phase::PhaseIndex)
33
4-
An object for use in referencing dynamic variables in a model.
4+
Represent the dynamic variable ``\boldsymbol{y}_j(\cdot)`` in an expression.
55
6-
It is a sub-type of [`AbstractDynamicFunction`](@ref). It represents a
7-
dynamic variable ``t_i \\mapsto y_j(t_i)`` defined in the domain
8-
``[t_i^0, t_i^f]``. The `Int64` index value is stored in the `value` field.
6+
It is a subtype of [`AbstractDynamicFunction`](@ref).
97
To allow for deletion, indices need not be consecutive.
108
"""
119
struct DynamicVariableIndex <: AbstractDynamicFunction
1210
value::Int64
1311
phase::PhaseIndex
1412
end
1513

16-
function MOI.Utilities._to_string(
17-
::MOI.Utilities._PrintOptions,
18-
::MOI.ModelLike,
19-
index::DynamicVariableIndex,
20-
)
21-
return string("DynamicVariableIndex(", index.value, ")")
14+
function Base.show(io::IO, ::MIME"text/plain", dyn_var::DynamicVariableIndex)
15+
return print(io, "DOI.DynamicVariableIndex($(dyn_var.value))")
2216
end
2317

2418
phase_index(dyn_var::DynamicVariableIndex) = dyn_var.phase
2519

20+
## Dynamic Variables in Models
21+
2622
"""
27-
supports_dynamic_variable(model::MOI.ModelLike)::Bool
23+
supports_dynamic_variables(model::MOI.ModelLike)::Bool
2824
29-
Return a `Bool` indicating whether `model` supports dynamic variables.
25+
Indicate whether `model` supports dynamic variables.
3026
"""
31-
supports_dynamic_variable(::MOI.ModelLike) = false
27+
supports_dynamic_variables(::MOI.ModelLike) = false
3228

3329
"""
34-
UnsupportedDynamicVariable(message::String)
30+
UnsupportedDynamicVariablesError(message::String)
3531
36-
An error indicating that dynamic variables are not supported by the model.
32+
The model does not support dynamic variables.
3733
38-
That is, that [`supports_dynamic_variable`](@ref) returns `false`. The message
39-
`String` is stored in the `message` field.
34+
That is, [`supports_dynamic_variables`](@ref) returns `false`.
4035
"""
41-
struct UnsupportedDynamicVariable <: MOI.UnsupportedError
36+
struct UnsupportedDynamicVariablesError <: MOI.UnsupportedError
4237
message::String
4338
end
4439

4540
"""
46-
AddDynamicVariableNotAllowed(message::String)
41+
add_dynamic_variable(model::MOI.ModelLike, phase::PhaseIndex)::DynamicVariableIndex
4742
48-
An error indicating that dynamic variables cannot be added to the model
49-
in its current state.
43+
Add a dynamic variable to `model`, returning a [`DynamicVariableIndex`](@ref).
5044
51-
The `String` error message is stored in the `message` field.
45+
An [`AddDynamicVariableNotAllowedError`](@ref) is thrown if a dynamic variable cannot be
46+
added to `model` in its current state.
5247
"""
53-
struct AddDynamicVariableNotAllowed <: MOI.NotAllowedError
54-
message::String
48+
function add_dynamic_variable(::MOI.ModelLike, ::PhaseIndex)
49+
return throw(AddDynamicVariableNotAllowedError(""))
5550
end
5651

57-
MOI.operation_name(::AddDynamicVariableNotAllowed) = "Adding a dynamic variable"
52+
"""
53+
AddDynamicVariableNotAllowedError(message::String)
5854
55+
Dynamic variables cannot be added to the model in its current state.
5956
"""
60-
add_dynamic_variable(model::MOI.ModelLike, phase::PhaseIndex)::DynamicVariableIndex
57+
struct AddDynamicVariableNotAllowedError <: MOI.NotAllowedError
58+
message::String
59+
end
6160

62-
Add a dynamic variable to `model`, returning a [`DynamicVariableIndex`](@ref).
61+
MOI.operation_name(::AddDynamicVariableNotAllowedError) = "Adding a dynamic variable"
6362

64-
An [`AddDynamicVariableNotAllowed`](@ref) is thrown if a dynamic variable cannot be added
65-
to `model` in its current state.
6663
"""
67-
add_dynamic_variable(::MOI.ModelLike, ::PhaseIndex) =
68-
throw(AddDynamicVariableNotAllowed(""))
64+
MOI.is_valid(model::MOI.ModelLike, dyn_var::DynamicVariableIndex)::Bool
6965
66+
Indicate whether `dyn_var` refers to a valid [`DynamicVariableIndex`](@ref) in `model`.
7067
"""
71-
MOI.is_valid(model::MOI.ModelLike, index::DynamicVariableIndex)::Bool
68+
MOI.is_valid(::MOI.ModelLike, ::DynamicVariableIndex) = false
7269

73-
Return a `Bool` indicating whether `index` refers to a valid [`DynamicVariableIndex`](@ref)
74-
in `model`.
7570
"""
76-
MOI.is_valid(model::MOI.ModelLike, index::DynamicVariableIndex) = false
71+
InvalidDynamicVariableError(dyn_var::DynamicVariableIndex)
7772
73+
The dynamic variable `dyn_var` is not valid in the model.
7874
"""
79-
InvalidDynamicVariableIndex(index::DynamicVariableIndex)
75+
struct InvalidDynamicVariableError <: Exception
76+
dyn_var::DynamicVariableIndex
77+
end
78+
79+
## Dynamic Variable Attributes
8080

81-
An error indicating that the dynamic variable `index` is not valid.
8281
"""
83-
struct InvalidDynamicVariableIndex <: Exception
84-
index::DynamicVariableIndex
85-
end
82+
AbstractDynamicVariableAttribute
8683
87-
## Attributes
84+
Supertype for dynamic variable attributes.
85+
"""
86+
abstract type AbstractDynamicVariableAttribute end
8887

8988
"""
9089
MOI.supports(
9190
model::MOI.ModelLike,
92-
attr::MOI.AbstractVariableAttribute,
93-
::Type{DynamicVariableIndex},
91+
attr::MOI.AbstractDynamicVariableAttribute,
9492
)::Bool
9593
96-
Return a `Bool` indicating whether `model` supports the attribute `attr` for
97-
[`DynamicVariableIndex`](@ref)s.
94+
Indicate whether `model` supports the dynamic variable attribute `attr`.
9895
"""
99-
function MOI.supports(
100-
::MOI.ModelLike,
101-
::MOI.AbstractVariableAttribute,
102-
::Type{DynamicVariableIndex},
103-
)
96+
function MOI.supports(::MOI.ModelLike, ::MOI.AbstractDynamicVariableAttribute)
10497
return false
10598
end
10699

107100
"""
108101
MOI.set(
109102
model::MOI.ModelLike,
110-
attr::MOI.AbstractVariableAttribute,
111-
index::DynamicVariableIndex,
112-
value,
103+
attr::MOI.AbstractDynamicVariableAttribute,
104+
dyn_var::DynamicVariableIndex,
105+
value::Any,
113106
)
114107
115-
Assign `value` to the attribute `attr` of dynamic variable `index` in model `model`.
116-
117-
An [`MOI.UnsupportedAttribute`](@extref MathOptInterface.UnsupportedAttribute)
118-
error is thrown if `model` does not support the attribute `attr`, and a
119-
[`MOI.SetAttributeNotAllowed`](@extref MathOptInterface.SetAttributeNotAllowed)
120-
error is thrown if it supports the attribute `attr` but it cannot be set.
108+
Assign `value` to the attribute `attr` of dynamic variable `dyn_var` in model `model`.
121109
"""
122110
function MOI.set(
123111
model::MOI.ModelLike,
124-
attr::MOI.AbstractVariableAttribute,
125-
index::DynamicVariableIndex,
126-
::Any,
112+
attr::MOI.AbstractDynamicVariableAttribute,
113+
::DynamicVariableIndex,
114+
value::Any,
127115
)
128-
if MOI.supports(model, attr, typeof(index))
129-
throw(MOI.SetAttributeNotAllowed(attr))
116+
if MOI.supports(model, attr)
117+
throw(ArgumentError(
118+
"$(typeof(model)) does not currently allow setting the attribute $(attr) to $(value)."
119+
))
130120
else
131-
throw(MOI.UnsupportedAttribute(attr))
121+
throw(ArgumentError(
122+
"$(typeof(model)) does not support attribute $(attr)."
123+
))
132124
end
133125
return nothing
134126
end
135127

136128
"""
137129
MOI.get(
138130
model::MOI.ModelLike,
139-
attr::MOI.AbstractVariableAttribute,
140-
index::DynamicVariableIndex,
131+
attr::MOI.AbstractDynamicVariableAttribute,
132+
dyn_var::DynamicVariableIndex,
141133
)
142134
143-
Return the value of the attribute `attr` set to dynamic variable `index` in model `model`.
135+
Return the value of the attribute `attr` set to dynamic variable `dyn_var` in model `model`.
144136
145137
If the attribute `attr` is not supported by `model` then an error should be thrown.
146138
If the attribute is supported but has not been set, `nothing` is returned.
147139
"""
148140
function MOI.get(
149141
model::MOI.ModelLike,
150-
attr::MOI.AbstractVariableAttribute,
151-
index::DynamicVariableIndex,
142+
attr::MOI.AbstractDynamicVariableAttribute,
143+
dyn_var::DynamicVariableIndex,
152144
)
153-
throw(MOI.GetAttributeNotAllowed(
154-
attr,
155-
"$(typeof(model)) does not support getting the attribute $(attr) for $(typeof(index)).",
156-
))
145+
throw(ArgumentError(
146+
"$(typeof(model)) does not support getting the attribute $(attr) for $(typeof(dyn_var))."
147+
))
157148
return nothing
158-
end
149+
end
150+
151+
"""
152+
DynamicVariableName
153+
154+
A dynamic variable attribute for a `String` identifying a dynamic variable.
155+
"""
156+
struct DynamicVariableName <: AbstractDynamicVariableAttribute end
157+
158+
"""
159+
DynamicVariableInitialStart
160+
161+
A dynamic variable attribute for the start value of the dynamic variable at the initial
162+
phase boundary.
163+
"""
164+
struct DynamicVariableInitialPrimalStart <: AbstractDynamicVariableAttribute end
165+
166+
"""
167+
DynamicVariableFinalStart
168+
169+
A dynamic variable attribute for the start value of the dynamic variable at the final phase
170+
boundary.
171+
"""
172+
struct DynamicVariableFinalStart <: AbstractDynamicVariableAttribute end

0 commit comments

Comments
 (0)