lib/rgraph/graph.rb in rgraph-0.0.8 vs lib/rgraph/graph.rb in rgraph-0.0.9
- old
+ new
@@ -123,17 +123,26 @@
n = @shortest_paths.select{|c| c[1..-2].include?(i)}.size.to_f
m = @shortest_paths.size.to_f
n / m
end
- def betweenness(normalized = false)
+ def betweenness(args = {})
+ cumulative = args[:cumulative] || false
+
+ #If we ask cumulative, normalized must be true
+ normalized = args[:normalized] || cumulative || false
+
bts = 0.upto(@nodes.size - 1).map { |i| between(i) }
if normalized
max = bts.max
min = bts.min
- bts.map{|bt| (bt - min) / (max - min)}
+ bts.map!{|bt| (bt - min) / (max - min)}
+ end
+
+ if cumulative
+ bts.uniq.sort.map{ |bt1| [bts.select{|bt2| bt2 >= bt1}.count, bt1] }
else
bts
end
end