URL
https://opencores.org/ocsvn/nocmodel/nocmodel/trunk
Subversion Repositories nocmodel
[/] [nocmodel/] [trunk/] [doc/] [nocmodel.noc_base.html] - Rev 3
Go to most recent revision | Compare with Previous | Blame | View Log
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Python: module nocmodel.noc_base</title> </head><body bgcolor="#f0f0f8"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> <tr bgcolor="#7799ee"> <td valign=bottom> <br> <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 ><td align=right valign=bottom ><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> <p><tt>================<br> NoCmodel Base Objects<br> ================<br> <br> This module declares classes used on a Network-on-chip representation:<br> <br> * NoC container class<br> * Router base class<br> * Channel base class<br> * IPCore base class<br> * Protocol base class<br> * Packet class</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#aa55cc"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="networkx.html">networkx</a><br> </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> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ee77aa"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> <td width="100%"><dl> <dt><font face="helvetica, arial"><a href="__builtin__.html#dict">__builtin__.dict</a>(<a href="__builtin__.html#object">__builtin__.object</a>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#packet">packet</a> </font></dt></dl> </dd> <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>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#noc">noc</a> </font></dt></dl> </dd> <dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#nocobject">nocobject</a> </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#channel">channel</a> </font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#ipcore">ipcore</a> </font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#protocol">protocol</a> </font></dt><dt><font face="helvetica, arial"><a href="nocmodel.noc_base.html#router">router</a> </font></dt></dl> </dd> </dl> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Channel base object<br> <br> This object represents a <a href="#channel">channel</a> object and its properties. This base class<br> is meant to either be inherited or extended by adding other attributes.<br> <br> Relations with other objects:<br> * It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> * It may be one of the edge attributes in the graph model <br> (edge["channel_ref"]). In this case, this <a href="#channel">channel</a> connects two routers<br> in the NoC model.<br> * It should have two references to NoC objects (self.<strong>endpoints</strong>). Two options<br> exists: two routers references (<a href="#channel">channel</a> has an edge object) or, one<br> <a href="#router">router</a> and one <a href="#ipcore">ipcore</a> (<a href="#channel">channel</a> don't have any edge object).<br> <br> Attributes:<br> * name<br> * index: optional index on a <a href="#noc">noc</a> object. Must have an index when it has<br> a related edge in the graph model (and allowing it to be able to do<br> <a href="#channel">channel</a> searching). None means it is an <a href="#ipcore">ipcore</a> related <a href="#channel">channel</a><br> * graph_ref optional reference to its graph model<br> * endpoints optional two-item list with references to the connected objects<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="channel-__init__"><strong>__init__</strong></a>(self, name, index<font color="#909090">=None</font>, **kwargs)</dt></dl> <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> <br> Return: True if the <a href="#channel">channel</a> is related to an <a href="#ipcore">ipcore</a></tt></dd></dl> <hr> Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> <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> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>IP core base object<br> <br> This object represents a IP Core object and its properties. This base class<br> is meant to either be inherited or extended by adding other attributes.<br> <br> Relations with other objects:<br> * It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> * It should have one reference to a <a href="#router">router</a> object (self.<strong>router_ref</strong>), even if<br> the <a href="#ipcore">ipcore</a> has a direct connection to the NoC.<br> * It should have one reference to a <a href="#channel">channel</a> object (self.<strong>channel_ref</strong>). This<br> <a href="#channel">channel</a> exclusively link this <a href="#ipcore">ipcore</a> and its <a href="#router">router</a>.<br> <br> Attributes:<br> * name<br> * router_ref: optional reference to its related <a href="#router">router</a>.<br> * channel_ref: optional reference to its related <a href="#channel">channel</a><br> * graph_ref: optional reference to its graph model<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="ipcore-__init__"><strong>__init__</strong></a>(self, name, **kwargs)</dt></dl> <hr> Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> <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> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Base class for NoC modeling.<br> Based on a <a href="networkx.classes.graph.html#Graph">Graph</a> object that hold the NoC structure<br> <br> Arguments<br> * kwargs: optional parameters to put as object attributes<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="nocmodel.noc_base.html#noc">noc</a></dd> <dd><a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a></dd> <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="noc-__init__"><strong>__init__</strong></a>(self, **kwargs)</dt><dd><tt>NoCmodel constructor</tt></dd></dl> <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> to NoC model.<br> <br> Arguments:<br> * router1: reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br> * router2: -idem-<br> * name: optional argument for <a href="#channel">channel</a> name<br> * kwargs: optional parameters to put as object attributes<br> <br> Notes:<br> * If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br> the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br> if both arguments are ipcores, throw an error exception</tt></dd></dl> <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> <br> Use this function to add an object based on a derived class of <br> base <a href="#channel">channel</a> defined in this module.<br> <br> Arguments<br> * channel_ref: reference to the <a href="#channel">channel</a> object<br> * router1: optional reference to a <a href="#router">router</a>, <a href="#router">router</a> index or <a href="#ipcore">ipcore</a><br> * router2: -idem-<br> <br> Return: the same reference passed in channel_ref<br> <br> Notes:<br> * If router1 or router2 are not used as arguments, will assume that<br> <a href="#channel">channel</a> object has defined its attribute "endpoints" with the <br> objects to connect. If the objects don't exist in the NoC model,<br> throw an error exception.<br> <br> * If router1 or router2 is an <a href="#ipcore">ipcore</a> reference, this method creates<br> the special <a href="#channel">channel</a> object and update <a href="#ipcore">ipcore</a> references. Additionally,<br> if both arguments are ipcores, throw an error exception.<br> <br> * This function will change channel_ref.index and channel_ref.graph_ref <br> attributes when inserted in the NoC model. Also it may change <br> channel_ref.endpoints with router1 and router2 references.</tt></dd></dl> <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> <br> Arguments<br> * ipcore_ref: reference to <a href="#ipcore">ipcore</a> object<br> * router_ref: reference to an existing <a href="#router">router</a> to connect<br> * channel_ref: optional <a href="#channel">channel</a> object that connect the <a href="#router">router</a> and<br> the <a href="#ipcore">ipcore</a>. If not used, this function will create a new <a href="#channel">channel</a> object.<br> <br> Return: the same reference passed in ipcore_ref<br> <br> Notes:<br> * This function automatically adds a special <a href="#channel">channel</a> object <br> (<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl> <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> <br> Arguments<br> * router_ref: reference to an existing <a href="#router">router</a><br> * name: optional name for this <a href="#router">router</a>. By default has the form of <br> "IP_<router_index>"<br> * kwargs: optional parameters to put as object attributes<br> <br> Return: reference to the created <a href="#ipcore">ipcore</a> object<br> <br> Notes:<br> * This function automatically adds a special <a href="#channel">channel</a> object <br> (<a href="#router">router</a>-to-<a href="#ipcore">ipcore</a>) and adjust its relations in all involved objects.</tt></dd></dl> <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> <br> Arguments<br> * name: optional name for this <a href="#router">router</a>. By default has the form of <br> "R_<index>"<br> * with_ipcore: If True, add an <a href="#ipcore">ipcore</a> to the created <a href="#router">router</a>.<br> * kwargs: optional parameters to put as object attributes<br> <br> Return: reference to the created <a href="#router">router</a> object</tt></dd></dl> <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> <br> Use this function to add an object based on a derived class of <br> base <a href="#router">router</a> defined in this module.<br> <br> Arguments<br> * router_ref: reference to the <a href="#router">router</a> object<br> <br> Return: the same reference passed in router_ref<br> <br> Notes: <br> * This function will change router_ref.index and router_ref.graph_ref <br> attributes when inserted in the NoC model.</tt></dd></dl> <dl><dt><a name="noc-all_list"><strong>all_list</strong></a>(self)</dt></dl> <dl><dt><a name="noc-channel_list"><strong>channel_list</strong></a>(self)</dt></dl> <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> <br> TODO: not implemented</tt></dd></dl> <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> <br> TODO: not implemented</tt></dd></dl> <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> <br> TODO: not implemented</tt></dd></dl> <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> <dl><dt><a name="noc-ipcore_list"><strong>ipcore_list</strong></a>(self)</dt></dl> <dl><dt><a name="noc-router_list"><strong>router_list</strong></a>(self)</dt><dd><tt># list generation functions</tt></dd></dl> <hr> Methods inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br> <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> 'n in G'.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> print 1 in G<br> True</tt></dd></dl> <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> <br> Parameters<br> ----------<br> n : node<br> A node in the graph.<br> <br> Returns<br> -------<br> adj_dict : dictionary<br> The adjacency dictionary for nodes connected to n.<br> <br> Notes<br> -----<br> G[n] is similar to G.<a href="#noc-neighbors">neighbors</a>(n) but the internal data dictionary<br> is returned instead of a list.<br> <br> Assigning G[n] will corrupt the internal graph data structure.<br> Use G[n] for reading data only.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> print G[0]<br> {1: {}}</tt></dd></dl> <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> <br> Returns<br> -------<br> niter : iterator<br> An iterator over all nodes in the graph.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> for n in G:<br> ... print n,<br> 0 1 2 3</tt></dd></dl> <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> <br> Returns<br> -------<br> nnodes : int<br> The number of nodes in the graph.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> print len(G)<br> 4</tt></dd></dl> <dl><dt><a name="noc-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return the graph name.<br> <br> Returns<br> -------<br> name : string<br> The name of the graph.<br> <br> Examples<br> --------<br> >>> G = nx.path_graph(4) <br> >>> print G<br> path_graph(4)</tt></dd></dl> <dl><dt><a name="noc-add_cycle"><strong>add_cycle</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a cycle.<br> <br> Parameters<br> ----------<br> nlist : list <br> A list of nodes. A cycle will be constructed from<br> the nodes (in order) and added to the graph.<br> attr : keyword arguments, optional (default= no attributes)<br> Attributes to add to every edge in cycle.<br> <br> See Also<br> --------<br> add_path, add_star<br> <br> Examples<br> --------<br> >>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_cycle">add_cycle</a>([0,1,2,3])<br> >>> G.<a href="#noc-add_cycle">add_cycle</a>([10,11,12],weight=7)</tt></dd></dl> <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> <br> The nodes u and v will be automatically added if they are <br> not already in the graph. <br> <br> Edge attributes can be specified with keywords or by providing<br> a dictionary with key/value pairs. See examples below.<br> <br> Parameters<br> ----------<br> u,v : nodes<br> Nodes can be, for example, strings or numbers. <br> Nodes must be hashable (and not None) Python objects.<br> attr_dict : dictionary, optional (default= no attributes)<br> Dictionary of edge attributes. Key/value pairs will<br> update existing data associated with the edge.<br> attr : keyword arguments, optional<br> Edge data (or labels or objects) can be assigned using<br> keyword arguments. <br> <br> See Also<br> --------<br> add_edges_from : add a collection of edges<br> <br> Notes <br> -----<br> Adding an edge that already exists updates the edge data.<br> <br> NetworkX algorithms designed for weighted graphs use as<br> the edge weight a numerical value assigned to the keyword<br> 'weight'.<br> <br> Examples<br> --------<br> The following all add the edge e=(1,2) to graph G:<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> e = (1,2)<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1, 2) # explicit two-node form<br> >>> G.<a href="#noc-add_edge">add_edge</a>(*e) # single edge as tuple of two nodes<br> >>> G.<a href="#noc-add_edges_from">add_edges_from</a>( [(1,2)] ) # add edges from iterable container<br> <br> Associate data to edges using keywords:<br> <br> >>> G.<a href="#noc-add_edge">add_edge</a>(1, 2, weight=3)<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1, 3, weight=7, capacity=15, length=342.7)</tt></dd></dl> <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> <br> Parameters<br> ----------<br> ebunch : container of edges<br> Each edge given in the container will be added to the<br> graph. The edges must be given as as 2-tuples (u,v) or<br> 3-tuples (u,v,d) where d is a dictionary containing edge<br> data.<br> attr_dict : dictionary, optional (default= no attributes)<br> Dictionary of edge attributes. Key/value pairs will<br> update existing data associated with each edge.<br> attr : keyword arguments, optional<br> Edge data (or labels or objects) can be assigned using<br> keyword arguments. <br> <br> <br> See Also<br> --------<br> add_edge : add a single edge<br> add_weighted_edges_from : convenient way to add weighted edges<br> <br> Notes<br> -----<br> Adding the same edge twice has no effect but any edge data<br> will be updated when each duplicate edge is added.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(0,1),(1,2)]) # using a list of edge tuples<br> >>> e = zip(range(0,3),range(1,4))<br> >>> G.<a href="#noc-add_edges_from">add_edges_from</a>(e) # Add the path graph 0-1-2-3<br> <br> Associate data to edges<br> <br> >>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(1,2),(2,3)], weight=3)<br> >>> G.<a href="#noc-add_edges_from">add_edges_from</a>([(3,4),(1,4)], label='WN2898')</tt></dd></dl> <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> <br> Parameters<br> ----------<br> n : node<br> A node can be any hashable Python object except None.<br> attr_dict : dictionary, optional (default= no attributes)<br> Dictionary of node attributes. Key/value pairs will<br> update existing data associated with the node.<br> attr : keyword arguments, optional<br> Set or change attributes using key=value.<br> <br> See Also<br> --------<br> add_nodes_from<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_node">add_node</a>(1)<br> >>> G.<a href="#noc-add_node">add_node</a>('Hello')<br> >>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br> >>> G.<a href="#noc-add_node">add_node</a>(K3)<br> >>> G.<a href="#noc-number_of_nodes">number_of_nodes</a>()<br> 3<br> <br> Use keywords set/change node attributes:<br> <br> >>> G.<a href="#noc-add_node">add_node</a>(1,size=10)<br> >>> G.<a href="#noc-add_node">add_node</a>(3,weight=0.4,UTM=('13S',382871,3972649))<br> <br> Notes<br> -----<br> A hashable object is one that can be used as a key in a Python<br> dictionary. This includes strings, numbers, tuples of strings<br> and numbers, etc.<br> <br> On many platforms hashable items also include mutables such as<br> NetworkX Graphs, though one should be careful that the hash<br> doesn't change on mutables.</tt></dd></dl> <dl><dt><a name="noc-add_nodes_from"><strong>add_nodes_from</strong></a>(self, nodes, **attr)</dt><dd><tt>Add multiple nodes.<br> <br> Parameters<br> ----------<br> nodes : iterable container<br> A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). <br> OR<br> A container of (node, attribute <a href="__builtin__.html#dict">dict</a>) tuples.<br> Node attributes are updated using the attribute <a href="__builtin__.html#dict">dict</a>.<br> attr : keyword arguments, optional (default= no attributes)<br> Update attributes for all nodes in nodes.<br> Node attributes specified in nodes as a tuple<br> take precedence over attributes specified generally.<br> <br> See Also<br> --------<br> add_node<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>('Hello')<br> >>> K3 = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>([(0,1),(1,2),(2,0)])<br> >>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>(K3)<br> >>> sorted(G.<a href="#noc-nodes">nodes</a>())<br> [0, 1, 2, 'H', 'e', 'l', 'o']<br> <br> Use keywords to update specific node attributes for every node.<br> <br> >>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([1,2], size=10)<br> >>> G.<a href="#noc-add_nodes_from">add_nodes_from</a>([3,4], weight=0.4)<br> <br> Use (node, attrdict) tuples to update attributes for specific<br> nodes.<br> <br> >>> 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> >>> G.node[1]['size']<br> 11<br> >>> H = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>()<br> >>> H.<a href="#noc-add_nodes_from">add_nodes_from</a>(G.<a href="#noc-nodes">nodes</a>(data=True))<br> >>> H.node[1]['size']<br> 11</tt></dd></dl> <dl><dt><a name="noc-add_path"><strong>add_path</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a path.<br> <br> Parameters<br> ----------<br> nlist : list <br> A list of nodes. A path will be constructed from<br> the nodes (in order) and added to the graph.<br> attr : keyword arguments, optional (default= no attributes)<br> Attributes to add to every edge in path.<br> <br> See Also<br> --------<br> add_star, add_cycle<br> <br> Examples<br> --------<br> >>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-add_path">add_path</a>([10,11,12],weight=7)</tt></dd></dl> <dl><dt><a name="noc-add_star"><strong>add_star</strong></a>(self, nlist, **attr)</dt><dd><tt>Add a star.<br> <br> The first node in nlist is the middle of the star. It is connected <br> to all other nodes in nlist.<br> <br> Parameters<br> ----------<br> nlist : list <br> A list of nodes. <br> attr : keyword arguments, optional (default= no attributes)<br> Attributes to add to every edge in star.<br> <br> See Also<br> --------<br> add_path, add_cycle<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_star">add_star</a>([0,1,2,3])<br> >>> G.<a href="#noc-add_star">add_star</a>([10,11,12],weight=2)</tt></dd></dl> <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> weights.<br> <br> Parameters<br> ----------<br> ebunch : container of edges<br> Each edge given in the list or container will be added<br> to the graph. The edges must be given as 3-tuples (u,v,w)<br> where w is a number.<br> attr : keyword arguments, optional (default= no attributes)<br> Edge attributes to add/update for all edges.<br> <br> See Also<br> --------<br> add_edge : add a single edge<br> add_edges_from : add multiple edges<br> <br> Notes<br> -----<br> Adding the same edge twice has no effect but any edge data<br> will be updated when each duplicate edge is added.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_weighted_edges_from">add_weighted_edges_from</a>([(0,1,3.0),(1,2,7.5)])</tt></dd></dl> <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> <br> This is the fastest way to look at every edge. <br> For directed graphs, only outgoing adjacencies are included.<br> <br> Returns<br> -------<br> adj_iter : iterator<br> An iterator of (node, adjacency dictionary) for all nodes in<br> the graph.<br> <br> See Also<br> --------<br> adjacency_list<br> <br> Examples <br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> [(n,nbrdict) for n,nbrdict in G.<a href="#noc-adjacency_iter">adjacency_iter</a>()]<br> [(0, {1: {}}), (1, {0: {}, 2: {}}), (2, {1: {}, 3: {}}), (3, {2: {}})]</tt></dd></dl> <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> <br> The output adjacency list is in the order of G.<a href="#noc-nodes">nodes</a>().<br> For directed graphs, only outgoing adjacencies are included. <br> <br> Returns<br> -------<br> adj_list : lists of lists<br> The adjacency structure of the graph as a list of lists.<br> <br> See Also<br> --------<br> adjacency_iter<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-adjacency_list">adjacency_list</a>() # in order given by G.<a href="#noc-nodes">nodes</a>()<br> [[1], [0, 2], [1, 3], [2]]</tt></dd></dl> <dl><dt><a name="noc-clear"><strong>clear</strong></a>(self)</dt><dd><tt>Remove all nodes and edges from the graph.<br> <br> This also removes the name, and all graph, node, and edge attributes.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-clear">clear</a>()<br> >>> G.<a href="#noc-nodes">nodes</a>()<br> []<br> >>> G.<a href="#noc-edges">edges</a>()<br> []</tt></dd></dl> <dl><dt><a name="noc-copy"><strong>copy</strong></a>(self)</dt><dd><tt>Return a copy of the graph.<br> <br> Returns<br> -------<br> G : <a href="networkx.classes.graph.html#Graph">Graph</a><br> A copy of the graph. <br> <br> See Also<br> --------<br> to_directed: return a directed copy of the graph.<br> <br> Notes<br> -----<br> This makes a complete copy of the graph including all of the <br> node or edge attributes. <br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> H = G.<a href="#noc-copy">copy</a>()</tt></dd></dl> <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> <br> The node degree is the number of edges adjacent to that node. <br> <br> Parameters<br> ----------<br> nbunch : iterable container, optional (default=all nodes)<br> A container of nodes. The container will be iterated<br> through once. <br> weighted : bool, optional (default=False)<br> If True return the sum of edge weights adjacent to the node. <br> <br> Returns<br> -------<br> nd : dictionary, or number<br> A dictionary with nodes as keys and degree as values or<br> a number if a single node is specified.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-degree">degree</a>(0)<br> 1<br> >>> G.<a href="#noc-degree">degree</a>([0,1])<br> {0: 1, 1: 2}<br> >>> G.<a href="#noc-degree">degree</a>([0,1]).values()<br> [1, 2]</tt></dd></dl> <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> <br> The node degree is the number of edges adjacent to the node. <br> <br> Parameters<br> ----------<br> nbunch : iterable container, optional (default=all nodes)<br> A container of nodes. The container will be iterated<br> through once. <br> weighted : bool, optional (default=False)<br> If True return the sum of edge weights adjacent to the node. <br> <br> Returns<br> -------<br> nd_iter : an iterator <br> The iterator returns two-tuples of (node, degree).<br> <br> See Also<br> --------<br> degree<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> list(G.<a href="#noc-degree_iter">degree_iter</a>(0)) # node 0 with degree 1<br> [(0, 1)]<br> >>> list(G.<a href="#noc-degree_iter">degree_iter</a>([0,1]))<br> [(0, 1), (1, 2)]</tt></dd></dl> <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> <br> Edges are returned as tuples with optional data <br> in the order (node, neighbor, data).<br> <br> Parameters<br> ----------<br> nbunch : iterable container, optional (default= all nodes)<br> A container of nodes. The container will be iterated<br> through once.<br> data : bool, optional (default=False)<br> Return two tuples (u,v) (False) or three-tuples (u,v,data) (True).<br> <br> Returns<br> --------<br> edge_list: list of edge tuples<br> Edges that are adjacent to any node in nbunch, or a list<br> of all edges if nbunch is not specified.<br> <br> See Also<br> --------<br> edges_iter : return an iterator over the edges<br> <br> Notes<br> -----<br> Nodes in nbunch that are not in the graph will be (quietly) ignored.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-edges">edges</a>()<br> [(0, 1), (1, 2), (2, 3)]<br> >>> G.<a href="#noc-edges">edges</a>(data=True) # default edge data is {} (empty dictionary)<br> [(0, 1, {}), (1, 2, {}), (2, 3, {})]<br> >>> G.<a href="#noc-edges">edges</a>([0,3])<br> [(0, 1), (3, 2)]<br> >>> G.<a href="#noc-edges">edges</a>(0)<br> [(0, 1)]</tt></dd></dl> <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> <br> Edges are returned as tuples with optional data <br> in the order (node, neighbor, data).<br> <br> Parameters<br> ----------<br> nbunch : iterable container, optional (default= all nodes)<br> A container of nodes. The container will be iterated<br> through once.<br> data : bool, optional (default=False)<br> If True, return edge attribute <a href="__builtin__.html#dict">dict</a> in 3-tuple (u,v,data).<br> <br> Returns<br> -------<br> edge_iter : iterator<br> An iterator of (u,v) or (u,v,d) tuples of edges.<br> <br> See Also<br> --------<br> edges : return a list of edges<br> <br> Notes<br> -----<br> Nodes in nbunch that are not in the graph will be (quietly) ignored.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> [e for e in G.<a href="#noc-edges_iter">edges_iter</a>()]<br> [(0, 1), (1, 2), (2, 3)]<br> >>> list(G.<a href="#noc-edges_iter">edges_iter</a>(data=True)) # default data is {} (empty <a href="__builtin__.html#dict">dict</a>)<br> [(0, 1, {}), (1, 2, {}), (2, 3, {})]<br> >>> list(G.<a href="#noc-edges_iter">edges_iter</a>([0,3]))<br> [(0, 1), (3, 2)]<br> >>> list(G.<a href="#noc-edges_iter">edges_iter</a>(0))<br> [(0, 1)]</tt></dd></dl> <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> <br> Parameters<br> ----------<br> u,v : nodes<br> default: any Python object (default=None) <br> Value to return if the edge (u,v) is not found. <br> <br> Returns<br> -------<br> edge_dict : dictionary<br> The edge attribute dictionary.<br> <br> Notes<br> -----<br> It is faster to use G[u][v].<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G[0][1]<br> {}<br> <br> Warning: Assigning G[u][v] corrupts the graph data structure.<br> But it is safe to assign attributes to that dictionary,<br> <br> >>> G[0][1]['weight'] = 7<br> >>> G[0][1]['weight']<br> 7<br> >>> G[1][0]['weight']<br> 7<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-get_edge_data">get_edge_data</a>(0,1) # default edge data is {}<br> {}<br> >>> e = (0,1)<br> >>> G.<a href="#noc-get_edge_data">get_edge_data</a>(*e) # tuple form<br> {}<br> >>> G.<a href="#noc-get_edge_data">get_edge_data</a>('a','b',default=0) # edge not in graph, return 0<br> 0</tt></dd></dl> <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> <br> Parameters<br> ----------<br> u,v : nodes<br> Nodes can be, for example, strings or numbers. <br> Nodes must be hashable (and not None) Python objects.<br> <br> Returns<br> -------<br> edge_ind : bool<br> True if edge is in the graph, False otherwise.<br> <br> Examples<br> --------<br> Can be called either using two nodes u,v or edge tuple (u,v)<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-has_edge">has_edge</a>(0,1) # using two nodes<br> True<br> >>> e = (0,1)<br> >>> G.<a href="#noc-has_edge">has_edge</a>(*e) # e is a 2-tuple (u,v)<br> True<br> >>> e = (0,1,{'weight':7})<br> >>> G.<a href="#noc-has_edge">has_edge</a>(*e[:2]) # e is a 3-tuple (u,v,data_dictionary)<br> True<br> <br> The following syntax are all equivalent: <br> <br> >>> G.<a href="#noc-has_edge">has_edge</a>(0,1)<br> True<br> >>> 1 in G[0] # though this gives KeyError if 0 not in G<br> True</tt></dd></dl> <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> <br> Parameters<br> ----------<br> n : node<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> print G.<a href="#noc-has_node">has_node</a>(0)<br> True<br> <br> It is more readable and simpler to use<br> <br> >>> 0 in G<br> True</tt></dd></dl> <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> <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> <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> also in the graph.<br> <br> The nodes in nbunch are checked for membership in the graph<br> and if not are silently ignored.<br> <br> Parameters<br> ----------<br> nbunch : iterable container, optional (default=all nodes)<br> A container of nodes. The container will be iterated<br> through once. <br> <br> Returns<br> -------<br> niter : iterator<br> An iterator over nodes in nbunch that are also in the graph.<br> If nbunch is None, iterate over all nodes in the graph.<br> <br> Raises<br> ------<br> NetworkXError<br> If nbunch is not a node or or sequence of nodes.<br> If a node in nbunch is not hashable.<br> <br> See Also<br> --------<br> <a href="networkx.classes.graph.html#Graph">Graph</a>.__iter__<br> <br> Notes <br> -----<br> When nbunch is an iterator, the returned iterator yields values <br> directly from nbunch, becoming exhausted when nbunch is exhausted.<br> <br> To test whether nbunch is a single node, one can use <br> "if nbunch in self:", even after processing with this routine.<br> <br> If nbunch is not a node or a (possibly empty) sequence/iterator<br> or None, a NetworkXError is raised. Also, if any object in<br> nbunch is not hashable, a NetworkXError is raised.</tt></dd></dl> <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> <br> Parameters<br> ----------<br> n : node<br> A node in the graph<br> <br> Returns<br> -------<br> nlist : list<br> A list of nodes that are adjacent to n.<br> <br> Raises<br> ------<br> NetworkXError<br> If the node n is not in the graph. <br> <br> Notes<br> -----<br> It is usually more convenient (and faster) to access the<br> adjacency dictionary as G[n]:<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=7)<br> >>> G['a']<br> {'b': {'weight': 7}}<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-neighbors">neighbors</a>(0)<br> [1]</tt></dd></dl> <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> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> print [n for n in G.<a href="#noc-neighbors_iter">neighbors_iter</a>(0)]<br> [1]<br> <br> Notes<br> -----<br> It is faster to use the idiom "in G[0]", e.g.<br> >>> for n in G[0]:<br> ... print n<br> 1</tt></dd></dl> <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> <br> Parameters<br> ----------<br> data : boolean, optional (default=False) <br> If False return a list of nodes. If True return a<br> two-tuple of node and node data dictionary<br> <br> Returns<br> -------<br> nlist : list<br> A list of nodes. If data=True a list of two-tuples containing<br> (node, node data dictionary). <br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> print G.<a href="#noc-nodes">nodes</a>()<br> [0, 1, 2]<br> >>> G.<a href="#noc-add_node">add_node</a>(1, time='5pm')<br> >>> print G.<a href="#noc-nodes">nodes</a>(data=True)<br> [(0, {}), (1, {'time': '5pm'}), (2, {})]</tt></dd></dl> <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> <br> Parameters<br> ----------<br> data : boolean, optional (default=False)<br> If False the iterator returns nodes. If True<br> return a two-tuple of node and node data dictionary<br> <br> Returns<br> -------<br> niter : iterator<br> An iterator over nodes. If data=True the iterator gives <br> two-tuples containing (node, node data, dictionary) <br> <br> Notes<br> -----<br> If the node data is not required it is simpler and equivalent <br> to use the expression 'for n in G'.<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> for n in G:<br> ... print n,<br> 0 1 2<br> <br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> for n in G.<a href="#noc-nodes_iter">nodes_iter</a>():<br> ... print n,<br> 0 1 2<br> >>> for n,d in G.<a href="#noc-nodes_iter">nodes_iter</a>(data=True):<br> ... print d,<br> {} {} {}</tt></dd></dl> <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> <br> A node with a self loop has an edge with both ends adjacent<br> to that node.<br> <br> Returns<br> -------<br> nodelist : list<br> A list of nodes with self loops.<br> <br> See Also<br> --------<br> selfloop_edges, number_of_selfloops<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> >>> G.<a href="#noc-nodes_with_selfloops">nodes_with_selfloops</a>()<br> [1]</tt></dd></dl> <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> <br> Parameters<br> ----------<br> u,v : nodes, optional (default=all edges)<br> If u and v are specified, return the number of edges between <br> u and v. Otherwise return the total number of all edges.<br> <br> Returns<br> -------<br> nedges : int<br> The number of edges in the graph. If nodes u and v are specified<br> return the number of edges between those nodes.<br> <br> See Also<br> --------<br> size<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-number_of_edges">number_of_edges</a>()<br> 3<br> >>> G.<a href="#noc-number_of_edges">number_of_edges</a>(0,1) <br> 1<br> >>> e = (0,1)<br> >>> G.<a href="#noc-number_of_edges">number_of_edges</a>(*e)<br> 1</tt></dd></dl> <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> <br> Returns<br> -------<br> nnodes : int<br> The number of nodes in the graph.<br> <br> See Also<br> --------<br> order, __len__ which are identical <br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> print len(G)<br> 3</tt></dd></dl> <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> <br> A selfloop edge has the same node at both ends.<br> <br> Returns<br> -------<br> nloops : int<br> The number of selfloops. <br> <br> See Also<br> --------<br> selfloop_nodes, selfloop_edges<br> <br> Examples<br> --------<br> >>> G=nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> >>> G.<a href="#noc-number_of_selfloops">number_of_selfloops</a>()<br> 1</tt></dd></dl> <dl><dt><a name="noc-order"><strong>order</strong></a>(self)</dt><dd><tt>Return the number of nodes in the graph.<br> <br> Returns<br> -------<br> nnodes : int<br> The number of nodes in the graph.<br> <br> See Also<br> --------<br> number_of_nodes, __len__ which are identical</tt></dd></dl> <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> <br> Parameters<br> ----------<br> u,v: nodes <br> Remove the edge between nodes u and v.<br> <br> Raises<br> ------<br> NetworkXError<br> If there is not an edge between u and v.<br> <br> See Also<br> --------<br> remove_edges_from : remove a collection of edges<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-remove_edge">remove_edge</a>(0,1)<br> >>> e = (1,2)<br> >>> G.<a href="#noc-remove_edge">remove_edge</a>(*e) # unpacks e from an edge tuple<br> >>> e = (2,3,{'weight':7}) # an edge with attribute data<br> >>> G.<a href="#noc-remove_edge">remove_edge</a>(*e[:2]) # select first part of edge tuple</tt></dd></dl> <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> <br> Parameters<br> ----------<br> ebunch: list or container of edge tuples<br> Each edge given in the list or container will be removed <br> from the graph. The edges can be:<br> <br> - 2-tuples (u,v) edge between u and v.<br> - 3-tuples (u,v,k) where k is ignored.<br> <br> See Also<br> --------<br> remove_edge : remove a single edge<br> <br> Notes<br> -----<br> Will fail silently if an edge in ebunch is not in the graph.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> ebunch=[(1,2),(2,3)]<br> >>> G.<a href="#noc-remove_edges_from">remove_edges_from</a>(ebunch)</tt></dd></dl> <dl><dt><a name="noc-remove_node"><strong>remove_node</strong></a>(self, n)</dt><dd><tt>Remove node n.<br> <br> Removes the node n and all adjacent edges.<br> Attempting to remove a non-existent node will raise an exception.<br> <br> Parameters<br> ----------<br> n : node<br> A node in the graph<br> <br> Raises<br> -------<br> NetworkXError<br> If n is not in the graph.<br> <br> See Also<br> --------<br> remove_nodes_from<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> G.<a href="#noc-edges">edges</a>()<br> [(0, 1), (1, 2)]<br> >>> G.<a href="#noc-remove_node">remove_node</a>(1)<br> >>> G.<a href="#noc-edges">edges</a>()<br> []</tt></dd></dl> <dl><dt><a name="noc-remove_nodes_from"><strong>remove_nodes_from</strong></a>(self, nodes)</dt><dd><tt>Remove multiple nodes.<br> <br> Parameters<br> ----------<br> nodes : iterable container<br> A container of nodes (list, <a href="__builtin__.html#dict">dict</a>, set, etc.). If a node<br> in the container is not in the graph it is silently<br> ignored.<br> <br> See Also<br> --------<br> remove_node<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2])<br> >>> e = G.<a href="#noc-nodes">nodes</a>()<br> >>> e<br> [0, 1, 2]<br> >>> G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>(e)<br> >>> G.<a href="#noc-nodes">nodes</a>()<br> []</tt></dd></dl> <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> <br> A selfloop edge has the same node at both ends.<br> <br> Parameters<br> -----------<br> data : bool, optional (default=False)<br> Return selfloop edges as two tuples (u,v) (data=False)<br> or three-tuples (u,v,data) (data=True)<br> <br> Returns<br> -------<br> edgelist : list of edge tuples<br> A list of all selfloop edges.<br> <br> See Also<br> --------<br> selfloop_nodes, number_of_selfloops<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,1)<br> >>> G.<a href="#noc-add_edge">add_edge</a>(1,2)<br> >>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>()<br> [(1, 1)]<br> >>> G.<a href="#noc-selfloop_edges">selfloop_edges</a>(data=True)<br> [(1, 1, {})]</tt></dd></dl> <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> <br> Parameters<br> ----------<br> weighted : boolean, optional (default=False)<br> If True return the sum of the edge weights.<br> <br> Returns<br> -------<br> nedges : int<br> The number of edges in the graph.<br> <br> See Also<br> --------<br> number_of_edges<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> G.<a href="#noc-size">size</a>()<br> 3<br> <br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_edge">add_edge</a>('a','b',weight=2)<br> >>> G.<a href="#noc-add_edge">add_edge</a>('b','c',weight=4)<br> >>> G.<a href="#noc-size">size</a>()<br> 2<br> >>> G.<a href="#noc-size">size</a>(weighted=True)<br> 6</tt></dd></dl> <dl><dt><a name="noc-subgraph"><strong>subgraph</strong></a>(self, nbunch)</dt><dd><tt>Return the subgraph induced on nodes in nbunch.<br> <br> The induced subgraph of the graph contains the nodes in nbunch <br> and the edges between those nodes. <br> <br> Parameters<br> ----------<br> nbunch : list, iterable<br> A container of nodes which will be iterated through once. <br> <br> Returns<br> -------<br> G : <a href="networkx.classes.graph.html#Graph">Graph</a><br> A subgraph of the graph with the same edge attributes. <br> <br> Notes<br> -----<br> The graph, edge or node attributes just point to the original graph.<br> So changes to the node or edge structure will not be reflected in<br> the original graph while changes to the attributes will.<br> <br> To create a subgraph with its own copy of the edge/node attributes use:<br> nx.<a href="networkx.classes.graph.html#Graph">Graph</a>(G.<a href="#noc-subgraph">subgraph</a>(nbunch))<br> <br> If edge attributes are containers, a deep copy can be obtained using:<br> G.<a href="#noc-subgraph">subgraph</a>(nbunch).<a href="#noc-copy">copy</a>()<br> <br> For an in-place reduction of a graph to a subgraph you can remove nodes:<br> G.<a href="#noc-remove_nodes_from">remove_nodes_from</a>([ n in G if n not in set(nbunch)]) <br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or DiGraph, MultiGraph, MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1,2,3])<br> >>> H = G.<a href="#noc-subgraph">subgraph</a>([0,1,2])<br> >>> print H.<a href="#noc-edges">edges</a>()<br> [(0, 1), (1, 2)]</tt></dd></dl> <dl><dt><a name="noc-to_directed"><strong>to_directed</strong></a>(self)</dt><dd><tt>Return a directed representation of the graph.<br> <br> Returns<br> -------<br> G : DiGraph<br> A directed graph with the same name, same nodes, and with<br> each edge (u,v,data) replaced by two directed edges<br> (u,v,data) and (v,u,data).<br> <br> Notes<br> -----<br> This returns a "deepcopy" of the edge, node, and <br> graph attributes which attempts to completely copy<br> all of the data and references.<br> <br> This is in contrast to the similar D=DiGraph(G) which returns a <br> shallow copy of the data. <br> <br> See the Python copy module for more information on shallow<br> and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> >>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> >>> H.<a href="#noc-edges">edges</a>()<br> [(0, 1), (1, 0)]<br> <br> If already directed, return a (deep) copy<br> <br> >>> G = nx.DiGraph() # or MultiDiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> >>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> >>> H.<a href="#noc-edges">edges</a>()<br> [(0, 1)]</tt></dd></dl> <dl><dt><a name="noc-to_undirected"><strong>to_undirected</strong></a>(self)</dt><dd><tt>Return an undirected copy of the graph. <br> <br> Returns<br> -------<br> G : <a href="networkx.classes.graph.html#Graph">Graph</a>/MultiGraph<br> A deepcopy of the graph.<br> <br> See Also<br> --------<br> copy, add_edge, add_edges_from<br> <br> Notes<br> -----<br> This returns a "deepcopy" of the edge, node, and <br> graph attributes which attempts to completely copy<br> all of the data and references.<br> <br> This is in contrast to the similar G=DiGraph(D) which returns a <br> shallow copy of the data. <br> <br> See the Python copy module for more information on shallow<br> and deep copies, <a href="http://docs.python.org/library/copy.html">http://docs.python.org/library/copy.html</a>.<br> <br> Examples<br> --------<br> >>> G = nx.<a href="networkx.classes.graph.html#Graph">Graph</a>() # or MultiGraph, etc<br> >>> G.<a href="#noc-add_path">add_path</a>([0,1])<br> >>> H = G.<a href="#noc-to_directed">to_directed</a>()<br> >>> H.<a href="#noc-edges">edges</a>()<br> [(0, 1), (1, 0)]<br> >>> G2 = H.<a href="#noc-to_undirected">to_undirected</a>()<br> >>> G2.<a href="#noc-edges">edges</a>()<br> [(0, 1)]</tt></dd></dl> <hr> Data descriptors inherited from <a href="networkx.classes.graph.html#Graph">networkx.classes.graph.Graph</a>:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary for instance variables (if defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list of weak references to the object (if defined)</tt></dd> </dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="nocobject">class <strong>nocobject</strong></a></font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>NoC base object<br> <br> This base class is used to implement common methods for NoC objects.<br> Don't use directly.<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <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> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Packet base object<br> <br> This object represents a <a href="#packet">packet</a> data, related to a <a href="#protocol">protocol</a> object. It <br> behaves exactly like a Python dictionary, but adds methods to simplify <br> <a href="#packet">packet</a> transformations. <br> <br> Relations with other objects:<br> * It should be generated by a <a href="#protocol">protocol</a> object (and will have a reference <br> in self.<strong>protocol_ref</strong>)<br> <br> Attributes:<br> * protocol_ref: <a href="#protocol">protocol</a> object that created this object.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="nocmodel.noc_base.html#packet">packet</a></dd> <dd><a href="__builtin__.html#dict">__builtin__.dict</a></dd> <dd><a href="__builtin__.html#object">__builtin__.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="packet-__init__"><strong>__init__</strong></a>(self, *args, **kwargs)</dt><dd><tt># the constructor</tt></dd></dl> <hr> Data descriptors defined here:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary for instance variables (if defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list of weak references to the object (if defined)</tt></dd> </dl> <hr> Methods inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> <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> If key is not found, d is returned if given, otherwise KeyError is raised</tt></dd></dl> <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> 2-tuple; but raise KeyError if D is empty.</tt></dd></dl> <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> <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> If E has a .<a href="#packet-keys">keys</a>() method, does: for k in E: D[k] = E[k]<br> If E lacks .<a href="#packet-keys">keys</a>() method, does: for (k, v) in E: D[k] = v<br> In either case, this is followed by: for k in F: D[k] = F[k]</tt></dd></dl> <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> <hr> Data and other attributes inherited from <a href="__builtin__.html#dict">__builtin__.dict</a>:<br> <dl><dt><strong>__hash__</strong> = None</dl> <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> <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> v defaults to None.</tt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Protocol base object<br> <br> This object represents the <a href="#protocol">protocol</a> that the NoC objects use. This <br> object has attributes that define the <a href="#protocol">protocol</a> used, mainly it can be<br> used to generate, encode, decode or interpret packets on the NoC.<br> This base class can be either be inherited or extended by adding <br> other attributes.<br> <br> Relations with other objects:<br> * Each object on the NoC (routers, channels and ipcores) may have<br> one reference to a <a href="#protocol">protocol</a> object (object.protocol_ref)<br> * A NoC model may have a <a href="#protocol">protocol</a> object: in this case, all objects in<br> the model will use this <a href="#protocol">protocol</a> (nocmodel.protocol_ref)<br> * A <a href="#protocol">protocol</a> object is a generator of <a href="#packet">packet</a> objects<br> <br> Attributes:<br> * name<br> <br> Notes: <br> * Optional arguments "packet_format" and "packet_order" can be<br> added at object construction, but will not check its data consistency. <br> At the moment, we recommend using <a href="#protocol-update_packet_field">update_packet_field</a>() method to<br> fill this data structures.<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="protocol-__init__"><strong>__init__</strong></a>(self, name<font color="#909090">=''</font>, **kwargs)</dt><dd><tt>Constructor<br> <br> Notes:<br> * Optional arguments will be added as object attributes.</tt></dd></dl> <dl><dt><a name="protocol-get_protocol_ref"><strong>get_protocol_ref</strong></a>(self)</dt></dl> <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> <br> Arguments:<br> * zerodefault: If True, all missing fields will be zeroed by default.<br> If False, a missing value in arguments will throw an exception.<br> * args: Nameless arguments will add field values based on <a href="#packet">packet</a> field<br> order.<br> * kwargs: Key-based arguments will add specified field values based in <br> its keys<br> <br> Notes: <br> * kwargs takes precedence over args: i.e. named arguments can overwrite<br> nameless arguments.</tt></dd></dl> <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> <br> Must be a derived class of <a href="#packet">packet</a></tt></dd></dl> <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> <br> Arguments<br> * name<br> * type: string that can be "int", "fixed" or "float"<br> * bitlen: bit length of this field<br> * description: optional description of this field<br> <br> Notes: <br> * Each new field will be added at the end.</tt></dd></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <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> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>Router base object<br> <br> This object represents a <a href="#router">router</a> object and its properties. This base class<br> is meant to either be inherited or extended by adding other attributes.<br> <br> Relations with other objects:<br> * It should be related to one NoC model object (self.<strong>graph_ref</strong>)<br> * It should be one of the node attributes in the graph model <br> (node["router_ref"])<br> * It may have one reference to an <a href="#ipcore">ipcore</a> object (self.<strong>ipcore_ref</strong>)<br> * It has a port list with relations to other routers through <a href="#channel">channel</a> objects,<br> and only one relation to its <a href="#ipcore">ipcore</a> object through one <a href="#channel">channel</a>.<br> (self.<strong>ports</strong>). Note that this attribute must be updated after changing <br> the NoC model.<br> <br> Attributes:<br> * index: index on a <a href="#noc">noc</a> object. Essential to search for a <a href="#router">router</a> object<br> * name<br> * ipcore_ref: optional reference to its related <a href="#ipcore">ipcore</a><br> * graph_ref: optional reference to its graph model<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="router-__init__"><strong>__init__</strong></a>(self, index, name, **kwargs)</dt></dl> <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> the channels that connect them and its references.<br> <br> Ports dictionary has the following structure:<br> * key: address of the neighbor <a href="#router">router</a> that this port connects.<br> * value: dictionary with the following keys:<br> * "peer" (required): reference to the neighbor <a href="#router">router</a><br> * "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br> <a href="#router">router</a> and its neighbor <a href="#router">router</a>.<br> * Optional keys can be added to this dictionary.<br> * Also, the special key "local address" holds the port to <br> <a href="#router">router</a>'s <a href="#ipcore">ipcore</a>. Its values are:<br> * "peer" (required): reference to its <a href="#ipcore">ipcore</a><br> * "<a href="#channel">channel</a>" (required): reference to the <a href="#channel">channel</a> that connects this <br> <a href="#router">router</a> and its <a href="#ipcore">ipcore</a>.<br> * Optional keys can be added to this dictionary with the same <br> meaning as other ports.</tt></dd></dl> <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> about how a package, starting from this <a href="#router">router</a>, can reach another one.<br> <br> routes_info dictionary has the following structure:<br> * keys : the address of all the routers in NoC<br> * values : an ordered list of dictionaries with <br> * "next" : address of the next <a href="#router">router</a><br> * "paths" : list of possible paths for key destination</tt></dd></dl> <hr> Methods inherited from <a href="nocmodel.noc_base.html#nocobject">nocobject</a>:<br> <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> </td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#eeaa77"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> <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> This is a function not available in NetworkX (checked at 22-02-2011)<br> <br> Taken from: <br> <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> </td></tr></table> </body></html>
Go to most recent revision | Compare with Previous | Blame | View Log