1 |
2 |
dargor |
|
2 |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
3 |
|
|
<html><head><title>Python: module nocmodel.noc_base</title>
|
4 |
|
|
</head><body bgcolor="#f0f0f8">
|
5 |
|
|
|
6 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
7 |
|
|
<tr bgcolor="#7799ee">
|
8 |
|
|
<td valign=bottom> <br>
|
9 |
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="nocmodel.html"><font color="#ffffff">nocmodel</font></a>.noc_base</strong></big></big></font></td
|
10 |
|
|
><td align=right valign=bottom
|
11 |
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_base.py">/home/oscard/Documentos/proyectos/nocmodel-0.1/nocmodel/noc_base.py</a></font></td></tr></table>
|
12 |
|
|
<p><tt>================<br>
|
13 |
|
|
NoCmodel Base Objects<br>
|
14 |
|
|
================<br>
|
15 |
|
|
<br>
|
16 |
|
|
This module declares classes used on a Network-on-chip representation:<br>
|
17 |
|
|
<br>
|
18 |
|
|
* NoC container class<br>
|
19 |
|
|
* Router base class<br>
|
20 |
|
|
* Channel base class<br>
|
21 |
|
|
* IPCore base class<br>
|
22 |
|
|
* Protocol base class<br>
|
23 |
|
|
* Packet class</tt></p>
|
24 |
|
|
<p>
|
25 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
26 |
|
|
<tr bgcolor="#aa55cc">
|
27 |
|
|
<td colspan=3 valign=bottom> <br>
|
28 |
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
29 |
|
|
|
30 |
|
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
31 |
|
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="networkx.html">networkx</a><br>
|
32 |
|
|
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
|
33 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
34 |
|
|
<tr bgcolor="#ee77aa">
|
35 |
|
|
<td colspan=3 valign=bottom> <br>
|
36 |
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
|
37 |
|
|
|
38 |
|
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
|
39 |
|
|
<td width="100%"><dl>
|
40 |
|
|
<dt><font face="helvetica, arial"><a href="__builtin__.html#dict">__builtin__.dict</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
|
41 |
|
|
</font></dt><dd>
|
42 |
|
|
<dl>
|
43 |
|
|
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#packet">packet</a>
|
44 |
|
|
</font></dt></dl>
|
45 |
|
|
</dd>
|
46 |
|
|
<dt><font face="helvetica, arial"><a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
|
47 |
|
|
</font></dt><dd>
|
48 |
|
|
<dl>
|
49 |
|
|
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#noc">noc</a>
|
50 |
|
|
</font></dt></dl>
|
51 |
|
|
</dd>
|
52 |
|
|
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#nocobject">nocobject</a>
|
53 |
|
|
</font></dt><dd>
|
54 |
|
|
<dl>
|
55 |
|
|
<dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#channel">channel</a>
|
56 |
|
|
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#ipcore">ipcore</a>
|
57 |
|
|
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#protocol">protocol</a>
|
58 |
|
|
</font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#router">router</a>
|
59 |
|
|
</font></dt></dl>
|
60 |
|
|
</dd>
|
61 |
|
|
</dl>
|
62 |
|
|
<p>
|
63 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
64 |
|
|
<tr bgcolor="#ffc8d8">
|
65 |
|
|
<td colspan=3 valign=bottom> <br>
|
66 |
|
|
<font color="#000000" face="helvetica, arial"><a name="channel">class <strong>channel</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr>
|
67 |
|
|
|
68 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
69 |
|
|
<td colspan=2><tt>Channel base object<br>
|
70 |
|
|
<br>
|
71 |
|
|
This object represents a <a href="#channel">channel</a> object and its properties. This base class<br>
|
72 |
|
|
is meant to either be inherited or extended by adding other attributes.<br>
|
73 |
|
|
<br>
|
74 |
|
|
Relations with other objects:<br>
|
75 |
|
|
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br>
|
76 |
|
|
* It may be one of the edge attributes in the graph model <br>
|
77 |
|
|
(edge["channel_ref"]). In this case, this <a href="#channel">channel</a> connects two routers<br>
|
78 |
|
|
in the NoC model.<br>
|
79 |
|
|
* It should have two references to NoC objects (self.<strong>endpoints</strong>). Two options<br>
|
80 |
|
|
exists: two routers references (<a href="#channel">channel</a> has an edge object) or, one<br>
|
81 |
|
|
<a href="#router">router</a> and one <a href="#ipcore">ipcore</a> (<a href="#channel">channel</a> don't have any edge object).<br>
|
82 |
|
|
<br>
|
83 |
|
|
Attributes:<br>
|
84 |
|
|
* name<br>
|
85 |
|
|
* index: optional index on a <a href="#noc">noc</a> object. Must have an index when it has<br>
|
86 |
|
|
a related edge in the graph model (and allowing it to be able to do<br>
|
87 |
|
|
<a href="#channel">channel</a> searching). None means it is an <a href="#ipcore">ipcore</a> related <a href="#channel">channel</a><br>
|
88 |
|
|
* graph_ref optional reference to its graph model<br>
|
89 |
|
|
* endpoints optional two-item list with references to the connected objects<br> </tt></td></tr>
|
90 |
|
|
<tr><td> </td>
|
91 |
|
|
<td width="100%">Methods defined here:<br>
|
92 |
|
|
<dl><dt><a name="channel-__init__"><strong>__init__</strong></a>(self, name, index<font color="#909090">=None</font>, **kwargs)</dt></dl>
|
93 |
|
|
|
94 |
|
|
<dl><dt><a name="channel-is_ipcore_link"><strong>is_ipcore_link</strong></a>(self)</dt><dd><tt>Checks if this <a href="#channel">channel</a> is a special link for an <a href="#ipcore">ipcore</a>.<br>
|
95 |
|
|
<br>
|
96 |
|
|
Return: True if the <a href="#channel">channel</a> is related to an <a href="#ipcore">ipcore</a></tt></dd></dl>
|
97 |
|
|
|
98 |
|
|
<hr>
|
99 |
|
|
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br>
|
100 |
|
|
<dl><dt><a name="channel-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl>
|
101 |
|
|
|
102 |
|
|
</td></tr></table> <p>
|
103 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
104 |
|
|
<tr bgcolor="#ffc8d8">
|
105 |
|
|
<td colspan=3 valign=bottom> <br>
|
106 |
|
|
<font color="#000000" face="helvetica, arial"><a name="ipcore">class <strong>ipcore</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr>
|
107 |
|
|
|
108 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
109 |
|
|
<td colspan=2><tt>IP core base object<br>
|
110 |
|
|
<br>
|
111 |
|
|
This object represents a IP Core object and its properties. This base class<br>
|
112 |
|
|
is meant to either be inherited or extended by adding other attributes.<br>
|
113 |
|
|
<br>
|
114 |
|
|
Relations with other objects:<br>
|
115 |
|
|
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br>
|
116 |
|
|
* It should have one reference to a <a href="#router">router</a> object (self.<strong>router_ref</strong>), even if<br>
|
117 |
|
|
the <a href="#ipcore">ipcore</a> has a direct connection to the NoC.<br>
|
118 |
|
|
* It should have one reference to a <a href="#channel">channel</a> object (self.<strong>channel_ref</strong>). This<br>
|
119 |
|
|
<a href="#channel">channel</a> exclusively link this <a href="#ipcore">ipcore</a> and its <a href="#router">router</a>.<br>
|
120 |
|
|
<br>
|
121 |
|
|
Attributes:<br>
|
122 |
|
|
* name<br>
|
123 |
|
|
* router_ref: optional reference to its related <a href="#router">router</a>.<br>
|
124 |
|
|
* channel_ref: optional reference to its related <a href="#channel">channel</a><br>
|
125 |
|
|
* graph_ref: optional reference to its graph model<br> </tt></td></tr>
|
126 |
|
|
<tr><td> </td>
|
127 |
|
|
<td width="100%">Methods defined here:<br>
|
128 |
|
|
<dl><dt><a name="ipcore-__init__"><strong>__init__</strong></a>(self, name, **kwargs)</dt></dl>
|
129 |
|
|
|
130 |
|
|
<hr>
|
131 |
|
|
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br>
|
132 |
|
|
<dl><dt><a name="ipcore-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl>
|
133 |
|
|
|
134 |
|
|
</td></tr></table> <p>
|
135 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
136 |
|
|
<tr bgcolor="#ffc8d8">
|
137 |
|
|
<td colspan=3 valign=bottom> <br>
|
138 |
|
|
<font color="#000000" face="helvetica, arial"><a name="noc">class <strong>noc</strong></a>(<a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>)</font></td></tr>
|
139 |
|
|
|
140 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
141 |
|
|
<td colspan=2><tt>Base class for NoC modeling.<br>
|
142 |
|
|
Based on a <a href="networkx.classes.graph.html#Graph">Graph</a> object that hold the NoC structure<br>
|
143 |
|
|
<br>
|
144 |
|
|
Arguments<br>
|
145 |
|
|
* kwargs: optional parameters to put as object attributes<br> </tt></td></tr>
|
146 |
|
|
<tr><td> </td>
|
147 |
|
|
<td width="100%"><dl><dt>Method resolution order:</dt>
|
148 |
|
|
<dd><a href="nocmodel.noc_base.html#noc">noc</a></dd>
|
149 |
|
|
<dd><a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a></dd>
|
150 |
|
|
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
|
151 |
|
|
</dl>
|
152 |
|
|
<hr>
|
153 |
|
|
Methods defined here:<br>
|
154 |
|
|
<dl><dt><a name="noc-__init__"><strong>__init__</strong></a>(self, **kwargs)</dt><dd><tt>NoCmodel constructor</tt></dd></dl>
|
155 |
|
|
|
156 |
|
|
<dl><dt><a name="noc-add_channel"><strong>add_channel</strong></a>(self, router1, router2, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Create a base <a href="#channel">channel</a> object to link two objects and add it <br>
|
157 |
|
|
to NoC model.<br>
|
158 |
|
|
<br>
|
159 |
|
|
Arguments:<br>
|
160 |
|
|
* router1: reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br>
|
161 |
|
|
* router2: -idem-<br>
|
162 |
|
|
* name: optional argument for <a href="#channel">channel</a> name<br>
|
163 |
|
|
* kwargs: optional parameters to put as object attributes<br>
|
164 |
|
|
<br>
|
165 |
|
|
Notes:<br>
|
166 |
|
|
* If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br>
|
167 |
|
|
the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br>
|
168 |
|
|
if both arguments are ipcores, throw an error exception</tt></dd></dl>
|
169 |
|
|
|
170 |
|
|
<dl><dt><a name="noc-add_from_channel"><strong>add_from_channel</strong></a>(self, channel_ref, router1<font color="#909090">=None</font>, router2<font color="#909090">=None</font>)</dt><dd><tt>Add a <a href="#channel">channel</a> object to NoC model.<br>
|
171 |
|
|
<br>
|
172 |
|
|
Use this function to add an object based on a derived class of <br>
|
173 |
|
|
base <a href="#channel">channel</a> defined in this module.<br>
|
174 |
|
|
<br>
|
175 |
|
|
Arguments<br>
|
176 |
|
|
* channel_ref: reference to the <a href="#channel">channel</a> object<br>
|
177 |
|
|
* router1: optional reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br>
|
178 |
|
|
* router2: -idem-<br>
|
179 |
|
|
<br>
|
180 |
|
|
Return: the same reference passed in channel_ref<br>
|
181 |
|
|
<br>
|
182 |
|
|
Notes:<br>
|
183 |
|
|
* If router1 or router2 are not used as arguments, will assume that<br>
|
184 |
|
|
<a href="#channel">channel</a> object has defined its attribute "endpoints" with the <br>
|
185 |
|
|
objects to connect. If the objects don't exist in the NoC model,<br>
|
186 |
|
|
throw an error exception.<br>
|
187 |
|
|
<br>
|
188 |
|
|
* If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br>
|
189 |
|
|
the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br>
|
190 |
|
|
if both arguments are ipcores, throw an error exception.<br>
|
191 |
|
|
<br>
|
192 |
|
|
* This function will change channel_ref.index and channel_ref.graph_ref <br>
|
193 |
|
|
attributes when inserted in the NoC model. Also it may change <br>
|
194 |
|
|
channel_ref.endpoints with router1 and router2 references.</tt></dd></dl>
|
195 |
|
|
|
196 |
|
|
<dl><dt><a name="noc-add_from_ipcore"><strong>add_from_ipcore</strong></a>(self, ipcore_ref, router_ref, channel_ref<font color="#909090">=None</font>)</dt><dd><tt>Add a <a href="#ipcore">ipcore</a> object to NoC model.<br>
|
197 |
|
|
<br>
|
198 |
|
|
Arguments<br>
|
199 |
|
|
* ipcore_ref: reference to <a href="#ipcore">ipcore</a> object<br>
|
200 |
|
|
* router_ref: reference to an existing <a href="#router">router</a> to connect<br>
|
201 |
|
|
* channel_ref: optional <a href="#channel">channel</a> object that connect the <a href="#router">router</a> and<br>
|
202 |
|
|
the <a href="#ipcore">ipcore</a>. If not used, this function will create a new <a href="#channel">channel</a> object.<br>
|
203 |
|
|
<br>
|
204 |
|
|
Return: the same reference passed in ipcore_ref<br>
|
205 |
|
|
<br>
|
206 |
|
|
Notes:<br>
|
207 |
|
|
* This function automatically adds a special <a href="#channel">channel</a> object <br>
|
208 |
|
|
(<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl>
|
209 |
|
|
|
210 |
|
|
<dl><dt><a name="noc-add_ipcore"><strong>add_ipcore</strong></a>(self, router_ref, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Create an <a href="#ipcore">ipcore</a> object and connect it to the <a href="#router">router</a> reference argument<br>
|
211 |
|
|
<br>
|
212 |
|
|
Arguments<br>
|
213 |
|
|
* router_ref: reference to an existing <a href="#router">router</a><br>
|
214 |
|
|
* name: optional name for this <a href="#router">router</a>. By default has the form of <br>
|
215 |
|
|
"IP_<router_index>"<br>
|
216 |
|
|
* kwargs: optional parameters to put as object attributes<br>
|
217 |
|
|
<br>
|
218 |
|
|
Return: reference to the created <a href="#ipcore">ipcore</a> object<br>
|
219 |
|
|
<br>
|
220 |
|
|
Notes:<br>
|
221 |
|
|
* This function automatically adds a special <a href="#channel">channel</a> object <br>
|
222 |
|
|
(<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl>
|
223 |
|
|
|
224 |
|
|
<dl><dt><a name="noc-add_router"><strong>add_router</strong></a>(self, name<font color="#909090">=''</font>, with_ipcore<font color="#909090">=False</font>, **kwargs)</dt><dd><tt>Create a base <a href="#router">router</a> object and add it to NoC model.<br>
|
225 |
|
|
<br>
|
226 |
|
|
Arguments<br>
|
227 |
|
|
* name: optional name for this <a href="#router">router</a>. By default has the form of <br>
|
228 |
|
|
"R_<index>"<br>
|
229 |
|
|
* with_ipcore: If True, add an <a href="#ipcore">ipcore</a> to the created <a href="#router">router</a>.<br>
|
230 |
|
|
* kwargs: optional parameters to put as object attributes<br>
|
231 |
|
|
<br>
|
232 |
|
|
Return: reference to the created <a href="#router">router</a> object</tt></dd></dl>
|
233 |
|
|
|
234 |
|
|
<dl><dt><a name="noc-add_router_from_object"><strong>add_router_from_object</strong></a>(self, router_ref)</dt><dd><tt>Add an existing <a href="#router">router</a> object to NoC model.<br>
|
235 |
|
|
<br>
|
236 |
|
|
Use this function to add an object based on a derived class of <br>
|
237 |
|
|
base <a href="#router">router</a> defined in this module.<br>
|
238 |
|
|
<br>
|
239 |
|
|
Arguments<br>
|
240 |
|
|
* router_ref: reference to the <a href="#router">router</a> object<br>
|
241 |
|
|
<br>
|
242 |
|
|
Return: the same reference passed in router_ref<br>
|
243 |
|
|
<br>
|
244 |
|
|
Notes: <br>
|
245 |
|
|
* This function will change router_ref.index and router_ref.graph_ref <br>
|
246 |
|
|
attributes when inserted in the NoC model.</tt></dd></dl>
|
247 |
|
|
|
248 |
|
|
<dl><dt><a name="noc-all_list"><strong>all_list</strong></a>(self)</dt></dl>
|
249 |
|
|
|
250 |
|
|
<dl><dt><a name="noc-channel_list"><strong>channel_list</strong></a>(self)</dt></dl>
|
251 |
|
|
|
252 |
|
|
<dl><dt><a name="noc-del_channel"><strong>del_channel</strong></a>(self, channel_ref)</dt><dd><tt>Remove channel_ref from the NoC model<br>
|
253 |
|
|
<br>
|
254 |
|
|
TODO: not implemented</tt></dd></dl>
|
255 |
|
|
|
256 |
|
|
<dl><dt><a name="noc-del_ipcore"><strong>del_ipcore</strong></a>(self, ipcore_ref)</dt><dd><tt>Remove ipcore_ref from the NoC model<br>
|
257 |
|
|
<br>
|
258 |
|
|
TODO: not implemented</tt></dd></dl>
|
259 |
|
|
|
260 |
|
|
<dl><dt><a name="noc-del_router"><strong>del_router</strong></a>(self, router_ref)</dt><dd><tt>Remove router_ref from the NoC model<br>
|
261 |
|
|
<br>
|
262 |
|
|
TODO: not implemented</tt></dd></dl>
|
263 |
|
|
|
264 |
|
|
<dl><dt><a name="noc-get_router_by_address"><strong>get_router_by_address</strong></a>(self, address)</dt><dd><tt># query functions</tt></dd></dl>
|
265 |
|
|
|
266 |
|
|
<dl><dt><a name="noc-ipcore_list"><strong>ipcore_list</strong></a>(self)</dt></dl>
|
267 |
|
|
|
268 |
|
|
<dl><dt><a name="noc-router_list"><strong>router_list</strong></a>(self)</dt><dd><tt># list generation functions</tt></dd></dl>
|
269 |
|
|
|
270 |
|
|
<hr>
|
271 |
|
|
Methods inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br>
|
272 |
|
|
<dl><dt><a name="noc-__contains__"><strong>__contains__</strong></a>(self, n)</dt><dd><tt>Return True if n is a node, False otherwise. Use the expression<br>
|
273 |
|
|
'n in G'.<br>
|
274 |
|
|
<br>
|
275 |
|
|
Examples<br>
|
276 |
|
|
--------<br>
|
277 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
278 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
279 |
|
|
>>> print 1 in G<br>
|
280 |
|
|
True</tt></dd></dl>
|
281 |
|
|
|
282 |
|
|
<dl><dt><a name="noc-__getitem__"><strong>__getitem__</strong></a>(self, n)</dt><dd><tt>Return a <a href="__builtin__.html#dict">dict</a> of neighbors of node n. Use the expression 'G[n]'.<br>
|
283 |
|
|
<br>
|
284 |
|
|
Parameters<br>
|
285 |
|
|
----------<br>
|
286 |
|
|
n : node<br>
|
287 |
|
|
A node in the graph.<br>
|
288 |
|
|
<br>
|
289 |
|
|
Returns<br>
|
290 |
|
|
-------<br>
|
291 |
|
|
adj_dict : dictionary<br>
|
292 |
|
|
The adjacency dictionary for nodes connected to n.<br>
|
293 |
|
|
<br>
|
294 |
|
|
Notes<br>
|
295 |
|
|
-----<br>
|
296 |
|
|
G[n] is similar to G.<a href="#noc-neighbors">neighbors</a>(n) but the internal data dictionary<br>
|
297 |
|
|
is returned instead of a list.<br>
|
298 |
|
|
<br>
|
299 |
|
|
Assigning G[n] will corrupt the internal graph data structure.<br>
|
300 |
|
|
Use G[n] for reading data only.<br>
|
301 |
|
|
<br>
|
302 |
|
|
Examples<br>
|
303 |
|
|
--------<br>
|
304 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
305 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
306 |
|
|
>>> print G[0]<br>
|
307 |
|
|
{1: {}}</tt></dd></dl>
|
308 |
|
|
|
309 |
|
|
<dl><dt><a name="noc-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>Iterate over the nodes. Use the expression 'for n in G'.<br>
|
310 |
|
|
<br>
|
311 |
|
|
Returns<br>
|
312 |
|
|
-------<br>
|
313 |
|
|
niter : iterator<br>
|
314 |
|
|
An iterator over all nodes in the graph.<br>
|
315 |
|
|
<br>
|
316 |
|
|
Examples<br>
|
317 |
|
|
--------<br>
|
318 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
319 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
320 |
|
|
>>> for n in G:<br>
|
321 |
|
|
... print n,<br>
|
322 |
|
|
0 1 2 3</tt></dd></dl>
|
323 |
|
|
|
324 |
|
|
<dl><dt><a name="noc-__len__"><strong>__len__</strong></a>(self)</dt><dd><tt>Return the number of nodes. Use the expression 'len(G)'.<br>
|
325 |
|
|
<br>
|
326 |
|
|
Returns<br>
|
327 |
|
|
-------<br>
|
328 |
|
|
nnodes : int<br>
|
329 |
|
|
The number of nodes in the graph.<br>
|
330 |
|
|
<br>
|
331 |
|
|
Examples<br>
|
332 |
|
|
--------<br>
|
333 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
334 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
335 |
|
|
>>> print len(G)<br>
|
336 |
|
|
4</tt></dd></dl>
|
337 |
|
|
|
338 |
|
|
<dl><dt><a name="noc-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return the graph name.<br>
|
339 |
|
|
<br>
|
340 |
|
|
Returns<br>
|
341 |
|
|
-------<br>
|
342 |
|
|
name : string<br>
|
343 |
|
|
The name of the graph.<br>
|
344 |
|
|
<br>
|
345 |
|
|
Examples<br>
|
346 |
|
|
--------<br>
|
347 |
|
|
>>> G = nx.path_graph(4) <br>
|
348 |
|
|
>>> print G<br>
|
349 |
|
|
path_graph(4)</tt></dd></dl>
|
350 |
|
|
|
351 |
|
|
<dl><dt><a name="noc-add_cycle"><strong>add_cycle</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a cycle.<br>
|
352 |
|
|
<br>
|
353 |
|
|
Parameters<br>
|
354 |
|
|
----------<br>
|
355 |
|
|
nlist : list <br>
|
356 |
|
|
A list of nodes. A cycle will be constructed from<br>
|
357 |
|
|
the nodes (in order) and added to the graph.<br>
|
358 |
|
|
attr : keyword arguments, optional (default= no attributes)<br>
|
359 |
|
|
Attributes to add to every edge in cycle.<br>
|
360 |
|
|
<br>
|
361 |
|
|
See Also<br>
|
362 |
|
|
--------<br>
|
363 |
|
|
add_path, add_star<br>
|
364 |
|
|
<br>
|
365 |
|
|
Examples<br>
|
366 |
|
|
--------<br>
|
367 |
|
|
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
368 |
|
|
>>> G.<a href="#noc-add_cycle">add_cycle</a>([0,1,2,3])<br>
|
369 |
|
|
>>> G.<a href="#noc-add_cycle">add_cycle</a>([10,11,12],weight=7)</tt></dd></dl>
|
370 |
|
|
|
371 |
|
|
<dl><dt><a name="noc-add_edge"><strong>add_edge</strong></a>(self, u, v, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add an edge between u and v.<br>
|
372 |
|
|
<br>
|
373 |
|
|
The nodes u and v will be automatically added if they are <br>
|
374 |
|
|
not already in the graph. <br>
|
375 |
|
|
<br>
|
376 |
|
|
Edge attributes can be specified with keywords or by providing<br>
|
377 |
|
|
a dictionary with key/value pairs. See examples below.<br>
|
378 |
|
|
<br>
|
379 |
|
|
Parameters<br>
|
380 |
|
|
----------<br>
|
381 |
|
|
u,v : nodes<br>
|
382 |
|
|
Nodes can be, for example, strings or numbers. <br>
|
383 |
|
|
Nodes must be hashable (and not None) Python objects.<br>
|
384 |
|
|
attr_dict : dictionary, optional (default= no attributes)<br>
|
385 |
|
|
Dictionary of edge attributes. Key/value pairs will<br>
|
386 |
|
|
update existing data associated with the edge.<br>
|
387 |
|
|
attr : keyword arguments, optional<br>
|
388 |
|
|
Edge data (or labels or objects) can be assigned using<br>
|
389 |
|
|
keyword arguments. <br>
|
390 |
|
|
<br>
|
391 |
|
|
See Also<br>
|
392 |
|
|
--------<br>
|
393 |
|
|
add_edges_from : add a collection of edges<br>
|
394 |
|
|
<br>
|
395 |
|
|
Notes <br>
|
396 |
|
|
-----<br>
|
397 |
|
|
Adding an edge that already exists updates the edge data.<br>
|
398 |
|
|
<br>
|
399 |
|
|
NetworkX algorithms designed for weighted graphs use as<br>
|
400 |
|
|
the edge weight a numerical value assigned to the keyword<br>
|
401 |
|
|
'weight'.<br>
|
402 |
|
|
<br>
|
403 |
|
|
Examples<br>
|
404 |
|
|
--------<br>
|
405 |
|
|
The following all add the edge e=(1,2) to graph G:<br>
|
406 |
|
|
<br>
|
407 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
408 |
|
|
>>> e = (1,2)<br>
|
409 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 2) # explicit two-node form<br>
|
410 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(*e) # single edge as tuple of two nodes<br>
|
411 |
|
|
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>( [(1,2)] ) # add edges from iterable container<br>
|
412 |
|
|
<br>
|
413 |
|
|
Associate data to edges using keywords:<br>
|
414 |
|
|
<br>
|
415 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 2, weight=3)<br>
|
416 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1, 3, weight=7, capacity=15, length=342.7)</tt></dd></dl>
|
417 |
|
|
|
418 |
|
|
<dl><dt><a name="noc-add_edges_from"><strong>add_edges_from</strong></a>(self, ebunch, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add all the edges in ebunch.<br>
|
419 |
|
|
<br>
|
420 |
|
|
Parameters<br>
|
421 |
|
|
----------<br>
|
422 |
|
|
ebunch : container of edges<br>
|
423 |
|
|
Each edge given in the container will be added to the<br>
|
424 |
|
|
graph. The edges must be given as as 2-tuples (u,v) or<br>
|
425 |
|
|
3-tuples (u,v,d) where d is a dictionary containing edge<br>
|
426 |
|
|
data.<br>
|
427 |
|
|
attr_dict : dictionary, optional (default= no attributes)<br>
|
428 |
|
|
Dictionary of edge attributes. Key/value pairs will<br>
|
429 |
|
|
update existing data associated with each edge.<br>
|
430 |
|
|
attr : keyword arguments, optional<br>
|
431 |
|
|
Edge data (or labels or objects) can be assigned using<br>
|
432 |
|
|
keyword arguments. <br>
|
433 |
|
|
<br>
|
434 |
|
|
<br>
|
435 |
|
|
See Also<br>
|
436 |
|
|
--------<br>
|
437 |
|
|
add_edge : add a single edge<br>
|
438 |
|
|
add_weighted_edges_from : convenient way to add weighted edges<br>
|
439 |
|
|
<br>
|
440 |
|
|
Notes<br>
|
441 |
|
|
-----<br>
|
442 |
|
|
Adding the same edge twice has no effect but any edge data<br>
|
443 |
|
|
will be updated when each duplicate edge is added.<br>
|
444 |
|
|
<br>
|
445 |
|
|
Examples<br>
|
446 |
|
|
--------<br>
|
447 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
448 |
|
|
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(0,1),(1,2)]) # using a list of edge tuples<br>
|
449 |
|
|
>>> e = zip(range(0,3),range(1,4))<br>
|
450 |
|
|
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>(e) # Add the path graph 0-1-2-3<br>
|
451 |
|
|
<br>
|
452 |
|
|
Associate data to edges<br>
|
453 |
|
|
<br>
|
454 |
|
|
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(1,2),(2,3)], weight=3)<br>
|
455 |
|
|
>>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(3,4),(1,4)], label='WN2898')</tt></dd></dl>
|
456 |
|
|
|
457 |
|
|
<dl><dt><a name="noc-add_node"><strong>add_node</strong></a>(self, n, attr_dict<font color="#909090">=None</font>, **attr)</dt><dd><tt>Add a single node n and update node attributes.<br>
|
458 |
|
|
<br>
|
459 |
|
|
Parameters<br>
|
460 |
|
|
----------<br>
|
461 |
|
|
n : node<br>
|
462 |
|
|
A node can be any hashable Python object except None.<br>
|
463 |
|
|
attr_dict : dictionary, optional (default= no attributes)<br>
|
464 |
|
|
Dictionary of node attributes. Key/value pairs will<br>
|
465 |
|
|
update existing data associated with the node.<br>
|
466 |
|
|
attr : keyword arguments, optional<br>
|
467 |
|
|
Set or change attributes using key=value.<br>
|
468 |
|
|
<br>
|
469 |
|
|
See Also<br>
|
470 |
|
|
--------<br>
|
471 |
|
|
add_nodes_from<br>
|
472 |
|
|
<br>
|
473 |
|
|
Examples<br>
|
474 |
|
|
--------<br>
|
475 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
476 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>(1)<br>
|
477 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>('Hello')<br>
|
478 |
|
|
>>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br>
|
479 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>(K3)<br>
|
480 |
|
|
>>> G.<a href="#noc-number_of_nodes">number_of_nodes</a>()<br>
|
481 |
|
|
3<br>
|
482 |
|
|
<br>
|
483 |
|
|
Use keywords set/change node attributes:<br>
|
484 |
|
|
<br>
|
485 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>(1,size=10)<br>
|
486 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>(3,weight=0.4,UTM=('13S',382871,3972649))<br>
|
487 |
|
|
<br>
|
488 |
|
|
Notes<br>
|
489 |
|
|
-----<br>
|
490 |
|
|
A hashable object is one that can be used as a key in a Python<br>
|
491 |
|
|
dictionary. This includes strings, numbers, tuples of strings<br>
|
492 |
|
|
and numbers, etc.<br>
|
493 |
|
|
<br>
|
494 |
|
|
On many platforms hashable items also include mutables such as<br>
|
495 |
|
|
NetworkX Graphs, though one should be careful that the hash<br>
|
496 |
|
|
doesn't change on mutables.</tt></dd></dl>
|
497 |
|
|
|
498 |
|
|
<dl><dt><a name="noc-add_nodes_from"><strong>add_nodes_from</strong></a>(self, nodes, **attr)</dt><dd><tt>Add multiple nodes.<br>
|
499 |
|
|
<br>
|
500 |
|
|
Parameters<br>
|
501 |
|
|
----------<br>
|
502 |
|
|
nodes : iterable container<br>
|
503 |
|
|
A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). <br>
|
504 |
|
|
OR<br>
|
505 |
|
|
A container of (node, attribute <a href="__builtin__.html#dict">dict</a>) tuples.<br>
|
506 |
|
|
Node attributes are updated using the attribute <a href="__builtin__.html#dict">dict</a>.<br>
|
507 |
|
|
attr : keyword arguments, optional (default= no attributes)<br>
|
508 |
|
|
Update attributes for all nodes in nodes.<br>
|
509 |
|
|
Node attributes specified in nodes as a tuple<br>
|
510 |
|
|
take precedence over attributes specified generally.<br>
|
511 |
|
|
<br>
|
512 |
|
|
See Also<br>
|
513 |
|
|
--------<br>
|
514 |
|
|
add_node<br>
|
515 |
|
|
<br>
|
516 |
|
|
Examples<br>
|
517 |
|
|
--------<br>
|
518 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
519 |
|
|
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>('Hello')<br>
|
520 |
|
|
>>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br>
|
521 |
|
|
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>(K3)<br>
|
522 |
|
|
>>> sorted(G.<a href="#noc-nodes">nodes</a>())<br>
|
523 |
|
|
[0, 1, 2, 'H', 'e', 'l', 'o']<br>
|
524 |
|
|
<br>
|
525 |
|
|
Use keywords to update specific node attributes for every node.<br>
|
526 |
|
|
<br>
|
527 |
|
|
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([1,2], size=10)<br>
|
528 |
|
|
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([3,4], weight=0.4)<br>
|
529 |
|
|
<br>
|
530 |
|
|
Use (node, attrdict) tuples to update attributes for specific<br>
|
531 |
|
|
nodes.<br>
|
532 |
|
|
<br>
|
533 |
|
|
>>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([(1,<a href="__builtin__.html#dict">dict</a>(size=11)), (2,{'color':'blue'})])<br>
|
534 |
|
|
>>> G.node[1]['size']<br>
|
535 |
|
|
11<br>
|
536 |
|
|
>>> H = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>()<br>
|
537 |
|
|
>>> H.<a href="#noc-add_nodes_from">add_nodes_from</a>(G.<a href="#noc-nodes">nodes</a>(data=True))<br>
|
538 |
|
|
>>> H.node[1]['size']<br>
|
539 |
|
|
11</tt></dd></dl>
|
540 |
|
|
|
541 |
|
|
<dl><dt><a name="noc-add_path"><strong>add_path</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a path.<br>
|
542 |
|
|
<br>
|
543 |
|
|
Parameters<br>
|
544 |
|
|
----------<br>
|
545 |
|
|
nlist : list <br>
|
546 |
|
|
A list of nodes. A path will be constructed from<br>
|
547 |
|
|
the nodes (in order) and added to the graph.<br>
|
548 |
|
|
attr : keyword arguments, optional (default= no attributes)<br>
|
549 |
|
|
Attributes to add to every edge in path.<br>
|
550 |
|
|
<br>
|
551 |
|
|
See Also<br>
|
552 |
|
|
--------<br>
|
553 |
|
|
add_star, add_cycle<br>
|
554 |
|
|
<br>
|
555 |
|
|
Examples<br>
|
556 |
|
|
--------<br>
|
557 |
|
|
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
558 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
559 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([10,11,12],weight=7)</tt></dd></dl>
|
560 |
|
|
|
561 |
|
|
<dl><dt><a name="noc-add_star"><strong>add_star</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a star.<br>
|
562 |
|
|
<br>
|
563 |
|
|
The first node in nlist is the middle of the star. It is connected <br>
|
564 |
|
|
to all other nodes in nlist.<br>
|
565 |
|
|
<br>
|
566 |
|
|
Parameters<br>
|
567 |
|
|
----------<br>
|
568 |
|
|
nlist : list <br>
|
569 |
|
|
A list of nodes. <br>
|
570 |
|
|
attr : keyword arguments, optional (default= no attributes)<br>
|
571 |
|
|
Attributes to add to every edge in star.<br>
|
572 |
|
|
<br>
|
573 |
|
|
See Also<br>
|
574 |
|
|
--------<br>
|
575 |
|
|
add_path, add_cycle<br>
|
576 |
|
|
<br>
|
577 |
|
|
Examples<br>
|
578 |
|
|
--------<br>
|
579 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
580 |
|
|
>>> G.<a href="#noc-add_star">add_star</a>([0,1,2,3])<br>
|
581 |
|
|
>>> G.<a href="#noc-add_star">add_star</a>([10,11,12],weight=2)</tt></dd></dl>
|
582 |
|
|
|
583 |
|
|
<dl><dt><a name="noc-add_weighted_edges_from"><strong>add_weighted_edges_from</strong></a>(self, ebunch, **attr)</dt><dd><tt>Add all the edges in ebunch as weighted edges with specified<br>
|
584 |
|
|
weights.<br>
|
585 |
|
|
<br>
|
586 |
|
|
Parameters<br>
|
587 |
|
|
----------<br>
|
588 |
|
|
ebunch : container of edges<br>
|
589 |
|
|
Each edge given in the list or container will be added<br>
|
590 |
|
|
to the graph. The edges must be given as 3-tuples (u,v,w)<br>
|
591 |
|
|
where w is a number.<br>
|
592 |
|
|
attr : keyword arguments, optional (default= no attributes)<br>
|
593 |
|
|
Edge attributes to add/update for all edges.<br>
|
594 |
|
|
<br>
|
595 |
|
|
See Also<br>
|
596 |
|
|
--------<br>
|
597 |
|
|
add_edge : add a single edge<br>
|
598 |
|
|
add_edges_from : add multiple edges<br>
|
599 |
|
|
<br>
|
600 |
|
|
Notes<br>
|
601 |
|
|
-----<br>
|
602 |
|
|
Adding the same edge twice has no effect but any edge data<br>
|
603 |
|
|
will be updated when each duplicate edge is added.<br>
|
604 |
|
|
<br>
|
605 |
|
|
Examples<br>
|
606 |
|
|
--------<br>
|
607 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
608 |
|
|
>>> G.<a href="#noc-add_weighted_edges_from">add_weighted_edges_from</a>([(0,1,3.0),(1,2,7.5)])</tt></dd></dl>
|
609 |
|
|
|
610 |
|
|
<dl><dt><a name="noc-adjacency_iter"><strong>adjacency_iter</strong></a>(self)</dt><dd><tt>Return an iterator of (node, adjacency <a href="__builtin__.html#dict">dict</a>) tuples for all nodes.<br>
|
611 |
|
|
<br>
|
612 |
|
|
This is the fastest way to look at every edge. <br>
|
613 |
|
|
For directed graphs, only outgoing adjacencies are included.<br>
|
614 |
|
|
<br>
|
615 |
|
|
Returns<br>
|
616 |
|
|
-------<br>
|
617 |
|
|
adj_iter : iterator<br>
|
618 |
|
|
An iterator of (node, adjacency dictionary) for all nodes in<br>
|
619 |
|
|
the graph.<br>
|
620 |
|
|
<br>
|
621 |
|
|
See Also<br>
|
622 |
|
|
--------<br>
|
623 |
|
|
adjacency_list<br>
|
624 |
|
|
<br>
|
625 |
|
|
Examples <br>
|
626 |
|
|
--------<br>
|
627 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
628 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
629 |
|
|
>>> [(n,nbrdict) for n,nbrdict in G.<a href="#noc-adjacency_iter">adjacency_iter</a>()]<br>
|
630 |
|
|
[(0, {1: {}}), (1, {0: {}, 2: {}}), (2, {1: {}, 3: {}}), (3, {2: {}})]</tt></dd></dl>
|
631 |
|
|
|
632 |
|
|
<dl><dt><a name="noc-adjacency_list"><strong>adjacency_list</strong></a>(self)</dt><dd><tt>Return an adjacency list representation of the graph.<br>
|
633 |
|
|
<br>
|
634 |
|
|
The output adjacency list is in the order of G.<a href="#noc-nodes">nodes</a>().<br>
|
635 |
|
|
For directed graphs, only outgoing adjacencies are included. <br>
|
636 |
|
|
<br>
|
637 |
|
|
Returns<br>
|
638 |
|
|
-------<br>
|
639 |
|
|
adj_list : lists of lists<br>
|
640 |
|
|
The adjacency structure of the graph as a list of lists.<br>
|
641 |
|
|
<br>
|
642 |
|
|
See Also<br>
|
643 |
|
|
--------<br>
|
644 |
|
|
adjacency_iter<br>
|
645 |
|
|
<br>
|
646 |
|
|
Examples<br>
|
647 |
|
|
--------<br>
|
648 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
649 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
650 |
|
|
>>> G.<a href="#noc-adjacency_list">adjacency_list</a>() # in order given by G.<a href="#noc-nodes">nodes</a>()<br>
|
651 |
|
|
[[1], [0, 2], [1, 3], [2]]</tt></dd></dl>
|
652 |
|
|
|
653 |
|
|
<dl><dt><a name="noc-clear"><strong>clear</strong></a>(self)</dt><dd><tt>Remove all nodes and edges from the graph.<br>
|
654 |
|
|
<br>
|
655 |
|
|
This also removes the name, and all graph, node, and edge attributes.<br>
|
656 |
|
|
<br>
|
657 |
|
|
Examples<br>
|
658 |
|
|
--------<br>
|
659 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
660 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
661 |
|
|
>>> G.<a href="#noc-clear">clear</a>()<br>
|
662 |
|
|
>>> G.<a href="#noc-nodes">nodes</a>()<br>
|
663 |
|
|
[]<br>
|
664 |
|
|
>>> G.<a href="#noc-edges">edges</a>()<br>
|
665 |
|
|
[]</tt></dd></dl>
|
666 |
|
|
|
667 |
|
|
<dl><dt><a name="noc-copy"><strong>copy</strong></a>(self)</dt><dd><tt>Return a copy of the graph.<br>
|
668 |
|
|
<br>
|
669 |
|
|
Returns<br>
|
670 |
|
|
-------<br>
|
671 |
|
|
G : <a href="networkx.classes.graph.html#Graph">Graph</a><br>
|
672 |
|
|
A copy of the graph. <br>
|
673 |
|
|
<br>
|
674 |
|
|
See Also<br>
|
675 |
|
|
--------<br>
|
676 |
|
|
to_directed: return a directed copy of the graph.<br>
|
677 |
|
|
<br>
|
678 |
|
|
Notes<br>
|
679 |
|
|
-----<br>
|
680 |
|
|
This makes a complete copy of the graph including all of the <br>
|
681 |
|
|
node or edge attributes. <br>
|
682 |
|
|
<br>
|
683 |
|
|
Examples<br>
|
684 |
|
|
--------<br>
|
685 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
686 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
687 |
|
|
>>> H = G.<a href="#noc-copy">copy</a>()</tt></dd></dl>
|
688 |
|
|
|
689 |
|
|
<dl><dt><a name="noc-degree"><strong>degree</strong></a>(self, nbunch<font color="#909090">=None</font>, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return the degree of a node or nodes.<br>
|
690 |
|
|
<br>
|
691 |
|
|
The node degree is the number of edges adjacent to that node. <br>
|
692 |
|
|
<br>
|
693 |
|
|
Parameters<br>
|
694 |
|
|
----------<br>
|
695 |
|
|
nbunch : iterable container, optional (default=all nodes)<br>
|
696 |
|
|
A container of nodes. The container will be iterated<br>
|
697 |
|
|
through once. <br>
|
698 |
|
|
weighted : bool, optional (default=False)<br>
|
699 |
|
|
If True return the sum of edge weights adjacent to the node. <br>
|
700 |
|
|
<br>
|
701 |
|
|
Returns<br>
|
702 |
|
|
-------<br>
|
703 |
|
|
nd : dictionary, or number<br>
|
704 |
|
|
A dictionary with nodes as keys and degree as values or<br>
|
705 |
|
|
a number if a single node is specified.<br>
|
706 |
|
|
<br>
|
707 |
|
|
Examples<br>
|
708 |
|
|
--------<br>
|
709 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
710 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
711 |
|
|
>>> G.<a href="#noc-degree">degree</a>(0)<br>
|
712 |
|
|
1<br>
|
713 |
|
|
>>> G.<a href="#noc-degree">degree</a>([0,1])<br>
|
714 |
|
|
{0: 1, 1: 2}<br>
|
715 |
|
|
>>> G.<a href="#noc-degree">degree</a>([0,1]).values()<br>
|
716 |
|
|
[1, 2]</tt></dd></dl>
|
717 |
|
|
|
718 |
|
|
<dl><dt><a name="noc-degree_iter"><strong>degree_iter</strong></a>(self, nbunch<font color="#909090">=None</font>, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator for (node, degree). <br>
|
719 |
|
|
<br>
|
720 |
|
|
The node degree is the number of edges adjacent to the node. <br>
|
721 |
|
|
<br>
|
722 |
|
|
Parameters<br>
|
723 |
|
|
----------<br>
|
724 |
|
|
nbunch : iterable container, optional (default=all nodes)<br>
|
725 |
|
|
A container of nodes. The container will be iterated<br>
|
726 |
|
|
through once. <br>
|
727 |
|
|
weighted : bool, optional (default=False)<br>
|
728 |
|
|
If True return the sum of edge weights adjacent to the node. <br>
|
729 |
|
|
<br>
|
730 |
|
|
Returns<br>
|
731 |
|
|
-------<br>
|
732 |
|
|
nd_iter : an iterator <br>
|
733 |
|
|
The iterator returns two-tuples of (node, degree).<br>
|
734 |
|
|
<br>
|
735 |
|
|
See Also<br>
|
736 |
|
|
--------<br>
|
737 |
|
|
degree<br>
|
738 |
|
|
<br>
|
739 |
|
|
Examples<br>
|
740 |
|
|
--------<br>
|
741 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
742 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
743 |
|
|
>>> list(G.<a href="#noc-degree_iter">degree_iter</a>(0)) # node 0 with degree 1<br>
|
744 |
|
|
[(0, 1)]<br>
|
745 |
|
|
>>> list(G.<a href="#noc-degree_iter">degree_iter</a>([0,1]))<br>
|
746 |
|
|
[(0, 1), (1, 2)]</tt></dd></dl>
|
747 |
|
|
|
748 |
|
|
<dl><dt><a name="noc-edges"><strong>edges</strong></a>(self, nbunch<font color="#909090">=None</font>, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of edges.<br>
|
749 |
|
|
<br>
|
750 |
|
|
Edges are returned as tuples with optional data <br>
|
751 |
|
|
in the order (node, neighbor, data).<br>
|
752 |
|
|
<br>
|
753 |
|
|
Parameters<br>
|
754 |
|
|
----------<br>
|
755 |
|
|
nbunch : iterable container, optional (default= all nodes)<br>
|
756 |
|
|
A container of nodes. The container will be iterated<br>
|
757 |
|
|
through once.<br>
|
758 |
|
|
data : bool, optional (default=False)<br>
|
759 |
|
|
Return two tuples (u,v) (False) or three-tuples (u,v,data) (True).<br>
|
760 |
|
|
<br>
|
761 |
|
|
Returns<br>
|
762 |
|
|
--------<br>
|
763 |
|
|
edge_list: list of edge tuples<br>
|
764 |
|
|
Edges that are adjacent to any node in nbunch, or a list<br>
|
765 |
|
|
of all edges if nbunch is not specified.<br>
|
766 |
|
|
<br>
|
767 |
|
|
See Also<br>
|
768 |
|
|
--------<br>
|
769 |
|
|
edges_iter : return an iterator over the edges<br>
|
770 |
|
|
<br>
|
771 |
|
|
Notes<br>
|
772 |
|
|
-----<br>
|
773 |
|
|
Nodes in nbunch that are not in the graph will be (quietly) ignored.<br>
|
774 |
|
|
<br>
|
775 |
|
|
Examples<br>
|
776 |
|
|
--------<br>
|
777 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
778 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
779 |
|
|
>>> G.<a href="#noc-edges">edges</a>()<br>
|
780 |
|
|
[(0, 1), (1, 2), (2, 3)]<br>
|
781 |
|
|
>>> G.<a href="#noc-edges">edges</a>(data=True) # default edge data is {} (empty dictionary)<br>
|
782 |
|
|
[(0, 1, {}), (1, 2, {}), (2, 3, {})]<br>
|
783 |
|
|
>>> G.<a href="#noc-edges">edges</a>([0,3])<br>
|
784 |
|
|
[(0, 1), (3, 2)]<br>
|
785 |
|
|
>>> G.<a href="#noc-edges">edges</a>(0)<br>
|
786 |
|
|
[(0, 1)]</tt></dd></dl>
|
787 |
|
|
|
788 |
|
|
<dl><dt><a name="noc-edges_iter"><strong>edges_iter</strong></a>(self, nbunch<font color="#909090">=None</font>, data<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator over the edges.<br>
|
789 |
|
|
<br>
|
790 |
|
|
Edges are returned as tuples with optional data <br>
|
791 |
|
|
in the order (node, neighbor, data).<br>
|
792 |
|
|
<br>
|
793 |
|
|
Parameters<br>
|
794 |
|
|
----------<br>
|
795 |
|
|
nbunch : iterable container, optional (default= all nodes)<br>
|
796 |
|
|
A container of nodes. The container will be iterated<br>
|
797 |
|
|
through once.<br>
|
798 |
|
|
data : bool, optional (default=False)<br>
|
799 |
|
|
If True, return edge attribute <a href="__builtin__.html#dict">dict</a> in 3-tuple (u,v,data).<br>
|
800 |
|
|
<br>
|
801 |
|
|
Returns<br>
|
802 |
|
|
-------<br>
|
803 |
|
|
edge_iter : iterator<br>
|
804 |
|
|
An iterator of (u,v) or (u,v,d) tuples of edges.<br>
|
805 |
|
|
<br>
|
806 |
|
|
See Also<br>
|
807 |
|
|
--------<br>
|
808 |
|
|
edges : return a list of edges<br>
|
809 |
|
|
<br>
|
810 |
|
|
Notes<br>
|
811 |
|
|
-----<br>
|
812 |
|
|
Nodes in nbunch that are not in the graph will be (quietly) ignored.<br>
|
813 |
|
|
<br>
|
814 |
|
|
Examples<br>
|
815 |
|
|
--------<br>
|
816 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br>
|
817 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
818 |
|
|
>>> [e for e in G.<a href="#noc-edges_iter">edges_iter</a>()]<br>
|
819 |
|
|
[(0, 1), (1, 2), (2, 3)]<br>
|
820 |
|
|
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>(data=True)) # default data is {} (empty <a href="__builtin__.html#dict">dict</a>)<br>
|
821 |
|
|
[(0, 1, {}), (1, 2, {}), (2, 3, {})]<br>
|
822 |
|
|
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>([0,3]))<br>
|
823 |
|
|
[(0, 1), (3, 2)]<br>
|
824 |
|
|
>>> list(G.<a href="#noc-edges_iter">edges_iter</a>(0))<br>
|
825 |
|
|
[(0, 1)]</tt></dd></dl>
|
826 |
|
|
|
827 |
|
|
<dl><dt><a name="noc-get_edge_data"><strong>get_edge_data</strong></a>(self, u, v, default<font color="#909090">=None</font>)</dt><dd><tt>Return the attribute dictionary associated with edge (u,v).<br>
|
828 |
|
|
<br>
|
829 |
|
|
Parameters<br>
|
830 |
|
|
----------<br>
|
831 |
|
|
u,v : nodes<br>
|
832 |
|
|
default: any Python object (default=None) <br>
|
833 |
|
|
Value to return if the edge (u,v) is not found. <br>
|
834 |
|
|
<br>
|
835 |
|
|
Returns<br>
|
836 |
|
|
-------<br>
|
837 |
|
|
edge_dict : dictionary<br>
|
838 |
|
|
The edge attribute dictionary.<br>
|
839 |
|
|
<br>
|
840 |
|
|
Notes<br>
|
841 |
|
|
-----<br>
|
842 |
|
|
It is faster to use G[u][v].<br>
|
843 |
|
|
<br>
|
844 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
845 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
846 |
|
|
>>> G[0][1]<br>
|
847 |
|
|
{}<br>
|
848 |
|
|
<br>
|
849 |
|
|
Warning: Assigning G[u][v] corrupts the graph data structure.<br>
|
850 |
|
|
But it is safe to assign attributes to that dictionary,<br>
|
851 |
|
|
<br>
|
852 |
|
|
>>> G[0][1]['weight'] = 7<br>
|
853 |
|
|
>>> G[0][1]['weight']<br>
|
854 |
|
|
7<br>
|
855 |
|
|
>>> G[1][0]['weight']<br>
|
856 |
|
|
7<br>
|
857 |
|
|
<br>
|
858 |
|
|
Examples<br>
|
859 |
|
|
--------<br>
|
860 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
861 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
862 |
|
|
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>(0,1) # default edge data is {}<br>
|
863 |
|
|
{}<br>
|
864 |
|
|
>>> e = (0,1)<br>
|
865 |
|
|
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>(*e) # tuple form<br>
|
866 |
|
|
{}<br>
|
867 |
|
|
>>> G.<a href="#noc-get_edge_data">get_edge_data</a>('a','b',default=0) # edge not in graph, return 0<br>
|
868 |
|
|
0</tt></dd></dl>
|
869 |
|
|
|
870 |
|
|
<dl><dt><a name="noc-has_edge"><strong>has_edge</strong></a>(self, u, v)</dt><dd><tt>Return True if the edge (u,v) is in the graph.<br>
|
871 |
|
|
<br>
|
872 |
|
|
Parameters<br>
|
873 |
|
|
----------<br>
|
874 |
|
|
u,v : nodes<br>
|
875 |
|
|
Nodes can be, for example, strings or numbers. <br>
|
876 |
|
|
Nodes must be hashable (and not None) Python objects.<br>
|
877 |
|
|
<br>
|
878 |
|
|
Returns<br>
|
879 |
|
|
-------<br>
|
880 |
|
|
edge_ind : bool<br>
|
881 |
|
|
True if edge is in the graph, False otherwise.<br>
|
882 |
|
|
<br>
|
883 |
|
|
Examples<br>
|
884 |
|
|
--------<br>
|
885 |
|
|
Can be called either using two nodes u,v or edge tuple (u,v)<br>
|
886 |
|
|
<br>
|
887 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
888 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
889 |
|
|
>>> G.<a href="#noc-has_edge">has_edge</a>(0,1) # using two nodes<br>
|
890 |
|
|
True<br>
|
891 |
|
|
>>> e = (0,1)<br>
|
892 |
|
|
>>> G.<a href="#noc-has_edge">has_edge</a>(*e) # e is a 2-tuple (u,v)<br>
|
893 |
|
|
True<br>
|
894 |
|
|
>>> e = (0,1,{'weight':7})<br>
|
895 |
|
|
>>> G.<a href="#noc-has_edge">has_edge</a>(*e[:2]) # e is a 3-tuple (u,v,data_dictionary)<br>
|
896 |
|
|
True<br>
|
897 |
|
|
<br>
|
898 |
|
|
The following syntax are all equivalent: <br>
|
899 |
|
|
<br>
|
900 |
|
|
>>> G.<a href="#noc-has_edge">has_edge</a>(0,1)<br>
|
901 |
|
|
True<br>
|
902 |
|
|
>>> 1 in G[0] # though this gives KeyError if 0 not in G<br>
|
903 |
|
|
True</tt></dd></dl>
|
904 |
|
|
|
905 |
|
|
<dl><dt><a name="noc-has_node"><strong>has_node</strong></a>(self, n)</dt><dd><tt>Return True if the graph contains the node n.<br>
|
906 |
|
|
<br>
|
907 |
|
|
Parameters<br>
|
908 |
|
|
----------<br>
|
909 |
|
|
n : node<br>
|
910 |
|
|
<br>
|
911 |
|
|
Examples<br>
|
912 |
|
|
--------<br>
|
913 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
914 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
915 |
|
|
>>> print G.<a href="#noc-has_node">has_node</a>(0)<br>
|
916 |
|
|
True<br>
|
917 |
|
|
<br>
|
918 |
|
|
It is more readable and simpler to use<br>
|
919 |
|
|
<br>
|
920 |
|
|
>>> 0 in G<br>
|
921 |
|
|
True</tt></dd></dl>
|
922 |
|
|
|
923 |
|
|
<dl><dt><a name="noc-is_directed"><strong>is_directed</strong></a>(self)</dt><dd><tt>Return True if graph is directed, False otherwise.</tt></dd></dl>
|
924 |
|
|
|
925 |
|
|
<dl><dt><a name="noc-is_multigraph"><strong>is_multigraph</strong></a>(self)</dt><dd><tt>Return True if graph is a multigraph, False otherwise.</tt></dd></dl>
|
926 |
|
|
|
927 |
|
|
<dl><dt><a name="noc-nbunch_iter"><strong>nbunch_iter</strong></a>(self, nbunch<font color="#909090">=None</font>)</dt><dd><tt>Return an iterator of nodes contained in nbunch that are <br>
|
928 |
|
|
also in the graph.<br>
|
929 |
|
|
<br>
|
930 |
|
|
The nodes in nbunch are checked for membership in the graph<br>
|
931 |
|
|
and if not are silently ignored.<br>
|
932 |
|
|
<br>
|
933 |
|
|
Parameters<br>
|
934 |
|
|
----------<br>
|
935 |
|
|
nbunch : iterable container, optional (default=all nodes)<br>
|
936 |
|
|
A container of nodes. The container will be iterated<br>
|
937 |
|
|
through once. <br>
|
938 |
|
|
<br>
|
939 |
|
|
Returns<br>
|
940 |
|
|
-------<br>
|
941 |
|
|
niter : iterator<br>
|
942 |
|
|
An iterator over nodes in nbunch that are also in the graph.<br>
|
943 |
|
|
If nbunch is None, iterate over all nodes in the graph.<br>
|
944 |
|
|
<br>
|
945 |
|
|
Raises<br>
|
946 |
|
|
------<br>
|
947 |
|
|
NetworkXError<br>
|
948 |
|
|
If nbunch is not a node or or sequence of nodes.<br>
|
949 |
|
|
If a node in nbunch is not hashable.<br>
|
950 |
|
|
<br>
|
951 |
|
|
See Also<br>
|
952 |
|
|
--------<br>
|
953 |
|
|
<a href="networkx.classes.graph.html#Graph">Graph</a>.__iter__<br>
|
954 |
|
|
<br>
|
955 |
|
|
Notes <br>
|
956 |
|
|
-----<br>
|
957 |
|
|
When nbunch is an iterator, the returned iterator yields values <br>
|
958 |
|
|
directly from nbunch, becoming exhausted when nbunch is exhausted.<br>
|
959 |
|
|
<br>
|
960 |
|
|
To test whether nbunch is a single node, one can use <br>
|
961 |
|
|
"if nbunch in self:", even after processing with this routine.<br>
|
962 |
|
|
<br>
|
963 |
|
|
If nbunch is not a node or a (possibly empty) sequence/iterator<br>
|
964 |
|
|
or None, a NetworkXError is raised. Also, if any object in<br>
|
965 |
|
|
nbunch is not hashable, a NetworkXError is raised.</tt></dd></dl>
|
966 |
|
|
|
967 |
|
|
<dl><dt><a name="noc-neighbors"><strong>neighbors</strong></a>(self, n)</dt><dd><tt>Return a list of the nodes connected to the node n.<br>
|
968 |
|
|
<br>
|
969 |
|
|
Parameters<br>
|
970 |
|
|
----------<br>
|
971 |
|
|
n : node<br>
|
972 |
|
|
A node in the graph<br>
|
973 |
|
|
<br>
|
974 |
|
|
Returns<br>
|
975 |
|
|
-------<br>
|
976 |
|
|
nlist : list<br>
|
977 |
|
|
A list of nodes that are adjacent to n.<br>
|
978 |
|
|
<br>
|
979 |
|
|
Raises<br>
|
980 |
|
|
------<br>
|
981 |
|
|
NetworkXError<br>
|
982 |
|
|
If the node n is not in the graph. <br>
|
983 |
|
|
<br>
|
984 |
|
|
Notes<br>
|
985 |
|
|
-----<br>
|
986 |
|
|
It is usually more convenient (and faster) to access the<br>
|
987 |
|
|
adjacency dictionary as G[n]:<br>
|
988 |
|
|
<br>
|
989 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
990 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=7)<br>
|
991 |
|
|
>>> G['a']<br>
|
992 |
|
|
{'b': {'weight': 7}}<br>
|
993 |
|
|
<br>
|
994 |
|
|
Examples<br>
|
995 |
|
|
--------<br>
|
996 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
997 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
998 |
|
|
>>> G.<a href="#noc-neighbors">neighbors</a>(0)<br>
|
999 |
|
|
[1]</tt></dd></dl>
|
1000 |
|
|
|
1001 |
|
|
<dl><dt><a name="noc-neighbors_iter"><strong>neighbors_iter</strong></a>(self, n)</dt><dd><tt>Return an iterator over all neighbors of node n.<br>
|
1002 |
|
|
<br>
|
1003 |
|
|
Examples<br>
|
1004 |
|
|
--------<br>
|
1005 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1006 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1007 |
|
|
>>> print [n for n in G.<a href="#noc-neighbors_iter">neighbors_iter</a>(0)]<br>
|
1008 |
|
|
[1]<br>
|
1009 |
|
|
<br>
|
1010 |
|
|
Notes<br>
|
1011 |
|
|
-----<br>
|
1012 |
|
|
It is faster to use the idiom "in G[0]", e.g.<br>
|
1013 |
|
|
>>> for n in G[0]:<br>
|
1014 |
|
|
... print n<br>
|
1015 |
|
|
1</tt></dd></dl>
|
1016 |
|
|
|
1017 |
|
|
<dl><dt><a name="noc-nodes"><strong>nodes</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of the nodes in the graph.<br>
|
1018 |
|
|
<br>
|
1019 |
|
|
Parameters<br>
|
1020 |
|
|
----------<br>
|
1021 |
|
|
data : boolean, optional (default=False) <br>
|
1022 |
|
|
If False return a list of nodes. If True return a<br>
|
1023 |
|
|
two-tuple of node and node data dictionary<br>
|
1024 |
|
|
<br>
|
1025 |
|
|
Returns<br>
|
1026 |
|
|
-------<br>
|
1027 |
|
|
nlist : list<br>
|
1028 |
|
|
A list of nodes. If data=True a list of two-tuples containing<br>
|
1029 |
|
|
(node, node data dictionary). <br>
|
1030 |
|
|
<br>
|
1031 |
|
|
Examples<br>
|
1032 |
|
|
--------<br>
|
1033 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1034 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1035 |
|
|
>>> print G.<a href="#noc-nodes">nodes</a>()<br>
|
1036 |
|
|
[0, 1, 2]<br>
|
1037 |
|
|
>>> G.<a href="#noc-add_node">add_node</a>(1, time='5pm')<br>
|
1038 |
|
|
>>> print G.<a href="#noc-nodes">nodes</a>(data=True)<br>
|
1039 |
|
|
[(0, {}), (1, {'time': '5pm'}), (2, {})]</tt></dd></dl>
|
1040 |
|
|
|
1041 |
|
|
<dl><dt><a name="noc-nodes_iter"><strong>nodes_iter</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return an iterator over the nodes.<br>
|
1042 |
|
|
<br>
|
1043 |
|
|
Parameters<br>
|
1044 |
|
|
----------<br>
|
1045 |
|
|
data : boolean, optional (default=False)<br>
|
1046 |
|
|
If False the iterator returns nodes. If True<br>
|
1047 |
|
|
return a two-tuple of node and node data dictionary<br>
|
1048 |
|
|
<br>
|
1049 |
|
|
Returns<br>
|
1050 |
|
|
-------<br>
|
1051 |
|
|
niter : iterator<br>
|
1052 |
|
|
An iterator over nodes. If data=True the iterator gives <br>
|
1053 |
|
|
two-tuples containing (node, node data, dictionary) <br>
|
1054 |
|
|
<br>
|
1055 |
|
|
Notes<br>
|
1056 |
|
|
-----<br>
|
1057 |
|
|
If the node data is not required it is simpler and equivalent <br>
|
1058 |
|
|
to use the expression 'for n in G'.<br>
|
1059 |
|
|
<br>
|
1060 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1061 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1062 |
|
|
>>> for n in G:<br>
|
1063 |
|
|
... print n,<br>
|
1064 |
|
|
0 1 2<br>
|
1065 |
|
|
<br>
|
1066 |
|
|
<br>
|
1067 |
|
|
Examples<br>
|
1068 |
|
|
--------<br>
|
1069 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1070 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1071 |
|
|
>>> for n in G.<a href="#noc-nodes_iter">nodes_iter</a>():<br>
|
1072 |
|
|
... print n,<br>
|
1073 |
|
|
0 1 2<br>
|
1074 |
|
|
>>> for n,d in G.<a href="#noc-nodes_iter">nodes_iter</a>(data=True):<br>
|
1075 |
|
|
... print d,<br>
|
1076 |
|
|
{} {} {}</tt></dd></dl>
|
1077 |
|
|
|
1078 |
|
|
<dl><dt><a name="noc-nodes_with_selfloops"><strong>nodes_with_selfloops</strong></a>(self)</dt><dd><tt>Return a list of nodes with self loops.<br>
|
1079 |
|
|
<br>
|
1080 |
|
|
A node with a self loop has an edge with both ends adjacent<br>
|
1081 |
|
|
to that node.<br>
|
1082 |
|
|
<br>
|
1083 |
|
|
Returns<br>
|
1084 |
|
|
-------<br>
|
1085 |
|
|
nodelist : list<br>
|
1086 |
|
|
A list of nodes with self loops.<br>
|
1087 |
|
|
<br>
|
1088 |
|
|
See Also<br>
|
1089 |
|
|
--------<br>
|
1090 |
|
|
selfloop_edges, number_of_selfloops<br>
|
1091 |
|
|
<br>
|
1092 |
|
|
Examples<br>
|
1093 |
|
|
--------<br>
|
1094 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1095 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br>
|
1096 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br>
|
1097 |
|
|
>>> G.<a href="#noc-nodes_with_selfloops">nodes_with_selfloops</a>()<br>
|
1098 |
|
|
[1]</tt></dd></dl>
|
1099 |
|
|
|
1100 |
|
|
<dl><dt><a name="noc-number_of_edges"><strong>number_of_edges</strong></a>(self, u<font color="#909090">=None</font>, v<font color="#909090">=None</font>)</dt><dd><tt>Return the number of edges between two nodes.<br>
|
1101 |
|
|
<br>
|
1102 |
|
|
Parameters<br>
|
1103 |
|
|
----------<br>
|
1104 |
|
|
u,v : nodes, optional (default=all edges)<br>
|
1105 |
|
|
If u and v are specified, return the number of edges between <br>
|
1106 |
|
|
u and v. Otherwise return the total number of all edges.<br>
|
1107 |
|
|
<br>
|
1108 |
|
|
Returns<br>
|
1109 |
|
|
-------<br>
|
1110 |
|
|
nedges : int<br>
|
1111 |
|
|
The number of edges in the graph. If nodes u and v are specified<br>
|
1112 |
|
|
return the number of edges between those nodes.<br>
|
1113 |
|
|
<br>
|
1114 |
|
|
See Also<br>
|
1115 |
|
|
--------<br>
|
1116 |
|
|
size<br>
|
1117 |
|
|
<br>
|
1118 |
|
|
Examples<br>
|
1119 |
|
|
--------<br>
|
1120 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1121 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1122 |
|
|
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>()<br>
|
1123 |
|
|
3<br>
|
1124 |
|
|
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>(0,1) <br>
|
1125 |
|
|
1<br>
|
1126 |
|
|
>>> e = (0,1)<br>
|
1127 |
|
|
>>> G.<a href="#noc-number_of_edges">number_of_edges</a>(*e)<br>
|
1128 |
|
|
1</tt></dd></dl>
|
1129 |
|
|
|
1130 |
|
|
<dl><dt><a name="noc-number_of_nodes"><strong>number_of_nodes</strong></a>(self)</dt><dd><tt>Return the number of nodes in the graph.<br>
|
1131 |
|
|
<br>
|
1132 |
|
|
Returns<br>
|
1133 |
|
|
-------<br>
|
1134 |
|
|
nnodes : int<br>
|
1135 |
|
|
The number of nodes in the graph.<br>
|
1136 |
|
|
<br>
|
1137 |
|
|
See Also<br>
|
1138 |
|
|
--------<br>
|
1139 |
|
|
order, __len__ which are identical <br>
|
1140 |
|
|
<br>
|
1141 |
|
|
Examples<br>
|
1142 |
|
|
--------<br>
|
1143 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1144 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1145 |
|
|
>>> print len(G)<br>
|
1146 |
|
|
3</tt></dd></dl>
|
1147 |
|
|
|
1148 |
|
|
<dl><dt><a name="noc-number_of_selfloops"><strong>number_of_selfloops</strong></a>(self)</dt><dd><tt>Return the number of selfloop edges.<br>
|
1149 |
|
|
<br>
|
1150 |
|
|
A selfloop edge has the same node at both ends.<br>
|
1151 |
|
|
<br>
|
1152 |
|
|
Returns<br>
|
1153 |
|
|
-------<br>
|
1154 |
|
|
nloops : int<br>
|
1155 |
|
|
The number of selfloops. <br>
|
1156 |
|
|
<br>
|
1157 |
|
|
See Also<br>
|
1158 |
|
|
--------<br>
|
1159 |
|
|
selfloop_nodes, selfloop_edges<br>
|
1160 |
|
|
<br>
|
1161 |
|
|
Examples<br>
|
1162 |
|
|
--------<br>
|
1163 |
|
|
>>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1164 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br>
|
1165 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br>
|
1166 |
|
|
>>> G.<a href="#noc-number_of_selfloops">number_of_selfloops</a>()<br>
|
1167 |
|
|
1</tt></dd></dl>
|
1168 |
|
|
|
1169 |
|
|
<dl><dt><a name="noc-order"><strong>order</strong></a>(self)</dt><dd><tt>Return the number of nodes in the graph.<br>
|
1170 |
|
|
<br>
|
1171 |
|
|
Returns<br>
|
1172 |
|
|
-------<br>
|
1173 |
|
|
nnodes : int<br>
|
1174 |
|
|
The number of nodes in the graph.<br>
|
1175 |
|
|
<br>
|
1176 |
|
|
See Also<br>
|
1177 |
|
|
--------<br>
|
1178 |
|
|
number_of_nodes, __len__ which are identical</tt></dd></dl>
|
1179 |
|
|
|
1180 |
|
|
<dl><dt><a name="noc-remove_edge"><strong>remove_edge</strong></a>(self, u, v)</dt><dd><tt>Remove the edge between u and v.<br>
|
1181 |
|
|
<br>
|
1182 |
|
|
Parameters<br>
|
1183 |
|
|
----------<br>
|
1184 |
|
|
u,v: nodes <br>
|
1185 |
|
|
Remove the edge between nodes u and v.<br>
|
1186 |
|
|
<br>
|
1187 |
|
|
Raises<br>
|
1188 |
|
|
------<br>
|
1189 |
|
|
NetworkXError<br>
|
1190 |
|
|
If there is not an edge between u and v.<br>
|
1191 |
|
|
<br>
|
1192 |
|
|
See Also<br>
|
1193 |
|
|
--------<br>
|
1194 |
|
|
remove_edges_from : remove a collection of edges<br>
|
1195 |
|
|
<br>
|
1196 |
|
|
Examples<br>
|
1197 |
|
|
--------<br>
|
1198 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, etc<br>
|
1199 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1200 |
|
|
>>> G.<a href="#noc-remove_edge">remove_edge</a>(0,1)<br>
|
1201 |
|
|
>>> e = (1,2)<br>
|
1202 |
|
|
>>> G.<a href="#noc-remove_edge">remove_edge</a>(*e) # unpacks e from an edge tuple<br>
|
1203 |
|
|
>>> e = (2,3,{'weight':7}) # an edge with attribute data<br>
|
1204 |
|
|
>>> G.<a href="#noc-remove_edge">remove_edge</a>(*e[:2]) # select first part of edge tuple</tt></dd></dl>
|
1205 |
|
|
|
1206 |
|
|
<dl><dt><a name="noc-remove_edges_from"><strong>remove_edges_from</strong></a>(self, ebunch)</dt><dd><tt>Remove all edges specified in ebunch.<br>
|
1207 |
|
|
<br>
|
1208 |
|
|
Parameters<br>
|
1209 |
|
|
----------<br>
|
1210 |
|
|
ebunch: list or container of edge tuples<br>
|
1211 |
|
|
Each edge given in the list or container will be removed <br>
|
1212 |
|
|
from the graph. The edges can be:<br>
|
1213 |
|
|
<br>
|
1214 |
|
|
- 2-tuples (u,v) edge between u and v.<br>
|
1215 |
|
|
- 3-tuples (u,v,k) where k is ignored.<br>
|
1216 |
|
|
<br>
|
1217 |
|
|
See Also<br>
|
1218 |
|
|
--------<br>
|
1219 |
|
|
remove_edge : remove a single edge<br>
|
1220 |
|
|
<br>
|
1221 |
|
|
Notes<br>
|
1222 |
|
|
-----<br>
|
1223 |
|
|
Will fail silently if an edge in ebunch is not in the graph.<br>
|
1224 |
|
|
<br>
|
1225 |
|
|
Examples<br>
|
1226 |
|
|
--------<br>
|
1227 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1228 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1229 |
|
|
>>> ebunch=[(1,2),(2,3)]<br>
|
1230 |
|
|
>>> G.<a href="#noc-remove_edges_from">remove_edges_from</a>(ebunch)</tt></dd></dl>
|
1231 |
|
|
|
1232 |
|
|
<dl><dt><a name="noc-remove_node"><strong>remove_node</strong></a>(self, n)</dt><dd><tt>Remove node n.<br>
|
1233 |
|
|
<br>
|
1234 |
|
|
Removes the node n and all adjacent edges.<br>
|
1235 |
|
|
Attempting to remove a non-existent node will raise an exception.<br>
|
1236 |
|
|
<br>
|
1237 |
|
|
Parameters<br>
|
1238 |
|
|
----------<br>
|
1239 |
|
|
n : node<br>
|
1240 |
|
|
A node in the graph<br>
|
1241 |
|
|
<br>
|
1242 |
|
|
Raises<br>
|
1243 |
|
|
-------<br>
|
1244 |
|
|
NetworkXError<br>
|
1245 |
|
|
If n is not in the graph.<br>
|
1246 |
|
|
<br>
|
1247 |
|
|
See Also<br>
|
1248 |
|
|
--------<br>
|
1249 |
|
|
remove_nodes_from<br>
|
1250 |
|
|
<br>
|
1251 |
|
|
Examples<br>
|
1252 |
|
|
--------<br>
|
1253 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1254 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1255 |
|
|
>>> G.<a href="#noc-edges">edges</a>()<br>
|
1256 |
|
|
[(0, 1), (1, 2)]<br>
|
1257 |
|
|
>>> G.<a href="#noc-remove_node">remove_node</a>(1)<br>
|
1258 |
|
|
>>> G.<a href="#noc-edges">edges</a>()<br>
|
1259 |
|
|
[]</tt></dd></dl>
|
1260 |
|
|
|
1261 |
|
|
<dl><dt><a name="noc-remove_nodes_from"><strong>remove_nodes_from</strong></a>(self, nodes)</dt><dd><tt>Remove multiple nodes.<br>
|
1262 |
|
|
<br>
|
1263 |
|
|
Parameters<br>
|
1264 |
|
|
----------<br>
|
1265 |
|
|
nodes : iterable container<br>
|
1266 |
|
|
A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). If a node<br>
|
1267 |
|
|
in the container is not in the graph it is silently<br>
|
1268 |
|
|
ignored.<br>
|
1269 |
|
|
<br>
|
1270 |
|
|
See Also<br>
|
1271 |
|
|
--------<br>
|
1272 |
|
|
remove_node<br>
|
1273 |
|
|
<br>
|
1274 |
|
|
Examples<br>
|
1275 |
|
|
--------<br>
|
1276 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1277 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br>
|
1278 |
|
|
>>> e = G.<a href="#noc-nodes">nodes</a>()<br>
|
1279 |
|
|
>>> e<br>
|
1280 |
|
|
[0, 1, 2]<br>
|
1281 |
|
|
>>> G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>(e)<br>
|
1282 |
|
|
>>> G.<a href="#noc-nodes">nodes</a>()<br>
|
1283 |
|
|
[]</tt></dd></dl>
|
1284 |
|
|
|
1285 |
|
|
<dl><dt><a name="noc-selfloop_edges"><strong>selfloop_edges</strong></a>(self, data<font color="#909090">=False</font>)</dt><dd><tt>Return a list of selfloop edges.<br>
|
1286 |
|
|
<br>
|
1287 |
|
|
A selfloop edge has the same node at both ends.<br>
|
1288 |
|
|
<br>
|
1289 |
|
|
Parameters<br>
|
1290 |
|
|
-----------<br>
|
1291 |
|
|
data : bool, optional (default=False)<br>
|
1292 |
|
|
Return selfloop edges as two tuples (u,v) (data=False)<br>
|
1293 |
|
|
or three-tuples (u,v,data) (data=True)<br>
|
1294 |
|
|
<br>
|
1295 |
|
|
Returns<br>
|
1296 |
|
|
-------<br>
|
1297 |
|
|
edgelist : list of edge tuples<br>
|
1298 |
|
|
A list of all selfloop edges.<br>
|
1299 |
|
|
<br>
|
1300 |
|
|
See Also<br>
|
1301 |
|
|
--------<br>
|
1302 |
|
|
selfloop_nodes, number_of_selfloops<br>
|
1303 |
|
|
<br>
|
1304 |
|
|
Examples<br>
|
1305 |
|
|
--------<br>
|
1306 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1307 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br>
|
1308 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br>
|
1309 |
|
|
>>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>()<br>
|
1310 |
|
|
[(1, 1)]<br>
|
1311 |
|
|
>>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>(data=True)<br>
|
1312 |
|
|
[(1, 1, {})]</tt></dd></dl>
|
1313 |
|
|
|
1314 |
|
|
<dl><dt><a name="noc-size"><strong>size</strong></a>(self, weighted<font color="#909090">=False</font>)</dt><dd><tt>Return the number of edges.<br>
|
1315 |
|
|
<br>
|
1316 |
|
|
Parameters<br>
|
1317 |
|
|
----------<br>
|
1318 |
|
|
weighted : boolean, optional (default=False)<br>
|
1319 |
|
|
If True return the sum of the edge weights.<br>
|
1320 |
|
|
<br>
|
1321 |
|
|
Returns<br>
|
1322 |
|
|
-------<br>
|
1323 |
|
|
nedges : int<br>
|
1324 |
|
|
The number of edges in the graph.<br>
|
1325 |
|
|
<br>
|
1326 |
|
|
See Also<br>
|
1327 |
|
|
--------<br>
|
1328 |
|
|
number_of_edges<br>
|
1329 |
|
|
<br>
|
1330 |
|
|
Examples<br>
|
1331 |
|
|
--------<br>
|
1332 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1333 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1334 |
|
|
>>> G.<a href="#noc-size">size</a>()<br>
|
1335 |
|
|
3<br>
|
1336 |
|
|
<br>
|
1337 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1338 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=2)<br>
|
1339 |
|
|
>>> G.<a href="#noc-add_edge">add_edge</a>('b','c',weight=4)<br>
|
1340 |
|
|
>>> G.<a href="#noc-size">size</a>()<br>
|
1341 |
|
|
2<br>
|
1342 |
|
|
>>> G.<a href="#noc-size">size</a>(weighted=True)<br>
|
1343 |
|
|
6</tt></dd></dl>
|
1344 |
|
|
|
1345 |
|
|
<dl><dt><a name="noc-subgraph"><strong>subgraph</strong></a>(self, nbunch)</dt><dd><tt>Return the subgraph induced on nodes in nbunch.<br>
|
1346 |
|
|
<br>
|
1347 |
|
|
The induced subgraph of the graph contains the nodes in nbunch <br>
|
1348 |
|
|
and the edges between those nodes. <br>
|
1349 |
|
|
<br>
|
1350 |
|
|
Parameters<br>
|
1351 |
|
|
----------<br>
|
1352 |
|
|
nbunch : list, iterable<br>
|
1353 |
|
|
A container of nodes which will be iterated through once. <br>
|
1354 |
|
|
<br>
|
1355 |
|
|
Returns<br>
|
1356 |
|
|
-------<br>
|
1357 |
|
|
G : <a href="networkx.classes.graph.html#Graph">Graph</a><br>
|
1358 |
|
|
A subgraph of the graph with the same edge attributes. <br>
|
1359 |
|
|
<br>
|
1360 |
|
|
Notes<br>
|
1361 |
|
|
-----<br>
|
1362 |
|
|
The graph, edge or node attributes just point to the original graph.<br>
|
1363 |
|
|
So changes to the node or edge structure will not be reflected in<br>
|
1364 |
|
|
the original graph while changes to the attributes will.<br>
|
1365 |
|
|
<br>
|
1366 |
|
|
To create a subgraph with its own copy of the edge/node attributes use:<br>
|
1367 |
|
|
nx.<a href="networkx.classes.graph.html#Graph">Graph</a>(G.<a href="#noc-subgraph">subgraph</a>(nbunch))<br>
|
1368 |
|
|
<br>
|
1369 |
|
|
If edge attributes are containers, a deep copy can be obtained using:<br>
|
1370 |
|
|
G.<a href="#noc-subgraph">subgraph</a>(nbunch).<a href="#noc-copy">copy</a>()<br>
|
1371 |
|
|
<br>
|
1372 |
|
|
For an in-place reduction of a graph to a subgraph you can remove nodes:<br>
|
1373 |
|
|
G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>([ n in G if n not in set(nbunch)]) <br>
|
1374 |
|
|
<br>
|
1375 |
|
|
Examples<br>
|
1376 |
|
|
--------<br>
|
1377 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br>
|
1378 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br>
|
1379 |
|
|
>>> H = G.<a href="#noc-subgraph">subgraph</a>([0,1,2])<br>
|
1380 |
|
|
>>> print H.<a href="#noc-edges">edges</a>()<br>
|
1381 |
|
|
[(0, 1), (1, 2)]</tt></dd></dl>
|
1382 |
|
|
|
1383 |
|
|
<dl><dt><a name="noc-to_directed"><strong>to_directed</strong></a>(self)</dt><dd><tt>Return a directed representation of the graph.<br>
|
1384 |
|
|
<br>
|
1385 |
|
|
Returns<br>
|
1386 |
|
|
-------<br>
|
1387 |
|
|
G : DiGraph<br>
|
1388 |
|
|
A directed graph with the same name, same nodes, and with<br>
|
1389 |
|
|
each edge (u,v,data) replaced by two directed edges<br>
|
1390 |
|
|
(u,v,data) and (v,u,data).<br>
|
1391 |
|
|
<br>
|
1392 |
|
|
Notes<br>
|
1393 |
|
|
-----<br>
|
1394 |
|
|
This returns a "deepcopy" of the edge, node, and <br>
|
1395 |
|
|
graph attributes which attempts to completely copy<br>
|
1396 |
|
|
all of the data and references.<br>
|
1397 |
|
|
<br>
|
1398 |
|
|
This is in contrast to the similar D=DiGraph(G) which returns a <br>
|
1399 |
|
|
shallow copy of the data. <br>
|
1400 |
|
|
<br>
|
1401 |
|
|
See the Python copy module for more information on shallow<br>
|
1402 |
|
|
and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br>
|
1403 |
|
|
<br>
|
1404 |
|
|
Examples<br>
|
1405 |
|
|
--------<br>
|
1406 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br>
|
1407 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br>
|
1408 |
|
|
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br>
|
1409 |
|
|
>>> H.<a href="#noc-edges">edges</a>()<br>
|
1410 |
|
|
[(0, 1), (1, 0)]<br>
|
1411 |
|
|
<br>
|
1412 |
|
|
If already directed, return a (deep) copy<br>
|
1413 |
|
|
<br>
|
1414 |
|
|
>>> G = nx.DiGraph() # or MultiDiGraph, etc<br>
|
1415 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br>
|
1416 |
|
|
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br>
|
1417 |
|
|
>>> H.<a href="#noc-edges">edges</a>()<br>
|
1418 |
|
|
[(0, 1)]</tt></dd></dl>
|
1419 |
|
|
|
1420 |
|
|
<dl><dt><a name="noc-to_undirected"><strong>to_undirected</strong></a>(self)</dt><dd><tt>Return an undirected copy of the graph. <br>
|
1421 |
|
|
<br>
|
1422 |
|
|
Returns<br>
|
1423 |
|
|
-------<br>
|
1424 |
|
|
G : <a href="networkx.classes.graph.html#Graph">Graph</a>/MultiGraph<br>
|
1425 |
|
|
A deepcopy of the graph.<br>
|
1426 |
|
|
<br>
|
1427 |
|
|
See Also<br>
|
1428 |
|
|
--------<br>
|
1429 |
|
|
copy, add_edge, add_edges_from<br>
|
1430 |
|
|
<br>
|
1431 |
|
|
Notes<br>
|
1432 |
|
|
-----<br>
|
1433 |
|
|
This returns a "deepcopy" of the edge, node, and <br>
|
1434 |
|
|
graph attributes which attempts to completely copy<br>
|
1435 |
|
|
all of the data and references.<br>
|
1436 |
|
|
<br>
|
1437 |
|
|
This is in contrast to the similar G=DiGraph(D) which returns a <br>
|
1438 |
|
|
shallow copy of the data. <br>
|
1439 |
|
|
<br>
|
1440 |
|
|
See the Python copy module for more information on shallow<br>
|
1441 |
|
|
and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br>
|
1442 |
|
|
<br>
|
1443 |
|
|
Examples<br>
|
1444 |
|
|
--------<br>
|
1445 |
|
|
>>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br>
|
1446 |
|
|
>>> G.<a href="#noc-add_path">add_path</a>([0,1])<br>
|
1447 |
|
|
>>> H = G.<a href="#noc-to_directed">to_directed</a>()<br>
|
1448 |
|
|
>>> H.<a href="#noc-edges">edges</a>()<br>
|
1449 |
|
|
[(0, 1), (1, 0)]<br>
|
1450 |
|
|
>>> G2 = H.<a href="#noc-to_undirected">to_undirected</a>()<br>
|
1451 |
|
|
>>> G2.<a href="#noc-edges">edges</a>()<br>
|
1452 |
|
|
[(0, 1)]</tt></dd></dl>
|
1453 |
|
|
|
1454 |
|
|
<hr>
|
1455 |
|
|
Data descriptors inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br>
|
1456 |
|
|
<dl><dt><strong>__dict__</strong></dt>
|
1457 |
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
1458 |
|
|
</dl>
|
1459 |
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
1460 |
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
1461 |
|
|
</dl>
|
1462 |
|
|
</td></tr></table> <p>
|
1463 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
1464 |
|
|
<tr bgcolor="#ffc8d8">
|
1465 |
|
|
<td colspan=3 valign=bottom> <br>
|
1466 |
|
|
<font color="#000000" face="helvetica, arial"><a name="nocobject">class <strong>nocobject</strong></a></font></td></tr>
|
1467 |
|
|
|
1468 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
1469 |
|
|
<td colspan=2><tt>NoC base object<br>
|
1470 |
|
|
<br>
|
1471 |
|
|
This base class is used to implement common methods for NoC objects.<br>
|
1472 |
|
|
Don't use directly.<br> </tt></td></tr>
|
1473 |
|
|
<tr><td> </td>
|
1474 |
|
|
<td width="100%">Methods defined here:<br>
|
1475 |
|
|
<dl><dt><a name="nocobject-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl>
|
1476 |
|
|
|
1477 |
|
|
</td></tr></table> <p>
|
1478 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
1479 |
|
|
<tr bgcolor="#ffc8d8">
|
1480 |
|
|
<td colspan=3 valign=bottom> <br>
|
1481 |
|
|
<font color="#000000" face="helvetica, arial"><a name="packet">class <strong>packet</strong></a>(<a href="__builtin__.html#dict">__builtin__.dict</a>)</font></td></tr>
|
1482 |
|
|
|
1483 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
1484 |
|
|
<td colspan=2><tt>Packet base object<br>
|
1485 |
|
|
<br>
|
1486 |
|
|
This object represents a <a href="#packet">packet</a> data, related to a <a href="#protocol">protocol</a> object. It <br>
|
1487 |
|
|
behaves exactly like a Python dictionary, but adds methods to simplify <br>
|
1488 |
|
|
<a href="#packet">packet</a> transformations. <br>
|
1489 |
|
|
<br>
|
1490 |
|
|
Relations with other objects:<br>
|
1491 |
|
|
* It should be generated by a <a href="#protocol">protocol</a> object (and will have a reference <br>
|
1492 |
|
|
in self.<strong>protocol_ref</strong>)<br>
|
1493 |
|
|
<br>
|
1494 |
|
|
Attributes:<br>
|
1495 |
|
|
* protocol_ref: <a href="#protocol">protocol</a> object that created this object.<br> </tt></td></tr>
|
1496 |
|
|
<tr><td> </td>
|
1497 |
|
|
<td width="100%"><dl><dt>Method resolution order:</dt>
|
1498 |
|
|
<dd><a href="nocmodel.noc_base.html#packet">packet</a></dd>
|
1499 |
|
|
<dd><a href="__builtin__.html#dict">__builtin__.dict</a></dd>
|
1500 |
|
|
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
|
1501 |
|
|
</dl>
|
1502 |
|
|
<hr>
|
1503 |
|
|
Methods defined here:<br>
|
1504 |
|
|
<dl><dt><a name="packet-__init__"><strong>__init__</strong></a>(self, *args, **kwargs)</dt><dd><tt># the constructor</tt></dd></dl>
|
1505 |
|
|
|
1506 |
|
|
<hr>
|
1507 |
|
|
Data descriptors defined here:<br>
|
1508 |
|
|
<dl><dt><strong>__dict__</strong></dt>
|
1509 |
|
|
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
|
1510 |
|
|
</dl>
|
1511 |
|
|
<dl><dt><strong>__weakref__</strong></dt>
|
1512 |
|
|
<dd><tt>list of weak references to the object (if defined)</tt></dd>
|
1513 |
|
|
</dl>
|
1514 |
|
|
<hr>
|
1515 |
|
|
Methods inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br>
|
1516 |
|
|
<dl><dt><a name="packet-__cmp__"><strong>__cmp__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__cmp__">__cmp__</a>(y) <==> cmp(x,y)</tt></dd></dl>
|
1517 |
|
|
|
1518 |
|
|
<dl><dt><a name="packet-__contains__"><strong>__contains__</strong></a>(...)</dt><dd><tt>D.<a href="#packet-__contains__">__contains__</a>(k) -> True if D has a key k, else False</tt></dd></dl>
|
1519 |
|
|
|
1520 |
|
|
<dl><dt><a name="packet-__delitem__"><strong>__delitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__delitem__">__delitem__</a>(y) <==> del x[y]</tt></dd></dl>
|
1521 |
|
|
|
1522 |
|
|
<dl><dt><a name="packet-__eq__"><strong>__eq__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__eq__">__eq__</a>(y) <==> x==y</tt></dd></dl>
|
1523 |
|
|
|
1524 |
|
|
<dl><dt><a name="packet-__ge__"><strong>__ge__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__ge__">__ge__</a>(y) <==> x>=y</tt></dd></dl>
|
1525 |
|
|
|
1526 |
|
|
<dl><dt><a name="packet-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
|
1527 |
|
|
|
1528 |
|
|
<dl><dt><a name="packet-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
|
1529 |
|
|
|
1530 |
|
|
<dl><dt><a name="packet-__gt__"><strong>__gt__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__gt__">__gt__</a>(y) <==> x>y</tt></dd></dl>
|
1531 |
|
|
|
1532 |
|
|
<dl><dt><a name="packet-__iter__"><strong>__iter__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__iter__">__iter__</a>() <==> iter(x)</tt></dd></dl>
|
1533 |
|
|
|
1534 |
|
|
<dl><dt><a name="packet-__le__"><strong>__le__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__le__">__le__</a>(y) <==> x<=y</tt></dd></dl>
|
1535 |
|
|
|
1536 |
|
|
<dl><dt><a name="packet-__len__"><strong>__len__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__len__">__len__</a>() <==> len(x)</tt></dd></dl>
|
1537 |
|
|
|
1538 |
|
|
<dl><dt><a name="packet-__lt__"><strong>__lt__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__lt__">__lt__</a>(y) <==> x<y</tt></dd></dl>
|
1539 |
|
|
|
1540 |
|
|
<dl><dt><a name="packet-__ne__"><strong>__ne__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__ne__">__ne__</a>(y) <==> x!=y</tt></dd></dl>
|
1541 |
|
|
|
1542 |
|
|
<dl><dt><a name="packet-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
|
1543 |
|
|
|
1544 |
|
|
<dl><dt><a name="packet-__setitem__"><strong>__setitem__</strong></a>(...)</dt><dd><tt>x.<a href="#packet-__setitem__">__setitem__</a>(i, y) <==> x[i]=y</tt></dd></dl>
|
1545 |
|
|
|
1546 |
|
|
<dl><dt><a name="packet-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>D.<a href="#packet-__sizeof__">__sizeof__</a>() -> size of D in memory, in bytes</tt></dd></dl>
|
1547 |
|
|
|
1548 |
|
|
<dl><dt><a name="packet-clear"><strong>clear</strong></a>(...)</dt><dd><tt>D.<a href="#packet-clear">clear</a>() -> None. Remove all items from D.</tt></dd></dl>
|
1549 |
|
|
|
1550 |
|
|
<dl><dt><a name="packet-copy"><strong>copy</strong></a>(...)</dt><dd><tt>D.<a href="#packet-copy">copy</a>() -> a shallow copy of D</tt></dd></dl>
|
1551 |
|
|
|
1552 |
|
|
<dl><dt><a name="packet-get"><strong>get</strong></a>(...)</dt><dd><tt>D.<a href="#packet-get">get</a>(k[,d]) -> D[k] if k in D, else d. d defaults to None.</tt></dd></dl>
|
1553 |
|
|
|
1554 |
|
|
<dl><dt><a name="packet-has_key"><strong>has_key</strong></a>(...)</dt><dd><tt>D.<a href="#packet-has_key">has_key</a>(k) -> True if D has a key k, else False</tt></dd></dl>
|
1555 |
|
|
|
1556 |
|
|
<dl><dt><a name="packet-items"><strong>items</strong></a>(...)</dt><dd><tt>D.<a href="#packet-items">items</a>() -> list of D's (key, value) pairs, as 2-tuples</tt></dd></dl>
|
1557 |
|
|
|
1558 |
|
|
<dl><dt><a name="packet-iteritems"><strong>iteritems</strong></a>(...)</dt><dd><tt>D.<a href="#packet-iteritems">iteritems</a>() -> an iterator over the (key, value) items of D</tt></dd></dl>
|
1559 |
|
|
|
1560 |
|
|
<dl><dt><a name="packet-iterkeys"><strong>iterkeys</strong></a>(...)</dt><dd><tt>D.<a href="#packet-iterkeys">iterkeys</a>() -> an iterator over the keys of D</tt></dd></dl>
|
1561 |
|
|
|
1562 |
|
|
<dl><dt><a name="packet-itervalues"><strong>itervalues</strong></a>(...)</dt><dd><tt>D.<a href="#packet-itervalues">itervalues</a>() -> an iterator over the values of D</tt></dd></dl>
|
1563 |
|
|
|
1564 |
|
|
<dl><dt><a name="packet-keys"><strong>keys</strong></a>(...)</dt><dd><tt>D.<a href="#packet-keys">keys</a>() -> list of D's keys</tt></dd></dl>
|
1565 |
|
|
|
1566 |
|
|
<dl><dt><a name="packet-pop"><strong>pop</strong></a>(...)</dt><dd><tt>D.<a href="#packet-pop">pop</a>(k[,d]) -> v, remove specified key and return the corresponding value.<br>
|
1567 |
|
|
If key is not found, d is returned if given, otherwise KeyError is raised</tt></dd></dl>
|
1568 |
|
|
|
1569 |
|
|
<dl><dt><a name="packet-popitem"><strong>popitem</strong></a>(...)</dt><dd><tt>D.<a href="#packet-popitem">popitem</a>() -> (k, v), remove and return some (key, value) pair as a<br>
|
1570 |
|
|
2-tuple; but raise KeyError if D is empty.</tt></dd></dl>
|
1571 |
|
|
|
1572 |
|
|
<dl><dt><a name="packet-setdefault"><strong>setdefault</strong></a>(...)</dt><dd><tt>D.<a href="#packet-setdefault">setdefault</a>(k[,d]) -> D.<a href="#packet-get">get</a>(k,d), also set D[k]=d if k not in D</tt></dd></dl>
|
1573 |
|
|
|
1574 |
|
|
<dl><dt><a name="packet-update"><strong>update</strong></a>(...)</dt><dd><tt>D.<a href="#packet-update">update</a>(E, **F) -> None. Update D from <a href="__builtin__.html#dict">dict</a>/iterable E and F.<br>
|
1575 |
|
|
If E has a .<a href="#packet-keys">keys</a>() method, does: for k in E: D[k] = E[k]<br>
|
1576 |
|
|
If E lacks .<a href="#packet-keys">keys</a>() method, does: for (k, v) in E: D[k] = v<br>
|
1577 |
|
|
In either case, this is followed by: for k in F: D[k] = F[k]</tt></dd></dl>
|
1578 |
|
|
|
1579 |
|
|
<dl><dt><a name="packet-values"><strong>values</strong></a>(...)</dt><dd><tt>D.<a href="#packet-values">values</a>() -> list of D's values</tt></dd></dl>
|
1580 |
|
|
|
1581 |
|
|
<hr>
|
1582 |
|
|
Data and other attributes inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br>
|
1583 |
|
|
<dl><dt><strong>__hash__</strong> = None</dl>
|
1584 |
|
|
|
1585 |
|
|
<dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#packet-__new__">__new__</a>(S, ...) -> a new object with type S, a subtype of T</tt></dl>
|
1586 |
|
|
|
1587 |
|
|
<dl><dt><strong>fromkeys</strong> = <built-in method fromkeys of type object><dd><tt><a href="__builtin__.html#dict">dict</a>.<a href="#packet-fromkeys">fromkeys</a>(S[,v]) -> New <a href="__builtin__.html#dict">dict</a> with keys from S and values equal to v.<br>
|
1588 |
|
|
v defaults to None.</tt></dl>
|
1589 |
|
|
|
1590 |
|
|
</td></tr></table> <p>
|
1591 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
1592 |
|
|
<tr bgcolor="#ffc8d8">
|
1593 |
|
|
<td colspan=3 valign=bottom> <br>
|
1594 |
|
|
<font color="#000000" face="helvetica, arial"><a name="protocol">class <strong>protocol</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr>
|
1595 |
|
|
|
1596 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
1597 |
|
|
<td colspan=2><tt>Protocol base object<br>
|
1598 |
|
|
<br>
|
1599 |
|
|
This object represents the <a href="#protocol">protocol</a> that the NoC objects use. This <br>
|
1600 |
|
|
object has attributes that define the <a href="#protocol">protocol</a> used, mainly it can be<br>
|
1601 |
|
|
used to generate, encode, decode or interpret packets on the NoC.<br>
|
1602 |
|
|
This base class can be either be inherited or extended by adding <br>
|
1603 |
|
|
other attributes.<br>
|
1604 |
|
|
<br>
|
1605 |
|
|
Relations with other objects:<br>
|
1606 |
|
|
* Each object on the NoC (routers, channels and ipcores) may have<br>
|
1607 |
|
|
one reference to a <a href="#protocol">protocol</a> object (object.protocol_ref)<br>
|
1608 |
|
|
* A NoC model may have a <a href="#protocol">protocol</a> object: in this case, all objects in<br>
|
1609 |
|
|
the model will use this <a href="#protocol">protocol</a> (nocmodel.protocol_ref)<br>
|
1610 |
|
|
* A <a href="#protocol">protocol</a> object is a generator of <a href="#packet">packet</a> objects<br>
|
1611 |
|
|
<br>
|
1612 |
|
|
Attributes:<br>
|
1613 |
|
|
* name<br>
|
1614 |
|
|
<br>
|
1615 |
|
|
Notes: <br>
|
1616 |
|
|
* Optional arguments "packet_format" and "packet_order" can be<br>
|
1617 |
|
|
added at object construction, but will not check its data consistency. <br>
|
1618 |
|
|
At the moment, we recommend using <a href="#protocol-update_packet_field">update_packet_field</a>() method to<br>
|
1619 |
|
|
fill this data structures.<br> </tt></td></tr>
|
1620 |
|
|
<tr><td> </td>
|
1621 |
|
|
<td width="100%">Methods defined here:<br>
|
1622 |
|
|
<dl><dt><a name="protocol-__init__"><strong>__init__</strong></a>(self, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Constructor<br>
|
1623 |
|
|
<br>
|
1624 |
|
|
Notes:<br>
|
1625 |
|
|
* Optional arguments will be added as object attributes.</tt></dd></dl>
|
1626 |
|
|
|
1627 |
|
|
<dl><dt><a name="protocol-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt></dl>
|
1628 |
|
|
|
1629 |
|
|
<dl><dt><a name="protocol-newpacket"><strong>newpacket</strong></a>(self, zerodefault<font color="#909090">=True</font>, *args, **kwargs)</dt><dd><tt>Return a new <a href="#packet">packet</a> with all required fields.<br>
|
1630 |
|
|
<br>
|
1631 |
|
|
Arguments:<br>
|
1632 |
|
|
* zerodefault: If True, all missing fields will be zeroed by default.<br>
|
1633 |
|
|
If False, a missing value in arguments will throw an exception.<br>
|
1634 |
|
|
* args: Nameless arguments will add field values based on <a href="#packet">packet</a> field<br>
|
1635 |
|
|
order.<br>
|
1636 |
|
|
* kwargs: Key-based arguments will add specified field values based in <br>
|
1637 |
|
|
its keys<br>
|
1638 |
|
|
<br>
|
1639 |
|
|
Notes: <br>
|
1640 |
|
|
* kwargs takes precedence over args: i.e. named arguments can overwrite<br>
|
1641 |
|
|
nameless arguments.</tt></dd></dl>
|
1642 |
|
|
|
1643 |
|
|
<dl><dt><a name="protocol-register_packet_generator"><strong>register_packet_generator</strong></a>(self, packet_class)</dt><dd><tt>Register a special <a href="#packet">packet</a> generator class.<br>
|
1644 |
|
|
<br>
|
1645 |
|
|
Must be a derived class of <a href="#packet">packet</a></tt></dd></dl>
|
1646 |
|
|
|
1647 |
|
|
<dl><dt><a name="protocol-update_packet_field"><strong>update_packet_field</strong></a>(self, name, type, bitlen, description<font color="#909090">=''</font>)</dt><dd><tt>Add or update a <a href="#packet">packet</a> field.<br>
|
1648 |
|
|
<br>
|
1649 |
|
|
Arguments<br>
|
1650 |
|
|
* name<br>
|
1651 |
|
|
* type: string that can be "int", "fixed" or "float"<br>
|
1652 |
|
|
* bitlen: bit length of this field<br>
|
1653 |
|
|
* description: optional description of this field<br>
|
1654 |
|
|
<br>
|
1655 |
|
|
Notes: <br>
|
1656 |
|
|
* Each new field will be added at the end.</tt></dd></dl>
|
1657 |
|
|
|
1658 |
|
|
</td></tr></table> <p>
|
1659 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
1660 |
|
|
<tr bgcolor="#ffc8d8">
|
1661 |
|
|
<td colspan=3 valign=bottom> <br>
|
1662 |
|
|
<font color="#000000" face="helvetica, arial"><a name="router">class <strong>router</strong></a>(<a href="nocmodel.noc_base.html#nocobject">nocobject</a>)</font></td></tr>
|
1663 |
|
|
|
1664 |
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
1665 |
|
|
<td colspan=2><tt>Router base object<br>
|
1666 |
|
|
<br>
|
1667 |
|
|
This object represents a <a href="#router">router</a> object and its properties. This base class<br>
|
1668 |
|
|
is meant to either be inherited or extended by adding other attributes.<br>
|
1669 |
|
|
<br>
|
1670 |
|
|
Relations with other objects:<br>
|
1671 |
|
|
* It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br>
|
1672 |
|
|
* It should be one of the node attributes in the graph model <br>
|
1673 |
|
|
(node["router_ref"])<br>
|
1674 |
|
|
* It may have one reference to an <a href="#ipcore">ipcore</a> object (self.<strong>ipcore_ref</strong>)<br>
|
1675 |
|
|
* It has a port list with relations to other routers through <a href="#channel">channel</a> objects,<br>
|
1676 |
|
|
and only one relation to its <a href="#ipcore">ipcore</a> object through one <a href="#channel">channel</a>.<br>
|
1677 |
|
|
(self.<strong>ports</strong>). Note that this attribute must be updated after changing <br>
|
1678 |
|
|
the NoC model.<br>
|
1679 |
|
|
<br>
|
1680 |
|
|
Attributes:<br>
|
1681 |
|
|
* index: index on a <a href="#noc">noc</a> object. Essential to search for a <a href="#router">router</a> object<br>
|
1682 |
|
|
* name<br>
|
1683 |
|
|
* ipcore_ref: optional reference to its related <a href="#ipcore">ipcore</a><br>
|
1684 |
|
|
* graph_ref: optional reference to its graph model<br> </tt></td></tr>
|
1685 |
|
|
<tr><td> </td>
|
1686 |
|
|
<td width="100%">Methods defined here:<br>
|
1687 |
|
|
<dl><dt><a name="router-__init__"><strong>__init__</strong></a>(self, index, name, **kwargs)</dt></dl>
|
1688 |
|
|
|
1689 |
|
|
<dl><dt><a name="router-update_ports_info"><strong>update_ports_info</strong></a>(self)</dt><dd><tt>Update the dictionary "ports": information about <a href="#router">router</a> neighbors,<br>
|
1690 |
|
|
the channels that connect them and its references.<br>
|
1691 |
|
|
<br>
|
1692 |
|
|
Ports dictionary has the following structure:<br>
|
1693 |
|
|
* key: address of the neighbor <a href="#router">router</a> that this port connects.<br>
|
1694 |
|
|
* value: dictionary with the following keys:<br>
|
1695 |
|
|
* "peer" (required): reference to the neighbor <a href="#router">router</a><br>
|
1696 |
|
|
* "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br>
|
1697 |
|
|
<a href="#router">router</a> and its neighbor <a href="#router">router</a>.<br>
|
1698 |
|
|
* Optional keys can be added to this dictionary.<br>
|
1699 |
|
|
* Also, the special key "local address" holds the port to <br>
|
1700 |
|
|
<a href="#router">router</a>'s <a href="#ipcore">ipcore</a>. Its values are:<br>
|
1701 |
|
|
* "peer" (required): reference to its <a href="#ipcore">ipcore</a><br>
|
1702 |
|
|
* "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br>
|
1703 |
|
|
<a href="#router">router</a> and its <a href="#ipcore">ipcore</a>.<br>
|
1704 |
|
|
* Optional keys can be added to this dictionary with the same <br>
|
1705 |
|
|
meaning as other ports.</tt></dd></dl>
|
1706 |
|
|
|
1707 |
|
|
<dl><dt><a name="router-update_routes_info"><strong>update_routes_info</strong></a>(self)</dt><dd><tt>Update the dictionary "routes_info": it is a table with information <br>
|
1708 |
|
|
about how a package, starting from this <a href="#router">router</a>, can reach another one.<br>
|
1709 |
|
|
<br>
|
1710 |
|
|
routes_info dictionary has the following structure:<br>
|
1711 |
|
|
* keys : the address of all the routers in NoC<br>
|
1712 |
|
|
* values : an ordered list of dictionaries with <br>
|
1713 |
|
|
* "next" : address of the next <a href="#router">router</a><br>
|
1714 |
|
|
* "paths" : list of possible paths for key destination</tt></dd></dl>
|
1715 |
|
|
|
1716 |
|
|
<hr>
|
1717 |
|
|
Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br>
|
1718 |
|
|
<dl><dt><a name="router-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt><dd><tt>Get <a href="#protocol">protocol</a> object for this instance</tt></dd></dl>
|
1719 |
|
|
|
1720 |
|
|
</td></tr></table></td></tr></table><p>
|
1721 |
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
1722 |
|
|
<tr bgcolor="#eeaa77">
|
1723 |
|
|
<td colspan=3 valign=bottom> <br>
|
1724 |
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
1725 |
|
|
|
1726 |
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
1727 |
|
|
<td width="100%"><dl><dt><a name="-all_shortest_paths"><strong>all_shortest_paths</strong></a>(G, a, b)</dt><dd><tt>Return a list of all shortest paths in graph G between nodes a and b<br>
|
1728 |
|
|
This is a function not available in NetworkX (checked at 22-02-2011)<br>
|
1729 |
|
|
<br>
|
1730 |
|
|
Taken from: <br>
|
1731 |
|
|
<a href="http://groups.google.com/group/networkx-discuss/browse_thread/thread/55465e6bb9bae12e">http://groups.google.com/group/networkx-discuss/browse_thread/thread/55465e6bb9bae12e</a></tt></dd></dl>
|
1732 |
|
|
</td></tr></table>
|
1733 |
|
|
</body></html>
|