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

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


Author: athos
Date: Wed Mar  2 10:51:11 2005
New Revision: 1589

Added:
   hugo/trunk/src/demo/helloworld.cc
Modified:
   hugo/trunk/doc/quicktour.dox

Log:
Some work has been done in the quicktour.

Modified: hugo/trunk/doc/quicktour.dox
==============================================================================
--- hugo/trunk/doc/quicktour.dox	(original)
+++ hugo/trunk/doc/quicktour.dox	Wed Mar  2 10:51:11 2005
@@ -16,17 +16,13 @@
 
 
 
-Some examples are the following:
+Some examples are the following (you will find links next to the code fragments that help to download full demo programs):
 
 - First we give two examples that show how to instantiate a graph. The
 first one shows the methods that add nodes and edges, but one will
 usually use the second way which reads a graph from a stream (file).
-
-
--# The following code fragment shows how to fill a graph with data.
-
+-# 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 supppose them later as well.
  \code
-
   typedef ListGraph Graph;
   typedef Graph::Edge Edge;
   typedef Graph::InEdgeIt InEdgeIt;
@@ -43,20 +39,36 @@
   for (NodeIt i(g); i!=INVALID; ++i)
     for (NodeIt j(g); j!=INVALID; ++j)
       if (i != j) g.addEdge(i, j);
-
  \endcode 
 
- -#
+If you want to read more on the LEMON graph structures and concepts, read the page about \ref graphs "graphs". 
+
+-# The following code shows how to read a graph from a stream (e.g. a file). LEMON supports the DIMACS file format: it can read a graph instance from a file 
+in that format (find the documentation of the format on the web). 
+\code
+Graph g;
+std::ifstream f("graph.dim");
+readDimacs(f, g);
+\endcode
+One can also store network (graph+capacity on the edges) instances and other things in DIMACS format: to see the details read the documentation of the \ref dimacs.h "Dimacs file format reader".
+
 
 - 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".
 A simple program using the \ref lemon::Dijkstra "LEMON Dijkstra class" is
-as follows (we assume that the graph is already given in the memory):
+as follows (we do not include the part that instantiates the graph and the length function):
 
 \code
-
+  typedef Graph::EdgeMap<int> LengthMap;
+  Graph G;
+  Node s, t;
+  LengthMap cap(G);
+	...
+  Dijkstra<Graph, LengthMap> 
+	dijkstra_test(G, cap);
+  dijkstra_test.run(s);
 \endcode
 
 - If you want to design a network and want to minimize the total length

Added: hugo/trunk/src/demo/helloworld.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/demo/helloworld.cc	Wed Mar  2 10:51:11 2005
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <lemon/list_graph.h>
+
+using namespace lemon;
+
+int main()
+{
+  typedef ListGraph Graph;
+  typedef Graph::Edge Edge;
+  typedef Graph::InEdgeIt InEdgeIt;
+  typedef Graph::OutEdgeIt OutEdgeIt;
+  typedef Graph::EdgeIt EdgeIt;
+  typedef Graph::Node Node;
+  typedef Graph::NodeIt NodeIt;
+
+  Graph g;
+  
+  for (int i = 0; i < 3; i++)
+    g.addNode();
+  
+  for (NodeIt i(g); i!=INVALID; ++i)
+    for (NodeIt j(g); j!=INVALID; ++j)
+      if (i != j) g.addEdge(i, j);
+
+  std::cout << "Nodes:";
+  for (NodeIt i(g); i!=INVALID; ++i)
+    std::cout << " " << g.id(i);
+  std::cout << std::endl;
+
+  std::cout << "Edges:";
+  for (EdgeIt i(g); i!=INVALID; ++i)
+    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
+  std::cout << std::endl;
+}



More information about the Lemon-commits mailing list