Skip to content

Commit

Permalink
Document IndexMap and identity_index_map
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 12, 2021
1 parent 713ed7c commit b4b7511
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ write_to_file
read_from_file
supports_incremental_interface
copy_to
IndexMap
identity_index_map
```

## Model attributes
Expand Down
18 changes: 18 additions & 0 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ function dense_variable_dict(::Type{V}, n) where {V}
)
end

"""
struct IndexMap <: AbstractDict{MOI.Index,MOI.Index}
varmap::DenseVariableDict{MOI.VariableIndex}
conmap::DoubleDicts.MainIndexDoubleDict
end
Dictionary-like object returned by [`MathOptInterface.copy_to`](@ref) that
contains the mapping between variable indices in `varmap` and between
constraint indices in `conmap`.
"""
struct IndexMap <: AbstractDict{MOI.Index,MOI.Index}
varmap::DenseVariableDict{MOI.VariableIndex}
conmap::DoubleDicts.MainIndexDoubleDict
Expand All @@ -69,6 +79,7 @@ function IndexMap(n = 0)
DoubleDicts.IndexDoubleDict(),
)
end

function _identity_constraints_map(
model,
index_map::MOIU.DoubleDicts.IndexWithType{F,S},
Expand All @@ -77,6 +88,13 @@ function _identity_constraints_map(
index_map[ci] = ci
end
end

"""
identity_index_map(model::MOI.ModelLike)
Return an [`IndexMap`](@ref) that maps all variable and constraint indices of
`model` to themselves.
"""
function identity_index_map(model::MOI.ModelLike)
vis = MOI.get(model, MOI.ListOfVariableIndices())
index_map = IndexMap(length(vis))
Expand Down

0 comments on commit b4b7511

Please sign in to comment.