Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 20, 2023
1 parent b348bc0 commit d0239ab
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function Base.getindex(
end

function Base.delete!(map::Map, ci::MOI.ConstraintIndex)
_unregister_for_final_touch(map, map.bridges[_index(ci)])
_unregister_for_final_touch(map, map.bridges[_index(ci)]::AbstractBridge)

Check warning on line 89 in src/Bridges/Constraint/map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/map.jl#L89

Added line #L89 was not covered by tests
map.bridges[_index(ci)] = nothing
return map
end
Expand Down
14 changes: 8 additions & 6 deletions src/Bridges/Variable/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function number_with_set(map::Map, S::Type{<:MOI.AbstractSet})
end

function constraint(map::Map, vi::MOI.VariableIndex)
S = constrained_set(map, vi)
S = constrained_set(map, vi)::Type{<:MOI.AbstractSet}

Check warning on line 211 in src/Bridges/Variable/map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/map.jl#L211

Added line #L211 was not covered by tests
F = MOI.Utilities.variable_function_type(S)
return MOI.ConstraintIndex{F,S}(-bridge_index(map, vi))
end
Expand All @@ -235,12 +235,14 @@ Return a list of all the different types `(F, S)` of `F`-in-`S` constraints in
function list_of_constraint_types(map::Map)
list = Set{Tuple{Type,Type}}()
for i in eachindex(map.bridges)
if map.bridges[i] !== nothing
S = map.sets[i]
if S != MOI.Reals
push!(list, (MOI.Utilities.variable_function_type(S), S))
end
if map.bridges[i] === nothing
continue

Check warning on line 239 in src/Bridges/Variable/map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/map.jl#L238-L239

Added lines #L238 - L239 were not covered by tests
end
S = map.sets[i]
if S === nothing || S == MOI.Reals
continue

Check warning on line 243 in src/Bridges/Variable/map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/map.jl#L241-L243

Added lines #L241 - L243 were not covered by tests
end
push!(list, (MOI.Utilities.variable_function_type(S), S))

Check warning on line 245 in src/Bridges/Variable/map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/map.jl#L245

Added line #L245 was not covered by tests
end
return list
end
Expand Down
9 changes: 6 additions & 3 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ end
function MOI.set(
b::AbstractBridgeOptimizer,
attr::MOI.AbstractVariableAttribute,
index::MOI.Index,
index::MOI.VariableIndex,
value,
)
value = bridged_function(b, value)
Expand All @@ -1240,7 +1240,7 @@ end
function MOI.set(
b::AbstractBridgeOptimizer,
attr::MOI.AbstractVariableAttribute,
indices::Vector{<:MOI.Index},
indices::Vector{MOI.VariableIndex},
values::Vector,
)
if any(index -> is_bridged(b, index), indices)
Expand Down Expand Up @@ -2004,7 +2004,10 @@ function bridged_variable_function(
vi::MOI.VariableIndex,
)
if is_bridged(b, vi)
func = bridged_function(bridge(b, vi), _index(b, vi)...)
func = bridged_function(
bridge(b, vi)::Variable.AbstractBridge,
_index(b, vi)...,
)
# If two variable bridges are chained, `func` may still contain
# bridged variables.
return bridged_function(b, func)
Expand Down
22 changes: 14 additions & 8 deletions src/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ end
Return the list of `VariableNode` that would be added if `BT` is used in `b`.
"""
function _variable_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT}
function _variable_nodes(
b::LazyBridgeOptimizer,
::Type{BT},
) where {BT<:AbstractBridge}
return VariableNode[
node(b, S) for (S,) in added_constrained_variable_types(BT)
node(b, S)::VariableNode for (S,) in added_constrained_variable_types(BT)
]
end

Expand All @@ -139,7 +142,10 @@ end
Return the list of `ConstraintNode` that would be added if `BT` is used in `b`.
"""
function _constraint_nodes(b::LazyBridgeOptimizer, ::Type{BT}) where {BT}
function _constraint_nodes(
b::LazyBridgeOptimizer,
::Type{BT},
) where {BT<:AbstractBridge}
return ConstraintNode[
node(b, F, S) for (F, S) in added_constraint_types(BT)
]
Expand Down Expand Up @@ -168,10 +174,10 @@ function _edge(
)
return ObjectiveEdge(
index,
_variable_nodes(b, BT),
_constraint_nodes(b, BT),
node(b, set_objective_function_type(BT)),
bridging_cost(BT),
_variable_nodes(b, BT)::Vector{VariableNode},
_constraint_nodes(b, BT)::Vector{ConstraintNode},
node(b, set_objective_function_type(BT))::ObjectiveNode,
bridging_cost(BT)::Float64,
)
end

Expand Down Expand Up @@ -321,7 +327,7 @@ function node(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction})
push!(b.objective_types, (F,))
for (i, BT) in enumerate(b.objective_bridge_types)
if Objective.supports_objective_function(BT, F)
bridge_type = Objective.concrete_bridge_type(BT, F)
bridge_type = Objective.concrete_bridge_type(BT, F)::Type{<:Objective.AbstractBridge}

Check warning on line 330 in src/Bridges/lazy_bridge_optimizer.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/lazy_bridge_optimizer.jl#L330

Added line #L330 was not covered by tests
edge = _edge(b, i, bridge_type)::ObjectiveEdge
add_edge(b.graph, objective_node, edge)
end
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function eval_variables(value_fn::Function, f::MOI.ScalarQuadraticFunction)
end

function eval_variables(value_fn::Function, f::MOI.VectorOfVariables)
return value_fn.(f.variables)
return map(value_fn, f.variables)
end

function eval_variables(value_fn::Function, f::MOI.VectorAffineFunction)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function rows end

MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets)

function MOI.empty!(v::MatrixOfConstraints{T}) where {T}
function MOI.empty!(v::MatrixOfConstraints{T,AT,BT,ST}) where {T,AT,BT,ST}
MOI.empty!(v.coefficients)
empty!(v.constants)
MOI.empty!(v.sets)
Expand Down
8 changes: 4 additions & 4 deletions src/Utilities/objective_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ function MOI.get(
T,
F<:Union{
MOI.VariableIndex,
MOI.ScalarAffineFunction{T},
MOI.ScalarQuadraticFunction{T},
MOI.ScalarAffineFunction,
MOI.ScalarQuadraticFunction,
MOI.ScalarNonlinearFunction,
MOI.VectorOfVariables,
MOI.VectorAffineFunction{T},
MOI.VectorQuadraticFunction{T},
MOI.VectorAffineFunction,
MOI.VectorQuadraticFunction,
MOI.VectorNonlinearFunction,
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/struct_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function struct_of_constraint_code(struct_name, types, field_types = nothing)
typed_struct = :($(struct_name){$T})
type_parametrized = field_types === nothing
if type_parametrized
field_types = [Symbol("C$i") for i in eachindex(types)]
field_types = Symbol[Symbol("C$i") for i in eachindex(types)]
append!(typed_struct.args, field_types)
end
code = quote
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ function MOI.modify(
if uf.objective === nothing
MOI.modify(uf.model, obj, change)
else
uf.objective = modify_function(uf.objective, change)
uf.objective = modify_function(something(uf.objective), change)
end
return
end
Expand Down

0 comments on commit d0239ab

Please sign in to comment.