Regards,
Chris
_______________________________________________
NetworkX-discuss mailing list
NetworkX...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/networkx-discuss
The ids that are given to nodes must be unique. But if you want
you can always have a symbol table to assign labels to the ids.
For example:
>>> import networkx as NX
>>> import pylab as P
>>> G=NX.Graph()
>>> label={}
>>> label[1]="a"
>>> label[2]="="
>>> label[3]="1"
>>> G.add_edge(1,2)
>>> G.add_edge(3,2)
>>> label[4]="b"
>>> label[5]="="
>>> label[6]="1"
>>> G.add_edge(4,5)
>>> G.add_edge(6,5)
>>> print [label[n] for n in G]
>>> for (u,v) in G.edges():
>>> print (label[u],label[v])
>>> NX.draw(G,labels=label)
>>> P.show()
Aric
On Thu, Jun 01, 2006 at 07:15:03PM -0400, Chris S wrote:
> Is it possible to represent an abstract syntax tree with networkx, in
> the sense that you can have two or more distinct nodes sharing a
> hashable value? For instance, consider a=1 and b=1. I want to have two
> nodes with the value '=', each with links to 'a', 'b' and '1' nodes
> respectively, not a single '=' node with all the other nodes linked to
> it.
_______________________________________________
Thanks, that might help, although I'm looking for something that will
still let me easily query nodes based on function. If every '=' node
has a unique value, I won't be able to quickly find all links to '='
nodes. However, I think I might be able to emulate this functionality
by using an XDiGraph and representing the unique id on the link. So
add_edge('a', '=', 123) would have the meaning of a link from node 'a'
to node '=' with id 123.