Class: Algorithms::Greedy::Engine
- Inherits:
-
Object
- Object
- Algorithms::Greedy::Engine
- Defined in:
- lib/algorithms/greedy.rb
Instance Method Summary collapse
- #best_solution ⇒ Object
-
#initialize(solution) ⇒ Engine
constructor
A new instance of Engine.
- #run(iterations) ⇒ Object
Constructor Details
#initialize(solution) ⇒ Engine
Returns a new instance of Engine.
16 17 18 19 |
# File 'lib/algorithms/greedy.rb', line 16 def initialize(solution) @initial_solution = solution @solutions_history = [@initial_solution] end |
Instance Method Details
#best_solution ⇒ Object
27 28 29 |
# File 'lib/algorithms/greedy.rb', line 27 def best_solution @solutions_history[-1] end |
#run(iterations) ⇒ Object
21 22 23 24 25 |
# File 'lib/algorithms/greedy.rb', line 21 def run(iterations) iterations.times do @solutions_history << @solutions_history[-1].next_solutions.max_by { |solution| solution.score } end end |