Class: BFS

Inherits:
Object
  • Object
show all
Defined in:
lib/rsearch/bfs.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BFS

Returns a new instance of BFS.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rsearch/bfs.rb', line 5

def initialize(options)
  queue = []
  marked = Set.new
  marked << options[:start]
  scheduler = Proc.new do |states|
    states.each do |state|
      if !marked.include?(state)
        queue << state
        marked << state
      end
    end
    queue.shift
  end

  @search = Search.new(start: options[:start],
                       generator: options[:generator],
                       scheduler: scheduler)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



24
25
26
# File 'lib/rsearch/bfs.rb', line 24

def method_missing(meth, *args, &block)
  @search.send(meth, *args, &block)
end