Method: NetworkX::MultiGraph#size

Defined in:
lib/networkx/multigraph.rb

#size(is_weighted = false) ⇒ Object

Returns the size of the graph

Examples:

graph.size(true)

Parameters:

  • is_weighted (Bool) (defaults to: false)

    if true, method returns sum of weights of all edges else returns number of edges



71
72
73
74
75
76
77
78
79
80
# File 'lib/networkx/multigraph.rb', line 71

def size(is_weighted = false)
  if is_weighted
    graph_size = 0
    @adj.each do |_, hash_val|
      hash_val.each { |_, v| v.each { |_, attrs| graph_size += attrs[:weight] if attrs.has_key?(:weight) } }
    end
    return graph_size / 2
  end
  number_of_edges
end