Class: Algorithms::Greedy::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/algorithms/greedy.rb

Instance Method Summary collapse

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_solutionObject



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