Class: AStar::PriorityQueue
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PriorityQueue.
11
12
13
14
15
|
# File 'lib/ext/astar/priority_queue.rb', line 11
def initialize(nodes=[])
@nodes=nodes
@tbmul=1+1/(Math.sqrt(@nodes.size))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodname, *args) ⇒ Object
16
17
18
19
|
# File 'lib/ext/astar/priority_queue.rb', line 16
def method_missing(methodname, *args)
@nodes.send(methodname, *args)
end
|
Instance Method Details
#find(node) ⇒ Object
28
29
30
31
|
# File 'lib/ext/astar/priority_queue.rb', line 28
def find(node)
@nodes.find {|x| x==node }
end
|
#find_best ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/ext/astar/priority_queue.rb', line 20
def find_best
best=@nodes.first
@nodes.each do |node|
if node.better?(best,@tbmul) then best=node end
end
remove(best)
end
|
#remove(node) ⇒ Object
33
34
35
36
|
# File 'lib/ext/astar/priority_queue.rb', line 33
def remove(node)
@nodes.delete(find(node))
end
|
38
39
40
41
|
# File 'lib/ext/astar/priority_queue.rb', line 38
def to_s
output=""
@nodes.each {|e| output<<"#{e};"}
end
|