Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 13 additions & 10 deletions src/Bridges/Constraint/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ end

_index(ci::MOI.ConstraintIndex) = ci.value

_index(ci::MOI.ConstraintIndex{MOI.VectorOfVariables}) = -ci.value

function Base.haskey(map::Map, ci::MOI.ConstraintIndex{F,S}) where {F,S}
return 1 <= _index(ci) <= length(map.bridges) &&
map.bridges[_index(ci)] !== nothing &&
Expand Down Expand Up @@ -126,10 +124,6 @@ end

_index(index, F, S) = MOI.ConstraintIndex{F,S}(index)

function _index(index, F::Type{MOI.VectorOfVariables}, S)
return MOI.ConstraintIndex{F,S}(-index)
end

function _iterate(map::Map, state = 1)
while state ≤ length(map.bridges) && map.bridges[state] === nothing
state += 1
Expand Down Expand Up @@ -243,7 +237,7 @@ Return the list of all keys that correspond to
function vector_of_variables_constraints(map::Map)
return MOI.Utilities.lazy_map(
MOI.ConstraintIndex{MOI.VectorOfVariables},
i -> MOI.ConstraintIndex{map.constraint_types[i]...}(-i),
i -> MOI.ConstraintIndex{map.constraint_types[i]...}(i),
Base.Iterators.Filter(
i ->
map.bridges[i] !== nothing &&
Expand Down Expand Up @@ -292,7 +286,7 @@ function _ensure_available(
::Type{S},
is_available::Function,
) where {S}
while !is_available(MOI.ConstraintIndex{F,S}(-length(map.bridges) - 1))
while !is_available(MOI.ConstraintIndex{F,S}(length(map.bridges) + 1))
push!(map.bridges, nothing)
push!(map.constraint_types, (F, S))
end
Expand All @@ -304,9 +298,18 @@ function add_key_for_bridge(
bridge::AbstractBridge,
::F,
::S,
is_available::Function,
is_available::Function;
index::Union{Nothing,Int64} = nothing,
) where {F<:MOI.AbstractFunction,S<:MOI.AbstractSet}
_ensure_available(map, F, S, is_available)
if index === nothing
_ensure_available(map, F, S, is_available)
else
@assert index > length(map.bridges)
while length(map.bridges) + 1 < index
push!(map.bridges, nothing)
push!(map.constraint_types, (F, S))
end
end
push!(map.bridges, bridge)
push!(map.constraint_types, (F, S))
return _index(length(map.bridges), F, S)
Expand Down
Loading
Loading