Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ function MOI.supports_incremental_interface(
)
return MOI.supports_incremental_interface(b.model, copy_names)
end
function MOIU.final_touch(uf::AbstractBridgeOptimizer, index_map)
return MOIU.final_touch(uf.model, index_map)
end

# References
function MOI.is_valid(b::AbstractBridgeOptimizer, vi::MOI.VariableIndex)
Expand Down
3 changes: 3 additions & 0 deletions src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ include("results.jl")
include("variables.jl")

include("vector_of_constraints.jl")
include("sparse_matrix.jl")
include("product_of_sets.jl")
include("matrix_of_constraints.jl")
include("struct_of_constraints.jl")
include("model.jl")
include("parser.jl")
Expand Down
18 changes: 18 additions & 0 deletions src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ end

_standardize(d::IndexMap) = d

function pass_nonvariable_constraints(
dest::CachingOptimizer,
src::MOI.ModelLike,
idxmap::IndexMap,
constraint_types,
pass_cons = copy_constraints;
filter_constraints::Union{Nothing,Function} = nothing,
)
dest.state == ATTACHED_OPTIMIZER && reset_optimizer(dest)
return pass_nonvariable_constraints(
dest.model_cache,
src,
idxmap,
constraint_types,
pass_cons;
filter_constraints = filter_constraints,
)
end
function MOI.copy_to(m::CachingOptimizer, src::MOI.ModelLike; kws...)
if m.state == ATTACHED_OPTIMIZER
reset_optimizer(m)
Expand Down
11 changes: 11 additions & 0 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ function try_constrain_variables_on_creation(
single_variable_not_added
end

"""
function final_touch(model::MOI.ModelLike, idxmap) end

This is called at the end of [`default_copy_to`](@ref) to inform the model that
the copy is finished. This allows `model` to perform thats that should be done
only once all the model information is gathered.
"""
function final_touch(::MOI.ModelLike, idxmap) end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a docstring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think for the name. Another option would be end_of_copy


"""
default_copy_to(
dest::MOI.ModelLike,
Expand Down Expand Up @@ -649,6 +658,8 @@ function default_copy_to(
filter_constraints = filter_constraints,
)

final_touch(dest, idxmap)

return idxmap
end

Expand Down
Loading