Class: Solve::GecodeSolver
- Inherits:
-
Object
- Object
- Solve::GecodeSolver
- Defined in:
- lib/solve/gecode_solver.rb
Instance Attribute Summary collapse
-
#demands_array ⇒ Array<String>, Array<Array<String, String>>
readonly
Demands.
-
#graph ⇒ Solve::Graph
readonly
Graph object with references to all known artifacts and dependency constraints.
Class Method Summary collapse
-
.activate ⇒ Object
Attemp to load the dep_selector gem which this solver engine requires.
-
.timeout ⇒ Integer
The timeout (in seconds) to use when resolving graphs.
Instance Method Summary collapse
-
#demands ⇒ Array<Solve::Demand>
The problem demands given as Demand model objects.
-
#initialize(graph, demands, options = {}) ⇒ GecodeSolver
constructor
A new instance of GecodeSolver.
-
#resolve(options = {}) ⇒ Hash, List
Returns a hash like { “Artifact Name” => “Version”,… } unless the :sorted option is true, then it returns a list like [[“Artifact Name”, “Version],…].
Constructor Details
#initialize(graph, demands, options = {}) ⇒ GecodeSolver
Returns a new instance of GecodeSolver.
44 45 46 47 48 49 |
# File 'lib/solve/gecode_solver.rb', line 44 def initialize(graph, demands, = {}) @ds_graph = DepSelector::DependencyGraph.new @graph = graph @demands_array = demands @timeout_ms = self.class.timeout end |
Instance Attribute Details
#demands_array ⇒ Array<String>, Array<Array<String, String>> (readonly)
Returns demands.
34 35 36 |
# File 'lib/solve/gecode_solver.rb', line 34 def demands_array @demands_array end |
#graph ⇒ Solve::Graph (readonly)
Graph object with references to all known artifacts and dependency constraints.
29 30 31 |
# File 'lib/solve/gecode_solver.rb', line 29 def graph @graph end |
Class Method Details
.activate ⇒ Object
Attemp to load the dep_selector gem which this solver engine requires.
18 19 20 21 22 |
# File 'lib/solve/gecode_solver.rb', line 18 def activate require "dep_selector" rescue LoadError => e raise Errors::EngineNotAvailable, "dep_selector is not installed, GecodeSolver cannot be used (#{e})" end |
.timeout ⇒ Integer
The timeout (in seconds) to use when resolving graphs. Default is 10. This can be configured by setting the SOLVE_TIMEOUT environment variable.
12 13 14 15 |
# File 'lib/solve/gecode_solver.rb', line 12 def timeout seconds = 30 unless ( seconds = ENV["SOLVE_TIMEOUT"] ) seconds.to_i * 1_000 end |
Instance Method Details
#demands ⇒ Array<Solve::Demand>
The problem demands given as Demand model objects
53 54 55 56 57 |
# File 'lib/solve/gecode_solver.rb', line 53 def demands demands_array.map do |name, constraint| Demand.new(self, name, constraint) end end |
#resolve(options = {}) ⇒ Hash, List
Returns a hash like { “Artifact Name” => “Version”,… } unless the :sorted option is true, then it returns a list like [[“Artifact Name”, “Version],…]
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/solve/gecode_solver.rb', line 69 def resolve( = {}) solution = solve_demands(demands_as_constraints) unsorted_solution = solution.inject({}) do |stringified_soln, (name, version)| stringified_soln[name] = version.to_s stringified_soln end if [:sorted] build_sorted_solution(unsorted_solution) else unsorted_solution end end |