@@ -75,24 +75,53 @@ operation_name(err::SetAttributeNotAllowed) = "Setting attribute $(err.attr)"
75
75
message (err:: SetAttributeNotAllowed ) = err. message
76
76
77
77
"""
78
- struct AddAttributeNotAllowed{AttrType} <: NotAllowedError
79
- attr::AttrType
78
+ AbstractSubmittable
79
+
80
+ Abstract supertype for objects that can be submitted to the model.
81
+ """
82
+ abstract type AbstractSubmittable end
83
+
84
+ # This allows to use submittable in broadcast calls without the need to embed
85
+ # it in a `Ref`.
86
+ Base. broadcastable (sub:: AbstractSubmittable ) = Ref (sub)
87
+
88
+ """
89
+ struct UnsupportedSubmittable{SubmitType} <: UnsupportedError
90
+ sub::SubmitType
91
+ message::String
92
+ end
93
+
94
+ An error indicating that the submittable `sub` is not supported by the model,
95
+ i.e. that [`supports`](@ref) returns `false`.
96
+ """
97
+ struct UnsupportedSubmittable{SubmitType<: AbstractSubmittable } <: UnsupportedError
98
+ sub:: SubmitType
99
+ message:: String
100
+ end
101
+
102
+ """
103
+ struct SubmitNotAllowed{SubmitTyp<:AbstractSubmittable} <: NotAllowedError
104
+ sub::SubmitType
80
105
message::String # Human-friendly explanation why the attribute cannot be set
81
106
end
82
107
83
- An error indicating that the attribute `attr ` is supported (see
108
+ An error indicating that the submittable `sub ` is supported (see
84
109
[`supports`](@ref)) but cannot be added for some reason (see the error string).
85
110
"""
86
- struct AddAttributeNotAllowed{AttrType <: AnyAttribute } <: NotAllowedError
87
- attr :: AttrType
88
- message:: String # Human-friendly explanation why the attribute cannot be set
111
+ struct SubmitNotAllowed{SubmitType <: AbstractSubmittable } <: NotAllowedError
112
+ sub :: SubmitType
113
+ message:: String # Human-friendly explanation why the attribute cannot be set
89
114
end
90
- AddAttributeNotAllowed (attr :: AnyAttribute ) = AddAttributeNotAllowed (attr , " " )
115
+ SubmitNotAllowed (sub :: AbstractSubmittable ) = SubmitNotAllowed (sub , " " )
91
116
92
- operation_name (err:: AddAttributeNotAllowed ) = " Adding attribute $(err. attr ) "
93
- message (err:: AddAttributeNotAllowed ) = err. message
117
+ operation_name (err:: SubmitNotAllowed ) = " Submitting $(err. sub ) "
118
+ message (err:: SubmitNotAllowed ) = err. message
94
119
95
120
"""
121
+ supports(model::ModelLike, sub::AbstractSubmittable)::Bool
122
+
123
+ Return a `Bool` indicating whether `model` supports the submittable `sub`.
124
+
96
125
supports(model::ModelLike, attr::AbstractOptimizerAttribute)::Bool
97
126
98
127
Return a `Bool` indicating whether `model` supports the optimizer attribute
@@ -120,14 +149,15 @@ Return a `Bool` indicating whether `model` supports the constraint attribute
120
149
`copy_to(model, src)` cannot be performed in case `attr` is in the
121
150
[`ListOfConstraintAttributesSet`](@ref) of `src`.
122
151
123
- For all four methods, if the attribute is only not supported in specific
152
+ For all five methods, if the attribute is only not supported in specific
124
153
circumstances, it should still return `true`.
125
154
126
155
Note that `supports` is only defined for attributes for which
127
156
[`is_copyable`](@ref) returns `true` as other attributes do not appear in the
128
157
list of attributes set obtained by `ListOf...AttributesSet`.
129
158
"""
130
159
function supports end
160
+ supports (:: ModelLike , :: AbstractSubmittable ) = false
131
161
function supports (:: ModelLike , attr:: Union {AbstractModelAttribute,
132
162
AbstractOptimizerAttribute})
133
163
if ! is_copyable (attr)
@@ -346,61 +376,22 @@ function throw_set_error_fallback(model::ModelLike,
346
376
end
347
377
348
378
"""
349
- add(optimizer::AbstractOptimizer, attr::AbstractOptimizerAttribute,
350
- value)::AttributeIndex{typeof(attr)}
351
-
352
- Add `value` to the attribute `attr` of the optimizer `optimizer`.
379
+ submit(optimizer::AbstractOptimizer, sub::AbstractSubmittable,
380
+ value)::Union{Nothing, SubmittedIndex{typeof(sub)}}
353
381
354
- add(model::ModelLike, attr::AbstractModelAttribute,
355
- value)::AttributeIndex{typeof(attr)}
382
+ Submit `value` to the submittable `sub` of the optimizer `optimizer`.
356
383
357
- Add `value` to the attribute `attr` of the model `model`.
358
-
359
- add(model::ModelLike, attr::AbstractVariableAttribute, v::VariableIndex,
360
- value)::AttributeIndex{typeof(attr)}
361
-
362
- Add `value` to the attribute `attr` of variable `v` in model `model`.
363
-
364
- add(model::ModelLike, attr::AbstractVariableAttribute,
365
- v::Vector{VariableIndex},
366
- vector_of_values)::Vector{AttributeIndex{typeof(attr)}}
367
-
368
- Add a value respectively to the attribute `attr` of each variable in the
369
- collection `v` in model `model`.
370
-
371
- set(model::ModelLike, attr::AbstractConstraintAttribute, c::ConstraintIndex,
372
- value)
373
-
374
- Add a value to the attribute `attr` of constraint `c` in model `model`.
375
-
376
- set(model::ModelLike, attr::AbstractConstraintAttribute,
377
- c::Vector{ConstraintIndex{F,S}}, vector_of_values)
378
-
379
- Add a value respectively to the attribute `attr` of each constraint in the
380
- collection `c` in model `model`.
381
-
382
- An [`UnsupportedAttribute`](@ref) error is thrown if `model` does not support
383
- the attribute `attr` (see [`supports`](@ref)) and a
384
- [`SetAttributeNotAllowed`](@ref) error is thrown if it supports the attribute
385
- `attr` but it cannot be set.
386
- """ # TODO add an example once we have an attribute which can be added, e.g. Lazy constraint
387
- function add end
388
- # See note with get
389
- function add (model:: ModelLike ,
390
- attr:: Union {AbstractVariableAttribute,
391
- AbstractConstraintAttribute},
392
- idxs:: Vector , vector_of_values:: Vector )
393
- if length (idxs) != length (vector_of_values)
394
- throw (DimensionMismatch (" Number of indices ($(length (idxs)) ) does " *
395
- " not match the number of values " *
396
- " ($(length (vector_of_values)) ) added to `$attr `." ))
384
+ An [`UnsupportedSubmittable`](@ref) error is thrown if `model` does not support
385
+ the attribute `attr` (see [`supports`](@ref)) and a [`SubmitNotAllowed`](@ref)
386
+ error is thrown if it supports the submittable `sub` but it cannot be submitted.
387
+ """ # TODO add an example once we have an attribute which can be submitted, e.g. Lazy constraint
388
+ function submit end
389
+ function submit (model:: ModelLike , sub:: AbstractSubmittable , args... )
390
+ if supports (model, sub)
391
+ throw (SubmitNotAllowed (sub))
392
+ else
393
+ throw (UnsupportedSubmittable (sub))
397
394
end
398
- return add .(model, attr, idxs, vector_of_values)
399
- end
400
-
401
- function add (model:: ModelLike , attr:: AnyAttribute , args... )
402
- throw_set_error_fallback (model, attr, args... ;
403
- error_if_supported = AddAttributeNotAllowed (attr))
404
395
end
405
396
406
397
"""
0 commit comments