Improve and extend basics page
authorPeter Kovacs <kpeter@inf.elte.hu>
Sat, 20 Feb 2010 21:54:52 +0100
changeset 37c8be1109221b
parent 36 199a65b64d90
child 38 236e7061b70d
Improve and extend basics page
basics.dox
toc.txt
     1.1 --- a/basics.dox	Sat Feb 20 19:02:04 2010 +0100
     1.2 +++ b/basics.dox	Sat Feb 20 21:54:52 2010 +0100
     1.3 @@ -31,11 +31,27 @@
     1.4  
     1.5  [SEC]sec_digraphs[SEC] Directed Graphs
     1.6  
     1.7 +The core features of LEMON are the data structures, algorithms and auxiliary
     1.8 +tools that make it possible to represent graphs and working with them easily
     1.9 +and efficiently.
    1.10  This section tells you how to work with a directed graph (\e digraph,
    1.11  for short) in LEMON. Here we use \ref ListDigraph, the most versatile
    1.12  digraph structure. (The library also provides other digraph types,
    1.13  see \ref sec_graph_structures "later".)
    1.14  
    1.15 +For using \ref ListDigraph, you must include the header file
    1.16 +\ref list_graph.h like this:
    1.17 +
    1.18 +\code
    1.19 +#include <lemon/list_graph.h>
    1.20 +\endcode
    1.21 +
    1.22 +The default constructor of the class creates an empty digraph.
    1.23 +
    1.24 +\code
    1.25 +  ListDigraph g;
    1.26 +\endcode
    1.27 +
    1.28  The nodes and the arcs of a graph are identified by two data types called
    1.29  \ref concepts::Digraph::Node "ListDigraph::Node" and \ref concepts::Digraph::Arc
    1.30  "ListDigraph::Arc". You can add new items to the graph using the member
    1.31 @@ -43,22 +59,26 @@
    1.32  \ref ListDigraph::addArc() "addArc()", like this:
    1.33  
    1.34  \code
    1.35 -  ListDigraph g;
    1.36 -  ListDigraph::Node a = g.addNode();
    1.37 -  ListDigraph::Node b = g.addNode();
    1.38 -  ListDigraph::Node c = g.addNode();
    1.39 -  ListDigraph::Node d = g.addNode();
    1.40 +  ListDigraph::Node x = g.addNode();
    1.41 +  ListDigraph::Node y = g.addNode();
    1.42 +  ListDigraph::Node z = g.addNode();
    1.43  
    1.44 -  g.addArc(a,b);
    1.45 -  g.addArc(b,c);
    1.46 -  g.addArc(c,d);
    1.47 -  g.addArc(d,a);
    1.48 +  g.addArc(x,y);
    1.49 +  g.addArc(y,z);
    1.50 +  g.addArc(z,x);
    1.51  \endcode
    1.52  
    1.53  Of course, \ref ListDigraph::addArc() "addArc()" also returns the created arc:
    1.54  
    1.55  \code
    1.56 -  ListDigraph::Arc arc = g.addArc(a,c);
    1.57 +  ListDigraph::Arc arc = g.addArc(x,z);
    1.58 +\endcode
    1.59 +
    1.60 +Parallel and loop arcs are also supported.
    1.61 +
    1.62 +\code
    1.63 +  ListDigraph::Arc parallel = g.addArc(x,y);
    1.64 +  ListDigraph::Arc loop = g.addArc(x,x);
    1.65  \endcode
    1.66  
    1.67  \note Using ListDigraph, you can also remove nodes or arcs with the
    1.68 @@ -71,15 +91,17 @@
    1.69  Two important member functions of the directed graphs are
    1.70  \ref concepts::Digraph::source() "source()"
    1.71  and \ref concepts::Digraph::target() "target()".
    1.72 -They give back the two end nodes of an arc.
    1.73 +They give back the two end nodes of an arc (as \c Node objects).
    1.74  
    1.75  \code
    1.76 -  if (g.source(arc) == g.target(arc))
    1.77 +  if (g.source(loop) == g.target(loop))
    1.78      std::cout << "This is a loop arc" << std::endl;
    1.79  \endcode
    1.80  
    1.81 -Each graph item has a unique integer identifier, which can be obtained using
    1.82 -the \ref concepts::Digraph::id() "id()" function of the graph structure.
    1.83 +Each graph item has a non-negative integer identifier, which can be obtained
    1.84 +using the \ref concepts::Digraph::id() "id()" function of the graph structure.
    1.85 +These identifiers are unique with respect to a certain item type in a graph,
    1.86 +but a node and an arc may have the same id.
    1.87  
    1.88  \code
    1.89    std::cout << "Arc " << g.id(arc) << " goes from node "
    1.90 @@ -93,7 +115,7 @@
    1.91  [SEC]sec_digraph_it[SEC] Iterators
    1.92  
    1.93  Let us assume you want to list the elements of the graph. For this purpose,
    1.94 -the graph structures provide several iterators. For example, the following
    1.95 +the graph structures provide several \e iterators. For example, the following
    1.96  code will count the number of nodes in a graph.
    1.97  
    1.98  \code
    1.99 @@ -103,18 +125,32 @@
   1.100    std::cout << "Number of nodes: " << cnt << std::endl;
   1.101  \endcode
   1.102  
   1.103 -Here \ref concepts::Digraph::NodeIt "ListDigraph::NodeIt"
   1.104 -is an iterator class that traverses the
   1.105 -nodes. You must give the graph to the constructor and the iterator will be set
   1.106 +\ref concepts::Digraph::NodeIt "ListDigraph::NodeIt"
   1.107 +is an iterator class that lists the nodes.
   1.108 +The name of an iterator type starts with a name that refers to
   1.109 +the iterated objects and ends with 'It'.
   1.110 +
   1.111 +Using \ref concepts::Digraph::NodeIt "NodeIt", you must give
   1.112 +the graph object to the constructor and the iterator will be set
   1.113  to the first node. The next node is obtained by the prefix ++
   1.114  operator. If there are no more nodes in the graph, the iterator will
   1.115 -be set to \ref INVALID.
   1.116 +be set to \ref INVALID, which is exploited in the stop condition of
   1.117 +the loop.
   1.118  
   1.119 -\note \ref INVALID is a global constant, which converts to
   1.120 -and compares with each and every iterator in LEMON.
   1.121 +\note \ref INVALID is a constant in the \ref lemon namespace, which converts to
   1.122 +and compares with each and every iterator and graph item type.
   1.123 +Thus, you can even assign \ref INVALID to a \c Node or \c Arc object.
   1.124  
   1.125 -The iterators convert to the corresponding item types. For example,
   1.126 -to following code will add a full graph to the existing nodes.
   1.127 +The iterators convert to the corresponding item types.
   1.128 +For example, the identifiers of the nodes can be printed like this.
   1.129 +
   1.130 +\code
   1.131 +  for (ListDigraph::NodeIt n(g); n != INVALID; ++n)
   1.132 +    std::cout << g.id(n) << std::endl;
   1.133 +\endcode
   1.134 +
   1.135 +As an other example, the following code adds a full graph to the
   1.136 +existing nodes.
   1.137  
   1.138  \code
   1.139    for (ListDigraph::NodeIt u(g); u != INVALID; ++u)
   1.140 @@ -162,11 +198,16 @@
   1.141  
   1.142  \code
   1.143    int cnt = 0;
   1.144 -  for (ListDigraph::OutArcIt a(g, start); a != INVALID; ++a)
   1.145 +  for (ListDigraph::OutArcIt a(g, x); a != INVALID; ++a)
   1.146      cnt++;
   1.147 -  std::cout << "Number of arcs leaving the node 'start': " << cnt << std::endl;
   1.148 +  std::cout << "Number of arcs leaving the node 'x': " << cnt << std::endl;
   1.149  \endcode
   1.150  
   1.151 +\note LEMON provides functions for counting the nodes and arcs of a digraph:
   1.152 +\ref countNodes(), \ref countArcs(), \ref countInArcs(), \ref countOutArcs().
   1.153 +Using them is not just simpler than the above loops, but they could be much
   1.154 +faster, since several graph types support constant time item counting.
   1.155 +
   1.156  
   1.157  [SEC]sec_digraph_maps[SEC] Maps
   1.158  
   1.159 @@ -183,9 +224,14 @@
   1.160    existing maps will automatically expanded and the new slots will be
   1.161    initialized. On the removal of an item, the corresponding values in the maps
   1.162    are properly destructed.
   1.163 +  
   1.164 +By principle, the graph classes represent only the pure structure of
   1.165 +the graph (i.e. the nodes and arcs and their connections).
   1.166 +All data that are assigned to the items of the graph (e.g. node labels,
   1.167 +arc costs or capacities) must be stored separately using maps.
   1.168  
   1.169  \note These maps must not be confused with \c std::map, since they provide
   1.170 -O(1) time acces to the elements instead of O(log n).
   1.171 +O(1) time access to the elements instead of O(log n).
   1.172  
   1.173  So, if you want to assign \c int values to each node, you have to allocate a
   1.174  \ref concepts::Digraph::NodeMap "NodeMap<int>".
   1.175 @@ -198,27 +244,28 @@
   1.176  constructor. Then you can access its element as if it were a vector.
   1.177  
   1.178  \code
   1.179 -  map[a] = 2;
   1.180 -  map[b] = 3;
   1.181 -  map[c] = map[a] + map[b];
   1.182 +  map[x] = 2;
   1.183 +  map[y] = 3;
   1.184 +  map[z] = map[x] + map[y];
   1.185  \endcode
   1.186  
   1.187 -Any kind of data can be assigned to the graph items.
   1.188 +Any kind of data can be assigned to the graph items (assuming that the type
   1.189 +has a default constructor).
   1.190  
   1.191  \code
   1.192 -  ListDigraph::NodeMap<std::string> label(g);
   1.193 -  label[a] = "Node A";
   1.194 -  label[b] = "Node B";
   1.195 +  ListDigraph::NodeMap<std::string> name(g);
   1.196 +  name[x] = "Node A";
   1.197 +  name[y] = "Node B";
   1.198  \endcode
   1.199  
   1.200 -For a more complex example, let us create a map that assigns a unique
   1.201 -integer number to each node.
   1.202 +As a more complex example, let us create a map that assigns \c char labels
   1.203 +to the nodes.
   1.204  
   1.205  \code
   1.206 -  ListDigraph::NodeMap<int> id(g);
   1.207 -  int cnt = 0;
   1.208 +  ListDigraph::NodeMap<char> label(g);
   1.209 +  char ch = 'A';
   1.210    for (ListDigraph::NodeIt n(g); n != INVALID; ++n)
   1.211 -    id[n] = cnt++;
   1.212 +    label[n] = ch++;
   1.213  \endcode
   1.214  
   1.215  When you create a map, you can also give an initial value of the elements
   1.216 @@ -227,7 +274,6 @@
   1.217  
   1.218  \code
   1.219    ListDigraph::NodeMap<int> out_deg(g, 0);
   1.220 -
   1.221    for (ListDigraph::ArcIt a(g); a != INVALID; ++a)
   1.222      out_deg[g.source(a)]++;
   1.223  \endcode
   1.224 @@ -237,6 +283,46 @@
   1.225  map will be initialized with the default constructor of the
   1.226  type.
   1.227  
   1.228 +
   1.229 +[SEC]sec_naming_conv[SEC] Naming Conventions
   1.230 +
   1.231 +In LEMON, there are some naming conventions you might already notice
   1.232 +in the above examples.
   1.233 +
   1.234 +The name of a source file is written lowercase and the words are separated with
   1.235 +underscores (e.g. \ref list_graph.h). All header files are located in the
   1.236 +\c %lemon subdirectory, so you can include them like this.
   1.237 +
   1.238 +\code
   1.239 +#include <lemon/header_file.h>
   1.240 +\endcode
   1.241 +
   1.242 +The name of a class or any type looks like the following
   1.243 +(e.g. \ref ListDigraph, \ref concepts::Digraph::Node "Node",
   1.244 +\ref concepts::Digraph::NodeIt "NodeIt" etc.).
   1.245 +
   1.246 +\code
   1.247 +AllWordsCapitalizedWithoutUnderscores
   1.248 +\endcode
   1.249 +
   1.250 +The name of a function looks like the following
   1.251 +(e.g. \ref concepts::Digraph::source() "source()",
   1.252 +\ref concepts::Digraph::source() "target()",
   1.253 +\ref countNodes(), \ref countArcs() etc.).
   1.254 +
   1.255 +\code
   1.256 +firstWordLowerCaseRestCapitalizedWithoutUnderscores
   1.257 +\endcode
   1.258 +
   1.259 +The names of constants and macros look like the following
   1.260 +(e.g. \ref INVALID).
   1.261 +
   1.262 +\code
   1.263 +ALL_UPPER_CASE_WITH_UNDERSCORES
   1.264 +\endcode
   1.265 +
   1.266 +For more details, see \ref coding_style.
   1.267 +
   1.268  [TRAILER]
   1.269  */
   1.270  }
     2.1 --- a/toc.txt	Sat Feb 20 19:02:04 2010 +0100
     2.2 +++ b/toc.txt	Sat Feb 20 21:54:52 2010 +0100
     2.3 @@ -6,6 +6,7 @@
     2.4  ** sec_digraphs
     2.5  ** sec_digraph_it
     2.6  ** sec_digraph_maps
     2.7 +** sec_naming_conv
     2.8  *_sec_algorithms
     2.9  **_sec_alg_graph_search
    2.10  **_sec_alg_shortest_paths