1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
require "benchmark"
require "solve"
require "solve/gecode_solver"
require_relative "large_graph_no_solution"
require_relative "opscode_ci_graph"
PROBLEM = OpscodeCiGraph
# PROBLEM = LargeGraphNoSolution
N = 100
def demands
PROBLEM::DEMANDS
end
def artifacts
PROBLEM::ARTIFACTS
end
require "pp"
def create_graph
graph = Solve::Graph.new
artifacts.each do |name, all_artifact_versions|
all_artifact_versions.each do |artifact|
graph.artifact(name, artifact[:version])
artifact[:dependencies].each do |dep|
dep_name, dep_constraint = dep
graph.artifact(name, artifact[:version])
.depends(dep_name, dep_constraint)
end
end
end
graph
end
STATIC_GRAPH = create_graph
def solve_gecode
Solve::GecodeSolver.new(STATIC_GRAPH, demands).resolve({})
rescue Solve::Errors::NoSolutionError => e
# Uncomment to look at the error messages. Probably only useful if N == 1
# puts e
e
end
def solve_ruby
Solve::RubySolver.new(STATIC_GRAPH, demands).resolve({})
rescue Solve::Errors::NoSolutionError => e
# Uncomment to look at the error messages. Probably only useful if N == 1
# puts e
e
end
Benchmark.bm(12) do |x|
x.report("Create graph") { N.times { create_graph } }
x.report("Solve Gecode") { N.times { solve_gecode } }
x.report("Solve Ruby") { N.times { solve_ruby } }
end
|