Skip to content

Commit

Permalink
Add benchmark script
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Oct 1, 2021
1 parent a770356 commit 2569bf7
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/perf/force_bridge_formulation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using JuMP
import Clp
import GLPK

### No bridging

function foo(optimizer, force_bridge_formulation)
model = Model(
optimizer;
bridge_constraints = force_bridge_formulation,
)
set_silent(model)
@variable(model, x >= 0)
@constraint(model, 2x + 1 <= 1)
@objective(model, Max, 1.0 * x)
optimize!(model)
end

### ObjectiveFunction bridging

function foo_obj(optimizer)
model = Model(optimizer)
set_silent(model)
@variable(model, x >= 0)
@constraint(model, 2x + 1 <= 1)
@objective(model, Max, x)
optimize!(model)
end

### variable bridging

function foo_var(optimizer)
model = Model(optimizer)
set_silent(model)
@variable(model, x[1:1] in MOI.Nonnegatives(1))
@constraint(model, 2x[1] + 1 <= 1)
@objective(model, Max, 1.0 * x[1])
optimize!(model)
end

### constraint bridging

function foo_con(optimizer)
model = Model(optimizer)
set_silent(model)
@variable(model, x[1:2])
@constraint(model, x in MOI.Nonpositives(2))
@objective(model, Max, 1.0 * x[1])
optimize!(model)
end

const optimizer = ARGS[1] == "clp" ? Clp.Optimizer : GLPK.Optimizer

if ARGS[2] == "--bridge"
@eval @time foo(optimizer, true)
@eval @time foo(optimizer, true)
elseif ARGS[2] == "--no-bridge"
@eval @time foo(optimizer, false)
@eval @time foo(optimizer, false)
elseif ARGS[2] == "--var"
@eval @time foo_var(optimizer)
@eval @time foo_var(optimizer)
elseif ARGS[2] == "--con"
@eval @time foo_con(optimizer)
@eval @time foo_con(optimizer)
else
@assert ARGS[2] == "--obj"
@eval @time foo_obj(optimizer)
@eval @time foo_obj(optimizer)
end

0 comments on commit 2569bf7

Please sign in to comment.