Skip to content

Commit a269639

Browse files
committed
added is_valid methods and exceptions
1 parent 6c58408 commit a269639

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

docs/src/reference/dynamic_functions/dynamic_variables.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ supports_dynamic_variable
1010
UnsupportedDynamicVariable
1111
add_dynamic_variable
1212
AddDynamicVariableNotAllowed
13+
MOI.is_valid(::MOI.ModelLike, ::DynamicVariableIndex)
14+
InvalidDynamicVariableIndex
1315
```

docs/src/reference/dynamic_functions/phases.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ supports_phase
1010
UnsupportedPhase
1111
AddPhaseNotAllowed
1212
add_phase
13+
MOI.is_valid(::MOI.ModelLike, ::PhaseIndex)
14+
InvalidPhaseIndex
1315
```

src/dynamic_functions/dynamic_variables.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@ An [`AddDynamicVariableNotAllowed`](@ref) is thrown if a dynamic variable cannot
6565
to `model` in its current state.
6666
"""
6767
add_dynamic_variable(::MOI.ModelLike, ::PhaseIndex) =
68-
throw(AddDynamicVariableNotAllowed(""))
68+
throw(AddDynamicVariableNotAllowed(""))
69+
70+
"""
71+
MOI.is_valid(model::MOI.ModelLike, index::DynamicVariableIndex)::Bool
72+
73+
Return a `Bool` indicating whether `index` refers to a valid object in `model`.
74+
"""
75+
MOI.is_valid(model::MOI.ModelLike, index::DynamicVariableIndex)
76+
77+
"""
78+
InvalidDynamicVariableIndex(index::DynamicVariableIndex)
79+
80+
An error indicating that the dynamic variable `index` is invalid.
81+
"""
82+
struct InvalidDynamicVariableIndex <: Exception
83+
index::DynamicVariableIndex
84+
end

src/dynamic_functions/phases.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,20 @@ in its current state.
6161
"""
6262
add_phase(::MOI.ModelLike) = throw(AddPhaseNotAllowed(""))
6363

64-
MOI.operation_name(::AddPhaseNotAllowed) = "Adding a phase"
64+
MOI.operation_name(::AddPhaseNotAllowed) = "Adding a phase"
65+
66+
"""
67+
MOI.is_valid(model::MOI.ModelLike, index::PhaseIndex)::Bool
68+
69+
Return a `Bool` indicating whether `index` refers to a valid object in `model`.
70+
"""
71+
MOI.is_valid(model::MOI.ModelLike, index::PhaseIndex)
72+
73+
"""
74+
InvalidPhaseIndex(index::PhaseIndex)
75+
76+
An error indicating that the phase `index` is invalid.
77+
"""
78+
struct InvalidPhaseIndex <: Exception
79+
index::PhaseIndex
80+
end

0 commit comments

Comments
 (0)