Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Graph and Shortest Path' topicStudent Support Forum > General > "Graph and Shortest Path"

Next Comment >Help | Reply To Topic
Author Comment/Response
eyas
11/30/12 08:50am

Hi,

I am struggling with the folowing problem. I ran this code on Mathematica 7.0.1 and it worked quite well but if I try to get this code on Mathematica 8.0.1 it
1) gives me an error message (see below) and
2) it does not print the shortest paths as it does in Mathematica 7.0.1

That's the code:

Needs["GraphUtilities`"]
g = Graph[
{{{1, 2}},
{{1, 3}},
{{2, 5}},
{{3, 4}},
{{3, 5}},
{{4, 5}},
{{5, 6}},
{{5, 10}},
{{6, 7}},
{{7, 8}},
{{7, 9}},
{{7, 12}},
{{8, 9}},
{{9, 10}},
{{9, 11}},
{{9, 12}},
{{10, 11}},
{{10, 7}},
{{11, 7}},
{{11, 12}}},

{{{0, 1}, VertexLabel -> True},
{{1, 2}, VertexLabel -> True},
{{1, 1}, VertexLabel -> True},
{{2, 2}, VertexLabel -> True},
{{2, 1}, VertexLabel -> True},
{{2, 0}, VertexLabel -> True},
{{3, 2}, VertexLabel -> True},
{{3, 1}, VertexLabel -> True},
{{4, 2}, VertexLabel -> True},
{{4, 1}, VertexLabel -> True},
{{1, 0}, VertexLabel -> True},
{{5, 1}, VertexLabel -> True}
}
, EdgeDirection -> True]
ShowGraph[g]
F = {}
F
For[i = 1, i < 13, i++,
For[j = 1, j < 13, j++, Print[
F = Insert[F, ShortestPath[g, i, j], -1]]]]
Export["Graph.xls", F]


In Mathematica 7.0.1 it works well and the output of the Excel-Sheet is like:

1               
1   2            
1   3            
1   3   4         
1   2   5         
1   2   5   6      
1   2   5   6   7   
1   2   5   6   7   8
1   2   5   6   7   9
1   2   5   10      
1   2   5   10   11   
1   2   5   6   7   12

But on Mathematica 8.0.1 the following error message comes:

Graph::optx: Unknown option EdgeDirection in Graph[{{{1,2}},{{1,3}},{{2,5}},{{3,4}},{{3,5}},{{4,5}},{{5,6}},{{5,10}},{{6,7}},{{7,8}},{{7,9}},{{7,12}},{{8,9}},{{9,10}},{{9,11}},{{9,12}},{{10,11}},{{10,7}},{{11,7}},{{11,12}}},{{{0,1},VertexLabel->True},{{1,2},VertexLabel->True},<<8>>,{{1,0},VertexLabel->True},{{5,1},VertexLabel->True}},EdgeDirection->True]. >>

And the Excel-File looks like this:

ShortestPath[Graph[{{{1, 2}}, {{1, 3}}, {{2, 5}}, {{3, 4}}, {{3, 5}}, {{4, 5}}, {{5, 6}}, {{5, 10}}, {{6, 7}}, {{7, 8}}, {{7, 9}}, {{7, 12}}, {{8, 9}}, {{9, 10}}, {{9, 11}}, {{9, 12}}, {{10, 11}}, {{10, 7}}, {{11, 7}}, {{11, 12}}}, {{{0, 1}, VertexLabel -> True}, {{1, 2}, VertexLabel -> True}, {{1, 1}, VertexLabel -> True}, {{2, 2}, VertexLabel -> True}, {{2, 1}, VertexLabel -> True}, {{2, 0}, VertexLabel -> True}, {{3, 2}, VertexLabel -> True}, {{3, 1}, VertexLabel -> True}, {{4, 2}, VertexLabel -> True}, {{4, 1}, VertexLabel -> True}, {{1, 0}, VertexLabel -> True}, {{5, 1}, VertexLabel -> True}}, EdgeDirection -> True], 1, 1]
ShortestPath[Graph[{{{1, 2}}, {{1, 3}}, {{2, 5}}, {{3, 4}}, {{3, 5}}, {{4, 5}}, {{5, 6}}, {{5, 10}}, {{6, 7}}, {{7, 8}}, {{7, 9}}, {{7, 12}}, {{8, 9}}, {{9, 10}}, {{9, 11}}, {{9, 12}}, {{10, 11}}, {{10, 7}}, {{11, 7}}, {{11, 12}}}, {{{0, 1}, VertexLabel -> True}, {{1, 2}, VertexLabel -> True}, {{1, 1}, VertexLabel -> True}, {{2, 2}, VertexLabel -> True}, {{2, 1}, VertexLabel -> True}, {{2, 0}, VertexLabel -> True}, {{3, 2}, VertexLabel -> True}, {{3, 1}, VertexLabel -> True}, {{4, 2}, VertexLabel -> True}, {{4, 1}, VertexLabel -> True}, {{1, 0}, VertexLabel -> True}, {{5, 1}, VertexLabel -> True}}, EdgeDirection -> True], 1, 2]



How can I run the code above correctly and get an Excel-sheet in Mathematica 8.0.1 like in Mathematica 7.0.1?

Thank you!

URL: ,

Subject (listing for 'Graph and Shortest Path')
Author Date Posted
Graph and Shortest Path eyas 11/30/12 08:50am
Re: Graph and Shortest Path yehuda 12/04/12 10:42pm
Next Comment >Help | Reply To Topic