Some work has been done in the quicktour.
authorathos
Wed, 02 Mar 2005 09:51:11 +0000
changeset 1181848b6006941d
parent 1180 f772c360b466
child 1182 a1abe9452199
Some work has been done in the quicktour.
doc/quicktour.dox
src/demo/helloworld.cc
     1.1 --- a/doc/quicktour.dox	Mon Feb 28 13:03:36 2005 +0000
     1.2 +++ b/doc/quicktour.dox	Wed Mar 02 09:51:11 2005 +0000
     1.3 @@ -16,17 +16,13 @@
     1.4  
     1.5  
     1.6  
     1.7 -Some examples are the following:
     1.8 +Some examples are the following (you will find links next to the code fragments that help to download full demo programs):
     1.9  
    1.10  - First we give two examples that show how to instantiate a graph. The
    1.11  first one shows the methods that add nodes and edges, but one will
    1.12  usually use the second way which reads a graph from a stream (file).
    1.13 -
    1.14 -
    1.15 --# The following code fragment shows how to fill a graph with data.
    1.16 -
    1.17 +-# 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.
    1.18   \code
    1.19 -
    1.20    typedef ListGraph Graph;
    1.21    typedef Graph::Edge Edge;
    1.22    typedef Graph::InEdgeIt InEdgeIt;
    1.23 @@ -43,20 +39,36 @@
    1.24    for (NodeIt i(g); i!=INVALID; ++i)
    1.25      for (NodeIt j(g); j!=INVALID; ++j)
    1.26        if (i != j) g.addEdge(i, j);
    1.27 -
    1.28   \endcode 
    1.29  
    1.30 - -#
    1.31 +If you want to read more on the LEMON graph structures and concepts, read the page about \ref graphs "graphs". 
    1.32 +
    1.33 +-# 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 
    1.34 +in that format (find the documentation of the format on the web). 
    1.35 +\code
    1.36 +Graph g;
    1.37 +std::ifstream f("graph.dim");
    1.38 +readDimacs(f, g);
    1.39 +\endcode
    1.40 +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".
    1.41 +
    1.42  
    1.43  - If you want to solve some transportation problems in a network then 
    1.44  you will want to find shortest paths between nodes of a graph. This is 
    1.45  usually solved using Dijkstra's algorithm. A utility
    1.46  that solves this is  the \ref lemon::Dijkstra "LEMON Dijkstra class".
    1.47  A simple program using the \ref lemon::Dijkstra "LEMON Dijkstra class" is
    1.48 -as follows (we assume that the graph is already given in the memory):
    1.49 +as follows (we do not include the part that instantiates the graph and the length function):
    1.50  
    1.51  \code
    1.52 -
    1.53 +  typedef Graph::EdgeMap<int> LengthMap;
    1.54 +  Graph G;
    1.55 +  Node s, t;
    1.56 +  LengthMap cap(G);
    1.57 +	...
    1.58 +  Dijkstra<Graph, LengthMap> 
    1.59 +	dijkstra_test(G, cap);
    1.60 +  dijkstra_test.run(s);
    1.61  \endcode
    1.62  
    1.63  - If you want to design a network and want to minimize the total length
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/demo/helloworld.cc	Wed Mar 02 09:51:11 2005 +0000
     2.3 @@ -0,0 +1,34 @@
     2.4 +#include <iostream>
     2.5 +#include <lemon/list_graph.h>
     2.6 +
     2.7 +using namespace lemon;
     2.8 +
     2.9 +int main()
    2.10 +{
    2.11 +  typedef ListGraph Graph;
    2.12 +  typedef Graph::Edge Edge;
    2.13 +  typedef Graph::InEdgeIt InEdgeIt;
    2.14 +  typedef Graph::OutEdgeIt OutEdgeIt;
    2.15 +  typedef Graph::EdgeIt EdgeIt;
    2.16 +  typedef Graph::Node Node;
    2.17 +  typedef Graph::NodeIt NodeIt;
    2.18 +
    2.19 +  Graph g;
    2.20 +  
    2.21 +  for (int i = 0; i < 3; i++)
    2.22 +    g.addNode();
    2.23 +  
    2.24 +  for (NodeIt i(g); i!=INVALID; ++i)
    2.25 +    for (NodeIt j(g); j!=INVALID; ++j)
    2.26 +      if (i != j) g.addEdge(i, j);
    2.27 +
    2.28 +  std::cout << "Nodes:";
    2.29 +  for (NodeIt i(g); i!=INVALID; ++i)
    2.30 +    std::cout << " " << g.id(i);
    2.31 +  std::cout << std::endl;
    2.32 +
    2.33 +  std::cout << "Edges:";
    2.34 +  for (EdgeIt i(g); i!=INVALID; ++i)
    2.35 +    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
    2.36 +  std::cout << std::endl;
    2.37 +}