It is a bug indeed ! Sage did not get that the graph was weighted, hence
thought that you had multiple edges in your graph, and hell followed. This
is fixed by this patch : http://trac.sagemath.org/sage_trac/ticket/13919
It will not be merged to Sage unless somebody reviews it, though. Thank you
for reporting that bug !
Nathann
On Monday, January 7, 2013 1:31:01 AM UTC+1, jamedrano wrote:
>
> Hello. I´m using Sage to teach some network algorithms. The strange thing
> is that when I define a graph using the weighted adjacency matrix, I'm able
> to get the min_spanning_tree but not the shortest path. However, when I
> define the graph using the dictionary form, everything works OK. Here's
> what I mean:
>
> sage: B =
> {0:{1:2,2:5,3:4},1:{2:2,4:7},2:{3:1,4:4,5:3},3:{5:4},4:{5:1,6:5},5:{6:7}}
> sage: grafo3 = Graph(B,weighted=True)
> sage: grafo3.min_spanning_tree(check=True)
>[(2, 3, 1), (4, 5, 1), (0, 1, 2), (1, 2, 2), (2, 5, 3), (4, 6, 5)]
> sage: grafo3.shortest_path(0,6,by_weight=True)
> [0, 1, 2, 5, 4, 6]
>
> so far so good, everything is as expected. Now I will define other graph
> using the weighted adjacency matrix from the previous graph
>
> sage: matad = grafo3.weighted_adjacency_matrix()
> sage: grafo4 = Graph(matad,format = "adjacency_matrix", weighted=True)
> sage: grafo4.min_spanning_tree(check=True)
> [(2, 3, 1), (4, 5, 1), (0, 1, 2), (1, 2, 2), (2, 5, 3), (4, 6, 5)]
>
> with min_spanning_tree there is no problem, but now with shortest path:
>
> sage: grafo4.shortest_path(0,6,by_weight=True)
> Traceback (most recent call last):
> File "", line 1, in
> File "_sage_input_104.py", line 10, in
> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8
> -*-\\n" +
> _support_.preparse_worksheet_cell(base64.b64decode("Z3JhZm80LnNob3J0ZXN0X3BhdGgoMCw2LGJ5X3dlaWdodD1UcnVlKQ=="),globals())+"\\n");
>
> execfile(os.path.abspath("___code___.py"))
> File "", line 1, in
>
> File "/tmp/tmpBOCDxN/___code___.py", line 3, in
> exec compile(u'grafo4.shortest_path(_sage_const_0 ,_sage_const_6
> ,by_weight=True)
> File "", line 1, in
>
> File
> "/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/graphs/generic_graph.py",
>
> line 12265, in shortest_path
> L = self._backend.bidirectional_dijkstra(u,v)
> File "c_graph.pyx", line 2341, in
> sage.graphs.base.c_graph.CGraphBackend.bidirectional_dijkstra
> (sage/graphs/base/c_graph.c:15964)
> TypeError: a float is required
>
>
> I tried defining the weighted adjacency matrix myself for other graphs and
> I always get the same error whith shortest path, is this a bug or am I
> missing something? Thank you very much for your help.
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.