@@ -124,23 +124,41 @@ This is used in two places to determine whether to add a cache:
124
124
supports_incremental_interface (:: ModelLike , :: Bool ) = false
125
125
126
126
"""
127
- copy_to(dest::ModelLike, src::ModelLike; copy_names=true, warn_attributes=true)
128
-
129
- Copy the model from `src` into `dest`. The target `dest` is emptied, and all
130
- previous indices to variables or constraints in `dest` are invalidated. Returns
131
- a dictionary-like object that translates variable and constraint indices from
132
- the `src` model to the corresponding indices in the `dest` model.
133
-
134
- If `copy_names` is `false`, the `Name`, `VariableName` and `ConstraintName`
135
- attributes are not copied even if they are set in `src`. If a constraint that
136
- is copied from `src` is not supported by `dest` then an
137
- [`UnsupportedConstraint`](@ref) error is thrown. Similarly, if a model, variable
138
- or constraint attribute that is copied from `src` is not supported by `dest`
139
- then an [`UnsupportedAttribute`](@ref) error is thrown. Unsupported *optimizer*
140
- attributes are treated differently:
141
-
142
- * If `warn_attributes` is `true`, a warning is displayed, otherwise,
143
- * the attribute is silently ignored.
127
+ copy_to(
128
+ dest::ModelLike,
129
+ src::ModelLike;
130
+ copy_names::Bool = true,
131
+ warn_attributes::Bool = true,
132
+ )::IndexMap
133
+
134
+ Copy the model from `src` into `dest`.
135
+
136
+ The target `dest` is emptied, and all previous indices to variables and
137
+ constraints in `dest` are invalidated.
138
+
139
+ Returns an [`IndexMap`](@ref) object that translates variable and constraint
140
+ indices from the `src` model to the corresponding indices in the `dest` model.
141
+
142
+ ## Notes
143
+
144
+ * If `copy_names == false`, the [`Name`](@ref), [`VariableName`](@ref) and
145
+ [`ConstraintName`](@ref) attributes are not copied, even if they are set in
146
+ `src`.
147
+ * If a constraint that in `src` is not supported by `dest`, then an
148
+ [`UnsupportedConstraint`](@ref) error is thrown.
149
+ * If an [`AbstractModelAttribute`](@ref), [`AbstractVariableAttribute`](@ref),
150
+ or [`AbstractConstraintAttribute`](@ref) is set in `src` but not supported by
151
+ `dest`, then an [`UnsupportedAttribute`](@ref) error is thrown.
152
+ * Unsupported [`AbstractOptimizerAttribute`](@ref)s are treated differently:
153
+ * If `warn_attributes == true`, a warning is displayed, otherwise, the
154
+ attribute is silently ignored.
155
+
156
+ ## IndexMap
157
+
158
+ Implementations of `copy_to` must return an [`IndexMap`](@ref). For technical
159
+ reasons, this type is defined in the Utilties submodule as
160
+ `MOI.Utilities.IndexMap`. However, since it is an integral part of the MOI API,
161
+ we provide `MOI.IndexMap` as an alias.
144
162
145
163
### Example
146
164
@@ -160,16 +178,26 @@ is_valid(dest, index_map[x]) # true
160
178
function copy_to end
161
179
162
180
"""
163
- copy_to_and_optimize!(dest::ModelLike, src::ModelLike; copy_names=true, warn_attributes=true)
181
+ copy_to_and_optimize!(
182
+ dest::AbstractOptimizer,
183
+ src::ModelLike;
184
+ kwargs...
185
+ )::IndexMap
164
186
165
- Same as [`copy_to`](@ref) followed [`optimize!`](@ref). An optimizer
166
- can decide to implement this function and not implement [`copy_to`](@ref) and
167
- [`optimize!`](@ref).
187
+ A single call equivalent to calling [`copy_to`](@ref) followed by
188
+ [`optimize!`](@ref). Like [`copy_to`](@ref), it returns an [`IndexMap`].
168
189
169
- **WARNING** This is an experimental new feature of MOI v0.10 that may break in MOI v1.0.
190
+ Keyword arguments are passed to [`copy_to`](@ref).
191
+
192
+ An optimizer can decide to implement this function instead of implementing
193
+ [`copy_to`](@ref) and [`optimize!`](@ref) individually.
194
+
195
+ !!! warning
196
+ This is an experimental new feature of MOI v0.10 that may break in MOI v1.0.
170
197
"""
171
- function copy_to_and_optimize! (dest, src; kws... )
172
- index_map = copy_to (dest, src; kws... )
198
+ function copy_to_and_optimize! (dest, src; kwargs... )
199
+ # The arguments above are untyped to avoid ambiguities.
200
+ index_map = copy_to (dest, src; kwargs... )
173
201
optimize! (dest)
174
202
return index_map
175
203
end
@@ -199,4 +227,21 @@ include("instantiate.jl")
199
227
include (" deprecate.jl" )
200
228
include (" DeprecatedTest/DeprecatedTest.jl" )
201
229
230
+ """
231
+ IndexMap(number_of_variables::Int = 0)
232
+
233
+ The dictionary-like object returned by [`copy_to`](@ref).
234
+
235
+ If known in advance, pass `number_of_variables` to preallocate the necessary
236
+ space for the variables.
237
+
238
+ ## IndexMap
239
+
240
+ Implementations of [`copy_to`](@ref) must return an [`IndexMap`](@ref). For
241
+ technical reasons, the `IndexMap` type is defined in the Utilties submodule as
242
+ `MOI.Utilities.IndexMap`. However, since it is an integral part of the MOI API,
243
+ we provide this `MOI.IndexMap` as an alias.
244
+ """
245
+ const IndexMap = Utilities. IndexMap
246
+
202
247
end
0 commit comments