lib/rgraph/graph.rb in rgraph-0.0.4 vs lib/rgraph/graph.rb in rgraph-0.0.5
- old
+ new
@@ -35,9 +35,17 @@
def each_link(&block)
@links.each(&block)
end
+ def degrees
+ @nodes.map{|node| node.degree}
+ end
+
+ def average_degree
+ degrees.inject(:+) / @nodes.size.to_f
+ end
+
private
def get_node_by_id(node_id)
@nodes.select{|n| n.id == node_id}.first
end