dynetworkx.IntervalGraph.add_edge

IntervalGraph.add_edge(u, v, begin, end, **attr)

Add an edge between u and v, during interval [begin, end).

The nodes u and v will be automatically added if they are not already in the interval 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.
  • begin (orderable type) – Inclusive beginning time of the edge appearing in the interval graph.
  • end (orderable type) – Non-inclusive ending time of the edge appearing in the interval graph. Must be bigger than begin.
  • 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.

Both begin and end must be the same type across all edges in the interval graph. Also, to create snapshots, both 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.IntervalGraph()
>>> e = (1, 2, 3, 10)
>>> G.add_edge(1, 2, 3, 10)           # explicit two-node form with interval
>>> G.add_edge(*e)             # single edge as tuple of two nodes and interval
>>> G.add_edges_from([(1, 2, 3, 10)])  # add edges from iterable container

Associate data to edges using keywords:

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