MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / add_edge

Method add_edge

easygraph/classes/directed_multigraph.py:83–178  ·  view source on GitHub ↗

Add an edge between u and v. The nodes u and v will be automatically added if they are not already in the graph. Edge attributes can be specified with keywords or by directly accessing the edge's attribute dictionary. See examples below. Parameters

(self, u_for_edge, v_for_edge, key=None, **attr)

Source from the content-addressed store, hash-verified

81 DiGraph.__init__(self, incoming_graph_data, **attr)
82
83 def add_edge(self, u_for_edge, v_for_edge, key=None, **attr):
84 """Add an edge between u and v.
85
86 The nodes u and v will be automatically added if they are
87 not already in the graph.
88
89 Edge attributes can be specified with keywords or by directly
90 accessing the edge's attribute dictionary. See examples below.
91
92 Parameters
93 ----------
94 u_for_edge, v_for_edge : nodes
95 Nodes can be, for example, strings or numbers.
96 Nodes must be hashable (and not None) Python objects.
97 key : hashable identifier, optional (default=lowest unused integer)
98 Used to distinguish multiedges between a pair of nodes.
99 attr : keyword arguments, optional
100 Edge data (or labels or objects) can be assigned using
101 keyword arguments.
102
103 Returns
104 -------
105 The edge key assigned to the edge.
106
107 See Also
108 --------
109 add_edges_from : add a collection of edges
110
111 Notes
112 -----
113 To replace/update edge data, use the optional key argument
114 to identify a unique edge. Otherwise a new edge will be created.
115
116 EasyGraph algorithms designed for weighted graphs cannot use
117 multigraphs directly because it is not clear how to handle
118 multiedge weights. Convert to Graph using edge attribute
119 'weight' to enable weighted graph algorithms.
120
121 Default keys are generated using the method `new_edge_key()`.
122 This method can be overridden by subclassing the base class and
123 providing a custom `new_edge_key()` method.
124
125 Examples
126 --------
127 The following all add the edge e=(1, 2) to graph G:
128
129 >>> G = eg.MultiDiGraph()
130 >>> e = (1, 2)
131 >>> key = G.add_edge(1, 2) # explicit two-node form
132 >>> G.add_edge(*e) # single edge as tuple of two nodes
133 1
134 >>> G.add_edges_from([(1, 2)]) # add edges from iterable container
135 [2]
136
137 Associate data to edges using keywords:
138
139 >>> key = G.add_edge(1, 2, weight=3)
140 >>> key = G.add_edge(1, 2, key=0, weight=4) # update data for key=0

Callers

nothing calls this directly

Calls 2

new_edge_keyMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected