-
Notifications
You must be signed in to change notification settings - Fork 98
Allow creating model from parts #2902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,13 +92,24 @@ mutable struct MatrixOfConstraints{T,AT,BT,ST} <: MOI.ModelLike | |
| caches::Vector{Any} | ||
| are_indices_mapped::Vector{BitSet} | ||
| final_touch::Bool | ||
| function MatrixOfConstraints{T,AT,BT,ST}() where {T,AT,BT,ST} | ||
| model = new{T,AT,BT,ST}(AT(), BT(), ST(), Any[], BitSet[], false) | ||
| MOI.empty!(model) | ||
| function MatrixOfConstraints{T}(coefficients, constants, sets) where {T} | ||
| model = new{T,typeof(coefficients),typeof(constants),typeof(sets)}( | ||
| coefficients, | ||
| constants, | ||
| sets, | ||
| Any[], | ||
| BitSet[], | ||
| false, | ||
| ) | ||
| _reset_caches!(model) | ||
| return model | ||
| end | ||
| end | ||
|
|
||
| function MatrixOfConstraints{T,AT,BT,ST}() where {T,AT,BT,ST} | ||
| return MatrixOfConstraints{T}(AT(), BT(), ST()) | ||
| end | ||
|
|
||
| ### | ||
| ### Interface for the .coefficients field | ||
| ### | ||
|
|
@@ -292,13 +303,17 @@ function rows end | |
|
|
||
| MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets) | ||
|
|
||
| function MOI.empty!(v::MatrixOfConstraints{T}) where {T} | ||
| function _reset_caches!(v::MatrixOfConstraints{T}) where {T} | ||
| v.caches = | ||
| [Tuple{_affine_function_type(T, S),S}[] for S in set_types(v.sets)] | ||
| return v.are_indices_mapped = [BitSet() for _ in eachindex(v.caches)] | ||
| end | ||
|
|
||
| function MOI.empty!(v::MatrixOfConstraints) | ||
| MOI.empty!(v.coefficients) | ||
| empty!(v.constants) | ||
| MOI.empty!(v.sets) | ||
| v.caches = | ||
| [Tuple{_affine_function_type(T, S),S}[] for S in set_types(v.sets)] | ||
| v.are_indices_mapped = [BitSet() for _ in eachindex(v.caches)] | ||
| _reset_caches!(v) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These caches actually only make sense for |
||
| v.final_touch = false | ||
| return | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,19 +183,21 @@ function Base.convert( | |
| ) | ||
| end | ||
|
|
||
| function _first_in_column( | ||
| A::MutableSparseMatrixCSC{Tv,Ti}, | ||
| row::Integer, | ||
| col::Integer, | ||
| ) where {Tv,Ti} | ||
| _indexing(A::MutableSparseMatrixCSC) = A.indexing | ||
| _indexing(::SparseArrays.SparseMatrixCSC) = OneBasedIndexing() | ||
|
|
||
| const _SparseMatrixCSC{Tv,Ti} = | ||
| Union{MutableSparseMatrixCSC{Tv,Ti},SparseArrays.SparseMatrixCSC{Tv,Ti}} | ||
|
|
||
| function _first_in_column(A::_SparseMatrixCSC, row::Integer, col::Integer) | ||
| range = SparseArrays.nzrange(A, col) | ||
| row = _shift(row, OneBasedIndexing(), A.indexing) | ||
| row = _shift(row, OneBasedIndexing(), _indexing(A)) | ||
| idx = searchsortedfirst(view(A.rowval, range), row) | ||
| return get(range, idx, last(range) + 1) | ||
| end | ||
|
|
||
| function extract_function( | ||
| A::MutableSparseMatrixCSC{T}, | ||
| A::_SparseMatrixCSC{T}, | ||
|
||
| row::Integer, | ||
| constant::T, | ||
| ) where {T} | ||
|
|
@@ -205,7 +207,7 @@ function extract_function( | |
| if idx > last(SparseArrays.nzrange(A, col)) | ||
| continue | ||
| end | ||
| r = _shift(A.rowval[idx], A.indexing, OneBasedIndexing()) | ||
| r = _shift(A.rowval[idx], _indexing(A), OneBasedIndexing()) | ||
| if r == row | ||
| push!( | ||
| func.terms, | ||
|
|
@@ -217,7 +219,7 @@ function extract_function( | |
| end | ||
|
|
||
| function extract_function( | ||
| A::MutableSparseMatrixCSC{T}, | ||
| A::_SparseMatrixCSC{T}, | ||
| rows::UnitRange, | ||
| constants::Vector{T}, | ||
| ) where {T} | ||
|
|
@@ -231,7 +233,7 @@ function extract_function( | |
| if idx[col] > last(SparseArrays.nzrange(A, col)) | ||
| continue | ||
| end | ||
| row = _shift(A.rowval[idx[col]], A.indexing, OneBasedIndexing()) | ||
| row = _shift(A.rowval[idx[col]], _indexing(A), OneBasedIndexing()) | ||
| if row != rows[output_index] | ||
| continue | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.