Class: Solve::Solver
- Inherits:
-
Object
- Object
- Solve::Solver
- Defined in:
- lib/solve/solver.rb,
lib/solve/solver/serializer.rb
Defined Under Namespace
Classes: Serializer
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
-
.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) ⇒ Solver
constructor
A new instance of Solver.
-
#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) ⇒ Solver
Returns a new instance of Solver.
36 37 38 39 40 41 |
# File 'lib/solve/solver.rb', line 36 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.
27 28 29 |
# File 'lib/solve/solver.rb', line 27 def demands_array @demands_array end |
#graph ⇒ Solve::Graph (readonly)
Graph object with references to all known artifacts and dependency constraints.
22 23 24 |
# File 'lib/solve/solver.rb', line 22 def graph @graph end |
Class Method Details
.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/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
45 46 47 48 49 |
# File 'lib/solve/solver.rb', line 45 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],…]
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/solve/solver.rb', line 61 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 |