From 2569bf745b043bc63ba19021f00949ebc6c5999d Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 30 Sep 2021 10:05:19 +1300 Subject: [PATCH] Add benchmark script --- test/perf/force_bridge_formulation.jl | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/perf/force_bridge_formulation.jl diff --git a/test/perf/force_bridge_formulation.jl b/test/perf/force_bridge_formulation.jl new file mode 100644 index 00000000000..210e64a8c76 --- /dev/null +++ b/test/perf/force_bridge_formulation.jl @@ -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