Method: NetworkX::Graph#add_edge

Defined in:
lib/networkx/graph.rb

#add_edge(node1, node2, **edge_attrs) ⇒ Object

Adds the respective edges

Examples:

Add an edge with attribute name

graph.add_edge(node1, node2, name: "Edge1")

Add an edge with no attribute

graph.add_edge("Bangalore", "Chennai")

Parameters:

  • node1 (Object)

    the first node of the edge

  • node2 (Object)

    the second node of the edge

  • edge_attrs (Hash{ Object => Object })

    the hash of the edge attributes



33
34
35
36
37
38
39
40
# File 'lib/networkx/graph.rb', line 33

def add_edge(node1, node2, **edge_attrs)
  add_node(node1)
  add_node(node2)

  edge_attrs = (@adj[node1][node2] || {}).merge(edge_attrs)
  @adj[node1][node2] = edge_attrs
  @adj[node2][node1] = edge_attrs
end