Multiple Edges between the nodes are not getting created

325 views
Skip to first unread message

Animesh Kumar

unread,
Jul 9, 2015, 6:58:14 PM7/9/15
to pygraphvi...@googlegroups.com
Hi,

I am trying to create a graph where multiple edges between two nodes are possible.

I am gone through various post in the forum and on the internet but none of the solutions work.


Here is the snippet of my code :-
graph = AGraph(strict = False, directed = True)
# Set the style attributes of the graph
graph.node_attr['style']='rounded'
graph.node_attr['shape']='box'
graph.node_attr['fixedsize']='false'
graph.node_attr['labelloc']='c'
graph.node_attr['fontname']='times'
graph.node_attr['fontcolor']='purple'

key_str = destination_port+"_"+source_port
# Get the data from the dictionary and work on in
graph.add_edge(source,destination,key=key_str,dir='both',taillabel=destination_port,headlabel=source_port,style='bold',color='blue')


I need multiple edges between two nodes which can have different source and destination port. The source_port, destination_port combination is always unique.

The issue i am getting is that, when my dot file is generated, the tail label and the head labels of edge with old key gets replaced by the tail and head label of the new key.

Output achieved :
graph  {
node [fixedsize=false,
fontcolor=red,
fontname=times,
label="\N",
labelloc=c,
shape=box,
style=rounded
];
r1_re [fontcolor=purple,
label=r1_re];
r2_re0 [label=r2_re0];
r1_re -- r2_re0 [key="abc_def",
color=blue,
dir=both,
headlabel="abc",
style=bold,
taillabel="xyz"];
}





Desired Result :

graph  {
node [fixedsize=false,
fontcolor=red,
fontname=times,
label="\N",
labelloc=c,
shape=box,
style=rounded
];
r1_re [fontcolor=purple,
label=r1_re];
r2_re0 [label=r2_re0];
r1_re -- r2_re0 [key="abc_def",
color=blue,
dir=both,
headlabel="abc",
style=bold,
taillabel="def"];
r1_re -- r2_re0 [key="abc_xyz",
color=blue,
dir=both,
headlabel="abc",
style=bold,
taillabel="xyz"];
}


What am I doing wrong here? Or what else should i do to get the desired result?

Animesh Kumar

unread,
Jul 9, 2015, 7:03:23 PM7/9/15
to pygraphvi...@googlegroups.com
I tried checking if my graph was strict or not by:-

print graph.is_strict()
print graph.strict


and both returned False

Aric Hagberg

unread,
Jul 9, 2015, 7:08:00 PM7/9/15
to pygraphvi...@googlegroups.com

It could be a bug.  But your example isn't complete which makes it harder to tell.  Could you post a complete example?  Aric

--
You received this message because you are subscribed to the Google Groups "pygraphviz-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pygraphviz-disc...@googlegroups.com.
To post to this group, send email to pygraphvi...@googlegroups.com.
Visit this group at http://groups.google.com/group/pygraphviz-discuss.
For more options, visit https://groups.google.com/d/optout.

Animesh Kumar

unread,
Jul 9, 2015, 7:39:46 PM7/9/15
to pygraphvi...@googlegroups.com
It won't be possible to post the complete example since that's specific my company's use case and I can't post that code here.

But I tried the simple example for multiple edges given in Pygraphviz documentation and that didn't work too :- 
from pygraphviz import *

G=AGraph(strict=False)
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys=True))
print G.strict
print G.is_strict()
G.write("graph.dot")   


The dot file it generated was:-

graph  {
a -- b [key=first];
}



For strict, both the print statements were False.

I am using OS X Yosemite 10.10.4 operating system.


Aric Hagberg

unread,
Jul 9, 2015, 7:40:49 PM7/9/15
to pygraphvi...@googlegroups.com

Then maybe it is an installation issue.  Do the tests run and pass?  Aric

Animesh Kumar

unread,
Jul 9, 2015, 10:53:09 PM7/9/15
to pygraphvi...@googlegroups.com

When I run the command for tests:-

python -c "import pygraphviz; pygraphviz.test()"




It fails saying 10 tests failed.


Running PyGraphiz tests:FF....FF................F..............................F..............F.FF...F......


======================================================================


FAIL: pygraphviz.tests.test_attribute_defaults.test_default_attributes


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_attribute_defaults.py", line 22, in test_default_attributes


    """.replace('\n', linesep))


AssertionError: u'strict graph {\n  graph [label=test, spam=eggs];\n}\n' != u'strict graph {\n  graph [label=test,\n    spam=eggs\n  ];\n}\n'


  strict graph {


-   graph [label=test, spam=eggs];


?                     ------------


+   graph [label=test,


+     spam=eggs


+   ];


  }






======================================================================


FAIL: pygraphviz.tests.test_attribute_defaults.test_graph_defaults


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_attribute_defaults.py", line 47, in test_graph_defaults


    """.replace('\n', linesep))


AssertionError: u'strict graph {\n  graph [pack=true, rankdir=LR];\n}\n' != u'strict graph {\n  graph [pack=true,\n    rankdir=LR\n  ];\n}\n'


  strict graph {


-   graph [pack=true, rankdir=LR];


?                    -------------


+   graph [pack=true,


+     rankdir=LR


+   ];


  }






======================================================================


FAIL: pygraphviz.tests.test_edge_attributes.test_edge_attributes


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_edge_attributes.py", line 15, in test_edge_attributes


    """.replace('\n', linesep)


AssertionError: u'strict graph {\n  1 -- 2 [label=test, spam=eggs];\n}\n' != u'strict graph {\n  1 -- 2   [label=test,\n    spam=eggs];\n}\n'


  strict graph {


-   1 -- 2 [label=test, spam=eggs];


?                      ------------


+   1 -- 2   [label=test,


?         ++


+     spam=eggs];


  }






======================================================================


FAIL: pygraphviz.tests.test_edge_attributes.test_edge_attributes2


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_edge_attributes.py", line 32, in test_edge_attributes2


    """.replace('\n', linesep)


AssertionError: u'strict graph {\n  1 -- 2 [label=test, spam=eggs];\n}\n' != u'strict graph {\n  1 -- 2   [label=test,\n    spam=eggs];\n}\n'


  strict graph {


-   1 -- 2 [label=test, spam=eggs];


?                      ------------


+   1 -- 2   [label=test,


?         ++


+     spam=eggs];


  }






======================================================================


FAIL: pygraphviz.tests.test_graph.TestDiGraphOnly.test_graph_not_strict


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_graph.py", line 262, in test_graph_not_strict


    [('1', '2'), ('1', '2'), ('3', '3'), ('3', '3')])


AssertionError: Lists differ: [(u'1', u'2'), (u'1', u'2'), (... != [(u'1', u'2'), (u'1', u'2'), (...




Second list contains 1 additional elements.


First extra element 3:


(u'3', u'3')




- [(u'1', u'2'), (u'1', u'2'), (u'3', u'3')]


+ [(u'1', u'2'), (u'1', u'2'), (u'3', u'3'), (u'3', u'3')]


?                                     ++++++++++++++






======================================================================


FAIL: pygraphviz.tests.test_graph.TestGraph.test_graph_not_strict


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_graph.py", line 262, in test_graph_not_strict


    [('1', '2'), ('1', '2'), ('3', '3'), ('3', '3')])


AssertionError: Lists differ: [(u'1', u'2'), (u'1', u'2'), (... != [(u'1', u'2'), (u'1', u'2'), (...




Second list contains 1 additional elements.


First extra element 3:


(u'3', u'3')




- [(u'1', u'2'), (u'1', u'2'), (u'3', u'3')]


+ [(u'1', u'2'), (u'1', u'2'), (u'3', u'3'), (u'3', u'3')]


?                                     ++++++++++++++






======================================================================


FAIL: pygraphviz.tests.test_html.test_html


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_html.py", line 23, in test_html


    """.replace('\n', linesep))


AssertionError: u'strict graph {\n  graph [label=<Hello<BR/>Graph>];\n  node [label="\\N"];\n  {\n    graph [label=<Hello<BR/>Subgraph>];\n    sa [label=<Hello<BR/>Subgraph Node b>];\n  }\n  a [label=<Hello<BR/>Node>];\n  a -- b [label=<Hello<BR/>Edge>];\n}\n' != 'strict graph {\n  graph [label=<Hello<BR/>Graph>];\n  node [label="\\N"];\n  {\n    graph [label=<Hello<BR/>Subgraph>];\n    sa     [label=<Hello<BR/>Subgraph Node b>];\n  }\n  a  [label=<Hello<BR/>Node>];\n  a -- b   [label=<Hello<BR/>Edge>];\n}\n'




======================================================================


FAIL: pygraphviz.tests.test_node_attributes.test_node_attribute


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_node_attributes.py", line 16, in test_node_attribute


    """.replace('\n', linesep))


AssertionError: u'strict graph {\n  node [label="\\N"];\n  1 [label=test, spam=eggs];\n}\n' != u'strict graph {\n  node [label="\\N"];\n  1  [label=test,\n    spam=eggs];\n}\n [truncated]...


  strict graph {


    node [label="\N"];


-   1 [label=test, spam=eggs];


+   1  [label=test,


+     spam=eggs];


  }






======================================================================


FAIL: pygraphviz.tests.test_node_attributes.test_node_attributes2


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_node_attributes.py", line 33, in test_node_attributes2


    """.replace('\n', linesep)


AssertionError: u'strict graph {\n  node [label="\\N"];\n  1 [label=test, spam=eggs];\n}\n' != u'strict graph {\n  node [label="\\N"];\n  1  [label=test,\n    spam=eggs];\n}\n [truncated]...


  strict graph {


    node [label="\N"];


-   1 [label=test, spam=eggs];


+   1  [label=test,


+     spam=eggs];


  }






======================================================================


FAIL: pygraphviz.tests.test_string.test_string_representation_large


----------------------------------------------------------------------


Traceback (most recent call last):


  File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest


    self.test(*self.arg)


  File "/Library/Python/2.7/site-packages/pygraphviz/tests/test_string.py", line 49, in test_string_representation_large


    """.replace('\n', linesep))


AssertionError: u'strict graph "test graph" {\n        11;\n        1 -- 2;\n        2 -- 3;\n        3 -- 4;\n        4 -- 5;\n        5 -- 6;\n        6 -- 7;\n        7 -- 8;\n        8 -- 9;\n        9 -- 10;\n}\n' != 'strict graph "test graph" {\n        1 -- 2;\n        2 -- 3;\n        3 -- 4;\n        4 -- 5;\n        5 -- 6;\n        6 -- 7;\n        7 -- 8;\n        8 -- 9;\n        9 -- 10;\n        11;\n}\n'




----------------------------------------------------------------------


Ran 84 tests in 0.459s




FAILED (failures=10)



Animesh Kumar

unread,
Jul 9, 2015, 10:53:09 PM7/9/15
to pygraphvi...@googlegroups.com
I just reinstalled the development snapshot 2.39 of Graphviz from the following link :-


and i reinstalled the PyGraphviz from the zip in the following link: 

Before installation i changed :
library_dirs='/usr/local/lib/graphviz'
include_dirs
='/usr/local/include/graphviz'

The installation completed fine without giving any errors but when I run the test, I am still getting these errors. Do I have to run the test from any specific location or something?

Aric Hagberg

unread,
Jul 9, 2015, 11:02:43 PM7/9/15
to pygraphvi...@googlegroups.com
I'm using graphivz-2.36.0. As soon as I can I'll try with 2.39 and
see what the results are.
There is some issue with the installation or configuration and it may
be the something has changed with graphviz in the newer versions.
Aric

Aric Hagberg

unread,
Jul 10, 2015, 1:27:25 PM7/10/15
to pygraphvi...@googlegroups.com
I can confirm there is definitely something not working right related
to keyed parallel edges using graphviz-2.39. I'm not sure what the
exact issue or fix is but I'll investigate further when I get a
chance.

Aric

Animesh Kumar

unread,
Jul 10, 2015, 2:14:53 PM7/10/15
to pygraphvi...@googlegroups.com
Yes that's right. I just installed version 2.36 on my Mac and tried running my script again and it gave me the desired result. So, something got broken in version 2.39.
Thank you :)

Aric Hagberg

unread,
Jul 10, 2015, 3:53:19 PM7/10/15
to pygraphvi...@googlegroups.com
Pygraphviz also works correctly with the latest stable release
graphviz-2.38.0.tar.gz13-Apr-2014 16:43
So something has changed since then.
It's probably one of the recent commits in libcgraph
https://github.com/ellson/graphviz/commits/734360a29a89a36d458d1eba624e7cf31d031416/lib/cgraph

Aric
Reply all
Reply to author
Forward
0 new messages