> --
> You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
> To post to this group, send email to networkx...@googlegroups.com.
> To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
> <2NW.graphml>
Can you post a small (nonworking) example. This is working for me:
In [1]: import networkx as nx
In [2]: G=nx.DiGraph()
In [3]: G.add_edge(1,2,weight=7)
In [4]: G.add_edge(1,2,weight=22) # update edge with new weight
In [5]: import sys
In [6]: nx.write_graphml(G,sys.stdout)
<?xml version="1.0" encoding="utf-8"?><graphml
xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key attr.name="weight" attr.type="int" for="edge" id="d0" />
<graph edgedefault="directed">
<node id="1" />
<node id="2" />
<edge source="1" target="2">
<data key="d0">22</data>
</edge>
</graph>
</graphml>
Aric
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
If the data in the GraphML format file has parallel edges you will get
a MultiDiGraph object returned from read_graphml() that contains those
parallel edges (see the read_graphml docs).
If you want to remove the parallel edges you can try
G=nx.DiGraph(nx.read_graphml(file)). That will arbitrarily remove all
but one (directed) edge between two nodes.
Aric
On Mon, Sep 19, 2011 at 9:26 AM, Denzil Correa <den...@iiitd.ac.in> wrote:If the data in the GraphML format file has parallel edges you will get
> Aric :
>
> Rather surprisingly such an example (on command line) works for me. Is there
> any way I can understand the type of graph if loaded from a GraphML file? If
> not, I would propose this as a feature request. I was made aware of the
> parallel edges once I imported my GraphML into a social network analysis
> tool including Gephi and CMU-ORA
a MultiDiGraph object returned from read_graphml() that contains those
parallel edges (see the read_graphml docs).
If you want to remove the parallel edges you can try
G=nx.DiGraph(nx.read_graphml(file)). That will arbitrarily remove all
but one (directed) edge between two nodes.
Aric
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
You don't get to choose with read_graphml(). That code tries to
figure out what kind of graph you have and choose the appropriate
container. In your case the right object is a multigraph (you have
parallel edges).
>> If you want to remove the parallel edges you can try
>> G=nx.DiGraph(nx.read_graphml(file)). That will arbitrarily remove all
>> but one (directed) edge between two nodes.
>
> I wouldn't mind doing this. Is there any heuristic (max. edge weight) to
> understand which edge this function would retain?
It's arbitrary (based on the arbitrary ordering of the Python
dictionary of dictionary storage). If you want more control over
which edges to keep you'll need to load the data as a MultiDiGraph,
initialize a new DiGraph(), and loop over the edges in the
MultiDiGraph keeping only the ones you want and adding to the DiGraph.
Aric
Aric
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
It's possible there is a bug in the chain somewhere.
Can you reproduce the behavior with a small example?
It works for the simple examples in the networkx tests, e.g.
In [1]: import networkx as nx
In [2]: G=nx.DiGraph()
In [3]: G.add_edge(1,2,weight=7)
In [4]: G.add_edge(1,2,weight=22)
In [5]: repr(G)
Out[5]: '<networkx.classes.digraph.DiGraph object at 0x1a46390>'
In [6]: G.edges()
Out[6]: [(1, 2)]
In [7]: nx.write_graphml(G,'test.graphml')
In [8]: H=nx.read_graphml('test.graphml')
In [9]: repr(H)
Out[9]: '<networkx.classes.digraph.DiGraph object at 0x1a46850>'
In [10]: H.edges()
Out[10]: [('1', '2')]
Aric
The read_graphml() function does try to figure out if the input graph
has parallel edges. If not the type is switched to Graph or DiGraph
before return. There could be a bug there. But that should be easy
to fix if we can isolate the problem.
Aric
Aric
Aric
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
I think the problem is that you are mixing integer and node types in
your graph. e.g. from your data file:
In [55]: G=nx.read_gpickle('2NW.gpickle')
In [56]: G.nodes()[10:20]
Out[56]:
[79691779,
68331541,
145311766,
20123671,
'20429407',
'23695379',
131147806,
'48301904',
'35094823',
'110306287']
The nodes in the GraphML file (as far as I know) have to be of one
type so if you have a string and an integer that both represent the
same number value they will get conflated.
Aric
Aric
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.