Class: Longjing::Search::Base
- Inherits:
-
Object
- Object
- Longjing::Search::Base
- Includes:
- Logging
- Defined in:
- lib/longjing/search/base.rb
Instance Attribute Summary collapse
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #log_progress(state) ⇒ Object
- #log_solution(steps) ⇒ Object
- #no_solution ⇒ Object
- #reset_best_heuristic ⇒ Object
- #solution(state) ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 |
# File 'lib/longjing/search/base.rb', line 11 def initialize @t = Time.now @statistics = Statistics.new reset_best_heuristic end |
Instance Attribute Details
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
9 10 11 |
# File 'lib/longjing/search/base.rb', line 9 def statistics @statistics end |
Instance Method Details
#log_progress(state) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/longjing/search/base.rb', line 21 def log_progress(state) return if @best <= state.cost @best = state.cost log { msg = [ "#{statistics.generated} generated", "#{statistics.evaluated} evaluated", "#{statistics.expanded} expanded", "h=#{@best}", "#{state.path.size} steps", "t=#{Time.now - @t}" ].join(', ') } end |
#log_solution(steps) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/longjing/search/base.rb', line 36 def log_solution(steps) log { "Solution found!" } log { "Actual search time: #{Time.now - @t}" } log { "Plan length: #{steps.size} step(s)." } log { "Expanded #{statistics.expanded} state(s)." } log { "Evaluated #{statistics.evaluated} state(s)." } log { "Generated #{statistics.generated} state(s)." } log { "Solution:" } steps.each_with_index do |step, i| log { "#{i}. #{step}" } end end |
#no_solution ⇒ Object
53 54 55 56 |
# File 'lib/longjing/search/base.rb', line 53 def no_solution log { "No solution found!" } nil end |
#reset_best_heuristic ⇒ Object
17 18 19 |
# File 'lib/longjing/search/base.rb', line 17 def reset_best_heuristic @best = Float::INFINITY end |
#solution(state) ⇒ Object
49 50 51 |
# File 'lib/longjing/search/base.rb', line 49 def solution(state) state.path.map(&:signature).tap(&method(:log_solution)) end |