Permalink
Browse files

pagerank works!

  • Loading branch information...
1 parent a985fe8 commit be8ed2cb392f716c7540bdc8354488879db97c4e @igrigorik committed Oct 30, 2010
Showing with 18 additions and 5 deletions.
  1. +1 −3 lib/pregel.rb
  2. +17 −2 spec/coordinator_spec.rb
View
@@ -24,9 +24,7 @@ def deliver(to, msg)
def read(box)
@mutex.synchronize do
- msgs = @mailboxes[box] || []
- @mailboxes.clear
- msgs
+ @mailboxes.delete(box) || []
end
end
end
View
@@ -33,12 +33,11 @@
end
it 'should perform simple PageRank calculation on the graph' do
- pending
class PageRankVertex < Vertex
def compute
if superstep >= 1
- sum = messages.collect(0) {|total,msg| total += msg; total }
+ sum = messages.inject(0) {|total,msg| total += msg; total }
@value = (0.15 / 3) + 0.85 * sum
end
@@ -50,6 +49,22 @@ def compute
end
end
+ graph = [
+ # name value out-edges
+ PageRankVertex.new(:igvita, 1, :wikipedia),
+ PageRankVertex.new(:wikipedia, 1, :google),
+ PageRankVertex.new(:google, 1, :igvita)
+ ]
+
+ c = Coordinator.new(graph)
+ c.run
+
+ c.workers.each do |w|
+ w.vertices.each do |v|
+ (v.value * 100).to_i.should == 33
+ end
+ end
+
end
it 'should parition nodes by hashing the node id'

0 comments on commit be8ed2c

Please sign in to comment.