Skip to content

Consider Union{Nothing, in LazyBridgeOptimizer #1347

@odow

Description

@odow

A key problem in LazyBridgeOptimizer is things like

Two important definitions are

function Variable.bridges(bridge::LazyBridgeOptimizer)
return bridge.variable_map
end

has_bridges(map::Map) = !isempty(map.info)

So in methods like

function MOI.empty!(b::AbstractBridgeOptimizer)
MOI.empty!(b.model)
if Variable.has_bridges(Variable.bridges(b))
empty!(b.var_to_name)
b.name_to_var = nothing
end
if Variable.has_bridges(Variable.bridges(b)) ||
Constraint.has_bridges(Constraint.bridges(b))
empty!(b.con_to_name)
b.name_to_con = nothing
end
empty!(Variable.bridges(b))
empty!(Constraint.bridges(b))
empty!(Objective.bridges(b))
return
end

the compiler has to do a run-time check to see if there are bridges.

If we made the field ::Union{Nothing,Map}, the compiler may be clever enough to compile away the branches based on the Nothing. As an alternative, we could pass map as a function argument to force it to specialize.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions