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

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


Author: athos
Date: Mon Jul  4 15:08:31 2005
New Revision: 2021

Modified:
   hugo/trunk/demo/dijkstra_demo.cc
   hugo/trunk/demo/hello_lemon.cc
   hugo/trunk/demo/lp_demo.cc
   hugo/trunk/demo/reader_writer_demo.cc
   hugo/trunk/demo/route.lgf
   hugo/trunk/demo/sample.lgf
   hugo/trunk/doc/quicktour.dox

Log:
Doc.

Modified: hugo/trunk/demo/dijkstra_demo.cc
==============================================================================
--- hugo/trunk/demo/dijkstra_demo.cc	(original)
+++ hugo/trunk/demo/dijkstra_demo.cc	Mon Jul  4 15:08:31 2005
@@ -44,6 +44,11 @@
     len.set(v4_t, 8);
     len.set(v5_t, 8);
 
+    std::cout << "This program is a simple demo of the LEMON Dijkstra class."<<std::endl;
+    std::cout << "We calculate the shortest path from node s to node t in a graph."<<std::endl;
+    std::cout <<std::endl;
+
+
     std::cout << "The id of s is " << g.id(s)<< ", the id of t is " << g.id(t)<<"."<<std::endl;
 
     std::cout << "Dijkstra algorithm test..." << std::endl;

Modified: hugo/trunk/demo/hello_lemon.cc
==============================================================================
--- hugo/trunk/demo/hello_lemon.cc	(original)
+++ hugo/trunk/demo/hello_lemon.cc	Mon Jul  4 15:08:31 2005
@@ -5,17 +5,38 @@
 {
   typedef lemon::ListGraph Graph;
   typedef Graph::EdgeIt EdgeIt;
+  typedef Graph::Edge Edge;
   typedef Graph::NodeIt NodeIt;
+  typedef Graph::Node Node;
+  typedef Graph::EdgeMap<int> LengthMap;
   using lemon::INVALID;
 
   Graph g;
   
-  for (int i = 0; i < 3; i++)
-    g.addNode();
+  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);
   
-  for (NodeIt i(g); i!=INVALID; ++i)
-    for (NodeIt j(g); j!=INVALID; ++j)
-      if (i != j) g.addEdge(i, j);
+  LengthMap length(g);
+
+  length.set(s_v2, 10);
+  length.set(s_v3, 10);
+  length.set(v2_v4, 5);
+  length.set(v2_v5, 8);
+  length.set(v3_v5, 5);
+  length.set(v4_t, 8);
+  length.set(v5_t, 8);
 
   std::cout << "Hello World!" << std::endl;
   std::cout <<  std::endl;
@@ -31,4 +52,13 @@
   for (EdgeIt i(g); i!=INVALID; ++i)
     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
   std::cout << std::endl;
+  std::cout <<  std::endl;
+
+  std::cout << "There is a map on the edges (length)!" << std::endl;
+  std::cout <<  std::endl;
+  for (EdgeIt i(g); i!=INVALID; ++i)
+    std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
+
+  std::cout << std::endl;
+
 }

Modified: hugo/trunk/demo/lp_demo.cc
==============================================================================
--- hugo/trunk/demo/lp_demo.cc	(original)
+++ hugo/trunk/demo/lp_demo.cc	Mon Jul  4 15:08:31 2005
@@ -23,6 +23,8 @@
 {     
  //The following example is taken from the documentation of the GLPK library.
  //See it in the GLPK reference manual and among the GLPK sample files (sample.c)
+
+  //A default solver is taken
   LpDefault lp;
   typedef LpDefault::Row Row;
   typedef LpDefault::Col Col;
@@ -36,15 +38,6 @@
   Col x2 = lp.addCol();
   Col x3 = lp.addCol();
 
-  //One solution
-  //   Row p = lp.addRow();
-  //   Row q = lp.addRow();
-  //   Row r = lp.addRow();
-  //   lp.setRow(p,x1+x2+x3 <=100);  
-  //   lp.setRow(q,10*x1+4*x2+5*x3<=600);  
-  //   lp.setRow(r,2*x1+2*x2+6*x3<=300);  
-
-  //A more elegant one
   //Constraints
   lp.addRow(x1+x2+x3 <=100);  
   lp.addRow(10*x1+4*x2+5*x3<=600);  
@@ -69,6 +62,7 @@
     std::cout<<"Optimal solution not found!"<<std::endl;
   }
 
+  //End of LEMON style code
 
   //Here comes the same problem written in C using GLPK API routines
 

Modified: hugo/trunk/demo/reader_writer_demo.cc
==============================================================================
--- hugo/trunk/demo/reader_writer_demo.cc	(original)
+++ hugo/trunk/demo/reader_writer_demo.cc	Mon Jul  4 15:08:31 2005
@@ -15,8 +15,6 @@
     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<< 
@@ -30,50 +28,6 @@
 //     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;
   }

Modified: hugo/trunk/demo/route.lgf
==============================================================================
--- hugo/trunk/demo/route.lgf	(original)
+++ hugo/trunk/demo/route.lgf	Mon Jul  4 15:08:31 2005
@@ -11,31 +11,33 @@
 1	408.248	577.327	
 0	189.239	92.5316	
 @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	
+		length	id	
+2	3	901.074	0	
+8	5	270.85	1	
+6	9	601.553	2	
+5	9	285.022	3	
+9	4	408.091	4	
+3	0	719.712	5	
+7	5	612.836	6	
+0	4	933.353	7	
+5	0	778.871	8	
+5	5	0	9	
+7	1	664.049	10	
+5	5	0	11	
+0	9	560.464	12	
+4	8	352.36	13	
+4	9	399.625	14	
+4	1	402.171	15	
+1	2	591.688	16	
+3	8	182.376	17	
+4	5	180.254	18	
+3	1	345.283	19	
+5	4	184.511	20	
+6	2	1112.45	21	
+0	1	556.624	22	
 @nodes
 source	1	
 target	8	
+ at edges 
+ at attributes 
 @end

Modified: hugo/trunk/demo/sample.lgf
==============================================================================
--- hugo/trunk/demo/sample.lgf	(original)
+++ hugo/trunk/demo/sample.lgf	Mon Jul  4 15:08:31 2005
@@ -1,21 +1,21 @@
- 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 
+ at nodeset
+id      coordinates_x   coordinates_y
+5       796.398 208.035
+4       573.002 63.002
+3       568.549 401.748
+2       277.889 68.476
+1       288.248 397.327
+0       102.239 257.532
+ 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
 @edges 

Modified: hugo/trunk/doc/quicktour.dox
==============================================================================
--- hugo/trunk/doc/quicktour.dox	(original)
+++ hugo/trunk/doc/quicktour.dox	Mon Jul  4 15:08:31 2005
@@ -42,21 +42,38 @@
 file format that gives a more flexible way to store data related to network
 optimization.
 
-<ol> <li>The following code fragment shows how to fill a graph with
-data. It creates a complete graph on 4 nodes. The type Listgraph is one of the
-LEMON graph types: the typedefs in the beginning are for convenience and we
-will suppose them later as well.  
+<ol> <li>The following code shows how to build a graph from scratch
+and iterate on its nodes and edges.  This example also shows how to
+give a map on the edges of the graph.  The type Listgraph is one of
+the LEMON graph types: the typedefs in the beginning are for
+convenience and we will assume them later as well.
 
-\dontinclude hello_lemon.cc
-\skip ListGraph
-\until addEdge
+\include hello_lemon.cc
 
-See the whole program in file \ref hello_lemon.cc in \c demo subdir of
+See the whole program in file \ref hello_lemon.cc in the \c demo subdir of
 LEMON package.
 
     If you want to read more on the LEMON graph structures and
 concepts, read the page about \ref graphs "graphs".
 
+
+<li>LEMON has an own file format for storing graphs, maps on edges/nodes and some other things. Instead of any explanation let us give a
+short example file in this format: read the detailed description of the LEMON
+graph file format and input-output routines here: \ref graph-io-page.
+
+So here is a file describing a graph of 6 nodes (0 to 5), two nodemaps
+(called \c coordinates_x and \c coordinates_y), several edges, an edge map
+called \c capacity and two designated nodes (called \c source and \c target).
+
+\include sample.lgf
+
+Finally let us give a simple example that reads a graph from a file and writes
+it to the standard output.
+
+\include reader_writer_demo.cc
+
+See the whole program in file \ref reader_writer_demo.cc.
+
 <li> The following code shows how to read a graph from a stream
 (e.g. a file) in the DIMACS file format (find the documentation of the
 DIMACS file formats on the web).
@@ -73,49 +90,30 @@
 \ref dimacs.h "Dimacs file format reader". There you will also find
 the details about the output routines into files of the DIMACS format.
 
-<li>DIMACS formats could not give us the flexibility we needed,
-so we worked out our own file format. Instead of any explanation let us give a
-short example file in this format: read the detailed description of the LEMON
-graph file format and input-output routines \ref graph-io-page here.
-
-So here is a file describing a graph of 10 nodes (0 to 9), two nodemaps
-(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 a shorter example would be better here.
-
-\include route.lgf
-
-Finally let us give a simple example that reads a graph from a file and writes
-it to the standard output.
-
-\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 
 you will want to find shortest paths between nodes of a graph. This is 
 usually solved using Dijkstra's algorithm. A utility
 that solves this is  the \ref lemon::Dijkstra "LEMON Dijkstra class".
 The following code is a simple program using the 
-\ref lemon::Dijkstra "LEMON Dijkstra class" and it also shows how to define a map on the edges (the length
-function):
+\ref lemon::Dijkstra "LEMON Dijkstra class": it calculates the shortest path between node \c s and \c t in a graph \c g.
+We omit the part reading the graph  \c g and the length map \c len.
 
 \dontinclude dijkstra_demo.cc
 \skip ListGraph
+\until Graph g
+...
+\skip Dijkstra algorithm
 \until std::cout << g.id(s)
 
 See the whole program in \ref dijkstra_demo.cc.
 
-The first part of the code is self-explanatory: we build the graph and set the
-length values of the edges. Then we instantiate a member of the Dijkstra class
-and run the Dijkstra algorithm from node \c s. After this we read some of the
-results. 
-You can do much more with the Dijkstra class, for example you can run it step
-by step and gain full control of the execution. For a detailed description, see the documentation of the \ref lemon::Dijkstra "LEMON Dijkstra class".
+Some explanation: after instantiating a member of the Dijkstra class
+we run the Dijkstra algorithm from node \c s. After this we read some
+of the results.  You can do much more with the Dijkstra class, for
+example you can run it step by step and gain full control of the
+execution. For a detailed description, see the documentation of the
+\ref lemon::Dijkstra "LEMON Dijkstra class".
 
 
 <li> If you want to design a network and want to minimize the total length
@@ -154,48 +152,9 @@
 <li>The following code shows how to solve an LP problem using the LEMON lp
 interface. The code together with the comments is self-explanatory.
 
-\code
-
-  //A default solver is taken
-  LpDefault lp;
-  typedef LpDefault::Row Row;
-  typedef LpDefault::Col Col;
-  
-
-  //This will be a maximization
-  lp.max();
-
-  //We add coloumns (variables) to our problem
-  Col x1 = lp.addCol();
-  Col x2 = lp.addCol();
-  Col x3 = lp.addCol();
-
-  //Constraints
-  lp.addRow(x1+x2+x3 <=100);  
-  lp.addRow(10*x1+4*x2+5*x3<=600);  
-  lp.addRow(2*x1+2*x2+6*x3<=300);  
-  //Nonnegativity of the variables
-  lp.colLowerBound(x1, 0);
-  lp.colLowerBound(x2, 0);
-  lp.colLowerBound(x3, 0);
-  //Objective function
-  lp.setObj(10*x1+6*x2+4*x3);
-  
-  //Call the routine of the underlying LP solver
-  lp.solve();
-
-  //Print results
-  if (lp.primalStatus()==LpSolverBase::OPTIMAL){
-    printf("Z = %g; x1 = %g; x2 = %g; x3 = %g\n", 
-	   lp.primalValue(), 
-	   lp.primal(x1), lp.primal(x2), lp.primal(x3));
-  }
-  else{
-    std::cout<<"Optimal solution not found!"<<std::endl;
-  }
-
-
-\endcode
+\dontinclude lp_demo.cc
+\skip A default solver is taken
+\until End of LEMON style code
 
 See the whole code in \ref lp_demo.cc.
 
@@ -210,41 +169,12 @@
 the capacity map \c cap, the source node \c s and the target node \c t
 in the memory. We will also omit the typedefs.
 
-\code
-  //Define a map on the edges for the variables of the LP problem
-  typename G::template EdgeMap<LpDefault::Col> x(g);
-  lp.addColSet(x);
-  
-  //Nonnegativity and capacity constraints
-  for(EdgeIt e(g);e!=INVALID;++e) {
-    lp.colUpperBound(x[e],cap[e]);
-    lp.colLowerBound(x[e],0);
-  }
-
-
-  //Flow conservation constraints for the nodes (except for 's' and 't')
-  for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
-    LpDefault::Expr ex;
-    for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
-    for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
-    lp.addRow(ex==0);
-  }
-  
-  //Objective function: the flow value entering 't'
-  {
-    LpDefault::Expr ex;
-    for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
-    for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
-    lp.setObj(ex);
-  }
-
-  //Maximization
-  lp.max();
+\dontinclude lp_maxflow_demo.cc
+\skip Define a map on the edges for the variables of the LP problem
+\until lp.max();
+\skip Solve with the underlying solver
+\until lp.solve();
 
-  //Solve with the underlying solver
-  lp.solve();
-
-\endcode
 
 The complete program can be found in file \ref lp_maxflow_demo.cc. After compiling run it in the form:
 



More information about the Lemon-commits mailing list