Quit

Routenplanung oder ein wenig Graphentheorie ...

\(vertices = 
      Import["~/papers/Vortraege/bozen-2003-09-26/OeBB-Knoten.txt", "CSV"]\)
\(edges = 
      Import["~/papers/Vortraege/bozen-2003-09-26/OeBB-Kanten.txt", "CSV"]\)

<< DiscreteMath`Combinatorica`

G = 
      FromOrderedPairs[
Map[Drop[#, -1] &, 
          edges], 
Map[{#[[3]], -#[[4]]} &, 
          vertices], 
Type -> Undirected]

xv = Map[#[[3]] &, vertices];
yv = Map[#[[4]] &, vertices];

Aratio = (Max[yv] - Min[yv])/(Max[xv] - Min[xv])

G1 = 
      SetEdgeWeights[
SetVertexLabels[
          G, 
Map[#[[2]] &, 
            vertices]], 
Map[#[[3]] &, 
          edges]
]

ShowGraph[G1, VertexStyle -> Disk[0.005], EdgeStyle -> Thin, 
      AspectRatio -> Aratio, ImageSize -> {1024, 1024*Aratio}, 
      VertexLabelPosition -> Center]

ShowGraph[SetEdgeLabels[G, Map[#[[3]] &, edges]], 
      VertexStyle -> Disk[0.005], EdgeStyle -> Thin, 
      AspectRatio -> Aratio, ImageSize -> {1024, 1024*Aratio}, 
      EdgeLabelPosition -> Center]

Nummer[s_] := 
      Module[{l}, l = Flatten[Position[vertices, {_, s, _, _}]]; 
        If[Length[l] == 1, l[[1]], 
          Print["Error: " <>  s  <>  "yields " <> 
              ToString[l]]]]

\(RoutenPlaner[von_, nach_] := 
      Module[{shortest, shortestedges}, 
shortest = 
          ShortestPath[G1, Nummer[von], 
            Nummer[nach]]; 
shortestedges = 
          Transpose[{Drop[shortest, \(-1\)], 
              Drop[shortest, 
                1]}]; 
ShowGraph[
SetGraphOptions[
            G1, {Append[shortestedges, EdgeColor -> Red], 
              Join[shortest, {VertexColor -> Green, 
                  VertexLabelColor -> 
                    Green}]}], 
VertexStyle -> 
            Disk[0.005], EdgeStyle -> Thin, AspectRatio -> Aratio, 
          ImageSize -> {1024, 1024*Aratio}, 
          VertexLabelPosition -> Center, 
          PlotRange -> 
            Zoom[shortest]]; 
Append[
Map[
            vertices[\([#, 2]\)] &, 
            shortest], 
ToString[
              Plus @@ GetEdgeWeights[G1, 
                  shortestedges]] <> " km"
]
]\)

RoutenPlaner["Graz", "Bolzano/Bozen"]

RoutenPlaner["Graz", "Innsbruck"]

RoutenPlaner["Innsbruck", "Bolzano/Bozen"]

RoutenPlaner["Graz", "Brennero/Brenner"]