dynetworkx.ImpulseGraph.add_edge

ImpulseGraph.add_edge(u, v, t, **attr)

Add an edge between u and v, at t.

The nodes u and v will be automatically added if they are not already in the impulse graph.

Edge attributes can be specified with keywords or by directly accessing the edge’s attribute dictionary. See examples below.

Parameters:
  • v (u,) – Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.
  • t (timestamp) – Timestamps can be, for example, strings or numbers. Timestamps must be hashable (and not None) Python objects.
  • attr (keyword arguments, optional) – Edge data (or labels or objects) can be assigned using keyword arguments.

See also

add_edges_from()
add a collection of edges

Notes

Adding an edge that already exists updates the edge data.

Timestamps must be the same type across all edges in the impulse graph. Also, to create snapshots, timestamps must be integers.

Many NetworkX algorithms designed for weighted graphs use an edge attribute (by default weight) to hold a numerical value.

Examples

The following all add the edge e=(1, 2, 3, 10) to graph G:

>>> G = dnx.ImpulseGraph()
>>> e = (1, 2, 10)
>>> G.add_edge(1, 2, 10)           # explicit two-node form with timestamp
>>> G.add_edge(*e)             # single edge as tuple of two nodes and timestamp
>>> G.add_edges_from([(1, 2, 10)])  # add edges from iterable container

Associate data to edges using keywords:

>>> G.add_edge(1, 2, 10 weight=3)
>>> G.add_edge(1, 3, 9, weight=7, capacity=15, length=342.7)