# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1215817768 -7200
# Node ID 9b052679a797a81c140aab35b4d3a729f454b89a
# Parent 21b33e184d46773be0a962811caef77048514d71
dijkstra_demo.cc read the graph from an .lgf file (see ticket #27)
Slightly modify lgf_demo.cc to use the same input file
diff -r 21b33e184d46 -r 9b052679a797 demo/digraph.lgf
a
|
b
|
|
9 | 9 | 6 |
10 | 10 | 7 |
11 | 11 | @arcs |
12 | | label capacity |
13 | | 0 1 0 16 |
14 | | 0 2 1 12 |
15 | | 0 3 2 20 |
16 | | 1 2 3 10 |
17 | | 1 4 4 10 |
18 | | 1 5 5 13 |
19 | | 2 3 6 10 |
20 | | 2 4 7 8 |
21 | | 2 6 8 8 |
22 | | 5 3 9 20 |
23 | | 3 6 10 25 |
24 | | 4 7 11 15 |
25 | | 5 7 12 15 |
26 | | 6 7 13 18 |
| 12 | label length |
| 13 | 0 1 0 10 |
| 14 | 0 2 1 20 |
| 15 | 0 3 2 30 |
| 16 | 1 2 3 5 |
| 17 | 1 4 4 16 |
| 18 | 1 5 5 10 |
| 19 | 2 3 6 12 |
| 20 | 2 4 7 15 |
| 21 | 2 6 8 20 |
| 22 | 3 6 10 8 |
| 23 | 4 7 11 20 |
| 24 | 5 3 9 5 |
| 25 | 5 7 12 25 |
| 26 | 6 7 13 10 |
27 | 27 | @attributes |
28 | 28 | source 0 |
29 | 29 | target 7 |
diff -r 21b33e184d46 -r 9b052679a797 demo/dijkstra_demo.cc
a
|
b
|
|
29 | 29 | |
30 | 30 | #include <iostream> |
31 | 31 | #include <lemon/list_graph.h> |
| 32 | #include <lemon/lgf_reader.h> |
32 | 33 | #include <lemon/dijkstra.h> |
33 | 34 | |
34 | 35 | using namespace lemon; |
35 | 36 | |
36 | 37 | int main (int, char*[]) |
37 | 38 | { |
38 | | // Convenient type definitions |
| 39 | // Type definitions |
39 | 40 | typedef ListDigraph Digraph; |
40 | 41 | typedef Digraph::Node Node; |
41 | | typedef Digraph::Arc Arc; |
42 | 42 | typedef Digraph::ArcMap<int> LengthMap; |
43 | 43 | |
44 | | // Create a directed graph and a length map |
| 44 | // Read a digraph with arc lengths form 'digraph.lgf' |
45 | 45 | Digraph g; |
46 | | |
47 | | Node s=g.addNode(); |
48 | | Node v2=g.addNode(); |
49 | | Node v3=g.addNode(); |
50 | | Node v4=g.addNode(); |
51 | | Node v5=g.addNode(); |
52 | | Node t=g.addNode(); |
53 | | |
54 | | Arc s_v2=g.addArc(s, v2); |
55 | | Arc s_v3=g.addArc(s, v3); |
56 | | Arc v2_v4=g.addArc(v2, v4); |
57 | | Arc v2_v5=g.addArc(v2, v5); |
58 | | Arc v3_v5=g.addArc(v3, v5); |
59 | | Arc v4_t=g.addArc(v4, t); |
60 | | Arc v5_t=g.addArc(v5, t); |
61 | | |
62 | 46 | LengthMap len(g); |
63 | | |
64 | | len.set(s_v2, 10); |
65 | | len.set(s_v3, 10); |
66 | | len.set(v2_v4, 5); |
67 | | len.set(v2_v5, 8); |
68 | | len.set(v3_v5, 5); |
69 | | len.set(v4_t, 8); |
70 | | len.set(v5_t, 8); |
| 47 | Node s, t; |
| 48 | digraphReader("digraph.lgf", g). |
| 49 | arcMap("length", len). |
| 50 | node("source", s). |
| 51 | node("target", t). |
| 52 | run(); |
71 | 53 | |
72 | 54 | std::cout << "This program is a simple demo of the LEMON Dijkstra class." |
73 | 55 | << std::endl; |
74 | 56 | std::cout << "We calculate the shortest path from node s to node t in a digraph." |
75 | 57 | << std::endl << std::endl; |
76 | 58 | |
| 59 | // Print the IDs of s and t |
77 | 60 | std::cout << "The id of s is " << g.id(s) << ", " |
78 | 61 | << "the id of t is " << g.id(t) << "." << std::endl; |
79 | 62 | |
diff -r 21b33e184d46 -r 9b052679a797 demo/lgf_demo.cc
a
|
b
|
|
40 | 40 | |
41 | 41 | int main() { |
42 | 42 | SmartDigraph g; |
43 | | SmartDigraph::ArcMap<int> cap(g); |
| 43 | SmartDigraph::ArcMap<int> len(g); |
44 | 44 | SmartDigraph::Node s, t; |
45 | 45 | |
46 | 46 | try { |
47 | 47 | digraphReader("digraph.lgf", g). // read the directed graph into g |
48 | | arcMap("capacity", cap). // read the 'capacity' arc map into cap |
| 48 | arcMap("length", len). // read the 'length' arc map into len |
49 | 49 | node("source", s). // read 'source' node to s |
50 | 50 | node("target", t). // read 'target' node to t |
51 | 51 | run(); |
… |
… |
|
61 | 61 | std::cout << "We can write it to the standard output:" << std::endl; |
62 | 62 | |
63 | 63 | digraphWriter(std::cout, g). // write g to the standard output |
64 | | arcMap("capacity", cap). // write cap into 'capacity' |
| 64 | arcMap("weight", len). // write len into 'weight' |
65 | 65 | node("source", s). // write s to 'source' |
66 | 66 | node("target", t). // write t to 'target' |
67 | 67 | run(); |