-
Notifications
You must be signed in to change notification settings - Fork 94
Fix logic in cost_of_bridging #1699
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
Conversation
It should be |
Okay, but we should probably prefer sets that don't require bridging over those that do? So we should distinguish |
Because for Pajarito the cost of bridging |
@blegat I'm not convinced of the current ordering of the sets. For example, the comment says "give priority to vector sets" but the ordering actually does the opposite (they come last). One issue with the costs is that they don't take into account modified costs if we choose one of the variable bridges. i.e., the act of bridging one set can invalidate the other bridges that we would have chosen. In this case, if we bridge on I think we need to construct some test cases first, and then modify the behavior to match the test-cases. struct Optimizer1698 <: MOI.AbstractOptimizer end
function MOI.supports_constraint(
::Optimizer1698,
::Type{MOI.VariableIndex},
::Type{MOI.Integer},
)
return true
end
function MOI.supports_constraint(
::Optimizer1698,
::Type{<:Union{MOI.VectorOfVariables,MOI.VectorAffineFunction{Float64}}},
::Type{<:Union{MOI.Nonnegatives,MOI.SecondOrderCone}},
)
return true
end
function test_sorted_variable_sets_by_cost()
src = MOI.Utilities.Model{Float64}()
x = MOI.add_variable(src)
y = MOI.add_variables(src, 2)
MOI.add_constraint(src, x, MOI.GreaterThan(1.0))
MOI.add_constraint(src, x, MOI.Integer())
MOI.add_constraint(src, y, MOI.SecondOrderCone(2))
dest = MOI.Bridges.full_bridge_optimizer(Optimizer1698(), Float64)
@test MOI.Utilities.sorted_variable_sets_by_cost(dest, src) == [
MOI.Integer,
MOI.GreaterThan{Float64},
MOI.SecondOrderCone,
]
return
end What about this one? struct Optimizer1698_2 <: MOI.AbstractOptimizer end
function MOI.supports_constraint(
::Optimizer1698_2,
::Type{<:Union{MOI.VectorOfVariables,MOI.VectorAffineFunction{Float64}}},
::Type{<:Union{MOI.Nonnegatives,MOI.Nonpositives}},
)
return true
end
function test_sorted_variable_sets_by_cost()
src = MOI.Utilities.Model{Float64}()
MOI.add_constrained_variables(src, MOI.Nonnegatives(2))
MOI.add_constrained_variables(src, MOI.Zeros(2))
dest = MOI.Bridges.full_bridge_optimizer(Optimizer1698_2(), Float64)
@test MOI.Utilities.sorted_variable_sets_by_cost(dest, src) == [
MOI.Nonnegatives,
MOI.Zeros,
]
return
end I think it makes sense for |
@chriscoey you can try MOIPajarito with this branch. julia> using JuMP, GLPK, ECOS, MOIPajarito
julia> solver = MOI.OptimizerWithAttributes(
MOIPajarito.Optimizer,
"oa_solver" => MOI.OptimizerWithAttributes(GLPK.Optimizer),
"conic_solver" => MOI.OptimizerWithAttributes(ECOS.Optimizer),
)
MathOptInterface.OptimizerWithAttributes(MOIPajarito.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[MathOptInterface.RawOptimizerAttribute("oa_solver") => MathOptInterface.OptimizerWithAttributes(GLPK.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[]), MathOptInterface.RawOptimizerAttribute("conic_solver") => MathOptInterface.OptimizerWithAttributes(ECOS.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[])])
julia> model = Model(solver)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Pajarito
julia> @variable(model, z >= 1, Int)
z
julia> optimize!(model)
no conic constraints need outer approximation
OA solver finished with status OPTIMAL, after 0.13000798225402832 seconds and 0 cuts
one tree method used 0 lazy callbacks and 0 heuristic callbacks |
Indeed, there is something I missed when writing this cost. For
Indeed, I'm surprised, I thought it was tested. This should be fixed. |
That order makes sense. |
How's this? |
I'd like something along these lines to be either in the docstring or a comment in the code as I feel I will forget about that subtlety but I can add in a separate PR:
|
I added a big chunk to the docstring, including the Pajarito example. An open research question for MOI 2.0 could be how to update the bridging costs in the presence of variable bridges. Getting that right would fix all of this. |
@blegat should this be a + or a -? Part of #1698
With the
-
:The cost for GreaterThan is
1 - 1
but the cost forInteger
is0 - 0
. Or perhaps we need to return a triplet of(x - y, x + y, false)
.