[Lemon-commits] [lemon_svn] athos: r2016 - in hugo/trunk: demo doc

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:49:32 CET 2006


Author: athos
Date: Fri Jul  1 18:10:46 2005
New Revision: 2016

Added:
   hugo/trunk/demo/reader_writer_demo.cc
   hugo/trunk/demo/sample.lgf
Modified:
   hugo/trunk/demo/Makefile.am
   hugo/trunk/demo/dijkstra_demo.cc
   hugo/trunk/doc/getstart.dox
   hugo/trunk/doc/quicktour.dox

Log:
Graph input-output demo, some documentation.

Modified: hugo/trunk/demo/Makefile.am
==============================================================================
--- hugo/trunk/demo/Makefile.am	(original)
+++ hugo/trunk/demo/Makefile.am	Fri Jul  1 18:10:46 2005
@@ -6,6 +6,7 @@
 noinst_PROGRAMS = \
 	dim_to_dot \
 	dijkstra_demo \
+	reader_writer_demo \
 	dim_to_lgf \
 	graph_to_eps_demo \
 	min_route \
@@ -26,6 +27,8 @@
 
 dijkstra_demo_SOURCES = dijkstra_demo.cc
 
+reader_writer_demo_SOURCES = reader_writer_demo.cc
+
 dim_to_lgf_SOURCES = dim_to_lgf.cc
 
 coloring_SOURCES = coloring.cc

Modified: hugo/trunk/demo/dijkstra_demo.cc
==============================================================================
--- hugo/trunk/demo/dijkstra_demo.cc	(original)
+++ hugo/trunk/demo/dijkstra_demo.cc	Fri Jul  1 18:10:46 2005
@@ -48,11 +48,6 @@
 
     std::cout << "Dijkstra algorithm test..." << std::endl;
 
-//     GraphWriter<ListGraph> writer(std::cout, g);
-//     writer.writeEdgeMap("capacity", len);
-//     writer.writeNode("source", s);
-//     writer.writeNode("target", t);
-//     writer.run();
 
     Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
     

Added: hugo/trunk/demo/reader_writer_demo.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/demo/reader_writer_demo.cc	Fri Jul  1 18:10:46 2005
@@ -0,0 +1,83 @@
+#include <iostream>
+#include <lemon/smart_graph.h>
+#include <lemon/invalid.h>
+#include <lemon/graph_reader.h>
+#include <lemon/graph_writer.h>
+
+
+using namespace lemon;
+
+int main() {
+  SmartGraph graph;
+
+  try {
+    std::string filename="sample.lgf";
+    GraphReader<SmartGraph> reader(filename,graph);
+    SmartGraph::EdgeMap<int> cap(graph);
+    reader.readEdgeMap("capacity",cap);
+//     reader.readNode("source",s).readNode("target",t)
+//       .readEdgeMap("capacity",cap).run();
+    reader.run();
+
+    std::cout << "Hello! We have read a graph from file " << filename<< 
+      " and some maps on it: now we write this to the standard output!" << 
+      std::endl;
+
+
+    GraphWriter<SmartGraph> writer(std::cout, graph);
+    writer.writeEdgeMap("multiplicity", cap);
+//     writer.writeNode("source", s);
+//     writer.writeNode("target", t);
+    writer.run();
+     
+//     LemonReader reader(std::cin);
+
+//     NodeSetReader<SmartGraph> nodeset(reader, graph);
+//     SmartGraph::NodeMap<int> cost(graph);
+//     nodeset.readMap("cost", cost);
+//     SmartGraph::NodeMap<char> mmap(graph);
+//     nodeset.readMap("mmap", mmap);
+
+//     EdgeSetReader<SmartGraph> edgeset(reader, graph, nodeset);
+//     SmartGraph::EdgeMap<std::string> description(graph);
+//     edgeset.readMap<QuotedStringReader>("description", description);
+
+//     NodeReader<SmartGraph> nodes(reader, nodeset);
+//     SmartGraph::Node source;
+//     nodes.readNode("source", source);
+//     SmartGraph::Node target;
+//     nodes.readNode("target", target);
+
+//     AttributeReader<> attribute(reader, "gui");
+//     std::string author;
+//     attribute.readAttribute<LineReader>("author", author);
+//     int count;
+//     attribute.readAttribute("count", count);
+
+//     PrintReader print(reader);
+
+//     reader.run();
+
+
+//     for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
+//       std::cout << cost[it] << ' ' << mmap[it] << std::endl;
+//     }
+
+//     for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
+//       std::cout << description[it] << std::endl;
+//     }
+
+//     std::cout << "author: " << author << std::endl;
+//     std::cout << "count: " << count << std::endl;
+
+//     std::cout << "source cost: " << cost[source] << std::endl;
+//     std::cout << "target cost: " << cost[target] << std::endl;
+
+//     std::cout.flush();
+  } catch (DataFormatError& error) {
+    std::cerr << error.what() << std::endl;
+  }
+
+
+  return 0;
+}

Added: hugo/trunk/demo/sample.lgf
==============================================================================
--- (empty file)
+++ hugo/trunk/demo/sample.lgf	Fri Jul  1 18:10:46 2005
@@ -0,0 +1,23 @@
+ at nodeset 
+id	
+5	
+4	
+3	
+2	
+1	
+0	
+ at edgeset 
+		id	capacity	
+4	5	6	8	
+3	5	5	8	
+2	4	4	5	
+1	4	3	8	
+1	3	2	5	
+0	2	1	10	
+0	1	0	10	
+ at nodes 
+source 0
+target 5
+ at edges 
+ at attributes 
+ at end

Modified: hugo/trunk/doc/getstart.dox
==============================================================================
--- hugo/trunk/doc/getstart.dox	(original)
+++ hugo/trunk/doc/getstart.dox	Fri Jul  1 18:10:46 2005
@@ -27,7 +27,7 @@
 \section downloadLEMON How to download LEMON
 
 You can download LEMON from the LEMON web site:
-http://lemon.cs.elte.hu/dowload.html.
+http://lemon.cs.elte.hu/download.html.
 There you will find released versions in form of <tt>.tar.gz</tt> files.
 If you want a developer version (for example you want to contribute in
 developing the library LEMON) then you might want to use our Subversion
@@ -38,7 +38,7 @@
 
 \section installLEMON How to install LEMON
 
-In order to install LEMON you have to do the following
+In order to install LEMON you have to do the following steps.
 
 Download the tarball (named <tt>lemon-x.y.z.tar.gz</tt> where \c x,\c y
 and \c z are numbers indicating the version of the library: in our example
@@ -50,15 +50,20 @@
 cd lemon-0.3.1
 ./configure
 make
-make check   #(This is optional, but recomended. It runs a bunch of tests.)
+make check   #(This is optional, but recommended. It runs a bunch of tests.)
 make install
 \endverbatim
 
 These commands install LEMON under \c /usr/local (you will
 need root privileges to be able to install to that
 directory). If you want to install it to some other place, then
-pass the \c --prefix=DIR flag to \c ./configure. In what follows
-we will assume that you were able to install to directory
+pass the \c --prefix=DIRECTORY flag to \c ./configure, for example:
+
+\verbatim
+./configure --prefix=/home/user1/lemon
+\endverbatim
+
+In what follows we will assume that you were able to install to directory
 \c /usr/local, otherwise some extra care is to be taken to use the
 library.
 

Modified: hugo/trunk/doc/quicktour.dox
==============================================================================
--- hugo/trunk/doc/quicktour.dox	(original)
+++ hugo/trunk/doc/quicktour.dox	Fri Jul  1 18:10:46 2005
@@ -22,7 +22,10 @@
 example a length or capacity function defined on the edges. You can do this in
 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".
 
-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):
+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. 
+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". 
+
+Have fun!
 
 <ul> <li> The first thing to discuss is the way one can create data structures
 like graphs and maps in a program using LEMON. 
@@ -79,56 +82,18 @@
 (called \c coordinates_x and \c coordinates_y), several edges, an edge map
 called \c length and two designated nodes (called \c source and \c target).
 
-\todo Maybe another example would be better here.
+\todo Maybe a shorter example would be better here.
 
-\code
- at nodeset
-id	coordinates_x	coordinates_y	
-9	447.907	578.328	
-8	79.2573	909.464	
-7	878.677	960.04	
-6	11.5504	938.413	
-5	327.398	815.035	
-4	427.002	954.002	
-3	148.549	753.748	
-2	903.889	326.476	
-1	408.248	577.327	
-0	189.239	92.5316	
- at edgeset
-		length	
-2	3	901.074	
-8	5	270.85	
-6	9	601.553	
-5	9	285.022	
-9	4	408.091	
-3	0	719.712	
-7	5	612.836	
-0	4	933.353	
-5	0	778.871	
-5	5	0	
-7	1	664.049	
-5	5	0	
-0	9	560.464	
-4	8	352.36	
-4	9	399.625	
-4	1	402.171	
-1	2	591.688	
-3	8	182.376	
-4	5	180.254	
-3	1	345.283	
-5	4	184.511	
-6	2	1112.45	
-0	1	556.624	
- at nodes
-source	1	
-target	8	
- at end
-\endcode
+\include route.lgf
 
 Finally let us give a simple example that reads a graph from a file and writes
-it to another.
+it to the standard output.
 
-\todo This is to be done!
+\include reader_writer_demo.cc
+
+See the whole program in file \ref reader_writer_demo.cc.
+
+\todo This is still under construction!
 
 </ol>
 <li> If you want to solve some transportation problems in a network then 
@@ -139,62 +104,9 @@
 \ref lemon::Dijkstra "LEMON Dijkstra class" and it also shows how to define a map on the edges (the length
 function):
 
-\code
-
-    typedef ListGraph Graph;
-    typedef Graph::Node Node;
-    typedef Graph::Edge Edge;
-    typedef Graph::EdgeMap<int> LengthMap;
-
-    Graph g;
-
-    //An example from Ahuja's book
-
-    Node s=g.addNode();
-    Node v2=g.addNode();
-    Node v3=g.addNode();
-    Node v4=g.addNode();
-    Node v5=g.addNode();
-    Node t=g.addNode();
-
-    Edge s_v2=g.addEdge(s, v2);
-    Edge s_v3=g.addEdge(s, v3);
-    Edge v2_v4=g.addEdge(v2, v4);
-    Edge v2_v5=g.addEdge(v2, v5);
-    Edge v3_v5=g.addEdge(v3, v5);
-    Edge v4_t=g.addEdge(v4, t);
-    Edge v5_t=g.addEdge(v5, t);
-  
-    LengthMap len(g);
-
-    len.set(s_v2, 10);
-    len.set(s_v3, 10);
-    len.set(v2_v4, 5);
-    len.set(v2_v5, 8);
-    len.set(v3_v5, 5);
-    len.set(v4_t, 8);
-    len.set(v5_t, 8);
-
-    std::cout << "The id of s is " << g.id(s)<< std::endl;
-    std::cout <<"The id of t is " << g.id(t)<<"."<<std::endl;
-
-    std::cout << "Dijkstra algorithm test..." << std::endl;
-
-    Dijkstra<Graph, LengthMap> dijkstra_test(g,len);
-    
-    dijkstra_test.run(s);
-
-    
-    std::cout << "The distance of node t from node s: " << dijkstra_test.dist(t)<<std::endl;
-
-    std::cout << "The shortest path from s to t goes through the following nodes" <<std::endl;
- std::cout << " (the first one is t, the last one is s): "<<std::endl;
-
-    for (Node v=t;v != s; v=dijkstra_test.predNode(v)){
-	std::cout << g.id(v) << "<-";
-    }
-    std::cout << g.id(s) << std::endl;	
-\endcode
+\dontinclude dijkstra_demo.cc
+\skip ListGraph
+\until std::cout << g.id(s)
 
 See the whole program in \ref dijkstra_demo.cc.
 
@@ -209,7 +121,7 @@
 <li> If you want to design a network and want to minimize the total length
 of wires then you might be looking for a <b>minimum spanning tree</b> in
 an undirected graph. This can be found using the Kruskal algorithm: the 
-class \ref lemon::Kruskal "LEMON Kruskal class" does this job for you.
+function \ref lemon::kruskal "LEMON Kruskal ..." does this job for you.
 The following code fragment shows an example:
 
 Ide Zsuzska fog irni!
@@ -336,9 +248,9 @@
 
 The complete program can be found in file \ref lp_maxflow_demo.cc. After compiling run it in the form:
 
-<tt>./lp_maxflow_demo < ?????????.lgf</tt>
+<tt>./lp_maxflow_demo < sample.lgf</tt>
 
-where ?????????.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges).
+where sample.lgf is a file in the lemon format containing a maxflow instance (designated "source", "target" nodes and "capacity" map on the edges).
 
 
 



More information about the Lemon-commits mailing list