Graph input-output demo, some documentation.
authorathos
Fri, 01 Jul 2005 16:10:46 +0000
changeset 15281aa71600000c
parent 1527 7ceab500e1f6
child 1529 c914e7ec2b7b
Graph input-output demo, some documentation.
demo/Makefile.am
demo/dijkstra_demo.cc
demo/reader_writer_demo.cc
demo/sample.lgf
doc/getstart.dox
doc/quicktour.dox
     1.1 --- a/demo/Makefile.am	Fri Jul 01 10:33:27 2005 +0000
     1.2 +++ b/demo/Makefile.am	Fri Jul 01 16:10:46 2005 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  noinst_PROGRAMS = \
     1.5  	dim_to_dot \
     1.6  	dijkstra_demo \
     1.7 +	reader_writer_demo \
     1.8  	dim_to_lgf \
     1.9  	graph_to_eps_demo \
    1.10  	min_route \
    1.11 @@ -26,6 +27,8 @@
    1.12  
    1.13  dijkstra_demo_SOURCES = dijkstra_demo.cc
    1.14  
    1.15 +reader_writer_demo_SOURCES = reader_writer_demo.cc
    1.16 +
    1.17  dim_to_lgf_SOURCES = dim_to_lgf.cc
    1.18  
    1.19  coloring_SOURCES = coloring.cc
     2.1 --- a/demo/dijkstra_demo.cc	Fri Jul 01 10:33:27 2005 +0000
     2.2 +++ b/demo/dijkstra_demo.cc	Fri Jul 01 16:10:46 2005 +0000
     2.3 @@ -48,11 +48,6 @@
     2.4  
     2.5      std::cout << "Dijkstra algorithm test..." << std::endl;
     2.6  
     2.7 -//     GraphWriter<ListGraph> writer(std::cout, g);
     2.8 -//     writer.writeEdgeMap("capacity", len);
     2.9 -//     writer.writeNode("source", s);
    2.10 -//     writer.writeNode("target", t);
    2.11 -//     writer.run();
    2.12  
    2.13      Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
    2.14      
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/demo/reader_writer_demo.cc	Fri Jul 01 16:10:46 2005 +0000
     3.3 @@ -0,0 +1,83 @@
     3.4 +#include <iostream>
     3.5 +#include <lemon/smart_graph.h>
     3.6 +#include <lemon/invalid.h>
     3.7 +#include <lemon/graph_reader.h>
     3.8 +#include <lemon/graph_writer.h>
     3.9 +
    3.10 +
    3.11 +using namespace lemon;
    3.12 +
    3.13 +int main() {
    3.14 +  SmartGraph graph;
    3.15 +
    3.16 +  try {
    3.17 +    std::string filename="sample.lgf";
    3.18 +    GraphReader<SmartGraph> reader(filename,graph);
    3.19 +    SmartGraph::EdgeMap<int> cap(graph);
    3.20 +    reader.readEdgeMap("capacity",cap);
    3.21 +//     reader.readNode("source",s).readNode("target",t)
    3.22 +//       .readEdgeMap("capacity",cap).run();
    3.23 +    reader.run();
    3.24 +
    3.25 +    std::cout << "Hello! We have read a graph from file " << filename<< 
    3.26 +      " and some maps on it: now we write this to the standard output!" << 
    3.27 +      std::endl;
    3.28 +
    3.29 +
    3.30 +    GraphWriter<SmartGraph> writer(std::cout, graph);
    3.31 +    writer.writeEdgeMap("multiplicity", cap);
    3.32 +//     writer.writeNode("source", s);
    3.33 +//     writer.writeNode("target", t);
    3.34 +    writer.run();
    3.35 +     
    3.36 +//     LemonReader reader(std::cin);
    3.37 +
    3.38 +//     NodeSetReader<SmartGraph> nodeset(reader, graph);
    3.39 +//     SmartGraph::NodeMap<int> cost(graph);
    3.40 +//     nodeset.readMap("cost", cost);
    3.41 +//     SmartGraph::NodeMap<char> mmap(graph);
    3.42 +//     nodeset.readMap("mmap", mmap);
    3.43 +
    3.44 +//     EdgeSetReader<SmartGraph> edgeset(reader, graph, nodeset);
    3.45 +//     SmartGraph::EdgeMap<std::string> description(graph);
    3.46 +//     edgeset.readMap<QuotedStringReader>("description", description);
    3.47 +
    3.48 +//     NodeReader<SmartGraph> nodes(reader, nodeset);
    3.49 +//     SmartGraph::Node source;
    3.50 +//     nodes.readNode("source", source);
    3.51 +//     SmartGraph::Node target;
    3.52 +//     nodes.readNode("target", target);
    3.53 +
    3.54 +//     AttributeReader<> attribute(reader, "gui");
    3.55 +//     std::string author;
    3.56 +//     attribute.readAttribute<LineReader>("author", author);
    3.57 +//     int count;
    3.58 +//     attribute.readAttribute("count", count);
    3.59 +
    3.60 +//     PrintReader print(reader);
    3.61 +
    3.62 +//     reader.run();
    3.63 +
    3.64 +
    3.65 +//     for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    3.66 +//       std::cout << cost[it] << ' ' << mmap[it] << std::endl;
    3.67 +//     }
    3.68 +
    3.69 +//     for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    3.70 +//       std::cout << description[it] << std::endl;
    3.71 +//     }
    3.72 +
    3.73 +//     std::cout << "author: " << author << std::endl;
    3.74 +//     std::cout << "count: " << count << std::endl;
    3.75 +
    3.76 +//     std::cout << "source cost: " << cost[source] << std::endl;
    3.77 +//     std::cout << "target cost: " << cost[target] << std::endl;
    3.78 +
    3.79 +//     std::cout.flush();
    3.80 +  } catch (DataFormatError& error) {
    3.81 +    std::cerr << error.what() << std::endl;
    3.82 +  }
    3.83 +
    3.84 +
    3.85 +  return 0;
    3.86 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/demo/sample.lgf	Fri Jul 01 16:10:46 2005 +0000
     4.3 @@ -0,0 +1,23 @@
     4.4 +@nodeset 
     4.5 +id	
     4.6 +5	
     4.7 +4	
     4.8 +3	
     4.9 +2	
    4.10 +1	
    4.11 +0	
    4.12 +@edgeset 
    4.13 +		id	capacity	
    4.14 +4	5	6	8	
    4.15 +3	5	5	8	
    4.16 +2	4	4	5	
    4.17 +1	4	3	8	
    4.18 +1	3	2	5	
    4.19 +0	2	1	10	
    4.20 +0	1	0	10	
    4.21 +@nodes 
    4.22 +source 0
    4.23 +target 5
    4.24 +@edges 
    4.25 +@attributes 
    4.26 +@end
     5.1 --- a/doc/getstart.dox	Fri Jul 01 10:33:27 2005 +0000
     5.2 +++ b/doc/getstart.dox	Fri Jul 01 16:10:46 2005 +0000
     5.3 @@ -27,7 +27,7 @@
     5.4  \section downloadLEMON How to download LEMON
     5.5  
     5.6  You can download LEMON from the LEMON web site:
     5.7 -http://lemon.cs.elte.hu/dowload.html.
     5.8 +http://lemon.cs.elte.hu/download.html.
     5.9  There you will find released versions in form of <tt>.tar.gz</tt> files.
    5.10  If you want a developer version (for example you want to contribute in
    5.11  developing the library LEMON) then you might want to use our Subversion
    5.12 @@ -38,7 +38,7 @@
    5.13  
    5.14  \section installLEMON How to install LEMON
    5.15  
    5.16 -In order to install LEMON you have to do the following
    5.17 +In order to install LEMON you have to do the following steps.
    5.18  
    5.19  Download the tarball (named <tt>lemon-x.y.z.tar.gz</tt> where \c x,\c y
    5.20  and \c z are numbers indicating the version of the library: in our example
    5.21 @@ -50,15 +50,20 @@
    5.22  cd lemon-0.3.1
    5.23  ./configure
    5.24  make
    5.25 -make check   #(This is optional, but recomended. It runs a bunch of tests.)
    5.26 +make check   #(This is optional, but recommended. It runs a bunch of tests.)
    5.27  make install
    5.28  \endverbatim
    5.29  
    5.30  These commands install LEMON under \c /usr/local (you will
    5.31  need root privileges to be able to install to that
    5.32  directory). If you want to install it to some other place, then
    5.33 -pass the \c --prefix=DIR flag to \c ./configure. In what follows
    5.34 -we will assume that you were able to install to directory
    5.35 +pass the \c --prefix=DIRECTORY flag to \c ./configure, for example:
    5.36 +
    5.37 +\verbatim
    5.38 +./configure --prefix=/home/user1/lemon
    5.39 +\endverbatim
    5.40 +
    5.41 +In what follows we will assume that you were able to install to directory
    5.42  \c /usr/local, otherwise some extra care is to be taken to use the
    5.43  library.
    5.44  
     6.1 --- a/doc/quicktour.dox	Fri Jul 01 10:33:27 2005 +0000
     6.2 +++ b/doc/quicktour.dox	Fri Jul 01 16:10:46 2005 +0000
     6.3 @@ -22,7 +22,10 @@
     6.4  example a length or capacity function defined on the edges. You can do this in
     6.5  LEMON using so called \b maps. You can define a map on the nodes or on the edges of the graph and the value of the map (the range of the function) can be practically almost of any type. Read more about maps \ref maps-page "here".
     6.6  
     6.7 -Some examples are the following (you will find links next to the code fragments that help to download full demo programs: save them on your computer and compile them according to the description in the page about \ref getsart How to start using LEMON):
     6.8 +In this quick tour we want to show you some facilities LEMON library can provide through examples (simple demo programs). The examples will only show part of the functionality, but links will always be given to reach complete details. 
     6.9 +You will find links next to the code fragments that help to download full demo programs: save them on your computer and compile them according to the description in the page about \ref getstart "How to start using LEMON". 
    6.10 +
    6.11 +Have fun!
    6.12  
    6.13  <ul> <li> The first thing to discuss is the way one can create data structures
    6.14  like graphs and maps in a program using LEMON. 
    6.15 @@ -79,56 +82,18 @@
    6.16  (called \c coordinates_x and \c coordinates_y), several edges, an edge map
    6.17  called \c length and two designated nodes (called \c source and \c target).
    6.18  
    6.19 -\todo Maybe another example would be better here.
    6.20 +\todo Maybe a shorter example would be better here.
    6.21  
    6.22 -\code
    6.23 -@nodeset
    6.24 -id	coordinates_x	coordinates_y	
    6.25 -9	447.907	578.328	
    6.26 -8	79.2573	909.464	
    6.27 -7	878.677	960.04	
    6.28 -6	11.5504	938.413	
    6.29 -5	327.398	815.035	
    6.30 -4	427.002	954.002	
    6.31 -3	148.549	753.748	
    6.32 -2	903.889	326.476	
    6.33 -1	408.248	577.327	
    6.34 -0	189.239	92.5316	
    6.35 -@edgeset
    6.36 -		length	
    6.37 -2	3	901.074	
    6.38 -8	5	270.85	
    6.39 -6	9	601.553	
    6.40 -5	9	285.022	
    6.41 -9	4	408.091	
    6.42 -3	0	719.712	
    6.43 -7	5	612.836	
    6.44 -0	4	933.353	
    6.45 -5	0	778.871	
    6.46 -5	5	0	
    6.47 -7	1	664.049	
    6.48 -5	5	0	
    6.49 -0	9	560.464	
    6.50 -4	8	352.36	
    6.51 -4	9	399.625	
    6.52 -4	1	402.171	
    6.53 -1	2	591.688	
    6.54 -3	8	182.376	
    6.55 -4	5	180.254	
    6.56 -3	1	345.283	
    6.57 -5	4	184.511	
    6.58 -6	2	1112.45	
    6.59 -0	1	556.624	
    6.60 -@nodes
    6.61 -source	1	
    6.62 -target	8	
    6.63 -@end
    6.64 -\endcode
    6.65 +\include route.lgf
    6.66  
    6.67  Finally let us give a simple example that reads a graph from a file and writes
    6.68 -it to another.
    6.69 +it to the standard output.
    6.70  
    6.71 -\todo This is to be done!
    6.72 +\include reader_writer_demo.cc
    6.73 +
    6.74 +See the whole program in file \ref reader_writer_demo.cc.
    6.75 +
    6.76 +\todo This is still under construction!
    6.77  
    6.78  </ol>
    6.79  <li> If you want to solve some transportation problems in a network then 
    6.80 @@ -139,62 +104,9 @@
    6.81  \ref lemon::Dijkstra "LEMON Dijkstra class" and it also shows how to define a map on the edges (the length
    6.82  function):
    6.83  
    6.84 -\code
    6.85 -
    6.86 -    typedef ListGraph Graph;
    6.87 -    typedef Graph::Node Node;
    6.88 -    typedef Graph::Edge Edge;
    6.89 -    typedef Graph::EdgeMap<int> LengthMap;
    6.90 -
    6.91 -    Graph g;
    6.92 -
    6.93 -    //An example from Ahuja's book
    6.94 -
    6.95 -    Node s=g.addNode();
    6.96 -    Node v2=g.addNode();
    6.97 -    Node v3=g.addNode();
    6.98 -    Node v4=g.addNode();
    6.99 -    Node v5=g.addNode();
   6.100 -    Node t=g.addNode();
   6.101 -
   6.102 -    Edge s_v2=g.addEdge(s, v2);
   6.103 -    Edge s_v3=g.addEdge(s, v3);
   6.104 -    Edge v2_v4=g.addEdge(v2, v4);
   6.105 -    Edge v2_v5=g.addEdge(v2, v5);
   6.106 -    Edge v3_v5=g.addEdge(v3, v5);
   6.107 -    Edge v4_t=g.addEdge(v4, t);
   6.108 -    Edge v5_t=g.addEdge(v5, t);
   6.109 -  
   6.110 -    LengthMap len(g);
   6.111 -
   6.112 -    len.set(s_v2, 10);
   6.113 -    len.set(s_v3, 10);
   6.114 -    len.set(v2_v4, 5);
   6.115 -    len.set(v2_v5, 8);
   6.116 -    len.set(v3_v5, 5);
   6.117 -    len.set(v4_t, 8);
   6.118 -    len.set(v5_t, 8);
   6.119 -
   6.120 -    std::cout << "The id of s is " << g.id(s)<< std::endl;
   6.121 -    std::cout <<"The id of t is " << g.id(t)<<"."<<std::endl;
   6.122 -
   6.123 -    std::cout << "Dijkstra algorithm test..." << std::endl;
   6.124 -
   6.125 -    Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
   6.126 -    
   6.127 -    dijkstra_test.run(s);
   6.128 -
   6.129 -    
   6.130 -    std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)<<std::endl;
   6.131 -
   6.132 -    std::cout << "The shortest path from s to t goes through the following nodes" <<std::endl;
   6.133 - std::cout << " (the first one is t, the last one is s): "<<std::endl;
   6.134 -
   6.135 -    for (Node v=t;v != s; v=dijkstra_test.predNode(v)){
   6.136 -	std::cout << g.id(v) << "<-";
   6.137 -    }
   6.138 -    std::cout << g.id(s) << std::endl;	
   6.139 -\endcode
   6.140 +\dontinclude dijkstra_demo.cc
   6.141 +\skip ListGraph
   6.142 +\until std::cout << g.id(s)
   6.143  
   6.144  See the whole program in \ref dijkstra_demo.cc.
   6.145  
   6.146 @@ -209,7 +121,7 @@
   6.147  <li> If you want to design a network and want to minimize the total length
   6.148  of wires then you might be looking for a <b>minimum spanning tree</b> in
   6.149  an undirected graph. This can be found using the Kruskal algorithm: the 
   6.150 -class \ref lemon::Kruskal "LEMON Kruskal class" does this job for you.
   6.151 +function \ref lemon::kruskal "LEMON Kruskal ..." does this job for you.
   6.152  The following code fragment shows an example:
   6.153  
   6.154  Ide Zsuzska fog irni!
   6.155 @@ -336,9 +248,9 @@
   6.156  
   6.157  The complete program can be found in file \ref lp_maxflow_demo.cc. After compiling run it in the form:
   6.158  
   6.159 -<tt>./lp_maxflow_demo < ?????????.lgf</tt>
   6.160 +<tt>./lp_maxflow_demo < sample.lgf</tt>
   6.161  
   6.162 -where ?????????.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges).
   6.163 +where sample.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges).
   6.164  
   6.165  
   6.166