hugo -> lemon
authoralpar
Wed, 29 Sep 2004 15:30:04 +0000
changeset 921818510fa3d99
parent 920 2d6c8075d9d0
child 922 e816fac59f6d
hugo -> lemon
Makefile.am
configure.ac
doc/coding_style.dox
doc/graphs.dox
doc/groups.dox
doc/mainpage.dox
doc/maps.dox
doc/namespaces.dox
src/Makefile.am
src/benchmark/bench_tools.h
src/benchmark/bfs-bench.cc
src/benchmark/graph-bench.cc
src/benchmark/hcube.cc
src/demo/sub_graph_wrapper_demo.cc
src/hugo/Makefile.am
src/hugo/array_map.h
src/hugo/attic/debug.h
src/hugo/attic/error.h
src/hugo/attic/tight_edge_filter_map.h
src/hugo/bfs.h
src/hugo/bin_heap.h
src/hugo/default_map.h
src/hugo/dfs.h
src/hugo/dijkstra.h
src/hugo/dimacs.h
src/hugo/extended_pair.h
src/hugo/fib_heap.h
src/hugo/full_graph.h
src/hugo/graph_wrapper.h
src/hugo/invalid.h
src/hugo/kruskal.h
src/hugo/list_graph.h
src/hugo/map_bits.h
src/hugo/map_defines.h
src/hugo/map_iterator.h
src/hugo/map_registry.h
src/hugo/maps.h
src/hugo/min_cost_flow.h
src/hugo/path.h
src/hugo/preflow.h
src/hugo/skeletons/graph.h
src/hugo/skeletons/maps.h
src/hugo/skeletons/path.h
src/hugo/smart_graph.h
src/hugo/suurballe.h
src/hugo/sym_map.h
src/hugo/template.h
src/hugo/time_measure.h
src/hugo/unionfind.h
src/hugo/vector_map.h
src/hugo/xy.h
src/lemon/Makefile.am
src/lemon/array_map.h
src/lemon/attic/debug.h
src/lemon/attic/error.h
src/lemon/attic/tight_edge_filter_map.h
src/lemon/bfs.h
src/lemon/bin_heap.h
src/lemon/default_map.h
src/lemon/dfs.h
src/lemon/dijkstra.h
src/lemon/dimacs.h
src/lemon/extended_pair.h
src/lemon/fib_heap.h
src/lemon/full_graph.h
src/lemon/graph_wrapper.h
src/lemon/invalid.h
src/lemon/kruskal.h
src/lemon/list_graph.h
src/lemon/map_bits.h
src/lemon/map_defines.h
src/lemon/map_iterator.h
src/lemon/map_registry.h
src/lemon/maps.h
src/lemon/min_cost_flow.h
src/lemon/path.h
src/lemon/preflow.h
src/lemon/skeletons/graph.h
src/lemon/skeletons/maps.h
src/lemon/skeletons/path.h
src/lemon/smart_graph.h
src/lemon/suurballe.h
src/lemon/sym_map.h
src/lemon/template.h
src/lemon/tight_edge_filter_map.h
src/lemon/time_measure.h
src/lemon/unionfind.h
src/lemon/vector_map.h
src/lemon/xy.h
src/test/bfs_test.cc
src/test/dfs_test.cc
src/test/dijkstra_heap_test.cc
src/test/dijkstra_test.cc
src/test/error_test.cc
src/test/graph_test.cc
src/test/graph_test.h
src/test/graph_wrapper_test.cc
src/test/kruskal_test.cc
src/test/min_cost_flow_test.cc
src/test/path_test.cc
src/test/preflow_test.cc
src/test/suurballe_test.cc
src/test/test_tools.h
src/test/test_tools_fail.cc
src/test/test_tools_pass.cc
src/test/time_measure_test.cc
src/test/unionfind_test.cc
src/test/xy_test.cc
src/work/akos/loader_demo.cc
src/work/alpar/bfs-named-param.cc
src/work/alpar/boolmap_iter.cc
src/work/alpar/f_ed_ka.h
src/work/alpar/f_ed_ka_demo.cc
src/work/alpar/gwrapper.h
src/work/alpar/list_graph_demo.cc
src/work/alpar/rw_nonref_map.cc
src/work/alpar/smart_graph_demo.cc
src/work/athos/bfs_test.cc
src/work/athos/dijkstra_at.h
src/work/athos/dijkstra_demo.cc
src/work/athos/kruskal.h
src/work/athos/min_cost_flow.cc
src/work/athos/mincostflow.h
src/work/athos/minlength_demo.cc
src/work/athos/old/minlengthpaths.h
src/work/athos/pf_demo.cc
src/work/athos/preflow_push_wogw.h
src/work/athos/suurballe.cc
src/work/athos/uf_demo.cc
src/work/athos/union_find.h
src/work/athos/xy/boundingbox.cc
src/work/athos/xy/xy.cc
src/work/bin_heap_demo.cc
src/work/deba/array_map_factory.h
src/work/deba/bin_heap.h
src/work/deba/dijkstra.h
src/work/deba/invalid.h
src/work/deba/list_graph.h
src/work/deba/map_registry.h
src/work/deba/pac_map_factory.h
src/work/deba/vector_map_factory.h
src/work/iterator_bfs_dfs_demo.cc
src/work/jacint/graph_gen.h
src/work/jacint/ledacomp.cc
src/work/jacint/max_flow.h
src/work/jacint/max_flow_bug.cc
src/work/jacint/max_flow_test.cc
src/work/jacint/max_matching.cc
src/work/jacint/max_matching.h
src/work/jacint/max_save.h
src/work/jacint/preflow.cc
src/work/jacint/preflow_excess.h
src/work/jacint/preflow_excess_test.cc
src/work/jacint/preflow_res.h
src/work/jacint/prim.cc
src/work/jacint/prim.h
src/work/johanna/contract_wrapper.h
src/work/johanna/ma_order.h
src/work/johanna/ma_order_test.cc
src/work/klao/debug.h
src/work/klao/iter_map.h
src/work/klao/iter_map_test.cc
src/work/klao/map_test.cc
src/work/marci/augmenting_flow.h
src/work/marci/bfs_dfs.h
src/work/marci/bfs_dfs_misc.h
src/work/marci/bfsit_vs_byhand.cc
src/work/marci/bipartite_graph_wrapper.h
src/work/marci/bipartite_graph_wrapper_test.cc
src/work/marci/bipartite_matching_demo.cc
src/work/marci/const_map_time.cc
src/work/marci/experiment/bfs_iterator.h
src/work/marci/experiment/bfs_iterator_1.h
src/work/marci/experiment/edmonds_karp.h
src/work/marci/experiment/edmonds_karp_1.h
src/work/marci/experiment/edmonds_karp_demo.cc
src/work/marci/experiment/edmonds_karp_demo_1.cc
src/work/marci/experiment/graph_wrapper.h
src/work/marci/experiment/graph_wrapper_1.h
src/work/marci/experiment/graph_wrapper_st_ostream_op.h
src/work/marci/experiment/iterator_bfs_demo.cc
src/work/marci/experiment/iterator_bfs_demo_1.cc
src/work/marci/experiment/list_graph.h
src/work/marci/for_each_macros.h
src/work/marci/graph_concept.h
src/work/marci/graph_wrapper_time.cc
src/work/marci/gw_vs_not.cc
src/work/marci/iterator_bfs_demo.cc
src/work/marci/leda/bipartite_matching_comparison.cc
src/work/marci/leda/bipartite_matching_leda.cc
src/work/marci/leda/bipartite_matching_leda_gen.cc
src/work/marci/leda/leda_graph_wrapper.h
src/work/marci/leda/max_bipartite_matching_demo.cc
src/work/marci/leda_bfs_dfs.cc
src/work/marci/leda_graph_demo.cc
src/work/marci/lg_vs_sg_vs_sg.cc
src/work/marci/lp/lp_solver_wrapper.h
src/work/marci/lp/max_flow_by_lp.cc
src/work/marci/macro_test.cc
src/work/marci/max_bipartite_matching.h
src/work/marci/max_flow_1.cc
src/work/marci/max_flow_demo.cc
src/work/marci/merge_node_graph_wrapper.h
src/work/marci/merge_node_graph_wrapper_test.cc
src/work/marci/oldies/edmonds_karp.h
src/work/marci/oldies/marci_graph_demo.cc
src/work/marci/preflow_bug.cc
src/work/marci/preflow_demo_athos.cc
src/work/marci/preflow_demo_jacint.cc
src/work/marci/top_sort_test.cc
src/work/peter/edgepathgraph.h
src/work/peter/edgepathgraph_test.cc
src/work/peter/hierarchygraph.h
src/work/peter/hierarchygraph_test.cc
src/work/peter/path/debug.h
src/work/peter/path/path.h
src/work/peter/path/path_skeleton.h
src/work/peter/path/path_test.cc
src/work/sage_graph.h
     1.1 --- a/Makefile.am	Wed Sep 29 14:12:26 2004 +0000
     1.2 +++ b/Makefile.am	Wed Sep 29 15:30:04 2004 +0000
     1.3 @@ -11,7 +11,7 @@
     1.4  	doc/Makefile.in							\
     1.5  	doc/doxygen.log							\
     1.6  	src/Makefile.in							\
     1.7 -	src/hugo/Makefile.in						\
     1.8 +	src/lemon/Makefile.in						\
     1.9  	src/test/Makefile.in                                            \
    1.10  	src/benchmark/Makefile.in
    1.11  
     2.1 --- a/configure.ac	Wed Sep 29 14:12:26 2004 +0000
     2.2 +++ b/configure.ac	Wed Sep 29 15:30:04 2004 +0000
     2.3 @@ -1,8 +1,8 @@
     2.4  dnl Process this file with autoconf to produce a configure script.
     2.5 -AC_INIT([HugoLib], [0.2], [etik-ol@cs.elte.hu], [hugo])
     2.6 +AC_INIT([LEMON], [0.2], [etik-ol@cs.elte.hu], [lemon])
     2.7  AC_CONFIG_AUX_DIR([config])
     2.8  AM_INIT_AUTOMAKE(1.7)
     2.9 -AC_CONFIG_SRCDIR([src/hugo/invalid.h])
    2.10 +AC_CONFIG_SRCDIR([src/lemon/invalid.h])
    2.11  AC_PREREQ(2.57)
    2.12  
    2.13  dnl Checks for programs.
    2.14 @@ -27,5 +27,5 @@
    2.15  AC_HEADER_STDC
    2.16  AC_CHECK_FUNCS(gettimeofday)
    2.17  
    2.18 -AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile src/hugo/Makefile src/test/Makefile src/benchmark/Makefile])
    2.19 +AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile src/lemon/Makefile src/test/Makefile src/benchmark/Makefile])
    2.20  AC_OUTPUT
     3.1 --- a/doc/coding_style.dox	Wed Sep 29 14:12:26 2004 +0000
     3.2 +++ b/doc/coding_style.dox	Wed Sep 29 15:30:04 2004 +0000
     3.3 @@ -1,6 +1,6 @@
     3.4  /*!
     3.5  
     3.6 -\page coding_style Hugo Coding Style 
     3.7 +\page coding_style LEMON Coding Style 
     3.8  
     3.9  \section naming_conv Naming Conventions
    3.10  
    3.11 @@ -9,7 +9,7 @@
    3.12  functions, variables, constants and exceptions. If these conventions
    3.13  are met in one's code then it is easier to read and maintain
    3.14  it. Please comply with these conventions if you want to contribute
    3.15 -developing Hugo library.
    3.16 +developing LEMON library.
    3.17  
    3.18  \subsection cs-class Classes and other types
    3.19  
     4.1 --- a/doc/graphs.dox	Wed Sep 29 14:12:26 2004 +0000
     4.2 +++ b/doc/graphs.dox	Wed Sep 29 15:30:04 2004 +0000
     4.3 @@ -2,60 +2,60 @@
     4.4  
     4.5  \page graphs How to use graphs
     4.6  
     4.7 -The primary data structures of HugoLib are the graph classes. They all
     4.8 +The primary data structures of LEMON are the graph classes. They all
     4.9  provide a node list - edge list interface, i.e. they have
    4.10  functionalities to list the nodes and the edges of the graph as well
    4.11  as in incoming and outgoing edges of a given node. 
    4.12  
    4.13  
    4.14  Each graph should meet the
    4.15 -\ref hugo::skeleton::StaticGraph "StaticGraph" concept.
    4.16 +\ref lemon::skeleton::StaticGraph "StaticGraph" concept.
    4.17  This concept does not
    4.18  makes it possible to change the graph (i.e. it is not possible to add
    4.19  or delete edges or nodes). Most of the graph algorithms will run on
    4.20  these graphs.
    4.21  
    4.22  The graphs meeting the
    4.23 -\ref hugo::skeleton::ExtendableGraph "ExtendableGraph"
    4.24 +\ref lemon::skeleton::ExtendableGraph "ExtendableGraph"
    4.25  concept allow node and
    4.26  edge addition. You can also "clear" (i.e. erase all edges and nodes)
    4.27  such a graph.
    4.28  
    4.29  In case of graphs meeting the full feature
    4.30 -\ref hugo::skeleton::ErasableGraph "ErasableGraph"
    4.31 +\ref lemon::skeleton::ErasableGraph "ErasableGraph"
    4.32  concept
    4.33  you can also erase individual edges and node in arbitrary order.
    4.34  
    4.35  The implemented graph structures are the following.
    4.36 -\li \ref hugo::ListGraph "ListGraph" is the most versatile graph class. It meets
    4.37 -the \ref hugo::skeleton::ErasableGraph "ErasableGraph" concept
    4.38 +\li \ref lemon::ListGraph "ListGraph" is the most versatile graph class. It meets
    4.39 +the \ref lemon::skeleton::ErasableGraph "ErasableGraph" concept
    4.40  and it also have some convenience features.
    4.41 -\li \ref hugo::SmartGraph "SmartGraph" is a more memory
    4.42 -efficient version of \ref hugo::ListGraph "ListGraph". The
    4.43 +\li \ref lemon::SmartGraph "SmartGraph" is a more memory
    4.44 +efficient version of \ref lemon::ListGraph "ListGraph". The
    4.45  price of it is that it only meets the
    4.46 -\ref hugo::skeleton::ExtendableGraph "ExtendableGraph" concept,
    4.47 +\ref lemon::skeleton::ExtendableGraph "ExtendableGraph" concept,
    4.48  so you cannot delete individual edges or nodes.
    4.49 -\li \ref hugo::SymListGraph "SymListGraph" and
    4.50 -\ref hugo::SymSmartGraph "SymSmartGraph" classes are very similar to
    4.51 -\ref hugo::ListGraph "ListGraph" and \ref hugo::SmartGraph "SmartGraph".
    4.52 +\li \ref lemon::SymListGraph "SymListGraph" and
    4.53 +\ref lemon::SymSmartGraph "SymSmartGraph" classes are very similar to
    4.54 +\ref lemon::ListGraph "ListGraph" and \ref lemon::SmartGraph "SmartGraph".
    4.55  The difference is that whenever you add a
    4.56  new edge to the graph, it actually adds a pair of oppositely directed edges.
    4.57  They are linked together so it is possible to access the counterpart of an
    4.58  edge. An even more important feature is that using these classes you can also
    4.59  attach data to the edges in such a way that the stored data
    4.60  are shared by the edge pairs. 
    4.61 -\li \ref hugo::FullGraph "FullGraph"
    4.62 -implements a full graph. It is a \ref hugo::skeleton::StaticGraph, so you cannot
    4.63 +\li \ref lemon::FullGraph "FullGraph"
    4.64 +implements a full graph. It is a \ref lemon::skeleton::StaticGraph, so you cannot
    4.65  change the number of nodes once it is constructed. It is extremely memory
    4.66  efficient: it uses constant amount of memory independently from the number of
    4.67  the nodes of the graph. Of course, the size of the \ref maps "NodeMap"'s and
    4.68  \ref maps "EdgeMap"'s will depend on the number of nodes.
    4.69  
    4.70 -\li \ref hugo::NodeSet "NodeSet" implements a graph with no edges. This class
    4.71 -can be used as a base class of \ref hugo::EdgeSet "EdgeSet".
    4.72 -\li \ref hugo::EdgeSet "EdgeSet" can be used to create a new graph on
    4.73 +\li \ref lemon::NodeSet "NodeSet" implements a graph with no edges. This class
    4.74 +can be used as a base class of \ref lemon::EdgeSet "EdgeSet".
    4.75 +\li \ref lemon::EdgeSet "EdgeSet" can be used to create a new graph on
    4.76  the node set of another graph. The base graph can be an arbitrary graph and it
    4.77 -is possible to attach several \ref hugo::EdgeSet "EdgeSet"'s to a base graph.
    4.78 +is possible to attach several \ref lemon::EdgeSet "EdgeSet"'s to a base graph.
    4.79  
    4.80  \todo Don't we need SmartNodeSet and SmartEdgeSet?
    4.81  \todo Some cross-refs are wrong.
    4.82 @@ -65,21 +65,21 @@
    4.83  \ref maps "map classes"
    4.84  to dynamically attach data the to graph components.
    4.85  
    4.86 -The following program demonstrates the basic features of HugoLib's graph
    4.87 +The following program demonstrates the basic features of LEMON's graph
    4.88  structures.
    4.89  
    4.90  \code
    4.91  #include <iostream>
    4.92 -#include <hugo/list_graph.h>
    4.93 +#include <lemon/list_graph.h>
    4.94  
    4.95 -using namespace hugo;
    4.96 +using namespace lemon;
    4.97  
    4.98  int main()
    4.99  {
   4.100    typedef ListGraph Graph;
   4.101  \endcode
   4.102  
   4.103 -ListGraph is one of HugoLib's graph classes. It is based on linked lists,
   4.104 +ListGraph is one of LEMON's graph classes. It is based on linked lists,
   4.105  therefore iterating throuh its edges and nodes is fast.
   4.106  
   4.107  \code
   4.108 @@ -114,7 +114,7 @@
   4.109  node iterator to initialize it to the first node. The operator++ is used to
   4.110  step to the next node. Using operator++ on the iterator pointing to the last
   4.111  node invalidates the iterator i.e. sets its value to
   4.112 -\ref hugo::INVALID "INVALID". This is what we exploit in the stop condition.
   4.113 +\ref lemon::INVALID "INVALID". This is what we exploit in the stop condition.
   4.114  
   4.115  The previous code fragment prints out the following:
   4.116  
   4.117 @@ -181,7 +181,7 @@
   4.118  \endcode
   4.119  
   4.120  As we mentioned above, graphs are not containers rather
   4.121 -incidence structures which are iterable in many ways. HugoLib introduces
   4.122 +incidence structures which are iterable in many ways. LEMON introduces
   4.123  concepts that allow us to attach containers to graphs. These containers are
   4.124  called maps.
   4.125  
     5.1 --- a/doc/groups.dox	Wed Sep 29 14:12:26 2004 +0000
     5.2 +++ b/doc/groups.dox	Wed Sep 29 15:30:04 2004 +0000
     5.3 @@ -1,23 +1,23 @@
     5.4  
     5.5  /**
     5.6  @defgroup datas Data Structures
     5.7 -This group describes the several graph structures implemented in HugoLib.
     5.8 +This group describes the several graph structures implemented in LEMON.
     5.9  */
    5.10  
    5.11  /**
    5.12  @defgroup graphs Graph Structures
    5.13  @ingroup datas
    5.14 -\brief Graph structures implemented in Hugo.
    5.15 +\brief Graph structures implemented in LEMON.
    5.16  
    5.17 -Hugolib provides several data structures to meet the diverging requirements
    5.18 +LEMON provides several data structures to meet the diverging requirements
    5.19  of the possible users.
    5.20  In order to save on running time or on memory usage, some structures may
    5.21  fail to provide
    5.22  some graph features like edge or node deletion.
    5.23  
    5.24 -Hugolib also offers special graphs that cannot be used alone but only
    5.25 +LEMON also offers special graphs that cannot be used alone but only
    5.26  in conjunction with other graph representation. The examples for this are
    5.27 -\ref hugo::EdgeSet "EdgeSet", \ref hugo::NodeSet "NodeSet"
    5.28 +\ref lemon::EdgeSet "EdgeSet", \ref lemon::NodeSet "NodeSet"
    5.29  and the large variety of \ref gwrappers "graph wrappers".
    5.30  
    5.31  You are free to use the graph structure that fit your requirements
    5.32 @@ -28,9 +28,9 @@
    5.33  /**
    5.34  @defgroup auxdat Auxiliary Data Structures
    5.35  @ingroup datas
    5.36 -\brief Some data structures implemented in HugoLib.
    5.37 +\brief Some data structures implemented in LEMON.
    5.38  
    5.39 -This group describes the data structures implemented in HugoLib in
    5.40 +This group describes the data structures implemented in LEMON in
    5.41  order to make it easier to implement combinatorial algorithms.
    5.42  */
    5.43  
    5.44 @@ -52,7 +52,7 @@
    5.45  /**
    5.46  @defgroup galgs Graph Algorithms
    5.47  \brief This group describes the several graph algorithms
    5.48 -implemented in HugoLib.
    5.49 +implemented in LEMON.
    5.50  */
    5.51  
    5.52  /**
    5.53 @@ -72,7 +72,7 @@
    5.54  @defgroup skeletons Skeletons
    5.55  \brief Skeletons (a.k.a. concept checking classes)
    5.56  
    5.57 -This group describes the data/algorithm skeletons implemented in HugoLib in
    5.58 +This group describes the data/algorithm skeletons implemented in LEMON in
    5.59  order to make it easier to check if a certain template class or
    5.60  template function is correctly implemented.
    5.61  */
     6.1 --- a/doc/mainpage.dox	Wed Sep 29 14:12:26 2004 +0000
     6.2 +++ b/doc/mainpage.dox	Wed Sep 29 15:30:04 2004 +0000
     6.3 @@ -3,9 +3,11 @@
     6.4  
     6.5  \section intro Introduction
     6.6  
     6.7 -\subsection whatis What is HugoLib
     6.8 +\subsection whatis What is LEMON
     6.9  
    6.10 -HugoLib stands for Hungarian Graph Optimization Library.
    6.11 +LEMON stands for
    6.12 +<it>L</it>ibrary of <it>E</it>fficient <it>M</it>odels
    6.13 +and <it>O</it>ptimization in <it>N</it>etworks.
    6.14  It is a C++ template
    6.15  library aimed at combinatorial optimization tasks which
    6.16  often involve in working
    6.17 @@ -14,7 +16,7 @@
    6.18  
    6.19  \subsection howtoread How to read this document
    6.20  
    6.21 -Graph structures play central role in HugoLib, so if you are new to it,
    6.22 +Graph structures play central role in LEMON, so if you are new to it,
    6.23  you probably should start \ref graphs "here".
    6.24  You can also find this page along with others under
    6.25  <a href="pages.html"> Related Pages </a>
     7.1 --- a/doc/maps.dox	Wed Sep 29 14:12:26 2004 +0000
     7.2 +++ b/doc/maps.dox	Wed Sep 29 15:30:04 2004 +0000
     7.3 @@ -4,7 +4,7 @@
     7.4  
     7.5  \page maps Maps
     7.6  
     7.7 -Maps play central role in HUGOlib. As their name suggests, they map a
     7.8 +Maps play central role in LEMON. As their name suggests, they map a
     7.9  certain range of \e keys to certain \e values. Each map has two
    7.10  <tt>typedef</tt>'s to determine the types of keys and values, like this:
    7.11  
    7.12 @@ -21,7 +21,7 @@
    7.13  value belonging to a key, so you have a direct access to the memory address
    7.14  where it is stored.
    7.15  
    7.16 -Each graph structure in HUGOlib provides two standard map templates called
    7.17 +Each graph structure in LEMON provides two standard map templates called
    7.18  \c EdgeMap and \c NodeMap. Both are reference maps and you can easily
    7.19  assign data to the nodes and to the edges of the graph. For example if you
    7.20  have a graph \c G defined as
    7.21 @@ -69,7 +69,7 @@
    7.22  
    7.23  The readable maps are very frequently used as the input of the
    7.24  algorithms.  For this purpose the most straightforward way is the use of the
    7.25 -default maps provided by Hugo's graph structures.
    7.26 +default maps provided by LEMON's graph structures.
    7.27  Very often however, it is more
    7.28  convenient and/or more efficient to write your own readable map.
    7.29  
     8.1 --- a/doc/namespaces.dox	Wed Sep 29 14:12:26 2004 +0000
     8.2 +++ b/doc/namespaces.dox	Wed Sep 29 15:30:04 2004 +0000
     8.3 @@ -1,10 +1,10 @@
     8.4 -/// The namespace of HugoLib
     8.5 +/// The namespace of LEMON
     8.6  
     8.7  /// \todo Some more detailed description would be nice here.
     8.8  ///
     8.9 -namespace hugo {
    8.10 +namespace lemon {
    8.11  
    8.12 -  /// The namespace of HUGOlib concepts and concept checking classes
    8.13 +  /// The namespace of LEMON concepts and concept checking classes
    8.14  
    8.15    /// \todo Some more detailed description would be nice here.
    8.16    ///
     9.1 --- a/src/Makefile.am	Wed Sep 29 14:12:26 2004 +0000
     9.2 +++ b/src/Makefile.am	Wed Sep 29 15:30:04 2004 +0000
     9.3 @@ -1,1 +1,1 @@
     9.4 -SUBDIRS = hugo benchmark test
     9.5 +SUBDIRS = lemon benchmark test
    10.1 --- a/src/benchmark/bench_tools.h	Wed Sep 29 14:12:26 2004 +0000
    10.2 +++ b/src/benchmark/bench_tools.h	Wed Sep 29 15:30:04 2004 +0000
    10.3 @@ -1,11 +1,11 @@
    10.4  // -*- mode:C++ -*-
    10.5 -#ifndef HUGO_BENCH_TEST_H
    10.6 -#define HUGO_BENCH_TEST_H
    10.7 +#ifndef LEMON_BENCH_TEST_H
    10.8 +#define LEMON_BENCH_TEST_H
    10.9  
   10.10  #include<vector>
   10.11  #include<iostream>
   10.12  
   10.13 -#include<hugo/time_measure.h>
   10.14 +#include<lemon/time_measure.h>
   10.15  
   10.16  ///An experimental typedef factory
   10.17  #define GRAPH_TYPEDEF_FACTORY(Graph) \
   10.18 @@ -74,9 +74,9 @@
   10.19      }
   10.20  };
   10.21  
   10.22 -inline void PrintTime(char *ID,hugo::Timer &T) 
   10.23 +inline void PrintTime(char *ID,lemon::Timer &T) 
   10.24  {
   10.25 -  hugo::TimeStamp S(T);
   10.26 +  lemon::TimeStamp S(T);
   10.27    std::cout << ID << ' ' << S.getUserTime() << ' '
   10.28  	    << S.getSystemTime() << ' ' << S.getRealTime() << std::endl;
   10.29  }
    11.1 --- a/src/benchmark/bfs-bench.cc	Wed Sep 29 14:12:26 2004 +0000
    11.2 +++ b/src/benchmark/bfs-bench.cc	Wed Sep 29 15:30:04 2004 +0000
    11.3 @@ -2,11 +2,11 @@
    11.4  
    11.5  #include <queue>
    11.6  #include<math.h>
    11.7 -#include<hugo/smart_graph.h>
    11.8 +#include<lemon/smart_graph.h>
    11.9  #include"bench_tools.h"
   11.10  
   11.11  using namespace std;
   11.12 -using namespace hugo;
   11.13 +using namespace lemon;
   11.14  
   11.15  inline int numOfOnes(int n,int dim)
   11.16  {
    12.1 --- a/src/benchmark/graph-bench.cc	Wed Sep 29 14:12:26 2004 +0000
    12.2 +++ b/src/benchmark/graph-bench.cc	Wed Sep 29 15:30:04 2004 +0000
    12.3 @@ -1,9 +1,9 @@
    12.4  #include<math.h>
    12.5 -#include<hugo/list_graph.h>
    12.6 +#include<lemon/list_graph.h>
    12.7  
    12.8  #include"bench_tools.h"
    12.9  
   12.10 -using namespace hugo;
   12.11 +using namespace lemon;
   12.12  
   12.13  ///Makes a full graph by adding and deleting a lot of edges;
   12.14  
   12.15 @@ -45,7 +45,7 @@
   12.16  
   12.17  int main()
   12.18  {
   12.19 -  hugo::Timer T;
   12.20 +  lemon::Timer T;
   12.21    makeFullGraph<ListGraph>(nextPrim(1000),nextPrim(300),nextPrim(100));
   12.22    
   12.23    PrintTime("BIG",T);
    13.1 --- a/src/benchmark/hcube.cc	Wed Sep 29 14:12:26 2004 +0000
    13.2 +++ b/src/benchmark/hcube.cc	Wed Sep 29 15:30:04 2004 +0000
    13.3 @@ -1,15 +1,15 @@
    13.4  // -*- mode:C++ -*-
    13.5  
    13.6  #include<math.h>
    13.7 -#include<hugo/list_graph.h>
    13.8 -#include<hugo/smart_graph.h>
    13.9 -#include<hugo/dijkstra.h>
   13.10 -#include<hugo/preflow.h>
   13.11 +#include<lemon/list_graph.h>
   13.12 +#include<lemon/smart_graph.h>
   13.13 +#include<lemon/dijkstra.h>
   13.14 +#include<lemon/preflow.h>
   13.15  
   13.16  #include"bench_tools.h"
   13.17  
   13.18  using namespace std;
   13.19 -using namespace hugo;
   13.20 +using namespace lemon;
   13.21  
   13.22  inline int numOfOnes(int n,int dim)
   13.23  {
    14.1 --- a/src/demo/sub_graph_wrapper_demo.cc	Wed Sep 29 14:12:26 2004 +0000
    14.2 +++ b/src/demo/sub_graph_wrapper_demo.cc	Wed Sep 29 15:30:04 2004 +0000
    14.3 @@ -8,15 +8,15 @@
    14.4  #include <iostream>
    14.5  #include <fstream>
    14.6  
    14.7 -#include <hugo/smart_graph.h>
    14.8 -#include <hugo/dijkstra.h>
    14.9 -#include <hugo/maps.h>
   14.10 -#include <hugo/graph_wrapper.h>
   14.11 -#include <hugo/dimacs.h>
   14.12 -#include <hugo/preflow.h>
   14.13 -#include <hugo/tight_edge_filter_map.h>
   14.14 +#include <lemon/smart_graph.h>
   14.15 +#include <lemon/dijkstra.h>
   14.16 +#include <lemon/maps.h>
   14.17 +#include <lemon/graph_wrapper.h>
   14.18 +#include <lemon/dimacs.h>
   14.19 +#include <lemon/preflow.h>
   14.20 +#include <lemon/tight_edge_filter_map.h>
   14.21  
   14.22 -using namespace hugo;
   14.23 +using namespace lemon;
   14.24  
   14.25  using std::cout;
   14.26  using std::endl;
    15.1 --- a/src/hugo/Makefile.am	Wed Sep 29 14:12:26 2004 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,35 +0,0 @@
    15.4 -pkginclude_HEADERS =							\
    15.5 -	array_map.h                                                     \
    15.6 -	bfs.h                                                           \
    15.7 -	dfs.h                                                           \
    15.8 -	bin_heap.h							\
    15.9 -	default_map.h							\
   15.10 -	dijkstra.h							\
   15.11 -	dimacs.h							\
   15.12 -	extended_pair.h                                                 \
   15.13 -	fib_heap.h							\
   15.14 -	full_graph.h							\
   15.15 -	graph_wrapper.h							\
   15.16 -	invalid.h							\
   15.17 -	kruskal.h							\
   15.18 -	list_graph.h							\
   15.19 -	map_defines.h                                                   \
   15.20 -	map_iterator.h                                                  \
   15.21 -	map_registry.h                                                  \
   15.22 -	map_bits.h							\
   15.23 -	maps.h								\
   15.24 -	min_cost_flow.h                                                \
   15.25 -	suurballe.h                                                     \
   15.26 -	preflow.h                                                       \
   15.27 -	path.h                                                          \
   15.28 -	smart_graph.h							\
   15.29 -	sym_map.h                                                       \
   15.30 -	time_measure.h							\
   15.31 -	unionfind.h							\
   15.32 -	vector_map.h                                                    \
   15.33 -	xy.h
   15.34 -
   15.35 -noinst_HEADERS =							\
   15.36 -	skeletons/graph.h						\
   15.37 -	skeletons/maps.h                                                \
   15.38 -	skeletons/path.h
    16.1 --- a/src/hugo/array_map.h	Wed Sep 29 14:12:26 2004 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,349 +0,0 @@
    16.4 -/* -*- C++ -*-
    16.5 - * src/hugo/array_map.h - Part of HUGOlib, a generic C++ optimization library
    16.6 - *
    16.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    16.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    16.9 - *
   16.10 - * Permission to use, modify and distribute this software is granted
   16.11 - * provided that this copyright notice appears in all copies. For
   16.12 - * precise terms see the accompanying LICENSE file.
   16.13 - *
   16.14 - * This software is provided "AS IS" with no warranty of any kind,
   16.15 - * express or implied, and with no claim as to its suitability for any
   16.16 - * purpose.
   16.17 - *
   16.18 - */
   16.19 -
   16.20 -#ifndef HUGO_ARRAY_MAP_H
   16.21 -#define HUGO_ARRAY_MAP_H
   16.22 -
   16.23 -#include <memory>
   16.24 -
   16.25 -#include <hugo/map_iterator.h>
   16.26 -#include <hugo/map_bits.h>
   16.27 -
   16.28 -///\ingroup graphmaps
   16.29 -///\file
   16.30 -///\brief Graph maps that construates and destruates
   16.31 -///their elements dynamically.
   16.32 -
   16.33 -namespace hugo {
   16.34 -
   16.35 -
   16.36 -  /// \addtogroup graphmaps
   16.37 -  /// @{
   16.38 -	
   16.39 -  /** The ArrayMap template class is graph map structure what
   16.40 -   *  automatically updates the map when a key is added to or erased from
   16.41 -   *  the map. This map factory uses the allocators to implement 
   16.42 -   *  the container functionality.
   16.43 -   *
   16.44 -   *  The template parameter is the MapRegistry that the maps
   16.45 -   *  will belong to and the ValueType.
   16.46 -   */
   16.47 -
   16.48 -  template <typename MapRegistry, typename Value> 
   16.49 -  class ArrayMap : public MapRegistry::MapBase {
   16.50 -
   16.51 -    template <typename MR, typename V> friend class ArrayMap;
   16.52 -		
   16.53 -  public:
   16.54 -		
   16.55 -    /// The graph type of the maps. 
   16.56 -    typedef typename MapRegistry::Graph Graph;
   16.57 -    /// The key type of the maps.
   16.58 -    typedef typename MapRegistry::KeyType KeyType;
   16.59 -    /// The iterator to iterate on the keys.
   16.60 -    typedef typename MapRegistry::KeyIt KeyIt;
   16.61 -
   16.62 -    /// The MapBase of the Map which imlements the core regisitry function.
   16.63 -    typedef typename MapRegistry::MapBase MapBase;
   16.64 -		
   16.65 -    
   16.66 -  public:
   16.67 -
   16.68 -    /// The value type of the map.
   16.69 -    typedef Value ValueType;
   16.70 -    /// The reference type of the map;
   16.71 -    typedef Value& ReferenceType;
   16.72 -    /// The pointer type of the map;
   16.73 -    typedef Value* PointerType;
   16.74 -
   16.75 -    /// The const value type of the map.
   16.76 -    typedef const Value ConstValueType;
   16.77 -    /// The const reference type of the map;
   16.78 -    typedef const Value& ConstReferenceType;
   16.79 -    /// The pointer type of the map;
   16.80 -    typedef const Value* ConstPointerType;
   16.81 -
   16.82 -
   16.83 -    typedef std::allocator<Value> Allocator;
   16.84 -
   16.85 -	
   16.86 -    /** Graph and Registry initialized map constructor.
   16.87 -     */
   16.88 -    ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
   16.89 -      allocate_memory();
   16.90 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   16.91 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   16.92 -	allocator.construct(&(values[id]), Value());
   16.93 -      }								
   16.94 -    }
   16.95 -
   16.96 -    /** Constructor to use default value to initialize the map. 
   16.97 -     */
   16.98 -    ArrayMap(const Graph& g, MapRegistry& r, const Value& v) 
   16.99 -      : MapBase(g, r) {
  16.100 -      allocate_memory();
  16.101 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.102 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.103 -	allocator.construct(&(values[id]), v);
  16.104 -      }								
  16.105 -    }
  16.106 -
  16.107 -    /** Constructor to copy a map of the same map type.
  16.108 -     */
  16.109 -    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
  16.110 -      capacity = copy.capacity;
  16.111 -      if (capacity == 0) return;
  16.112 -      values = allocator.allocate(capacity);
  16.113 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.114 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.115 -	allocator.construct(&(values[id]), copy.values[id]);
  16.116 -      }
  16.117 -    }
  16.118 -
  16.119 -    /** Constructor to copy a map of an other map type.
  16.120 -     */
  16.121 -    template <typename TT>
  16.122 -    ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 
  16.123 -      : MapBase(copy) {
  16.124 -      capacity = copy.capacity;
  16.125 -      if (capacity == 0) return;
  16.126 -      values = allocator.allocate(capacity);
  16.127 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.128 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.129 -	allocator.construct(&(values[id]), copy.values[id]);
  16.130 -      }
  16.131 -    }
  16.132 -
  16.133 -    /** Assign operator to copy a map of the same map type.
  16.134 -     */
  16.135 -    ArrayMap& operator=(const ArrayMap& copy) {
  16.136 -      if (&copy == this) return *this;
  16.137 -      
  16.138 -      if (MapBase::getGraph() != copy.getGraph()) {
  16.139 -	if (capacity != 0) {
  16.140 -	  MapBase::destroy();
  16.141 -	  allocator.deallocate(values, capacity);
  16.142 -	}
  16.143 -
  16.144 -	MapBase::operator=(copy);
  16.145 -	capacity = copy.capacity;
  16.146 -	if (capacity == 0) return *this;
  16.147 -	values = allocator.allocate(capacity);      
  16.148 -      }
  16.149 -
  16.150 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.151 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.152 -	allocator.construct(&(values[id]), copy.values[id]);
  16.153 -      }
  16.154 -
  16.155 -      return *this;
  16.156 -    }
  16.157 -
  16.158 -    /** Assign operator to copy a map of an other map type.
  16.159 -     */
  16.160 -    template <typename TT>
  16.161 -    ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) {
  16.162 -
  16.163 -      if (MapBase::getGraph() != copy.getGraph()) {
  16.164 -	if (capacity != 0) {
  16.165 -	  MapBase::destroy();
  16.166 -	  allocator.deallocate(values, capacity);
  16.167 -	}
  16.168 -
  16.169 -	MapBase::operator=(copy);
  16.170 -
  16.171 -	capacity = copy.capacity;
  16.172 -	if (capacity == 0) return *this;
  16.173 -	values = allocator.allocate(capacity);
  16.174 -      }
  16.175 -
  16.176 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.177 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.178 -	allocator.construct(&(values[id]), copy.values[id]);
  16.179 -      }
  16.180 -
  16.181 -      return *this;
  16.182 -    }
  16.183 -				
  16.184 -    /** The destructor of the map.
  16.185 -     */
  16.186 -    virtual ~ArrayMap() {
  16.187 -      if (capacity != 0) {
  16.188 -	MapBase::destroy();
  16.189 -	allocator.deallocate(values, capacity);
  16.190 -      }
  16.191 -    }
  16.192 -	
  16.193 -	
  16.194 -    /**
  16.195 -     * The subscript operator. The map can be subscripted by the
  16.196 -     * actual keys of the graph. 
  16.197 -     */
  16.198 -    ReferenceType operator[](const KeyType& key) {
  16.199 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  16.200 -      return values[id];
  16.201 -    } 
  16.202 -		
  16.203 -    /**
  16.204 -     * The const subscript operator. The map can be subscripted by the
  16.205 -     * actual keys of the graph. 
  16.206 -     */
  16.207 -    ConstReferenceType operator[](const KeyType& key) const {
  16.208 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  16.209 -      return values[id];
  16.210 -    }
  16.211 -	
  16.212 -    /** Setter function of the map. Equivalent with map[key] = val.
  16.213 -     *  This is a compatibility feature with the not dereferable maps.
  16.214 -     */
  16.215 -    void set(const KeyType& key, const ValueType& val) {
  16.216 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  16.217 -      values[id] = val;
  16.218 -    }
  16.219 -		
  16.220 -    /** Add a new key to the map. It called by the map registry.
  16.221 -     */
  16.222 -    void add(const KeyType& key) {
  16.223 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  16.224 -      if (id >= capacity) {
  16.225 -	int new_capacity = (capacity == 0 ? 1 : capacity);
  16.226 -	while (new_capacity <= id) {
  16.227 -	  new_capacity <<= 1;
  16.228 -	}
  16.229 -	Value* new_values = allocator.allocate(new_capacity);;
  16.230 -	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  16.231 -	  int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  16.232 -	  if (id != jd) {
  16.233 -	    allocator.construct(&(new_values[jd]), values[jd]);
  16.234 -	    allocator.destroy(&(values[jd]));
  16.235 -	  }
  16.236 -	}
  16.237 -	if (capacity != 0) allocator.deallocate(values, capacity);
  16.238 -	values = new_values;
  16.239 -	capacity = new_capacity;
  16.240 -      }
  16.241 -      allocator.construct(&(values[id]), Value());
  16.242 -    }
  16.243 -		
  16.244 -    /** Erase a key from the map. It called by the map registry.
  16.245 -     */
  16.246 -    void erase(const KeyType& key) {
  16.247 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  16.248 -      allocator.destroy(&(values[id]));
  16.249 -    }
  16.250 -
  16.251 -    /** Clear the data structure.
  16.252 -     */
  16.253 -    void clear() {	
  16.254 -      if (capacity != 0) {
  16.255 -	MapBase::destroy();
  16.256 -	allocator.deallocate(values, capacity);
  16.257 -	capacity = 0;
  16.258 -      }
  16.259 -    }
  16.260 -
  16.261 -    /// The stl compatible pair iterator of the map.
  16.262 -    typedef MapIterator<ArrayMap> Iterator;
  16.263 -    /// The stl compatible const pair iterator of the map.
  16.264 -    typedef MapConstIterator<ArrayMap> ConstIterator;
  16.265 -
  16.266 -    /** Returns the begin iterator of the map.
  16.267 -     */
  16.268 -    Iterator begin() {
  16.269 -      return Iterator(*this, KeyIt(*MapBase::getGraph()));
  16.270 -    }
  16.271 -
  16.272 -    /** Returns the end iterator of the map.
  16.273 -     */
  16.274 -    Iterator end() {
  16.275 -      return Iterator(*this, INVALID);
  16.276 -    }
  16.277 -
  16.278 -    /** Returns the begin ConstIterator of the map.
  16.279 -     */
  16.280 -    ConstIterator begin() const {
  16.281 -      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
  16.282 -    }
  16.283 -
  16.284 -    /** Returns the end const_iterator of the map.
  16.285 -     */
  16.286 -    ConstIterator end() const {
  16.287 -      return ConstIterator(*this, INVALID);
  16.288 -    }
  16.289 -
  16.290 -    /// The KeySet of the Map.
  16.291 -    typedef MapConstKeySet<ArrayMap> ConstKeySet;
  16.292 -
  16.293 -    /// KeySet getter function.
  16.294 -    ConstKeySet keySet() const {
  16.295 -      return ConstKeySet(*this); 
  16.296 -    }
  16.297 -
  16.298 -    /// The ConstValueSet of the Map.
  16.299 -    typedef MapConstValueSet<ArrayMap> ConstValueSet;
  16.300 -
  16.301 -    /// ConstValueSet getter function.
  16.302 -    ConstValueSet valueSet() const {
  16.303 -      return ConstValueSet(*this);
  16.304 -    }
  16.305 -
  16.306 -    /// The ValueSet of the Map.
  16.307 -    typedef MapValueSet<ArrayMap> ValueSet;
  16.308 -
  16.309 -    /// ValueSet getter function.
  16.310 -    ValueSet valueSet() {
  16.311 -      return ValueSet(*this);
  16.312 -    }
  16.313 -
  16.314 -  private:
  16.315 -      
  16.316 -    void allocate_memory() {
  16.317 -      int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
  16.318 -      if (max_id == -1) {
  16.319 -	capacity = 0;
  16.320 -	values = 0;
  16.321 -	return;
  16.322 -      }
  16.323 -      capacity = 1;
  16.324 -      while (capacity <= max_id) {
  16.325 -	capacity <<= 1;
  16.326 -      }
  16.327 -      values = allocator.allocate(capacity);	
  16.328 -    }      
  16.329 -
  16.330 -    int capacity;
  16.331 -    Value* values;
  16.332 -    Allocator allocator;
  16.333 -
  16.334 -  public:
  16.335 -    // STL  compatibility typedefs.
  16.336 -    typedef Iterator iterator;
  16.337 -    typedef ConstIterator const_iterator;
  16.338 -    typedef typename Iterator::PairValueType value_type;
  16.339 -    typedef typename Iterator::KeyType key_type;
  16.340 -    typedef typename Iterator::ValueType data_type;
  16.341 -    typedef typename Iterator::PairReferenceType reference;
  16.342 -    typedef typename Iterator::PairPointerType pointer;
  16.343 -    typedef typename ConstIterator::PairReferenceType const_reference;
  16.344 -    typedef typename ConstIterator::PairPointerType const_pointer;
  16.345 -    typedef int difference_type;		
  16.346 -  };		
  16.347 -
  16.348 -/// @}
  16.349 -
  16.350 -}
  16.351 -
  16.352 -#endif //HUGO_ARRAY_MAP_H
    17.1 --- a/src/hugo/attic/debug.h	Wed Sep 29 14:12:26 2004 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,70 +0,0 @@
    17.4 -/* -*- C++ -*-
    17.5 - * src/hugo/debug.h - Part of HUGOlib, a generic C++ optimization library
    17.6 - *
    17.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    17.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    17.9 - *
   17.10 - * Permission to use, modify and distribute this software is granted
   17.11 - * provided that this copyright notice appears in all copies. For
   17.12 - * precise terms see the accompanying LICENSE file.
   17.13 - *
   17.14 - * This software is provided "AS IS" with no warranty of any kind,
   17.15 - * express or implied, and with no claim as to its suitability for any
   17.16 - * purpose.
   17.17 - *
   17.18 - */
   17.19 -
   17.20 -#ifndef HUGO_DEBUG_H
   17.21 -#define HUGO_DEBUG_H
   17.22 -
   17.23 -//! \file
   17.24 -//! \brief Basic definitions for debug control.
   17.25 -
   17.26 -namespace hugo {
   17.27 -
   17.28 -  //! Debug mode for testing/debugging
   17.29 -
   17.30 -  //! Use this debug mode if you want exhaustive range and consistency checks.
   17.31 -  //! It also produces verbose debug messages.
   17.32 -  struct DebugOn {
   17.33 -    //! Example: check whether the edges added to a path are adjacent
   17.34 -    static const bool consistensy_check = true;
   17.35 -
   17.36 -    static const bool range_check = true;
   17.37 -
   17.38 -    //! Examples: initialize maps with some value;
   17.39 -    //! after deleting an item from UnionFindEnum set its value in the
   17.40 -    //! corresponding map to NULL...
   17.41 -    static const bool ensure_safe_state = true;
   17.42 -
   17.43 -    static const int verbose = 5;
   17.44 -  };
   17.45 -
   17.46 -  //! Debug mode for turning off debug aids.
   17.47 -
   17.48 -  //! This debud mode switches off all range and consistency checks,
   17.49 -  //! as well as the debug messages.
   17.50 -  //!
   17.51 -  struct DebugOff {
   17.52 -    static const bool consistensy_check = false;
   17.53 -    static const bool range_check = false;
   17.54 -    static const bool ensure_safe_state = false;
   17.55 -    static const int verbose = 0;
   17.56 -  };
   17.57 -
   17.58 -#ifdef DEBUG
   17.59 -  //! The default debug mode.
   17.60 -
   17.61 -  //! The default debug mode.
   17.62 -  //!
   17.63 -  typedef DebugOn DefaultDebugMode;
   17.64 -#else
   17.65 -  //! The default debug mode. 
   17.66 -
   17.67 -  //! The default debug mode. 
   17.68 -  //!
   17.69 -  typedef DebugOff DefaultDebugMode;
   17.70 -#endif
   17.71 -
   17.72 -}
   17.73 -#endif // HUGO_DEBUG_H
    18.1 --- a/src/hugo/attic/error.h	Wed Sep 29 14:12:26 2004 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,82 +0,0 @@
    18.4 -/* -*- C++ -*-
    18.5 - * src/hugo/error.h - Part of HUGOlib, a generic C++ optimization library
    18.6 - *
    18.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    18.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    18.9 - *
   18.10 - * Permission to use, modify and distribute this software is granted
   18.11 - * provided that this copyright notice appears in all copies. For
   18.12 - * precise terms see the accompanying LICENSE file.
   18.13 - *
   18.14 - * This software is provided "AS IS" with no warranty of any kind,
   18.15 - * express or implied, and with no claim as to its suitability for any
   18.16 - * purpose.
   18.17 - *
   18.18 - */
   18.19 -
   18.20 -#ifndef HUGO_ERROR_H
   18.21 -#define HUGO_ERROR_H
   18.22 -
   18.23 -//! \ingroup misc
   18.24 -//! \file
   18.25 -//! \brief Basic error handling (signaling) routines.
   18.26 -
   18.27 -#include <exception>
   18.28 -#include <string>
   18.29 -#include <sstream>
   18.30 -
   18.31 -
   18.32 -namespace hugo {
   18.33 -
   18.34 -  /**
   18.35 -   * \brief Generic exception class.
   18.36 -   *
   18.37 -   * \todo Do we need this?
   18.38 -   *
   18.39 -   * \todo Don't we need different kind of exceptions for different kind
   18.40 -   * of errors?
   18.41 -   * Shouldn't we use \<stdexcept\> instead?
   18.42 -   */
   18.43 -  class Exception : public std::exception {
   18.44 -  protected:
   18.45 -    std::ostringstream buf;
   18.46 -  public:
   18.47 -    Exception() {}
   18.48 -    explicit Exception(const std::string &s) { buf << s; }
   18.49 -    Exception(const Exception &e) : std::exception() {
   18.50 -      buf << e.buf.str();
   18.51 -    }
   18.52 -    virtual ~Exception() throw() {}
   18.53 -    
   18.54 -    virtual const char* what() const throw() {
   18.55 -      return buf.str().c_str();
   18.56 -    }
   18.57 -
   18.58 -    Exception& operator<<(std::string const& s) { buf << s; return *this; }
   18.59 -    Exception& operator<<(char const *s) { buf << s; return *this; }
   18.60 -    Exception& operator<<(int i) { buf << i; return *this; }
   18.61 -  };
   18.62 -
   18.63 -  /**
   18.64 -   * \brief Generic error signaling function.
   18.65 -   *
   18.66 -   * \todo Do we really need this? Is it helpful?
   18.67 -   */
   18.68 -  inline void fault(const std::string &msg) {
   18.69 -    throw Exception(msg);
   18.70 -  }
   18.71 -
   18.72 -  /**
   18.73 -   * \brief Macro for mark not yet implemented features.
   18.74 -   *
   18.75 -   * \todo Is this the right place for this? It should be used only in
   18.76 -   * modules under development.
   18.77 -   */
   18.78 -
   18.79 -# define FIXME(msg) \
   18.80 -    do { throw ::hugo::Exception() << "FIXME: " msg " (in: "    \
   18.81 -      __FILE__ ", " << __LINE__ << ")";                         \
   18.82 -    } while(false)
   18.83 -
   18.84 -}
   18.85 -#endif // HUGO_ERROR_H
    19.1 --- a/src/hugo/attic/tight_edge_filter_map.h	Wed Sep 29 14:12:26 2004 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,63 +0,0 @@
    19.4 -/* -*- C++ -*-
    19.5 - * src/hugo/tight_edge_filter_map.h - Part of HUGOlib, a generic C++ optimization library
    19.6 - *
    19.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    19.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    19.9 - *
   19.10 - * Permission to use, modify and distribute this software is granted
   19.11 - * provided that this copyright notice appears in all copies. For
   19.12 - * precise terms see the accompanying LICENSE file.
   19.13 - *
   19.14 - * This software is provided "AS IS" with no warranty of any kind,
   19.15 - * express or implied, and with no claim as to its suitability for any
   19.16 - * purpose.
   19.17 - *
   19.18 - */
   19.19 -
   19.20 -#ifndef HUGO_TIGHT_EDGE_FILTER_MAP_H
   19.21 -#define HUGO_TIGHT_EDGE_FILTER_MAP_H
   19.22 -
   19.23 -#include <hugo/maps.h>
   19.24 -
   19.25 -// /// \file
   19.26 -// /// \brief Maximum flow algorithms.
   19.27 -// /// \ingroup galgs
   19.28 -
   19.29 -namespace hugo {
   19.30 -
   19.31 -  /// \brief A map for filtering the edge-set to those edges 
   19.32 -  /// which are tight w.r.t. some node_potential map and 
   19.33 -  /// edge_distance map.
   19.34 -  ///
   19.35 -  /// A node-map node_potential is said to be a potential w.r.t. 
   19.36 -  /// an edge-map edge_distance 
   19.37 -  /// if and only if for each edge e, node_potential[g.head(e)] 
   19.38 -  /// <= edge_distance[e]+node_potential[g.tail(e)] 
   19.39 -  /// (or the reverse inequality holds for each edge).
   19.40 -  /// An edge is said to be tight if this inequality holds with equality, 
   19.41 -  /// and the map returns true exactly for those edges.
   19.42 -  /// To avoid rounding errors, it is recommended to use this class with exact 
   19.43 -  /// types, e.g. with int.
   19.44 -  template<typename Graph, 
   19.45 -	   typename NodePotentialMap, typename EdgeDistanceMap>
   19.46 -  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
   19.47 -  protected:
   19.48 -    const Graph* g;
   19.49 -    NodePotentialMap* node_potential;
   19.50 -    EdgeDistanceMap* edge_distance;
   19.51 -  public:
   19.52 -    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
   19.53 -		       EdgeDistanceMap& _edge_distance) : 
   19.54 -      g(&_g), node_potential(&_node_potential), 
   19.55 -      edge_distance(&_edge_distance) { }
   19.56 -    bool operator[](const typename Graph::Edge& e) const {
   19.57 -      return ((*node_potential)[g->head(e)] == 
   19.58 -	      (*edge_distance)[e]+(*node_potential)[g->tail(e)]);
   19.59 -    }
   19.60 -  };
   19.61 -
   19.62 -} //namespace hugo
   19.63 -
   19.64 -#endif //HUGO_TIGHT_EDGE_FILTER_MAP_H
   19.65 -
   19.66 -
    20.1 --- a/src/hugo/bfs.h	Wed Sep 29 14:12:26 2004 +0000
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,286 +0,0 @@
    20.4 -/* -*- C++ -*-
    20.5 - * src/hugo/bfs.h - Part of HUGOlib, a generic C++ optimization library
    20.6 - *
    20.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    20.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    20.9 - *
   20.10 - * Permission to use, modify and distribute this software is granted
   20.11 - * provided that this copyright notice appears in all copies. For
   20.12 - * precise terms see the accompanying LICENSE file.
   20.13 - *
   20.14 - * This software is provided "AS IS" with no warranty of any kind,
   20.15 - * express or implied, and with no claim as to its suitability for any
   20.16 - * purpose.
   20.17 - *
   20.18 - */
   20.19 -
   20.20 -#ifndef HUGO_BFS_H
   20.21 -#define HUGO_BFS_H
   20.22 -
   20.23 -///\ingroup flowalgs
   20.24 -///\file
   20.25 -///\brief Bfs algorithm.
   20.26 -///
   20.27 -///\todo Revise Manual.
   20.28 -
   20.29 -#include <hugo/bin_heap.h>
   20.30 -#include <hugo/invalid.h>
   20.31 -
   20.32 -namespace hugo {
   20.33 -
   20.34 -/// \addtogroup flowalgs
   20.35 -/// @{
   20.36 -
   20.37 -  ///%BFS algorithm class.
   20.38 -
   20.39 -  ///This class provides an efficient implementation of %BFS algorithm.
   20.40 -  ///\param GR The graph type the algorithm runs on.
   20.41 -  ///This class does the same as Dijkstra does with constant 1 edge length,
   20.42 -  ///but it is faster.
   20.43 -  ///
   20.44 -  ///\author Alpar Juttner
   20.45 -
   20.46 -#ifdef DOXYGEN
   20.47 -  template <typename GR>
   20.48 -#else
   20.49 -  template <typename GR>
   20.50 -#endif
   20.51 -  class Bfs{
   20.52 -  public:
   20.53 -    ///The type of the underlying graph.
   20.54 -    typedef GR Graph;
   20.55 -    ///\e
   20.56 -    typedef typename Graph::Node Node;
   20.57 -    ///\e
   20.58 -    typedef typename Graph::NodeIt NodeIt;
   20.59 -    ///\e
   20.60 -    typedef typename Graph::Edge Edge;
   20.61 -    ///\e
   20.62 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   20.63 -    
   20.64 -    ///\brief The type of the map that stores the last
   20.65 -    ///edges of the shortest paths.
   20.66 -    typedef typename Graph::template NodeMap<Edge> PredMap;
   20.67 -    ///\brief The type of the map that stores the last but one
   20.68 -    ///nodes of the shortest paths.
   20.69 -    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   20.70 -    ///The type of the map that stores the dists of the nodes.
   20.71 -    typedef typename Graph::template NodeMap<int> DistMap;
   20.72 -
   20.73 -  private:
   20.74 -    /// Pointer to the underlying graph.
   20.75 -    const Graph *G;
   20.76 -    ///Pointer to the map of predecessors edges.
   20.77 -    PredMap *predecessor;
   20.78 -    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
   20.79 -    bool local_predecessor;
   20.80 -    ///Pointer to the map of predecessors nodes.
   20.81 -    PredNodeMap *pred_node;
   20.82 -    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
   20.83 -    bool local_pred_node;
   20.84 -    ///Pointer to the map of distances.
   20.85 -    DistMap *distance;
   20.86 -    ///Indicates if \ref distance is locally allocated (\c true) or not.
   20.87 -    bool local_distance;
   20.88 -
   20.89 -    ///The source node of the last execution.
   20.90 -    Node source;
   20.91 -
   20.92 -
   20.93 -    ///Initializes the maps.
   20.94 -    void init_maps() 
   20.95 -    {
   20.96 -      if(!predecessor) {
   20.97 -	local_predecessor = true;
   20.98 -	predecessor = new PredMap(*G);
   20.99 -      }
  20.100 -      if(!pred_node) {
  20.101 -	local_pred_node = true;
  20.102 -	pred_node = new PredNodeMap(*G);
  20.103 -      }
  20.104 -      if(!distance) {
  20.105 -	local_distance = true;
  20.106 -	distance = new DistMap(*G);
  20.107 -      }
  20.108 -    }
  20.109 -    
  20.110 -  public :    
  20.111 -    ///Constructor.
  20.112 -    
  20.113 -    ///\param _G the graph the algorithm will run on.
  20.114 -    ///
  20.115 -    Bfs(const Graph& _G) :
  20.116 -      G(&_G),
  20.117 -      predecessor(NULL), local_predecessor(false),
  20.118 -      pred_node(NULL), local_pred_node(false),
  20.119 -      distance(NULL), local_distance(false)
  20.120 -    { }
  20.121 -    
  20.122 -    ///Destructor.
  20.123 -    ~Bfs() 
  20.124 -    {
  20.125 -      if(local_predecessor) delete predecessor;
  20.126 -      if(local_pred_node) delete pred_node;
  20.127 -      if(local_distance) delete distance;
  20.128 -    }
  20.129 -
  20.130 -    ///Sets the map storing the predecessor edges.
  20.131 -
  20.132 -    ///Sets the map storing the predecessor edges.
  20.133 -    ///If you don't use this function before calling \ref run(),
  20.134 -    ///it will allocate one. The destuctor deallocates this
  20.135 -    ///automatically allocated map, of course.
  20.136 -    ///\return <tt> (*this) </tt>
  20.137 -    Bfs &setPredMap(PredMap &m) 
  20.138 -    {
  20.139 -      if(local_predecessor) {
  20.140 -	delete predecessor;
  20.141 -	local_predecessor=false;
  20.142 -      }
  20.143 -      predecessor = &m;
  20.144 -      return *this;
  20.145 -    }
  20.146 -
  20.147 -    ///Sets the map storing the predecessor nodes.
  20.148 -
  20.149 -    ///Sets the map storing the predecessor nodes.
  20.150 -    ///If you don't use this function before calling \ref run(),
  20.151 -    ///it will allocate one. The destuctor deallocates this
  20.152 -    ///automatically allocated map, of course.
  20.153 -    ///\return <tt> (*this) </tt>
  20.154 -    Bfs &setPredNodeMap(PredNodeMap &m) 
  20.155 -    {
  20.156 -      if(local_pred_node) {
  20.157 -	delete pred_node;
  20.158 -	local_pred_node=false;
  20.159 -      }
  20.160 -      pred_node = &m;
  20.161 -      return *this;
  20.162 -    }
  20.163 -
  20.164 -    ///Sets the map storing the distances calculated by the algorithm.
  20.165 -
  20.166 -    ///Sets the map storing the distances calculated by the algorithm.
  20.167 -    ///If you don't use this function before calling \ref run(),
  20.168 -    ///it will allocate one. The destuctor deallocates this
  20.169 -    ///automatically allocated map, of course.
  20.170 -    ///\return <tt> (*this) </tt>
  20.171 -    Bfs &setDistMap(DistMap &m) 
  20.172 -    {
  20.173 -      if(local_distance) {
  20.174 -	delete distance;
  20.175 -	local_distance=false;
  20.176 -      }
  20.177 -      distance = &m;
  20.178 -      return *this;
  20.179 -    }
  20.180 -    
  20.181 -  ///Runs %BFS algorithm from node \c s.
  20.182 -
  20.183 -  ///This method runs the %BFS algorithm from a root node \c s
  20.184 -  ///in order to
  20.185 -  ///compute a
  20.186 -  ///shortest path to each node. The algorithm computes
  20.187 -  ///- The %BFS tree.
  20.188 -  ///- The distance of each node from the root.
  20.189 - 
  20.190 -    void run(Node s) {
  20.191 -      
  20.192 -      init_maps();
  20.193 -      
  20.194 -      source = s;
  20.195 -      
  20.196 -      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  20.197 -	predecessor->set(u,INVALID);
  20.198 -	pred_node->set(u,INVALID);
  20.199 -      }
  20.200 -      
  20.201 -      int N=G->nodeNum();
  20.202 -      std::vector<typename Graph::Node> Q(N);
  20.203 -      int Qh=0;
  20.204 -      int Qt=0;
  20.205 -      
  20.206 -      Q[Qh++]=source;
  20.207 -      distance->set(s, 0);
  20.208 -      do {
  20.209 -	Node m;
  20.210 -	Node n=Q[Qt++];
  20.211 -	int d= (*distance)[n]+1;
  20.212 -	
  20.213 -	for(OutEdgeIt e(*G,n);e!=INVALID;++e)
  20.214 -	  if((m=G->head(e))!=s && (*predecessor)[m]==INVALID) {
  20.215 -	    Q[Qh++]=m;
  20.216 -	    predecessor->set(m,e);
  20.217 -	    pred_node->set(m,n);
  20.218 -	    distance->set(m,d);
  20.219 -	  }
  20.220 -      } while(Qt!=Qh);
  20.221 -    }
  20.222 -    
  20.223 -    ///The distance of a node from the root.
  20.224 -
  20.225 -    ///Returns the distance of a node from the root.
  20.226 -    ///\pre \ref run() must be called before using this function.
  20.227 -    ///\warning If node \c v in unreachable from the root the return value
  20.228 -    ///of this funcion is undefined.
  20.229 -    int dist(Node v) const { return (*distance)[v]; }
  20.230 -
  20.231 -    ///Returns the 'previous edge' of the %BFS path tree.
  20.232 -
  20.233 -    ///For a node \c v it returns the 'previous edge' of the %BFS tree,
  20.234 -    ///i.e. it returns the last edge of a shortest path from the root to \c
  20.235 -    ///v. It is \ref INVALID
  20.236 -    ///if \c v is unreachable from the root or if \c v=s. The
  20.237 -    ///%BFS tree used here is equal to the %BFS tree used in
  20.238 -    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  20.239 -    ///this function.
  20.240 -    Edge pred(Node v) const { return (*predecessor)[v]; }
  20.241 -
  20.242 -    ///Returns the 'previous node' of the %BFS tree.
  20.243 -
  20.244 -    ///For a node \c v it returns the 'previous node' on the %BFS tree,
  20.245 -    ///i.e. it returns the last but one node from a shortest path from the
  20.246 -    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
  20.247 -    ///\c v=s. The shortest path tree used here is equal to the %BFS
  20.248 -    ///tree used in \ref pred(Node v).  \pre \ref run() must be called before
  20.249 -    ///using this function.
  20.250 -    Node predNode(Node v) const { return (*pred_node)[v]; }
  20.251 -    
  20.252 -    ///Returns a reference to the NodeMap of distances.
  20.253 -    
  20.254 -    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
  20.255 -    ///be called before using this function.
  20.256 -    const DistMap &distMap() const { return *distance;}
  20.257 - 
  20.258 -    ///Returns a reference to the %BFS tree map.
  20.259 -
  20.260 -    ///Returns a reference to the NodeMap of the edges of the
  20.261 -    ///%BFS tree.
  20.262 -    ///\pre \ref run() must be called before using this function.
  20.263 -    const PredMap &predMap() const { return *predecessor;}
  20.264 - 
  20.265 -    ///Returns a reference to the map of last but one nodes of shortest paths.
  20.266 -
  20.267 -    ///Returns a reference to the NodeMap of the last but one nodes on the
  20.268 -    ///%BFS tree.
  20.269 -    ///\pre \ref run() must be called before using this function.
  20.270 -    const PredNodeMap &predNodeMap() const { return *pred_node;}
  20.271 -
  20.272 -    ///Checks if a node is reachable from the root.
  20.273 -
  20.274 -    ///Returns \c true if \c v is reachable from the root.
  20.275 -    ///\note The root node is reported to be reached!
  20.276 -    ///
  20.277 -    ///\pre \ref run() must be called before using this function.
  20.278 -    ///
  20.279 -    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  20.280 -    
  20.281 -  };
  20.282 -  
  20.283 -/// @}
  20.284 -  
  20.285 -} //END OF NAMESPACE HUGO
  20.286 -
  20.287 -#endif
  20.288 -
  20.289 -
    21.1 --- a/src/hugo/bin_heap.h	Wed Sep 29 14:12:26 2004 +0000
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,203 +0,0 @@
    21.4 -/* -*- C++ -*-
    21.5 - * src/hugo/bin_heap.h - Part of HUGOlib, a generic C++ optimization library
    21.6 - *
    21.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    21.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    21.9 - *
   21.10 - * Permission to use, modify and distribute this software is granted
   21.11 - * provided that this copyright notice appears in all copies. For
   21.12 - * precise terms see the accompanying LICENSE file.
   21.13 - *
   21.14 - * This software is provided "AS IS" with no warranty of any kind,
   21.15 - * express or implied, and with no claim as to its suitability for any
   21.16 - * purpose.
   21.17 - *
   21.18 - */
   21.19 -
   21.20 -#ifndef HUGO_BIN_HEAP_H
   21.21 -#define HUGO_BIN_HEAP_H
   21.22 -
   21.23 -///\ingroup auxdat
   21.24 -///\file
   21.25 -///\brief Binary Heap implementation.
   21.26 -///\todo It should be documented.
   21.27 -
   21.28 -#include <vector>
   21.29 -#include <utility>
   21.30 -#include <functional>
   21.31 -
   21.32 -namespace hugo {
   21.33 -
   21.34 -  /// \addtogroup auxdat
   21.35 -  /// @{
   21.36 -
   21.37 -   /// A Binary Heap implementation.
   21.38 -  template <typename Item, typename Prio, typename ItemIntMap,
   21.39 -	    typename Compare = std::less<Prio> >
   21.40 -  class BinHeap {
   21.41 -
   21.42 -  public:
   21.43 -    typedef Item                             ItemType;
   21.44 -    // FIXME: stl-ben nem ezt hivjak value_type -nak, hanem a kovetkezot...
   21.45 -    typedef Prio                             PrioType;
   21.46 -    typedef std::pair<ItemType,PrioType>     PairType;
   21.47 -    typedef ItemIntMap                       ItemIntMapType;
   21.48 -    typedef Compare                          PrioCompare;
   21.49 -
   21.50 -    /**
   21.51 -     * Each Item element have a state associated to it. It may be "in heap",
   21.52 -     * "pre heap" or "post heap". The later two are indifferent from the
   21.53 -     * heap's point of view, but may be useful to the user.
   21.54 -     *
   21.55 -     * The ItemIntMap _should_ be initialized in such way, that it maps
   21.56 -     * PRE_HEAP (-1) to any element to be put in the heap...
   21.57 -     */
   21.58 -    ///\todo it is used nowhere
   21.59 -    ///
   21.60 -    enum state_enum {
   21.61 -      IN_HEAP = 0,
   21.62 -      PRE_HEAP = -1,
   21.63 -      POST_HEAP = -2
   21.64 -    };
   21.65 -
   21.66 -  private:
   21.67 -    std::vector<PairType> data;
   21.68 -    Compare comp;
   21.69 -    // FIXME: jo ez igy???
   21.70 -    ItemIntMap &iim;
   21.71 -
   21.72 -  public:
   21.73 -    BinHeap(ItemIntMap &_iim) : iim(_iim) {}
   21.74 -    BinHeap(ItemIntMap &_iim, const Compare &_comp) : comp(_comp), iim(_iim) {}
   21.75 -
   21.76 -
   21.77 -    int size() const { return data.size(); }
   21.78 -    bool empty() const { return data.empty(); }
   21.79 -
   21.80 -  private:
   21.81 -    static int parent(int i) { return (i-1)/2; }
   21.82 -    static int second_child(int i) { return 2*i+2; }
   21.83 -    bool less(const PairType &p1, const PairType &p2) const {
   21.84 -      return comp(p1.second, p2.second);
   21.85 -    }
   21.86 -
   21.87 -    int bubble_up(int hole, PairType p);
   21.88 -    int bubble_down(int hole, PairType p, int length);
   21.89 -
   21.90 -    void move(const PairType &p, int i) {
   21.91 -      data[i] = p;
   21.92 -      iim.set(p.first, i);
   21.93 -    }
   21.94 -
   21.95 -    void rmidx(int h) {
   21.96 -      int n = data.size()-1;
   21.97 -      if( h>=0 && h<=n ) {
   21.98 -	iim.set(data[h].first, POST_HEAP);
   21.99 -	if ( h<n ) {
  21.100 -	  bubble_down(h, data[n], n);
  21.101 -	}
  21.102 -	data.pop_back();
  21.103 -      }
  21.104 -    }
  21.105 -
  21.106 -  public:
  21.107 -    void push(const PairType &p) {
  21.108 -      int n = data.size();
  21.109 -      data.resize(n+1);
  21.110 -      bubble_up(n, p);
  21.111 -    }
  21.112 -    void push(const Item &i, const Prio &p) { push(PairType(i,p)); }
  21.113 -
  21.114 -    Item top() const {
  21.115 -      return data[0].first;
  21.116 -    }
  21.117 -    /// Returns the prio of the top element of the heap.
  21.118 -    Prio prio() const {
  21.119 -      return data[0].second;
  21.120 -    }
  21.121 -
  21.122 -    void pop() {
  21.123 -      rmidx(0);
  21.124 -    }
  21.125 -
  21.126 -    void erase(const Item &i) {
  21.127 -      rmidx(iim[i]);
  21.128 -    }
  21.129 -
  21.130 -    Prio operator[](const Item &i) const {
  21.131 -      int idx = iim[i];
  21.132 -      return data[idx].second;
  21.133 -    }
  21.134 -
  21.135 -    void set(const Item &i, const Prio &p) {
  21.136 -      int idx = iim[i];
  21.137 -      if( idx < 0 ) {
  21.138 -	push(i,p);
  21.139 -      }
  21.140 -      else if( comp(p, data[idx].second) ) {
  21.141 -	bubble_up(idx, PairType(i,p));
  21.142 -      }
  21.143 -      else {
  21.144 -	bubble_down(idx, PairType(i,p), data.size());
  21.145 -      }
  21.146 -    }
  21.147 -
  21.148 -    void decrease(const Item &i, const Prio &p) {
  21.149 -      int idx = iim[i];
  21.150 -      bubble_up(idx, PairType(i,p));
  21.151 -    }
  21.152 -    void increase(const Item &i, const Prio &p) {
  21.153 -      int idx = iim[i];
  21.154 -      bubble_down(idx, PairType(i,p), data.size());
  21.155 -    }
  21.156 -
  21.157 -    state_enum state(const Item &i) const {
  21.158 -      int s = iim[i];
  21.159 -      if( s>=0 )
  21.160 -	s=0;
  21.161 -      return state_enum(s);
  21.162 -    }
  21.163 -
  21.164 -  }; // class BinHeap
  21.165 -
  21.166 -  
  21.167 -  template <typename K, typename V, typename M, typename C>
  21.168 -  int BinHeap<K,V,M,C>::bubble_up(int hole, PairType p) {
  21.169 -    int par = parent(hole);
  21.170 -    while( hole>0 && less(p,data[par]) ) {
  21.171 -      move(data[par],hole);
  21.172 -      hole = par;
  21.173 -      par = parent(hole);
  21.174 -    }
  21.175 -    move(p, hole);
  21.176 -    return hole;
  21.177 -  }
  21.178 -
  21.179 -  template <typename K, typename V, typename M, typename C>
  21.180 -  int BinHeap<K,V,M,C>::bubble_down(int hole, PairType p, int length) {
  21.181 -    int child = second_child(hole);
  21.182 -    while(child < length) {
  21.183 -      if( less(data[child-1], data[child]) ) {
  21.184 -	--child;
  21.185 -      }
  21.186 -      if( !less(data[child], p) )
  21.187 -	goto ok;
  21.188 -      move(data[child], hole);
  21.189 -      hole = child;
  21.190 -      child = second_child(hole);
  21.191 -    }
  21.192 -    child--;
  21.193 -    if( child<length && less(data[child], p) ) {
  21.194 -      move(data[child], hole);
  21.195 -      hole=child;
  21.196 -    }
  21.197 -  ok:
  21.198 -    move(p, hole);
  21.199 -    return hole;
  21.200 -  }
  21.201 -
  21.202 -  ///@}
  21.203 -
  21.204 -} // namespace hugo
  21.205 -
  21.206 -#endif // HUGO_BIN_HEAP_H
    22.1 --- a/src/hugo/default_map.h	Wed Sep 29 14:12:26 2004 +0000
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,144 +0,0 @@
    22.4 -/* -*- C++ -*-
    22.5 - * src/hugo/default_map.h - Part of HUGOlib, a generic C++ optimization library
    22.6 - *
    22.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    22.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    22.9 - *
   22.10 - * Permission to use, modify and distribute this software is granted
   22.11 - * provided that this copyright notice appears in all copies. For
   22.12 - * precise terms see the accompanying LICENSE file.
   22.13 - *
   22.14 - * This software is provided "AS IS" with no warranty of any kind,
   22.15 - * express or implied, and with no claim as to its suitability for any
   22.16 - * purpose.
   22.17 - *
   22.18 - */
   22.19 -
   22.20 -#ifndef HUGO_DEFAULT_MAP_H
   22.21 -#define HUGO_DEFAULT_MAP_H
   22.22 -
   22.23 -
   22.24 -#include <hugo/array_map.h>
   22.25 -#include <hugo/vector_map.h>
   22.26 -
   22.27 -///\ingroup graphmaps
   22.28 -///\file
   22.29 -///\brief Graph maps that construates and destruates
   22.30 -///their elements dynamically.
   22.31 -
   22.32 -namespace hugo {
   22.33 -
   22.34 -/// \addtogroup graphmaps
   22.35 -/// @{
   22.36 -
   22.37 -  /** The ArrayMap template class is graph map structure what
   22.38 -   *  automatically updates the map when a key is added to or erased from
   22.39 -   *  the map. This map uses the VectorMap if the ValueType is a primitive
   22.40 -   *  type and the ArrayMap for the other cases.
   22.41 -   *
   22.42 -   *  The template parameter is the MapRegistry that the maps
   22.43 -   *  will belong to and the ValueType.
   22.44 -   */
   22.45 -
   22.46 -
   22.47 -  /** Macro to implement the DefaultMap.
   22.48 -   */
   22.49 -#define DEFAULT_MAP_BODY(DynMap, Value) \
   22.50 -{ \
   22.51 -\
   22.52 -public: \
   22.53 -\
   22.54 -typedef DynMap<MapRegistry, Value> Parent; \
   22.55 -\
   22.56 -typedef typename MapRegistry::Graph Graph; \
   22.57 -\
   22.58 -DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
   22.59 -DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
   22.60 -  : Parent(g, r, v) {} \
   22.61 -DefaultMap(const DefaultMap& copy) \
   22.62 -  : Parent(static_cast<const Parent&>(copy)) {} \
   22.63 -template <typename TT> \
   22.64 -DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
   22.65 -  : { \
   22.66 -  Parent::MapBase::operator= \
   22.67 -    (static_cast<const typename Parent::MapBase&>(copy)); \
   22.68 -  if (Parent::getGraph()) { \
   22.69 -    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
   22.70 -      Parent::add(it); \
   22.71 -      Parent::operator[](it) = copy[it]; \
   22.72 -    } \
   22.73 -  } \
   22.74 -} \
   22.75 -DefaultMap& operator=(const DefaultMap& copy) { \
   22.76 -  Parent::operator=(static_cast<const Parent&>(copy)); \
   22.77 -  return *this; \
   22.78 -} \
   22.79 -template <typename TT> \
   22.80 -DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
   22.81 -  if (Parent::getGraph() != copy.getGraph()) { \
   22.82 -    Parent::clear(); \
   22.83 -    Parent::MapBase::operator=(copy); \
   22.84 -    Parent::construct(); \
   22.85 -  } \
   22.86 -  if (Parent::getGraph()) { \
   22.87 -    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
   22.88 -      Parent::operator[](it) = copy[it]; \
   22.89 -    } \
   22.90 -  } \
   22.91 -  return *this; \
   22.92 -} \
   22.93 -};
   22.94 -
   22.95 -
   22.96 -  template <typename MapRegistry, typename Type>
   22.97 -  class DefaultMap : public ArrayMap<MapRegistry, Type> 
   22.98 -  DEFAULT_MAP_BODY(ArrayMap, Type);
   22.99 -
  22.100 -  template <typename MapRegistry>
  22.101 -  class DefaultMap<MapRegistry, bool> 
  22.102 -    : public VectorMap<MapRegistry, bool> 
  22.103 -  DEFAULT_MAP_BODY(VectorMap, bool);
  22.104 -
  22.105 -  template <typename MapRegistry>
  22.106 -  class DefaultMap<MapRegistry, char> 
  22.107 -    : public VectorMap<MapRegistry, char> 
  22.108 -  DEFAULT_MAP_BODY(VectorMap, char);
  22.109 -
  22.110 -  template <typename MapRegistry>
  22.111 -  class DefaultMap<MapRegistry, int> 
  22.112 -    : public VectorMap<MapRegistry, int> 
  22.113 -  DEFAULT_MAP_BODY(VectorMap, int);
  22.114 -
  22.115 -  template <typename MapRegistry>
  22.116 -  class DefaultMap<MapRegistry, short> 
  22.117 -    : public VectorMap<MapRegistry, short> 
  22.118 -  DEFAULT_MAP_BODY(VectorMap, short);
  22.119 -
  22.120 -  template <typename MapRegistry>
  22.121 -  class DefaultMap<MapRegistry, long> 
  22.122 -    : public VectorMap<MapRegistry, long> 
  22.123 -  DEFAULT_MAP_BODY(VectorMap, long);
  22.124 -
  22.125 -  template <typename MapRegistry>
  22.126 -  class DefaultMap<MapRegistry, float> 
  22.127 -    : public VectorMap<MapRegistry, float> 
  22.128 -  DEFAULT_MAP_BODY(VectorMap, float);
  22.129 -
  22.130 -  template <typename MapRegistry>
  22.131 -  class DefaultMap<MapRegistry, double> 
  22.132 -    : public VectorMap<MapRegistry, double> 
  22.133 -  DEFAULT_MAP_BODY(VectorMap, double);
  22.134 -
  22.135 -  template <typename MapRegistry>
  22.136 -  class DefaultMap<MapRegistry, long double> 
  22.137 -    : public VectorMap<MapRegistry, long double> 
  22.138 -  DEFAULT_MAP_BODY(VectorMap, long double);
  22.139 -
  22.140 -  template <typename MapRegistry, typename Type>
  22.141 -  class DefaultMap<MapRegistry, Type*>
  22.142 -    : public VectorMap<MapRegistry, Type*> 
  22.143 -  DEFAULT_MAP_BODY(VectorMap, Type*);
  22.144 -
  22.145 -}
  22.146 -
  22.147 -#endif
    23.1 --- a/src/hugo/dfs.h	Wed Sep 29 14:12:26 2004 +0000
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,290 +0,0 @@
    23.4 -/* -*- C++ -*-
    23.5 - * src/hugo/dfs.h - Part of HUGOlib, a generic C++ optimization library
    23.6 - *
    23.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    23.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    23.9 - *
   23.10 - * Permission to use, modify and distribute this software is granted
   23.11 - * provided that this copyright notice appears in all copies. For
   23.12 - * precise terms see the accompanying LICENSE file.
   23.13 - *
   23.14 - * This software is provided "AS IS" with no warranty of any kind,
   23.15 - * express or implied, and with no claim as to its suitability for any
   23.16 - * purpose.
   23.17 - *
   23.18 - */
   23.19 -
   23.20 -#ifndef HUGO_DFS_H
   23.21 -#define HUGO_DFS_H
   23.22 -
   23.23 -///\ingroup flowalgs
   23.24 -///\file
   23.25 -///\brief %DFS algorithm.
   23.26 -///
   23.27 -///\todo Revise Manual.
   23.28 -
   23.29 -#include <hugo/bin_heap.h>
   23.30 -#include <hugo/invalid.h>
   23.31 -
   23.32 -namespace hugo {
   23.33 -
   23.34 -/// \addtogroup flowalgs
   23.35 -/// @{
   23.36 -
   23.37 -  ///%DFS algorithm class.
   23.38 -
   23.39 -  ///This class provides an efficient implementation of %DFS algorithm.
   23.40 -  ///
   23.41 -  ///\param GR The graph type the algorithm runs on.
   23.42 -  ///
   23.43 -  ///\author Alpar Juttner
   23.44 -
   23.45 -#ifdef DOXYGEN
   23.46 -  template <typename GR>
   23.47 -#else
   23.48 -  template <typename GR>
   23.49 -#endif
   23.50 -  class Dfs{
   23.51 -  public:
   23.52 -    ///The type of the underlying graph.
   23.53 -    typedef GR Graph;
   23.54 -    ///\e
   23.55 -    typedef typename Graph::Node Node;
   23.56 -    ///\e
   23.57 -    typedef typename Graph::NodeIt NodeIt;
   23.58 -    ///\e
   23.59 -    typedef typename Graph::Edge Edge;
   23.60 -    ///\e
   23.61 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   23.62 -    
   23.63 -    ///\brief The type of the map that stores the last
   23.64 -    ///edges of the paths on the %DFS tree.
   23.65 -    typedef typename Graph::template NodeMap<Edge> PredMap;
   23.66 -    ///\brief The type of the map that stores the last but one
   23.67 -    ///nodes of the paths on the %DFS tree.
   23.68 -    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   23.69 -    ///The type of the map that stores the dists of the nodes on the %DFS tree.
   23.70 -    typedef typename Graph::template NodeMap<int> DistMap;
   23.71 -
   23.72 -  private:
   23.73 -    /// Pointer to the underlying graph.
   23.74 -    const Graph *G;
   23.75 -    ///Pointer to the map of predecessors edges.
   23.76 -    PredMap *predecessor;
   23.77 -    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
   23.78 -    bool local_predecessor;
   23.79 -    ///Pointer to the map of predecessors nodes.
   23.80 -    PredNodeMap *pred_node;
   23.81 -    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
   23.82 -    bool local_pred_node;
   23.83 -    ///Pointer to the map of distances.
   23.84 -    DistMap *distance;
   23.85 -    ///Indicates if \ref distance is locally allocated (\c true) or not.
   23.86 -    bool local_distance;
   23.87 -
   23.88 -    ///The source node of the last execution.
   23.89 -    Node source;
   23.90 -
   23.91 -
   23.92 -    ///Initializes the maps.
   23.93 -    void init_maps() 
   23.94 -    {
   23.95 -      if(!predecessor) {
   23.96 -	local_predecessor = true;
   23.97 -	predecessor = new PredMap(*G);
   23.98 -      }
   23.99 -      if(!pred_node) {
  23.100 -	local_pred_node = true;
  23.101 -	pred_node = new PredNodeMap(*G);
  23.102 -      }
  23.103 -      if(!distance) {
  23.104 -	local_distance = true;
  23.105 -	distance = new DistMap(*G);
  23.106 -      }
  23.107 -    }
  23.108 -    
  23.109 -  public :    
  23.110 -    ///Constructor.
  23.111 -    
  23.112 -    ///\param _G the graph the algorithm will run on.
  23.113 -    ///
  23.114 -    Dfs(const Graph& _G) :
  23.115 -      G(&_G),
  23.116 -      predecessor(NULL), local_predecessor(false),
  23.117 -      pred_node(NULL), local_pred_node(false),
  23.118 -      distance(NULL), local_distance(false)
  23.119 -    { }
  23.120 -    
  23.121 -    ///Destructor.
  23.122 -    ~Dfs() 
  23.123 -    {
  23.124 -      if(local_predecessor) delete predecessor;
  23.125 -      if(local_pred_node) delete pred_node;
  23.126 -      if(local_distance) delete distance;
  23.127 -    }
  23.128 -
  23.129 -    ///Sets the map storing the predecessor edges.
  23.130 -
  23.131 -    ///Sets the map storing the predecessor edges.
  23.132 -    ///If you don't use this function before calling \ref run(),
  23.133 -    ///it will allocate one. The destuctor deallocates this
  23.134 -    ///automatically allocated map, of course.
  23.135 -    ///\return <tt> (*this) </tt>
  23.136 -    Dfs &setPredMap(PredMap &m) 
  23.137 -    {
  23.138 -      if(local_predecessor) {
  23.139 -	delete predecessor;
  23.140 -	local_predecessor=false;
  23.141 -      }
  23.142 -      predecessor = &m;
  23.143 -      return *this;
  23.144 -    }
  23.145 -
  23.146 -    ///Sets the map storing the predecessor nodes.
  23.147 -
  23.148 -    ///Sets the map storing the predecessor nodes.
  23.149 -    ///If you don't use this function before calling \ref run(),
  23.150 -    ///it will allocate one. The destuctor deallocates this
  23.151 -    ///automatically allocated map, of course.
  23.152 -    ///\return <tt> (*this) </tt>
  23.153 -    Dfs &setPredNodeMap(PredNodeMap &m) 
  23.154 -    {
  23.155 -      if(local_pred_node) {
  23.156 -	delete pred_node;
  23.157 -	local_pred_node=false;
  23.158 -      }
  23.159 -      pred_node = &m;
  23.160 -      return *this;
  23.161 -    }
  23.162 -
  23.163 -    ///Sets the map storing the distances calculated by the algorithm.
  23.164 -
  23.165 -    ///Sets the map storing the distances calculated by the algorithm.
  23.166 -    ///If you don't use this function before calling \ref run(),
  23.167 -    ///it will allocate one. The destuctor deallocates this
  23.168 -    ///automatically allocated map, of course.
  23.169 -    ///\return <tt> (*this) </tt>
  23.170 -    Dfs &setDistMap(DistMap &m) 
  23.171 -    {
  23.172 -      if(local_distance) {
  23.173 -	delete distance;
  23.174 -	local_distance=false;
  23.175 -      }
  23.176 -      distance = &m;
  23.177 -      return *this;
  23.178 -    }
  23.179 -    
  23.180 -  ///Runs %DFS algorithm from node \c s.
  23.181 -
  23.182 -  ///This method runs the %DFS algorithm from a root node \c s
  23.183 -  ///in order to
  23.184 -  ///compute 
  23.185 -  ///- a %DFS tree and
  23.186 -  ///- the distance of each node from the root on this tree.
  23.187 - 
  23.188 -    void run(Node s) {
  23.189 -      
  23.190 -      init_maps();
  23.191 -      
  23.192 -      source = s;
  23.193 -      
  23.194 -      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  23.195 -	predecessor->set(u,INVALID);
  23.196 -	pred_node->set(u,INVALID);
  23.197 -      }
  23.198 -      
  23.199 -      int N=G->nodeNum();
  23.200 -      std::vector<typename Graph::OutEdgeIt> Q(N);
  23.201 -
  23.202 -      int Qh=0;
  23.203 -      
  23.204 -      G->first(Q[Qh],s);
  23.205 -      distance->set(s, 0);
  23.206 -
  23.207 -      Node n=s;
  23.208 -      Node m;
  23.209 -      OutEdgeIt e;
  23.210 -      do {
  23.211 -	if((e=Q[Qh])!=INVALID)
  23.212 -	  if((m=G->head(e))!=s && (*predecessor)[m=G->head(e)]==INVALID) {
  23.213 -	    predecessor->set(m,e);
  23.214 -	    pred_node->set(m,n);
  23.215 -	    G->first(Q[++Qh],m);
  23.216 -	    distance->set(m,Qh);
  23.217 -	    n=m;
  23.218 -	  }
  23.219 -	  else ++Q[Qh];
  23.220 -	else if(--Qh>=0) n=G->tail(Q[Qh]);
  23.221 -      } while(Qh>=0);
  23.222 -    }
  23.223 -    
  23.224 -    ///The distance of a node from the root on the %DFS tree.
  23.225 -
  23.226 -    ///Returns the distance of a node from the root on the %DFS tree.
  23.227 -    ///\pre \ref run() must be called before using this function.
  23.228 -    ///\warning If node \c v in unreachable from the root the return value
  23.229 -    ///of this funcion is undefined.
  23.230 -    int dist(Node v) const { return (*distance)[v]; }
  23.231 -
  23.232 -    ///Returns the 'previous edge' of the %DFS path tree.
  23.233 -
  23.234 -    ///For a node \c v it returns the last edge of the path on the %DFS tree
  23.235 -    ///from the root to \c
  23.236 -    ///v. It is \ref INVALID
  23.237 -    ///if \c v is unreachable from the root or if \c v=s. The
  23.238 -    ///%DFS tree used here is equal to the %DFS tree used in
  23.239 -    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  23.240 -    ///this function.
  23.241 -    Edge pred(Node v) const { return (*predecessor)[v]; }
  23.242 -
  23.243 -    ///Returns the 'previous node' of the %DFS tree.
  23.244 -
  23.245 -    ///For a node \c v it returns the 'previous node' on the %DFS tree,
  23.246 -    ///i.e. it returns the last but one node of the path from the
  23.247 -    ///root to \c /v on the %DFS tree.
  23.248 -    ///It is INVALID if \c v is unreachable from the root or if
  23.249 -    ///\c v=s.
  23.250 -    ///\pre \ref run() must be called before
  23.251 -    ///using this function.
  23.252 -    Node predNode(Node v) const { return (*pred_node)[v]; }
  23.253 -    
  23.254 -    ///Returns a reference to the NodeMap of distances on the %DFS tree.
  23.255 -    
  23.256 -    ///Returns a reference to the NodeMap of distances on the %DFS tree.
  23.257 -    ///\pre \ref run() must
  23.258 -    ///be called before using this function.
  23.259 -    const DistMap &distMap() const { return *distance;}
  23.260 - 
  23.261 -    ///Returns a reference to the %DFS tree map.
  23.262 -
  23.263 -    ///Returns a reference to the NodeMap of the edges of the
  23.264 -    ///%DFS tree.
  23.265 -    ///\pre \ref run() must be called before using this function.
  23.266 -    const PredMap &predMap() const { return *predecessor;}
  23.267 - 
  23.268 -    ///Returns a reference to the map of last but one nodes of the %DFS tree.
  23.269 -
  23.270 -    ///Returns a reference to the NodeMap of the last but one nodes of the paths
  23.271 -    ///on the
  23.272 -    ///%DFS tree.
  23.273 -    ///\pre \ref run() must be called before using this function.
  23.274 -    const PredNodeMap &predNodeMap() const { return *pred_node;}
  23.275 -
  23.276 -    ///Checks if a node is reachable from the root.
  23.277 -
  23.278 -    ///Returns \c true if \c v is reachable from the root.
  23.279 -    ///\note The root node is reported to be reached!
  23.280 -    ///
  23.281 -    ///\pre \ref run() must be called before using this function.
  23.282 -    ///
  23.283 -    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  23.284 -    
  23.285 -  };
  23.286 -  
  23.287 -/// @}
  23.288 -  
  23.289 -} //END OF NAMESPACE HUGO
  23.290 -
  23.291 -#endif
  23.292 -
  23.293 -
    24.1 --- a/src/hugo/dijkstra.h	Wed Sep 29 14:12:26 2004 +0000
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,344 +0,0 @@
    24.4 -/* -*- C++ -*-
    24.5 - * src/hugo/dijkstra.h - Part of HUGOlib, a generic C++ optimization library
    24.6 - *
    24.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    24.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    24.9 - *
   24.10 - * Permission to use, modify and distribute this software is granted
   24.11 - * provided that this copyright notice appears in all copies. For
   24.12 - * precise terms see the accompanying LICENSE file.
   24.13 - *
   24.14 - * This software is provided "AS IS" with no warranty of any kind,
   24.15 - * express or implied, and with no claim as to its suitability for any
   24.16 - * purpose.
   24.17 - *
   24.18 - */
   24.19 -
   24.20 -#ifndef HUGO_DIJKSTRA_H
   24.21 -#define HUGO_DIJKSTRA_H
   24.22 -
   24.23 -///\ingroup flowalgs
   24.24 -///\file
   24.25 -///\brief Dijkstra algorithm.
   24.26 -
   24.27 -#include <hugo/bin_heap.h>
   24.28 -#include <hugo/invalid.h>
   24.29 -
   24.30 -namespace hugo {
   24.31 -
   24.32 -/// \addtogroup flowalgs
   24.33 -/// @{
   24.34 -
   24.35 -  ///%Dijkstra algorithm class.
   24.36 -
   24.37 -  ///This class provides an efficient implementation of %Dijkstra algorithm.
   24.38 -  ///The edge lengths are passed to the algorithm using a
   24.39 -  ///\ref skeleton::ReadMap "ReadMap",
   24.40 -  ///so it is easy to change it to any kind of length.
   24.41 -  ///
   24.42 -  ///The type of the length is determined by the
   24.43 -  ///\ref skeleton::ReadMap::ValueType "ValueType" of the length map.
   24.44 -  ///
   24.45 -  ///It is also possible to change the underlying priority heap.
   24.46 -  ///
   24.47 -  ///\param GR The graph type the algorithm runs on.
   24.48 -  ///\param LM This read-only
   24.49 -  ///EdgeMap
   24.50 -  ///determines the
   24.51 -  ///lengths of the edges. It is read once for each edge, so the map
   24.52 -  ///may involve in relatively time consuming process to compute the edge
   24.53 -  ///length if it is necessary. The default map type is
   24.54 -  ///\ref skeleton::StaticGraph::EdgeMap "Graph::EdgeMap<int>"
   24.55 -  ///\param Heap The heap type used by the %Dijkstra
   24.56 -  ///algorithm. The default
   24.57 -  ///is using \ref BinHeap "binary heap".
   24.58 -  ///
   24.59 -  ///\author Jacint Szabo and Alpar Juttner
   24.60 -  ///\todo We need a typedef-names should be standardized. (-:
   24.61 -  ///\todo Type of \c PredMap, \c PredNodeMap and \c DistMap
   24.62 -  ///should not be fixed. (Problematic to solve).
   24.63 -
   24.64 -#ifdef DOXYGEN
   24.65 -  template <typename GR,
   24.66 -	    typename LM,
   24.67 -	    typename Heap>
   24.68 -#else
   24.69 -  template <typename GR,
   24.70 -	    typename LM=typename GR::template EdgeMap<int>,
   24.71 -	    template <class,class,class,class> class Heap = BinHeap >
   24.72 -#endif
   24.73 -  class Dijkstra{
   24.74 -  public:
   24.75 -    ///The type of the underlying graph.
   24.76 -    typedef GR Graph;
   24.77 -    ///\e
   24.78 -    typedef typename Graph::Node Node;
   24.79 -    ///\e
   24.80 -    typedef typename Graph::NodeIt NodeIt;
   24.81 -    ///\e
   24.82 -    typedef typename Graph::Edge Edge;
   24.83 -    ///\e
   24.84 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   24.85 -    
   24.86 -    ///The type of the length of the edges.
   24.87 -    typedef typename LM::ValueType ValueType;
   24.88 -    ///The type of the map that stores the edge lengths.
   24.89 -    typedef LM LengthMap;
   24.90 -    ///\brief The type of the map that stores the last
   24.91 -    ///edges of the shortest paths.
   24.92 -    typedef typename Graph::template NodeMap<Edge> PredMap;
   24.93 -    ///\brief The type of the map that stores the last but one
   24.94 -    ///nodes of the shortest paths.
   24.95 -    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   24.96 -    ///The type of the map that stores the dists of the nodes.
   24.97 -    typedef typename Graph::template NodeMap<ValueType> DistMap;
   24.98 -
   24.99 -  private:
  24.100 -    /// Pointer to the underlying graph.
  24.101 -    const Graph *G;
  24.102 -    /// Pointer to the length map
  24.103 -    const LM *length;
  24.104 -    ///Pointer to the map of predecessors edges.
  24.105 -    PredMap *predecessor;
  24.106 -    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
  24.107 -    bool local_predecessor;
  24.108 -    ///Pointer to the map of predecessors nodes.
  24.109 -    PredNodeMap *pred_node;
  24.110 -    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
  24.111 -    bool local_pred_node;
  24.112 -    ///Pointer to the map of distances.
  24.113 -    DistMap *distance;
  24.114 -    ///Indicates if \ref distance is locally allocated (\c true) or not.
  24.115 -    bool local_distance;
  24.116 -
  24.117 -    ///The source node of the last execution.
  24.118 -    Node source;
  24.119 -
  24.120 -    ///Initializes the maps.
  24.121 -    
  24.122 -    ///\todo Error if \c G or are \c NULL. What about \c length?
  24.123 -    ///\todo Better memory allocation (instead of new).
  24.124 -    void init_maps() 
  24.125 -    {
  24.126 -      if(!predecessor) {
  24.127 -	local_predecessor = true;
  24.128 -	predecessor = new PredMap(*G);
  24.129 -      }
  24.130 -      if(!pred_node) {
  24.131 -	local_pred_node = true;
  24.132 -	pred_node = new PredNodeMap(*G);
  24.133 -      }
  24.134 -      if(!distance) {
  24.135 -	local_distance = true;
  24.136 -	distance = new DistMap(*G);
  24.137 -      }
  24.138 -    }
  24.139 -    
  24.140 -  public :
  24.141 -    ///Constructor.
  24.142 -    
  24.143 -    ///\param _G the graph the algorithm will run on.
  24.144 -    ///\param _length the length map used by the algorithm.
  24.145 -    Dijkstra(const Graph& _G, const LM& _length) :
  24.146 -      G(&_G), length(&_length),
  24.147 -      predecessor(NULL), local_predecessor(false),
  24.148 -      pred_node(NULL), local_pred_node(false),
  24.149 -      distance(NULL), local_distance(false)
  24.150 -    { }
  24.151 -    
  24.152 -    ///Destructor.
  24.153 -    ~Dijkstra() 
  24.154 -    {
  24.155 -      if(local_predecessor) delete predecessor;
  24.156 -      if(local_pred_node) delete pred_node;
  24.157 -      if(local_distance) delete distance;
  24.158 -    }
  24.159 -
  24.160 -    ///Sets the length map.
  24.161 -
  24.162 -    ///Sets the length map.
  24.163 -    ///\return <tt> (*this) </tt>
  24.164 -    Dijkstra &setLengthMap(const LM &m) 
  24.165 -    {
  24.166 -      length = &m;
  24.167 -      return *this;
  24.168 -    }
  24.169 -
  24.170 -    ///Sets the map storing the predecessor edges.
  24.171 -
  24.172 -    ///Sets the map storing the predecessor edges.
  24.173 -    ///If you don't use this function before calling \ref run(),
  24.174 -    ///it will allocate one. The destuctor deallocates this
  24.175 -    ///automatically allocated map, of course.
  24.176 -    ///\return <tt> (*this) </tt>
  24.177 -    Dijkstra &setPredMap(PredMap &m) 
  24.178 -    {
  24.179 -      if(local_predecessor) {
  24.180 -	delete predecessor;
  24.181 -	local_predecessor=false;
  24.182 -      }
  24.183 -      predecessor = &m;
  24.184 -      return *this;
  24.185 -    }
  24.186 -
  24.187 -    ///Sets the map storing the predecessor nodes.
  24.188 -
  24.189 -    ///Sets the map storing the predecessor nodes.
  24.190 -    ///If you don't use this function before calling \ref run(),
  24.191 -    ///it will allocate one. The destuctor deallocates this
  24.192 -    ///automatically allocated map, of course.
  24.193 -    ///\return <tt> (*this) </tt>
  24.194 -    Dijkstra &setPredNodeMap(PredNodeMap &m) 
  24.195 -    {
  24.196 -      if(local_pred_node) {
  24.197 -	delete pred_node;
  24.198 -	local_pred_node=false;
  24.199 -      }
  24.200 -      pred_node = &m;
  24.201 -      return *this;
  24.202 -    }
  24.203 -
  24.204 -    ///Sets the map storing the distances calculated by the algorithm.
  24.205 -
  24.206 -    ///Sets the map storing the distances calculated by the algorithm.
  24.207 -    ///If you don't use this function before calling \ref run(),
  24.208 -    ///it will allocate one. The destuctor deallocates this
  24.209 -    ///automatically allocated map, of course.
  24.210 -    ///\return <tt> (*this) </tt>
  24.211 -    Dijkstra &setDistMap(DistMap &m) 
  24.212 -    {
  24.213 -      if(local_distance) {
  24.214 -	delete distance;
  24.215 -	local_distance=false;
  24.216 -      }
  24.217 -      distance = &m;
  24.218 -      return *this;
  24.219 -    }
  24.220 -    
  24.221 -  ///Runs %Dijkstra algorithm from node \c s.
  24.222 -
  24.223 -  ///This method runs the %Dijkstra algorithm from a root node \c s
  24.224 -  ///in order to
  24.225 -  ///compute the
  24.226 -  ///shortest path to each node. The algorithm computes
  24.227 -  ///- The shortest path tree.
  24.228 -  ///- The distance of each node from the root.
  24.229 -    
  24.230 -    void run(Node s) {
  24.231 -      
  24.232 -      init_maps();
  24.233 -      
  24.234 -      source = s;
  24.235 -      
  24.236 -      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  24.237 -	predecessor->set(u,INVALID);
  24.238 -	pred_node->set(u,INVALID);
  24.239 -      }
  24.240 -      
  24.241 -      typename GR::template NodeMap<int> heap_map(*G,-1);
  24.242 -      
  24.243 -      typedef Heap<Node, ValueType, typename GR::template NodeMap<int>,
  24.244 -      std::less<ValueType> > 
  24.245 -      HeapType;
  24.246 -      
  24.247 -      HeapType heap(heap_map);
  24.248 -      
  24.249 -      heap.push(s,0); 
  24.250 -      
  24.251 -      while ( !heap.empty() ) {
  24.252 -	
  24.253 -	Node v=heap.top(); 
  24.254 -	ValueType oldvalue=heap[v];
  24.255 -	heap.pop();
  24.256 -	distance->set(v, oldvalue);
  24.257 -	
  24.258 -	
  24.259 -	for(OutEdgeIt e(*G,v); e!=INVALID; ++e) {
  24.260 -	  Node w=G->head(e); 
  24.261 -	  switch(heap.state(w)) {
  24.262 -	  case HeapType::PRE_HEAP:
  24.263 -	    heap.push(w,oldvalue+(*length)[e]); 
  24.264 -	    predecessor->set(w,e);
  24.265 -	    pred_node->set(w,v);
  24.266 -	    break;
  24.267 -	  case HeapType::IN_HEAP:
  24.268 -	    if ( oldvalue+(*length)[e] < heap[w] ) {
  24.269 -	      heap.decrease(w, oldvalue+(*length)[e]); 
  24.270 -	      predecessor->set(w,e);
  24.271 -	      pred_node->set(w,v);
  24.272 -	    }
  24.273 -	    break;
  24.274 -	  case HeapType::POST_HEAP:
  24.275 -	    break;
  24.276 -	  }
  24.277 -	}
  24.278 -      }
  24.279 -    }
  24.280 -    
  24.281 -    ///The distance of a node from the root.
  24.282 -
  24.283 -    ///Returns the distance of a node from the root.
  24.284 -    ///\pre \ref run() must be called before using this function.
  24.285 -    ///\warning If node \c v in unreachable from the root the return value
  24.286 -    ///of this funcion is undefined.
  24.287 -    ValueType dist(Node v) const { return (*distance)[v]; }
  24.288 -
  24.289 -    ///Returns the 'previous edge' of the shortest path tree.
  24.290 -
  24.291 -    ///For a node \c v it returns the 'previous edge' of the shortest path tree,
  24.292 -    ///i.e. it returns the last edge of a shortest path from the root to \c
  24.293 -    ///v. It is \ref INVALID
  24.294 -    ///if \c v is unreachable from the root or if \c v=s. The
  24.295 -    ///shortest path tree used here is equal to the shortest path tree used in
  24.296 -    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  24.297 -    ///this function.
  24.298 -    ///\todo predEdge could be a better name.
  24.299 -    Edge pred(Node v) const { return (*predecessor)[v]; }
  24.300 -
  24.301 -    ///Returns the 'previous node' of the shortest path tree.
  24.302 -
  24.303 -    ///For a node \c v it returns the 'previous node' of the shortest path tree,
  24.304 -    ///i.e. it returns the last but one node from a shortest path from the
  24.305 -    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
  24.306 -    ///\c v=s. The shortest path tree used here is equal to the shortest path
  24.307 -    ///tree used in \ref pred(Node v).  \pre \ref run() must be called before
  24.308 -    ///using this function.
  24.309 -    Node predNode(Node v) const { return (*pred_node)[v]; }
  24.310 -    
  24.311 -    ///Returns a reference to the NodeMap of distances.
  24.312 -
  24.313 -    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
  24.314 -    ///be called before using this function.
  24.315 -    const DistMap &distMap() const { return *distance;}
  24.316 - 
  24.317 -    ///Returns a reference to the shortest path tree map.
  24.318 -
  24.319 -    ///Returns a reference to the NodeMap of the edges of the
  24.320 -    ///shortest path tree.
  24.321 -    ///\pre \ref run() must be called before using this function.
  24.322 -    const PredMap &predMap() const { return *predecessor;}
  24.323 - 
  24.324 -    ///Returns a reference to the map of nodes of shortest paths.
  24.325 -
  24.326 -    ///Returns a reference to the NodeMap of the last but one nodes of the
  24.327 -    ///shortest path tree.
  24.328 -    ///\pre \ref run() must be called before using this function.
  24.329 -    const PredNodeMap &predNodeMap() const { return *pred_node;}
  24.330 -
  24.331 -    ///Checks if a node is reachable from the root.
  24.332 -
  24.333 -    ///Returns \c true if \c v is reachable from the root.
  24.334 -    ///\note The root node is reported to be reached!
  24.335 -    ///\pre \ref run() must be called before using this function.
  24.336 -    ///
  24.337 -    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  24.338 -    
  24.339 -  };
  24.340 -  
  24.341 -/// @}
  24.342 -  
  24.343 -} //END OF NAMESPACE HUGO
  24.344 -
  24.345 -#endif
  24.346 -
  24.347 -
    25.1 --- a/src/hugo/dimacs.h	Wed Sep 29 14:12:26 2004 +0000
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,207 +0,0 @@
    25.4 -/* -*- C++ -*-
    25.5 - * src/hugo/dimacs.h - Part of HUGOlib, a generic C++ optimization library
    25.6 - *
    25.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    25.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    25.9 - *
   25.10 - * Permission to use, modify and distribute this software is granted
   25.11 - * provided that this copyright notice appears in all copies. For
   25.12 - * precise terms see the accompanying LICENSE file.
   25.13 - *
   25.14 - * This software is provided "AS IS" with no warranty of any kind,
   25.15 - * express or implied, and with no claim as to its suitability for any
   25.16 - * purpose.
   25.17 - *
   25.18 - */
   25.19 -
   25.20 -#ifndef HUGO_DIMACS_H
   25.21 -#define HUGO_DIMACS_H
   25.22 -
   25.23 -#include <iostream>
   25.24 -#include <string>
   25.25 -#include <vector>
   25.26 -#include <hugo/maps.h>
   25.27 -
   25.28 -/// \ingroup misc
   25.29 -/// \file
   25.30 -/// \brief Dimacs file format reader.
   25.31 -
   25.32 -namespace hugo {
   25.33 -
   25.34 -
   25.35 -  /// \addtogroup misc
   25.36 -  /// @{
   25.37 -
   25.38 -  /// Dimacs min cost flow reader function.
   25.39 -
   25.40 -  /// This function reads a min cost flow instance from dimacs format,
   25.41 -  /// i.e. from dimacs files having a line starting with \c p \c "min".
   25.42 -  /// At the beginning \c g is cleared by \c g.clear(). The edge
   25.43 -  /// capacities are written to \c capacity, \c s and \c t are set to
   25.44 -  /// the source and the target nodes resp. and the cost of the edges
   25.45 -  /// are written to \c cost.
   25.46 -  ///
   25.47 -  /// \author Marton Makai
   25.48 -  template<typename Graph, typename CapacityMap, typename CostMap>
   25.49 -  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
   25.50 -		  typename Graph::Node &s, typename Graph::Node &t, 
   25.51 -		  CostMap& cost) {
   25.52 -    g.clear();
   25.53 -    typename CapacityMap::ValueType _cap;
   25.54 -    typename CostMap::ValueType _cost;
   25.55 -    char d;
   25.56 -    std::string problem;
   25.57 -    char c;
   25.58 -    int i, j;
   25.59 -    std::string str;
   25.60 -    int n, m; 
   25.61 -    typename Graph::Edge e;
   25.62 -    std::vector<typename Graph::Node> nodes;
   25.63 -    while (is>>c) {
   25.64 -      switch (c) {
   25.65 -      case 'c': //comment
   25.66 -	getline(is, str);
   25.67 -	break;
   25.68 -      case 'p': //problem definition
   25.69 -	is >> problem >> n >> m;
   25.70 -	getline(is, str);
   25.71 -	nodes.resize(n+1);
   25.72 -	for (int k=1; k<=n; ++k) nodes[k]=g.addNode();
   25.73 -	break;
   25.74 -      case 'n': //node definition
   25.75 -	if (problem=="sp") { //shortest path problem
   25.76 -	  is >> i;
   25.77 -	  getline(is, str);
   25.78 -	  s=nodes[i];
   25.79 -	}
   25.80 -	if (problem=="max" || problem=="min") { //((max) or (min cost)) flow problem
   25.81 -	  is >> i >> d;
   25.82 -	  getline(is, str);
   25.83 -	  if (d=='s') s=nodes[i];
   25.84 -	  if (d=='t') t=nodes[i];
   25.85 -	}
   25.86 -	break;
   25.87 -      case 'a':
   25.88 -	if ( problem == "max" || problem == "sp") {
   25.89 -	  is >> i >> j >> _cap;
   25.90 -	  getline(is, str);
   25.91 -	  e=g.addEdge(nodes[i], nodes[j]);
   25.92 -	  //capacity.update();
   25.93 -	  capacity.set(e, _cap);
   25.94 -	} else {
   25.95 -	  if ( problem == "min" ) {
   25.96 -	    is >> i >> j >> _cap >> _cost;
   25.97 -	    getline(is, str);
   25.98 -	    e=g.addEdge(nodes[i], nodes[j]);
   25.99 -	    //capacity.update();
  25.100 -	    capacity.set(e, _cap);
  25.101 -	    //cost.update();
  25.102 -	    cost.set(e, _cost);
  25.103 -	  } else {
  25.104 -	    is >> i >> j;
  25.105 -	    getline(is, str);
  25.106 -	    g.addEdge(nodes[i], nodes[j]);
  25.107 -	  }
  25.108 -	}
  25.109 -	break;
  25.110 -      }
  25.111 -    }
  25.112 -  }
  25.113 -
  25.114 -
  25.115 -  /// Dimacs max flow reader function.
  25.116 -
  25.117 -  /// This function reads a max flow instance from dimacs format,
  25.118 -  /// i.e. from dimacs files having a line starting with \c p \c
  25.119 -  /// "max".  At the beginning \c g is cleared by \c g.clear(). The
  25.120 -  /// edge capacities are written to \c capacity and \c s and \c t are
  25.121 -  /// set to the source and the target nodes.
  25.122 -  ///
  25.123 -  /// \author Marton Makai
  25.124 -  template<typename Graph, typename CapacityMap>
  25.125 -  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
  25.126 -		  typename Graph::Node &s, typename Graph::Node &t) {
  25.127 -    NullMap<typename Graph::Edge, int> n;
  25.128 -    readDimacs(is, g, capacity, s, t, n);
  25.129 -  }
  25.130 -
  25.131 -
  25.132 -  /// Dimacs shortest path reader function.
  25.133 -
  25.134 -  /// This function reads a shortest path instance from dimacs format,
  25.135 -  /// i.e. from dimacs files having a line starting with \c p \c "sp".
  25.136 -  /// At the beginning \c g is cleared by \c g.clear(). The edge
  25.137 -  /// capacities are written to \c capacity and \c s is set to the
  25.138 -  /// source node.
  25.139 -  ///
  25.140 -  /// \author Marton Makai
  25.141 -  template<typename Graph, typename CapacityMap>
  25.142 -  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
  25.143 -		  typename Graph::Node &s) {
  25.144 -    NullMap<typename Graph::Edge, int> n;
  25.145 -    readDimacs(is, g, capacity, s, s, n);
  25.146 -  }
  25.147 -
  25.148 -
  25.149 -  /// Dimacs capacitated graph reader function.
  25.150 -
  25.151 -  /// This function reads an edge capacitated graph instance from
  25.152 -  /// dimacs format.  At the beginning \c g is cleared by \c g.clear()
  25.153 -  /// and the edge capacities are written to \c capacity.
  25.154 -  ///
  25.155 -  /// \author Marton Makai
  25.156 -  template<typename Graph, typename CapacityMap>
  25.157 -  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity) {
  25.158 -    typename Graph::Node u;
  25.159 -    NullMap<typename Graph::Edge, int> n;
  25.160 -    readDimacs(is, g, capacity, u, u, n);
  25.161 -  }
  25.162 -
  25.163 -
  25.164 -  /// Dimacs plain graph reader function.
  25.165 -
  25.166 -  /// This function reads a graph without any designated nodes and
  25.167 -  /// maps from dimacs format, i.e. from dimacs files having a line
  25.168 -  /// starting with \c p \c "mat".  At the beginning \c g is cleared
  25.169 -  /// by \c g.clear().
  25.170 -  ///
  25.171 -  /// \author Marton Makai
  25.172 -  template<typename Graph>
  25.173 -  void readDimacs(std::istream& is, Graph &g) {
  25.174 -    typename Graph::Node u;
  25.175 -    NullMap<typename Graph::Edge, int> n;
  25.176 -    readDimacs(is, g, n, u, u, n);
  25.177 -  }
  25.178 -  
  25.179 -
  25.180 -
  25.181 -  
  25.182 -  /// write matching problem
  25.183 -  template<typename Graph>
  25.184 -  void writeDimacs(std::ostream& os, const Graph &g) {
  25.185 -    typedef typename Graph::NodeIt NodeIt;
  25.186 -    typedef typename Graph::EdgeIt EdgeIt;  
  25.187 -    
  25.188 -    typename Graph::template NodeMap<int> nodes(g);
  25.189 -
  25.190 -    os << "c matching problem" << std::endl;
  25.191 -
  25.192 -    int i=1;
  25.193 -    for(NodeIt v(g); v!=INVALID; ++v) {
  25.194 -      nodes.set(v, i);
  25.195 -      ++i;
  25.196 -    }    
  25.197 -    
  25.198 -    os << "p mat " << g.nodeNum() << " " << g.edgeNum() << std::endl;
  25.199 -
  25.200 -    for(EdgeIt e(g); e!=INVALID; ++e) {
  25.201 -      os << "a " << nodes[g.tail(e)] << " " << nodes[g.head(e)] << std::endl; 
  25.202 -    }
  25.203 -
  25.204 -  }
  25.205 -
  25.206 -  /// @}
  25.207 -
  25.208 -} //namespace hugo
  25.209 -
  25.210 -#endif //HUGO_DIMACS_H
    26.1 --- a/src/hugo/extended_pair.h	Wed Sep 29 14:12:26 2004 +0000
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,80 +0,0 @@
    26.4 -/* -*- C++ -*-
    26.5 - * src/hugo/extended_pair.h - Part of HUGOlib, a generic C++ optimization library
    26.6 - *
    26.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    26.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    26.9 - *
   26.10 - * Permission to use, modify and distribute this software is granted
   26.11 - * provided that this copyright notice appears in all copies. For
   26.12 - * precise terms see the accompanying LICENSE file.
   26.13 - *
   26.14 - * This software is provided "AS IS" with no warranty of any kind,
   26.15 - * express or implied, and with no claim as to its suitability for any
   26.16 - * purpose.
   26.17 - *
   26.18 - */
   26.19 -
   26.20 -#ifndef HUGO_EXTENDED_PAIR_H
   26.21 -#define HUGO_EXTENDED_PAIR_H
   26.22 -
   26.23 -template <typename T1, typename A1, typename T2, typename A2>
   26.24 -struct extended_pair {
   26.25 -  typedef T1 first_type;
   26.26 -  typedef T2 second_type;
   26.27 -
   26.28 -  extended_pair() : first(), second() {}
   26.29 -
   26.30 -  extended_pair(A1 f, A2 s) : first(f), second(s) {}
   26.31 -
   26.32 -  template <class Pair>
   26.33 -  extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
   26.34 -
   26.35 -  T1 first;
   26.36 -  T2 second;
   26.37 -};
   26.38 -
   26.39 -template <typename T1, typename T2, 
   26.40 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.41 -bool operator==(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.42 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.43 -  return left.first == right.first && left.second == right.second;
   26.44 -}
   26.45 -
   26.46 -template <typename T1, typename T2, 
   26.47 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.48 -bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.49 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.50 -  return  !(left == right);
   26.51 -}
   26.52 -
   26.53 -template <typename T1, typename T2, 
   26.54 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.55 -bool operator<(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.56 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.57 -  return left.first < right.first || 
   26.58 -           (!(right.first<left.first) && left.second < right.second);
   26.59 -}
   26.60 -
   26.61 -template <typename T1, typename T2, 
   26.62 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.63 -bool operator>(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.64 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.65 -  return right < left;
   26.66 -}
   26.67 -
   26.68 -template <typename T1, typename T2, 
   26.69 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.70 -bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.71 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.72 -  return !(right > left);
   26.73 -}
   26.74 -
   26.75 -template <typename T1, typename T2, 
   26.76 -	  typename LA1, typename LA2, typename RA1, typename RA2>
   26.77 -bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left, 
   26.78 -		const extended_pair<T1, RA1, T2, RA2>& right) {
   26.79 -  return !(right < left);
   26.80 -}
   26.81 -
   26.82 -
   26.83 -#endif
    27.1 --- a/src/hugo/fib_heap.h	Wed Sep 29 14:12:26 2004 +0000
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,510 +0,0 @@
    27.4 -/* -*- C++ -*-
    27.5 - * src/hugo/fib_heap.h - Part of HUGOlib, a generic C++ optimization library
    27.6 - *
    27.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    27.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    27.9 - *
   27.10 - * Permission to use, modify and distribute this software is granted
   27.11 - * provided that this copyright notice appears in all copies. For
   27.12 - * precise terms see the accompanying LICENSE file.
   27.13 - *
   27.14 - * This software is provided "AS IS" with no warranty of any kind,
   27.15 - * express or implied, and with no claim as to its suitability for any
   27.16 - * purpose.
   27.17 - *
   27.18 - */
   27.19 -
   27.20 -#ifndef HUGO_FIB_HEAP_H
   27.21 -#define HUGO_FIB_HEAP_H
   27.22 -
   27.23 -///\file
   27.24 -///\ingroup auxdat
   27.25 -///\brief Fibonacci Heap implementation.
   27.26 -
   27.27 -#include <vector>
   27.28 -#include <functional>
   27.29 -#include <math.h>
   27.30 -
   27.31 -namespace hugo {
   27.32 -  
   27.33 -  /// \addtogroup auxdat
   27.34 -  /// @{
   27.35 -
   27.36 -  /// Fibonacci Heap.
   27.37 -
   27.38 -  ///This class implements the \e Fibonacci \e heap data structure. A \e heap
   27.39 -  ///is a data structure for storing items with specified values called \e
   27.40 -  ///priorities in such a way that finding the item with minimum priority is
   27.41 -  ///efficient. \c Compare specifies the ordering of the priorities. In a heap
   27.42 -  ///one can change the priority of an item, add or erase an item, etc.
   27.43 -  ///
   27.44 -  ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
   27.45 -  ///heap. In case of many calls to these operations, it is better to use a
   27.46 -  ///\e binary \e heap.
   27.47 -  ///
   27.48 -  ///\param Item Type of the items to be stored.  
   27.49 -  ///\param Prio Type of the priority of the items.
   27.50 -  ///\param ItemIntMap A read and writable Item int map, for the usage of
   27.51 -  ///the heap.
   27.52 -  ///\param Compare A class for the ordering of the priorities. The
   27.53 -  ///default is \c std::less<Prio>.
   27.54 -  ///
   27.55 -  ///\author Jacint Szabo 
   27.56 - 
   27.57 -#ifdef DOXYGEN
   27.58 -  template <typename Item, 
   27.59 -	    typename Prio, 
   27.60 -	    typename ItemIntMap, 
   27.61 -	    typename Compare>
   27.62 -#else
   27.63 -  template <typename Item, 
   27.64 -	    typename Prio, 
   27.65 -	    typename ItemIntMap, 
   27.66 -	    typename Compare = std::less<Prio> >
   27.67 -#endif
   27.68 -  class FibHeap {
   27.69 -  public:     
   27.70 -    typedef Prio PrioType;
   27.71 -    
   27.72 -  private:
   27.73 -    class store;
   27.74 -    
   27.75 -    std::vector<store> container;
   27.76 -    int minimum;
   27.77 -    ItemIntMap &iimap;
   27.78 -    Compare comp;
   27.79 -    int num_items;
   27.80 -    
   27.81 -  public:
   27.82 -    enum state_enum {
   27.83 -      IN_HEAP = 0,
   27.84 -      PRE_HEAP = -1,
   27.85 -      POST_HEAP = -2
   27.86 -    };
   27.87 -    
   27.88 -    FibHeap(ItemIntMap &_iimap) : minimum(0), iimap(_iimap), num_items() {} 
   27.89 -    FibHeap(ItemIntMap &_iimap, const Compare &_comp) : minimum(0), 
   27.90 -      iimap(_iimap), comp(_comp), num_items() {}
   27.91 -    
   27.92 -    ///The number of items stored in the heap.
   27.93 -
   27.94 -    /**
   27.95 -       Returns the number of items stored in the heap.
   27.96 -    */
   27.97 -    int size() const { return num_items; }
   27.98 -
   27.99 -    ///Checks if the heap stores no items.
  27.100 -    
  27.101 -    /**
  27.102 -       Returns \c true if and only if the heap stores no items.
  27.103 -    */
  27.104 -    bool empty() const { return num_items==0; }
  27.105 -
  27.106 -    ///\c item gets to the heap with priority \c value independently if \c item was already there.
  27.107 -
  27.108 -    /**
  27.109 -       This method calls \ref push(\c item, \c value) if \c item is not
  27.110 -       stored in the heap and it calls \ref decrease(\c item, \c value) or
  27.111 -       \ref increase(\c item, \c value) otherwise.
  27.112 -    */
  27.113 -    void set (Item const item, PrioType const value); 
  27.114 -    
  27.115 -    ///Adds \c item to the heap with priority \c value. 
  27.116 -    
  27.117 -    /**
  27.118 -       Adds \c item to the heap with priority \c value. 
  27.119 -       \pre \c item must not be stored in the heap. 
  27.120 -    */
  27.121 -    void push (Item const item, PrioType const value);
  27.122 -    
  27.123 -    ///Returns the item with minimum priority relative to \c Compare.
  27.124 -    
  27.125 -    /**
  27.126 -       This method returns the item with minimum priority relative to \c
  27.127 -       Compare.  
  27.128 -       \pre The heap must be nonempty.  
  27.129 -    */
  27.130 -    Item top() const { return container[minimum].name; }
  27.131 -
  27.132 -    ///Returns the minimum priority relative to \c Compare.
  27.133 -
  27.134 -    /**
  27.135 -       It returns the minimum priority relative to \c Compare.
  27.136 -       \pre The heap must be nonempty.
  27.137 -    */
  27.138 -    PrioType prio() const { return container[minimum].prio; }
  27.139 -    
  27.140 -    ///Returns the priority of \c item.
  27.141 -
  27.142 -    /**
  27.143 -       This function returns the priority of \c item.
  27.144 -       \pre \c item must be in the heap.
  27.145 -    */
  27.146 -    PrioType& operator[](const Item& item) { 
  27.147 -      return container[iimap[item]].prio; 
  27.148 -    }
  27.149 -    
  27.150 -    ///Returns the priority of \c item.
  27.151 -    
  27.152 -    /**
  27.153 -       It returns the priority of \c item.
  27.154 -       \pre \c item must be in the heap.
  27.155 -    */
  27.156 -    const PrioType& operator[](const Item& item) const { 
  27.157 -      return container[iimap[item]].prio; 
  27.158 -    }
  27.159 -
  27.160 -
  27.161 -    ///Deletes the item with minimum priority relative to \c Compare.
  27.162 -
  27.163 -    /**
  27.164 -    This method deletes the item with minimum priority relative to \c
  27.165 -    Compare from the heap.  
  27.166 -    \pre The heap must be non-empty.  
  27.167 -    */
  27.168 -    void pop();
  27.169 -
  27.170 -    ///Deletes \c item from the heap.
  27.171 -
  27.172 -    /**
  27.173 -       This method deletes \c item from the heap, if \c item was already
  27.174 -       stored in the heap. It is quite inefficient in Fibonacci heaps.
  27.175 -    */
  27.176 -    void erase (const Item& item); 
  27.177 -
  27.178 -    ///Decreases the priority of \c item to \c value.
  27.179 -
  27.180 -    /**
  27.181 -       This method decreases the priority of \c item to \c value.
  27.182 -       \pre \c item must be stored in the heap with priority at least \c
  27.183 -       value relative to \c Compare.
  27.184 -    */
  27.185 -    void decrease (Item item, PrioType const value); 
  27.186 -
  27.187 -    ///Increases the priority of \c item to \c value.
  27.188 -
  27.189 -    /**
  27.190 -       This method sets the priority of \c item to \c value. Though
  27.191 -       there is no precondition on the priority of \c item, this
  27.192 -       method should be used only if it is indeed necessary to increase
  27.193 -       (relative to \c Compare) the priority of \c item, because this
  27.194 -       method is inefficient.
  27.195 -    */
  27.196 -    void increase (Item item, PrioType const value) {
  27.197 -      erase(item);
  27.198 -      push(item, value);
  27.199 -    }
  27.200 -
  27.201 -
  27.202 -    ///Returns if \c item is in, has already been in, or has never been in the heap.
  27.203 -
  27.204 -    /**
  27.205 -       This method returns PRE_HEAP if \c item has never been in the
  27.206 -       heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  27.207 -       otherwise. In the latter case it is possible that \c item will
  27.208 -       get back to the heap again.
  27.209 -    */
  27.210 -    state_enum state(const Item &item) const {
  27.211 -      int i=iimap[item];
  27.212 -      if( i>=0 ) {
  27.213 -	if ( container[i].in ) i=0;
  27.214 -	else i=-2; 
  27.215 -      }
  27.216 -      return state_enum(i);
  27.217 -    }    
  27.218 -    
  27.219 -  private:
  27.220 -    
  27.221 -    void balance();
  27.222 -    void makeroot(int c);
  27.223 -    void cut(int a, int b);
  27.224 -    void cascade(int a);
  27.225 -    void fuse(int a, int b);
  27.226 -    void unlace(int a);
  27.227 -
  27.228 -
  27.229 -    class store {
  27.230 -      friend class FibHeap;
  27.231 -      
  27.232 -      Item name;
  27.233 -      int parent;
  27.234 -      int left_neighbor;
  27.235 -      int right_neighbor;
  27.236 -      int child;
  27.237 -      int degree;  
  27.238 -      bool marked;
  27.239 -      bool in;
  27.240 -      PrioType prio;
  27.241 -      
  27.242 -      store() : parent(-1), child(-1), degree(), marked(false), in(true) {} 
  27.243 -    };
  27.244 -  };    
  27.245 - 
  27.246 -
  27.247 -
  27.248 -    // **********************************************************************
  27.249 -    //  IMPLEMENTATIONS
  27.250 -    // **********************************************************************
  27.251 -    
  27.252 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.253 -    typename Compare>
  27.254 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::set 
  27.255 -  (Item const item, PrioType const value) 
  27.256 -  {
  27.257 -    int i=iimap[item];
  27.258 -    if ( i >= 0 && container[i].in ) {
  27.259 -      if ( comp(value, container[i].prio) ) decrease(item, value); 
  27.260 -      if ( comp(container[i].prio, value) ) increase(item, value); 
  27.261 -    } else push(item, value);
  27.262 -  }
  27.263 -    
  27.264 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.265 -    typename Compare>
  27.266 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::push 
  27.267 -  (Item const item, PrioType const value) {
  27.268 -      int i=iimap[item];      
  27.269 -      if ( i < 0 ) {
  27.270 -	int s=container.size();
  27.271 -	iimap.set( item, s );	
  27.272 -	store st;
  27.273 -	st.name=item;
  27.274 -	container.push_back(st);
  27.275 -	i=s;
  27.276 -      } else {
  27.277 -	container[i].parent=container[i].child=-1;
  27.278 -	container[i].degree=0;
  27.279 -	container[i].in=true;
  27.280 -	container[i].marked=false;
  27.281 -      }
  27.282 -
  27.283 -      if ( num_items ) {
  27.284 -	container[container[minimum].right_neighbor].left_neighbor=i;
  27.285 -	container[i].right_neighbor=container[minimum].right_neighbor;
  27.286 -	container[minimum].right_neighbor=i;
  27.287 -	container[i].left_neighbor=minimum;
  27.288 -	if ( comp( value, container[minimum].prio) ) minimum=i; 
  27.289 -      } else {
  27.290 -	container[i].right_neighbor=container[i].left_neighbor=i;
  27.291 -	minimum=i;	
  27.292 -      }
  27.293 -      container[i].prio=value;
  27.294 -      ++num_items;
  27.295 -    }
  27.296 -    
  27.297 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.298 -    typename Compare>
  27.299 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::pop() {
  27.300 -      /*The first case is that there are only one root.*/
  27.301 -      if ( container[minimum].left_neighbor==minimum ) {
  27.302 -	container[minimum].in=false;
  27.303 -	if ( container[minimum].degree!=0 ) { 
  27.304 -	  makeroot(container[minimum].child);
  27.305 -	  minimum=container[minimum].child;
  27.306 -	  balance();
  27.307 -	}
  27.308 -      } else {
  27.309 -	int right=container[minimum].right_neighbor;
  27.310 -	unlace(minimum);
  27.311 -	container[minimum].in=false;
  27.312 -	if ( container[minimum].degree > 0 ) {
  27.313 -	  int left=container[minimum].left_neighbor;
  27.314 -	  int child=container[minimum].child;
  27.315 -	  int last_child=container[child].left_neighbor;
  27.316 -	
  27.317 -	  makeroot(child);
  27.318 -	  
  27.319 -	  container[left].right_neighbor=child;
  27.320 -	  container[child].left_neighbor=left;
  27.321 -	  container[right].left_neighbor=last_child;
  27.322 -	  container[last_child].right_neighbor=right;
  27.323 -	}
  27.324 -	minimum=right;
  27.325 -	balance();
  27.326 -      } // the case where there are more roots
  27.327 -      --num_items;   
  27.328 -    }
  27.329 -
  27.330 -
  27.331 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.332 -    typename Compare>
  27.333 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::erase 
  27.334 -  (const Item& item) {
  27.335 -      int i=iimap[item];
  27.336 -      
  27.337 -      if ( i >= 0 && container[i].in ) { 	
  27.338 -	if ( container[i].parent!=-1 ) {
  27.339 -	  int p=container[i].parent;
  27.340 -	  cut(i,p);	    
  27.341 -	  cascade(p);
  27.342 -	}
  27.343 -	minimum=i;     //As if its prio would be -infinity
  27.344 -	pop();
  27.345 -      }
  27.346 -  }
  27.347 -    
  27.348 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.349 -    typename Compare>
  27.350 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::decrease 
  27.351 -  (Item item, PrioType const value) {
  27.352 -      int i=iimap[item];
  27.353 -      container[i].prio=value;
  27.354 -      int p=container[i].parent;
  27.355 -      
  27.356 -      if ( p!=-1 && comp(value, container[p].prio) ) {
  27.357 -	cut(i,p);	    
  27.358 -	cascade(p);
  27.359 -      }      
  27.360 -      if ( comp(value, container[minimum].prio) ) minimum=i; 
  27.361 -  }
  27.362 - 
  27.363 -
  27.364 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.365 -    typename Compare>
  27.366 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::balance() {      
  27.367 -
  27.368 -    int maxdeg=int( floor( 2.08*log(double(container.size()))))+1;
  27.369 -  
  27.370 -    std::vector<int> A(maxdeg,-1); 
  27.371 -    
  27.372 -    /*
  27.373 -     *Recall that now minimum does not point to the minimum prio element.
  27.374 -     *We set minimum to this during balance().
  27.375 -     */
  27.376 -    int anchor=container[minimum].left_neighbor; 
  27.377 -    int next=minimum; 
  27.378 -    bool end=false; 
  27.379 -    	
  27.380 -       do {
  27.381 -	int active=next;
  27.382 -	if ( anchor==active ) end=true;
  27.383 -	int d=container[active].degree;
  27.384 -	next=container[active].right_neighbor;
  27.385 -
  27.386 -	while (A[d]!=-1) {	  
  27.387 -	  if( comp(container[active].prio, container[A[d]].prio) ) {
  27.388 -	    fuse(active,A[d]); 
  27.389 -	  } else { 
  27.390 -	    fuse(A[d],active);
  27.391 -	    active=A[d];
  27.392 -	  } 
  27.393 -	  A[d]=-1;
  27.394 -	  ++d;
  27.395 -	}	
  27.396 -	A[d]=active;
  27.397 -       } while ( !end );
  27.398 -
  27.399 -
  27.400 -       while ( container[minimum].parent >=0 ) minimum=container[minimum].parent;
  27.401 -       int s=minimum;
  27.402 -       int m=minimum;
  27.403 -       do {  
  27.404 -	 if ( comp(container[s].prio, container[minimum].prio) ) minimum=s;
  27.405 -	 s=container[s].right_neighbor;
  27.406 -       } while ( s != m );
  27.407 -    }
  27.408 -
  27.409 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.410 -    typename Compare>
  27.411 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::makeroot 
  27.412 -  (int c) {
  27.413 -      int s=c;
  27.414 -      do {  
  27.415 -	container[s].parent=-1;
  27.416 -	s=container[s].right_neighbor;
  27.417 -      } while ( s != c );
  27.418 -    }
  27.419 -  
  27.420 -  
  27.421 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.422 -    typename Compare>
  27.423 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::cut 
  27.424 -  (int a, int b) {    
  27.425 -    /*
  27.426 -     *Replacing a from the children of b.
  27.427 -     */
  27.428 -    --container[b].degree;
  27.429 -    
  27.430 -    if ( container[b].degree !=0 ) {
  27.431 -      int child=container[b].child;
  27.432 -      if ( child==a ) 
  27.433 -	container[b].child=container[child].right_neighbor;
  27.434 -      unlace(a);
  27.435 -    }
  27.436 -    
  27.437 -    
  27.438 -    /*Lacing a to the roots.*/
  27.439 -    int right=container[minimum].right_neighbor;
  27.440 -    container[minimum].right_neighbor=a;
  27.441 -    container[a].left_neighbor=minimum;
  27.442 -    container[a].right_neighbor=right;
  27.443 -    container[right].left_neighbor=a;
  27.444 -    
  27.445 -    container[a].parent=-1;
  27.446 -    container[a].marked=false;
  27.447 -  }
  27.448 -  
  27.449 -
  27.450 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.451 -    typename Compare>
  27.452 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::cascade 
  27.453 -  (int a) 
  27.454 -    {
  27.455 -      if ( container[a].parent!=-1 ) {
  27.456 -	int p=container[a].parent;
  27.457 -	
  27.458 -	if ( container[a].marked==false ) container[a].marked=true;
  27.459 -	else {
  27.460 -	  cut(a,p);
  27.461 -	  cascade(p);
  27.462 -	}
  27.463 -      }
  27.464 -    }
  27.465 -
  27.466 -
  27.467 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.468 -    typename Compare>
  27.469 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::fuse 
  27.470 -  (int a, int b) {
  27.471 -      unlace(b);
  27.472 -      
  27.473 -      /*Lacing b under a.*/
  27.474 -      container[b].parent=a;
  27.475 -
  27.476 -      if (container[a].degree==0) {
  27.477 -	container[b].left_neighbor=b;
  27.478 -	container[b].right_neighbor=b;
  27.479 -	container[a].child=b;	
  27.480 -      } else {
  27.481 -	int child=container[a].child;
  27.482 -	int last_child=container[child].left_neighbor;
  27.483 -	container[child].left_neighbor=b;
  27.484 -	container[b].right_neighbor=child;
  27.485 -	container[last_child].right_neighbor=b;
  27.486 -	container[b].left_neighbor=last_child;
  27.487 -      }
  27.488 -
  27.489 -      ++container[a].degree;
  27.490 -      
  27.491 -      container[b].marked=false;
  27.492 -    }
  27.493 -
  27.494 -  
  27.495 -  /*
  27.496 -   *It is invoked only if a has siblings.
  27.497 -   */
  27.498 -  template <typename Item, typename Prio, typename ItemIntMap, 
  27.499 -    typename Compare>
  27.500 -  void FibHeap<Item, Prio, ItemIntMap, Compare>::unlace 
  27.501 -  (int a) {      
  27.502 -      int leftn=container[a].left_neighbor;
  27.503 -      int rightn=container[a].right_neighbor;
  27.504 -      container[leftn].right_neighbor=rightn;
  27.505 -      container[rightn].left_neighbor=leftn;
  27.506 -  }
  27.507 -  
  27.508 -  ///@}
  27.509 -
  27.510 -} //namespace hugo
  27.511 -
  27.512 -#endif //HUGO_FIB_HEAP_H
  27.513 -
    28.1 --- a/src/hugo/full_graph.h	Wed Sep 29 14:12:26 2004 +0000
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,248 +0,0 @@
    28.4 -/* -*- C++ -*-
    28.5 - * src/hugo/full_graph.h - Part of HUGOlib, a generic C++ optimization library
    28.6 - *
    28.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    28.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    28.9 - *
   28.10 - * Permission to use, modify and distribute this software is granted
   28.11 - * provided that this copyright notice appears in all copies. For
   28.12 - * precise terms see the accompanying LICENSE file.
   28.13 - *
   28.14 - * This software is provided "AS IS" with no warranty of any kind,
   28.15 - * express or implied, and with no claim as to its suitability for any
   28.16 - * purpose.
   28.17 - *
   28.18 - */
   28.19 -
   28.20 -#ifndef HUGO_FULL_GRAPH_H
   28.21 -#define HUGO_FULL_GRAPH_H
   28.22 -
   28.23 -///\ingroup graphs
   28.24 -///\file
   28.25 -///\brief FullGraph and SymFullGraph classes.
   28.26 -
   28.27 -#include <vector>
   28.28 -#include <climits>
   28.29 -
   28.30 -#include <hugo/invalid.h>
   28.31 -
   28.32 -#include <hugo/map_registry.h>
   28.33 -#include <hugo/array_map.h>
   28.34 -
   28.35 -#include <hugo/map_defines.h>
   28.36 -
   28.37 -namespace hugo {
   28.38 -
   28.39 -/// \addtogroup graphs
   28.40 -/// @{
   28.41 -
   28.42 -  ///A full graph class.
   28.43 -
   28.44 -  ///This is a simple and fast directed full graph implementation.
   28.45 -  ///It is completely static, so you can neither add nor delete either
   28.46 -  ///edges or nodes.
   28.47 -  ///Thus it conforms to
   28.48 -  ///the \ref skeleton::StaticGraph "StaticGraph" concept
   28.49 -  ///\sa skeleton::StaticGraph.
   28.50 -  ///\todo What about loops?
   28.51 -  ///\todo Don't we need SymEdgeMap?
   28.52 -  ///
   28.53 -  ///\author Alpar Juttner
   28.54 -  class FullGraph {
   28.55 -    int NodeNum;
   28.56 -    int EdgeNum;
   28.57 -  public:
   28.58 -
   28.59 -    typedef FullGraph Graph;
   28.60 -
   28.61 -    class Node;
   28.62 -    class Edge;
   28.63 -
   28.64 -    class NodeIt;
   28.65 -    class EdgeIt;
   28.66 -    class OutEdgeIt;
   28.67 -    class InEdgeIt;
   28.68 -    
   28.69 -
   28.70 -    // Create map registries.
   28.71 -    CREATE_MAP_REGISTRIES;
   28.72 -    // Create node and edge maps.
   28.73 -    CREATE_MAPS(ArrayMap);
   28.74 -    
   28.75 -  public:
   28.76 -
   28.77 -    ///Creates a full graph with \c n nodes.
   28.78 -    FullGraph(int n) : NodeNum(n), EdgeNum(NodeNum*NodeNum) { }
   28.79 -    ///
   28.80 -    FullGraph(const FullGraph &_g)
   28.81 -      : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { }
   28.82 -    
   28.83 -    ///Number of nodes.
   28.84 -    int nodeNum() const { return NodeNum; }
   28.85 -    ///Number of edges.
   28.86 -    int edgeNum() const { return EdgeNum; }
   28.87 -
   28.88 -    /// Maximum node ID.
   28.89 -    
   28.90 -    /// Maximum node ID.
   28.91 -    ///\sa id(Node)
   28.92 -    int maxNodeId() const { return NodeNum-1; }
   28.93 -    /// Maximum edge ID.
   28.94 -    
   28.95 -    /// Maximum edge ID.
   28.96 -    ///\sa id(Edge)
   28.97 -    int maxEdgeId() const { return EdgeNum-1; }
   28.98 -
   28.99 -    Node tail(Edge e) const { return e.n%NodeNum; }
  28.100 -    Node head(Edge e) const { return e.n/NodeNum; }
  28.101 -
  28.102 -    NodeIt& first(NodeIt& v) const {
  28.103 -      v=NodeIt(*this); return v; }
  28.104 -    EdgeIt& first(EdgeIt& e) const { 
  28.105 -      e=EdgeIt(*this); return e; }
  28.106 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  28.107 -      e=OutEdgeIt(*this,v); return e; }
  28.108 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  28.109 -      e=InEdgeIt(*this,v); return e; }
  28.110 -
  28.111 -    /// Node ID.
  28.112 -    
  28.113 -    /// The ID of a valid Node is a nonnegative integer not greater than
  28.114 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  28.115 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  28.116 -    ///
  28.117 -    /// The ID of the \ref INVALID node is -1.
  28.118 -    ///\return The ID of the node \c v. 
  28.119 -    static int id(Node v) { return v.n; }
  28.120 -    /// Edge ID.
  28.121 -    
  28.122 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  28.123 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  28.124 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  28.125 -    ///
  28.126 -    /// The ID of the \ref INVALID edge is -1.
  28.127 -    ///\return The ID of the edge \c e. 
  28.128 -    static int id(Edge e) { return e.n; }
  28.129 -
  28.130 -    /// Finds an edge between two nodes.
  28.131 -    
  28.132 -    /// Finds an edge from node \c u to node \c v.
  28.133 -    ///
  28.134 -    /// If \c prev is \ref INVALID (this is the default value), then
  28.135 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  28.136 -    /// the next edge from \c u to \c v after \c prev.
  28.137 -    /// \return The found edge or INVALID if there is no such an edge.
  28.138 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  28.139 -    {
  28.140 -      return prev.n == -1 ? Edge(*this, u.n, v.n) : INVALID;
  28.141 -    }
  28.142 -    
  28.143 -      
  28.144 -    class Node {
  28.145 -      friend class FullGraph;
  28.146 -      template <typename T> friend class NodeMap;
  28.147 -
  28.148 -      friend class Edge;
  28.149 -      friend class OutEdgeIt;
  28.150 -      friend class InEdgeIt;
  28.151 -      friend class SymEdge;
  28.152 -
  28.153 -    protected:
  28.154 -      int n;
  28.155 -      friend int FullGraph::id(Node v); 
  28.156 -      Node(int nn) {n=nn;}
  28.157 -    public:
  28.158 -      Node() {}
  28.159 -      Node (Invalid) { n=-1; }
  28.160 -      bool operator==(const Node i) const {return n==i.n;}
  28.161 -      bool operator!=(const Node i) const {return n!=i.n;}
  28.162 -      bool operator<(const Node i) const {return n<i.n;}
  28.163 -    };
  28.164 -    
  28.165 -    class NodeIt : public Node {
  28.166 -      const FullGraph *G;
  28.167 -      friend class FullGraph;
  28.168 -    public:
  28.169 -      NodeIt() : Node() { }
  28.170 -      NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { }
  28.171 -      NodeIt(Invalid i) : Node(i) { }
  28.172 -      NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { }
  28.173 -      ///\todo Undocumented conversion Node -\> NodeIt.
  28.174 -      NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; }
  28.175 -    };
  28.176 -
  28.177 -    class Edge {
  28.178 -      friend class FullGraph;
  28.179 -      template <typename T> friend class EdgeMap;
  28.180 -      
  28.181 -      friend class Node;
  28.182 -      friend class NodeIt;
  28.183 -    protected:
  28.184 -      int n; //NodeNum*head+tail;
  28.185 -      friend int FullGraph::id(Edge e);
  28.186 -
  28.187 -      Edge(int nn) : n(nn) {}
  28.188 -      Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
  28.189 -    public:
  28.190 -      Edge() { }
  28.191 -      Edge (Invalid) { n=-1; }
  28.192 -      bool operator==(const Edge i) const {return n==i.n;}
  28.193 -      bool operator!=(const Edge i) const {return n!=i.n;}
  28.194 -      bool operator<(const Edge i) const {return n<i.n;}
  28.195 -      ///\bug This is a workaround until somebody tells me how to
  28.196 -      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  28.197 -      int &idref() {return n;}
  28.198 -      const int &idref() const {return n;}
  28.199 -    };
  28.200 -    
  28.201 -    class EdgeIt : public Edge {
  28.202 -      friend class FullGraph;
  28.203 -    public:
  28.204 -      EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { }
  28.205 -      EdgeIt(const FullGraph&, Edge e) : Edge(e) { }
  28.206 -      EdgeIt (Invalid i) : Edge(i) { }
  28.207 -      EdgeIt() : Edge() { }
  28.208 -      EdgeIt& operator++() { --n; return *this; }
  28.209 -
  28.210 -      ///\bug This is a workaround until somebody tells me how to
  28.211 -      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  28.212 -      int &idref() {return n;}
  28.213 -    };
  28.214 -    
  28.215 -    class OutEdgeIt : public Edge {
  28.216 -      const FullGraph *G;
  28.217 -      friend class FullGraph;
  28.218 -    public: 
  28.219 -      OutEdgeIt() : Edge() { }
  28.220 -      OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  28.221 -      OutEdgeIt (Invalid i) : Edge(i) { }
  28.222 -
  28.223 -      OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {}
  28.224 -      
  28.225 -      OutEdgeIt& operator++()
  28.226 -      { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; }
  28.227 -
  28.228 -    };
  28.229 -    
  28.230 -    class InEdgeIt : public Edge {
  28.231 -      const FullGraph *G;
  28.232 -      friend class FullGraph;
  28.233 -    public: 
  28.234 -      InEdgeIt() : Edge() { }
  28.235 -      InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  28.236 -      InEdgeIt (Invalid i) : Edge(i) { }
  28.237 -      InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {}
  28.238 -      InEdgeIt& operator++()
  28.239 -      { if(!((++n)%G->NodeNum)) n=-1; return *this; }
  28.240 -    };
  28.241 -
  28.242 -  };
  28.243 -
  28.244 -  /// @}  
  28.245 -
  28.246 -} //namespace hugo
  28.247 -
  28.248 -
  28.249 -
  28.250 -
  28.251 -#endif //HUGO_FULL_GRAPH_H
    29.1 --- a/src/hugo/graph_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,1227 +0,0 @@
    29.4 -/* -*- C++ -*-
    29.5 - * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
    29.6 - *
    29.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    29.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    29.9 - *
   29.10 - * Permission to use, modify and distribute this software is granted
   29.11 - * provided that this copyright notice appears in all copies. For
   29.12 - * precise terms see the accompanying LICENSE file.
   29.13 - *
   29.14 - * This software is provided "AS IS" with no warranty of any kind,
   29.15 - * express or implied, and with no claim as to its suitability for any
   29.16 - * purpose.
   29.17 - *
   29.18 - */
   29.19 -
   29.20 -#ifndef HUGO_GRAPH_WRAPPER_H
   29.21 -#define HUGO_GRAPH_WRAPPER_H
   29.22 -
   29.23 -///\ingroup gwrappers
   29.24 -///\file
   29.25 -///\brief Several graph wrappers.
   29.26 -///
   29.27 -///This file contains several useful graph wrapper functions.
   29.28 -///
   29.29 -///\author Marton Makai
   29.30 -
   29.31 -#include <hugo/invalid.h>
   29.32 -#include <hugo/maps.h>
   29.33 -#include <hugo/map_defines.h>
   29.34 -#include <iostream>
   29.35 -
   29.36 -namespace hugo {
   29.37 -
   29.38 -  // Graph wrappers
   29.39 -
   29.40 -  /// \addtogroup gwrappers
   29.41 -  /// A main parts of HUGOlib are the different graph structures, 
   29.42 -  /// generic graph algorithms, graph concepts which couple these, and 
   29.43 -  /// graph wrappers. While the previous ones are more or less clear, the 
   29.44 -  /// latter notion needs further explanation.
   29.45 -  /// Graph wrappers are graph classes which serve for considering graph 
   29.46 -  /// structures in different ways. A short example makes the notion much 
   29.47 -  /// clearer. 
   29.48 -  /// Suppose that we have an instance \c g of a directed graph
   29.49 -  /// type say \c ListGraph and an algorithm 
   29.50 -  /// \code template<typename Graph> int algorithm(const Graph&); \endcode 
   29.51 -  /// is needed to run on the reversely oriented graph. 
   29.52 -  /// It may be expensive (in time or in memory usage) to copy 
   29.53 -  /// \c g with the reverse orientation. 
   29.54 -  /// Thus, a wrapper class
   29.55 -  /// \code template<typename Graph> class RevGraphWrapper; \endcode is used. 
   29.56 -  /// The code looks as follows
   29.57 -  /// \code
   29.58 -  /// ListGraph g;
   29.59 -  /// RevGraphWrapper<ListGraph> rgw(g);
   29.60 -  /// int result=algorithm(rgw);
   29.61 -  /// \endcode
   29.62 -  /// After running the algorithm, the original graph \c g 
   29.63 -  /// remains untouched. Thus the graph wrapper used above is to consider the 
   29.64 -  /// original graph with reverse orientation. 
   29.65 -  /// This techniques gives rise to an elegant code, and 
   29.66 -  /// based on stable graph wrappers, complex algorithms can be 
   29.67 -  /// implemented easily. 
   29.68 -  /// In flow, circulation and bipartite matching problems, the residual 
   29.69 -  /// graph is of particular importance. Combining a wrapper implementing 
   29.70 -  /// this, shortest path algorithms and minimum mean cycle algorithms, 
   29.71 -  /// a range of weighted and cardinality optimization algorithms can be 
   29.72 -  /// obtained. For lack of space, for other examples, 
   29.73 -  /// the interested user is referred to the detailed documentation of graph 
   29.74 -  /// wrappers. 
   29.75 -  /// The behavior of graph wrappers can be very different. Some of them keep 
   29.76 -  /// capabilities of the original graph while in other cases this would be 
   29.77 -  /// meaningless. This means that the concepts that they are a model of depend 
   29.78 -  /// on the graph wrapper, and the wrapped graph(s). 
   29.79 -  /// If an edge of \c rgw is deleted, this is carried out by 
   29.80 -  /// deleting the corresponding edge of \c g. But for a residual 
   29.81 -  /// graph, this operation has no sense. 
   29.82 -  /// Let we stand one more example here to simplify your work. 
   29.83 -  /// wrapper class
   29.84 -  /// \code template<typename Graph> class RevGraphWrapper; \endcode 
   29.85 -  /// has constructor 
   29.86 -  /// <tt> RevGraphWrapper(Graph& _g)</tt>. 
   29.87 -  /// This means that in a situation, 
   29.88 -  /// when a <tt> const ListGraph& </tt> reference to a graph is given, 
   29.89 -  /// then it have to be instantiated with <tt>Graph=const ListGraph</tt>.
   29.90 -  /// \code
   29.91 -  /// int algorithm1(const ListGraph& g) {
   29.92 -  ///   RevGraphWrapper<const ListGraph> rgw(g);
   29.93 -  ///   return algorithm2(rgw);
   29.94 -  /// }
   29.95 -  /// \endcode
   29.96 -
   29.97 -  /// \addtogroup gwrappers
   29.98 -  /// @{
   29.99 -
  29.100 -  ///Base type for the Graph Wrappers
  29.101 -
  29.102 -  ///\warning Graph wrappers are in even more experimental state than the other
  29.103 -  ///parts of the lib. Use them at you own risk.
  29.104 -  ///
  29.105 -  ///This is the base type for the Graph Wrappers.
  29.106 -  ///\todo Some more docs... 
  29.107 -  ///
  29.108 -  ///\author Marton Makai 
  29.109 -  template<typename Graph>
  29.110 -  class GraphWrapper {
  29.111 -  protected:
  29.112 -    Graph* graph;
  29.113 -    GraphWrapper() : graph(0) { }
  29.114 -    void setGraph(Graph& _graph) { graph=&_graph; }
  29.115 -
  29.116 -  public:
  29.117 -    typedef Graph BaseGraph;
  29.118 -    typedef Graph ParentGraph;
  29.119 -
  29.120 -    GraphWrapper(Graph& _graph) : graph(&_graph) { }
  29.121 -    GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { }
  29.122 - 
  29.123 -    typedef typename Graph::Node Node;
  29.124 -    class NodeIt : public Node { 
  29.125 -      const GraphWrapper<Graph>* gw;
  29.126 -      friend class GraphWrapper<Graph>;
  29.127 -     public:
  29.128 -      NodeIt() { }
  29.129 -      NodeIt(Invalid i) : Node(i) { }
  29.130 -      NodeIt(const GraphWrapper<Graph>& _gw) : 
  29.131 -	Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { }
  29.132 -      NodeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  29.133 -	Node(n), gw(&_gw) { }
  29.134 -      NodeIt& operator++() { 
  29.135 -	*(static_cast<Node*>(this))=
  29.136 -	  ++(typename Graph::NodeIt(*(gw->graph), *this));
  29.137 -	return *this; 
  29.138 -      }
  29.139 -    };
  29.140 -    typedef typename Graph::Edge Edge;
  29.141 -    class OutEdgeIt : public Edge { 
  29.142 -      const GraphWrapper<Graph>* gw;
  29.143 -      friend class GraphWrapper<Graph>;
  29.144 -     public:
  29.145 -      OutEdgeIt() { }
  29.146 -      OutEdgeIt(Invalid i) : Edge(i) { }
  29.147 -      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  29.148 -	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  29.149 -      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  29.150 -	Edge(e), gw(&_gw) { }
  29.151 -      OutEdgeIt& operator++() { 
  29.152 -	*(static_cast<Edge*>(this))=
  29.153 -	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.154 -	return *this; 
  29.155 -      }
  29.156 -    };
  29.157 -    class InEdgeIt : public Edge { 
  29.158 -      const GraphWrapper<Graph>* gw;
  29.159 -      friend class GraphWrapper<Graph>;
  29.160 -     public:
  29.161 -      InEdgeIt() { }
  29.162 -      InEdgeIt(Invalid i) : Edge(i) { }
  29.163 -      InEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  29.164 -	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  29.165 -      InEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  29.166 -	Edge(e), gw(&_gw) { }
  29.167 -      InEdgeIt& operator++() { 
  29.168 -	*(static_cast<Edge*>(this))=
  29.169 -	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.170 -	return *this; 
  29.171 -      }
  29.172 -    };
  29.173 -    class EdgeIt : public Edge { 
  29.174 -      const GraphWrapper<Graph>* gw;
  29.175 -      friend class GraphWrapper<Graph>;
  29.176 -     public:
  29.177 -      EdgeIt() { }
  29.178 -      EdgeIt(Invalid i) : Edge(i) { }
  29.179 -      EdgeIt(const GraphWrapper<Graph>& _gw) : 
  29.180 -	Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { }
  29.181 -      EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  29.182 -	Edge(e), gw(&_gw) { }
  29.183 -      EdgeIt& operator++() { 
  29.184 -	*(static_cast<Edge*>(this))=
  29.185 -	  ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.186 -	return *this; 
  29.187 -      }
  29.188 -    };
  29.189 -   
  29.190 -    NodeIt& first(NodeIt& i) const { 
  29.191 -      i=NodeIt(*this); return i;
  29.192 -    }
  29.193 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  29.194 -      i=OutEdgeIt(*this, p); return i;
  29.195 -    }
  29.196 -    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  29.197 -      i=InEdgeIt(*this, p); return i;
  29.198 -    }
  29.199 -    EdgeIt& first(EdgeIt& i) const { 
  29.200 -      i=EdgeIt(*this); return i;
  29.201 -    }
  29.202 -
  29.203 -    Node tail(const Edge& e) const { 
  29.204 -      return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
  29.205 -    Node head(const Edge& e) const { 
  29.206 -      return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
  29.207 -
  29.208 -    int nodeNum() const { return graph->nodeNum(); }
  29.209 -    int edgeNum() const { return graph->edgeNum(); }
  29.210 -  
  29.211 -    Node addNode() const { return Node(graph->addNode()); }
  29.212 -    Edge addEdge(const Node& tail, const Node& head) const { 
  29.213 -      return Edge(graph->addEdge(tail, head)); }
  29.214 -
  29.215 -    void erase(const Node& i) const { graph->erase(i); }
  29.216 -    void erase(const Edge& i) const { graph->erase(i); }
  29.217 -  
  29.218 -    void clear() const { graph->clear(); }
  29.219 -    
  29.220 -    bool forward(const Edge& e) const { return graph->forward(e); }
  29.221 -    bool backward(const Edge& e) const { return graph->backward(e); }
  29.222 -
  29.223 -    int id(const Node& v) const { return graph->id(v); }
  29.224 -    int id(const Edge& e) const { return graph->id(e); }
  29.225 -    
  29.226 -    Edge opposite(const Edge& e) const { return Edge(graph->opposite(e)); }
  29.227 -
  29.228 -
  29.229 -    IMPORT_NODE_MAP(Graph, *(gw.graph), GraphWrapper, gw);    
  29.230 -    IMPORT_EDGE_MAP(Graph, *(gw.graph), GraphWrapper, gw);
  29.231 -    
  29.232 -
  29.233 -  };
  29.234 -
  29.235 -
  29.236 -
  29.237 -  /// A graph wrapper which reverses the orientation of the edges.
  29.238 -
  29.239 -  ///\warning Graph wrappers are in even more experimental state than the other
  29.240 -  ///parts of the lib. Use them at you own risk.
  29.241 -  ///
  29.242 -  /// A graph wrapper which reverses the orientation of the edges.
  29.243 -  /// Thus \c Graph have to be a directed graph type.
  29.244 -  ///
  29.245 -  ///\author Marton Makai
  29.246 -  template<typename Graph>
  29.247 -  class RevGraphWrapper : public GraphWrapper<Graph> {
  29.248 -  public:
  29.249 -    typedef GraphWrapper<Graph> Parent; 
  29.250 -  protected:
  29.251 -    RevGraphWrapper() : GraphWrapper<Graph>() { }
  29.252 -  public:
  29.253 -    RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
  29.254 -    RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
  29.255 -
  29.256 -    typedef typename GraphWrapper<Graph>::Node Node;
  29.257 -    typedef typename GraphWrapper<Graph>::Edge Edge;
  29.258 -    //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other
  29.259 -    //because this does not work is some of them are not defined in the 
  29.260 -    //original graph. The problem with this is that typedef-ed stuff 
  29.261 -    //are instantiated in c++.
  29.262 -    class OutEdgeIt : public Edge { 
  29.263 -      const RevGraphWrapper<Graph>* gw;
  29.264 -      friend class GraphWrapper<Graph>;
  29.265 -     public:
  29.266 -      OutEdgeIt() { }
  29.267 -      OutEdgeIt(Invalid i) : Edge(i) { }
  29.268 -      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
  29.269 -	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  29.270 -      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
  29.271 -	Edge(e), gw(&_gw) { }
  29.272 -      OutEdgeIt& operator++() { 
  29.273 -	*(static_cast<Edge*>(this))=
  29.274 -	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.275 -	return *this; 
  29.276 -      }
  29.277 -    };
  29.278 -    class InEdgeIt : public Edge { 
  29.279 -      const RevGraphWrapper<Graph>* gw;
  29.280 -      friend class GraphWrapper<Graph>;
  29.281 -     public:
  29.282 -      InEdgeIt() { }
  29.283 -      InEdgeIt(Invalid i) : Edge(i) { }
  29.284 -      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
  29.285 -	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  29.286 -      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
  29.287 -	Edge(e), gw(&_gw) { }
  29.288 -      InEdgeIt& operator++() { 
  29.289 -	*(static_cast<Edge*>(this))=
  29.290 -	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.291 -	return *this; 
  29.292 -      }
  29.293 -    };
  29.294 -
  29.295 -    using GraphWrapper<Graph>::first;
  29.296 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  29.297 -      i=OutEdgeIt(*this, p); return i;
  29.298 -    }
  29.299 -    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  29.300 -      i=InEdgeIt(*this, p); return i;
  29.301 -    }
  29.302 -
  29.303 -    Node tail(const Edge& e) const { 
  29.304 -      return GraphWrapper<Graph>::head(e); }
  29.305 -    Node head(const Edge& e) const { 
  29.306 -      return GraphWrapper<Graph>::tail(e); }
  29.307 -
  29.308 -    //    KEEP_MAPS(Parent, RevGraphWrapper);
  29.309 -
  29.310 -  };
  29.311 -
  29.312 -
  29.313 -
  29.314 -  /// A graph wrapper for hiding nodes and edges from a graph.
  29.315 -  
  29.316 -  ///\warning Graph wrappers are in even more experimental state than the other
  29.317 -  ///parts of the lib. Use them at you own risk.
  29.318 -  ///
  29.319 -  /// This wrapper shows a graph with filtered node-set and 
  29.320 -  /// edge-set. Given a bool-valued map on the node-set and one on 
  29.321 -  /// the edge-set of the graphs, the iterators show only the objects 
  29.322 -  /// having true value. 
  29.323 -  /// The quick brown fox iterators jump over 
  29.324 -  /// the lazy dog nodes or edges if their values for are false in the 
  29.325 -  /// corresponding bool maps. 
  29.326 -  ///
  29.327 -  ///\author Marton Makai
  29.328 -  template<typename Graph, typename NodeFilterMap, 
  29.329 -	   typename EdgeFilterMap>
  29.330 -  class SubGraphWrapper : public GraphWrapper<Graph> {
  29.331 -  public:
  29.332 -    typedef GraphWrapper<Graph> Parent;
  29.333 -  protected:
  29.334 -    NodeFilterMap* node_filter_map;
  29.335 -    EdgeFilterMap* edge_filter_map;
  29.336 -
  29.337 -    SubGraphWrapper() : GraphWrapper<Graph>(), 
  29.338 -			node_filter_map(0), edge_filter_map(0) { }
  29.339 -    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
  29.340 -      node_filter_map=&_node_filter_map;
  29.341 -    }
  29.342 -    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
  29.343 -      edge_filter_map=&_edge_filter_map;
  29.344 -    }
  29.345 -    
  29.346 -  public:
  29.347 -    SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
  29.348 -		    EdgeFilterMap& _edge_filter_map) : 
  29.349 -      GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
  29.350 -      edge_filter_map(&_edge_filter_map) { }  
  29.351 -
  29.352 -    typedef typename GraphWrapper<Graph>::Node Node;
  29.353 -    class NodeIt : public Node { 
  29.354 -      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  29.355 -      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  29.356 -    public:
  29.357 -      NodeIt() { }
  29.358 -      NodeIt(Invalid i) : Node(i) { }
  29.359 -      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) : 
  29.360 -	Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { 
  29.361 -	while (*static_cast<Node*>(this)!=INVALID && 
  29.362 -	       !(*(gw->node_filter_map))[*this]) 
  29.363 -	  *(static_cast<Node*>(this))=
  29.364 -	    ++(typename Graph::NodeIt(*(gw->graph), *this));
  29.365 -      }
  29.366 -      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  29.367 -	     const Node& n) : 
  29.368 -	Node(n), gw(&_gw) { }
  29.369 -      NodeIt& operator++() { 
  29.370 -	*(static_cast<Node*>(this))=
  29.371 -	  ++(typename Graph::NodeIt(*(gw->graph), *this));
  29.372 -	while (*static_cast<Node*>(this)!=INVALID && 
  29.373 -	       !(*(gw->node_filter_map))[*this]) 
  29.374 -	  *(static_cast<Node*>(this))=
  29.375 -	    ++(typename Graph::NodeIt(*(gw->graph), *this));
  29.376 -	return *this; 
  29.377 -      }
  29.378 -    };
  29.379 -    typedef typename GraphWrapper<Graph>::Edge Edge;
  29.380 -    class OutEdgeIt : public Edge { 
  29.381 -      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  29.382 -      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  29.383 -    public:
  29.384 -      OutEdgeIt() { }
  29.385 -      OutEdgeIt(Invalid i) : Edge(i) { }
  29.386 -      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 
  29.387 -	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { 
  29.388 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.389 -	       !(*(gw->edge_filter_map))[*this]) 
  29.390 -	  *(static_cast<Edge*>(this))=
  29.391 -	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.392 -      }
  29.393 -      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  29.394 -	     const Edge& e) : 
  29.395 -	Edge(e), gw(&_gw) { }
  29.396 -      OutEdgeIt& operator++() { 
  29.397 -	*(static_cast<Edge*>(this))=
  29.398 -	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.399 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.400 -	       !(*(gw->edge_filter_map))[*this]) 
  29.401 -	  *(static_cast<Edge*>(this))=
  29.402 -	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.403 -	return *this; 
  29.404 -      }
  29.405 -    };
  29.406 -    class InEdgeIt : public Edge { 
  29.407 -      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  29.408 -      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  29.409 -    public:
  29.410 -      InEdgeIt() { }
  29.411 -      //      InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { }
  29.412 -      InEdgeIt(Invalid i) : Edge(i) { }
  29.413 -      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 
  29.414 -	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { 
  29.415 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.416 -	       !(*(gw->edge_filter_map))[*this]) 
  29.417 -	  *(static_cast<Edge*>(this))=
  29.418 -	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.419 -      }
  29.420 -      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  29.421 -	     const Edge& e) : 
  29.422 -	Edge(e), gw(&_gw) { }
  29.423 -      InEdgeIt& operator++() { 
  29.424 -	*(static_cast<Edge*>(this))=
  29.425 -	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.426 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.427 -	       !(*(gw->edge_filter_map))[*this]) 
  29.428 -	  *(static_cast<Edge*>(this))=
  29.429 -	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.430 -	return *this; 
  29.431 -      }
  29.432 -    };
  29.433 -    class EdgeIt : public Edge { 
  29.434 -      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  29.435 -      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  29.436 -    public:
  29.437 -      EdgeIt() { }
  29.438 -      EdgeIt(Invalid i) : Edge(i) { }
  29.439 -      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) : 
  29.440 -	Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { 
  29.441 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.442 -	       !(*(gw->edge_filter_map))[*this]) 
  29.443 -	  *(static_cast<Edge*>(this))=
  29.444 -	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.445 -      }
  29.446 -      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  29.447 -	     const Edge& e) : 
  29.448 -	Edge(e), gw(&_gw) { }
  29.449 -      EdgeIt& operator++() { 
  29.450 -	*(static_cast<Edge*>(this))=
  29.451 -	  ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.452 -	while (*static_cast<Edge*>(this)!=INVALID && 
  29.453 -	       !(*(gw->edge_filter_map))[*this]) 
  29.454 -	  *(static_cast<Edge*>(this))=
  29.455 -	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.456 -	return *this; 
  29.457 -      }
  29.458 -    };
  29.459 -
  29.460 -    NodeIt& first(NodeIt& i) const { 
  29.461 -      i=NodeIt(*this); return i;
  29.462 -    }
  29.463 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  29.464 -      i=OutEdgeIt(*this, p); return i;
  29.465 -    }
  29.466 -    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  29.467 -      i=InEdgeIt(*this, p); return i;
  29.468 -    }
  29.469 -    EdgeIt& first(EdgeIt& i) const { 
  29.470 -      i=EdgeIt(*this); return i;
  29.471 -    }
  29.472 -    
  29.473 -    /// This function hides \c n in the graph, i.e. the iteration 
  29.474 -    /// jumps over it. This is done by simply setting the value of \c n  
  29.475 -    /// to be false in the corresponding node-map.
  29.476 -    void hide(const Node& n) const { node_filter_map->set(n, false); }
  29.477 -
  29.478 -    /// This function hides \c e in the graph, i.e. the iteration 
  29.479 -    /// jumps over it. This is done by simply setting the value of \c e  
  29.480 -    /// to be false in the corresponding edge-map.
  29.481 -    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
  29.482 -
  29.483 -    /// The value of \c n is set to be true in the node-map which stores 
  29.484 -    /// hide information. If \c n was hidden previuosly, then it is shown 
  29.485 -    /// again
  29.486 -     void unHide(const Node& n) const { node_filter_map->set(n, true); }
  29.487 -
  29.488 -    /// The value of \c e is set to be true in the edge-map which stores 
  29.489 -    /// hide information. If \c e was hidden previuosly, then it is shown 
  29.490 -    /// again
  29.491 -    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
  29.492 -
  29.493 -    /// Returns true if \c n is hidden.
  29.494 -    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
  29.495 -
  29.496 -    /// Returns true if \c n is hidden.
  29.497 -    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
  29.498 -
  29.499 -    /// \warning This is a linear time operation and works only if 
  29.500 -    /// \c Graph::NodeIt is defined.
  29.501 -    int nodeNum() const { 
  29.502 -      int i=0;
  29.503 -      for (NodeIt n(*this); n!=INVALID; ++n) ++i;
  29.504 -      return i; 
  29.505 -    }
  29.506 -
  29.507 -    /// \warning This is a linear time operation and works only if 
  29.508 -    /// \c Graph::EdgeIt is defined.
  29.509 -    int edgeNum() const { 
  29.510 -      int i=0;
  29.511 -      for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
  29.512 -      return i; 
  29.513 -    }
  29.514 -
  29.515 -    //    KEEP_MAPS(Parent, SubGraphWrapper);
  29.516 -  };
  29.517 -
  29.518 -
  29.519 -
  29.520 -  template<typename Graph>
  29.521 -  class UndirGraphWrapper : public GraphWrapper<Graph> {
  29.522 -  public:
  29.523 -    typedef GraphWrapper<Graph> Parent; 
  29.524 -  protected:
  29.525 -    UndirGraphWrapper() : GraphWrapper<Graph>() { }
  29.526 -    
  29.527 -  public:
  29.528 -    typedef typename GraphWrapper<Graph>::Node Node;
  29.529 -    typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
  29.530 -    typedef typename GraphWrapper<Graph>::Edge Edge;
  29.531 -    typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
  29.532 -
  29.533 -    UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
  29.534 -
  29.535 -    class OutEdgeIt {
  29.536 -      friend class UndirGraphWrapper<Graph>;
  29.537 -      bool out_or_in; //true iff out
  29.538 -      typename Graph::OutEdgeIt out;
  29.539 -      typename Graph::InEdgeIt in;
  29.540 -    public:
  29.541 -      OutEdgeIt() { }
  29.542 -      OutEdgeIt(const Invalid& i) : Edge(i) { }
  29.543 -      OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& _n) {
  29.544 -	out_or_in=true; _G.graph->first(out, _n);
  29.545 -	if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, _n);	}
  29.546 -      } 
  29.547 -      operator Edge() const { 
  29.548 -	if (out_or_in) return Edge(out); else return Edge(in); 
  29.549 -      }
  29.550 -    };
  29.551 -
  29.552 -    typedef OutEdgeIt InEdgeIt; 
  29.553 -
  29.554 -    using GraphWrapper<Graph>::first;
  29.555 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  29.556 -      i=OutEdgeIt(*this, p); return i;
  29.557 -    }
  29.558 -
  29.559 -    using GraphWrapper<Graph>::next;
  29.560 -
  29.561 -    OutEdgeIt& next(OutEdgeIt& e) const {
  29.562 -      if (e.out_or_in) {
  29.563 -	typename Graph::Node n=this->graph->tail(e.out);
  29.564 -	this->graph->next(e.out);
  29.565 -	if (!this->graph->valid(e.out)) { 
  29.566 -	  e.out_or_in=false; this->graph->first(e.in, n); }
  29.567 -      } else {
  29.568 -	this->graph->next(e.in);
  29.569 -      }
  29.570 -      return e;
  29.571 -    }
  29.572 -
  29.573 -    Node aNode(const OutEdgeIt& e) const { 
  29.574 -      if (e.out_or_in) return this->graph->tail(e); else 
  29.575 -	return this->graph->head(e); }
  29.576 -    Node bNode(const OutEdgeIt& e) const { 
  29.577 -      if (e.out_or_in) return this->graph->head(e); else 
  29.578 -	return this->graph->tail(e); }
  29.579 -
  29.580 -    //    KEEP_MAPS(Parent, UndirGraphWrapper);
  29.581 -
  29.582 -  };
  29.583 -  
  29.584 -//   /// \brief An undirected graph template.
  29.585 -//   ///
  29.586 -//   ///\warning Graph wrappers are in even more experimental state than the other
  29.587 -//   ///parts of the lib. Use them at your own risk.
  29.588 -//   ///
  29.589 -//   /// An undirected graph template.
  29.590 -//   /// This class works as an undirected graph and a directed graph of 
  29.591 -//   /// class \c Graph is used for the physical storage.
  29.592 -//   /// \ingroup graphs
  29.593 -  template<typename Graph>
  29.594 -  class UndirGraph : public UndirGraphWrapper<Graph> {
  29.595 -    typedef UndirGraphWrapper<Graph> Parent;
  29.596 -  protected:
  29.597 -    Graph gr;
  29.598 -  public:
  29.599 -    UndirGraph() : UndirGraphWrapper<Graph>() { 
  29.600 -      Parent::setGraph(gr); 
  29.601 -    }
  29.602 -
  29.603 -    //    KEEP_MAPS(Parent, UndirGraph);
  29.604 -  };
  29.605 -
  29.606 -
  29.607 -
  29.608 -  ///\brief A wrapper for composing a subgraph of a 
  29.609 -  /// bidirected graph made from a directed one. 
  29.610 -  ///
  29.611 -  /// A wrapper for composing a subgraph of a 
  29.612 -  /// bidirected graph made from a directed one. 
  29.613 -  ///
  29.614 -  ///\warning Graph wrappers are in even more experimental state than the other
  29.615 -  ///parts of the lib. Use them at you own risk.
  29.616 -  ///
  29.617 -  /// Suppose that for a directed graph $G=(V, A)$, 
  29.618 -  /// two bool valued maps on the edge-set, 
  29.619 -  /// $forward_filter$, and $backward_filter$ 
  29.620 -  /// is given, and we are dealing with the directed graph
  29.621 -  /// a $G'=(V, \{uv : uv\in A \mbox{ and } forward_filter(uv) \mbox{ is true}\}+\{vu : uv\in A \mbox{ and } backward_filter(uv) \mbox{ is true}\})$. 
  29.622 -  /// The purpose of writing + instead of union is because parallel 
  29.623 -  /// edges can arose. 
  29.624 -  /// In other words, a subgraph of the bidirected graph obtained, which 
  29.625 -  /// is given by orienting the edges of the original graph in both directions.
  29.626 -  /// An example for such a construction is the \c RevGraphWrapper where the 
  29.627 -  /// forward_filter is everywhere false and the backward_filter is 
  29.628 -  /// everywhere true. We note that for sake of efficiency, 
  29.629 -  /// \c RevGraphWrapper is implemented in a different way. 
  29.630 -  /// But BidirGraphWrapper is obtained from 
  29.631 -  /// SubBidirGraphWrapper by considering everywhere true 
  29.632 -  /// valued maps both for forward_filter and backward_filter. 
  29.633 -  /// Finally, one of the most important applications of SubBidirGraphWrapper 
  29.634 -  /// is ResGraphWrapper, which stands for the residual graph in directed 
  29.635 -  /// flow and circulation problems. 
  29.636 -  /// As wrappers usually, the SubBidirGraphWrapper implements the 
  29.637 -  /// above mentioned graph structure without its physical storage, 
  29.638 -  /// that is the whole stuff eats constant memory. 
  29.639 -  /// As the oppositely directed edges are logically different, 
  29.640 -  /// the maps are able to attach different values for them. 
  29.641 -  template<typename Graph, 
  29.642 -	   typename ForwardFilterMap, typename BackwardFilterMap>
  29.643 -  class SubBidirGraphWrapper : public GraphWrapper<Graph> {
  29.644 -  public:
  29.645 -    typedef GraphWrapper<Graph> Parent; 
  29.646 -  protected:
  29.647 -    ForwardFilterMap* forward_filter;
  29.648 -    BackwardFilterMap* backward_filter;
  29.649 -
  29.650 -    SubBidirGraphWrapper() : GraphWrapper<Graph>() { }
  29.651 -    void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
  29.652 -      forward_filter=&_forward_filter;
  29.653 -    }
  29.654 -    void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
  29.655 -      backward_filter=&_backward_filter;
  29.656 -    }
  29.657 -
  29.658 -  public:
  29.659 -
  29.660 -    SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter, 
  29.661 -			 BackwardFilterMap& _backward_filter) : 
  29.662 -      GraphWrapper<Graph>(_graph), 
  29.663 -      forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
  29.664 -    SubBidirGraphWrapper(const SubBidirGraphWrapper<Graph, 
  29.665 -			 ForwardFilterMap, BackwardFilterMap>& gw) : 
  29.666 -      Parent(gw), 
  29.667 -      forward_filter(gw.forward_filter), 
  29.668 -      backward_filter(gw.backward_filter) { }
  29.669 -
  29.670 -    class Edge; 
  29.671 -    class OutEdgeIt; 
  29.672 -    friend class Edge; 
  29.673 -    friend class OutEdgeIt; 
  29.674 -
  29.675 -    template<typename T> class EdgeMap;
  29.676 -
  29.677 -    typedef typename GraphWrapper<Graph>::Node Node;
  29.678 -
  29.679 -    typedef typename Graph::Edge GraphEdge;
  29.680 -    /// SubBidirGraphWrapper<..., ..., ...>::Edge is inherited from 
  29.681 -    /// Graph::Edge. It contains an extra bool flag which is true 
  29.682 -    /// if and only if the 
  29.683 -    /// edge is the backward version of the original edge.
  29.684 -    class Edge : public Graph::Edge {
  29.685 -      friend class SubBidirGraphWrapper<Graph, 
  29.686 -					ForwardFilterMap, BackwardFilterMap>;
  29.687 -      template<typename T> friend class EdgeMap;
  29.688 -    protected:
  29.689 -      bool backward; //true, iff backward
  29.690 -    public:
  29.691 -      Edge() { }
  29.692 -      /// \todo =false is needed, or causes problems?
  29.693 -      /// If \c _backward is false, then we get an edge corresponding to the 
  29.694 -      /// original one, otherwise its oppositely directed pair is obtained.
  29.695 -      Edge(const typename Graph::Edge& e, bool _backward/*=false*/) : 
  29.696 -	Graph::Edge(e), backward(_backward) { }
  29.697 -      Edge(Invalid i) : Graph::Edge(i), backward(true) { }
  29.698 -      bool operator==(const Edge& v) const { 
  29.699 -	return (this->backward==v.backward && 
  29.700 -		static_cast<typename Graph::Edge>(*this)==
  29.701 -		static_cast<typename Graph::Edge>(v));
  29.702 -      } 
  29.703 -      bool operator!=(const Edge& v) const { 
  29.704 -	return (this->backward!=v.backward || 
  29.705 -		static_cast<typename Graph::Edge>(*this)!=
  29.706 -		static_cast<typename Graph::Edge>(v));
  29.707 -      }
  29.708 -    };
  29.709 -
  29.710 -    class OutEdgeIt : public Edge {
  29.711 -      friend class SubBidirGraphWrapper<Graph, 
  29.712 -					ForwardFilterMap, BackwardFilterMap>;
  29.713 -    protected:
  29.714 -      const SubBidirGraphWrapper<Graph, 
  29.715 -				 ForwardFilterMap, BackwardFilterMap>* gw;
  29.716 -    public:
  29.717 -      OutEdgeIt() { }
  29.718 -      OutEdgeIt(Invalid i) : Edge(i) { }
  29.719 -      OutEdgeIt(const SubBidirGraphWrapper<Graph, 
  29.720 -		ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 
  29.721 -	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 
  29.722 -	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.723 -	       !(*(gw->forward_filter))[*this]) 
  29.724 -	  *(static_cast<GraphEdge*>(this))=
  29.725 -	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.726 -	if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.727 -	  *static_cast<Edge*>(this)=
  29.728 -	    Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true);
  29.729 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.730 -		 !(*(gw->backward_filter))[*this]) 
  29.731 -	    *(static_cast<GraphEdge*>(this))=
  29.732 -	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.733 -	}
  29.734 -      }
  29.735 -      OutEdgeIt(const SubBidirGraphWrapper<Graph, 
  29.736 -		ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  29.737 -	Edge(e), gw(&_gw) { }
  29.738 -      OutEdgeIt& operator++() { 
  29.739 -	if (!this->backward) {
  29.740 -	  Node n=gw->tail(*this);
  29.741 -	  *(static_cast<GraphEdge*>(this))=
  29.742 -	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.743 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.744 -		 !(*(gw->forward_filter))[*this]) 
  29.745 -	    *(static_cast<GraphEdge*>(this))=
  29.746 -	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.747 -	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.748 -	    *static_cast<Edge*>(this)=
  29.749 -	      Edge(typename Graph::InEdgeIt(*(gw->graph), n), true);
  29.750 -	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.751 -		   !(*(gw->backward_filter))[*this]) 
  29.752 -	      *(static_cast<GraphEdge*>(this))=
  29.753 -		++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.754 -	  }
  29.755 -	} else {
  29.756 -	  *(static_cast<GraphEdge*>(this))=
  29.757 -	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.758 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.759 -		 !(*(gw->backward_filter))[*this]) 
  29.760 -	    *(static_cast<GraphEdge*>(this))=
  29.761 -	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.762 -	}
  29.763 -	return *this;
  29.764 -      }
  29.765 -    };
  29.766 -
  29.767 -    class InEdgeIt : public Edge {
  29.768 -      friend class SubBidirGraphWrapper<Graph, 
  29.769 -					ForwardFilterMap, BackwardFilterMap>;
  29.770 -    protected:
  29.771 -      const SubBidirGraphWrapper<Graph, 
  29.772 -				 ForwardFilterMap, BackwardFilterMap>* gw;
  29.773 -    public:
  29.774 -      InEdgeIt() { }
  29.775 -      InEdgeIt(Invalid i) : Edge(i) { }
  29.776 -      InEdgeIt(const SubBidirGraphWrapper<Graph, 
  29.777 -	       ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 
  29.778 -	Edge(typename Graph::InEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 
  29.779 -	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.780 -	       !(*(gw->forward_filter))[*this]) 
  29.781 -	  *(static_cast<GraphEdge*>(this))=
  29.782 -	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.783 -	if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.784 -	  *static_cast<Edge*>(this)=
  29.785 -	    Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true);
  29.786 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.787 -		 !(*(gw->backward_filter))[*this]) 
  29.788 -	    *(static_cast<GraphEdge*>(this))=
  29.789 -	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.790 -	}
  29.791 -      }
  29.792 -      InEdgeIt(const SubBidirGraphWrapper<Graph, 
  29.793 -	       ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  29.794 -	Edge(e), gw(&_gw) { }
  29.795 -      InEdgeIt& operator++() { 
  29.796 -	if (!this->backward) {
  29.797 -	  Node n=gw->tail(*this);
  29.798 -	  *(static_cast<GraphEdge*>(this))=
  29.799 -	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.800 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.801 -		 !(*(gw->forward_filter))[*this]) 
  29.802 -	    *(static_cast<GraphEdge*>(this))=
  29.803 -	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  29.804 -	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.805 -	    *static_cast<Edge*>(this)=
  29.806 -	      Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true);
  29.807 -	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.808 -		   !(*(gw->backward_filter))[*this]) 
  29.809 -	      *(static_cast<GraphEdge*>(this))=
  29.810 -		++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.811 -	  }
  29.812 -	} else {
  29.813 -	  *(static_cast<GraphEdge*>(this))=
  29.814 -	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.815 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.816 -		 !(*(gw->backward_filter))[*this]) 
  29.817 -	    *(static_cast<GraphEdge*>(this))=
  29.818 -	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  29.819 -	}
  29.820 -	return *this;
  29.821 -      }
  29.822 -    };
  29.823 -
  29.824 -    class EdgeIt : public Edge {
  29.825 -      friend class SubBidirGraphWrapper<Graph, 
  29.826 -					ForwardFilterMap, BackwardFilterMap>;
  29.827 -    protected:
  29.828 -      const SubBidirGraphWrapper<Graph, 
  29.829 -				 ForwardFilterMap, BackwardFilterMap>* gw;
  29.830 -    public:
  29.831 -      EdgeIt() { }
  29.832 -      EdgeIt(Invalid i) : Edge(i) { }
  29.833 -      EdgeIt(const SubBidirGraphWrapper<Graph, 
  29.834 -	     ForwardFilterMap, BackwardFilterMap>& _gw) : 
  29.835 -	Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) { 
  29.836 -	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.837 -	       !(*(gw->forward_filter))[*this]) 
  29.838 -	  *(static_cast<GraphEdge*>(this))=
  29.839 -	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.840 -	if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.841 -	  *static_cast<Edge*>(this)=
  29.842 -	    Edge(typename Graph::EdgeIt(*(_gw.graph)), true);
  29.843 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.844 -		 !(*(gw->backward_filter))[*this]) 
  29.845 -	    *(static_cast<GraphEdge*>(this))=
  29.846 -	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.847 -	}
  29.848 -      }
  29.849 -      EdgeIt(const SubBidirGraphWrapper<Graph, 
  29.850 -	     ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  29.851 -	Edge(e), gw(&_gw) { }
  29.852 -      EdgeIt& operator++() { 
  29.853 -	if (!this->backward) {
  29.854 -	  *(static_cast<GraphEdge*>(this))=
  29.855 -	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.856 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.857 -		 !(*(gw->forward_filter))[*this]) 
  29.858 -	    *(static_cast<GraphEdge*>(this))=
  29.859 -	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.860 -	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  29.861 -	    *static_cast<Edge*>(this)=
  29.862 -	      Edge(typename Graph::EdgeIt(*(gw->graph)), true);
  29.863 -	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.864 -		   !(*(gw->backward_filter))[*this]) 
  29.865 -	      *(static_cast<GraphEdge*>(this))=
  29.866 -		++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.867 -	  }
  29.868 -	} else {
  29.869 -	  *(static_cast<GraphEdge*>(this))=
  29.870 -	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.871 -	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  29.872 -		 !(*(gw->backward_filter))[*this]) 
  29.873 -	    *(static_cast<GraphEdge*>(this))=
  29.874 -	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  29.875 -	}
  29.876 -	return *this;
  29.877 -      }
  29.878 -    };
  29.879 -
  29.880 -    using GraphWrapper<Graph>::first;
  29.881 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  29.882 -      i=OutEdgeIt(*this, p); return i;
  29.883 -    }
  29.884 -    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  29.885 -      i=InEdgeIt(*this, p); return i;
  29.886 -    }
  29.887 -    EdgeIt& first(EdgeIt& i) const { 
  29.888 -      i=EdgeIt(*this); return i;
  29.889 -    }
  29.890 -  
  29.891 -
  29.892 -    Node tail(Edge e) const { 
  29.893 -      return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
  29.894 -    Node head(Edge e) const { 
  29.895 -      return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
  29.896 -
  29.897 -    /// Gives back the opposite edge.
  29.898 -    Edge opposite(const Edge& e) const { 
  29.899 -      Edge f=e;
  29.900 -      f.backward=!f.backward;
  29.901 -      return f;
  29.902 -    }
  29.903 -
  29.904 -    /// \warning This is a linear time operation and works only if 
  29.905 -    /// \c Graph::EdgeIt is defined.
  29.906 -    int edgeNum() const { 
  29.907 -      int i=0;
  29.908 -      for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
  29.909 -      return i; 
  29.910 -    }
  29.911 -
  29.912 -    bool forward(const Edge& e) const { return !e.backward; }
  29.913 -    bool backward(const Edge& e) const { return e.backward; }
  29.914 -
  29.915 -
  29.916 -    template <typename T>
  29.917 -    /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two 
  29.918 -    /// Graph::EdgeMap one for the forward edges and 
  29.919 -    /// one for the backward edges.
  29.920 -    class EdgeMap {
  29.921 -      template <typename TT> friend class EdgeMap;
  29.922 -      typename Graph::template EdgeMap<T> forward_map, backward_map; 
  29.923 -    public:
  29.924 -      typedef T ValueType;
  29.925 -      typedef Edge KeyType;
  29.926 -
  29.927 -      EdgeMap(const SubBidirGraphWrapper<Graph, 
  29.928 -	      ForwardFilterMap, BackwardFilterMap>& g) : 
  29.929 -	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
  29.930 -
  29.931 -      EdgeMap(const SubBidirGraphWrapper<Graph, 
  29.932 -	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
  29.933 -	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
  29.934 -
  29.935 -      template <typename TT>
  29.936 -      EdgeMap(const EdgeMap<TT>& copy) 
  29.937 -	: forward_map(copy.forward_map), backward_map(copy.backward_map) {}
  29.938 -
  29.939 -      template <typename TT>
  29.940 -      EdgeMap& operator=(const EdgeMap<TT>& copy) {
  29.941 -	forward_map = copy.forward_map;
  29.942 -	backward_map = copy.backward_map;
  29.943 -	return *this;
  29.944 -      }
  29.945 -      
  29.946 -      void set(Edge e, T a) { 
  29.947 -	if (!e.backward) 
  29.948 -	  forward_map.set(e, a); 
  29.949 -	else 
  29.950 -	  backward_map.set(e, a); 
  29.951 -      }
  29.952 -
  29.953 -      typename Graph::template EdgeMap<T>::ConstReferenceType 
  29.954 -      operator[](Edge e) const { 
  29.955 -	if (!e.backward) 
  29.956 -	  return forward_map[e]; 
  29.957 -	else 
  29.958 -	  return backward_map[e]; 
  29.959 -      }
  29.960 -
  29.961 -      typename Graph::template EdgeMap<T>::ReferenceType 
  29.962 -      operator[](Edge e) { 
  29.963 -	if (!e.backward) 
  29.964 -	  return forward_map[e]; 
  29.965 -	else 
  29.966 -	  return backward_map[e]; 
  29.967 -      }
  29.968 -
  29.969 -      void update() { 
  29.970 -	forward_map.update(); 
  29.971 -	backward_map.update();
  29.972 -      }
  29.973 -    };
  29.974 -
  29.975 -
  29.976 -    //    KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
  29.977 -
  29.978 -  };
  29.979 -
  29.980 -
  29.981 -  ///\brief A wrapper for composing bidirected graph from a directed one. 
  29.982 -  ///
  29.983 -  ///\warning Graph wrappers are in even more experimental state than the other
  29.984 -  ///parts of the lib. Use them at you own risk.
  29.985 -  ///
  29.986 -  /// A wrapper for composing bidirected graph from a directed one. 
  29.987 -  /// A bidirected graph is composed over the directed one without physical 
  29.988 -  /// storage. As the oppositely directed edges are logically different ones 
  29.989 -  /// the maps are able to attach different values for them.
  29.990 -  template<typename Graph>
  29.991 -  class BidirGraphWrapper : 
  29.992 -    public SubBidirGraphWrapper<
  29.993 -    Graph, 
  29.994 -    ConstMap<typename Graph::Edge, bool>, 
  29.995 -    ConstMap<typename Graph::Edge, bool> > {
  29.996 -  public:
  29.997 -    typedef  SubBidirGraphWrapper<
  29.998 -      Graph, 
  29.999 -      ConstMap<typename Graph::Edge, bool>, 
 29.1000 -      ConstMap<typename Graph::Edge, bool> > Parent; 
 29.1001 -  protected:
 29.1002 -    ConstMap<typename Graph::Edge, bool> cm;
 29.1003 -
 29.1004 -    BidirGraphWrapper() : Parent(), cm(true) { 
 29.1005 -      Parent::setForwardFilterMap(cm);
 29.1006 -      Parent::setBackwardFilterMap(cm);
 29.1007 -    }
 29.1008 -  public:
 29.1009 -    BidirGraphWrapper(Graph& _graph) : Parent() { 
 29.1010 -      Parent::setGraph(_graph);
 29.1011 -      Parent::setForwardFilterMap(cm);
 29.1012 -      Parent::setBackwardFilterMap(cm);
 29.1013 -    }
 29.1014 -
 29.1015 -    int edgeNum() const { 
 29.1016 -      return 2*this->graph->edgeNum();
 29.1017 -    }
 29.1018 -    //    KEEP_MAPS(Parent, BidirGraphWrapper);
 29.1019 -  };
 29.1020 -
 29.1021 -
 29.1022 -  /// \brief A bidirected graph template.
 29.1023 -  ///
 29.1024 -  ///\warning Graph wrappers are in even more experimental state than the other
 29.1025 -  ///parts of the lib. Use them at you own risk.
 29.1026 -  ///
 29.1027 -  /// A bidirected graph template.
 29.1028 -  /// Such a bidirected graph stores each pair of oppositely directed edges 
 29.1029 -  /// ones in the memory, i.e. a directed graph of type 
 29.1030 -  /// \c Graph is used for that.
 29.1031 -  /// As the oppositely directed edges are logically different ones 
 29.1032 -  /// the maps are able to attach different values for them.
 29.1033 -  /// \ingroup graphs
 29.1034 -  template<typename Graph>
 29.1035 -  class BidirGraph : public BidirGraphWrapper<Graph> {
 29.1036 -  public:
 29.1037 -    typedef UndirGraphWrapper<Graph> Parent;
 29.1038 -  protected:
 29.1039 -    Graph gr;
 29.1040 -  public:
 29.1041 -    BidirGraph() : BidirGraphWrapper<Graph>() { 
 29.1042 -      Parent::setGraph(gr); 
 29.1043 -    }
 29.1044 -    //    KEEP_MAPS(Parent, BidirGraph);
 29.1045 -  };
 29.1046 -
 29.1047 -
 29.1048 -
 29.1049 -  template<typename Graph, typename Number,
 29.1050 -	   typename CapacityMap, typename FlowMap>
 29.1051 -  class ResForwardFilter {
 29.1052 -    //    const Graph* graph;
 29.1053 -    const CapacityMap* capacity;
 29.1054 -    const FlowMap* flow;
 29.1055 -  public:
 29.1056 -    ResForwardFilter(/*const Graph& _graph, */
 29.1057 -		     const CapacityMap& _capacity, const FlowMap& _flow) :
 29.1058 -      /*graph(&_graph),*/ capacity(&_capacity), flow(&_flow) { }
 29.1059 -    ResForwardFilter() : /*graph(0),*/ capacity(0), flow(0) { }
 29.1060 -    void setCapacity(const CapacityMap& _capacity) { capacity=&_capacity; }
 29.1061 -    void setFlow(const FlowMap& _flow) { flow=&_flow; }
 29.1062 -    bool operator[](const typename Graph::Edge& e) const {
 29.1063 -      return (Number((*flow)[e]) < Number((*capacity)[e]));
 29.1064 -    }
 29.1065 -  };
 29.1066 -
 29.1067 -  template<typename Graph, typename Number,
 29.1068 -	   typename CapacityMap, typename FlowMap>
 29.1069 -  class ResBackwardFilter {
 29.1070 -    const CapacityMap* capacity;
 29.1071 -    const FlowMap* flow;
 29.1072 -  public:
 29.1073 -    ResBackwardFilter(/*const Graph& _graph,*/ 
 29.1074 -		      const CapacityMap& _capacity, const FlowMap& _flow) :
 29.1075 -      /*graph(&_graph),*/ capacity(&_capacity), flow(&_flow) { }
 29.1076 -    ResBackwardFilter() : /*graph(0),*/ capacity(0), flow(0) { }
 29.1077 -    void setCapacity(const CapacityMap& _capacity) { capacity=&_capacity; }
 29.1078 -    void setFlow(const FlowMap& _flow) { flow=&_flow; }
 29.1079 -    bool operator[](const typename Graph::Edge& e) const {
 29.1080 -      return (Number(0) < Number((*flow)[e]));
 29.1081 -    }
 29.1082 -  };
 29.1083 -
 29.1084 -  
 29.1085 -  /// A wrapper for composing the residual graph for directed flow and circulation problems.
 29.1086 -
 29.1087 -  ///\warning Graph wrappers are in even more experimental state than the other
 29.1088 -  ///parts of the lib. Use them at you own risk.
 29.1089 -  ///
 29.1090 -  /// A wrapper for composing the residual graph for directed flow and circulation problems.
 29.1091 -  template<typename Graph, typename Number, 
 29.1092 -	   typename CapacityMap, typename FlowMap>
 29.1093 -  class ResGraphWrapper : 
 29.1094 -    public SubBidirGraphWrapper< 
 29.1095 -    Graph, 
 29.1096 -    ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
 29.1097 -    ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
 29.1098 -  public:
 29.1099 -    typedef SubBidirGraphWrapper< 
 29.1100 -      Graph, 
 29.1101 -      ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
 29.1102 -      ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
 29.1103 -  protected:
 29.1104 -    const CapacityMap* capacity;
 29.1105 -    FlowMap* flow;
 29.1106 -    ResForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
 29.1107 -    ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
 29.1108 -    ResGraphWrapper() : Parent(), 
 29.1109 - 			capacity(0), flow(0) { }
 29.1110 -    void setCapacityMap(const CapacityMap& _capacity) {
 29.1111 -      capacity=&_capacity;
 29.1112 -      forward_filter.setCapacity(_capacity);
 29.1113 -      backward_filter.setCapacity(_capacity);
 29.1114 -    }
 29.1115 -    void setFlowMap(FlowMap& _flow) {
 29.1116 -      flow=&_flow;
 29.1117 -      forward_filter.setFlow(_flow);
 29.1118 -      backward_filter.setFlow(_flow);
 29.1119 -    }
 29.1120 -  public:
 29.1121 -    ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
 29.1122 -		       FlowMap& _flow) : 
 29.1123 -      Parent(), capacity(&_capacity), flow(&_flow), 
 29.1124 -      forward_filter(/*_graph,*/ _capacity, _flow), 
 29.1125 -      backward_filter(/*_graph,*/ _capacity, _flow) {
 29.1126 -      Parent::setGraph(_graph);
 29.1127 -      Parent::setForwardFilterMap(forward_filter);
 29.1128 -      Parent::setBackwardFilterMap(backward_filter);
 29.1129 -    }
 29.1130 -
 29.1131 -    typedef typename Parent::Edge Edge;
 29.1132 -
 29.1133 -    void augment(const Edge& e, Number a) const {
 29.1134 -      if (Parent::forward(e))  
 29.1135 -	flow->set(e, (*flow)[e]+a);
 29.1136 -      else  
 29.1137 -	flow->set(e, (*flow)[e]-a);
 29.1138 -    }
 29.1139 -
 29.1140 -    /// \brief Residual capacity map.
 29.1141 -    ///
 29.1142 -    /// In generic residual graphs the residual capacity can be obtained 
 29.1143 -    /// as a map. 
 29.1144 -    class ResCap {
 29.1145 -    protected:
 29.1146 -      const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>* res_graph;
 29.1147 -    public:
 29.1148 -      typedef Number ValueType;
 29.1149 -      typedef Edge KeyType;
 29.1150 -      ResCap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& 
 29.1151 -	     _res_graph) : res_graph(&_res_graph) { }
 29.1152 -      Number operator[](const Edge& e) const { 
 29.1153 -	if (res_graph->forward(e)) 
 29.1154 -	  return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e]; 
 29.1155 -	else 
 29.1156 -	  return (*(res_graph->flow))[e]; 
 29.1157 -      }
 29.1158 -    };
 29.1159 -
 29.1160 -    //    KEEP_MAPS(Parent, ResGraphWrapper);
 29.1161 -  };
 29.1162 -
 29.1163 -
 29.1164 -  /// For blocking flows.
 29.1165 -
 29.1166 -  ///\warning Graph wrappers are in even more experimental state than the other
 29.1167 -  ///parts of the lib. Use them at you own risk.
 29.1168 -  ///
 29.1169 -  /// This graph wrapper is used for on-the-fly 
 29.1170 -  /// Dinits blocking flow computations.
 29.1171 -  /// For each node, an out-edge is stored which is used when the 
 29.1172 -  /// \code 
 29.1173 -  /// OutEdgeIt& first(OutEdgeIt&, const Node&)
 29.1174 -  /// \endcode
 29.1175 -  /// is called. 
 29.1176 -  ///
 29.1177 -  /// \author Marton Makai
 29.1178 -  template<typename Graph, typename FirstOutEdgesMap>
 29.1179 -  class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
 29.1180 -  public:
 29.1181 -    typedef GraphWrapper<Graph> Parent; 
 29.1182 -  protected:
 29.1183 -    FirstOutEdgesMap* first_out_edges;
 29.1184 -  public:
 29.1185 -    ErasingFirstGraphWrapper(Graph& _graph, 
 29.1186 -			     FirstOutEdgesMap& _first_out_edges) : 
 29.1187 -      GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
 29.1188 -
 29.1189 -    typedef typename GraphWrapper<Graph>::Node Node;
 29.1190 -    typedef typename GraphWrapper<Graph>::Edge Edge;
 29.1191 -    class OutEdgeIt : public Edge { 
 29.1192 -      friend class GraphWrapper<Graph>;
 29.1193 -      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 29.1194 -      const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
 29.1195 -    public:
 29.1196 -      OutEdgeIt() { }
 29.1197 -      OutEdgeIt(Invalid i) : Edge(i) { }
 29.1198 -      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
 29.1199 -		const Node& n) : 
 29.1200 -	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
 29.1201 -      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
 29.1202 -		const Edge& e) : 
 29.1203 -	Edge(e), gw(&_gw) { }
 29.1204 -      OutEdgeIt& operator++() { 
 29.1205 -	*(static_cast<Edge*>(this))=
 29.1206 -	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
 29.1207 -	return *this; 
 29.1208 -      }
 29.1209 -    };
 29.1210 -
 29.1211 -    using GraphWrapper<Graph>::first;
 29.1212 -    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 29.1213 -      i=OutEdgeIt(*this, p); return i;
 29.1214 -    }
 29.1215 -    void erase(const Edge& e) const {
 29.1216 -      Node n=tail(e);
 29.1217 -      typename Graph::OutEdgeIt f(*Parent::graph, n);
 29.1218 -      ++f;
 29.1219 -      first_out_edges->set(n, f);
 29.1220 -    }
 29.1221 -
 29.1222 -    //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
 29.1223 -  };
 29.1224 -
 29.1225 -  ///@}
 29.1226 -
 29.1227 -} //namespace hugo
 29.1228 -
 29.1229 -#endif //HUGO_GRAPH_WRAPPER_H
 29.1230 -
    30.1 --- a/src/hugo/invalid.h	Wed Sep 29 14:12:26 2004 +0000
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,52 +0,0 @@
    30.4 -/* -*- C++ -*-
    30.5 - * src/hugo/invalid.h - Part of HUGOlib, a generic C++ optimization library
    30.6 - *
    30.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    30.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    30.9 - *
   30.10 - * Permission to use, modify and distribute this software is granted
   30.11 - * provided that this copyright notice appears in all copies. For
   30.12 - * precise terms see the accompanying LICENSE file.
   30.13 - *
   30.14 - * This software is provided "AS IS" with no warranty of any kind,
   30.15 - * express or implied, and with no claim as to its suitability for any
   30.16 - * purpose.
   30.17 - *
   30.18 - */
   30.19 -
   30.20 -#ifndef HUGO_INVALID_H
   30.21 -#define HUGO_INVALID_H
   30.22 -
   30.23 -///\file
   30.24 -///\brief Definition of INVALID.
   30.25 -
   30.26 -namespace hugo {
   30.27 -
   30.28 -  /// Dummy type to make it easier to make invalid iterators.
   30.29 -  
   30.30 -  /// See \ref INVALID, how to use it.
   30.31 -  
   30.32 -  struct Invalid {
   30.33 -  public:
   30.34 -    bool operator==(Invalid) { return true;  }
   30.35 -    bool operator!=(Invalid) { return false; }
   30.36 -    bool operator< (Invalid) { return false; }
   30.37 -  };
   30.38 -  
   30.39 -  /// Invalid iterators.
   30.40 -  
   30.41 -  /// \ref Invalid is a global type that converts to each iterator
   30.42 -  /// in such a way that the value of the target iterator will be invalid.
   30.43 -
   30.44 -  // It is also used to convert the \c INVALID constant to the
   30.45 -  // node iterator that makes is possible to write 
   30.46 -
   30.47 -  //extern Invalid INVALID;
   30.48 -
   30.49 -  //const Invalid &INVALID = *(Invalid *)0;
   30.50 -  const Invalid INVALID = Invalid();
   30.51 -
   30.52 -} //namespace hugo
   30.53 -
   30.54 -#endif
   30.55 -  
    31.1 --- a/src/hugo/kruskal.h	Wed Sep 29 14:12:26 2004 +0000
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,348 +0,0 @@
    31.4 -/* -*- C++ -*-
    31.5 - * src/hugo/kruskal.h - Part of HUGOlib, a generic C++ optimization library
    31.6 - *
    31.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    31.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    31.9 - *
   31.10 - * Permission to use, modify and distribute this software is granted
   31.11 - * provided that this copyright notice appears in all copies. For
   31.12 - * precise terms see the accompanying LICENSE file.
   31.13 - *
   31.14 - * This software is provided "AS IS" with no warranty of any kind,
   31.15 - * express or implied, and with no claim as to its suitability for any
   31.16 - * purpose.
   31.17 - *
   31.18 - */
   31.19 -
   31.20 -#ifndef HUGO_KRUSKAL_H
   31.21 -#define HUGO_KRUSKAL_H
   31.22 -
   31.23 -#include <algorithm>
   31.24 -#include <hugo/unionfind.h>
   31.25 -
   31.26 -/**
   31.27 -@defgroup spantree Minimum Cost Spanning Tree Algorithms
   31.28 -@ingroup galgs
   31.29 -\brief This group containes the algorithms for finding a minimum cost spanning
   31.30 -tree in a graph
   31.31 -
   31.32 -This group containes the algorithms for finding a minimum cost spanning
   31.33 -tree in a graph
   31.34 -*/
   31.35 -
   31.36 -///\ingroup spantree
   31.37 -///\file
   31.38 -///\brief Kruskal's algorithm to compute a minimum cost tree
   31.39 -///
   31.40 -///Kruskal's algorithm to compute a minimum cost tree.
   31.41 -
   31.42 -namespace hugo {
   31.43 -
   31.44 -  /// \addtogroup spantree
   31.45 -  /// @{
   31.46 -
   31.47 -  /// Kruskal's algorithm to find a minimum cost tree of a graph.
   31.48 -
   31.49 -  /// This function runs Kruskal's algorithm to find a minimum cost tree.
   31.50 -  /// \param G The graph the algorithm runs on. The algorithm considers the
   31.51 -  /// graph to be undirected, the direction of the edges are not used.
   31.52 -  ///
   31.53 -  /// \param in This object is used to describe the edge costs. It must
   31.54 -  /// be an STL compatible 'Forward Container'
   31.55 -  /// with <tt>std::pair<GR::Edge,X></tt> as its <tt>value_type</tt>,
   31.56 -  /// where X is the type of the costs. It must contain every edge in
   31.57 -  /// cost-ascending order.
   31.58 -  ///\par
   31.59 -  /// For the sake of simplicity, there is a helper class KruskalMapInput,
   31.60 -  /// which converts a
   31.61 -  /// simple edge map to an input of this form. Alternatively, you can use
   31.62 -  /// the function \ref kruskalEdgeMap to compute the minimum cost tree if
   31.63 -  /// the edge costs are given by an edge map.
   31.64 -  ///
   31.65 -  /// \retval out This must be a writable \c bool edge map.
   31.66 -  /// After running the algorithm
   31.67 -  /// this will contain the found minimum cost spanning tree: the value of an
   31.68 -  /// edge will be set to \c true if it belongs to the tree, otherwise it will
   31.69 -  /// be set to \c false. The value of each edge will be set exactly once.
   31.70 -  ///
   31.71 -  /// \return The cost of the found tree.
   31.72 -
   31.73 -  template <class GR, class IN, class OUT>
   31.74 -  typename IN::value_type::second_type
   31.75 -  kruskal(GR const& G, IN const& in, 
   31.76 -		 OUT& out)
   31.77 -  {
   31.78 -    typedef typename IN::value_type::second_type EdgeCost;
   31.79 -    typedef typename GR::template NodeMap<int> NodeIntMap;
   31.80 -    typedef typename GR::Node Node;
   31.81 -
   31.82 -    NodeIntMap comp(G, -1);
   31.83 -    UnionFind<Node,NodeIntMap> uf(comp); 
   31.84 -      
   31.85 -    EdgeCost tot_cost = 0;
   31.86 -    for (typename IN::const_iterator p = in.begin(); 
   31.87 -	 p!=in.end(); ++p ) {
   31.88 -      if ( uf.join(G.head((*p).first),
   31.89 -		   G.tail((*p).first)) ) {
   31.90 -	out.set((*p).first, true);
   31.91 -	tot_cost += (*p).second;
   31.92 -      }
   31.93 -      else {
   31.94 -	out.set((*p).first, false);
   31.95 -      }
   31.96 -    }
   31.97 -    return tot_cost;
   31.98 -  }
   31.99 -
  31.100 -  /* A work-around for running Kruskal with const-reference bool maps... */
  31.101 -
  31.102 -  /// Helper class for calling kruskal with "constant" output map.
  31.103 -
  31.104 -  /// Helper class for calling kruskal with output maps constructed
  31.105 -  /// on-the-fly.
  31.106 -  ///
  31.107 -  /// A typical examle is the following call:
  31.108 -  /// <tt>kruskal(G, some_input, makeSequenceOutput(iterator))</tt>.
  31.109 -  /// Here, the third argument is a temporary object (which wraps around an
  31.110 -  /// iterator with a writable bool map interface), and thus by rules of C++
  31.111 -  /// is a \c const object. To enable call like this exist this class and
  31.112 -  /// the prototype of the \ref kruskal() function with <tt>const& OUT</tt>
  31.113 -  /// third argument.
  31.114 -  template<class Map>
  31.115 -  class NonConstMapWr {
  31.116 -    const Map &m;
  31.117 -  public:
  31.118 -    typedef typename Map::ValueType ValueType;
  31.119 -
  31.120 -    NonConstMapWr(const Map &_m) : m(_m) {}
  31.121 -
  31.122 -    template<class KeyType>
  31.123 -    void set(KeyType const& k, ValueType const &v) const { m.set(k,v); }
  31.124 -  };
  31.125 -
  31.126 -  template <class GR, class IN, class OUT>
  31.127 -  inline
  31.128 -  typename IN::value_type::second_type
  31.129 -  kruskal(GR const& G, IN const& edges, OUT const& out_map)
  31.130 -  {
  31.131 -    NonConstMapWr<OUT> map_wr(out_map);
  31.132 -    return kruskal(G, edges, map_wr);
  31.133 -  }  
  31.134 -
  31.135 -  /* ** ** Input-objects ** ** */
  31.136 -
  31.137 -  /// Kruskal input source.
  31.138 -
  31.139 -  /// Kruskal input source.
  31.140 -  ///
  31.141 -  /// In most cases you possibly want to use the \ref kruskalEdgeMap() instead.
  31.142 -  ///
  31.143 -  /// \sa makeKruskalMapInput()
  31.144 -  ///
  31.145 -  ///\param GR The type of the graph the algorithm runs on.
  31.146 -  ///\param Map An edge map containing the cost of the edges.
  31.147 -  ///\par
  31.148 -  ///The cost type can be any type satisfying
  31.149 -  ///the STL 'LessThan comparable'
  31.150 -  ///concept if it also has an operator+() implemented. (It is necessary for
  31.151 -  ///computing the total cost of the tree).
  31.152 -  ///
  31.153 -  template<class GR, class Map>
  31.154 -  class KruskalMapInput
  31.155 -    : public std::vector< std::pair<typename GR::Edge,
  31.156 -				    typename Map::ValueType> > {
  31.157 -    
  31.158 -  public:
  31.159 -    typedef std::vector< std::pair<typename GR::Edge,
  31.160 -				   typename Map::ValueType> > Parent;
  31.161 -    typedef typename Parent::value_type value_type;
  31.162 -
  31.163 -  private:
  31.164 -    class comparePair {
  31.165 -    public:
  31.166 -      bool operator()(const value_type& a,
  31.167 -		      const value_type& b) {
  31.168 -	return a.second < b.second;
  31.169 -      }
  31.170 -    };
  31.171 -
  31.172 -  public:
  31.173 -
  31.174 -    void sort() {
  31.175 -      std::sort(this->begin(), this->end(), comparePair());
  31.176 -    }
  31.177 -
  31.178 -    KruskalMapInput(GR const& G, Map const& m) {
  31.179 -      typedef typename GR::EdgeIt EdgeIt;
  31.180 -      
  31.181 -      for(EdgeIt e(G);e!=INVALID;++e) push_back(value_type(e, m[e]));
  31.182 -      sort();
  31.183 -    }
  31.184 -  };
  31.185 -
  31.186 -  /// Creates a KruskalMapInput object for \ref kruskal()
  31.187 -
  31.188 -  /// It makes is easier to use 
  31.189 -  /// \ref KruskalMapInput by making it unnecessary 
  31.190 -  /// to explicitly give the type of the parameters.
  31.191 -  ///
  31.192 -  /// In most cases you possibly
  31.193 -  /// want to use the function kruskalEdgeMap() instead.
  31.194 -  ///
  31.195 -  ///\param G The type of the graph the algorithm runs on.
  31.196 -  ///\param m An edge map containing the cost of the edges.
  31.197 -  ///\par
  31.198 -  ///The cost type can be any type satisfying the
  31.199 -  ///STL 'LessThan Comparable'
  31.200 -  ///concept if it also has an operator+() implemented. (It is necessary for
  31.201 -  ///computing the total cost of the tree).
  31.202 -  ///
  31.203 -  ///\return An appropriate input source for \ref kruskal().
  31.204 -  ///
  31.205 -  template<class GR, class Map>
  31.206 -  inline
  31.207 -  KruskalMapInput<GR,Map> makeKruskalMapInput(const GR &G,const Map &m)
  31.208 -  {
  31.209 -    return KruskalMapInput<GR,Map>(G,m);
  31.210 -  }
  31.211 -  
  31.212 -  
  31.213 -
  31.214 -  /* ** ** Output-objects: simple writable bool maps ** ** */
  31.215 -  
  31.216 -
  31.217 -
  31.218 -  /// A writable bool-map that makes a sequence of "true" keys
  31.219 -
  31.220 -  /// A writable bool-map that creates a sequence out of keys that receives
  31.221 -  /// the value "true".
  31.222 -  ///
  31.223 -  /// \sa makeKruskalSequenceOutput()
  31.224 -  ///
  31.225 -  /// Very often, when looking for a min cost spanning tree, we want as
  31.226 -  /// output a container containing the edges of the found tree. For this
  31.227 -  /// purpose exist this class that wraps around an STL iterator with a
  31.228 -  /// writable bool map interface. When a key gets value "true" this key
  31.229 -  /// is added to sequence pointed by the iterator.
  31.230 -  ///
  31.231 -  /// A typical usage:
  31.232 -  /// \code
  31.233 -  /// std::vector<Graph::Edge> v;
  31.234 -  /// kruskal(g, input, makeKruskalSequenceOutput(back_inserter(v)));
  31.235 -  /// \endcode
  31.236 -  /// 
  31.237 -  /// For the most common case, when the input is given by a simple edge
  31.238 -  /// map and the output is a sequence of the tree edges, a special
  31.239 -  /// wrapper function exists: \ref kruskalEdgeMap_IteratorOut().
  31.240 -  ///
  31.241 -  /// \warning Not a regular property map, as it doesn't know its KeyType
  31.242 -
  31.243 -  template<class Iterator>
  31.244 -  class KruskalSequenceOutput {
  31.245 -    mutable Iterator it;
  31.246 -
  31.247 -  public:
  31.248 -    typedef bool ValueType;
  31.249 -
  31.250 -    KruskalSequenceOutput(Iterator const &_it) : it(_it) {}
  31.251 -
  31.252 -    template<typename KeyType>
  31.253 -    void set(KeyType const& k, bool v) const { if(v) {*it=k; ++it;} }
  31.254 -  };
  31.255 -
  31.256 -  template<class Iterator>
  31.257 -  inline
  31.258 -  KruskalSequenceOutput<Iterator>
  31.259 -  makeKruskalSequenceOutput(Iterator it) {
  31.260 -    return KruskalSequenceOutput<Iterator>(it);
  31.261 -  }
  31.262 -
  31.263 -
  31.264 -
  31.265 -  /* ** ** Wrapper funtions ** ** */
  31.266 -
  31.267 -
  31.268 -
  31.269 -  /// \brief Wrapper function to kruskal().
  31.270 -  /// Input is from an edge map, output is a plain bool map.
  31.271 -  ///
  31.272 -  /// Wrapper function to kruskal().
  31.273 -  /// Input is from an edge map, output is a plain bool map.
  31.274 -  ///
  31.275 -  ///\param G The type of the graph the algorithm runs on.
  31.276 -  ///\param in An edge map containing the cost of the edges.
  31.277 -  ///\par
  31.278 -  ///The cost type can be any type satisfying the
  31.279 -  ///STL 'LessThan Comparable'
  31.280 -  ///concept if it also has an operator+() implemented. (It is necessary for
  31.281 -  ///computing the total cost of the tree).
  31.282 -  ///
  31.283 -  /// \retval out This must be a writable \c bool edge map.
  31.284 -  /// After running the algorithm
  31.285 -  /// this will contain the found minimum cost spanning tree: the value of an
  31.286 -  /// edge will be set to \c true if it belongs to the tree, otherwise it will
  31.287 -  /// be set to \c false. The value of each edge will be set exactly once.
  31.288 -  ///
  31.289 -  /// \return The cost of the found tree.
  31.290 -
  31.291 -  template <class GR, class IN, class RET>
  31.292 -  inline
  31.293 -  typename IN::ValueType
  31.294 -  kruskalEdgeMap(GR const& G,
  31.295 -		 IN const& in,
  31.296 -		 RET &out) {
  31.297 -    return kruskal(G,
  31.298 -		   KruskalMapInput<GR,IN>(G,in),
  31.299 -		   out);
  31.300 -  }
  31.301 -
  31.302 -  /// \brief Wrapper function to kruskal().
  31.303 -  /// Input is from an edge map, output is an STL Sequence.
  31.304 -  ///
  31.305 -  /// Wrapper function to kruskal().
  31.306 -  /// Input is from an edge map, output is an STL Sequence.
  31.307 -  ///
  31.308 -  ///\param G The type of the graph the algorithm runs on.
  31.309 -  ///\param in An edge map containing the cost of the edges.
  31.310 -  ///\par
  31.311 -  ///The cost type can be any type satisfying the
  31.312 -  ///STL 'LessThan Comparable'
  31.313 -  ///concept if it also has an operator+() implemented. (It is necessary for
  31.314 -  ///computing the total cost of the tree).
  31.315 -  ///
  31.316 -  /// \retval out This must be an iteraror of an STL Container with
  31.317 -  /// <tt>GR::Edge</tt> as its <tt>value_type</tt>.
  31.318 -  /// The algorithm copies the elements of the found tree into this sequence.
  31.319 -  /// For example, if we know that the spanning tree of the graph \c G has
  31.320 -  /// say 53 edges then
  31.321 -  /// we can put its edges into a STL vector \c tree with a code like this.
  31.322 -  /// \code
  31.323 -  /// std::vector<Edge> tree(53);
  31.324 -  /// kruskalEdgeMap_IteratorOut(G,cost,tree.begin());
  31.325 -  /// \endcode
  31.326 -  /// Or if we don't know in advance the size of the tree, we can write this.
  31.327 -  /// \code
  31.328 -  /// std::vector<Edge> tree;
  31.329 -  /// kruskalEdgeMap_IteratorOut(G,cost,std::back_inserter(tree));
  31.330 -  /// \endcode
  31.331 -  ///
  31.332 -  /// \return The cost of the found tree.
  31.333 -  ///
  31.334 -  /// \bug its name does not follow the coding style.
  31.335 -
  31.336 -  template <class GR, class IN, class RET>
  31.337 -  inline
  31.338 -  typename IN::ValueType
  31.339 -  kruskalEdgeMap_IteratorOut(const GR& G,
  31.340 -			     const IN& in,
  31.341 -			     RET out)
  31.342 -  {
  31.343 -    KruskalSequenceOutput<RET> _out(out);
  31.344 -    return kruskal(G, KruskalMapInput<GR,IN>(G, in), _out);
  31.345 -  }
  31.346 -
  31.347 -  /// @}
  31.348 -
  31.349 -} //namespace hugo
  31.350 -
  31.351 -#endif //HUGO_KRUSKAL_H
    32.1 --- a/src/hugo/list_graph.h	Wed Sep 29 14:12:26 2004 +0000
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,1106 +0,0 @@
    32.4 -/* -*- C++ -*-
    32.5 - * src/hugo/list_graph.h - Part of HUGOlib, a generic C++ optimization library
    32.6 - *
    32.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    32.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    32.9 - *
   32.10 - * Permission to use, modify and distribute this software is granted
   32.11 - * provided that this copyright notice appears in all copies. For
   32.12 - * precise terms see the accompanying LICENSE file.
   32.13 - *
   32.14 - * This software is provided "AS IS" with no warranty of any kind,
   32.15 - * express or implied, and with no claim as to its suitability for any
   32.16 - * purpose.
   32.17 - *
   32.18 - */
   32.19 -
   32.20 -#ifndef HUGO_LIST_GRAPH_H
   32.21 -#define HUGO_LIST_GRAPH_H
   32.22 -
   32.23 -///\ingroup graphs
   32.24 -///\file
   32.25 -///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
   32.26 -
   32.27 -#include <vector>
   32.28 -#include <climits>
   32.29 -
   32.30 -#include <hugo/invalid.h>
   32.31 -
   32.32 -#include <hugo/map_registry.h>
   32.33 -#include <hugo/array_map.h>
   32.34 -
   32.35 -#include <hugo/sym_map.h>
   32.36 -
   32.37 -#include <hugo/map_defines.h>
   32.38 -
   32.39 -
   32.40 -namespace hugo {
   32.41 -
   32.42 -/// \addtogroup graphs
   32.43 -/// @{
   32.44 -
   32.45 -  ///A list graph class.
   32.46 -
   32.47 -  ///This is a simple and fast erasable graph implementation.
   32.48 -  ///
   32.49 -  ///It conforms to the
   32.50 -  ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
   32.51 -  ///\sa skeleton::ErasableGraph.
   32.52 -  class ListGraph {
   32.53 -
   32.54 -    //Nodes are double linked.
   32.55 -    //The free nodes are only single linked using the "next" field.
   32.56 -    struct NodeT 
   32.57 -    {
   32.58 -      int first_in,first_out;
   32.59 -      int prev, next;
   32.60 -    };
   32.61 -    //Edges are double linked.
   32.62 -    //The free edges are only single linked using the "next_in" field.
   32.63 -    struct EdgeT 
   32.64 -    {
   32.65 -      int head, tail;
   32.66 -      int prev_in, prev_out;
   32.67 -      int next_in, next_out;
   32.68 -    };
   32.69 -
   32.70 -    std::vector<NodeT> nodes;
   32.71 -    //The first node
   32.72 -    int first_node;
   32.73 -    //The first free node
   32.74 -    int first_free_node;
   32.75 -    std::vector<EdgeT> edges;
   32.76 -    //The first free edge
   32.77 -    int first_free_edge;
   32.78 -    
   32.79 -  public:
   32.80 -    
   32.81 -    typedef ListGraph Graph;
   32.82 -    
   32.83 -    class Node;
   32.84 -    class Edge;
   32.85 -
   32.86 -    
   32.87 -  public:
   32.88 -
   32.89 -    class NodeIt;
   32.90 -    class EdgeIt;
   32.91 -    class OutEdgeIt;
   32.92 -    class InEdgeIt;
   32.93 -
   32.94 -    // Create map registries.
   32.95 -    CREATE_MAP_REGISTRIES;
   32.96 -    // Create node and edge maps.
   32.97 -    CREATE_MAPS(ArrayMap);
   32.98 -
   32.99 -  public:
  32.100 -
  32.101 -    ListGraph() 
  32.102 -      : nodes(), first_node(-1),
  32.103 -	first_free_node(-1), edges(), first_free_edge(-1) {}
  32.104 -
  32.105 -    ListGraph(const ListGraph &_g) 
  32.106 -      : nodes(_g.nodes), first_node(_g.first_node),
  32.107 -	first_free_node(_g.first_free_node), edges(_g.edges),
  32.108 -	first_free_edge(_g.first_free_edge) {}
  32.109 -    
  32.110 -    ///Number of nodes.
  32.111 -    int nodeNum() const { return nodes.size(); }
  32.112 -    ///Number of edges.
  32.113 -    int edgeNum() const { return edges.size(); }
  32.114 -
  32.115 -    ///Set the expected maximum number of edges.
  32.116 -
  32.117 -    ///With this function, it is possible to set the expected number of edges.
  32.118 -    ///The use of this fasten the building of the graph and makes
  32.119 -    ///it possible to avoid the superfluous memory allocation.
  32.120 -    void reserveEdge(int n) { edges.reserve(n); };
  32.121 -    
  32.122 -    /// Maximum node ID.
  32.123 -    
  32.124 -    /// Maximum node ID.
  32.125 -    ///\sa id(Node)
  32.126 -    int maxNodeId() const { return nodes.size()-1; } 
  32.127 -    /// Maximum edge ID.
  32.128 -    
  32.129 -    /// Maximum edge ID.
  32.130 -    ///\sa id(Edge)
  32.131 -    int maxEdgeId() const { return edges.size()-1; }
  32.132 -
  32.133 -    Node tail(Edge e) const { return edges[e.n].tail; }
  32.134 -    Node head(Edge e) const { return edges[e.n].head; }
  32.135 -
  32.136 -    NodeIt& first(NodeIt& v) const { 
  32.137 -      v=NodeIt(*this); return v; }
  32.138 -    EdgeIt& first(EdgeIt& e) const { 
  32.139 -      e=EdgeIt(*this); return e; }
  32.140 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  32.141 -      e=OutEdgeIt(*this,v); return e; }
  32.142 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  32.143 -      e=InEdgeIt(*this,v); return e; }
  32.144 -
  32.145 -    /// Node ID.
  32.146 -    
  32.147 -    /// The ID of a valid Node is a nonnegative integer not greater than
  32.148 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  32.149 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  32.150 -    ///
  32.151 -    /// The ID of the \ref INVALID node is -1.
  32.152 -    ///\return The ID of the node \c v. 
  32.153 -    static int id(Node v) { return v.n; }
  32.154 -    /// Edge ID.
  32.155 -    
  32.156 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  32.157 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  32.158 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  32.159 -    ///
  32.160 -    /// The ID of the \ref INVALID edge is -1.
  32.161 -    ///\return The ID of the edge \c e. 
  32.162 -    static int id(Edge e) { return e.n; }
  32.163 -
  32.164 -    /// Adds a new node to the graph.
  32.165 -
  32.166 -    /// \warning It adds the new node to the front of the list.
  32.167 -    /// (i.e. the lastly added node becomes the first.)
  32.168 -    Node addNode() {
  32.169 -      int n;
  32.170 -      
  32.171 -      if(first_free_node==-1)
  32.172 -	{
  32.173 -	  n = nodes.size();
  32.174 -	  nodes.push_back(NodeT());
  32.175 -	}
  32.176 -      else {
  32.177 -	n = first_free_node;
  32.178 -	first_free_node = nodes[n].next;
  32.179 -      }
  32.180 -      
  32.181 -      nodes[n].next = first_node;
  32.182 -      if(first_node != -1) nodes[first_node].prev = n;
  32.183 -      first_node = n;
  32.184 -      nodes[n].prev = -1;
  32.185 -      
  32.186 -      nodes[n].first_in = nodes[n].first_out = -1;
  32.187 -      
  32.188 -      Node nn; nn.n=n;
  32.189 -
  32.190 -      //Update dynamic maps
  32.191 -      node_maps.add(nn);
  32.192 -
  32.193 -      return nn;
  32.194 -    }
  32.195 -    
  32.196 -    Edge addEdge(Node u, Node v) {
  32.197 -      int n;
  32.198 -      
  32.199 -      if(first_free_edge==-1)
  32.200 -	{
  32.201 -	  n = edges.size();
  32.202 -	  edges.push_back(EdgeT());
  32.203 -	}
  32.204 -      else {
  32.205 -	n = first_free_edge;
  32.206 -	first_free_edge = edges[n].next_in;
  32.207 -      }
  32.208 -      
  32.209 -      edges[n].tail = u.n; edges[n].head = v.n;
  32.210 -
  32.211 -      edges[n].next_out = nodes[u.n].first_out;
  32.212 -      if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
  32.213 -      edges[n].next_in = nodes[v.n].first_in;
  32.214 -      if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
  32.215 -      edges[n].prev_in = edges[n].prev_out = -1;
  32.216 -	
  32.217 -      nodes[u.n].first_out = nodes[v.n].first_in = n;
  32.218 -
  32.219 -      Edge e; e.n=n;
  32.220 -
  32.221 -      //Update dynamic maps
  32.222 -      edge_maps.add(e);
  32.223 -
  32.224 -      return e;
  32.225 -    }
  32.226 -    
  32.227 -    /// Finds an edge between two nodes.
  32.228 -
  32.229 -    /// Finds an edge from node \c u to node \c v.
  32.230 -    ///
  32.231 -    /// If \c prev is \ref INVALID (this is the default value), then
  32.232 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  32.233 -    /// the next edge from \c u to \c v after \c prev.
  32.234 -    /// \return The found edge or INVALID if there is no such an edge.
  32.235 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  32.236 -    {
  32.237 -      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
  32.238 -      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
  32.239 -      prev.n=e;
  32.240 -      return prev;
  32.241 -    }
  32.242 -    
  32.243 -  private:
  32.244 -    void eraseEdge(int n) {
  32.245 -      
  32.246 -      if(edges[n].next_in!=-1)
  32.247 -	edges[edges[n].next_in].prev_in = edges[n].prev_in;
  32.248 -      if(edges[n].prev_in!=-1)
  32.249 -	edges[edges[n].prev_in].next_in = edges[n].next_in;
  32.250 -      else nodes[edges[n].head].first_in = edges[n].next_in;
  32.251 -      
  32.252 -      if(edges[n].next_out!=-1)
  32.253 -	edges[edges[n].next_out].prev_out = edges[n].prev_out;
  32.254 -      if(edges[n].prev_out!=-1)
  32.255 -	edges[edges[n].prev_out].next_out = edges[n].next_out;
  32.256 -      else nodes[edges[n].tail].first_out = edges[n].next_out;
  32.257 -      
  32.258 -      edges[n].next_in = first_free_edge;
  32.259 -      first_free_edge = n;      
  32.260 -
  32.261 -      //Update dynamic maps
  32.262 -      Edge e; e.n=n;
  32.263 -      edge_maps.erase(e);
  32.264 -
  32.265 -    }
  32.266 -      
  32.267 -  public:
  32.268 -
  32.269 -    void erase(Node nn) {
  32.270 -      int n=nn.n;
  32.271 -      
  32.272 -      int m;
  32.273 -      while((m=nodes[n].first_in)!=-1) eraseEdge(m);
  32.274 -      while((m=nodes[n].first_out)!=-1) eraseEdge(m);
  32.275 -
  32.276 -      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
  32.277 -      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
  32.278 -      else first_node = nodes[n].next;
  32.279 -      
  32.280 -      nodes[n].next = first_free_node;
  32.281 -      first_free_node = n;
  32.282 -
  32.283 -      //Update dynamic maps
  32.284 -      node_maps.erase(nn);
  32.285 -
  32.286 -    }
  32.287 -    
  32.288 -    void erase(Edge e) { eraseEdge(e.n); }
  32.289 -
  32.290 -    void clear() {
  32.291 -      edge_maps.clear();
  32.292 -      edges.clear();
  32.293 -      node_maps.clear();
  32.294 -      nodes.clear();
  32.295 -      first_node=first_free_node=first_free_edge=-1;
  32.296 -    }
  32.297 -
  32.298 -    class Node {
  32.299 -      friend class ListGraph;
  32.300 -      template <typename T> friend class NodeMap;
  32.301 -       
  32.302 -      friend class Edge;
  32.303 -      friend class OutEdgeIt;
  32.304 -      friend class InEdgeIt;
  32.305 -      friend class SymEdge;
  32.306 -
  32.307 -    protected:
  32.308 -      int n;
  32.309 -      friend int ListGraph::id(Node v); 
  32.310 -      Node(int nn) {n=nn;}
  32.311 -    public:
  32.312 -      Node() {}
  32.313 -      Node (Invalid) { n=-1; }
  32.314 -      bool operator==(const Node i) const {return n==i.n;}
  32.315 -      bool operator!=(const Node i) const {return n!=i.n;}
  32.316 -      bool operator<(const Node i) const {return n<i.n;}
  32.317 -      //      ///Validity check
  32.318 -      //      operator bool() { return n!=-1; }
  32.319 -    };
  32.320 -    
  32.321 -    class NodeIt : public Node {
  32.322 -      const ListGraph *G;
  32.323 -      friend class ListGraph;
  32.324 -    public:
  32.325 -      NodeIt() : Node() { }
  32.326 -      NodeIt(Invalid i) : Node(i) { }
  32.327 -      NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
  32.328 -      NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
  32.329 -      NodeIt &operator++() {
  32.330 -	n=G->nodes[n].next; 
  32.331 -	return *this; 
  32.332 -      }
  32.333 -      //      ///Validity check
  32.334 -      //      operator bool() { return Node::operator bool(); }      
  32.335 -    };
  32.336 -
  32.337 -    class Edge {
  32.338 -      friend class ListGraph;
  32.339 -      template <typename T> friend class EdgeMap;
  32.340 -
  32.341 -      friend class SymListGraph;
  32.342 -      
  32.343 -      friend class Node;
  32.344 -      friend class NodeIt;
  32.345 -    protected:
  32.346 -      int n;
  32.347 -      friend int ListGraph::id(Edge e);
  32.348 -
  32.349 -    public:
  32.350 -      /// An Edge with id \c n.
  32.351 -
  32.352 -      /// \bug It should be
  32.353 -      /// obtained by a member function of the Graph.
  32.354 -      Edge(int nn) {n=nn;}
  32.355 -
  32.356 -      Edge() { }
  32.357 -      Edge (Invalid) { n=-1; }
  32.358 -      bool operator==(const Edge i) const {return n==i.n;}
  32.359 -      bool operator!=(const Edge i) const {return n!=i.n;}
  32.360 -      bool operator<(const Edge i) const {return n<i.n;}
  32.361 -      //      ///Validity check
  32.362 -      //      operator bool() { return n!=-1; }
  32.363 -   };
  32.364 -    
  32.365 -    class EdgeIt : public Edge {
  32.366 -      const ListGraph *G;
  32.367 -      friend class ListGraph;
  32.368 -    public:
  32.369 -      EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
  32.370 -      	int m;
  32.371 -	for(m=_G.first_node;
  32.372 -	    m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
  32.373 -	n = (m==-1)?-1:_G.nodes[m].first_in;
  32.374 -      }
  32.375 -      EdgeIt (Invalid i) : Edge(i) { }
  32.376 -      EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  32.377 -      EdgeIt() : Edge() { }
  32.378 -      EdgeIt &operator++() {
  32.379 -	if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
  32.380 -	else {
  32.381 -	  int nn;
  32.382 -	  for(nn=G->nodes[G->edges[n].head].next;
  32.383 -	      nn!=-1 && G->nodes[nn].first_in == -1;
  32.384 -	      nn = G->nodes[nn].next) ;
  32.385 -	  n = (nn==-1)?-1:G->nodes[nn].first_in;
  32.386 -	}
  32.387 -	return *this;
  32.388 -      }
  32.389 -      //      ///Validity check
  32.390 -      //      operator bool() { return Edge::operator bool(); }      
  32.391 -    };
  32.392 -    
  32.393 -    class OutEdgeIt : public Edge {
  32.394 -      const ListGraph *G;
  32.395 -      friend class ListGraph;
  32.396 -    public: 
  32.397 -      OutEdgeIt() : Edge() { }
  32.398 -      OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  32.399 -      OutEdgeIt (Invalid i) : Edge(i) { }
  32.400 -
  32.401 -      OutEdgeIt(const ListGraph& _G,const Node v)
  32.402 -	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  32.403 -      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  32.404 -      //      ///Validity check
  32.405 -      //      operator bool() { return Edge::operator bool(); }      
  32.406 -    };
  32.407 -    
  32.408 -    class InEdgeIt : public Edge {
  32.409 -      const ListGraph *G;
  32.410 -      friend class ListGraph;
  32.411 -    public: 
  32.412 -      InEdgeIt() : Edge() { }
  32.413 -      InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  32.414 -      InEdgeIt (Invalid i) : Edge(i) { }
  32.415 -      InEdgeIt(const ListGraph& _G,Node v)
  32.416 -	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  32.417 -      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  32.418 -      //      ///Validity check
  32.419 -      //      operator bool() { return Edge::operator bool(); }      
  32.420 -    };
  32.421 -  };
  32.422 -
  32.423 -  ///Graph for bidirectional edges.
  32.424 -
  32.425 -  ///The purpose of this graph structure is to handle graphs
  32.426 -  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  32.427 -  ///of oppositely directed edges.
  32.428 -  ///There is a new edge map type called
  32.429 -  ///\ref hugo::SymListGraph::SymEdgeMap "SymEdgeMap"
  32.430 -  ///that complements this
  32.431 -  ///feature by
  32.432 -  ///storing shared values for the edge pairs. The usual
  32.433 -  ///\ref hugo::skeleton::StaticGraph::EdgeMap "EdgeMap"
  32.434 -  ///can be used
  32.435 -  ///as well.
  32.436 -  ///
  32.437 -  ///The oppositely directed edge can also be obtained easily
  32.438 -  ///using \ref hugo::SymListGraph::opposite() "opposite()" member function.
  32.439 -  ///
  32.440 -  ///Here erase(Edge) deletes a pair of edges.
  32.441 -  ///
  32.442 -  ///\todo this date structure need some reconsiderations. Maybe it
  32.443 -  ///should be implemented independently from ListGraph.
  32.444 -  
  32.445 -  class SymListGraph : public ListGraph
  32.446 -  {
  32.447 -  public:
  32.448 -
  32.449 -    typedef SymListGraph Graph;
  32.450 -
  32.451 -    // Create symmetric map registry.
  32.452 -    CREATE_SYM_EDGE_MAP_REGISTRY;
  32.453 -    // Create symmetric edge map.
  32.454 -    CREATE_SYM_EDGE_MAP(ArrayMap);
  32.455 -
  32.456 -    SymListGraph() : ListGraph() { }
  32.457 -    SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
  32.458 -    ///Adds a pair of oppositely directed edges to the graph.
  32.459 -    Edge addEdge(Node u, Node v)
  32.460 -    {
  32.461 -      Edge e = ListGraph::addEdge(u,v);
  32.462 -      Edge f = ListGraph::addEdge(v,u);
  32.463 -      sym_edge_maps.add(e);
  32.464 -      sym_edge_maps.add(f);
  32.465 -      
  32.466 -      return e;
  32.467 -    }
  32.468 -
  32.469 -    void erase(Node n) { ListGraph::erase(n);}
  32.470 -    ///The oppositely directed edge.
  32.471 -
  32.472 -    ///Returns the oppositely directed
  32.473 -    ///pair of the edge \c e.
  32.474 -    static Edge opposite(Edge e)
  32.475 -    {
  32.476 -      Edge f;
  32.477 -      f.n = e.n - 2*(e.n%2) + 1;
  32.478 -      return f;
  32.479 -    }
  32.480 -    
  32.481 -    ///Removes a pair of oppositely directed edges to the graph.
  32.482 -    void erase(Edge e) {
  32.483 -      Edge f = opposite(e);
  32.484 -      sym_edge_maps.erase(e);
  32.485 -      sym_edge_maps.erase(f);
  32.486 -      ListGraph::erase(f);
  32.487 -      ListGraph::erase(e);
  32.488 -    }    
  32.489 -  };
  32.490 -
  32.491 -
  32.492 -  ///A graph class containing only nodes.
  32.493 -
  32.494 -  ///This class implements a graph structure without edges.
  32.495 -  ///The most useful application of this class is to be the node set of an
  32.496 -  ///\ref EdgeSet class.
  32.497 -  ///
  32.498 -  ///It conforms to 
  32.499 -  ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept
  32.500 -  ///with the exception that you cannot
  32.501 -  ///add (or delete) edges. The usual edge iterators are exists, but they are
  32.502 -  ///always \ref INVALID.
  32.503 -  ///\sa skeleton::ExtendableGraph
  32.504 -  ///\sa EdgeSet
  32.505 -  class NodeSet {
  32.506 -
  32.507 -    //Nodes are double linked.
  32.508 -    //The free nodes are only single linked using the "next" field.
  32.509 -    struct NodeT 
  32.510 -    {
  32.511 -      int first_in,first_out;
  32.512 -      int prev, next;
  32.513 -      //      NodeT() {}
  32.514 -    };
  32.515 -
  32.516 -    std::vector<NodeT> nodes;
  32.517 -    //The first node
  32.518 -    int first_node;
  32.519 -    //The first free node
  32.520 -    int first_free_node;
  32.521 -    
  32.522 -  public:
  32.523 -
  32.524 -    typedef NodeSet Graph;
  32.525 -    
  32.526 -    class Node;
  32.527 -    class Edge;
  32.528 -
  32.529 -  public:
  32.530 -
  32.531 -    class NodeIt;
  32.532 -    class EdgeIt;
  32.533 -    class OutEdgeIt;
  32.534 -    class InEdgeIt;
  32.535 -    
  32.536 -    // Create node map registry.
  32.537 -    CREATE_NODE_MAP_REGISTRY;
  32.538 -    // Create node maps.
  32.539 -    CREATE_NODE_MAP(ArrayMap);
  32.540 -
  32.541 -    /// Creating empty map structure for edges.
  32.542 -    template <typename Value>
  32.543 -    class EdgeMap {
  32.544 -    public:
  32.545 -      EdgeMap(const Graph&) {}
  32.546 -      EdgeMap(const Graph&, const Value&) {}
  32.547 -
  32.548 -      EdgeMap(const EdgeMap&) {}
  32.549 -      template <typename CMap> EdgeMap(const CMap&) {}
  32.550 -
  32.551 -      EdgeMap& operator=(const EdgeMap&) {}
  32.552 -      template <typename CMap> EdgeMap& operator=(const CMap&) {}
  32.553 -      
  32.554 -      class ConstIterator {
  32.555 -      public:
  32.556 -	bool operator==(const ConstIterator&) {return true;}
  32.557 -	bool operator!=(const ConstIterator&) {return false;}
  32.558 -      };
  32.559 -
  32.560 -      typedef ConstIterator Iterator;
  32.561 -      
  32.562 -      Iterator begin() { return Iterator();}
  32.563 -      Iterator end() { return Iterator();}
  32.564 -
  32.565 -      ConstIterator begin() const { return ConstIterator();}
  32.566 -      ConstIterator end() const { return ConstIterator();}
  32.567 -
  32.568 -    };
  32.569 -    
  32.570 -  public:
  32.571 -
  32.572 -    ///Default constructor
  32.573 -    NodeSet() 
  32.574 -      : nodes(), first_node(-1), first_free_node(-1) {}
  32.575 -    ///Copy constructor
  32.576 -    NodeSet(const NodeSet &_g) 
  32.577 -      : nodes(_g.nodes), first_node(_g.first_node),
  32.578 -	first_free_node(_g.first_free_node) {}
  32.579 -    
  32.580 -    ///Number of nodes.
  32.581 -    int nodeNum() const { return nodes.size(); }
  32.582 -    ///Number of edges.
  32.583 -    int edgeNum() const { return 0; }
  32.584 -
  32.585 -    /// Maximum node ID.
  32.586 -    
  32.587 -    /// Maximum node ID.
  32.588 -    ///\sa id(Node)
  32.589 -    int maxNodeId() const { return nodes.size()-1; }
  32.590 -    /// Maximum edge ID.
  32.591 -    
  32.592 -    /// Maximum edge ID.
  32.593 -    ///\sa id(Edge)
  32.594 -    int maxEdgeId() const { return 0; }
  32.595 -
  32.596 -    Node tail(Edge e) const { return INVALID; }
  32.597 -    Node head(Edge e) const { return INVALID; }
  32.598 -
  32.599 -    NodeIt& first(NodeIt& v) const { 
  32.600 -      v=NodeIt(*this); return v; }
  32.601 -    EdgeIt& first(EdgeIt& e) const { 
  32.602 -      e=EdgeIt(*this); return e; }
  32.603 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  32.604 -      e=OutEdgeIt(*this,v); return e; }
  32.605 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  32.606 -      e=InEdgeIt(*this,v); return e; }
  32.607 -
  32.608 -    /// Node ID.
  32.609 -    
  32.610 -    /// The ID of a valid Node is a nonnegative integer not greater than
  32.611 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  32.612 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  32.613 -    ///
  32.614 -    /// The ID of the \ref INVALID node is -1.
  32.615 -    ///\return The ID of the node \c v. 
  32.616 -    static int id(Node v) { return v.n; }
  32.617 -    /// Edge ID.
  32.618 -    
  32.619 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  32.620 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  32.621 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  32.622 -    ///
  32.623 -    /// The ID of the \ref INVALID edge is -1.
  32.624 -    ///\return The ID of the edge \c e. 
  32.625 -    static int id(Edge e) { return -1; }
  32.626 -
  32.627 -    /// Adds a new node to the graph.
  32.628 -
  32.629 -    /// \warning It adds the new node to the front of the list.
  32.630 -    /// (i.e. the lastly added node becomes the first.)
  32.631 -    Node addNode() {
  32.632 -      int n;
  32.633 -      
  32.634 -      if(first_free_node==-1)
  32.635 -	{
  32.636 -	  n = nodes.size();
  32.637 -	  nodes.push_back(NodeT());
  32.638 -	}
  32.639 -      else {
  32.640 -	n = first_free_node;
  32.641 -	first_free_node = nodes[n].next;
  32.642 -      }
  32.643 -      
  32.644 -      nodes[n].next = first_node;
  32.645 -      if(first_node != -1) nodes[first_node].prev = n;
  32.646 -      first_node = n;
  32.647 -      nodes[n].prev = -1;
  32.648 -      
  32.649 -      nodes[n].first_in = nodes[n].first_out = -1;
  32.650 -      
  32.651 -      Node nn; nn.n=n;
  32.652 -
  32.653 -      //Update dynamic maps
  32.654 -      node_maps.add(nn);
  32.655 -
  32.656 -      return nn;
  32.657 -    }
  32.658 -    
  32.659 -    void erase(Node nn) {
  32.660 -      int n=nn.n;
  32.661 -      
  32.662 -      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
  32.663 -      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
  32.664 -      else first_node = nodes[n].next;
  32.665 -      
  32.666 -      nodes[n].next = first_free_node;
  32.667 -      first_free_node = n;
  32.668 -
  32.669 -      //Update dynamic maps
  32.670 -      node_maps.erase(nn);
  32.671 -    }
  32.672 -    
  32.673 -        
  32.674 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  32.675 -    {
  32.676 -      return INVALID;
  32.677 -    }
  32.678 -    
  32.679 -    void clear() {
  32.680 -      node_maps.clear();
  32.681 -      nodes.clear();
  32.682 -      first_node = first_free_node = -1;
  32.683 -    }
  32.684 -
  32.685 -    class Node {
  32.686 -      friend class NodeSet;
  32.687 -      template <typename T> friend class NodeMap;
  32.688 -      
  32.689 -      friend class Edge;
  32.690 -      friend class OutEdgeIt;
  32.691 -      friend class InEdgeIt;
  32.692 -
  32.693 -    protected:
  32.694 -      int n;
  32.695 -      friend int NodeSet::id(Node v); 
  32.696 -      Node(int nn) {n=nn;}
  32.697 -    public:
  32.698 -      Node() {}
  32.699 -      Node (Invalid i) { n=-1; }
  32.700 -      bool operator==(const Node i) const {return n==i.n;}
  32.701 -      bool operator!=(const Node i) const {return n!=i.n;}
  32.702 -      bool operator<(const Node i) const {return n<i.n;}
  32.703 -    };
  32.704 -    
  32.705 -    class NodeIt : public Node {
  32.706 -      const NodeSet *G;
  32.707 -      friend class NodeSet;
  32.708 -    public:
  32.709 -      NodeIt() : Node() { }
  32.710 -      NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
  32.711 -      NodeIt(Invalid i) : Node(i) { }
  32.712 -      NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
  32.713 -      NodeIt &operator++() {
  32.714 -	n=G->nodes[n].next; 
  32.715 -	return *this; 
  32.716 -      }
  32.717 -    };
  32.718 -
  32.719 -    class Edge {
  32.720 -    public:
  32.721 -      Edge() { }
  32.722 -      Edge (Invalid) { }
  32.723 -      bool operator==(const Edge i) const {return true;}
  32.724 -      bool operator!=(const Edge i) const {return false;}
  32.725 -      bool operator<(const Edge i) const {return false;}
  32.726 -    };
  32.727 -    
  32.728 -    class EdgeIt : public Edge {
  32.729 -    public:
  32.730 -      EdgeIt(const NodeSet& G) : Edge() { }
  32.731 -      EdgeIt(const NodeSet&, Edge) : Edge() { }
  32.732 -      EdgeIt (Invalid i) : Edge(i) { }
  32.733 -      EdgeIt() : Edge() { }
  32.734 -      EdgeIt operator++() { return INVALID; }
  32.735 -    };
  32.736 -    
  32.737 -    class OutEdgeIt : public Edge {
  32.738 -      friend class NodeSet;
  32.739 -    public: 
  32.740 -      OutEdgeIt() : Edge() { }
  32.741 -      OutEdgeIt(const NodeSet&, Edge) : Edge() { }
  32.742 -      OutEdgeIt (Invalid i) : Edge(i) { }
  32.743 -      OutEdgeIt(const NodeSet& G,const Node v)	: Edge() {}
  32.744 -      OutEdgeIt operator++() { return INVALID; }
  32.745 -    };
  32.746 -    
  32.747 -    class InEdgeIt : public Edge {
  32.748 -      friend class NodeSet;
  32.749 -    public: 
  32.750 -      InEdgeIt() : Edge() { }
  32.751 -      InEdgeIt(const NodeSet&, Edge) : Edge() { }
  32.752 -      InEdgeIt (Invalid i) : Edge(i) { }
  32.753 -      InEdgeIt(const NodeSet& G,Node v) :Edge() {}
  32.754 -      InEdgeIt operator++() { return INVALID; }
  32.755 -    };
  32.756 -
  32.757 -  };
  32.758 -
  32.759 -
  32.760 -
  32.761 -  ///Graph structure using a node set of another graph.
  32.762 -
  32.763 -  ///This structure can be used to establish another graph over a node set
  32.764 -  /// of an existing one. The node iterator will go through the nodes of the
  32.765 -  /// original graph, and the NodeMap's of both graphs will convert to
  32.766 -  /// each other.
  32.767 -  ///
  32.768 -  ///\warning Adding or deleting nodes from the graph is not safe if an
  32.769 -  ///\ref EdgeSet is currently attached to it!
  32.770 -  ///
  32.771 -  ///\todo Make it possible to add/delete edges from the base graph
  32.772 -  ///(and from \ref EdgeSet, as well)
  32.773 -  ///
  32.774 -  ///\param GG The type of the graph which shares its node set with this class.
  32.775 -  ///Its interface must conform to the
  32.776 -  ///\ref skeleton::StaticGraph "StaticGraph" concept.
  32.777 -  ///
  32.778 -  ///It conforms to the 
  32.779 -  ///\ref skeleton::ExtendableGraph "ExtendableGraph" concept.
  32.780 -  ///\sa skeleton::ExtendableGraph.
  32.781 -  ///\sa NodeSet.
  32.782 -  template<typename GG>
  32.783 -  class EdgeSet {
  32.784 -
  32.785 -    typedef GG NodeGraphType;
  32.786 -
  32.787 -    NodeGraphType &G;
  32.788 -
  32.789 -  public:
  32.790 -
  32.791 -    class Node;
  32.792 -    class Edge;
  32.793 -    class OutEdgeIt;
  32.794 -    class InEdgeIt;
  32.795 -    class SymEdge;
  32.796 -
  32.797 -    typedef EdgeSet Graph;
  32.798 -
  32.799 -    int id(Node v) const; 
  32.800 -
  32.801 -    class Node : public NodeGraphType::Node {
  32.802 -      friend class EdgeSet;
  32.803 -      
  32.804 -      friend class Edge;
  32.805 -      friend class OutEdgeIt;
  32.806 -      friend class InEdgeIt;
  32.807 -      friend class SymEdge;
  32.808 -
  32.809 -    public:
  32.810 -      friend int EdgeSet::id(Node v) const; 
  32.811 -    public:
  32.812 -      Node() : NodeGraphType::Node() {}
  32.813 -      Node (Invalid i) : NodeGraphType::Node(i) {}
  32.814 -      Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
  32.815 -    };
  32.816 -    
  32.817 -    class NodeIt : public NodeGraphType::NodeIt {
  32.818 -      friend class EdgeSet;
  32.819 -    public:
  32.820 -      NodeIt() : NodeGraphType::NodeIt() { }
  32.821 -      NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
  32.822 -      NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
  32.823 -      NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
  32.824 -      NodeIt(const typename NodeGraphType::NodeIt &n)
  32.825 -	: NodeGraphType::NodeIt(n) {}
  32.826 -
  32.827 -      operator Node() { return Node(*this);}
  32.828 -      NodeIt &operator++()
  32.829 -      { this->NodeGraphType::NodeIt::operator++(); return *this;} 
  32.830 -    };
  32.831 -
  32.832 -  private:
  32.833 -    //Edges are double linked.
  32.834 -    //The free edges are only single linked using the "next_in" field.
  32.835 -    struct NodeT 
  32.836 -    {
  32.837 -      int first_in,first_out;
  32.838 -      NodeT() : first_in(-1), first_out(-1) { }
  32.839 -    };
  32.840 -
  32.841 -    struct EdgeT 
  32.842 -    {
  32.843 -      Node head, tail;
  32.844 -      int prev_in, prev_out;
  32.845 -      int next_in, next_out;
  32.846 -    };
  32.847 -
  32.848 -    
  32.849 -    typename NodeGraphType::template NodeMap<NodeT> nodes;
  32.850 -    
  32.851 -    std::vector<EdgeT> edges;
  32.852 -    //The first free edge
  32.853 -    int first_free_edge;
  32.854 -    
  32.855 -  public:
  32.856 -    
  32.857 -    class Node;
  32.858 -    class Edge;
  32.859 -
  32.860 -    class NodeIt;
  32.861 -    class EdgeIt;
  32.862 -    class OutEdgeIt;
  32.863 -    class InEdgeIt;
  32.864 -
  32.865 -
  32.866 -    // Create edge map registry.
  32.867 -    CREATE_EDGE_MAP_REGISTRY;
  32.868 -    // Create edge maps.
  32.869 -    CREATE_EDGE_MAP(ArrayMap);
  32.870 -
  32.871 -    // Import node maps from the NodeGraphType.
  32.872 -    IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
  32.873 -    
  32.874 -    
  32.875 -  public:
  32.876 -
  32.877 -    ///Constructor
  32.878 -    
  32.879 -    ///Construates a new graph based on the nodeset of an existing one.
  32.880 -    ///\param _G the base graph.
  32.881 -    explicit EdgeSet(NodeGraphType &_G) 
  32.882 -      : G(_G), nodes(_G), edges(),
  32.883 -	first_free_edge(-1) {}
  32.884 -    ///Copy constructor
  32.885 -
  32.886 -    ///Makes a copy of an EdgeSet.
  32.887 -    ///It will be based on the same graph.
  32.888 -    explicit EdgeSet(const EdgeSet &_g) 
  32.889 -      : G(_g.G), nodes(_g.G), edges(_g.edges),
  32.890 -	first_free_edge(_g.first_free_edge) {}
  32.891 -    
  32.892 -    ///Number of nodes.
  32.893 -    int nodeNum() const { return G.nodeNum(); }
  32.894 -    ///Number of edges.
  32.895 -    int edgeNum() const { return edges.size(); }
  32.896 -
  32.897 -    /// Maximum node ID.
  32.898 -    
  32.899 -    /// Maximum node ID.
  32.900 -    ///\sa id(Node)
  32.901 -    int maxNodeId() const { return G.maxNodeId(); }
  32.902 -    /// Maximum edge ID.
  32.903 -    
  32.904 -    /// Maximum edge ID.
  32.905 -    ///\sa id(Edge)
  32.906 -    int maxEdgeId() const { return edges.size()-1; }
  32.907 -
  32.908 -    Node tail(Edge e) const { return edges[e.n].tail; }
  32.909 -    Node head(Edge e) const { return edges[e.n].head; }
  32.910 -
  32.911 -    NodeIt& first(NodeIt& v) const { 
  32.912 -      v=NodeIt(*this); return v; }
  32.913 -    EdgeIt& first(EdgeIt& e) const { 
  32.914 -      e=EdgeIt(*this); return e; }
  32.915 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  32.916 -      e=OutEdgeIt(*this,v); return e; }
  32.917 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  32.918 -      e=InEdgeIt(*this,v); return e; }
  32.919 -
  32.920 -    /// Node ID.
  32.921 -    
  32.922 -    /// The ID of a valid Node is a nonnegative integer not greater than
  32.923 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  32.924 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  32.925 -    ///
  32.926 -    /// The ID of the \ref INVALID node is -1.
  32.927 -    ///\return The ID of the node \c v. 
  32.928 -    int id(Node v) { return G.id(v); }
  32.929 -    /// Edge ID.
  32.930 -    
  32.931 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  32.932 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  32.933 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  32.934 -    ///
  32.935 -    /// The ID of the \ref INVALID edge is -1.
  32.936 -    ///\return The ID of the edge \c e. 
  32.937 -    static int id(Edge e) { return e.n; }
  32.938 -
  32.939 -    /// Adds a new node to the graph.
  32.940 -    Node addNode() { return G.addNode(); }
  32.941 -    
  32.942 -    Edge addEdge(Node u, Node v) {
  32.943 -      int n;
  32.944 -      
  32.945 -      if(first_free_edge==-1)
  32.946 -	{
  32.947 -	  n = edges.size();
  32.948 -	  edges.push_back(EdgeT());
  32.949 -	}
  32.950 -      else {
  32.951 -	n = first_free_edge;
  32.952 -	first_free_edge = edges[n].next_in;
  32.953 -      }
  32.954 -      
  32.955 -      edges[n].tail = u; edges[n].head = v;
  32.956 -
  32.957 -      edges[n].next_out = nodes[u].first_out;
  32.958 -      if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
  32.959 -      edges[n].next_in = nodes[v].first_in;
  32.960 -      if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
  32.961 -      edges[n].prev_in = edges[n].prev_out = -1;
  32.962 -	
  32.963 -      nodes[u].first_out = nodes[v].first_in = n;
  32.964 -
  32.965 -      Edge e; e.n=n;
  32.966 -
  32.967 -      //Update dynamic maps
  32.968 -      edge_maps.add(e);
  32.969 -
  32.970 -      return e;
  32.971 -    }
  32.972 -
  32.973 -    /// Finds an edge between two nodes.
  32.974 -
  32.975 -    /// Finds an edge from node \c u to node \c v.
  32.976 -    ///
  32.977 -    /// If \c prev is \ref INVALID (this is the default value), then
  32.978 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  32.979 -    /// the next edge from \c u to \c v after \c prev.
  32.980 -    /// \return The found edge or INVALID if there is no such an edge.
  32.981 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  32.982 -    {
  32.983 -      int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
  32.984 -      while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
  32.985 -      prev.n=e;
  32.986 -      return prev;
  32.987 -    }
  32.988 -    
  32.989 -  private:
  32.990 -    void eraseEdge(int n) {
  32.991 -      
  32.992 -      if(edges[n].next_in!=-1)
  32.993 -	edges[edges[n].next_in].prev_in = edges[n].prev_in;
  32.994 -      if(edges[n].prev_in!=-1)
  32.995 -	edges[edges[n].prev_in].next_in = edges[n].next_in;
  32.996 -      else nodes[edges[n].head].first_in = edges[n].next_in;
  32.997 -      
  32.998 -      if(edges[n].next_out!=-1)
  32.999 -	edges[edges[n].next_out].prev_out = edges[n].prev_out;
 32.1000 -      if(edges[n].prev_out!=-1)
 32.1001 -	edges[edges[n].prev_out].next_out = edges[n].next_out;
 32.1002 -      else nodes[edges[n].tail].first_out = edges[n].next_out;
 32.1003 -      
 32.1004 -      edges[n].next_in = first_free_edge;
 32.1005 -      first_free_edge = -1;      
 32.1006 -
 32.1007 -      //Update dynamic maps
 32.1008 -      Edge e; e.n = n;
 32.1009 -      edge_maps.erase(e);
 32.1010 -    }
 32.1011 -      
 32.1012 -  public:
 32.1013 -
 32.1014 -    void erase(Edge e) { eraseEdge(e.n); }
 32.1015 -
 32.1016 -    ///Clear all edges. (Doesn't clear the nodes!)
 32.1017 -    void clear() {
 32.1018 -      edge_maps.clear();
 32.1019 -      edges.clear();
 32.1020 -      first_free_edge=-1;
 32.1021 -    }
 32.1022 -
 32.1023 -
 32.1024 -    class Edge {
 32.1025 -    public:
 32.1026 -      friend class EdgeSet;
 32.1027 -      template <typename T> friend class EdgeMap;
 32.1028 -
 32.1029 -      friend class Node;
 32.1030 -      friend class NodeIt;
 32.1031 -    protected:
 32.1032 -      int n;
 32.1033 -      friend int EdgeSet::id(Edge e) const;
 32.1034 -
 32.1035 -      Edge(int nn) {n=nn;}
 32.1036 -    public:
 32.1037 -      Edge() { }
 32.1038 -      Edge (Invalid) { n=-1; }
 32.1039 -      bool operator==(const Edge i) const {return n==i.n;}
 32.1040 -      bool operator!=(const Edge i) const {return n!=i.n;}
 32.1041 -      bool operator<(const Edge i) const {return n<i.n;}
 32.1042 -    };
 32.1043 -    
 32.1044 -    class EdgeIt : public Edge {
 32.1045 -      friend class EdgeSet;
 32.1046 -      template <typename T> friend class EdgeMap;
 32.1047 -    
 32.1048 -      const EdgeSet *G;
 32.1049 -    public:
 32.1050 -      EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
 32.1051 -        NodeIt m;
 32.1052 -	for(G->first(m);
 32.1053 -	    m!=INVALID && G->nodes[m].first_in == -1;  ++m);
 32.1054 -	///\bug AJJAJ! This is a non sense!!!!!!!
 32.1055 -	this->n = m!=INVALID?-1:G->nodes[m].first_in;
 32.1056 -      }
 32.1057 -      EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 32.1058 -      EdgeIt (Invalid i) : Edge(i) { }
 32.1059 -      EdgeIt() : Edge() { }
 32.1060 -      ///.
 32.1061 -      
 32.1062 -      ///\bug UNIMPLEMENTED!!!!!
 32.1063 -      //
 32.1064 -      EdgeIt &operator++() {
 32.1065 -	return *this;
 32.1066 -      }
 32.1067 -    };
 32.1068 -    
 32.1069 -    class OutEdgeIt : public Edge {
 32.1070 -      const EdgeSet *G;
 32.1071 -      friend class EdgeSet;
 32.1072 -    public: 
 32.1073 -      OutEdgeIt() : Edge() { }
 32.1074 -      OutEdgeIt (Invalid i) : Edge(i) { }
 32.1075 -      OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 32.1076 -
 32.1077 -      OutEdgeIt(const EdgeSet& _G,const Node v) :
 32.1078 -	Edge(_G.nodes[v].first_out), G(&_G) { }
 32.1079 -      OutEdgeIt &operator++() { 
 32.1080 -	Edge::n = G->edges[Edge::n].next_out;
 32.1081 -	return *this; 
 32.1082 -      }
 32.1083 -    };
 32.1084 -    
 32.1085 -    class InEdgeIt : public Edge {
 32.1086 -      const EdgeSet *G;
 32.1087 -      friend class EdgeSet;
 32.1088 -    public: 
 32.1089 -      InEdgeIt() : Edge() { }
 32.1090 -      InEdgeIt (Invalid i) : Edge(i) { }
 32.1091 -      InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 32.1092 -      InEdgeIt(const EdgeSet& _G,Node v)
 32.1093 -	: Edge(_G.nodes[v].first_in), G(&_G) { }
 32.1094 -      InEdgeIt &operator++() { 
 32.1095 -	Edge::n = G->edges[Edge::n].next_in; 
 32.1096 -	return *this; 
 32.1097 -      }
 32.1098 -    };
 32.1099 -    
 32.1100 -  };
 32.1101 -
 32.1102 -  template<typename GG>
 32.1103 -  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
 32.1104 -
 32.1105 -/// @}  
 32.1106 -
 32.1107 -} //namespace hugo
 32.1108 -
 32.1109 -#endif //HUGO_LIST_GRAPH_H
    33.1 --- a/src/hugo/map_bits.h	Wed Sep 29 14:12:26 2004 +0000
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,67 +0,0 @@
    33.4 -/* -*- C++ -*-
    33.5 - * src/hugo/map_bits.h - Part of HUGOlib, a generic C++ optimization library
    33.6 - *
    33.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    33.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    33.9 - *
   33.10 - * Permission to use, modify and distribute this software is granted
   33.11 - * provided that this copyright notice appears in all copies. For
   33.12 - * precise terms see the accompanying LICENSE file.
   33.13 - *
   33.14 - * This software is provided "AS IS" with no warranty of any kind,
   33.15 - * express or implied, and with no claim as to its suitability for any
   33.16 - * purpose.
   33.17 - *
   33.18 - */
   33.19 -
   33.20 -#ifndef HUGO_MAP_BITS_H
   33.21 -#define HUGO_MAP_BITS_H
   33.22 -
   33.23 -///\ingroup graphmaps
   33.24 -///\file
   33.25 -///\brief Some utils to help implement maps.
   33.26 -
   33.27 -namespace hugo {
   33.28 -
   33.29 -
   33.30 -  /// \addtogroup graphmaps
   33.31 -  /// @{
   33.32 -
   33.33 -  /// Helper class to get information about the key type.
   33.34 -  template <typename Graph, typename KeyIt>
   33.35 -  struct KeyInfo {};
   33.36 -
   33.37 -  template <typename Graph>
   33.38 -  struct KeyInfo<Graph, typename Graph::NodeIt> {
   33.39 -    static int maxId(const Graph& graph) {
   33.40 -      return graph.maxNodeId();
   33.41 -    }
   33.42 -    static int id(const Graph& graph, const typename Graph::Node& node) {
   33.43 -      return graph.id(node);
   33.44 -    }
   33.45 -  };
   33.46 -
   33.47 -  template <typename Graph>
   33.48 -  struct KeyInfo<Graph, typename Graph::EdgeIt> {
   33.49 -    static int maxId(const Graph& graph) {
   33.50 -      return graph.maxEdgeId();
   33.51 -    }
   33.52 -    static int id(const Graph& graph, const typename Graph::Edge& edge) {
   33.53 -      return graph.id(edge);
   33.54 -    }
   33.55 -  };
   33.56 -
   33.57 -  template <typename Graph>
   33.58 -  struct KeyInfo<Graph, typename Graph::SymEdgeIt> {
   33.59 -    static int maxId(const Graph& graph) {
   33.60 -      return graph.maxEdgeId() >> 1;
   33.61 -    }
   33.62 -    static int id(const Graph& graph, const typename Graph::Edge& edge) {
   33.63 -      return graph.id(edge) >> 1;
   33.64 -    }
   33.65 -  };
   33.66 -
   33.67 -  /// @}
   33.68 -}
   33.69 -
   33.70 -#endif
    34.1 --- a/src/hugo/map_defines.h	Wed Sep 29 14:12:26 2004 +0000
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,228 +0,0 @@
    34.4 -/* -*- C++ -*-
    34.5 - * src/hugo/map_defines.h - Part of HUGOlib, a generic C++ optimization library
    34.6 - *
    34.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    34.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    34.9 - *
   34.10 - * Permission to use, modify and distribute this software is granted
   34.11 - * provided that this copyright notice appears in all copies. For
   34.12 - * precise terms see the accompanying LICENSE file.
   34.13 - *
   34.14 - * This software is provided "AS IS" with no warranty of any kind,
   34.15 - * express or implied, and with no claim as to its suitability for any
   34.16 - * purpose.
   34.17 - *
   34.18 - */
   34.19 -
   34.20 -#ifndef HUGO_MAP_DEFINES_H
   34.21 -#define HUGO_MAP_DEFINES_H
   34.22 -
   34.23 -///\ingroup graphmaps
   34.24 -///\file
   34.25 -///\brief Defines to help creating graph maps.
   34.26 -
   34.27 -/// \addtogroup graphmapfactory
   34.28 -/// @{
   34.29 -
   34.30 -/** Creates the EdgeMapRegistry type an declare a mutable instance 
   34.31 - *  named edge_maps.
   34.32 - */
   34.33 -#define CREATE_EDGE_MAP_REGISTRY \
   34.34 -typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
   34.35 -mutable EdgeMapRegistry edge_maps;
   34.36 -
   34.37 -/** Creates the NodeMapRegistry type an declare a mutable instance 
   34.38 - *  named node_maps.
   34.39 - */
   34.40 -#define CREATE_NODE_MAP_REGISTRY \
   34.41 -typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
   34.42 -mutable NodeMapRegistry node_maps;
   34.43 -
   34.44 -/** Creates both map registries.
   34.45 - */
   34.46 -#define CREATE_MAP_REGISTRIES \
   34.47 -CREATE_NODE_MAP_REGISTRY \
   34.48 -CREATE_EDGE_MAP_REGISTRY
   34.49 -
   34.50 -/** Creates a map from a template map. The import method is
   34.51 - *  an overloading of the map type.
   34.52 - *  The reason to use these macro is that the c++ does not support
   34.53 - *  the template typedefs. If a future release of the c++ 
   34.54 - *  supports this feature it should be fixed.
   34.55 - */
   34.56 -#define CREATE_NODE_MAP(DynMap) \
   34.57 -template <typename Value> \
   34.58 -class NodeMap : public DynMap<NodeMapRegistry, Value> { \
   34.59 -public: \
   34.60 -typedef DynMap<NodeMapRegistry, Value> Parent; \
   34.61 -NodeMap(const typename Parent::Graph& g) \
   34.62 -  : Parent(g, g.node_maps) {} \
   34.63 -NodeMap(const typename Parent::Graph& g, const Value& v) \
   34.64 -  : Parent(g, g.node_maps, v) {} \
   34.65 -NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
   34.66 -template <typename TT> \
   34.67 -NodeMap(const NodeMap<TT>& copy) \
   34.68 -  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
   34.69 -NodeMap& operator=(const NodeMap& copy) { \
   34.70 -  Parent::operator=(static_cast<const Parent&>(copy));\
   34.71 -  return *this; \
   34.72 -} \
   34.73 -template <typename TT> \
   34.74 -NodeMap& operator=(const NodeMap<TT>& copy) { \
   34.75 -  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
   34.76 -  return *this; \
   34.77 -} \
   34.78 -};
   34.79 -
   34.80 -/** Creates a map from a template map. The import method is
   34.81 - *  an overloading of the map type.
   34.82 - *  The reason to use these macro is that the c++ does not support
   34.83 - *  the template typedefs. If a future release of the c++ 
   34.84 - *  supports this feature it should be fixed.
   34.85 - */
   34.86 -#define CREATE_EDGE_MAP(DynMap) \
   34.87 -template <typename Value> \
   34.88 -class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
   34.89 -public: \
   34.90 -typedef DynMap<EdgeMapRegistry, Value> Parent; \
   34.91 -\
   34.92 -EdgeMap(const typename Parent::Graph& g) \
   34.93 -  : Parent(g, g.edge_maps) {} \
   34.94 -EdgeMap(const typename Parent::Graph& g, const Value& v) \
   34.95 -  : Parent(g, g.edge_maps, v) {} \
   34.96 -EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
   34.97 -template <typename TT> \
   34.98 -EdgeMap(const EdgeMap<TT>& copy) \
   34.99 -  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
  34.100 -EdgeMap& operator=(const EdgeMap& copy) { \
  34.101 -  Parent::operator=(static_cast<const Parent&>(copy));\
  34.102 -  return *this; \
  34.103 -} \
  34.104 -template <typename TT> \
  34.105 -EdgeMap& operator=(const EdgeMap<TT>& copy) { \
  34.106 -  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
  34.107 -  return *this; \
  34.108 -} \
  34.109 -};
  34.110 -
  34.111 -/** This macro creates both maps.
  34.112 - */
  34.113 -#define CREATE_MAPS(DynMap) \
  34.114 -CREATE_NODE_MAP(DynMap) \
  34.115 -CREATE_EDGE_MAP(DynMap)
  34.116 -
  34.117 -/** This macro creates MapRegistry for Symmetric Edge Maps.
  34.118 - */
  34.119 -#define CREATE_SYM_EDGE_MAP_REGISTRY \
  34.120 -typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
  34.121 -typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
  34.122 -mutable SymEdgeMapRegistry sym_edge_maps;
  34.123 -
  34.124 -
  34.125 -/** Creates a map from a template map. The import method is
  34.126 - *  an overloading of the map type.
  34.127 - *  The reason to use these macro is that the c++ does not support
  34.128 - *  the template typedefs. If a future release of the c++ 
  34.129 - *  supports this feature it should be fixed.
  34.130 - */
  34.131 -#define CREATE_SYM_EDGE_MAP(DynMap) \
  34.132 -template <typename Value> \
  34.133 -class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
  34.134 -public: \
  34.135 -typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \
  34.136 -\
  34.137 -SymEdgeMap(const typename Parent::Graph& g) \
  34.138 -  : Parent(g, g.sym_edge_maps) {} \
  34.139 -SymEdgeMap(const typename Parent::Graph& g, const Value& v) \
  34.140 -  : Parent(g, g.sym_edge_maps, v) {} \
  34.141 -SymEdgeMap(const SymEdgeMap& copy) \
  34.142 -  : Parent(static_cast<const Parent&>(copy)) {} \
  34.143 -template <typename TT> \
  34.144 -SymEdgeMap(const NodeMap<TT>& copy) \
  34.145 -  : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
  34.146 -SymEdgeMap& operator=(const SymEdgeMap& copy) { \
  34.147 -  Parent::operator=(static_cast<const Parent&>(copy));\
  34.148 -  return *this; \
  34.149 -} \
  34.150 -template <typename TT> \
  34.151 -SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
  34.152 -  Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
  34.153 -  return *this; \
  34.154 -} \
  34.155 -};
  34.156 -
  34.157 -/** This is a macro to import an node map into a graph class.
  34.158 - */
  34.159 -#define IMPORT_NODE_MAP(From, from, To, to) \
  34.160 -template <typename Value> \
  34.161 -class NodeMap : public From::template NodeMap<Value> { \
  34.162 -\
  34.163 -public: \
  34.164 -typedef typename From::template NodeMap<Value> Parent; \
  34.165 -\
  34.166 -NodeMap(const To& to) \
  34.167 -  : Parent(static_cast<const From&>(from)) { } \
  34.168 -NodeMap(const To& to, const Value& value) \
  34.169 -  : Parent(static_cast<const From&>(from), value) { } \
  34.170 -NodeMap(const NodeMap& copy) \
  34.171 -  : Parent(static_cast<const Parent&>(copy)) {} \
  34.172 -template <typename TT> \
  34.173 -NodeMap(const NodeMap<TT>& copy) \
  34.174 -  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
  34.175 -NodeMap& operator=(const NodeMap& copy) { \
  34.176 -  Parent::operator=(static_cast<const Parent&>(copy)); \
  34.177 -  return *this; \
  34.178 -} \
  34.179 -template <typename TT> \
  34.180 -NodeMap& operator=(const NodeMap<TT>& copy) { \
  34.181 -  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
  34.182 -  return *this; \
  34.183 -} \
  34.184 -};
  34.185 -
  34.186 -/** This is a macro to import an edge map into a graph class.
  34.187 - */
  34.188 -#define IMPORT_EDGE_MAP(From, from, To, to) \
  34.189 -template <typename Value> \
  34.190 -class EdgeMap : public From::template EdgeMap<Value> { \
  34.191 -\
  34.192 -public: \
  34.193 -typedef typename From::template EdgeMap<Value> Parent; \
  34.194 -\
  34.195 -EdgeMap(const To& to) \
  34.196 -  : Parent(static_cast<const From&>(from)) { } \
  34.197 -EdgeMap(const To& to, const Value& value) \
  34.198 -  : Parent(static_cast<const From&>(from), value) { } \
  34.199 -EdgeMap(const EdgeMap& copy) \
  34.200 -  : Parent(static_cast<const Parent&>(copy)) {} \
  34.201 -template <typename TT> \
  34.202 -EdgeMap(const EdgeMap<TT>& copy) \
  34.203 -  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
  34.204 -EdgeMap& operator=(const EdgeMap& copy) { \
  34.205 -  Parent::operator=(static_cast<const Parent&>(copy)); \
  34.206 -  return *this; \
  34.207 -} \
  34.208 -template <typename TT> \
  34.209 -EdgeMap& operator=(const EdgeMap<TT>& copy) { \
  34.210 -  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
  34.211 -  return *this; \
  34.212 -} \
  34.213 -};
  34.214 -
  34.215 -#define KEEP_EDGE_MAP(From, To) \
  34.216 -IMPORT_EDGE_MAP(From, graph, To, graph)
  34.217 -
  34.218 -
  34.219 -#define KEEP_NODE_MAP(From, To) \
  34.220 -IMPORT_NODE_MAP(From, graph, To, graph)
  34.221 -
  34.222 -/** This is a macro to keep the node and edge maps for a graph class.
  34.223 - */
  34.224 -#define KEEP_MAPS(From, To) \
  34.225 -KEEP_EDGE_MAP(From, To) \
  34.226 -KEEP_NODE_MAP(From, To)
  34.227 -
  34.228 -  
  34.229 -/// @}
  34.230 -  
  34.231 -#endif
    35.1 --- a/src/hugo/map_iterator.h	Wed Sep 29 14:12:26 2004 +0000
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,692 +0,0 @@
    35.4 -/* -*- C++ -*-
    35.5 - * src/hugo/map_iterator.h - Part of HUGOlib, a generic C++ optimization library
    35.6 - *
    35.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    35.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    35.9 - *
   35.10 - * Permission to use, modify and distribute this software is granted
   35.11 - * provided that this copyright notice appears in all copies. For
   35.12 - * precise terms see the accompanying LICENSE file.
   35.13 - *
   35.14 - * This software is provided "AS IS" with no warranty of any kind,
   35.15 - * express or implied, and with no claim as to its suitability for any
   35.16 - * purpose.
   35.17 - *
   35.18 - */
   35.19 -
   35.20 -#ifndef HUGO_MAP_ITERATOR_H
   35.21 -#define HUGO_MAP_ITERATOR_H
   35.22 -
   35.23 -#include <iterator>
   35.24 -
   35.25 -#include <hugo/extended_pair.h>
   35.26 -
   35.27 -///\ingroup graphmaps
   35.28 -///\file
   35.29 -///\brief Iterators on the maps.
   35.30 -
   35.31 -namespace hugo {
   35.32 -
   35.33 -  /// \addtogroup graphmaps
   35.34 -  /// @{
   35.35 -
   35.36 -  /** The base class all of the map iterators.
   35.37 -   *  The class defines the typedefs of the iterators,
   35.38 -   *  simple step functions and equality operators.
   35.39 -   */ 
   35.40 -
   35.41 -  template <typename Map>
   35.42 -  class MapIteratorBase {
   35.43 -
   35.44 -  public:
   35.45 -
   35.46 -    /// The key type of the iterator.
   35.47 -    typedef typename Map::KeyType KeyType;
   35.48 -    /// The iterator to iterate on the keys.
   35.49 -    typedef typename Map::KeyIt KeyIt;
   35.50 -
   35.51 -    /// The value type of the iterator.
   35.52 -    typedef typename Map::ValueType ValueType;
   35.53 -    /// The reference type of the iterator.
   35.54 -    typedef typename Map::ReferenceType ReferenceType;
   35.55 -    /// The pointer type of the iterator.
   35.56 -    typedef typename Map::PointerType PointerType;
   35.57 -
   35.58 -    /// The const value type of the iterator.
   35.59 -    typedef typename Map::ConstValueType ConstValueType;
   35.60 -    /// The const reference type of the iterator.
   35.61 -    typedef typename Map::ConstReferenceType ConstReferenceType;
   35.62 -    /// The pointer type of the iterator.
   35.63 -    typedef typename Map::ConstPointerType ConstPointerType;
   35.64 -
   35.65 -  protected:
   35.66 -
   35.67 -    KeyIt it;
   35.68 -
   35.69 -    /// Default constructor.
   35.70 -    MapIteratorBase() {}
   35.71 -
   35.72 -    /// KeyIt initialized MapIteratorBase constructor.
   35.73 -    MapIteratorBase(const KeyIt pit) : it(pit) {}
   35.74 -
   35.75 -  public:
   35.76 -
   35.77 -    /// Stepping forward in the map.   
   35.78 -    void increment() { 
   35.79 -      ++it; 
   35.80 -    }
   35.81 -
   35.82 -    /// The equality operator of the map.
   35.83 -    bool operator==(const MapIteratorBase& pit) const {
   35.84 -      return pit.it == it;
   35.85 -    }
   35.86 -	
   35.87 -    /// The not-equality operator of the map.
   35.88 -    bool operator!=(const MapIteratorBase& pit) const {
   35.89 -      return !(*this == pit);
   35.90 -    }
   35.91 -  };
   35.92 -
   35.93 -  template <typename Map> class MapConstIterator;
   35.94 -
   35.95 -  /** Compatible iterator with the stl maps' iterators.
   35.96 -   * It iterates on pairs of a key and a value.
   35.97 -   */
   35.98 -  template <typename Map>  
   35.99 -  class MapIterator : public MapIteratorBase<Map> {
  35.100 -
  35.101 -    friend class MapConstIterator<Map>;
  35.102 -
  35.103 -
  35.104 -  public:
  35.105 -
  35.106 -    /// The iterator base class.
  35.107 -    typedef MapIteratorBase<Map> Base;
  35.108 -
  35.109 -    /// The key type of the iterator.
  35.110 -    typedef typename Map::KeyType KeyType;
  35.111 -    /// The iterator to iterate on the keys.
  35.112 -    typedef typename Map::KeyIt KeyIt;
  35.113 -
  35.114 -    /// The value type of the iterator.
  35.115 -    typedef typename Map::ValueType ValueType;
  35.116 -    /// The reference type of the iterator.
  35.117 -    typedef typename Map::ReferenceType ReferenceType;
  35.118 -    /// The pointer type of the iterator.
  35.119 -    typedef typename Map::PointerType PointerType;
  35.120 -
  35.121 -    /// The const value type of the iterator.
  35.122 -    typedef typename Map::ConstValueType ConstValueType;
  35.123 -    /// The const reference type of the iterator.
  35.124 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.125 -    /// The pointer type of the iterator.
  35.126 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.127 -    
  35.128 -  public:
  35.129 -
  35.130 -    /// The value type of the iterator.
  35.131 -    typedef extended_pair<KeyType, const KeyType&,
  35.132 -      ValueType, const ValueType&> PairValueType;
  35.133 -
  35.134 -    /// The reference type of the iterator. 
  35.135 -    typedef extended_pair<const KeyType&, const KeyType&, 
  35.136 -      ReferenceType, ReferenceType> PairReferenceType;
  35.137 -
  35.138 -    /// Default constructor. 
  35.139 -    MapIterator() {}
  35.140 -
  35.141 -    /// Constructor to initalize the iterators returned 
  35.142 -    /// by the begin() and end().
  35.143 -    MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
  35.144 -
  35.145 -    /// Dereference operator for the iterator.
  35.146 -    PairReferenceType operator*() {
  35.147 -      return PairReferenceType(Base::it, (*map)[Base::it]);
  35.148 -    }
  35.149 -
  35.150 -    /// The pointer type of the iterator.
  35.151 -    class PairPointerType {
  35.152 -      friend class MapIterator;
  35.153 -    private:
  35.154 -      PairReferenceType data;
  35.155 -      PairPointerType(const KeyType& key, ReferenceType val) 
  35.156 -	: data(key, val) {}
  35.157 -    public:
  35.158 -      PairReferenceType* operator->() {return &data;}
  35.159 -    };
  35.160 -
  35.161 -    /// Arrow operator for the iterator.
  35.162 -    PairPointerType operator->() {
  35.163 -      return PairPointerType(Base::it, ((*map)[Base::it])); 
  35.164 -    }
  35.165 -	
  35.166 -    /// The pre increment operator of the iterator.
  35.167 -    MapIterator& operator++() { 
  35.168 -      Base::increment(); 
  35.169 -      return *this; 
  35.170 -    }
  35.171 -
  35.172 -    /// The post increment operator of the iterator.
  35.173 -    MapIterator operator++(int) { 
  35.174 -      MapIterator tmp(*this); 
  35.175 -      Base::increment(); 
  35.176 -      return tmp; 
  35.177 -    }
  35.178 -
  35.179 -  private:
  35.180 -    Map* map;
  35.181 -
  35.182 -  public:
  35.183 -    // STL  compatibility typedefs.
  35.184 -    typedef std::forward_iterator_tag iterator_category;
  35.185 -    typedef int difference_type;
  35.186 -    typedef PairValueType value_type;
  35.187 -    typedef PairReferenceType reference;
  35.188 -    typedef PairPointerType pointer;
  35.189 -  };
  35.190 -
  35.191 -  /** Compatible iterator with the stl maps' iterators.
  35.192 -   *  It iterates on pairs of a key and a value.
  35.193 -   */
  35.194 -  template <typename Map>
  35.195 -  class MapConstIterator : public MapIteratorBase<Map> {
  35.196 -    
  35.197 -  public:
  35.198 -
  35.199 -    /// The iterator base class.
  35.200 -    typedef MapIteratorBase<Map> Base;
  35.201 -
  35.202 -    /// The key type of the iterator.
  35.203 -    typedef typename Map::KeyType KeyType;
  35.204 -    /// The iterator to iterate on the keys.
  35.205 -    typedef typename Map::KeyIt KeyIt;
  35.206 -
  35.207 -    /// The value type of the iterator.
  35.208 -    typedef typename Map::ValueType ValueType;
  35.209 -    /// The reference type of the iterator.
  35.210 -    typedef typename Map::ReferenceType ReferenceType;
  35.211 -    /// The pointer type of the iterator.
  35.212 -    typedef typename Map::PointerType PointerType;
  35.213 -
  35.214 -    /// The const value type of the iterator.
  35.215 -    typedef typename Map::ConstValueType ConstValueType;
  35.216 -    /// The const reference type of the iterator.
  35.217 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.218 -    /// The pointer type of the iterator.
  35.219 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.220 -
  35.221 -  public:    
  35.222 -
  35.223 -    /// Default constructor. 
  35.224 -    MapConstIterator() {}
  35.225 -
  35.226 -    /// Constructor to initalize the the iterators returned
  35.227 -    ///  by the begin() and end().
  35.228 -    MapConstIterator(const Map& pmap, const KeyIt& pit) 
  35.229 -      : Base(pit), map(&pmap) {}
  35.230 -
  35.231 -    /// Constructor to create const iterator from a non const.
  35.232 -    MapConstIterator(const MapIterator<Map>& pit) {
  35.233 -      Base::it = pit.Base::it;
  35.234 -      map = pit.map;
  35.235 -    }
  35.236 -
  35.237 -    /// The value type of the iterator.
  35.238 -    typedef extended_pair<KeyType, const KeyType&,
  35.239 -      ValueType, const ValueType&> PairValueType;
  35.240 -
  35.241 -    /// The reference type of map.
  35.242 -    typedef extended_pair<const KeyType&, const KeyType&, 
  35.243 -      ConstReferenceType, ConstReferenceType> PairReferenceType;
  35.244 -
  35.245 -    /// Dereference operator for the iterator.
  35.246 -    PairReferenceType operator*() {
  35.247 -      return PairReferenceType(Base::it, (*map)[Base::it]);
  35.248 -    }
  35.249 -
  35.250 -    /// The pointer type of the iterator.
  35.251 -    class PairPointerType {
  35.252 -      friend class MapConstIterator;
  35.253 -    private:
  35.254 -      PairReferenceType data;
  35.255 -      PairPointerType(const KeyType& key, ConstReferenceType val) 
  35.256 -	: data(key, val) {}
  35.257 -    public:
  35.258 -      PairReferenceType* operator->() {return &data;}
  35.259 -    };
  35.260 -
  35.261 -    /// Arrow operator for the iterator.
  35.262 -    PairPointerType operator->() {
  35.263 -      return PairPointerType(Base::it, (*map)[Base::it]); 
  35.264 -    }
  35.265 -
  35.266 -    /// The pre increment operator of the iterator.
  35.267 -    MapConstIterator& operator++() { 
  35.268 -      Base::increment(); 
  35.269 -      return *this; 
  35.270 -    }
  35.271 -
  35.272 -    /// The post increment operator of the iterator.
  35.273 -    MapConstIterator operator++(int) { 
  35.274 -      MapConstIterator tmp(*this); 
  35.275 -      Base::increment(); 
  35.276 -      return tmp; 
  35.277 -    }
  35.278 -
  35.279 -  private:
  35.280 -    const Map* map;
  35.281 -
  35.282 -  public:
  35.283 -    // STL  compatibility typedefs.
  35.284 -    typedef std::input_iterator_tag iterator_category;
  35.285 -    typedef int difference_type;
  35.286 -    typedef PairValueType value_type;
  35.287 -    typedef PairReferenceType reference;
  35.288 -    typedef PairPointerType pointer;
  35.289 -  };
  35.290 -
  35.291 -  /** The class makes the KeyIt to an stl compatible iterator
  35.292 -   *  with dereferencing operator.
  35.293 -   */
  35.294 -  template <typename Map>
  35.295 -  class MapKeyIterator : public MapIteratorBase<Map> {
  35.296 -
  35.297 -  public:
  35.298 -
  35.299 -    /// The iterator base class.
  35.300 -    typedef MapIteratorBase<Map> Base;
  35.301 - 
  35.302 -    /// The key type of the iterator.
  35.303 -    typedef typename Map::KeyType KeyType;
  35.304 -    /// The iterator to iterate on the keys.
  35.305 -    typedef typename Map::KeyIt KeyIt;
  35.306 -
  35.307 -  public:
  35.308 -
  35.309 -    /// Default constructor.
  35.310 -    MapKeyIterator() {}
  35.311 -
  35.312 -    /// KeyIt initialized iterator.
  35.313 -    MapKeyIterator(const KeyIt& pit) : Base(pit) {}
  35.314 -
  35.315 -    /// The pre increment operator of the iterator.
  35.316 -    MapKeyIterator& operator++() {
  35.317 -      Base::increment(); 
  35.318 -      return *this; 
  35.319 -    }
  35.320 -
  35.321 -    /// The post increment operator of the iterator.
  35.322 -    MapKeyIterator operator++(int) {
  35.323 -      MapKeyIterator tmp(*this);
  35.324 -      Base::increment();
  35.325 -      return tmp;
  35.326 -    }
  35.327 -
  35.328 -    /// The dereferencing operator of the iterator.
  35.329 -    KeyType operator*() const {
  35.330 -      return static_cast<KeyType>(Base::it);
  35.331 -    }
  35.332 -
  35.333 -  public:
  35.334 -    // STL  compatibility typedefs.
  35.335 -    typedef std::input_iterator_tag iterator_category;
  35.336 -    typedef int difference_type;
  35.337 -    typedef KeyType value_type;
  35.338 -    typedef const KeyType& reference;
  35.339 -    typedef const KeyType* pointer;
  35.340 -  };
  35.341 -
  35.342 -  template <typename Map> class MapConstValueIterator;
  35.343 -
  35.344 -  /** MapValueIterator creates an stl compatible iterator
  35.345 -   *  for the values.
  35.346 -   */
  35.347 -  template <typename Map>
  35.348 -  class MapValueIterator : public MapIteratorBase<Map> {
  35.349 -
  35.350 -    friend class MapConstValueIterator<Map>;
  35.351 -
  35.352 -  public:
  35.353 -
  35.354 -    /// The iterator base class.
  35.355 -    typedef MapIteratorBase<Map> Base;
  35.356 -
  35.357 -    /// The key type of the iterator.
  35.358 -    typedef typename Map::KeyType KeyType;
  35.359 -    /// The iterator to iterate on the keys.
  35.360 -    typedef typename Map::KeyIt KeyIt;
  35.361 -
  35.362 -
  35.363 -    /// The value type of the iterator.
  35.364 -    typedef typename Map::ValueType ValueType;
  35.365 -    /// The reference type of the iterator.
  35.366 -    typedef typename Map::ReferenceType ReferenceType;
  35.367 -    /// The pointer type of the iterator.
  35.368 -    typedef typename Map::PointerType PointerType;
  35.369 -
  35.370 -    /// The const value type of the iterator.
  35.371 -    typedef typename Map::ConstValueType ConstValueType;
  35.372 -    /// The const reference type of the iterator.
  35.373 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.374 -    /// The pointer type of the iterator.
  35.375 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.376 -
  35.377 -  private:
  35.378 -
  35.379 -    Map* map;
  35.380 -
  35.381 -  public:
  35.382 -
  35.383 -    /// Default constructor.
  35.384 -    MapValueIterator() {}
  35.385 -
  35.386 -    /// Map and KeyIt initialized iterator.
  35.387 -    MapValueIterator(Map& pmap, const KeyIt& pit) 
  35.388 -      : Base(pit), map(&pmap) {}
  35.389 -    
  35.390 -
  35.391 -    /// The pre increment operator of the iterator.
  35.392 -    MapValueIterator& operator++() {
  35.393 -      Base::increment(); 
  35.394 -      return *this; 
  35.395 -    }
  35.396 -
  35.397 -    /// The post increment operator of the iterator.
  35.398 -    MapValueIterator operator++(int) {
  35.399 -      MapValueIterator tmp(*this);
  35.400 -      Base::increment();
  35.401 -      return tmp;
  35.402 -    }
  35.403 -
  35.404 -    /// The dereferencing operator of the iterator.
  35.405 -    ReferenceType operator*() const {
  35.406 -      return (*map)[Base::it];
  35.407 -    }
  35.408 -
  35.409 -    /// The arrow operator of the iterator.
  35.410 -    PointerType operator->() const {
  35.411 -      return &(operator*());
  35.412 -    }
  35.413 -
  35.414 -  public:
  35.415 -    // STL  compatibility typedefs.
  35.416 -    typedef std::forward_iterator_tag iterator_category;
  35.417 -    typedef int difference_type;
  35.418 -    typedef ValueType value_type;
  35.419 -    typedef ReferenceType reference;
  35.420 -    typedef PointerType pointer;
  35.421 -  };
  35.422 -
  35.423 -  /** MapValueIterator creates an stl compatible iterator
  35.424 -   *  for the const values.
  35.425 -   */
  35.426 -
  35.427 -  template <typename Map>
  35.428 -  class MapConstValueIterator : public MapIteratorBase<Map> {
  35.429 -
  35.430 -  public:
  35.431 -
  35.432 -    /// The iterator base class.
  35.433 -    typedef MapIteratorBase<Map> Base;
  35.434 -
  35.435 -    /// The key type of the iterator.
  35.436 -    typedef typename Map::KeyType KeyType;
  35.437 -    /// The iterator to iterate on the keys.
  35.438 -    typedef typename Map::KeyIt KeyIt;
  35.439 -
  35.440 -    /// The value type of the iterator.
  35.441 -    typedef typename Map::ValueType ValueType;
  35.442 -    /// The reference type of the iterator.
  35.443 -    typedef typename Map::ReferenceType ReferenceType;
  35.444 -    /// The pointer type of the iterator.
  35.445 -    typedef typename Map::PointerType PointerType;
  35.446 -
  35.447 -    /// The const value type of the iterator.
  35.448 -    typedef typename Map::ConstValueType ConstValueType;
  35.449 -    /// The const reference type of the iterator.
  35.450 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.451 -    /// The pointer type of the iterator.
  35.452 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.453 -
  35.454 -  private:
  35.455 -
  35.456 -    const Map* map;
  35.457 -
  35.458 -  public:
  35.459 -
  35.460 -    /// Default constructor.
  35.461 -    MapConstValueIterator() {}
  35.462 -
  35.463 -    /// Constructor to create const iterator from a non const.
  35.464 -    MapConstValueIterator(const MapValueIterator<Map>& pit) {
  35.465 -      Base::it = pit.Base::it;
  35.466 -      map = pit.map;
  35.467 -    }
  35.468 -
  35.469 -    /// Map and KeyIt initialized iterator.
  35.470 -    MapConstValueIterator(const Map& pmap, const KeyIt& pit) 
  35.471 -      : Base(pit), map(&pmap) {}
  35.472 -
  35.473 -    /// The pre increment operator of the iterator.
  35.474 -    MapConstValueIterator& operator++() {
  35.475 -      Base::increment(); 
  35.476 -      return *this; 
  35.477 -    }
  35.478 -
  35.479 -    /// The post increment operator of the iterator.
  35.480 -    MapConstValueIterator operator++(int) {
  35.481 -      MapConstValueIterator tmp(*this);
  35.482 -      Base::increment();
  35.483 -      return tmp;
  35.484 -    }
  35.485 -
  35.486 -    /// The dereferencing operator of the iterator.
  35.487 -    ConstReferenceType operator*() const {
  35.488 -      return (*map)[Base::it];
  35.489 -    }
  35.490 -
  35.491 -    /// The arrow operator of the iterator.
  35.492 -    ConstPointerType operator->() const {
  35.493 -      return &(operator*());
  35.494 -    }
  35.495 -
  35.496 -  public:
  35.497 -    // STL  compatibility typedefs.
  35.498 -    typedef std::input_iterator_tag iterator_category;
  35.499 -    typedef int difference_type;
  35.500 -    typedef ValueType value_type;
  35.501 -    typedef ConstReferenceType reference;
  35.502 -    typedef ConstPointerType pointer;
  35.503 -  };
  35.504 -
  35.505 -
  35.506 -  /** This class makes from a map an iteratable set
  35.507 -   *  which contains all the keys of the map.
  35.508 -   */
  35.509 -  template <typename Map>
  35.510 -  class MapConstKeySet {
  35.511 -
  35.512 -    const Map* map;
  35.513 -
  35.514 -  public:
  35.515 -
  35.516 -    /// The key type of the iterator.
  35.517 -    typedef typename Map::KeyType KeyType;
  35.518 -    /// The iterator to iterate on the keys.
  35.519 -    typedef typename Map::KeyIt KeyIt;
  35.520 -
  35.521 -
  35.522 -    /// The value type of the iterator.
  35.523 -    typedef typename Map::ValueType ValueType;
  35.524 -    /// The reference type of the iterator.
  35.525 -    typedef typename Map::ReferenceType ReferenceType;
  35.526 -    /// The pointer type of the iterator.
  35.527 -    typedef typename Map::PointerType PointerType;
  35.528 -
  35.529 -    /// The const value type of the iterator.
  35.530 -    typedef typename Map::ConstValueType ConstValueType;
  35.531 -    /// The const reference type of the iterator.
  35.532 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.533 -    /// The pointer type of the iterator.
  35.534 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.535 -
  35.536 -    /// The map initialized const key set.
  35.537 -    MapConstKeySet(const Map& pmap) : map(&pmap) {}
  35.538 -
  35.539 -    /// The const iterator of the set.
  35.540 -    typedef MapKeyIterator<Map> ConstIterator;
  35.541 -
  35.542 -    /// It gives back the const iterator pointed to the first element.
  35.543 -    ConstIterator begin() const {
  35.544 -      return ConstIterator(KeyIt(*map->getGraph()));
  35.545 -    }
  35.546 -            
  35.547 -    /// It gives back the const iterator pointed to the first ivalid element.
  35.548 -    ConstIterator end() const {
  35.549 -      return ConstIterator(KeyIt(INVALID));
  35.550 -    }
  35.551 - 
  35.552 -  public:
  35.553 -    // STL  compatibility typedefs.
  35.554 -    typedef ValueType value_type;
  35.555 -    typedef ConstIterator const_iterator;
  35.556 -    typedef ConstReferenceType const_reference;
  35.557 -    typedef ConstPointerType const_pointer;
  35.558 -    typedef int difference_type;
  35.559 -  };
  35.560 -
  35.561 -  /** This class makes from a map an iteratable set
  35.562 -   *  which contains all the values of the map.
  35.563 -   *  The values cannot be modified.
  35.564 -   */
  35.565 -  template <typename Map>
  35.566 -  class MapConstValueSet {
  35.567 -
  35.568 -    const Map* map;
  35.569 -
  35.570 -  public:
  35.571 -
  35.572 -    /// The key type of the iterator.
  35.573 -    typedef typename Map::KeyType KeyType;
  35.574 -    /// The iterator to iterate on the keys.
  35.575 -    typedef typename Map::KeyIt KeyIt;
  35.576 -
  35.577 -
  35.578 -    /// The value type of the iterator.
  35.579 -    typedef typename Map::ValueType ValueType;
  35.580 -    /// The reference type of the iterator.
  35.581 -    typedef typename Map::ReferenceType ReferenceType;
  35.582 -    /// The pointer type of the iterator.
  35.583 -    typedef typename Map::PointerType PointerType;
  35.584 -
  35.585 -    /// The const value type of the iterator.
  35.586 -    typedef typename Map::ConstValueType ConstValueType;
  35.587 -    /// The const reference type of the iterator.
  35.588 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.589 -    /// The pointer type of the iterator.
  35.590 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.591 -
  35.592 -    /// The map initialized const value set.
  35.593 -    MapConstValueSet(const Map& pmap) : map(&pmap) {}
  35.594 -
  35.595 -    /// The const iterator of the set.
  35.596 -    typedef MapConstValueIterator<Map> ConstIterator;
  35.597 -
  35.598 -    /// It gives back the const iterator pointed to the first element.
  35.599 -    ConstIterator begin() const {
  35.600 -      return ConstIterator(*map, KeyIt(*map->getGraph()));
  35.601 -    }
  35.602 -
  35.603 -    /// It gives back the const iterator pointed to the first invalid element.
  35.604 -    ConstIterator end() const {
  35.605 -      return ConstIterator(*map, KeyIt(INVALID));
  35.606 -    }
  35.607 -
  35.608 -  public:
  35.609 -    // STL  compatibility typedefs.
  35.610 -    typedef ValueType value_type;
  35.611 -    typedef ConstIterator const_iterator;
  35.612 -    typedef ConstReferenceType const_reference;
  35.613 -    typedef ConstPointerType const_pointer;
  35.614 -    typedef int difference_type;
  35.615 -  };
  35.616 -
  35.617 -
  35.618 -  /** This class makes from a map an iteratable set
  35.619 -   *  which contains all the values of the map.
  35.620 -   *  The values can be modified.
  35.621 -   */
  35.622 -  template <typename Map>
  35.623 -  class MapValueSet {
  35.624 -
  35.625 -    Map* map;
  35.626 -
  35.627 -  public:
  35.628 -
  35.629 -    /// The key type of the iterator.
  35.630 -    typedef typename Map::KeyType KeyType;
  35.631 -    /// The iterator to iterate on the keys.
  35.632 -    typedef typename Map::KeyIt KeyIt;
  35.633 -
  35.634 -
  35.635 -    /// The value type of the iterator.
  35.636 -    typedef typename Map::ValueType ValueType;
  35.637 -    /// The reference type of the iterator.
  35.638 -    typedef typename Map::ReferenceType ReferenceType;
  35.639 -    /// The pointer type of the iterator.
  35.640 -    typedef typename Map::PointerType PointerType;
  35.641 -
  35.642 -    /// The const value type of the iterator.
  35.643 -    typedef typename Map::ConstValueType ConstValueType;
  35.644 -    /// The const reference type of the iterator.
  35.645 -    typedef typename Map::ConstReferenceType ConstReferenceType;
  35.646 -    /// The pointer type of the iterator.
  35.647 -    typedef typename Map::ConstPointerType ConstPointerType;
  35.648 -
  35.649 -    /// The map initialized value set.
  35.650 -    MapValueSet(Map& pmap) : map(&pmap) {}
  35.651 -
  35.652 -    /// The const iterator of the set.
  35.653 -    typedef MapConstValueIterator<Map> ConstIterator;
  35.654 -
  35.655 -    /// It gives back the const iterator pointed to the first element.
  35.656 -    ConstIterator begin() const {
  35.657 -      return ConstIterator(*map, KeyIt(*map->getGraph()));
  35.658 -    }
  35.659 -
  35.660 -    /// It gives back the const iterator pointed to the first invalid element.
  35.661 -    ConstIterator end() const {
  35.662 -      return ConstIterator(*map, KeyIt(INVALID));
  35.663 -    }
  35.664 -
  35.665 -    /// The iterator of the set.
  35.666 -    typedef MapValueIterator<Map> Iterator;
  35.667 -
  35.668 -    /// It gives back the iterator pointed to the first element.
  35.669 -    Iterator begin() {
  35.670 -      return Iterator(*map, KeyIt(*map->getGraph()));
  35.671 -    }
  35.672 -
  35.673 -    /// It gives back the iterator pointed to the first invalid element.
  35.674 -    Iterator end() {
  35.675 -      return Iterator(*map, KeyIt(INVALID));
  35.676 -    }
  35.677 -            
  35.678 -  public:
  35.679 -    // STL  compatibility typedefs.
  35.680 -    typedef ValueType value_type;
  35.681 -    typedef Iterator iterator;
  35.682 -    typedef ConstIterator const_iterator;
  35.683 -    typedef ReferenceType reference;
  35.684 -    typedef ConstReferenceType const_reference;
  35.685 -    typedef PointerType pointer;
  35.686 -    typedef ConstPointerType const_pointer;
  35.687 -    typedef int difference_type;
  35.688 -
  35.689 -  };
  35.690 -
  35.691 -  /// @}
  35.692 -
  35.693 -}
  35.694 -
  35.695 -#endif
    36.1 --- a/src/hugo/map_registry.h	Wed Sep 29 14:12:26 2004 +0000
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,289 +0,0 @@
    36.4 -/* -*- C++ -*-
    36.5 - * src/hugo/map_registry.h - Part of HUGOlib, a generic C++ optimization library
    36.6 - *
    36.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    36.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    36.9 - *
   36.10 - * Permission to use, modify and distribute this software is granted
   36.11 - * provided that this copyright notice appears in all copies. For
   36.12 - * precise terms see the accompanying LICENSE file.
   36.13 - *
   36.14 - * This software is provided "AS IS" with no warranty of any kind,
   36.15 - * express or implied, and with no claim as to its suitability for any
   36.16 - * purpose.
   36.17 - *
   36.18 - */
   36.19 -
   36.20 -#ifndef HUGO_MAP_REGISTRY_H
   36.21 -#define HUGO_MAP_REGISTRY_H
   36.22 -
   36.23 -#include <vector>
   36.24 -
   36.25 -///\ingroup graphmapfactory
   36.26 -///\file
   36.27 -///\brief Map registry for graph maps.
   36.28 -
   36.29 -using namespace std;
   36.30 -
   36.31 -namespace hugo {
   36.32 -
   36.33 -/// \addtogroup graphmapfactory
   36.34 -/// @{
   36.35 -
   36.36 -/** 
   36.37 - * Registry class to register edge or node maps into the graph. The
   36.38 - * registry helps you to implement an observer pattern. If you add
   36.39 - * or erase an edge or node you must notify all the maps about the
   36.40 - * event.
   36.41 -*/
   36.42 -  template <typename G, typename K, typename KIt>
   36.43 -  class MapRegistry {
   36.44 -  public:
   36.45 -    typedef G Graph;
   36.46 -    typedef K KeyType;
   36.47 -    typedef KIt KeyIt;
   36.48 -	
   36.49 -    /**
   36.50 -     * MapBase is the base class of the registered maps.
   36.51 -     * It defines the core modification operations on the maps and
   36.52 -     * implements some helper functions. 
   36.53 -     */
   36.54 -    class MapBase {
   36.55 -    public:
   36.56 -      typedef G Graph;
   36.57 -      typedef K KeyType;
   36.58 -      typedef KIt KeyIt;
   36.59 -
   36.60 -      typedef MapRegistry<G, K, KIt> Registry;
   36.61 -	
   36.62 -      friend class MapRegistry<G, K, KIt>;
   36.63 -
   36.64 -      /**
   36.65 -       * Default constructor for MapBase.
   36.66 -       */
   36.67 -
   36.68 -      MapBase() : graph(0), registry(0) {}
   36.69 -		
   36.70 -      /** 
   36.71 -       * Simple constructor to register into a graph registry.
   36.72 -      */
   36.73 -	
   36.74 -      MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
   36.75 -	r.attach(*this);
   36.76 -      }
   36.77 -
   36.78 -      /** 
   36.79 -       * Copy constructor to register into the registry.
   36.80 -      */	
   36.81 -	
   36.82 -      MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
   36.83 -	if (copy.registry) {
   36.84 -	  copy.registry->attach(*this);
   36.85 -	}
   36.86 -      } 
   36.87 -	
   36.88 -      /** 
   36.89 -       * Assign operator.
   36.90 -      */	
   36.91 -      const MapBase& operator=(const MapBase& copy) {
   36.92 -	if (registry) {
   36.93 -	  registry->detach(*this);
   36.94 -	}
   36.95 -	graph = copy.graph;
   36.96 -	if (copy.registry) {
   36.97 -	  copy.registry->attach(*this);
   36.98 -	}
   36.99 -	return *this;
  36.100 -      }
  36.101 -	
  36.102 -
  36.103 -      /** 
  36.104 -       * Destructor. 
  36.105 -      */		
  36.106 -
  36.107 -      virtual ~MapBase() {
  36.108 -	if (registry) {
  36.109 -	  registry->detach(*this);
  36.110 -	}
  36.111 -      }
  36.112 -
  36.113 -      /*
  36.114 -       * Returns the graph that the map belongs to.
  36.115 -      */
  36.116 -
  36.117 -      const Graph* getGraph() const { return graph; }
  36.118 -	
  36.119 -    protected:
  36.120 -		
  36.121 -      const Graph* graph;     
  36.122 -      Registry* registry;
  36.123 -
  36.124 -      int registry_index;
  36.125 -
  36.126 -    protected:
  36.127 -	
  36.128 -      /**
  36.129 -	 Helper function to implement constructors in the subclasses.
  36.130 -      */
  36.131 -	
  36.132 -      virtual void init() {
  36.133 -	for (KeyIt it(*graph); it != INVALID; ++it) {
  36.134 -	  add(it);
  36.135 -	}
  36.136 -      }
  36.137 -	
  36.138 -      /**
  36.139 -	 Helper function to implement the destructor in the subclasses.
  36.140 -      */
  36.141 -	
  36.142 -      virtual void destroy() {
  36.143 -	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
  36.144 -	  erase(it);
  36.145 -	}
  36.146 -      }
  36.147 -	
  36.148 -      /** 
  36.149 -	  The add member function should be overloaded in the subclasses.
  36.150 -	  \e Add extends the map with the new node.
  36.151 -      */
  36.152 -	
  36.153 -      virtual void add(const KeyType&) = 0;	
  36.154 -      /** 
  36.155 -	  The erase member function should be overloaded in the subclasses.
  36.156 -	  \e Erase removes the node from the map.
  36.157 -      */
  36.158 -	
  36.159 -      virtual void erase(const KeyType&) = 0;
  36.160 -
  36.161 -      /**
  36.162 -       *  The clear member function should be overloaded in the subclasses.
  36.163 -       *  \e Clear makes empty the data structure.
  36.164 -       */
  36.165 -
  36.166 -      virtual void clear() = 0;
  36.167 -	
  36.168 -      /**
  36.169 -	 Exception class to throw at unsupported operation.
  36.170 -      */
  36.171 -	
  36.172 -      class NotSupportedOperationException {};
  36.173 -
  36.174 -    };
  36.175 -	
  36.176 -  protected:
  36.177 -	
  36.178 -    /** 
  36.179 -     * The container type of the maps.
  36.180 -     */
  36.181 -    typedef std::vector<MapBase*> Container; 
  36.182 -
  36.183 -    /**
  36.184 -     * The container of the registered maps.
  36.185 -     */
  36.186 -    Container container;
  36.187 -
  36.188 -		
  36.189 -  public:
  36.190 -	
  36.191 -    /**
  36.192 -     * Default Constructor of the MapRegistry. It creates an empty registry.
  36.193 -     */
  36.194 -    MapRegistry() {}
  36.195 -	
  36.196 -    /**
  36.197 -     * Copy Constructor of the MapRegistry. The new registry does not steal
  36.198 -     * the maps from the right value. The new registry will be an empty.
  36.199 -     */
  36.200 -    MapRegistry(const MapRegistry&) {}
  36.201 -		
  36.202 -    /**
  36.203 -     * Assign operator. The left value does not steal the maps 
  36.204 -     * from the right value. The left value will be an empty registry.
  36.205 -     */
  36.206 -    MapRegistry& operator=(const MapRegistry&) {
  36.207 -      typename Container::iterator it;
  36.208 -      for (it = container.begin(); it != container.end(); ++it) {
  36.209 -	(*it)->destroy();
  36.210 -	(*it)->graph = 0;
  36.211 -	(*it)->registry = 0;
  36.212 -      }
  36.213 -    }
  36.214 -				
  36.215 -    /**
  36.216 -     * Destructor of the MapRegistry.
  36.217 -     */
  36.218 -    ~MapRegistry() {
  36.219 -      typename Container::iterator it;
  36.220 -      for (it = container.begin(); it != container.end(); ++it) {
  36.221 -	(*it)->destroy();
  36.222 -	(*it)->registry = 0;
  36.223 -	(*it)->graph = 0;
  36.224 -      }
  36.225 -    }
  36.226 -	
  36.227 -	
  36.228 -    public:
  36.229 -	
  36.230 -    /**
  36.231 -     * Attach a map into thr registry. If the map has been attached
  36.232 -     * into an other registry it is detached from that automaticly.
  36.233 -     */
  36.234 -    void attach(MapBase& map) {
  36.235 -      if (map.registry) {
  36.236 -	map.registry->detach(map);
  36.237 -      }
  36.238 -      container.push_back(&map);
  36.239 -      map.registry = this;
  36.240 -      map.registry_index = container.size()-1;
  36.241 -    } 
  36.242 -	
  36.243 -    /**
  36.244 -     * Detach the map from the registry.
  36.245 -     */
  36.246 -    void detach(MapBase& map) {
  36.247 -      container.back()->registry_index = map.registry_index; 
  36.248 -      container[map.registry_index] = container.back();
  36.249 -      container.pop_back();
  36.250 -      map.registry = 0;
  36.251 -      map.graph = 0;
  36.252 -    }
  36.253 -	
  36.254 -		
  36.255 -    /**
  36.256 -     * Notify all the registered maps about a Key added.
  36.257 -     */
  36.258 -    void add(KeyType& key) {
  36.259 -      typename Container::iterator it;
  36.260 -      for (it = container.begin(); it != container.end(); ++it) {
  36.261 -	(*it)->add(key);
  36.262 -      }
  36.263 -    }	
  36.264 -		
  36.265 -    /**
  36.266 -     * Notify all the registered maps about a Key erased.
  36.267 -     */ 
  36.268 -    void erase(KeyType& key) {
  36.269 -      typename Container::iterator it;
  36.270 -      for (it = container.begin(); it != container.end(); ++it) {
  36.271 -	(*it)->erase(key);
  36.272 -      }
  36.273 -    }
  36.274 -
  36.275 -    /**
  36.276 -     * Notify all the registered maps about the map should be cleared.
  36.277 -     */ 
  36.278 -    void clear() {
  36.279 -      typename Container::iterator it;
  36.280 -      for (it = container.begin(); it != container.end(); ++it) {
  36.281 -	(*it)->clear();
  36.282 -      }
  36.283 -    }
  36.284 -  };
  36.285 -
  36.286 -  
  36.287 -/// @}
  36.288 -  
  36.289 -
  36.290 -}
  36.291 -
  36.292 -#endif
    37.1 --- a/src/hugo/maps.h	Wed Sep 29 14:12:26 2004 +0000
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,176 +0,0 @@
    37.4 -/* -*- C++ -*-
    37.5 - * src/hugo/maps.h - Part of HUGOlib, a generic C++ optimization library
    37.6 - *
    37.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    37.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    37.9 - *
   37.10 - * Permission to use, modify and distribute this software is granted
   37.11 - * provided that this copyright notice appears in all copies. For
   37.12 - * precise terms see the accompanying LICENSE file.
   37.13 - *
   37.14 - * This software is provided "AS IS" with no warranty of any kind,
   37.15 - * express or implied, and with no claim as to its suitability for any
   37.16 - * purpose.
   37.17 - *
   37.18 - */
   37.19 -
   37.20 -#ifndef HUGO_MAPS_H
   37.21 -#define HUGO_MAPS_H
   37.22 -
   37.23 -///\file
   37.24 -///\brief Miscellaneous property maps
   37.25 -///
   37.26 -///\todo This file has the same name as the concept file in skeletons,
   37.27 -/// and this is not easily detectable in docs...
   37.28 -
   37.29 -#include <map>
   37.30 -
   37.31 -namespace hugo {
   37.32 -
   37.33 -  /// Base class of maps.
   37.34 -
   37.35 -  /// Base class of maps.
   37.36 -  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
   37.37 -  template<typename K, typename T>
   37.38 -  class MapBase
   37.39 -  {
   37.40 -  public:
   37.41 -    ///\e
   37.42 -    typedef K KeyType;
   37.43 -    ///\e
   37.44 -    typedef T ValueType;
   37.45 -  };
   37.46 -
   37.47 -  /// Null map. (a.k.a. DoNothingMap)
   37.48 -
   37.49 -  /// If you have to provide a map only for its type definitions,
   37.50 -  /// or if you have to provide a writable map, but
   37.51 -  /// data written to it will sent to <tt>/dev/null</tt>...
   37.52 -  template<typename K, typename T>
   37.53 -  class NullMap : public MapBase<K,T>
   37.54 -  {
   37.55 -  public:
   37.56 -
   37.57 -    /// Gives back a default constructed element.
   37.58 -    T operator[](const K&) const { return T(); }
   37.59 -    /// Absorbs the value.
   37.60 -    void set(const K&, const T&) {}
   37.61 -  };
   37.62 -
   37.63 -
   37.64 -  /// Constant map.
   37.65 -
   37.66 -  /// This is a readable map which assigns a specified value to each key.
   37.67 -  /// In other aspects it is equivalent to the \ref NullMap.
   37.68 -  /// \todo set could be used to set the value.
   37.69 -  template<typename K, typename T>
   37.70 -  class ConstMap : public MapBase<K,T>
   37.71 -  {
   37.72 -    T v;
   37.73 -  public:
   37.74 -
   37.75 -    /// Default constructor
   37.76 -
   37.77 -    /// The value of the map will be uninitialized. 
   37.78 -    /// (More exactly it will be default constructed.)
   37.79 -    ConstMap() {}
   37.80 -    ///\e
   37.81 -
   37.82 -    /// \param _v The initial value of the map.
   37.83 -    ///
   37.84 -    ConstMap(const T &_v) : v(_v) {}
   37.85 -
   37.86 -    T operator[](const K&) const { return v; }
   37.87 -    void set(const K&, const T&) {}
   37.88 -
   37.89 -    template<typename T1>
   37.90 -    struct rebind {
   37.91 -      typedef ConstMap<K,T1> other;
   37.92 -    };
   37.93 -
   37.94 -    template<typename T1>
   37.95 -    ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
   37.96 -  };
   37.97 -
   37.98 -  //to document later
   37.99 -  template<typename T, T v>
  37.100 -  struct Const { };
  37.101 -  //to document later
  37.102 -  template<typename K, typename V, V v>
  37.103 -  class ConstMap<K, Const<V, v> > : public MapBase<K, V>
  37.104 -  {
  37.105 -  public:
  37.106 -    ConstMap() { }
  37.107 -    V operator[](const K&) const { return v; }
  37.108 -    void set(const K&, const V&) { }
  37.109 -  };
  37.110 -  //to document later
  37.111 -  typedef Const<bool, true> True;
  37.112 -  typedef Const<bool, false> False;
  37.113 -
  37.114 -  /// \c std::map wrapper
  37.115 -
  37.116 -  /// This is essentially a wrapper for \c std::map. With addition that
  37.117 -  /// you can specify a default value different from \c ValueType() .
  37.118 -  ///
  37.119 -  /// \todo Provide allocator parameter...
  37.120 -  template <typename Key, typename T, typename Compare = std::less<Key> >
  37.121 -  class StdMap : public std::map<Key,T,Compare> {
  37.122 -    typedef std::map<Key,T,Compare> parent;
  37.123 -    T v;
  37.124 -    typedef typename parent::value_type PairType;
  37.125 -
  37.126 -  public:
  37.127 -    typedef Key KeyType;
  37.128 -    typedef T ValueType;
  37.129 -    typedef T& ReferenceType;
  37.130 -    typedef const T& ConstReferenceType;
  37.131 -
  37.132 -
  37.133 -    StdMap() : v() {}
  37.134 -    /// Constructor with specified default value
  37.135 -    StdMap(const T& _v) : v(_v) {}
  37.136 -
  37.137 -    /// \brief Constructs the map from an appropriate std::map.
  37.138 -    ///
  37.139 -    /// \warning Inefficient: copies the content of \c m !
  37.140 -    StdMap(const parent &m) : parent(m) {}
  37.141 -    /// \brief Constructs the map from an appropriate std::map, and explicitly
  37.142 -    /// specifies a default value.
  37.143 -    ///
  37.144 -    /// \warning Inefficient: copies the content of \c m !
  37.145 -    StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
  37.146 -    
  37.147 -    template<typename T1, typename Comp1>
  37.148 -    StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
  37.149 -      //FIXME; 
  37.150 -    }
  37.151 -
  37.152 -    ReferenceType operator[](const Key &k) {
  37.153 -      return insert(PairType(k,v)).first -> second;
  37.154 -    }
  37.155 -    ConstReferenceType operator[](const Key &k) const {
  37.156 -      typename parent::iterator i = lower_bound(k);
  37.157 -      if (i == parent::end() || parent::key_comp()(k, (*i).first))
  37.158 -	return v;
  37.159 -      return (*i).second;
  37.160 -    }
  37.161 -    void set(const Key &k, const T &t) {
  37.162 -      parent::operator[](k) = t;
  37.163 -    }
  37.164 -
  37.165 -    /// Changes the default value of the map.
  37.166 -    /// \return Returns the previous default value.
  37.167 -    ///
  37.168 -    /// \warning The value of some keys (which has already been queried, but
  37.169 -    /// the value has been unchanged from the default) may change!
  37.170 -    T setDefault(const T &_v) { T old=v; v=_v; return old; }
  37.171 -
  37.172 -    template<typename T1>
  37.173 -    struct rebind {
  37.174 -      typedef StdMap<Key,T1,Compare> other;
  37.175 -    };
  37.176 -  };
  37.177 -  
  37.178 -}
  37.179 -#endif // HUGO_MAPS_H
    38.1 --- a/src/hugo/min_cost_flow.h	Wed Sep 29 14:12:26 2004 +0000
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,256 +0,0 @@
    38.4 -/* -*- C++ -*-
    38.5 - * src/hugo/min_cost_flow.h - Part of HUGOlib, a generic C++ optimization library
    38.6 - *
    38.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    38.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    38.9 - *
   38.10 - * Permission to use, modify and distribute this software is granted
   38.11 - * provided that this copyright notice appears in all copies. For
   38.12 - * precise terms see the accompanying LICENSE file.
   38.13 - *
   38.14 - * This software is provided "AS IS" with no warranty of any kind,
   38.15 - * express or implied, and with no claim as to its suitability for any
   38.16 - * purpose.
   38.17 - *
   38.18 - */
   38.19 -
   38.20 -#ifndef HUGO_MIN_COST_FLOW_H
   38.21 -#define HUGO_MIN_COST_FLOW_H
   38.22 -
   38.23 -///\ingroup flowalgs
   38.24 -///\file
   38.25 -///\brief An algorithm for finding a flow of value \c k (for small values of \c k) having minimal total cost 
   38.26 -
   38.27 -
   38.28 -#include <hugo/dijkstra.h>
   38.29 -#include <hugo/graph_wrapper.h>
   38.30 -#include <hugo/maps.h>
   38.31 -#include <vector>
   38.32 -
   38.33 -namespace hugo {
   38.34 -
   38.35 -/// \addtogroup flowalgs
   38.36 -/// @{
   38.37 -
   38.38 -  ///\brief Implementation of an algorithm for finding a flow of value \c k 
   38.39 -  ///(for small values of \c k) having minimal total cost between 2 nodes 
   38.40 -  /// 
   38.41 -  ///
   38.42 -  /// The class \ref hugo::MinCostFlow "MinCostFlow" implements
   38.43 -  /// an algorithm for finding a flow of value \c k 
   38.44 -  /// having minimal total cost 
   38.45 -  /// from a given source node to a given target node in an
   38.46 -  /// edge-weighted directed graph. To this end, 
   38.47 -  /// the edge-capacities and edge-weitghs have to be nonnegative. 
   38.48 -  /// The edge-capacities should be integers, but the edge-weights can be 
   38.49 -  /// integers, reals or of other comparable numeric type.
   38.50 -  /// This algorithm is intended to use only for small values of \c k, 
   38.51 -  /// since it is only polynomial in k, 
   38.52 -  /// not in the length of k (which is log k). 
   38.53 -  /// In order to find the minimum cost flow of value \c k it 
   38.54 -  /// finds the minimum cost flow of value \c i for every 
   38.55 -  /// \c i between 0 and \c k. 
   38.56 -  ///
   38.57 -  ///\param Graph The directed graph type the algorithm runs on.
   38.58 -  ///\param LengthMap The type of the length map.
   38.59 -  ///\param CapacityMap The capacity map type.
   38.60 -  ///
   38.61 -  ///\author Attila Bernath
   38.62 -  template <typename Graph, typename LengthMap, typename CapacityMap>
   38.63 -  class MinCostFlow {
   38.64 -
   38.65 -    typedef typename LengthMap::ValueType Length;
   38.66 -
   38.67 -    //Warning: this should be integer type
   38.68 -    typedef typename CapacityMap::ValueType Capacity;
   38.69 -    
   38.70 -    typedef typename Graph::Node Node;
   38.71 -    typedef typename Graph::NodeIt NodeIt;
   38.72 -    typedef typename Graph::Edge Edge;
   38.73 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   38.74 -    typedef typename Graph::template EdgeMap<int> EdgeIntMap;
   38.75 -
   38.76 -
   38.77 -    typedef ResGraphWrapper<const Graph,int,CapacityMap,EdgeIntMap> ResGW;
   38.78 -    typedef typename ResGW::Edge ResGraphEdge;
   38.79 -
   38.80 -    class ModLengthMap {   
   38.81 -      typedef typename Graph::template NodeMap<Length> NodeMap;
   38.82 -      const ResGW& G;
   38.83 -      const LengthMap &ol;
   38.84 -      const NodeMap &pot;
   38.85 -    public :
   38.86 -      typedef typename LengthMap::KeyType KeyType;
   38.87 -      typedef typename LengthMap::ValueType ValueType;
   38.88 -	
   38.89 -      ValueType operator[](typename ResGW::Edge e) const {     
   38.90 -	if (G.forward(e))
   38.91 -	  return  ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
   38.92 -	else
   38.93 -	  return -ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
   38.94 -      }     
   38.95 -	
   38.96 -      ModLengthMap(const ResGW& _G,
   38.97 -		   const LengthMap &o,  const NodeMap &p) : 
   38.98 -	G(_G), /*rev(_rev),*/ ol(o), pot(p){}; 
   38.99 -    };//ModLengthMap
  38.100 -
  38.101 -
  38.102 -  protected:
  38.103 -    
  38.104 -    //Input
  38.105 -    const Graph& G;
  38.106 -    const LengthMap& length;
  38.107 -    const CapacityMap& capacity;
  38.108 -
  38.109 -
  38.110 -    //auxiliary variables
  38.111 -
  38.112 -    //To store the flow
  38.113 -    EdgeIntMap flow; 
  38.114 -    //To store the potential (dual variables)
  38.115 -    typedef typename Graph::template NodeMap<Length> PotentialMap;
  38.116 -    PotentialMap potential;
  38.117 -    
  38.118 -
  38.119 -    Length total_length;
  38.120 -
  38.121 -
  38.122 -  public :
  38.123 -
  38.124 -    /// The constructor of the class.
  38.125 -    
  38.126 -    ///\param _G The directed graph the algorithm runs on. 
  38.127 -    ///\param _length The length (weight or cost) of the edges. 
  38.128 -    ///\param _cap The capacity of the edges. 
  38.129 -    MinCostFlow(Graph& _G, LengthMap& _length, CapacityMap& _cap) : G(_G), 
  38.130 -      length(_length), capacity(_cap), flow(_G), potential(_G){ }
  38.131 -
  38.132 -    
  38.133 -    ///Runs the algorithm.
  38.134 -    
  38.135 -    ///Runs the algorithm.
  38.136 -    ///Returns k if there is a flow of value at least k edge-disjoint 
  38.137 -    ///from s to t.
  38.138 -    ///Otherwise it returns the maximum value of a flow from s to t.
  38.139 -    ///
  38.140 -    ///\param s The source node.
  38.141 -    ///\param t The target node.
  38.142 -    ///\param k The value of the flow we are looking for.
  38.143 -    ///
  38.144 -    ///\todo May be it does make sense to be able to start with a nonzero 
  38.145 -    /// feasible primal-dual solution pair as well.
  38.146 -    int run(Node s, Node t, int k) {
  38.147 -
  38.148 -      //Resetting variables from previous runs
  38.149 -      total_length = 0;
  38.150 -      
  38.151 -      for (typename Graph::EdgeIt e(G); e!=INVALID; ++e) flow.set(e, 0);
  38.152 -
  38.153 -      //Initialize the potential to zero
  38.154 -      for (typename Graph::NodeIt n(G); n!=INVALID; ++n) potential.set(n, 0);
  38.155 -      
  38.156 -      
  38.157 -      //We need a residual graph
  38.158 -      ResGW res_graph(G, capacity, flow);
  38.159 -
  38.160 -
  38.161 -      ModLengthMap mod_length(res_graph, length, potential);
  38.162 -
  38.163 -      Dijkstra<ResGW, ModLengthMap> dijkstra(res_graph, mod_length);
  38.164 -
  38.165 -      int i;
  38.166 -      for (i=0; i<k; ++i){
  38.167 -	dijkstra.run(s);
  38.168 -	if (!dijkstra.reached(t)){
  38.169 -	  //There are no flow of value k from s to t
  38.170 -	  break;
  38.171 -	};
  38.172 -	
  38.173 -	//We have to change the potential
  38.174 -        for(typename ResGW::NodeIt n(res_graph); n!=INVALID; ++n)
  38.175 -	  potential[n] += dijkstra.distMap()[n];
  38.176 -
  38.177 -
  38.178 -	//Augmenting on the sortest path
  38.179 -	Node n=t;
  38.180 -	ResGraphEdge e;
  38.181 -	while (n!=s){
  38.182 -	  e = dijkstra.pred(n);
  38.183 -	  n = dijkstra.predNode(n);
  38.184 -	  res_graph.augment(e,1);
  38.185 -	  //Let's update the total length
  38.186 -	  if (res_graph.forward(e))
  38.187 -	    total_length += length[e];
  38.188 -	  else 
  38.189 -	    total_length -= length[e];	    
  38.190 -	}
  38.191 -
  38.192 -	  
  38.193 -      }
  38.194 -      
  38.195 -
  38.196 -      return i;
  38.197 -    }
  38.198 -
  38.199 -
  38.200 -
  38.201 -    /// Gives back the total weight of the found flow.
  38.202 -
  38.203 -    ///This function gives back the total weight of the found flow.
  38.204 -    ///Assumes that \c run() has been run and nothing changed since then.
  38.205 -    Length totalLength(){
  38.206 -      return total_length;
  38.207 -    }
  38.208 -
  38.209 -    ///Returns a const reference to the EdgeMap \c flow. 
  38.210 -
  38.211 -    ///Returns a const reference to the EdgeMap \c flow. 
  38.212 -    ///\pre \ref run() must
  38.213 -    ///be called before using this function.
  38.214 -    const EdgeIntMap &getFlow() const { return flow;}
  38.215 -
  38.216 -    ///Returns a const reference to the NodeMap \c potential (the dual solution).
  38.217 -
  38.218 -    ///Returns a const reference to the NodeMap \c potential (the dual solution).
  38.219 -    /// \pre \ref run() must be called before using this function.
  38.220 -    const PotentialMap &getPotential() const { return potential;}
  38.221 -
  38.222 -    /// Checking the complementary slackness optimality criteria
  38.223 -
  38.224 -    ///This function checks, whether the given solution is optimal
  38.225 -    ///If executed after the call of \c run() then it should return with true.
  38.226 -    ///This function only checks optimality, doesn't bother with feasibility.
  38.227 -    ///It is meant for testing purposes.
  38.228 -    ///
  38.229 -    bool checkComplementarySlackness(){
  38.230 -      Length mod_pot;
  38.231 -      Length fl_e;
  38.232 -        for(typename Graph::EdgeIt e(G); e!=INVALID; ++e) {
  38.233 -	//C^{\Pi}_{i,j}
  38.234 -	mod_pot = length[e]-potential[G.head(e)]+potential[G.tail(e)];
  38.235 -	fl_e = flow[e];
  38.236 -	if (0<fl_e && fl_e<capacity[e]) {
  38.237 -	  /// \todo better comparison is needed for real types, moreover, 
  38.238 -	  /// this comparison here is superfluous.
  38.239 -	  if (mod_pot != 0)
  38.240 -	    return false;
  38.241 -	} 
  38.242 -	else {
  38.243 -	  if (mod_pot > 0 && fl_e != 0)
  38.244 -	    return false;
  38.245 -	  if (mod_pot < 0 && fl_e != capacity[e])
  38.246 -	    return false;
  38.247 -	}
  38.248 -      }
  38.249 -      return true;
  38.250 -    }
  38.251 -    
  38.252 -
  38.253 -  }; //class MinCostFlow
  38.254 -
  38.255 -  ///@}
  38.256 -
  38.257 -} //namespace hugo
  38.258 -
  38.259 -#endif //HUGO_MIN_COST_FLOW_H
    39.1 --- a/src/hugo/path.h	Wed Sep 29 14:12:26 2004 +0000
    39.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.3 @@ -1,709 +0,0 @@
    39.4 -/* -*- C++ -*-
    39.5 - * src/hugo/path.h - Part of HUGOlib, a generic C++ optimization library
    39.6 - *
    39.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    39.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    39.9 - *
   39.10 - * Permission to use, modify and distribute this software is granted
   39.11 - * provided that this copyright notice appears in all copies. For
   39.12 - * precise terms see the accompanying LICENSE file.
   39.13 - *
   39.14 - * This software is provided "AS IS" with no warranty of any kind,
   39.15 - * express or implied, and with no claim as to its suitability for any
   39.16 - * purpose.
   39.17 - *
   39.18 - */
   39.19 -
   39.20 -/**
   39.21 -@defgroup paths Path Structures
   39.22 -@ingroup datas
   39.23 -\brief Path structures implemented in Hugo.
   39.24 -
   39.25 -Hugolib provides flexible data structures
   39.26 -to work with paths.
   39.27 -
   39.28 -All of them have the same interface, especially they can be built or extended
   39.29 -using a standard Builder subclass. This make is easy to have e.g. the Dijkstra
   39.30 -algorithm to store its result in any kind of path structure.
   39.31 -
   39.32 -\sa hugo::skeleton::Path
   39.33 -
   39.34 -*/
   39.35 -
   39.36 -///\ingroup paths
   39.37 -///\file
   39.38 -///\brief Classes for representing paths in graphs.
   39.39 -
   39.40 -#ifndef HUGO_PATH_H
   39.41 -#define HUGO_PATH_H
   39.42 -
   39.43 -#include <deque>
   39.44 -#include <vector>
   39.45 -#include <algorithm>
   39.46 -
   39.47 -#include <hugo/invalid.h>
   39.48 -
   39.49 -namespace hugo {
   39.50 -
   39.51 -  /// \addtogroup paths
   39.52 -  /// @{
   39.53 -
   39.54 -
   39.55 -  //! \brief A structure for representing directed paths in a graph.
   39.56 -  //!
   39.57 -  //! A structure for representing directed path in a graph.
   39.58 -  //! \param Graph The graph type in which the path is.
   39.59 -  //! \param DM DebugMode, defaults to DefaultDebugMode.
   39.60 -  //!
   39.61 -  //! In a sense, the path can be treated as a graph, for is has \c NodeIt
   39.62 -  //! and \c EdgeIt with the same usage. These types converts to the \c Node
   39.63 -  //! and \c Edge of the original graph.
   39.64 -  //!
   39.65 -  //! \todo Thoroughfully check all the range and consistency tests.
   39.66 -  template<typename Graph>
   39.67 -  class DirPath {
   39.68 -  public:
   39.69 -    /// Edge type of the underlying graph.
   39.70 -    typedef typename Graph::Edge GraphEdge;
   39.71 -    /// Node type of the underlying graph.
   39.72 -    typedef typename Graph::Node GraphNode;
   39.73 -    class NodeIt;
   39.74 -    class EdgeIt;
   39.75 -
   39.76 -  protected:
   39.77 -    const Graph *gr;
   39.78 -    typedef std::vector<GraphEdge> Container;
   39.79 -    Container edges;
   39.80 -
   39.81 -  public:
   39.82 -
   39.83 -    /// \param _G The graph in which the path is.
   39.84 -    ///
   39.85 -    DirPath(const Graph &_G) : gr(&_G) {}
   39.86 -
   39.87 -    /// \brief Subpath constructor.
   39.88 -    ///
   39.89 -    /// Subpath defined by two nodes.
   39.90 -    /// \warning It is an error if the two edges are not in order!
   39.91 -    DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b) {
   39.92 -      gr = P.gr;
   39.93 -      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
   39.94 -    }
   39.95 -
   39.96 -    /// \brief Subpath constructor.
   39.97 -    ///
   39.98 -    /// Subpath defined by two edges. Contains edges in [a,b)
   39.99 -    /// \warning It is an error if the two edges are not in order!
  39.100 -    DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b) {
  39.101 -      gr = P.gr;
  39.102 -      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  39.103 -    }
  39.104 -
  39.105 -    /// Length of the path.
  39.106 -    size_t length() const { return edges.size(); }
  39.107 -    /// Returns whether the path is empty.
  39.108 -    bool empty() const { return edges.empty(); }
  39.109 -
  39.110 -    /// Resets the path to an empty path.
  39.111 -    void clear() { edges.clear(); }
  39.112 -
  39.113 -    /// \brief Starting point of the path.
  39.114 -    ///
  39.115 -    /// Starting point of the path.
  39.116 -    /// Returns INVALID if the path is empty.
  39.117 -    GraphNode tail() const {
  39.118 -      return empty() ? INVALID : gr->tail(edges[0]);
  39.119 -    }
  39.120 -    /// \brief End point of the path.
  39.121 -    ///
  39.122 -    /// End point of the path.
  39.123 -    /// Returns INVALID if the path is empty.
  39.124 -    GraphNode head() const {
  39.125 -      return empty() ? INVALID : gr->head(edges[length()-1]);
  39.126 -    }
  39.127 -
  39.128 -    /// \brief Initializes node or edge iterator to point to the first
  39.129 -    /// node or edge.
  39.130 -    ///
  39.131 -    /// \sa nth
  39.132 -    template<typename It>
  39.133 -    It& first(It &i) const { return i=It(*this); }
  39.134 -
  39.135 -    /// \brief Initializes node iterator to point to the node of a given index.
  39.136 -    NodeIt& nth(NodeIt &i, int n) const {
  39.137 -      return i=NodeIt(*this, n);
  39.138 -    }
  39.139 -
  39.140 -    /// \brief Initializes edge iterator to point to the edge of a given index.
  39.141 -    EdgeIt& nth(EdgeIt &i, int n) const {
  39.142 -      return i=EdgeIt(*this, n);
  39.143 -    }
  39.144 -
  39.145 -    /// \brief Returns node iterator pointing to the head node of the
  39.146 -    /// given edge iterator.
  39.147 -    NodeIt head(const EdgeIt& e) const {
  39.148 -      return NodeIt(*this, e.idx+1);
  39.149 -    }
  39.150 -
  39.151 -    /// \brief Returns node iterator pointing to the tail node of the
  39.152 -    /// given edge iterator.
  39.153 -    NodeIt tail(const EdgeIt& e) const {
  39.154 -      return NodeIt(*this, e.idx);
  39.155 -    }
  39.156 -
  39.157 -
  39.158 -    /* Iterator classes */
  39.159 -
  39.160 -    /**
  39.161 -     * \brief Iterator class to iterate on the edges of the paths
  39.162 -     *
  39.163 -     * \ingroup paths
  39.164 -     * This class is used to iterate on the edges of the paths
  39.165 -     *
  39.166 -     * Of course it converts to Graph::Edge
  39.167 -     *
  39.168 -     */
  39.169 -    class EdgeIt {
  39.170 -      friend class DirPath;
  39.171 -
  39.172 -      int idx;
  39.173 -      const DirPath *p;
  39.174 -    public:
  39.175 -      /// Default constructor
  39.176 -      EdgeIt() {}
  39.177 -      /// Invalid constructor
  39.178 -      EdgeIt(Invalid) : idx(-1), p(0) {}
  39.179 -      /// Constructor with starting point
  39.180 -      EdgeIt(const DirPath &_p, int _idx = 0) :
  39.181 -	idx(_idx), p(&_p) { validate(); }
  39.182 -
  39.183 -      ///Validity check
  39.184 -      bool valid() const { return idx!=-1; }
  39.185 -
  39.186 -      ///Conversion to Graph::Edge
  39.187 -      operator GraphEdge () const {
  39.188 -	return valid() ? p->edges[idx] : INVALID;
  39.189 -      }
  39.190 -
  39.191 -      /// Next edge
  39.192 -      EdgeIt& operator++() { ++idx; validate(); return *this; }
  39.193 -
  39.194 -      /// Comparison operator
  39.195 -      bool operator==(const EdgeIt& e) const { return idx==e.idx; }
  39.196 -      /// Comparison operator
  39.197 -      bool operator!=(const EdgeIt& e) const { return idx!=e.idx; }
  39.198 -      /// Comparison operator
  39.199 -      bool operator<(const EdgeIt& e) const { return idx<e.idx; }
  39.200 -
  39.201 -    private:
  39.202 -      // FIXME: comparison between signed and unsigned...
  39.203 -      // Jo ez igy? Vagy esetleg legyen a length() int?
  39.204 -      void validate() { if( size_t(idx) >= p->length() ) idx=-1; }
  39.205 -    };
  39.206 -
  39.207 -    /**
  39.208 -     * \brief Iterator class to iterate on the nodes of the paths
  39.209 -     *
  39.210 -     * \ingroup paths
  39.211 -     * This class is used to iterate on the nodes of the paths
  39.212 -     *
  39.213 -     * Of course it converts to Graph::Node
  39.214 -     *
  39.215 -     */
  39.216 -    class NodeIt {
  39.217 -      friend class DirPath;
  39.218 -
  39.219 -      int idx;
  39.220 -      const DirPath *p;
  39.221 -    public:
  39.222 -      /// Default constructor
  39.223 -      NodeIt() {}
  39.224 -      /// Invalid constructor
  39.225 -      NodeIt(Invalid) : idx(-1), p(0) {}
  39.226 -      /// Constructor with starting point
  39.227 -      NodeIt(const DirPath &_p, int _idx = 0) :
  39.228 -	idx(_idx), p(&_p) { validate(); }
  39.229 -
  39.230 -      ///Validity check
  39.231 -      bool valid() const { return idx!=-1; }
  39.232 -
  39.233 -      ///Conversion to Graph::Node
  39.234 -      operator const GraphNode& () const {
  39.235 -	if(idx >= p->length())
  39.236 -	  return p->head();
  39.237 -	else if(idx >= 0)
  39.238 -	  return p->gr->tail(p->edges[idx]);
  39.239 -	else
  39.240 -	  return INVALID;
  39.241 -      }
  39.242 -      /// Next node
  39.243 -      NodeIt& operator++() { ++idx; validate(); return *this; }
  39.244 -
  39.245 -      /// Comparison operator
  39.246 -      bool operator==(const NodeIt& e) const { return idx==e.idx; }
  39.247 -      /// Comparison operator
  39.248 -      bool operator!=(const NodeIt& e) const { return idx!=e.idx; }
  39.249 -      /// Comparison operator
  39.250 -      bool operator<(const NodeIt& e) const { return idx<e.idx; }
  39.251 -
  39.252 -    private:
  39.253 -      void validate() { if( size_t(idx) > p->length() ) idx=-1; }
  39.254 -    };
  39.255 -
  39.256 -    friend class Builder;
  39.257 -
  39.258 -    /**
  39.259 -     * \brief Class to build paths
  39.260 -     *
  39.261 -     * \ingroup paths
  39.262 -     * This class is used to fill a path with edges.
  39.263 -     *
  39.264 -     * You can push new edges to the front and to the back of the path in
  39.265 -     * arbitrary order then you should commit these changes to the graph.
  39.266 -     *
  39.267 -     * Fundamentally, for most "Paths" (classes fulfilling the
  39.268 -     * PathConcept) while the builder is active (after the first modifying
  39.269 -     * operation and until the commit()) the original Path is in a
  39.270 -     * "transitional" state (operations on it have undefined result). But
  39.271 -     * in the case of DirPath the original path remains unchanged until the
  39.272 -     * commit. However we don't recomend that you use this feature.
  39.273 -     */
  39.274 -    class Builder {
  39.275 -      DirPath &P;
  39.276 -      Container front, back;
  39.277 -
  39.278 -    public:
  39.279 -      ///\param _P the path you want to fill in.
  39.280 -      ///
  39.281 -      Builder(DirPath &_P) : P(_P) {}
  39.282 -
  39.283 -      /// Sets the starting node of the path.
  39.284 -
  39.285 -      /// Sets the starting node of the path. Edge added to the path
  39.286 -      /// afterwards have to be incident to this node.
  39.287 -      /// It should be called if and only if
  39.288 -      /// the path is empty and before any call to
  39.289 -      /// \ref pushFront() or \ref pushBack()
  39.290 -      void setStartNode(const GraphNode &) {}
  39.291 -
  39.292 -      ///Push a new edge to the front of the path
  39.293 -
  39.294 -      ///Push a new edge to the front of the path.
  39.295 -      ///\sa setStartNode
  39.296 -      void pushFront(const GraphEdge& e) {
  39.297 -	front.push_back(e);
  39.298 -      }
  39.299 -
  39.300 -      ///Push a new edge to the back of the path
  39.301 -
  39.302 -      ///Push a new edge to the back of the path.
  39.303 -      ///\sa setStartNode
  39.304 -      void pushBack(const GraphEdge& e) {
  39.305 -	back.push_back(e);
  39.306 -      }
  39.307 -
  39.308 -      ///Commit the changes to the path.
  39.309 -      void commit() {
  39.310 -	if( !front.empty() || !back.empty() ) {
  39.311 -	  Container tmp;
  39.312 -	  tmp.reserve(front.size()+back.size()+P.length());
  39.313 -	  tmp.insert(tmp.end(), front.rbegin(), front.rend());
  39.314 -	  tmp.insert(tmp.end(), P.edges.begin(), P.edges.end());
  39.315 -	  tmp.insert(tmp.end(), back.begin(), back.end());
  39.316 -	  P.edges.swap(tmp);
  39.317 -	  front.clear();
  39.318 -	  back.clear();
  39.319 -	}
  39.320 -      }
  39.321 -
  39.322 -      ///Reserve storage for the builder in advance.
  39.323 -
  39.324 -      ///If you know a reasonable upper bound of the number of the edges
  39.325 -      ///to add to the front, using this function you can speed up the building.
  39.326 -
  39.327 -      void reserveFront(size_t r) {front.reserve(r);}
  39.328 -
  39.329 -      ///Reserve storage for the builder in advance.
  39.330 -
  39.331 -      ///If you know a reasonable upper bound of the number of the edges
  39.332 -      ///to add to the back, using this function you can speed up the building.
  39.333 -
  39.334 -      void reserveBack(size_t r) {back.reserve(r);}
  39.335 -
  39.336 -    private:
  39.337 -      bool empty() {
  39.338 -	return front.empty() && back.empty() && P.empty();
  39.339 -      }
  39.340 -
  39.341 -      GraphNode tail() const {
  39.342 -	if( ! front.empty() )
  39.343 -	  return P.gr->tail(front[front.size()-1]);
  39.344 -	else if( ! P.empty() )
  39.345 -	  return P.gr->tail(P.edges[0]);
  39.346 -	else if( ! back.empty() )
  39.347 -	  return P.gr->tail(back[0]);
  39.348 -	else
  39.349 -	  return INVALID;
  39.350 -      }
  39.351 -      GraphNode head() const {
  39.352 -	if( ! back.empty() )
  39.353 -	  return P.gr->head(back[back.size()-1]);
  39.354 -	else if( ! P.empty() )
  39.355 -	  return P.gr->head(P.edges[P.length()-1]);
  39.356 -	else if( ! front.empty() )
  39.357 -	  return P.gr->head(front[0]);
  39.358 -	else
  39.359 -	  return INVALID;
  39.360 -      }
  39.361 -
  39.362 -    };
  39.363 -
  39.364 -  };
  39.365 -
  39.366 -
  39.367 -
  39.368 -
  39.369 -
  39.370 -
  39.371 -
  39.372 -
  39.373 -
  39.374 -
  39.375 -  /**********************************************************************/
  39.376 -
  39.377 -
  39.378 -  //! \brief A structure for representing undirected path in a graph.
  39.379 -  //!
  39.380 -  //! A structure for representing undirected path in a graph. Ie. this is
  39.381 -  //! a path in a \e directed graph but the edges should not be directed
  39.382 -  //! forward.
  39.383 -  //!
  39.384 -  //! \param Graph The graph type in which the path is.
  39.385 -  //! \param DM DebugMode, defaults to DefaultDebugMode.
  39.386 -  //!
  39.387 -  //! In a sense, the path can be treated as a graph, for is has \c NodeIt
  39.388 -  //! and \c EdgeIt with the same usage. These types converts to the \c Node
  39.389 -  //! and \c Edge of the original graph.
  39.390 -  //!
  39.391 -  //! \todo Thoroughfully check all the range and consistency tests.
  39.392 -  template<typename Graph>
  39.393 -  class UndirPath {
  39.394 -  public:
  39.395 -    /// Edge type of the underlying graph.
  39.396 -    typedef typename Graph::Edge GraphEdge;
  39.397 -     /// Node type of the underlying graph.
  39.398 -   typedef typename Graph::Node GraphNode;
  39.399 -    class NodeIt;
  39.400 -    class EdgeIt;
  39.401 -
  39.402 -  protected:
  39.403 -    const Graph *gr;
  39.404 -    typedef std::vector<GraphEdge> Container;
  39.405 -    Container edges;
  39.406 -
  39.407 -  public:
  39.408 -
  39.409 -    /// \param _G The graph in which the path is.
  39.410 -    ///
  39.411 -    UndirPath(const Graph &_G) : gr(&_G) {}
  39.412 -
  39.413 -    /// \brief Subpath constructor.
  39.414 -    ///
  39.415 -    /// Subpath defined by two nodes.
  39.416 -    /// \warning It is an error if the two edges are not in order!
  39.417 -    UndirPath(const UndirPath &P, const NodeIt &a, const NodeIt &b) {
  39.418 -      gr = P.gr;
  39.419 -      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  39.420 -    }
  39.421 -
  39.422 -    /// \brief Subpath constructor.
  39.423 -    ///
  39.424 -    /// Subpath defined by two edges. Contains edges in [a,b)
  39.425 -    /// \warning It is an error if the two edges are not in order!
  39.426 -    UndirPath(const UndirPath &P, const EdgeIt &a, const EdgeIt &b) {
  39.427 -      gr = P.gr;
  39.428 -      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  39.429 -    }
  39.430 -
  39.431 -    /// Length of the path.
  39.432 -    size_t length() const { return edges.size(); }
  39.433 -    /// Returns whether the path is empty.
  39.434 -    bool empty() const { return edges.empty(); }
  39.435 -
  39.436 -    /// Resets the path to an empty path.
  39.437 -    void clear() { edges.clear(); }
  39.438 -
  39.439 -    /// \brief Starting point of the path.
  39.440 -    ///
  39.441 -    /// Starting point of the path.
  39.442 -    /// Returns INVALID if the path is empty.
  39.443 -    GraphNode tail() const {
  39.444 -      return empty() ? INVALID : gr->tail(edges[0]);
  39.445 -    }
  39.446 -    /// \brief End point of the path.
  39.447 -    ///
  39.448 -    /// End point of the path.
  39.449 -    /// Returns INVALID if the path is empty.
  39.450 -    GraphNode head() const {
  39.451 -      return empty() ? INVALID : gr->head(edges[length()-1]);
  39.452 -    }
  39.453 -
  39.454 -    /// \brief Initializes node or edge iterator to point to the first
  39.455 -    /// node or edge.
  39.456 -    ///
  39.457 -    /// \sa nth
  39.458 -    template<typename It>
  39.459 -    It& first(It &i) const { return i=It(*this); }
  39.460 -
  39.461 -    /// \brief Initializes node iterator to point to the node of a given index.
  39.462 -    NodeIt& nth(NodeIt &i, int n) const {
  39.463 -      return i=NodeIt(*this, n);
  39.464 -    }
  39.465 -
  39.466 -    /// \brief Initializes edge iterator to point to the edge of a given index.
  39.467 -    EdgeIt& nth(EdgeIt &i, int n) const {
  39.468 -      return i=EdgeIt(*this, n);
  39.469 -    }
  39.470 -
  39.471 -    /// Checks validity of a node or edge iterator.
  39.472 -    template<typename It>
  39.473 -    static
  39.474 -    bool valid(const It &i) { return i.valid(); }
  39.475 -
  39.476 -    /// Steps the given node or edge iterator.
  39.477 -    template<typename It>
  39.478 -    static
  39.479 -    It& next(It &e) {
  39.480 -      return ++e;
  39.481 -    }
  39.482 -
  39.483 -    /// \brief Returns node iterator pointing to the head node of the
  39.484 -    /// given edge iterator.
  39.485 -    NodeIt head(const EdgeIt& e) const {
  39.486 -      return NodeIt(*this, e.idx+1);
  39.487 -    }
  39.488 -
  39.489 -    /// \brief Returns node iterator pointing to the tail node of the
  39.490 -    /// given edge iterator.
  39.491 -    NodeIt tail(const EdgeIt& e) const {
  39.492 -      return NodeIt(*this, e.idx);
  39.493 -    }
  39.494 -
  39.495 -
  39.496 -
  39.497 -    /**
  39.498 -     * \brief Iterator class to iterate on the edges of the paths
  39.499 -     *
  39.500 -     * \ingroup paths
  39.501 -     * This class is used to iterate on the edges of the paths
  39.502 -     *
  39.503 -     * Of course it converts to Graph::Edge
  39.504 -     *
  39.505 -     * \todo Its interface differs from the standard edge iterator.
  39.506 -     * Yes, it shouldn't.
  39.507 -     */
  39.508 -    class EdgeIt {
  39.509 -      friend class UndirPath;
  39.510 -
  39.511 -      int idx;
  39.512 -      const UndirPath *p;
  39.513 -    public:
  39.514 -      /// Default constructor
  39.515 -      EdgeIt() {}
  39.516 -      /// Invalid constructor
  39.517 -      EdgeIt(Invalid) : idx(-1), p(0) {}
  39.518 -      /// Constructor with starting point
  39.519 -      EdgeIt(const UndirPath &_p, int _idx = 0) :
  39.520 -	idx(_idx), p(&_p) { validate(); }
  39.521 -
  39.522 -      ///Validity check
  39.523 -      bool valid() const { return idx!=-1; }
  39.524 -
  39.525 -      ///Conversion to Graph::Edge
  39.526 -      operator GraphEdge () const {
  39.527 -	return valid() ? p->edges[idx] : INVALID;
  39.528 -      }
  39.529 -      /// Next edge
  39.530 -     EdgeIt& operator++() { ++idx; validate(); return *this; }
  39.531 -
  39.532 -      /// Comparison operator
  39.533 -      bool operator==(const EdgeIt& e) const { return idx==e.idx; }
  39.534 -      /// Comparison operator
  39.535 -      bool operator!=(const EdgeIt& e) const { return idx!=e.idx; }
  39.536 -      /// Comparison operator
  39.537 -      bool operator<(const EdgeIt& e) const { return idx<e.idx; }
  39.538 -
  39.539 -    private:
  39.540 -      // FIXME: comparison between signed and unsigned...
  39.541 -      // Jo ez igy? Vagy esetleg legyen a length() int?
  39.542 -      void validate() { if( size_t(idx) >= p->length() ) idx=-1; }
  39.543 -    };
  39.544 -
  39.545 -    /**
  39.546 -     * \brief Iterator class to iterate on the nodes of the paths
  39.547 -     *
  39.548 -     * \ingroup paths
  39.549 -     * This class is used to iterate on the nodes of the paths
  39.550 -     *
  39.551 -     * Of course it converts to Graph::Node
  39.552 -     *
  39.553 -     * \todo Its interface differs from the standard node iterator.
  39.554 -     * Yes, it shouldn't.
  39.555 -     */
  39.556 -    class NodeIt {
  39.557 -      friend class UndirPath;
  39.558 -
  39.559 -      int idx;
  39.560 -      const UndirPath *p;
  39.561 -    public:
  39.562 -      /// Default constructor
  39.563 -      NodeIt() {}
  39.564 -      /// Invalid constructor
  39.565 -      NodeIt(Invalid) : idx(-1), p(0) {}
  39.566 -      /// Constructor with starting point
  39.567 -      NodeIt(const UndirPath &_p, int _idx = 0) :
  39.568 -	idx(_idx), p(&_p) { validate(); }
  39.569 -
  39.570 -      ///Validity check
  39.571 -      bool valid() const { return idx!=-1; }
  39.572 -
  39.573 -      ///Conversion to Graph::Node
  39.574 -      operator const GraphNode& () const {
  39.575 -	if(idx >= p->length())
  39.576 -	  return p->head();
  39.577 -	else if(idx >= 0)
  39.578 -	  return p->gr->tail(p->edges[idx]);
  39.579 -	else
  39.580 -	  return INVALID;
  39.581 -      }
  39.582 -      /// Next node
  39.583 -      NodeIt& operator++() { ++idx; validate(); return *this; }
  39.584 -
  39.585 -      /// Comparison operator
  39.586 -      bool operator==(const NodeIt& e) const { return idx==e.idx; }
  39.587 -      /// Comparison operator
  39.588 -      bool operator!=(const NodeIt& e) const { return idx!=e.idx; }
  39.589 -       /// Comparison operator
  39.590 -     bool operator<(const NodeIt& e) const { return idx<e.idx; }
  39.591 -
  39.592 -    private:
  39.593 -      void validate() { if( size_t(idx) > p->length() ) idx=-1; }
  39.594 -    };
  39.595 -
  39.596 -    friend class Builder;
  39.597 -
  39.598 -    /**
  39.599 -     * \brief Class to build paths
  39.600 -     *
  39.601 -     * \ingroup paths
  39.602 -     * This class is used to fill a path with edges.
  39.603 -     *
  39.604 -     * You can push new edges to the front and to the back of the path in
  39.605 -     * arbitrary order then you should commit these changes to the graph.
  39.606 -     *
  39.607 -     * Fundamentally, for most "Paths" (classes fulfilling the
  39.608 -     * PathConcept) while the builder is active (after the first modifying
  39.609 -     * operation and until the commit()) the original Path is in a
  39.610 -     * "transitional" state (operations ot it have undefined result). But
  39.611 -     * in the case of UndirPath the original path is unchanged until the
  39.612 -     * commit. However we don't recomend that you use this feature.
  39.613 -     */
  39.614 -    class Builder {
  39.615 -      UndirPath &P;
  39.616 -      Container front, back;
  39.617 -
  39.618 -    public:
  39.619 -      ///\param _P the path you want to fill in.
  39.620 -      ///
  39.621 -      Builder(UndirPath &_P) : P(_P) {}
  39.622 -
  39.623 -      /// Sets the starting node of the path.
  39.624 -
  39.625 -      /// Sets the starting node of the path. Edge added to the path
  39.626 -      /// afterwards have to be incident to this node.
  39.627 -      /// It should be called if and only if
  39.628 -      /// the path is empty and before any call to
  39.629 -      /// \ref pushFront() or \ref pushBack()
  39.630 -      void setStartNode(const GraphNode &) {}
  39.631 -
  39.632 -      ///Push a new edge to the front of the path
  39.633 -
  39.634 -      ///Push a new edge to the front of the path.
  39.635 -      ///\sa setStartNode
  39.636 -      void pushFront(const GraphEdge& e) {
  39.637 -	front.push_back(e);
  39.638 -      }
  39.639 -
  39.640 -      ///Push a new edge to the back of the path
  39.641 -
  39.642 -      ///Push a new edge to the back of the path.
  39.643 -      ///\sa setStartNode
  39.644 -      void pushBack(const GraphEdge& e) {
  39.645 -	back.push_back(e);
  39.646 -      }
  39.647 -
  39.648 -      ///Commit the changes to the path.
  39.649 -      void commit() {
  39.650 -	if( !(front.empty() && back.empty()) ) {
  39.651 -	  Container tmp;
  39.652 -	  tmp.reserve(front.size()+back.size()+P.length());
  39.653 -	  tmp.insert(tmp.end(), front.rbegin(), front.rend());
  39.654 -	  tmp.insert(tmp.end(), P.edges.begin(), P.edges.end());
  39.655 -	  tmp.insert(tmp.end(), back.begin(), back.end());
  39.656 -	  P.edges.swap(tmp);
  39.657 -	  front.clear();
  39.658 -	  back.clear();
  39.659 -	}
  39.660 -      }
  39.661 -
  39.662 -
  39.663 -      ///Reserve storage for the builder in advance.
  39.664 -
  39.665 -      ///If you know a reasonable upper bound of the number of the edges
  39.666 -      ///to add to the front, using this function you can speed up the building.
  39.667 -
  39.668 -      void reserveFront(size_t r) {front.reserve(r);}
  39.669 -
  39.670 -      ///Reserve storage for the builder in advance.
  39.671 -
  39.672 -      ///If you know a reasonable upper bound of the number of the edges
  39.673 -      ///to add to the back, using this function you can speed up the building.
  39.674 -
  39.675 -      void reserveBack(size_t r) {back.reserve(r);}
  39.676 -
  39.677 -    private:
  39.678 -      bool empty() {
  39.679 -	return front.empty() && back.empty() && P.empty();
  39.680 -      }
  39.681 -
  39.682 -      GraphNode tail() const {
  39.683 -	if( ! front.empty() )
  39.684 -	  return P.gr->tail(front[front.size()-1]);
  39.685 -	else if( ! P.empty() )
  39.686 -	  return P.gr->tail(P.edges[0]);
  39.687 -	else if( ! back.empty() )
  39.688 -	  return P.gr->tail(back[0]);
  39.689 -	else
  39.690 -	  return INVALID;
  39.691 -      }
  39.692 -      GraphNode head() const {
  39.693 -	if( ! back.empty() )
  39.694 -	  return P.gr->head(back[back.size()-1]);
  39.695 -	else if( ! P.empty() )
  39.696 -	  return P.gr->head(P.edges[P.length()-1]);
  39.697 -	else if( ! front.empty() )
  39.698 -	  return P.gr->head(front[0]);
  39.699 -	else
  39.700 -	  return INVALID;
  39.701 -      }
  39.702 -
  39.703 -    };
  39.704 -
  39.705 -  };
  39.706 -
  39.707 -
  39.708 -  ///@}
  39.709 -
  39.710 -} // namespace hugo
  39.711 -
  39.712 -#endif // HUGO_PATH_H
    40.1 --- a/src/hugo/preflow.h	Wed Sep 29 14:12:26 2004 +0000
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,819 +0,0 @@
    40.4 -/* -*- C++ -*-
    40.5 - * src/hugo/preflow.h - Part of HUGOlib, a generic C++ optimization library
    40.6 - *
    40.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    40.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    40.9 - *
   40.10 - * Permission to use, modify and distribute this software is granted
   40.11 - * provided that this copyright notice appears in all copies. For
   40.12 - * precise terms see the accompanying LICENSE file.
   40.13 - *
   40.14 - * This software is provided "AS IS" with no warranty of any kind,
   40.15 - * express or implied, and with no claim as to its suitability for any
   40.16 - * purpose.
   40.17 - *
   40.18 - */
   40.19 -
   40.20 -#ifndef HUGO_PREFLOW_H
   40.21 -#define HUGO_PREFLOW_H
   40.22 -
   40.23 -#include <vector>
   40.24 -#include <queue>
   40.25 -
   40.26 -#include <hugo/invalid.h>
   40.27 -#include <hugo/maps.h>
   40.28 -
   40.29 -/// \file
   40.30 -/// \ingroup flowalgs
   40.31 -/// Implementation of the preflow algorithm.
   40.32 -
   40.33 -namespace hugo {
   40.34 -
   40.35 -  /// \addtogroup flowalgs
   40.36 -  /// @{                                                   
   40.37 -
   40.38 -  ///%Preflow algorithms class.
   40.39 -
   40.40 -  ///This class provides an implementation of the \e preflow \e
   40.41 -  ///algorithm producing a flow of maximum value in a directed
   40.42 -  ///graph. The preflow algorithms are the fastest max flow algorithms
   40.43 -  ///up to now. The \e source node, the \e target node, the \e
   40.44 -  ///capacity of the edges and the \e starting \e flow value of the
   40.45 -  ///edges should be passed to the algorithm through the
   40.46 -  ///constructor. It is possible to change these quantities using the
   40.47 -  ///functions \ref setSource, \ref setTarget, \ref setCap and \ref
   40.48 -  ///setFlow.
   40.49 -  ///
   40.50 -  ///After running \ref hugo::Preflow::phase1() "phase1()"
   40.51 -  ///or \ref hugo::Preflow::run() "run()", the maximal flow
   40.52 -  ///value can be obtained by calling \ref flowValue(). The minimum
   40.53 -  ///value cut can be written into a <tt>bool</tt> node map by
   40.54 -  ///calling \ref minCut(). (\ref minMinCut() and \ref maxMinCut() writes
   40.55 -  ///the inclusionwise minimum and maximum of the minimum value cuts,
   40.56 -  ///resp.)
   40.57 -  ///
   40.58 -  ///\param Graph The directed graph type the algorithm runs on.
   40.59 -  ///\param Num The number type of the capacities and the flow values.
   40.60 -  ///\param CapMap The capacity map type.
   40.61 -  ///\param FlowMap The flow map type.
   40.62 -  ///
   40.63 -  ///\author Jacint Szabo 
   40.64 -  template <typename Graph, typename Num,
   40.65 -	    typename CapMap=typename Graph::template EdgeMap<Num>,
   40.66 -            typename FlowMap=typename Graph::template EdgeMap<Num> >
   40.67 -  class Preflow {
   40.68 -  protected:
   40.69 -    typedef typename Graph::Node Node;
   40.70 -    typedef typename Graph::NodeIt NodeIt;
   40.71 -    typedef typename Graph::EdgeIt EdgeIt;
   40.72 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   40.73 -    typedef typename Graph::InEdgeIt InEdgeIt;
   40.74 -
   40.75 -    typedef typename Graph::template NodeMap<Node> NNMap;
   40.76 -    typedef typename std::vector<Node> VecNode;
   40.77 -
   40.78 -    const Graph* g;
   40.79 -    Node s;
   40.80 -    Node t;
   40.81 -    const CapMap* capacity;
   40.82 -    FlowMap* flow;
   40.83 -    int n;      //the number of nodes of G
   40.84 -    
   40.85 -    typename Graph::template NodeMap<int> level;  
   40.86 -    typename Graph::template NodeMap<Num> excess;
   40.87 -
   40.88 -    // constants used for heuristics
   40.89 -    static const int H0=20;
   40.90 -    static const int H1=1;
   40.91 -
   40.92 -    public:
   40.93 -
   40.94 -    ///Indicates the property of the starting flow map.
   40.95 -
   40.96 -    ///Indicates the property of the starting flow map. The meanings are as follows:
   40.97 -    ///- \c ZERO_FLOW: constant zero flow
   40.98 -    ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
   40.99 -    ///the sum of the out-flows in every node except the \e source and
  40.100 -    ///the \e target.
  40.101 -    ///- \c PRE_FLOW: any preflow, i.e. the sum of the in-flows is at 
  40.102 -    ///least the sum of the out-flows in every node except the \e source.
  40.103 -    ///- \c NO_FLOW: indicates an unspecified edge map. \c flow will be 
  40.104 -    ///set to the constant zero flow in the beginning of
  40.105 -    ///the algorithm in this case.
  40.106 -    ///
  40.107 -    enum FlowEnum{
  40.108 -      NO_FLOW,
  40.109 -      ZERO_FLOW,
  40.110 -      GEN_FLOW,
  40.111 -      PRE_FLOW
  40.112 -    };
  40.113 -
  40.114 -    ///Indicates the state of the preflow algorithm.
  40.115 -
  40.116 -    ///Indicates the state of the preflow algorithm. The meanings are as follows:
  40.117 -    ///- \c AFTER_NOTHING: before running the algorithm or at an unspecified state.
  40.118 -    ///- \c AFTER_PREFLOW_PHASE_1: right after running \c phase1
  40.119 -    ///- \c AFTER_PREFLOW_PHASE_2: after running \ref phase2()
  40.120 -    ///
  40.121 -    enum StatusEnum {
  40.122 -      AFTER_NOTHING,
  40.123 -      AFTER_PREFLOW_PHASE_1,      
  40.124 -      AFTER_PREFLOW_PHASE_2
  40.125 -    };
  40.126 -    
  40.127 -    protected: 
  40.128 -      FlowEnum flow_prop;
  40.129 -    StatusEnum status; // Do not needle this flag only if necessary.
  40.130 -    
  40.131 -  public: 
  40.132 -    ///The constructor of the class.
  40.133 -
  40.134 -    ///The constructor of the class. 
  40.135 -    ///\param _G The directed graph the algorithm runs on. 
  40.136 -    ///\param _s The source node.
  40.137 -    ///\param _t The target node.
  40.138 -    ///\param _capacity The capacity of the edges. 
  40.139 -    ///\param _flow The flow of the edges. 
  40.140 -    ///Except the graph, all of these parameters can be reset by
  40.141 -    ///calling \ref setSource, \ref setTarget, \ref setCap and \ref
  40.142 -    ///setFlow, resp.
  40.143 -      Preflow(const Graph& _G, Node _s, Node _t, 
  40.144 -	      const CapMap& _capacity, FlowMap& _flow) :
  40.145 -	g(&_G), s(_s), t(_t), capacity(&_capacity),
  40.146 -	flow(&_flow), n(_G.nodeNum()), level(_G), excess(_G,0), 
  40.147 -	flow_prop(NO_FLOW), status(AFTER_NOTHING) { }
  40.148 -
  40.149 -
  40.150 -                                                                              
  40.151 -    ///Runs the preflow algorithm.  
  40.152 -
  40.153 -    ///Runs the preflow algorithm.
  40.154 -    ///
  40.155 -    void run() {
  40.156 -      phase1(flow_prop);
  40.157 -      phase2();
  40.158 -    }
  40.159 -    
  40.160 -    ///Runs the preflow algorithm.  
  40.161 -    
  40.162 -    ///Runs the preflow algorithm. 
  40.163 -    ///\pre The starting flow map must be
  40.164 -    /// - a constant zero flow if \c fp is \c ZERO_FLOW,
  40.165 -    /// - an arbitrary flow if \c fp is \c GEN_FLOW,
  40.166 -    /// - an arbitrary preflow if \c fp is \c PRE_FLOW,
  40.167 -    /// - any map if \c fp is NO_FLOW.
  40.168 -    ///If the starting flow map is a flow or a preflow then 
  40.169 -    ///the algorithm terminates faster.
  40.170 -    void run(FlowEnum fp) {
  40.171 -      flow_prop=fp;
  40.172 -      run();
  40.173 -    }
  40.174 -      
  40.175 -    ///Runs the first phase of the preflow algorithm.
  40.176 -
  40.177 -    ///The preflow algorithm consists of two phases, this method runs
  40.178 -    ///the first phase. After the first phase the maximum flow value
  40.179 -    ///and a minimum value cut can already be computed, though a
  40.180 -    ///maximum flow is not yet obtained. So after calling this method
  40.181 -    ///\ref flowValue returns the value of a maximum flow and \ref
  40.182 -    ///minCut returns a minimum cut.     
  40.183 -    ///\warning \ref minMinCut and \ref maxMinCut do not give minimum
  40.184 -    ///value cuts unless calling \ref phase2.  
  40.185 -    ///\pre The starting flow must be 
  40.186 -    ///- a constant zero flow if \c fp is \c ZERO_FLOW, 
  40.187 -    ///- an arbitary flow if \c fp is \c GEN_FLOW, 
  40.188 -    ///- an arbitary preflow if \c fp is \c PRE_FLOW, 
  40.189 -    ///- any map if \c fp is NO_FLOW.
  40.190 -    void phase1(FlowEnum fp)
  40.191 -    {
  40.192 -      flow_prop=fp;
  40.193 -      phase1();
  40.194 -    }
  40.195 -
  40.196 -    
  40.197 -    ///Runs the first phase of the preflow algorithm.
  40.198 -
  40.199 -    ///The preflow algorithm consists of two phases, this method runs
  40.200 -    ///the first phase. After the first phase the maximum flow value
  40.201 -    ///and a minimum value cut can already be computed, though a
  40.202 -    ///maximum flow is not yet obtained. So after calling this method
  40.203 -    ///\ref flowValue returns the value of a maximum flow and \ref
  40.204 -    ///minCut returns a minimum cut.
  40.205 -    ///\warning \ref minCut(), \ref minMinCut() and \ref maxMinCut() do not
  40.206 -    ///give minimum value cuts unless calling \ref phase2().
  40.207 -    void phase1()
  40.208 -    {
  40.209 -      int heur0=(int)(H0*n);  //time while running 'bound decrease'
  40.210 -      int heur1=(int)(H1*n);  //time while running 'highest label'
  40.211 -      int heur=heur1;         //starting time interval (#of relabels)
  40.212 -      int numrelabel=0;
  40.213 -
  40.214 -      bool what_heur=1;
  40.215 -      //It is 0 in case 'bound decrease' and 1 in case 'highest label'
  40.216 -
  40.217 -      bool end=false;
  40.218 -      //Needed for 'bound decrease', true means no active 
  40.219 -      //nodes are above bound b.
  40.220 -
  40.221 -      int k=n-2;  //bound on the highest level under n containing a node
  40.222 -      int b=k;    //bound on the highest level under n of an active node
  40.223 -
  40.224 -      VecNode first(n, INVALID);
  40.225 -      NNMap next(*g, INVALID);
  40.226 -
  40.227 -      NNMap left(*g, INVALID);
  40.228 -      NNMap right(*g, INVALID);
  40.229 -      VecNode level_list(n,INVALID);
  40.230 -      //List of the nodes in level i<n, set to n.
  40.231 -
  40.232 -      preflowPreproc(first, next, level_list, left, right);
  40.233 -
  40.234 -      //Push/relabel on the highest level active nodes.
  40.235 -      while ( true ) {
  40.236 -	if ( b == 0 ) {
  40.237 -	  if ( !what_heur && !end && k > 0 ) {
  40.238 -	    b=k;
  40.239 -	    end=true;
  40.240 -	  } else break;
  40.241 -	}
  40.242 -
  40.243 -	if ( first[b]==INVALID ) --b;
  40.244 -	else {
  40.245 -	  end=false;
  40.246 -	  Node w=first[b];
  40.247 -	  first[b]=next[w];
  40.248 -	  int newlevel=push(w, next, first);
  40.249 -	  if ( excess[w] > 0 ) relabel(w, newlevel, first, next, level_list, 
  40.250 -				       left, right, b, k, what_heur);
  40.251 -
  40.252 -	  ++numrelabel;
  40.253 -	  if ( numrelabel >= heur ) {
  40.254 -	    numrelabel=0;
  40.255 -	    if ( what_heur ) {
  40.256 -	      what_heur=0;
  40.257 -	      heur=heur0;
  40.258 -	      end=false;
  40.259 -	    } else {
  40.260 -	      what_heur=1;
  40.261 -	      heur=heur1;
  40.262 -	      b=k;
  40.263 -	    }
  40.264 -	  }
  40.265 -	}
  40.266 -      }
  40.267 -      flow_prop=PRE_FLOW;
  40.268 -      status=AFTER_PREFLOW_PHASE_1;
  40.269 -    }
  40.270 -    // Heuristics:
  40.271 -    //   2 phase
  40.272 -    //   gap
  40.273 -    //   list 'level_list' on the nodes on level i implemented by hand
  40.274 -    //   stack 'active' on the active nodes on level i      
  40.275 -    //   runs heuristic 'highest label' for H1*n relabels
  40.276 -    //   runs heuristic 'bound decrease' for H0*n relabels, starts with 'highest label'
  40.277 -    //   Parameters H0 and H1 are initialized to 20 and 1.
  40.278 -
  40.279 -
  40.280 -    ///Runs the second phase of the preflow algorithm.
  40.281 -
  40.282 -    ///The preflow algorithm consists of two phases, this method runs
  40.283 -    ///the second phase. After calling \ref phase1 and then \ref
  40.284 -    ///phase2, \ref flow contains a maximum flow, \ref flowValue
  40.285 -    ///returns the value of a maximum flow, \ref minCut returns a
  40.286 -    ///minimum cut, while the methods \ref minMinCut and \ref
  40.287 -    ///maxMinCut return the inclusionwise minimum and maximum cuts of
  40.288 -    ///minimum value, resp.  \pre \ref phase1 must be called before.
  40.289 -    void phase2()
  40.290 -    {
  40.291 -
  40.292 -      int k=n-2;  //bound on the highest level under n containing a node
  40.293 -      int b=k;    //bound on the highest level under n of an active node
  40.294 -
  40.295 -    
  40.296 -      VecNode first(n, INVALID);
  40.297 -      NNMap next(*g, INVALID); 
  40.298 -      level.set(s,0);
  40.299 -      std::queue<Node> bfs_queue;
  40.300 -      bfs_queue.push(s);
  40.301 -
  40.302 -      while ( !bfs_queue.empty() ) {
  40.303 -
  40.304 -	Node v=bfs_queue.front();
  40.305 -	bfs_queue.pop();
  40.306 -	int l=level[v]+1;
  40.307 -
  40.308 -	for(InEdgeIt e(*g,v); e!=INVALID; ++e) {
  40.309 -	  if ( (*capacity)[e] <= (*flow)[e] ) continue;
  40.310 -	  Node u=g->tail(e);
  40.311 -	  if ( level[u] >= n ) {
  40.312 -	    bfs_queue.push(u);
  40.313 -	    level.set(u, l);
  40.314 -	    if ( excess[u] > 0 ) {
  40.315 -	      next.set(u,first[l]);
  40.316 -	      first[l]=u;
  40.317 -	    }
  40.318 -	  }
  40.319 -	}
  40.320 -
  40.321 -	for(OutEdgeIt e(*g,v); e!=INVALID; ++e) {
  40.322 -	  if ( 0 >= (*flow)[e] ) continue;
  40.323 -	  Node u=g->head(e);
  40.324 -	  if ( level[u] >= n ) {
  40.325 -	    bfs_queue.push(u);
  40.326 -	    level.set(u, l);
  40.327 -	    if ( excess[u] > 0 ) {
  40.328 -	      next.set(u,first[l]);
  40.329 -	      first[l]=u;
  40.330 -	    }
  40.331 -	  }
  40.332 -	}
  40.333 -      }
  40.334 -      b=n-2;
  40.335 -
  40.336 -      while ( true ) {
  40.337 -
  40.338 -	if ( b == 0 ) break;
  40.339 -	if ( first[b]==INVALID ) --b;
  40.340 -	else {
  40.341 -	  Node w=first[b];
  40.342 -	  first[b]=next[w];
  40.343 -	  int newlevel=push(w,next, first);
  40.344 -	  
  40.345 -	  //relabel
  40.346 -	  if ( excess[w] > 0 ) {
  40.347 -	    level.set(w,++newlevel);
  40.348 -	    next.set(w,first[newlevel]);
  40.349 -	    first[newlevel]=w;
  40.350 -	    b=newlevel;
  40.351 -	  }
  40.352 -	} 
  40.353 -      } // while(true)
  40.354 -      flow_prop=GEN_FLOW;
  40.355 -      status=AFTER_PREFLOW_PHASE_2;
  40.356 -    }
  40.357 -
  40.358 -    /// Returns the value of the maximum flow.
  40.359 -
  40.360 -    /// Returns the value of the maximum flow by returning the excess
  40.361 -    /// of the target node \c t. This value equals to the value of
  40.362 -    /// the maximum flow already after running \ref phase1.
  40.363 -    Num flowValue() const {
  40.364 -      return excess[t];
  40.365 -    }
  40.366 -
  40.367 -
  40.368 -    ///Returns a minimum value cut.
  40.369 -
  40.370 -    ///Sets \c M to the characteristic vector of a minimum value
  40.371 -    ///cut. This method can be called both after running \ref
  40.372 -    ///phase1 and \ref phase2. It is much faster after
  40.373 -    ///\ref phase1.  \pre M should be a bool-valued node-map. \pre
  40.374 -    ///If \ref minCut() is called after \ref phase2() then M should
  40.375 -    ///be initialized to false.
  40.376 -    template<typename _CutMap>
  40.377 -    void minCut(_CutMap& M) const {
  40.378 -      switch ( status ) {
  40.379 -	case AFTER_PREFLOW_PHASE_1:
  40.380 -	for(NodeIt v(*g); v!=INVALID; ++v) {
  40.381 -	  if (level[v] < n) {
  40.382 -	    M.set(v, false);
  40.383 -	  } else {
  40.384 -	    M.set(v, true);
  40.385 -	  }
  40.386 -	}
  40.387 -	break;
  40.388 -	case AFTER_PREFLOW_PHASE_2:
  40.389 -	minMinCut(M);
  40.390 -	break;
  40.391 -	case AFTER_NOTHING:
  40.392 -	break;
  40.393 -      }
  40.394 -    }
  40.395 -
  40.396 -    ///Returns the inclusionwise minimum of the minimum value cuts.
  40.397 -
  40.398 -    ///Sets \c M to the characteristic vector of the minimum value cut
  40.399 -    ///which is inclusionwise minimum. It is computed by processing a
  40.400 -    ///bfs from the source node \c s in the residual graph.  \pre M
  40.401 -    ///should be a node map of bools initialized to false.  \pre \ref
  40.402 -    ///phase2 should already be run.
  40.403 -    template<typename _CutMap>
  40.404 -    void minMinCut(_CutMap& M) const {
  40.405 -
  40.406 -      std::queue<Node> queue;
  40.407 -      M.set(s,true);
  40.408 -      queue.push(s);
  40.409 -      
  40.410 -      while (!queue.empty()) {
  40.411 -	Node w=queue.front();
  40.412 -	queue.pop();
  40.413 -	
  40.414 -	for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.415 -	  Node v=g->head(e);
  40.416 -	  if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
  40.417 -	    queue.push(v);
  40.418 -	    M.set(v, true);
  40.419 -	  }
  40.420 -	}
  40.421 -	
  40.422 -	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.423 -	  Node v=g->tail(e);
  40.424 -	  if (!M[v] && (*flow)[e] > 0 ) {
  40.425 -	    queue.push(v);
  40.426 -	    M.set(v, true);
  40.427 -	  }
  40.428 -	}
  40.429 -      }
  40.430 -    }
  40.431 -    
  40.432 -    ///Returns the inclusionwise maximum of the minimum value cuts.
  40.433 -
  40.434 -    ///Sets \c M to the characteristic vector of the minimum value cut
  40.435 -    ///which is inclusionwise maximum. It is computed by processing a
  40.436 -    ///backward bfs from the target node \c t in the residual graph.
  40.437 -    ///\pre \ref phase2() or run() should already be run.
  40.438 -    template<typename _CutMap>
  40.439 -    void maxMinCut(_CutMap& M) const {
  40.440 -
  40.441 -      for(NodeIt v(*g) ; v!=INVALID; ++v) M.set(v, true);
  40.442 -
  40.443 -      std::queue<Node> queue;
  40.444 -
  40.445 -      M.set(t,false);
  40.446 -      queue.push(t);
  40.447 -
  40.448 -      while (!queue.empty()) {
  40.449 -        Node w=queue.front();
  40.450 -	queue.pop();
  40.451 -
  40.452 -	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.453 -	  Node v=g->tail(e);
  40.454 -	  if (M[v] && (*flow)[e] < (*capacity)[e] ) {
  40.455 -	    queue.push(v);
  40.456 -	    M.set(v, false);
  40.457 -	  }
  40.458 -	}
  40.459 -
  40.460 -	for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.461 -	  Node v=g->head(e);
  40.462 -	  if (M[v] && (*flow)[e] > 0 ) {
  40.463 -	    queue.push(v);
  40.464 -	    M.set(v, false);
  40.465 -	  }
  40.466 -	}
  40.467 -      }
  40.468 -    }
  40.469 -
  40.470 -    ///Sets the source node to \c _s.
  40.471 -
  40.472 -    ///Sets the source node to \c _s.
  40.473 -    /// 
  40.474 -    void setSource(Node _s) { 
  40.475 -      s=_s; 
  40.476 -      if ( flow_prop != ZERO_FLOW ) flow_prop=NO_FLOW;
  40.477 -      status=AFTER_NOTHING; 
  40.478 -    }
  40.479 -
  40.480 -    ///Sets the target node to \c _t.
  40.481 -
  40.482 -    ///Sets the target node to \c _t.
  40.483 -    ///
  40.484 -    void setTarget(Node _t) { 
  40.485 -      t=_t; 
  40.486 -      if ( flow_prop == GEN_FLOW ) flow_prop=PRE_FLOW;
  40.487 -      status=AFTER_NOTHING; 
  40.488 -    }
  40.489 -
  40.490 -    /// Sets the edge map of the capacities to _cap.
  40.491 -
  40.492 -    /// Sets the edge map of the capacities to _cap.
  40.493 -    /// 
  40.494 -    void setCap(const CapMap& _cap) { 
  40.495 -      capacity=&_cap; 
  40.496 -      status=AFTER_NOTHING; 
  40.497 -    }
  40.498 -
  40.499 -    /// Sets the edge map of the flows to _flow.
  40.500 -
  40.501 -    /// Sets the edge map of the flows to _flow.
  40.502 -    /// 
  40.503 -    void setFlow(FlowMap& _flow) { 
  40.504 -      flow=&_flow; 
  40.505 -      flow_prop=NO_FLOW;
  40.506 -      status=AFTER_NOTHING; 
  40.507 -    }
  40.508 -
  40.509 -
  40.510 -  private:
  40.511 -
  40.512 -    int push(Node w, NNMap& next, VecNode& first) {
  40.513 -
  40.514 -      int lev=level[w];
  40.515 -      Num exc=excess[w];
  40.516 -      int newlevel=n;       //bound on the next level of w
  40.517 -
  40.518 -      for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.519 -	if ( (*flow)[e] >= (*capacity)[e] ) continue;
  40.520 -	Node v=g->head(e);
  40.521 -
  40.522 -	if( lev > level[v] ) { //Push is allowed now
  40.523 -	  
  40.524 -	  if ( excess[v]<=0 && v!=t && v!=s ) {
  40.525 -	    next.set(v,first[level[v]]);
  40.526 -	    first[level[v]]=v;
  40.527 -	  }
  40.528 -
  40.529 -	  Num cap=(*capacity)[e];
  40.530 -	  Num flo=(*flow)[e];
  40.531 -	  Num remcap=cap-flo;
  40.532 -	  
  40.533 -	  if ( remcap >= exc ) { //A nonsaturating push.
  40.534 -	    
  40.535 -	    flow->set(e, flo+exc);
  40.536 -	    excess.set(v, excess[v]+exc);
  40.537 -	    exc=0;
  40.538 -	    break;
  40.539 -
  40.540 -	  } else { //A saturating push.
  40.541 -	    flow->set(e, cap);
  40.542 -	    excess.set(v, excess[v]+remcap);
  40.543 -	    exc-=remcap;
  40.544 -	  }
  40.545 -	} else if ( newlevel > level[v] ) newlevel = level[v];
  40.546 -      } //for out edges wv
  40.547 -
  40.548 -      if ( exc > 0 ) {
  40.549 -	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  40.550 -	  
  40.551 -	  if( (*flow)[e] <= 0 ) continue;
  40.552 -	  Node v=g->tail(e);
  40.553 -
  40.554 -	  if( lev > level[v] ) { //Push is allowed now
  40.555 -
  40.556 -	    if ( excess[v]<=0 && v!=t && v!=s ) {
  40.557 -	      next.set(v,first[level[v]]);
  40.558 -	      first[level[v]]=v;
  40.559 -	    }
  40.560 -
  40.561 -	    Num flo=(*flow)[e];
  40.562 -
  40.563 -	    if ( flo >= exc ) { //A nonsaturating push.
  40.564 -
  40.565 -	      flow->set(e, flo-exc);
  40.566 -	      excess.set(v, excess[v]+exc);
  40.567 -	      exc=0;
  40.568 -	      break;
  40.569 -	    } else {  //A saturating push.
  40.570 -
  40.571 -	      excess.set(v, excess[v]+flo);
  40.572 -	      exc-=flo;
  40.573 -	      flow->set(e,0);
  40.574 -	    }
  40.575 -	  } else if ( newlevel > level[v] ) newlevel = level[v];
  40.576 -	} //for in edges vw
  40.577 -
  40.578 -      } // if w still has excess after the out edge for cycle
  40.579 -
  40.580 -      excess.set(w, exc);
  40.581 -      
  40.582 -      return newlevel;
  40.583 -    }
  40.584 -    
  40.585 -    
  40.586 -    
  40.587 -    void preflowPreproc(VecNode& first, NNMap& next, 
  40.588 -			VecNode& level_list, NNMap& left, NNMap& right)
  40.589 -    {
  40.590 -      for(NodeIt v(*g); v!=INVALID; ++v) level.set(v,n);
  40.591 -      std::queue<Node> bfs_queue;
  40.592 -      
  40.593 -      if ( flow_prop == GEN_FLOW || flow_prop == PRE_FLOW ) {
  40.594 -	//Reverse_bfs from t in the residual graph,
  40.595 -	//to find the starting level.
  40.596 -	level.set(t,0);
  40.597 -	bfs_queue.push(t);
  40.598 -	
  40.599 -	while ( !bfs_queue.empty() ) {
  40.600 -	  
  40.601 -	  Node v=bfs_queue.front();
  40.602 -	  bfs_queue.pop();
  40.603 -	  int l=level[v]+1;
  40.604 -	  
  40.605 -	  for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  40.606 -	    if ( (*capacity)[e] <= (*flow)[e] ) continue;
  40.607 -	    Node w=g->tail(e);
  40.608 -	    if ( level[w] == n && w != s ) {
  40.609 -	      bfs_queue.push(w);
  40.610 -	      Node z=level_list[l];
  40.611 -	      if ( z!=INVALID ) left.set(z,w);
  40.612 -	      right.set(w,z);
  40.613 -	      level_list[l]=w;
  40.614 -	      level.set(w, l);
  40.615 -	    }
  40.616 -	  }
  40.617 -	  
  40.618 -	  for(OutEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  40.619 -	    if ( 0 >= (*flow)[e] ) continue;
  40.620 -	    Node w=g->head(e);
  40.621 -	    if ( level[w] == n && w != s ) {
  40.622 -	      bfs_queue.push(w);
  40.623 -	      Node z=level_list[l];
  40.624 -	      if ( z!=INVALID ) left.set(z,w);
  40.625 -	      right.set(w,z);
  40.626 -	      level_list[l]=w;
  40.627 -	      level.set(w, l);
  40.628 -	    }
  40.629 -	  }
  40.630 -	} //while
  40.631 -      } //if
  40.632 -
  40.633 -
  40.634 -      switch (flow_prop) {
  40.635 -	case NO_FLOW:  
  40.636 -	for(EdgeIt e(*g); e!=INVALID; ++e) flow->set(e,0);
  40.637 -	case ZERO_FLOW:
  40.638 -	for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
  40.639 -	
  40.640 -	//Reverse_bfs from t, to find the starting level.
  40.641 -	level.set(t,0);
  40.642 -	bfs_queue.push(t);
  40.643 -	
  40.644 -	while ( !bfs_queue.empty() ) {
  40.645 -	  
  40.646 -	  Node v=bfs_queue.front();
  40.647 -	  bfs_queue.pop();
  40.648 -	  int l=level[v]+1;
  40.649 -	  
  40.650 -	  for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  40.651 -	    Node w=g->tail(e);
  40.652 -	    if ( level[w] == n && w != s ) {
  40.653 -	      bfs_queue.push(w);
  40.654 -	      Node z=level_list[l];
  40.655 -	      if ( z!=INVALID ) left.set(z,w);
  40.656 -	      right.set(w,z);
  40.657 -	      level_list[l]=w;
  40.658 -	      level.set(w, l);
  40.659 -	    }
  40.660 -	  }
  40.661 -	}
  40.662 -	
  40.663 -	//the starting flow
  40.664 -	for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  40.665 -	  Num c=(*capacity)[e];
  40.666 -	  if ( c <= 0 ) continue;
  40.667 -	  Node w=g->head(e);
  40.668 -	  if ( level[w] < n ) {
  40.669 -	    if ( excess[w] <= 0 && w!=t ) { //putting into the stack
  40.670 -	      next.set(w,first[level[w]]);
  40.671 -	      first[level[w]]=w;
  40.672 -	    }
  40.673 -	    flow->set(e, c);
  40.674 -	    excess.set(w, excess[w]+c);
  40.675 -	  }
  40.676 -	}
  40.677 -	break;
  40.678 -
  40.679 -	case GEN_FLOW:
  40.680 -	for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
  40.681 -	{
  40.682 -	  Num exc=0;
  40.683 -	  for(InEdgeIt e(*g,t) ; e!=INVALID; ++e) exc+=(*flow)[e];
  40.684 -	  for(OutEdgeIt e(*g,t) ; e!=INVALID; ++e) exc-=(*flow)[e];
  40.685 -	  excess.set(t,exc);
  40.686 -	}
  40.687 -
  40.688 -	//the starting flow
  40.689 -	for(OutEdgeIt e(*g,s); e!=INVALID; ++e)	{
  40.690 -	  Num rem=(*capacity)[e]-(*flow)[e];
  40.691 -	  if ( rem <= 0 ) continue;
  40.692 -	  Node w=g->head(e);
  40.693 -	  if ( level[w] < n ) {
  40.694 -	    if ( excess[w] <= 0 && w!=t ) { //putting into the stack
  40.695 -	      next.set(w,first[level[w]]);
  40.696 -	      first[level[w]]=w;
  40.697 -	    }   
  40.698 -	    flow->set(e, (*capacity)[e]);
  40.699 -	    excess.set(w, excess[w]+rem);
  40.700 -	  }
  40.701 -	}
  40.702 -	
  40.703 -	for(InEdgeIt e(*g,s); e!=INVALID; ++e) {
  40.704 -	  if ( (*flow)[e] <= 0 ) continue;
  40.705 -	  Node w=g->tail(e);
  40.706 -	  if ( level[w] < n ) {
  40.707 -	    if ( excess[w] <= 0 && w!=t ) {
  40.708 -	      next.set(w,first[level[w]]);
  40.709 -	      first[level[w]]=w;
  40.710 -	    }  
  40.711 -	    excess.set(w, excess[w]+(*flow)[e]);
  40.712 -	    flow->set(e, 0);
  40.713 -	  }
  40.714 -	}
  40.715 -	break;
  40.716 -
  40.717 -	case PRE_FLOW:	
  40.718 -	//the starting flow
  40.719 -	for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  40.720 -	  Num rem=(*capacity)[e]-(*flow)[e];
  40.721 -	  if ( rem <= 0 ) continue;
  40.722 -	  Node w=g->head(e);
  40.723 -	  if ( level[w] < n ) flow->set(e, (*capacity)[e]);
  40.724 -	}
  40.725 -	
  40.726 -	for(InEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  40.727 -	  if ( (*flow)[e] <= 0 ) continue;
  40.728 -	  Node w=g->tail(e);
  40.729 -	  if ( level[w] < n ) flow->set(e, 0);
  40.730 -	}
  40.731 -	
  40.732 -	//computing the excess
  40.733 -	for(NodeIt w(*g); w!=INVALID; ++w) {
  40.734 -	  Num exc=0;
  40.735 -	  for(InEdgeIt e(*g,w); e!=INVALID; ++e) exc+=(*flow)[e];
  40.736 -	  for(OutEdgeIt e(*g,w); e!=INVALID; ++e) exc-=(*flow)[e];
  40.737 -	  excess.set(w,exc);
  40.738 -	  
  40.739 -	  //putting the active nodes into the stack
  40.740 -	  int lev=level[w];
  40.741 -	    if ( exc > 0 && lev < n && Node(w) != t ) {
  40.742 -	      next.set(w,first[lev]);
  40.743 -	      first[lev]=w;
  40.744 -	    }
  40.745 -	}
  40.746 -	break;
  40.747 -      } //switch
  40.748 -    } //preflowPreproc
  40.749 -
  40.750 -
  40.751 -    void relabel(Node w, int newlevel, VecNode& first, NNMap& next, 
  40.752 -		 VecNode& level_list, NNMap& left,
  40.753 -		 NNMap& right, int& b, int& k, bool what_heur )
  40.754 -    {
  40.755 -
  40.756 -      int lev=level[w];
  40.757 -
  40.758 -      Node right_n=right[w];
  40.759 -      Node left_n=left[w];
  40.760 -
  40.761 -      //unlacing starts
  40.762 -      if ( right_n!=INVALID ) {
  40.763 -	if ( left_n!=INVALID ) {
  40.764 -	  right.set(left_n, right_n);
  40.765 -	  left.set(right_n, left_n);
  40.766 -	} else {
  40.767 -	  level_list[lev]=right_n;
  40.768 -	  left.set(right_n, INVALID);
  40.769 -	}
  40.770 -      } else {
  40.771 -	if ( left_n!=INVALID ) {
  40.772 -	  right.set(left_n, INVALID);
  40.773 -	} else {
  40.774 -	  level_list[lev]=INVALID;
  40.775 -	}
  40.776 -      }
  40.777 -      //unlacing ends
  40.778 -
  40.779 -      if ( level_list[lev]==INVALID ) {
  40.780 -
  40.781 -	//gapping starts
  40.782 -	for (int i=lev; i!=k ; ) {
  40.783 -	  Node v=level_list[++i];
  40.784 -	  while ( v!=INVALID ) {
  40.785 -	    level.set(v,n);
  40.786 -	    v=right[v];
  40.787 -	  }
  40.788 -	  level_list[i]=INVALID;
  40.789 -	  if ( !what_heur ) first[i]=INVALID;
  40.790 -	}
  40.791 -
  40.792 -	level.set(w,n);
  40.793 -	b=lev-1;
  40.794 -	k=b;
  40.795 -	//gapping ends
  40.796 -
  40.797 -      } else {
  40.798 -
  40.799 -	if ( newlevel == n ) level.set(w,n);
  40.800 -	else {
  40.801 -	  level.set(w,++newlevel);
  40.802 -	  next.set(w,first[newlevel]);
  40.803 -	  first[newlevel]=w;
  40.804 -	  if ( what_heur ) b=newlevel;
  40.805 -	  if ( k < newlevel ) ++k;      //now k=newlevel
  40.806 -	  Node z=level_list[newlevel];
  40.807 -	  if ( z!=INVALID ) left.set(z,w);
  40.808 -	  right.set(w,z);
  40.809 -	  left.set(w,INVALID);
  40.810 -	  level_list[newlevel]=w;
  40.811 -	}
  40.812 -      }
  40.813 -    } //relabel
  40.814 -
  40.815 -  }; 
  40.816 -} //namespace hugo
  40.817 -
  40.818 -#endif //HUGO_PREFLOW_H
  40.819 -
  40.820 -
  40.821 -
  40.822 -
    41.1 --- a/src/hugo/skeletons/graph.h	Wed Sep 29 14:12:26 2004 +0000
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,510 +0,0 @@
    41.4 -/* -*- C++ -*-
    41.5 - * src/hugo/skeletons/graph.h - Part of HUGOlib, a generic C++ optimization library
    41.6 - *
    41.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    41.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    41.9 - *
   41.10 - * Permission to use, modify and distribute this software is granted
   41.11 - * provided that this copyright notice appears in all copies. For
   41.12 - * precise terms see the accompanying LICENSE file.
   41.13 - *
   41.14 - * This software is provided "AS IS" with no warranty of any kind,
   41.15 - * express or implied, and with no claim as to its suitability for any
   41.16 - * purpose.
   41.17 - *
   41.18 - */
   41.19 -
   41.20 -#ifndef HUGO_SKELETON_GRAPH_H
   41.21 -#define HUGO_SKELETON_GRAPH_H
   41.22 -
   41.23 -///\ingroup skeletons
   41.24 -///\file
   41.25 -///\brief Declaration of Graph.
   41.26 -
   41.27 -#include <hugo/invalid.h>
   41.28 -#include <hugo/skeletons/maps.h>
   41.29 -
   41.30 -namespace hugo {
   41.31 -  namespace skeleton {
   41.32 -    
   41.33 -    /// \addtogroup skeletons
   41.34 -    /// @{
   41.35 -
   41.36 -    /// An empty static graph class.
   41.37 -  
   41.38 -    /// This class provides all the common features of a graph structure,
   41.39 -    /// however completely without implementations and real data structures
   41.40 -    /// behind the interface.
   41.41 -    /// All graph algorithms should compile with this class, but it will not
   41.42 -    /// run properly, of course.
   41.43 -    ///
   41.44 -    /// It can be used for checking the interface compatibility,
   41.45 -    /// or it can serve as a skeleton of a new graph structure.
   41.46 -    /// 
   41.47 -    /// Also, you will find here the full documentation of a certain graph
   41.48 -    /// feature, the documentation of a real graph imlementation
   41.49 -    /// like @ref ListGraph or
   41.50 -    /// @ref SmartGraph will just refer to this structure.
   41.51 -    class StaticGraph
   41.52 -    {
   41.53 -    public:
   41.54 -      /// Defalult constructor.
   41.55 -
   41.56 -      /// Defalult constructor.
   41.57 -      ///
   41.58 -      StaticGraph() { }
   41.59 -      ///Copy consructor.
   41.60 -
   41.61 -//       ///\todo It is not clear, what we expect from a copy constructor.
   41.62 -//       ///E.g. How to assign the nodes/edges to each other? What about maps?
   41.63 -//       StaticGraph(const StaticGraph& g) { }
   41.64 -
   41.65 -      /// The base type of node iterators, 
   41.66 -      /// or in other words, the trivial node iterator.
   41.67 -
   41.68 -      /// This is the base type of each node iterator,
   41.69 -      /// thus each kind of node iterator converts to this.
   41.70 -      /// More precisely each kind of node iterator should be inherited 
   41.71 -      /// from the trivial node iterator.
   41.72 -      class Node {
   41.73 -      public:
   41.74 -	/// Default constructor
   41.75 -
   41.76 -	/// @warning The default constructor sets the iterator
   41.77 -	/// to an undefined value.
   41.78 -	Node() { }
   41.79 -	/// Copy constructor.
   41.80 -
   41.81 -	/// Copy constructor.
   41.82 -	///
   41.83 -	Node(const Node&) { }
   41.84 -
   41.85 -	/// Invalid constructor \& conversion.
   41.86 -
   41.87 -	/// This constructor initializes the iterator to be invalid.
   41.88 -	/// \sa Invalid for more details.
   41.89 -	Node(Invalid) { }
   41.90 -	/// Equality operator
   41.91 -
   41.92 -	/// Two iterators are equal if and only if they point to the
   41.93 -	/// same object or both are invalid.
   41.94 -	bool operator==(Node) const { return true; }
   41.95 -
   41.96 -	/// Inequality operator
   41.97 -	
   41.98 -	/// \sa operator==(Node n)
   41.99 -	///
  41.100 -	bool operator!=(Node) const { return true; }
  41.101 -
  41.102 - 	///Comparison operator.
  41.103 -
  41.104 -	///This is a strict ordering between the nodes.
  41.105 -	///
  41.106 -	///This ordering can be different from the order in which NodeIt
  41.107 -	///goes through the nodes.
  41.108 -	///\todo Possibly we don't need it.
  41.109 -	bool operator<(Node) const { return true; }
  41.110 -      };
  41.111 -    
  41.112 -      /// This iterator goes through each node.
  41.113 -
  41.114 -      /// This iterator goes through each node.
  41.115 -      /// Its usage is quite simple, for example you can count the number
  41.116 -      /// of nodes in graph \c g of type \c Graph like this:
  41.117 -      /// \code
  41.118 -      /// int count=0;
  41.119 -      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
  41.120 -      /// \endcode
  41.121 -      class NodeIt : public Node {
  41.122 -      public:
  41.123 -	/// Default constructor
  41.124 -
  41.125 -	/// @warning The default constructor sets the iterator
  41.126 -	/// to an undefined value.
  41.127 -	NodeIt() { }
  41.128 -	/// Copy constructor.
  41.129 -	
  41.130 -	/// Copy constructor.
  41.131 -	///
  41.132 -	NodeIt(const NodeIt&) { }
  41.133 -	/// Invalid constructor \& conversion.
  41.134 -
  41.135 -	/// Initialize the iterator to be invalid.
  41.136 -	/// \sa Invalid for more details.
  41.137 -	NodeIt(Invalid) { }
  41.138 -	/// Sets the iterator to the first node.
  41.139 -
  41.140 -	/// Sets the iterator to the first node of \c g.
  41.141 -	///
  41.142 -	NodeIt(const StaticGraph& g) { }
  41.143 -	/// Node -> NodeIt conversion.
  41.144 -
  41.145 -	/// Sets the iterator to the node of \c g pointed by the trivial 
  41.146 -	/// iterator n.
  41.147 -	/// This feature necessitates that each time we 
  41.148 -	/// iterate the edge-set, the iteration order is the same.
  41.149 -	NodeIt(const StaticGraph& g, const Node& n) { }
  41.150 -	/// Next node.
  41.151 -
  41.152 -	/// Assign the iterator to the next node.
  41.153 -	///
  41.154 -	NodeIt& operator++() { return *this; }
  41.155 -      };
  41.156 -    
  41.157 -    
  41.158 -      /// The base type of the edge iterators.
  41.159 -
  41.160 -      /// The base type of the edge iterators.
  41.161 -      ///
  41.162 -      class Edge {
  41.163 -      public:
  41.164 -	/// Default constructor
  41.165 -
  41.166 -	/// @warning The default constructor sets the iterator
  41.167 -	/// to an undefined value.
  41.168 -	Edge() { }
  41.169 -	/// Copy constructor.
  41.170 -
  41.171 -	/// Copy constructor.
  41.172 -	///
  41.173 -	Edge(const Edge&) { }
  41.174 -	/// Initialize the iterator to be invalid.
  41.175 -
  41.176 -	/// Initialize the iterator to be invalid.
  41.177 -	///
  41.178 -	Edge(Invalid) { }
  41.179 -	/// Equality operator
  41.180 -
  41.181 -	/// Two iterators are equal if and only if they point to the
  41.182 -	/// same object or both are invalid.
  41.183 -	bool operator==(Edge) const { return true; }
  41.184 -	/// Inequality operator
  41.185 -
  41.186 -	/// \sa operator==(Node n)
  41.187 -	///
  41.188 -	bool operator!=(Edge) const { return true; }
  41.189 - 	///Comparison operator.
  41.190 -
  41.191 -	///This is a strict ordering between the nodes.
  41.192 -	///
  41.193 -	///This ordering can be different from the order in which NodeIt
  41.194 -	///goes through the nodes.
  41.195 -	///\todo Possibly we don't need it.
  41.196 - 	bool operator<(Edge) const { return true; }
  41.197 -      };
  41.198 -    
  41.199 -      /// This iterator goes trough the outgoing edges of a node.
  41.200 -
  41.201 -      /// This iterator goes trough the \e outgoing edges of a certain node
  41.202 -      /// of a graph.
  41.203 -      /// Its usage is quite simple, for example you can count the number
  41.204 -      /// of outgoing edges of a node \c n
  41.205 -      /// in graph \c g of type \c Graph as follows.
  41.206 -      /// \code
  41.207 -      /// int count=0;
  41.208 -      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  41.209 -      /// \endcode
  41.210 -    
  41.211 -      class OutEdgeIt : public Edge {
  41.212 -      public:
  41.213 -	/// Default constructor
  41.214 -
  41.215 -	/// @warning The default constructor sets the iterator
  41.216 -	/// to an undefined value.
  41.217 -	OutEdgeIt() { }
  41.218 -	/// Copy constructor.
  41.219 -
  41.220 -	/// Copy constructor.
  41.221 -	///
  41.222 -	OutEdgeIt(const OutEdgeIt&) { }
  41.223 -	/// Initialize the iterator to be invalid.
  41.224 -
  41.225 -	/// Initialize the iterator to be invalid.
  41.226 -	///
  41.227 -	OutEdgeIt(Invalid) { }
  41.228 -	/// This constructor sets the iterator to first outgoing edge.
  41.229 -    
  41.230 -	/// This constructor set the iterator to the first outgoing edge of
  41.231 -	/// node
  41.232 -	///@param n the node
  41.233 -	///@param g the graph
  41.234 -	OutEdgeIt(const StaticGraph& g, const Node& n) { }
  41.235 -	/// Edge -> OutEdgeIt conversion
  41.236 -
  41.237 -	/// Sets the iterator to the value of the trivial iterator \c e.
  41.238 -	/// This feature necessitates that each time we 
  41.239 -	/// iterate the edge-set, the iteration order is the same.
  41.240 -	OutEdgeIt(const StaticGraph& g, const Edge& e) { }
  41.241 -	///Next outgoing edge
  41.242 -	
  41.243 -	/// Assign the iterator to the next 
  41.244 -	/// outgoing edge of the corresponding node.
  41.245 -	OutEdgeIt& operator++() { return *this; }
  41.246 -      };
  41.247 -
  41.248 -      /// This iterator goes trough the incoming edges of a node.
  41.249 -
  41.250 -      /// This iterator goes trough the \e incoming edges of a certain node
  41.251 -      /// of a graph.
  41.252 -      /// Its usage is quite simple, for example you can count the number
  41.253 -      /// of outgoing edges of a node \c n
  41.254 -      /// in graph \c g of type \c Graph as follows.
  41.255 -      /// \code
  41.256 -      /// int count=0;
  41.257 -      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  41.258 -      /// \endcode
  41.259 -
  41.260 -      class InEdgeIt : public Edge {
  41.261 -      public:
  41.262 -	/// Default constructor
  41.263 -
  41.264 -	/// @warning The default constructor sets the iterator
  41.265 -	/// to an undefined value.
  41.266 -	InEdgeIt() { }
  41.267 -	/// Copy constructor.
  41.268 -
  41.269 -	/// Copy constructor.
  41.270 -	///
  41.271 -	InEdgeIt(const InEdgeIt&) { }
  41.272 -	/// Initialize the iterator to be invalid.
  41.273 -
  41.274 -	/// Initialize the iterator to be invalid.
  41.275 -	///
  41.276 -	InEdgeIt(Invalid) { }
  41.277 -	/// This constructor sets the iterator to first incoming edge.
  41.278 -    
  41.279 -	/// This constructor set the iterator to the first incoming edge of
  41.280 -	/// node
  41.281 -	///@param n the node
  41.282 -	///@param g the graph
  41.283 -	InEdgeIt(const StaticGraph& g, const Node& n) { }
  41.284 -	/// Edge -> InEdgeIt conversion
  41.285 -
  41.286 -	/// Sets the iterator to the value of the trivial iterator \c e.
  41.287 -	/// This feature necessitates that each time we 
  41.288 -	/// iterate the edge-set, the iteration order is the same.
  41.289 -	InEdgeIt(const StaticGraph& g, const Edge& n) { }
  41.290 -	/// Next incoming edge
  41.291 -
  41.292 -	/// Assign the iterator to the next inedge of the corresponding node.
  41.293 -	///
  41.294 -	InEdgeIt& operator++() { return *this; }
  41.295 -      };
  41.296 -      /// This iterator goes through each edge.
  41.297 -
  41.298 -      /// This iterator goes through each edge of a graph.
  41.299 -      /// Its usage is quite simple, for example you can count the number
  41.300 -      /// of edges in a graph \c g of type \c Graph as follows:
  41.301 -      /// \code
  41.302 -      /// int count=0;
  41.303 -      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
  41.304 -      /// \endcode
  41.305 -      class EdgeIt : public Edge {
  41.306 -      public:
  41.307 -	/// Default constructor
  41.308 -
  41.309 -	/// @warning The default constructor sets the iterator
  41.310 -	/// to an undefined value.
  41.311 -	EdgeIt() { }
  41.312 -	/// Copy constructor.
  41.313 -
  41.314 -	/// Copy constructor.
  41.315 -	///
  41.316 -	EdgeIt(const EdgeIt&) { }
  41.317 -	/// Initialize the iterator to be invalid.
  41.318 -
  41.319 -	/// Initialize the iterator to be invalid.
  41.320 -	///
  41.321 -	EdgeIt(Invalid) { }
  41.322 -	/// This constructor sets the iterator to first edge.
  41.323 -    
  41.324 -	/// This constructor set the iterator to the first edge of
  41.325 -	/// node
  41.326 -	///@param g the graph
  41.327 -	EdgeIt(const StaticGraph& g) { }
  41.328 -	/// Edge -> EdgeIt conversion
  41.329 -
  41.330 -	/// Sets the iterator to the value of the trivial iterator \c e.
  41.331 -	/// This feature necessitates that each time we 
  41.332 -	/// iterate the edge-set, the iteration order is the same.
  41.333 -	EdgeIt(const StaticGraph&, const Edge&) { } 
  41.334 -    	///Next edge
  41.335 -	
  41.336 -	/// Assign the iterator to the next 
  41.337 -	/// edge of the corresponding node.
  41.338 -	EdgeIt& operator++() { return *this; }
  41.339 -      };
  41.340 -
  41.341 -      /// First node of the graph.
  41.342 -
  41.343 -      /// \retval i the first node.
  41.344 -      /// \return the first node.
  41.345 -      ///
  41.346 -      NodeIt& first(NodeIt& i) const { return i; }
  41.347 -
  41.348 -      /// The first incoming edge.
  41.349 -
  41.350 -      /// The first incoming edge.
  41.351 -      ///
  41.352 -      InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
  41.353 -      /// The first outgoing edge.
  41.354 -
  41.355 -      /// The first outgoing edge.
  41.356 -      ///
  41.357 -      OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
  41.358 -      /// The first edge of the Graph.
  41.359 -
  41.360 -      /// The first edge of the Graph.
  41.361 -      ///
  41.362 -      EdgeIt& first(EdgeIt& i) const { return i; }
  41.363 -
  41.364 -      ///Gives back the head node of an edge.
  41.365 -
  41.366 -      ///Gives back the head node of an edge.
  41.367 -      ///
  41.368 -      Node head(Edge) const { return INVALID; }
  41.369 -      ///Gives back the tail node of an edge.
  41.370 -
  41.371 -      ///Gives back the tail node of an edge.
  41.372 -      ///
  41.373 -      Node tail(Edge) const { return INVALID; }
  41.374 -  
  41.375 -      ///Gives back the \e id of a node.
  41.376 -
  41.377 -      ///\warning Not all graph structures provide this feature.
  41.378 -      ///
  41.379 -      ///\todo Should each graph provide \c id?
  41.380 -      int id(const Node&) const { return 0; }
  41.381 -      ///Gives back the \e id of an edge.
  41.382 -
  41.383 -      ///\warning Not all graph structures provide this feature.
  41.384 -      ///
  41.385 -      ///\todo Should each graph provide \c id?
  41.386 -      int id(const Edge&) const { return 0; }
  41.387 -
  41.388 -      ///\e
  41.389 -      
  41.390 -      ///\todo Should it be in the concept?
  41.391 -      ///
  41.392 -      int nodeNum() const { return 0; }
  41.393 -      ///\e
  41.394 -
  41.395 -      ///\todo Should it be in the concept?
  41.396 -      ///
  41.397 -      int edgeNum() const { return 0; }
  41.398 -
  41.399 -
  41.400 -      ///Reference map of the nodes to type \c T.
  41.401 -
  41.402 -      /// \ingroup skeletons
  41.403 -      ///Reference map of the nodes to type \c T.
  41.404 -      /// \sa Reference
  41.405 -      /// \warning Making maps that can handle bool type (NodeMap<bool>)
  41.406 -      /// needs some extra attention!
  41.407 -      template<class T> class NodeMap : public ReferenceMap< Node, T >
  41.408 -      {
  41.409 -      public:
  41.410 -
  41.411 -	///\e
  41.412 -	NodeMap(const StaticGraph&) { }
  41.413 -	///\e
  41.414 -	NodeMap(const StaticGraph&, T) { }
  41.415 -
  41.416 -	///Copy constructor
  41.417 -	template<typename TT> NodeMap(const NodeMap<TT>&) { }
  41.418 -	///Assignment operator
  41.419 -	template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
  41.420 -	{ return *this; }
  41.421 -      };
  41.422 -
  41.423 -      ///Reference map of the edges to type \c T.
  41.424 -
  41.425 -      /// \ingroup skeletons
  41.426 -      ///Reference map of the edges to type \c T.
  41.427 -      /// \sa Reference
  41.428 -      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
  41.429 -      /// needs some extra attention!
  41.430 -      template<class T> class EdgeMap
  41.431 -	: public ReferenceMap<Edge,T>
  41.432 -      {
  41.433 -      public:
  41.434 -
  41.435 -	///\e
  41.436 -	EdgeMap(const StaticGraph&) { }
  41.437 -	///\e
  41.438 -	EdgeMap(const StaticGraph&, T) { }
  41.439 -    
  41.440 -	///Copy constructor
  41.441 -	template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
  41.442 -	///Assignment operator
  41.443 -	template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
  41.444 -	{ return *this; }
  41.445 -      };
  41.446 -    };
  41.447 -
  41.448 -
  41.449 -  
  41.450 -    /// An empty non-static graph class.
  41.451 -
  41.452 -    /// This class provides everything that \ref StaticGraph
  41.453 -    /// with additional functionality which enables to build a
  41.454 -    /// graph from scratch.
  41.455 -    class ExtendableGraph : public StaticGraph
  41.456 -    {
  41.457 -    public:
  41.458 -      /// Defalult constructor.
  41.459 -
  41.460 -      /// Defalult constructor.
  41.461 -      ///
  41.462 -      ExtendableGraph() { }
  41.463 -      ///Add a new node to the graph.
  41.464 -
  41.465 -      /// \return the new node.
  41.466 -      ///
  41.467 -      Node addNode() { return INVALID; }
  41.468 -      ///Add a new edge to the graph.
  41.469 -
  41.470 -      ///Add a new edge to the graph with tail node \c t
  41.471 -      ///and head node \c h.
  41.472 -      ///\return the new edge.
  41.473 -      Edge addEdge(Node h, Node t) { return INVALID; }
  41.474 -    
  41.475 -      /// Resets the graph.
  41.476 -
  41.477 -      /// This function deletes all edges and nodes of the graph.
  41.478 -      /// It also frees the memory allocated to store them.
  41.479 -      /// \todo It might belong to \ref ErasableGraph.
  41.480 -      void clear() { }
  41.481 -    };
  41.482 -
  41.483 -    /// An empty erasable graph class.
  41.484 -  
  41.485 -    /// This class is an extension of \ref ExtendableGraph. It also makes it
  41.486 -    /// possible to erase edges or nodes.
  41.487 -    class ErasableGraph : public ExtendableGraph
  41.488 -    {
  41.489 -    public:
  41.490 -      /// Defalult constructor.
  41.491 -
  41.492 -      /// Defalult constructor.
  41.493 -      ///
  41.494 -      ErasableGraph() { }
  41.495 -      /// Deletes a node.
  41.496 -
  41.497 -      /// Deletes node \c n node.
  41.498 -      ///
  41.499 -      void erase(Node n) { }
  41.500 -      /// Deletes an edge.
  41.501 -
  41.502 -      /// Deletes edge \c e edge.
  41.503 -      ///
  41.504 -      void erase(Edge e) { }
  41.505 -    };
  41.506 -
  41.507 -    // @}
  41.508 -  } //namespace skeleton  
  41.509 -} //namespace hugo
  41.510 -
  41.511 -
  41.512 -
  41.513 -#endif // HUGO_SKELETON_GRAPH_H
    42.1 --- a/src/hugo/skeletons/maps.h	Wed Sep 29 14:12:26 2004 +0000
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,120 +0,0 @@
    42.4 -/* -*- C++ -*-
    42.5 - * src/hugo/skeletons/maps.h - Part of HUGOlib, a generic C++ optimization library
    42.6 - *
    42.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    42.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    42.9 - *
   42.10 - * Permission to use, modify and distribute this software is granted
   42.11 - * provided that this copyright notice appears in all copies. For
   42.12 - * precise terms see the accompanying LICENSE file.
   42.13 - *
   42.14 - * This software is provided "AS IS" with no warranty of any kind,
   42.15 - * express or implied, and with no claim as to its suitability for any
   42.16 - * purpose.
   42.17 - *
   42.18 - */
   42.19 -
   42.20 -#ifndef HUGO_MAPSKELETON_H
   42.21 -#define HUGO_MAPSKELETON_H
   42.22 -
   42.23 -///\ingroup skeletons
   42.24 -///\file
   42.25 -///\brief Map concepts checking classes for testing and documenting.
   42.26 -
   42.27 -namespace hugo {
   42.28 -
   42.29 -  namespace skeleton {
   42.30 -  
   42.31 -    /// \addtogroup skeletons
   42.32 -    /// @{
   42.33 -
   42.34 -    /// Readable map concept
   42.35 -    template<typename K, typename T>
   42.36 -    class ReadMap
   42.37 -    {
   42.38 -    public:
   42.39 -      /// Map's key type.
   42.40 -      typedef K KeyType;    
   42.41 -      /// Map's value type. (The type of objects associated with the keys).
   42.42 -      typedef T ValueType;
   42.43 -
   42.44 -      /// Returns the value associated with a key.
   42.45 -      ValueType operator[](const KeyType &k) const {return ValueType();}
   42.46 -
   42.47 -      ///Default constructor
   42.48 -      ReadMap() {}
   42.49 -    };
   42.50 -
   42.51 -
   42.52 -    /// Writable map concept
   42.53 -    template<typename K, typename T>
   42.54 -    class WriteMap
   42.55 -    {
   42.56 -    public:
   42.57 -      /// Map's key type.
   42.58 -      typedef K KeyType;    
   42.59 -      /// Map's value type. (The type of objects associated with the keys).
   42.60 -      typedef T ValueType;
   42.61 -
   42.62 -      /// Sets the value associated with a key.
   42.63 -      void set(const KeyType &k,const ValueType &t) {}
   42.64 -
   42.65 -      ///Default constructor
   42.66 -      WriteMap() {}
   42.67 -    };
   42.68 -
   42.69 -    ///Read/Writable map concept
   42.70 -    template<typename K, typename T>
   42.71 -    class ReadWriteMap : public ReadMap<K,T>,
   42.72 -			    public WriteMap<K,T>
   42.73 -    {
   42.74 -    public:
   42.75 -      /// Map's key type.
   42.76 -      typedef K KeyType;    
   42.77 -      /// Map's value type. (The type of objects associated with the keys).
   42.78 -      typedef T ValueType;
   42.79 -
   42.80 -      /// Returns the value associated with a key.
   42.81 -      ValueType operator[](const KeyType &k) const {return ValueType();}
   42.82 -      /// Sets the value associated with a key.
   42.83 -      void set(const KeyType &k,const ValueType &t) {}
   42.84 -
   42.85 -      ///Default constructor
   42.86 -      ReadWriteMap() {}
   42.87 -    };
   42.88 -  
   42.89 -  
   42.90 -    ///Dereferable map concept
   42.91 -    template<typename K, typename T>
   42.92 -    class ReferenceMap : public ReadWriteMap<K,T>
   42.93 -    {
   42.94 -    public:
   42.95 -      /// Map's key type.
   42.96 -      typedef K KeyType;    
   42.97 -      /// Map's value type. (The type of objects associated with the keys).
   42.98 -      typedef T ValueType;
   42.99 -
  42.100 -    protected:
  42.101 -      ValueType tmp;
  42.102 -    public:
  42.103 -      typedef ValueType& ReferenceType;
  42.104 -      /// Map's const reference type.
  42.105 -      typedef const ValueType& ConstReferenceType;
  42.106 -
  42.107 -      ///Returns a reference to the value associated to a key.
  42.108 -      ReferenceType operator[](const KeyType &i) { return tmp; }
  42.109 -      ///Returns a const reference to the value associated to a key.
  42.110 -      ConstReferenceType operator[](const KeyType &i) const
  42.111 -      { return tmp; }
  42.112 -      /// Sets the value associated with a key.
  42.113 -      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
  42.114 -
  42.115 -      ///Default constructor
  42.116 -      ReferenceMap() {}
  42.117 -    };
  42.118 -
  42.119 -    // @}
  42.120 -
  42.121 -  } //namespace skeleton
  42.122 -} //namespace hugo
  42.123 -#endif // HUGO_MAPSKELETON_H
    43.1 --- a/src/hugo/skeletons/path.h	Wed Sep 29 14:12:26 2004 +0000
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,236 +0,0 @@
    43.4 -/* -*- C++ -*-
    43.5 - * src/hugo/skeletons/path.h - Part of HUGOlib, a generic C++ optimization library
    43.6 - *
    43.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    43.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    43.9 - *
   43.10 - * Permission to use, modify and distribute this software is granted
   43.11 - * provided that this copyright notice appears in all copies. For
   43.12 - * precise terms see the accompanying LICENSE file.
   43.13 - *
   43.14 - * This software is provided "AS IS" with no warranty of any kind,
   43.15 - * express or implied, and with no claim as to its suitability for any
   43.16 - * purpose.
   43.17 - *
   43.18 - */
   43.19 -
   43.20 -///\ingroup skeletons
   43.21 -///\file
   43.22 -///\brief Classes for representing paths in graphs.
   43.23 -
   43.24 -#ifndef HUGO_SKELETON_PATH_H
   43.25 -#define HUGO_SKELETON_PATH_H
   43.26 -
   43.27 -#include <hugo/invalid.h>
   43.28 -
   43.29 -namespace hugo {
   43.30 -  namespace skeleton {
   43.31 -    /// \addtogroup skeletons
   43.32 -    /// @{
   43.33 -
   43.34 -
   43.35 -    //! \brief A skeletom structure for representing directed paths in a graph.
   43.36 -    //!
   43.37 -    //! A skeleton structure for representing directed paths in a graph.
   43.38 -    //! \param GR The graph type in which the path is.
   43.39 -    //!
   43.40 -    //! In a sense, the path can be treated as a graph, for is has \c NodeIt
   43.41 -    //! and \c EdgeIt with the same usage. These types converts to the \c Node
   43.42 -    //! and \c Edge of the original graph.
   43.43 -    template<typename GR>
   43.44 -    class Path {
   43.45 -    public:
   43.46 -
   43.47 -      /// Type of the underlying graph.
   43.48 -      typedef /*typename*/ GR Graph;
   43.49 -      /// Edge type of the underlying graph.
   43.50 -      typedef typename Graph::Edge GraphEdge;
   43.51 -      /// Node type of the underlying graph.
   43.52 -     typedef typename Graph::Node GraphNode;
   43.53 -      class NodeIt;
   43.54 -      class EdgeIt;
   43.55 -
   43.56 -      /// \param _G The graph in which the path is.
   43.57 -      ///
   43.58 -      Path(const Graph &_G) {}
   43.59 -
   43.60 -      /// Length of the path.
   43.61 -      size_t length() const {return 0;}
   43.62 -      /// Returns whether the path is empty.
   43.63 -      bool empty() const { return true;}
   43.64 -
   43.65 -      /// Resets the path to an empty path.
   43.66 -      void clear() {}
   43.67 -
   43.68 -      /// \brief Starting point of the path.
   43.69 -      ///
   43.70 -      /// Starting point of the path.
   43.71 -      /// Returns INVALID if the path is empty.
   43.72 -      GraphNode/*It*/ head() const {return INVALID;}
   43.73 -      /// \brief End point of the path.
   43.74 -      ///
   43.75 -      /// End point of the path.
   43.76 -      /// Returns INVALID if the path is empty.
   43.77 -      GraphNode/*It*/ tail() const {return INVALID;}
   43.78 -
   43.79 -      /// \brief First NodeIt/EdgeIt.
   43.80 -      ///
   43.81 -      /// Initializes node or edge iterator to point to the first
   43.82 -      /// node or edge.
   43.83 -      template<typename It>
   43.84 -      It& first(It &i) const { return i=It(*this); }
   43.85 -
   43.86 -      /// \brief The head of an edge.
   43.87 -      ///
   43.88 -      /// Returns node iterator pointing to the head node of the
   43.89 -      /// given edge iterator.
   43.90 -      NodeIt head(const EdgeIt& e) const {return INVALID;}
   43.91 -
   43.92 -      /// \brief The tail of an edge.
   43.93 -      ///
   43.94 -      /// Returns node iterator pointing to the tail node of the
   43.95 -      /// given edge iterator.
   43.96 -      NodeIt tail(const EdgeIt& e) const {return INVALID;}
   43.97 -
   43.98 -
   43.99 -      /* Iterator classes */
  43.100 -
  43.101 -      /**
  43.102 -       * \brief Iterator class to iterate on the edges of the paths
  43.103 -       *
  43.104 -       * \ingroup skeletons
  43.105 -       * This class is used to iterate on the edges of the paths
  43.106 -       *
  43.107 -       * Of course it converts to Graph::Edge
  43.108 -       *
  43.109 -       */
  43.110 -      class EdgeIt {
  43.111 -      public:
  43.112 -	/// Default constructor
  43.113 -	EdgeIt() {}
  43.114 -	/// Invalid constructor
  43.115 -	EdgeIt(Invalid) {}
  43.116 -	/// Constructor with starting point
  43.117 -	EdgeIt(const Path &_p) {}
  43.118 -
  43.119 -	operator GraphEdge () const {}
  43.120 -
  43.121 -	/// Next edge
  43.122 -	EdgeIt& operator++() {return *this;}
  43.123 -
  43.124 -	/// Comparison operator
  43.125 -	bool operator==(const EdgeIt& e) const {return true;}
  43.126 -	/// Comparison operator
  43.127 -	bool operator!=(const EdgeIt& e) const {return true;}
  43.128 -// 	/// Comparison operator
  43.129 -//      /// \todo It is not clear what is the "natural" ordering.
  43.130 -// 	bool operator<(const EdgeIt& e) const {}
  43.131 -
  43.132 -      };
  43.133 -
  43.134 -      /**
  43.135 -       * \brief Iterator class to iterate on the nodes of the paths
  43.136 -       *
  43.137 -       * \ingroup skeletons
  43.138 -       * This class is used to iterate on the nodes of the paths
  43.139 -       *
  43.140 -       * Of course it converts to Graph::Node.
  43.141 -       *
  43.142 -       */
  43.143 -      class NodeIt {
  43.144 -      public:
  43.145 -	/// Default constructor
  43.146 -	NodeIt() {}
  43.147 -	/// Invalid constructor
  43.148 -	NodeIt(Invalid) {}
  43.149 -	/// Constructor with starting point
  43.150 -	NodeIt(const Path &_p) {}
  43.151 -
  43.152 -	///Conversion to Graph::Node
  43.153 -	operator const GraphNode& () const {}
  43.154 -	/// Next node
  43.155 -	NodeIt& operator++() {return *this;}
  43.156 -
  43.157 -	/// Comparison operator
  43.158 -	bool operator==(const NodeIt& e) const {return true;}
  43.159 -	/// Comparison operator
  43.160 -	bool operator!=(const NodeIt& e) const {return true;}
  43.161 -// 	/// Comparison operator
  43.162 -//      /// \todo It is not clear what is the "natural" ordering.
  43.163 -// 	bool operator<(const NodeIt& e) const {}
  43.164 -
  43.165 -      };
  43.166 -
  43.167 -      friend class Builder;
  43.168 -
  43.169 -      /**
  43.170 -       * \brief Class to build paths
  43.171 -       *
  43.172 -       * \ingroup skeletons
  43.173 -       * This class is used to fill a path with edges.
  43.174 -       *
  43.175 -       * You can push new edges to the front and to the back of the path in
  43.176 -       * arbitrary order then you should commit these changes to the graph.
  43.177 -       *
  43.178 -       * While the builder is active (after the first modifying
  43.179 -       * operation and until the call of \ref commit())
  43.180 -       * the underlining Path is in a
  43.181 -       * "transitional" state (operations on it have undefined result).
  43.182 -       */
  43.183 -      class Builder {
  43.184 -      public:
  43.185 -
  43.186 -        Path &P;
  43.187 -
  43.188 -	///\param _P the path you want to fill in.
  43.189 -	///
  43.190 -	Builder(Path &_P) : P(_P) {}
  43.191 -
  43.192 -	/// Sets the starting node of the path.
  43.193 -
  43.194 -	/// Sets the starting node of the path. Edge added to the path
  43.195 -	/// afterwards have to be incident to this node.
  43.196 -	/// You \em must start building an empry path with this functions.
  43.197 -	/// (And you \em must \em not use it later).
  43.198 -	/// \sa pushFront()
  43.199 -	/// \sa pushBack()
  43.200 -	void setStartNode(const GraphNode &) {}
  43.201 -
  43.202 -	///Push a new edge to the front of the path
  43.203 -
  43.204 -	///Push a new edge to the front of the path.
  43.205 -	///If the path is empty, you \em must call \ref setStartNode() before
  43.206 -	///the first use of \ref pushFront().
  43.207 -	void pushFront(const GraphEdge& e) {}
  43.208 -
  43.209 -	///Push a new edge to the back of the path
  43.210 -
  43.211 -	///Push a new edge to the back of the path.
  43.212 -	///If the path is empty, you \em must call \ref setStartNode() before
  43.213 -	///the first use of \ref pushBack().
  43.214 -	void pushBack(const GraphEdge& e) {}
  43.215 -
  43.216 -	///Commit the changes to the path.
  43.217 -	void commit() {}
  43.218 -
  43.219 -	///Reserve (front) storage for the builder in advance.
  43.220 -
  43.221 -	///If you know an reasonable upper bound of the number of the edges
  43.222 -	///to add to the front of the path,
  43.223 -	///using this function you may speed up the building.
  43.224 -	void reserveFront(size_t r) {}
  43.225 -	///Reserve (back) storage for the builder in advance.
  43.226 -
  43.227 -	///If you know an reasonable upper bound of the number of the edges
  43.228 -	///to add to the back of the path,
  43.229 -	///using this function you may speed up the building.
  43.230 -	void reserveBack(size_t r) {}
  43.231 -      };
  43.232 -    };
  43.233 -
  43.234 -  ///@}
  43.235 -  }
  43.236 -
  43.237 -} // namespace hugo
  43.238 -
  43.239 -#endif // HUGO_SKELETON_PATH_H
    44.1 --- a/src/hugo/smart_graph.h	Wed Sep 29 14:12:26 2004 +0000
    44.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.3 @@ -1,364 +0,0 @@
    44.4 -/* -*- C++ -*-
    44.5 - * src/hugo/smart_graph.h - Part of HUGOlib, a generic C++ optimization library
    44.6 - *
    44.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    44.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    44.9 - *
   44.10 - * Permission to use, modify and distribute this software is granted
   44.11 - * provided that this copyright notice appears in all copies. For
   44.12 - * precise terms see the accompanying LICENSE file.
   44.13 - *
   44.14 - * This software is provided "AS IS" with no warranty of any kind,
   44.15 - * express or implied, and with no claim as to its suitability for any
   44.16 - * purpose.
   44.17 - *
   44.18 - */
   44.19 -
   44.20 -#ifndef HUGO_SMART_GRAPH_H
   44.21 -#define HUGO_SMART_GRAPH_H
   44.22 -
   44.23 -///\ingroup graphs
   44.24 -///\file
   44.25 -///\brief SmartGraph and SymSmartGraph classes.
   44.26 -
   44.27 -#include <vector>
   44.28 -#include <climits>
   44.29 -
   44.30 -#include <hugo/invalid.h>
   44.31 -
   44.32 -#include <hugo/array_map.h>
   44.33 -#include <hugo/sym_map.h>
   44.34 -
   44.35 -#include <hugo/map_registry.h>
   44.36 -
   44.37 -#include <hugo/map_defines.h>
   44.38 -
   44.39 -namespace hugo {
   44.40 -
   44.41 -/// \addtogroup graphs
   44.42 -/// @{
   44.43 -//  class SymSmartGraph;
   44.44 -
   44.45 -  ///A smart graph class.
   44.46 -
   44.47 -  ///This is a simple and fast graph implementation.
   44.48 -  ///It is also quite memory efficient, but at the price
   44.49 -  ///that <b> it does not support node and edge deletion</b>.
   44.50 -  ///It conforms to 
   44.51 -  ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept.
   44.52 -  ///\sa skeleton::ExtendableGraph.
   44.53 -  ///
   44.54 -  ///\todo Some member functions could be \c static.
   44.55 -  ///
   44.56 -  ///\todo A possibly useful functionality: a function saveState() would
   44.57 -  ///give back a data sturcture X and then the function restoreState(X)
   44.58 -  ///would remove the nodes and edges added after the call of saveState().
   44.59 -  ///Of course it should be used as a stack. (Maybe X is not necessary.)
   44.60 -  ///
   44.61 -  ///\author Alpar Juttner
   44.62 -  class SmartGraph {
   44.63 -
   44.64 -    struct NodeT 
   44.65 -    {
   44.66 -      int first_in,first_out;      
   44.67 -      NodeT() : first_in(-1), first_out(-1) {}
   44.68 -    };
   44.69 -    struct EdgeT 
   44.70 -    {
   44.71 -      int head, tail, next_in, next_out;      
   44.72 -      //FIXME: is this necessary?
   44.73 -      EdgeT() : next_in(-1), next_out(-1) {}  
   44.74 -    };
   44.75 -
   44.76 -    std::vector<NodeT> nodes;
   44.77 -
   44.78 -    std::vector<EdgeT> edges;
   44.79 -    
   44.80 -    
   44.81 -  public:
   44.82 -
   44.83 -    typedef SmartGraph Graph;
   44.84 -
   44.85 -    class Node;
   44.86 -    class Edge;
   44.87 -
   44.88 -    class NodeIt;
   44.89 -    class EdgeIt;
   44.90 -    class OutEdgeIt;
   44.91 -    class InEdgeIt;
   44.92 -    
   44.93 -    // Create map registries.
   44.94 -    CREATE_MAP_REGISTRIES;
   44.95 -    // Create node and edge maps.
   44.96 -    CREATE_MAPS(ArrayMap);
   44.97 -    
   44.98 -  public:
   44.99 -
  44.100 -    SmartGraph() : nodes(), edges() { }
  44.101 -    SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
  44.102 -    
  44.103 -    ///Number of nodes.
  44.104 -    int nodeNum() const { return nodes.size(); }
  44.105 -    ///Number of edges.
  44.106 -    int edgeNum() const { return edges.size(); }
  44.107 -
  44.108 -    /// Maximum node ID.
  44.109 -    
  44.110 -    /// Maximum node ID.
  44.111 -    ///\sa id(Node)
  44.112 -    int maxNodeId() const { return nodes.size()-1; }
  44.113 -    /// Maximum edge ID.
  44.114 -    
  44.115 -    /// Maximum edge ID.
  44.116 -    ///\sa id(Edge)
  44.117 -    int maxEdgeId() const { return edges.size()-1; }
  44.118 -
  44.119 -    Node tail(Edge e) const { return edges[e.n].tail; }
  44.120 -    Node head(Edge e) const { return edges[e.n].head; }
  44.121 -
  44.122 -    NodeIt& first(NodeIt& v) const { 
  44.123 -      v=NodeIt(*this); return v; }
  44.124 -    EdgeIt& first(EdgeIt& e) const { 
  44.125 -      e=EdgeIt(*this); return e; }
  44.126 -    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  44.127 -      e=OutEdgeIt(*this,v); return e; }
  44.128 -    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  44.129 -      e=InEdgeIt(*this,v); return e; }
  44.130 -
  44.131 -    /// Node ID.
  44.132 -    
  44.133 -    /// The ID of a valid Node is a nonnegative integer not greater than
  44.134 -    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  44.135 -    /// and the greatest node ID can be actually less then \ref maxNodeId().
  44.136 -    ///
  44.137 -    /// The ID of the \ref INVALID node is -1.
  44.138 -    ///\return The ID of the node \c v. 
  44.139 -    static int id(Node v) { return v.n; }
  44.140 -    /// Edge ID.
  44.141 -    
  44.142 -    /// The ID of a valid Edge is a nonnegative integer not greater than
  44.143 -    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  44.144 -    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  44.145 -    ///
  44.146 -    /// The ID of the \ref INVALID edge is -1.
  44.147 -    ///\return The ID of the edge \c e. 
  44.148 -    static int id(Edge e) { return e.n; }
  44.149 -
  44.150 -    Node addNode() {
  44.151 -      Node n; n.n=nodes.size();
  44.152 -      nodes.push_back(NodeT()); //FIXME: Hmmm...
  44.153 -
  44.154 -      
  44.155 -      node_maps.add(n);
  44.156 -      return n;
  44.157 -    }
  44.158 -    
  44.159 -    Edge addEdge(Node u, Node v) {
  44.160 -      Edge e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm...
  44.161 -      edges[e.n].tail=u.n; edges[e.n].head=v.n;
  44.162 -      edges[e.n].next_out=nodes[u.n].first_out;
  44.163 -      edges[e.n].next_in=nodes[v.n].first_in;
  44.164 -      nodes[u.n].first_out=nodes[v.n].first_in=e.n;
  44.165 -
  44.166 -      edge_maps.add(e);
  44.167 -
  44.168 -      return e;
  44.169 -    }
  44.170 -
  44.171 -    /// Finds an edge between two nodes.
  44.172 -
  44.173 -    /// Finds an edge from node \c u to node \c v.
  44.174 -    ///
  44.175 -    /// If \c prev is \ref INVALID (this is the default value), then
  44.176 -    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  44.177 -    /// the next edge from \c u to \c v after \c prev.
  44.178 -    /// \return The found edge or INVALID if there is no such an edge.
  44.179 -    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  44.180 -    {
  44.181 -      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
  44.182 -      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
  44.183 -      prev.n=e;
  44.184 -      return prev;
  44.185 -    }
  44.186 -    
  44.187 -    void clear() {
  44.188 -      edge_maps.clear();
  44.189 -      edges.clear();
  44.190 -      node_maps.clear();
  44.191 -      nodes.clear();
  44.192 -    }
  44.193 -
  44.194 -    class Node {
  44.195 -      friend class SmartGraph;
  44.196 -      template <typename T> friend class NodeMap;
  44.197 -      
  44.198 -      friend class Edge;
  44.199 -      friend class OutEdgeIt;
  44.200 -      friend class InEdgeIt;
  44.201 -      friend class SymEdge;
  44.202 -
  44.203 -    protected:
  44.204 -      int n;
  44.205 -      friend int SmartGraph::id(Node v); 
  44.206 -      Node(int nn) {n=nn;}
  44.207 -    public:
  44.208 -      Node() {}
  44.209 -      Node (Invalid) { n=-1; }
  44.210 -      bool operator==(const Node i) const {return n==i.n;}
  44.211 -      bool operator!=(const Node i) const {return n!=i.n;}
  44.212 -      bool operator<(const Node i) const {return n<i.n;}
  44.213 -      //      ///Validity check
  44.214 -      //      operator bool() { return n!=-1; }
  44.215 -    };
  44.216 -    
  44.217 -    class NodeIt : public Node {
  44.218 -      const SmartGraph *G;
  44.219 -      friend class SmartGraph;
  44.220 -    public:
  44.221 -      NodeIt() : Node() { }
  44.222 -      NodeIt(const SmartGraph& _G,Node n) : Node(n), G(&_G) { }
  44.223 -      NodeIt(Invalid i) : Node(i) { }
  44.224 -      NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { }
  44.225 -      NodeIt &operator++() {
  44.226 -	n=(n+2)%(G->nodes.size()+1)-1; 
  44.227 -	return *this; 
  44.228 -      }
  44.229 -//       ///Validity check
  44.230 -//       operator bool() { return Node::operator bool(); }      
  44.231 -    };
  44.232 -
  44.233 -    class Edge {
  44.234 -      friend class SmartGraph;
  44.235 -      template <typename T> friend class EdgeMap;
  44.236 -
  44.237 -      friend class SymSmartGraph;
  44.238 -      
  44.239 -      friend class Node;
  44.240 -      friend class NodeIt;
  44.241 -    protected:
  44.242 -      int n;
  44.243 -      friend int SmartGraph::id(Edge e);
  44.244 -      Edge(int nn) {n=nn;}
  44.245 -    public:
  44.246 -      /// An Edge with id \c n.
  44.247 -
  44.248 -      Edge() { }
  44.249 -      Edge (Invalid) { n=-1; }
  44.250 -      bool operator==(const Edge i) const {return n==i.n;}
  44.251 -      bool operator!=(const Edge i) const {return n!=i.n;}
  44.252 -      bool operator<(const Edge i) const {return n<i.n;}
  44.253 -//       ///Validity check
  44.254 -//       operator bool() { return n!=-1; }
  44.255 -
  44.256 -      ///Set the edge to that have ID \c ID.
  44.257 -      void setToId(int id) { n=id; }
  44.258 -   };
  44.259 -    
  44.260 -    class EdgeIt : public Edge {
  44.261 -      const SmartGraph *G;
  44.262 -      friend class SmartGraph;
  44.263 -    public:
  44.264 -      EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { }
  44.265 -      EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  44.266 -      EdgeIt (Invalid i) : Edge(i) { }
  44.267 -      EdgeIt() : Edge() { }
  44.268 -      EdgeIt &operator++() { --n; return *this; }
  44.269 -//       ///Validity check
  44.270 -//       operator bool() { return Edge::operator bool(); }      
  44.271 -    };
  44.272 -    
  44.273 -    class OutEdgeIt : public Edge {
  44.274 -      const SmartGraph *G;
  44.275 -      friend class SmartGraph;
  44.276 -    public: 
  44.277 -      OutEdgeIt() : Edge() { }
  44.278 -      OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  44.279 -      OutEdgeIt (Invalid i) : Edge(i) { }
  44.280 -
  44.281 -      OutEdgeIt(const SmartGraph& _G,const Node v)
  44.282 -	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  44.283 -      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  44.284 -//       ///Validity check
  44.285 -//       operator bool() { return Edge::operator bool(); }      
  44.286 -    };
  44.287 -    
  44.288 -    class InEdgeIt : public Edge {
  44.289 -      const SmartGraph *G;
  44.290 -      friend class SmartGraph;
  44.291 -    public: 
  44.292 -      InEdgeIt() : Edge() { }
  44.293 -      InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  44.294 -      InEdgeIt (Invalid i) : Edge(i) { }
  44.295 -      InEdgeIt(const SmartGraph& _G,Node v)
  44.296 -	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  44.297 -      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  44.298 -//       ///Validity check
  44.299 -//       operator bool() { return Edge::operator bool(); }      
  44.300 -    };
  44.301 -
  44.302 -  };
  44.303 -
  44.304 -  ///Graph for bidirectional edges.
  44.305 -
  44.306 -  ///The purpose of this graph structure is to handle graphs
  44.307 -  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  44.308 -  ///of oppositely directed edges.
  44.309 -  ///There is a new edge map type called
  44.310 -  ///\ref SymSmartGraph::SymEdgeMap "SymEdgeMap"
  44.311 -  ///that complements this
  44.312 -  ///feature by
  44.313 -  ///storing shared values for the edge pairs. The usual
  44.314 -  ///\ref Graph::EdgeMap "EdgeMap"
  44.315 -  ///can be used
  44.316 -  ///as well.
  44.317 -  ///
  44.318 -  ///The oppositely directed edge can also be obtained easily
  44.319 -  ///using \ref opposite.
  44.320 -  ///\warning It shares the similarity with \ref SmartGraph that
  44.321 -  ///it is not possible to delete edges or nodes from the graph.
  44.322 -  //\sa SmartGraph.
  44.323 -
  44.324 -  class SymSmartGraph : public SmartGraph
  44.325 -  {
  44.326 -  public:
  44.327 -    typedef SymSmartGraph Graph;
  44.328 -
  44.329 -    // Create symmetric map registry.
  44.330 -    CREATE_SYM_EDGE_MAP_REGISTRY;
  44.331 -    // Create symmetric edge map.
  44.332 -    CREATE_SYM_EDGE_MAP(ArrayMap);
  44.333 -
  44.334 -
  44.335 -    SymSmartGraph() : SmartGraph() { }
  44.336 -    SymSmartGraph(const SmartGraph &_g) : SmartGraph(_g) { }
  44.337 -    ///Adds a pair of oppositely directed edges to the graph.
  44.338 -    Edge addEdge(Node u, Node v)
  44.339 -    {
  44.340 -      Edge e = SmartGraph::addEdge(u,v);
  44.341 -      Edge f = SmartGraph::addEdge(v,u);
  44.342 -      sym_edge_maps.add(e);
  44.343 -      sym_edge_maps.add(f);
  44.344 -      return e;
  44.345 -    }
  44.346 -
  44.347 -    ///The oppositely directed edge.
  44.348 -
  44.349 -    ///Returns the oppositely directed
  44.350 -    ///pair of the edge \c e.
  44.351 -    static Edge opposite(Edge e)
  44.352 -    {
  44.353 -      Edge f;
  44.354 -      f.n = e.n - 2*(e.n%2) + 1;
  44.355 -      return f;
  44.356 -    }
  44.357 -    
  44.358 -
  44.359 -  };
  44.360 -  
  44.361 -  /// @}  
  44.362 -} //namespace hugo
  44.363 -
  44.364 -
  44.365 -
  44.366 -
  44.367 -#endif //HUGO_SMART_GRAPH_H
    45.1 --- a/src/hugo/suurballe.h	Wed Sep 29 14:12:26 2004 +0000
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,215 +0,0 @@
    45.4 -/* -*- C++ -*-
    45.5 - * src/hugo/suurballe.h - Part of HUGOlib, a generic C++ optimization library
    45.6 - *
    45.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    45.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    45.9 - *
   45.10 - * Permission to use, modify and distribute this software is granted
   45.11 - * provided that this copyright notice appears in all copies. For
   45.12 - * precise terms see the accompanying LICENSE file.
   45.13 - *
   45.14 - * This software is provided "AS IS" with no warranty of any kind,
   45.15 - * express or implied, and with no claim as to its suitability for any
   45.16 - * purpose.
   45.17 - *
   45.18 - */
   45.19 -
   45.20 -#ifndef HUGO_SUURBALLE_H
   45.21 -#define HUGO_SUURBALLE_H
   45.22 -
   45.23 -///\ingroup flowalgs
   45.24 -///\file
   45.25 -///\brief An algorithm for finding k paths of minimal total length.
   45.26 -
   45.27 -
   45.28 -#include <hugo/maps.h>
   45.29 -#include <vector>
   45.30 -#include <hugo/min_cost_flow.h>
   45.31 -
   45.32 -namespace hugo {
   45.33 -
   45.34 -/// \addtogroup flowalgs
   45.35 -/// @{
   45.36 -
   45.37 -  ///\brief Implementation of an algorithm for finding k edge-disjoint paths between 2 nodes 
   45.38 -  /// of minimal total length 
   45.39 -  ///
   45.40 -  /// The class \ref hugo::Suurballe implements
   45.41 -  /// an algorithm for finding k edge-disjoint paths
   45.42 -  /// from a given source node to a given target node in an
   45.43 -  /// edge-weighted directed graph having minimal total weight (length).
   45.44 -  ///
   45.45 -  ///\warning Length values should be nonnegative.
   45.46 -  /// 
   45.47 -  ///\param Graph The directed graph type the algorithm runs on.
   45.48 -  ///\param LengthMap The type of the length map (values should be nonnegative).
   45.49 -  ///
   45.50 -  ///\note It it questionable if it is correct to call this method after
   45.51 -  ///%Suurballe for it is just a special case of Edmond's and Karp's algorithm
   45.52 -  ///for finding minimum cost flows. In fact, this implementation is just
   45.53 -  ///wraps the MinCostFlow algorithms. The paper of both %Suurballe and
   45.54 -  ///Edmonds-Karp published in 1972, therefore it is possibly right to
   45.55 -  ///state that they are
   45.56 -  ///independent results. Most frequently this special case is referred as
   45.57 -  ///%Suurballe method in the literature, especially in communication
   45.58 -  ///network context.
   45.59 -  ///\author Attila Bernath
   45.60 -  template <typename Graph, typename LengthMap>
   45.61 -  class Suurballe{
   45.62 -
   45.63 -
   45.64 -    typedef typename LengthMap::ValueType Length;
   45.65 -    
   45.66 -    typedef typename Graph::Node Node;
   45.67 -    typedef typename Graph::NodeIt NodeIt;
   45.68 -    typedef typename Graph::Edge Edge;
   45.69 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
   45.70 -    typedef typename Graph::template EdgeMap<int> EdgeIntMap;
   45.71 -
   45.72 -    typedef ConstMap<Edge,int> ConstMap;
   45.73 -
   45.74 -    //Input
   45.75 -    const Graph& G;
   45.76 -
   45.77 -    //Auxiliary variables
   45.78 -    //This is the capacity map for the mincostflow problem
   45.79 -    ConstMap const1map;
   45.80 -    //This MinCostFlow instance will actually solve the problem
   45.81 -    MinCostFlow<Graph, LengthMap, ConstMap> mincost_flow;
   45.82 -
   45.83 -    //Container to store found paths
   45.84 -    std::vector< std::vector<Edge> > paths;
   45.85 -
   45.86 -  public :
   45.87 -
   45.88 -
   45.89 -    /// The constructor of the class.
   45.90 -    
   45.91 -    ///\param _G The directed graph the algorithm runs on. 
   45.92 -    ///\param _length The length (weight or cost) of the edges. 
   45.93 -    Suurballe(Graph& _G, LengthMap& _length) : G(_G),
   45.94 -      const1map(1), mincost_flow(_G, _length, const1map){}
   45.95 -
   45.96 -    ///Runs the algorithm.
   45.97 -
   45.98 -    ///Runs the algorithm.
   45.99 -    ///Returns k if there are at least k edge-disjoint paths from s to t.
  45.100 -    ///Otherwise it returns the number of found edge-disjoint paths from s to t.
  45.101 -    ///
  45.102 -    ///\param s The source node.
  45.103 -    ///\param t The target node.
  45.104 -    ///\param k How many paths are we looking for?
  45.105 -    ///
  45.106 -    int run(Node s, Node t, int k) {
  45.107 -
  45.108 -      int i = mincost_flow.run(s,t,k);
  45.109 -    
  45.110 -
  45.111 -      //Let's find the paths
  45.112 -      //We put the paths into stl vectors (as an inner representation). 
  45.113 -      //In the meantime we lose the information stored in 'reversed'.
  45.114 -      //We suppose the lengths to be positive now.
  45.115 -
  45.116 -      //We don't want to change the flow of mincost_flow, so we make a copy
  45.117 -      //The name here suggests that the flow has only 0/1 values.
  45.118 -      EdgeIntMap reversed(G); 
  45.119 -
  45.120 -      for(typename Graph::EdgeIt e(G); e!=INVALID; ++e) 
  45.121 -	reversed[e] = mincost_flow.getFlow()[e];
  45.122 -      
  45.123 -      paths.clear();
  45.124 -      //total_length=0;
  45.125 -      paths.resize(k);
  45.126 -      for (int j=0; j<i; ++j){
  45.127 -	Node n=s;
  45.128 -	OutEdgeIt e;
  45.129 -
  45.130 -	while (n!=t){
  45.131 -
  45.132 -
  45.133 -	  G.first(e,n);
  45.134 -	  
  45.135 -	  while (!reversed[e]){
  45.136 -	    ++e;
  45.137 -	  }
  45.138 -	  n = G.head(e);
  45.139 -	  paths[j].push_back(e);
  45.140 -	  //total_length += length[e];
  45.141 -	  reversed[e] = 1-reversed[e];
  45.142 -	}
  45.143 -	
  45.144 -      }
  45.145 -      return i;
  45.146 -    }
  45.147 -
  45.148 -    
  45.149 -    ///Returns the total length of the paths
  45.150 -    
  45.151 -    ///This function gives back the total length of the found paths.
  45.152 -    ///\pre \ref run() must
  45.153 -    ///be called before using this function.
  45.154 -    Length totalLength(){
  45.155 -      return mincost_flow.totalLength();
  45.156 -    }
  45.157 -
  45.158 -    ///Returns the found flow.
  45.159 -
  45.160 -    ///This function returns a const reference to the EdgeMap \c flow.
  45.161 -    ///\pre \ref run() must
  45.162 -    ///be called before using this function.
  45.163 -    const EdgeIntMap &getFlow() const { return mincost_flow.flow;}
  45.164 -
  45.165 -    /// Returns the optimal dual solution
  45.166 -    
  45.167 -    ///This function returns a const reference to the NodeMap
  45.168 -    ///\c potential (the dual solution).
  45.169 -    /// \pre \ref run() must be called before using this function.
  45.170 -    const EdgeIntMap &getPotential() const { return mincost_flow.potential;}
  45.171 -
  45.172 -    ///Checks whether the complementary slackness holds.
  45.173 -
  45.174 -    ///This function checks, whether the given solution is optimal.
  45.175 -    ///It should return true after calling \ref run() 
  45.176 -    ///Currently this function only checks optimality,
  45.177 -    ///doesn't bother with feasibility
  45.178 -    ///It is meant for testing purposes.
  45.179 -    ///
  45.180 -    bool checkComplementarySlackness(){
  45.181 -      return mincost_flow.checkComplementarySlackness();
  45.182 -    }
  45.183 -
  45.184 -    ///Read the found paths.
  45.185 -    
  45.186 -    ///This function gives back the \c j-th path in argument p.
  45.187 -    ///Assumes that \c run() has been run and nothing changed since then.
  45.188 -    /// \warning It is assumed that \c p is constructed to
  45.189 -    ///be a path of graph \c G.
  45.190 -    ///If \c j is not less than the result of previous \c run,
  45.191 -    ///then the result here will be an empty path (\c j can be 0 as well).
  45.192 -    ///
  45.193 -    ///\param Path The type of the path structure to put the result to (must meet hugo path concept).
  45.194 -    ///\param p The path to put the result to 
  45.195 -    ///\param j Which path you want to get from the found paths (in a real application you would get the found paths iteratively)
  45.196 -    template<typename Path>
  45.197 -    void getPath(Path& p, size_t j){
  45.198 -
  45.199 -      p.clear();
  45.200 -      if (j>paths.size()-1){
  45.201 -	return;
  45.202 -      }
  45.203 -      typename Path::Builder B(p);
  45.204 -      for(typename std::vector<Edge>::iterator i=paths[j].begin(); 
  45.205 -	  i!=paths[j].end(); ++i ){
  45.206 -	B.pushBack(*i);
  45.207 -      }
  45.208 -
  45.209 -      B.commit();
  45.210 -    }
  45.211 -
  45.212 -  }; //class Suurballe
  45.213 -
  45.214 -  ///@}
  45.215 -
  45.216 -} //namespace hugo
  45.217 -
  45.218 -#endif //HUGO_SUURBALLE_H
    46.1 --- a/src/hugo/sym_map.h	Wed Sep 29 14:12:26 2004 +0000
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,144 +0,0 @@
    46.4 -/* -*- C++ -*-
    46.5 - * src/hugo/sym_map.h - Part of HUGOlib, a generic C++ optimization library
    46.6 - *
    46.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    46.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    46.9 - *
   46.10 - * Permission to use, modify and distribute this software is granted
   46.11 - * provided that this copyright notice appears in all copies. For
   46.12 - * precise terms see the accompanying LICENSE file.
   46.13 - *
   46.14 - * This software is provided "AS IS" with no warranty of any kind,
   46.15 - * express or implied, and with no claim as to its suitability for any
   46.16 - * purpose.
   46.17 - *
   46.18 - */
   46.19 -
   46.20 -#ifndef HUGO_SYM_MAP_H
   46.21 -#define HUGO_SYM_MAP_H
   46.22 -
   46.23 -///\ingroup graphmaps
   46.24 -///\file
   46.25 -///\brief Graph maps that construates and destruates
   46.26 -///their elements dynamically.
   46.27 -
   46.28 -namespace hugo {
   46.29 -
   46.30 -/// \addtogroup graphmaps
   46.31 -/// @{
   46.32 -
   46.33 -  /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
   46.34 -   *  iterate on the symmetric maps when all of the edge - reverse edge pair
   46.35 -   *  has different parity.
   46.36 -   */
   46.37 -
   46.38 -
   46.39 -  template <typename Graph, typename Edge, typename EdgeIt>
   46.40 -  class SymEdgeIt : public EdgeIt {
   46.41 -  public:
   46.42 -
   46.43 -    /** Default constructor.
   46.44 -     */
   46.45 -    SymEdgeIt() 
   46.46 -      : EdgeIt() {}
   46.47 -
   46.48 -    /** Graph initialized constructor.
   46.49 -     */
   46.50 -    SymEdgeIt(const Graph& graph) 
   46.51 -      : EdgeIt(graph) {
   46.52 -      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   46.53 -	EdgeIt::operator++();
   46.54 -      }
   46.55 -    }
   46.56 -
   46.57 -    /** Creating invelid SymEdgeIt.
   46.58 -     */
   46.59 -    SymEdgeIt(Invalid invalid) 
   46.60 -      : EdgeIt(invalid) {}
   46.61 -
   46.62 -    /** SymEdgeIt from the given Edge.
   46.63 -     */
   46.64 -    SymEdgeIt(const Graph& graph, const Edge& edge)
   46.65 -      : EdgeIt(graph, edge) {
   46.66 -      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   46.67 -	EdgeIt::operator++();
   46.68 -      }
   46.69 -    }
   46.70 -
   46.71 -    /** Increase operator.
   46.72 -     */
   46.73 -    SymEdgeIt& operator++() {
   46.74 -      EdgeIt::operator++();
   46.75 -      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   46.76 -	EdgeIt::operator++();
   46.77 -      }
   46.78 -      return *this;
   46.79 -    }
   46.80 -  };
   46.81 -
   46.82 -  /** The SymMap template class is graph map structure what
   46.83 -   *  wraps an other map structure to use as symmetric map structure.
   46.84 -   *
   46.85 -   *  The template parameter is the MapRegistry that the maps
   46.86 -   *  will belong to and the ValueType.
   46.87 -   */
   46.88 -  template <template <typename, typename> class DynMap, 
   46.89 -	    typename MapRegistry, typename Value>
   46.90 -  class SymMap : public DynMap<MapRegistry, Value>{
   46.91 -
   46.92 -  private:
   46.93 -
   46.94 -    typedef DynMap<MapRegistry, Value> MapImpl;
   46.95 -
   46.96 -  public:
   46.97 -		
   46.98 -    /// The graph type of the maps. 
   46.99 -    typedef typename MapRegistry::Graph Graph;
  46.100 -
  46.101 -    typedef typename MapImpl::KeyType KeyType;
  46.102 -
  46.103 -  public:
  46.104 -
  46.105 -
  46.106 -    /** Graph and Registry initialized map constructor.
  46.107 -     */
  46.108 -    SymMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
  46.109 -
  46.110 -    /** Constructor to use default value to initialize the map. 
  46.111 -     */
  46.112 -    SymMap(const Graph& g, MapRegistry& r, const Value& v) 
  46.113 -      : MapImpl(g, r, v) {}
  46.114 -
  46.115 -    /** Constructor to copy a map of the same map type.
  46.116 -     */
  46.117 -    SymMap(const SymMap& copy) 
  46.118 -      : MapImpl(static_cast<const MapImpl&>(copy)) {}
  46.119 -
  46.120 -    /** Assign operator to copy a map of the same map type.
  46.121 -     */
  46.122 -    SymMap& operator=(const SymMap& copy) {
  46.123 -      MapImpl::operator=(static_cast<const MapImpl&>(copy));
  46.124 -      return *this;
  46.125 -    }
  46.126 -
  46.127 -    /** Add a new key to the map. It called by the map registry.
  46.128 -     */
  46.129 -    void add(const KeyType& key) {
  46.130 -      int id = MapImpl::getGraph()->id(key);
  46.131 -      if (id & 1) return;
  46.132 -      MapImpl::add(key);
  46.133 -    }
  46.134 -		
  46.135 -    /** Erase a key from the map. It called by the map registry.
  46.136 -     */
  46.137 -    void erase(const KeyType& key) {
  46.138 -      int id = MapImpl::getGraph()->id(key);
  46.139 -      if (id & 1) return;
  46.140 -      MapImpl::add(key);
  46.141 -    }
  46.142 -  };
  46.143 -
  46.144 -  /// @}
  46.145 -}
  46.146 -
  46.147 -#endif
    47.1 --- a/src/hugo/template.h	Wed Sep 29 14:12:26 2004 +0000
    47.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    47.3 @@ -1,20 +0,0 @@
    47.4 -/* -*- C++ -*-
    47.5 - * src/hugo/template.h - Part of HUGOlib, a generic C++ optimization library
    47.6 - *
    47.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    47.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    47.9 - *
   47.10 - * Permission to use, modify and distribute this software is granted
   47.11 - * provided that this copyright notice appears in all copies. For
   47.12 - * precise terms see the accompanying LICENSE file.
   47.13 - *
   47.14 - * This software is provided "AS IS" with no warranty of any kind,
   47.15 - * express or implied, and with no claim as to its suitability for any
   47.16 - * purpose.
   47.17 - *
   47.18 - */
   47.19 -
   47.20 -#ifndef HUGO_TEMPLATE_H
   47.21 -#define HUGO_TEMPLATE_H
   47.22 -
   47.23 -#endif // HUGO_TEMPLATE_H
    48.1 --- a/src/hugo/time_measure.h	Wed Sep 29 14:12:26 2004 +0000
    48.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.3 @@ -1,227 +0,0 @@
    48.4 -/* -*- C++ -*-
    48.5 - * src/hugo/time_measure.h - Part of HUGOlib, a generic C++ optimization library
    48.6 - *
    48.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    48.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    48.9 - *
   48.10 - * Permission to use, modify and distribute this software is granted
   48.11 - * provided that this copyright notice appears in all copies. For
   48.12 - * precise terms see the accompanying LICENSE file.
   48.13 - *
   48.14 - * This software is provided "AS IS" with no warranty of any kind,
   48.15 - * express or implied, and with no claim as to its suitability for any
   48.16 - * purpose.
   48.17 - *
   48.18 - */
   48.19 -
   48.20 -#ifndef HUGO_TIME_MEASURE_H
   48.21 -#define HUGO_TIME_MEASURE_H
   48.22 -
   48.23 -///\ingroup misc
   48.24 -///\file
   48.25 -///\brief Tools for measuring cpu usage
   48.26 -
   48.27 -#include <sys/time.h>
   48.28 -#include <sys/times.h>
   48.29 -#include <fstream>
   48.30 -#include <iostream>
   48.31 -#include <unistd.h>
   48.32 -
   48.33 -namespace hugo {
   48.34 -
   48.35 -  /// \addtogroup misc
   48.36 -  /// @{
   48.37 -
   48.38 -  /// A class to store (cpu)time instances.
   48.39 -
   48.40 -  /// This class stores five time values.
   48.41 -  /// - a real time
   48.42 -  /// - a user cpu time
   48.43 -  /// - a system cpu time
   48.44 -  /// - a user cpu time of children
   48.45 -  /// - a system cpu time of children
   48.46 -  ///
   48.47 -  /// TimeStamp's can be added to or substracted from each other and
   48.48 -  /// they can be pushed to a stream.
   48.49 -  ///
   48.50 -  /// In most cases, perhaps \ref Timer class is what you want to use instead.
   48.51 -  ///
   48.52 -  ///\author Alpar Juttner
   48.53 -
   48.54 -  class TimeStamp
   48.55 -  {
   48.56 -    tms ts;
   48.57 -    double real_time;
   48.58 -  
   48.59 -  public:
   48.60 -
   48.61 -    tms &getTms() {return ts;}
   48.62 -    const tms &getTms() const {return ts;}
   48.63 -    ///Read the current time values of the process
   48.64 -    void stamp()
   48.65 -    {
   48.66 -      timeval tv;
   48.67 -      times(&ts);
   48.68 -      gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
   48.69 -    }
   48.70 -  
   48.71 -    /// Constructor initializing with zero
   48.72 -    TimeStamp()
   48.73 -    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
   48.74 -    ///Constructor initializing with the current time values of the process
   48.75 -    TimeStamp(void *) { stamp();}
   48.76 -  
   48.77 -    ///
   48.78 -    TimeStamp &operator+=(const TimeStamp &b)
   48.79 -    {
   48.80 -      ts.tms_utime+=b.ts.tms_utime;
   48.81 -      ts.tms_stime+=b.ts.tms_stime;
   48.82 -      ts.tms_cutime+=b.ts.tms_cutime;
   48.83 -      ts.tms_cstime+=b.ts.tms_cstime;
   48.84 -      real_time+=b.real_time;
   48.85 -      return *this;
   48.86 -    }
   48.87 -    ///
   48.88 -    TimeStamp operator+(const TimeStamp &b) const
   48.89 -    {
   48.90 -      TimeStamp t(*this);
   48.91 -      return t+=b;
   48.92 -    }
   48.93 -    ///
   48.94 -    TimeStamp &operator-=(const TimeStamp &b)
   48.95 -    {
   48.96 -      ts.tms_utime-=b.ts.tms_utime;
   48.97 -      ts.tms_stime-=b.ts.tms_stime;
   48.98 -      ts.tms_cutime-=b.ts.tms_cutime;
   48.99 -      ts.tms_cstime-=b.ts.tms_cstime;
  48.100 -      real_time-=b.real_time;
  48.101 -      return *this;
  48.102 -    }
  48.103 -    ///
  48.104 -    TimeStamp operator-(const TimeStamp &b) const
  48.105 -    {
  48.106 -      TimeStamp t(*this);
  48.107 -      return t-=b;
  48.108 -    }
  48.109 -
  48.110 -    ///The time ellapsed since the last call of stamp()
  48.111 -    TimeStamp ellapsed() const
  48.112 -    {
  48.113 -      TimeStamp t(NULL);
  48.114 -      return t-*this;
  48.115 -    }
  48.116 -  
  48.117 -    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
  48.118 -  
  48.119 -    ///Gives back the user time of the process
  48.120 -    double getUserTime() const
  48.121 -    {
  48.122 -      return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
  48.123 -    }
  48.124 -    ///Gives back the system time of the process
  48.125 -    double getSystemTime() const
  48.126 -    {
  48.127 -      return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
  48.128 -    }
  48.129 -    ///Gives back the user time of the process' children
  48.130 -    double getCUserTime() const
  48.131 -    {
  48.132 -      return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
  48.133 -    }
  48.134 -    ///Gives back the user time of the process' children
  48.135 -    double getCSystemTime() const
  48.136 -    {
  48.137 -      return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
  48.138 -    }
  48.139 -    ///Gives back the real time of the process
  48.140 -    double getRealTime() const {return real_time;}
  48.141 -  };
  48.142 -
  48.143 -  ///Class measuring the cpu time and real time usage of the process
  48.144 -
  48.145 -  ///Class measuring the cpu time and real time usage of the process.
  48.146 -  ///It is quite easy-to-use, here is a short example.
  48.147 -  ///\code
  48.148 -  ///#include<hugo/time_measure.h>
  48.149 -  ///#include<iostream>
  48.150 -  ///
  48.151 -  ///int main()
  48.152 -  ///{
  48.153 -  ///
  48.154 -  ///  ...
  48.155 -  ///
  48.156 -  ///  Timer T;
  48.157 -  ///  doSomething();
  48.158 -  ///  std::cout << T << '\n';
  48.159 -  ///  T.reset();
  48.160 -  ///  doSomethingElse();
  48.161 -  ///  std::cout << T << '\n';
  48.162 -  ///
  48.163 -  ///  ...
  48.164 -  ///
  48.165 -  ///}
  48.166 -  ///\endcode
  48.167 -  ///
  48.168 -  ///\todo This shouldn't be Unix (Linux) specific.
  48.169 -  ///
  48.170 -  ///\author Alpar Juttner
  48.171 -  class Timer
  48.172 -  {
  48.173 -    TimeStamp start_time;
  48.174 -
  48.175 -    void _reset() {start_time.stamp();}
  48.176 -  
  48.177 -  public: 
  48.178 -    ///Constructor. It starts with zero time counters
  48.179 -    Timer() {_reset();}
  48.180 -
  48.181 -    ///Computes the ellapsed time
  48.182 -
  48.183 -    ///This conversion computes the ellapsed time
  48.184 -    ///since the construction of \c t or since
  48.185 -    ///the last \c t.reset().
  48.186 -    operator TimeStamp ()
  48.187 -    {
  48.188 -      TimeStamp t;
  48.189 -      t.stamp();
  48.190 -      return t-start_time;
  48.191 -    }
  48.192 -
  48.193 -    ///Resets the time counters
  48.194 -    TimeStamp reset()
  48.195 -    {
  48.196 -      TimeStamp t(start_time);
  48.197 -      _reset();
  48.198 -      return start_time-t;
  48.199 -    }
  48.200 -  };
  48.201 -
  48.202 -  ///Prints the time counters
  48.203 -
  48.204 -  ///Prints the time counters in the following form:
  48.205 -  ///
  48.206 -  /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt>
  48.207 -  ///
  48.208 -  /// where the values are the
  48.209 -  /// \li \c u: user cpu time,
  48.210 -  /// \li \c s: system cpu time,
  48.211 -  /// \li \c cu: user cpu time of children,
  48.212 -  /// \li \c cs: system cpu time of children,
  48.213 -  /// \li \c real: real time.
  48.214 -  /// \relates TimeStamp
  48.215 -  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
  48.216 -  {
  48.217 -    long cls = sysconf(_SC_CLK_TCK);
  48.218 -    os << "u: " << double(t.getTms().tms_utime)/cls <<
  48.219 -      "s, s: " << double(t.getTms().tms_stime)/cls <<
  48.220 -      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
  48.221 -      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
  48.222 -      "s, real: " << t.getRealTime() << "s";
  48.223 -    return os;
  48.224 -  }
  48.225 -
  48.226 -  /// @}  
  48.227 -
  48.228 -} //namespace hugo
  48.229 -
  48.230 -#endif //HUGO_TIME_MEASURE_H
    49.1 --- a/src/hugo/unionfind.h	Wed Sep 29 14:12:26 2004 +0000
    49.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.3 @@ -1,724 +0,0 @@
    49.4 -/* -*- C++ -*-
    49.5 - * src/hugo/unionfind.h - Part of HUGOlib, a generic C++ optimization library
    49.6 - *
    49.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    49.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    49.9 - *
   49.10 - * Permission to use, modify and distribute this software is granted
   49.11 - * provided that this copyright notice appears in all copies. For
   49.12 - * precise terms see the accompanying LICENSE file.
   49.13 - *
   49.14 - * This software is provided "AS IS" with no warranty of any kind,
   49.15 - * express or implied, and with no claim as to its suitability for any
   49.16 - * purpose.
   49.17 - *
   49.18 - */
   49.19 -
   49.20 -#ifndef HUGO_UNION_FIND_H
   49.21 -#define HUGO_UNION_FIND_H
   49.22 -
   49.23 -//!\ingroup auxdat
   49.24 -//!\file
   49.25 -//!\brief Union-Find data structures.
   49.26 -//!
   49.27 -//!\bug unionfind_test.cc doesn't work with Intel compiler. It compiles but
   49.28 -//!fails to run (Segmentation fault).
   49.29 -
   49.30 -
   49.31 -#include <vector>
   49.32 -#include <list>
   49.33 -#include <utility>
   49.34 -#include <algorithm>
   49.35 -
   49.36 -#include <hugo/invalid.h>
   49.37 -
   49.38 -namespace hugo {
   49.39 -
   49.40 -  //! \addtogroup auxdat
   49.41 -  //! @{
   49.42 -
   49.43 -  /**
   49.44 -   * \brief A \e Union-Find data structure implementation
   49.45 -   *
   49.46 -   * The class implements the \e Union-Find data structure. 
   49.47 -   * The union operation uses rank heuristic, while
   49.48 -   * the find operation uses path compression.
   49.49 -   * This is a very simple but efficient implementation, providing 
   49.50 -   * only four methods: join (union), find, insert and size.
   49.51 -   * For more features see the \ref UnionFindEnum class.
   49.52 -   *
   49.53 -   * It is primarily used in Kruskal algorithm for finding minimal
   49.54 -   * cost spanning tree in a graph.
   49.55 -   * \sa kruskal()
   49.56 -   *
   49.57 -   * \pre The elements are automatically added only if the map 
   49.58 -   * given to the constructor was filled with -1's. Otherwise you
   49.59 -   * need to add all the elements by the \ref insert() method.
   49.60 -   * \bug It is not clear what the constructor parameter is used for.
   49.61 -   */
   49.62 -
   49.63 -  template <typename T, typename TIntMap>
   49.64 -  class UnionFind {
   49.65 -    
   49.66 -  public:
   49.67 -    typedef T ElementType;
   49.68 -    typedef std::pair<int,int> PairType;
   49.69 -
   49.70 -  private:
   49.71 -    std::vector<PairType> data;
   49.72 -    TIntMap& map;
   49.73 -
   49.74 -  public:
   49.75 -    UnionFind(TIntMap& m) : map(m) {}
   49.76 -
   49.77 -    /**
   49.78 -     * \brief Returns the index of the element's component.
   49.79 -     *
   49.80 -     * The method returns the index of the element's component.
   49.81 -     * This is an integer between zero and the number of inserted elements.
   49.82 -     */
   49.83 -
   49.84 -    int find(T a)
   49.85 -    {
   49.86 -      int comp0 = map[a];
   49.87 -      if (comp0 < 0) {
   49.88 -	return insert(a);
   49.89 -      }
   49.90 -      int comp = comp0;
   49.91 -      int next;
   49.92 -      while ( (next = data[comp].first) != comp) {
   49.93 -	comp = next;
   49.94 -      }
   49.95 -      while ( (next = data[comp0].first) != comp) {
   49.96 -	data[comp0].first = comp;
   49.97 -	comp0 = next;
   49.98 -      }
   49.99 -
  49.100 -      return comp;
  49.101 -    }
  49.102 -
  49.103 -    /**
  49.104 -     * \brief Insert a new element into the structure.
  49.105 -     *
  49.106 -     * This method inserts a new element into the data structure. 
  49.107 -     *
  49.108 -     * It is not required to use this method:
  49.109 -     * if the map given to the constructor was filled 
  49.110 -     * with -1's then it is called automatically
  49.111 -     * on the first \ref find or \ref join.
  49.112 -     *
  49.113 -     * The method returns the index of the new component.
  49.114 -     */
  49.115 -
  49.116 -    int insert(T a)
  49.117 -    {
  49.118 -      int n = data.size();
  49.119 -      data.push_back(std::make_pair(n, 1));
  49.120 -      map.set(a,n);
  49.121 -      return n;
  49.122 -    }
  49.123 -
  49.124 -    /**
  49.125 -     * \brief Joining the components of element \e a and element \e b.
  49.126 -     *
  49.127 -     * This is the \e union operation of the Union-Find structure. 
  49.128 -     * Joins the component of elemenent \e a and component of
  49.129 -     * element \e b. If \e a and \e b are in the same component then
  49.130 -     * it returns false otherwise it returns true.
  49.131 -     */
  49.132 -
  49.133 -    bool join(T a, T b)
  49.134 -    {
  49.135 -      int ca = find(a);
  49.136 -      int cb = find(b);
  49.137 -
  49.138 -      if ( ca == cb ) 
  49.139 -	return false;
  49.140 -
  49.141 -      if ( data[ca].second > data[cb].second ) {
  49.142 -	data[cb].first = ca;
  49.143 -	data[ca].second += data[cb].second;
  49.144 -      }
  49.145 -      else {
  49.146 -	data[ca].first = cb;
  49.147 -	data[cb].second += data[ca].second;
  49.148 -      }
  49.149 -      return true;
  49.150 -    }
  49.151 -
  49.152 -    /**
  49.153 -     * \brief Returns the size of the component of element \e a.
  49.154 -     *
  49.155 -     * Returns the size of the component of element \e a.
  49.156 -     */
  49.157 -
  49.158 -    int size(T a)
  49.159 -    {
  49.160 -      int ca = find(a);
  49.161 -      return data[ca].second;
  49.162 -    }
  49.163 -
  49.164 -  };
  49.165 -
  49.166 -
  49.167 -
  49.168 -
  49.169 -  /*******************************************************/
  49.170 -
  49.171 -
  49.172 -#ifdef DEVELOPMENT_DOCS
  49.173 -
  49.174 -  /**
  49.175 -   * \brief The auxiliary class for the \ref UnionFindEnum class.
  49.176 -   *
  49.177 -   * In the \ref UnionFindEnum class all components are represented as
  49.178 -   * a std::list. 
  49.179 -   * Items of these lists are UnionFindEnumItem structures.
  49.180 -   *
  49.181 -   * The class has four fields:
  49.182 -   *  - T me - the actual element 
  49.183 -   *  - IIter parent - the parent of the element in the union-find structure
  49.184 -   *  - int size - the size of the component of the element. 
  49.185 -   *            Only valid if the element
  49.186 -   *            is the leader of the component.
  49.187 -   *  - CIter my_class - pointer into the list of components 
  49.188 -   *            pointing to the component of the element.
  49.189 -   *            Only valid if the element is the leader of the component.
  49.190 -   */
  49.191 -
  49.192 -#endif
  49.193 -
  49.194 -  template <typename T>
  49.195 -  struct UnionFindEnumItem {
  49.196 -
  49.197 -    typedef std::list<UnionFindEnumItem> ItemList;
  49.198 -    typedef std::list<ItemList> ClassList;
  49.199 -    typedef typename ItemList::iterator IIter;
  49.200 -    typedef typename ClassList::iterator CIter;
  49.201 -
  49.202 -    T me;
  49.203 -    IIter parent;
  49.204 -    int size;
  49.205 -    CIter my_class;
  49.206 -
  49.207 -    UnionFindEnumItem() {}
  49.208 -    UnionFindEnumItem(const T &_me, CIter _my_class): 
  49.209 -      me(_me), size(1), my_class(_my_class) {}
  49.210 -  };
  49.211 -
  49.212 -
  49.213 -  /**
  49.214 -   * \brief A \e Union-Find data structure implementation which
  49.215 -   * is able to enumerate the components.
  49.216 -   *
  49.217 -   * The class implements a \e Union-Find data structure
  49.218 -   * which is able to enumerate the components and the items in
  49.219 -   * a component. If you don't need this feature then perhaps it's
  49.220 -   * better to use the \ref UnionFind class which is more efficient.
  49.221 -   *
  49.222 -   * The union operation uses rank heuristic, while
  49.223 -   * the find operation uses path compression.
  49.224 -   *
  49.225 -   * \pre You
  49.226 -   * need to add all the elements by the \ref insert() method.
  49.227 -   */
  49.228 -
  49.229 -
  49.230 -  template <typename T, template <typename Item> class Map>
  49.231 -  class UnionFindEnum {
  49.232 -
  49.233 -    typedef std::list<UnionFindEnumItem<T> > ItemList;
  49.234 -    typedef std::list<ItemList> ClassList;
  49.235 -    typedef typename ItemList::iterator IIter;
  49.236 -    typedef typename ItemList::const_iterator IcIter;
  49.237 -    typedef typename ClassList::iterator CIter;
  49.238 -    typedef typename ClassList::const_iterator CcIter;
  49.239 -
  49.240 -  public:
  49.241 -    typedef T ElementType;
  49.242 -    typedef UnionFindEnumItem<T> ItemType;
  49.243 -    typedef Map< IIter > MapType;
  49.244 -
  49.245 -  private:
  49.246 -    MapType& m;
  49.247 -    ClassList classes;
  49.248 -
  49.249 -    IIter _find(IIter a) const {
  49.250 -      IIter comp = a;
  49.251 -      IIter next;
  49.252 -      while( (next = comp->parent) != comp ) {
  49.253 -	comp = next;
  49.254 -      }
  49.255 -
  49.256 -      IIter comp1 = a;
  49.257 -      while( (next = comp1->parent) != comp ) {
  49.258 -	comp1->parent = comp->parent;
  49.259 -	comp1 = next;
  49.260 -      }
  49.261 -      return comp;
  49.262 -    }
  49.263 -
  49.264 -  public:
  49.265 -    UnionFindEnum(MapType& _m) : m(_m) {}
  49.266 -
  49.267 -
  49.268 -    /**
  49.269 -     * \brief Insert the given element into a new component.
  49.270 -     *
  49.271 -     * This method creates a new component consisting only of the
  49.272 -     * given element.
  49.273 -     */
  49.274 -
  49.275 -    void insert(const T &a)
  49.276 -    {
  49.277 -
  49.278 -
  49.279 -      classes.push_back(ItemList());
  49.280 -      CIter aclass = classes.end();
  49.281 -      --aclass;
  49.282 -
  49.283 -      ItemList &alist = *aclass;
  49.284 -      alist.push_back(ItemType(a, aclass));
  49.285 -      IIter ai = alist.begin();
  49.286 -
  49.287 -      ai->parent = ai;
  49.288 -      m.set(a, ai);
  49.289 -
  49.290 -    }
  49.291 -
  49.292 -    /**
  49.293 -     * \brief Insert the given element into the component of the others.
  49.294 -     *
  49.295 -     * This methods insert the element \e a into the component of the
  49.296 -     * element \e comp. 
  49.297 -     */
  49.298 -
  49.299 -    void insert(const T &a, const T &comp) {
  49.300 -      
  49.301 -      IIter clit = _find(m[comp]);
  49.302 -      ItemList &c = *clit->my_class;
  49.303 -      c.push_back(ItemType(a,0));
  49.304 -      IIter ai = c.end();
  49.305 -      --ai;
  49.306 -      ai->parent = clit;
  49.307 -      m.set(a, ai);
  49.308 -      ++clit->size;
  49.309 -    }
  49.310 -
  49.311 -
  49.312 -    /**
  49.313 -     * \brief Find the leader of the component of the given element.
  49.314 -     *
  49.315 -     * The method returns the leader of the component of the given element.
  49.316 -     */
  49.317 -
  49.318 -    T find(const T &a) const {
  49.319 -      return _find(m[a])->me;
  49.320 -    }
  49.321 -
  49.322 -
  49.323 -    /**
  49.324 -     * \brief Joining the component of element \e a and element \e b.
  49.325 -     *
  49.326 -     * This is the \e union operation of the Union-Find structure. 
  49.327 -     * Joins the component of elemenent \e a and component of
  49.328 -     * element \e b. If \e a and \e b are in the same component then
  49.329 -     * returns false else returns true.
  49.330 -     */
  49.331 -
  49.332 -    bool join(T a, T b) {
  49.333 -
  49.334 -      IIter ca = _find(m[a]);
  49.335 -      IIter cb = _find(m[b]);
  49.336 -
  49.337 -      if ( ca == cb ) {
  49.338 -	return false;
  49.339 -      }
  49.340 -
  49.341 -      if ( ca->size > cb->size ) {
  49.342 -
  49.343 -	cb->parent = ca->parent;
  49.344 -	ca->size += cb->size;
  49.345 -	
  49.346 -	ItemList &alist = *ca->my_class;
  49.347 -	alist.splice(alist.end(),*cb->my_class);
  49.348 -
  49.349 -	classes.erase(cb->my_class);
  49.350 -	cb->my_class = 0;
  49.351 -      }
  49.352 -      else {
  49.353 -
  49.354 -	ca->parent = cb->parent;
  49.355 -	cb->size += ca->size;
  49.356 -	
  49.357 -	ItemList &blist = *cb->my_class;
  49.358 -	blist.splice(blist.end(),*ca->my_class);
  49.359 -
  49.360 -	classes.erase(ca->my_class);
  49.361 -	ca->my_class = 0;
  49.362 -      }
  49.363 -
  49.364 -      return true;
  49.365 -    }
  49.366 -
  49.367 -
  49.368 -    /**
  49.369 -     * \brief Returns the size of the component of element \e a.
  49.370 -     *
  49.371 -     * Returns the size of the component of element \e a.
  49.372 -     */
  49.373 -
  49.374 -    int size(const T &a) const {
  49.375 -      return _find(m[a])->size;
  49.376 -    }
  49.377 -
  49.378 -
  49.379 -    /**
  49.380 -     * \brief Split up the component of the element. 
  49.381 -     *
  49.382 -     * Splitting the component of the element into sigleton
  49.383 -     * components (component of size one).
  49.384 -     */
  49.385 -
  49.386 -    void split(const T &a) {
  49.387 -
  49.388 -      IIter ca = _find(m[a]);
  49.389 - 
  49.390 -      if ( ca->size == 1 )
  49.391 -	return;
  49.392 -      
  49.393 -      CIter aclass = ca->my_class;
  49.394 -
  49.395 -      for(IIter curr = ca; ++curr != aclass->end(); curr=ca) {
  49.396 -	classes.push_back(ItemList());
  49.397 -	CIter nl = --classes.end();
  49.398 -	nl->splice(nl->end(), *aclass, curr);
  49.399 -
  49.400 -	curr->size=1;
  49.401 -	curr->parent=curr;
  49.402 -	curr->my_class = nl;
  49.403 -      }
  49.404 -
  49.405 -      ca->size=1;
  49.406 -      return;
  49.407 -    }
  49.408 -
  49.409 -
  49.410 -    /**
  49.411 -     * \brief Set the given element to the leader element of its component.
  49.412 -     *
  49.413 -     * Set the given element to the leader element of its component.
  49.414 -     */
  49.415 -
  49.416 -    void makeRep(const T &a) {
  49.417 -
  49.418 -      IIter ia = m[a];
  49.419 -      IIter la = _find(ia);
  49.420 -      if (la == ia) return;
  49.421 -
  49.422 -      ia->my_class = la->my_class;
  49.423 -      la->my_class = 0;
  49.424 -
  49.425 -      ia->size = la->size;
  49.426 -
  49.427 -      CIter l = ia->my_class;
  49.428 -      l->splice(l->begin(),*l,ia);
  49.429 -
  49.430 -      ia->parent = ia;
  49.431 -      la->parent = ia;
  49.432 -    }
  49.433 -
  49.434 -    /**
  49.435 -     * \brief Move the given element to an other component.
  49.436 -     *
  49.437 -     * This method moves the element \e a from its component
  49.438 -     * to the component of \e comp.
  49.439 -     * If \e a and \e comp are in the same component then
  49.440 -     * it returns false otherwise it returns true.
  49.441 -     */
  49.442 -
  49.443 -    bool move(const T &a, const T &comp) {
  49.444 -
  49.445 -      IIter ai = m[a];
  49.446 -      IIter lai = _find(ai);
  49.447 -      IIter clit = _find(m[comp]);
  49.448 -
  49.449 -      if (lai == clit)
  49.450 -	return false;
  49.451 -
  49.452 -      ItemList &cl = *clit->my_class,
  49.453 -	&al = *lai->my_class;
  49.454 -
  49.455 -      bool is_leader = (lai == ai);
  49.456 -      bool singleton = false;
  49.457 -
  49.458 -      if (is_leader) {
  49.459 -	++lai;
  49.460 -      }
  49.461 -
  49.462 -      cl.splice(cl.end(), al, ai);
  49.463 -
  49.464 -      if (is_leader) {
  49.465 -	if (ai->size == 1) {
  49.466 -	  classes.erase(ai->my_class);
  49.467 -	  singleton = true;
  49.468 -	}
  49.469 -	else {
  49.470 -	  lai->size = ai->size; 
  49.471 -	  lai->my_class = ai->my_class;	
  49.472 -	}
  49.473 -      }
  49.474 -      if (!singleton) {
  49.475 -	for (IIter i = lai; i != al.end(); ++i)
  49.476 -	  i->parent = lai;
  49.477 -	--lai->size;
  49.478 -      }
  49.479 -
  49.480 -      ai->parent = clit;
  49.481 -      ai->my_class = 0;
  49.482 -      ++clit->size;
  49.483 -
  49.484 -      return true;
  49.485 -    }
  49.486 -
  49.487 -
  49.488 -    /**
  49.489 -     * \brief Remove the given element from the structure.
  49.490 -     *
  49.491 -     * Remove the given element from the structure.
  49.492 -     *
  49.493 -     * Removes the element from its component and if the component becomes
  49.494 -     * empty then removes that component from the component list.
  49.495 -     */
  49.496 -    void erase(const T &a) {
  49.497 -
  49.498 -      IIter ma = m[a];
  49.499 -      if (ma == 0) return;
  49.500 -
  49.501 -      IIter la = _find(ma);
  49.502 -      if (la == ma) {
  49.503 -	if (ma -> size == 1){
  49.504 -	  classes.erase(ma->my_class);
  49.505 -	  m.set(a,0);
  49.506 -	  return;
  49.507 -	}
  49.508 -	++la;
  49.509 -	la->size = ma->size; 
  49.510 -	la->my_class = ma->my_class;	
  49.511 -      }
  49.512 -
  49.513 -      for (IIter i = la; i != la->my_class->end(); ++i) {
  49.514 -	i->parent = la;
  49.515 -      }
  49.516 -
  49.517 -      la->size--;
  49.518 -      la->my_class->erase(ma);
  49.519 -      m.set(a,0);
  49.520 -    }
  49.521 -
  49.522 -    /**
  49.523 -     * \brief Removes the component of the given element from the structure.
  49.524 -     *
  49.525 -     * Removes the component of the given element from the structure.
  49.526 -     */
  49.527 -
  49.528 -    void eraseClass(const T &a) {
  49.529 -      IIter ma = m[a];
  49.530 -      if (ma == 0) return;
  49.531 -#     ifdef DEBUG
  49.532 -      CIter c = _find(ma)->my_class;
  49.533 -      for (IIter i=c->begin(); i!=c->end(); ++i)
  49.534 -	m.set(i->me, 0);
  49.535 -#     endif
  49.536 -      classes.erase(_find(ma)->my_class);
  49.537 -    }
  49.538 -
  49.539 -
  49.540 -    class ClassIt {
  49.541 -      friend class UnionFindEnum;
  49.542 -
  49.543 -      CcIter i;
  49.544 -    public:
  49.545 -      ClassIt(Invalid): i(0) {}
  49.546 -      ClassIt() {}
  49.547 -      
  49.548 -      operator const T& () const { 
  49.549 -	ItemList const &ll = *i;
  49.550 -	return (ll.begin())->me; }
  49.551 -      bool operator == (ClassIt it) const {
  49.552 -	return (i == it.i);
  49.553 -      }
  49.554 -      bool operator != (ClassIt it) const {
  49.555 -	return (i != it.i);
  49.556 -      }
  49.557 -      bool operator < (ClassIt it) const {
  49.558 -	return (i < it.i);
  49.559 -      }
  49.560 -
  49.561 -      bool valid() const { return i != 0; }
  49.562 -    private:
  49.563 -      void first(const ClassList &l) { i = l.begin(); validate(l); }
  49.564 -      void next(const ClassList &l) {
  49.565 -	++i; 
  49.566 -	validate(l);
  49.567 -      }
  49.568 -      void validate(const ClassList &l) {
  49.569 -	if ( i == l.end() ) 
  49.570 -	  i = 0;
  49.571 -      }
  49.572 -    };
  49.573 -
  49.574 -    /**
  49.575 -     * \brief Sets the iterator to point to the first component.
  49.576 -     * 
  49.577 -     * Sets the iterator to point to the first component.
  49.578 -     *
  49.579 -     * With the \ref first, \ref valid and \ref next methods you can
  49.580 -     * iterate through the components. For example:
  49.581 -     * \code
  49.582 -     * UnionFindEnum<Graph::Node, Graph::NodeMap>::MapType map(G);
  49.583 -     * UnionFindEnum<Graph::Node, Graph::NodeMap> U(map);
  49.584 -     * UnionFindEnum<Graph::Node, Graph::NodeMap>::ClassIt iter;
  49.585 -     *  for (U.first(iter); U.valid(iter); U.next(iter)) {
  49.586 -     *    // iter is convertible to Graph::Node
  49.587 -     *    cout << iter << endl;
  49.588 -     *  }
  49.589 -     * \endcode
  49.590 -     */
  49.591 -
  49.592 -    ClassIt& first(ClassIt& it) const {
  49.593 -      it.first(classes);
  49.594 -      return it;
  49.595 -    }
  49.596 -
  49.597 -    /**
  49.598 -     * \brief Returns whether the iterator is valid.
  49.599 -     *
  49.600 -     * Returns whether the iterator is valid.
  49.601 -     *
  49.602 -     * With the \ref first, \ref valid and \ref next methods you can
  49.603 -     * iterate through the components. See the example here: \ref first.
  49.604 -     */
  49.605 -
  49.606 -    bool valid(ClassIt const &it) const {
  49.607 -      return it.valid(); 
  49.608 -    }
  49.609 -
  49.610 -    /**
  49.611 -     * \brief Steps the iterator to the next component. 
  49.612 -     *
  49.613 -     * Steps the iterator to the next component.
  49.614 -     *
  49.615 -     * With the \ref first, \ref valid and \ref next methods you can
  49.616 -     * iterate through the components. See the example here: \ref first.
  49.617 -     */
  49.618 -
  49.619 -    ClassIt& next(ClassIt& it) const {
  49.620 -      it.next(classes);
  49.621 -      return it;
  49.622 -    }
  49.623 -
  49.624 -
  49.625 -    class ItemIt {
  49.626 -      friend class UnionFindEnum;
  49.627 -
  49.628 -      IcIter i;
  49.629 -      const ItemList *l;
  49.630 -    public:
  49.631 -      ItemIt(Invalid): i(0) {}
  49.632 -      ItemIt() {}
  49.633 -      
  49.634 -      operator const T& () const { return i->me; }
  49.635 -      bool operator == (ItemIt it) const {
  49.636 -	return (i == it.i);
  49.637 -      }
  49.638 -      bool operator != (ItemIt it) const {
  49.639 -	return (i != it.i);
  49.640 -      }
  49.641 -      bool operator < (ItemIt it) const {
  49.642 -	return (i < it.i);
  49.643 -      }
  49.644 -
  49.645 -      bool valid() const { return i != 0; }
  49.646 -    private:
  49.647 -      void first(const ItemList &il) { l=&il; i = l->begin(); validate(); }
  49.648 -      void next() {
  49.649 -	++i; 
  49.650 -	validate();
  49.651 -      }
  49.652 -      void validate() {
  49.653 -	if ( i == l->end() ) 
  49.654 -	  i = 0;
  49.655 -      }
  49.656 -    };
  49.657 -
  49.658 -
  49.659 -
  49.660 -    /**
  49.661 -     * \brief Sets the iterator to point to the first element of the component.
  49.662 -     * 
  49.663 -     * \anchor first2 
  49.664 -     * Sets the iterator to point to the first element of the component.
  49.665 -     *
  49.666 -     * With the \ref first2 "first", \ref valid2 "valid" 
  49.667 -     * and \ref next2 "next" methods you can
  49.668 -     * iterate through the elements of a component. For example
  49.669 -     * (iterating through the component of the node \e node):
  49.670 -     * \code
  49.671 -     * Graph::Node node = ...;
  49.672 -     * UnionFindEnum<Graph::Node, Graph::NodeMap>::MapType map(G);
  49.673 -     * UnionFindEnum<Graph::Node, Graph::NodeMap> U(map);
  49.674 -     * UnionFindEnum<Graph::Node, Graph::NodeMap>::ItemIt iiter;
  49.675 -     *   for (U.first(iiter, node); U.valid(iiter); U.next(iiter)) {
  49.676 -     *     // iiter is convertible to Graph::Node
  49.677 -     *     cout << iiter << endl;
  49.678 -     *   }
  49.679 -     * \endcode
  49.680 -     */
  49.681 -    
  49.682 -    ItemIt& first(ItemIt& it, const T& a) const {
  49.683 -      it.first( * _find(m[a])->my_class );
  49.684 -      return it;
  49.685 -    }
  49.686 -
  49.687 -    /**
  49.688 -     * \brief Returns whether the iterator is valid.
  49.689 -     *
  49.690 -     * \anchor valid2
  49.691 -     * Returns whether the iterator is valid.
  49.692 -     *
  49.693 -     * With the \ref first2 "first", \ref valid2 "valid" 
  49.694 -     * and \ref next2 "next" methods you can
  49.695 -     * iterate through the elements of a component.
  49.696 -     * See the example here: \ref first2 "first".
  49.697 -     */
  49.698 -
  49.699 -    bool valid(ItemIt const &it) const {
  49.700 -      return it.valid(); 
  49.701 -    }
  49.702 -
  49.703 -    /**
  49.704 -     * \brief Steps the iterator to the next component. 
  49.705 -     *
  49.706 -     * \anchor next2
  49.707 -     * Steps the iterator to the next component.
  49.708 -     *
  49.709 -     * With the \ref first2 "first", \ref valid2 "valid" 
  49.710 -     * and \ref next2 "next" methods you can
  49.711 -     * iterate through the elements of a component.
  49.712 -     * See the example here: \ref first2 "first".
  49.713 -     */
  49.714 -
  49.715 -    ItemIt& next(ItemIt& it) const {
  49.716 -      it.next();
  49.717 -      return it;
  49.718 -    }
  49.719 -    
  49.720 -  };
  49.721 -
  49.722 -
  49.723 -  //! @}
  49.724 -
  49.725 -} //namespace hugo
  49.726 -
  49.727 -#endif //HUGO_UNION_FIND_H
    50.1 --- a/src/hugo/vector_map.h	Wed Sep 29 14:12:26 2004 +0000
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,243 +0,0 @@
    50.4 -/* -*- C++ -*-
    50.5 - * src/hugo/vector_map.h - Part of HUGOlib, a generic C++ optimization library
    50.6 - *
    50.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    50.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    50.9 - *
   50.10 - * Permission to use, modify and distribute this software is granted
   50.11 - * provided that this copyright notice appears in all copies. For
   50.12 - * precise terms see the accompanying LICENSE file.
   50.13 - *
   50.14 - * This software is provided "AS IS" with no warranty of any kind,
   50.15 - * express or implied, and with no claim as to its suitability for any
   50.16 - * purpose.
   50.17 - *
   50.18 - */
   50.19 -
   50.20 -#ifndef HUGO_VECTOR_MAP_H
   50.21 -#define HUGO_VECTOR_MAP_H
   50.22 -
   50.23 -#include <vector>
   50.24 -
   50.25 -#include <hugo/map_iterator.h>
   50.26 -#include <hugo/map_bits.h>
   50.27 -
   50.28 -///\ingroup graphmaps
   50.29 -///\file
   50.30 -///\brief Vector based graph maps.
   50.31 -
   50.32 -namespace hugo {
   50.33 -  
   50.34 -  /// \addtogroup graphmaps
   50.35 -  /// @{
   50.36 -  
   50.37 -  /** The ArrayMap template class is graph map structure what
   50.38 -   *  automatically updates the map when a key is added to or erased from
   50.39 -   *  the map. This map factory uses the allocators to implement 
   50.40 -   *  the container functionality. This map factory
   50.41 -   *  uses the std::vector to implement the container function.
   50.42 -   *
   50.43 -   *  The template parameter is the MapRegistry that the maps
   50.44 -   *  will belong to and the ValueType.
   50.45 -   * 
   50.46 -   * \todo It should use a faster initialization using the maxNodeId() or
   50.47 -   * maxEdgeId() function of the graph instead of iterating through each
   50.48 -   * edge/node.
   50.49 -   */
   50.50 -	
   50.51 -  template <typename MapRegistry, typename Value>
   50.52 -  class VectorMap : public MapRegistry::MapBase {
   50.53 -    template <typename MR, typename T> friend class VectorMap;
   50.54 -  public:
   50.55 -		
   50.56 -    /// The graph type of the maps. 
   50.57 -    typedef typename MapRegistry::Graph Graph;
   50.58 -    /// The key type of the maps.
   50.59 -    typedef typename MapRegistry::KeyType KeyType;
   50.60 -    /// The iterator to iterate on the keys.
   50.61 -    typedef typename MapRegistry::KeyIt KeyIt;
   50.62 -
   50.63 -    /// The map type.
   50.64 -    typedef VectorMap Map;
   50.65 -    /// The MapBase of the Map which implements the core regisitry function.
   50.66 -    typedef typename MapRegistry::MapBase MapBase;
   50.67 -
   50.68 -  private:
   50.69 -		
   50.70 -    /// The container type of the map.
   50.71 -    typedef std::vector<Value> Container;	
   50.72 -
   50.73 -  public:
   50.74 -
   50.75 -
   50.76 -    /// The value type of the map.
   50.77 -    typedef Value ValueType;
   50.78 -    /// The reference type of the map;
   50.79 -    typedef typename Container::reference ReferenceType;
   50.80 -    /// The pointer type of the map;
   50.81 -    typedef typename Container::pointer PointerType;
   50.82 -
   50.83 -    /// The const value type of the map.
   50.84 -    typedef const Value ConstValueType;
   50.85 -    /// The const reference type of the map;
   50.86 -    typedef typename Container::const_reference ConstReferenceType;
   50.87 -    /// The pointer type of the map;
   50.88 -    typedef typename Container::const_pointer ConstPointerType;
   50.89 -
   50.90 -    /** Graph and Registry initialized map constructor.
   50.91 -     */
   50.92 -    VectorMap(const Graph& g, MapRegistry& r) 
   50.93 -      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
   50.94 -
   50.95 -    /** Constructor to use default value to initialize the map. 
   50.96 -     */
   50.97 -    VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
   50.98 -      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
   50.99 -
  50.100 -    /** Assign operator to copy a map of an other map type.
  50.101 -     */
  50.102 -    template <typename TT>
  50.103 -    VectorMap(const VectorMap<MapRegistry, TT>& c) 
  50.104 -      : MapBase(c), container(c.container.size()) {
  50.105 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  50.106 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  50.107 -	container[id] = c.container[id];
  50.108 -      }
  50.109 -    }
  50.110 -
  50.111 -    /** Assign operator to copy a map of an other map type.
  50.112 -     */
  50.113 -    template <typename TT>
  50.114 -    VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
  50.115 -      if (MapBase::getGraph() != c.getGraph()) {
  50.116 -	MapBase::operator=(c);
  50.117 -	container.resize(c.container.size());
  50.118 -      }
  50.119 -      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  50.120 -	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  50.121 -	container[id] = c.container[id];
  50.122 -      }
  50.123 -      return *this;
  50.124 -    }
  50.125 -    /**
  50.126 -     * The subscript operator. The map can be subscripted by the
  50.127 -     * actual keys of the graph. 
  50.128 -     */
  50.129 -    ReferenceType operator[](const KeyType& key) {
  50.130 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  50.131 -      return container[id];
  50.132 -    } 
  50.133 -		
  50.134 -    /**
  50.135 -     * The const subscript operator. The map can be subscripted by the
  50.136 -     * actual keys of the graph. 
  50.137 -     */
  50.138 -    ConstReferenceType operator[](const KeyType& key) const {
  50.139 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  50.140 -      return container[id];
  50.141 -    }
  50.142 -
  50.143 -    /** Setter function of the map. Equivalent with map[key] = val.
  50.144 -     *  This is a compatibility feature with the not dereferable maps.
  50.145 -     */
  50.146 -    void set(const KeyType& key, const ValueType& val) {
  50.147 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  50.148 -      container[id] = val;
  50.149 -    }
  50.150 -		
  50.151 -    /** Add a new key to the map. It called by the map registry.
  50.152 -     */
  50.153 -    void add(const KeyType& key) {
  50.154 -      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  50.155 -      if (id >= (int)container.size()) {
  50.156 -	container.resize(id + 1);
  50.157 -      }
  50.158 -    }
  50.159 -		
  50.160 -    /** Erase a key from the map. It called by the map registry.
  50.161 -     */
  50.162 -    void erase(const KeyType& key) {}
  50.163 -
  50.164 -    /** Clear the data structure.
  50.165 -     */
  50.166 -    void clear() { 
  50.167 -      container.clear();
  50.168 -    }
  50.169 -
  50.170 -    /// The stl compatible pair iterator of the map.
  50.171 -    typedef MapIterator<VectorMap> Iterator;
  50.172 -    /// The stl compatible const pair iterator of the map.
  50.173 -    typedef MapConstIterator<VectorMap> ConstIterator;
  50.174 -
  50.175 -    /** Returns the begin iterator of the map.
  50.176 -     */
  50.177 -    Iterator begin() {
  50.178 -      return Iterator(*this, KeyIt(*MapBase::getGraph()));
  50.179 -    }
  50.180 -
  50.181 -    /** Returns the end iterator of the map.
  50.182 -     */
  50.183 -    Iterator end() {
  50.184 -      return Iterator(*this, INVALID);
  50.185 -    }
  50.186 -
  50.187 -    /** Returns the begin ConstIterator of the map.
  50.188 -     */
  50.189 -    ConstIterator begin() const {
  50.190 -      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
  50.191 -    }
  50.192 -
  50.193 -    /** Returns the end const_iterator of the map.
  50.194 -     */
  50.195 -    ConstIterator end() const {
  50.196 -      return ConstIterator(*this, INVALID);
  50.197 -    }
  50.198 -
  50.199 -    /// The KeySet of the Map.
  50.200 -    typedef MapConstKeySet<VectorMap> ConstKeySet;
  50.201 -
  50.202 -    /// KeySet getter function.
  50.203 -    ConstKeySet keySet() const {
  50.204 -      return ConstKeySet(*this); 
  50.205 -    }
  50.206 -
  50.207 -    /// The ConstValueSet of the Map.
  50.208 -    typedef MapConstValueSet<VectorMap> ConstValueSet;
  50.209 -
  50.210 -    /// ConstValueSet getter function.
  50.211 -    ConstValueSet valueSet() const {
  50.212 -      return ConstValueSet(*this);
  50.213 -    }
  50.214 -
  50.215 -    /// The ValueSet of the Map.
  50.216 -    typedef MapValueSet<VectorMap> ValueSet;
  50.217 -
  50.218 -    /// ValueSet getter function.
  50.219 -    ValueSet valueSet() {
  50.220 -      return ValueSet(*this);
  50.221 -    }
  50.222 -
  50.223 -
  50.224 -  private:
  50.225 -		
  50.226 -    Container container;
  50.227 -
  50.228 -  public:
  50.229 -    // STL  compatibility typedefs.
  50.230 -    typedef Iterator iterator;
  50.231 -    typedef ConstIterator const_iterator;
  50.232 -    typedef typename Iterator::PairValueType value_type;
  50.233 -    typedef typename Iterator::KeyType key_type;
  50.234 -    typedef typename Iterator::ValueType data_type;
  50.235 -    typedef typename Iterator::PairReferenceType reference;
  50.236 -    typedef typename Iterator::PairPointerType pointer;
  50.237 -    typedef typename ConstIterator::PairReferenceType const_reference;
  50.238 -    typedef typename ConstIterator::PairPointerType const_pointer;
  50.239 -    typedef int difference_type;		
  50.240 -  };
  50.241 -  
  50.242 -  /// @}
  50.243 -  
  50.244 -}
  50.245 -
  50.246 -#endif
    51.1 --- a/src/hugo/xy.h	Wed Sep 29 14:12:26 2004 +0000
    51.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.3 @@ -1,248 +0,0 @@
    51.4 -/* -*- C++ -*-
    51.5 - * src/hugo/xy.h - Part of HUGOlib, a generic C++ optimization library
    51.6 - *
    51.7 - * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    51.8 - * (Egervary Combinatorial Optimization Research Group, EGRES).
    51.9 - *
   51.10 - * Permission to use, modify and distribute this software is granted
   51.11 - * provided that this copyright notice appears in all copies. For
   51.12 - * precise terms see the accompanying LICENSE file.
   51.13 - *
   51.14 - * This software is provided "AS IS" with no warranty of any kind,
   51.15 - * express or implied, and with no claim as to its suitability for any
   51.16 - * purpose.
   51.17 - *
   51.18 - */
   51.19 -
   51.20 -#ifndef HUGO_XY_H
   51.21 -#define HUGO_XY_H
   51.22 -
   51.23 -#include <iostream>
   51.24 -
   51.25 -///\ingroup misc
   51.26 -///\file
   51.27 -///\brief A simple two dimensional vector and a bounding box implementation 
   51.28 -///
   51.29 -/// The class \ref hugo::xy "xy" implements
   51.30 -///a two dimensional vector with the usual
   51.31 -/// operations.
   51.32 -///
   51.33 -/// The class \ref hugo::BoundingBox "BoundingBox" can be used to determine
   51.34 -/// the rectangular bounding box a set of \ref hugo::xy "xy"'s.
   51.35 -///
   51.36 -///\author Attila Bernath
   51.37 -
   51.38 -
   51.39 -namespace hugo {
   51.40 -
   51.41 -  /// \addtogroup misc
   51.42 -  /// @{
   51.43 -
   51.44 -  /// A two dimensional vector (plainvector) implementation
   51.45 -
   51.46 -  /// A two dimensional vector (plainvector) implementation
   51.47 -  ///with the usual vector
   51.48 -  /// operators.
   51.49 -  ///
   51.50 -  ///\author Attila Bernath
   51.51 -  template<typename T>
   51.52 -    class xy {
   51.53 -
   51.54 -    public:
   51.55 -
   51.56 -      T x,y;     
   51.57 -      
   51.58 -      ///Default constructor: both coordinates become 0
   51.59 -      xy() : x(0), y(0) {}
   51.60 -
   51.61 -      ///Constructing the instance from coordinates
   51.62 -      xy(T a, T b) : x(a), y(b) { }
   51.63 -
   51.64 -
   51.65 -      ///Gives back the square of the norm of the vector
   51.66 -      T normSquare(){
   51.67 -	return x*x+y*y;
   51.68 -      };
   51.69 -  
   51.70 -      ///Increments the left hand side by u
   51.71 -      xy<T>& operator +=(const xy<T>& u){
   51.72 -	x += u.x;
   51.73 -	y += u.y;
   51.74 -	return *this;
   51.75 -      };
   51.76 -  
   51.77 -      ///Decrements the left hand side by u
   51.78 -      xy<T>& operator -=(const xy<T>& u){
   51.79 -	x -= u.x;
   51.80 -	y -= u.y;
   51.81 -	return *this;
   51.82 -      };
   51.83 -
   51.84 -      ///Multiplying the left hand side with a scalar
   51.85 -      xy<T>& operator *=(const T &u){
   51.86 -	x *= u;
   51.87 -	y *= u;
   51.88 -	return *this;
   51.89 -      };
   51.90 -
   51.91 -      ///Dividing the left hand side by a scalar
   51.92 -      xy<T>& operator /=(const T &u){
   51.93 -	x /= u;
   51.94 -	y /= u;
   51.95 -	return *this;
   51.96 -      };
   51.97 -  
   51.98 -      ///Returns the scalar product of two vectors
   51.99 -      T operator *(const xy<T>& u){
  51.100 -	return x*u.x+y*u.y;
  51.101 -      };
  51.102 -  
  51.103 -      ///Returns the sum of two vectors
  51.104 -      xy<T> operator+(const xy<T> &u) const {
  51.105 -	xy<T> b=*this;
  51.106 -	return b+=u;
  51.107 -      };
  51.108 -
  51.109 -      ///Returns the difference of two vectors
  51.110 -      xy<T> operator-(const xy<T> &u) const {
  51.111 -	xy<T> b=*this;
  51.112 -	return b-=u;
  51.113 -      };
  51.114 -
  51.115 -      ///Returns a vector multiplied by a scalar
  51.116 -      xy<T> operator*(const T &u) const {
  51.117 -	xy<T> b=*this;
  51.118 -	return b*=u;
  51.119 -      };
  51.120 -
  51.121 -      ///Returns a vector divided by a scalar
  51.122 -      xy<T> operator/(const T &u) const {
  51.123 -	xy<T> b=*this;
  51.124 -	return b/=u;
  51.125 -      };
  51.126 -
  51.127 -      ///Testing equality
  51.128 -      bool operator==(const xy<T> &u){
  51.129 -	return (x==u.x) && (y==u.y);
  51.130 -      };
  51.131 -
  51.132 -      ///Testing inequality
  51.133 -      bool operator!=(xy u){
  51.134 -	return  (x!=u.x) || (y!=u.y);
  51.135 -      };
  51.136 -
  51.137 -    };
  51.138 -
  51.139 -  ///Read a plainvector from a stream
  51.140 -
  51.141 -  ///\relates xy
  51.142 -  ///
  51.143 -  template<typename T>
  51.144 -  inline
  51.145 -  std::istream& operator>>(std::istream &is, xy<T> &z)
  51.146 -  {
  51.147 -
  51.148 -    is >> z.x >> z.y;
  51.149 -    return is;
  51.150 -  }
  51.151 -
  51.152 -  ///Write a plainvector to a stream
  51.153 -
  51.154 -  ///\relates xy
  51.155 -  ///
  51.156 -  template<typename T>
  51.157 -  inline
  51.158 -  std::ostream& operator<<(std::ostream &os, xy<T> z)
  51.159 -  {
  51.160 -    os << "(" << z.x << ", " << z.y << ")";
  51.161 -    return os;
  51.162 -  }
  51.163 -
  51.164 -
  51.165 -  /// A class to calculate or store the bounding box of plainvectors.
  51.166 -
  51.167 -  /// A class to calculate or store the bounding box of plainvectors.
  51.168 -  ///
  51.169 -  ///\author Attila Bernath
  51.170 -  template<typename T>
  51.171 -    class BoundingBox {
  51.172 -      xy<T> bottom_left, top_right;
  51.173 -      bool _empty;
  51.174 -    public:
  51.175 -      
  51.176 -      ///Default constructor: an empty bounding box
  51.177 -      BoundingBox() { _empty = true; }
  51.178 -
  51.179 -      ///Constructing the instance from one point
  51.180 -      BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
  51.181 -
  51.182 -      ///Is there any point added
  51.183 -      bool empty() const {
  51.184 -	return _empty;
  51.185 -      }
  51.186 -
  51.187 -      ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined) 
  51.188 -      xy<T> bottomLeft() const {
  51.189 -	return bottom_left;
  51.190 -      };
  51.191 -
  51.192 -      ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined) 
  51.193 -      xy<T> topRight() const {
  51.194 -	return top_right;
  51.195 -      };
  51.196 -
  51.197 -      ///Checks whether a point is inside a bounding box
  51.198 -      bool inside(const xy<T>& u){
  51.199 -	if (_empty)
  51.200 -	  return false;
  51.201 -	else{
  51.202 -	  return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
  51.203 -		  (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
  51.204 -	}
  51.205 -      }
  51.206 -  
  51.207 -      ///Increments a bounding box with a point
  51.208 -      BoundingBox& operator +=(const xy<T>& u){
  51.209 -	if (_empty){
  51.210 -	  bottom_left=top_right=u;
  51.211 -	  _empty = false;
  51.212 -	}
  51.213 -	else{
  51.214 -	  if (bottom_left.x > u.x) bottom_left.x = u.x;
  51.215 -	  if (bottom_left.y > u.y) bottom_left.y = u.y;
  51.216 -	  if (top_right.x < u.x) top_right.x = u.x;
  51.217 -	  if (top_right.y < u.y) top_right.y = u.y;
  51.218 -	}
  51.219 -	return *this;
  51.220 -      };
  51.221 -  
  51.222 -      ///Sums a bounding box and a point
  51.223 -      BoundingBox operator +(const xy<T>& u){
  51.224 -	BoundingBox b = *this;
  51.225 -	return b += u;
  51.226 -      };
  51.227 -
  51.228 -      ///Increments a bounding box with an other bounding box
  51.229 -      BoundingBox& operator +=(const BoundingBox &u){
  51.230 -	if ( !u.empty() ){
  51.231 -	  *this += u.bottomLeft();
  51.232 -	  *this += u.topRight();
  51.233 -	}
  51.234 -	return *this;
  51.235 -      };
  51.236 -  
  51.237 -      ///Sums two bounding boxes
  51.238 -      BoundingBox operator +(const BoundingBox& u){
  51.239 -	BoundingBox b = *this;
  51.240 -	return b += u;
  51.241 -      };
  51.242 -
  51.243 -    };//class Boundingbox
  51.244 -
  51.245 -
  51.246 -  /// @}
  51.247 -
  51.248 -
  51.249 -} //namespace hugo
  51.250 -
  51.251 -#endif //HUGO_XY_H
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/src/lemon/Makefile.am	Wed Sep 29 15:30:04 2004 +0000
    52.3 @@ -0,0 +1,35 @@
    52.4 +pkginclude_HEADERS =							\
    52.5 +	array_map.h                                                     \
    52.6 +	bfs.h                                                           \
    52.7 +	dfs.h                                                           \
    52.8 +	bin_heap.h							\
    52.9 +	default_map.h							\
   52.10 +	dijkstra.h							\
   52.11 +	dimacs.h							\
   52.12 +	extended_pair.h                                                 \
   52.13 +	fib_heap.h							\
   52.14 +	full_graph.h							\
   52.15 +	graph_wrapper.h							\
   52.16 +	invalid.h							\
   52.17 +	kruskal.h							\
   52.18 +	list_graph.h							\
   52.19 +	map_defines.h                                                   \
   52.20 +	map_iterator.h                                                  \
   52.21 +	map_registry.h                                                  \
   52.22 +	map_bits.h							\
   52.23 +	maps.h								\
   52.24 +	min_cost_flow.h                                                \
   52.25 +	suurballe.h                                                     \
   52.26 +	preflow.h                                                       \
   52.27 +	path.h                                                          \
   52.28 +	smart_graph.h							\
   52.29 +	sym_map.h                                                       \
   52.30 +	time_measure.h							\
   52.31 +	unionfind.h							\
   52.32 +	vector_map.h                                                    \
   52.33 +	xy.h
   52.34 +
   52.35 +noinst_HEADERS =							\
   52.36 +	skeletons/graph.h						\
   52.37 +	skeletons/maps.h                                                \
   52.38 +	skeletons/path.h
    53.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.2 +++ b/src/lemon/array_map.h	Wed Sep 29 15:30:04 2004 +0000
    53.3 @@ -0,0 +1,349 @@
    53.4 +/* -*- C++ -*-
    53.5 + * src/lemon/array_map.h - Part of LEMON, a generic C++ optimization library
    53.6 + *
    53.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    53.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    53.9 + *
   53.10 + * Permission to use, modify and distribute this software is granted
   53.11 + * provided that this copyright notice appears in all copies. For
   53.12 + * precise terms see the accompanying LICENSE file.
   53.13 + *
   53.14 + * This software is provided "AS IS" with no warranty of any kind,
   53.15 + * express or implied, and with no claim as to its suitability for any
   53.16 + * purpose.
   53.17 + *
   53.18 + */
   53.19 +
   53.20 +#ifndef LEMON_ARRAY_MAP_H
   53.21 +#define LEMON_ARRAY_MAP_H
   53.22 +
   53.23 +#include <memory>
   53.24 +
   53.25 +#include <lemon/map_iterator.h>
   53.26 +#include <lemon/map_bits.h>
   53.27 +
   53.28 +///\ingroup graphmaps
   53.29 +///\file
   53.30 +///\brief Graph maps that construates and destruates
   53.31 +///their elements dynamically.
   53.32 +
   53.33 +namespace lemon {
   53.34 +
   53.35 +
   53.36 +  /// \addtogroup graphmaps
   53.37 +  /// @{
   53.38 +	
   53.39 +  /** The ArrayMap template class is graph map structure what
   53.40 +   *  automatically updates the map when a key is added to or erased from
   53.41 +   *  the map. This map factory uses the allocators to implement 
   53.42 +   *  the container functionality.
   53.43 +   *
   53.44 +   *  The template parameter is the MapRegistry that the maps
   53.45 +   *  will belong to and the ValueType.
   53.46 +   */
   53.47 +
   53.48 +  template <typename MapRegistry, typename Value> 
   53.49 +  class ArrayMap : public MapRegistry::MapBase {
   53.50 +
   53.51 +    template <typename MR, typename V> friend class ArrayMap;
   53.52 +		
   53.53 +  public:
   53.54 +		
   53.55 +    /// The graph type of the maps. 
   53.56 +    typedef typename MapRegistry::Graph Graph;
   53.57 +    /// The key type of the maps.
   53.58 +    typedef typename MapRegistry::KeyType KeyType;
   53.59 +    /// The iterator to iterate on the keys.
   53.60 +    typedef typename MapRegistry::KeyIt KeyIt;
   53.61 +
   53.62 +    /// The MapBase of the Map which imlements the core regisitry function.
   53.63 +    typedef typename MapRegistry::MapBase MapBase;
   53.64 +		
   53.65 +    
   53.66 +  public:
   53.67 +
   53.68 +    /// The value type of the map.
   53.69 +    typedef Value ValueType;
   53.70 +    /// The reference type of the map;
   53.71 +    typedef Value& ReferenceType;
   53.72 +    /// The pointer type of the map;
   53.73 +    typedef Value* PointerType;
   53.74 +
   53.75 +    /// The const value type of the map.
   53.76 +    typedef const Value ConstValueType;
   53.77 +    /// The const reference type of the map;
   53.78 +    typedef const Value& ConstReferenceType;
   53.79 +    /// The pointer type of the map;
   53.80 +    typedef const Value* ConstPointerType;
   53.81 +
   53.82 +
   53.83 +    typedef std::allocator<Value> Allocator;
   53.84 +
   53.85 +	
   53.86 +    /** Graph and Registry initialized map constructor.
   53.87 +     */
   53.88 +    ArrayMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
   53.89 +      allocate_memory();
   53.90 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
   53.91 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
   53.92 +	allocator.construct(&(values[id]), Value());
   53.93 +      }								
   53.94 +    }
   53.95 +
   53.96 +    /** Constructor to use default value to initialize the map. 
   53.97 +     */
   53.98 +    ArrayMap(const Graph& g, MapRegistry& r, const Value& v) 
   53.99 +      : MapBase(g, r) {
  53.100 +      allocate_memory();
  53.101 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.102 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.103 +	allocator.construct(&(values[id]), v);
  53.104 +      }								
  53.105 +    }
  53.106 +
  53.107 +    /** Constructor to copy a map of the same map type.
  53.108 +     */
  53.109 +    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
  53.110 +      capacity = copy.capacity;
  53.111 +      if (capacity == 0) return;
  53.112 +      values = allocator.allocate(capacity);
  53.113 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.114 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.115 +	allocator.construct(&(values[id]), copy.values[id]);
  53.116 +      }
  53.117 +    }
  53.118 +
  53.119 +    /** Constructor to copy a map of an other map type.
  53.120 +     */
  53.121 +    template <typename TT>
  53.122 +    ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 
  53.123 +      : MapBase(copy) {
  53.124 +      capacity = copy.capacity;
  53.125 +      if (capacity == 0) return;
  53.126 +      values = allocator.allocate(capacity);
  53.127 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.128 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.129 +	allocator.construct(&(values[id]), copy.values[id]);
  53.130 +      }
  53.131 +    }
  53.132 +
  53.133 +    /** Assign operator to copy a map of the same map type.
  53.134 +     */
  53.135 +    ArrayMap& operator=(const ArrayMap& copy) {
  53.136 +      if (&copy == this) return *this;
  53.137 +      
  53.138 +      if (MapBase::getGraph() != copy.getGraph()) {
  53.139 +	if (capacity != 0) {
  53.140 +	  MapBase::destroy();
  53.141 +	  allocator.deallocate(values, capacity);
  53.142 +	}
  53.143 +
  53.144 +	MapBase::operator=(copy);
  53.145 +	capacity = copy.capacity;
  53.146 +	if (capacity == 0) return *this;
  53.147 +	values = allocator.allocate(capacity);      
  53.148 +      }
  53.149 +
  53.150 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.151 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.152 +	allocator.construct(&(values[id]), copy.values[id]);
  53.153 +      }
  53.154 +
  53.155 +      return *this;
  53.156 +    }
  53.157 +
  53.158 +    /** Assign operator to copy a map of an other map type.
  53.159 +     */
  53.160 +    template <typename TT>
  53.161 +    ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) {
  53.162 +
  53.163 +      if (MapBase::getGraph() != copy.getGraph()) {
  53.164 +	if (capacity != 0) {
  53.165 +	  MapBase::destroy();
  53.166 +	  allocator.deallocate(values, capacity);
  53.167 +	}
  53.168 +
  53.169 +	MapBase::operator=(copy);
  53.170 +
  53.171 +	capacity = copy.capacity;
  53.172 +	if (capacity == 0) return *this;
  53.173 +	values = allocator.allocate(capacity);
  53.174 +      }
  53.175 +
  53.176 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.177 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.178 +	allocator.construct(&(values[id]), copy.values[id]);
  53.179 +      }
  53.180 +
  53.181 +      return *this;
  53.182 +    }
  53.183 +				
  53.184 +    /** The destructor of the map.
  53.185 +     */
  53.186 +    virtual ~ArrayMap() {
  53.187 +      if (capacity != 0) {
  53.188 +	MapBase::destroy();
  53.189 +	allocator.deallocate(values, capacity);
  53.190 +      }
  53.191 +    }
  53.192 +	
  53.193 +	
  53.194 +    /**
  53.195 +     * The subscript operator. The map can be subscripted by the
  53.196 +     * actual keys of the graph. 
  53.197 +     */
  53.198 +    ReferenceType operator[](const KeyType& key) {
  53.199 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  53.200 +      return values[id];
  53.201 +    } 
  53.202 +		
  53.203 +    /**
  53.204 +     * The const subscript operator. The map can be subscripted by the
  53.205 +     * actual keys of the graph. 
  53.206 +     */
  53.207 +    ConstReferenceType operator[](const KeyType& key) const {
  53.208 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  53.209 +      return values[id];
  53.210 +    }
  53.211 +	
  53.212 +    /** Setter function of the map. Equivalent with map[key] = val.
  53.213 +     *  This is a compatibility feature with the not dereferable maps.
  53.214 +     */
  53.215 +    void set(const KeyType& key, const ValueType& val) {
  53.216 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  53.217 +      values[id] = val;
  53.218 +    }
  53.219 +		
  53.220 +    /** Add a new key to the map. It called by the map registry.
  53.221 +     */
  53.222 +    void add(const KeyType& key) {
  53.223 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  53.224 +      if (id >= capacity) {
  53.225 +	int new_capacity = (capacity == 0 ? 1 : capacity);
  53.226 +	while (new_capacity <= id) {
  53.227 +	  new_capacity <<= 1;
  53.228 +	}
  53.229 +	Value* new_values = allocator.allocate(new_capacity);;
  53.230 +	for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  53.231 +	  int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  53.232 +	  if (id != jd) {
  53.233 +	    allocator.construct(&(new_values[jd]), values[jd]);
  53.234 +	    allocator.destroy(&(values[jd]));
  53.235 +	  }
  53.236 +	}
  53.237 +	if (capacity != 0) allocator.deallocate(values, capacity);
  53.238 +	values = new_values;
  53.239 +	capacity = new_capacity;
  53.240 +      }
  53.241 +      allocator.construct(&(values[id]), Value());
  53.242 +    }
  53.243 +		
  53.244 +    /** Erase a key from the map. It called by the map registry.
  53.245 +     */
  53.246 +    void erase(const KeyType& key) {
  53.247 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  53.248 +      allocator.destroy(&(values[id]));
  53.249 +    }
  53.250 +
  53.251 +    /** Clear the data structure.
  53.252 +     */
  53.253 +    void clear() {	
  53.254 +      if (capacity != 0) {
  53.255 +	MapBase::destroy();
  53.256 +	allocator.deallocate(values, capacity);
  53.257 +	capacity = 0;
  53.258 +      }
  53.259 +    }
  53.260 +
  53.261 +    /// The stl compatible pair iterator of the map.
  53.262 +    typedef MapIterator<ArrayMap> Iterator;
  53.263 +    /// The stl compatible const pair iterator of the map.
  53.264 +    typedef MapConstIterator<ArrayMap> ConstIterator;
  53.265 +
  53.266 +    /** Returns the begin iterator of the map.
  53.267 +     */
  53.268 +    Iterator begin() {
  53.269 +      return Iterator(*this, KeyIt(*MapBase::getGraph()));
  53.270 +    }
  53.271 +
  53.272 +    /** Returns the end iterator of the map.
  53.273 +     */
  53.274 +    Iterator end() {
  53.275 +      return Iterator(*this, INVALID);
  53.276 +    }
  53.277 +
  53.278 +    /** Returns the begin ConstIterator of the map.
  53.279 +     */
  53.280 +    ConstIterator begin() const {
  53.281 +      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
  53.282 +    }
  53.283 +
  53.284 +    /** Returns the end const_iterator of the map.
  53.285 +     */
  53.286 +    ConstIterator end() const {
  53.287 +      return ConstIterator(*this, INVALID);
  53.288 +    }
  53.289 +
  53.290 +    /// The KeySet of the Map.
  53.291 +    typedef MapConstKeySet<ArrayMap> ConstKeySet;
  53.292 +
  53.293 +    /// KeySet getter function.
  53.294 +    ConstKeySet keySet() const {
  53.295 +      return ConstKeySet(*this); 
  53.296 +    }
  53.297 +
  53.298 +    /// The ConstValueSet of the Map.
  53.299 +    typedef MapConstValueSet<ArrayMap> ConstValueSet;
  53.300 +
  53.301 +    /// ConstValueSet getter function.
  53.302 +    ConstValueSet valueSet() const {
  53.303 +      return ConstValueSet(*this);
  53.304 +    }
  53.305 +
  53.306 +    /// The ValueSet of the Map.
  53.307 +    typedef MapValueSet<ArrayMap> ValueSet;
  53.308 +
  53.309 +    /// ValueSet getter function.
  53.310 +    ValueSet valueSet() {
  53.311 +      return ValueSet(*this);
  53.312 +    }
  53.313 +
  53.314 +  private:
  53.315 +      
  53.316 +    void allocate_memory() {
  53.317 +      int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
  53.318 +      if (max_id == -1) {
  53.319 +	capacity = 0;
  53.320 +	values = 0;
  53.321 +	return;
  53.322 +      }
  53.323 +      capacity = 1;
  53.324 +      while (capacity <= max_id) {
  53.325 +	capacity <<= 1;
  53.326 +      }
  53.327 +      values = allocator.allocate(capacity);	
  53.328 +    }      
  53.329 +
  53.330 +    int capacity;
  53.331 +    Value* values;
  53.332 +    Allocator allocator;
  53.333 +
  53.334 +  public:
  53.335 +    // STL  compatibility typedefs.
  53.336 +    typedef Iterator iterator;
  53.337 +    typedef ConstIterator const_iterator;
  53.338 +    typedef typename Iterator::PairValueType value_type;
  53.339 +    typedef typename Iterator::KeyType key_type;
  53.340 +    typedef typename Iterator::ValueType data_type;
  53.341 +    typedef typename Iterator::PairReferenceType reference;
  53.342 +    typedef typename Iterator::PairPointerType pointer;
  53.343 +    typedef typename ConstIterator::PairReferenceType const_reference;
  53.344 +    typedef typename ConstIterator::PairPointerType const_pointer;
  53.345 +    typedef int difference_type;		
  53.346 +  };		
  53.347 +
  53.348 +/// @}
  53.349 +
  53.350 +}
  53.351 +
  53.352 +#endif //LEMON_ARRAY_MAP_H
    54.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    54.2 +++ b/src/lemon/attic/debug.h	Wed Sep 29 15:30:04 2004 +0000
    54.3 @@ -0,0 +1,70 @@
    54.4 +/* -*- C++ -*-
    54.5 + * src/lemon/debug.h - Part of LEMON, a generic C++ optimization library
    54.6 + *
    54.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    54.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    54.9 + *
   54.10 + * Permission to use, modify and distribute this software is granted
   54.11 + * provided that this copyright notice appears in all copies. For
   54.12 + * precise terms see the accompanying LICENSE file.
   54.13 + *
   54.14 + * This software is provided "AS IS" with no warranty of any kind,
   54.15 + * express or implied, and with no claim as to its suitability for any
   54.16 + * purpose.
   54.17 + *
   54.18 + */
   54.19 +
   54.20 +#ifndef LEMON_DEBUG_H
   54.21 +#define LEMON_DEBUG_H
   54.22 +
   54.23 +//! \file
   54.24 +//! \brief Basic definitions for debug control.
   54.25 +
   54.26 +namespace lemon {
   54.27 +
   54.28 +  //! Debug mode for testing/debugging
   54.29 +
   54.30 +  //! Use this debug mode if you want exhaustive range and consistency checks.
   54.31 +  //! It also produces verbose debug messages.
   54.32 +  struct DebugOn {
   54.33 +    //! Example: check whether the edges added to a path are adjacent
   54.34 +    static const bool consistensy_check = true;
   54.35 +
   54.36 +    static const bool range_check = true;
   54.37 +
   54.38 +    //! Examples: initialize maps with some value;
   54.39 +    //! after deleting an item from UnionFindEnum set its value in the
   54.40 +    //! corresponding map to NULL...
   54.41 +    static const bool ensure_safe_state = true;
   54.42 +
   54.43 +    static const int verbose = 5;
   54.44 +  };
   54.45 +
   54.46 +  //! Debug mode for turning off debug aids.
   54.47 +
   54.48 +  //! This debud mode switches off all range and consistency checks,
   54.49 +  //! as well as the debug messages.
   54.50 +  //!
   54.51 +  struct DebugOff {
   54.52 +    static const bool consistensy_check = false;
   54.53 +    static const bool range_check = false;
   54.54 +    static const bool ensure_safe_state = false;
   54.55 +    static const int verbose = 0;
   54.56 +  };
   54.57 +
   54.58 +#ifdef DEBUG
   54.59 +  //! The default debug mode.
   54.60 +
   54.61 +  //! The default debug mode.
   54.62 +  //!
   54.63 +  typedef DebugOn DefaultDebugMode;
   54.64 +#else
   54.65 +  //! The default debug mode. 
   54.66 +
   54.67 +  //! The default debug mode. 
   54.68 +  //!
   54.69 +  typedef DebugOff DefaultDebugMode;
   54.70 +#endif
   54.71 +
   54.72 +}
   54.73 +#endif // LEMON_DEBUG_H
    55.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    55.2 +++ b/src/lemon/attic/error.h	Wed Sep 29 15:30:04 2004 +0000
    55.3 @@ -0,0 +1,82 @@
    55.4 +/* -*- C++ -*-
    55.5 + * src/lemon/error.h - Part of LEMON, a generic C++ optimization library
    55.6 + *
    55.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    55.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    55.9 + *
   55.10 + * Permission to use, modify and distribute this software is granted
   55.11 + * provided that this copyright notice appears in all copies. For
   55.12 + * precise terms see the accompanying LICENSE file.
   55.13 + *
   55.14 + * This software is provided "AS IS" with no warranty of any kind,
   55.15 + * express or implied, and with no claim as to its suitability for any
   55.16 + * purpose.
   55.17 + *
   55.18 + */
   55.19 +
   55.20 +#ifndef LEMON_ERROR_H
   55.21 +#define LEMON_ERROR_H
   55.22 +
   55.23 +//! \ingroup misc
   55.24 +//! \file
   55.25 +//! \brief Basic error handling (signaling) routines.
   55.26 +
   55.27 +#include <exception>
   55.28 +#include <string>
   55.29 +#include <sstream>
   55.30 +
   55.31 +
   55.32 +namespace lemon {
   55.33 +
   55.34 +  /**
   55.35 +   * \brief Generic exception class.
   55.36 +   *
   55.37 +   * \todo Do we need this?
   55.38 +   *
   55.39 +   * \todo Don't we need different kind of exceptions for different kind
   55.40 +   * of errors?
   55.41 +   * Shouldn't we use \<stdexcept\> instead?
   55.42 +   */
   55.43 +  class Exception : public std::exception {
   55.44 +  protected:
   55.45 +    std::ostringstream buf;
   55.46 +  public:
   55.47 +    Exception() {}
   55.48 +    explicit Exception(const std::string &s) { buf << s; }
   55.49 +    Exception(const Exception &e) : std::exception() {
   55.50 +      buf << e.buf.str();
   55.51 +    }
   55.52 +    virtual ~Exception() throw() {}
   55.53 +    
   55.54 +    virtual const char* what() const throw() {
   55.55 +      return buf.str().c_str();
   55.56 +    }
   55.57 +
   55.58 +    Exception& operator<<(std::string const& s) { buf << s; return *this; }
   55.59 +    Exception& operator<<(char const *s) { buf << s; return *this; }
   55.60 +    Exception& operator<<(int i) { buf << i; return *this; }
   55.61 +  };
   55.62 +
   55.63 +  /**
   55.64 +   * \brief Generic error signaling function.
   55.65 +   *
   55.66 +   * \todo Do we really need this? Is it helpful?
   55.67 +   */
   55.68 +  inline void fault(const std::string &msg) {
   55.69 +    throw Exception(msg);
   55.70 +  }
   55.71 +
   55.72 +  /**
   55.73 +   * \brief Macro for mark not yet implemented features.
   55.74 +   *
   55.75 +   * \todo Is this the right place for this? It should be used only in
   55.76 +   * modules under development.
   55.77 +   */
   55.78 +
   55.79 +# define FIXME(msg) \
   55.80 +    do { throw ::lemon::Exception() << "FIXME: " msg " (in: "    \
   55.81 +      __FILE__ ", " << __LINE__ << ")";                         \
   55.82 +    } while(false)
   55.83 +
   55.84 +}
   55.85 +#endif // LEMON_ERROR_H
    56.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.2 +++ b/src/lemon/attic/tight_edge_filter_map.h	Wed Sep 29 15:30:04 2004 +0000
    56.3 @@ -0,0 +1,63 @@
    56.4 +/* -*- C++ -*-
    56.5 + * src/lemon/tight_edge_filter_map.h - Part of LEMON, a generic C++ optimization library
    56.6 + *
    56.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    56.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    56.9 + *
   56.10 + * Permission to use, modify and distribute this software is granted
   56.11 + * provided that this copyright notice appears in all copies. For
   56.12 + * precise terms see the accompanying LICENSE file.
   56.13 + *
   56.14 + * This software is provided "AS IS" with no warranty of any kind,
   56.15 + * express or implied, and with no claim as to its suitability for any
   56.16 + * purpose.
   56.17 + *
   56.18 + */
   56.19 +
   56.20 +#ifndef LEMON_TIGHT_EDGE_FILTER_MAP_H
   56.21 +#define LEMON_TIGHT_EDGE_FILTER_MAP_H
   56.22 +
   56.23 +#include <lemon/maps.h>
   56.24 +
   56.25 +// /// \file
   56.26 +// /// \brief Maximum flow algorithms.
   56.27 +// /// \ingroup galgs
   56.28 +
   56.29 +namespace lemon {
   56.30 +
   56.31 +  /// \brief A map for filtering the edge-set to those edges 
   56.32 +  /// which are tight w.r.t. some node_potential map and 
   56.33 +  /// edge_distance map.
   56.34 +  ///
   56.35 +  /// A node-map node_potential is said to be a potential w.r.t. 
   56.36 +  /// an edge-map edge_distance 
   56.37 +  /// if and only if for each edge e, node_potential[g.head(e)] 
   56.38 +  /// <= edge_distance[e]+node_potential[g.tail(e)] 
   56.39 +  /// (or the reverse inequality holds for each edge).
   56.40 +  /// An edge is said to be tight if this inequality holds with equality, 
   56.41 +  /// and the map returns true exactly for those edges.
   56.42 +  /// To avoid rounding errors, it is recommended to use this class with exact 
   56.43 +  /// types, e.g. with int.
   56.44 +  template<typename Graph, 
   56.45 +	   typename NodePotentialMap, typename EdgeDistanceMap>
   56.46 +  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
   56.47 +  protected:
   56.48 +    const Graph* g;
   56.49 +    NodePotentialMap* node_potential;
   56.50 +    EdgeDistanceMap* edge_distance;
   56.51 +  public:
   56.52 +    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
   56.53 +		       EdgeDistanceMap& _edge_distance) : 
   56.54 +      g(&_g), node_potential(&_node_potential), 
   56.55 +      edge_distance(&_edge_distance) { }
   56.56 +    bool operator[](const typename Graph::Edge& e) const {
   56.57 +      return ((*node_potential)[g->head(e)] == 
   56.58 +	      (*edge_distance)[e]+(*node_potential)[g->tail(e)]);
   56.59 +    }
   56.60 +  };
   56.61 +
   56.62 +} //namespace lemon
   56.63 +
   56.64 +#endif //LEMON_TIGHT_EDGE_FILTER_MAP_H
   56.65 +
   56.66 +
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/src/lemon/bfs.h	Wed Sep 29 15:30:04 2004 +0000
    57.3 @@ -0,0 +1,286 @@
    57.4 +/* -*- C++ -*-
    57.5 + * src/lemon/bfs.h - Part of LEMON, a generic C++ optimization library
    57.6 + *
    57.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    57.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    57.9 + *
   57.10 + * Permission to use, modify and distribute this software is granted
   57.11 + * provided that this copyright notice appears in all copies. For
   57.12 + * precise terms see the accompanying LICENSE file.
   57.13 + *
   57.14 + * This software is provided "AS IS" with no warranty of any kind,
   57.15 + * express or implied, and with no claim as to its suitability for any
   57.16 + * purpose.
   57.17 + *
   57.18 + */
   57.19 +
   57.20 +#ifndef LEMON_BFS_H
   57.21 +#define LEMON_BFS_H
   57.22 +
   57.23 +///\ingroup flowalgs
   57.24 +///\file
   57.25 +///\brief Bfs algorithm.
   57.26 +///
   57.27 +///\todo Revise Manual.
   57.28 +
   57.29 +#include <lemon/bin_heap.h>
   57.30 +#include <lemon/invalid.h>
   57.31 +
   57.32 +namespace lemon {
   57.33 +
   57.34 +/// \addtogroup flowalgs
   57.35 +/// @{
   57.36 +
   57.37 +  ///%BFS algorithm class.
   57.38 +
   57.39 +  ///This class provides an efficient implementation of %BFS algorithm.
   57.40 +  ///\param GR The graph type the algorithm runs on.
   57.41 +  ///This class does the same as Dijkstra does with constant 1 edge length,
   57.42 +  ///but it is faster.
   57.43 +  ///
   57.44 +  ///\author Alpar Juttner
   57.45 +
   57.46 +#ifdef DOXYGEN
   57.47 +  template <typename GR>
   57.48 +#else
   57.49 +  template <typename GR>
   57.50 +#endif
   57.51 +  class Bfs{
   57.52 +  public:
   57.53 +    ///The type of the underlying graph.
   57.54 +    typedef GR Graph;
   57.55 +    ///\e
   57.56 +    typedef typename Graph::Node Node;
   57.57 +    ///\e
   57.58 +    typedef typename Graph::NodeIt NodeIt;
   57.59 +    ///\e
   57.60 +    typedef typename Graph::Edge Edge;
   57.61 +    ///\e
   57.62 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   57.63 +    
   57.64 +    ///\brief The type of the map that stores the last
   57.65 +    ///edges of the shortest paths.
   57.66 +    typedef typename Graph::template NodeMap<Edge> PredMap;
   57.67 +    ///\brief The type of the map that stores the last but one
   57.68 +    ///nodes of the shortest paths.
   57.69 +    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   57.70 +    ///The type of the map that stores the dists of the nodes.
   57.71 +    typedef typename Graph::template NodeMap<int> DistMap;
   57.72 +
   57.73 +  private:
   57.74 +    /// Pointer to the underlying graph.
   57.75 +    const Graph *G;
   57.76 +    ///Pointer to the map of predecessors edges.
   57.77 +    PredMap *predecessor;
   57.78 +    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
   57.79 +    bool local_predecessor;
   57.80 +    ///Pointer to the map of predecessors nodes.
   57.81 +    PredNodeMap *pred_node;
   57.82 +    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
   57.83 +    bool local_pred_node;
   57.84 +    ///Pointer to the map of distances.
   57.85 +    DistMap *distance;
   57.86 +    ///Indicates if \ref distance is locally allocated (\c true) or not.
   57.87 +    bool local_distance;
   57.88 +
   57.89 +    ///The source node of the last execution.
   57.90 +    Node source;
   57.91 +
   57.92 +
   57.93 +    ///Initializes the maps.
   57.94 +    void init_maps() 
   57.95 +    {
   57.96 +      if(!predecessor) {
   57.97 +	local_predecessor = true;
   57.98 +	predecessor = new PredMap(*G);
   57.99 +      }
  57.100 +      if(!pred_node) {
  57.101 +	local_pred_node = true;
  57.102 +	pred_node = new PredNodeMap(*G);
  57.103 +      }
  57.104 +      if(!distance) {
  57.105 +	local_distance = true;
  57.106 +	distance = new DistMap(*G);
  57.107 +      }
  57.108 +    }
  57.109 +    
  57.110 +  public :    
  57.111 +    ///Constructor.
  57.112 +    
  57.113 +    ///\param _G the graph the algorithm will run on.
  57.114 +    ///
  57.115 +    Bfs(const Graph& _G) :
  57.116 +      G(&_G),
  57.117 +      predecessor(NULL), local_predecessor(false),
  57.118 +      pred_node(NULL), local_pred_node(false),
  57.119 +      distance(NULL), local_distance(false)
  57.120 +    { }
  57.121 +    
  57.122 +    ///Destructor.
  57.123 +    ~Bfs() 
  57.124 +    {
  57.125 +      if(local_predecessor) delete predecessor;
  57.126 +      if(local_pred_node) delete pred_node;
  57.127 +      if(local_distance) delete distance;
  57.128 +    }
  57.129 +
  57.130 +    ///Sets the map storing the predecessor edges.
  57.131 +
  57.132 +    ///Sets the map storing the predecessor edges.
  57.133 +    ///If you don't use this function before calling \ref run(),
  57.134 +    ///it will allocate one. The destuctor deallocates this
  57.135 +    ///automatically allocated map, of course.
  57.136 +    ///\return <tt> (*this) </tt>
  57.137 +    Bfs &setPredMap(PredMap &m) 
  57.138 +    {
  57.139 +      if(local_predecessor) {
  57.140 +	delete predecessor;
  57.141 +	local_predecessor=false;
  57.142 +      }
  57.143 +      predecessor = &m;
  57.144 +      return *this;
  57.145 +    }
  57.146 +
  57.147 +    ///Sets the map storing the predecessor nodes.
  57.148 +
  57.149 +    ///Sets the map storing the predecessor nodes.
  57.150 +    ///If you don't use this function before calling \ref run(),
  57.151 +    ///it will allocate one. The destuctor deallocates this
  57.152 +    ///automatically allocated map, of course.
  57.153 +    ///\return <tt> (*this) </tt>
  57.154 +    Bfs &setPredNodeMap(PredNodeMap &m) 
  57.155 +    {
  57.156 +      if(local_pred_node) {
  57.157 +	delete pred_node;
  57.158 +	local_pred_node=false;
  57.159 +      }
  57.160 +      pred_node = &m;
  57.161 +      return *this;
  57.162 +    }
  57.163 +
  57.164 +    ///Sets the map storing the distances calculated by the algorithm.
  57.165 +
  57.166 +    ///Sets the map storing the distances calculated by the algorithm.
  57.167 +    ///If you don't use this function before calling \ref run(),
  57.168 +    ///it will allocate one. The destuctor deallocates this
  57.169 +    ///automatically allocated map, of course.
  57.170 +    ///\return <tt> (*this) </tt>
  57.171 +    Bfs &setDistMap(DistMap &m) 
  57.172 +    {
  57.173 +      if(local_distance) {
  57.174 +	delete distance;
  57.175 +	local_distance=false;
  57.176 +      }
  57.177 +      distance = &m;
  57.178 +      return *this;
  57.179 +    }
  57.180 +    
  57.181 +  ///Runs %BFS algorithm from node \c s.
  57.182 +
  57.183 +  ///This method runs the %BFS algorithm from a root node \c s
  57.184 +  ///in order to
  57.185 +  ///compute a
  57.186 +  ///shortest path to each node. The algorithm computes
  57.187 +  ///- The %BFS tree.
  57.188 +  ///- The distance of each node from the root.
  57.189 + 
  57.190 +    void run(Node s) {
  57.191 +      
  57.192 +      init_maps();
  57.193 +      
  57.194 +      source = s;
  57.195 +      
  57.196 +      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  57.197 +	predecessor->set(u,INVALID);
  57.198 +	pred_node->set(u,INVALID);
  57.199 +      }
  57.200 +      
  57.201 +      int N=G->nodeNum();
  57.202 +      std::vector<typename Graph::Node> Q(N);
  57.203 +      int Qh=0;
  57.204 +      int Qt=0;
  57.205 +      
  57.206 +      Q[Qh++]=source;
  57.207 +      distance->set(s, 0);
  57.208 +      do {
  57.209 +	Node m;
  57.210 +	Node n=Q[Qt++];
  57.211 +	int d= (*distance)[n]+1;
  57.212 +	
  57.213 +	for(OutEdgeIt e(*G,n);e!=INVALID;++e)
  57.214 +	  if((m=G->head(e))!=s && (*predecessor)[m]==INVALID) {
  57.215 +	    Q[Qh++]=m;
  57.216 +	    predecessor->set(m,e);
  57.217 +	    pred_node->set(m,n);
  57.218 +	    distance->set(m,d);
  57.219 +	  }
  57.220 +      } while(Qt!=Qh);
  57.221 +    }
  57.222 +    
  57.223 +    ///The distance of a node from the root.
  57.224 +
  57.225 +    ///Returns the distance of a node from the root.
  57.226 +    ///\pre \ref run() must be called before using this function.
  57.227 +    ///\warning If node \c v in unreachable from the root the return value
  57.228 +    ///of this funcion is undefined.
  57.229 +    int dist(Node v) const { return (*distance)[v]; }
  57.230 +
  57.231 +    ///Returns the 'previous edge' of the %BFS path tree.
  57.232 +
  57.233 +    ///For a node \c v it returns the 'previous edge' of the %BFS tree,
  57.234 +    ///i.e. it returns the last edge of a shortest path from the root to \c
  57.235 +    ///v. It is \ref INVALID
  57.236 +    ///if \c v is unreachable from the root or if \c v=s. The
  57.237 +    ///%BFS tree used here is equal to the %BFS tree used in
  57.238 +    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  57.239 +    ///this function.
  57.240 +    Edge pred(Node v) const { return (*predecessor)[v]; }
  57.241 +
  57.242 +    ///Returns the 'previous node' of the %BFS tree.
  57.243 +
  57.244 +    ///For a node \c v it returns the 'previous node' on the %BFS tree,
  57.245 +    ///i.e. it returns the last but one node from a shortest path from the
  57.246 +    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
  57.247 +    ///\c v=s. The shortest path tree used here is equal to the %BFS
  57.248 +    ///tree used in \ref pred(Node v).  \pre \ref run() must be called before
  57.249 +    ///using this function.
  57.250 +    Node predNode(Node v) const { return (*pred_node)[v]; }
  57.251 +    
  57.252 +    ///Returns a reference to the NodeMap of distances.
  57.253 +    
  57.254 +    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
  57.255 +    ///be called before using this function.
  57.256 +    const DistMap &distMap() const { return *distance;}
  57.257 + 
  57.258 +    ///Returns a reference to the %BFS tree map.
  57.259 +
  57.260 +    ///Returns a reference to the NodeMap of the edges of the
  57.261 +    ///%BFS tree.
  57.262 +    ///\pre \ref run() must be called before using this function.
  57.263 +    const PredMap &predMap() const { return *predecessor;}
  57.264 + 
  57.265 +    ///Returns a reference to the map of last but one nodes of shortest paths.
  57.266 +
  57.267 +    ///Returns a reference to the NodeMap of the last but one nodes on the
  57.268 +    ///%BFS tree.
  57.269 +    ///\pre \ref run() must be called before using this function.
  57.270 +    const PredNodeMap &predNodeMap() const { return *pred_node;}
  57.271 +
  57.272 +    ///Checks if a node is reachable from the root.
  57.273 +
  57.274 +    ///Returns \c true if \c v is reachable from the root.
  57.275 +    ///\note The root node is reported to be reached!
  57.276 +    ///
  57.277 +    ///\pre \ref run() must be called before using this function.
  57.278 +    ///
  57.279 +    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  57.280 +    
  57.281 +  };
  57.282 +  
  57.283 +/// @}
  57.284 +  
  57.285 +} //END OF NAMESPACE LEMON
  57.286 +
  57.287 +#endif
  57.288 +
  57.289 +
    58.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.2 +++ b/src/lemon/bin_heap.h	Wed Sep 29 15:30:04 2004 +0000
    58.3 @@ -0,0 +1,203 @@
    58.4 +/* -*- C++ -*-
    58.5 + * src/lemon/bin_heap.h - Part of LEMON, a generic C++ optimization library
    58.6 + *
    58.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    58.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    58.9 + *
   58.10 + * Permission to use, modify and distribute this software is granted
   58.11 + * provided that this copyright notice appears in all copies. For
   58.12 + * precise terms see the accompanying LICENSE file.
   58.13 + *
   58.14 + * This software is provided "AS IS" with no warranty of any kind,
   58.15 + * express or implied, and with no claim as to its suitability for any
   58.16 + * purpose.
   58.17 + *
   58.18 + */
   58.19 +
   58.20 +#ifndef LEMON_BIN_HEAP_H
   58.21 +#define LEMON_BIN_HEAP_H
   58.22 +
   58.23 +///\ingroup auxdat
   58.24 +///\file
   58.25 +///\brief Binary Heap implementation.
   58.26 +///\todo It should be documented.
   58.27 +
   58.28 +#include <vector>
   58.29 +#include <utility>
   58.30 +#include <functional>
   58.31 +
   58.32 +namespace lemon {
   58.33 +
   58.34 +  /// \addtogroup auxdat
   58.35 +  /// @{
   58.36 +
   58.37 +   /// A Binary Heap implementation.
   58.38 +  template <typename Item, typename Prio, typename ItemIntMap,
   58.39 +	    typename Compare = std::less<Prio> >
   58.40 +  class BinHeap {
   58.41 +
   58.42 +  public:
   58.43 +    typedef Item                             ItemType;
   58.44 +    // FIXME: stl-ben nem ezt hivjak value_type -nak, hanem a kovetkezot...
   58.45 +    typedef Prio                             PrioType;
   58.46 +    typedef std::pair<ItemType,PrioType>     PairType;
   58.47 +    typedef ItemIntMap                       ItemIntMapType;
   58.48 +    typedef Compare                          PrioCompare;
   58.49 +
   58.50 +    /**
   58.51 +     * Each Item element have a state associated to it. It may be "in heap",
   58.52 +     * "pre heap" or "post heap". The later two are indifferent from the
   58.53 +     * heap's point of view, but may be useful to the user.
   58.54 +     *
   58.55 +     * The ItemIntMap _should_ be initialized in such way, that it maps
   58.56 +     * PRE_HEAP (-1) to any element to be put in the heap...
   58.57 +     */
   58.58 +    ///\todo it is used nowhere
   58.59 +    ///
   58.60 +    enum state_enum {
   58.61 +      IN_HEAP = 0,
   58.62 +      PRE_HEAP = -1,
   58.63 +      POST_HEAP = -2
   58.64 +    };
   58.65 +
   58.66 +  private:
   58.67 +    std::vector<PairType> data;
   58.68 +    Compare comp;
   58.69 +    // FIXME: jo ez igy???
   58.70 +    ItemIntMap &iim;
   58.71 +
   58.72 +  public:
   58.73 +    BinHeap(ItemIntMap &_iim) : iim(_iim) {}
   58.74 +    BinHeap(ItemIntMap &_iim, const Compare &_comp) : comp(_comp), iim(_iim) {}
   58.75 +
   58.76 +
   58.77 +    int size() const { return data.size(); }
   58.78 +    bool empty() const { return data.empty(); }
   58.79 +
   58.80 +  private:
   58.81 +    static int parent(int i) { return (i-1)/2; }
   58.82 +    static int second_child(int i) { return 2*i+2; }
   58.83 +    bool less(const PairType &p1, const PairType &p2) const {
   58.84 +      return comp(p1.second, p2.second);
   58.85 +    }
   58.86 +
   58.87 +    int bubble_up(int hole, PairType p);
   58.88 +    int bubble_down(int hole, PairType p, int length);
   58.89 +
   58.90 +    void move(const PairType &p, int i) {
   58.91 +      data[i] = p;
   58.92 +      iim.set(p.first, i);
   58.93 +    }
   58.94 +
   58.95 +    void rmidx(int h) {
   58.96 +      int n = data.size()-1;
   58.97 +      if( h>=0 && h<=n ) {
   58.98 +	iim.set(data[h].first, POST_HEAP);
   58.99 +	if ( h<n ) {
  58.100 +	  bubble_down(h, data[n], n);
  58.101 +	}
  58.102 +	data.pop_back();
  58.103 +      }
  58.104 +    }
  58.105 +
  58.106 +  public:
  58.107 +    void push(const PairType &p) {
  58.108 +      int n = data.size();
  58.109 +      data.resize(n+1);
  58.110 +      bubble_up(n, p);
  58.111 +    }
  58.112 +    void push(const Item &i, const Prio &p) { push(PairType(i,p)); }
  58.113 +
  58.114 +    Item top() const {
  58.115 +      return data[0].first;
  58.116 +    }
  58.117 +    /// Returns the prio of the top element of the heap.
  58.118 +    Prio prio() const {
  58.119 +      return data[0].second;
  58.120 +    }
  58.121 +
  58.122 +    void pop() {
  58.123 +      rmidx(0);
  58.124 +    }
  58.125 +
  58.126 +    void erase(const Item &i) {
  58.127 +      rmidx(iim[i]);
  58.128 +    }
  58.129 +
  58.130 +    Prio operator[](const Item &i) const {
  58.131 +      int idx = iim[i];
  58.132 +      return data[idx].second;
  58.133 +    }
  58.134 +
  58.135 +    void set(const Item &i, const Prio &p) {
  58.136 +      int idx = iim[i];
  58.137 +      if( idx < 0 ) {
  58.138 +	push(i,p);
  58.139 +      }
  58.140 +      else if( comp(p, data[idx].second) ) {
  58.141 +	bubble_up(idx, PairType(i,p));
  58.142 +      }
  58.143 +      else {
  58.144 +	bubble_down(idx, PairType(i,p), data.size());
  58.145 +      }
  58.146 +    }
  58.147 +
  58.148 +    void decrease(const Item &i, const Prio &p) {
  58.149 +      int idx = iim[i];
  58.150 +      bubble_up(idx, PairType(i,p));
  58.151 +    }
  58.152 +    void increase(const Item &i, const Prio &p) {
  58.153 +      int idx = iim[i];
  58.154 +      bubble_down(idx, PairType(i,p), data.size());
  58.155 +    }
  58.156 +
  58.157 +    state_enum state(const Item &i) const {
  58.158 +      int s = iim[i];
  58.159 +      if( s>=0 )
  58.160 +	s=0;
  58.161 +      return state_enum(s);
  58.162 +    }
  58.163 +
  58.164 +  }; // class BinHeap
  58.165 +
  58.166 +  
  58.167 +  template <typename K, typename V, typename M, typename C>
  58.168 +  int BinHeap<K,V,M,C>::bubble_up(int hole, PairType p) {
  58.169 +    int par = parent(hole);
  58.170 +    while( hole>0 && less(p,data[par]) ) {
  58.171 +      move(data[par],hole);
  58.172 +      hole = par;
  58.173 +      par = parent(hole);
  58.174 +    }
  58.175 +    move(p, hole);
  58.176 +    return hole;
  58.177 +  }
  58.178 +
  58.179 +  template <typename K, typename V, typename M, typename C>
  58.180 +  int BinHeap<K,V,M,C>::bubble_down(int hole, PairType p, int length) {
  58.181 +    int child = second_child(hole);
  58.182 +    while(child < length) {
  58.183 +      if( less(data[child-1], data[child]) ) {
  58.184 +	--child;
  58.185 +      }
  58.186 +      if( !less(data[child], p) )
  58.187 +	goto ok;
  58.188 +      move(data[child], hole);
  58.189 +      hole = child;
  58.190 +      child = second_child(hole);
  58.191 +    }
  58.192 +    child--;
  58.193 +    if( child<length && less(data[child], p) ) {
  58.194 +      move(data[child], hole);
  58.195 +      hole=child;
  58.196 +    }
  58.197 +  ok:
  58.198 +    move(p, hole);
  58.199 +    return hole;
  58.200 +  }
  58.201 +
  58.202 +  ///@}
  58.203 +
  58.204 +} // namespace lemon
  58.205 +
  58.206 +#endif // LEMON_BIN_HEAP_H
    59.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    59.2 +++ b/src/lemon/default_map.h	Wed Sep 29 15:30:04 2004 +0000
    59.3 @@ -0,0 +1,144 @@
    59.4 +/* -*- C++ -*-
    59.5 + * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
    59.6 + *
    59.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    59.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    59.9 + *
   59.10 + * Permission to use, modify and distribute this software is granted
   59.11 + * provided that this copyright notice appears in all copies. For
   59.12 + * precise terms see the accompanying LICENSE file.
   59.13 + *
   59.14 + * This software is provided "AS IS" with no warranty of any kind,
   59.15 + * express or implied, and with no claim as to its suitability for any
   59.16 + * purpose.
   59.17 + *
   59.18 + */
   59.19 +
   59.20 +#ifndef LEMON_DEFAULT_MAP_H
   59.21 +#define LEMON_DEFAULT_MAP_H
   59.22 +
   59.23 +
   59.24 +#include <lemon/array_map.h>
   59.25 +#include <lemon/vector_map.h>
   59.26 +
   59.27 +///\ingroup graphmaps
   59.28 +///\file
   59.29 +///\brief Graph maps that construates and destruates
   59.30 +///their elements dynamically.
   59.31 +
   59.32 +namespace lemon {
   59.33 +
   59.34 +/// \addtogroup graphmaps
   59.35 +/// @{
   59.36 +
   59.37 +  /** The ArrayMap template class is graph map structure what
   59.38 +   *  automatically updates the map when a key is added to or erased from
   59.39 +   *  the map. This map uses the VectorMap if the ValueType is a primitive
   59.40 +   *  type and the ArrayMap for the other cases.
   59.41 +   *
   59.42 +   *  The template parameter is the MapRegistry that the maps
   59.43 +   *  will belong to and the ValueType.
   59.44 +   */
   59.45 +
   59.46 +
   59.47 +  /** Macro to implement the DefaultMap.
   59.48 +   */
   59.49 +#define DEFAULT_MAP_BODY(DynMap, Value) \
   59.50 +{ \
   59.51 +\
   59.52 +public: \
   59.53 +\
   59.54 +typedef DynMap<MapRegistry, Value> Parent; \
   59.55 +\
   59.56 +typedef typename MapRegistry::Graph Graph; \
   59.57 +\
   59.58 +DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
   59.59 +DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
   59.60 +  : Parent(g, r, v) {} \
   59.61 +DefaultMap(const DefaultMap& copy) \
   59.62 +  : Parent(static_cast<const Parent&>(copy)) {} \
   59.63 +template <typename TT> \
   59.64 +DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
   59.65 +  : { \
   59.66 +  Parent::MapBase::operator= \
   59.67 +    (static_cast<const typename Parent::MapBase&>(copy)); \
   59.68 +  if (Parent::getGraph()) { \
   59.69 +    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
   59.70 +      Parent::add(it); \
   59.71 +      Parent::operator[](it) = copy[it]; \
   59.72 +    } \
   59.73 +  } \
   59.74 +} \
   59.75 +DefaultMap& operator=(const DefaultMap& copy) { \
   59.76 +  Parent::operator=(static_cast<const Parent&>(copy)); \
   59.77 +  return *this; \
   59.78 +} \
   59.79 +template <typename TT> \
   59.80 +DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
   59.81 +  if (Parent::getGraph() != copy.getGraph()) { \
   59.82 +    Parent::clear(); \
   59.83 +    Parent::MapBase::operator=(copy); \
   59.84 +    Parent::construct(); \
   59.85 +  } \
   59.86 +  if (Parent::getGraph()) { \
   59.87 +    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
   59.88 +      Parent::operator[](it) = copy[it]; \
   59.89 +    } \
   59.90 +  } \
   59.91 +  return *this; \
   59.92 +} \
   59.93 +};
   59.94 +
   59.95 +
   59.96 +  template <typename MapRegistry, typename Type>
   59.97 +  class DefaultMap : public ArrayMap<MapRegistry, Type> 
   59.98 +  DEFAULT_MAP_BODY(ArrayMap, Type);
   59.99 +
  59.100 +  template <typename MapRegistry>
  59.101 +  class DefaultMap<MapRegistry, bool> 
  59.102 +    : public VectorMap<MapRegistry, bool> 
  59.103 +  DEFAULT_MAP_BODY(VectorMap, bool);
  59.104 +
  59.105 +  template <typename MapRegistry>
  59.106 +  class DefaultMap<MapRegistry, char> 
  59.107 +    : public VectorMap<MapRegistry, char> 
  59.108 +  DEFAULT_MAP_BODY(VectorMap, char);
  59.109 +
  59.110 +  template <typename MapRegistry>
  59.111 +  class DefaultMap<MapRegistry, int> 
  59.112 +    : public VectorMap<MapRegistry, int> 
  59.113 +  DEFAULT_MAP_BODY(VectorMap, int);
  59.114 +
  59.115 +  template <typename MapRegistry>
  59.116 +  class DefaultMap<MapRegistry, short> 
  59.117 +    : public VectorMap<MapRegistry, short> 
  59.118 +  DEFAULT_MAP_BODY(VectorMap, short);
  59.119 +
  59.120 +  template <typename MapRegistry>
  59.121 +  class DefaultMap<MapRegistry, long> 
  59.122 +    : public VectorMap<MapRegistry, long> 
  59.123 +  DEFAULT_MAP_BODY(VectorMap, long);
  59.124 +
  59.125 +  template <typename MapRegistry>
  59.126 +  class DefaultMap<MapRegistry, float> 
  59.127 +    : public VectorMap<MapRegistry, float> 
  59.128 +  DEFAULT_MAP_BODY(VectorMap, float);
  59.129 +
  59.130 +  template <typename MapRegistry>
  59.131 +  class DefaultMap<MapRegistry, double> 
  59.132 +    : public VectorMap<MapRegistry, double> 
  59.133 +  DEFAULT_MAP_BODY(VectorMap, double);
  59.134 +
  59.135 +  template <typename MapRegistry>
  59.136 +  class DefaultMap<MapRegistry, long double> 
  59.137 +    : public VectorMap<MapRegistry, long double> 
  59.138 +  DEFAULT_MAP_BODY(VectorMap, long double);
  59.139 +
  59.140 +  template <typename MapRegistry, typename Type>
  59.141 +  class DefaultMap<MapRegistry, Type*>
  59.142 +    : public VectorMap<MapRegistry, Type*> 
  59.143 +  DEFAULT_MAP_BODY(VectorMap, Type*);
  59.144 +
  59.145 +}
  59.146 +
  59.147 +#endif
    60.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    60.2 +++ b/src/lemon/dfs.h	Wed Sep 29 15:30:04 2004 +0000
    60.3 @@ -0,0 +1,290 @@
    60.4 +/* -*- C++ -*-
    60.5 + * src/lemon/dfs.h - Part of LEMON, a generic C++ optimization library
    60.6 + *
    60.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    60.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    60.9 + *
   60.10 + * Permission to use, modify and distribute this software is granted
   60.11 + * provided that this copyright notice appears in all copies. For
   60.12 + * precise terms see the accompanying LICENSE file.
   60.13 + *
   60.14 + * This software is provided "AS IS" with no warranty of any kind,
   60.15 + * express or implied, and with no claim as to its suitability for any
   60.16 + * purpose.
   60.17 + *
   60.18 + */
   60.19 +
   60.20 +#ifndef LEMON_DFS_H
   60.21 +#define LEMON_DFS_H
   60.22 +
   60.23 +///\ingroup flowalgs
   60.24 +///\file
   60.25 +///\brief %DFS algorithm.
   60.26 +///
   60.27 +///\todo Revise Manual.
   60.28 +
   60.29 +#include <lemon/bin_heap.h>
   60.30 +#include <lemon/invalid.h>
   60.31 +
   60.32 +namespace lemon {
   60.33 +
   60.34 +/// \addtogroup flowalgs
   60.35 +/// @{
   60.36 +
   60.37 +  ///%DFS algorithm class.
   60.38 +
   60.39 +  ///This class provides an efficient implementation of %DFS algorithm.
   60.40 +  ///
   60.41 +  ///\param GR The graph type the algorithm runs on.
   60.42 +  ///
   60.43 +  ///\author Alpar Juttner
   60.44 +
   60.45 +#ifdef DOXYGEN
   60.46 +  template <typename GR>
   60.47 +#else
   60.48 +  template <typename GR>
   60.49 +#endif
   60.50 +  class Dfs{
   60.51 +  public:
   60.52 +    ///The type of the underlying graph.
   60.53 +    typedef GR Graph;
   60.54 +    ///\e
   60.55 +    typedef typename Graph::Node Node;
   60.56 +    ///\e
   60.57 +    typedef typename Graph::NodeIt NodeIt;
   60.58 +    ///\e
   60.59 +    typedef typename Graph::Edge Edge;
   60.60 +    ///\e
   60.61 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   60.62 +    
   60.63 +    ///\brief The type of the map that stores the last
   60.64 +    ///edges of the paths on the %DFS tree.
   60.65 +    typedef typename Graph::template NodeMap<Edge> PredMap;
   60.66 +    ///\brief The type of the map that stores the last but one
   60.67 +    ///nodes of the paths on the %DFS tree.
   60.68 +    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   60.69 +    ///The type of the map that stores the dists of the nodes on the %DFS tree.
   60.70 +    typedef typename Graph::template NodeMap<int> DistMap;
   60.71 +
   60.72 +  private:
   60.73 +    /// Pointer to the underlying graph.
   60.74 +    const Graph *G;
   60.75 +    ///Pointer to the map of predecessors edges.
   60.76 +    PredMap *predecessor;
   60.77 +    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
   60.78 +    bool local_predecessor;
   60.79 +    ///Pointer to the map of predecessors nodes.
   60.80 +    PredNodeMap *pred_node;
   60.81 +    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
   60.82 +    bool local_pred_node;
   60.83 +    ///Pointer to the map of distances.
   60.84 +    DistMap *distance;
   60.85 +    ///Indicates if \ref distance is locally allocated (\c true) or not.
   60.86 +    bool local_distance;
   60.87 +
   60.88 +    ///The source node of the last execution.
   60.89 +    Node source;
   60.90 +
   60.91 +
   60.92 +    ///Initializes the maps.
   60.93 +    void init_maps() 
   60.94 +    {
   60.95 +      if(!predecessor) {
   60.96 +	local_predecessor = true;
   60.97 +	predecessor = new PredMap(*G);
   60.98 +      }
   60.99 +      if(!pred_node) {
  60.100 +	local_pred_node = true;
  60.101 +	pred_node = new PredNodeMap(*G);
  60.102 +      }
  60.103 +      if(!distance) {
  60.104 +	local_distance = true;
  60.105 +	distance = new DistMap(*G);
  60.106 +      }
  60.107 +    }
  60.108 +    
  60.109 +  public :    
  60.110 +    ///Constructor.
  60.111 +    
  60.112 +    ///\param _G the graph the algorithm will run on.
  60.113 +    ///
  60.114 +    Dfs(const Graph& _G) :
  60.115 +      G(&_G),
  60.116 +      predecessor(NULL), local_predecessor(false),
  60.117 +      pred_node(NULL), local_pred_node(false),
  60.118 +      distance(NULL), local_distance(false)
  60.119 +    { }
  60.120 +    
  60.121 +    ///Destructor.
  60.122 +    ~Dfs() 
  60.123 +    {
  60.124 +      if(local_predecessor) delete predecessor;
  60.125 +      if(local_pred_node) delete pred_node;
  60.126 +      if(local_distance) delete distance;
  60.127 +    }
  60.128 +
  60.129 +    ///Sets the map storing the predecessor edges.
  60.130 +
  60.131 +    ///Sets the map storing the predecessor edges.
  60.132 +    ///If you don't use this function before calling \ref run(),
  60.133 +    ///it will allocate one. The destuctor deallocates this
  60.134 +    ///automatically allocated map, of course.
  60.135 +    ///\return <tt> (*this) </tt>
  60.136 +    Dfs &setPredMap(PredMap &m) 
  60.137 +    {
  60.138 +      if(local_predecessor) {
  60.139 +	delete predecessor;
  60.140 +	local_predecessor=false;
  60.141 +      }
  60.142 +      predecessor = &m;
  60.143 +      return *this;
  60.144 +    }
  60.145 +
  60.146 +    ///Sets the map storing the predecessor nodes.
  60.147 +
  60.148 +    ///Sets the map storing the predecessor nodes.
  60.149 +    ///If you don't use this function before calling \ref run(),
  60.150 +    ///it will allocate one. The destuctor deallocates this
  60.151 +    ///automatically allocated map, of course.
  60.152 +    ///\return <tt> (*this) </tt>
  60.153 +    Dfs &setPredNodeMap(PredNodeMap &m) 
  60.154 +    {
  60.155 +      if(local_pred_node) {
  60.156 +	delete pred_node;
  60.157 +	local_pred_node=false;
  60.158 +      }
  60.159 +      pred_node = &m;
  60.160 +      return *this;
  60.161 +    }
  60.162 +
  60.163 +    ///Sets the map storing the distances calculated by the algorithm.
  60.164 +
  60.165 +    ///Sets the map storing the distances calculated by the algorithm.
  60.166 +    ///If you don't use this function before calling \ref run(),
  60.167 +    ///it will allocate one. The destuctor deallocates this
  60.168 +    ///automatically allocated map, of course.
  60.169 +    ///\return <tt> (*this) </tt>
  60.170 +    Dfs &setDistMap(DistMap &m) 
  60.171 +    {
  60.172 +      if(local_distance) {
  60.173 +	delete distance;
  60.174 +	local_distance=false;
  60.175 +      }
  60.176 +      distance = &m;
  60.177 +      return *this;
  60.178 +    }
  60.179 +    
  60.180 +  ///Runs %DFS algorithm from node \c s.
  60.181 +
  60.182 +  ///This method runs the %DFS algorithm from a root node \c s
  60.183 +  ///in order to
  60.184 +  ///compute 
  60.185 +  ///- a %DFS tree and
  60.186 +  ///- the distance of each node from the root on this tree.
  60.187 + 
  60.188 +    void run(Node s) {
  60.189 +      
  60.190 +      init_maps();
  60.191 +      
  60.192 +      source = s;
  60.193 +      
  60.194 +      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  60.195 +	predecessor->set(u,INVALID);
  60.196 +	pred_node->set(u,INVALID);
  60.197 +      }
  60.198 +      
  60.199 +      int N=G->nodeNum();
  60.200 +      std::vector<typename Graph::OutEdgeIt> Q(N);
  60.201 +
  60.202 +      int Qh=0;
  60.203 +      
  60.204 +      G->first(Q[Qh],s);
  60.205 +      distance->set(s, 0);
  60.206 +
  60.207 +      Node n=s;
  60.208 +      Node m;
  60.209 +      OutEdgeIt e;
  60.210 +      do {
  60.211 +	if((e=Q[Qh])!=INVALID)
  60.212 +	  if((m=G->head(e))!=s && (*predecessor)[m=G->head(e)]==INVALID) {
  60.213 +	    predecessor->set(m,e);
  60.214 +	    pred_node->set(m,n);
  60.215 +	    G->first(Q[++Qh],m);
  60.216 +	    distance->set(m,Qh);
  60.217 +	    n=m;
  60.218 +	  }
  60.219 +	  else ++Q[Qh];
  60.220 +	else if(--Qh>=0) n=G->tail(Q[Qh]);
  60.221 +      } while(Qh>=0);
  60.222 +    }
  60.223 +    
  60.224 +    ///The distance of a node from the root on the %DFS tree.
  60.225 +
  60.226 +    ///Returns the distance of a node from the root on the %DFS tree.
  60.227 +    ///\pre \ref run() must be called before using this function.
  60.228 +    ///\warning If node \c v in unreachable from the root the return value
  60.229 +    ///of this funcion is undefined.
  60.230 +    int dist(Node v) const { return (*distance)[v]; }
  60.231 +
  60.232 +    ///Returns the 'previous edge' of the %DFS path tree.
  60.233 +
  60.234 +    ///For a node \c v it returns the last edge of the path on the %DFS tree
  60.235 +    ///from the root to \c
  60.236 +    ///v. It is \ref INVALID
  60.237 +    ///if \c v is unreachable from the root or if \c v=s. The
  60.238 +    ///%DFS tree used here is equal to the %DFS tree used in
  60.239 +    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  60.240 +    ///this function.
  60.241 +    Edge pred(Node v) const { return (*predecessor)[v]; }
  60.242 +
  60.243 +    ///Returns the 'previous node' of the %DFS tree.
  60.244 +
  60.245 +    ///For a node \c v it returns the 'previous node' on the %DFS tree,
  60.246 +    ///i.e. it returns the last but one node of the path from the
  60.247 +    ///root to \c /v on the %DFS tree.
  60.248 +    ///It is INVALID if \c v is unreachable from the root or if
  60.249 +    ///\c v=s.
  60.250 +    ///\pre \ref run() must be called before
  60.251 +    ///using this function.
  60.252 +    Node predNode(Node v) const { return (*pred_node)[v]; }
  60.253 +    
  60.254 +    ///Returns a reference to the NodeMap of distances on the %DFS tree.
  60.255 +    
  60.256 +    ///Returns a reference to the NodeMap of distances on the %DFS tree.
  60.257 +    ///\pre \ref run() must
  60.258 +    ///be called before using this function.
  60.259 +    const DistMap &distMap() const { return *distance;}
  60.260 + 
  60.261 +    ///Returns a reference to the %DFS tree map.
  60.262 +
  60.263 +    ///Returns a reference to the NodeMap of the edges of the
  60.264 +    ///%DFS tree.
  60.265 +    ///\pre \ref run() must be called before using this function.
  60.266 +    const PredMap &predMap() const { return *predecessor;}
  60.267 + 
  60.268 +    ///Returns a reference to the map of last but one nodes of the %DFS tree.
  60.269 +
  60.270 +    ///Returns a reference to the NodeMap of the last but one nodes of the paths
  60.271 +    ///on the
  60.272 +    ///%DFS tree.
  60.273 +    ///\pre \ref run() must be called before using this function.
  60.274 +    const PredNodeMap &predNodeMap() const { return *pred_node;}
  60.275 +
  60.276 +    ///Checks if a node is reachable from the root.
  60.277 +
  60.278 +    ///Returns \c true if \c v is reachable from the root.
  60.279 +    ///\note The root node is reported to be reached!
  60.280 +    ///
  60.281 +    ///\pre \ref run() must be called before using this function.
  60.282 +    ///
  60.283 +    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  60.284 +    
  60.285 +  };
  60.286 +  
  60.287 +/// @}
  60.288 +  
  60.289 +} //END OF NAMESPACE LEMON
  60.290 +
  60.291 +#endif
  60.292 +
  60.293 +
    61.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.2 +++ b/src/lemon/dijkstra.h	Wed Sep 29 15:30:04 2004 +0000
    61.3 @@ -0,0 +1,344 @@
    61.4 +/* -*- C++ -*-
    61.5 + * src/lemon/dijkstra.h - Part of LEMON, a generic C++ optimization library
    61.6 + *
    61.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    61.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    61.9 + *
   61.10 + * Permission to use, modify and distribute this software is granted
   61.11 + * provided that this copyright notice appears in all copies. For
   61.12 + * precise terms see the accompanying LICENSE file.
   61.13 + *
   61.14 + * This software is provided "AS IS" with no warranty of any kind,
   61.15 + * express or implied, and with no claim as to its suitability for any
   61.16 + * purpose.
   61.17 + *
   61.18 + */
   61.19 +
   61.20 +#ifndef LEMON_DIJKSTRA_H
   61.21 +#define LEMON_DIJKSTRA_H
   61.22 +
   61.23 +///\ingroup flowalgs
   61.24 +///\file
   61.25 +///\brief Dijkstra algorithm.
   61.26 +
   61.27 +#include <lemon/bin_heap.h>
   61.28 +#include <lemon/invalid.h>
   61.29 +
   61.30 +namespace lemon {
   61.31 +
   61.32 +/// \addtogroup flowalgs
   61.33 +/// @{
   61.34 +
   61.35 +  ///%Dijkstra algorithm class.
   61.36 +
   61.37 +  ///This class provides an efficient implementation of %Dijkstra algorithm.
   61.38 +  ///The edge lengths are passed to the algorithm using a
   61.39 +  ///\ref skeleton::ReadMap "ReadMap",
   61.40 +  ///so it is easy to change it to any kind of length.
   61.41 +  ///
   61.42 +  ///The type of the length is determined by the
   61.43 +  ///\ref skeleton::ReadMap::ValueType "ValueType" of the length map.
   61.44 +  ///
   61.45 +  ///It is also possible to change the underlying priority heap.
   61.46 +  ///
   61.47 +  ///\param GR The graph type the algorithm runs on.
   61.48 +  ///\param LM This read-only
   61.49 +  ///EdgeMap
   61.50 +  ///determines the
   61.51 +  ///lengths of the edges. It is read once for each edge, so the map
   61.52 +  ///may involve in relatively time consuming process to compute the edge
   61.53 +  ///length if it is necessary. The default map type is
   61.54 +  ///\ref skeleton::StaticGraph::EdgeMap "Graph::EdgeMap<int>"
   61.55 +  ///\param Heap The heap type used by the %Dijkstra
   61.56 +  ///algorithm. The default
   61.57 +  ///is using \ref BinHeap "binary heap".
   61.58 +  ///
   61.59 +  ///\author Jacint Szabo and Alpar Juttner
   61.60 +  ///\todo We need a typedef-names should be standardized. (-:
   61.61 +  ///\todo Type of \c PredMap, \c PredNodeMap and \c DistMap
   61.62 +  ///should not be fixed. (Problematic to solve).
   61.63 +
   61.64 +#ifdef DOXYGEN
   61.65 +  template <typename GR,
   61.66 +	    typename LM,
   61.67 +	    typename Heap>
   61.68 +#else
   61.69 +  template <typename GR,
   61.70 +	    typename LM=typename GR::template EdgeMap<int>,
   61.71 +	    template <class,class,class,class> class Heap = BinHeap >
   61.72 +#endif
   61.73 +  class Dijkstra{
   61.74 +  public:
   61.75 +    ///The type of the underlying graph.
   61.76 +    typedef GR Graph;
   61.77 +    ///\e
   61.78 +    typedef typename Graph::Node Node;
   61.79 +    ///\e
   61.80 +    typedef typename Graph::NodeIt NodeIt;
   61.81 +    ///\e
   61.82 +    typedef typename Graph::Edge Edge;
   61.83 +    ///\e
   61.84 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   61.85 +    
   61.86 +    ///The type of the length of the edges.
   61.87 +    typedef typename LM::ValueType ValueType;
   61.88 +    ///The type of the map that stores the edge lengths.
   61.89 +    typedef LM LengthMap;
   61.90 +    ///\brief The type of the map that stores the last
   61.91 +    ///edges of the shortest paths.
   61.92 +    typedef typename Graph::template NodeMap<Edge> PredMap;
   61.93 +    ///\brief The type of the map that stores the last but one
   61.94 +    ///nodes of the shortest paths.
   61.95 +    typedef typename Graph::template NodeMap<Node> PredNodeMap;
   61.96 +    ///The type of the map that stores the dists of the nodes.
   61.97 +    typedef typename Graph::template NodeMap<ValueType> DistMap;
   61.98 +
   61.99 +  private:
  61.100 +    /// Pointer to the underlying graph.
  61.101 +    const Graph *G;
  61.102 +    /// Pointer to the length map
  61.103 +    const LM *length;
  61.104 +    ///Pointer to the map of predecessors edges.
  61.105 +    PredMap *predecessor;
  61.106 +    ///Indicates if \ref predecessor is locally allocated (\c true) or not.
  61.107 +    bool local_predecessor;
  61.108 +    ///Pointer to the map of predecessors nodes.
  61.109 +    PredNodeMap *pred_node;
  61.110 +    ///Indicates if \ref pred_node is locally allocated (\c true) or not.
  61.111 +    bool local_pred_node;
  61.112 +    ///Pointer to the map of distances.
  61.113 +    DistMap *distance;
  61.114 +    ///Indicates if \ref distance is locally allocated (\c true) or not.
  61.115 +    bool local_distance;
  61.116 +
  61.117 +    ///The source node of the last execution.
  61.118 +    Node source;
  61.119 +
  61.120 +    ///Initializes the maps.
  61.121 +    
  61.122 +    ///\todo Error if \c G or are \c NULL. What about \c length?
  61.123 +    ///\todo Better memory allocation (instead of new).
  61.124 +    void init_maps() 
  61.125 +    {
  61.126 +      if(!predecessor) {
  61.127 +	local_predecessor = true;
  61.128 +	predecessor = new PredMap(*G);
  61.129 +      }
  61.130 +      if(!pred_node) {
  61.131 +	local_pred_node = true;
  61.132 +	pred_node = new PredNodeMap(*G);
  61.133 +      }
  61.134 +      if(!distance) {
  61.135 +	local_distance = true;
  61.136 +	distance = new DistMap(*G);
  61.137 +      }
  61.138 +    }
  61.139 +    
  61.140 +  public :
  61.141 +    ///Constructor.
  61.142 +    
  61.143 +    ///\param _G the graph the algorithm will run on.
  61.144 +    ///\param _length the length map used by the algorithm.
  61.145 +    Dijkstra(const Graph& _G, const LM& _length) :
  61.146 +      G(&_G), length(&_length),
  61.147 +      predecessor(NULL), local_predecessor(false),
  61.148 +      pred_node(NULL), local_pred_node(false),
  61.149 +      distance(NULL), local_distance(false)
  61.150 +    { }
  61.151 +    
  61.152 +    ///Destructor.
  61.153 +    ~Dijkstra() 
  61.154 +    {
  61.155 +      if(local_predecessor) delete predecessor;
  61.156 +      if(local_pred_node) delete pred_node;
  61.157 +      if(local_distance) delete distance;
  61.158 +    }
  61.159 +
  61.160 +    ///Sets the length map.
  61.161 +
  61.162 +    ///Sets the length map.
  61.163 +    ///\return <tt> (*this) </tt>
  61.164 +    Dijkstra &setLengthMap(const LM &m) 
  61.165 +    {
  61.166 +      length = &m;
  61.167 +      return *this;
  61.168 +    }
  61.169 +
  61.170 +    ///Sets the map storing the predecessor edges.
  61.171 +
  61.172 +    ///Sets the map storing the predecessor edges.
  61.173 +    ///If you don't use this function before calling \ref run(),
  61.174 +    ///it will allocate one. The destuctor deallocates this
  61.175 +    ///automatically allocated map, of course.
  61.176 +    ///\return <tt> (*this) </tt>
  61.177 +    Dijkstra &setPredMap(PredMap &m) 
  61.178 +    {
  61.179 +      if(local_predecessor) {
  61.180 +	delete predecessor;
  61.181 +	local_predecessor=false;
  61.182 +      }
  61.183 +      predecessor = &m;
  61.184 +      return *this;
  61.185 +    }
  61.186 +
  61.187 +    ///Sets the map storing the predecessor nodes.
  61.188 +
  61.189 +    ///Sets the map storing the predecessor nodes.
  61.190 +    ///If you don't use this function before calling \ref run(),
  61.191 +    ///it will allocate one. The destuctor deallocates this
  61.192 +    ///automatically allocated map, of course.
  61.193 +    ///\return <tt> (*this) </tt>
  61.194 +    Dijkstra &setPredNodeMap(PredNodeMap &m) 
  61.195 +    {
  61.196 +      if(local_pred_node) {
  61.197 +	delete pred_node;
  61.198 +	local_pred_node=false;
  61.199 +      }
  61.200 +      pred_node = &m;
  61.201 +      return *this;
  61.202 +    }
  61.203 +
  61.204 +    ///Sets the map storing the distances calculated by the algorithm.
  61.205 +
  61.206 +    ///Sets the map storing the distances calculated by the algorithm.
  61.207 +    ///If you don't use this function before calling \ref run(),
  61.208 +    ///it will allocate one. The destuctor deallocates this
  61.209 +    ///automatically allocated map, of course.
  61.210 +    ///\return <tt> (*this) </tt>
  61.211 +    Dijkstra &setDistMap(DistMap &m) 
  61.212 +    {
  61.213 +      if(local_distance) {
  61.214 +	delete distance;
  61.215 +	local_distance=false;
  61.216 +      }
  61.217 +      distance = &m;
  61.218 +      return *this;
  61.219 +    }
  61.220 +    
  61.221 +  ///Runs %Dijkstra algorithm from node \c s.
  61.222 +
  61.223 +  ///This method runs the %Dijkstra algorithm from a root node \c s
  61.224 +  ///in order to
  61.225 +  ///compute the
  61.226 +  ///shortest path to each node. The algorithm computes
  61.227 +  ///- The shortest path tree.
  61.228 +  ///- The distance of each node from the root.
  61.229 +    
  61.230 +    void run(Node s) {
  61.231 +      
  61.232 +      init_maps();
  61.233 +      
  61.234 +      source = s;
  61.235 +      
  61.236 +      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
  61.237 +	predecessor->set(u,INVALID);
  61.238 +	pred_node->set(u,INVALID);
  61.239 +      }
  61.240 +      
  61.241 +      typename GR::template NodeMap<int> heap_map(*G,-1);
  61.242 +      
  61.243 +      typedef Heap<Node, ValueType, typename GR::template NodeMap<int>,
  61.244 +      std::less<ValueType> > 
  61.245 +      HeapType;
  61.246 +      
  61.247 +      HeapType heap(heap_map);
  61.248 +      
  61.249 +      heap.push(s,0); 
  61.250 +      
  61.251 +      while ( !heap.empty() ) {
  61.252 +	
  61.253 +	Node v=heap.top(); 
  61.254 +	ValueType oldvalue=heap[v];
  61.255 +	heap.pop();
  61.256 +	distance->set(v, oldvalue);
  61.257 +	
  61.258 +	
  61.259 +	for(OutEdgeIt e(*G,v); e!=INVALID; ++e) {
  61.260 +	  Node w=G->head(e); 
  61.261 +	  switch(heap.state(w)) {
  61.262 +	  case HeapType::PRE_HEAP:
  61.263 +	    heap.push(w,oldvalue+(*length)[e]); 
  61.264 +	    predecessor->set(w,e);
  61.265 +	    pred_node->set(w,v);
  61.266 +	    break;
  61.267 +	  case HeapType::IN_HEAP:
  61.268 +	    if ( oldvalue+(*length)[e] < heap[w] ) {
  61.269 +	      heap.decrease(w, oldvalue+(*length)[e]); 
  61.270 +	      predecessor->set(w,e);
  61.271 +	      pred_node->set(w,v);
  61.272 +	    }
  61.273 +	    break;
  61.274 +	  case HeapType::POST_HEAP:
  61.275 +	    break;
  61.276 +	  }
  61.277 +	}
  61.278 +      }
  61.279 +    }
  61.280 +    
  61.281 +    ///The distance of a node from the root.
  61.282 +
  61.283 +    ///Returns the distance of a node from the root.
  61.284 +    ///\pre \ref run() must be called before using this function.
  61.285 +    ///\warning If node \c v in unreachable from the root the return value
  61.286 +    ///of this funcion is undefined.
  61.287 +    ValueType dist(Node v) const { return (*distance)[v]; }
  61.288 +
  61.289 +    ///Returns the 'previous edge' of the shortest path tree.
  61.290 +
  61.291 +    ///For a node \c v it returns the 'previous edge' of the shortest path tree,
  61.292 +    ///i.e. it returns the last edge of a shortest path from the root to \c
  61.293 +    ///v. It is \ref INVALID
  61.294 +    ///if \c v is unreachable from the root or if \c v=s. The
  61.295 +    ///shortest path tree used here is equal to the shortest path tree used in
  61.296 +    ///\ref predNode(Node v).  \pre \ref run() must be called before using
  61.297 +    ///this function.
  61.298 +    ///\todo predEdge could be a better name.
  61.299 +    Edge pred(Node v) const { return (*predecessor)[v]; }
  61.300 +
  61.301 +    ///Returns the 'previous node' of the shortest path tree.
  61.302 +
  61.303 +    ///For a node \c v it returns the 'previous node' of the shortest path tree,
  61.304 +    ///i.e. it returns the last but one node from a shortest path from the
  61.305 +    ///root to \c /v. It is INVALID if \c v is unreachable from the root or if
  61.306 +    ///\c v=s. The shortest path tree used here is equal to the shortest path
  61.307 +    ///tree used in \ref pred(Node v).  \pre \ref run() must be called before
  61.308 +    ///using this function.
  61.309 +    Node predNode(Node v) const { return (*pred_node)[v]; }
  61.310 +    
  61.311 +    ///Returns a reference to the NodeMap of distances.
  61.312 +
  61.313 +    ///Returns a reference to the NodeMap of distances. \pre \ref run() must
  61.314 +    ///be called before using this function.
  61.315 +    const DistMap &distMap() const { return *distance;}
  61.316 + 
  61.317 +    ///Returns a reference to the shortest path tree map.
  61.318 +
  61.319 +    ///Returns a reference to the NodeMap of the edges of the
  61.320 +    ///shortest path tree.
  61.321 +    ///\pre \ref run() must be called before using this function.
  61.322 +    const PredMap &predMap() const { return *predecessor;}
  61.323 + 
  61.324 +    ///Returns a reference to the map of nodes of shortest paths.
  61.325 +
  61.326 +    ///Returns a reference to the NodeMap of the last but one nodes of the
  61.327 +    ///shortest path tree.
  61.328 +    ///\pre \ref run() must be called before using this function.
  61.329 +    const PredNodeMap &predNodeMap() const { return *pred_node;}
  61.330 +
  61.331 +    ///Checks if a node is reachable from the root.
  61.332 +
  61.333 +    ///Returns \c true if \c v is reachable from the root.
  61.334 +    ///\note The root node is reported to be reached!
  61.335 +    ///\pre \ref run() must be called before using this function.
  61.336 +    ///
  61.337 +    bool reached(Node v) { return v==source || (*predecessor)[v]!=INVALID; }
  61.338 +    
  61.339 +  };
  61.340 +  
  61.341 +/// @}
  61.342 +  
  61.343 +} //END OF NAMESPACE LEMON
  61.344 +
  61.345 +#endif
  61.346 +
  61.347 +
    62.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    62.2 +++ b/src/lemon/dimacs.h	Wed Sep 29 15:30:04 2004 +0000
    62.3 @@ -0,0 +1,207 @@
    62.4 +/* -*- C++ -*-
    62.5 + * src/lemon/dimacs.h - Part of LEMON, a generic C++ optimization library
    62.6 + *
    62.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    62.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    62.9 + *
   62.10 + * Permission to use, modify and distribute this software is granted
   62.11 + * provided that this copyright notice appears in all copies. For
   62.12 + * precise terms see the accompanying LICENSE file.
   62.13 + *
   62.14 + * This software is provided "AS IS" with no warranty of any kind,
   62.15 + * express or implied, and with no claim as to its suitability for any
   62.16 + * purpose.
   62.17 + *
   62.18 + */
   62.19 +
   62.20 +#ifndef LEMON_DIMACS_H
   62.21 +#define LEMON_DIMACS_H
   62.22 +
   62.23 +#include <iostream>
   62.24 +#include <string>
   62.25 +#include <vector>
   62.26 +#include <lemon/maps.h>
   62.27 +
   62.28 +/// \ingroup misc
   62.29 +/// \file
   62.30 +/// \brief Dimacs file format reader.
   62.31 +
   62.32 +namespace lemon {
   62.33 +
   62.34 +
   62.35 +  /// \addtogroup misc
   62.36 +  /// @{
   62.37 +
   62.38 +  /// Dimacs min cost flow reader function.
   62.39 +
   62.40 +  /// This function reads a min cost flow instance from dimacs format,
   62.41 +  /// i.e. from dimacs files having a line starting with \c p \c "min".
   62.42 +  /// At the beginning \c g is cleared by \c g.clear(). The edge
   62.43 +  /// capacities are written to \c capacity, \c s and \c t are set to
   62.44 +  /// the source and the target nodes resp. and the cost of the edges
   62.45 +  /// are written to \c cost.
   62.46 +  ///
   62.47 +  /// \author Marton Makai
   62.48 +  template<typename Graph, typename CapacityMap, typename CostMap>
   62.49 +  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
   62.50 +		  typename Graph::Node &s, typename Graph::Node &t, 
   62.51 +		  CostMap& cost) {
   62.52 +    g.clear();
   62.53 +    typename CapacityMap::ValueType _cap;
   62.54 +    typename CostMap::ValueType _cost;
   62.55 +    char d;
   62.56 +    std::string problem;
   62.57 +    char c;
   62.58 +    int i, j;
   62.59 +    std::string str;
   62.60 +    int n, m; 
   62.61 +    typename Graph::Edge e;
   62.62 +    std::vector<typename Graph::Node> nodes;
   62.63 +    while (is>>c) {
   62.64 +      switch (c) {
   62.65 +      case 'c': //comment
   62.66 +	getline(is, str);
   62.67 +	break;
   62.68 +      case 'p': //problem definition
   62.69 +	is >> problem >> n >> m;
   62.70 +	getline(is, str);
   62.71 +	nodes.resize(n+1);
   62.72 +	for (int k=1; k<=n; ++k) nodes[k]=g.addNode();
   62.73 +	break;
   62.74 +      case 'n': //node definition
   62.75 +	if (problem=="sp") { //shortest path problem
   62.76 +	  is >> i;
   62.77 +	  getline(is, str);
   62.78 +	  s=nodes[i];
   62.79 +	}
   62.80 +	if (problem=="max" || problem=="min") { //((max) or (min cost)) flow problem
   62.81 +	  is >> i >> d;
   62.82 +	  getline(is, str);
   62.83 +	  if (d=='s') s=nodes[i];
   62.84 +	  if (d=='t') t=nodes[i];
   62.85 +	}
   62.86 +	break;
   62.87 +      case 'a':
   62.88 +	if ( problem == "max" || problem == "sp") {
   62.89 +	  is >> i >> j >> _cap;
   62.90 +	  getline(is, str);
   62.91 +	  e=g.addEdge(nodes[i], nodes[j]);
   62.92 +	  //capacity.update();
   62.93 +	  capacity.set(e, _cap);
   62.94 +	} else {
   62.95 +	  if ( problem == "min" ) {
   62.96 +	    is >> i >> j >> _cap >> _cost;
   62.97 +	    getline(is, str);
   62.98 +	    e=g.addEdge(nodes[i], nodes[j]);
   62.99 +	    //capacity.update();
  62.100 +	    capacity.set(e, _cap);
  62.101 +	    //cost.update();
  62.102 +	    cost.set(e, _cost);
  62.103 +	  } else {
  62.104 +	    is >> i >> j;
  62.105 +	    getline(is, str);
  62.106 +	    g.addEdge(nodes[i], nodes[j]);
  62.107 +	  }
  62.108 +	}
  62.109 +	break;
  62.110 +      }
  62.111 +    }
  62.112 +  }
  62.113 +
  62.114 +
  62.115 +  /// Dimacs max flow reader function.
  62.116 +
  62.117 +  /// This function reads a max flow instance from dimacs format,
  62.118 +  /// i.e. from dimacs files having a line starting with \c p \c
  62.119 +  /// "max".  At the beginning \c g is cleared by \c g.clear(). The
  62.120 +  /// edge capacities are written to \c capacity and \c s and \c t are
  62.121 +  /// set to the source and the target nodes.
  62.122 +  ///
  62.123 +  /// \author Marton Makai
  62.124 +  template<typename Graph, typename CapacityMap>
  62.125 +  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
  62.126 +		  typename Graph::Node &s, typename Graph::Node &t) {
  62.127 +    NullMap<typename Graph::Edge, int> n;
  62.128 +    readDimacs(is, g, capacity, s, t, n);
  62.129 +  }
  62.130 +
  62.131 +
  62.132 +  /// Dimacs shortest path reader function.
  62.133 +
  62.134 +  /// This function reads a shortest path instance from dimacs format,
  62.135 +  /// i.e. from dimacs files having a line starting with \c p \c "sp".
  62.136 +  /// At the beginning \c g is cleared by \c g.clear(). The edge
  62.137 +  /// capacities are written to \c capacity and \c s is set to the
  62.138 +  /// source node.
  62.139 +  ///
  62.140 +  /// \author Marton Makai
  62.141 +  template<typename Graph, typename CapacityMap>
  62.142 +  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity, 
  62.143 +		  typename Graph::Node &s) {
  62.144 +    NullMap<typename Graph::Edge, int> n;
  62.145 +    readDimacs(is, g, capacity, s, s, n);
  62.146 +  }
  62.147 +
  62.148 +
  62.149 +  /// Dimacs capacitated graph reader function.
  62.150 +
  62.151 +  /// This function reads an edge capacitated graph instance from
  62.152 +  /// dimacs format.  At the beginning \c g is cleared by \c g.clear()
  62.153 +  /// and the edge capacities are written to \c capacity.
  62.154 +  ///
  62.155 +  /// \author Marton Makai
  62.156 +  template<typename Graph, typename CapacityMap>
  62.157 +  void readDimacs(std::istream& is, Graph &g, CapacityMap& capacity) {
  62.158 +    typename Graph::Node u;
  62.159 +    NullMap<typename Graph::Edge, int> n;
  62.160 +    readDimacs(is, g, capacity, u, u, n);
  62.161 +  }
  62.162 +
  62.163 +
  62.164 +  /// Dimacs plain graph reader function.
  62.165 +
  62.166 +  /// This function reads a graph without any designated nodes and
  62.167 +  /// maps from dimacs format, i.e. from dimacs files having a line
  62.168 +  /// starting with \c p \c "mat".  At the beginning \c g is cleared
  62.169 +  /// by \c g.clear().
  62.170 +  ///
  62.171 +  /// \author Marton Makai
  62.172 +  template<typename Graph>
  62.173 +  void readDimacs(std::istream& is, Graph &g) {
  62.174 +    typename Graph::Node u;
  62.175 +    NullMap<typename Graph::Edge, int> n;
  62.176 +    readDimacs(is, g, n, u, u, n);
  62.177 +  }
  62.178 +  
  62.179 +
  62.180 +
  62.181 +  
  62.182 +  /// write matching problem
  62.183 +  template<typename Graph>
  62.184 +  void writeDimacs(std::ostream& os, const Graph &g) {
  62.185 +    typedef typename Graph::NodeIt NodeIt;
  62.186 +    typedef typename Graph::EdgeIt EdgeIt;  
  62.187 +    
  62.188 +    typename Graph::template NodeMap<int> nodes(g);
  62.189 +
  62.190 +    os << "c matching problem" << std::endl;
  62.191 +
  62.192 +    int i=1;
  62.193 +    for(NodeIt v(g); v!=INVALID; ++v) {
  62.194 +      nodes.set(v, i);
  62.195 +      ++i;
  62.196 +    }    
  62.197 +    
  62.198 +    os << "p mat " << g.nodeNum() << " " << g.edgeNum() << std::endl;
  62.199 +
  62.200 +    for(EdgeIt e(g); e!=INVALID; ++e) {
  62.201 +      os << "a " << nodes[g.tail(e)] << " " << nodes[g.head(e)] << std::endl; 
  62.202 +    }
  62.203 +
  62.204 +  }
  62.205 +
  62.206 +  /// @}
  62.207 +
  62.208 +} //namespace lemon
  62.209 +
  62.210 +#endif //LEMON_DIMACS_H
    63.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    63.2 +++ b/src/lemon/extended_pair.h	Wed Sep 29 15:30:04 2004 +0000
    63.3 @@ -0,0 +1,80 @@
    63.4 +/* -*- C++ -*-
    63.5 + * src/lemon/extended_pair.h - Part of LEMON, a generic C++ optimization library
    63.6 + *
    63.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    63.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    63.9 + *
   63.10 + * Permission to use, modify and distribute this software is granted
   63.11 + * provided that this copyright notice appears in all copies. For
   63.12 + * precise terms see the accompanying LICENSE file.
   63.13 + *
   63.14 + * This software is provided "AS IS" with no warranty of any kind,
   63.15 + * express or implied, and with no claim as to its suitability for any
   63.16 + * purpose.
   63.17 + *
   63.18 + */
   63.19 +
   63.20 +#ifndef LEMON_EXTENDED_PAIR_H
   63.21 +#define LEMON_EXTENDED_PAIR_H
   63.22 +
   63.23 +template <typename T1, typename A1, typename T2, typename A2>
   63.24 +struct extended_pair {
   63.25 +  typedef T1 first_type;
   63.26 +  typedef T2 second_type;
   63.27 +
   63.28 +  extended_pair() : first(), second() {}
   63.29 +
   63.30 +  extended_pair(A1 f, A2 s) : first(f), second(s) {}
   63.31 +
   63.32 +  template <class Pair>
   63.33 +  extended_pair(const Pair& pair) : first(pair.first), second(pair.second) {}
   63.34 +
   63.35 +  T1 first;
   63.36 +  T2 second;
   63.37 +};
   63.38 +
   63.39 +template <typename T1, typename T2, 
   63.40 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.41 +bool operator==(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.42 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.43 +  return left.first == right.first && left.second == right.second;
   63.44 +}
   63.45 +
   63.46 +template <typename T1, typename T2, 
   63.47 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.48 +bool operator!=(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.49 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.50 +  return  !(left == right);
   63.51 +}
   63.52 +
   63.53 +template <typename T1, typename T2, 
   63.54 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.55 +bool operator<(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.56 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.57 +  return left.first < right.first || 
   63.58 +           (!(right.first<left.first) && left.second < right.second);
   63.59 +}
   63.60 +
   63.61 +template <typename T1, typename T2, 
   63.62 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.63 +bool operator>(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.64 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.65 +  return right < left;
   63.66 +}
   63.67 +
   63.68 +template <typename T1, typename T2, 
   63.69 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.70 +bool operator<=(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.71 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.72 +  return !(right > left);
   63.73 +}
   63.74 +
   63.75 +template <typename T1, typename T2, 
   63.76 +	  typename LA1, typename LA2, typename RA1, typename RA2>
   63.77 +bool operator>=(const extended_pair<T1, LA1, T2, LA2>& left, 
   63.78 +		const extended_pair<T1, RA1, T2, RA2>& right) {
   63.79 +  return !(right < left);
   63.80 +}
   63.81 +
   63.82 +
   63.83 +#endif
    64.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    64.2 +++ b/src/lemon/fib_heap.h	Wed Sep 29 15:30:04 2004 +0000
    64.3 @@ -0,0 +1,510 @@
    64.4 +/* -*- C++ -*-
    64.5 + * src/lemon/fib_heap.h - Part of LEMON, a generic C++ optimization library
    64.6 + *
    64.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    64.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    64.9 + *
   64.10 + * Permission to use, modify and distribute this software is granted
   64.11 + * provided that this copyright notice appears in all copies. For
   64.12 + * precise terms see the accompanying LICENSE file.
   64.13 + *
   64.14 + * This software is provided "AS IS" with no warranty of any kind,
   64.15 + * express or implied, and with no claim as to its suitability for any
   64.16 + * purpose.
   64.17 + *
   64.18 + */
   64.19 +
   64.20 +#ifndef LEMON_FIB_HEAP_H
   64.21 +#define LEMON_FIB_HEAP_H
   64.22 +
   64.23 +///\file
   64.24 +///\ingroup auxdat
   64.25 +///\brief Fibonacci Heap implementation.
   64.26 +
   64.27 +#include <vector>
   64.28 +#include <functional>
   64.29 +#include <math.h>
   64.30 +
   64.31 +namespace lemon {
   64.32 +  
   64.33 +  /// \addtogroup auxdat
   64.34 +  /// @{
   64.35 +
   64.36 +  /// Fibonacci Heap.
   64.37 +
   64.38 +  ///This class implements the \e Fibonacci \e heap data structure. A \e heap
   64.39 +  ///is a data structure for storing items with specified values called \e
   64.40 +  ///priorities in such a way that finding the item with minimum priority is
   64.41 +  ///efficient. \c Compare specifies the ordering of the priorities. In a heap
   64.42 +  ///one can change the priority of an item, add or erase an item, etc.
   64.43 +  ///
   64.44 +  ///The methods \ref increase and \ref erase are not efficient in a Fibonacci
   64.45 +  ///heap. In case of many calls to these operations, it is better to use a
   64.46 +  ///\e binary \e heap.
   64.47 +  ///
   64.48 +  ///\param Item Type of the items to be stored.  
   64.49 +  ///\param Prio Type of the priority of the items.
   64.50 +  ///\param ItemIntMap A read and writable Item int map, for the usage of
   64.51 +  ///the heap.
   64.52 +  ///\param Compare A class for the ordering of the priorities. The
   64.53 +  ///default is \c std::less<Prio>.
   64.54 +  ///
   64.55 +  ///\author Jacint Szabo 
   64.56 + 
   64.57 +#ifdef DOXYGEN
   64.58 +  template <typename Item, 
   64.59 +	    typename Prio, 
   64.60 +	    typename ItemIntMap, 
   64.61 +	    typename Compare>
   64.62 +#else
   64.63 +  template <typename Item, 
   64.64 +	    typename Prio, 
   64.65 +	    typename ItemIntMap, 
   64.66 +	    typename Compare = std::less<Prio> >
   64.67 +#endif
   64.68 +  class FibHeap {
   64.69 +  public:     
   64.70 +    typedef Prio PrioType;
   64.71 +    
   64.72 +  private:
   64.73 +    class store;
   64.74 +    
   64.75 +    std::vector<store> container;
   64.76 +    int minimum;
   64.77 +    ItemIntMap &iimap;
   64.78 +    Compare comp;
   64.79 +    int num_items;
   64.80 +    
   64.81 +  public:
   64.82 +    enum state_enum {
   64.83 +      IN_HEAP = 0,
   64.84 +      PRE_HEAP = -1,
   64.85 +      POST_HEAP = -2
   64.86 +    };
   64.87 +    
   64.88 +    FibHeap(ItemIntMap &_iimap) : minimum(0), iimap(_iimap), num_items() {} 
   64.89 +    FibHeap(ItemIntMap &_iimap, const Compare &_comp) : minimum(0), 
   64.90 +      iimap(_iimap), comp(_comp), num_items() {}
   64.91 +    
   64.92 +    ///The number of items stored in the heap.
   64.93 +
   64.94 +    /**
   64.95 +       Returns the number of items stored in the heap.
   64.96 +    */
   64.97 +    int size() const { return num_items; }
   64.98 +
   64.99 +    ///Checks if the heap stores no items.
  64.100 +    
  64.101 +    /**
  64.102 +       Returns \c true if and only if the heap stores no items.
  64.103 +    */
  64.104 +    bool empty() const { return num_items==0; }
  64.105 +
  64.106 +    ///\c item gets to the heap with priority \c value independently if \c item was already there.
  64.107 +
  64.108 +    /**
  64.109 +       This method calls \ref push(\c item, \c value) if \c item is not
  64.110 +       stored in the heap and it calls \ref decrease(\c item, \c value) or
  64.111 +       \ref increase(\c item, \c value) otherwise.
  64.112 +    */
  64.113 +    void set (Item const item, PrioType const value); 
  64.114 +    
  64.115 +    ///Adds \c item to the heap with priority \c value. 
  64.116 +    
  64.117 +    /**
  64.118 +       Adds \c item to the heap with priority \c value. 
  64.119 +       \pre \c item must not be stored in the heap. 
  64.120 +    */
  64.121 +    void push (Item const item, PrioType const value);
  64.122 +    
  64.123 +    ///Returns the item with minimum priority relative to \c Compare.
  64.124 +    
  64.125 +    /**
  64.126 +       This method returns the item with minimum priority relative to \c
  64.127 +       Compare.  
  64.128 +       \pre The heap must be nonempty.  
  64.129 +    */
  64.130 +    Item top() const { return container[minimum].name; }
  64.131 +
  64.132 +    ///Returns the minimum priority relative to \c Compare.
  64.133 +
  64.134 +    /**
  64.135 +       It returns the minimum priority relative to \c Compare.
  64.136 +       \pre The heap must be nonempty.
  64.137 +    */
  64.138 +    PrioType prio() const { return container[minimum].prio; }
  64.139 +    
  64.140 +    ///Returns the priority of \c item.
  64.141 +
  64.142 +    /**
  64.143 +       This function returns the priority of \c item.
  64.144 +       \pre \c item must be in the heap.
  64.145 +    */
  64.146 +    PrioType& operator[](const Item& item) { 
  64.147 +      return container[iimap[item]].prio; 
  64.148 +    }
  64.149 +    
  64.150 +    ///Returns the priority of \c item.
  64.151 +    
  64.152 +    /**
  64.153 +       It returns the priority of \c item.
  64.154 +       \pre \c item must be in the heap.
  64.155 +    */
  64.156 +    const PrioType& operator[](const Item& item) const { 
  64.157 +      return container[iimap[item]].prio; 
  64.158 +    }
  64.159 +
  64.160 +
  64.161 +    ///Deletes the item with minimum priority relative to \c Compare.
  64.162 +
  64.163 +    /**
  64.164 +    This method deletes the item with minimum priority relative to \c
  64.165 +    Compare from the heap.  
  64.166 +    \pre The heap must be non-empty.  
  64.167 +    */
  64.168 +    void pop();
  64.169 +
  64.170 +    ///Deletes \c item from the heap.
  64.171 +
  64.172 +    /**
  64.173 +       This method deletes \c item from the heap, if \c item was already
  64.174 +       stored in the heap. It is quite inefficient in Fibonacci heaps.
  64.175 +    */
  64.176 +    void erase (const Item& item); 
  64.177 +
  64.178 +    ///Decreases the priority of \c item to \c value.
  64.179 +
  64.180 +    /**
  64.181 +       This method decreases the priority of \c item to \c value.
  64.182 +       \pre \c item must be stored in the heap with priority at least \c
  64.183 +       value relative to \c Compare.
  64.184 +    */
  64.185 +    void decrease (Item item, PrioType const value); 
  64.186 +
  64.187 +    ///Increases the priority of \c item to \c value.
  64.188 +
  64.189 +    /**
  64.190 +       This method sets the priority of \c item to \c value. Though
  64.191 +       there is no precondition on the priority of \c item, this
  64.192 +       method should be used only if it is indeed necessary to increase
  64.193 +       (relative to \c Compare) the priority of \c item, because this
  64.194 +       method is inefficient.
  64.195 +    */
  64.196 +    void increase (Item item, PrioType const value) {
  64.197 +      erase(item);
  64.198 +      push(item, value);
  64.199 +    }
  64.200 +
  64.201 +
  64.202 +    ///Returns if \c item is in, has already been in, or has never been in the heap.
  64.203 +
  64.204 +    /**
  64.205 +       This method returns PRE_HEAP if \c item has never been in the
  64.206 +       heap, IN_HEAP if it is in the heap at the moment, and POST_HEAP
  64.207 +       otherwise. In the latter case it is possible that \c item will
  64.208 +       get back to the heap again.
  64.209 +    */
  64.210 +    state_enum state(const Item &item) const {
  64.211 +      int i=iimap[item];
  64.212 +      if( i>=0 ) {
  64.213 +	if ( container[i].in ) i=0;
  64.214 +	else i=-2; 
  64.215 +      }
  64.216 +      return state_enum(i);
  64.217 +    }    
  64.218 +    
  64.219 +  private:
  64.220 +    
  64.221 +    void balance();
  64.222 +    void makeroot(int c);
  64.223 +    void cut(int a, int b);
  64.224 +    void cascade(int a);
  64.225 +    void fuse(int a, int b);
  64.226 +    void unlace(int a);
  64.227 +
  64.228 +
  64.229 +    class store {
  64.230 +      friend class FibHeap;
  64.231 +      
  64.232 +      Item name;
  64.233 +      int parent;
  64.234 +      int left_neighbor;
  64.235 +      int right_neighbor;
  64.236 +      int child;
  64.237 +      int degree;  
  64.238 +      bool marked;
  64.239 +      bool in;
  64.240 +      PrioType prio;
  64.241 +      
  64.242 +      store() : parent(-1), child(-1), degree(), marked(false), in(true) {} 
  64.243 +    };
  64.244 +  };    
  64.245 + 
  64.246 +
  64.247 +
  64.248 +    // **********************************************************************
  64.249 +    //  IMPLEMENTATIONS
  64.250 +    // **********************************************************************
  64.251 +    
  64.252 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.253 +    typename Compare>
  64.254 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::set 
  64.255 +  (Item const item, PrioType const value) 
  64.256 +  {
  64.257 +    int i=iimap[item];
  64.258 +    if ( i >= 0 && container[i].in ) {
  64.259 +      if ( comp(value, container[i].prio) ) decrease(item, value); 
  64.260 +      if ( comp(container[i].prio, value) ) increase(item, value); 
  64.261 +    } else push(item, value);
  64.262 +  }
  64.263 +    
  64.264 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.265 +    typename Compare>
  64.266 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::push 
  64.267 +  (Item const item, PrioType const value) {
  64.268 +      int i=iimap[item];      
  64.269 +      if ( i < 0 ) {
  64.270 +	int s=container.size();
  64.271 +	iimap.set( item, s );	
  64.272 +	store st;
  64.273 +	st.name=item;
  64.274 +	container.push_back(st);
  64.275 +	i=s;
  64.276 +      } else {
  64.277 +	container[i].parent=container[i].child=-1;
  64.278 +	container[i].degree=0;
  64.279 +	container[i].in=true;
  64.280 +	container[i].marked=false;
  64.281 +      }
  64.282 +
  64.283 +      if ( num_items ) {
  64.284 +	container[container[minimum].right_neighbor].left_neighbor=i;
  64.285 +	container[i].right_neighbor=container[minimum].right_neighbor;
  64.286 +	container[minimum].right_neighbor=i;
  64.287 +	container[i].left_neighbor=minimum;
  64.288 +	if ( comp( value, container[minimum].prio) ) minimum=i; 
  64.289 +      } else {
  64.290 +	container[i].right_neighbor=container[i].left_neighbor=i;
  64.291 +	minimum=i;	
  64.292 +      }
  64.293 +      container[i].prio=value;
  64.294 +      ++num_items;
  64.295 +    }
  64.296 +    
  64.297 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.298 +    typename Compare>
  64.299 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::pop() {
  64.300 +      /*The first case is that there are only one root.*/
  64.301 +      if ( container[minimum].left_neighbor==minimum ) {
  64.302 +	container[minimum].in=false;
  64.303 +	if ( container[minimum].degree!=0 ) { 
  64.304 +	  makeroot(container[minimum].child);
  64.305 +	  minimum=container[minimum].child;
  64.306 +	  balance();
  64.307 +	}
  64.308 +      } else {
  64.309 +	int right=container[minimum].right_neighbor;
  64.310 +	unlace(minimum);
  64.311 +	container[minimum].in=false;
  64.312 +	if ( container[minimum].degree > 0 ) {
  64.313 +	  int left=container[minimum].left_neighbor;
  64.314 +	  int child=container[minimum].child;
  64.315 +	  int last_child=container[child].left_neighbor;
  64.316 +	
  64.317 +	  makeroot(child);
  64.318 +	  
  64.319 +	  container[left].right_neighbor=child;
  64.320 +	  container[child].left_neighbor=left;
  64.321 +	  container[right].left_neighbor=last_child;
  64.322 +	  container[last_child].right_neighbor=right;
  64.323 +	}
  64.324 +	minimum=right;
  64.325 +	balance();
  64.326 +      } // the case where there are more roots
  64.327 +      --num_items;   
  64.328 +    }
  64.329 +
  64.330 +
  64.331 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.332 +    typename Compare>
  64.333 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::erase 
  64.334 +  (const Item& item) {
  64.335 +      int i=iimap[item];
  64.336 +      
  64.337 +      if ( i >= 0 && container[i].in ) { 	
  64.338 +	if ( container[i].parent!=-1 ) {
  64.339 +	  int p=container[i].parent;
  64.340 +	  cut(i,p);	    
  64.341 +	  cascade(p);
  64.342 +	}
  64.343 +	minimum=i;     //As if its prio would be -infinity
  64.344 +	pop();
  64.345 +      }
  64.346 +  }
  64.347 +    
  64.348 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.349 +    typename Compare>
  64.350 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::decrease 
  64.351 +  (Item item, PrioType const value) {
  64.352 +      int i=iimap[item];
  64.353 +      container[i].prio=value;
  64.354 +      int p=container[i].parent;
  64.355 +      
  64.356 +      if ( p!=-1 && comp(value, container[p].prio) ) {
  64.357 +	cut(i,p);	    
  64.358 +	cascade(p);
  64.359 +      }      
  64.360 +      if ( comp(value, container[minimum].prio) ) minimum=i; 
  64.361 +  }
  64.362 + 
  64.363 +
  64.364 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.365 +    typename Compare>
  64.366 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::balance() {      
  64.367 +
  64.368 +    int maxdeg=int( floor( 2.08*log(double(container.size()))))+1;
  64.369 +  
  64.370 +    std::vector<int> A(maxdeg,-1); 
  64.371 +    
  64.372 +    /*
  64.373 +     *Recall that now minimum does not point to the minimum prio element.
  64.374 +     *We set minimum to this during balance().
  64.375 +     */
  64.376 +    int anchor=container[minimum].left_neighbor; 
  64.377 +    int next=minimum; 
  64.378 +    bool end=false; 
  64.379 +    	
  64.380 +       do {
  64.381 +	int active=next;
  64.382 +	if ( anchor==active ) end=true;
  64.383 +	int d=container[active].degree;
  64.384 +	next=container[active].right_neighbor;
  64.385 +
  64.386 +	while (A[d]!=-1) {	  
  64.387 +	  if( comp(container[active].prio, container[A[d]].prio) ) {
  64.388 +	    fuse(active,A[d]); 
  64.389 +	  } else { 
  64.390 +	    fuse(A[d],active);
  64.391 +	    active=A[d];
  64.392 +	  } 
  64.393 +	  A[d]=-1;
  64.394 +	  ++d;
  64.395 +	}	
  64.396 +	A[d]=active;
  64.397 +       } while ( !end );
  64.398 +
  64.399 +
  64.400 +       while ( container[minimum].parent >=0 ) minimum=container[minimum].parent;
  64.401 +       int s=minimum;
  64.402 +       int m=minimum;
  64.403 +       do {  
  64.404 +	 if ( comp(container[s].prio, container[minimum].prio) ) minimum=s;
  64.405 +	 s=container[s].right_neighbor;
  64.406 +       } while ( s != m );
  64.407 +    }
  64.408 +
  64.409 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.410 +    typename Compare>
  64.411 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::makeroot 
  64.412 +  (int c) {
  64.413 +      int s=c;
  64.414 +      do {  
  64.415 +	container[s].parent=-1;
  64.416 +	s=container[s].right_neighbor;
  64.417 +      } while ( s != c );
  64.418 +    }
  64.419 +  
  64.420 +  
  64.421 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.422 +    typename Compare>
  64.423 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::cut 
  64.424 +  (int a, int b) {    
  64.425 +    /*
  64.426 +     *Replacing a from the children of b.
  64.427 +     */
  64.428 +    --container[b].degree;
  64.429 +    
  64.430 +    if ( container[b].degree !=0 ) {
  64.431 +      int child=container[b].child;
  64.432 +      if ( child==a ) 
  64.433 +	container[b].child=container[child].right_neighbor;
  64.434 +      unlace(a);
  64.435 +    }
  64.436 +    
  64.437 +    
  64.438 +    /*Lacing a to the roots.*/
  64.439 +    int right=container[minimum].right_neighbor;
  64.440 +    container[minimum].right_neighbor=a;
  64.441 +    container[a].left_neighbor=minimum;
  64.442 +    container[a].right_neighbor=right;
  64.443 +    container[right].left_neighbor=a;
  64.444 +    
  64.445 +    container[a].parent=-1;
  64.446 +    container[a].marked=false;
  64.447 +  }
  64.448 +  
  64.449 +
  64.450 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.451 +    typename Compare>
  64.452 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::cascade 
  64.453 +  (int a) 
  64.454 +    {
  64.455 +      if ( container[a].parent!=-1 ) {
  64.456 +	int p=container[a].parent;
  64.457 +	
  64.458 +	if ( container[a].marked==false ) container[a].marked=true;
  64.459 +	else {
  64.460 +	  cut(a,p);
  64.461 +	  cascade(p);
  64.462 +	}
  64.463 +      }
  64.464 +    }
  64.465 +
  64.466 +
  64.467 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.468 +    typename Compare>
  64.469 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::fuse 
  64.470 +  (int a, int b) {
  64.471 +      unlace(b);
  64.472 +      
  64.473 +      /*Lacing b under a.*/
  64.474 +      container[b].parent=a;
  64.475 +
  64.476 +      if (container[a].degree==0) {
  64.477 +	container[b].left_neighbor=b;
  64.478 +	container[b].right_neighbor=b;
  64.479 +	container[a].child=b;	
  64.480 +      } else {
  64.481 +	int child=container[a].child;
  64.482 +	int last_child=container[child].left_neighbor;
  64.483 +	container[child].left_neighbor=b;
  64.484 +	container[b].right_neighbor=child;
  64.485 +	container[last_child].right_neighbor=b;
  64.486 +	container[b].left_neighbor=last_child;
  64.487 +      }
  64.488 +
  64.489 +      ++container[a].degree;
  64.490 +      
  64.491 +      container[b].marked=false;
  64.492 +    }
  64.493 +
  64.494 +  
  64.495 +  /*
  64.496 +   *It is invoked only if a has siblings.
  64.497 +   */
  64.498 +  template <typename Item, typename Prio, typename ItemIntMap, 
  64.499 +    typename Compare>
  64.500 +  void FibHeap<Item, Prio, ItemIntMap, Compare>::unlace 
  64.501 +  (int a) {      
  64.502 +      int leftn=container[a].left_neighbor;
  64.503 +      int rightn=container[a].right_neighbor;
  64.504 +      container[leftn].right_neighbor=rightn;
  64.505 +      container[rightn].left_neighbor=leftn;
  64.506 +  }
  64.507 +  
  64.508 +  ///@}
  64.509 +
  64.510 +} //namespace lemon
  64.511 +
  64.512 +#endif //LEMON_FIB_HEAP_H
  64.513 +
    65.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    65.2 +++ b/src/lemon/full_graph.h	Wed Sep 29 15:30:04 2004 +0000
    65.3 @@ -0,0 +1,248 @@
    65.4 +/* -*- C++ -*-
    65.5 + * src/lemon/full_graph.h - Part of LEMON, a generic C++ optimization library
    65.6 + *
    65.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    65.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    65.9 + *
   65.10 + * Permission to use, modify and distribute this software is granted
   65.11 + * provided that this copyright notice appears in all copies. For
   65.12 + * precise terms see the accompanying LICENSE file.
   65.13 + *
   65.14 + * This software is provided "AS IS" with no warranty of any kind,
   65.15 + * express or implied, and with no claim as to its suitability for any
   65.16 + * purpose.
   65.17 + *
   65.18 + */
   65.19 +
   65.20 +#ifndef LEMON_FULL_GRAPH_H
   65.21 +#define LEMON_FULL_GRAPH_H
   65.22 +
   65.23 +///\ingroup graphs
   65.24 +///\file
   65.25 +///\brief FullGraph and SymFullGraph classes.
   65.26 +
   65.27 +#include <vector>
   65.28 +#include <climits>
   65.29 +
   65.30 +#include <lemon/invalid.h>
   65.31 +
   65.32 +#include <lemon/map_registry.h>
   65.33 +#include <lemon/array_map.h>
   65.34 +
   65.35 +#include <lemon/map_defines.h>
   65.36 +
   65.37 +namespace lemon {
   65.38 +
   65.39 +/// \addtogroup graphs
   65.40 +/// @{
   65.41 +
   65.42 +  ///A full graph class.
   65.43 +
   65.44 +  ///This is a simple and fast directed full graph implementation.
   65.45 +  ///It is completely static, so you can neither add nor delete either
   65.46 +  ///edges or nodes.
   65.47 +  ///Thus it conforms to
   65.48 +  ///the \ref skeleton::StaticGraph "StaticGraph" concept
   65.49 +  ///\sa skeleton::StaticGraph.
   65.50 +  ///\todo What about loops?
   65.51 +  ///\todo Don't we need SymEdgeMap?
   65.52 +  ///
   65.53 +  ///\author Alpar Juttner
   65.54 +  class FullGraph {
   65.55 +    int NodeNum;
   65.56 +    int EdgeNum;
   65.57 +  public:
   65.58 +
   65.59 +    typedef FullGraph Graph;
   65.60 +
   65.61 +    class Node;
   65.62 +    class Edge;
   65.63 +
   65.64 +    class NodeIt;
   65.65 +    class EdgeIt;
   65.66 +    class OutEdgeIt;
   65.67 +    class InEdgeIt;
   65.68 +    
   65.69 +
   65.70 +    // Create map registries.
   65.71 +    CREATE_MAP_REGISTRIES;
   65.72 +    // Create node and edge maps.
   65.73 +    CREATE_MAPS(ArrayMap);
   65.74 +    
   65.75 +  public:
   65.76 +
   65.77 +    ///Creates a full graph with \c n nodes.
   65.78 +    FullGraph(int n) : NodeNum(n), EdgeNum(NodeNum*NodeNum) { }
   65.79 +    ///
   65.80 +    FullGraph(const FullGraph &_g)
   65.81 +      : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { }
   65.82 +    
   65.83 +    ///Number of nodes.
   65.84 +    int nodeNum() const { return NodeNum; }
   65.85 +    ///Number of edges.
   65.86 +    int edgeNum() const { return EdgeNum; }
   65.87 +
   65.88 +    /// Maximum node ID.
   65.89 +    
   65.90 +    /// Maximum node ID.
   65.91 +    ///\sa id(Node)
   65.92 +    int maxNodeId() const { return NodeNum-1; }
   65.93 +    /// Maximum edge ID.
   65.94 +    
   65.95 +    /// Maximum edge ID.
   65.96 +    ///\sa id(Edge)
   65.97 +    int maxEdgeId() const { return EdgeNum-1; }
   65.98 +
   65.99 +    Node tail(Edge e) const { return e.n%NodeNum; }
  65.100 +    Node head(Edge e) const { return e.n/NodeNum; }
  65.101 +
  65.102 +    NodeIt& first(NodeIt& v) const {
  65.103 +      v=NodeIt(*this); return v; }
  65.104 +    EdgeIt& first(EdgeIt& e) const { 
  65.105 +      e=EdgeIt(*this); return e; }
  65.106 +    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  65.107 +      e=OutEdgeIt(*this,v); return e; }
  65.108 +    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  65.109 +      e=InEdgeIt(*this,v); return e; }
  65.110 +
  65.111 +    /// Node ID.
  65.112 +    
  65.113 +    /// The ID of a valid Node is a nonnegative integer not greater than
  65.114 +    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  65.115 +    /// and the greatest node ID can be actually less then \ref maxNodeId().
  65.116 +    ///
  65.117 +    /// The ID of the \ref INVALID node is -1.
  65.118 +    ///\return The ID of the node \c v. 
  65.119 +    static int id(Node v) { return v.n; }
  65.120 +    /// Edge ID.
  65.121 +    
  65.122 +    /// The ID of a valid Edge is a nonnegative integer not greater than
  65.123 +    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  65.124 +    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  65.125 +    ///
  65.126 +    /// The ID of the \ref INVALID edge is -1.
  65.127 +    ///\return The ID of the edge \c e. 
  65.128 +    static int id(Edge e) { return e.n; }
  65.129 +
  65.130 +    /// Finds an edge between two nodes.
  65.131 +    
  65.132 +    /// Finds an edge from node \c u to node \c v.
  65.133 +    ///
  65.134 +    /// If \c prev is \ref INVALID (this is the default value), then
  65.135 +    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  65.136 +    /// the next edge from \c u to \c v after \c prev.
  65.137 +    /// \return The found edge or INVALID if there is no such an edge.
  65.138 +    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  65.139 +    {
  65.140 +      return prev.n == -1 ? Edge(*this, u.n, v.n) : INVALID;
  65.141 +    }
  65.142 +    
  65.143 +      
  65.144 +    class Node {
  65.145 +      friend class FullGraph;
  65.146 +      template <typename T> friend class NodeMap;
  65.147 +
  65.148 +      friend class Edge;
  65.149 +      friend class OutEdgeIt;
  65.150 +      friend class InEdgeIt;
  65.151 +      friend class SymEdge;
  65.152 +
  65.153 +    protected:
  65.154 +      int n;
  65.155 +      friend int FullGraph::id(Node v); 
  65.156 +      Node(int nn) {n=nn;}
  65.157 +    public:
  65.158 +      Node() {}
  65.159 +      Node (Invalid) { n=-1; }
  65.160 +      bool operator==(const Node i) const {return n==i.n;}
  65.161 +      bool operator!=(const Node i) const {return n!=i.n;}
  65.162 +      bool operator<(const Node i) const {return n<i.n;}
  65.163 +    };
  65.164 +    
  65.165 +    class NodeIt : public Node {
  65.166 +      const FullGraph *G;
  65.167 +      friend class FullGraph;
  65.168 +    public:
  65.169 +      NodeIt() : Node() { }
  65.170 +      NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { }
  65.171 +      NodeIt(Invalid i) : Node(i) { }
  65.172 +      NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { }
  65.173 +      ///\todo Undocumented conversion Node -\> NodeIt.
  65.174 +      NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; }
  65.175 +    };
  65.176 +
  65.177 +    class Edge {
  65.178 +      friend class FullGraph;
  65.179 +      template <typename T> friend class EdgeMap;
  65.180 +      
  65.181 +      friend class Node;
  65.182 +      friend class NodeIt;
  65.183 +    protected:
  65.184 +      int n; //NodeNum*head+tail;
  65.185 +      friend int FullGraph::id(Edge e);
  65.186 +
  65.187 +      Edge(int nn) : n(nn) {}
  65.188 +      Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
  65.189 +    public:
  65.190 +      Edge() { }
  65.191 +      Edge (Invalid) { n=-1; }
  65.192 +      bool operator==(const Edge i) const {return n==i.n;}
  65.193 +      bool operator!=(const Edge i) const {return n!=i.n;}
  65.194 +      bool operator<(const Edge i) const {return n<i.n;}
  65.195 +      ///\bug This is a workaround until somebody tells me how to
  65.196 +      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  65.197 +      int &idref() {return n;}
  65.198 +      const int &idref() const {return n;}
  65.199 +    };
  65.200 +    
  65.201 +    class EdgeIt : public Edge {
  65.202 +      friend class FullGraph;
  65.203 +    public:
  65.204 +      EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { }
  65.205 +      EdgeIt(const FullGraph&, Edge e) : Edge(e) { }
  65.206 +      EdgeIt (Invalid i) : Edge(i) { }
  65.207 +      EdgeIt() : Edge() { }
  65.208 +      EdgeIt& operator++() { --n; return *this; }
  65.209 +
  65.210 +      ///\bug This is a workaround until somebody tells me how to
  65.211 +      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
  65.212 +      int &idref() {return n;}
  65.213 +    };
  65.214 +    
  65.215 +    class OutEdgeIt : public Edge {
  65.216 +      const FullGraph *G;
  65.217 +      friend class FullGraph;
  65.218 +    public: 
  65.219 +      OutEdgeIt() : Edge() { }
  65.220 +      OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  65.221 +      OutEdgeIt (Invalid i) : Edge(i) { }
  65.222 +
  65.223 +      OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {}
  65.224 +      
  65.225 +      OutEdgeIt& operator++()
  65.226 +      { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; }
  65.227 +
  65.228 +    };
  65.229 +    
  65.230 +    class InEdgeIt : public Edge {
  65.231 +      const FullGraph *G;
  65.232 +      friend class FullGraph;
  65.233 +    public: 
  65.234 +      InEdgeIt() : Edge() { }
  65.235 +      InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
  65.236 +      InEdgeIt (Invalid i) : Edge(i) { }
  65.237 +      InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {}
  65.238 +      InEdgeIt& operator++()
  65.239 +      { if(!((++n)%G->NodeNum)) n=-1; return *this; }
  65.240 +    };
  65.241 +
  65.242 +  };
  65.243 +
  65.244 +  /// @}  
  65.245 +
  65.246 +} //namespace lemon
  65.247 +
  65.248 +
  65.249 +
  65.250 +
  65.251 +#endif //LEMON_FULL_GRAPH_H
    66.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    66.2 +++ b/src/lemon/graph_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
    66.3 @@ -0,0 +1,1227 @@
    66.4 +/* -*- C++ -*-
    66.5 + * src/lemon/graph_wrapper.h - Part of LEMON, a generic C++ optimization library
    66.6 + *
    66.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    66.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    66.9 + *
   66.10 + * Permission to use, modify and distribute this software is granted
   66.11 + * provided that this copyright notice appears in all copies. For
   66.12 + * precise terms see the accompanying LICENSE file.
   66.13 + *
   66.14 + * This software is provided "AS IS" with no warranty of any kind,
   66.15 + * express or implied, and with no claim as to its suitability for any
   66.16 + * purpose.
   66.17 + *
   66.18 + */
   66.19 +
   66.20 +#ifndef LEMON_GRAPH_WRAPPER_H
   66.21 +#define LEMON_GRAPH_WRAPPER_H
   66.22 +
   66.23 +///\ingroup gwrappers
   66.24 +///\file
   66.25 +///\brief Several graph wrappers.
   66.26 +///
   66.27 +///This file contains several useful graph wrapper functions.
   66.28 +///
   66.29 +///\author Marton Makai
   66.30 +
   66.31 +#include <lemon/invalid.h>
   66.32 +#include <lemon/maps.h>
   66.33 +#include <lemon/map_defines.h>
   66.34 +#include <iostream>
   66.35 +
   66.36 +namespace lemon {
   66.37 +
   66.38 +  // Graph wrappers
   66.39 +
   66.40 +  /// \addtogroup gwrappers
   66.41 +  /// A main parts of LEMON are the different graph structures, 
   66.42 +  /// generic graph algorithms, graph concepts which couple these, and 
   66.43 +  /// graph wrappers. While the previous ones are more or less clear, the 
   66.44 +  /// latter notion needs further explanation.
   66.45 +  /// Graph wrappers are graph classes which serve for considering graph 
   66.46 +  /// structures in different ways. A short example makes the notion much 
   66.47 +  /// clearer. 
   66.48 +  /// Suppose that we have an instance \c g of a directed graph
   66.49 +  /// type say \c ListGraph and an algorithm 
   66.50 +  /// \code template<typename Graph> int algorithm(const Graph&); \endcode 
   66.51 +  /// is needed to run on the reversely oriented graph. 
   66.52 +  /// It may be expensive (in time or in memory usage) to copy 
   66.53 +  /// \c g with the reverse orientation. 
   66.54 +  /// Thus, a wrapper class
   66.55 +  /// \code template<typename Graph> class RevGraphWrapper; \endcode is used. 
   66.56 +  /// The code looks as follows
   66.57 +  /// \code
   66.58 +  /// ListGraph g;
   66.59 +  /// RevGraphWrapper<ListGraph> rgw(g);
   66.60 +  /// int result=algorithm(rgw);
   66.61 +  /// \endcode
   66.62 +  /// After running the algorithm, the original graph \c g 
   66.63 +  /// remains untouched. Thus the graph wrapper used above is to consider the 
   66.64 +  /// original graph with reverse orientation. 
   66.65 +  /// This techniques gives rise to an elegant code, and 
   66.66 +  /// based on stable graph wrappers, complex algorithms can be 
   66.67 +  /// implemented easily. 
   66.68 +  /// In flow, circulation and bipartite matching problems, the residual 
   66.69 +  /// graph is of particular importance. Combining a wrapper implementing 
   66.70 +  /// this, shortest path algorithms and minimum mean cycle algorithms, 
   66.71 +  /// a range of weighted and cardinality optimization algorithms can be 
   66.72 +  /// obtained. For lack of space, for other examples, 
   66.73 +  /// the interested user is referred to the detailed documentation of graph 
   66.74 +  /// wrappers. 
   66.75 +  /// The behavior of graph wrappers can be very different. Some of them keep 
   66.76 +  /// capabilities of the original graph while in other cases this would be 
   66.77 +  /// meaningless. This means that the concepts that they are a model of depend 
   66.78 +  /// on the graph wrapper, and the wrapped graph(s). 
   66.79 +  /// If an edge of \c rgw is deleted, this is carried out by 
   66.80 +  /// deleting the corresponding edge of \c g. But for a residual 
   66.81 +  /// graph, this operation has no sense. 
   66.82 +  /// Let we stand one more example here to simplify your work. 
   66.83 +  /// wrapper class
   66.84 +  /// \code template<typename Graph> class RevGraphWrapper; \endcode 
   66.85 +  /// has constructor 
   66.86 +  /// <tt> RevGraphWrapper(Graph& _g)</tt>. 
   66.87 +  /// This means that in a situation, 
   66.88 +  /// when a <tt> const ListGraph& </tt> reference to a graph is given, 
   66.89 +  /// then it have to be instantiated with <tt>Graph=const ListGraph</tt>.
   66.90 +  /// \code
   66.91 +  /// int algorithm1(const ListGraph& g) {
   66.92 +  ///   RevGraphWrapper<const ListGraph> rgw(g);
   66.93 +  ///   return algorithm2(rgw);
   66.94 +  /// }
   66.95 +  /// \endcode
   66.96 +
   66.97 +  /// \addtogroup gwrappers
   66.98 +  /// @{
   66.99 +
  66.100 +  ///Base type for the Graph Wrappers
  66.101 +
  66.102 +  ///\warning Graph wrappers are in even more experimental state than the other
  66.103 +  ///parts of the lib. Use them at you own risk.
  66.104 +  ///
  66.105 +  ///This is the base type for the Graph Wrappers.
  66.106 +  ///\todo Some more docs... 
  66.107 +  ///
  66.108 +  ///\author Marton Makai 
  66.109 +  template<typename Graph>
  66.110 +  class GraphWrapper {
  66.111 +  protected:
  66.112 +    Graph* graph;
  66.113 +    GraphWrapper() : graph(0) { }
  66.114 +    void setGraph(Graph& _graph) { graph=&_graph; }
  66.115 +
  66.116 +  public:
  66.117 +    typedef Graph BaseGraph;
  66.118 +    typedef Graph ParentGraph;
  66.119 +
  66.120 +    GraphWrapper(Graph& _graph) : graph(&_graph) { }
  66.121 +    GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { }
  66.122 + 
  66.123 +    typedef typename Graph::Node Node;
  66.124 +    class NodeIt : public Node { 
  66.125 +      const GraphWrapper<Graph>* gw;
  66.126 +      friend class GraphWrapper<Graph>;
  66.127 +     public:
  66.128 +      NodeIt() { }
  66.129 +      NodeIt(Invalid i) : Node(i) { }
  66.130 +      NodeIt(const GraphWrapper<Graph>& _gw) : 
  66.131 +	Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { }
  66.132 +      NodeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  66.133 +	Node(n), gw(&_gw) { }
  66.134 +      NodeIt& operator++() { 
  66.135 +	*(static_cast<Node*>(this))=
  66.136 +	  ++(typename Graph::NodeIt(*(gw->graph), *this));
  66.137 +	return *this; 
  66.138 +      }
  66.139 +    };
  66.140 +    typedef typename Graph::Edge Edge;
  66.141 +    class OutEdgeIt : public Edge { 
  66.142 +      const GraphWrapper<Graph>* gw;
  66.143 +      friend class GraphWrapper<Graph>;
  66.144 +     public:
  66.145 +      OutEdgeIt() { }
  66.146 +      OutEdgeIt(Invalid i) : Edge(i) { }
  66.147 +      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  66.148 +	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  66.149 +      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  66.150 +	Edge(e), gw(&_gw) { }
  66.151 +      OutEdgeIt& operator++() { 
  66.152 +	*(static_cast<Edge*>(this))=
  66.153 +	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.154 +	return *this; 
  66.155 +      }
  66.156 +    };
  66.157 +    class InEdgeIt : public Edge { 
  66.158 +      const GraphWrapper<Graph>* gw;
  66.159 +      friend class GraphWrapper<Graph>;
  66.160 +     public:
  66.161 +      InEdgeIt() { }
  66.162 +      InEdgeIt(Invalid i) : Edge(i) { }
  66.163 +      InEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
  66.164 +	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  66.165 +      InEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  66.166 +	Edge(e), gw(&_gw) { }
  66.167 +      InEdgeIt& operator++() { 
  66.168 +	*(static_cast<Edge*>(this))=
  66.169 +	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.170 +	return *this; 
  66.171 +      }
  66.172 +    };
  66.173 +    class EdgeIt : public Edge { 
  66.174 +      const GraphWrapper<Graph>* gw;
  66.175 +      friend class GraphWrapper<Graph>;
  66.176 +     public:
  66.177 +      EdgeIt() { }
  66.178 +      EdgeIt(Invalid i) : Edge(i) { }
  66.179 +      EdgeIt(const GraphWrapper<Graph>& _gw) : 
  66.180 +	Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { }
  66.181 +      EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
  66.182 +	Edge(e), gw(&_gw) { }
  66.183 +      EdgeIt& operator++() { 
  66.184 +	*(static_cast<Edge*>(this))=
  66.185 +	  ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.186 +	return *this; 
  66.187 +      }
  66.188 +    };
  66.189 +   
  66.190 +    NodeIt& first(NodeIt& i) const { 
  66.191 +      i=NodeIt(*this); return i;
  66.192 +    }
  66.193 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  66.194 +      i=OutEdgeIt(*this, p); return i;
  66.195 +    }
  66.196 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  66.197 +      i=InEdgeIt(*this, p); return i;
  66.198 +    }
  66.199 +    EdgeIt& first(EdgeIt& i) const { 
  66.200 +      i=EdgeIt(*this); return i;
  66.201 +    }
  66.202 +
  66.203 +    Node tail(const Edge& e) const { 
  66.204 +      return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
  66.205 +    Node head(const Edge& e) const { 
  66.206 +      return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
  66.207 +
  66.208 +    int nodeNum() const { return graph->nodeNum(); }
  66.209 +    int edgeNum() const { return graph->edgeNum(); }
  66.210 +  
  66.211 +    Node addNode() const { return Node(graph->addNode()); }
  66.212 +    Edge addEdge(const Node& tail, const Node& head) const { 
  66.213 +      return Edge(graph->addEdge(tail, head)); }
  66.214 +
  66.215 +    void erase(const Node& i) const { graph->erase(i); }
  66.216 +    void erase(const Edge& i) const { graph->erase(i); }
  66.217 +  
  66.218 +    void clear() const { graph->clear(); }
  66.219 +    
  66.220 +    bool forward(const Edge& e) const { return graph->forward(e); }
  66.221 +    bool backward(const Edge& e) const { return graph->backward(e); }
  66.222 +
  66.223 +    int id(const Node& v) const { return graph->id(v); }
  66.224 +    int id(const Edge& e) const { return graph->id(e); }
  66.225 +    
  66.226 +    Edge opposite(const Edge& e) const { return Edge(graph->opposite(e)); }
  66.227 +
  66.228 +
  66.229 +    IMPORT_NODE_MAP(Graph, *(gw.graph), GraphWrapper, gw);    
  66.230 +    IMPORT_EDGE_MAP(Graph, *(gw.graph), GraphWrapper, gw);
  66.231 +    
  66.232 +
  66.233 +  };
  66.234 +
  66.235 +
  66.236 +
  66.237 +  /// A graph wrapper which reverses the orientation of the edges.
  66.238 +
  66.239 +  ///\warning Graph wrappers are in even more experimental state than the other
  66.240 +  ///parts of the lib. Use them at you own risk.
  66.241 +  ///
  66.242 +  /// A graph wrapper which reverses the orientation of the edges.
  66.243 +  /// Thus \c Graph have to be a directed graph type.
  66.244 +  ///
  66.245 +  ///\author Marton Makai
  66.246 +  template<typename Graph>
  66.247 +  class RevGraphWrapper : public GraphWrapper<Graph> {
  66.248 +  public:
  66.249 +    typedef GraphWrapper<Graph> Parent; 
  66.250 +  protected:
  66.251 +    RevGraphWrapper() : GraphWrapper<Graph>() { }
  66.252 +  public:
  66.253 +    RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
  66.254 +    RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
  66.255 +
  66.256 +    typedef typename GraphWrapper<Graph>::Node Node;
  66.257 +    typedef typename GraphWrapper<Graph>::Edge Edge;
  66.258 +    //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other
  66.259 +    //because this does not work is some of them are not defined in the 
  66.260 +    //original graph. The problem with this is that typedef-ed stuff 
  66.261 +    //are instantiated in c++.
  66.262 +    class OutEdgeIt : public Edge { 
  66.263 +      const RevGraphWrapper<Graph>* gw;
  66.264 +      friend class GraphWrapper<Graph>;
  66.265 +     public:
  66.266 +      OutEdgeIt() { }
  66.267 +      OutEdgeIt(Invalid i) : Edge(i) { }
  66.268 +      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
  66.269 +	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  66.270 +      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
  66.271 +	Edge(e), gw(&_gw) { }
  66.272 +      OutEdgeIt& operator++() { 
  66.273 +	*(static_cast<Edge*>(this))=
  66.274 +	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.275 +	return *this; 
  66.276 +      }
  66.277 +    };
  66.278 +    class InEdgeIt : public Edge { 
  66.279 +      const RevGraphWrapper<Graph>* gw;
  66.280 +      friend class GraphWrapper<Graph>;
  66.281 +     public:
  66.282 +      InEdgeIt() { }
  66.283 +      InEdgeIt(Invalid i) : Edge(i) { }
  66.284 +      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
  66.285 +	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
  66.286 +      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
  66.287 +	Edge(e), gw(&_gw) { }
  66.288 +      InEdgeIt& operator++() { 
  66.289 +	*(static_cast<Edge*>(this))=
  66.290 +	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.291 +	return *this; 
  66.292 +      }
  66.293 +    };
  66.294 +
  66.295 +    using GraphWrapper<Graph>::first;
  66.296 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  66.297 +      i=OutEdgeIt(*this, p); return i;
  66.298 +    }
  66.299 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  66.300 +      i=InEdgeIt(*this, p); return i;
  66.301 +    }
  66.302 +
  66.303 +    Node tail(const Edge& e) const { 
  66.304 +      return GraphWrapper<Graph>::head(e); }
  66.305 +    Node head(const Edge& e) const { 
  66.306 +      return GraphWrapper<Graph>::tail(e); }
  66.307 +
  66.308 +    //    KEEP_MAPS(Parent, RevGraphWrapper);
  66.309 +
  66.310 +  };
  66.311 +
  66.312 +
  66.313 +
  66.314 +  /// A graph wrapper for hiding nodes and edges from a graph.
  66.315 +  
  66.316 +  ///\warning Graph wrappers are in even more experimental state than the other
  66.317 +  ///parts of the lib. Use them at you own risk.
  66.318 +  ///
  66.319 +  /// This wrapper shows a graph with filtered node-set and 
  66.320 +  /// edge-set. Given a bool-valued map on the node-set and one on 
  66.321 +  /// the edge-set of the graphs, the iterators show only the objects 
  66.322 +  /// having true value. 
  66.323 +  /// The quick brown fox iterators jump over 
  66.324 +  /// the lazy dog nodes or edges if their values for are false in the 
  66.325 +  /// corresponding bool maps. 
  66.326 +  ///
  66.327 +  ///\author Marton Makai
  66.328 +  template<typename Graph, typename NodeFilterMap, 
  66.329 +	   typename EdgeFilterMap>
  66.330 +  class SubGraphWrapper : public GraphWrapper<Graph> {
  66.331 +  public:
  66.332 +    typedef GraphWrapper<Graph> Parent;
  66.333 +  protected:
  66.334 +    NodeFilterMap* node_filter_map;
  66.335 +    EdgeFilterMap* edge_filter_map;
  66.336 +
  66.337 +    SubGraphWrapper() : GraphWrapper<Graph>(), 
  66.338 +			node_filter_map(0), edge_filter_map(0) { }
  66.339 +    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
  66.340 +      node_filter_map=&_node_filter_map;
  66.341 +    }
  66.342 +    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
  66.343 +      edge_filter_map=&_edge_filter_map;
  66.344 +    }
  66.345 +    
  66.346 +  public:
  66.347 +    SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
  66.348 +		    EdgeFilterMap& _edge_filter_map) : 
  66.349 +      GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
  66.350 +      edge_filter_map(&_edge_filter_map) { }  
  66.351 +
  66.352 +    typedef typename GraphWrapper<Graph>::Node Node;
  66.353 +    class NodeIt : public Node { 
  66.354 +      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  66.355 +      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  66.356 +    public:
  66.357 +      NodeIt() { }
  66.358 +      NodeIt(Invalid i) : Node(i) { }
  66.359 +      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) : 
  66.360 +	Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { 
  66.361 +	while (*static_cast<Node*>(this)!=INVALID && 
  66.362 +	       !(*(gw->node_filter_map))[*this]) 
  66.363 +	  *(static_cast<Node*>(this))=
  66.364 +	    ++(typename Graph::NodeIt(*(gw->graph), *this));
  66.365 +      }
  66.366 +      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  66.367 +	     const Node& n) : 
  66.368 +	Node(n), gw(&_gw) { }
  66.369 +      NodeIt& operator++() { 
  66.370 +	*(static_cast<Node*>(this))=
  66.371 +	  ++(typename Graph::NodeIt(*(gw->graph), *this));
  66.372 +	while (*static_cast<Node*>(this)!=INVALID && 
  66.373 +	       !(*(gw->node_filter_map))[*this]) 
  66.374 +	  *(static_cast<Node*>(this))=
  66.375 +	    ++(typename Graph::NodeIt(*(gw->graph), *this));
  66.376 +	return *this; 
  66.377 +      }
  66.378 +    };
  66.379 +    typedef typename GraphWrapper<Graph>::Edge Edge;
  66.380 +    class OutEdgeIt : public Edge { 
  66.381 +      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  66.382 +      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  66.383 +    public:
  66.384 +      OutEdgeIt() { }
  66.385 +      OutEdgeIt(Invalid i) : Edge(i) { }
  66.386 +      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 
  66.387 +	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { 
  66.388 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.389 +	       !(*(gw->edge_filter_map))[*this]) 
  66.390 +	  *(static_cast<Edge*>(this))=
  66.391 +	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.392 +      }
  66.393 +      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  66.394 +	     const Edge& e) : 
  66.395 +	Edge(e), gw(&_gw) { }
  66.396 +      OutEdgeIt& operator++() { 
  66.397 +	*(static_cast<Edge*>(this))=
  66.398 +	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.399 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.400 +	       !(*(gw->edge_filter_map))[*this]) 
  66.401 +	  *(static_cast<Edge*>(this))=
  66.402 +	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.403 +	return *this; 
  66.404 +      }
  66.405 +    };
  66.406 +    class InEdgeIt : public Edge { 
  66.407 +      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  66.408 +      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  66.409 +    public:
  66.410 +      InEdgeIt() { }
  66.411 +      //      InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { }
  66.412 +      InEdgeIt(Invalid i) : Edge(i) { }
  66.413 +      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) : 
  66.414 +	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { 
  66.415 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.416 +	       !(*(gw->edge_filter_map))[*this]) 
  66.417 +	  *(static_cast<Edge*>(this))=
  66.418 +	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.419 +      }
  66.420 +      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  66.421 +	     const Edge& e) : 
  66.422 +	Edge(e), gw(&_gw) { }
  66.423 +      InEdgeIt& operator++() { 
  66.424 +	*(static_cast<Edge*>(this))=
  66.425 +	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.426 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.427 +	       !(*(gw->edge_filter_map))[*this]) 
  66.428 +	  *(static_cast<Edge*>(this))=
  66.429 +	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.430 +	return *this; 
  66.431 +      }
  66.432 +    };
  66.433 +    class EdgeIt : public Edge { 
  66.434 +      const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
  66.435 +      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
  66.436 +    public:
  66.437 +      EdgeIt() { }
  66.438 +      EdgeIt(Invalid i) : Edge(i) { }
  66.439 +      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) : 
  66.440 +	Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { 
  66.441 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.442 +	       !(*(gw->edge_filter_map))[*this]) 
  66.443 +	  *(static_cast<Edge*>(this))=
  66.444 +	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.445 +      }
  66.446 +      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, 
  66.447 +	     const Edge& e) : 
  66.448 +	Edge(e), gw(&_gw) { }
  66.449 +      EdgeIt& operator++() { 
  66.450 +	*(static_cast<Edge*>(this))=
  66.451 +	  ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.452 +	while (*static_cast<Edge*>(this)!=INVALID && 
  66.453 +	       !(*(gw->edge_filter_map))[*this]) 
  66.454 +	  *(static_cast<Edge*>(this))=
  66.455 +	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.456 +	return *this; 
  66.457 +      }
  66.458 +    };
  66.459 +
  66.460 +    NodeIt& first(NodeIt& i) const { 
  66.461 +      i=NodeIt(*this); return i;
  66.462 +    }
  66.463 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  66.464 +      i=OutEdgeIt(*this, p); return i;
  66.465 +    }
  66.466 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  66.467 +      i=InEdgeIt(*this, p); return i;
  66.468 +    }
  66.469 +    EdgeIt& first(EdgeIt& i) const { 
  66.470 +      i=EdgeIt(*this); return i;
  66.471 +    }
  66.472 +    
  66.473 +    /// This function hides \c n in the graph, i.e. the iteration 
  66.474 +    /// jumps over it. This is done by simply setting the value of \c n  
  66.475 +    /// to be false in the corresponding node-map.
  66.476 +    void hide(const Node& n) const { node_filter_map->set(n, false); }
  66.477 +
  66.478 +    /// This function hides \c e in the graph, i.e. the iteration 
  66.479 +    /// jumps over it. This is done by simply setting the value of \c e  
  66.480 +    /// to be false in the corresponding edge-map.
  66.481 +    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
  66.482 +
  66.483 +    /// The value of \c n is set to be true in the node-map which stores 
  66.484 +    /// hide information. If \c n was hidden previuosly, then it is shown 
  66.485 +    /// again
  66.486 +     void unHide(const Node& n) const { node_filter_map->set(n, true); }
  66.487 +
  66.488 +    /// The value of \c e is set to be true in the edge-map which stores 
  66.489 +    /// hide information. If \c e was hidden previuosly, then it is shown 
  66.490 +    /// again
  66.491 +    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
  66.492 +
  66.493 +    /// Returns true if \c n is hidden.
  66.494 +    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
  66.495 +
  66.496 +    /// Returns true if \c n is hidden.
  66.497 +    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
  66.498 +
  66.499 +    /// \warning This is a linear time operation and works only if 
  66.500 +    /// \c Graph::NodeIt is defined.
  66.501 +    int nodeNum() const { 
  66.502 +      int i=0;
  66.503 +      for (NodeIt n(*this); n!=INVALID; ++n) ++i;
  66.504 +      return i; 
  66.505 +    }
  66.506 +
  66.507 +    /// \warning This is a linear time operation and works only if 
  66.508 +    /// \c Graph::EdgeIt is defined.
  66.509 +    int edgeNum() const { 
  66.510 +      int i=0;
  66.511 +      for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
  66.512 +      return i; 
  66.513 +    }
  66.514 +
  66.515 +    //    KEEP_MAPS(Parent, SubGraphWrapper);
  66.516 +  };
  66.517 +
  66.518 +
  66.519 +
  66.520 +  template<typename Graph>
  66.521 +  class UndirGraphWrapper : public GraphWrapper<Graph> {
  66.522 +  public:
  66.523 +    typedef GraphWrapper<Graph> Parent; 
  66.524 +  protected:
  66.525 +    UndirGraphWrapper() : GraphWrapper<Graph>() { }
  66.526 +    
  66.527 +  public:
  66.528 +    typedef typename GraphWrapper<Graph>::Node Node;
  66.529 +    typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
  66.530 +    typedef typename GraphWrapper<Graph>::Edge Edge;
  66.531 +    typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
  66.532 +
  66.533 +    UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
  66.534 +
  66.535 +    class OutEdgeIt {
  66.536 +      friend class UndirGraphWrapper<Graph>;
  66.537 +      bool out_or_in; //true iff out
  66.538 +      typename Graph::OutEdgeIt out;
  66.539 +      typename Graph::InEdgeIt in;
  66.540 +    public:
  66.541 +      OutEdgeIt() { }
  66.542 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
  66.543 +      OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& _n) {
  66.544 +	out_or_in=true; _G.graph->first(out, _n);
  66.545 +	if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, _n);	}
  66.546 +      } 
  66.547 +      operator Edge() const { 
  66.548 +	if (out_or_in) return Edge(out); else return Edge(in); 
  66.549 +      }
  66.550 +    };
  66.551 +
  66.552 +    typedef OutEdgeIt InEdgeIt; 
  66.553 +
  66.554 +    using GraphWrapper<Graph>::first;
  66.555 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  66.556 +      i=OutEdgeIt(*this, p); return i;
  66.557 +    }
  66.558 +
  66.559 +    using GraphWrapper<Graph>::next;
  66.560 +
  66.561 +    OutEdgeIt& next(OutEdgeIt& e) const {
  66.562 +      if (e.out_or_in) {
  66.563 +	typename Graph::Node n=this->graph->tail(e.out);
  66.564 +	this->graph->next(e.out);
  66.565 +	if (!this->graph->valid(e.out)) { 
  66.566 +	  e.out_or_in=false; this->graph->first(e.in, n); }
  66.567 +      } else {
  66.568 +	this->graph->next(e.in);
  66.569 +      }
  66.570 +      return e;
  66.571 +    }
  66.572 +
  66.573 +    Node aNode(const OutEdgeIt& e) const { 
  66.574 +      if (e.out_or_in) return this->graph->tail(e); else 
  66.575 +	return this->graph->head(e); }
  66.576 +    Node bNode(const OutEdgeIt& e) const { 
  66.577 +      if (e.out_or_in) return this->graph->head(e); else 
  66.578 +	return this->graph->tail(e); }
  66.579 +
  66.580 +    //    KEEP_MAPS(Parent, UndirGraphWrapper);
  66.581 +
  66.582 +  };
  66.583 +  
  66.584 +//   /// \brief An undirected graph template.
  66.585 +//   ///
  66.586 +//   ///\warning Graph wrappers are in even more experimental state than the other
  66.587 +//   ///parts of the lib. Use them at your own risk.
  66.588 +//   ///
  66.589 +//   /// An undirected graph template.
  66.590 +//   /// This class works as an undirected graph and a directed graph of 
  66.591 +//   /// class \c Graph is used for the physical storage.
  66.592 +//   /// \ingroup graphs
  66.593 +  template<typename Graph>
  66.594 +  class UndirGraph : public UndirGraphWrapper<Graph> {
  66.595 +    typedef UndirGraphWrapper<Graph> Parent;
  66.596 +  protected:
  66.597 +    Graph gr;
  66.598 +  public:
  66.599 +    UndirGraph() : UndirGraphWrapper<Graph>() { 
  66.600 +      Parent::setGraph(gr); 
  66.601 +    }
  66.602 +
  66.603 +    //    KEEP_MAPS(Parent, UndirGraph);
  66.604 +  };
  66.605 +
  66.606 +
  66.607 +
  66.608 +  ///\brief A wrapper for composing a subgraph of a 
  66.609 +  /// bidirected graph made from a directed one. 
  66.610 +  ///
  66.611 +  /// A wrapper for composing a subgraph of a 
  66.612 +  /// bidirected graph made from a directed one. 
  66.613 +  ///
  66.614 +  ///\warning Graph wrappers are in even more experimental state than the other
  66.615 +  ///parts of the lib. Use them at you own risk.
  66.616 +  ///
  66.617 +  /// Suppose that for a directed graph $G=(V, A)$, 
  66.618 +  /// two bool valued maps on the edge-set, 
  66.619 +  /// $forward_filter$, and $backward_filter$ 
  66.620 +  /// is given, and we are dealing with the directed graph
  66.621 +  /// a $G'=(V, \{uv : uv\in A \mbox{ and } forward_filter(uv) \mbox{ is true}\}+\{vu : uv\in A \mbox{ and } backward_filter(uv) \mbox{ is true}\})$. 
  66.622 +  /// The purpose of writing + instead of union is because parallel 
  66.623 +  /// edges can arose. 
  66.624 +  /// In other words, a subgraph of the bidirected graph obtained, which 
  66.625 +  /// is given by orienting the edges of the original graph in both directions.
  66.626 +  /// An example for such a construction is the \c RevGraphWrapper where the 
  66.627 +  /// forward_filter is everywhere false and the backward_filter is 
  66.628 +  /// everywhere true. We note that for sake of efficiency, 
  66.629 +  /// \c RevGraphWrapper is implemented in a different way. 
  66.630 +  /// But BidirGraphWrapper is obtained from 
  66.631 +  /// SubBidirGraphWrapper by considering everywhere true 
  66.632 +  /// valued maps both for forward_filter and backward_filter. 
  66.633 +  /// Finally, one of the most important applications of SubBidirGraphWrapper 
  66.634 +  /// is ResGraphWrapper, which stands for the residual graph in directed 
  66.635 +  /// flow and circulation problems. 
  66.636 +  /// As wrappers usually, the SubBidirGraphWrapper implements the 
  66.637 +  /// above mentioned graph structure without its physical storage, 
  66.638 +  /// that is the whole stuff eats constant memory. 
  66.639 +  /// As the oppositely directed edges are logically different, 
  66.640 +  /// the maps are able to attach different values for them. 
  66.641 +  template<typename Graph, 
  66.642 +	   typename ForwardFilterMap, typename BackwardFilterMap>
  66.643 +  class SubBidirGraphWrapper : public GraphWrapper<Graph> {
  66.644 +  public:
  66.645 +    typedef GraphWrapper<Graph> Parent; 
  66.646 +  protected:
  66.647 +    ForwardFilterMap* forward_filter;
  66.648 +    BackwardFilterMap* backward_filter;
  66.649 +
  66.650 +    SubBidirGraphWrapper() : GraphWrapper<Graph>() { }
  66.651 +    void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
  66.652 +      forward_filter=&_forward_filter;
  66.653 +    }
  66.654 +    void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
  66.655 +      backward_filter=&_backward_filter;
  66.656 +    }
  66.657 +
  66.658 +  public:
  66.659 +
  66.660 +    SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter, 
  66.661 +			 BackwardFilterMap& _backward_filter) : 
  66.662 +      GraphWrapper<Graph>(_graph), 
  66.663 +      forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
  66.664 +    SubBidirGraphWrapper(const SubBidirGraphWrapper<Graph, 
  66.665 +			 ForwardFilterMap, BackwardFilterMap>& gw) : 
  66.666 +      Parent(gw), 
  66.667 +      forward_filter(gw.forward_filter), 
  66.668 +      backward_filter(gw.backward_filter) { }
  66.669 +
  66.670 +    class Edge; 
  66.671 +    class OutEdgeIt; 
  66.672 +    friend class Edge; 
  66.673 +    friend class OutEdgeIt; 
  66.674 +
  66.675 +    template<typename T> class EdgeMap;
  66.676 +
  66.677 +    typedef typename GraphWrapper<Graph>::Node Node;
  66.678 +
  66.679 +    typedef typename Graph::Edge GraphEdge;
  66.680 +    /// SubBidirGraphWrapper<..., ..., ...>::Edge is inherited from 
  66.681 +    /// Graph::Edge. It contains an extra bool flag which is true 
  66.682 +    /// if and only if the 
  66.683 +    /// edge is the backward version of the original edge.
  66.684 +    class Edge : public Graph::Edge {
  66.685 +      friend class SubBidirGraphWrapper<Graph, 
  66.686 +					ForwardFilterMap, BackwardFilterMap>;
  66.687 +      template<typename T> friend class EdgeMap;
  66.688 +    protected:
  66.689 +      bool backward; //true, iff backward
  66.690 +    public:
  66.691 +      Edge() { }
  66.692 +      /// \todo =false is needed, or causes problems?
  66.693 +      /// If \c _backward is false, then we get an edge corresponding to the 
  66.694 +      /// original one, otherwise its oppositely directed pair is obtained.
  66.695 +      Edge(const typename Graph::Edge& e, bool _backward/*=false*/) : 
  66.696 +	Graph::Edge(e), backward(_backward) { }
  66.697 +      Edge(Invalid i) : Graph::Edge(i), backward(true) { }
  66.698 +      bool operator==(const Edge& v) const { 
  66.699 +	return (this->backward==v.backward && 
  66.700 +		static_cast<typename Graph::Edge>(*this)==
  66.701 +		static_cast<typename Graph::Edge>(v));
  66.702 +      } 
  66.703 +      bool operator!=(const Edge& v) const { 
  66.704 +	return (this->backward!=v.backward || 
  66.705 +		static_cast<typename Graph::Edge>(*this)!=
  66.706 +		static_cast<typename Graph::Edge>(v));
  66.707 +      }
  66.708 +    };
  66.709 +
  66.710 +    class OutEdgeIt : public Edge {
  66.711 +      friend class SubBidirGraphWrapper<Graph, 
  66.712 +					ForwardFilterMap, BackwardFilterMap>;
  66.713 +    protected:
  66.714 +      const SubBidirGraphWrapper<Graph, 
  66.715 +				 ForwardFilterMap, BackwardFilterMap>* gw;
  66.716 +    public:
  66.717 +      OutEdgeIt() { }
  66.718 +      OutEdgeIt(Invalid i) : Edge(i) { }
  66.719 +      OutEdgeIt(const SubBidirGraphWrapper<Graph, 
  66.720 +		ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 
  66.721 +	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 
  66.722 +	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.723 +	       !(*(gw->forward_filter))[*this]) 
  66.724 +	  *(static_cast<GraphEdge*>(this))=
  66.725 +	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.726 +	if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.727 +	  *static_cast<Edge*>(this)=
  66.728 +	    Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true);
  66.729 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.730 +		 !(*(gw->backward_filter))[*this]) 
  66.731 +	    *(static_cast<GraphEdge*>(this))=
  66.732 +	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.733 +	}
  66.734 +      }
  66.735 +      OutEdgeIt(const SubBidirGraphWrapper<Graph, 
  66.736 +		ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  66.737 +	Edge(e), gw(&_gw) { }
  66.738 +      OutEdgeIt& operator++() { 
  66.739 +	if (!this->backward) {
  66.740 +	  Node n=gw->tail(*this);
  66.741 +	  *(static_cast<GraphEdge*>(this))=
  66.742 +	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.743 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.744 +		 !(*(gw->forward_filter))[*this]) 
  66.745 +	    *(static_cast<GraphEdge*>(this))=
  66.746 +	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.747 +	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.748 +	    *static_cast<Edge*>(this)=
  66.749 +	      Edge(typename Graph::InEdgeIt(*(gw->graph), n), true);
  66.750 +	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.751 +		   !(*(gw->backward_filter))[*this]) 
  66.752 +	      *(static_cast<GraphEdge*>(this))=
  66.753 +		++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.754 +	  }
  66.755 +	} else {
  66.756 +	  *(static_cast<GraphEdge*>(this))=
  66.757 +	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.758 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.759 +		 !(*(gw->backward_filter))[*this]) 
  66.760 +	    *(static_cast<GraphEdge*>(this))=
  66.761 +	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.762 +	}
  66.763 +	return *this;
  66.764 +      }
  66.765 +    };
  66.766 +
  66.767 +    class InEdgeIt : public Edge {
  66.768 +      friend class SubBidirGraphWrapper<Graph, 
  66.769 +					ForwardFilterMap, BackwardFilterMap>;
  66.770 +    protected:
  66.771 +      const SubBidirGraphWrapper<Graph, 
  66.772 +				 ForwardFilterMap, BackwardFilterMap>* gw;
  66.773 +    public:
  66.774 +      InEdgeIt() { }
  66.775 +      InEdgeIt(Invalid i) : Edge(i) { }
  66.776 +      InEdgeIt(const SubBidirGraphWrapper<Graph, 
  66.777 +	       ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) : 
  66.778 +	Edge(typename Graph::InEdgeIt(*(_gw.graph), n), false), gw(&_gw) { 
  66.779 +	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.780 +	       !(*(gw->forward_filter))[*this]) 
  66.781 +	  *(static_cast<GraphEdge*>(this))=
  66.782 +	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.783 +	if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.784 +	  *static_cast<Edge*>(this)=
  66.785 +	    Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true);
  66.786 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.787 +		 !(*(gw->backward_filter))[*this]) 
  66.788 +	    *(static_cast<GraphEdge*>(this))=
  66.789 +	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.790 +	}
  66.791 +      }
  66.792 +      InEdgeIt(const SubBidirGraphWrapper<Graph, 
  66.793 +	       ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  66.794 +	Edge(e), gw(&_gw) { }
  66.795 +      InEdgeIt& operator++() { 
  66.796 +	if (!this->backward) {
  66.797 +	  Node n=gw->tail(*this);
  66.798 +	  *(static_cast<GraphEdge*>(this))=
  66.799 +	    ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.800 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.801 +		 !(*(gw->forward_filter))[*this]) 
  66.802 +	    *(static_cast<GraphEdge*>(this))=
  66.803 +	      ++(typename Graph::InEdgeIt(*(gw->graph), *this));
  66.804 +	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.805 +	    *static_cast<Edge*>(this)=
  66.806 +	      Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true);
  66.807 +	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.808 +		   !(*(gw->backward_filter))[*this]) 
  66.809 +	      *(static_cast<GraphEdge*>(this))=
  66.810 +		++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.811 +	  }
  66.812 +	} else {
  66.813 +	  *(static_cast<GraphEdge*>(this))=
  66.814 +	    ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.815 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.816 +		 !(*(gw->backward_filter))[*this]) 
  66.817 +	    *(static_cast<GraphEdge*>(this))=
  66.818 +	      ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
  66.819 +	}
  66.820 +	return *this;
  66.821 +      }
  66.822 +    };
  66.823 +
  66.824 +    class EdgeIt : public Edge {
  66.825 +      friend class SubBidirGraphWrapper<Graph, 
  66.826 +					ForwardFilterMap, BackwardFilterMap>;
  66.827 +    protected:
  66.828 +      const SubBidirGraphWrapper<Graph, 
  66.829 +				 ForwardFilterMap, BackwardFilterMap>* gw;
  66.830 +    public:
  66.831 +      EdgeIt() { }
  66.832 +      EdgeIt(Invalid i) : Edge(i) { }
  66.833 +      EdgeIt(const SubBidirGraphWrapper<Graph, 
  66.834 +	     ForwardFilterMap, BackwardFilterMap>& _gw) : 
  66.835 +	Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) { 
  66.836 +	while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.837 +	       !(*(gw->forward_filter))[*this]) 
  66.838 +	  *(static_cast<GraphEdge*>(this))=
  66.839 +	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.840 +	if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.841 +	  *static_cast<Edge*>(this)=
  66.842 +	    Edge(typename Graph::EdgeIt(*(_gw.graph)), true);
  66.843 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.844 +		 !(*(gw->backward_filter))[*this]) 
  66.845 +	    *(static_cast<GraphEdge*>(this))=
  66.846 +	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.847 +	}
  66.848 +      }
  66.849 +      EdgeIt(const SubBidirGraphWrapper<Graph, 
  66.850 +	     ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) : 
  66.851 +	Edge(e), gw(&_gw) { }
  66.852 +      EdgeIt& operator++() { 
  66.853 +	if (!this->backward) {
  66.854 +	  *(static_cast<GraphEdge*>(this))=
  66.855 +	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.856 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.857 +		 !(*(gw->forward_filter))[*this]) 
  66.858 +	    *(static_cast<GraphEdge*>(this))=
  66.859 +	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.860 +	  if (*static_cast<GraphEdge*>(this)==INVALID) {
  66.861 +	    *static_cast<Edge*>(this)=
  66.862 +	      Edge(typename Graph::EdgeIt(*(gw->graph)), true);
  66.863 +	    while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.864 +		   !(*(gw->backward_filter))[*this]) 
  66.865 +	      *(static_cast<GraphEdge*>(this))=
  66.866 +		++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.867 +	  }
  66.868 +	} else {
  66.869 +	  *(static_cast<GraphEdge*>(this))=
  66.870 +	    ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.871 +	  while (*static_cast<GraphEdge*>(this)!=INVALID && 
  66.872 +		 !(*(gw->backward_filter))[*this]) 
  66.873 +	    *(static_cast<GraphEdge*>(this))=
  66.874 +	      ++(typename Graph::EdgeIt(*(gw->graph), *this));
  66.875 +	}
  66.876 +	return *this;
  66.877 +      }
  66.878 +    };
  66.879 +
  66.880 +    using GraphWrapper<Graph>::first;
  66.881 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
  66.882 +      i=OutEdgeIt(*this, p); return i;
  66.883 +    }
  66.884 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
  66.885 +      i=InEdgeIt(*this, p); return i;
  66.886 +    }
  66.887 +    EdgeIt& first(EdgeIt& i) const { 
  66.888 +      i=EdgeIt(*this); return i;
  66.889 +    }
  66.890 +  
  66.891 +
  66.892 +    Node tail(Edge e) const { 
  66.893 +      return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
  66.894 +    Node head(Edge e) const { 
  66.895 +      return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
  66.896 +
  66.897 +    /// Gives back the opposite edge.
  66.898 +    Edge opposite(const Edge& e) const { 
  66.899 +      Edge f=e;
  66.900 +      f.backward=!f.backward;
  66.901 +      return f;
  66.902 +    }
  66.903 +
  66.904 +    /// \warning This is a linear time operation and works only if 
  66.905 +    /// \c Graph::EdgeIt is defined.
  66.906 +    int edgeNum() const { 
  66.907 +      int i=0;
  66.908 +      for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
  66.909 +      return i; 
  66.910 +    }
  66.911 +
  66.912 +    bool forward(const Edge& e) const { return !e.backward; }
  66.913 +    bool backward(const Edge& e) const { return e.backward; }
  66.914 +
  66.915 +
  66.916 +    template <typename T>
  66.917 +    /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two 
  66.918 +    /// Graph::EdgeMap one for the forward edges and 
  66.919 +    /// one for the backward edges.
  66.920 +    class EdgeMap {
  66.921 +      template <typename TT> friend class EdgeMap;
  66.922 +      typename Graph::template EdgeMap<T> forward_map, backward_map; 
  66.923 +    public:
  66.924 +      typedef T ValueType;
  66.925 +      typedef Edge KeyType;
  66.926 +
  66.927 +      EdgeMap(const SubBidirGraphWrapper<Graph, 
  66.928 +	      ForwardFilterMap, BackwardFilterMap>& g) : 
  66.929 +	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
  66.930 +
  66.931 +      EdgeMap(const SubBidirGraphWrapper<Graph, 
  66.932 +	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
  66.933 +	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
  66.934 +
  66.935 +      template <typename TT>
  66.936 +      EdgeMap(const EdgeMap<TT>& copy) 
  66.937 +	: forward_map(copy.forward_map), backward_map(copy.backward_map) {}
  66.938 +
  66.939 +      template <typename TT>
  66.940 +      EdgeMap& operator=(const EdgeMap<TT>& copy) {
  66.941 +	forward_map = copy.forward_map;
  66.942 +	backward_map = copy.backward_map;
  66.943 +	return *this;
  66.944 +      }
  66.945 +      
  66.946 +      void set(Edge e, T a) { 
  66.947 +	if (!e.backward) 
  66.948 +	  forward_map.set(e, a); 
  66.949 +	else 
  66.950 +	  backward_map.set(e, a); 
  66.951 +      }
  66.952 +
  66.953 +      typename Graph::template EdgeMap<T>::ConstReferenceType 
  66.954 +      operator[](Edge e) const { 
  66.955 +	if (!e.backward) 
  66.956 +	  return forward_map[e]; 
  66.957 +	else 
  66.958 +	  return backward_map[e]; 
  66.959 +      }
  66.960 +
  66.961 +      typename Graph::template EdgeMap<T>::ReferenceType 
  66.962 +      operator[](Edge e) { 
  66.963 +	if (!e.backward) 
  66.964 +	  return forward_map[e]; 
  66.965 +	else 
  66.966 +	  return backward_map[e]; 
  66.967 +      }
  66.968 +
  66.969 +      void update() { 
  66.970 +	forward_map.update(); 
  66.971 +	backward_map.update();
  66.972 +      }
  66.973 +    };
  66.974 +
  66.975 +
  66.976 +    //    KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
  66.977 +
  66.978 +  };
  66.979 +
  66.980 +
  66.981 +  ///\brief A wrapper for composing bidirected graph from a directed one. 
  66.982 +  ///
  66.983 +  ///\warning Graph wrappers are in even more experimental state than the other
  66.984 +  ///parts of the lib. Use them at you own risk.
  66.985 +  ///
  66.986 +  /// A wrapper for composing bidirected graph from a directed one. 
  66.987 +  /// A bidirected graph is composed over the directed one without physical 
  66.988 +  /// storage. As the oppositely directed edges are logically different ones 
  66.989 +  /// the maps are able to attach different values for them.
  66.990 +  template<typename Graph>
  66.991 +  class BidirGraphWrapper : 
  66.992 +    public SubBidirGraphWrapper<
  66.993 +    Graph, 
  66.994 +    ConstMap<typename Graph::Edge, bool>, 
  66.995 +    ConstMap<typename Graph::Edge, bool> > {
  66.996 +  public:
  66.997 +    typedef  SubBidirGraphWrapper<
  66.998 +      Graph, 
  66.999 +      ConstMap<typename Graph::Edge, bool>, 
 66.1000 +      ConstMap<typename Graph::Edge, bool> > Parent; 
 66.1001 +  protected:
 66.1002 +    ConstMap<typename Graph::Edge, bool> cm;
 66.1003 +
 66.1004 +    BidirGraphWrapper() : Parent(), cm(true) { 
 66.1005 +      Parent::setForwardFilterMap(cm);
 66.1006 +      Parent::setBackwardFilterMap(cm);
 66.1007 +    }
 66.1008 +  public:
 66.1009 +    BidirGraphWrapper(Graph& _graph) : Parent() { 
 66.1010 +      Parent::setGraph(_graph);
 66.1011 +      Parent::setForwardFilterMap(cm);
 66.1012 +      Parent::setBackwardFilterMap(cm);
 66.1013 +    }
 66.1014 +
 66.1015 +    int edgeNum() const { 
 66.1016 +      return 2*this->graph->edgeNum();
 66.1017 +    }
 66.1018 +    //    KEEP_MAPS(Parent, BidirGraphWrapper);
 66.1019 +  };
 66.1020 +
 66.1021 +
 66.1022 +  /// \brief A bidirected graph template.
 66.1023 +  ///
 66.1024 +  ///\warning Graph wrappers are in even more experimental state than the other
 66.1025 +  ///parts of the lib. Use them at you own risk.
 66.1026 +  ///
 66.1027 +  /// A bidirected graph template.
 66.1028 +  /// Such a bidirected graph stores each pair of oppositely directed edges 
 66.1029 +  /// ones in the memory, i.e. a directed graph of type 
 66.1030 +  /// \c Graph is used for that.
 66.1031 +  /// As the oppositely directed edges are logically different ones 
 66.1032 +  /// the maps are able to attach different values for them.
 66.1033 +  /// \ingroup graphs
 66.1034 +  template<typename Graph>
 66.1035 +  class BidirGraph : public BidirGraphWrapper<Graph> {
 66.1036 +  public:
 66.1037 +    typedef UndirGraphWrapper<Graph> Parent;
 66.1038 +  protected:
 66.1039 +    Graph gr;
 66.1040 +  public:
 66.1041 +    BidirGraph() : BidirGraphWrapper<Graph>() { 
 66.1042 +      Parent::setGraph(gr); 
 66.1043 +    }
 66.1044 +    //    KEEP_MAPS(Parent, BidirGraph);
 66.1045 +  };
 66.1046 +
 66.1047 +
 66.1048 +
 66.1049 +  template<typename Graph, typename Number,
 66.1050 +	   typename CapacityMap, typename FlowMap>
 66.1051 +  class ResForwardFilter {
 66.1052 +    //    const Graph* graph;
 66.1053 +    const CapacityMap* capacity;
 66.1054 +    const FlowMap* flow;
 66.1055 +  public:
 66.1056 +    ResForwardFilter(/*const Graph& _graph, */
 66.1057 +		     const CapacityMap& _capacity, const FlowMap& _flow) :
 66.1058 +      /*graph(&_graph),*/ capacity(&_capacity), flow(&_flow) { }
 66.1059 +    ResForwardFilter() : /*graph(0),*/ capacity(0), flow(0) { }
 66.1060 +    void setCapacity(const CapacityMap& _capacity) { capacity=&_capacity; }
 66.1061 +    void setFlow(const FlowMap& _flow) { flow=&_flow; }
 66.1062 +    bool operator[](const typename Graph::Edge& e) const {
 66.1063 +      return (Number((*flow)[e]) < Number((*capacity)[e]));
 66.1064 +    }
 66.1065 +  };
 66.1066 +
 66.1067 +  template<typename Graph, typename Number,
 66.1068 +	   typename CapacityMap, typename FlowMap>
 66.1069 +  class ResBackwardFilter {
 66.1070 +    const CapacityMap* capacity;
 66.1071 +    const FlowMap* flow;
 66.1072 +  public:
 66.1073 +    ResBackwardFilter(/*const Graph& _graph,*/ 
 66.1074 +		      const CapacityMap& _capacity, const FlowMap& _flow) :
 66.1075 +      /*graph(&_graph),*/ capacity(&_capacity), flow(&_flow) { }
 66.1076 +    ResBackwardFilter() : /*graph(0),*/ capacity(0), flow(0) { }
 66.1077 +    void setCapacity(const CapacityMap& _capacity) { capacity=&_capacity; }
 66.1078 +    void setFlow(const FlowMap& _flow) { flow=&_flow; }
 66.1079 +    bool operator[](const typename Graph::Edge& e) const {
 66.1080 +      return (Number(0) < Number((*flow)[e]));
 66.1081 +    }
 66.1082 +  };
 66.1083 +
 66.1084 +  
 66.1085 +  /// A wrapper for composing the residual graph for directed flow and circulation problems.
 66.1086 +
 66.1087 +  ///\warning Graph wrappers are in even more experimental state than the other
 66.1088 +  ///parts of the lib. Use them at you own risk.
 66.1089 +  ///
 66.1090 +  /// A wrapper for composing the residual graph for directed flow and circulation problems.
 66.1091 +  template<typename Graph, typename Number, 
 66.1092 +	   typename CapacityMap, typename FlowMap>
 66.1093 +  class ResGraphWrapper : 
 66.1094 +    public SubBidirGraphWrapper< 
 66.1095 +    Graph, 
 66.1096 +    ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
 66.1097 +    ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
 66.1098 +  public:
 66.1099 +    typedef SubBidirGraphWrapper< 
 66.1100 +      Graph, 
 66.1101 +      ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
 66.1102 +      ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
 66.1103 +  protected:
 66.1104 +    const CapacityMap* capacity;
 66.1105 +    FlowMap* flow;
 66.1106 +    ResForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
 66.1107 +    ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
 66.1108 +    ResGraphWrapper() : Parent(), 
 66.1109 + 			capacity(0), flow(0) { }
 66.1110 +    void setCapacityMap(const CapacityMap& _capacity) {
 66.1111 +      capacity=&_capacity;
 66.1112 +      forward_filter.setCapacity(_capacity);
 66.1113 +      backward_filter.setCapacity(_capacity);
 66.1114 +    }
 66.1115 +    void setFlowMap(FlowMap& _flow) {
 66.1116 +      flow=&_flow;
 66.1117 +      forward_filter.setFlow(_flow);
 66.1118 +      backward_filter.setFlow(_flow);
 66.1119 +    }
 66.1120 +  public:
 66.1121 +    ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
 66.1122 +		       FlowMap& _flow) : 
 66.1123 +      Parent(), capacity(&_capacity), flow(&_flow), 
 66.1124 +      forward_filter(/*_graph,*/ _capacity, _flow), 
 66.1125 +      backward_filter(/*_graph,*/ _capacity, _flow) {
 66.1126 +      Parent::setGraph(_graph);
 66.1127 +      Parent::setForwardFilterMap(forward_filter);
 66.1128 +      Parent::setBackwardFilterMap(backward_filter);
 66.1129 +    }
 66.1130 +
 66.1131 +    typedef typename Parent::Edge Edge;
 66.1132 +
 66.1133 +    void augment(const Edge& e, Number a) const {
 66.1134 +      if (Parent::forward(e))  
 66.1135 +	flow->set(e, (*flow)[e]+a);
 66.1136 +      else  
 66.1137 +	flow->set(e, (*flow)[e]-a);
 66.1138 +    }
 66.1139 +
 66.1140 +    /// \brief Residual capacity map.
 66.1141 +    ///
 66.1142 +    /// In generic residual graphs the residual capacity can be obtained 
 66.1143 +    /// as a map. 
 66.1144 +    class ResCap {
 66.1145 +    protected:
 66.1146 +      const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>* res_graph;
 66.1147 +    public:
 66.1148 +      typedef Number ValueType;
 66.1149 +      typedef Edge KeyType;
 66.1150 +      ResCap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& 
 66.1151 +	     _res_graph) : res_graph(&_res_graph) { }
 66.1152 +      Number operator[](const Edge& e) const { 
 66.1153 +	if (res_graph->forward(e)) 
 66.1154 +	  return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e]; 
 66.1155 +	else 
 66.1156 +	  return (*(res_graph->flow))[e]; 
 66.1157 +      }
 66.1158 +    };
 66.1159 +
 66.1160 +    //    KEEP_MAPS(Parent, ResGraphWrapper);
 66.1161 +  };
 66.1162 +
 66.1163 +
 66.1164 +  /// For blocking flows.
 66.1165 +
 66.1166 +  ///\warning Graph wrappers are in even more experimental state than the other
 66.1167 +  ///parts of the lib. Use them at you own risk.
 66.1168 +  ///
 66.1169 +  /// This graph wrapper is used for on-the-fly 
 66.1170 +  /// Dinits blocking flow computations.
 66.1171 +  /// For each node, an out-edge is stored which is used when the 
 66.1172 +  /// \code 
 66.1173 +  /// OutEdgeIt& first(OutEdgeIt&, const Node&)
 66.1174 +  /// \endcode
 66.1175 +  /// is called. 
 66.1176 +  ///
 66.1177 +  /// \author Marton Makai
 66.1178 +  template<typename Graph, typename FirstOutEdgesMap>
 66.1179 +  class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
 66.1180 +  public:
 66.1181 +    typedef GraphWrapper<Graph> Parent; 
 66.1182 +  protected:
 66.1183 +    FirstOutEdgesMap* first_out_edges;
 66.1184 +  public:
 66.1185 +    ErasingFirstGraphWrapper(Graph& _graph, 
 66.1186 +			     FirstOutEdgesMap& _first_out_edges) : 
 66.1187 +      GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
 66.1188 +
 66.1189 +    typedef typename GraphWrapper<Graph>::Node Node;
 66.1190 +    typedef typename GraphWrapper<Graph>::Edge Edge;
 66.1191 +    class OutEdgeIt : public Edge { 
 66.1192 +      friend class GraphWrapper<Graph>;
 66.1193 +      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
 66.1194 +      const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
 66.1195 +    public:
 66.1196 +      OutEdgeIt() { }
 66.1197 +      OutEdgeIt(Invalid i) : Edge(i) { }
 66.1198 +      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
 66.1199 +		const Node& n) : 
 66.1200 +	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
 66.1201 +      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
 66.1202 +		const Edge& e) : 
 66.1203 +	Edge(e), gw(&_gw) { }
 66.1204 +      OutEdgeIt& operator++() { 
 66.1205 +	*(static_cast<Edge*>(this))=
 66.1206 +	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
 66.1207 +	return *this; 
 66.1208 +      }
 66.1209 +    };
 66.1210 +
 66.1211 +    using GraphWrapper<Graph>::first;
 66.1212 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
 66.1213 +      i=OutEdgeIt(*this, p); return i;
 66.1214 +    }
 66.1215 +    void erase(const Edge& e) const {
 66.1216 +      Node n=tail(e);
 66.1217 +      typename Graph::OutEdgeIt f(*Parent::graph, n);
 66.1218 +      ++f;
 66.1219 +      first_out_edges->set(n, f);
 66.1220 +    }
 66.1221 +
 66.1222 +    //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
 66.1223 +  };
 66.1224 +
 66.1225 +  ///@}
 66.1226 +
 66.1227 +} //namespace lemon
 66.1228 +
 66.1229 +#endif //LEMON_GRAPH_WRAPPER_H
 66.1230 +
    67.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    67.2 +++ b/src/lemon/invalid.h	Wed Sep 29 15:30:04 2004 +0000
    67.3 @@ -0,0 +1,52 @@
    67.4 +/* -*- C++ -*-
    67.5 + * src/lemon/invalid.h - Part of LEMON, a generic C++ optimization library
    67.6 + *
    67.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    67.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    67.9 + *
   67.10 + * Permission to use, modify and distribute this software is granted
   67.11 + * provided that this copyright notice appears in all copies. For
   67.12 + * precise terms see the accompanying LICENSE file.
   67.13 + *
   67.14 + * This software is provided "AS IS" with no warranty of any kind,
   67.15 + * express or implied, and with no claim as to its suitability for any
   67.16 + * purpose.
   67.17 + *
   67.18 + */
   67.19 +
   67.20 +#ifndef LEMON_INVALID_H
   67.21 +#define LEMON_INVALID_H
   67.22 +
   67.23 +///\file
   67.24 +///\brief Definition of INVALID.
   67.25 +
   67.26 +namespace lemon {
   67.27 +
   67.28 +  /// Dummy type to make it easier to make invalid iterators.
   67.29 +  
   67.30 +  /// See \ref INVALID, how to use it.
   67.31 +  
   67.32 +  struct Invalid {
   67.33 +  public:
   67.34 +    bool operator==(Invalid) { return true;  }
   67.35 +    bool operator!=(Invalid) { return false; }
   67.36 +    bool operator< (Invalid) { return false; }
   67.37 +  };
   67.38 +  
   67.39 +  /// Invalid iterators.
   67.40 +  
   67.41 +  /// \ref Invalid is a global type that converts to each iterator
   67.42 +  /// in such a way that the value of the target iterator will be invalid.
   67.43 +
   67.44 +  // It is also used to convert the \c INVALID constant to the
   67.45 +  // node iterator that makes is possible to write 
   67.46 +
   67.47 +  //extern Invalid INVALID;
   67.48 +
   67.49 +  //const Invalid &INVALID = *(Invalid *)0;
   67.50 +  const Invalid INVALID = Invalid();
   67.51 +
   67.52 +} //namespace lemon
   67.53 +
   67.54 +#endif
   67.55 +  
    68.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    68.2 +++ b/src/lemon/kruskal.h	Wed Sep 29 15:30:04 2004 +0000
    68.3 @@ -0,0 +1,348 @@
    68.4 +/* -*- C++ -*-
    68.5 + * src/lemon/kruskal.h - Part of LEMON, a generic C++ optimization library
    68.6 + *
    68.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    68.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    68.9 + *
   68.10 + * Permission to use, modify and distribute this software is granted
   68.11 + * provided that this copyright notice appears in all copies. For
   68.12 + * precise terms see the accompanying LICENSE file.
   68.13 + *
   68.14 + * This software is provided "AS IS" with no warranty of any kind,
   68.15 + * express or implied, and with no claim as to its suitability for any
   68.16 + * purpose.
   68.17 + *
   68.18 + */
   68.19 +
   68.20 +#ifndef LEMON_KRUSKAL_H
   68.21 +#define LEMON_KRUSKAL_H
   68.22 +
   68.23 +#include <algorithm>
   68.24 +#include <lemon/unionfind.h>
   68.25 +
   68.26 +/**
   68.27 +@defgroup spantree Minimum Cost Spanning Tree Algorithms
   68.28 +@ingroup galgs
   68.29 +\brief This group containes the algorithms for finding a minimum cost spanning
   68.30 +tree in a graph
   68.31 +
   68.32 +This group containes the algorithms for finding a minimum cost spanning
   68.33 +tree in a graph
   68.34 +*/
   68.35 +
   68.36 +///\ingroup spantree
   68.37 +///\file
   68.38 +///\brief Kruskal's algorithm to compute a minimum cost tree
   68.39 +///
   68.40 +///Kruskal's algorithm to compute a minimum cost tree.
   68.41 +
   68.42 +namespace lemon {
   68.43 +
   68.44 +  /// \addtogroup spantree
   68.45 +  /// @{
   68.46 +
   68.47 +  /// Kruskal's algorithm to find a minimum cost tree of a graph.
   68.48 +
   68.49 +  /// This function runs Kruskal's algorithm to find a minimum cost tree.
   68.50 +  /// \param G The graph the algorithm runs on. The algorithm considers the
   68.51 +  /// graph to be undirected, the direction of the edges are not used.
   68.52 +  ///
   68.53 +  /// \param in This object is used to describe the edge costs. It must
   68.54 +  /// be an STL compatible 'Forward Container'
   68.55 +  /// with <tt>std::pair<GR::Edge,X></tt> as its <tt>value_type</tt>,
   68.56 +  /// where X is the type of the costs. It must contain every edge in
   68.57 +  /// cost-ascending order.
   68.58 +  ///\par
   68.59 +  /// For the sake of simplicity, there is a helper class KruskalMapInput,
   68.60 +  /// which converts a
   68.61 +  /// simple edge map to an input of this form. Alternatively, you can use
   68.62 +  /// the function \ref kruskalEdgeMap to compute the minimum cost tree if
   68.63 +  /// the edge costs are given by an edge map.
   68.64 +  ///
   68.65 +  /// \retval out This must be a writable \c bool edge map.
   68.66 +  /// After running the algorithm
   68.67 +  /// this will contain the found minimum cost spanning tree: the value of an
   68.68 +  /// edge will be set to \c true if it belongs to the tree, otherwise it will
   68.69 +  /// be set to \c false. The value of each edge will be set exactly once.
   68.70 +  ///
   68.71 +  /// \return The cost of the found tree.
   68.72 +
   68.73 +  template <class GR, class IN, class OUT>
   68.74 +  typename IN::value_type::second_type
   68.75 +  kruskal(GR const& G, IN const& in, 
   68.76 +		 OUT& out)
   68.77 +  {
   68.78 +    typedef typename IN::value_type::second_type EdgeCost;
   68.79 +    typedef typename GR::template NodeMap<int> NodeIntMap;
   68.80 +    typedef typename GR::Node Node;
   68.81 +
   68.82 +    NodeIntMap comp(G, -1);
   68.83 +    UnionFind<Node,NodeIntMap> uf(comp); 
   68.84 +      
   68.85 +    EdgeCost tot_cost = 0;
   68.86 +    for (typename IN::const_iterator p = in.begin(); 
   68.87 +	 p!=in.end(); ++p ) {
   68.88 +      if ( uf.join(G.head((*p).first),
   68.89 +		   G.tail((*p).first)) ) {
   68.90 +	out.set((*p).first, true);
   68.91 +	tot_cost += (*p).second;
   68.92 +      }
   68.93 +      else {
   68.94 +	out.set((*p).first, false);
   68.95 +      }
   68.96 +    }
   68.97 +    return tot_cost;
   68.98 +  }
   68.99 +
  68.100 +  /* A work-around for running Kruskal with const-reference bool maps... */
  68.101 +
  68.102 +  /// Helper class for calling kruskal with "constant" output map.
  68.103 +
  68.104 +  /// Helper class for calling kruskal with output maps constructed
  68.105 +  /// on-the-fly.
  68.106 +  ///
  68.107 +  /// A typical examle is the following call:
  68.108 +  /// <tt>kruskal(G, some_input, makeSequenceOutput(iterator))</tt>.
  68.109 +  /// Here, the third argument is a temporary object (which wraps around an
  68.110 +  /// iterator with a writable bool map interface), and thus by rules of C++
  68.111 +  /// is a \c const object. To enable call like this exist this class and
  68.112 +  /// the prototype of the \ref kruskal() function with <tt>const& OUT</tt>
  68.113 +  /// third argument.
  68.114 +  template<class Map>
  68.115 +  class NonConstMapWr {
  68.116 +    const Map &m;
  68.117 +  public:
  68.118 +    typedef typename Map::ValueType ValueType;
  68.119 +
  68.120 +    NonConstMapWr(const Map &_m) : m(_m) {}
  68.121 +
  68.122 +    template<class KeyType>
  68.123 +    void set(KeyType const& k, ValueType const &v) const { m.set(k,v); }
  68.124 +  };
  68.125 +
  68.126 +  template <class GR, class IN, class OUT>
  68.127 +  inline
  68.128 +  typename IN::value_type::second_type
  68.129 +  kruskal(GR const& G, IN const& edges, OUT const& out_map)
  68.130 +  {
  68.131 +    NonConstMapWr<OUT> map_wr(out_map);
  68.132 +    return kruskal(G, edges, map_wr);
  68.133 +  }  
  68.134 +
  68.135 +  /* ** ** Input-objects ** ** */
  68.136 +
  68.137 +  /// Kruskal input source.
  68.138 +
  68.139 +  /// Kruskal input source.
  68.140 +  ///
  68.141 +  /// In most cases you possibly want to use the \ref kruskalEdgeMap() instead.
  68.142 +  ///
  68.143 +  /// \sa makeKruskalMapInput()
  68.144 +  ///
  68.145 +  ///\param GR The type of the graph the algorithm runs on.
  68.146 +  ///\param Map An edge map containing the cost of the edges.
  68.147 +  ///\par
  68.148 +  ///The cost type can be any type satisfying
  68.149 +  ///the STL 'LessThan comparable'
  68.150 +  ///concept if it also has an operator+() implemented. (It is necessary for
  68.151 +  ///computing the total cost of the tree).
  68.152 +  ///
  68.153 +  template<class GR, class Map>
  68.154 +  class KruskalMapInput
  68.155 +    : public std::vector< std::pair<typename GR::Edge,
  68.156 +				    typename Map::ValueType> > {
  68.157 +    
  68.158 +  public:
  68.159 +    typedef std::vector< std::pair<typename GR::Edge,
  68.160 +				   typename Map::ValueType> > Parent;
  68.161 +    typedef typename Parent::value_type value_type;
  68.162 +
  68.163 +  private:
  68.164 +    class comparePair {
  68.165 +    public:
  68.166 +      bool operator()(const value_type& a,
  68.167 +		      const value_type& b) {
  68.168 +	return a.second < b.second;
  68.169 +      }
  68.170 +    };
  68.171 +
  68.172 +  public:
  68.173 +
  68.174 +    void sort() {
  68.175 +      std::sort(this->begin(), this->end(), comparePair());
  68.176 +    }
  68.177 +
  68.178 +    KruskalMapInput(GR const& G, Map const& m) {
  68.179 +      typedef typename GR::EdgeIt EdgeIt;
  68.180 +      
  68.181 +      for(EdgeIt e(G);e!=INVALID;++e) push_back(value_type(e, m[e]));
  68.182 +      sort();
  68.183 +    }
  68.184 +  };
  68.185 +
  68.186 +  /// Creates a KruskalMapInput object for \ref kruskal()
  68.187 +
  68.188 +  /// It makes is easier to use 
  68.189 +  /// \ref KruskalMapInput by making it unnecessary 
  68.190 +  /// to explicitly give the type of the parameters.
  68.191 +  ///
  68.192 +  /// In most cases you possibly
  68.193 +  /// want to use the function kruskalEdgeMap() instead.
  68.194 +  ///
  68.195 +  ///\param G The type of the graph the algorithm runs on.
  68.196 +  ///\param m An edge map containing the cost of the edges.
  68.197 +  ///\par
  68.198 +  ///The cost type can be any type satisfying the
  68.199 +  ///STL 'LessThan Comparable'
  68.200 +  ///concept if it also has an operator+() implemented. (It is necessary for
  68.201 +  ///computing the total cost of the tree).
  68.202 +  ///
  68.203 +  ///\return An appropriate input source for \ref kruskal().
  68.204 +  ///
  68.205 +  template<class GR, class Map>
  68.206 +  inline
  68.207 +  KruskalMapInput<GR,Map> makeKruskalMapInput(const GR &G,const Map &m)
  68.208 +  {
  68.209 +    return KruskalMapInput<GR,Map>(G,m);
  68.210 +  }
  68.211 +  
  68.212 +  
  68.213 +
  68.214 +  /* ** ** Output-objects: simple writable bool maps ** ** */
  68.215 +  
  68.216 +
  68.217 +
  68.218 +  /// A writable bool-map that makes a sequence of "true" keys
  68.219 +
  68.220 +  /// A writable bool-map that creates a sequence out of keys that receives
  68.221 +  /// the value "true".
  68.222 +  ///
  68.223 +  /// \sa makeKruskalSequenceOutput()
  68.224 +  ///
  68.225 +  /// Very often, when looking for a min cost spanning tree, we want as
  68.226 +  /// output a container containing the edges of the found tree. For this
  68.227 +  /// purpose exist this class that wraps around an STL iterator with a
  68.228 +  /// writable bool map interface. When a key gets value "true" this key
  68.229 +  /// is added to sequence pointed by the iterator.
  68.230 +  ///
  68.231 +  /// A typical usage:
  68.232 +  /// \code
  68.233 +  /// std::vector<Graph::Edge> v;
  68.234 +  /// kruskal(g, input, makeKruskalSequenceOutput(back_inserter(v)));
  68.235 +  /// \endcode
  68.236 +  /// 
  68.237 +  /// For the most common case, when the input is given by a simple edge
  68.238 +  /// map and the output is a sequence of the tree edges, a special
  68.239 +  /// wrapper function exists: \ref kruskalEdgeMap_IteratorOut().
  68.240 +  ///
  68.241 +  /// \warning Not a regular property map, as it doesn't know its KeyType
  68.242 +
  68.243 +  template<class Iterator>
  68.244 +  class KruskalSequenceOutput {
  68.245 +    mutable Iterator it;
  68.246 +
  68.247 +  public:
  68.248 +    typedef bool ValueType;
  68.249 +
  68.250 +    KruskalSequenceOutput(Iterator const &_it) : it(_it) {}
  68.251 +
  68.252 +    template<typename KeyType>
  68.253 +    void set(KeyType const& k, bool v) const { if(v) {*it=k; ++it;} }
  68.254 +  };
  68.255 +
  68.256 +  template<class Iterator>
  68.257 +  inline
  68.258 +  KruskalSequenceOutput<Iterator>
  68.259 +  makeKruskalSequenceOutput(Iterator it) {
  68.260 +    return KruskalSequenceOutput<Iterator>(it);
  68.261 +  }
  68.262 +
  68.263 +
  68.264 +
  68.265 +  /* ** ** Wrapper funtions ** ** */
  68.266 +
  68.267 +
  68.268 +
  68.269 +  /// \brief Wrapper function to kruskal().
  68.270 +  /// Input is from an edge map, output is a plain bool map.
  68.271 +  ///
  68.272 +  /// Wrapper function to kruskal().
  68.273 +  /// Input is from an edge map, output is a plain bool map.
  68.274 +  ///
  68.275 +  ///\param G The type of the graph the algorithm runs on.
  68.276 +  ///\param in An edge map containing the cost of the edges.
  68.277 +  ///\par
  68.278 +  ///The cost type can be any type satisfying the
  68.279 +  ///STL 'LessThan Comparable'
  68.280 +  ///concept if it also has an operator+() implemented. (It is necessary for
  68.281 +  ///computing the total cost of the tree).
  68.282 +  ///
  68.283 +  /// \retval out This must be a writable \c bool edge map.
  68.284 +  /// After running the algorithm
  68.285 +  /// this will contain the found minimum cost spanning tree: the value of an
  68.286 +  /// edge will be set to \c true if it belongs to the tree, otherwise it will
  68.287 +  /// be set to \c false. The value of each edge will be set exactly once.
  68.288 +  ///
  68.289 +  /// \return The cost of the found tree.
  68.290 +
  68.291 +  template <class GR, class IN, class RET>
  68.292 +  inline
  68.293 +  typename IN::ValueType
  68.294 +  kruskalEdgeMap(GR const& G,
  68.295 +		 IN const& in,
  68.296 +		 RET &out) {
  68.297 +    return kruskal(G,
  68.298 +		   KruskalMapInput<GR,IN>(G,in),
  68.299 +		   out);
  68.300 +  }
  68.301 +
  68.302 +  /// \brief Wrapper function to kruskal().
  68.303 +  /// Input is from an edge map, output is an STL Sequence.
  68.304 +  ///
  68.305 +  /// Wrapper function to kruskal().
  68.306 +  /// Input is from an edge map, output is an STL Sequence.
  68.307 +  ///
  68.308 +  ///\param G The type of the graph the algorithm runs on.
  68.309 +  ///\param in An edge map containing the cost of the edges.
  68.310 +  ///\par
  68.311 +  ///The cost type can be any type satisfying the
  68.312 +  ///STL 'LessThan Comparable'
  68.313 +  ///concept if it also has an operator+() implemented. (It is necessary for
  68.314 +  ///computing the total cost of the tree).
  68.315 +  ///
  68.316 +  /// \retval out This must be an iteraror of an STL Container with
  68.317 +  /// <tt>GR::Edge</tt> as its <tt>value_type</tt>.
  68.318 +  /// The algorithm copies the elements of the found tree into this sequence.
  68.319 +  /// For example, if we know that the spanning tree of the graph \c G has
  68.320 +  /// say 53 edges then
  68.321 +  /// we can put its edges into a STL vector \c tree with a code like this.
  68.322 +  /// \code
  68.323 +  /// std::vector<Edge> tree(53);
  68.324 +  /// kruskalEdgeMap_IteratorOut(G,cost,tree.begin());
  68.325 +  /// \endcode
  68.326 +  /// Or if we don't know in advance the size of the tree, we can write this.
  68.327 +  /// \code
  68.328 +  /// std::vector<Edge> tree;
  68.329 +  /// kruskalEdgeMap_IteratorOut(G,cost,std::back_inserter(tree));
  68.330 +  /// \endcode
  68.331 +  ///
  68.332 +  /// \return The cost of the found tree.
  68.333 +  ///
  68.334 +  /// \bug its name does not follow the coding style.
  68.335 +
  68.336 +  template <class GR, class IN, class RET>
  68.337 +  inline
  68.338 +  typename IN::ValueType
  68.339 +  kruskalEdgeMap_IteratorOut(const GR& G,
  68.340 +			     const IN& in,
  68.341 +			     RET out)
  68.342 +  {
  68.343 +    KruskalSequenceOutput<RET> _out(out);
  68.344 +    return kruskal(G, KruskalMapInput<GR,IN>(G, in), _out);
  68.345 +  }
  68.346 +
  68.347 +  /// @}
  68.348 +
  68.349 +} //namespace lemon
  68.350 +
  68.351 +#endif //LEMON_KRUSKAL_H
    69.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    69.2 +++ b/src/lemon/list_graph.h	Wed Sep 29 15:30:04 2004 +0000
    69.3 @@ -0,0 +1,1106 @@
    69.4 +/* -*- C++ -*-
    69.5 + * src/lemon/list_graph.h - Part of LEMON, a generic C++ optimization library
    69.6 + *
    69.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    69.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    69.9 + *
   69.10 + * Permission to use, modify and distribute this software is granted
   69.11 + * provided that this copyright notice appears in all copies. For
   69.12 + * precise terms see the accompanying LICENSE file.
   69.13 + *
   69.14 + * This software is provided "AS IS" with no warranty of any kind,
   69.15 + * express or implied, and with no claim as to its suitability for any
   69.16 + * purpose.
   69.17 + *
   69.18 + */
   69.19 +
   69.20 +#ifndef LEMON_LIST_GRAPH_H
   69.21 +#define LEMON_LIST_GRAPH_H
   69.22 +
   69.23 +///\ingroup graphs
   69.24 +///\file
   69.25 +///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
   69.26 +
   69.27 +#include <vector>
   69.28 +#include <climits>
   69.29 +
   69.30 +#include <lemon/invalid.h>
   69.31 +
   69.32 +#include <lemon/map_registry.h>
   69.33 +#include <lemon/array_map.h>
   69.34 +
   69.35 +#include <lemon/sym_map.h>
   69.36 +
   69.37 +#include <lemon/map_defines.h>
   69.38 +
   69.39 +
   69.40 +namespace lemon {
   69.41 +
   69.42 +/// \addtogroup graphs
   69.43 +/// @{
   69.44 +
   69.45 +  ///A list graph class.
   69.46 +
   69.47 +  ///This is a simple and fast erasable graph implementation.
   69.48 +  ///
   69.49 +  ///It conforms to the
   69.50 +  ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
   69.51 +  ///\sa skeleton::ErasableGraph.
   69.52 +  class ListGraph {
   69.53 +
   69.54 +    //Nodes are double linked.
   69.55 +    //The free nodes are only single linked using the "next" field.
   69.56 +    struct NodeT 
   69.57 +    {
   69.58 +      int first_in,first_out;
   69.59 +      int prev, next;
   69.60 +    };
   69.61 +    //Edges are double linked.
   69.62 +    //The free edges are only single linked using the "next_in" field.
   69.63 +    struct EdgeT 
   69.64 +    {
   69.65 +      int head, tail;
   69.66 +      int prev_in, prev_out;
   69.67 +      int next_in, next_out;
   69.68 +    };
   69.69 +
   69.70 +    std::vector<NodeT> nodes;
   69.71 +    //The first node
   69.72 +    int first_node;
   69.73 +    //The first free node
   69.74 +    int first_free_node;
   69.75 +    std::vector<EdgeT> edges;
   69.76 +    //The first free edge
   69.77 +    int first_free_edge;
   69.78 +    
   69.79 +  public:
   69.80 +    
   69.81 +    typedef ListGraph Graph;
   69.82 +    
   69.83 +    class Node;
   69.84 +    class Edge;
   69.85 +
   69.86 +    
   69.87 +  public:
   69.88 +
   69.89 +    class NodeIt;
   69.90 +    class EdgeIt;
   69.91 +    class OutEdgeIt;
   69.92 +    class InEdgeIt;
   69.93 +
   69.94 +    // Create map registries.
   69.95 +    CREATE_MAP_REGISTRIES;
   69.96 +    // Create node and edge maps.
   69.97 +    CREATE_MAPS(ArrayMap);
   69.98 +
   69.99 +  public:
  69.100 +
  69.101 +    ListGraph() 
  69.102 +      : nodes(), first_node(-1),
  69.103 +	first_free_node(-1), edges(), first_free_edge(-1) {}
  69.104 +
  69.105 +    ListGraph(const ListGraph &_g) 
  69.106 +      : nodes(_g.nodes), first_node(_g.first_node),
  69.107 +	first_free_node(_g.first_free_node), edges(_g.edges),
  69.108 +	first_free_edge(_g.first_free_edge) {}
  69.109 +    
  69.110 +    ///Number of nodes.
  69.111 +    int nodeNum() const { return nodes.size(); }
  69.112 +    ///Number of edges.
  69.113 +    int edgeNum() const { return edges.size(); }
  69.114 +
  69.115 +    ///Set the expected maximum number of edges.
  69.116 +
  69.117 +    ///With this function, it is possible to set the expected number of edges.
  69.118 +    ///The use of this fasten the building of the graph and makes
  69.119 +    ///it possible to avoid the superfluous memory allocation.
  69.120 +    void reserveEdge(int n) { edges.reserve(n); };
  69.121 +    
  69.122 +    /// Maximum node ID.
  69.123 +    
  69.124 +    /// Maximum node ID.
  69.125 +    ///\sa id(Node)
  69.126 +    int maxNodeId() const { return nodes.size()-1; } 
  69.127 +    /// Maximum edge ID.
  69.128 +    
  69.129 +    /// Maximum edge ID.
  69.130 +    ///\sa id(Edge)
  69.131 +    int maxEdgeId() const { return edges.size()-1; }
  69.132 +
  69.133 +    Node tail(Edge e) const { return edges[e.n].tail; }
  69.134 +    Node head(Edge e) const { return edges[e.n].head; }
  69.135 +
  69.136 +    NodeIt& first(NodeIt& v) const { 
  69.137 +      v=NodeIt(*this); return v; }
  69.138 +    EdgeIt& first(EdgeIt& e) const { 
  69.139 +      e=EdgeIt(*this); return e; }
  69.140 +    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  69.141 +      e=OutEdgeIt(*this,v); return e; }
  69.142 +    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  69.143 +      e=InEdgeIt(*this,v); return e; }
  69.144 +
  69.145 +    /// Node ID.
  69.146 +    
  69.147 +    /// The ID of a valid Node is a nonnegative integer not greater than
  69.148 +    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  69.149 +    /// and the greatest node ID can be actually less then \ref maxNodeId().
  69.150 +    ///
  69.151 +    /// The ID of the \ref INVALID node is -1.
  69.152 +    ///\return The ID of the node \c v. 
  69.153 +    static int id(Node v) { return v.n; }
  69.154 +    /// Edge ID.
  69.155 +    
  69.156 +    /// The ID of a valid Edge is a nonnegative integer not greater than
  69.157 +    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  69.158 +    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  69.159 +    ///
  69.160 +    /// The ID of the \ref INVALID edge is -1.
  69.161 +    ///\return The ID of the edge \c e. 
  69.162 +    static int id(Edge e) { return e.n; }
  69.163 +
  69.164 +    /// Adds a new node to the graph.
  69.165 +
  69.166 +    /// \warning It adds the new node to the front of the list.
  69.167 +    /// (i.e. the lastly added node becomes the first.)
  69.168 +    Node addNode() {
  69.169 +      int n;
  69.170 +      
  69.171 +      if(first_free_node==-1)
  69.172 +	{
  69.173 +	  n = nodes.size();
  69.174 +	  nodes.push_back(NodeT());
  69.175 +	}
  69.176 +      else {
  69.177 +	n = first_free_node;
  69.178 +	first_free_node = nodes[n].next;
  69.179 +      }
  69.180 +      
  69.181 +      nodes[n].next = first_node;
  69.182 +      if(first_node != -1) nodes[first_node].prev = n;
  69.183 +      first_node = n;
  69.184 +      nodes[n].prev = -1;
  69.185 +      
  69.186 +      nodes[n].first_in = nodes[n].first_out = -1;
  69.187 +      
  69.188 +      Node nn; nn.n=n;
  69.189 +
  69.190 +      //Update dynamic maps
  69.191 +      node_maps.add(nn);
  69.192 +
  69.193 +      return nn;
  69.194 +    }
  69.195 +    
  69.196 +    Edge addEdge(Node u, Node v) {
  69.197 +      int n;
  69.198 +      
  69.199 +      if(first_free_edge==-1)
  69.200 +	{
  69.201 +	  n = edges.size();
  69.202 +	  edges.push_back(EdgeT());
  69.203 +	}
  69.204 +      else {
  69.205 +	n = first_free_edge;
  69.206 +	first_free_edge = edges[n].next_in;
  69.207 +      }
  69.208 +      
  69.209 +      edges[n].tail = u.n; edges[n].head = v.n;
  69.210 +
  69.211 +      edges[n].next_out = nodes[u.n].first_out;
  69.212 +      if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
  69.213 +      edges[n].next_in = nodes[v.n].first_in;
  69.214 +      if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
  69.215 +      edges[n].prev_in = edges[n].prev_out = -1;
  69.216 +	
  69.217 +      nodes[u.n].first_out = nodes[v.n].first_in = n;
  69.218 +
  69.219 +      Edge e; e.n=n;
  69.220 +
  69.221 +      //Update dynamic maps
  69.222 +      edge_maps.add(e);
  69.223 +
  69.224 +      return e;
  69.225 +    }
  69.226 +    
  69.227 +    /// Finds an edge between two nodes.
  69.228 +
  69.229 +    /// Finds an edge from node \c u to node \c v.
  69.230 +    ///
  69.231 +    /// If \c prev is \ref INVALID (this is the default value), then
  69.232 +    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  69.233 +    /// the next edge from \c u to \c v after \c prev.
  69.234 +    /// \return The found edge or INVALID if there is no such an edge.
  69.235 +    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  69.236 +    {
  69.237 +      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
  69.238 +      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
  69.239 +      prev.n=e;
  69.240 +      return prev;
  69.241 +    }
  69.242 +    
  69.243 +  private:
  69.244 +    void eraseEdge(int n) {
  69.245 +      
  69.246 +      if(edges[n].next_in!=-1)
  69.247 +	edges[edges[n].next_in].prev_in = edges[n].prev_in;
  69.248 +      if(edges[n].prev_in!=-1)
  69.249 +	edges[edges[n].prev_in].next_in = edges[n].next_in;
  69.250 +      else nodes[edges[n].head].first_in = edges[n].next_in;
  69.251 +      
  69.252 +      if(edges[n].next_out!=-1)
  69.253 +	edges[edges[n].next_out].prev_out = edges[n].prev_out;
  69.254 +      if(edges[n].prev_out!=-1)
  69.255 +	edges[edges[n].prev_out].next_out = edges[n].next_out;
  69.256 +      else nodes[edges[n].tail].first_out = edges[n].next_out;
  69.257 +      
  69.258 +      edges[n].next_in = first_free_edge;
  69.259 +      first_free_edge = n;      
  69.260 +
  69.261 +      //Update dynamic maps
  69.262 +      Edge e; e.n=n;
  69.263 +      edge_maps.erase(e);
  69.264 +
  69.265 +    }
  69.266 +      
  69.267 +  public:
  69.268 +
  69.269 +    void erase(Node nn) {
  69.270 +      int n=nn.n;
  69.271 +      
  69.272 +      int m;
  69.273 +      while((m=nodes[n].first_in)!=-1) eraseEdge(m);
  69.274 +      while((m=nodes[n].first_out)!=-1) eraseEdge(m);
  69.275 +
  69.276 +      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
  69.277 +      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
  69.278 +      else first_node = nodes[n].next;
  69.279 +      
  69.280 +      nodes[n].next = first_free_node;
  69.281 +      first_free_node = n;
  69.282 +
  69.283 +      //Update dynamic maps
  69.284 +      node_maps.erase(nn);
  69.285 +
  69.286 +    }
  69.287 +    
  69.288 +    void erase(Edge e) { eraseEdge(e.n); }
  69.289 +
  69.290 +    void clear() {
  69.291 +      edge_maps.clear();
  69.292 +      edges.clear();
  69.293 +      node_maps.clear();
  69.294 +      nodes.clear();
  69.295 +      first_node=first_free_node=first_free_edge=-1;
  69.296 +    }
  69.297 +
  69.298 +    class Node {
  69.299 +      friend class ListGraph;
  69.300 +      template <typename T> friend class NodeMap;
  69.301 +       
  69.302 +      friend class Edge;
  69.303 +      friend class OutEdgeIt;
  69.304 +      friend class InEdgeIt;
  69.305 +      friend class SymEdge;
  69.306 +
  69.307 +    protected:
  69.308 +      int n;
  69.309 +      friend int ListGraph::id(Node v); 
  69.310 +      Node(int nn) {n=nn;}
  69.311 +    public:
  69.312 +      Node() {}
  69.313 +      Node (Invalid) { n=-1; }
  69.314 +      bool operator==(const Node i) const {return n==i.n;}
  69.315 +      bool operator!=(const Node i) const {return n!=i.n;}
  69.316 +      bool operator<(const Node i) const {return n<i.n;}
  69.317 +      //      ///Validity check
  69.318 +      //      operator bool() { return n!=-1; }
  69.319 +    };
  69.320 +    
  69.321 +    class NodeIt : public Node {
  69.322 +      const ListGraph *G;
  69.323 +      friend class ListGraph;
  69.324 +    public:
  69.325 +      NodeIt() : Node() { }
  69.326 +      NodeIt(Invalid i) : Node(i) { }
  69.327 +      NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
  69.328 +      NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
  69.329 +      NodeIt &operator++() {
  69.330 +	n=G->nodes[n].next; 
  69.331 +	return *this; 
  69.332 +      }
  69.333 +      //      ///Validity check
  69.334 +      //      operator bool() { return Node::operator bool(); }      
  69.335 +    };
  69.336 +
  69.337 +    class Edge {
  69.338 +      friend class ListGraph;
  69.339 +      template <typename T> friend class EdgeMap;
  69.340 +
  69.341 +      friend class SymListGraph;
  69.342 +      
  69.343 +      friend class Node;
  69.344 +      friend class NodeIt;
  69.345 +    protected:
  69.346 +      int n;
  69.347 +      friend int ListGraph::id(Edge e);
  69.348 +
  69.349 +    public:
  69.350 +      /// An Edge with id \c n.
  69.351 +
  69.352 +      /// \bug It should be
  69.353 +      /// obtained by a member function of the Graph.
  69.354 +      Edge(int nn) {n=nn;}
  69.355 +
  69.356 +      Edge() { }
  69.357 +      Edge (Invalid) { n=-1; }
  69.358 +      bool operator==(const Edge i) const {return n==i.n;}
  69.359 +      bool operator!=(const Edge i) const {return n!=i.n;}
  69.360 +      bool operator<(const Edge i) const {return n<i.n;}
  69.361 +      //      ///Validity check
  69.362 +      //      operator bool() { return n!=-1; }
  69.363 +   };
  69.364 +    
  69.365 +    class EdgeIt : public Edge {
  69.366 +      const ListGraph *G;
  69.367 +      friend class ListGraph;
  69.368 +    public:
  69.369 +      EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
  69.370 +      	int m;
  69.371 +	for(m=_G.first_node;
  69.372 +	    m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
  69.373 +	n = (m==-1)?-1:_G.nodes[m].first_in;
  69.374 +      }
  69.375 +      EdgeIt (Invalid i) : Edge(i) { }
  69.376 +      EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  69.377 +      EdgeIt() : Edge() { }
  69.378 +      EdgeIt &operator++() {
  69.379 +	if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
  69.380 +	else {
  69.381 +	  int nn;
  69.382 +	  for(nn=G->nodes[G->edges[n].head].next;
  69.383 +	      nn!=-1 && G->nodes[nn].first_in == -1;
  69.384 +	      nn = G->nodes[nn].next) ;
  69.385 +	  n = (nn==-1)?-1:G->nodes[nn].first_in;
  69.386 +	}
  69.387 +	return *this;
  69.388 +      }
  69.389 +      //      ///Validity check
  69.390 +      //      operator bool() { return Edge::operator bool(); }      
  69.391 +    };
  69.392 +    
  69.393 +    class OutEdgeIt : public Edge {
  69.394 +      const ListGraph *G;
  69.395 +      friend class ListGraph;
  69.396 +    public: 
  69.397 +      OutEdgeIt() : Edge() { }
  69.398 +      OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  69.399 +      OutEdgeIt (Invalid i) : Edge(i) { }
  69.400 +
  69.401 +      OutEdgeIt(const ListGraph& _G,const Node v)
  69.402 +	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  69.403 +      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  69.404 +      //      ///Validity check
  69.405 +      //      operator bool() { return Edge::operator bool(); }      
  69.406 +    };
  69.407 +    
  69.408 +    class InEdgeIt : public Edge {
  69.409 +      const ListGraph *G;
  69.410 +      friend class ListGraph;
  69.411 +    public: 
  69.412 +      InEdgeIt() : Edge() { }
  69.413 +      InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
  69.414 +      InEdgeIt (Invalid i) : Edge(i) { }
  69.415 +      InEdgeIt(const ListGraph& _G,Node v)
  69.416 +	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  69.417 +      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  69.418 +      //      ///Validity check
  69.419 +      //      operator bool() { return Edge::operator bool(); }      
  69.420 +    };
  69.421 +  };
  69.422 +
  69.423 +  ///Graph for bidirectional edges.
  69.424 +
  69.425 +  ///The purpose of this graph structure is to handle graphs
  69.426 +  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  69.427 +  ///of oppositely directed edges.
  69.428 +  ///There is a new edge map type called
  69.429 +  ///\ref lemon::SymListGraph::SymEdgeMap "SymEdgeMap"
  69.430 +  ///that complements this
  69.431 +  ///feature by
  69.432 +  ///storing shared values for the edge pairs. The usual
  69.433 +  ///\ref lemon::skeleton::StaticGraph::EdgeMap "EdgeMap"
  69.434 +  ///can be used
  69.435 +  ///as well.
  69.436 +  ///
  69.437 +  ///The oppositely directed edge can also be obtained easily
  69.438 +  ///using \ref lemon::SymListGraph::opposite() "opposite()" member function.
  69.439 +  ///
  69.440 +  ///Here erase(Edge) deletes a pair of edges.
  69.441 +  ///
  69.442 +  ///\todo this date structure need some reconsiderations. Maybe it
  69.443 +  ///should be implemented independently from ListGraph.
  69.444 +  
  69.445 +  class SymListGraph : public ListGraph
  69.446 +  {
  69.447 +  public:
  69.448 +
  69.449 +    typedef SymListGraph Graph;
  69.450 +
  69.451 +    // Create symmetric map registry.
  69.452 +    CREATE_SYM_EDGE_MAP_REGISTRY;
  69.453 +    // Create symmetric edge map.
  69.454 +    CREATE_SYM_EDGE_MAP(ArrayMap);
  69.455 +
  69.456 +    SymListGraph() : ListGraph() { }
  69.457 +    SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
  69.458 +    ///Adds a pair of oppositely directed edges to the graph.
  69.459 +    Edge addEdge(Node u, Node v)
  69.460 +    {
  69.461 +      Edge e = ListGraph::addEdge(u,v);
  69.462 +      Edge f = ListGraph::addEdge(v,u);
  69.463 +      sym_edge_maps.add(e);
  69.464 +      sym_edge_maps.add(f);
  69.465 +      
  69.466 +      return e;
  69.467 +    }
  69.468 +
  69.469 +    void erase(Node n) { ListGraph::erase(n);}
  69.470 +    ///The oppositely directed edge.
  69.471 +
  69.472 +    ///Returns the oppositely directed
  69.473 +    ///pair of the edge \c e.
  69.474 +    static Edge opposite(Edge e)
  69.475 +    {
  69.476 +      Edge f;
  69.477 +      f.n = e.n - 2*(e.n%2) + 1;
  69.478 +      return f;
  69.479 +    }
  69.480 +    
  69.481 +    ///Removes a pair of oppositely directed edges to the graph.
  69.482 +    void erase(Edge e) {
  69.483 +      Edge f = opposite(e);
  69.484 +      sym_edge_maps.erase(e);
  69.485 +      sym_edge_maps.erase(f);
  69.486 +      ListGraph::erase(f);
  69.487 +      ListGraph::erase(e);
  69.488 +    }    
  69.489 +  };
  69.490 +
  69.491 +
  69.492 +  ///A graph class containing only nodes.
  69.493 +
  69.494 +  ///This class implements a graph structure without edges.
  69.495 +  ///The most useful application of this class is to be the node set of an
  69.496 +  ///\ref EdgeSet class.
  69.497 +  ///
  69.498 +  ///It conforms to 
  69.499 +  ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept
  69.500 +  ///with the exception that you cannot
  69.501 +  ///add (or delete) edges. The usual edge iterators are exists, but they are
  69.502 +  ///always \ref INVALID.
  69.503 +  ///\sa skeleton::ExtendableGraph
  69.504 +  ///\sa EdgeSet
  69.505 +  class NodeSet {
  69.506 +
  69.507 +    //Nodes are double linked.
  69.508 +    //The free nodes are only single linked using the "next" field.
  69.509 +    struct NodeT 
  69.510 +    {
  69.511 +      int first_in,first_out;
  69.512 +      int prev, next;
  69.513 +      //      NodeT() {}
  69.514 +    };
  69.515 +
  69.516 +    std::vector<NodeT> nodes;
  69.517 +    //The first node
  69.518 +    int first_node;
  69.519 +    //The first free node
  69.520 +    int first_free_node;
  69.521 +    
  69.522 +  public:
  69.523 +
  69.524 +    typedef NodeSet Graph;
  69.525 +    
  69.526 +    class Node;
  69.527 +    class Edge;
  69.528 +
  69.529 +  public:
  69.530 +
  69.531 +    class NodeIt;
  69.532 +    class EdgeIt;
  69.533 +    class OutEdgeIt;
  69.534 +    class InEdgeIt;
  69.535 +    
  69.536 +    // Create node map registry.
  69.537 +    CREATE_NODE_MAP_REGISTRY;
  69.538 +    // Create node maps.
  69.539 +    CREATE_NODE_MAP(ArrayMap);
  69.540 +
  69.541 +    /// Creating empty map structure for edges.
  69.542 +    template <typename Value>
  69.543 +    class EdgeMap {
  69.544 +    public:
  69.545 +      EdgeMap(const Graph&) {}
  69.546 +      EdgeMap(const Graph&, const Value&) {}
  69.547 +
  69.548 +      EdgeMap(const EdgeMap&) {}
  69.549 +      template <typename CMap> EdgeMap(const CMap&) {}
  69.550 +
  69.551 +      EdgeMap& operator=(const EdgeMap&) {}
  69.552 +      template <typename CMap> EdgeMap& operator=(const CMap&) {}
  69.553 +      
  69.554 +      class ConstIterator {
  69.555 +      public:
  69.556 +	bool operator==(const ConstIterator&) {return true;}
  69.557 +	bool operator!=(const ConstIterator&) {return false;}
  69.558 +      };
  69.559 +
  69.560 +      typedef ConstIterator Iterator;
  69.561 +      
  69.562 +      Iterator begin() { return Iterator();}
  69.563 +      Iterator end() { return Iterator();}
  69.564 +
  69.565 +      ConstIterator begin() const { return ConstIterator();}
  69.566 +      ConstIterator end() const { return ConstIterator();}
  69.567 +
  69.568 +    };
  69.569 +    
  69.570 +  public:
  69.571 +
  69.572 +    ///Default constructor
  69.573 +    NodeSet() 
  69.574 +      : nodes(), first_node(-1), first_free_node(-1) {}
  69.575 +    ///Copy constructor
  69.576 +    NodeSet(const NodeSet &_g) 
  69.577 +      : nodes(_g.nodes), first_node(_g.first_node),
  69.578 +	first_free_node(_g.first_free_node) {}
  69.579 +    
  69.580 +    ///Number of nodes.
  69.581 +    int nodeNum() const { return nodes.size(); }
  69.582 +    ///Number of edges.
  69.583 +    int edgeNum() const { return 0; }
  69.584 +
  69.585 +    /// Maximum node ID.
  69.586 +    
  69.587 +    /// Maximum node ID.
  69.588 +    ///\sa id(Node)
  69.589 +    int maxNodeId() const { return nodes.size()-1; }
  69.590 +    /// Maximum edge ID.
  69.591 +    
  69.592 +    /// Maximum edge ID.
  69.593 +    ///\sa id(Edge)
  69.594 +    int maxEdgeId() const { return 0; }
  69.595 +
  69.596 +    Node tail(Edge e) const { return INVALID; }
  69.597 +    Node head(Edge e) const { return INVALID; }
  69.598 +
  69.599 +    NodeIt& first(NodeIt& v) const { 
  69.600 +      v=NodeIt(*this); return v; }
  69.601 +    EdgeIt& first(EdgeIt& e) const { 
  69.602 +      e=EdgeIt(*this); return e; }
  69.603 +    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  69.604 +      e=OutEdgeIt(*this,v); return e; }
  69.605 +    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  69.606 +      e=InEdgeIt(*this,v); return e; }
  69.607 +
  69.608 +    /// Node ID.
  69.609 +    
  69.610 +    /// The ID of a valid Node is a nonnegative integer not greater than
  69.611 +    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  69.612 +    /// and the greatest node ID can be actually less then \ref maxNodeId().
  69.613 +    ///
  69.614 +    /// The ID of the \ref INVALID node is -1.
  69.615 +    ///\return The ID of the node \c v. 
  69.616 +    static int id(Node v) { return v.n; }
  69.617 +    /// Edge ID.
  69.618 +    
  69.619 +    /// The ID of a valid Edge is a nonnegative integer not greater than
  69.620 +    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  69.621 +    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  69.622 +    ///
  69.623 +    /// The ID of the \ref INVALID edge is -1.
  69.624 +    ///\return The ID of the edge \c e. 
  69.625 +    static int id(Edge e) { return -1; }
  69.626 +
  69.627 +    /// Adds a new node to the graph.
  69.628 +
  69.629 +    /// \warning It adds the new node to the front of the list.
  69.630 +    /// (i.e. the lastly added node becomes the first.)
  69.631 +    Node addNode() {
  69.632 +      int n;
  69.633 +      
  69.634 +      if(first_free_node==-1)
  69.635 +	{
  69.636 +	  n = nodes.size();
  69.637 +	  nodes.push_back(NodeT());
  69.638 +	}
  69.639 +      else {
  69.640 +	n = first_free_node;
  69.641 +	first_free_node = nodes[n].next;
  69.642 +      }
  69.643 +      
  69.644 +      nodes[n].next = first_node;
  69.645 +      if(first_node != -1) nodes[first_node].prev = n;
  69.646 +      first_node = n;
  69.647 +      nodes[n].prev = -1;
  69.648 +      
  69.649 +      nodes[n].first_in = nodes[n].first_out = -1;
  69.650 +      
  69.651 +      Node nn; nn.n=n;
  69.652 +
  69.653 +      //Update dynamic maps
  69.654 +      node_maps.add(nn);
  69.655 +
  69.656 +      return nn;
  69.657 +    }
  69.658 +    
  69.659 +    void erase(Node nn) {
  69.660 +      int n=nn.n;
  69.661 +      
  69.662 +      if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
  69.663 +      if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
  69.664 +      else first_node = nodes[n].next;
  69.665 +      
  69.666 +      nodes[n].next = first_free_node;
  69.667 +      first_free_node = n;
  69.668 +
  69.669 +      //Update dynamic maps
  69.670 +      node_maps.erase(nn);
  69.671 +    }
  69.672 +    
  69.673 +        
  69.674 +    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  69.675 +    {
  69.676 +      return INVALID;
  69.677 +    }
  69.678 +    
  69.679 +    void clear() {
  69.680 +      node_maps.clear();
  69.681 +      nodes.clear();
  69.682 +      first_node = first_free_node = -1;
  69.683 +    }
  69.684 +
  69.685 +    class Node {
  69.686 +      friend class NodeSet;
  69.687 +      template <typename T> friend class NodeMap;
  69.688 +      
  69.689 +      friend class Edge;
  69.690 +      friend class OutEdgeIt;
  69.691 +      friend class InEdgeIt;
  69.692 +
  69.693 +    protected:
  69.694 +      int n;
  69.695 +      friend int NodeSet::id(Node v); 
  69.696 +      Node(int nn) {n=nn;}
  69.697 +    public:
  69.698 +      Node() {}
  69.699 +      Node (Invalid i) { n=-1; }
  69.700 +      bool operator==(const Node i) const {return n==i.n;}
  69.701 +      bool operator!=(const Node i) const {return n!=i.n;}
  69.702 +      bool operator<(const Node i) const {return n<i.n;}
  69.703 +    };
  69.704 +    
  69.705 +    class NodeIt : public Node {
  69.706 +      const NodeSet *G;
  69.707 +      friend class NodeSet;
  69.708 +    public:
  69.709 +      NodeIt() : Node() { }
  69.710 +      NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
  69.711 +      NodeIt(Invalid i) : Node(i) { }
  69.712 +      NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
  69.713 +      NodeIt &operator++() {
  69.714 +	n=G->nodes[n].next; 
  69.715 +	return *this; 
  69.716 +      }
  69.717 +    };
  69.718 +
  69.719 +    class Edge {
  69.720 +    public:
  69.721 +      Edge() { }
  69.722 +      Edge (Invalid) { }
  69.723 +      bool operator==(const Edge i) const {return true;}
  69.724 +      bool operator!=(const Edge i) const {return false;}
  69.725 +      bool operator<(const Edge i) const {return false;}
  69.726 +    };
  69.727 +    
  69.728 +    class EdgeIt : public Edge {
  69.729 +    public:
  69.730 +      EdgeIt(const NodeSet& G) : Edge() { }
  69.731 +      EdgeIt(const NodeSet&, Edge) : Edge() { }
  69.732 +      EdgeIt (Invalid i) : Edge(i) { }
  69.733 +      EdgeIt() : Edge() { }
  69.734 +      EdgeIt operator++() { return INVALID; }
  69.735 +    };
  69.736 +    
  69.737 +    class OutEdgeIt : public Edge {
  69.738 +      friend class NodeSet;
  69.739 +    public: 
  69.740 +      OutEdgeIt() : Edge() { }
  69.741 +      OutEdgeIt(const NodeSet&, Edge) : Edge() { }
  69.742 +      OutEdgeIt (Invalid i) : Edge(i) { }
  69.743 +      OutEdgeIt(const NodeSet& G,const Node v)	: Edge() {}
  69.744 +      OutEdgeIt operator++() { return INVALID; }
  69.745 +    };
  69.746 +    
  69.747 +    class InEdgeIt : public Edge {
  69.748 +      friend class NodeSet;
  69.749 +    public: 
  69.750 +      InEdgeIt() : Edge() { }
  69.751 +      InEdgeIt(const NodeSet&, Edge) : Edge() { }
  69.752 +      InEdgeIt (Invalid i) : Edge(i) { }
  69.753 +      InEdgeIt(const NodeSet& G,Node v) :Edge() {}
  69.754 +      InEdgeIt operator++() { return INVALID; }
  69.755 +    };
  69.756 +
  69.757 +  };
  69.758 +
  69.759 +
  69.760 +
  69.761 +  ///Graph structure using a node set of another graph.
  69.762 +
  69.763 +  ///This structure can be used to establish another graph over a node set
  69.764 +  /// of an existing one. The node iterator will go through the nodes of the
  69.765 +  /// original graph, and the NodeMap's of both graphs will convert to
  69.766 +  /// each other.
  69.767 +  ///
  69.768 +  ///\warning Adding or deleting nodes from the graph is not safe if an
  69.769 +  ///\ref EdgeSet is currently attached to it!
  69.770 +  ///
  69.771 +  ///\todo Make it possible to add/delete edges from the base graph
  69.772 +  ///(and from \ref EdgeSet, as well)
  69.773 +  ///
  69.774 +  ///\param GG The type of the graph which shares its node set with this class.
  69.775 +  ///Its interface must conform to the
  69.776 +  ///\ref skeleton::StaticGraph "StaticGraph" concept.
  69.777 +  ///
  69.778 +  ///It conforms to the 
  69.779 +  ///\ref skeleton::ExtendableGraph "ExtendableGraph" concept.
  69.780 +  ///\sa skeleton::ExtendableGraph.
  69.781 +  ///\sa NodeSet.
  69.782 +  template<typename GG>
  69.783 +  class EdgeSet {
  69.784 +
  69.785 +    typedef GG NodeGraphType;
  69.786 +
  69.787 +    NodeGraphType &G;
  69.788 +
  69.789 +  public:
  69.790 +
  69.791 +    class Node;
  69.792 +    class Edge;
  69.793 +    class OutEdgeIt;
  69.794 +    class InEdgeIt;
  69.795 +    class SymEdge;
  69.796 +
  69.797 +    typedef EdgeSet Graph;
  69.798 +
  69.799 +    int id(Node v) const; 
  69.800 +
  69.801 +    class Node : public NodeGraphType::Node {
  69.802 +      friend class EdgeSet;
  69.803 +      
  69.804 +      friend class Edge;
  69.805 +      friend class OutEdgeIt;
  69.806 +      friend class InEdgeIt;
  69.807 +      friend class SymEdge;
  69.808 +
  69.809 +    public:
  69.810 +      friend int EdgeSet::id(Node v) const; 
  69.811 +    public:
  69.812 +      Node() : NodeGraphType::Node() {}
  69.813 +      Node (Invalid i) : NodeGraphType::Node(i) {}
  69.814 +      Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
  69.815 +    };
  69.816 +    
  69.817 +    class NodeIt : public NodeGraphType::NodeIt {
  69.818 +      friend class EdgeSet;
  69.819 +    public:
  69.820 +      NodeIt() : NodeGraphType::NodeIt() { }
  69.821 +      NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
  69.822 +      NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
  69.823 +      NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
  69.824 +      NodeIt(const typename NodeGraphType::NodeIt &n)
  69.825 +	: NodeGraphType::NodeIt(n) {}
  69.826 +
  69.827 +      operator Node() { return Node(*this);}
  69.828 +      NodeIt &operator++()
  69.829 +      { this->NodeGraphType::NodeIt::operator++(); return *this;} 
  69.830 +    };
  69.831 +
  69.832 +  private:
  69.833 +    //Edges are double linked.
  69.834 +    //The free edges are only single linked using the "next_in" field.
  69.835 +    struct NodeT 
  69.836 +    {
  69.837 +      int first_in,first_out;
  69.838 +      NodeT() : first_in(-1), first_out(-1) { }
  69.839 +    };
  69.840 +
  69.841 +    struct EdgeT 
  69.842 +    {
  69.843 +      Node head, tail;
  69.844 +      int prev_in, prev_out;
  69.845 +      int next_in, next_out;
  69.846 +    };
  69.847 +
  69.848 +    
  69.849 +    typename NodeGraphType::template NodeMap<NodeT> nodes;
  69.850 +    
  69.851 +    std::vector<EdgeT> edges;
  69.852 +    //The first free edge
  69.853 +    int first_free_edge;
  69.854 +    
  69.855 +  public:
  69.856 +    
  69.857 +    class Node;
  69.858 +    class Edge;
  69.859 +
  69.860 +    class NodeIt;
  69.861 +    class EdgeIt;
  69.862 +    class OutEdgeIt;
  69.863 +    class InEdgeIt;
  69.864 +
  69.865 +
  69.866 +    // Create edge map registry.
  69.867 +    CREATE_EDGE_MAP_REGISTRY;
  69.868 +    // Create edge maps.
  69.869 +    CREATE_EDGE_MAP(ArrayMap);
  69.870 +
  69.871 +    // Import node maps from the NodeGraphType.
  69.872 +    IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
  69.873 +    
  69.874 +    
  69.875 +  public:
  69.876 +
  69.877 +    ///Constructor
  69.878 +    
  69.879 +    ///Construates a new graph based on the nodeset of an existing one.
  69.880 +    ///\param _G the base graph.
  69.881 +    explicit EdgeSet(NodeGraphType &_G) 
  69.882 +      : G(_G), nodes(_G), edges(),
  69.883 +	first_free_edge(-1) {}
  69.884 +    ///Copy constructor
  69.885 +
  69.886 +    ///Makes a copy of an EdgeSet.
  69.887 +    ///It will be based on the same graph.
  69.888 +    explicit EdgeSet(const EdgeSet &_g) 
  69.889 +      : G(_g.G), nodes(_g.G), edges(_g.edges),
  69.890 +	first_free_edge(_g.first_free_edge) {}
  69.891 +    
  69.892 +    ///Number of nodes.
  69.893 +    int nodeNum() const { return G.nodeNum(); }
  69.894 +    ///Number of edges.
  69.895 +    int edgeNum() const { return edges.size(); }
  69.896 +
  69.897 +    /// Maximum node ID.
  69.898 +    
  69.899 +    /// Maximum node ID.
  69.900 +    ///\sa id(Node)
  69.901 +    int maxNodeId() const { return G.maxNodeId(); }
  69.902 +    /// Maximum edge ID.
  69.903 +    
  69.904 +    /// Maximum edge ID.
  69.905 +    ///\sa id(Edge)
  69.906 +    int maxEdgeId() const { return edges.size()-1; }
  69.907 +
  69.908 +    Node tail(Edge e) const { return edges[e.n].tail; }
  69.909 +    Node head(Edge e) const { return edges[e.n].head; }
  69.910 +
  69.911 +    NodeIt& first(NodeIt& v) const { 
  69.912 +      v=NodeIt(*this); return v; }
  69.913 +    EdgeIt& first(EdgeIt& e) const { 
  69.914 +      e=EdgeIt(*this); return e; }
  69.915 +    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  69.916 +      e=OutEdgeIt(*this,v); return e; }
  69.917 +    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  69.918 +      e=InEdgeIt(*this,v); return e; }
  69.919 +
  69.920 +    /// Node ID.
  69.921 +    
  69.922 +    /// The ID of a valid Node is a nonnegative integer not greater than
  69.923 +    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  69.924 +    /// and the greatest node ID can be actually less then \ref maxNodeId().
  69.925 +    ///
  69.926 +    /// The ID of the \ref INVALID node is -1.
  69.927 +    ///\return The ID of the node \c v. 
  69.928 +    int id(Node v) { return G.id(v); }
  69.929 +    /// Edge ID.
  69.930 +    
  69.931 +    /// The ID of a valid Edge is a nonnegative integer not greater than
  69.932 +    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  69.933 +    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  69.934 +    ///
  69.935 +    /// The ID of the \ref INVALID edge is -1.
  69.936 +    ///\return The ID of the edge \c e. 
  69.937 +    static int id(Edge e) { return e.n; }
  69.938 +
  69.939 +    /// Adds a new node to the graph.
  69.940 +    Node addNode() { return G.addNode(); }
  69.941 +    
  69.942 +    Edge addEdge(Node u, Node v) {
  69.943 +      int n;
  69.944 +      
  69.945 +      if(first_free_edge==-1)
  69.946 +	{
  69.947 +	  n = edges.size();
  69.948 +	  edges.push_back(EdgeT());
  69.949 +	}
  69.950 +      else {
  69.951 +	n = first_free_edge;
  69.952 +	first_free_edge = edges[n].next_in;
  69.953 +      }
  69.954 +      
  69.955 +      edges[n].tail = u; edges[n].head = v;
  69.956 +
  69.957 +      edges[n].next_out = nodes[u].first_out;
  69.958 +      if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
  69.959 +      edges[n].next_in = nodes[v].first_in;
  69.960 +      if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
  69.961 +      edges[n].prev_in = edges[n].prev_out = -1;
  69.962 +	
  69.963 +      nodes[u].first_out = nodes[v].first_in = n;
  69.964 +
  69.965 +      Edge e; e.n=n;
  69.966 +
  69.967 +      //Update dynamic maps
  69.968 +      edge_maps.add(e);
  69.969 +
  69.970 +      return e;
  69.971 +    }
  69.972 +
  69.973 +    /// Finds an edge between two nodes.
  69.974 +
  69.975 +    /// Finds an edge from node \c u to node \c v.
  69.976 +    ///
  69.977 +    /// If \c prev is \ref INVALID (this is the default value), then
  69.978 +    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  69.979 +    /// the next edge from \c u to \c v after \c prev.
  69.980 +    /// \return The found edge or INVALID if there is no such an edge.
  69.981 +    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  69.982 +    {
  69.983 +      int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
  69.984 +      while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
  69.985 +      prev.n=e;
  69.986 +      return prev;
  69.987 +    }
  69.988 +    
  69.989 +  private:
  69.990 +    void eraseEdge(int n) {
  69.991 +      
  69.992 +      if(edges[n].next_in!=-1)
  69.993 +	edges[edges[n].next_in].prev_in = edges[n].prev_in;
  69.994 +      if(edges[n].prev_in!=-1)
  69.995 +	edges[edges[n].prev_in].next_in = edges[n].next_in;
  69.996 +      else nodes[edges[n].head].first_in = edges[n].next_in;
  69.997 +      
  69.998 +      if(edges[n].next_out!=-1)
  69.999 +	edges[edges[n].next_out].prev_out = edges[n].prev_out;
 69.1000 +      if(edges[n].prev_out!=-1)
 69.1001 +	edges[edges[n].prev_out].next_out = edges[n].next_out;
 69.1002 +      else nodes[edges[n].tail].first_out = edges[n].next_out;
 69.1003 +      
 69.1004 +      edges[n].next_in = first_free_edge;
 69.1005 +      first_free_edge = -1;      
 69.1006 +
 69.1007 +      //Update dynamic maps
 69.1008 +      Edge e; e.n = n;
 69.1009 +      edge_maps.erase(e);
 69.1010 +    }
 69.1011 +      
 69.1012 +  public:
 69.1013 +
 69.1014 +    void erase(Edge e) { eraseEdge(e.n); }
 69.1015 +
 69.1016 +    ///Clear all edges. (Doesn't clear the nodes!)
 69.1017 +    void clear() {
 69.1018 +      edge_maps.clear();
 69.1019 +      edges.clear();
 69.1020 +      first_free_edge=-1;
 69.1021 +    }
 69.1022 +
 69.1023 +
 69.1024 +    class Edge {
 69.1025 +    public:
 69.1026 +      friend class EdgeSet;
 69.1027 +      template <typename T> friend class EdgeMap;
 69.1028 +
 69.1029 +      friend class Node;
 69.1030 +      friend class NodeIt;
 69.1031 +    protected:
 69.1032 +      int n;
 69.1033 +      friend int EdgeSet::id(Edge e) const;
 69.1034 +
 69.1035 +      Edge(int nn) {n=nn;}
 69.1036 +    public:
 69.1037 +      Edge() { }
 69.1038 +      Edge (Invalid) { n=-1; }
 69.1039 +      bool operator==(const Edge i) const {return n==i.n;}
 69.1040 +      bool operator!=(const Edge i) const {return n!=i.n;}
 69.1041 +      bool operator<(const Edge i) const {return n<i.n;}
 69.1042 +    };
 69.1043 +    
 69.1044 +    class EdgeIt : public Edge {
 69.1045 +      friend class EdgeSet;
 69.1046 +      template <typename T> friend class EdgeMap;
 69.1047 +    
 69.1048 +      const EdgeSet *G;
 69.1049 +    public:
 69.1050 +      EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
 69.1051 +        NodeIt m;
 69.1052 +	for(G->first(m);
 69.1053 +	    m!=INVALID && G->nodes[m].first_in == -1;  ++m);
 69.1054 +	///\bug AJJAJ! This is a non sense!!!!!!!
 69.1055 +	this->n = m!=INVALID?-1:G->nodes[m].first_in;
 69.1056 +      }
 69.1057 +      EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 69.1058 +      EdgeIt (Invalid i) : Edge(i) { }
 69.1059 +      EdgeIt() : Edge() { }
 69.1060 +      ///.
 69.1061 +      
 69.1062 +      ///\bug UNIMPLEMENTED!!!!!
 69.1063 +      //
 69.1064 +      EdgeIt &operator++() {
 69.1065 +	return *this;
 69.1066 +      }
 69.1067 +    };
 69.1068 +    
 69.1069 +    class OutEdgeIt : public Edge {
 69.1070 +      const EdgeSet *G;
 69.1071 +      friend class EdgeSet;
 69.1072 +    public: 
 69.1073 +      OutEdgeIt() : Edge() { }
 69.1074 +      OutEdgeIt (Invalid i) : Edge(i) { }
 69.1075 +      OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 69.1076 +
 69.1077 +      OutEdgeIt(const EdgeSet& _G,const Node v) :
 69.1078 +	Edge(_G.nodes[v].first_out), G(&_G) { }
 69.1079 +      OutEdgeIt &operator++() { 
 69.1080 +	Edge::n = G->edges[Edge::n].next_out;
 69.1081 +	return *this; 
 69.1082 +      }
 69.1083 +    };
 69.1084 +    
 69.1085 +    class InEdgeIt : public Edge {
 69.1086 +      const EdgeSet *G;
 69.1087 +      friend class EdgeSet;
 69.1088 +    public: 
 69.1089 +      InEdgeIt() : Edge() { }
 69.1090 +      InEdgeIt (Invalid i) : Edge(i) { }
 69.1091 +      InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
 69.1092 +      InEdgeIt(const EdgeSet& _G,Node v)
 69.1093 +	: Edge(_G.nodes[v].first_in), G(&_G) { }
 69.1094 +      InEdgeIt &operator++() { 
 69.1095 +	Edge::n = G->edges[Edge::n].next_in; 
 69.1096 +	return *this; 
 69.1097 +      }
 69.1098 +    };
 69.1099 +    
 69.1100 +  };
 69.1101 +
 69.1102 +  template<typename GG>
 69.1103 +  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
 69.1104 +
 69.1105 +/// @}  
 69.1106 +
 69.1107 +} //namespace lemon
 69.1108 +
 69.1109 +#endif //LEMON_LIST_GRAPH_H
    70.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    70.2 +++ b/src/lemon/map_bits.h	Wed Sep 29 15:30:04 2004 +0000
    70.3 @@ -0,0 +1,67 @@
    70.4 +/* -*- C++ -*-
    70.5 + * src/lemon/map_bits.h - Part of LEMON, a generic C++ optimization library
    70.6 + *
    70.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    70.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    70.9 + *
   70.10 + * Permission to use, modify and distribute this software is granted
   70.11 + * provided that this copyright notice appears in all copies. For
   70.12 + * precise terms see the accompanying LICENSE file.
   70.13 + *
   70.14 + * This software is provided "AS IS" with no warranty of any kind,
   70.15 + * express or implied, and with no claim as to its suitability for any
   70.16 + * purpose.
   70.17 + *
   70.18 + */
   70.19 +
   70.20 +#ifndef LEMON_MAP_BITS_H
   70.21 +#define LEMON_MAP_BITS_H
   70.22 +
   70.23 +///\ingroup graphmaps
   70.24 +///\file
   70.25 +///\brief Some utils to help implement maps.
   70.26 +
   70.27 +namespace lemon {
   70.28 +
   70.29 +
   70.30 +  /// \addtogroup graphmaps
   70.31 +  /// @{
   70.32 +
   70.33 +  /// Helper class to get information about the key type.
   70.34 +  template <typename Graph, typename KeyIt>
   70.35 +  struct KeyInfo {};
   70.36 +
   70.37 +  template <typename Graph>
   70.38 +  struct KeyInfo<Graph, typename Graph::NodeIt> {
   70.39 +    static int maxId(const Graph& graph) {
   70.40 +      return graph.maxNodeId();
   70.41 +    }
   70.42 +    static int id(const Graph& graph, const typename Graph::Node& node) {
   70.43 +      return graph.id(node);
   70.44 +    }
   70.45 +  };
   70.46 +
   70.47 +  template <typename Graph>
   70.48 +  struct KeyInfo<Graph, typename Graph::EdgeIt> {
   70.49 +    static int maxId(const Graph& graph) {
   70.50 +      return graph.maxEdgeId();
   70.51 +    }
   70.52 +    static int id(const Graph& graph, const typename Graph::Edge& edge) {
   70.53 +      return graph.id(edge);
   70.54 +    }
   70.55 +  };
   70.56 +
   70.57 +  template <typename Graph>
   70.58 +  struct KeyInfo<Graph, typename Graph::SymEdgeIt> {
   70.59 +    static int maxId(const Graph& graph) {
   70.60 +      return graph.maxEdgeId() >> 1;
   70.61 +    }
   70.62 +    static int id(const Graph& graph, const typename Graph::Edge& edge) {
   70.63 +      return graph.id(edge) >> 1;
   70.64 +    }
   70.65 +  };
   70.66 +
   70.67 +  /// @}
   70.68 +}
   70.69 +
   70.70 +#endif
    71.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    71.2 +++ b/src/lemon/map_defines.h	Wed Sep 29 15:30:04 2004 +0000
    71.3 @@ -0,0 +1,228 @@
    71.4 +/* -*- C++ -*-
    71.5 + * src/lemon/map_defines.h - Part of LEMON, a generic C++ optimization library
    71.6 + *
    71.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    71.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    71.9 + *
   71.10 + * Permission to use, modify and distribute this software is granted
   71.11 + * provided that this copyright notice appears in all copies. For
   71.12 + * precise terms see the accompanying LICENSE file.
   71.13 + *
   71.14 + * This software is provided "AS IS" with no warranty of any kind,
   71.15 + * express or implied, and with no claim as to its suitability for any
   71.16 + * purpose.
   71.17 + *
   71.18 + */
   71.19 +
   71.20 +#ifndef LEMON_MAP_DEFINES_H
   71.21 +#define LEMON_MAP_DEFINES_H
   71.22 +
   71.23 +///\ingroup graphmaps
   71.24 +///\file
   71.25 +///\brief Defines to help creating graph maps.
   71.26 +
   71.27 +/// \addtogroup graphmapfactory
   71.28 +/// @{
   71.29 +
   71.30 +/** Creates the EdgeMapRegistry type an declare a mutable instance 
   71.31 + *  named edge_maps.
   71.32 + */
   71.33 +#define CREATE_EDGE_MAP_REGISTRY \
   71.34 +typedef MapRegistry<Graph, Edge, EdgeIt> EdgeMapRegistry; \
   71.35 +mutable EdgeMapRegistry edge_maps;
   71.36 +
   71.37 +/** Creates the NodeMapRegistry type an declare a mutable instance 
   71.38 + *  named node_maps.
   71.39 + */
   71.40 +#define CREATE_NODE_MAP_REGISTRY \
   71.41 +typedef MapRegistry<Graph, Node, NodeIt> NodeMapRegistry; \
   71.42 +mutable NodeMapRegistry node_maps;
   71.43 +
   71.44 +/** Creates both map registries.
   71.45 + */
   71.46 +#define CREATE_MAP_REGISTRIES \
   71.47 +CREATE_NODE_MAP_REGISTRY \
   71.48 +CREATE_EDGE_MAP_REGISTRY
   71.49 +
   71.50 +/** Creates a map from a template map. The import method is
   71.51 + *  an overloading of the map type.
   71.52 + *  The reason to use these macro is that the c++ does not support
   71.53 + *  the template typedefs. If a future release of the c++ 
   71.54 + *  supports this feature it should be fixed.
   71.55 + */
   71.56 +#define CREATE_NODE_MAP(DynMap) \
   71.57 +template <typename Value> \
   71.58 +class NodeMap : public DynMap<NodeMapRegistry, Value> { \
   71.59 +public: \
   71.60 +typedef DynMap<NodeMapRegistry, Value> Parent; \
   71.61 +NodeMap(const typename Parent::Graph& g) \
   71.62 +  : Parent(g, g.node_maps) {} \
   71.63 +NodeMap(const typename Parent::Graph& g, const Value& v) \
   71.64 +  : Parent(g, g.node_maps, v) {} \
   71.65 +NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
   71.66 +template <typename TT> \
   71.67 +NodeMap(const NodeMap<TT>& copy) \
   71.68 +  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
   71.69 +NodeMap& operator=(const NodeMap& copy) { \
   71.70 +  Parent::operator=(static_cast<const Parent&>(copy));\
   71.71 +  return *this; \
   71.72 +} \
   71.73 +template <typename TT> \
   71.74 +NodeMap& operator=(const NodeMap<TT>& copy) { \
   71.75 +  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
   71.76 +  return *this; \
   71.77 +} \
   71.78 +};
   71.79 +
   71.80 +/** Creates a map from a template map. The import method is
   71.81 + *  an overloading of the map type.
   71.82 + *  The reason to use these macro is that the c++ does not support
   71.83 + *  the template typedefs. If a future release of the c++ 
   71.84 + *  supports this feature it should be fixed.
   71.85 + */
   71.86 +#define CREATE_EDGE_MAP(DynMap) \
   71.87 +template <typename Value> \
   71.88 +class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
   71.89 +public: \
   71.90 +typedef DynMap<EdgeMapRegistry, Value> Parent; \
   71.91 +\
   71.92 +EdgeMap(const typename Parent::Graph& g) \
   71.93 +  : Parent(g, g.edge_maps) {} \
   71.94 +EdgeMap(const typename Parent::Graph& g, const Value& v) \
   71.95 +  : Parent(g, g.edge_maps, v) {} \
   71.96 +EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \
   71.97 +template <typename TT> \
   71.98 +EdgeMap(const EdgeMap<TT>& copy) \
   71.99 +  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
  71.100 +EdgeMap& operator=(const EdgeMap& copy) { \
  71.101 +  Parent::operator=(static_cast<const Parent&>(copy));\
  71.102 +  return *this; \
  71.103 +} \
  71.104 +template <typename TT> \
  71.105 +EdgeMap& operator=(const EdgeMap<TT>& copy) { \
  71.106 +  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
  71.107 +  return *this; \
  71.108 +} \
  71.109 +};
  71.110 +
  71.111 +/** This macro creates both maps.
  71.112 + */
  71.113 +#define CREATE_MAPS(DynMap) \
  71.114 +CREATE_NODE_MAP(DynMap) \
  71.115 +CREATE_EDGE_MAP(DynMap)
  71.116 +
  71.117 +/** This macro creates MapRegistry for Symmetric Edge Maps.
  71.118 + */
  71.119 +#define CREATE_SYM_EDGE_MAP_REGISTRY \
  71.120 +typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
  71.121 +typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
  71.122 +mutable SymEdgeMapRegistry sym_edge_maps;
  71.123 +
  71.124 +
  71.125 +/** Creates a map from a template map. The import method is
  71.126 + *  an overloading of the map type.
  71.127 + *  The reason to use these macro is that the c++ does not support
  71.128 + *  the template typedefs. If a future release of the c++ 
  71.129 + *  supports this feature it should be fixed.
  71.130 + */
  71.131 +#define CREATE_SYM_EDGE_MAP(DynMap) \
  71.132 +template <typename Value> \
  71.133 +class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
  71.134 +public: \
  71.135 +typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \
  71.136 +\
  71.137 +SymEdgeMap(const typename Parent::Graph& g) \
  71.138 +  : Parent(g, g.sym_edge_maps) {} \
  71.139 +SymEdgeMap(const typename Parent::Graph& g, const Value& v) \
  71.140 +  : Parent(g, g.sym_edge_maps, v) {} \
  71.141 +SymEdgeMap(const SymEdgeMap& copy) \
  71.142 +  : Parent(static_cast<const Parent&>(copy)) {} \
  71.143 +template <typename TT> \
  71.144 +SymEdgeMap(const NodeMap<TT>& copy) \
  71.145 +  : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \
  71.146 +SymEdgeMap& operator=(const SymEdgeMap& copy) { \
  71.147 +  Parent::operator=(static_cast<const Parent&>(copy));\
  71.148 +  return *this; \
  71.149 +} \
  71.150 +template <typename TT> \
  71.151 +SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \
  71.152 +  Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\
  71.153 +  return *this; \
  71.154 +} \
  71.155 +};
  71.156 +
  71.157 +/** This is a macro to import an node map into a graph class.
  71.158 + */
  71.159 +#define IMPORT_NODE_MAP(From, from, To, to) \
  71.160 +template <typename Value> \
  71.161 +class NodeMap : public From::template NodeMap<Value> { \
  71.162 +\
  71.163 +public: \
  71.164 +typedef typename From::template NodeMap<Value> Parent; \
  71.165 +\
  71.166 +NodeMap(const To& to) \
  71.167 +  : Parent(static_cast<const From&>(from)) { } \
  71.168 +NodeMap(const To& to, const Value& value) \
  71.169 +  : Parent(static_cast<const From&>(from), value) { } \
  71.170 +NodeMap(const NodeMap& copy) \
  71.171 +  : Parent(static_cast<const Parent&>(copy)) {} \
  71.172 +template <typename TT> \
  71.173 +NodeMap(const NodeMap<TT>& copy) \
  71.174 +  : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \
  71.175 +NodeMap& operator=(const NodeMap& copy) { \
  71.176 +  Parent::operator=(static_cast<const Parent&>(copy)); \
  71.177 +  return *this; \
  71.178 +} \
  71.179 +template <typename TT> \
  71.180 +NodeMap& operator=(const NodeMap<TT>& copy) { \
  71.181 +  Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\
  71.182 +  return *this; \
  71.183 +} \
  71.184 +};
  71.185 +
  71.186 +/** This is a macro to import an edge map into a graph class.
  71.187 + */
  71.188 +#define IMPORT_EDGE_MAP(From, from, To, to) \
  71.189 +template <typename Value> \
  71.190 +class EdgeMap : public From::template EdgeMap<Value> { \
  71.191 +\
  71.192 +public: \
  71.193 +typedef typename From::template EdgeMap<Value> Parent; \
  71.194 +\
  71.195 +EdgeMap(const To& to) \
  71.196 +  : Parent(static_cast<const From&>(from)) { } \
  71.197 +EdgeMap(const To& to, const Value& value) \
  71.198 +  : Parent(static_cast<const From&>(from), value) { } \
  71.199 +EdgeMap(const EdgeMap& copy) \
  71.200 +  : Parent(static_cast<const Parent&>(copy)) {} \
  71.201 +template <typename TT> \
  71.202 +EdgeMap(const EdgeMap<TT>& copy) \
  71.203 +  : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \
  71.204 +EdgeMap& operator=(const EdgeMap& copy) { \
  71.205 +  Parent::operator=(static_cast<const Parent&>(copy)); \
  71.206 +  return *this; \
  71.207 +} \
  71.208 +template <typename TT> \
  71.209 +EdgeMap& operator=(const EdgeMap<TT>& copy) { \
  71.210 +  Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\
  71.211 +  return *this; \
  71.212 +} \
  71.213 +};
  71.214 +
  71.215 +#define KEEP_EDGE_MAP(From, To) \
  71.216 +IMPORT_EDGE_MAP(From, graph, To, graph)
  71.217 +
  71.218 +
  71.219 +#define KEEP_NODE_MAP(From, To) \
  71.220 +IMPORT_NODE_MAP(From, graph, To, graph)
  71.221 +
  71.222 +/** This is a macro to keep the node and edge maps for a graph class.
  71.223 + */
  71.224 +#define KEEP_MAPS(From, To) \
  71.225 +KEEP_EDGE_MAP(From, To) \
  71.226 +KEEP_NODE_MAP(From, To)
  71.227 +
  71.228 +  
  71.229 +/// @}
  71.230 +  
  71.231 +#endif
    72.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    72.2 +++ b/src/lemon/map_iterator.h	Wed Sep 29 15:30:04 2004 +0000
    72.3 @@ -0,0 +1,692 @@
    72.4 +/* -*- C++ -*-
    72.5 + * src/lemon/map_iterator.h - Part of LEMON, a generic C++ optimization library
    72.6 + *
    72.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    72.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    72.9 + *
   72.10 + * Permission to use, modify and distribute this software is granted
   72.11 + * provided that this copyright notice appears in all copies. For
   72.12 + * precise terms see the accompanying LICENSE file.
   72.13 + *
   72.14 + * This software is provided "AS IS" with no warranty of any kind,
   72.15 + * express or implied, and with no claim as to its suitability for any
   72.16 + * purpose.
   72.17 + *
   72.18 + */
   72.19 +
   72.20 +#ifndef LEMON_MAP_ITERATOR_H
   72.21 +#define LEMON_MAP_ITERATOR_H
   72.22 +
   72.23 +#include <iterator>
   72.24 +
   72.25 +#include <lemon/extended_pair.h>
   72.26 +
   72.27 +///\ingroup graphmaps
   72.28 +///\file
   72.29 +///\brief Iterators on the maps.
   72.30 +
   72.31 +namespace lemon {
   72.32 +
   72.33 +  /// \addtogroup graphmaps
   72.34 +  /// @{
   72.35 +
   72.36 +  /** The base class all of the map iterators.
   72.37 +   *  The class defines the typedefs of the iterators,
   72.38 +   *  simple step functions and equality operators.
   72.39 +   */ 
   72.40 +
   72.41 +  template <typename Map>
   72.42 +  class MapIteratorBase {
   72.43 +
   72.44 +  public:
   72.45 +
   72.46 +    /// The key type of the iterator.
   72.47 +    typedef typename Map::KeyType KeyType;
   72.48 +    /// The iterator to iterate on the keys.
   72.49 +    typedef typename Map::KeyIt KeyIt;
   72.50 +
   72.51 +    /// The value type of the iterator.
   72.52 +    typedef typename Map::ValueType ValueType;
   72.53 +    /// The reference type of the iterator.
   72.54 +    typedef typename Map::ReferenceType ReferenceType;
   72.55 +    /// The pointer type of the iterator.
   72.56 +    typedef typename Map::PointerType PointerType;
   72.57 +
   72.58 +    /// The const value type of the iterator.
   72.59 +    typedef typename Map::ConstValueType ConstValueType;
   72.60 +    /// The const reference type of the iterator.
   72.61 +    typedef typename Map::ConstReferenceType ConstReferenceType;
   72.62 +    /// The pointer type of the iterator.
   72.63 +    typedef typename Map::ConstPointerType ConstPointerType;
   72.64 +
   72.65 +  protected:
   72.66 +
   72.67 +    KeyIt it;
   72.68 +
   72.69 +    /// Default constructor.
   72.70 +    MapIteratorBase() {}
   72.71 +
   72.72 +    /// KeyIt initialized MapIteratorBase constructor.
   72.73 +    MapIteratorBase(const KeyIt pit) : it(pit) {}
   72.74 +
   72.75 +  public:
   72.76 +
   72.77 +    /// Stepping forward in the map.   
   72.78 +    void increment() { 
   72.79 +      ++it; 
   72.80 +    }
   72.81 +
   72.82 +    /// The equality operator of the map.
   72.83 +    bool operator==(const MapIteratorBase& pit) const {
   72.84 +      return pit.it == it;
   72.85 +    }
   72.86 +	
   72.87 +    /// The not-equality operator of the map.
   72.88 +    bool operator!=(const MapIteratorBase& pit) const {
   72.89 +      return !(*this == pit);
   72.90 +    }
   72.91 +  };
   72.92 +
   72.93 +  template <typename Map> class MapConstIterator;
   72.94 +
   72.95 +  /** Compatible iterator with the stl maps' iterators.
   72.96 +   * It iterates on pairs of a key and a value.
   72.97 +   */
   72.98 +  template <typename Map>  
   72.99 +  class MapIterator : public MapIteratorBase<Map> {
  72.100 +
  72.101 +    friend class MapConstIterator<Map>;
  72.102 +
  72.103 +
  72.104 +  public:
  72.105 +
  72.106 +    /// The iterator base class.
  72.107 +    typedef MapIteratorBase<Map> Base;
  72.108 +
  72.109 +    /// The key type of the iterator.
  72.110 +    typedef typename Map::KeyType KeyType;
  72.111 +    /// The iterator to iterate on the keys.
  72.112 +    typedef typename Map::KeyIt KeyIt;
  72.113 +
  72.114 +    /// The value type of the iterator.
  72.115 +    typedef typename Map::ValueType ValueType;
  72.116 +    /// The reference type of the iterator.
  72.117 +    typedef typename Map::ReferenceType ReferenceType;
  72.118 +    /// The pointer type of the iterator.
  72.119 +    typedef typename Map::PointerType PointerType;
  72.120 +
  72.121 +    /// The const value type of the iterator.
  72.122 +    typedef typename Map::ConstValueType ConstValueType;
  72.123 +    /// The const reference type of the iterator.
  72.124 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.125 +    /// The pointer type of the iterator.
  72.126 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.127 +    
  72.128 +  public:
  72.129 +
  72.130 +    /// The value type of the iterator.
  72.131 +    typedef extended_pair<KeyType, const KeyType&,
  72.132 +      ValueType, const ValueType&> PairValueType;
  72.133 +
  72.134 +    /// The reference type of the iterator. 
  72.135 +    typedef extended_pair<const KeyType&, const KeyType&, 
  72.136 +      ReferenceType, ReferenceType> PairReferenceType;
  72.137 +
  72.138 +    /// Default constructor. 
  72.139 +    MapIterator() {}
  72.140 +
  72.141 +    /// Constructor to initalize the iterators returned 
  72.142 +    /// by the begin() and end().
  72.143 +    MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
  72.144 +
  72.145 +    /// Dereference operator for the iterator.
  72.146 +    PairReferenceType operator*() {
  72.147 +      return PairReferenceType(Base::it, (*map)[Base::it]);
  72.148 +    }
  72.149 +
  72.150 +    /// The pointer type of the iterator.
  72.151 +    class PairPointerType {
  72.152 +      friend class MapIterator;
  72.153 +    private:
  72.154 +      PairReferenceType data;
  72.155 +      PairPointerType(const KeyType& key, ReferenceType val) 
  72.156 +	: data(key, val) {}
  72.157 +    public:
  72.158 +      PairReferenceType* operator->() {return &data;}
  72.159 +    };
  72.160 +
  72.161 +    /// Arrow operator for the iterator.
  72.162 +    PairPointerType operator->() {
  72.163 +      return PairPointerType(Base::it, ((*map)[Base::it])); 
  72.164 +    }
  72.165 +	
  72.166 +    /// The pre increment operator of the iterator.
  72.167 +    MapIterator& operator++() { 
  72.168 +      Base::increment(); 
  72.169 +      return *this; 
  72.170 +    }
  72.171 +
  72.172 +    /// The post increment operator of the iterator.
  72.173 +    MapIterator operator++(int) { 
  72.174 +      MapIterator tmp(*this); 
  72.175 +      Base::increment(); 
  72.176 +      return tmp; 
  72.177 +    }
  72.178 +
  72.179 +  private:
  72.180 +    Map* map;
  72.181 +
  72.182 +  public:
  72.183 +    // STL  compatibility typedefs.
  72.184 +    typedef std::forward_iterator_tag iterator_category;
  72.185 +    typedef int difference_type;
  72.186 +    typedef PairValueType value_type;
  72.187 +    typedef PairReferenceType reference;
  72.188 +    typedef PairPointerType pointer;
  72.189 +  };
  72.190 +
  72.191 +  /** Compatible iterator with the stl maps' iterators.
  72.192 +   *  It iterates on pairs of a key and a value.
  72.193 +   */
  72.194 +  template <typename Map>
  72.195 +  class MapConstIterator : public MapIteratorBase<Map> {
  72.196 +    
  72.197 +  public:
  72.198 +
  72.199 +    /// The iterator base class.
  72.200 +    typedef MapIteratorBase<Map> Base;
  72.201 +
  72.202 +    /// The key type of the iterator.
  72.203 +    typedef typename Map::KeyType KeyType;
  72.204 +    /// The iterator to iterate on the keys.
  72.205 +    typedef typename Map::KeyIt KeyIt;
  72.206 +
  72.207 +    /// The value type of the iterator.
  72.208 +    typedef typename Map::ValueType ValueType;
  72.209 +    /// The reference type of the iterator.
  72.210 +    typedef typename Map::ReferenceType ReferenceType;
  72.211 +    /// The pointer type of the iterator.
  72.212 +    typedef typename Map::PointerType PointerType;
  72.213 +
  72.214 +    /// The const value type of the iterator.
  72.215 +    typedef typename Map::ConstValueType ConstValueType;
  72.216 +    /// The const reference type of the iterator.
  72.217 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.218 +    /// The pointer type of the iterator.
  72.219 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.220 +
  72.221 +  public:    
  72.222 +
  72.223 +    /// Default constructor. 
  72.224 +    MapConstIterator() {}
  72.225 +
  72.226 +    /// Constructor to initalize the the iterators returned
  72.227 +    ///  by the begin() and end().
  72.228 +    MapConstIterator(const Map& pmap, const KeyIt& pit) 
  72.229 +      : Base(pit), map(&pmap) {}
  72.230 +
  72.231 +    /// Constructor to create const iterator from a non const.
  72.232 +    MapConstIterator(const MapIterator<Map>& pit) {
  72.233 +      Base::it = pit.Base::it;
  72.234 +      map = pit.map;
  72.235 +    }
  72.236 +
  72.237 +    /// The value type of the iterator.
  72.238 +    typedef extended_pair<KeyType, const KeyType&,
  72.239 +      ValueType, const ValueType&> PairValueType;
  72.240 +
  72.241 +    /// The reference type of map.
  72.242 +    typedef extended_pair<const KeyType&, const KeyType&, 
  72.243 +      ConstReferenceType, ConstReferenceType> PairReferenceType;
  72.244 +
  72.245 +    /// Dereference operator for the iterator.
  72.246 +    PairReferenceType operator*() {
  72.247 +      return PairReferenceType(Base::it, (*map)[Base::it]);
  72.248 +    }
  72.249 +
  72.250 +    /// The pointer type of the iterator.
  72.251 +    class PairPointerType {
  72.252 +      friend class MapConstIterator;
  72.253 +    private:
  72.254 +      PairReferenceType data;
  72.255 +      PairPointerType(const KeyType& key, ConstReferenceType val) 
  72.256 +	: data(key, val) {}
  72.257 +    public:
  72.258 +      PairReferenceType* operator->() {return &data;}
  72.259 +    };
  72.260 +
  72.261 +    /// Arrow operator for the iterator.
  72.262 +    PairPointerType operator->() {
  72.263 +      return PairPointerType(Base::it, (*map)[Base::it]); 
  72.264 +    }
  72.265 +
  72.266 +    /// The pre increment operator of the iterator.
  72.267 +    MapConstIterator& operator++() { 
  72.268 +      Base::increment(); 
  72.269 +      return *this; 
  72.270 +    }
  72.271 +
  72.272 +    /// The post increment operator of the iterator.
  72.273 +    MapConstIterator operator++(int) { 
  72.274 +      MapConstIterator tmp(*this); 
  72.275 +      Base::increment(); 
  72.276 +      return tmp; 
  72.277 +    }
  72.278 +
  72.279 +  private:
  72.280 +    const Map* map;
  72.281 +
  72.282 +  public:
  72.283 +    // STL  compatibility typedefs.
  72.284 +    typedef std::input_iterator_tag iterator_category;
  72.285 +    typedef int difference_type;
  72.286 +    typedef PairValueType value_type;
  72.287 +    typedef PairReferenceType reference;
  72.288 +    typedef PairPointerType pointer;
  72.289 +  };
  72.290 +
  72.291 +  /** The class makes the KeyIt to an stl compatible iterator
  72.292 +   *  with dereferencing operator.
  72.293 +   */
  72.294 +  template <typename Map>
  72.295 +  class MapKeyIterator : public MapIteratorBase<Map> {
  72.296 +
  72.297 +  public:
  72.298 +
  72.299 +    /// The iterator base class.
  72.300 +    typedef MapIteratorBase<Map> Base;
  72.301 + 
  72.302 +    /// The key type of the iterator.
  72.303 +    typedef typename Map::KeyType KeyType;
  72.304 +    /// The iterator to iterate on the keys.
  72.305 +    typedef typename Map::KeyIt KeyIt;
  72.306 +
  72.307 +  public:
  72.308 +
  72.309 +    /// Default constructor.
  72.310 +    MapKeyIterator() {}
  72.311 +
  72.312 +    /// KeyIt initialized iterator.
  72.313 +    MapKeyIterator(const KeyIt& pit) : Base(pit) {}
  72.314 +
  72.315 +    /// The pre increment operator of the iterator.
  72.316 +    MapKeyIterator& operator++() {
  72.317 +      Base::increment(); 
  72.318 +      return *this; 
  72.319 +    }
  72.320 +
  72.321 +    /// The post increment operator of the iterator.
  72.322 +    MapKeyIterator operator++(int) {
  72.323 +      MapKeyIterator tmp(*this);
  72.324 +      Base::increment();
  72.325 +      return tmp;
  72.326 +    }
  72.327 +
  72.328 +    /// The dereferencing operator of the iterator.
  72.329 +    KeyType operator*() const {
  72.330 +      return static_cast<KeyType>(Base::it);
  72.331 +    }
  72.332 +
  72.333 +  public:
  72.334 +    // STL  compatibility typedefs.
  72.335 +    typedef std::input_iterator_tag iterator_category;
  72.336 +    typedef int difference_type;
  72.337 +    typedef KeyType value_type;
  72.338 +    typedef const KeyType& reference;
  72.339 +    typedef const KeyType* pointer;
  72.340 +  };
  72.341 +
  72.342 +  template <typename Map> class MapConstValueIterator;
  72.343 +
  72.344 +  /** MapValueIterator creates an stl compatible iterator
  72.345 +   *  for the values.
  72.346 +   */
  72.347 +  template <typename Map>
  72.348 +  class MapValueIterator : public MapIteratorBase<Map> {
  72.349 +
  72.350 +    friend class MapConstValueIterator<Map>;
  72.351 +
  72.352 +  public:
  72.353 +
  72.354 +    /// The iterator base class.
  72.355 +    typedef MapIteratorBase<Map> Base;
  72.356 +
  72.357 +    /// The key type of the iterator.
  72.358 +    typedef typename Map::KeyType KeyType;
  72.359 +    /// The iterator to iterate on the keys.
  72.360 +    typedef typename Map::KeyIt KeyIt;
  72.361 +
  72.362 +
  72.363 +    /// The value type of the iterator.
  72.364 +    typedef typename Map::ValueType ValueType;
  72.365 +    /// The reference type of the iterator.
  72.366 +    typedef typename Map::ReferenceType ReferenceType;
  72.367 +    /// The pointer type of the iterator.
  72.368 +    typedef typename Map::PointerType PointerType;
  72.369 +
  72.370 +    /// The const value type of the iterator.
  72.371 +    typedef typename Map::ConstValueType ConstValueType;
  72.372 +    /// The const reference type of the iterator.
  72.373 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.374 +    /// The pointer type of the iterator.
  72.375 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.376 +
  72.377 +  private:
  72.378 +
  72.379 +    Map* map;
  72.380 +
  72.381 +  public:
  72.382 +
  72.383 +    /// Default constructor.
  72.384 +    MapValueIterator() {}
  72.385 +
  72.386 +    /// Map and KeyIt initialized iterator.
  72.387 +    MapValueIterator(Map& pmap, const KeyIt& pit) 
  72.388 +      : Base(pit), map(&pmap) {}
  72.389 +    
  72.390 +
  72.391 +    /// The pre increment operator of the iterator.
  72.392 +    MapValueIterator& operator++() {
  72.393 +      Base::increment(); 
  72.394 +      return *this; 
  72.395 +    }
  72.396 +
  72.397 +    /// The post increment operator of the iterator.
  72.398 +    MapValueIterator operator++(int) {
  72.399 +      MapValueIterator tmp(*this);
  72.400 +      Base::increment();
  72.401 +      return tmp;
  72.402 +    }
  72.403 +
  72.404 +    /// The dereferencing operator of the iterator.
  72.405 +    ReferenceType operator*() const {
  72.406 +      return (*map)[Base::it];
  72.407 +    }
  72.408 +
  72.409 +    /// The arrow operator of the iterator.
  72.410 +    PointerType operator->() const {
  72.411 +      return &(operator*());
  72.412 +    }
  72.413 +
  72.414 +  public:
  72.415 +    // STL  compatibility typedefs.
  72.416 +    typedef std::forward_iterator_tag iterator_category;
  72.417 +    typedef int difference_type;
  72.418 +    typedef ValueType value_type;
  72.419 +    typedef ReferenceType reference;
  72.420 +    typedef PointerType pointer;
  72.421 +  };
  72.422 +
  72.423 +  /** MapValueIterator creates an stl compatible iterator
  72.424 +   *  for the const values.
  72.425 +   */
  72.426 +
  72.427 +  template <typename Map>
  72.428 +  class MapConstValueIterator : public MapIteratorBase<Map> {
  72.429 +
  72.430 +  public:
  72.431 +
  72.432 +    /// The iterator base class.
  72.433 +    typedef MapIteratorBase<Map> Base;
  72.434 +
  72.435 +    /// The key type of the iterator.
  72.436 +    typedef typename Map::KeyType KeyType;
  72.437 +    /// The iterator to iterate on the keys.
  72.438 +    typedef typename Map::KeyIt KeyIt;
  72.439 +
  72.440 +    /// The value type of the iterator.
  72.441 +    typedef typename Map::ValueType ValueType;
  72.442 +    /// The reference type of the iterator.
  72.443 +    typedef typename Map::ReferenceType ReferenceType;
  72.444 +    /// The pointer type of the iterator.
  72.445 +    typedef typename Map::PointerType PointerType;
  72.446 +
  72.447 +    /// The const value type of the iterator.
  72.448 +    typedef typename Map::ConstValueType ConstValueType;
  72.449 +    /// The const reference type of the iterator.
  72.450 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.451 +    /// The pointer type of the iterator.
  72.452 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.453 +
  72.454 +  private:
  72.455 +
  72.456 +    const Map* map;
  72.457 +
  72.458 +  public:
  72.459 +
  72.460 +    /// Default constructor.
  72.461 +    MapConstValueIterator() {}
  72.462 +
  72.463 +    /// Constructor to create const iterator from a non const.
  72.464 +    MapConstValueIterator(const MapValueIterator<Map>& pit) {
  72.465 +      Base::it = pit.Base::it;
  72.466 +      map = pit.map;
  72.467 +    }
  72.468 +
  72.469 +    /// Map and KeyIt initialized iterator.
  72.470 +    MapConstValueIterator(const Map& pmap, const KeyIt& pit) 
  72.471 +      : Base(pit), map(&pmap) {}
  72.472 +
  72.473 +    /// The pre increment operator of the iterator.
  72.474 +    MapConstValueIterator& operator++() {
  72.475 +      Base::increment(); 
  72.476 +      return *this; 
  72.477 +    }
  72.478 +
  72.479 +    /// The post increment operator of the iterator.
  72.480 +    MapConstValueIterator operator++(int) {
  72.481 +      MapConstValueIterator tmp(*this);
  72.482 +      Base::increment();
  72.483 +      return tmp;
  72.484 +    }
  72.485 +
  72.486 +    /// The dereferencing operator of the iterator.
  72.487 +    ConstReferenceType operator*() const {
  72.488 +      return (*map)[Base::it];
  72.489 +    }
  72.490 +
  72.491 +    /// The arrow operator of the iterator.
  72.492 +    ConstPointerType operator->() const {
  72.493 +      return &(operator*());
  72.494 +    }
  72.495 +
  72.496 +  public:
  72.497 +    // STL  compatibility typedefs.
  72.498 +    typedef std::input_iterator_tag iterator_category;
  72.499 +    typedef int difference_type;
  72.500 +    typedef ValueType value_type;
  72.501 +    typedef ConstReferenceType reference;
  72.502 +    typedef ConstPointerType pointer;
  72.503 +  };
  72.504 +
  72.505 +
  72.506 +  /** This class makes from a map an iteratable set
  72.507 +   *  which contains all the keys of the map.
  72.508 +   */
  72.509 +  template <typename Map>
  72.510 +  class MapConstKeySet {
  72.511 +
  72.512 +    const Map* map;
  72.513 +
  72.514 +  public:
  72.515 +
  72.516 +    /// The key type of the iterator.
  72.517 +    typedef typename Map::KeyType KeyType;
  72.518 +    /// The iterator to iterate on the keys.
  72.519 +    typedef typename Map::KeyIt KeyIt;
  72.520 +
  72.521 +
  72.522 +    /// The value type of the iterator.
  72.523 +    typedef typename Map::ValueType ValueType;
  72.524 +    /// The reference type of the iterator.
  72.525 +    typedef typename Map::ReferenceType ReferenceType;
  72.526 +    /// The pointer type of the iterator.
  72.527 +    typedef typename Map::PointerType PointerType;
  72.528 +
  72.529 +    /// The const value type of the iterator.
  72.530 +    typedef typename Map::ConstValueType ConstValueType;
  72.531 +    /// The const reference type of the iterator.
  72.532 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.533 +    /// The pointer type of the iterator.
  72.534 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.535 +
  72.536 +    /// The map initialized const key set.
  72.537 +    MapConstKeySet(const Map& pmap) : map(&pmap) {}
  72.538 +
  72.539 +    /// The const iterator of the set.
  72.540 +    typedef MapKeyIterator<Map> ConstIterator;
  72.541 +
  72.542 +    /// It gives back the const iterator pointed to the first element.
  72.543 +    ConstIterator begin() const {
  72.544 +      return ConstIterator(KeyIt(*map->getGraph()));
  72.545 +    }
  72.546 +            
  72.547 +    /// It gives back the const iterator pointed to the first ivalid element.
  72.548 +    ConstIterator end() const {
  72.549 +      return ConstIterator(KeyIt(INVALID));
  72.550 +    }
  72.551 + 
  72.552 +  public:
  72.553 +    // STL  compatibility typedefs.
  72.554 +    typedef ValueType value_type;
  72.555 +    typedef ConstIterator const_iterator;
  72.556 +    typedef ConstReferenceType const_reference;
  72.557 +    typedef ConstPointerType const_pointer;
  72.558 +    typedef int difference_type;
  72.559 +  };
  72.560 +
  72.561 +  /** This class makes from a map an iteratable set
  72.562 +   *  which contains all the values of the map.
  72.563 +   *  The values cannot be modified.
  72.564 +   */
  72.565 +  template <typename Map>
  72.566 +  class MapConstValueSet {
  72.567 +
  72.568 +    const Map* map;
  72.569 +
  72.570 +  public:
  72.571 +
  72.572 +    /// The key type of the iterator.
  72.573 +    typedef typename Map::KeyType KeyType;
  72.574 +    /// The iterator to iterate on the keys.
  72.575 +    typedef typename Map::KeyIt KeyIt;
  72.576 +
  72.577 +
  72.578 +    /// The value type of the iterator.
  72.579 +    typedef typename Map::ValueType ValueType;
  72.580 +    /// The reference type of the iterator.
  72.581 +    typedef typename Map::ReferenceType ReferenceType;
  72.582 +    /// The pointer type of the iterator.
  72.583 +    typedef typename Map::PointerType PointerType;
  72.584 +
  72.585 +    /// The const value type of the iterator.
  72.586 +    typedef typename Map::ConstValueType ConstValueType;
  72.587 +    /// The const reference type of the iterator.
  72.588 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.589 +    /// The pointer type of the iterator.
  72.590 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.591 +
  72.592 +    /// The map initialized const value set.
  72.593 +    MapConstValueSet(const Map& pmap) : map(&pmap) {}
  72.594 +
  72.595 +    /// The const iterator of the set.
  72.596 +    typedef MapConstValueIterator<Map> ConstIterator;
  72.597 +
  72.598 +    /// It gives back the const iterator pointed to the first element.
  72.599 +    ConstIterator begin() const {
  72.600 +      return ConstIterator(*map, KeyIt(*map->getGraph()));
  72.601 +    }
  72.602 +
  72.603 +    /// It gives back the const iterator pointed to the first invalid element.
  72.604 +    ConstIterator end() const {
  72.605 +      return ConstIterator(*map, KeyIt(INVALID));
  72.606 +    }
  72.607 +
  72.608 +  public:
  72.609 +    // STL  compatibility typedefs.
  72.610 +    typedef ValueType value_type;
  72.611 +    typedef ConstIterator const_iterator;
  72.612 +    typedef ConstReferenceType const_reference;
  72.613 +    typedef ConstPointerType const_pointer;
  72.614 +    typedef int difference_type;
  72.615 +  };
  72.616 +
  72.617 +
  72.618 +  /** This class makes from a map an iteratable set
  72.619 +   *  which contains all the values of the map.
  72.620 +   *  The values can be modified.
  72.621 +   */
  72.622 +  template <typename Map>
  72.623 +  class MapValueSet {
  72.624 +
  72.625 +    Map* map;
  72.626 +
  72.627 +  public:
  72.628 +
  72.629 +    /// The key type of the iterator.
  72.630 +    typedef typename Map::KeyType KeyType;
  72.631 +    /// The iterator to iterate on the keys.
  72.632 +    typedef typename Map::KeyIt KeyIt;
  72.633 +
  72.634 +
  72.635 +    /// The value type of the iterator.
  72.636 +    typedef typename Map::ValueType ValueType;
  72.637 +    /// The reference type of the iterator.
  72.638 +    typedef typename Map::ReferenceType ReferenceType;
  72.639 +    /// The pointer type of the iterator.
  72.640 +    typedef typename Map::PointerType PointerType;
  72.641 +
  72.642 +    /// The const value type of the iterator.
  72.643 +    typedef typename Map::ConstValueType ConstValueType;
  72.644 +    /// The const reference type of the iterator.
  72.645 +    typedef typename Map::ConstReferenceType ConstReferenceType;
  72.646 +    /// The pointer type of the iterator.
  72.647 +    typedef typename Map::ConstPointerType ConstPointerType;
  72.648 +
  72.649 +    /// The map initialized value set.
  72.650 +    MapValueSet(Map& pmap) : map(&pmap) {}
  72.651 +
  72.652 +    /// The const iterator of the set.
  72.653 +    typedef MapConstValueIterator<Map> ConstIterator;
  72.654 +
  72.655 +    /// It gives back the const iterator pointed to the first element.
  72.656 +    ConstIterator begin() const {
  72.657 +      return ConstIterator(*map, KeyIt(*map->getGraph()));
  72.658 +    }
  72.659 +
  72.660 +    /// It gives back the const iterator pointed to the first invalid element.
  72.661 +    ConstIterator end() const {
  72.662 +      return ConstIterator(*map, KeyIt(INVALID));
  72.663 +    }
  72.664 +
  72.665 +    /// The iterator of the set.
  72.666 +    typedef MapValueIterator<Map> Iterator;
  72.667 +
  72.668 +    /// It gives back the iterator pointed to the first element.
  72.669 +    Iterator begin() {
  72.670 +      return Iterator(*map, KeyIt(*map->getGraph()));
  72.671 +    }
  72.672 +
  72.673 +    /// It gives back the iterator pointed to the first invalid element.
  72.674 +    Iterator end() {
  72.675 +      return Iterator(*map, KeyIt(INVALID));
  72.676 +    }
  72.677 +            
  72.678 +  public:
  72.679 +    // STL  compatibility typedefs.
  72.680 +    typedef ValueType value_type;
  72.681 +    typedef Iterator iterator;
  72.682 +    typedef ConstIterator const_iterator;
  72.683 +    typedef ReferenceType reference;
  72.684 +    typedef ConstReferenceType const_reference;
  72.685 +    typedef PointerType pointer;
  72.686 +    typedef ConstPointerType const_pointer;
  72.687 +    typedef int difference_type;
  72.688 +
  72.689 +  };
  72.690 +
  72.691 +  /// @}
  72.692 +
  72.693 +}
  72.694 +
  72.695 +#endif
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/src/lemon/map_registry.h	Wed Sep 29 15:30:04 2004 +0000
    73.3 @@ -0,0 +1,289 @@
    73.4 +/* -*- C++ -*-
    73.5 + * src/lemon/map_registry.h - Part of LEMON, a generic C++ optimization library
    73.6 + *
    73.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    73.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    73.9 + *
   73.10 + * Permission to use, modify and distribute this software is granted
   73.11 + * provided that this copyright notice appears in all copies. For
   73.12 + * precise terms see the accompanying LICENSE file.
   73.13 + *
   73.14 + * This software is provided "AS IS" with no warranty of any kind,
   73.15 + * express or implied, and with no claim as to its suitability for any
   73.16 + * purpose.
   73.17 + *
   73.18 + */
   73.19 +
   73.20 +#ifndef LEMON_MAP_REGISTRY_H
   73.21 +#define LEMON_MAP_REGISTRY_H
   73.22 +
   73.23 +#include <vector>
   73.24 +
   73.25 +///\ingroup graphmapfactory
   73.26 +///\file
   73.27 +///\brief Map registry for graph maps.
   73.28 +
   73.29 +using namespace std;
   73.30 +
   73.31 +namespace lemon {
   73.32 +
   73.33 +/// \addtogroup graphmapfactory
   73.34 +/// @{
   73.35 +
   73.36 +/** 
   73.37 + * Registry class to register edge or node maps into the graph. The
   73.38 + * registry helps you to implement an observer pattern. If you add
   73.39 + * or erase an edge or node you must notify all the maps about the
   73.40 + * event.
   73.41 +*/
   73.42 +  template <typename G, typename K, typename KIt>
   73.43 +  class MapRegistry {
   73.44 +  public:
   73.45 +    typedef G Graph;
   73.46 +    typedef K KeyType;
   73.47 +    typedef KIt KeyIt;
   73.48 +	
   73.49 +    /**
   73.50 +     * MapBase is the base class of the registered maps.
   73.51 +     * It defines the core modification operations on the maps and
   73.52 +     * implements some helper functions. 
   73.53 +     */
   73.54 +    class MapBase {
   73.55 +    public:
   73.56 +      typedef G Graph;
   73.57 +      typedef K KeyType;
   73.58 +      typedef KIt KeyIt;
   73.59 +
   73.60 +      typedef MapRegistry<G, K, KIt> Registry;
   73.61 +	
   73.62 +      friend class MapRegistry<G, K, KIt>;
   73.63 +
   73.64 +      /**
   73.65 +       * Default constructor for MapBase.
   73.66 +       */
   73.67 +
   73.68 +      MapBase() : graph(0), registry(0) {}
   73.69 +		
   73.70 +      /** 
   73.71 +       * Simple constructor to register into a graph registry.
   73.72 +      */
   73.73 +	
   73.74 +      MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
   73.75 +	r.attach(*this);
   73.76 +      }
   73.77 +
   73.78 +      /** 
   73.79 +       * Copy constructor to register into the registry.
   73.80 +      */	
   73.81 +	
   73.82 +      MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
   73.83 +	if (copy.registry) {
   73.84 +	  copy.registry->attach(*this);
   73.85 +	}
   73.86 +      } 
   73.87 +	
   73.88 +      /** 
   73.89 +       * Assign operator.
   73.90 +      */	
   73.91 +      const MapBase& operator=(const MapBase& copy) {
   73.92 +	if (registry) {
   73.93 +	  registry->detach(*this);
   73.94 +	}
   73.95 +	graph = copy.graph;
   73.96 +	if (copy.registry) {
   73.97 +	  copy.registry->attach(*this);
   73.98 +	}
   73.99 +	return *this;
  73.100 +      }
  73.101 +	
  73.102 +
  73.103 +      /** 
  73.104 +       * Destructor. 
  73.105 +      */		
  73.106 +
  73.107 +      virtual ~MapBase() {
  73.108 +	if (registry) {
  73.109 +	  registry->detach(*this);
  73.110 +	}
  73.111 +      }
  73.112 +
  73.113 +      /*
  73.114 +       * Returns the graph that the map belongs to.
  73.115 +      */
  73.116 +
  73.117 +      const Graph* getGraph() const { return graph; }
  73.118 +	
  73.119 +    protected:
  73.120 +		
  73.121 +      const Graph* graph;     
  73.122 +      Registry* registry;
  73.123 +
  73.124 +      int registry_index;
  73.125 +
  73.126 +    protected:
  73.127 +	
  73.128 +      /**
  73.129 +	 Helper function to implement constructors in the subclasses.
  73.130 +      */
  73.131 +	
  73.132 +      virtual void init() {
  73.133 +	for (KeyIt it(*graph); it != INVALID; ++it) {
  73.134 +	  add(it);
  73.135 +	}
  73.136 +      }
  73.137 +	
  73.138 +      /**
  73.139 +	 Helper function to implement the destructor in the subclasses.
  73.140 +      */
  73.141 +	
  73.142 +      virtual void destroy() {
  73.143 +	for (KeyIt it(*getGraph()); it != INVALID; ++it) {
  73.144 +	  erase(it);
  73.145 +	}
  73.146 +      }
  73.147 +	
  73.148 +      /** 
  73.149 +	  The add member function should be overloaded in the subclasses.
  73.150 +	  \e Add extends the map with the new node.
  73.151 +      */
  73.152 +	
  73.153 +      virtual void add(const KeyType&) = 0;	
  73.154 +      /** 
  73.155 +	  The erase member function should be overloaded in the subclasses.
  73.156 +	  \e Erase removes the node from the map.
  73.157 +      */
  73.158 +	
  73.159 +      virtual void erase(const KeyType&) = 0;
  73.160 +
  73.161 +      /**
  73.162 +       *  The clear member function should be overloaded in the subclasses.
  73.163 +       *  \e Clear makes empty the data structure.
  73.164 +       */
  73.165 +
  73.166 +      virtual void clear() = 0;
  73.167 +	
  73.168 +      /**
  73.169 +	 Exception class to throw at unsupported operation.
  73.170 +      */
  73.171 +	
  73.172 +      class NotSupportedOperationException {};
  73.173 +
  73.174 +    };
  73.175 +	
  73.176 +  protected:
  73.177 +	
  73.178 +    /** 
  73.179 +     * The container type of the maps.
  73.180 +     */
  73.181 +    typedef std::vector<MapBase*> Container; 
  73.182 +
  73.183 +    /**
  73.184 +     * The container of the registered maps.
  73.185 +     */
  73.186 +    Container container;
  73.187 +
  73.188 +		
  73.189 +  public:
  73.190 +	
  73.191 +    /**
  73.192 +     * Default Constructor of the MapRegistry. It creates an empty registry.
  73.193 +     */
  73.194 +    MapRegistry() {}
  73.195 +	
  73.196 +    /**
  73.197 +     * Copy Constructor of the MapRegistry. The new registry does not steal
  73.198 +     * the maps from the right value. The new registry will be an empty.
  73.199 +     */
  73.200 +    MapRegistry(const MapRegistry&) {}
  73.201 +		
  73.202 +    /**
  73.203 +     * Assign operator. The left value does not steal the maps 
  73.204 +     * from the right value. The left value will be an empty registry.
  73.205 +     */
  73.206 +    MapRegistry& operator=(const MapRegistry&) {
  73.207 +      typename Container::iterator it;
  73.208 +      for (it = container.begin(); it != container.end(); ++it) {
  73.209 +	(*it)->destroy();
  73.210 +	(*it)->graph = 0;
  73.211 +	(*it)->registry = 0;
  73.212 +      }
  73.213 +    }
  73.214 +				
  73.215 +    /**
  73.216 +     * Destructor of the MapRegistry.
  73.217 +     */
  73.218 +    ~MapRegistry() {
  73.219 +      typename Container::iterator it;
  73.220 +      for (it = container.begin(); it != container.end(); ++it) {
  73.221 +	(*it)->destroy();
  73.222 +	(*it)->registry = 0;
  73.223 +	(*it)->graph = 0;
  73.224 +      }
  73.225 +    }
  73.226 +	
  73.227 +	
  73.228 +    public:
  73.229 +	
  73.230 +    /**
  73.231 +     * Attach a map into thr registry. If the map has been attached
  73.232 +     * into an other registry it is detached from that automaticly.
  73.233 +     */
  73.234 +    void attach(MapBase& map) {
  73.235 +      if (map.registry) {
  73.236 +	map.registry->detach(map);
  73.237 +      }
  73.238 +      container.push_back(&map);
  73.239 +      map.registry = this;
  73.240 +      map.registry_index = container.size()-1;
  73.241 +    } 
  73.242 +	
  73.243 +    /**
  73.244 +     * Detach the map from the registry.
  73.245 +     */
  73.246 +    void detach(MapBase& map) {
  73.247 +      container.back()->registry_index = map.registry_index; 
  73.248 +      container[map.registry_index] = container.back();
  73.249 +      container.pop_back();
  73.250 +      map.registry = 0;
  73.251 +      map.graph = 0;
  73.252 +    }
  73.253 +	
  73.254 +		
  73.255 +    /**
  73.256 +     * Notify all the registered maps about a Key added.
  73.257 +     */
  73.258 +    void add(KeyType& key) {
  73.259 +      typename Container::iterator it;
  73.260 +      for (it = container.begin(); it != container.end(); ++it) {
  73.261 +	(*it)->add(key);
  73.262 +      }
  73.263 +    }	
  73.264 +		
  73.265 +    /**
  73.266 +     * Notify all the registered maps about a Key erased.
  73.267 +     */ 
  73.268 +    void erase(KeyType& key) {
  73.269 +      typename Container::iterator it;
  73.270 +      for (it = container.begin(); it != container.end(); ++it) {
  73.271 +	(*it)->erase(key);
  73.272 +      }
  73.273 +    }
  73.274 +
  73.275 +    /**
  73.276 +     * Notify all the registered maps about the map should be cleared.
  73.277 +     */ 
  73.278 +    void clear() {
  73.279 +      typename Container::iterator it;
  73.280 +      for (it = container.begin(); it != container.end(); ++it) {
  73.281 +	(*it)->clear();
  73.282 +      }
  73.283 +    }
  73.284 +  };
  73.285 +
  73.286 +  
  73.287 +/// @}
  73.288 +  
  73.289 +
  73.290 +}
  73.291 +
  73.292 +#endif
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/src/lemon/maps.h	Wed Sep 29 15:30:04 2004 +0000
    74.3 @@ -0,0 +1,176 @@
    74.4 +/* -*- C++ -*-
    74.5 + * src/lemon/maps.h - Part of LEMON, a generic C++ optimization library
    74.6 + *
    74.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    74.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    74.9 + *
   74.10 + * Permission to use, modify and distribute this software is granted
   74.11 + * provided that this copyright notice appears in all copies. For
   74.12 + * precise terms see the accompanying LICENSE file.
   74.13 + *
   74.14 + * This software is provided "AS IS" with no warranty of any kind,
   74.15 + * express or implied, and with no claim as to its suitability for any
   74.16 + * purpose.
   74.17 + *
   74.18 + */
   74.19 +
   74.20 +#ifndef LEMON_MAPS_H
   74.21 +#define LEMON_MAPS_H
   74.22 +
   74.23 +///\file
   74.24 +///\brief Miscellaneous property maps
   74.25 +///
   74.26 +///\todo This file has the same name as the concept file in skeletons,
   74.27 +/// and this is not easily detectable in docs...
   74.28 +
   74.29 +#include <map>
   74.30 +
   74.31 +namespace lemon {
   74.32 +
   74.33 +  /// Base class of maps.
   74.34 +
   74.35 +  /// Base class of maps.
   74.36 +  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
   74.37 +  template<typename K, typename T>
   74.38 +  class MapBase
   74.39 +  {
   74.40 +  public:
   74.41 +    ///\e
   74.42 +    typedef K KeyType;
   74.43 +    ///\e
   74.44 +    typedef T ValueType;
   74.45 +  };
   74.46 +
   74.47 +  /// Null map. (a.k.a. DoNothingMap)
   74.48 +
   74.49 +  /// If you have to provide a map only for its type definitions,
   74.50 +  /// or if you have to provide a writable map, but
   74.51 +  /// data written to it will sent to <tt>/dev/null</tt>...
   74.52 +  template<typename K, typename T>
   74.53 +  class NullMap : public MapBase<K,T>
   74.54 +  {
   74.55 +  public:
   74.56 +
   74.57 +    /// Gives back a default constructed element.
   74.58 +    T operator[](const K&) const { return T(); }
   74.59 +    /// Absorbs the value.
   74.60 +    void set(const K&, const T&) {}
   74.61 +  };
   74.62 +
   74.63 +
   74.64 +  /// Constant map.
   74.65 +
   74.66 +  /// This is a readable map which assigns a specified value to each key.
   74.67 +  /// In other aspects it is equivalent to the \ref NullMap.
   74.68 +  /// \todo set could be used to set the value.
   74.69 +  template<typename K, typename T>
   74.70 +  class ConstMap : public MapBase<K,T>
   74.71 +  {
   74.72 +    T v;
   74.73 +  public:
   74.74 +
   74.75 +    /// Default constructor
   74.76 +
   74.77 +    /// The value of the map will be uninitialized. 
   74.78 +    /// (More exactly it will be default constructed.)
   74.79 +    ConstMap() {}
   74.80 +    ///\e
   74.81 +
   74.82 +    /// \param _v The initial value of the map.
   74.83 +    ///
   74.84 +    ConstMap(const T &_v) : v(_v) {}
   74.85 +
   74.86 +    T operator[](const K&) const { return v; }
   74.87 +    void set(const K&, const T&) {}
   74.88 +
   74.89 +    template<typename T1>
   74.90 +    struct rebind {
   74.91 +      typedef ConstMap<K,T1> other;
   74.92 +    };
   74.93 +
   74.94 +    template<typename T1>
   74.95 +    ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
   74.96 +  };
   74.97 +
   74.98 +  //to document later
   74.99 +  template<typename T, T v>
  74.100 +  struct Const { };
  74.101 +  //to document later
  74.102 +  template<typename K, typename V, V v>
  74.103 +  class ConstMap<K, Const<V, v> > : public MapBase<K, V>
  74.104 +  {
  74.105 +  public:
  74.106 +    ConstMap() { }
  74.107 +    V operator[](const K&) const { return v; }
  74.108 +    void set(const K&, const V&) { }
  74.109 +  };
  74.110 +  //to document later
  74.111 +  typedef Const<bool, true> True;
  74.112 +  typedef Const<bool, false> False;
  74.113 +
  74.114 +  /// \c std::map wrapper
  74.115 +
  74.116 +  /// This is essentially a wrapper for \c std::map. With addition that
  74.117 +  /// you can specify a default value different from \c ValueType() .
  74.118 +  ///
  74.119 +  /// \todo Provide allocator parameter...
  74.120 +  template <typename Key, typename T, typename Compare = std::less<Key> >
  74.121 +  class StdMap : public std::map<Key,T,Compare> {
  74.122 +    typedef std::map<Key,T,Compare> parent;
  74.123 +    T v;
  74.124 +    typedef typename parent::value_type PairType;
  74.125 +
  74.126 +  public:
  74.127 +    typedef Key KeyType;
  74.128 +    typedef T ValueType;
  74.129 +    typedef T& ReferenceType;
  74.130 +    typedef const T& ConstReferenceType;
  74.131 +
  74.132 +
  74.133 +    StdMap() : v() {}
  74.134 +    /// Constructor with specified default value
  74.135 +    StdMap(const T& _v) : v(_v) {}
  74.136 +
  74.137 +    /// \brief Constructs the map from an appropriate std::map.
  74.138 +    ///
  74.139 +    /// \warning Inefficient: copies the content of \c m !
  74.140 +    StdMap(const parent &m) : parent(m) {}
  74.141 +    /// \brief Constructs the map from an appropriate std::map, and explicitly
  74.142 +    /// specifies a default value.
  74.143 +    ///
  74.144 +    /// \warning Inefficient: copies the content of \c m !
  74.145 +    StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
  74.146 +    
  74.147 +    template<typename T1, typename Comp1>
  74.148 +    StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) { 
  74.149 +      //FIXME; 
  74.150 +    }
  74.151 +
  74.152 +    ReferenceType operator[](const Key &k) {
  74.153 +      return insert(PairType(k,v)).first -> second;
  74.154 +    }
  74.155 +    ConstReferenceType operator[](const Key &k) const {
  74.156 +      typename parent::iterator i = lower_bound(k);
  74.157 +      if (i == parent::end() || parent::key_comp()(k, (*i).first))
  74.158 +	return v;
  74.159 +      return (*i).second;
  74.160 +    }
  74.161 +    void set(const Key &k, const T &t) {
  74.162 +      parent::operator[](k) = t;
  74.163 +    }
  74.164 +
  74.165 +    /// Changes the default value of the map.
  74.166 +    /// \return Returns the previous default value.
  74.167 +    ///
  74.168 +    /// \warning The value of some keys (which has already been queried, but
  74.169 +    /// the value has been unchanged from the default) may change!
  74.170 +    T setDefault(const T &_v) { T old=v; v=_v; return old; }
  74.171 +
  74.172 +    template<typename T1>
  74.173 +    struct rebind {
  74.174 +      typedef StdMap<Key,T1,Compare> other;
  74.175 +    };
  74.176 +  };
  74.177 +  
  74.178 +}
  74.179 +#endif // LEMON_MAPS_H
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/src/lemon/min_cost_flow.h	Wed Sep 29 15:30:04 2004 +0000
    75.3 @@ -0,0 +1,256 @@
    75.4 +/* -*- C++ -*-
    75.5 + * src/lemon/min_cost_flow.h - Part of LEMON, a generic C++ optimization library
    75.6 + *
    75.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    75.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    75.9 + *
   75.10 + * Permission to use, modify and distribute this software is granted
   75.11 + * provided that this copyright notice appears in all copies. For
   75.12 + * precise terms see the accompanying LICENSE file.
   75.13 + *
   75.14 + * This software is provided "AS IS" with no warranty of any kind,
   75.15 + * express or implied, and with no claim as to its suitability for any
   75.16 + * purpose.
   75.17 + *
   75.18 + */
   75.19 +
   75.20 +#ifndef LEMON_MIN_COST_FLOW_H
   75.21 +#define LEMON_MIN_COST_FLOW_H
   75.22 +
   75.23 +///\ingroup flowalgs
   75.24 +///\file
   75.25 +///\brief An algorithm for finding a flow of value \c k (for small values of \c k) having minimal total cost 
   75.26 +
   75.27 +
   75.28 +#include <lemon/dijkstra.h>
   75.29 +#include <lemon/graph_wrapper.h>
   75.30 +#include <lemon/maps.h>
   75.31 +#include <vector>
   75.32 +
   75.33 +namespace lemon {
   75.34 +
   75.35 +/// \addtogroup flowalgs
   75.36 +/// @{
   75.37 +
   75.38 +  ///\brief Implementation of an algorithm for finding a flow of value \c k 
   75.39 +  ///(for small values of \c k) having minimal total cost between 2 nodes 
   75.40 +  /// 
   75.41 +  ///
   75.42 +  /// The class \ref lemon::MinCostFlow "MinCostFlow" implements
   75.43 +  /// an algorithm for finding a flow of value \c k 
   75.44 +  /// having minimal total cost 
   75.45 +  /// from a given source node to a given target node in an
   75.46 +  /// edge-weighted directed graph. To this end, 
   75.47 +  /// the edge-capacities and edge-weitghs have to be nonnegative. 
   75.48 +  /// The edge-capacities should be integers, but the edge-weights can be 
   75.49 +  /// integers, reals or of other comparable numeric type.
   75.50 +  /// This algorithm is intended to use only for small values of \c k, 
   75.51 +  /// since it is only polynomial in k, 
   75.52 +  /// not in the length of k (which is log k). 
   75.53 +  /// In order to find the minimum cost flow of value \c k it 
   75.54 +  /// finds the minimum cost flow of value \c i for every 
   75.55 +  /// \c i between 0 and \c k. 
   75.56 +  ///
   75.57 +  ///\param Graph The directed graph type the algorithm runs on.
   75.58 +  ///\param LengthMap The type of the length map.
   75.59 +  ///\param CapacityMap The capacity map type.
   75.60 +  ///
   75.61 +  ///\author Attila Bernath
   75.62 +  template <typename Graph, typename LengthMap, typename CapacityMap>
   75.63 +  class MinCostFlow {
   75.64 +
   75.65 +    typedef typename LengthMap::ValueType Length;
   75.66 +
   75.67 +    //Warning: this should be integer type
   75.68 +    typedef typename CapacityMap::ValueType Capacity;
   75.69 +    
   75.70 +    typedef typename Graph::Node Node;
   75.71 +    typedef typename Graph::NodeIt NodeIt;
   75.72 +    typedef typename Graph::Edge Edge;
   75.73 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   75.74 +    typedef typename Graph::template EdgeMap<int> EdgeIntMap;
   75.75 +
   75.76 +
   75.77 +    typedef ResGraphWrapper<const Graph,int,CapacityMap,EdgeIntMap> ResGW;
   75.78 +    typedef typename ResGW::Edge ResGraphEdge;
   75.79 +
   75.80 +    class ModLengthMap {   
   75.81 +      typedef typename Graph::template NodeMap<Length> NodeMap;
   75.82 +      const ResGW& G;
   75.83 +      const LengthMap &ol;
   75.84 +      const NodeMap &pot;
   75.85 +    public :
   75.86 +      typedef typename LengthMap::KeyType KeyType;
   75.87 +      typedef typename LengthMap::ValueType ValueType;
   75.88 +	
   75.89 +      ValueType operator[](typename ResGW::Edge e) const {     
   75.90 +	if (G.forward(e))
   75.91 +	  return  ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
   75.92 +	else
   75.93 +	  return -ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);   
   75.94 +      }     
   75.95 +	
   75.96 +      ModLengthMap(const ResGW& _G,
   75.97 +		   const LengthMap &o,  const NodeMap &p) : 
   75.98 +	G(_G), /*rev(_rev),*/ ol(o), pot(p){}; 
   75.99 +    };//ModLengthMap
  75.100 +
  75.101 +
  75.102 +  protected:
  75.103 +    
  75.104 +    //Input
  75.105 +    const Graph& G;
  75.106 +    const LengthMap& length;
  75.107 +    const CapacityMap& capacity;
  75.108 +
  75.109 +
  75.110 +    //auxiliary variables
  75.111 +
  75.112 +    //To store the flow
  75.113 +    EdgeIntMap flow; 
  75.114 +    //To store the potential (dual variables)
  75.115 +    typedef typename Graph::template NodeMap<Length> PotentialMap;
  75.116 +    PotentialMap potential;
  75.117 +    
  75.118 +
  75.119 +    Length total_length;
  75.120 +
  75.121 +
  75.122 +  public :
  75.123 +
  75.124 +    /// The constructor of the class.
  75.125 +    
  75.126 +    ///\param _G The directed graph the algorithm runs on. 
  75.127 +    ///\param _length The length (weight or cost) of the edges. 
  75.128 +    ///\param _cap The capacity of the edges. 
  75.129 +    MinCostFlow(Graph& _G, LengthMap& _length, CapacityMap& _cap) : G(_G), 
  75.130 +      length(_length), capacity(_cap), flow(_G), potential(_G){ }
  75.131 +
  75.132 +    
  75.133 +    ///Runs the algorithm.
  75.134 +    
  75.135 +    ///Runs the algorithm.
  75.136 +    ///Returns k if there is a flow of value at least k edge-disjoint 
  75.137 +    ///from s to t.
  75.138 +    ///Otherwise it returns the maximum value of a flow from s to t.
  75.139 +    ///
  75.140 +    ///\param s The source node.
  75.141 +    ///\param t The target node.
  75.142 +    ///\param k The value of the flow we are looking for.
  75.143 +    ///
  75.144 +    ///\todo May be it does make sense to be able to start with a nonzero 
  75.145 +    /// feasible primal-dual solution pair as well.
  75.146 +    int run(Node s, Node t, int k) {
  75.147 +
  75.148 +      //Resetting variables from previous runs
  75.149 +      total_length = 0;
  75.150 +      
  75.151 +      for (typename Graph::EdgeIt e(G); e!=INVALID; ++e) flow.set(e, 0);
  75.152 +
  75.153 +      //Initialize the potential to zero
  75.154 +      for (typename Graph::NodeIt n(G); n!=INVALID; ++n) potential.set(n, 0);
  75.155 +      
  75.156 +      
  75.157 +      //We need a residual graph
  75.158 +      ResGW res_graph(G, capacity, flow);
  75.159 +
  75.160 +
  75.161 +      ModLengthMap mod_length(res_graph, length, potential);
  75.162 +
  75.163 +      Dijkstra<ResGW, ModLengthMap> dijkstra(res_graph, mod_length);
  75.164 +
  75.165 +      int i;
  75.166 +      for (i=0; i<k; ++i){
  75.167 +	dijkstra.run(s);
  75.168 +	if (!dijkstra.reached(t)){
  75.169 +	  //There are no flow of value k from s to t
  75.170 +	  break;
  75.171 +	};
  75.172 +	
  75.173 +	//We have to change the potential
  75.174 +        for(typename ResGW::NodeIt n(res_graph); n!=INVALID; ++n)
  75.175 +	  potential[n] += dijkstra.distMap()[n];
  75.176 +
  75.177 +
  75.178 +	//Augmenting on the sortest path
  75.179 +	Node n=t;
  75.180 +	ResGraphEdge e;
  75.181 +	while (n!=s){
  75.182 +	  e = dijkstra.pred(n);
  75.183 +	  n = dijkstra.predNode(n);
  75.184 +	  res_graph.augment(e,1);
  75.185 +	  //Let's update the total length
  75.186 +	  if (res_graph.forward(e))
  75.187 +	    total_length += length[e];
  75.188 +	  else 
  75.189 +	    total_length -= length[e];	    
  75.190 +	}
  75.191 +
  75.192 +	  
  75.193 +      }
  75.194 +      
  75.195 +
  75.196 +      return i;
  75.197 +    }
  75.198 +
  75.199 +
  75.200 +
  75.201 +    /// Gives back the total weight of the found flow.
  75.202 +
  75.203 +    ///This function gives back the total weight of the found flow.
  75.204 +    ///Assumes that \c run() has been run and nothing changed since then.
  75.205 +    Length totalLength(){
  75.206 +      return total_length;
  75.207 +    }
  75.208 +
  75.209 +    ///Returns a const reference to the EdgeMap \c flow. 
  75.210 +
  75.211 +    ///Returns a const reference to the EdgeMap \c flow. 
  75.212 +    ///\pre \ref run() must
  75.213 +    ///be called before using this function.
  75.214 +    const EdgeIntMap &getFlow() const { return flow;}
  75.215 +
  75.216 +    ///Returns a const reference to the NodeMap \c potential (the dual solution).
  75.217 +
  75.218 +    ///Returns a const reference to the NodeMap \c potential (the dual solution).
  75.219 +    /// \pre \ref run() must be called before using this function.
  75.220 +    const PotentialMap &getPotential() const { return potential;}
  75.221 +
  75.222 +    /// Checking the complementary slackness optimality criteria
  75.223 +
  75.224 +    ///This function checks, whether the given solution is optimal
  75.225 +    ///If executed after the call of \c run() then it should return with true.
  75.226 +    ///This function only checks optimality, doesn't bother with feasibility.
  75.227 +    ///It is meant for testing purposes.
  75.228 +    ///
  75.229 +    bool checkComplementarySlackness(){
  75.230 +      Length mod_pot;
  75.231 +      Length fl_e;
  75.232 +        for(typename Graph::EdgeIt e(G); e!=INVALID; ++e) {
  75.233 +	//C^{\Pi}_{i,j}
  75.234 +	mod_pot = length[e]-potential[G.head(e)]+potential[G.tail(e)];
  75.235 +	fl_e = flow[e];
  75.236 +	if (0<fl_e && fl_e<capacity[e]) {
  75.237 +	  /// \todo better comparison is needed for real types, moreover, 
  75.238 +	  /// this comparison here is superfluous.
  75.239 +	  if (mod_pot != 0)
  75.240 +	    return false;
  75.241 +	} 
  75.242 +	else {
  75.243 +	  if (mod_pot > 0 && fl_e != 0)
  75.244 +	    return false;
  75.245 +	  if (mod_pot < 0 && fl_e != capacity[e])
  75.246 +	    return false;
  75.247 +	}
  75.248 +      }
  75.249 +      return true;
  75.250 +    }
  75.251 +    
  75.252 +
  75.253 +  }; //class MinCostFlow
  75.254 +
  75.255 +  ///@}
  75.256 +
  75.257 +} //namespace lemon
  75.258 +
  75.259 +#endif //LEMON_MIN_COST_FLOW_H
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/src/lemon/path.h	Wed Sep 29 15:30:04 2004 +0000
    76.3 @@ -0,0 +1,709 @@
    76.4 +/* -*- C++ -*-
    76.5 + * src/lemon/path.h - Part of LEMON, a generic C++ optimization library
    76.6 + *
    76.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    76.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    76.9 + *
   76.10 + * Permission to use, modify and distribute this software is granted
   76.11 + * provided that this copyright notice appears in all copies. For
   76.12 + * precise terms see the accompanying LICENSE file.
   76.13 + *
   76.14 + * This software is provided "AS IS" with no warranty of any kind,
   76.15 + * express or implied, and with no claim as to its suitability for any
   76.16 + * purpose.
   76.17 + *
   76.18 + */
   76.19 +
   76.20 +/**
   76.21 +@defgroup paths Path Structures
   76.22 +@ingroup datas
   76.23 +\brief Path structures implemented in LEMON.
   76.24 +
   76.25 +LEMON provides flexible data structures
   76.26 +to work with paths.
   76.27 +
   76.28 +All of them have the same interface, especially they can be built or extended
   76.29 +using a standard Builder subclass. This make is easy to have e.g. the Dijkstra
   76.30 +algorithm to store its result in any kind of path structure.
   76.31 +
   76.32 +\sa lemon::skeleton::Path
   76.33 +
   76.34 +*/
   76.35 +
   76.36 +///\ingroup paths
   76.37 +///\file
   76.38 +///\brief Classes for representing paths in graphs.
   76.39 +
   76.40 +#ifndef LEMON_PATH_H
   76.41 +#define LEMON_PATH_H
   76.42 +
   76.43 +#include <deque>
   76.44 +#include <vector>
   76.45 +#include <algorithm>
   76.46 +
   76.47 +#include <lemon/invalid.h>
   76.48 +
   76.49 +namespace lemon {
   76.50 +
   76.51 +  /// \addtogroup paths
   76.52 +  /// @{
   76.53 +
   76.54 +
   76.55 +  //! \brief A structure for representing directed paths in a graph.
   76.56 +  //!
   76.57 +  //! A structure for representing directed path in a graph.
   76.58 +  //! \param Graph The graph type in which the path is.
   76.59 +  //! \param DM DebugMode, defaults to DefaultDebugMode.
   76.60 +  //!
   76.61 +  //! In a sense, the path can be treated as a graph, for is has \c NodeIt
   76.62 +  //! and \c EdgeIt with the same usage. These types converts to the \c Node
   76.63 +  //! and \c Edge of the original graph.
   76.64 +  //!
   76.65 +  //! \todo Thoroughfully check all the range and consistency tests.
   76.66 +  template<typename Graph>
   76.67 +  class DirPath {
   76.68 +  public:
   76.69 +    /// Edge type of the underlying graph.
   76.70 +    typedef typename Graph::Edge GraphEdge;
   76.71 +    /// Node type of the underlying graph.
   76.72 +    typedef typename Graph::Node GraphNode;
   76.73 +    class NodeIt;
   76.74 +    class EdgeIt;
   76.75 +
   76.76 +  protected:
   76.77 +    const Graph *gr;
   76.78 +    typedef std::vector<GraphEdge> Container;
   76.79 +    Container edges;
   76.80 +
   76.81 +  public:
   76.82 +
   76.83 +    /// \param _G The graph in which the path is.
   76.84 +    ///
   76.85 +    DirPath(const Graph &_G) : gr(&_G) {}
   76.86 +
   76.87 +    /// \brief Subpath constructor.
   76.88 +    ///
   76.89 +    /// Subpath defined by two nodes.
   76.90 +    /// \warning It is an error if the two edges are not in order!
   76.91 +    DirPath(const DirPath &P, const NodeIt &a, const NodeIt &b) {
   76.92 +      gr = P.gr;
   76.93 +      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
   76.94 +    }
   76.95 +
   76.96 +    /// \brief Subpath constructor.
   76.97 +    ///
   76.98 +    /// Subpath defined by two edges. Contains edges in [a,b)
   76.99 +    /// \warning It is an error if the two edges are not in order!
  76.100 +    DirPath(const DirPath &P, const EdgeIt &a, const EdgeIt &b) {
  76.101 +      gr = P.gr;
  76.102 +      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  76.103 +    }
  76.104 +
  76.105 +    /// Length of the path.
  76.106 +    size_t length() const { return edges.size(); }
  76.107 +    /// Returns whether the path is empty.
  76.108 +    bool empty() const { return edges.empty(); }
  76.109 +
  76.110 +    /// Resets the path to an empty path.
  76.111 +    void clear() { edges.clear(); }
  76.112 +
  76.113 +    /// \brief Starting point of the path.
  76.114 +    ///
  76.115 +    /// Starting point of the path.
  76.116 +    /// Returns INVALID if the path is empty.
  76.117 +    GraphNode tail() const {
  76.118 +      return empty() ? INVALID : gr->tail(edges[0]);
  76.119 +    }
  76.120 +    /// \brief End point of the path.
  76.121 +    ///
  76.122 +    /// End point of the path.
  76.123 +    /// Returns INVALID if the path is empty.
  76.124 +    GraphNode head() const {
  76.125 +      return empty() ? INVALID : gr->head(edges[length()-1]);
  76.126 +    }
  76.127 +
  76.128 +    /// \brief Initializes node or edge iterator to point to the first
  76.129 +    /// node or edge.
  76.130 +    ///
  76.131 +    /// \sa nth
  76.132 +    template<typename It>
  76.133 +    It& first(It &i) const { return i=It(*this); }
  76.134 +
  76.135 +    /// \brief Initializes node iterator to point to the node of a given index.
  76.136 +    NodeIt& nth(NodeIt &i, int n) const {
  76.137 +      return i=NodeIt(*this, n);
  76.138 +    }
  76.139 +
  76.140 +    /// \brief Initializes edge iterator to point to the edge of a given index.
  76.141 +    EdgeIt& nth(EdgeIt &i, int n) const {
  76.142 +      return i=EdgeIt(*this, n);
  76.143 +    }
  76.144 +
  76.145 +    /// \brief Returns node iterator pointing to the head node of the
  76.146 +    /// given edge iterator.
  76.147 +    NodeIt head(const EdgeIt& e) const {
  76.148 +      return NodeIt(*this, e.idx+1);
  76.149 +    }
  76.150 +
  76.151 +    /// \brief Returns node iterator pointing to the tail node of the
  76.152 +    /// given edge iterator.
  76.153 +    NodeIt tail(const EdgeIt& e) const {
  76.154 +      return NodeIt(*this, e.idx);
  76.155 +    }
  76.156 +
  76.157 +
  76.158 +    /* Iterator classes */
  76.159 +
  76.160 +    /**
  76.161 +     * \brief Iterator class to iterate on the edges of the paths
  76.162 +     *
  76.163 +     * \ingroup paths
  76.164 +     * This class is used to iterate on the edges of the paths
  76.165 +     *
  76.166 +     * Of course it converts to Graph::Edge
  76.167 +     *
  76.168 +     */
  76.169 +    class EdgeIt {
  76.170 +      friend class DirPath;
  76.171 +
  76.172 +      int idx;
  76.173 +      const DirPath *p;
  76.174 +    public:
  76.175 +      /// Default constructor
  76.176 +      EdgeIt() {}
  76.177 +      /// Invalid constructor
  76.178 +      EdgeIt(Invalid) : idx(-1), p(0) {}
  76.179 +      /// Constructor with starting point
  76.180 +      EdgeIt(const DirPath &_p, int _idx = 0) :
  76.181 +	idx(_idx), p(&_p) { validate(); }
  76.182 +
  76.183 +      ///Validity check
  76.184 +      bool valid() const { return idx!=-1; }
  76.185 +
  76.186 +      ///Conversion to Graph::Edge
  76.187 +      operator GraphEdge () const {
  76.188 +	return valid() ? p->edges[idx] : INVALID;
  76.189 +      }
  76.190 +
  76.191 +      /// Next edge
  76.192 +      EdgeIt& operator++() { ++idx; validate(); return *this; }
  76.193 +
  76.194 +      /// Comparison operator
  76.195 +      bool operator==(const EdgeIt& e) const { return idx==e.idx; }
  76.196 +      /// Comparison operator
  76.197 +      bool operator!=(const EdgeIt& e) const { return idx!=e.idx; }
  76.198 +      /// Comparison operator
  76.199 +      bool operator<(const EdgeIt& e) const { return idx<e.idx; }
  76.200 +
  76.201 +    private:
  76.202 +      // FIXME: comparison between signed and unsigned...
  76.203 +      // Jo ez igy? Vagy esetleg legyen a length() int?
  76.204 +      void validate() { if( size_t(idx) >= p->length() ) idx=-1; }
  76.205 +    };
  76.206 +
  76.207 +    /**
  76.208 +     * \brief Iterator class to iterate on the nodes of the paths
  76.209 +     *
  76.210 +     * \ingroup paths
  76.211 +     * This class is used to iterate on the nodes of the paths
  76.212 +     *
  76.213 +     * Of course it converts to Graph::Node
  76.214 +     *
  76.215 +     */
  76.216 +    class NodeIt {
  76.217 +      friend class DirPath;
  76.218 +
  76.219 +      int idx;
  76.220 +      const DirPath *p;
  76.221 +    public:
  76.222 +      /// Default constructor
  76.223 +      NodeIt() {}
  76.224 +      /// Invalid constructor
  76.225 +      NodeIt(Invalid) : idx(-1), p(0) {}
  76.226 +      /// Constructor with starting point
  76.227 +      NodeIt(const DirPath &_p, int _idx = 0) :
  76.228 +	idx(_idx), p(&_p) { validate(); }
  76.229 +
  76.230 +      ///Validity check
  76.231 +      bool valid() const { return idx!=-1; }
  76.232 +
  76.233 +      ///Conversion to Graph::Node
  76.234 +      operator const GraphNode& () const {
  76.235 +	if(idx >= p->length())
  76.236 +	  return p->head();
  76.237 +	else if(idx >= 0)
  76.238 +	  return p->gr->tail(p->edges[idx]);
  76.239 +	else
  76.240 +	  return INVALID;
  76.241 +      }
  76.242 +      /// Next node
  76.243 +      NodeIt& operator++() { ++idx; validate(); return *this; }
  76.244 +
  76.245 +      /// Comparison operator
  76.246 +      bool operator==(const NodeIt& e) const { return idx==e.idx; }
  76.247 +      /// Comparison operator
  76.248 +      bool operator!=(const NodeIt& e) const { return idx!=e.idx; }
  76.249 +      /// Comparison operator
  76.250 +      bool operator<(const NodeIt& e) const { return idx<e.idx; }
  76.251 +
  76.252 +    private:
  76.253 +      void validate() { if( size_t(idx) > p->length() ) idx=-1; }
  76.254 +    };
  76.255 +
  76.256 +    friend class Builder;
  76.257 +
  76.258 +    /**
  76.259 +     * \brief Class to build paths
  76.260 +     *
  76.261 +     * \ingroup paths
  76.262 +     * This class is used to fill a path with edges.
  76.263 +     *
  76.264 +     * You can push new edges to the front and to the back of the path in
  76.265 +     * arbitrary order then you should commit these changes to the graph.
  76.266 +     *
  76.267 +     * Fundamentally, for most "Paths" (classes fulfilling the
  76.268 +     * PathConcept) while the builder is active (after the first modifying
  76.269 +     * operation and until the commit()) the original Path is in a
  76.270 +     * "transitional" state (operations on it have undefined result). But
  76.271 +     * in the case of DirPath the original path remains unchanged until the
  76.272 +     * commit. However we don't recomend that you use this feature.
  76.273 +     */
  76.274 +    class Builder {
  76.275 +      DirPath &P;
  76.276 +      Container front, back;
  76.277 +
  76.278 +    public:
  76.279 +      ///\param _P the path you want to fill in.
  76.280 +      ///
  76.281 +      Builder(DirPath &_P) : P(_P) {}
  76.282 +
  76.283 +      /// Sets the starting node of the path.
  76.284 +
  76.285 +      /// Sets the starting node of the path. Edge added to the path
  76.286 +      /// afterwards have to be incident to this node.
  76.287 +      /// It should be called if and only if
  76.288 +      /// the path is empty and before any call to
  76.289 +      /// \ref pushFront() or \ref pushBack()
  76.290 +      void setStartNode(const GraphNode &) {}
  76.291 +
  76.292 +      ///Push a new edge to the front of the path
  76.293 +
  76.294 +      ///Push a new edge to the front of the path.
  76.295 +      ///\sa setStartNode
  76.296 +      void pushFront(const GraphEdge& e) {
  76.297 +	front.push_back(e);
  76.298 +      }
  76.299 +
  76.300 +      ///Push a new edge to the back of the path
  76.301 +
  76.302 +      ///Push a new edge to the back of the path.
  76.303 +      ///\sa setStartNode
  76.304 +      void pushBack(const GraphEdge& e) {
  76.305 +	back.push_back(e);
  76.306 +      }
  76.307 +
  76.308 +      ///Commit the changes to the path.
  76.309 +      void commit() {
  76.310 +	if( !front.empty() || !back.empty() ) {
  76.311 +	  Container tmp;
  76.312 +	  tmp.reserve(front.size()+back.size()+P.length());
  76.313 +	  tmp.insert(tmp.end(), front.rbegin(), front.rend());
  76.314 +	  tmp.insert(tmp.end(), P.edges.begin(), P.edges.end());
  76.315 +	  tmp.insert(tmp.end(), back.begin(), back.end());
  76.316 +	  P.edges.swap(tmp);
  76.317 +	  front.clear();
  76.318 +	  back.clear();
  76.319 +	}
  76.320 +      }
  76.321 +
  76.322 +      ///Reserve storage for the builder in advance.
  76.323 +
  76.324 +      ///If you know a reasonable upper bound of the number of the edges
  76.325 +      ///to add to the front, using this function you can speed up the building.
  76.326 +
  76.327 +      void reserveFront(size_t r) {front.reserve(r);}
  76.328 +
  76.329 +      ///Reserve storage for the builder in advance.
  76.330 +
  76.331 +      ///If you know a reasonable upper bound of the number of the edges
  76.332 +      ///to add to the back, using this function you can speed up the building.
  76.333 +
  76.334 +      void reserveBack(size_t r) {back.reserve(r);}
  76.335 +
  76.336 +    private:
  76.337 +      bool empty() {
  76.338 +	return front.empty() && back.empty() && P.empty();
  76.339 +      }
  76.340 +
  76.341 +      GraphNode tail() const {
  76.342 +	if( ! front.empty() )
  76.343 +	  return P.gr->tail(front[front.size()-1]);
  76.344 +	else if( ! P.empty() )
  76.345 +	  return P.gr->tail(P.edges[0]);
  76.346 +	else if( ! back.empty() )
  76.347 +	  return P.gr->tail(back[0]);
  76.348 +	else
  76.349 +	  return INVALID;
  76.350 +      }
  76.351 +      GraphNode head() const {
  76.352 +	if( ! back.empty() )
  76.353 +	  return P.gr->head(back[back.size()-1]);
  76.354 +	else if( ! P.empty() )
  76.355 +	  return P.gr->head(P.edges[P.length()-1]);
  76.356 +	else if( ! front.empty() )
  76.357 +	  return P.gr->head(front[0]);
  76.358 +	else
  76.359 +	  return INVALID;
  76.360 +      }
  76.361 +
  76.362 +    };
  76.363 +
  76.364 +  };
  76.365 +
  76.366 +
  76.367 +
  76.368 +
  76.369 +
  76.370 +
  76.371 +
  76.372 +
  76.373 +
  76.374 +
  76.375 +  /**********************************************************************/
  76.376 +
  76.377 +
  76.378 +  //! \brief A structure for representing undirected path in a graph.
  76.379 +  //!
  76.380 +  //! A structure for representing undirected path in a graph. Ie. this is
  76.381 +  //! a path in a \e directed graph but the edges should not be directed
  76.382 +  //! forward.
  76.383 +  //!
  76.384 +  //! \param Graph The graph type in which the path is.
  76.385 +  //! \param DM DebugMode, defaults to DefaultDebugMode.
  76.386 +  //!
  76.387 +  //! In a sense, the path can be treated as a graph, for is has \c NodeIt
  76.388 +  //! and \c EdgeIt with the same usage. These types converts to the \c Node
  76.389 +  //! and \c Edge of the original graph.
  76.390 +  //!
  76.391 +  //! \todo Thoroughfully check all the range and consistency tests.
  76.392 +  template<typename Graph>
  76.393 +  class UndirPath {
  76.394 +  public:
  76.395 +    /// Edge type of the underlying graph.
  76.396 +    typedef typename Graph::Edge GraphEdge;
  76.397 +     /// Node type of the underlying graph.
  76.398 +   typedef typename Graph::Node GraphNode;
  76.399 +    class NodeIt;
  76.400 +    class EdgeIt;
  76.401 +
  76.402 +  protected:
  76.403 +    const Graph *gr;
  76.404 +    typedef std::vector<GraphEdge> Container;
  76.405 +    Container edges;
  76.406 +
  76.407 +  public:
  76.408 +
  76.409 +    /// \param _G The graph in which the path is.
  76.410 +    ///
  76.411 +    UndirPath(const Graph &_G) : gr(&_G) {}
  76.412 +
  76.413 +    /// \brief Subpath constructor.
  76.414 +    ///
  76.415 +    /// Subpath defined by two nodes.
  76.416 +    /// \warning It is an error if the two edges are not in order!
  76.417 +    UndirPath(const UndirPath &P, const NodeIt &a, const NodeIt &b) {
  76.418 +      gr = P.gr;
  76.419 +      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  76.420 +    }
  76.421 +
  76.422 +    /// \brief Subpath constructor.
  76.423 +    ///
  76.424 +    /// Subpath defined by two edges. Contains edges in [a,b)
  76.425 +    /// \warning It is an error if the two edges are not in order!
  76.426 +    UndirPath(const UndirPath &P, const EdgeIt &a, const EdgeIt &b) {
  76.427 +      gr = P.gr;
  76.428 +      edges.insert(edges.end(), P.edges.begin()+a.idx, P.edges.begin()+b.idx);
  76.429 +    }
  76.430 +
  76.431 +    /// Length of the path.
  76.432 +    size_t length() const { return edges.size(); }
  76.433 +    /// Returns whether the path is empty.
  76.434 +    bool empty() const { return edges.empty(); }
  76.435 +
  76.436 +    /// Resets the path to an empty path.
  76.437 +    void clear() { edges.clear(); }
  76.438 +
  76.439 +    /// \brief Starting point of the path.
  76.440 +    ///
  76.441 +    /// Starting point of the path.
  76.442 +    /// Returns INVALID if the path is empty.
  76.443 +    GraphNode tail() const {
  76.444 +      return empty() ? INVALID : gr->tail(edges[0]);
  76.445 +    }
  76.446 +    /// \brief End point of the path.
  76.447 +    ///
  76.448 +    /// End point of the path.
  76.449 +    /// Returns INVALID if the path is empty.
  76.450 +    GraphNode head() const {
  76.451 +      return empty() ? INVALID : gr->head(edges[length()-1]);
  76.452 +    }
  76.453 +
  76.454 +    /// \brief Initializes node or edge iterator to point to the first
  76.455 +    /// node or edge.
  76.456 +    ///
  76.457 +    /// \sa nth
  76.458 +    template<typename It>
  76.459 +    It& first(It &i) const { return i=It(*this); }
  76.460 +
  76.461 +    /// \brief Initializes node iterator to point to the node of a given index.
  76.462 +    NodeIt& nth(NodeIt &i, int n) const {
  76.463 +      return i=NodeIt(*this, n);
  76.464 +    }
  76.465 +
  76.466 +    /// \brief Initializes edge iterator to point to the edge of a given index.
  76.467 +    EdgeIt& nth(EdgeIt &i, int n) const {
  76.468 +      return i=EdgeIt(*this, n);
  76.469 +    }
  76.470 +
  76.471 +    /// Checks validity of a node or edge iterator.
  76.472 +    template<typename It>
  76.473 +    static
  76.474 +    bool valid(const It &i) { return i.valid(); }
  76.475 +
  76.476 +    /// Steps the given node or edge iterator.
  76.477 +    template<typename It>
  76.478 +    static
  76.479 +    It& next(It &e) {
  76.480 +      return ++e;
  76.481 +    }
  76.482 +
  76.483 +    /// \brief Returns node iterator pointing to the head node of the
  76.484 +    /// given edge iterator.
  76.485 +    NodeIt head(const EdgeIt& e) const {
  76.486 +      return NodeIt(*this, e.idx+1);
  76.487 +    }
  76.488 +
  76.489 +    /// \brief Returns node iterator pointing to the tail node of the
  76.490 +    /// given edge iterator.
  76.491 +    NodeIt tail(const EdgeIt& e) const {
  76.492 +      return NodeIt(*this, e.idx);
  76.493 +    }
  76.494 +
  76.495 +
  76.496 +
  76.497 +    /**
  76.498 +     * \brief Iterator class to iterate on the edges of the paths
  76.499 +     *
  76.500 +     * \ingroup paths
  76.501 +     * This class is used to iterate on the edges of the paths
  76.502 +     *
  76.503 +     * Of course it converts to Graph::Edge
  76.504 +     *
  76.505 +     * \todo Its interface differs from the standard edge iterator.
  76.506 +     * Yes, it shouldn't.
  76.507 +     */
  76.508 +    class EdgeIt {
  76.509 +      friend class UndirPath;
  76.510 +
  76.511 +      int idx;
  76.512 +      const UndirPath *p;
  76.513 +    public:
  76.514 +      /// Default constructor
  76.515 +      EdgeIt() {}
  76.516 +      /// Invalid constructor
  76.517 +      EdgeIt(Invalid) : idx(-1), p(0) {}
  76.518 +      /// Constructor with starting point
  76.519 +      EdgeIt(const UndirPath &_p, int _idx = 0) :
  76.520 +	idx(_idx), p(&_p) { validate(); }
  76.521 +
  76.522 +      ///Validity check
  76.523 +      bool valid() const { return idx!=-1; }
  76.524 +
  76.525 +      ///Conversion to Graph::Edge
  76.526 +      operator GraphEdge () const {
  76.527 +	return valid() ? p->edges[idx] : INVALID;
  76.528 +      }
  76.529 +      /// Next edge
  76.530 +     EdgeIt& operator++() { ++idx; validate(); return *this; }
  76.531 +
  76.532 +      /// Comparison operator
  76.533 +      bool operator==(const EdgeIt& e) const { return idx==e.idx; }
  76.534 +      /// Comparison operator
  76.535 +      bool operator!=(const EdgeIt& e) const { return idx!=e.idx; }
  76.536 +      /// Comparison operator
  76.537 +      bool operator<(const EdgeIt& e) const { return idx<e.idx; }
  76.538 +
  76.539 +    private:
  76.540 +      // FIXME: comparison between signed and unsigned...
  76.541 +      // Jo ez igy? Vagy esetleg legyen a length() int?
  76.542 +      void validate() { if( size_t(idx) >= p->length() ) idx=-1; }
  76.543 +    };
  76.544 +
  76.545 +    /**
  76.546 +     * \brief Iterator class to iterate on the nodes of the paths
  76.547 +     *
  76.548 +     * \ingroup paths
  76.549 +     * This class is used to iterate on the nodes of the paths
  76.550 +     *
  76.551 +     * Of course it converts to Graph::Node
  76.552 +     *
  76.553 +     * \todo Its interface differs from the standard node iterator.
  76.554 +     * Yes, it shouldn't.
  76.555 +     */
  76.556 +    class NodeIt {
  76.557 +      friend class UndirPath;
  76.558 +
  76.559 +      int idx;
  76.560 +      const UndirPath *p;
  76.561 +    public:
  76.562 +      /// Default constructor
  76.563 +      NodeIt() {}
  76.564 +      /// Invalid constructor
  76.565 +      NodeIt(Invalid) : idx(-1), p(0) {}
  76.566 +      /// Constructor with starting point
  76.567 +      NodeIt(const UndirPath &_p, int _idx = 0) :
  76.568 +	idx(_idx), p(&_p) { validate(); }
  76.569 +
  76.570 +      ///Validity check
  76.571 +      bool valid() const { return idx!=-1; }
  76.572 +
  76.573 +      ///Conversion to Graph::Node
  76.574 +      operator const GraphNode& () const {
  76.575 +	if(idx >= p->length())
  76.576 +	  return p->head();
  76.577 +	else if(idx >= 0)
  76.578 +	  return p->gr->tail(p->edges[idx]);
  76.579 +	else
  76.580 +	  return INVALID;
  76.581 +      }
  76.582 +      /// Next node
  76.583 +      NodeIt& operator++() { ++idx; validate(); return *this; }
  76.584 +
  76.585 +      /// Comparison operator
  76.586 +      bool operator==(const NodeIt& e) const { return idx==e.idx; }
  76.587 +      /// Comparison operator
  76.588 +      bool operator!=(const NodeIt& e) const { return idx!=e.idx; }
  76.589 +       /// Comparison operator
  76.590 +     bool operator<(const NodeIt& e) const { return idx<e.idx; }
  76.591 +
  76.592 +    private:
  76.593 +      void validate() { if( size_t(idx) > p->length() ) idx=-1; }
  76.594 +    };
  76.595 +
  76.596 +    friend class Builder;
  76.597 +
  76.598 +    /**
  76.599 +     * \brief Class to build paths
  76.600 +     *
  76.601 +     * \ingroup paths
  76.602 +     * This class is used to fill a path with edges.
  76.603 +     *
  76.604 +     * You can push new edges to the front and to the back of the path in
  76.605 +     * arbitrary order then you should commit these changes to the graph.
  76.606 +     *
  76.607 +     * Fundamentally, for most "Paths" (classes fulfilling the
  76.608 +     * PathConcept) while the builder is active (after the first modifying
  76.609 +     * operation and until the commit()) the original Path is in a
  76.610 +     * "transitional" state (operations ot it have undefined result). But
  76.611 +     * in the case of UndirPath the original path is unchanged until the
  76.612 +     * commit. However we don't recomend that you use this feature.
  76.613 +     */
  76.614 +    class Builder {
  76.615 +      UndirPath &P;
  76.616 +      Container front, back;
  76.617 +
  76.618 +    public:
  76.619 +      ///\param _P the path you want to fill in.
  76.620 +      ///
  76.621 +      Builder(UndirPath &_P) : P(_P) {}
  76.622 +
  76.623 +      /// Sets the starting node of the path.
  76.624 +
  76.625 +      /// Sets the starting node of the path. Edge added to the path
  76.626 +      /// afterwards have to be incident to this node.
  76.627 +      /// It should be called if and only if
  76.628 +      /// the path is empty and before any call to
  76.629 +      /// \ref pushFront() or \ref pushBack()
  76.630 +      void setStartNode(const GraphNode &) {}
  76.631 +
  76.632 +      ///Push a new edge to the front of the path
  76.633 +
  76.634 +      ///Push a new edge to the front of the path.
  76.635 +      ///\sa setStartNode
  76.636 +      void pushFront(const GraphEdge& e) {
  76.637 +	front.push_back(e);
  76.638 +      }
  76.639 +
  76.640 +      ///Push a new edge to the back of the path
  76.641 +
  76.642 +      ///Push a new edge to the back of the path.
  76.643 +      ///\sa setStartNode
  76.644 +      void pushBack(const GraphEdge& e) {
  76.645 +	back.push_back(e);
  76.646 +      }
  76.647 +
  76.648 +      ///Commit the changes to the path.
  76.649 +      void commit() {
  76.650 +	if( !(front.empty() && back.empty()) ) {
  76.651 +	  Container tmp;
  76.652 +	  tmp.reserve(front.size()+back.size()+P.length());
  76.653 +	  tmp.insert(tmp.end(), front.rbegin(), front.rend());
  76.654 +	  tmp.insert(tmp.end(), P.edges.begin(), P.edges.end());
  76.655 +	  tmp.insert(tmp.end(), back.begin(), back.end());
  76.656 +	  P.edges.swap(tmp);
  76.657 +	  front.clear();
  76.658 +	  back.clear();
  76.659 +	}
  76.660 +      }
  76.661 +
  76.662 +
  76.663 +      ///Reserve storage for the builder in advance.
  76.664 +
  76.665 +      ///If you know a reasonable upper bound of the number of the edges
  76.666 +      ///to add to the front, using this function you can speed up the building.
  76.667 +
  76.668 +      void reserveFront(size_t r) {front.reserve(r);}
  76.669 +
  76.670 +      ///Reserve storage for the builder in advance.
  76.671 +
  76.672 +      ///If you know a reasonable upper bound of the number of the edges
  76.673 +      ///to add to the back, using this function you can speed up the building.
  76.674 +
  76.675 +      void reserveBack(size_t r) {back.reserve(r);}
  76.676 +
  76.677 +    private:
  76.678 +      bool empty() {
  76.679 +	return front.empty() && back.empty() && P.empty();
  76.680 +      }
  76.681 +
  76.682 +      GraphNode tail() const {
  76.683 +	if( ! front.empty() )
  76.684 +	  return P.gr->tail(front[front.size()-1]);
  76.685 +	else if( ! P.empty() )
  76.686 +	  return P.gr->tail(P.edges[0]);
  76.687 +	else if( ! back.empty() )
  76.688 +	  return P.gr->tail(back[0]);
  76.689 +	else
  76.690 +	  return INVALID;
  76.691 +      }
  76.692 +      GraphNode head() const {
  76.693 +	if( ! back.empty() )
  76.694 +	  return P.gr->head(back[back.size()-1]);
  76.695 +	else if( ! P.empty() )
  76.696 +	  return P.gr->head(P.edges[P.length()-1]);
  76.697 +	else if( ! front.empty() )
  76.698 +	  return P.gr->head(front[0]);
  76.699 +	else
  76.700 +	  return INVALID;
  76.701 +      }
  76.702 +
  76.703 +    };
  76.704 +
  76.705 +  };
  76.706 +
  76.707 +
  76.708 +  ///@}
  76.709 +
  76.710 +} // namespace lemon
  76.711 +
  76.712 +#endif // LEMON_PATH_H
    77.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    77.2 +++ b/src/lemon/preflow.h	Wed Sep 29 15:30:04 2004 +0000
    77.3 @@ -0,0 +1,819 @@
    77.4 +/* -*- C++ -*-
    77.5 + * src/lemon/preflow.h - Part of LEMON, a generic C++ optimization library
    77.6 + *
    77.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    77.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    77.9 + *
   77.10 + * Permission to use, modify and distribute this software is granted
   77.11 + * provided that this copyright notice appears in all copies. For
   77.12 + * precise terms see the accompanying LICENSE file.
   77.13 + *
   77.14 + * This software is provided "AS IS" with no warranty of any kind,
   77.15 + * express or implied, and with no claim as to its suitability for any
   77.16 + * purpose.
   77.17 + *
   77.18 + */
   77.19 +
   77.20 +#ifndef LEMON_PREFLOW_H
   77.21 +#define LEMON_PREFLOW_H
   77.22 +
   77.23 +#include <vector>
   77.24 +#include <queue>
   77.25 +
   77.26 +#include <lemon/invalid.h>
   77.27 +#include <lemon/maps.h>
   77.28 +
   77.29 +/// \file
   77.30 +/// \ingroup flowalgs
   77.31 +/// Implementation of the preflow algorithm.
   77.32 +
   77.33 +namespace lemon {
   77.34 +
   77.35 +  /// \addtogroup flowalgs
   77.36 +  /// @{                                                   
   77.37 +
   77.38 +  ///%Preflow algorithms class.
   77.39 +
   77.40 +  ///This class provides an implementation of the \e preflow \e
   77.41 +  ///algorithm producing a flow of maximum value in a directed
   77.42 +  ///graph. The preflow algorithms are the fastest max flow algorithms
   77.43 +  ///up to now. The \e source node, the \e target node, the \e
   77.44 +  ///capacity of the edges and the \e starting \e flow value of the
   77.45 +  ///edges should be passed to the algorithm through the
   77.46 +  ///constructor. It is possible to change these quantities using the
   77.47 +  ///functions \ref setSource, \ref setTarget, \ref setCap and \ref
   77.48 +  ///setFlow.
   77.49 +  ///
   77.50 +  ///After running \ref lemon::Preflow::phase1() "phase1()"
   77.51 +  ///or \ref lemon::Preflow::run() "run()", the maximal flow
   77.52 +  ///value can be obtained by calling \ref flowValue(). The minimum
   77.53 +  ///value cut can be written into a <tt>bool</tt> node map by
   77.54 +  ///calling \ref minCut(). (\ref minMinCut() and \ref maxMinCut() writes
   77.55 +  ///the inclusionwise minimum and maximum of the minimum value cuts,
   77.56 +  ///resp.)
   77.57 +  ///
   77.58 +  ///\param Graph The directed graph type the algorithm runs on.
   77.59 +  ///\param Num The number type of the capacities and the flow values.
   77.60 +  ///\param CapMap The capacity map type.
   77.61 +  ///\param FlowMap The flow map type.
   77.62 +  ///
   77.63 +  ///\author Jacint Szabo 
   77.64 +  template <typename Graph, typename Num,
   77.65 +	    typename CapMap=typename Graph::template EdgeMap<Num>,
   77.66 +            typename FlowMap=typename Graph::template EdgeMap<Num> >
   77.67 +  class Preflow {
   77.68 +  protected:
   77.69 +    typedef typename Graph::Node Node;
   77.70 +    typedef typename Graph::NodeIt NodeIt;
   77.71 +    typedef typename Graph::EdgeIt EdgeIt;
   77.72 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   77.73 +    typedef typename Graph::InEdgeIt InEdgeIt;
   77.74 +
   77.75 +    typedef typename Graph::template NodeMap<Node> NNMap;
   77.76 +    typedef typename std::vector<Node> VecNode;
   77.77 +
   77.78 +    const Graph* g;
   77.79 +    Node s;
   77.80 +    Node t;
   77.81 +    const CapMap* capacity;
   77.82 +    FlowMap* flow;
   77.83 +    int n;      //the number of nodes of G
   77.84 +    
   77.85 +    typename Graph::template NodeMap<int> level;  
   77.86 +    typename Graph::template NodeMap<Num> excess;
   77.87 +
   77.88 +    // constants used for heuristics
   77.89 +    static const int H0=20;
   77.90 +    static const int H1=1;
   77.91 +
   77.92 +    public:
   77.93 +
   77.94 +    ///Indicates the property of the starting flow map.
   77.95 +
   77.96 +    ///Indicates the property of the starting flow map. The meanings are as follows:
   77.97 +    ///- \c ZERO_FLOW: constant zero flow
   77.98 +    ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
   77.99 +    ///the sum of the out-flows in every node except the \e source and
  77.100 +    ///the \e target.
  77.101 +    ///- \c PRE_FLOW: any preflow, i.e. the sum of the in-flows is at 
  77.102 +    ///least the sum of the out-flows in every node except the \e source.
  77.103 +    ///- \c NO_FLOW: indicates an unspecified edge map. \c flow will be 
  77.104 +    ///set to the constant zero flow in the beginning of
  77.105 +    ///the algorithm in this case.
  77.106 +    ///
  77.107 +    enum FlowEnum{
  77.108 +      NO_FLOW,
  77.109 +      ZERO_FLOW,
  77.110 +      GEN_FLOW,
  77.111 +      PRE_FLOW
  77.112 +    };
  77.113 +
  77.114 +    ///Indicates the state of the preflow algorithm.
  77.115 +
  77.116 +    ///Indicates the state of the preflow algorithm. The meanings are as follows:
  77.117 +    ///- \c AFTER_NOTHING: before running the algorithm or at an unspecified state.
  77.118 +    ///- \c AFTER_PREFLOW_PHASE_1: right after running \c phase1
  77.119 +    ///- \c AFTER_PREFLOW_PHASE_2: after running \ref phase2()
  77.120 +    ///
  77.121 +    enum StatusEnum {
  77.122 +      AFTER_NOTHING,
  77.123 +      AFTER_PREFLOW_PHASE_1,      
  77.124 +      AFTER_PREFLOW_PHASE_2
  77.125 +    };
  77.126 +    
  77.127 +    protected: 
  77.128 +      FlowEnum flow_prop;
  77.129 +    StatusEnum status; // Do not needle this flag only if necessary.
  77.130 +    
  77.131 +  public: 
  77.132 +    ///The constructor of the class.
  77.133 +
  77.134 +    ///The constructor of the class. 
  77.135 +    ///\param _G The directed graph the algorithm runs on. 
  77.136 +    ///\param _s The source node.
  77.137 +    ///\param _t The target node.
  77.138 +    ///\param _capacity The capacity of the edges. 
  77.139 +    ///\param _flow The flow of the edges. 
  77.140 +    ///Except the graph, all of these parameters can be reset by
  77.141 +    ///calling \ref setSource, \ref setTarget, \ref setCap and \ref
  77.142 +    ///setFlow, resp.
  77.143 +      Preflow(const Graph& _G, Node _s, Node _t, 
  77.144 +	      const CapMap& _capacity, FlowMap& _flow) :
  77.145 +	g(&_G), s(_s), t(_t), capacity(&_capacity),
  77.146 +	flow(&_flow), n(_G.nodeNum()), level(_G), excess(_G,0), 
  77.147 +	flow_prop(NO_FLOW), status(AFTER_NOTHING) { }
  77.148 +
  77.149 +
  77.150 +                                                                              
  77.151 +    ///Runs the preflow algorithm.  
  77.152 +
  77.153 +    ///Runs the preflow algorithm.
  77.154 +    ///
  77.155 +    void run() {
  77.156 +      phase1(flow_prop);
  77.157 +      phase2();
  77.158 +    }
  77.159 +    
  77.160 +    ///Runs the preflow algorithm.  
  77.161 +    
  77.162 +    ///Runs the preflow algorithm. 
  77.163 +    ///\pre The starting flow map must be
  77.164 +    /// - a constant zero flow if \c fp is \c ZERO_FLOW,
  77.165 +    /// - an arbitrary flow if \c fp is \c GEN_FLOW,
  77.166 +    /// - an arbitrary preflow if \c fp is \c PRE_FLOW,
  77.167 +    /// - any map if \c fp is NO_FLOW.
  77.168 +    ///If the starting flow map is a flow or a preflow then 
  77.169 +    ///the algorithm terminates faster.
  77.170 +    void run(FlowEnum fp) {
  77.171 +      flow_prop=fp;
  77.172 +      run();
  77.173 +    }
  77.174 +      
  77.175 +    ///Runs the first phase of the preflow algorithm.
  77.176 +
  77.177 +    ///The preflow algorithm consists of two phases, this method runs
  77.178 +    ///the first phase. After the first phase the maximum flow value
  77.179 +    ///and a minimum value cut can already be computed, though a
  77.180 +    ///maximum flow is not yet obtained. So after calling this method
  77.181 +    ///\ref flowValue returns the value of a maximum flow and \ref
  77.182 +    ///minCut returns a minimum cut.     
  77.183 +    ///\warning \ref minMinCut and \ref maxMinCut do not give minimum
  77.184 +    ///value cuts unless calling \ref phase2.  
  77.185 +    ///\pre The starting flow must be 
  77.186 +    ///- a constant zero flow if \c fp is \c ZERO_FLOW, 
  77.187 +    ///- an arbitary flow if \c fp is \c GEN_FLOW, 
  77.188 +    ///- an arbitary preflow if \c fp is \c PRE_FLOW, 
  77.189 +    ///- any map if \c fp is NO_FLOW.
  77.190 +    void phase1(FlowEnum fp)
  77.191 +    {
  77.192 +      flow_prop=fp;
  77.193 +      phase1();
  77.194 +    }
  77.195 +
  77.196 +    
  77.197 +    ///Runs the first phase of the preflow algorithm.
  77.198 +
  77.199 +    ///The preflow algorithm consists of two phases, this method runs
  77.200 +    ///the first phase. After the first phase the maximum flow value
  77.201 +    ///and a minimum value cut can already be computed, though a
  77.202 +    ///maximum flow is not yet obtained. So after calling this method
  77.203 +    ///\ref flowValue returns the value of a maximum flow and \ref
  77.204 +    ///minCut returns a minimum cut.
  77.205 +    ///\warning \ref minCut(), \ref minMinCut() and \ref maxMinCut() do not
  77.206 +    ///give minimum value cuts unless calling \ref phase2().
  77.207 +    void phase1()
  77.208 +    {
  77.209 +      int heur0=(int)(H0*n);  //time while running 'bound decrease'
  77.210 +      int heur1=(int)(H1*n);  //time while running 'highest label'
  77.211 +      int heur=heur1;         //starting time interval (#of relabels)
  77.212 +      int numrelabel=0;
  77.213 +
  77.214 +      bool what_heur=1;
  77.215 +      //It is 0 in case 'bound decrease' and 1 in case 'highest label'
  77.216 +
  77.217 +      bool end=false;
  77.218 +      //Needed for 'bound decrease', true means no active 
  77.219 +      //nodes are above bound b.
  77.220 +
  77.221 +      int k=n-2;  //bound on the highest level under n containing a node
  77.222 +      int b=k;    //bound on the highest level under n of an active node
  77.223 +
  77.224 +      VecNode first(n, INVALID);
  77.225 +      NNMap next(*g, INVALID);
  77.226 +
  77.227 +      NNMap left(*g, INVALID);
  77.228 +      NNMap right(*g, INVALID);
  77.229 +      VecNode level_list(n,INVALID);
  77.230 +      //List of the nodes in level i<n, set to n.
  77.231 +
  77.232 +      preflowPreproc(first, next, level_list, left, right);
  77.233 +
  77.234 +      //Push/relabel on the highest level active nodes.
  77.235 +      while ( true ) {
  77.236 +	if ( b == 0 ) {
  77.237 +	  if ( !what_heur && !end && k > 0 ) {
  77.238 +	    b=k;
  77.239 +	    end=true;
  77.240 +	  } else break;
  77.241 +	}
  77.242 +
  77.243 +	if ( first[b]==INVALID ) --b;
  77.244 +	else {
  77.245 +	  end=false;
  77.246 +	  Node w=first[b];
  77.247 +	  first[b]=next[w];
  77.248 +	  int newlevel=push(w, next, first);
  77.249 +	  if ( excess[w] > 0 ) relabel(w, newlevel, first, next, level_list, 
  77.250 +				       left, right, b, k, what_heur);
  77.251 +
  77.252 +	  ++numrelabel;
  77.253 +	  if ( numrelabel >= heur ) {
  77.254 +	    numrelabel=0;
  77.255 +	    if ( what_heur ) {
  77.256 +	      what_heur=0;
  77.257 +	      heur=heur0;
  77.258 +	      end=false;
  77.259 +	    } else {
  77.260 +	      what_heur=1;
  77.261 +	      heur=heur1;
  77.262 +	      b=k;
  77.263 +	    }
  77.264 +	  }
  77.265 +	}
  77.266 +      }
  77.267 +      flow_prop=PRE_FLOW;
  77.268 +      status=AFTER_PREFLOW_PHASE_1;
  77.269 +    }
  77.270 +    // Heuristics:
  77.271 +    //   2 phase
  77.272 +    //   gap
  77.273 +    //   list 'level_list' on the nodes on level i implemented by hand
  77.274 +    //   stack 'active' on the active nodes on level i      
  77.275 +    //   runs heuristic 'highest label' for H1*n relabels
  77.276 +    //   runs heuristic 'bound decrease' for H0*n relabels, starts with 'highest label'
  77.277 +    //   Parameters H0 and H1 are initialized to 20 and 1.
  77.278 +
  77.279 +
  77.280 +    ///Runs the second phase of the preflow algorithm.
  77.281 +
  77.282 +    ///The preflow algorithm consists of two phases, this method runs
  77.283 +    ///the second phase. After calling \ref phase1 and then \ref
  77.284 +    ///phase2, \ref flow contains a maximum flow, \ref flowValue
  77.285 +    ///returns the value of a maximum flow, \ref minCut returns a
  77.286 +    ///minimum cut, while the methods \ref minMinCut and \ref
  77.287 +    ///maxMinCut return the inclusionwise minimum and maximum cuts of
  77.288 +    ///minimum value, resp.  \pre \ref phase1 must be called before.
  77.289 +    void phase2()
  77.290 +    {
  77.291 +
  77.292 +      int k=n-2;  //bound on the highest level under n containing a node
  77.293 +      int b=k;    //bound on the highest level under n of an active node
  77.294 +
  77.295 +    
  77.296 +      VecNode first(n, INVALID);
  77.297 +      NNMap next(*g, INVALID); 
  77.298 +      level.set(s,0);
  77.299 +      std::queue<Node> bfs_queue;
  77.300 +      bfs_queue.push(s);
  77.301 +
  77.302 +      while ( !bfs_queue.empty() ) {
  77.303 +
  77.304 +	Node v=bfs_queue.front();
  77.305 +	bfs_queue.pop();
  77.306 +	int l=level[v]+1;
  77.307 +
  77.308 +	for(InEdgeIt e(*g,v); e!=INVALID; ++e) {
  77.309 +	  if ( (*capacity)[e] <= (*flow)[e] ) continue;
  77.310 +	  Node u=g->tail(e);
  77.311 +	  if ( level[u] >= n ) {
  77.312 +	    bfs_queue.push(u);
  77.313 +	    level.set(u, l);
  77.314 +	    if ( excess[u] > 0 ) {
  77.315 +	      next.set(u,first[l]);
  77.316 +	      first[l]=u;
  77.317 +	    }
  77.318 +	  }
  77.319 +	}
  77.320 +
  77.321 +	for(OutEdgeIt e(*g,v); e!=INVALID; ++e) {
  77.322 +	  if ( 0 >= (*flow)[e] ) continue;
  77.323 +	  Node u=g->head(e);
  77.324 +	  if ( level[u] >= n ) {
  77.325 +	    bfs_queue.push(u);
  77.326 +	    level.set(u, l);
  77.327 +	    if ( excess[u] > 0 ) {
  77.328 +	      next.set(u,first[l]);
  77.329 +	      first[l]=u;
  77.330 +	    }
  77.331 +	  }
  77.332 +	}
  77.333 +      }
  77.334 +      b=n-2;
  77.335 +
  77.336 +      while ( true ) {
  77.337 +
  77.338 +	if ( b == 0 ) break;
  77.339 +	if ( first[b]==INVALID ) --b;
  77.340 +	else {
  77.341 +	  Node w=first[b];
  77.342 +	  first[b]=next[w];
  77.343 +	  int newlevel=push(w,next, first);
  77.344 +	  
  77.345 +	  //relabel
  77.346 +	  if ( excess[w] > 0 ) {
  77.347 +	    level.set(w,++newlevel);
  77.348 +	    next.set(w,first[newlevel]);
  77.349 +	    first[newlevel]=w;
  77.350 +	    b=newlevel;
  77.351 +	  }
  77.352 +	} 
  77.353 +      } // while(true)
  77.354 +      flow_prop=GEN_FLOW;
  77.355 +      status=AFTER_PREFLOW_PHASE_2;
  77.356 +    }
  77.357 +
  77.358 +    /// Returns the value of the maximum flow.
  77.359 +
  77.360 +    /// Returns the value of the maximum flow by returning the excess
  77.361 +    /// of the target node \c t. This value equals to the value of
  77.362 +    /// the maximum flow already after running \ref phase1.
  77.363 +    Num flowValue() const {
  77.364 +      return excess[t];
  77.365 +    }
  77.366 +
  77.367 +
  77.368 +    ///Returns a minimum value cut.
  77.369 +
  77.370 +    ///Sets \c M to the characteristic vector of a minimum value
  77.371 +    ///cut. This method can be called both after running \ref
  77.372 +    ///phase1 and \ref phase2. It is much faster after
  77.373 +    ///\ref phase1.  \pre M should be a bool-valued node-map. \pre
  77.374 +    ///If \ref minCut() is called after \ref phase2() then M should
  77.375 +    ///be initialized to false.
  77.376 +    template<typename _CutMap>
  77.377 +    void minCut(_CutMap& M) const {
  77.378 +      switch ( status ) {
  77.379 +	case AFTER_PREFLOW_PHASE_1:
  77.380 +	for(NodeIt v(*g); v!=INVALID; ++v) {
  77.381 +	  if (level[v] < n) {
  77.382 +	    M.set(v, false);
  77.383 +	  } else {
  77.384 +	    M.set(v, true);
  77.385 +	  }
  77.386 +	}
  77.387 +	break;
  77.388 +	case AFTER_PREFLOW_PHASE_2:
  77.389 +	minMinCut(M);
  77.390 +	break;
  77.391 +	case AFTER_NOTHING:
  77.392 +	break;
  77.393 +      }
  77.394 +    }
  77.395 +
  77.396 +    ///Returns the inclusionwise minimum of the minimum value cuts.
  77.397 +
  77.398 +    ///Sets \c M to the characteristic vector of the minimum value cut
  77.399 +    ///which is inclusionwise minimum. It is computed by processing a
  77.400 +    ///bfs from the source node \c s in the residual graph.  \pre M
  77.401 +    ///should be a node map of bools initialized to false.  \pre \ref
  77.402 +    ///phase2 should already be run.
  77.403 +    template<typename _CutMap>
  77.404 +    void minMinCut(_CutMap& M) const {
  77.405 +
  77.406 +      std::queue<Node> queue;
  77.407 +      M.set(s,true);
  77.408 +      queue.push(s);
  77.409 +      
  77.410 +      while (!queue.empty()) {
  77.411 +	Node w=queue.front();
  77.412 +	queue.pop();
  77.413 +	
  77.414 +	for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.415 +	  Node v=g->head(e);
  77.416 +	  if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
  77.417 +	    queue.push(v);
  77.418 +	    M.set(v, true);
  77.419 +	  }
  77.420 +	}
  77.421 +	
  77.422 +	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.423 +	  Node v=g->tail(e);
  77.424 +	  if (!M[v] && (*flow)[e] > 0 ) {
  77.425 +	    queue.push(v);
  77.426 +	    M.set(v, true);
  77.427 +	  }
  77.428 +	}
  77.429 +      }
  77.430 +    }
  77.431 +    
  77.432 +    ///Returns the inclusionwise maximum of the minimum value cuts.
  77.433 +
  77.434 +    ///Sets \c M to the characteristic vector of the minimum value cut
  77.435 +    ///which is inclusionwise maximum. It is computed by processing a
  77.436 +    ///backward bfs from the target node \c t in the residual graph.
  77.437 +    ///\pre \ref phase2() or run() should already be run.
  77.438 +    template<typename _CutMap>
  77.439 +    void maxMinCut(_CutMap& M) const {
  77.440 +
  77.441 +      for(NodeIt v(*g) ; v!=INVALID; ++v) M.set(v, true);
  77.442 +
  77.443 +      std::queue<Node> queue;
  77.444 +
  77.445 +      M.set(t,false);
  77.446 +      queue.push(t);
  77.447 +
  77.448 +      while (!queue.empty()) {
  77.449 +        Node w=queue.front();
  77.450 +	queue.pop();
  77.451 +
  77.452 +	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.453 +	  Node v=g->tail(e);
  77.454 +	  if (M[v] && (*flow)[e] < (*capacity)[e] ) {
  77.455 +	    queue.push(v);
  77.456 +	    M.set(v, false);
  77.457 +	  }
  77.458 +	}
  77.459 +
  77.460 +	for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.461 +	  Node v=g->head(e);
  77.462 +	  if (M[v] && (*flow)[e] > 0 ) {
  77.463 +	    queue.push(v);
  77.464 +	    M.set(v, false);
  77.465 +	  }
  77.466 +	}
  77.467 +      }
  77.468 +    }
  77.469 +
  77.470 +    ///Sets the source node to \c _s.
  77.471 +
  77.472 +    ///Sets the source node to \c _s.
  77.473 +    /// 
  77.474 +    void setSource(Node _s) { 
  77.475 +      s=_s; 
  77.476 +      if ( flow_prop != ZERO_FLOW ) flow_prop=NO_FLOW;
  77.477 +      status=AFTER_NOTHING; 
  77.478 +    }
  77.479 +
  77.480 +    ///Sets the target node to \c _t.
  77.481 +
  77.482 +    ///Sets the target node to \c _t.
  77.483 +    ///
  77.484 +    void setTarget(Node _t) { 
  77.485 +      t=_t; 
  77.486 +      if ( flow_prop == GEN_FLOW ) flow_prop=PRE_FLOW;
  77.487 +      status=AFTER_NOTHING; 
  77.488 +    }
  77.489 +
  77.490 +    /// Sets the edge map of the capacities to _cap.
  77.491 +
  77.492 +    /// Sets the edge map of the capacities to _cap.
  77.493 +    /// 
  77.494 +    void setCap(const CapMap& _cap) { 
  77.495 +      capacity=&_cap; 
  77.496 +      status=AFTER_NOTHING; 
  77.497 +    }
  77.498 +
  77.499 +    /// Sets the edge map of the flows to _flow.
  77.500 +
  77.501 +    /// Sets the edge map of the flows to _flow.
  77.502 +    /// 
  77.503 +    void setFlow(FlowMap& _flow) { 
  77.504 +      flow=&_flow; 
  77.505 +      flow_prop=NO_FLOW;
  77.506 +      status=AFTER_NOTHING; 
  77.507 +    }
  77.508 +
  77.509 +
  77.510 +  private:
  77.511 +
  77.512 +    int push(Node w, NNMap& next, VecNode& first) {
  77.513 +
  77.514 +      int lev=level[w];
  77.515 +      Num exc=excess[w];
  77.516 +      int newlevel=n;       //bound on the next level of w
  77.517 +
  77.518 +      for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.519 +	if ( (*flow)[e] >= (*capacity)[e] ) continue;
  77.520 +	Node v=g->head(e);
  77.521 +
  77.522 +	if( lev > level[v] ) { //Push is allowed now
  77.523 +	  
  77.524 +	  if ( excess[v]<=0 && v!=t && v!=s ) {
  77.525 +	    next.set(v,first[level[v]]);
  77.526 +	    first[level[v]]=v;
  77.527 +	  }
  77.528 +
  77.529 +	  Num cap=(*capacity)[e];
  77.530 +	  Num flo=(*flow)[e];
  77.531 +	  Num remcap=cap-flo;
  77.532 +	  
  77.533 +	  if ( remcap >= exc ) { //A nonsaturating push.
  77.534 +	    
  77.535 +	    flow->set(e, flo+exc);
  77.536 +	    excess.set(v, excess[v]+exc);
  77.537 +	    exc=0;
  77.538 +	    break;
  77.539 +
  77.540 +	  } else { //A saturating push.
  77.541 +	    flow->set(e, cap);
  77.542 +	    excess.set(v, excess[v]+remcap);
  77.543 +	    exc-=remcap;
  77.544 +	  }
  77.545 +	} else if ( newlevel > level[v] ) newlevel = level[v];
  77.546 +      } //for out edges wv
  77.547 +
  77.548 +      if ( exc > 0 ) {
  77.549 +	for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
  77.550 +	  
  77.551 +	  if( (*flow)[e] <= 0 ) continue;
  77.552 +	  Node v=g->tail(e);
  77.553 +
  77.554 +	  if( lev > level[v] ) { //Push is allowed now
  77.555 +
  77.556 +	    if ( excess[v]<=0 && v!=t && v!=s ) {
  77.557 +	      next.set(v,first[level[v]]);
  77.558 +	      first[level[v]]=v;
  77.559 +	    }
  77.560 +
  77.561 +	    Num flo=(*flow)[e];
  77.562 +
  77.563 +	    if ( flo >= exc ) { //A nonsaturating push.
  77.564 +
  77.565 +	      flow->set(e, flo-exc);
  77.566 +	      excess.set(v, excess[v]+exc);
  77.567 +	      exc=0;
  77.568 +	      break;
  77.569 +	    } else {  //A saturating push.
  77.570 +
  77.571 +	      excess.set(v, excess[v]+flo);
  77.572 +	      exc-=flo;
  77.573 +	      flow->set(e,0);
  77.574 +	    }
  77.575 +	  } else if ( newlevel > level[v] ) newlevel = level[v];
  77.576 +	} //for in edges vw
  77.577 +
  77.578 +      } // if w still has excess after the out edge for cycle
  77.579 +
  77.580 +      excess.set(w, exc);
  77.581 +      
  77.582 +      return newlevel;
  77.583 +    }
  77.584 +    
  77.585 +    
  77.586 +    
  77.587 +    void preflowPreproc(VecNode& first, NNMap& next, 
  77.588 +			VecNode& level_list, NNMap& left, NNMap& right)
  77.589 +    {
  77.590 +      for(NodeIt v(*g); v!=INVALID; ++v) level.set(v,n);
  77.591 +      std::queue<Node> bfs_queue;
  77.592 +      
  77.593 +      if ( flow_prop == GEN_FLOW || flow_prop == PRE_FLOW ) {
  77.594 +	//Reverse_bfs from t in the residual graph,
  77.595 +	//to find the starting level.
  77.596 +	level.set(t,0);
  77.597 +	bfs_queue.push(t);
  77.598 +	
  77.599 +	while ( !bfs_queue.empty() ) {
  77.600 +	  
  77.601 +	  Node v=bfs_queue.front();
  77.602 +	  bfs_queue.pop();
  77.603 +	  int l=level[v]+1;
  77.604 +	  
  77.605 +	  for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  77.606 +	    if ( (*capacity)[e] <= (*flow)[e] ) continue;
  77.607 +	    Node w=g->tail(e);
  77.608 +	    if ( level[w] == n && w != s ) {
  77.609 +	      bfs_queue.push(w);
  77.610 +	      Node z=level_list[l];
  77.611 +	      if ( z!=INVALID ) left.set(z,w);
  77.612 +	      right.set(w,z);
  77.613 +	      level_list[l]=w;
  77.614 +	      level.set(w, l);
  77.615 +	    }
  77.616 +	  }
  77.617 +	  
  77.618 +	  for(OutEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  77.619 +	    if ( 0 >= (*flow)[e] ) continue;
  77.620 +	    Node w=g->head(e);
  77.621 +	    if ( level[w] == n && w != s ) {
  77.622 +	      bfs_queue.push(w);
  77.623 +	      Node z=level_list[l];
  77.624 +	      if ( z!=INVALID ) left.set(z,w);
  77.625 +	      right.set(w,z);
  77.626 +	      level_list[l]=w;
  77.627 +	      level.set(w, l);
  77.628 +	    }
  77.629 +	  }
  77.630 +	} //while
  77.631 +      } //if
  77.632 +
  77.633 +
  77.634 +      switch (flow_prop) {
  77.635 +	case NO_FLOW:  
  77.636 +	for(EdgeIt e(*g); e!=INVALID; ++e) flow->set(e,0);
  77.637 +	case ZERO_FLOW:
  77.638 +	for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
  77.639 +	
  77.640 +	//Reverse_bfs from t, to find the starting level.
  77.641 +	level.set(t,0);
  77.642 +	bfs_queue.push(t);
  77.643 +	
  77.644 +	while ( !bfs_queue.empty() ) {
  77.645 +	  
  77.646 +	  Node v=bfs_queue.front();
  77.647 +	  bfs_queue.pop();
  77.648 +	  int l=level[v]+1;
  77.649 +	  
  77.650 +	  for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
  77.651 +	    Node w=g->tail(e);
  77.652 +	    if ( level[w] == n && w != s ) {
  77.653 +	      bfs_queue.push(w);
  77.654 +	      Node z=level_list[l];
  77.655 +	      if ( z!=INVALID ) left.set(z,w);
  77.656 +	      right.set(w,z);
  77.657 +	      level_list[l]=w;
  77.658 +	      level.set(w, l);
  77.659 +	    }
  77.660 +	  }
  77.661 +	}
  77.662 +	
  77.663 +	//the starting flow
  77.664 +	for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  77.665 +	  Num c=(*capacity)[e];
  77.666 +	  if ( c <= 0 ) continue;
  77.667 +	  Node w=g->head(e);
  77.668 +	  if ( level[w] < n ) {
  77.669 +	    if ( excess[w] <= 0 && w!=t ) { //putting into the stack
  77.670 +	      next.set(w,first[level[w]]);
  77.671 +	      first[level[w]]=w;
  77.672 +	    }
  77.673 +	    flow->set(e, c);
  77.674 +	    excess.set(w, excess[w]+c);
  77.675 +	  }
  77.676 +	}
  77.677 +	break;
  77.678 +
  77.679 +	case GEN_FLOW:
  77.680 +	for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
  77.681 +	{
  77.682 +	  Num exc=0;
  77.683 +	  for(InEdgeIt e(*g,t) ; e!=INVALID; ++e) exc+=(*flow)[e];
  77.684 +	  for(OutEdgeIt e(*g,t) ; e!=INVALID; ++e) exc-=(*flow)[e];
  77.685 +	  excess.set(t,exc);
  77.686 +	}
  77.687 +
  77.688 +	//the starting flow
  77.689 +	for(OutEdgeIt e(*g,s); e!=INVALID; ++e)	{
  77.690 +	  Num rem=(*capacity)[e]-(*flow)[e];
  77.691 +	  if ( rem <= 0 ) continue;
  77.692 +	  Node w=g->head(e);
  77.693 +	  if ( level[w] < n ) {
  77.694 +	    if ( excess[w] <= 0 && w!=t ) { //putting into the stack
  77.695 +	      next.set(w,first[level[w]]);
  77.696 +	      first[level[w]]=w;
  77.697 +	    }   
  77.698 +	    flow->set(e, (*capacity)[e]);
  77.699 +	    excess.set(w, excess[w]+rem);
  77.700 +	  }
  77.701 +	}
  77.702 +	
  77.703 +	for(InEdgeIt e(*g,s); e!=INVALID; ++e) {
  77.704 +	  if ( (*flow)[e] <= 0 ) continue;
  77.705 +	  Node w=g->tail(e);
  77.706 +	  if ( level[w] < n ) {
  77.707 +	    if ( excess[w] <= 0 && w!=t ) {
  77.708 +	      next.set(w,first[level[w]]);
  77.709 +	      first[level[w]]=w;
  77.710 +	    }  
  77.711 +	    excess.set(w, excess[w]+(*flow)[e]);
  77.712 +	    flow->set(e, 0);
  77.713 +	  }
  77.714 +	}
  77.715 +	break;
  77.716 +
  77.717 +	case PRE_FLOW:	
  77.718 +	//the starting flow
  77.719 +	for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  77.720 +	  Num rem=(*capacity)[e]-(*flow)[e];
  77.721 +	  if ( rem <= 0 ) continue;
  77.722 +	  Node w=g->head(e);
  77.723 +	  if ( level[w] < n ) flow->set(e, (*capacity)[e]);
  77.724 +	}
  77.725 +	
  77.726 +	for(InEdgeIt e(*g,s) ; e!=INVALID; ++e) {
  77.727 +	  if ( (*flow)[e] <= 0 ) continue;
  77.728 +	  Node w=g->tail(e);
  77.729 +	  if ( level[w] < n ) flow->set(e, 0);
  77.730 +	}
  77.731 +	
  77.732 +	//computing the excess
  77.733 +	for(NodeIt w(*g); w!=INVALID; ++w) {
  77.734 +	  Num exc=0;
  77.735 +	  for(InEdgeIt e(*g,w); e!=INVALID; ++e) exc+=(*flow)[e];
  77.736 +	  for(OutEdgeIt e(*g,w); e!=INVALID; ++e) exc-=(*flow)[e];
  77.737 +	  excess.set(w,exc);
  77.738 +	  
  77.739 +	  //putting the active nodes into the stack
  77.740 +	  int lev=level[w];
  77.741 +	    if ( exc > 0 && lev < n && Node(w) != t ) {
  77.742 +	      next.set(w,first[lev]);
  77.743 +	      first[lev]=w;
  77.744 +	    }
  77.745 +	}
  77.746 +	break;
  77.747 +      } //switch
  77.748 +    } //preflowPreproc
  77.749 +
  77.750 +
  77.751 +    void relabel(Node w, int newlevel, VecNode& first, NNMap& next, 
  77.752 +		 VecNode& level_list, NNMap& left,
  77.753 +		 NNMap& right, int& b, int& k, bool what_heur )
  77.754 +    {
  77.755 +
  77.756 +      int lev=level[w];
  77.757 +
  77.758 +      Node right_n=right[w];
  77.759 +      Node left_n=left[w];
  77.760 +
  77.761 +      //unlacing starts
  77.762 +      if ( right_n!=INVALID ) {
  77.763 +	if ( left_n!=INVALID ) {
  77.764 +	  right.set(left_n, right_n);
  77.765 +	  left.set(right_n, left_n);
  77.766 +	} else {
  77.767 +	  level_list[lev]=right_n;
  77.768 +	  left.set(right_n, INVALID);
  77.769 +	}
  77.770 +      } else {
  77.771 +	if ( left_n!=INVALID ) {
  77.772 +	  right.set(left_n, INVALID);
  77.773 +	} else {
  77.774 +	  level_list[lev]=INVALID;
  77.775 +	}
  77.776 +      }
  77.777 +      //unlacing ends
  77.778 +
  77.779 +      if ( level_list[lev]==INVALID ) {
  77.780 +
  77.781 +	//gapping starts
  77.782 +	for (int i=lev; i!=k ; ) {
  77.783 +	  Node v=level_list[++i];
  77.784 +	  while ( v!=INVALID ) {
  77.785 +	    level.set(v,n);
  77.786 +	    v=right[v];
  77.787 +	  }
  77.788 +	  level_list[i]=INVALID;
  77.789 +	  if ( !what_heur ) first[i]=INVALID;
  77.790 +	}
  77.791 +
  77.792 +	level.set(w,n);
  77.793 +	b=lev-1;
  77.794 +	k=b;
  77.795 +	//gapping ends
  77.796 +
  77.797 +      } else {
  77.798 +
  77.799 +	if ( newlevel == n ) level.set(w,n);
  77.800 +	else {
  77.801 +	  level.set(w,++newlevel);
  77.802 +	  next.set(w,first[newlevel]);
  77.803 +	  first[newlevel]=w;
  77.804 +	  if ( what_heur ) b=newlevel;
  77.805 +	  if ( k < newlevel ) ++k;      //now k=newlevel
  77.806 +	  Node z=level_list[newlevel];
  77.807 +	  if ( z!=INVALID ) left.set(z,w);
  77.808 +	  right.set(w,z);
  77.809 +	  left.set(w,INVALID);
  77.810 +	  level_list[newlevel]=w;
  77.811 +	}
  77.812 +      }
  77.813 +    } //relabel
  77.814 +
  77.815 +  }; 
  77.816 +} //namespace lemon
  77.817 +
  77.818 +#endif //LEMON_PREFLOW_H
  77.819 +
  77.820 +
  77.821 +
  77.822 +
    78.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    78.2 +++ b/src/lemon/skeletons/graph.h	Wed Sep 29 15:30:04 2004 +0000
    78.3 @@ -0,0 +1,510 @@
    78.4 +/* -*- C++ -*-
    78.5 + * src/lemon/skeletons/graph.h - Part of LEMON, a generic C++ optimization library
    78.6 + *
    78.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    78.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    78.9 + *
   78.10 + * Permission to use, modify and distribute this software is granted
   78.11 + * provided that this copyright notice appears in all copies. For
   78.12 + * precise terms see the accompanying LICENSE file.
   78.13 + *
   78.14 + * This software is provided "AS IS" with no warranty of any kind,
   78.15 + * express or implied, and with no claim as to its suitability for any
   78.16 + * purpose.
   78.17 + *
   78.18 + */
   78.19 +
   78.20 +#ifndef LEMON_SKELETON_GRAPH_H
   78.21 +#define LEMON_SKELETON_GRAPH_H
   78.22 +
   78.23 +///\ingroup skeletons
   78.24 +///\file
   78.25 +///\brief Declaration of Graph.
   78.26 +
   78.27 +#include <lemon/invalid.h>
   78.28 +#include <lemon/skeletons/maps.h>
   78.29 +
   78.30 +namespace lemon {
   78.31 +  namespace skeleton {
   78.32 +    
   78.33 +    /// \addtogroup skeletons
   78.34 +    /// @{
   78.35 +
   78.36 +    /// An empty static graph class.
   78.37 +  
   78.38 +    /// This class provides all the common features of a graph structure,
   78.39 +    /// however completely without implementations and real data structures
   78.40 +    /// behind the interface.
   78.41 +    /// All graph algorithms should compile with this class, but it will not
   78.42 +    /// run properly, of course.
   78.43 +    ///
   78.44 +    /// It can be used for checking the interface compatibility,
   78.45 +    /// or it can serve as a skeleton of a new graph structure.
   78.46 +    /// 
   78.47 +    /// Also, you will find here the full documentation of a certain graph
   78.48 +    /// feature, the documentation of a real graph imlementation
   78.49 +    /// like @ref ListGraph or
   78.50 +    /// @ref SmartGraph will just refer to this structure.
   78.51 +    class StaticGraph
   78.52 +    {
   78.53 +    public:
   78.54 +      /// Defalult constructor.
   78.55 +
   78.56 +      /// Defalult constructor.
   78.57 +      ///
   78.58 +      StaticGraph() { }
   78.59 +      ///Copy consructor.
   78.60 +
   78.61 +//       ///\todo It is not clear, what we expect from a copy constructor.
   78.62 +//       ///E.g. How to assign the nodes/edges to each other? What about maps?
   78.63 +//       StaticGraph(const StaticGraph& g) { }
   78.64 +
   78.65 +      /// The base type of node iterators, 
   78.66 +      /// or in other words, the trivial node iterator.
   78.67 +
   78.68 +      /// This is the base type of each node iterator,
   78.69 +      /// thus each kind of node iterator converts to this.
   78.70 +      /// More precisely each kind of node iterator should be inherited 
   78.71 +      /// from the trivial node iterator.
   78.72 +      class Node {
   78.73 +      public:
   78.74 +	/// Default constructor
   78.75 +
   78.76 +	/// @warning The default constructor sets the iterator
   78.77 +	/// to an undefined value.
   78.78 +	Node() { }
   78.79 +	/// Copy constructor.
   78.80 +
   78.81 +	/// Copy constructor.
   78.82 +	///
   78.83 +	Node(const Node&) { }
   78.84 +
   78.85 +	/// Invalid constructor \& conversion.
   78.86 +
   78.87 +	/// This constructor initializes the iterator to be invalid.
   78.88 +	/// \sa Invalid for more details.
   78.89 +	Node(Invalid) { }
   78.90 +	/// Equality operator
   78.91 +
   78.92 +	/// Two iterators are equal if and only if they point to the
   78.93 +	/// same object or both are invalid.
   78.94 +	bool operator==(Node) const { return true; }
   78.95 +
   78.96 +	/// Inequality operator
   78.97 +	
   78.98 +	/// \sa operator==(Node n)
   78.99 +	///
  78.100 +	bool operator!=(Node) const { return true; }
  78.101 +
  78.102 + 	///Comparison operator.
  78.103 +
  78.104 +	///This is a strict ordering between the nodes.
  78.105 +	///
  78.106 +	///This ordering can be different from the order in which NodeIt
  78.107 +	///goes through the nodes.
  78.108 +	///\todo Possibly we don't need it.
  78.109 +	bool operator<(Node) const { return true; }
  78.110 +      };
  78.111 +    
  78.112 +      /// This iterator goes through each node.
  78.113 +
  78.114 +      /// This iterator goes through each node.
  78.115 +      /// Its usage is quite simple, for example you can count the number
  78.116 +      /// of nodes in graph \c g of type \c Graph like this:
  78.117 +      /// \code
  78.118 +      /// int count=0;
  78.119 +      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
  78.120 +      /// \endcode
  78.121 +      class NodeIt : public Node {
  78.122 +      public:
  78.123 +	/// Default constructor
  78.124 +
  78.125 +	/// @warning The default constructor sets the iterator
  78.126 +	/// to an undefined value.
  78.127 +	NodeIt() { }
  78.128 +	/// Copy constructor.
  78.129 +	
  78.130 +	/// Copy constructor.
  78.131 +	///
  78.132 +	NodeIt(const NodeIt&) { }
  78.133 +	/// Invalid constructor \& conversion.
  78.134 +
  78.135 +	/// Initialize the iterator to be invalid.
  78.136 +	/// \sa Invalid for more details.
  78.137 +	NodeIt(Invalid) { }
  78.138 +	/// Sets the iterator to the first node.
  78.139 +
  78.140 +	/// Sets the iterator to the first node of \c g.
  78.141 +	///
  78.142 +	NodeIt(const StaticGraph& g) { }
  78.143 +	/// Node -> NodeIt conversion.
  78.144 +
  78.145 +	/// Sets the iterator to the node of \c g pointed by the trivial 
  78.146 +	/// iterator n.
  78.147 +	/// This feature necessitates that each time we 
  78.148 +	/// iterate the edge-set, the iteration order is the same.
  78.149 +	NodeIt(const StaticGraph& g, const Node& n) { }
  78.150 +	/// Next node.
  78.151 +
  78.152 +	/// Assign the iterator to the next node.
  78.153 +	///
  78.154 +	NodeIt& operator++() { return *this; }
  78.155 +      };
  78.156 +    
  78.157 +    
  78.158 +      /// The base type of the edge iterators.
  78.159 +
  78.160 +      /// The base type of the edge iterators.
  78.161 +      ///
  78.162 +      class Edge {
  78.163 +      public:
  78.164 +	/// Default constructor
  78.165 +
  78.166 +	/// @warning The default constructor sets the iterator
  78.167 +	/// to an undefined value.
  78.168 +	Edge() { }
  78.169 +	/// Copy constructor.
  78.170 +
  78.171 +	/// Copy constructor.
  78.172 +	///
  78.173 +	Edge(const Edge&) { }
  78.174 +	/// Initialize the iterator to be invalid.
  78.175 +
  78.176 +	/// Initialize the iterator to be invalid.
  78.177 +	///
  78.178 +	Edge(Invalid) { }
  78.179 +	/// Equality operator
  78.180 +
  78.181 +	/// Two iterators are equal if and only if they point to the
  78.182 +	/// same object or both are invalid.
  78.183 +	bool operator==(Edge) const { return true; }
  78.184 +	/// Inequality operator
  78.185 +
  78.186 +	/// \sa operator==(Node n)
  78.187 +	///
  78.188 +	bool operator!=(Edge) const { return true; }
  78.189 + 	///Comparison operator.
  78.190 +
  78.191 +	///This is a strict ordering between the nodes.
  78.192 +	///
  78.193 +	///This ordering can be different from the order in which NodeIt
  78.194 +	///goes through the nodes.
  78.195 +	///\todo Possibly we don't need it.
  78.196 + 	bool operator<(Edge) const { return true; }
  78.197 +      };
  78.198 +    
  78.199 +      /// This iterator goes trough the outgoing edges of a node.
  78.200 +
  78.201 +      /// This iterator goes trough the \e outgoing edges of a certain node
  78.202 +      /// of a graph.
  78.203 +      /// Its usage is quite simple, for example you can count the number
  78.204 +      /// of outgoing edges of a node \c n
  78.205 +      /// in graph \c g of type \c Graph as follows.
  78.206 +      /// \code
  78.207 +      /// int count=0;
  78.208 +      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  78.209 +      /// \endcode
  78.210 +    
  78.211 +      class OutEdgeIt : public Edge {
  78.212 +      public:
  78.213 +	/// Default constructor
  78.214 +
  78.215 +	/// @warning The default constructor sets the iterator
  78.216 +	/// to an undefined value.
  78.217 +	OutEdgeIt() { }
  78.218 +	/// Copy constructor.
  78.219 +
  78.220 +	/// Copy constructor.
  78.221 +	///
  78.222 +	OutEdgeIt(const OutEdgeIt&) { }
  78.223 +	/// Initialize the iterator to be invalid.
  78.224 +
  78.225 +	/// Initialize the iterator to be invalid.
  78.226 +	///
  78.227 +	OutEdgeIt(Invalid) { }
  78.228 +	/// This constructor sets the iterator to first outgoing edge.
  78.229 +    
  78.230 +	/// This constructor set the iterator to the first outgoing edge of
  78.231 +	/// node
  78.232 +	///@param n the node
  78.233 +	///@param g the graph
  78.234 +	OutEdgeIt(const StaticGraph& g, const Node& n) { }
  78.235 +	/// Edge -> OutEdgeIt conversion
  78.236 +
  78.237 +	/// Sets the iterator to the value of the trivial iterator \c e.
  78.238 +	/// This feature necessitates that each time we 
  78.239 +	/// iterate the edge-set, the iteration order is the same.
  78.240 +	OutEdgeIt(const StaticGraph& g, const Edge& e) { }
  78.241 +	///Next outgoing edge
  78.242 +	
  78.243 +	/// Assign the iterator to the next 
  78.244 +	/// outgoing edge of the corresponding node.
  78.245 +	OutEdgeIt& operator++() { return *this; }
  78.246 +      };
  78.247 +
  78.248 +      /// This iterator goes trough the incoming edges of a node.
  78.249 +
  78.250 +      /// This iterator goes trough the \e incoming edges of a certain node
  78.251 +      /// of a graph.
  78.252 +      /// Its usage is quite simple, for example you can count the number
  78.253 +      /// of outgoing edges of a node \c n
  78.254 +      /// in graph \c g of type \c Graph as follows.
  78.255 +      /// \code
  78.256 +      /// int count=0;
  78.257 +      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
  78.258 +      /// \endcode
  78.259 +
  78.260 +      class InEdgeIt : public Edge {
  78.261 +      public:
  78.262 +	/// Default constructor
  78.263 +
  78.264 +	/// @warning The default constructor sets the iterator
  78.265 +	/// to an undefined value.
  78.266 +	InEdgeIt() { }
  78.267 +	/// Copy constructor.
  78.268 +
  78.269 +	/// Copy constructor.
  78.270 +	///
  78.271 +	InEdgeIt(const InEdgeIt&) { }
  78.272 +	/// Initialize the iterator to be invalid.
  78.273 +
  78.274 +	/// Initialize the iterator to be invalid.
  78.275 +	///
  78.276 +	InEdgeIt(Invalid) { }
  78.277 +	/// This constructor sets the iterator to first incoming edge.
  78.278 +    
  78.279 +	/// This constructor set the iterator to the first incoming edge of
  78.280 +	/// node
  78.281 +	///@param n the node
  78.282 +	///@param g the graph
  78.283 +	InEdgeIt(const StaticGraph& g, const Node& n) { }
  78.284 +	/// Edge -> InEdgeIt conversion
  78.285 +
  78.286 +	/// Sets the iterator to the value of the trivial iterator \c e.
  78.287 +	/// This feature necessitates that each time we 
  78.288 +	/// iterate the edge-set, the iteration order is the same.
  78.289 +	InEdgeIt(const StaticGraph& g, const Edge& n) { }
  78.290 +	/// Next incoming edge
  78.291 +
  78.292 +	/// Assign the iterator to the next inedge of the corresponding node.
  78.293 +	///
  78.294 +	InEdgeIt& operator++() { return *this; }
  78.295 +      };
  78.296 +      /// This iterator goes through each edge.
  78.297 +
  78.298 +      /// This iterator goes through each edge of a graph.
  78.299 +      /// Its usage is quite simple, for example you can count the number
  78.300 +      /// of edges in a graph \c g of type \c Graph as follows:
  78.301 +      /// \code
  78.302 +      /// int count=0;
  78.303 +      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
  78.304 +      /// \endcode
  78.305 +      class EdgeIt : public Edge {
  78.306 +      public:
  78.307 +	/// Default constructor
  78.308 +
  78.309 +	/// @warning The default constructor sets the iterator
  78.310 +	/// to an undefined value.
  78.311 +	EdgeIt() { }
  78.312 +	/// Copy constructor.
  78.313 +
  78.314 +	/// Copy constructor.
  78.315 +	///
  78.316 +	EdgeIt(const EdgeIt&) { }
  78.317 +	/// Initialize the iterator to be invalid.
  78.318 +
  78.319 +	/// Initialize the iterator to be invalid.
  78.320 +	///
  78.321 +	EdgeIt(Invalid) { }
  78.322 +	/// This constructor sets the iterator to first edge.
  78.323 +    
  78.324 +	/// This constructor set the iterator to the first edge of
  78.325 +	/// node
  78.326 +	///@param g the graph
  78.327 +	EdgeIt(const StaticGraph& g) { }
  78.328 +	/// Edge -> EdgeIt conversion
  78.329 +
  78.330 +	/// Sets the iterator to the value of the trivial iterator \c e.
  78.331 +	/// This feature necessitates that each time we 
  78.332 +	/// iterate the edge-set, the iteration order is the same.
  78.333 +	EdgeIt(const StaticGraph&, const Edge&) { } 
  78.334 +    	///Next edge
  78.335 +	
  78.336 +	/// Assign the iterator to the next 
  78.337 +	/// edge of the corresponding node.
  78.338 +	EdgeIt& operator++() { return *this; }
  78.339 +      };
  78.340 +
  78.341 +      /// First node of the graph.
  78.342 +
  78.343 +      /// \retval i the first node.
  78.344 +      /// \return the first node.
  78.345 +      ///
  78.346 +      NodeIt& first(NodeIt& i) const { return i; }
  78.347 +
  78.348 +      /// The first incoming edge.
  78.349 +
  78.350 +      /// The first incoming edge.
  78.351 +      ///
  78.352 +      InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
  78.353 +      /// The first outgoing edge.
  78.354 +
  78.355 +      /// The first outgoing edge.
  78.356 +      ///
  78.357 +      OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
  78.358 +      /// The first edge of the Graph.
  78.359 +
  78.360 +      /// The first edge of the Graph.
  78.361 +      ///
  78.362 +      EdgeIt& first(EdgeIt& i) const { return i; }
  78.363 +
  78.364 +      ///Gives back the head node of an edge.
  78.365 +
  78.366 +      ///Gives back the head node of an edge.
  78.367 +      ///
  78.368 +      Node head(Edge) const { return INVALID; }
  78.369 +      ///Gives back the tail node of an edge.
  78.370 +
  78.371 +      ///Gives back the tail node of an edge.
  78.372 +      ///
  78.373 +      Node tail(Edge) const { return INVALID; }
  78.374 +  
  78.375 +      ///Gives back the \e id of a node.
  78.376 +
  78.377 +      ///\warning Not all graph structures provide this feature.
  78.378 +      ///
  78.379 +      ///\todo Should each graph provide \c id?
  78.380 +      int id(const Node&) const { return 0; }
  78.381 +      ///Gives back the \e id of an edge.
  78.382 +
  78.383 +      ///\warning Not all graph structures provide this feature.
  78.384 +      ///
  78.385 +      ///\todo Should each graph provide \c id?
  78.386 +      int id(const Edge&) const { return 0; }
  78.387 +
  78.388 +      ///\e
  78.389 +      
  78.390 +      ///\todo Should it be in the concept?
  78.391 +      ///
  78.392 +      int nodeNum() const { return 0; }
  78.393 +      ///\e
  78.394 +
  78.395 +      ///\todo Should it be in the concept?
  78.396 +      ///
  78.397 +      int edgeNum() const { return 0; }
  78.398 +
  78.399 +
  78.400 +      ///Reference map of the nodes to type \c T.
  78.401 +
  78.402 +      /// \ingroup skeletons
  78.403 +      ///Reference map of the nodes to type \c T.
  78.404 +      /// \sa Reference
  78.405 +      /// \warning Making maps that can handle bool type (NodeMap<bool>)
  78.406 +      /// needs some extra attention!
  78.407 +      template<class T> class NodeMap : public ReferenceMap< Node, T >
  78.408 +      {
  78.409 +      public:
  78.410 +
  78.411 +	///\e
  78.412 +	NodeMap(const StaticGraph&) { }
  78.413 +	///\e
  78.414 +	NodeMap(const StaticGraph&, T) { }
  78.415 +
  78.416 +	///Copy constructor
  78.417 +	template<typename TT> NodeMap(const NodeMap<TT>&) { }
  78.418 +	///Assignment operator
  78.419 +	template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
  78.420 +	{ return *this; }
  78.421 +      };
  78.422 +
  78.423 +      ///Reference map of the edges to type \c T.
  78.424 +
  78.425 +      /// \ingroup skeletons
  78.426 +      ///Reference map of the edges to type \c T.
  78.427 +      /// \sa Reference
  78.428 +      /// \warning Making maps that can handle bool type (EdgeMap<bool>)
  78.429 +      /// needs some extra attention!
  78.430 +      template<class T> class EdgeMap
  78.431 +	: public ReferenceMap<Edge,T>
  78.432 +      {
  78.433 +      public:
  78.434 +
  78.435 +	///\e
  78.436 +	EdgeMap(const StaticGraph&) { }
  78.437 +	///\e
  78.438 +	EdgeMap(const StaticGraph&, T) { }
  78.439 +    
  78.440 +	///Copy constructor
  78.441 +	template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
  78.442 +	///Assignment operator
  78.443 +	template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
  78.444 +	{ return *this; }
  78.445 +      };
  78.446 +    };
  78.447 +
  78.448 +
  78.449 +  
  78.450 +    /// An empty non-static graph class.
  78.451 +
  78.452 +    /// This class provides everything that \ref StaticGraph
  78.453 +    /// with additional functionality which enables to build a
  78.454 +    /// graph from scratch.
  78.455 +    class ExtendableGraph : public StaticGraph
  78.456 +    {
  78.457 +    public:
  78.458 +      /// Defalult constructor.
  78.459 +
  78.460 +      /// Defalult constructor.
  78.461 +      ///
  78.462 +      ExtendableGraph() { }
  78.463 +      ///Add a new node to the graph.
  78.464 +
  78.465 +      /// \return the new node.
  78.466 +      ///
  78.467 +      Node addNode() { return INVALID; }
  78.468 +      ///Add a new edge to the graph.
  78.469 +
  78.470 +      ///Add a new edge to the graph with tail node \c t
  78.471 +      ///and head node \c h.
  78.472 +      ///\return the new edge.
  78.473 +      Edge addEdge(Node h, Node t) { return INVALID; }
  78.474 +    
  78.475 +      /// Resets the graph.
  78.476 +
  78.477 +      /// This function deletes all edges and nodes of the graph.
  78.478 +      /// It also frees the memory allocated to store them.
  78.479 +      /// \todo It might belong to \ref ErasableGraph.
  78.480 +      void clear() { }
  78.481 +    };
  78.482 +
  78.483 +    /// An empty erasable graph class.
  78.484 +  
  78.485 +    /// This class is an extension of \ref ExtendableGraph. It also makes it
  78.486 +    /// possible to erase edges or nodes.
  78.487 +    class ErasableGraph : public ExtendableGraph
  78.488 +    {
  78.489 +    public:
  78.490 +      /// Defalult constructor.
  78.491 +
  78.492 +      /// Defalult constructor.
  78.493 +      ///
  78.494 +      ErasableGraph() { }
  78.495 +      /// Deletes a node.
  78.496 +
  78.497 +      /// Deletes node \c n node.
  78.498 +      ///
  78.499 +      void erase(Node n) { }
  78.500 +      /// Deletes an edge.
  78.501 +
  78.502 +      /// Deletes edge \c e edge.
  78.503 +      ///
  78.504 +      void erase(Edge e) { }
  78.505 +    };
  78.506 +
  78.507 +    // @}
  78.508 +  } //namespace skeleton  
  78.509 +} //namespace lemon
  78.510 +
  78.511 +
  78.512 +
  78.513 +#endif // LEMON_SKELETON_GRAPH_H
    79.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    79.2 +++ b/src/lemon/skeletons/maps.h	Wed Sep 29 15:30:04 2004 +0000
    79.3 @@ -0,0 +1,120 @@
    79.4 +/* -*- C++ -*-
    79.5 + * src/lemon/skeletons/maps.h - Part of LEMON, a generic C++ optimization library
    79.6 + *
    79.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    79.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    79.9 + *
   79.10 + * Permission to use, modify and distribute this software is granted
   79.11 + * provided that this copyright notice appears in all copies. For
   79.12 + * precise terms see the accompanying LICENSE file.
   79.13 + *
   79.14 + * This software is provided "AS IS" with no warranty of any kind,
   79.15 + * express or implied, and with no claim as to its suitability for any
   79.16 + * purpose.
   79.17 + *
   79.18 + */
   79.19 +
   79.20 +#ifndef LEMON_MAPSKELETON_H
   79.21 +#define LEMON_MAPSKELETON_H
   79.22 +
   79.23 +///\ingroup skeletons
   79.24 +///\file
   79.25 +///\brief Map concepts checking classes for testing and documenting.
   79.26 +
   79.27 +namespace lemon {
   79.28 +
   79.29 +  namespace skeleton {
   79.30 +  
   79.31 +    /// \addtogroup skeletons
   79.32 +    /// @{
   79.33 +
   79.34 +    /// Readable map concept
   79.35 +    template<typename K, typename T>
   79.36 +    class ReadMap
   79.37 +    {
   79.38 +    public:
   79.39 +      /// Map's key type.
   79.40 +      typedef K KeyType;    
   79.41 +      /// Map's value type. (The type of objects associated with the keys).
   79.42 +      typedef T ValueType;
   79.43 +
   79.44 +      /// Returns the value associated with a key.
   79.45 +      ValueType operator[](const KeyType &k) const {return ValueType();}
   79.46 +
   79.47 +      ///Default constructor
   79.48 +      ReadMap() {}
   79.49 +    };
   79.50 +
   79.51 +
   79.52 +    /// Writable map concept
   79.53 +    template<typename K, typename T>
   79.54 +    class WriteMap
   79.55 +    {
   79.56 +    public:
   79.57 +      /// Map's key type.
   79.58 +      typedef K KeyType;    
   79.59 +      /// Map's value type. (The type of objects associated with the keys).
   79.60 +      typedef T ValueType;
   79.61 +
   79.62 +      /// Sets the value associated with a key.
   79.63 +      void set(const KeyType &k,const ValueType &t) {}
   79.64 +
   79.65 +      ///Default constructor
   79.66 +      WriteMap() {}
   79.67 +    };
   79.68 +
   79.69 +    ///Read/Writable map concept
   79.70 +    template<typename K, typename T>
   79.71 +    class ReadWriteMap : public ReadMap<K,T>,
   79.72 +			    public WriteMap<K,T>
   79.73 +    {
   79.74 +    public:
   79.75 +      /// Map's key type.
   79.76 +      typedef K KeyType;    
   79.77 +      /// Map's value type. (The type of objects associated with the keys).
   79.78 +      typedef T ValueType;
   79.79 +
   79.80 +      /// Returns the value associated with a key.
   79.81 +      ValueType operator[](const KeyType &k) const {return ValueType();}
   79.82 +      /// Sets the value associated with a key.
   79.83 +      void set(const KeyType &k,const ValueType &t) {}
   79.84 +
   79.85 +      ///Default constructor
   79.86 +      ReadWriteMap() {}
   79.87 +    };
   79.88 +  
   79.89 +  
   79.90 +    ///Dereferable map concept
   79.91 +    template<typename K, typename T>
   79.92 +    class ReferenceMap : public ReadWriteMap<K,T>
   79.93 +    {
   79.94 +    public:
   79.95 +      /// Map's key type.
   79.96 +      typedef K KeyType;    
   79.97 +      /// Map's value type. (The type of objects associated with the keys).
   79.98 +      typedef T ValueType;
   79.99 +
  79.100 +    protected:
  79.101 +      ValueType tmp;
  79.102 +    public:
  79.103 +      typedef ValueType& ReferenceType;
  79.104 +      /// Map's const reference type.
  79.105 +      typedef const ValueType& ConstReferenceType;
  79.106 +
  79.107 +      ///Returns a reference to the value associated to a key.
  79.108 +      ReferenceType operator[](const KeyType &i) { return tmp; }
  79.109 +      ///Returns a const reference to the value associated to a key.
  79.110 +      ConstReferenceType operator[](const KeyType &i) const
  79.111 +      { return tmp; }
  79.112 +      /// Sets the value associated with a key.
  79.113 +      void set(const KeyType &k,const ValueType &t) { operator[](k)=t; }
  79.114 +
  79.115 +      ///Default constructor
  79.116 +      ReferenceMap() {}
  79.117 +    };
  79.118 +
  79.119 +    // @}
  79.120 +
  79.121 +  } //namespace skeleton
  79.122 +} //namespace lemon
  79.123 +#endif // LEMON_MAPSKELETON_H
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/src/lemon/skeletons/path.h	Wed Sep 29 15:30:04 2004 +0000
    80.3 @@ -0,0 +1,236 @@
    80.4 +/* -*- C++ -*-
    80.5 + * src/lemon/skeletons/path.h - Part of LEMON, a generic C++ optimization library
    80.6 + *
    80.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    80.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    80.9 + *
   80.10 + * Permission to use, modify and distribute this software is granted
   80.11 + * provided that this copyright notice appears in all copies. For
   80.12 + * precise terms see the accompanying LICENSE file.
   80.13 + *
   80.14 + * This software is provided "AS IS" with no warranty of any kind,
   80.15 + * express or implied, and with no claim as to its suitability for any
   80.16 + * purpose.
   80.17 + *
   80.18 + */
   80.19 +
   80.20 +///\ingroup skeletons
   80.21 +///\file
   80.22 +///\brief Classes for representing paths in graphs.
   80.23 +
   80.24 +#ifndef LEMON_SKELETON_PATH_H
   80.25 +#define LEMON_SKELETON_PATH_H
   80.26 +
   80.27 +#include <lemon/invalid.h>
   80.28 +
   80.29 +namespace lemon {
   80.30 +  namespace skeleton {
   80.31 +    /// \addtogroup skeletons
   80.32 +    /// @{
   80.33 +
   80.34 +
   80.35 +    //! \brief A skeletom structure for representing directed paths in a graph.
   80.36 +    //!
   80.37 +    //! A skeleton structure for representing directed paths in a graph.
   80.38 +    //! \param GR The graph type in which the path is.
   80.39 +    //!
   80.40 +    //! In a sense, the path can be treated as a graph, for is has \c NodeIt
   80.41 +    //! and \c EdgeIt with the same usage. These types converts to the \c Node
   80.42 +    //! and \c Edge of the original graph.
   80.43 +    template<typename GR>
   80.44 +    class Path {
   80.45 +    public:
   80.46 +
   80.47 +      /// Type of the underlying graph.
   80.48 +      typedef /*typename*/ GR Graph;
   80.49 +      /// Edge type of the underlying graph.
   80.50 +      typedef typename Graph::Edge GraphEdge;
   80.51 +      /// Node type of the underlying graph.
   80.52 +     typedef typename Graph::Node GraphNode;
   80.53 +      class NodeIt;
   80.54 +      class EdgeIt;
   80.55 +
   80.56 +      /// \param _G The graph in which the path is.
   80.57 +      ///
   80.58 +      Path(const Graph &_G) {}
   80.59 +
   80.60 +      /// Length of the path.
   80.61 +      size_t length() const {return 0;}
   80.62 +      /// Returns whether the path is empty.
   80.63 +      bool empty() const { return true;}
   80.64 +
   80.65 +      /// Resets the path to an empty path.
   80.66 +      void clear() {}
   80.67 +
   80.68 +      /// \brief Starting point of the path.
   80.69 +      ///
   80.70 +      /// Starting point of the path.
   80.71 +      /// Returns INVALID if the path is empty.
   80.72 +      GraphNode/*It*/ head() const {return INVALID;}
   80.73 +      /// \brief End point of the path.
   80.74 +      ///
   80.75 +      /// End point of the path.
   80.76 +      /// Returns INVALID if the path is empty.
   80.77 +      GraphNode/*It*/ tail() const {return INVALID;}
   80.78 +
   80.79 +      /// \brief First NodeIt/EdgeIt.
   80.80 +      ///
   80.81 +      /// Initializes node or edge iterator to point to the first
   80.82 +      /// node or edge.
   80.83 +      template<typename It>
   80.84 +      It& first(It &i) const { return i=It(*this); }
   80.85 +
   80.86 +      /// \brief The head of an edge.
   80.87 +      ///
   80.88 +      /// Returns node iterator pointing to the head node of the
   80.89 +      /// given edge iterator.
   80.90 +      NodeIt head(const EdgeIt& e) const {return INVALID;}
   80.91 +
   80.92 +      /// \brief The tail of an edge.
   80.93 +      ///
   80.94 +      /// Returns node iterator pointing to the tail node of the
   80.95 +      /// given edge iterator.
   80.96 +      NodeIt tail(const EdgeIt& e) const {return INVALID;}
   80.97 +
   80.98 +
   80.99 +      /* Iterator classes */
  80.100 +
  80.101 +      /**
  80.102 +       * \brief Iterator class to iterate on the edges of the paths
  80.103 +       *
  80.104 +       * \ingroup skeletons
  80.105 +       * This class is used to iterate on the edges of the paths
  80.106 +       *
  80.107 +       * Of course it converts to Graph::Edge
  80.108 +       *
  80.109 +       */
  80.110 +      class EdgeIt {
  80.111 +      public:
  80.112 +	/// Default constructor
  80.113 +	EdgeIt() {}
  80.114 +	/// Invalid constructor
  80.115 +	EdgeIt(Invalid) {}
  80.116 +	/// Constructor with starting point
  80.117 +	EdgeIt(const Path &_p) {}
  80.118 +
  80.119 +	operator GraphEdge () const {}
  80.120 +
  80.121 +	/// Next edge
  80.122 +	EdgeIt& operator++() {return *this;}
  80.123 +
  80.124 +	/// Comparison operator
  80.125 +	bool operator==(const EdgeIt& e) const {return true;}
  80.126 +	/// Comparison operator
  80.127 +	bool operator!=(const EdgeIt& e) const {return true;}
  80.128 +// 	/// Comparison operator
  80.129 +//      /// \todo It is not clear what is the "natural" ordering.
  80.130 +// 	bool operator<(const EdgeIt& e) const {}
  80.131 +
  80.132 +      };
  80.133 +
  80.134 +      /**
  80.135 +       * \brief Iterator class to iterate on the nodes of the paths
  80.136 +       *
  80.137 +       * \ingroup skeletons
  80.138 +       * This class is used to iterate on the nodes of the paths
  80.139 +       *
  80.140 +       * Of course it converts to Graph::Node.
  80.141 +       *
  80.142 +       */
  80.143 +      class NodeIt {
  80.144 +      public:
  80.145 +	/// Default constructor
  80.146 +	NodeIt() {}
  80.147 +	/// Invalid constructor
  80.148 +	NodeIt(Invalid) {}
  80.149 +	/// Constructor with starting point
  80.150 +	NodeIt(const Path &_p) {}
  80.151 +
  80.152 +	///Conversion to Graph::Node
  80.153 +	operator const GraphNode& () const {}
  80.154 +	/// Next node
  80.155 +	NodeIt& operator++() {return *this;}
  80.156 +
  80.157 +	/// Comparison operator
  80.158 +	bool operator==(const NodeIt& e) const {return true;}
  80.159 +	/// Comparison operator
  80.160 +	bool operator!=(const NodeIt& e) const {return true;}
  80.161 +// 	/// Comparison operator
  80.162 +//      /// \todo It is not clear what is the "natural" ordering.
  80.163 +// 	bool operator<(const NodeIt& e) const {}
  80.164 +
  80.165 +      };
  80.166 +
  80.167 +      friend class Builder;
  80.168 +
  80.169 +      /**
  80.170 +       * \brief Class to build paths
  80.171 +       *
  80.172 +       * \ingroup skeletons
  80.173 +       * This class is used to fill a path with edges.
  80.174 +       *
  80.175 +       * You can push new edges to the front and to the back of the path in
  80.176 +       * arbitrary order then you should commit these changes to the graph.
  80.177 +       *
  80.178 +       * While the builder is active (after the first modifying
  80.179 +       * operation and until the call of \ref commit())
  80.180 +       * the underlining Path is in a
  80.181 +       * "transitional" state (operations on it have undefined result).
  80.182 +       */
  80.183 +      class Builder {
  80.184 +      public:
  80.185 +
  80.186 +        Path &P;
  80.187 +
  80.188 +	///\param _P the path you want to fill in.
  80.189 +	///
  80.190 +	Builder(Path &_P) : P(_P) {}
  80.191 +
  80.192 +	/// Sets the starting node of the path.
  80.193 +
  80.194 +	/// Sets the starting node of the path. Edge added to the path
  80.195 +	/// afterwards have to be incident to this node.
  80.196 +	/// You \em must start building an empry path with this functions.
  80.197 +	/// (And you \em must \em not use it later).
  80.198 +	/// \sa pushFront()
  80.199 +	/// \sa pushBack()
  80.200 +	void setStartNode(const GraphNode &) {}
  80.201 +
  80.202 +	///Push a new edge to the front of the path
  80.203 +
  80.204 +	///Push a new edge to the front of the path.
  80.205 +	///If the path is empty, you \em must call \ref setStartNode() before
  80.206 +	///the first use of \ref pushFront().
  80.207 +	void pushFront(const GraphEdge& e) {}
  80.208 +
  80.209 +	///Push a new edge to the back of the path
  80.210 +
  80.211 +	///Push a new edge to the back of the path.
  80.212 +	///If the path is empty, you \em must call \ref setStartNode() before
  80.213 +	///the first use of \ref pushBack().
  80.214 +	void pushBack(const GraphEdge& e) {}
  80.215 +
  80.216 +	///Commit the changes to the path.
  80.217 +	void commit() {}
  80.218 +
  80.219 +	///Reserve (front) storage for the builder in advance.
  80.220 +
  80.221 +	///If you know an reasonable upper bound of the number of the edges
  80.222 +	///to add to the front of the path,
  80.223 +	///using this function you may speed up the building.
  80.224 +	void reserveFront(size_t r) {}
  80.225 +	///Reserve (back) storage for the builder in advance.
  80.226 +
  80.227 +	///If you know an reasonable upper bound of the number of the edges
  80.228 +	///to add to the back of the path,
  80.229 +	///using this function you may speed up the building.
  80.230 +	void reserveBack(size_t r) {}
  80.231 +      };
  80.232 +    };
  80.233 +
  80.234 +  ///@}
  80.235 +  }
  80.236 +
  80.237 +} // namespace lemon
  80.238 +
  80.239 +#endif // LEMON_SKELETON_PATH_H
    81.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    81.2 +++ b/src/lemon/smart_graph.h	Wed Sep 29 15:30:04 2004 +0000
    81.3 @@ -0,0 +1,364 @@
    81.4 +/* -*- C++ -*-
    81.5 + * src/lemon/smart_graph.h - Part of LEMON, a generic C++ optimization library
    81.6 + *
    81.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    81.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    81.9 + *
   81.10 + * Permission to use, modify and distribute this software is granted
   81.11 + * provided that this copyright notice appears in all copies. For
   81.12 + * precise terms see the accompanying LICENSE file.
   81.13 + *
   81.14 + * This software is provided "AS IS" with no warranty of any kind,
   81.15 + * express or implied, and with no claim as to its suitability for any
   81.16 + * purpose.
   81.17 + *
   81.18 + */
   81.19 +
   81.20 +#ifndef LEMON_SMART_GRAPH_H
   81.21 +#define LEMON_SMART_GRAPH_H
   81.22 +
   81.23 +///\ingroup graphs
   81.24 +///\file
   81.25 +///\brief SmartGraph and SymSmartGraph classes.
   81.26 +
   81.27 +#include <vector>
   81.28 +#include <climits>
   81.29 +
   81.30 +#include <lemon/invalid.h>
   81.31 +
   81.32 +#include <lemon/array_map.h>
   81.33 +#include <lemon/sym_map.h>
   81.34 +
   81.35 +#include <lemon/map_registry.h>
   81.36 +
   81.37 +#include <lemon/map_defines.h>
   81.38 +
   81.39 +namespace lemon {
   81.40 +
   81.41 +/// \addtogroup graphs
   81.42 +/// @{
   81.43 +//  class SymSmartGraph;
   81.44 +
   81.45 +  ///A smart graph class.
   81.46 +
   81.47 +  ///This is a simple and fast graph implementation.
   81.48 +  ///It is also quite memory efficient, but at the price
   81.49 +  ///that <b> it does not support node and edge deletion</b>.
   81.50 +  ///It conforms to 
   81.51 +  ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept.
   81.52 +  ///\sa skeleton::ExtendableGraph.
   81.53 +  ///
   81.54 +  ///\todo Some member functions could be \c static.
   81.55 +  ///
   81.56 +  ///\todo A possibly useful functionality: a function saveState() would
   81.57 +  ///give back a data sturcture X and then the function restoreState(X)
   81.58 +  ///would remove the nodes and edges added after the call of saveState().
   81.59 +  ///Of course it should be used as a stack. (Maybe X is not necessary.)
   81.60 +  ///
   81.61 +  ///\author Alpar Juttner
   81.62 +  class SmartGraph {
   81.63 +
   81.64 +    struct NodeT 
   81.65 +    {
   81.66 +      int first_in,first_out;      
   81.67 +      NodeT() : first_in(-1), first_out(-1) {}
   81.68 +    };
   81.69 +    struct EdgeT 
   81.70 +    {
   81.71 +      int head, tail, next_in, next_out;      
   81.72 +      //FIXME: is this necessary?
   81.73 +      EdgeT() : next_in(-1), next_out(-1) {}  
   81.74 +    };
   81.75 +
   81.76 +    std::vector<NodeT> nodes;
   81.77 +
   81.78 +    std::vector<EdgeT> edges;
   81.79 +    
   81.80 +    
   81.81 +  public:
   81.82 +
   81.83 +    typedef SmartGraph Graph;
   81.84 +
   81.85 +    class Node;
   81.86 +    class Edge;
   81.87 +
   81.88 +    class NodeIt;
   81.89 +    class EdgeIt;
   81.90 +    class OutEdgeIt;
   81.91 +    class InEdgeIt;
   81.92 +    
   81.93 +    // Create map registries.
   81.94 +    CREATE_MAP_REGISTRIES;
   81.95 +    // Create node and edge maps.
   81.96 +    CREATE_MAPS(ArrayMap);
   81.97 +    
   81.98 +  public:
   81.99 +
  81.100 +    SmartGraph() : nodes(), edges() { }
  81.101 +    SmartGraph(const SmartGraph &_g) : nodes(_g.nodes), edges(_g.edges) { }
  81.102 +    
  81.103 +    ///Number of nodes.
  81.104 +    int nodeNum() const { return nodes.size(); }
  81.105 +    ///Number of edges.
  81.106 +    int edgeNum() const { return edges.size(); }
  81.107 +
  81.108 +    /// Maximum node ID.
  81.109 +    
  81.110 +    /// Maximum node ID.
  81.111 +    ///\sa id(Node)
  81.112 +    int maxNodeId() const { return nodes.size()-1; }
  81.113 +    /// Maximum edge ID.
  81.114 +    
  81.115 +    /// Maximum edge ID.
  81.116 +    ///\sa id(Edge)
  81.117 +    int maxEdgeId() const { return edges.size()-1; }
  81.118 +
  81.119 +    Node tail(Edge e) const { return edges[e.n].tail; }
  81.120 +    Node head(Edge e) const { return edges[e.n].head; }
  81.121 +
  81.122 +    NodeIt& first(NodeIt& v) const { 
  81.123 +      v=NodeIt(*this); return v; }
  81.124 +    EdgeIt& first(EdgeIt& e) const { 
  81.125 +      e=EdgeIt(*this); return e; }
  81.126 +    OutEdgeIt& first(OutEdgeIt& e, const Node v) const { 
  81.127 +      e=OutEdgeIt(*this,v); return e; }
  81.128 +    InEdgeIt& first(InEdgeIt& e, const Node v) const { 
  81.129 +      e=InEdgeIt(*this,v); return e; }
  81.130 +
  81.131 +    /// Node ID.
  81.132 +    
  81.133 +    /// The ID of a valid Node is a nonnegative integer not greater than
  81.134 +    /// \ref maxNodeId(). The range of the ID's is not surely continuous
  81.135 +    /// and the greatest node ID can be actually less then \ref maxNodeId().
  81.136 +    ///
  81.137 +    /// The ID of the \ref INVALID node is -1.
  81.138 +    ///\return The ID of the node \c v. 
  81.139 +    static int id(Node v) { return v.n; }
  81.140 +    /// Edge ID.
  81.141 +    
  81.142 +    /// The ID of a valid Edge is a nonnegative integer not greater than
  81.143 +    /// \ref maxEdgeId(). The range of the ID's is not surely continuous
  81.144 +    /// and the greatest edge ID can be actually less then \ref maxEdgeId().
  81.145 +    ///
  81.146 +    /// The ID of the \ref INVALID edge is -1.
  81.147 +    ///\return The ID of the edge \c e. 
  81.148 +    static int id(Edge e) { return e.n; }
  81.149 +
  81.150 +    Node addNode() {
  81.151 +      Node n; n.n=nodes.size();
  81.152 +      nodes.push_back(NodeT()); //FIXME: Hmmm...
  81.153 +
  81.154 +      
  81.155 +      node_maps.add(n);
  81.156 +      return n;
  81.157 +    }
  81.158 +    
  81.159 +    Edge addEdge(Node u, Node v) {
  81.160 +      Edge e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm...
  81.161 +      edges[e.n].tail=u.n; edges[e.n].head=v.n;
  81.162 +      edges[e.n].next_out=nodes[u.n].first_out;
  81.163 +      edges[e.n].next_in=nodes[v.n].first_in;
  81.164 +      nodes[u.n].first_out=nodes[v.n].first_in=e.n;
  81.165 +
  81.166 +      edge_maps.add(e);
  81.167 +
  81.168 +      return e;
  81.169 +    }
  81.170 +
  81.171 +    /// Finds an edge between two nodes.
  81.172 +
  81.173 +    /// Finds an edge from node \c u to node \c v.
  81.174 +    ///
  81.175 +    /// If \c prev is \ref INVALID (this is the default value), then
  81.176 +    /// It finds the first edge from \c u to \c v. Otherwise it looks for
  81.177 +    /// the next edge from \c u to \c v after \c prev.
  81.178 +    /// \return The found edge or INVALID if there is no such an edge.
  81.179 +    Edge findEdge(Node u,Node v, Edge prev = INVALID) 
  81.180 +    {
  81.181 +      int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
  81.182 +      while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
  81.183 +      prev.n=e;
  81.184 +      return prev;
  81.185 +    }
  81.186 +    
  81.187 +    void clear() {
  81.188 +      edge_maps.clear();
  81.189 +      edges.clear();
  81.190 +      node_maps.clear();
  81.191 +      nodes.clear();
  81.192 +    }
  81.193 +
  81.194 +    class Node {
  81.195 +      friend class SmartGraph;
  81.196 +      template <typename T> friend class NodeMap;
  81.197 +      
  81.198 +      friend class Edge;
  81.199 +      friend class OutEdgeIt;
  81.200 +      friend class InEdgeIt;
  81.201 +      friend class SymEdge;
  81.202 +
  81.203 +    protected:
  81.204 +      int n;
  81.205 +      friend int SmartGraph::id(Node v); 
  81.206 +      Node(int nn) {n=nn;}
  81.207 +    public:
  81.208 +      Node() {}
  81.209 +      Node (Invalid) { n=-1; }
  81.210 +      bool operator==(const Node i) const {return n==i.n;}
  81.211 +      bool operator!=(const Node i) const {return n!=i.n;}
  81.212 +      bool operator<(const Node i) const {return n<i.n;}
  81.213 +      //      ///Validity check
  81.214 +      //      operator bool() { return n!=-1; }
  81.215 +    };
  81.216 +    
  81.217 +    class NodeIt : public Node {
  81.218 +      const SmartGraph *G;
  81.219 +      friend class SmartGraph;
  81.220 +    public:
  81.221 +      NodeIt() : Node() { }
  81.222 +      NodeIt(const SmartGraph& _G,Node n) : Node(n), G(&_G) { }
  81.223 +      NodeIt(Invalid i) : Node(i) { }
  81.224 +      NodeIt(const SmartGraph& _G) : Node(_G.nodes.size()?0:-1), G(&_G) { }
  81.225 +      NodeIt &operator++() {
  81.226 +	n=(n+2)%(G->nodes.size()+1)-1; 
  81.227 +	return *this; 
  81.228 +      }
  81.229 +//       ///Validity check
  81.230 +//       operator bool() { return Node::operator bool(); }      
  81.231 +    };
  81.232 +
  81.233 +    class Edge {
  81.234 +      friend class SmartGraph;
  81.235 +      template <typename T> friend class EdgeMap;
  81.236 +
  81.237 +      friend class SymSmartGraph;
  81.238 +      
  81.239 +      friend class Node;
  81.240 +      friend class NodeIt;
  81.241 +    protected:
  81.242 +      int n;
  81.243 +      friend int SmartGraph::id(Edge e);
  81.244 +      Edge(int nn) {n=nn;}
  81.245 +    public:
  81.246 +      /// An Edge with id \c n.
  81.247 +
  81.248 +      Edge() { }
  81.249 +      Edge (Invalid) { n=-1; }
  81.250 +      bool operator==(const Edge i) const {return n==i.n;}
  81.251 +      bool operator!=(const Edge i) const {return n!=i.n;}
  81.252 +      bool operator<(const Edge i) const {return n<i.n;}
  81.253 +//       ///Validity check
  81.254 +//       operator bool() { return n!=-1; }
  81.255 +
  81.256 +      ///Set the edge to that have ID \c ID.
  81.257 +      void setToId(int id) { n=id; }
  81.258 +   };
  81.259 +    
  81.260 +    class EdgeIt : public Edge {
  81.261 +      const SmartGraph *G;
  81.262 +      friend class SmartGraph;
  81.263 +    public:
  81.264 +      EdgeIt(const SmartGraph& _G) : Edge(_G.edges.size()-1), G(&_G) { }
  81.265 +      EdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  81.266 +      EdgeIt (Invalid i) : Edge(i) { }
  81.267 +      EdgeIt() : Edge() { }
  81.268 +      EdgeIt &operator++() { --n; return *this; }
  81.269 +//       ///Validity check
  81.270 +//       operator bool() { return Edge::operator bool(); }      
  81.271 +    };
  81.272 +    
  81.273 +    class OutEdgeIt : public Edge {
  81.274 +      const SmartGraph *G;
  81.275 +      friend class SmartGraph;
  81.276 +    public: 
  81.277 +      OutEdgeIt() : Edge() { }
  81.278 +      OutEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  81.279 +      OutEdgeIt (Invalid i) : Edge(i) { }
  81.280 +
  81.281 +      OutEdgeIt(const SmartGraph& _G,const Node v)
  81.282 +	: Edge(_G.nodes[v.n].first_out), G(&_G) {}
  81.283 +      OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
  81.284 +//       ///Validity check
  81.285 +//       operator bool() { return Edge::operator bool(); }      
  81.286 +    };
  81.287 +    
  81.288 +    class InEdgeIt : public Edge {
  81.289 +      const SmartGraph *G;
  81.290 +      friend class SmartGraph;
  81.291 +    public: 
  81.292 +      InEdgeIt() : Edge() { }
  81.293 +      InEdgeIt(const SmartGraph& _G, Edge e) : Edge(e), G(&_G) { }
  81.294 +      InEdgeIt (Invalid i) : Edge(i) { }
  81.295 +      InEdgeIt(const SmartGraph& _G,Node v)
  81.296 +	: Edge(_G.nodes[v.n].first_in), G(&_G) { }
  81.297 +      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
  81.298 +//       ///Validity check
  81.299 +//       operator bool() { return Edge::operator bool(); }      
  81.300 +    };
  81.301 +
  81.302 +  };
  81.303 +
  81.304 +  ///Graph for bidirectional edges.
  81.305 +
  81.306 +  ///The purpose of this graph structure is to handle graphs
  81.307 +  ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
  81.308 +  ///of oppositely directed edges.
  81.309 +  ///There is a new edge map type called
  81.310 +  ///\ref SymSmartGraph::SymEdgeMap "SymEdgeMap"
  81.311 +  ///that complements this
  81.312 +  ///feature by
  81.313 +  ///storing shared values for the edge pairs. The usual
  81.314 +  ///\ref Graph::EdgeMap "EdgeMap"
  81.315 +  ///can be used
  81.316 +  ///as well.
  81.317 +  ///
  81.318 +  ///The oppositely directed edge can also be obtained easily
  81.319 +  ///using \ref opposite.
  81.320 +  ///\warning It shares the similarity with \ref SmartGraph that
  81.321 +  ///it is not possible to delete edges or nodes from the graph.
  81.322 +  //\sa SmartGraph.
  81.323 +
  81.324 +  class SymSmartGraph : public SmartGraph
  81.325 +  {
  81.326 +  public:
  81.327 +    typedef SymSmartGraph Graph;
  81.328 +
  81.329 +    // Create symmetric map registry.
  81.330 +    CREATE_SYM_EDGE_MAP_REGISTRY;
  81.331 +    // Create symmetric edge map.
  81.332 +    CREATE_SYM_EDGE_MAP(ArrayMap);
  81.333 +
  81.334 +
  81.335 +    SymSmartGraph() : SmartGraph() { }
  81.336 +    SymSmartGraph(const SmartGraph &_g) : SmartGraph(_g) { }
  81.337 +    ///Adds a pair of oppositely directed edges to the graph.
  81.338 +    Edge addEdge(Node u, Node v)
  81.339 +    {
  81.340 +      Edge e = SmartGraph::addEdge(u,v);
  81.341 +      Edge f = SmartGraph::addEdge(v,u);
  81.342 +      sym_edge_maps.add(e);
  81.343 +      sym_edge_maps.add(f);
  81.344 +      return e;
  81.345 +    }
  81.346 +
  81.347 +    ///The oppositely directed edge.
  81.348 +
  81.349 +    ///Returns the oppositely directed
  81.350 +    ///pair of the edge \c e.
  81.351 +    static Edge opposite(Edge e)
  81.352 +    {
  81.353 +      Edge f;
  81.354 +      f.n = e.n - 2*(e.n%2) + 1;
  81.355 +      return f;
  81.356 +    }
  81.357 +    
  81.358 +
  81.359 +  };
  81.360 +  
  81.361 +  /// @}  
  81.362 +} //namespace lemon
  81.363 +
  81.364 +
  81.365 +
  81.366 +
  81.367 +#endif //LEMON_SMART_GRAPH_H
    82.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    82.2 +++ b/src/lemon/suurballe.h	Wed Sep 29 15:30:04 2004 +0000
    82.3 @@ -0,0 +1,215 @@
    82.4 +/* -*- C++ -*-
    82.5 + * src/lemon/suurballe.h - Part of LEMON, a generic C++ optimization library
    82.6 + *
    82.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    82.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    82.9 + *
   82.10 + * Permission to use, modify and distribute this software is granted
   82.11 + * provided that this copyright notice appears in all copies. For
   82.12 + * precise terms see the accompanying LICENSE file.
   82.13 + *
   82.14 + * This software is provided "AS IS" with no warranty of any kind,
   82.15 + * express or implied, and with no claim as to its suitability for any
   82.16 + * purpose.
   82.17 + *
   82.18 + */
   82.19 +
   82.20 +#ifndef LEMON_SUURBALLE_H
   82.21 +#define LEMON_SUURBALLE_H
   82.22 +
   82.23 +///\ingroup flowalgs
   82.24 +///\file
   82.25 +///\brief An algorithm for finding k paths of minimal total length.
   82.26 +
   82.27 +
   82.28 +#include <lemon/maps.h>
   82.29 +#include <vector>
   82.30 +#include <lemon/min_cost_flow.h>
   82.31 +
   82.32 +namespace lemon {
   82.33 +
   82.34 +/// \addtogroup flowalgs
   82.35 +/// @{
   82.36 +
   82.37 +  ///\brief Implementation of an algorithm for finding k edge-disjoint paths between 2 nodes 
   82.38 +  /// of minimal total length 
   82.39 +  ///
   82.40 +  /// The class \ref lemon::Suurballe implements
   82.41 +  /// an algorithm for finding k edge-disjoint paths
   82.42 +  /// from a given source node to a given target node in an
   82.43 +  /// edge-weighted directed graph having minimal total weight (length).
   82.44 +  ///
   82.45 +  ///\warning Length values should be nonnegative.
   82.46 +  /// 
   82.47 +  ///\param Graph The directed graph type the algorithm runs on.
   82.48 +  ///\param LengthMap The type of the length map (values should be nonnegative).
   82.49 +  ///
   82.50 +  ///\note It it questionable if it is correct to call this method after
   82.51 +  ///%Suurballe for it is just a special case of Edmond's and Karp's algorithm
   82.52 +  ///for finding minimum cost flows. In fact, this implementation is just
   82.53 +  ///wraps the MinCostFlow algorithms. The paper of both %Suurballe and
   82.54 +  ///Edmonds-Karp published in 1972, therefore it is possibly right to
   82.55 +  ///state that they are
   82.56 +  ///independent results. Most frequently this special case is referred as
   82.57 +  ///%Suurballe method in the literature, especially in communication
   82.58 +  ///network context.
   82.59 +  ///\author Attila Bernath
   82.60 +  template <typename Graph, typename LengthMap>
   82.61 +  class Suurballe{
   82.62 +
   82.63 +
   82.64 +    typedef typename LengthMap::ValueType Length;
   82.65 +    
   82.66 +    typedef typename Graph::Node Node;
   82.67 +    typedef typename Graph::NodeIt NodeIt;
   82.68 +    typedef typename Graph::Edge Edge;
   82.69 +    typedef typename Graph::OutEdgeIt OutEdgeIt;
   82.70 +    typedef typename Graph::template EdgeMap<int> EdgeIntMap;
   82.71 +
   82.72 +    typedef ConstMap<Edge,int> ConstMap;
   82.73 +
   82.74 +    //Input
   82.75 +    const Graph& G;
   82.76 +
   82.77 +    //Auxiliary variables
   82.78 +    //This is the capacity map for the mincostflow problem
   82.79 +    ConstMap const1map;
   82.80 +    //This MinCostFlow instance will actually solve the problem
   82.81 +    MinCostFlow<Graph, LengthMap, ConstMap> mincost_flow;
   82.82 +
   82.83 +    //Container to store found paths
   82.84 +    std::vector< std::vector<Edge> > paths;
   82.85 +
   82.86 +  public :
   82.87 +
   82.88 +
   82.89 +    /// The constructor of the class.
   82.90 +    
   82.91 +    ///\param _G The directed graph the algorithm runs on. 
   82.92 +    ///\param _length The length (weight or cost) of the edges. 
   82.93 +    Suurballe(Graph& _G, LengthMap& _length) : G(_G),
   82.94 +      const1map(1), mincost_flow(_G, _length, const1map){}
   82.95 +
   82.96 +    ///Runs the algorithm.
   82.97 +
   82.98 +    ///Runs the algorithm.
   82.99 +    ///Returns k if there are at least k edge-disjoint paths from s to t.
  82.100 +    ///Otherwise it returns the number of found edge-disjoint paths from s to t.
  82.101 +    ///
  82.102 +    ///\param s The source node.
  82.103 +    ///\param t The target node.
  82.104 +    ///\param k How many paths are we looking for?
  82.105 +    ///
  82.106 +    int run(Node s, Node t, int k) {
  82.107 +
  82.108 +      int i = mincost_flow.run(s,t,k);
  82.109 +    
  82.110 +
  82.111 +      //Let's find the paths
  82.112 +      //We put the paths into stl vectors (as an inner representation). 
  82.113 +      //In the meantime we lose the information stored in 'reversed'.
  82.114 +      //We suppose the lengths to be positive now.
  82.115 +
  82.116 +      //We don't want to change the flow of mincost_flow, so we make a copy
  82.117 +      //The name here suggests that the flow has only 0/1 values.
  82.118 +      EdgeIntMap reversed(G); 
  82.119 +
  82.120 +      for(typename Graph::EdgeIt e(G); e!=INVALID; ++e) 
  82.121 +	reversed[e] = mincost_flow.getFlow()[e];
  82.122 +      
  82.123 +      paths.clear();
  82.124 +      //total_length=0;
  82.125 +      paths.resize(k);
  82.126 +      for (int j=0; j<i; ++j){
  82.127 +	Node n=s;
  82.128 +	OutEdgeIt e;
  82.129 +
  82.130 +	while (n!=t){
  82.131 +
  82.132 +
  82.133 +	  G.first(e,n);
  82.134 +	  
  82.135 +	  while (!reversed[e]){
  82.136 +	    ++e;
  82.137 +	  }
  82.138 +	  n = G.head(e);
  82.139 +	  paths[j].push_back(e);
  82.140 +	  //total_length += length[e];
  82.141 +	  reversed[e] = 1-reversed[e];
  82.142 +	}
  82.143 +	
  82.144 +      }
  82.145 +      return i;
  82.146 +    }
  82.147 +
  82.148 +    
  82.149 +    ///Returns the total length of the paths
  82.150 +    
  82.151 +    ///This function gives back the total length of the found paths.
  82.152 +    ///\pre \ref run() must
  82.153 +    ///be called before using this function.
  82.154 +    Length totalLength(){
  82.155 +      return mincost_flow.totalLength();
  82.156 +    }
  82.157 +
  82.158 +    ///Returns the found flow.
  82.159 +
  82.160 +    ///This function returns a const reference to the EdgeMap \c flow.
  82.161 +    ///\pre \ref run() must
  82.162 +    ///be called before using this function.
  82.163 +    const EdgeIntMap &getFlow() const { return mincost_flow.flow;}
  82.164 +
  82.165 +    /// Returns the optimal dual solution
  82.166 +    
  82.167 +    ///This function returns a const reference to the NodeMap
  82.168 +    ///\c potential (the dual solution).
  82.169 +    /// \pre \ref run() must be called before using this function.
  82.170 +    const EdgeIntMap &getPotential() const { return mincost_flow.potential;}
  82.171 +
  82.172 +    ///Checks whether the complementary slackness holds.
  82.173 +
  82.174 +    ///This function checks, whether the given solution is optimal.
  82.175 +    ///It should return true after calling \ref run() 
  82.176 +    ///Currently this function only checks optimality,
  82.177 +    ///doesn't bother with feasibility
  82.178 +    ///It is meant for testing purposes.
  82.179 +    ///
  82.180 +    bool checkComplementarySlackness(){
  82.181 +      return mincost_flow.checkComplementarySlackness();
  82.182 +    }
  82.183 +
  82.184 +    ///Read the found paths.
  82.185 +    
  82.186 +    ///This function gives back the \c j-th path in argument p.
  82.187 +    ///Assumes that \c run() has been run and nothing changed since then.
  82.188 +    /// \warning It is assumed that \c p is constructed to
  82.189 +    ///be a path of graph \c G.
  82.190 +    ///If \c j is not less than the result of previous \c run,
  82.191 +    ///then the result here will be an empty path (\c j can be 0 as well).
  82.192 +    ///
  82.193 +    ///\param Path The type of the path structure to put the result to (must meet lemon path concept).
  82.194 +    ///\param p The path to put the result to 
  82.195 +    ///\param j Which path you want to get from the found paths (in a real application you would get the found paths iteratively)
  82.196 +    template<typename Path>
  82.197 +    void getPath(Path& p, size_t j){
  82.198 +
  82.199 +      p.clear();
  82.200 +      if (j>paths.size()-1){
  82.201 +	return;
  82.202 +      }
  82.203 +      typename Path::Builder B(p);
  82.204 +      for(typename std::vector<Edge>::iterator i=paths[j].begin(); 
  82.205 +	  i!=paths[j].end(); ++i ){
  82.206 +	B.pushBack(*i);
  82.207 +      }
  82.208 +
  82.209 +      B.commit();
  82.210 +    }
  82.211 +
  82.212 +  }; //class Suurballe
  82.213 +
  82.214 +  ///@}
  82.215 +
  82.216 +} //namespace lemon
  82.217 +
  82.218 +#endif //LEMON_SUURBALLE_H
    83.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    83.2 +++ b/src/lemon/sym_map.h	Wed Sep 29 15:30:04 2004 +0000
    83.3 @@ -0,0 +1,144 @@
    83.4 +/* -*- C++ -*-
    83.5 + * src/lemon/sym_map.h - Part of LEMON, a generic C++ optimization library
    83.6 + *
    83.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    83.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    83.9 + *
   83.10 + * Permission to use, modify and distribute this software is granted
   83.11 + * provided that this copyright notice appears in all copies. For
   83.12 + * precise terms see the accompanying LICENSE file.
   83.13 + *
   83.14 + * This software is provided "AS IS" with no warranty of any kind,
   83.15 + * express or implied, and with no claim as to its suitability for any
   83.16 + * purpose.
   83.17 + *
   83.18 + */
   83.19 +
   83.20 +#ifndef LEMON_SYM_MAP_H
   83.21 +#define LEMON_SYM_MAP_H
   83.22 +
   83.23 +///\ingroup graphmaps
   83.24 +///\file
   83.25 +///\brief Graph maps that construates and destruates
   83.26 +///their elements dynamically.
   83.27 +
   83.28 +namespace lemon {
   83.29 +
   83.30 +/// \addtogroup graphmaps
   83.31 +/// @{
   83.32 +
   83.33 +  /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
   83.34 +   *  iterate on the symmetric maps when all of the edge - reverse edge pair
   83.35 +   *  has different parity.
   83.36 +   */
   83.37 +
   83.38 +
   83.39 +  template <typename Graph, typename Edge, typename EdgeIt>
   83.40 +  class SymEdgeIt : public EdgeIt {
   83.41 +  public:
   83.42 +
   83.43 +    /** Default constructor.
   83.44 +     */
   83.45 +    SymEdgeIt() 
   83.46 +      : EdgeIt() {}
   83.47 +
   83.48 +    /** Graph initialized constructor.
   83.49 +     */
   83.50 +    SymEdgeIt(const Graph& graph) 
   83.51 +      : EdgeIt(graph) {
   83.52 +      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   83.53 +	EdgeIt::operator++();
   83.54 +      }
   83.55 +    }
   83.56 +
   83.57 +    /** Creating invelid SymEdgeIt.
   83.58 +     */
   83.59 +    SymEdgeIt(Invalid invalid) 
   83.60 +      : EdgeIt(invalid) {}
   83.61 +
   83.62 +    /** SymEdgeIt from the given Edge.
   83.63 +     */
   83.64 +    SymEdgeIt(const Graph& graph, const Edge& edge)
   83.65 +      : EdgeIt(graph, edge) {
   83.66 +      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   83.67 +	EdgeIt::operator++();
   83.68 +      }
   83.69 +    }
   83.70 +
   83.71 +    /** Increase operator.
   83.72 +     */
   83.73 +    SymEdgeIt& operator++() {
   83.74 +      EdgeIt::operator++();
   83.75 +      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
   83.76 +	EdgeIt::operator++();
   83.77 +      }
   83.78 +      return *this;
   83.79 +    }
   83.80 +  };
   83.81 +
   83.82 +  /** The SymMap template class is graph map structure what
   83.83 +   *  wraps an other map structure to use as symmetric map structure.
   83.84 +   *
   83.85 +   *  The template parameter is the MapRegistry that the maps
   83.86 +   *  will belong to and the ValueType.
   83.87 +   */
   83.88 +  template <template <typename, typename> class DynMap, 
   83.89 +	    typename MapRegistry, typename Value>
   83.90 +  class SymMap : public DynMap<MapRegistry, Value>{
   83.91 +
   83.92 +  private:
   83.93 +
   83.94 +    typedef DynMap<MapRegistry, Value> MapImpl;
   83.95 +
   83.96 +  public:
   83.97 +		
   83.98 +    /// The graph type of the maps. 
   83.99 +    typedef typename MapRegistry::Graph Graph;
  83.100 +
  83.101 +    typedef typename MapImpl::KeyType KeyType;
  83.102 +
  83.103 +  public:
  83.104 +
  83.105 +
  83.106 +    /** Graph and Registry initialized map constructor.
  83.107 +     */
  83.108 +    SymMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
  83.109 +
  83.110 +    /** Constructor to use default value to initialize the map. 
  83.111 +     */
  83.112 +    SymMap(const Graph& g, MapRegistry& r, const Value& v) 
  83.113 +      : MapImpl(g, r, v) {}
  83.114 +
  83.115 +    /** Constructor to copy a map of the same map type.
  83.116 +     */
  83.117 +    SymMap(const SymMap& copy) 
  83.118 +      : MapImpl(static_cast<const MapImpl&>(copy)) {}
  83.119 +
  83.120 +    /** Assign operator to copy a map of the same map type.
  83.121 +     */
  83.122 +    SymMap& operator=(const SymMap& copy) {
  83.123 +      MapImpl::operator=(static_cast<const MapImpl&>(copy));
  83.124 +      return *this;
  83.125 +    }
  83.126 +
  83.127 +    /** Add a new key to the map. It called by the map registry.
  83.128 +     */
  83.129 +    void add(const KeyType& key) {
  83.130 +      int id = MapImpl::getGraph()->id(key);
  83.131 +      if (id & 1) return;
  83.132 +      MapImpl::add(key);
  83.133 +    }
  83.134 +		
  83.135 +    /** Erase a key from the map. It called by the map registry.
  83.136 +     */
  83.137 +    void erase(const KeyType& key) {
  83.138 +      int id = MapImpl::getGraph()->id(key);
  83.139 +      if (id & 1) return;
  83.140 +      MapImpl::add(key);
  83.141 +    }
  83.142 +  };
  83.143 +
  83.144 +  /// @}
  83.145 +}
  83.146 +
  83.147 +#endif
    84.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    84.2 +++ b/src/lemon/template.h	Wed Sep 29 15:30:04 2004 +0000
    84.3 @@ -0,0 +1,20 @@
    84.4 +/* -*- C++ -*-
    84.5 + * src/lemon/template.h - Part of LEMON, a generic C++ optimization library
    84.6 + *
    84.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    84.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    84.9 + *
   84.10 + * Permission to use, modify and distribute this software is granted
   84.11 + * provided that this copyright notice appears in all copies. For
   84.12 + * precise terms see the accompanying LICENSE file.
   84.13 + *
   84.14 + * This software is provided "AS IS" with no warranty of any kind,
   84.15 + * express or implied, and with no claim as to its suitability for any
   84.16 + * purpose.
   84.17 + *
   84.18 + */
   84.19 +
   84.20 +#ifndef LEMON_TEMPLATE_H
   84.21 +#define LEMON_TEMPLATE_H
   84.22 +
   84.23 +#endif // LEMON_TEMPLATE_H
    85.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    85.2 +++ b/src/lemon/tight_edge_filter_map.h	Wed Sep 29 15:30:04 2004 +0000
    85.3 @@ -0,0 +1,63 @@
    85.4 +/* -*- C++ -*-
    85.5 + * src/hugo/tight_edge_filter_map.h - Part of HUGOlib, a generic C++ optimization library
    85.6 + *
    85.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    85.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    85.9 + *
   85.10 + * Permission to use, modify and distribute this software is granted
   85.11 + * provided that this copyright notice appears in all copies. For
   85.12 + * precise terms see the accompanying LICENSE file.
   85.13 + *
   85.14 + * This software is provided "AS IS" with no warranty of any kind,
   85.15 + * express or implied, and with no claim as to its suitability for any
   85.16 + * purpose.
   85.17 + *
   85.18 + */
   85.19 +
   85.20 +#ifndef HUGO_TIGHT_EDGE_FILTER_MAP_H
   85.21 +#define HUGO_TIGHT_EDGE_FILTER_MAP_H
   85.22 +
   85.23 +#include <hugo/maps.h>
   85.24 +
   85.25 +// /// \file
   85.26 +// /// \brief Maximum flow algorithms.
   85.27 +// /// \ingroup galgs
   85.28 +
   85.29 +namespace hugo {
   85.30 +
   85.31 +  /// \brief A map for filtering the edge-set to those edges 
   85.32 +  /// which are tight w.r.t. some node_potential map and 
   85.33 +  /// edge_distance map.
   85.34 +  ///
   85.35 +  /// A node-map node_potential is said to be a potential w.r.t. 
   85.36 +  /// an edge-map edge_distance 
   85.37 +  /// if and only if for each edge e, node_potential[g.head(e)] 
   85.38 +  /// <= edge_distance[e]+node_potential[g.tail(e)] 
   85.39 +  /// (or the reverse inequality holds for each edge).
   85.40 +  /// An edge is said to be tight if this inequality holds with equality, 
   85.41 +  /// and the map returns true exactly for those edges.
   85.42 +  /// To avoid rounding errors, it is recommended to use this class with exact 
   85.43 +  /// types, e.g. with int.
   85.44 +  template<typename Graph, 
   85.45 +	   typename NodePotentialMap, typename EdgeDistanceMap>
   85.46 +  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
   85.47 +  protected:
   85.48 +    const Graph* g;
   85.49 +    NodePotentialMap* node_potential;
   85.50 +    EdgeDistanceMap* edge_distance;
   85.51 +  public:
   85.52 +    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
   85.53 +		       EdgeDistanceMap& _edge_distance) : 
   85.54 +      g(&_g), node_potential(&_node_potential), 
   85.55 +      edge_distance(&_edge_distance) { }
   85.56 +    bool operator[](const typename Graph::Edge& e) const {
   85.57 +      return ((*node_potential)[g->head(e)] == 
   85.58 +	      (*edge_distance)[e]+(*node_potential)[g->tail(e)]);
   85.59 +    }
   85.60 +  };
   85.61 +
   85.62 +} //namespace hugo
   85.63 +
   85.64 +#endif //HUGO_TIGHT_EDGE_FILTER_MAP_H
   85.65 +
   85.66 +
    86.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.2 +++ b/src/lemon/time_measure.h	Wed Sep 29 15:30:04 2004 +0000
    86.3 @@ -0,0 +1,227 @@
    86.4 +/* -*- C++ -*-
    86.5 + * src/lemon/time_measure.h - Part of LEMON, a generic C++ optimization library
    86.6 + *
    86.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    86.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    86.9 + *
   86.10 + * Permission to use, modify and distribute this software is granted
   86.11 + * provided that this copyright notice appears in all copies. For
   86.12 + * precise terms see the accompanying LICENSE file.
   86.13 + *
   86.14 + * This software is provided "AS IS" with no warranty of any kind,
   86.15 + * express or implied, and with no claim as to its suitability for any
   86.16 + * purpose.
   86.17 + *
   86.18 + */
   86.19 +
   86.20 +#ifndef LEMON_TIME_MEASURE_H
   86.21 +#define LEMON_TIME_MEASURE_H
   86.22 +
   86.23 +///\ingroup misc
   86.24 +///\file
   86.25 +///\brief Tools for measuring cpu usage
   86.26 +
   86.27 +#include <sys/time.h>
   86.28 +#include <sys/times.h>
   86.29 +#include <fstream>
   86.30 +#include <iostream>
   86.31 +#include <unistd.h>
   86.32 +
   86.33 +namespace lemon {
   86.34 +
   86.35 +  /// \addtogroup misc
   86.36 +  /// @{
   86.37 +
   86.38 +  /// A class to store (cpu)time instances.
   86.39 +
   86.40 +  /// This class stores five time values.
   86.41 +  /// - a real time
   86.42 +  /// - a user cpu time
   86.43 +  /// - a system cpu time
   86.44 +  /// - a user cpu time of children
   86.45 +  /// - a system cpu time of children
   86.46 +  ///
   86.47 +  /// TimeStamp's can be added to or substracted from each other and
   86.48 +  /// they can be pushed to a stream.
   86.49 +  ///
   86.50 +  /// In most cases, perhaps \ref Timer class is what you want to use instead.
   86.51 +  ///
   86.52 +  ///\author Alpar Juttner
   86.53 +
   86.54 +  class TimeStamp
   86.55 +  {
   86.56 +    tms ts;
   86.57 +    double real_time;
   86.58 +  
   86.59 +  public:
   86.60 +
   86.61 +    tms &getTms() {return ts;}
   86.62 +    const tms &getTms() const {return ts;}
   86.63 +    ///Read the current time values of the process
   86.64 +    void stamp()
   86.65 +    {
   86.66 +      timeval tv;
   86.67 +      times(&ts);
   86.68 +      gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
   86.69 +    }
   86.70 +  
   86.71 +    /// Constructor initializing with zero
   86.72 +    TimeStamp()
   86.73 +    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
   86.74 +    ///Constructor initializing with the current time values of the process
   86.75 +    TimeStamp(void *) { stamp();}
   86.76 +  
   86.77 +    ///
   86.78 +    TimeStamp &operator+=(const TimeStamp &b)
   86.79 +    {
   86.80 +      ts.tms_utime+=b.ts.tms_utime;
   86.81 +      ts.tms_stime+=b.ts.tms_stime;
   86.82 +      ts.tms_cutime+=b.ts.tms_cutime;
   86.83 +      ts.tms_cstime+=b.ts.tms_cstime;
   86.84 +      real_time+=b.real_time;
   86.85 +      return *this;
   86.86 +    }
   86.87 +    ///
   86.88 +    TimeStamp operator+(const TimeStamp &b) const
   86.89 +    {
   86.90 +      TimeStamp t(*this);
   86.91 +      return t+=b;
   86.92 +    }
   86.93 +    ///
   86.94 +    TimeStamp &operator-=(const TimeStamp &b)
   86.95 +    {
   86.96 +      ts.tms_utime-=b.ts.tms_utime;
   86.97 +      ts.tms_stime-=b.ts.tms_stime;
   86.98 +      ts.tms_cutime-=b.ts.tms_cutime;
   86.99 +      ts.tms_cstime-=b.ts.tms_cstime;
  86.100 +      real_time-=b.real_time;
  86.101 +      return *this;
  86.102 +    }
  86.103 +    ///
  86.104 +    TimeStamp operator-(const TimeStamp &b) const
  86.105 +    {
  86.106 +      TimeStamp t(*this);
  86.107 +      return t-=b;
  86.108 +    }
  86.109 +
  86.110 +    ///The time ellapsed since the last call of stamp()
  86.111 +    TimeStamp ellapsed() const
  86.112 +    {
  86.113 +      TimeStamp t(NULL);
  86.114 +      return t-*this;
  86.115 +    }
  86.116 +  
  86.117 +    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
  86.118 +  
  86.119 +    ///Gives back the user time of the process
  86.120 +    double getUserTime() const
  86.121 +    {
  86.122 +      return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
  86.123 +    }
  86.124 +    ///Gives back the system time of the process
  86.125 +    double getSystemTime() const
  86.126 +    {
  86.127 +      return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
  86.128 +    }
  86.129 +    ///Gives back the user time of the process' children
  86.130 +    double getCUserTime() const
  86.131 +    {
  86.132 +      return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
  86.133 +    }
  86.134 +    ///Gives back the user time of the process' children
  86.135 +    double getCSystemTime() const
  86.136 +    {
  86.137 +      return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
  86.138 +    }
  86.139 +    ///Gives back the real time of the process
  86.140 +    double getRealTime() const {return real_time;}
  86.141 +  };
  86.142 +
  86.143 +  ///Class measuring the cpu time and real time usage of the process
  86.144 +
  86.145 +  ///Class measuring the cpu time and real time usage of the process.
  86.146 +  ///It is quite easy-to-use, here is a short example.
  86.147 +  ///\code
  86.148 +  ///#include<lemon/time_measure.h>
  86.149 +  ///#include<iostream>
  86.150 +  ///
  86.151 +  ///int main()
  86.152 +  ///{
  86.153 +  ///
  86.154 +  ///  ...
  86.155 +  ///
  86.156 +  ///  Timer T;
  86.157 +  ///  doSomething();
  86.158 +  ///  std::cout << T << '\n';
  86.159 +  ///  T.reset();
  86.160 +  ///  doSomethingElse();
  86.161 +  ///  std::cout << T << '\n';
  86.162 +  ///
  86.163 +  ///  ...
  86.164 +  ///
  86.165 +  ///}
  86.166 +  ///\endcode
  86.167 +  ///
  86.168 +  ///\todo This shouldn't be Unix (Linux) specific.
  86.169 +  ///
  86.170 +  ///\author Alpar Juttner
  86.171 +  class Timer
  86.172 +  {
  86.173 +    TimeStamp start_time;
  86.174 +
  86.175 +    void _reset() {start_time.stamp();}
  86.176 +  
  86.177 +  public: 
  86.178 +    ///Constructor. It starts with zero time counters
  86.179 +    Timer() {_reset();}
  86.180 +
  86.181 +    ///Computes the ellapsed time
  86.182 +
  86.183 +    ///This conversion computes the ellapsed time
  86.184 +    ///since the construction of \c t or since
  86.185 +    ///the last \c t.reset().
  86.186 +    operator TimeStamp ()
  86.187 +    {
  86.188 +      TimeStamp t;
  86.189 +      t.stamp();
  86.190 +      return t-start_time;
  86.191 +    }
  86.192 +
  86.193 +    ///Resets the time counters
  86.194 +    TimeStamp reset()
  86.195 +    {
  86.196 +      TimeStamp t(start_time);
  86.197 +      _reset();
  86.198 +      return start_time-t;
  86.199 +    }
  86.200 +  };
  86.201 +
  86.202 +  ///Prints the time counters
  86.203 +
  86.204 +  ///Prints the time counters in the following form:
  86.205 +  ///
  86.206 +  /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt>
  86.207 +  ///
  86.208 +  /// where the values are the
  86.209 +  /// \li \c u: user cpu time,
  86.210 +  /// \li \c s: system cpu time,
  86.211 +  /// \li \c cu: user cpu time of children,
  86.212 +  /// \li \c cs: system cpu time of children,
  86.213 +  /// \li \c real: real time.
  86.214 +  /// \relates TimeStamp
  86.215 +  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
  86.216 +  {
  86.217 +    long cls = sysconf(_SC_CLK_TCK);
  86.218 +    os << "u: " << double(t.getTms().tms_utime)/cls <<
  86.219 +      "s, s: " << double(t.getTms().tms_stime)/cls <<
  86.220 +      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
  86.221 +      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
  86.222 +      "s, real: " << t.getRealTime() << "s";
  86.223 +    return os;
  86.224 +  }
  86.225 +
  86.226 +  /// @}  
  86.227 +
  86.228 +} //namespace lemon
  86.229 +
  86.230 +#endif //LEMON_TIME_MEASURE_H
    87.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    87.2 +++ b/src/lemon/unionfind.h	Wed Sep 29 15:30:04 2004 +0000
    87.3 @@ -0,0 +1,724 @@
    87.4 +/* -*- C++ -*-
    87.5 + * src/lemon/unionfind.h - Part of LEMON, a generic C++ optimization library
    87.6 + *
    87.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    87.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    87.9 + *
   87.10 + * Permission to use, modify and distribute this software is granted
   87.11 + * provided that this copyright notice appears in all copies. For
   87.12 + * precise terms see the accompanying LICENSE file.
   87.13 + *
   87.14 + * This software is provided "AS IS" with no warranty of any kind,
   87.15 + * express or implied, and with no claim as to its suitability for any
   87.16 + * purpose.
   87.17 + *
   87.18 + */
   87.19 +
   87.20 +#ifndef LEMON_UNION_FIND_H
   87.21 +#define LEMON_UNION_FIND_H
   87.22 +
   87.23 +//!\ingroup auxdat
   87.24 +//!\file
   87.25 +//!\brief Union-Find data structures.
   87.26 +//!
   87.27 +//!\bug unionfind_test.cc doesn't work with Intel compiler. It compiles but
   87.28 +//!fails to run (Segmentation fault).
   87.29 +
   87.30 +
   87.31 +#include <vector>
   87.32 +#include <list>
   87.33 +#include <utility>
   87.34 +#include <algorithm>
   87.35 +
   87.36 +#include <lemon/invalid.h>
   87.37 +
   87.38 +namespace lemon {
   87.39 +
   87.40 +  //! \addtogroup auxdat
   87.41 +  //! @{
   87.42 +
   87.43 +  /**
   87.44 +   * \brief A \e Union-Find data structure implementation
   87.45 +   *
   87.46 +   * The class implements the \e Union-Find data structure. 
   87.47 +   * The union operation uses rank heuristic, while
   87.48 +   * the find operation uses path compression.
   87.49 +   * This is a very simple but efficient implementation, providing 
   87.50 +   * only four methods: join (union), find, insert and size.
   87.51 +   * For more features see the \ref UnionFindEnum class.
   87.52 +   *
   87.53 +   * It is primarily used in Kruskal algorithm for finding minimal
   87.54 +   * cost spanning tree in a graph.
   87.55 +   * \sa kruskal()
   87.56 +   *
   87.57 +   * \pre The elements are automatically added only if the map 
   87.58 +   * given to the constructor was filled with -1's. Otherwise you
   87.59 +   * need to add all the elements by the \ref insert() method.
   87.60 +   * \bug It is not clear what the constructor parameter is used for.
   87.61 +   */
   87.62 +
   87.63 +  template <typename T, typename TIntMap>
   87.64 +  class UnionFind {
   87.65 +    
   87.66 +  public:
   87.67 +    typedef T ElementType;
   87.68 +    typedef std::pair<int,int> PairType;
   87.69 +
   87.70 +  private:
   87.71 +    std::vector<PairType> data;
   87.72 +    TIntMap& map;
   87.73 +
   87.74 +  public:
   87.75 +    UnionFind(TIntMap& m) : map(m) {}
   87.76 +
   87.77 +    /**
   87.78 +     * \brief Returns the index of the element's component.
   87.79 +     *
   87.80 +     * The method returns the index of the element's component.
   87.81 +     * This is an integer between zero and the number of inserted elements.
   87.82 +     */
   87.83 +
   87.84 +    int find(T a)
   87.85 +    {
   87.86 +      int comp0 = map[a];
   87.87 +      if (comp0 < 0) {
   87.88 +	return insert(a);
   87.89 +      }
   87.90 +      int comp = comp0;
   87.91 +      int next;
   87.92 +      while ( (next = data[comp].first) != comp) {
   87.93 +	comp = next;
   87.94 +      }
   87.95 +      while ( (next = data[comp0].first) != comp) {
   87.96 +	data[comp0].first = comp;
   87.97 +	comp0 = next;
   87.98 +      }
   87.99 +
  87.100 +      return comp;
  87.101 +    }
  87.102 +
  87.103 +    /**
  87.104 +     * \brief Insert a new element into the structure.
  87.105 +     *
  87.106 +     * This method inserts a new element into the data structure. 
  87.107 +     *
  87.108 +     * It is not required to use this method:
  87.109 +     * if the map given to the constructor was filled 
  87.110 +     * with -1's then it is called automatically
  87.111 +     * on the first \ref find or \ref join.
  87.112 +     *
  87.113 +     * The method returns the index of the new component.
  87.114 +     */
  87.115 +
  87.116 +    int insert(T a)
  87.117 +    {
  87.118 +      int n = data.size();
  87.119 +      data.push_back(std::make_pair(n, 1));
  87.120 +      map.set(a,n);
  87.121 +      return n;
  87.122 +    }
  87.123 +
  87.124 +    /**
  87.125 +     * \brief Joining the components of element \e a and element \e b.
  87.126 +     *
  87.127 +     * This is the \e union operation of the Union-Find structure. 
  87.128 +     * Joins the component of elemenent \e a and component of
  87.129 +     * element \e b. If \e a and \e b are in the same component then
  87.130 +     * it returns false otherwise it returns true.
  87.131 +     */
  87.132 +
  87.133 +    bool join(T a, T b)
  87.134 +    {
  87.135 +      int ca = find(a);
  87.136 +      int cb = find(b);
  87.137 +
  87.138 +      if ( ca == cb ) 
  87.139 +	return false;
  87.140 +
  87.141 +      if ( data[ca].second > data[cb].second ) {
  87.142 +	data[cb].first = ca;
  87.143 +	data[ca].second += data[cb].second;
  87.144 +      }
  87.145 +      else {
  87.146 +	data[ca].first = cb;
  87.147 +	data[cb].second += data[ca].second;
  87.148 +      }
  87.149 +      return true;
  87.150 +    }
  87.151 +
  87.152 +    /**
  87.153 +     * \brief Returns the size of the component of element \e a.
  87.154 +     *
  87.155 +     * Returns the size of the component of element \e a.
  87.156 +     */
  87.157 +
  87.158 +    int size(T a)
  87.159 +    {
  87.160 +      int ca = find(a);
  87.161 +      return data[ca].second;
  87.162 +    }
  87.163 +
  87.164 +  };
  87.165 +
  87.166 +
  87.167 +
  87.168 +
  87.169 +  /*******************************************************/
  87.170 +
  87.171 +
  87.172 +#ifdef DEVELOPMENT_DOCS
  87.173 +
  87.174 +  /**
  87.175 +   * \brief The auxiliary class for the \ref UnionFindEnum class.
  87.176 +   *
  87.177 +   * In the \ref UnionFindEnum class all components are represented as
  87.178 +   * a std::list. 
  87.179 +   * Items of these lists are UnionFindEnumItem structures.
  87.180 +   *
  87.181 +   * The class has four fields:
  87.182 +   *  - T me - the actual element 
  87.183 +   *  - IIter parent - the parent of the element in the union-find structure
  87.184 +   *  - int size - the size of the component of the element. 
  87.185 +   *            Only valid if the element
  87.186 +   *            is the leader of the component.
  87.187 +   *  - CIter my_class - pointer into the list of components 
  87.188 +   *            pointing to the component of the element.
  87.189 +   *            Only valid if the element is the leader of the component.
  87.190 +   */
  87.191 +
  87.192 +#endif
  87.193 +
  87.194 +  template <typename T>
  87.195 +  struct UnionFindEnumItem {
  87.196 +
  87.197 +    typedef std::list<UnionFindEnumItem> ItemList;
  87.198 +    typedef std::list<ItemList> ClassList;
  87.199 +    typedef typename ItemList::iterator IIter;
  87.200 +    typedef typename ClassList::iterator CIter;
  87.201 +
  87.202 +    T me;
  87.203 +    IIter parent;
  87.204 +    int size;
  87.205 +    CIter my_class;
  87.206 +
  87.207 +    UnionFindEnumItem() {}
  87.208 +    UnionFindEnumItem(const T &_me, CIter _my_class): 
  87.209 +      me(_me), size(1), my_class(_my_class) {}
  87.210 +  };
  87.211 +
  87.212 +
  87.213 +  /**
  87.214 +   * \brief A \e Union-Find data structure implementation which
  87.215 +   * is able to enumerate the components.
  87.216 +   *
  87.217 +   * The class implements a \e Union-Find data structure
  87.218 +   * which is able to enumerate the components and the items in
  87.219 +   * a component. If you don't need this feature then perhaps it's
  87.220 +   * better to use the \ref UnionFind class which is more efficient.
  87.221 +   *
  87.222 +   * The union operation uses rank heuristic, while
  87.223 +   * the find operation uses path compression.
  87.224 +   *
  87.225 +   * \pre You
  87.226 +   * need to add all the elements by the \ref insert() method.
  87.227 +   */
  87.228 +
  87.229 +
  87.230 +  template <typename T, template <typename Item> class Map>
  87.231 +  class UnionFindEnum {
  87.232 +
  87.233 +    typedef std::list<UnionFindEnumItem<T> > ItemList;
  87.234 +    typedef std::list<ItemList> ClassList;
  87.235 +    typedef typename ItemList::iterator IIter;
  87.236 +    typedef typename ItemList::const_iterator IcIter;
  87.237 +    typedef typename ClassList::iterator CIter;
  87.238 +    typedef typename ClassList::const_iterator CcIter;
  87.239 +
  87.240 +  public:
  87.241 +    typedef T ElementType;
  87.242 +    typedef UnionFindEnumItem<T> ItemType;
  87.243 +    typedef Map< IIter > MapType;
  87.244 +
  87.245 +  private:
  87.246 +    MapType& m;
  87.247 +    ClassList classes;
  87.248 +
  87.249 +    IIter _find(IIter a) const {
  87.250 +      IIter comp = a;
  87.251 +      IIter next;
  87.252 +      while( (next = comp->parent) != comp ) {
  87.253 +	comp = next;
  87.254 +      }
  87.255 +
  87.256 +      IIter comp1 = a;
  87.257 +      while( (next = comp1->parent) != comp ) {
  87.258 +	comp1->parent = comp->parent;
  87.259 +	comp1 = next;
  87.260 +      }
  87.261 +      return comp;
  87.262 +    }
  87.263 +
  87.264 +  public:
  87.265 +    UnionFindEnum(MapType& _m) : m(_m) {}
  87.266 +
  87.267 +
  87.268 +    /**
  87.269 +     * \brief Insert the given element into a new component.
  87.270 +     *
  87.271 +     * This method creates a new component consisting only of the
  87.272 +     * given element.
  87.273 +     */
  87.274 +
  87.275 +    void insert(const T &a)
  87.276 +    {
  87.277 +
  87.278 +
  87.279 +      classes.push_back(ItemList());
  87.280 +      CIter aclass = classes.end();
  87.281 +      --aclass;
  87.282 +
  87.283 +      ItemList &alist = *aclass;
  87.284 +      alist.push_back(ItemType(a, aclass));
  87.285 +      IIter ai = alist.begin();
  87.286 +
  87.287 +      ai->parent = ai;
  87.288 +      m.set(a, ai);
  87.289 +
  87.290 +    }
  87.291 +
  87.292 +    /**
  87.293 +     * \brief Insert the given element into the component of the others.
  87.294 +     *
  87.295 +     * This methods insert the element \e a into the component of the
  87.296 +     * element \e comp. 
  87.297 +     */
  87.298 +
  87.299 +    void insert(const T &a, const T &comp) {
  87.300 +      
  87.301 +      IIter clit = _find(m[comp]);
  87.302 +      ItemList &c = *clit->my_class;
  87.303 +      c.push_back(ItemType(a,0));
  87.304 +      IIter ai = c.end();
  87.305 +      --ai;
  87.306 +      ai->parent = clit;
  87.307 +      m.set(a, ai);
  87.308 +      ++clit->size;
  87.309 +    }
  87.310 +
  87.311 +
  87.312 +    /**
  87.313 +     * \brief Find the leader of the component of the given element.
  87.314 +     *
  87.315 +     * The method returns the leader of the component of the given element.
  87.316 +     */
  87.317 +
  87.318 +    T find(const T &a) const {
  87.319 +      return _find(m[a])->me;
  87.320 +    }
  87.321 +
  87.322 +
  87.323 +    /**
  87.324 +     * \brief Joining the component of element \e a and element \e b.
  87.325 +     *
  87.326 +     * This is the \e union operation of the Union-Find structure. 
  87.327 +     * Joins the component of elemenent \e a and component of
  87.328 +     * element \e b. If \e a and \e b are in the same component then
  87.329 +     * returns false else returns true.
  87.330 +     */
  87.331 +
  87.332 +    bool join(T a, T b) {
  87.333 +
  87.334 +      IIter ca = _find(m[a]);
  87.335 +      IIter cb = _find(m[b]);
  87.336 +
  87.337 +      if ( ca == cb ) {
  87.338 +	return false;
  87.339 +      }
  87.340 +
  87.341 +      if ( ca->size > cb->size ) {
  87.342 +
  87.343 +	cb->parent = ca->parent;
  87.344 +	ca->size += cb->size;
  87.345 +	
  87.346 +	ItemList &alist = *ca->my_class;
  87.347 +	alist.splice(alist.end(),*cb->my_class);
  87.348 +
  87.349 +	classes.erase(cb->my_class);
  87.350 +	cb->my_class = 0;
  87.351 +      }
  87.352 +      else {
  87.353 +
  87.354 +	ca->parent = cb->parent;
  87.355 +	cb->size += ca->size;
  87.356 +	
  87.357 +	ItemList &blist = *cb->my_class;
  87.358 +	blist.splice(blist.end(),*ca->my_class);
  87.359 +
  87.360 +	classes.erase(ca->my_class);
  87.361 +	ca->my_class = 0;
  87.362 +      }
  87.363 +
  87.364 +      return true;
  87.365 +    }
  87.366 +
  87.367 +
  87.368 +    /**
  87.369 +     * \brief Returns the size of the component of element \e a.
  87.370 +     *
  87.371 +     * Returns the size of the component of element \e a.
  87.372 +     */
  87.373 +
  87.374 +    int size(const T &a) const {
  87.375 +      return _find(m[a])->size;
  87.376 +    }
  87.377 +
  87.378 +
  87.379 +    /**
  87.380 +     * \brief Split up the component of the element. 
  87.381 +     *
  87.382 +     * Splitting the component of the element into sigleton
  87.383 +     * components (component of size one).
  87.384 +     */
  87.385 +
  87.386 +    void split(const T &a) {
  87.387 +
  87.388 +      IIter ca = _find(m[a]);
  87.389 + 
  87.390 +      if ( ca->size == 1 )
  87.391 +	return;
  87.392 +      
  87.393 +      CIter aclass = ca->my_class;
  87.394 +
  87.395 +      for(IIter curr = ca; ++curr != aclass->end(); curr=ca) {
  87.396 +	classes.push_back(ItemList());
  87.397 +	CIter nl = --classes.end();
  87.398 +	nl->splice(nl->end(), *aclass, curr);
  87.399 +
  87.400 +	curr->size=1;
  87.401 +	curr->parent=curr;
  87.402 +	curr->my_class = nl;
  87.403 +      }
  87.404 +
  87.405 +      ca->size=1;
  87.406 +      return;
  87.407 +    }
  87.408 +
  87.409 +
  87.410 +    /**
  87.411 +     * \brief Set the given element to the leader element of its component.
  87.412 +     *
  87.413 +     * Set the given element to the leader element of its component.
  87.414 +     */
  87.415 +
  87.416 +    void makeRep(const T &a) {
  87.417 +
  87.418 +      IIter ia = m[a];
  87.419 +      IIter la = _find(ia);
  87.420 +      if (la == ia) return;
  87.421 +
  87.422 +      ia->my_class = la->my_class;
  87.423 +      la->my_class = 0;
  87.424 +
  87.425 +      ia->size = la->size;
  87.426 +
  87.427 +      CIter l = ia->my_class;
  87.428 +      l->splice(l->begin(),*l,ia);
  87.429 +
  87.430 +      ia->parent = ia;
  87.431 +      la->parent = ia;
  87.432 +    }
  87.433 +
  87.434 +    /**
  87.435 +     * \brief Move the given element to an other component.
  87.436 +     *
  87.437 +     * This method moves the element \e a from its component
  87.438 +     * to the component of \e comp.
  87.439 +     * If \e a and \e comp are in the same component then
  87.440 +     * it returns false otherwise it returns true.
  87.441 +     */
  87.442 +
  87.443 +    bool move(const T &a, const T &comp) {
  87.444 +
  87.445 +      IIter ai = m[a];
  87.446 +      IIter lai = _find(ai);
  87.447 +      IIter clit = _find(m[comp]);
  87.448 +
  87.449 +      if (lai == clit)
  87.450 +	return false;
  87.451 +
  87.452 +      ItemList &cl = *clit->my_class,
  87.453 +	&al = *lai->my_class;
  87.454 +
  87.455 +      bool is_leader = (lai == ai);
  87.456 +      bool singleton = false;
  87.457 +
  87.458 +      if (is_leader) {
  87.459 +	++lai;
  87.460 +      }
  87.461 +
  87.462 +      cl.splice(cl.end(), al, ai);
  87.463 +
  87.464 +      if (is_leader) {
  87.465 +	if (ai->size == 1) {
  87.466 +	  classes.erase(ai->my_class);
  87.467 +	  singleton = true;
  87.468 +	}
  87.469 +	else {
  87.470 +	  lai->size = ai->size; 
  87.471 +	  lai->my_class = ai->my_class;	
  87.472 +	}
  87.473 +      }
  87.474 +      if (!singleton) {
  87.475 +	for (IIter i = lai; i != al.end(); ++i)
  87.476 +	  i->parent = lai;
  87.477 +	--lai->size;
  87.478 +      }
  87.479 +
  87.480 +      ai->parent = clit;
  87.481 +      ai->my_class = 0;
  87.482 +      ++clit->size;
  87.483 +
  87.484 +      return true;
  87.485 +    }
  87.486 +
  87.487 +
  87.488 +    /**
  87.489 +     * \brief Remove the given element from the structure.
  87.490 +     *
  87.491 +     * Remove the given element from the structure.
  87.492 +     *
  87.493 +     * Removes the element from its component and if the component becomes
  87.494 +     * empty then removes that component from the component list.
  87.495 +     */
  87.496 +    void erase(const T &a) {
  87.497 +
  87.498 +      IIter ma = m[a];
  87.499 +      if (ma == 0) return;
  87.500 +
  87.501 +      IIter la = _find(ma);
  87.502 +      if (la == ma) {
  87.503 +	if (ma -> size == 1){
  87.504 +	  classes.erase(ma->my_class);
  87.505 +	  m.set(a,0);
  87.506 +	  return;
  87.507 +	}
  87.508 +	++la;
  87.509 +	la->size = ma->size; 
  87.510 +	la->my_class = ma->my_class;	
  87.511 +      }
  87.512 +
  87.513 +      for (IIter i = la; i != la->my_class->end(); ++i) {
  87.514 +	i->parent = la;
  87.515 +      }
  87.516 +
  87.517 +      la->size--;
  87.518 +      la->my_class->erase(ma);
  87.519 +      m.set(a,0);
  87.520 +    }
  87.521 +
  87.522 +    /**
  87.523 +     * \brief Removes the component of the given element from the structure.
  87.524 +     *
  87.525 +     * Removes the component of the given element from the structure.
  87.526 +     */
  87.527 +
  87.528 +    void eraseClass(const T &a) {
  87.529 +      IIter ma = m[a];
  87.530 +      if (ma == 0) return;
  87.531 +#     ifdef DEBUG
  87.532 +      CIter c = _find(ma)->my_class;
  87.533 +      for (IIter i=c->begin(); i!=c->end(); ++i)
  87.534 +	m.set(i->me, 0);
  87.535 +#     endif
  87.536 +      classes.erase(_find(ma)->my_class);
  87.537 +    }
  87.538 +
  87.539 +
  87.540 +    class ClassIt {
  87.541 +      friend class UnionFindEnum;
  87.542 +
  87.543 +      CcIter i;
  87.544 +    public:
  87.545 +      ClassIt(Invalid): i(0) {}
  87.546 +      ClassIt() {}
  87.547 +      
  87.548 +      operator const T& () const { 
  87.549 +	ItemList const &ll = *i;
  87.550 +	return (ll.begin())->me; }
  87.551 +      bool operator == (ClassIt it) const {
  87.552 +	return (i == it.i);
  87.553 +      }
  87.554 +      bool operator != (ClassIt it) const {
  87.555 +	return (i != it.i);
  87.556 +      }
  87.557 +      bool operator < (ClassIt it) const {
  87.558 +	return (i < it.i);
  87.559 +      }
  87.560 +
  87.561 +      bool valid() const { return i != 0; }
  87.562 +    private:
  87.563 +      void first(const ClassList &l) { i = l.begin(); validate(l); }
  87.564 +      void next(const ClassList &l) {
  87.565 +	++i; 
  87.566 +	validate(l);
  87.567 +      }
  87.568 +      void validate(const ClassList &l) {
  87.569 +	if ( i == l.end() ) 
  87.570 +	  i = 0;
  87.571 +      }
  87.572 +    };
  87.573 +
  87.574 +    /**
  87.575 +     * \brief Sets the iterator to point to the first component.
  87.576 +     * 
  87.577 +     * Sets the iterator to point to the first component.
  87.578 +     *
  87.579 +     * With the \ref first, \ref valid and \ref next methods you can
  87.580 +     * iterate through the components. For example:
  87.581 +     * \code
  87.582 +     * UnionFindEnum<Graph::Node, Graph::NodeMap>::MapType map(G);
  87.583 +     * UnionFindEnum<Graph::Node, Graph::NodeMap> U(map);
  87.584 +     * UnionFindEnum<Graph::Node, Graph::NodeMap>::ClassIt iter;
  87.585 +     *  for (U.first(iter); U.valid(iter); U.next(iter)) {
  87.586 +     *    // iter is convertible to Graph::Node
  87.587 +     *    cout << iter << endl;
  87.588 +     *  }
  87.589 +     * \endcode
  87.590 +     */
  87.591 +
  87.592 +    ClassIt& first(ClassIt& it) const {
  87.593 +      it.first(classes);
  87.594 +      return it;
  87.595 +    }
  87.596 +
  87.597 +    /**
  87.598 +     * \brief Returns whether the iterator is valid.
  87.599 +     *
  87.600 +     * Returns whether the iterator is valid.
  87.601 +     *
  87.602 +     * With the \ref first, \ref valid and \ref next methods you can
  87.603 +     * iterate through the components. See the example here: \ref first.
  87.604 +     */
  87.605 +
  87.606 +    bool valid(ClassIt const &it) const {
  87.607 +      return it.valid(); 
  87.608 +    }
  87.609 +
  87.610 +    /**
  87.611 +     * \brief Steps the iterator to the next component. 
  87.612 +     *
  87.613 +     * Steps the iterator to the next component.
  87.614 +     *
  87.615 +     * With the \ref first, \ref valid and \ref next methods you can
  87.616 +     * iterate through the components. See the example here: \ref first.
  87.617 +     */
  87.618 +
  87.619 +    ClassIt& next(ClassIt& it) const {
  87.620 +      it.next(classes);
  87.621 +      return it;
  87.622 +    }
  87.623 +
  87.624 +
  87.625 +    class ItemIt {
  87.626 +      friend class UnionFindEnum;
  87.627 +
  87.628 +      IcIter i;
  87.629 +      const ItemList *l;
  87.630 +    public:
  87.631 +      ItemIt(Invalid): i(0) {}
  87.632 +      ItemIt() {}
  87.633 +      
  87.634 +      operator const T& () const { return i->me; }
  87.635 +      bool operator == (ItemIt it) const {
  87.636 +	return (i == it.i);
  87.637 +      }
  87.638 +      bool operator != (ItemIt it) const {
  87.639 +	return (i != it.i);
  87.640 +      }
  87.641 +      bool operator < (ItemIt it) const {
  87.642 +	return (i < it.i);
  87.643 +      }
  87.644 +
  87.645 +      bool valid() const { return i != 0; }
  87.646 +    private:
  87.647 +      void first(const ItemList &il) { l=&il; i = l->begin(); validate(); }
  87.648 +      void next() {
  87.649 +	++i; 
  87.650 +	validate();
  87.651 +      }
  87.652 +      void validate() {
  87.653 +	if ( i == l->end() ) 
  87.654 +	  i = 0;
  87.655 +      }
  87.656 +    };
  87.657 +
  87.658 +
  87.659 +
  87.660 +    /**
  87.661 +     * \brief Sets the iterator to point to the first element of the component.
  87.662 +     * 
  87.663 +     * \anchor first2 
  87.664 +     * Sets the iterator to point to the first element of the component.
  87.665 +     *
  87.666 +     * With the \ref first2 "first", \ref valid2 "valid" 
  87.667 +     * and \ref next2 "next" methods you can
  87.668 +     * iterate through the elements of a component. For example
  87.669 +     * (iterating through the component of the node \e node):
  87.670 +     * \code
  87.671 +     * Graph::Node node = ...;
  87.672 +     * UnionFindEnum<Graph::Node, Graph::NodeMap>::MapType map(G);
  87.673 +     * UnionFindEnum<Graph::Node, Graph::NodeMap> U(map);
  87.674 +     * UnionFindEnum<Graph::Node, Graph::NodeMap>::ItemIt iiter;
  87.675 +     *   for (U.first(iiter, node); U.valid(iiter); U.next(iiter)) {
  87.676 +     *     // iiter is convertible to Graph::Node
  87.677 +     *     cout << iiter << endl;
  87.678 +     *   }
  87.679 +     * \endcode
  87.680 +     */
  87.681 +    
  87.682 +    ItemIt& first(ItemIt& it, const T& a) const {
  87.683 +      it.first( * _find(m[a])->my_class );
  87.684 +      return it;
  87.685 +    }
  87.686 +
  87.687 +    /**
  87.688 +     * \brief Returns whether the iterator is valid.
  87.689 +     *
  87.690 +     * \anchor valid2
  87.691 +     * Returns whether the iterator is valid.
  87.692 +     *
  87.693 +     * With the \ref first2 "first", \ref valid2 "valid" 
  87.694 +     * and \ref next2 "next" methods you can
  87.695 +     * iterate through the elements of a component.
  87.696 +     * See the example here: \ref first2 "first".
  87.697 +     */
  87.698 +
  87.699 +    bool valid(ItemIt const &it) const {
  87.700 +      return it.valid(); 
  87.701 +    }
  87.702 +
  87.703 +    /**
  87.704 +     * \brief Steps the iterator to the next component. 
  87.705 +     *
  87.706 +     * \anchor next2
  87.707 +     * Steps the iterator to the next component.
  87.708 +     *
  87.709 +     * With the \ref first2 "first", \ref valid2 "valid" 
  87.710 +     * and \ref next2 "next" methods you can
  87.711 +     * iterate through the elements of a component.
  87.712 +     * See the example here: \ref first2 "first".
  87.713 +     */
  87.714 +
  87.715 +    ItemIt& next(ItemIt& it) const {
  87.716 +      it.next();
  87.717 +      return it;
  87.718 +    }
  87.719 +    
  87.720 +  };
  87.721 +
  87.722 +
  87.723 +  //! @}
  87.724 +
  87.725 +} //namespace lemon
  87.726 +
  87.727 +#endif //LEMON_UNION_FIND_H
    88.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.2 +++ b/src/lemon/vector_map.h	Wed Sep 29 15:30:04 2004 +0000
    88.3 @@ -0,0 +1,243 @@
    88.4 +/* -*- C++ -*-
    88.5 + * src/lemon/vector_map.h - Part of LEMON, a generic C++ optimization library
    88.6 + *
    88.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    88.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    88.9 + *
   88.10 + * Permission to use, modify and distribute this software is granted
   88.11 + * provided that this copyright notice appears in all copies. For
   88.12 + * precise terms see the accompanying LICENSE file.
   88.13 + *
   88.14 + * This software is provided "AS IS" with no warranty of any kind,
   88.15 + * express or implied, and with no claim as to its suitability for any
   88.16 + * purpose.
   88.17 + *
   88.18 + */
   88.19 +
   88.20 +#ifndef LEMON_VECTOR_MAP_H
   88.21 +#define LEMON_VECTOR_MAP_H
   88.22 +
   88.23 +#include <vector>
   88.24 +
   88.25 +#include <lemon/map_iterator.h>
   88.26 +#include <lemon/map_bits.h>
   88.27 +
   88.28 +///\ingroup graphmaps
   88.29 +///\file
   88.30 +///\brief Vector based graph maps.
   88.31 +
   88.32 +namespace lemon {
   88.33 +  
   88.34 +  /// \addtogroup graphmaps
   88.35 +  /// @{
   88.36 +  
   88.37 +  /** The ArrayMap template class is graph map structure what
   88.38 +   *  automatically updates the map when a key is added to or erased from
   88.39 +   *  the map. This map factory uses the allocators to implement 
   88.40 +   *  the container functionality. This map factory
   88.41 +   *  uses the std::vector to implement the container function.
   88.42 +   *
   88.43 +   *  The template parameter is the MapRegistry that the maps
   88.44 +   *  will belong to and the ValueType.
   88.45 +   * 
   88.46 +   * \todo It should use a faster initialization using the maxNodeId() or
   88.47 +   * maxEdgeId() function of the graph instead of iterating through each
   88.48 +   * edge/node.
   88.49 +   */
   88.50 +	
   88.51 +  template <typename MapRegistry, typename Value>
   88.52 +  class VectorMap : public MapRegistry::MapBase {
   88.53 +    template <typename MR, typename T> friend class VectorMap;
   88.54 +  public:
   88.55 +		
   88.56 +    /// The graph type of the maps. 
   88.57 +    typedef typename MapRegistry::Graph Graph;
   88.58 +    /// The key type of the maps.
   88.59 +    typedef typename MapRegistry::KeyType KeyType;
   88.60 +    /// The iterator to iterate on the keys.
   88.61 +    typedef typename MapRegistry::KeyIt KeyIt;
   88.62 +
   88.63 +    /// The map type.
   88.64 +    typedef VectorMap Map;
   88.65 +    /// The MapBase of the Map which implements the core regisitry function.
   88.66 +    typedef typename MapRegistry::MapBase MapBase;
   88.67 +
   88.68 +  private:
   88.69 +		
   88.70 +    /// The container type of the map.
   88.71 +    typedef std::vector<Value> Container;	
   88.72 +
   88.73 +  public:
   88.74 +
   88.75 +
   88.76 +    /// The value type of the map.
   88.77 +    typedef Value ValueType;
   88.78 +    /// The reference type of the map;
   88.79 +    typedef typename Container::reference ReferenceType;
   88.80 +    /// The pointer type of the map;
   88.81 +    typedef typename Container::pointer PointerType;
   88.82 +
   88.83 +    /// The const value type of the map.
   88.84 +    typedef const Value ConstValueType;
   88.85 +    /// The const reference type of the map;
   88.86 +    typedef typename Container::const_reference ConstReferenceType;
   88.87 +    /// The pointer type of the map;
   88.88 +    typedef typename Container::const_pointer ConstPointerType;
   88.89 +
   88.90 +    /** Graph and Registry initialized map constructor.
   88.91 +     */
   88.92 +    VectorMap(const Graph& g, MapRegistry& r) 
   88.93 +      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
   88.94 +
   88.95 +    /** Constructor to use default value to initialize the map. 
   88.96 +     */
   88.97 +    VectorMap(const Graph& g, MapRegistry& r, const Value& v) 
   88.98 +      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
   88.99 +
  88.100 +    /** Assign operator to copy a map of an other map type.
  88.101 +     */
  88.102 +    template <typename TT>
  88.103 +    VectorMap(const VectorMap<MapRegistry, TT>& c) 
  88.104 +      : MapBase(c), container(c.container.size()) {
  88.105 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  88.106 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  88.107 +	container[id] = c.container[id];
  88.108 +      }
  88.109 +    }
  88.110 +
  88.111 +    /** Assign operator to copy a map of an other map type.
  88.112 +     */
  88.113 +    template <typename TT>
  88.114 +    VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
  88.115 +      if (MapBase::getGraph() != c.getGraph()) {
  88.116 +	MapBase::operator=(c);
  88.117 +	container.resize(c.container.size());
  88.118 +      }
  88.119 +      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
  88.120 +	int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
  88.121 +	container[id] = c.container[id];
  88.122 +      }
  88.123 +      return *this;
  88.124 +    }
  88.125 +    /**
  88.126 +     * The subscript operator. The map can be subscripted by the
  88.127 +     * actual keys of the graph. 
  88.128 +     */
  88.129 +    ReferenceType operator[](const KeyType& key) {
  88.130 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  88.131 +      return container[id];
  88.132 +    } 
  88.133 +		
  88.134 +    /**
  88.135 +     * The const subscript operator. The map can be subscripted by the
  88.136 +     * actual keys of the graph. 
  88.137 +     */
  88.138 +    ConstReferenceType operator[](const KeyType& key) const {
  88.139 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  88.140 +      return container[id];
  88.141 +    }
  88.142 +
  88.143 +    /** Setter function of the map. Equivalent with map[key] = val.
  88.144 +     *  This is a compatibility feature with the not dereferable maps.
  88.145 +     */
  88.146 +    void set(const KeyType& key, const ValueType& val) {
  88.147 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  88.148 +      container[id] = val;
  88.149 +    }
  88.150 +		
  88.151 +    /** Add a new key to the map. It called by the map registry.
  88.152 +     */
  88.153 +    void add(const KeyType& key) {
  88.154 +      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
  88.155 +      if (id >= (int)container.size()) {
  88.156 +	container.resize(id + 1);
  88.157 +      }
  88.158 +    }
  88.159 +		
  88.160 +    /** Erase a key from the map. It called by the map registry.
  88.161 +     */
  88.162 +    void erase(const KeyType& key) {}
  88.163 +
  88.164 +    /** Clear the data structure.
  88.165 +     */
  88.166 +    void clear() { 
  88.167 +      container.clear();
  88.168 +    }
  88.169 +
  88.170 +    /// The stl compatible pair iterator of the map.
  88.171 +    typedef MapIterator<VectorMap> Iterator;
  88.172 +    /// The stl compatible const pair iterator of the map.
  88.173 +    typedef MapConstIterator<VectorMap> ConstIterator;
  88.174 +
  88.175 +    /** Returns the begin iterator of the map.
  88.176 +     */
  88.177 +    Iterator begin() {
  88.178 +      return Iterator(*this, KeyIt(*MapBase::getGraph()));
  88.179 +    }
  88.180 +
  88.181 +    /** Returns the end iterator of the map.
  88.182 +     */
  88.183 +    Iterator end() {
  88.184 +      return Iterator(*this, INVALID);
  88.185 +    }
  88.186 +
  88.187 +    /** Returns the begin ConstIterator of the map.
  88.188 +     */
  88.189 +    ConstIterator begin() const {
  88.190 +      return ConstIterator(*this, KeyIt(*MapBase::getGraph()));
  88.191 +    }
  88.192 +
  88.193 +    /** Returns the end const_iterator of the map.
  88.194 +     */
  88.195 +    ConstIterator end() const {
  88.196 +      return ConstIterator(*this, INVALID);
  88.197 +    }
  88.198 +
  88.199 +    /// The KeySet of the Map.
  88.200 +    typedef MapConstKeySet<VectorMap> ConstKeySet;
  88.201 +
  88.202 +    /// KeySet getter function.
  88.203 +    ConstKeySet keySet() const {
  88.204 +      return ConstKeySet(*this); 
  88.205 +    }
  88.206 +
  88.207 +    /// The ConstValueSet of the Map.
  88.208 +    typedef MapConstValueSet<VectorMap> ConstValueSet;
  88.209 +
  88.210 +    /// ConstValueSet getter function.
  88.211 +    ConstValueSet valueSet() const {
  88.212 +      return ConstValueSet(*this);
  88.213 +    }
  88.214 +
  88.215 +    /// The ValueSet of the Map.
  88.216 +    typedef MapValueSet<VectorMap> ValueSet;
  88.217 +
  88.218 +    /// ValueSet getter function.
  88.219 +    ValueSet valueSet() {
  88.220 +      return ValueSet(*this);
  88.221 +    }
  88.222 +
  88.223 +
  88.224 +  private:
  88.225 +		
  88.226 +    Container container;
  88.227 +
  88.228 +  public:
  88.229 +    // STL  compatibility typedefs.
  88.230 +    typedef Iterator iterator;
  88.231 +    typedef ConstIterator const_iterator;
  88.232 +    typedef typename Iterator::PairValueType value_type;
  88.233 +    typedef typename Iterator::KeyType key_type;
  88.234 +    typedef typename Iterator::ValueType data_type;
  88.235 +    typedef typename Iterator::PairReferenceType reference;
  88.236 +    typedef typename Iterator::PairPointerType pointer;
  88.237 +    typedef typename ConstIterator::PairReferenceType const_reference;
  88.238 +    typedef typename ConstIterator::PairPointerType const_pointer;
  88.239 +    typedef int difference_type;		
  88.240 +  };
  88.241 +  
  88.242 +  /// @}
  88.243 +  
  88.244 +}
  88.245 +
  88.246 +#endif
    89.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    89.2 +++ b/src/lemon/xy.h	Wed Sep 29 15:30:04 2004 +0000
    89.3 @@ -0,0 +1,248 @@
    89.4 +/* -*- C++ -*-
    89.5 + * src/lemon/xy.h - Part of LEMON, a generic C++ optimization library
    89.6 + *
    89.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    89.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    89.9 + *
   89.10 + * Permission to use, modify and distribute this software is granted
   89.11 + * provided that this copyright notice appears in all copies. For
   89.12 + * precise terms see the accompanying LICENSE file.
   89.13 + *
   89.14 + * This software is provided "AS IS" with no warranty of any kind,
   89.15 + * express or implied, and with no claim as to its suitability for any
   89.16 + * purpose.
   89.17 + *
   89.18 + */
   89.19 +
   89.20 +#ifndef LEMON_XY_H
   89.21 +#define LEMON_XY_H
   89.22 +
   89.23 +#include <iostream>
   89.24 +
   89.25 +///\ingroup misc
   89.26 +///\file
   89.27 +///\brief A simple two dimensional vector and a bounding box implementation 
   89.28 +///
   89.29 +/// The class \ref lemon::xy "xy" implements
   89.30 +///a two dimensional vector with the usual
   89.31 +/// operations.
   89.32 +///
   89.33 +/// The class \ref lemon::BoundingBox "BoundingBox" can be used to determine
   89.34 +/// the rectangular bounding box a set of \ref lemon::xy "xy"'s.
   89.35 +///
   89.36 +///\author Attila Bernath
   89.37 +
   89.38 +
   89.39 +namespace lemon {
   89.40 +
   89.41 +  /// \addtogroup misc
   89.42 +  /// @{
   89.43 +
   89.44 +  /// A two dimensional vector (plainvector) implementation
   89.45 +
   89.46 +  /// A two dimensional vector (plainvector) implementation
   89.47 +  ///with the usual vector
   89.48 +  /// operators.
   89.49 +  ///
   89.50 +  ///\author Attila Bernath
   89.51 +  template<typename T>
   89.52 +    class xy {
   89.53 +
   89.54 +    public:
   89.55 +
   89.56 +      T x,y;     
   89.57 +      
   89.58 +      ///Default constructor: both coordinates become 0
   89.59 +      xy() : x(0), y(0) {}
   89.60 +
   89.61 +      ///Constructing the instance from coordinates
   89.62 +      xy(T a, T b) : x(a), y(b) { }
   89.63 +
   89.64 +
   89.65 +      ///Gives back the square of the norm of the vector
   89.66 +      T normSquare(){
   89.67 +	return x*x+y*y;
   89.68 +      };
   89.69 +  
   89.70 +      ///Increments the left hand side by u
   89.71 +      xy<T>& operator +=(const xy<T>& u){
   89.72 +	x += u.x;
   89.73 +	y += u.y;
   89.74 +	return *this;
   89.75 +      };
   89.76 +  
   89.77 +      ///Decrements the left hand side by u
   89.78 +      xy<T>& operator -=(const xy<T>& u){
   89.79 +	x -= u.x;
   89.80 +	y -= u.y;
   89.81 +	return *this;
   89.82 +      };
   89.83 +
   89.84 +      ///Multiplying the left hand side with a scalar
   89.85 +      xy<T>& operator *=(const T &u){
   89.86 +	x *= u;
   89.87 +	y *= u;
   89.88 +	return *this;
   89.89 +      };
   89.90 +
   89.91 +      ///Dividing the left hand side by a scalar
   89.92 +      xy<T>& operator /=(const T &u){
   89.93 +	x /= u;
   89.94 +	y /= u;
   89.95 +	return *this;
   89.96 +      };
   89.97 +  
   89.98 +      ///Returns the scalar product of two vectors
   89.99 +      T operator *(const xy<T>& u){
  89.100 +	return x*u.x+y*u.y;
  89.101 +      };
  89.102 +  
  89.103 +      ///Returns the sum of two vectors
  89.104 +      xy<T> operator+(const xy<T> &u) const {
  89.105 +	xy<T> b=*this;
  89.106 +	return b+=u;
  89.107 +      };
  89.108 +
  89.109 +      ///Returns the difference of two vectors
  89.110 +      xy<T> operator-(const xy<T> &u) const {
  89.111 +	xy<T> b=*this;
  89.112 +	return b-=u;
  89.113 +      };
  89.114 +
  89.115 +      ///Returns a vector multiplied by a scalar
  89.116 +      xy<T> operator*(const T &u) const {
  89.117 +	xy<T> b=*this;
  89.118 +	return b*=u;
  89.119 +      };
  89.120 +
  89.121 +      ///Returns a vector divided by a scalar
  89.122 +      xy<T> operator/(const T &u) const {
  89.123 +	xy<T> b=*this;
  89.124 +	return b/=u;
  89.125 +      };
  89.126 +
  89.127 +      ///Testing equality
  89.128 +      bool operator==(const xy<T> &u){
  89.129 +	return (x==u.x) && (y==u.y);
  89.130 +      };
  89.131 +
  89.132 +      ///Testing inequality
  89.133 +      bool operator!=(xy u){
  89.134 +	return  (x!=u.x) || (y!=u.y);
  89.135 +      };
  89.136 +
  89.137 +    };
  89.138 +
  89.139 +  ///Read a plainvector from a stream
  89.140 +
  89.141 +  ///\relates xy
  89.142 +  ///
  89.143 +  template<typename T>
  89.144 +  inline
  89.145 +  std::istream& operator>>(std::istream &is, xy<T> &z)
  89.146 +  {
  89.147 +
  89.148 +    is >> z.x >> z.y;
  89.149 +    return is;
  89.150 +  }
  89.151 +
  89.152 +  ///Write a plainvector to a stream
  89.153 +
  89.154 +  ///\relates xy
  89.155 +  ///
  89.156 +  template<typename T>
  89.157 +  inline
  89.158 +  std::ostream& operator<<(std::ostream &os, xy<T> z)
  89.159 +  {
  89.160 +    os << "(" << z.x << ", " << z.y << ")";
  89.161 +    return os;
  89.162 +  }
  89.163 +
  89.164 +
  89.165 +  /// A class to calculate or store the bounding box of plainvectors.
  89.166 +
  89.167 +  /// A class to calculate or store the bounding box of plainvectors.
  89.168 +  ///
  89.169 +  ///\author Attila Bernath
  89.170 +  template<typename T>
  89.171 +    class BoundingBox {
  89.172 +      xy<T> bottom_left, top_right;
  89.173 +      bool _empty;
  89.174 +    public:
  89.175 +      
  89.176 +      ///Default constructor: an empty bounding box
  89.177 +      BoundingBox() { _empty = true; }
  89.178 +
  89.179 +      ///Constructing the instance from one point
  89.180 +      BoundingBox(xy<T> a) { bottom_left=top_right=a; _empty = false; }
  89.181 +
  89.182 +      ///Is there any point added
  89.183 +      bool empty() const {
  89.184 +	return _empty;
  89.185 +      }
  89.186 +
  89.187 +      ///Gives back the bottom left corner (if the bounding box is empty, then the return value is not defined) 
  89.188 +      xy<T> bottomLeft() const {
  89.189 +	return bottom_left;
  89.190 +      };
  89.191 +
  89.192 +      ///Gives back the top right corner (if the bounding box is empty, then the return value is not defined) 
  89.193 +      xy<T> topRight() const {
  89.194 +	return top_right;
  89.195 +      };
  89.196 +
  89.197 +      ///Checks whether a point is inside a bounding box
  89.198 +      bool inside(const xy<T>& u){
  89.199 +	if (_empty)
  89.200 +	  return false;
  89.201 +	else{
  89.202 +	  return ((u.x-bottom_left.x)*(top_right.x-u.x) >= 0 &&
  89.203 +		  (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 );
  89.204 +	}
  89.205 +      }
  89.206 +  
  89.207 +      ///Increments a bounding box with a point
  89.208 +      BoundingBox& operator +=(const xy<T>& u){
  89.209 +	if (_empty){
  89.210 +	  bottom_left=top_right=u;
  89.211 +	  _empty = false;
  89.212 +	}
  89.213 +	else{
  89.214 +	  if (bottom_left.x > u.x) bottom_left.x = u.x;
  89.215 +	  if (bottom_left.y > u.y) bottom_left.y = u.y;
  89.216 +	  if (top_right.x < u.x) top_right.x = u.x;
  89.217 +	  if (top_right.y < u.y) top_right.y = u.y;
  89.218 +	}
  89.219 +	return *this;
  89.220 +      };
  89.221 +  
  89.222 +      ///Sums a bounding box and a point
  89.223 +      BoundingBox operator +(const xy<T>& u){
  89.224 +	BoundingBox b = *this;
  89.225 +	return b += u;
  89.226 +      };
  89.227 +
  89.228 +      ///Increments a bounding box with an other bounding box
  89.229 +      BoundingBox& operator +=(const BoundingBox &u){
  89.230 +	if ( !u.empty() ){
  89.231 +	  *this += u.bottomLeft();
  89.232 +	  *this += u.topRight();
  89.233 +	}
  89.234 +	return *this;
  89.235 +      };
  89.236 +  
  89.237 +      ///Sums two bounding boxes
  89.238 +      BoundingBox operator +(const BoundingBox& u){
  89.239 +	BoundingBox b = *this;
  89.240 +	return b += u;
  89.241 +      };
  89.242 +
  89.243 +    };//class Boundingbox
  89.244 +
  89.245 +
  89.246 +  /// @}
  89.247 +
  89.248 +
  89.249 +} //namespace lemon
  89.250 +
  89.251 +#endif //LEMON_XY_H
    90.1 --- a/src/test/bfs_test.cc	Wed Sep 29 14:12:26 2004 +0000
    90.2 +++ b/src/test/bfs_test.cc	Wed Sep 29 15:30:04 2004 +0000
    90.3 @@ -1,5 +1,5 @@
    90.4  /* -*- C++ -*-
    90.5 - * src/test/bfs_test.cc - Part of HUGOlib, a generic C++ optimization library
    90.6 + * src/test/bfs_test.cc - Part of LEMON, a generic C++ optimization library
    90.7   *
    90.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    90.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   90.10 @@ -15,11 +15,11 @@
   90.11   */
   90.12  
   90.13  #include "test_tools.h"
   90.14 -#include <hugo/smart_graph.h>
   90.15 -#include <hugo/bfs.h>
   90.16 -#include<hugo/skeletons/graph.h>
   90.17 +#include <lemon/smart_graph.h>
   90.18 +#include <lemon/bfs.h>
   90.19 +#include<lemon/skeletons/graph.h>
   90.20  
   90.21 -using namespace hugo;
   90.22 +using namespace lemon;
   90.23  
   90.24  const int PET_SIZE =5;
   90.25  
    91.1 --- a/src/test/dfs_test.cc	Wed Sep 29 14:12:26 2004 +0000
    91.2 +++ b/src/test/dfs_test.cc	Wed Sep 29 15:30:04 2004 +0000
    91.3 @@ -1,5 +1,5 @@
    91.4  /* -*- C++ -*-
    91.5 - * src/test/dfs_test.cc - Part of HUGOlib, a generic C++ optimization library
    91.6 + * src/test/dfs_test.cc - Part of LEMON, a generic C++ optimization library
    91.7   *
    91.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    91.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   91.10 @@ -15,11 +15,11 @@
   91.11   */
   91.12  
   91.13  #include "test_tools.h"
   91.14 -#include <hugo/smart_graph.h>
   91.15 -#include <hugo/dfs.h>
   91.16 -#include<hugo/skeletons/graph.h>
   91.17 +#include <lemon/smart_graph.h>
   91.18 +#include <lemon/dfs.h>
   91.19 +#include<lemon/skeletons/graph.h>
   91.20  
   91.21 -using namespace hugo;
   91.22 +using namespace lemon;
   91.23  
   91.24  const int PET_SIZE =5;
   91.25  
    92.1 --- a/src/test/dijkstra_heap_test.cc	Wed Sep 29 14:12:26 2004 +0000
    92.2 +++ b/src/test/dijkstra_heap_test.cc	Wed Sep 29 15:30:04 2004 +0000
    92.3 @@ -1,5 +1,5 @@
    92.4  /* -*- C++ -*-
    92.5 - * src/test/dijkstra_heap_test.cc - Part of HUGOlib, a generic C++ optimization library
    92.6 + * src/test/dijkstra_heap_test.cc - Part of LEMON, a generic C++ optimization library
    92.7   *
    92.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    92.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   92.10 @@ -19,7 +19,7 @@
   92.11  //Fibonacci heap of fib_heap.h.
   92.12  
   92.13  //The input is a graph in standard dimacs format from the standard input (like
   92.14 -//in /hugo_loc/testfiles/dimacs). It runs dijkstra.h on this graph with both
   92.15 +//in /lemon_loc/testfiles/dimacs). It runs dijkstra.h on this graph with both
   92.16  //heaps, checking two postconditions:
   92.17  
   92.18  //- if the edges e=uv of the shortest path tree reported by dijkstra.h have
   92.19 @@ -30,14 +30,14 @@
   92.20  #include <iostream>
   92.21  #include <math.h>
   92.22  
   92.23 -#include <hugo/smart_graph.h>
   92.24 -#include <hugo/dimacs.h>
   92.25 -#include <hugo/dijkstra.h>
   92.26 -#include <hugo/time_measure.h>
   92.27 -#include <hugo/bin_heap.h>
   92.28 -#include <hugo/fib_heap.h>
   92.29 +#include <lemon/smart_graph.h>
   92.30 +#include <lemon/dimacs.h>
   92.31 +#include <lemon/dijkstra.h>
   92.32 +#include <lemon/time_measure.h>
   92.33 +#include <lemon/bin_heap.h>
   92.34 +#include <lemon/fib_heap.h>
   92.35  
   92.36 -using namespace hugo;
   92.37 +using namespace lemon;
   92.38  
   92.39  int main(int, char **) {
   92.40    
    93.1 --- a/src/test/dijkstra_test.cc	Wed Sep 29 14:12:26 2004 +0000
    93.2 +++ b/src/test/dijkstra_test.cc	Wed Sep 29 15:30:04 2004 +0000
    93.3 @@ -1,5 +1,5 @@
    93.4  /* -*- C++ -*-
    93.5 - * src/test/dijkstra_test.cc - Part of HUGOlib, a generic C++ optimization library
    93.6 + * src/test/dijkstra_test.cc - Part of LEMON, a generic C++ optimization library
    93.7   *
    93.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    93.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   93.10 @@ -15,11 +15,11 @@
   93.11   */
   93.12  
   93.13  #include "test_tools.h"
   93.14 -#include <hugo/smart_graph.h>
   93.15 -#include <hugo/dijkstra.h>
   93.16 -#include<hugo/skeletons/graph.h>
   93.17 -#include<hugo/skeletons/maps.h>
   93.18 -using namespace hugo;
   93.19 +#include <lemon/smart_graph.h>
   93.20 +#include <lemon/dijkstra.h>
   93.21 +#include<lemon/skeletons/graph.h>
   93.22 +#include<lemon/skeletons/maps.h>
   93.23 +using namespace lemon;
   93.24  
   93.25  const int PET_SIZE =5;
   93.26  
    94.1 --- a/src/test/error_test.cc	Wed Sep 29 14:12:26 2004 +0000
    94.2 +++ b/src/test/error_test.cc	Wed Sep 29 15:30:04 2004 +0000
    94.3 @@ -1,5 +1,5 @@
    94.4  /* -*- C++ -*-
    94.5 - * src/test/error_test.cc - Part of HUGOlib, a generic C++ optimization library
    94.6 + * src/test/error_test.cc - Part of LEMON, a generic C++ optimization library
    94.7   *
    94.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    94.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   94.10 @@ -16,9 +16,9 @@
   94.11  
   94.12  #include <iostream>
   94.13  
   94.14 -#include <hugo/error.h>
   94.15 +#include <lemon/error.h>
   94.16  #include "test_tools.h"
   94.17 -using namespace hugo;
   94.18 +using namespace lemon;
   94.19  using std::cout;
   94.20  using std::endl;
   94.21  
    95.1 --- a/src/test/graph_test.cc	Wed Sep 29 14:12:26 2004 +0000
    95.2 +++ b/src/test/graph_test.cc	Wed Sep 29 15:30:04 2004 +0000
    95.3 @@ -1,5 +1,5 @@
    95.4  /* -*- C++ -*-
    95.5 - * src/test/graph_test.cc - Part of HUGOlib, a generic C++ optimization library
    95.6 + * src/test/graph_test.cc - Part of LEMON, a generic C++ optimization library
    95.7   *
    95.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    95.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   95.10 @@ -15,10 +15,10 @@
   95.11   */
   95.12  
   95.13  #include<iostream>
   95.14 -#include<hugo/smart_graph.h>
   95.15 -#include<hugo/skeletons/graph.h>
   95.16 -#include<hugo/list_graph.h>
   95.17 -#include<hugo/full_graph.h>
   95.18 +#include<lemon/smart_graph.h>
   95.19 +#include<lemon/skeletons/graph.h>
   95.20 +#include<lemon/list_graph.h>
   95.21 +#include<lemon/full_graph.h>
   95.22  
   95.23  #include"test_tools.h"
   95.24  #include"graph_test.h"
   95.25 @@ -33,7 +33,7 @@
   95.26  conversion.
   95.27  */
   95.28  
   95.29 -using namespace hugo;
   95.30 +using namespace lemon;
   95.31  
   95.32  template<class Graph> void bidirPetersen(Graph &G)
   95.33  {
   95.34 @@ -68,51 +68,51 @@
   95.35  }
   95.36  
   95.37  //Compile Graph
   95.38 -template void hugo::checkCompileStaticGraph<skeleton::StaticGraph>
   95.39 +template void lemon::checkCompileStaticGraph<skeleton::StaticGraph>
   95.40  (skeleton::StaticGraph &);
   95.41  
   95.42 -template void hugo::checkCompileGraph<skeleton::ExtendableGraph>
   95.43 +template void lemon::checkCompileGraph<skeleton::ExtendableGraph>
   95.44  (skeleton::ExtendableGraph &);
   95.45  
   95.46 -template void hugo::checkCompileErasableGraph<skeleton::ErasableGraph>
   95.47 +template void lemon::checkCompileErasableGraph<skeleton::ErasableGraph>
   95.48  (skeleton::ErasableGraph &);
   95.49  
   95.50  //Compile SmartGraph
   95.51 -template void hugo::checkCompileGraph<SmartGraph>(SmartGraph &);
   95.52 -template void hugo::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
   95.53 +template void lemon::checkCompileGraph<SmartGraph>(SmartGraph &);
   95.54 +template void lemon::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
   95.55  
   95.56  //Compile SymSmartGraph
   95.57 -template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
   95.58 -template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
   95.59 +template void lemon::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
   95.60 +template void lemon::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
   95.61  
   95.62  //Compile ListGraph
   95.63 -template void hugo::checkCompileGraph<ListGraph>(ListGraph &);
   95.64 -template void hugo::checkCompileErasableGraph<ListGraph>(ListGraph &);
   95.65 -template void hugo::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
   95.66 +template void lemon::checkCompileGraph<ListGraph>(ListGraph &);
   95.67 +template void lemon::checkCompileErasableGraph<ListGraph>(ListGraph &);
   95.68 +template void lemon::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
   95.69  
   95.70  
   95.71  //Compile SymListGraph
   95.72 -template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &);
   95.73 -template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
   95.74 -template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
   95.75 +template void lemon::checkCompileGraph<SymListGraph>(SymListGraph &);
   95.76 +template void lemon::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
   95.77 +template void lemon::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
   95.78  
   95.79  //Compile FullGraph
   95.80 -template void hugo::checkCompileStaticGraph<FullGraph>(FullGraph &);
   95.81 -template void hugo::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
   95.82 +template void lemon::checkCompileStaticGraph<FullGraph>(FullGraph &);
   95.83 +template void lemon::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
   95.84  
   95.85  //Compile EdgeSet <ListGraph>
   95.86 -template void hugo::checkCompileGraph<EdgeSet <ListGraph> >
   95.87 +template void lemon::checkCompileGraph<EdgeSet <ListGraph> >
   95.88  (EdgeSet <ListGraph> &);
   95.89 -template void hugo::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
   95.90 +template void lemon::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
   95.91  (EdgeSet <ListGraph> &);
   95.92 -template void hugo::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
   95.93 +template void lemon::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
   95.94  (EdgeSet <ListGraph> &);
   95.95  
   95.96  //Compile EdgeSet <NodeSet>
   95.97 -template void hugo::checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
   95.98 -template void hugo::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
   95.99 +template void lemon::checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
  95.100 +template void lemon::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
  95.101  (EdgeSet <NodeSet> &);
  95.102 -template void hugo::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
  95.103 +template void lemon::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
  95.104  (EdgeSet <NodeSet> &);
  95.105  
  95.106  
    96.1 --- a/src/test/graph_test.h	Wed Sep 29 14:12:26 2004 +0000
    96.2 +++ b/src/test/graph_test.h	Wed Sep 29 15:30:04 2004 +0000
    96.3 @@ -1,5 +1,5 @@
    96.4  /* -*- C++ -*-
    96.5 - * src/test/graph_test.h - Part of HUGOlib, a generic C++ optimization library
    96.6 + * src/test/graph_test.h - Part of LEMON, a generic C++ optimization library
    96.7   *
    96.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    96.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   96.10 @@ -13,8 +13,8 @@
   96.11   * purpose.
   96.12   *
   96.13   */
   96.14 -#ifndef HUGO_TEST_GRAPH_TEST_H
   96.15 -#define HUGO_TEST_GRAPH_TEST_H
   96.16 +#ifndef LEMON_TEST_GRAPH_TEST_H
   96.17 +#define LEMON_TEST_GRAPH_TEST_H
   96.18  
   96.19  
   96.20  #include "test_tools.h"
   96.21 @@ -22,7 +22,7 @@
   96.22  //! \ingroup misc
   96.23  //! \file
   96.24  //! \brief Some utility to  test graph classes.
   96.25 -namespace hugo {
   96.26 +namespace lemon {
   96.27  
   96.28    struct DummyType {
   96.29      int value;
   96.30 @@ -319,7 +319,7 @@
   96.31    ///\todo Check head(), tail() as well;
   96.32  
   96.33    
   96.34 -} //namespace hugo
   96.35 +} //namespace lemon
   96.36  
   96.37  
   96.38  #endif
    97.1 --- a/src/test/graph_wrapper_test.cc	Wed Sep 29 14:12:26 2004 +0000
    97.2 +++ b/src/test/graph_wrapper_test.cc	Wed Sep 29 15:30:04 2004 +0000
    97.3 @@ -1,5 +1,5 @@
    97.4  /* -*- C++ -*-
    97.5 - * src/test/graph_wrapper_test.cc - Part of HUGOlib, a generic C++ optimization library
    97.6 + * src/test/graph_wrapper_test.cc - Part of LEMON, a generic C++ optimization library
    97.7   *
    97.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    97.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   97.10 @@ -15,11 +15,11 @@
   97.11   */
   97.12  
   97.13  #include<iostream>
   97.14 -#include<hugo/smart_graph.h>
   97.15 -#include<hugo/skeletons/graph.h>
   97.16 -#include<hugo/list_graph.h>
   97.17 -#include<hugo/full_graph.h>
   97.18 -#include<hugo/graph_wrapper.h>
   97.19 +#include<lemon/smart_graph.h>
   97.20 +#include<lemon/skeletons/graph.h>
   97.21 +#include<lemon/list_graph.h>
   97.22 +#include<lemon/full_graph.h>
   97.23 +#include<lemon/graph_wrapper.h>
   97.24  
   97.25  #include"test/test_tools.h"
   97.26  #include"test/graph_test.h"
   97.27 @@ -31,7 +31,7 @@
   97.28  \todo More extensive tests are needed 
   97.29  */
   97.30  
   97.31 -using namespace hugo;
   97.32 +using namespace lemon;
   97.33  
   97.34  
   97.35  typedef SmartGraph Graph;
    98.1 --- a/src/test/kruskal_test.cc	Wed Sep 29 14:12:26 2004 +0000
    98.2 +++ b/src/test/kruskal_test.cc	Wed Sep 29 15:30:04 2004 +0000
    98.3 @@ -1,5 +1,5 @@
    98.4  /* -*- C++ -*-
    98.5 - * src/test/kruskal_test.cc - Part of HUGOlib, a generic C++ optimization library
    98.6 + * src/test/kruskal_test.cc - Part of LEMON, a generic C++ optimization library
    98.7   *
    98.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    98.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   98.10 @@ -18,15 +18,15 @@
   98.11  #include <vector>
   98.12  
   98.13  #include "test_tools.h"
   98.14 -#include <hugo/maps.h>
   98.15 -#include <hugo/kruskal.h>
   98.16 -#include <hugo/list_graph.h>
   98.17 -#include <hugo/skeletons/maps.h>
   98.18 -#include <hugo/skeletons/graph.h>
   98.19 +#include <lemon/maps.h>
   98.20 +#include <lemon/kruskal.h>
   98.21 +#include <lemon/list_graph.h>
   98.22 +#include <lemon/skeletons/maps.h>
   98.23 +#include <lemon/skeletons/graph.h>
   98.24  
   98.25  
   98.26  using namespace std;
   98.27 -using namespace hugo;
   98.28 +using namespace lemon;
   98.29  
   98.30  void checkCompileKruskal()
   98.31  {
    99.1 --- a/src/test/min_cost_flow_test.cc	Wed Sep 29 14:12:26 2004 +0000
    99.2 +++ b/src/test/min_cost_flow_test.cc	Wed Sep 29 15:30:04 2004 +0000
    99.3 @@ -1,5 +1,5 @@
    99.4  /* -*- C++ -*-
    99.5 - * src/test/min_cost_flow_test.cc - Part of HUGOlib, a generic C++ optimization library
    99.6 + * src/test/min_cost_flow_test.cc - Part of LEMON, a generic C++ optimization library
    99.7   *
    99.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    99.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   99.10 @@ -16,13 +16,13 @@
   99.11  
   99.12  #include <iostream>
   99.13  #include "test_tools.h"
   99.14 -#include <hugo/list_graph.h>
   99.15 -#include <hugo/min_cost_flow.h>
   99.16 +#include <lemon/list_graph.h>
   99.17 +#include <lemon/min_cost_flow.h>
   99.18  //#include <path.h>
   99.19  //#include <maps.h>
   99.20  
   99.21  using namespace std;
   99.22 -using namespace hugo;
   99.23 +using namespace lemon;
   99.24  
   99.25  
   99.26  
   100.1 --- a/src/test/path_test.cc	Wed Sep 29 14:12:26 2004 +0000
   100.2 +++ b/src/test/path_test.cc	Wed Sep 29 15:30:04 2004 +0000
   100.3 @@ -1,5 +1,5 @@
   100.4  /* -*- C++ -*-
   100.5 - * src/test/path_test.cc - Part of HUGOlib, a generic C++ optimization library
   100.6 + * src/test/path_test.cc - Part of LEMON, a generic C++ optimization library
   100.7   *
   100.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   100.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  100.10 @@ -16,12 +16,12 @@
  100.11  
  100.12  #include <string>
  100.13  #include <iostream>
  100.14 -#include <hugo/skeletons/path.h>
  100.15 -#include <hugo/path.h>
  100.16 -#include <hugo/list_graph.h>
  100.17 +#include <lemon/skeletons/path.h>
  100.18 +#include <lemon/path.h>
  100.19 +#include <lemon/list_graph.h>
  100.20  
  100.21  using namespace std;
  100.22 -using namespace hugo;
  100.23 +using namespace lemon;
  100.24  using namespace skeleton;
  100.25  
  100.26  template<class Path> void checkCompilePath(Path &P) 
   101.1 --- a/src/test/preflow_test.cc	Wed Sep 29 14:12:26 2004 +0000
   101.2 +++ b/src/test/preflow_test.cc	Wed Sep 29 15:30:04 2004 +0000
   101.3 @@ -1,5 +1,5 @@
   101.4  /* -*- C++ -*-
   101.5 - * src/test/preflow_test.cc - Part of HUGOlib, a generic C++ optimization library
   101.6 + * src/test/preflow_test.cc - Part of LEMON, a generic C++ optimization library
   101.7   *
   101.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   101.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  101.10 @@ -18,13 +18,13 @@
  101.11  #include <string>
  101.12  
  101.13  #include "test_tools.h"
  101.14 -#include <hugo/smart_graph.h>
  101.15 -#include <hugo/dimacs.h>
  101.16 -#include <hugo/preflow.h>
  101.17 -#include <hugo/skeletons/graph.h>
  101.18 -#include <hugo/skeletons/maps.h>
  101.19 +#include <lemon/smart_graph.h>
  101.20 +#include <lemon/dimacs.h>
  101.21 +#include <lemon/preflow.h>
  101.22 +#include <lemon/skeletons/graph.h>
  101.23 +#include <lemon/skeletons/maps.h>
  101.24  
  101.25 -using namespace hugo;
  101.26 +using namespace lemon;
  101.27  
  101.28  void check_Preflow() 
  101.29  {
   102.1 --- a/src/test/suurballe_test.cc	Wed Sep 29 14:12:26 2004 +0000
   102.2 +++ b/src/test/suurballe_test.cc	Wed Sep 29 15:30:04 2004 +0000
   102.3 @@ -1,5 +1,5 @@
   102.4  /* -*- C++ -*-
   102.5 - * src/test/suurballe_test.cc - Part of HUGOlib, a generic C++ optimization library
   102.6 + * src/test/suurballe_test.cc - Part of LEMON, a generic C++ optimization library
   102.7   *
   102.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   102.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  102.10 @@ -15,13 +15,13 @@
  102.11   */
  102.12  
  102.13  #include <iostream>
  102.14 -#include <hugo/list_graph.h>
  102.15 -#include <hugo/suurballe.h>
  102.16 +#include <lemon/list_graph.h>
  102.17 +#include <lemon/suurballe.h>
  102.18  //#include <path.h>
  102.19  #include "test_tools.h"
  102.20  
  102.21  using namespace std;
  102.22 -using namespace hugo;
  102.23 +using namespace lemon;
  102.24  
  102.25  
  102.26  
   103.1 --- a/src/test/test_tools.h	Wed Sep 29 14:12:26 2004 +0000
   103.2 +++ b/src/test/test_tools.h	Wed Sep 29 15:30:04 2004 +0000
   103.3 @@ -1,5 +1,5 @@
   103.4  /* -*- C++ -*-
   103.5 - * src/test/test_tools.h - Part of HUGOlib, a generic C++ optimization library
   103.6 + * src/test/test_tools.h - Part of LEMON, a generic C++ optimization library
   103.7   *
   103.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   103.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  103.10 @@ -14,8 +14,8 @@
  103.11   *
  103.12   */
  103.13  
  103.14 -#ifndef HUGO_TEST_TEST_TOOLS_H
  103.15 -#define HUGO_TEST_TEST_TOOLS_H
  103.16 +#ifndef LEMON_TEST_TEST_TOOLS_H
  103.17 +#define LEMON_TEST_TEST_TOOLS_H
  103.18  
  103.19  //! \ingroup misc
  103.20  //! \file
   104.1 --- a/src/test/test_tools_fail.cc	Wed Sep 29 14:12:26 2004 +0000
   104.2 +++ b/src/test/test_tools_fail.cc	Wed Sep 29 15:30:04 2004 +0000
   104.3 @@ -1,5 +1,5 @@
   104.4  /* -*- C++ -*-
   104.5 - * src/test/test_tools_fail.cc - Part of HUGOlib, a generic C++ optimization library
   104.6 + * src/test/test_tools_fail.cc - Part of LEMON, a generic C++ optimization library
   104.7   *
   104.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   104.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   105.1 --- a/src/test/test_tools_pass.cc	Wed Sep 29 14:12:26 2004 +0000
   105.2 +++ b/src/test/test_tools_pass.cc	Wed Sep 29 15:30:04 2004 +0000
   105.3 @@ -1,5 +1,5 @@
   105.4  /* -*- C++ -*-
   105.5 - * src/test/test_tools_pass.cc - Part of HUGOlib, a generic C++ optimization library
   105.6 + * src/test/test_tools_pass.cc - Part of LEMON, a generic C++ optimization library
   105.7   *
   105.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   105.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
   106.1 --- a/src/test/time_measure_test.cc	Wed Sep 29 14:12:26 2004 +0000
   106.2 +++ b/src/test/time_measure_test.cc	Wed Sep 29 15:30:04 2004 +0000
   106.3 @@ -1,5 +1,5 @@
   106.4  /* -*- C++ -*-
   106.5 - * src/test/time_measure_test.cc - Part of HUGOlib, a generic C++ optimization library
   106.6 + * src/test/time_measure_test.cc - Part of LEMON, a generic C++ optimization library
   106.7   *
   106.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   106.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  106.10 @@ -14,14 +14,14 @@
  106.11   *
  106.12   */
  106.13  
  106.14 -#include <hugo/time_measure.h>
  106.15 +#include <lemon/time_measure.h>
  106.16  
  106.17  ///\file \brief Test cases for time_measure.h
  106.18  ///
  106.19  ///\todo To be extended
  106.20  
  106.21  
  106.22 -using namespace hugo;
  106.23 +using namespace lemon;
  106.24  
  106.25  int main()
  106.26  {
   107.1 --- a/src/test/unionfind_test.cc	Wed Sep 29 14:12:26 2004 +0000
   107.2 +++ b/src/test/unionfind_test.cc	Wed Sep 29 15:30:04 2004 +0000
   107.3 @@ -1,5 +1,5 @@
   107.4  /* -*- C++ -*-
   107.5 - * src/test/unionfind_test.cc - Part of HUGOlib, a generic C++ optimization library
   107.6 + * src/test/unionfind_test.cc - Part of LEMON, a generic C++ optimization library
   107.7   *
   107.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   107.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  107.10 @@ -16,11 +16,11 @@
  107.11  
  107.12  #include <iostream>
  107.13  
  107.14 -#include <hugo/maps.h>
  107.15 -#include <hugo/unionfind.h>
  107.16 +#include <lemon/maps.h>
  107.17 +#include <lemon/unionfind.h>
  107.18  #include "test_tools.h"
  107.19  
  107.20 -using namespace hugo;
  107.21 +using namespace lemon;
  107.22  using namespace std;
  107.23  
  107.24  template <typename T>
   108.1 --- a/src/test/xy_test.cc	Wed Sep 29 14:12:26 2004 +0000
   108.2 +++ b/src/test/xy_test.cc	Wed Sep 29 15:30:04 2004 +0000
   108.3 @@ -1,5 +1,5 @@
   108.4  /* -*- C++ -*-
   108.5 - * src/test/xy_test.cc - Part of HUGOlib, a generic C++ optimization library
   108.6 + * src/test/xy_test.cc - Part of LEMON, a generic C++ optimization library
   108.7   *
   108.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   108.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  108.10 @@ -14,12 +14,12 @@
  108.11   *
  108.12   */
  108.13  
  108.14 -#include <hugo/xy.h>
  108.15 +#include <lemon/xy.h>
  108.16  #include <iostream>
  108.17  #include "test_tools.h"
  108.18  
  108.19  using namespace std;
  108.20 -using namespace hugo;
  108.21 +using namespace lemon;
  108.22  int main()
  108.23  {
  108.24  
   109.1 --- a/src/work/akos/loader_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   109.2 +++ b/src/work/akos/loader_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   109.3 @@ -4,7 +4,7 @@
   109.4  #include <bfs_iterator.hh>
   109.5  #include <loader.h>
   109.6  
   109.7 -using namespace hugo;
   109.8 +using namespace lemon;
   109.9  
  109.10  int main(int, char **) {
  109.11    typedef ListGraph::NodeIt NodeIt;
   110.1 --- a/src/work/alpar/bfs-named-param.cc	Wed Sep 29 14:12:26 2004 +0000
   110.2 +++ b/src/work/alpar/bfs-named-param.cc	Wed Sep 29 15:30:04 2004 +0000
   110.3 @@ -1,11 +1,11 @@
   110.4  // -*- mode:C++ -*-
   110.5  
   110.6 -#include <hugo/smart_graph.h>
   110.7 -#include <hugo/maps.h>
   110.8 +#include <lemon/smart_graph.h>
   110.9 +#include <lemon/maps.h>
  110.10  #include <vector>
  110.11  #include <iostream>
  110.12  
  110.13 -using namespace hugo;
  110.14 +using namespace lemon;
  110.15  
  110.16  struct _BFS_DEFAULT_VIS {};
  110.17  struct _BFS_CUSTOM_VIS {};
   111.1 --- a/src/work/alpar/boolmap_iter.cc	Wed Sep 29 14:12:26 2004 +0000
   111.2 +++ b/src/work/alpar/boolmap_iter.cc	Wed Sep 29 15:30:04 2004 +0000
   111.3 @@ -2,7 +2,7 @@
   111.4  #include <vector>
   111.5  #include <smart_graph.h>
   111.6  
   111.7 -using namespace hugo;
   111.8 +using namespace lemon;
   111.9  
  111.10  ///\todo This is only a static map!
  111.11  ///
   112.1 --- a/src/work/alpar/f_ed_ka.h	Wed Sep 29 14:12:26 2004 +0000
   112.2 +++ b/src/work/alpar/f_ed_ka.h	Wed Sep 29 15:30:04 2004 +0000
   112.3 @@ -11,7 +11,7 @@
   112.4  
   112.5  //#include <bfs_iterator.hh>
   112.6  
   112.7 -namespace hugo {
   112.8 +namespace lemon {
   112.9    template <typename Graph, typename FlowMap, typename CapacityMap>
  112.10    typename FlowMap::ValueType maxFlow(Graph &G,
  112.11  				      FlowMap &f,
  112.12 @@ -114,6 +114,6 @@
  112.13      goto augment;   // Vivat goto forever!
  112.14    }
  112.15    
  112.16 -} // namespace hugo
  112.17 +} // namespace lemon
  112.18  
  112.19  #endif //EDMONDS_KARP_HH
   113.1 --- a/src/work/alpar/f_ed_ka_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   113.2 +++ b/src/work/alpar/f_ed_ka_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   113.3 @@ -8,7 +8,7 @@
   113.4  #include "f_ed_ka.h"
   113.5  #include "../marci/time_measure.h"
   113.6  
   113.7 -using namespace hugo;
   113.8 +using namespace lemon;
   113.9  
  113.10  // Use a DIMACS max flow file as stdin.
  113.11  // read_dimacs_demo < dimacs_max_flow_file
   114.1 --- a/src/work/alpar/gwrapper.h	Wed Sep 29 14:12:26 2004 +0000
   114.2 +++ b/src/work/alpar/gwrapper.h	Wed Sep 29 15:30:04 2004 +0000
   114.3 @@ -2,7 +2,7 @@
   114.4  #ifndef GRAPH_WRAPPER_H
   114.5  #define GRAPH_WRAPPER_H
   114.6  
   114.7 -namespace hugo {
   114.8 +namespace lemon {
   114.9  
  114.10  template<typename G>
  114.11  class TrivGraphWrapper
   115.1 --- a/src/work/alpar/list_graph_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   115.2 +++ b/src/work/alpar/list_graph_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   115.3 @@ -4,7 +4,7 @@
   115.4  #include <iostream>
   115.5  #include <vector>
   115.6  
   115.7 -using namespace hugo;
   115.8 +using namespace lemon;
   115.9  
  115.10  typedef ListGraph Graph;
  115.11  //typedef Graph Graph;
   116.1 --- a/src/work/alpar/rw_nonref_map.cc	Wed Sep 29 14:12:26 2004 +0000
   116.2 +++ b/src/work/alpar/rw_nonref_map.cc	Wed Sep 29 15:30:04 2004 +0000
   116.3 @@ -1,7 +1,7 @@
   116.4  #include <iostream>
   116.5  #include <smart_graph.h>
   116.6  
   116.7 -using namespace hugo;
   116.8 +using namespace lemon;
   116.9  
  116.10  template<class GG,class TT>
  116.11  class CinCoutMap
   117.1 --- a/src/work/alpar/smart_graph_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   117.2 +++ b/src/work/alpar/smart_graph_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   117.3 @@ -4,7 +4,7 @@
   117.4  #include <iostream>
   117.5  #include <vector>
   117.6  
   117.7 -using namespace hugo;
   117.8 +using namespace lemon;
   117.9  
  117.10  typedef SmartGraph Graph;
  117.11  //typedef Graph Graph;
   118.1 --- a/src/work/athos/bfs_test.cc	Wed Sep 29 14:12:26 2004 +0000
   118.2 +++ b/src/work/athos/bfs_test.cc	Wed Sep 29 15:30:04 2004 +0000
   118.3 @@ -4,12 +4,12 @@
   118.4  
   118.5  #include <sage_graph.h>
   118.6  //#include <smart_graph.h>
   118.7 -#include <hugo/dimacs.h>
   118.8 -#include <hugo/time_measure.h>
   118.9 -#include <hugo/for_each_macros.h>
  118.10 +#include <lemon/dimacs.h>
  118.11 +#include <lemon/time_measure.h>
  118.12 +#include <lemon/for_each_macros.h>
  118.13  #include <bfs_dfs.h>
  118.14  
  118.15 -using namespace hugo;
  118.16 +using namespace lemon;
  118.17  
  118.18  int main() {
  118.19    typedef SageGraph Graph; 
   119.1 --- a/src/work/athos/dijkstra_at.h	Wed Sep 29 14:12:26 2004 +0000
   119.2 +++ b/src/work/athos/dijkstra_at.h	Wed Sep 29 15:30:04 2004 +0000
   119.3 @@ -24,7 +24,7 @@
   119.4  
   119.5  using namespace std;
   119.6  
   119.7 -namespace hugo {
   119.8 +namespace lemon {
   119.9  
  119.10    template <typename graph_type, typename T>
  119.11    class dijkstra_at {
  119.12 @@ -118,6 +118,6 @@
  119.13    };  //class dijkstra_at  
  119.14  
  119.15  
  119.16 -}//namespace hugo
  119.17 +}//namespace lemon
  119.18  
  119.19  #endif //DIJKSTRA_AT
   120.1 --- a/src/work/athos/dijkstra_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   120.2 +++ b/src/work/athos/dijkstra_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   120.3 @@ -5,7 +5,7 @@
   120.4  //#include "marci_property_vector.hh"
   120.5  #include <dijkstra_at.h>
   120.6  
   120.7 -using namespace hugo;
   120.8 +using namespace lemon;
   120.9  
  120.10  
  120.11  int main (int, char*[])
   121.1 --- a/src/work/athos/kruskal.h	Wed Sep 29 14:12:26 2004 +0000
   121.2 +++ b/src/work/athos/kruskal.h	Wed Sep 29 15:30:04 2004 +0000
   121.3 @@ -7,7 +7,7 @@
   121.4  
   121.5  #include <union_find.h>
   121.6  
   121.7 -namespace hugo {
   121.8 +namespace lemon {
   121.9    
  121.10    template <typename graph_type, typename T>
  121.11      class Kruskal {
  121.12 @@ -56,6 +56,6 @@
  121.13       
  121.14    }
  121.15  
  121.16 -}//namespacc hugo
  121.17 +}//namespacc lemon
  121.18  
  121.19  #endif
   122.1 --- a/src/work/athos/min_cost_flow.cc	Wed Sep 29 14:12:26 2004 +0000
   122.2 +++ b/src/work/athos/min_cost_flow.cc	Wed Sep 29 15:30:04 2004 +0000
   122.3 @@ -1,12 +1,12 @@
   122.4  #include <iostream>
   122.5  //#include "test_tools.h"
   122.6 -#include <hugo/list_graph.h>
   122.7 +#include <lemon/list_graph.h>
   122.8  #include <mincostflow.h>
   122.9  //#include <path.h>
  122.10  //#include <maps.h>
  122.11  
  122.12  using namespace std;
  122.13 -using namespace hugo;
  122.14 +using namespace lemon;
  122.15  
  122.16  
  122.17  
   123.1 --- a/src/work/athos/mincostflow.h	Wed Sep 29 14:12:26 2004 +0000
   123.2 +++ b/src/work/athos/mincostflow.h	Wed Sep 29 15:30:04 2004 +0000
   123.3 @@ -1,23 +1,23 @@
   123.4  // -*- c++ -*-
   123.5 -#ifndef HUGO_MINCOSTFLOW_H
   123.6 -#define HUGO_MINCOSTFLOW_H
   123.7 +#ifndef LEMON_MINCOSTFLOW_H
   123.8 +#define LEMON_MINCOSTFLOW_H
   123.9  
  123.10  ///\ingroup galgs
  123.11  ///\file
  123.12  ///\brief An algorithm for finding the minimum cost flow of given value in an uncapacitated network
  123.13  
  123.14 -#include <hugo/dijkstra.h>
  123.15 -#include <hugo/graph_wrapper.h>
  123.16 -#include <hugo/maps.h>
  123.17 +#include <lemon/dijkstra.h>
  123.18 +#include <lemon/graph_wrapper.h>
  123.19 +#include <lemon/maps.h>
  123.20  #include <vector>
  123.21  #include <list>
  123.22  #include <values.h>
  123.23 -#include <hugo/for_each_macros.h>
  123.24 -#include <hugo/unionfind.h>
  123.25 -#include <hugo/bin_heap.h>
  123.26 +#include <lemon/for_each_macros.h>
  123.27 +#include <lemon/unionfind.h>
  123.28 +#include <lemon/bin_heap.h>
  123.29  #include <bfs_dfs.h>
  123.30  
  123.31 -namespace hugo {
  123.32 +namespace lemon {
  123.33  
  123.34  /// \addtogroup galgs
  123.35  /// @{
  123.36 @@ -26,7 +26,7 @@
  123.37    /// flow problem in an uncapacitated network
  123.38    /// 
  123.39    ///
  123.40 -  /// The class \ref hugo::MinCostFlow "MinCostFlow" implements
  123.41 +  /// The class \ref lemon::MinCostFlow "MinCostFlow" implements
  123.42    /// an algorithm for solving the following general minimum cost flow problem>
  123.43    /// 
  123.44    ///
  123.45 @@ -508,6 +508,6 @@
  123.46  
  123.47    ///@}
  123.48  
  123.49 -} //namespace hugo
  123.50 +} //namespace lemon
  123.51  
  123.52 -#endif //HUGO_MINCOSTFLOW_H
  123.53 +#endif //LEMON_MINCOSTFLOW_H
   124.1 --- a/src/work/athos/minlength_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   124.2 +++ b/src/work/athos/minlength_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   124.3 @@ -2,12 +2,12 @@
   124.4  #include <fstream>
   124.5  
   124.6  #include <list_graph.h>
   124.7 -#include <hugo/dimacs.h>
   124.8 -#include <hugo/time_measure.h>
   124.9 +#include <lemon/dimacs.h>
  124.10 +#include <lemon/time_measure.h>
  124.11  #include "minlengthpaths.h"
  124.12  //#include <time_measure.h>
  124.13  
  124.14 -using namespace hugo;
  124.15 +using namespace lemon;
  124.16  
  124.17  // Use a DIMACS max flow file as stdin.
  124.18  // read_dimacs_demo < dimacs_max_flow_file
   125.1 --- a/src/work/athos/old/minlengthpaths.h	Wed Sep 29 14:12:26 2004 +0000
   125.2 +++ b/src/work/athos/old/minlengthpaths.h	Wed Sep 29 15:30:04 2004 +0000
   125.3 @@ -1,19 +1,19 @@
   125.4  // -*- c++ -*-
   125.5 -#ifndef HUGO_MINLENGTHPATHS_H
   125.6 -#define HUGO_MINLENGTHPATHS_H
   125.7 +#ifndef LEMON_MINLENGTHPATHS_H
   125.8 +#define LEMON_MINLENGTHPATHS_H
   125.9  
  125.10  ///\ingroup galgs
  125.11  ///\file
  125.12  ///\brief An algorithm for finding k paths of minimal total length.
  125.13  
  125.14  #include <iostream>
  125.15 -#include <hugo/dijkstra.h>
  125.16 -#include <hugo/graph_wrapper.h>
  125.17 -#include <hugo/maps.h>
  125.18 +#include <lemon/dijkstra.h>
  125.19 +#include <lemon/graph_wrapper.h>
  125.20 +#include <lemon/maps.h>
  125.21  #include <vector>
  125.22  
  125.23  
  125.24 -namespace hugo {
  125.25 +namespace lemon {
  125.26  
  125.27  /// \addtogroup galgs
  125.28  /// @{
  125.29 @@ -21,7 +21,7 @@
  125.30    ///\brief Implementation of an algorithm for finding k paths between 2 nodes 
  125.31    /// of minimal total length 
  125.32    ///
  125.33 -  /// The class \ref hugo::MinLengthPaths "MinLengthPaths" implements
  125.34 +  /// The class \ref lemon::MinLengthPaths "MinLengthPaths" implements
  125.35    /// an algorithm for finding k edge-disjoint paths
  125.36    /// from a given source node to a given target node in an
  125.37    /// edge-weighted directed graph having minimal total weigth (length).
  125.38 @@ -197,6 +197,6 @@
  125.39  
  125.40    ///@}
  125.41  
  125.42 -} //namespace hugo
  125.43 +} //namespace lemon
  125.44  
  125.45 -#endif //HUGO_MINLENGTHPATHS_H
  125.46 +#endif //LEMON_MINLENGTHPATHS_H
   126.1 --- a/src/work/athos/pf_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   126.2 +++ b/src/work/athos/pf_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   126.3 @@ -7,7 +7,7 @@
   126.4  //#include "marci_property_vector.hh"
   126.5  #include "preflow_push.hh"
   126.6  
   126.7 -using namespace hugo;
   126.8 +using namespace lemon;
   126.9  
  126.10  
  126.11  int main (int, char*[])
   127.1 --- a/src/work/athos/preflow_push_wogw.h	Wed Sep 29 14:12:26 2004 +0000
   127.2 +++ b/src/work/athos/preflow_push_wogw.h	Wed Sep 29 15:30:04 2004 +0000
   127.3 @@ -1,5 +1,5 @@
   127.4 -#ifndef HUGO_PREFLOW_PUSH_HH
   127.5 -#define HUGO_PREFLOW_PUSH_HH
   127.6 +#ifndef LEMON_PREFLOW_PUSH_HH
   127.7 +#define LEMON_PREFLOW_PUSH_HH
   127.8  
   127.9  //#include <algorithm>
  127.10  #include <list>
  127.11 @@ -13,7 +13,7 @@
  127.12  
  127.13  using namespace std;
  127.14  
  127.15 -namespace hugo {
  127.16 +namespace lemon {
  127.17  
  127.18    template <typename Graph, typename T>
  127.19    class preflow_push {
  127.20 @@ -458,6 +458,6 @@
  127.21    }//run
  127.22  
  127.23  
  127.24 -}//namespace hugo
  127.25 +}//namespace lemon
  127.26  
  127.27  #endif //PREFLOW_PUSH_HH
   128.1 --- a/src/work/athos/suurballe.cc	Wed Sep 29 14:12:26 2004 +0000
   128.2 +++ b/src/work/athos/suurballe.cc	Wed Sep 29 15:30:04 2004 +0000
   128.3 @@ -6,7 +6,7 @@
   128.4  #include <list_graph.h>
   128.5  #include <minlengthpaths.h>
   128.6  
   128.7 -using namespace hugo;
   128.8 +using namespace lemon;
   128.9  
  128.10  
  128.11  int main()
   129.1 --- a/src/work/athos/uf_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   129.2 +++ b/src/work/athos/uf_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   129.3 @@ -4,7 +4,7 @@
   129.4  #include <union_find.h>
   129.5  #include <iostream>
   129.6  #include <list_graph.hh>
   129.7 -using namespace hugo;
   129.8 +using namespace lemon;
   129.9  using namespace std;
  129.10  
  129.11  int main (int, char*[])
   130.1 --- a/src/work/athos/union_find.h	Wed Sep 29 14:12:26 2004 +0000
   130.2 +++ b/src/work/athos/union_find.h	Wed Sep 29 15:30:04 2004 +0000
   130.3 @@ -13,7 +13,7 @@
   130.4  //#include <map>
   130.5  
   130.6  
   130.7 -namespace hugo {
   130.8 +namespace lemon {
   130.9    
  130.10    template <typename KeyType, typename KeyIntMap>
  130.11      class UnionFind {
  130.12 @@ -90,5 +90,5 @@
  130.13      }//unio
  130.14    };
  130.15    
  130.16 -}//namespace hugo
  130.17 +}//namespace lemon
  130.18  #endif
   131.1 --- a/src/work/athos/xy/boundingbox.cc	Wed Sep 29 14:12:26 2004 +0000
   131.2 +++ b/src/work/athos/xy/boundingbox.cc	Wed Sep 29 15:30:04 2004 +0000
   131.3 @@ -2,7 +2,7 @@
   131.4  
   131.5  #include <iostream>
   131.6  using namespace std;
   131.7 -using namespace hugo;
   131.8 +using namespace lemon;
   131.9  int main()
  131.10  {
  131.11  	xy<int> z;
   132.1 --- a/src/work/athos/xy/xy.cc	Wed Sep 29 14:12:26 2004 +0000
   132.2 +++ b/src/work/athos/xy/xy.cc	Wed Sep 29 15:30:04 2004 +0000
   132.3 @@ -2,7 +2,7 @@
   132.4  #include <iostream>
   132.5  #include <vector>
   132.6  using namespace std;
   132.7 -using namespace hugo;
   132.8 +using namespace lemon;
   132.9  
  132.10  
  132.11  int main()
   133.1 --- a/src/work/bin_heap_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   133.2 +++ b/src/work/bin_heap_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   133.3 @@ -2,9 +2,9 @@
   133.4  #include <string>
   133.5  #include <map>
   133.6  
   133.7 -#include <hugo/bin_heap.h>
   133.8 +#include <lemon/bin_heap.h>
   133.9  
  133.10 -using namespace hugo;
  133.11 +using namespace lemon;
  133.12  using namespace std;
  133.13  
  133.14  class string_int_map;
   134.1 --- a/src/work/deba/array_map_factory.h	Wed Sep 29 14:12:26 2004 +0000
   134.2 +++ b/src/work/deba/array_map_factory.h	Wed Sep 29 15:30:04 2004 +0000
   134.3 @@ -6,7 +6,7 @@
   134.4  
   134.5  #include "extended_pair.h"
   134.6  
   134.7 -namespace hugo {
   134.8 +namespace lemon {
   134.9  	
  134.10    template <typename MapRegistry> class ArrayMapFactory {
  134.11  		
   135.1 --- a/src/work/deba/bin_heap.h	Wed Sep 29 14:12:26 2004 +0000
   135.2 +++ b/src/work/deba/bin_heap.h	Wed Sep 29 15:30:04 2004 +0000
   135.3 @@ -58,8 +58,8 @@
   135.4   */
   135.5  
   135.6  
   135.7 -#ifndef HUGO_BIN_HEAP_H
   135.8 -#define HUGO_BIN_HEAP_H
   135.9 +#ifndef LEMON_BIN_HEAP_H
  135.10 +#define LEMON_BIN_HEAP_H
  135.11  
  135.12  ///\ingroup auxdat
  135.13  ///\file
  135.14 @@ -69,7 +69,7 @@
  135.15  #include <utility>
  135.16  #include <functional>
  135.17  
  135.18 -namespace hugo {
  135.19 +namespace lemon {
  135.20  
  135.21    /// \addtogroup auxdat
  135.22    /// @{
  135.23 @@ -241,6 +241,6 @@
  135.24  
  135.25    ///@}
  135.26  
  135.27 -} // namespace hugo
  135.28 +} // namespace lemon
  135.29  
  135.30  #endif // BIN_HEAP_HH
   136.1 --- a/src/work/deba/dijkstra.h	Wed Sep 29 14:12:26 2004 +0000
   136.2 +++ b/src/work/deba/dijkstra.h	Wed Sep 29 15:30:04 2004 +0000
   136.3 @@ -1,15 +1,15 @@
   136.4  // -*- C++ -*-
   136.5 -#ifndef HUGO_DIJKSTRA_H
   136.6 -#define HUGO_DIJKSTRA_H
   136.7 +#ifndef LEMON_DIJKSTRA_H
   136.8 +#define LEMON_DIJKSTRA_H
   136.9  
  136.10  ///\ingroup galgs
  136.11  ///\file
  136.12  ///\brief Dijkstra algorithm.
  136.13  
  136.14 -#include <hugo/bin_heap.h>
  136.15 -#include <hugo/invalid.h>
  136.16 +#include <lemon/bin_heap.h>
  136.17 +#include <lemon/invalid.h>
  136.18  
  136.19 -namespace hugo {
  136.20 +namespace lemon {
  136.21  
  136.22  /// \addtogroup galgs
  136.23  /// @{
  136.24 @@ -322,7 +322,7 @@
  136.25  
  136.26  /// @}
  136.27    
  136.28 -} //END OF NAMESPACE HUGO
  136.29 +} //END OF NAMESPACE LEMON
  136.30  
  136.31  #endif
  136.32  
   137.1 --- a/src/work/deba/invalid.h	Wed Sep 29 14:12:26 2004 +0000
   137.2 +++ b/src/work/deba/invalid.h	Wed Sep 29 15:30:04 2004 +0000
   137.3 @@ -1,12 +1,12 @@
   137.4  // -*- mode:C++ -*-
   137.5  
   137.6 -#ifndef HUGO_INVALID_H
   137.7 -#define HUGO_INVALID_H
   137.8 +#ifndef LEMON_INVALID_H
   137.9 +#define LEMON_INVALID_H
  137.10  
  137.11  ///\file
  137.12  ///\brief Definition of INVALID.
  137.13  
  137.14 -namespace hugo {
  137.15 +namespace lemon {
  137.16  
  137.17    /// Dummy type to make it easier to make invalid iterators.
  137.18    
  137.19 @@ -32,7 +32,7 @@
  137.20    //const Invalid &INVALID = *(Invalid *)0;
  137.21    const Invalid INVALID = Invalid();
  137.22  
  137.23 -} //namespace hugo
  137.24 +} //namespace lemon
  137.25  
  137.26  #endif
  137.27    
   138.1 --- a/src/work/deba/list_graph.h	Wed Sep 29 14:12:26 2004 +0000
   138.2 +++ b/src/work/deba/list_graph.h	Wed Sep 29 15:30:04 2004 +0000
   138.3 @@ -1,7 +1,7 @@
   138.4  // -*- mode:C++ -*-
   138.5  
   138.6 -#ifndef HUGO_LIST_GRAPH_H
   138.7 -#define HUGO_LIST_GRAPH_H
   138.8 +#ifndef LEMON_LIST_GRAPH_H
   138.9 +#define LEMON_LIST_GRAPH_H
  138.10  
  138.11  ///\ingroup graphs
  138.12  ///\file
  138.13 @@ -17,7 +17,7 @@
  138.14  
  138.15  #include "map_defines.h"
  138.16  
  138.17 -namespace hugo {
  138.18 +namespace lemon {
  138.19  
  138.20  /// \addtogroup graphs
  138.21  /// @{
  138.22 @@ -396,4 +396,4 @@
  138.23  
  138.24  }
  138.25  
  138.26 -#endif //HUGO_LIST_GRAPH_H
  138.27 +#endif //LEMON_LIST_GRAPH_H
   139.1 --- a/src/work/deba/map_registry.h	Wed Sep 29 14:12:26 2004 +0000
   139.2 +++ b/src/work/deba/map_registry.h	Wed Sep 29 15:30:04 2004 +0000
   139.3 @@ -5,7 +5,7 @@
   139.4  
   139.5  using namespace std;
   139.6  
   139.7 -namespace hugo {
   139.8 +namespace lemon {
   139.9  
  139.10  /** 
  139.11   * Registry class to register edge or node maps into the graph. The
   140.1 --- a/src/work/deba/pac_map_factory.h	Wed Sep 29 14:12:26 2004 +0000
   140.2 +++ b/src/work/deba/pac_map_factory.h	Wed Sep 29 15:30:04 2004 +0000
   140.3 @@ -8,7 +8,7 @@
   140.4  	libary's pair associative containers as a graph map.
   140.5  */
   140.6  
   140.7 -namespace hugo {
   140.8 +namespace lemon {
   140.9  	
  140.10  	template <typename G, typename K, typename KIt, template <typename, typename> class PAC>
  140.11  	class PacMapFactory {
   141.1 --- a/src/work/deba/vector_map_factory.h	Wed Sep 29 14:12:26 2004 +0000
   141.2 +++ b/src/work/deba/vector_map_factory.h	Wed Sep 29 15:30:04 2004 +0000
   141.3 @@ -6,7 +6,7 @@
   141.4  
   141.5  #include "extended_pair.h"
   141.6  
   141.7 -namespace hugo {
   141.8 +namespace lemon {
   141.9  
  141.10    /** The VectorMapFactory template class is a factory class
  141.11     *  to create maps for the edge and nodes. This map factory
   142.1 --- a/src/work/iterator_bfs_dfs_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   142.2 +++ b/src/work/iterator_bfs_dfs_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   142.3 @@ -5,7 +5,7 @@
   142.4  #include <list_graph.hh>
   142.5  #include <bfs_iterator.hh>
   142.6  
   142.7 -using namespace hugo;
   142.8 +using namespace lemon;
   142.9  
  142.10  int main (int, char*[])
  142.11  {
   143.1 --- a/src/work/jacint/graph_gen.h	Wed Sep 29 14:12:26 2004 +0000
   143.2 +++ b/src/work/jacint/graph_gen.h	Wed Sep 29 15:30:04 2004 +0000
   143.3 @@ -10,7 +10,7 @@
   143.4  ///
   143.5  // ///\author Marton Makai
   143.6  
   143.7 -namespace hugo {
   143.8 +namespace lemon {
   143.9  
  143.10  
  143.11    /**
  143.12 @@ -117,4 +117,4 @@
  143.13  	g.addEdge(s_nodes[i], t_nodes[j]);
  143.14    }
  143.15    
  143.16 -} //namespace hugo
  143.17 +} //namespace lemon
   144.1 --- a/src/work/jacint/ledacomp.cc	Wed Sep 29 14:12:26 2004 +0000
   144.2 +++ b/src/work/jacint/ledacomp.cc	Wed Sep 29 15:30:04 2004 +0000
   144.3 @@ -41,7 +41,7 @@
   144.4  //   return int( double(m) * rand() / (RAND_MAX + 1.0) );
   144.5  // }
   144.6  
   144.7 -using namespace hugo;
   144.8 +using namespace lemon;
   144.9  
  144.10  int main() {
  144.11  
   145.1 --- a/src/work/jacint/max_flow.h	Wed Sep 29 14:12:26 2004 +0000
   145.2 +++ b/src/work/jacint/max_flow.h	Wed Sep 29 15:30:04 2004 +0000
   145.3 @@ -1,22 +1,22 @@
   145.4  // -*- C++ -*-
   145.5 -#ifndef HUGO_MAX_FLOW_H
   145.6 -#define HUGO_MAX_FLOW_H
   145.7 +#ifndef LEMON_MAX_FLOW_H
   145.8 +#define LEMON_MAX_FLOW_H
   145.9  
  145.10  #include <vector>
  145.11  #include <queue>
  145.12  #include <stack>
  145.13  
  145.14 -#include <hugo/graph_wrapper.h>
  145.15 +#include <lemon/graph_wrapper.h>
  145.16  #include <bfs_dfs.h>
  145.17 -#include <hugo/invalid.h>
  145.18 -#include <hugo/maps.h>
  145.19 -#include <hugo/for_each_macros.h>
  145.20 +#include <lemon/invalid.h>
  145.21 +#include <lemon/maps.h>
  145.22 +#include <lemon/for_each_macros.h>
  145.23  
  145.24  /// \file
  145.25  /// \brief Maximum flow algorithms.
  145.26  /// \ingroup galgs
  145.27  
  145.28 -namespace hugo {
  145.29 +namespace lemon {
  145.30  
  145.31    /// \addtogroup galgs
  145.32    /// @{                                                                                                                                        
  145.33 @@ -1193,7 +1193,7 @@
  145.34  	free1(erasing_res_graph);
  145.35  
  145.36        dfs.pushAndSetReached
  145.37 -	///\bug hugo 0.2
  145.38 +	///\bug lemon 0.2
  145.39  	(typename ErasingResGW::Node
  145.40  	 (typename FilterResGW::Node
  145.41  	  (typename ResGW::Node(s)
  145.42 @@ -1260,9 +1260,9 @@
  145.43    }
  145.44  
  145.45  
  145.46 -} //namespace hugo
  145.47 +} //namespace lemon
  145.48  
  145.49 -#endif //HUGO_MAX_FLOW_H
  145.50 +#endif //LEMON_MAX_FLOW_H
  145.51  
  145.52  
  145.53  
   146.1 --- a/src/work/jacint/max_flow_bug.cc	Wed Sep 29 14:12:26 2004 +0000
   146.2 +++ b/src/work/jacint/max_flow_bug.cc	Wed Sep 29 15:30:04 2004 +0000
   146.3 @@ -1,13 +1,13 @@
   146.4  #include <iostream>
   146.5  
   146.6 -//#include <hugo/list_graph.h>
   146.7 +//#include <lemon/list_graph.h>
   146.8  #include <sage_graph.h>
   146.9 -#include <hugo/dimacs.h>
  146.10 -#include <hugo/max_flow.h>
  146.11 +#include <lemon/dimacs.h>
  146.12 +#include <lemon/max_flow.h>
  146.13  //#include <max_flow_no_stack.h>
  146.14 -#include <hugo/time_measure.h>
  146.15 +#include <lemon/time_measure.h>
  146.16  
  146.17 -using namespace hugo;
  146.18 +using namespace lemon;
  146.19  
  146.20  int main(int, char **) {
  146.21   
   147.1 --- a/src/work/jacint/max_flow_test.cc	Wed Sep 29 14:12:26 2004 +0000
   147.2 +++ b/src/work/jacint/max_flow_test.cc	Wed Sep 29 15:30:04 2004 +0000
   147.3 @@ -1,12 +1,12 @@
   147.4  #include <iostream>
   147.5  
   147.6 -#include <hugo/list_graph.h>
   147.7 -#include <hugo/dimacs.h>
   147.8 +#include <lemon/list_graph.h>
   147.9 +#include <lemon/dimacs.h>
  147.10  #include <max_flow.h>
  147.11  #include <max_flow_no_stack.h>
  147.12 -#include <hugo/time_measure.h>
  147.13 +#include <lemon/time_measure.h>
  147.14  
  147.15 -using namespace hugo;
  147.16 +using namespace lemon;
  147.17  
  147.18  int main(int, char **) {
  147.19   
   148.1 --- a/src/work/jacint/max_matching.cc	Wed Sep 29 14:12:26 2004 +0000
   148.2 +++ b/src/work/jacint/max_matching.cc	Wed Sep 29 15:30:04 2004 +0000
   148.3 @@ -10,7 +10,7 @@
   148.4  #include <time_measure.h>
   148.5  #include <graph_wrapper.h>
   148.6  
   148.7 -using namespace hugo;
   148.8 +using namespace lemon;
   148.9  
  148.10  int main(int, char **) {
  148.11   
   149.1 --- a/src/work/jacint/max_matching.h	Wed Sep 29 14:12:26 2004 +0000
   149.2 +++ b/src/work/jacint/max_matching.h	Wed Sep 29 15:30:04 2004 +0000
   149.3 @@ -1,6 +1,6 @@
   149.4  // -*- C++ -*-
   149.5 -#ifndef HUGO_MAX_MATCHING_H
   149.6 -#define HUGO_MAX_MATCHING_H
   149.7 +#ifndef LEMON_MAX_MATCHING_H
   149.8 +#define LEMON_MAX_MATCHING_H
   149.9  
  149.10  ///\ingroup galgs
  149.11  ///\file
  149.12 @@ -11,7 +11,7 @@
  149.13  #include <invalid.h>
  149.14  #include <unionfind.h>
  149.15  
  149.16 -namespace hugo {
  149.17 +namespace lemon {
  149.18  
  149.19    /// \addtogroup galgs
  149.20    /// @{
  149.21 @@ -564,6 +564,6 @@
  149.22  
  149.23    /// @}
  149.24    
  149.25 -} //END OF NAMESPACE HUGO
  149.26 +} //END OF NAMESPACE LEMON
  149.27  
  149.28  #endif //EDMONDS_H
   150.1 --- a/src/work/jacint/max_save.h	Wed Sep 29 14:12:26 2004 +0000
   150.2 +++ b/src/work/jacint/max_save.h	Wed Sep 29 15:30:04 2004 +0000
   150.3 @@ -1,6 +1,6 @@
   150.4  // -*- C++ -*-
   150.5 -#ifndef HUGO_MAX_FLOW_H
   150.6 -#define HUGO_MAX_FLOW_H
   150.7 +#ifndef LEMON_MAX_FLOW_H
   150.8 +#define LEMON_MAX_FLOW_H
   150.9  
  150.10  ///\ingroup galgs
  150.11  ///\file
  150.12 @@ -22,7 +22,7 @@
  150.13  /// \file
  150.14  /// \brief Dimacs file format reader.
  150.15  
  150.16 -namespace hugo {
  150.17 +namespace lemon {
  150.18  
  150.19    /// \addtogroup galgs
  150.20    /// @{
  150.21 @@ -1127,9 +1127,9 @@
  150.22  
  150.23    /// @}
  150.24    
  150.25 -} //END OF NAMESPACE HUGO
  150.26 +} //END OF NAMESPACE LEMON
  150.27  
  150.28 -#endif //HUGO_MAX_FLOW_H
  150.29 +#endif //LEMON_MAX_FLOW_H
  150.30  
  150.31  
  150.32  
   151.1 --- a/src/work/jacint/preflow.cc	Wed Sep 29 14:12:26 2004 +0000
   151.2 +++ b/src/work/jacint/preflow.cc	Wed Sep 29 15:30:04 2004 +0000
   151.3 @@ -5,7 +5,7 @@
   151.4  #include <preflow.h>
   151.5  #include <time_measure.h>
   151.6  
   151.7 -using namespace hugo;
   151.8 +using namespace lemon;
   151.9  
  151.10  int main(int, char **) {
  151.11   
   152.1 --- a/src/work/jacint/preflow_excess.h	Wed Sep 29 14:12:26 2004 +0000
   152.2 +++ b/src/work/jacint/preflow_excess.h	Wed Sep 29 15:30:04 2004 +0000
   152.3 @@ -43,8 +43,8 @@
   152.4  
   152.5  */
   152.6  
   152.7 -#ifndef HUGO_PREFLOW_H
   152.8 -#define HUGO_PREFLOW_H
   152.9 +#ifndef LEMON_PREFLOW_H
  152.10 +#define LEMON_PREFLOW_H
  152.11  
  152.12  #define H0 20
  152.13  #define H1 1
  152.14 @@ -53,7 +53,7 @@
  152.15  #include <queue>
  152.16  #include <stack>
  152.17  
  152.18 -namespace hugo {
  152.19 +namespace lemon {
  152.20  
  152.21    template <typename Graph, typename T, 
  152.22  	    typename CapMap=typename Graph::template EdgeMap<T>, 
  152.23 @@ -655,7 +655,7 @@
  152.24  
  152.25    };
  152.26  
  152.27 -} //namespace hugo
  152.28 +} //namespace lemon
  152.29  
  152.30  #endif //PREFLOW_H
  152.31  
   153.1 --- a/src/work/jacint/preflow_excess_test.cc	Wed Sep 29 14:12:26 2004 +0000
   153.2 +++ b/src/work/jacint/preflow_excess_test.cc	Wed Sep 29 15:30:04 2004 +0000
   153.3 @@ -11,7 +11,7 @@
   153.4  #include <preflow_excess.h>
   153.5  #include <time_measure.h>
   153.6  
   153.7 -using namespace hugo;
   153.8 +using namespace lemon;
   153.9  
  153.10  int main(int, char **) {
  153.11   
   154.1 --- a/src/work/jacint/preflow_res.h	Wed Sep 29 14:12:26 2004 +0000
   154.2 +++ b/src/work/jacint/preflow_res.h	Wed Sep 29 15:30:04 2004 +0000
   154.3 @@ -1,7 +1,7 @@
   154.4  // -*- C++ -*-
   154.5  //The same as preflow.h, using ResGraphWrapper
   154.6 -#ifndef HUGO_PREFLOW_RES_H
   154.7 -#define HUGO_PREFLOW_RES_H
   154.8 +#ifndef LEMON_PREFLOW_RES_H
   154.9 +#define LEMON_PREFLOW_RES_H
  154.10  
  154.11  #define H0 20
  154.12  #define H1 1
  154.13 @@ -12,7 +12,7 @@
  154.14  
  154.15  #include<iostream>
  154.16  
  154.17 -namespace hugo {
  154.18 +namespace lemon {
  154.19  
  154.20    template <typename Graph, typename T, 
  154.21  	    typename CapMap=typename Graph::template EdgeMap<T>, 
  154.22 @@ -486,9 +486,9 @@
  154.23  
  154.24    };
  154.25  
  154.26 -} //namespace hugo
  154.27 +} //namespace lemon
  154.28  
  154.29 -#endif //HUGO_PREFLOW_RES_H
  154.30 +#endif //LEMON_PREFLOW_RES_H
  154.31  
  154.32  
  154.33  
   155.1 --- a/src/work/jacint/prim.cc	Wed Sep 29 14:12:26 2004 +0000
   155.2 +++ b/src/work/jacint/prim.cc	Wed Sep 29 15:30:04 2004 +0000
   155.3 @@ -10,7 +10,7 @@
   155.4  #include <bin_heap.h>
   155.5  #include <fib_heap.h>
   155.6  
   155.7 -using namespace hugo;
   155.8 +using namespace lemon;
   155.9  
  155.10  int main(int, char **) {
  155.11    typedef SmartGraph::Node Node;
   156.1 --- a/src/work/jacint/prim.h	Wed Sep 29 14:12:26 2004 +0000
   156.2 +++ b/src/work/jacint/prim.h	Wed Sep 29 15:30:04 2004 +0000
   156.3 @@ -29,13 +29,13 @@
   156.4   *
   156.5   */
   156.6  
   156.7 -#ifndef HUGO_PRIM_H
   156.8 -#define HUGO_PRIM_H
   156.9 +#ifndef LEMON_PRIM_H
  156.10 +#define LEMON_PRIM_H
  156.11  
  156.12  #include <fib_heap.h>
  156.13  #include <invalid.h>
  156.14  
  156.15 -namespace hugo {
  156.16 +namespace lemon {
  156.17  
  156.18    template <typename Graph, typename T, 
  156.19      typename Heap=FibHeap<typename Graph::Node, T, 
   157.1 --- a/src/work/johanna/contract_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   157.2 +++ b/src/work/johanna/contract_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   157.3 @@ -1,11 +1,11 @@
   157.4  // -*- C++ -*- //
   157.5  
   157.6 -#ifndef HUGO_CONTRACT_WRAPPER
   157.7 -#define HUGO_CONTRACT_WRAPPER
   157.8 +#ifndef LEMON_CONTRACT_WRAPPER
   157.9 +#define LEMON_CONTRACT_WRAPPER
  157.10  
  157.11  #include <graph_wrapper.h>
  157.12  
  157.13 -namespace hugo {
  157.14 +namespace lemon {
  157.15  
  157.16    template<typename Graph>
  157.17    class ConractWrapper : public GraphWrapper<const Graph> {
   158.1 --- a/src/work/johanna/ma_order.h	Wed Sep 29 14:12:26 2004 +0000
   158.2 +++ b/src/work/johanna/ma_order.h	Wed Sep 29 15:30:04 2004 +0000
   158.3 @@ -1,13 +1,13 @@
   158.4  // -*- C++ -*- //
   158.5  
   158.6 -#ifndef HUGO_MA_ORDER_H
   158.7 -#define HUGO_MA_ORDER_H
   158.8 +#ifndef LEMON_MA_ORDER_H
   158.9 +#define LEMON_MA_ORDER_H
  158.10  
  158.11  #include <vector>
  158.12  #include <functional>
  158.13  #include <bin_heap.h>
  158.14  
  158.15 -namespace hugo {
  158.16 +namespace lemon {
  158.17  
  158.18    template <typename Graph, 
  158.19  	    typename Heap = BinHeap<typename Graph::Node, int, 
  158.20 @@ -82,6 +82,6 @@
  158.21  
  158.22    };
  158.23  
  158.24 -} // namespace hugo
  158.25 +} // namespace lemon
  158.26  
  158.27 -#endif // HUGO_MA_ORDER_H
  158.28 +#endif // LEMON_MA_ORDER_H
   159.1 --- a/src/work/johanna/ma_order_test.cc	Wed Sep 29 14:12:26 2004 +0000
   159.2 +++ b/src/work/johanna/ma_order_test.cc	Wed Sep 29 15:30:04 2004 +0000
   159.3 @@ -8,7 +8,7 @@
   159.4  
   159.5  
   159.6  using namespace std;
   159.7 -using namespace hugo;
   159.8 +using namespace lemon;
   159.9  
  159.10  int main() {
  159.11  
   160.1 --- a/src/work/klao/debug.h	Wed Sep 29 14:12:26 2004 +0000
   160.2 +++ b/src/work/klao/debug.h	Wed Sep 29 15:30:04 2004 +0000
   160.3 @@ -1,12 +1,12 @@
   160.4  // -*- C++ -*- //
   160.5  
   160.6 -#ifndef HUGO_DEBUG_H
   160.7 -#define HUGO_DEBUG_H
   160.8 +#ifndef LEMON_DEBUG_H
   160.9 +#define LEMON_DEBUG_H
  160.10  
  160.11  //! \file
  160.12  //! \brief Basic definitions for debug control.
  160.13  
  160.14 -namespace hugo {
  160.15 +namespace lemon {
  160.16  
  160.17    //! Debug mode for testing/debugging
  160.18  
  160.19 @@ -53,4 +53,4 @@
  160.20  #endif
  160.21  
  160.22  }
  160.23 -#endif // HUGO_DEBUG_H
  160.24 +#endif // LEMON_DEBUG_H
   161.1 --- a/src/work/klao/iter_map.h	Wed Sep 29 14:12:26 2004 +0000
   161.2 +++ b/src/work/klao/iter_map.h	Wed Sep 29 15:30:04 2004 +0000
   161.3 @@ -1,7 +1,7 @@
   161.4  // -*- c++ -*- //
   161.5  
   161.6 -#ifndef HUGO_ITER_MAP
   161.7 -#define HUGO_ITER_MAP
   161.8 +#ifndef LEMON_ITER_MAP
   161.9 +#define LEMON_ITER_MAP
  161.10  
  161.11  #include <vector>
  161.12  #include <algorithm>
  161.13 @@ -10,9 +10,9 @@
  161.14  // for memset
  161.15  #include <cstring>
  161.16  
  161.17 -#include <hugo/invalid.h>
  161.18 +#include <lemon/invalid.h>
  161.19  
  161.20 -namespace hugo {
  161.21 +namespace lemon {
  161.22  
  161.23    /// \brief A map with "small integers" as value set which can enumarate it
  161.24    /// value classes
   162.1 --- a/src/work/klao/iter_map_test.cc	Wed Sep 29 14:12:26 2004 +0000
   162.2 +++ b/src/work/klao/iter_map_test.cc	Wed Sep 29 15:30:04 2004 +0000
   162.3 @@ -1,9 +1,9 @@
   162.4  #include <iter_map.h>
   162.5 -#include <hugo/maps.h>
   162.6 +#include <lemon/maps.h>
   162.7  
   162.8  #include <iostream>
   162.9  
  162.10 -using namespace hugo;
  162.11 +using namespace lemon;
  162.12  using namespace std;
  162.13  
  162.14  const int N = 3;
   163.1 --- a/src/work/klao/map_test.cc	Wed Sep 29 14:12:26 2004 +0000
   163.2 +++ b/src/work/klao/map_test.cc	Wed Sep 29 15:30:04 2004 +0000
   163.3 @@ -1,9 +1,9 @@
   163.4  #include <iostream>
   163.5  
   163.6 -#include <hugo/maps.h>
   163.7 +#include <lemon/maps.h>
   163.8  
   163.9  using namespace std;
  163.10 -using namespace hugo;
  163.11 +using namespace lemon;
  163.12  
  163.13  int main()
  163.14  {
   164.1 --- a/src/work/marci/augmenting_flow.h	Wed Sep 29 14:12:26 2004 +0000
   164.2 +++ b/src/work/marci/augmenting_flow.h	Wed Sep 29 15:30:04 2004 +0000
   164.3 @@ -1,21 +1,21 @@
   164.4  // -*- C++ -*-
   164.5 -#ifndef HUGO_AUGMENTING_FLOW_H
   164.6 -#define HUGO_AUGMENTING_FLOW_H
   164.7 +#ifndef LEMON_AUGMENTING_FLOW_H
   164.8 +#define LEMON_AUGMENTING_FLOW_H
   164.9  
  164.10  #include <vector>
  164.11  #include <iostream>
  164.12  
  164.13 -#include <hugo/graph_wrapper.h>
  164.14 +#include <lemon/graph_wrapper.h>
  164.15  #include <bfs_dfs.h>
  164.16 -#include <hugo/invalid.h>
  164.17 -#include <hugo/maps.h>
  164.18 -#include <hugo/tight_edge_filter_map.h>
  164.19 +#include <lemon/invalid.h>
  164.20 +#include <lemon/maps.h>
  164.21 +#include <lemon/tight_edge_filter_map.h>
  164.22  
  164.23  /// \file
  164.24  /// \brief Maximum flow algorithms.
  164.25  /// \ingroup galgs
  164.26  
  164.27 -namespace hugo {
  164.28 +namespace lemon {
  164.29  
  164.30    /// \addtogroup galgs
  164.31    /// @{                                                                                                                                        
  164.32 @@ -536,7 +536,7 @@
  164.33  	free1(erasing_res_graph);
  164.34  
  164.35        dfs.pushAndSetReached
  164.36 -	/// \bug hugo 0.2
  164.37 +	/// \bug lemon 0.2
  164.38  	(typename ErasingResGW::Node
  164.39  	 (typename FilterResGW::Node
  164.40  	  (typename ResGW::Node(s)
  164.41 @@ -594,8 +594,8 @@
  164.42    }
  164.43  
  164.44  
  164.45 -} //namespace hugo
  164.46 +} //namespace lemon
  164.47  
  164.48 -#endif //HUGO_AUGMENTING_FLOW_H
  164.49 +#endif //LEMON_AUGMENTING_FLOW_H
  164.50  
  164.51  
   165.1 --- a/src/work/marci/bfs_dfs.h	Wed Sep 29 14:12:26 2004 +0000
   165.2 +++ b/src/work/marci/bfs_dfs.h	Wed Sep 29 15:30:04 2004 +0000
   165.3 @@ -1,6 +1,6 @@
   165.4  // -*- c++ -*-
   165.5 -#ifndef HUGO_BFS_DFS_H
   165.6 -#define HUGO_BFS_DFS_H
   165.7 +#ifndef LEMON_BFS_DFS_H
   165.8 +#define LEMON_BFS_DFS_H
   165.9  
  165.10  /// \ingroup galgs
  165.11  /// \file
  165.12 @@ -14,9 +14,9 @@
  165.13  #include <stack>
  165.14  #include <utility>
  165.15  
  165.16 -#include <hugo/invalid.h>
  165.17 +#include <lemon/invalid.h>
  165.18  
  165.19 -namespace hugo {
  165.20 +namespace lemon {
  165.21  
  165.22    /// Bfs searches for the nodes wich are not marked in 
  165.23    /// \c reached_map
  165.24 @@ -117,7 +117,7 @@
  165.25      bool finished() const { return bfs_queue.empty(); }
  165.26      /// The conversion operator makes for converting the bfs-iterator 
  165.27      /// to an \c out-edge-iterator.
  165.28 -    ///\bug Edge have to be in HUGO 0.2
  165.29 +    ///\bug Edge have to be in LEMON 0.2
  165.30      operator Edge() const { return actual_edge; }
  165.31      /// Returns if b-node has been reached just now.
  165.32      bool isBNodeNewlyReached() const { return b_node_newly_reached; }
  165.33 @@ -269,7 +269,7 @@
  165.34      bool finished() const { return dfs_stack.empty(); }
  165.35      /// The conversion operator makes for converting the bfs-iterator 
  165.36      /// to an \c out-edge-iterator.
  165.37 -    ///\bug Edge have to be in HUGO 0.2
  165.38 +    ///\bug Edge have to be in LEMON 0.2
  165.39      operator Edge() const { return actual_edge; }
  165.40      /// Returns if b-node has been reached just now.
  165.41      bool isBNodeNewlyReached() const { return b_node_newly_reached; }
  165.42 @@ -343,6 +343,6 @@
  165.43    };
  165.44  
  165.45  
  165.46 -} // namespace hugo
  165.47 +} // namespace lemon
  165.48  
  165.49 -#endif //HUGO_BFS_DFS_H
  165.50 +#endif //LEMON_BFS_DFS_H
   166.1 --- a/src/work/marci/bfs_dfs_misc.h	Wed Sep 29 14:12:26 2004 +0000
   166.2 +++ b/src/work/marci/bfs_dfs_misc.h	Wed Sep 29 15:30:04 2004 +0000
   166.3 @@ -1,6 +1,6 @@
   166.4  // -*- c++ -*-
   166.5 -#ifndef HUGO_BFS_DFS_MISC_H
   166.6 -#define HUGO_BFS_DFS_MISC_H
   166.7 +#ifndef LEMON_BFS_DFS_MISC_H
   166.8 +#define LEMON_BFS_DFS_MISC_H
   166.9  
  166.10  /// \ingroup galgs
  166.11  /// \file
  166.12 @@ -13,7 +13,7 @@
  166.13  #include <bfs_dfs.h>
  166.14  #include <for_each_macros.h>
  166.15  
  166.16 -namespace hugo {
  166.17 +namespace lemon {
  166.18  
  166.19    /// This function eats a read-write \c BoolMap& bool_map, 
  166.20    /// which have to work well up 
  166.21 @@ -71,13 +71,13 @@
  166.22  	while (!dfs.finished()) {
  166.23  	  ++dfs;
  166.24  	  if (dfs.isBNodeNewlyReached()) {
  166.25 -	    ///\bug hugo 0.2-ben Edge kell
  166.26 +	    ///\bug lemon 0.2-ben Edge kell
  166.27  	    pred.set(dfs.aNode(), typename Graph::OutEdgeIt(dfs));
  166.28  	  } else {
  166.29  	    ///\bug ugyanaz
  166.30  	    if (g.valid(typename Graph::OutEdgeIt(dfs)) && 
  166.31  		!examined[dfs.bNode()]) {
  166.32 -	      ///\bug hugo 0.2-ben Edge kell
  166.33 +	      ///\bug lemon 0.2-ben Edge kell
  166.34  	      pred.set(dfs.bNode(), typename Graph::OutEdgeIt(dfs));
  166.35  	      return dfs.aNode();
  166.36  	    }
  166.37 @@ -92,6 +92,6 @@
  166.38      return INVALID;
  166.39    }
  166.40  
  166.41 -} //namespace hugo
  166.42 +} //namespace lemon
  166.43  
  166.44 -#endif //HUGO_BFS_DFS_MISC_H
  166.45 +#endif //LEMON_BFS_DFS_MISC_H
   167.1 --- a/src/work/marci/bfsit_vs_byhand.cc	Wed Sep 29 14:12:26 2004 +0000
   167.2 +++ b/src/work/marci/bfsit_vs_byhand.cc	Wed Sep 29 15:30:04 2004 +0000
   167.3 @@ -3,13 +3,13 @@
   167.4  #include <fstream>
   167.5  
   167.6  #include <sage_graph.h>
   167.7 -#include <hugo/smart_graph.h>
   167.8 -#include <hugo/dimacs.h>
   167.9 -#include <hugo/time_measure.h>
  167.10 -//#include <hugo/for_each_macros.h>
  167.11 +#include <lemon/smart_graph.h>
  167.12 +#include <lemon/dimacs.h>
  167.13 +#include <lemon/time_measure.h>
  167.14 +//#include <lemon/for_each_macros.h>
  167.15  #include <bfs_dfs.h>
  167.16  
  167.17 -using namespace hugo;
  167.18 +using namespace lemon;
  167.19  
  167.20  using std::cout;
  167.21  using std::endl;
   168.1 --- a/src/work/marci/bipartite_graph_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   168.2 +++ b/src/work/marci/bipartite_graph_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   168.3 @@ -1,6 +1,6 @@
   168.4  // -*- c++ -*-
   168.5 -#ifndef HUGO_BIPARTITE_GRAPH_WRAPPER_H
   168.6 -#define HUGO_BIPARTITE_GRAPH_WRAPPER_H
   168.7 +#ifndef LEMON_BIPARTITE_GRAPH_WRAPPER_H
   168.8 +#define LEMON_BIPARTITE_GRAPH_WRAPPER_H
   168.9  
  168.10  ///\ingroup gwrappers
  168.11  ///\file
  168.12 @@ -10,12 +10,12 @@
  168.13  ///
  168.14  ///\author Marton Makai
  168.15  
  168.16 -#include <hugo/invalid.h>
  168.17 +#include <lemon/invalid.h>
  168.18  #include <iter_map.h>
  168.19 -#include <hugo/graph_wrapper.h>
  168.20 +#include <lemon/graph_wrapper.h>
  168.21  #include <for_each_macros.h>
  168.22  
  168.23 -namespace hugo {
  168.24 +namespace lemon {
  168.25  
  168.26    /// \brief A wrapper for composing a bipartite graph from a graph 
  168.27    /// and from a node-map showing for any node which color class it belongs to.
  168.28 @@ -926,8 +926,8 @@
  168.29  
  168.30    ///@}
  168.31  
  168.32 -} //namespace hugo
  168.33 +} //namespace lemon
  168.34  
  168.35  
  168.36 -#endif //HUGO_BIPARTITE_GRAPH_WRAPPER_H
  168.37 +#endif //LEMON_BIPARTITE_GRAPH_WRAPPER_H
  168.38  
   169.1 --- a/src/work/marci/bipartite_graph_wrapper_test.cc	Wed Sep 29 14:12:26 2004 +0000
   169.2 +++ b/src/work/marci/bipartite_graph_wrapper_test.cc	Wed Sep 29 15:30:04 2004 +0000
   169.3 @@ -4,21 +4,21 @@
   169.4  #include <vector>
   169.5  
   169.6  //#include <sage_graph.h>
   169.7 -#include <hugo/smart_graph.h>
   169.8 +#include <lemon/smart_graph.h>
   169.9  //#include <dimacs.h>
  169.10 -#include <hugo/time_measure.h>
  169.11 +#include <lemon/time_measure.h>
  169.12  //#include <for_each_macros.h>
  169.13  #include <bfs_dfs.h>
  169.14 -#include <hugo/graph_wrapper.h>
  169.15 +#include <lemon/graph_wrapper.h>
  169.16  #include <bipartite_graph_wrapper.h>
  169.17 -#include <hugo/maps.h>
  169.18 -#include <hugo/preflow.h>
  169.19 +#include <lemon/maps.h>
  169.20 +#include <lemon/preflow.h>
  169.21  #include <augmenting_flow.h>
  169.22  
  169.23  using std::cout;
  169.24  using std::endl;
  169.25  
  169.26 -using namespace hugo;
  169.27 +using namespace lemon;
  169.28  
  169.29  int main() {
  169.30    //typedef UndirSageGraph Graph; 
   170.1 --- a/src/work/marci/bipartite_matching_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   170.2 +++ b/src/work/marci/bipartite_matching_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   170.3 @@ -6,16 +6,16 @@
   170.4  #include <sage_graph.h>
   170.5  //#include <smart_graph.h>
   170.6  //#include <dimacs.h>
   170.7 -#include <hugo/time_measure.h>
   170.8 +#include <lemon/time_measure.h>
   170.9  #include <for_each_macros.h>
  170.10  #include <bfs_dfs.h>
  170.11  #include <bipartite_graph_wrapper.h>
  170.12 -#include <hugo/maps.h>
  170.13 -#include <hugo/max_flow.h>
  170.14 +#include <lemon/maps.h>
  170.15 +#include <lemon/max_flow.h>
  170.16  #include <graph_gen.h>
  170.17  #include <max_bipartite_matching.h>
  170.18  
  170.19 -using namespace hugo;
  170.20 +using namespace lemon;
  170.21  
  170.22  using std::cin;
  170.23  using std::cout;
   171.1 --- a/src/work/marci/const_map_time.cc	Wed Sep 29 14:12:26 2004 +0000
   171.2 +++ b/src/work/marci/const_map_time.cc	Wed Sep 29 15:30:04 2004 +0000
   171.3 @@ -3,13 +3,13 @@
   171.4  
   171.5  #include <iostream>
   171.6  
   171.7 -#include <hugo/maps.h>
   171.8 -#include <hugo/smart_graph.h>
   171.9 -#include <hugo/time_measure.h>
  171.10 -#include <hugo/dimacs.h>
  171.11 -#include <hugo/graph_wrapper.h>
  171.12 +#include <lemon/maps.h>
  171.13 +#include <lemon/smart_graph.h>
  171.14 +#include <lemon/time_measure.h>
  171.15 +#include <lemon/dimacs.h>
  171.16 +#include <lemon/graph_wrapper.h>
  171.17  
  171.18 -using namespace hugo;
  171.19 +using namespace lemon;
  171.20  
  171.21  int main() {
  171.22  
   172.1 --- a/src/work/marci/experiment/bfs_iterator.h	Wed Sep 29 14:12:26 2004 +0000
   172.2 +++ b/src/work/marci/experiment/bfs_iterator.h	Wed Sep 29 15:30:04 2004 +0000
   172.3 @@ -1,13 +1,13 @@
   172.4  // -*- c++ -*-
   172.5 -#ifndef HUGO_BFS_ITERATOR_H
   172.6 -#define HUGO_BFS_ITERATOR_H
   172.7 +#ifndef LEMON_BFS_ITERATOR_H
   172.8 +#define LEMON_BFS_ITERATOR_H
   172.9  
  172.10  #include <queue>
  172.11  #include <stack>
  172.12  #include <utility>
  172.13  #include <graph_wrapper.h>
  172.14  
  172.15 -namespace hugo {
  172.16 +namespace lemon {
  172.17  
  172.18  //   template <typename Graph>
  172.19  //   struct bfs {
  172.20 @@ -836,6 +836,6 @@
  172.21  
  172.22  
  172.23  
  172.24 -} // namespace hugo
  172.25 +} // namespace lemon
  172.26  
  172.27 -#endif //HUGO_BFS_ITERATOR_H
  172.28 +#endif //LEMON_BFS_ITERATOR_H
   173.1 --- a/src/work/marci/experiment/bfs_iterator_1.h	Wed Sep 29 14:12:26 2004 +0000
   173.2 +++ b/src/work/marci/experiment/bfs_iterator_1.h	Wed Sep 29 15:30:04 2004 +0000
   173.3 @@ -1,13 +1,13 @@
   173.4  // -*- c++ -*-
   173.5 -#ifndef HUGO_BFS_ITERATOR_H
   173.6 -#define HUGO_BFS_ITERATOR_H
   173.7 +#ifndef LEMON_BFS_ITERATOR_H
   173.8 +#define LEMON_BFS_ITERATOR_H
   173.9  
  173.10  #include <queue>
  173.11  #include <stack>
  173.12  #include <utility>
  173.13  #include <graph_wrapper_1.h>
  173.14  
  173.15 -namespace hugo {
  173.16 +namespace lemon {
  173.17  
  173.18  //   template <typename Graph>
  173.19  //   struct bfs {
  173.20 @@ -831,6 +831,6 @@
  173.21  
  173.22  
  173.23  
  173.24 -} // namespace hugo
  173.25 +} // namespace lemon
  173.26  
  173.27 -#endif //HUGO_BFS_ITERATOR_H
  173.28 +#endif //LEMON_BFS_ITERATOR_H
   174.1 --- a/src/work/marci/experiment/edmonds_karp.h	Wed Sep 29 14:12:26 2004 +0000
   174.2 +++ b/src/work/marci/experiment/edmonds_karp.h	Wed Sep 29 15:30:04 2004 +0000
   174.3 @@ -1,6 +1,6 @@
   174.4  // -*- c++ -*-
   174.5 -#ifndef HUGO_EDMONDS_KARP_H
   174.6 -#define HUGO_EDMONDS_KARP_H
   174.7 +#ifndef LEMON_EDMONDS_KARP_H
   174.8 +#define LEMON_EDMONDS_KARP_H
   174.9  
  174.10  #include <algorithm>
  174.11  #include <list>
  174.12 @@ -9,7 +9,7 @@
  174.13  #include <bfs_iterator.h>
  174.14  #include <invalid.h>
  174.15  
  174.16 -namespace hugo {
  174.17 +namespace lemon {
  174.18  
  174.19    template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  174.20    class ResGraph {
  174.21 @@ -1233,6 +1233,6 @@
  174.22  // //   };
  174.23  
  174.24  
  174.25 -} // namespace hugo
  174.26 +} // namespace lemon
  174.27  
  174.28 -#endif //HUGO_EDMONDS_KARP_H
  174.29 +#endif //LEMON_EDMONDS_KARP_H
   175.1 --- a/src/work/marci/experiment/edmonds_karp_1.h	Wed Sep 29 14:12:26 2004 +0000
   175.2 +++ b/src/work/marci/experiment/edmonds_karp_1.h	Wed Sep 29 15:30:04 2004 +0000
   175.3 @@ -1,6 +1,6 @@
   175.4  // -*- c++ -*-
   175.5 -#ifndef HUGO_EDMONDS_KARP_H
   175.6 -#define HUGO_EDMONDS_KARP_H
   175.7 +#ifndef LEMON_EDMONDS_KARP_H
   175.8 +#define LEMON_EDMONDS_KARP_H
   175.9  
  175.10  #include <algorithm>
  175.11  #include <list>
  175.12 @@ -10,7 +10,7 @@
  175.13  #include <invalid.h>
  175.14  #include <graph_wrapper_1.h>
  175.15  
  175.16 -namespace hugo {
  175.17 +namespace lemon {
  175.18  
  175.19    template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  175.20    class ResGraph {
  175.21 @@ -1143,6 +1143,6 @@
  175.22  // //   };
  175.23  
  175.24  
  175.25 -} // namespace hugo
  175.26 +} // namespace lemon
  175.27  
  175.28 -#endif //HUGO_EDMONDS_KARP_H
  175.29 +#endif //LEMON_EDMONDS_KARP_H
   176.1 --- a/src/work/marci/experiment/edmonds_karp_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   176.2 +++ b/src/work/marci/experiment/edmonds_karp_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   176.3 @@ -14,7 +14,7 @@
   176.4    template<typename T> int get(T) const {return 1;}
   176.5  };
   176.6  
   176.7 -using namespace hugo;
   176.8 +using namespace lemon;
   176.9  
  176.10  // Use a DIMACS max flow file as stdin.
  176.11  // read_dimacs_demo < dimacs_max_flow_file
   177.1 --- a/src/work/marci/experiment/edmonds_karp_demo_1.cc	Wed Sep 29 14:12:26 2004 +0000
   177.2 +++ b/src/work/marci/experiment/edmonds_karp_demo_1.cc	Wed Sep 29 15:30:04 2004 +0000
   177.3 @@ -14,7 +14,7 @@
   177.4    template<typename T> int get(T) const {return 1;}
   177.5  };
   177.6  
   177.7 -using namespace hugo;
   177.8 +using namespace lemon;
   177.9  
  177.10  // Use a DIMACS max flow file as stdin.
  177.11  // read_dimacs_demo < dimacs_max_flow_file
   178.1 --- a/src/work/marci/experiment/graph_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   178.2 +++ b/src/work/marci/experiment/graph_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   178.3 @@ -1,10 +1,10 @@
   178.4  // -*- c++ -*-
   178.5 -#ifndef HUGO_GRAPH_WRAPPER_H
   178.6 -#define HUGO_GRAPH_WRAPPER_H
   178.7 +#ifndef LEMON_GRAPH_WRAPPER_H
   178.8 +#define LEMON_GRAPH_WRAPPER_H
   178.9  
  178.10  #include <invalid.h>
  178.11  
  178.12 -namespace hugo {
  178.13 +namespace lemon {
  178.14  
  178.15    template<typename Graph>
  178.16    class TrivGraphWrapper {
  178.17 @@ -1701,7 +1701,7 @@
  178.18  //     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
  178.19  //   };
  178.20  
  178.21 -} //namespace hugo
  178.22 +} //namespace lemon
  178.23  
  178.24 -#endif //HUGO_GRAPH_WRAPPER_H
  178.25 +#endif //LEMON_GRAPH_WRAPPER_H
  178.26  
   179.1 --- a/src/work/marci/experiment/graph_wrapper_1.h	Wed Sep 29 14:12:26 2004 +0000
   179.2 +++ b/src/work/marci/experiment/graph_wrapper_1.h	Wed Sep 29 15:30:04 2004 +0000
   179.3 @@ -1,10 +1,10 @@
   179.4  // -*- c++ -*-
   179.5 -#ifndef HUGO_GRAPH_WRAPPER_H
   179.6 -#define HUGO_GRAPH_WRAPPER_H
   179.7 +#ifndef LEMON_GRAPH_WRAPPER_H
   179.8 +#define LEMON_GRAPH_WRAPPER_H
   179.9  
  179.10  #include <invalid.h>
  179.11  
  179.12 -namespace hugo {
  179.13 +namespace lemon {
  179.14  
  179.15    template<typename Graph>
  179.16    class TrivGraphWrapper {
  179.17 @@ -1342,7 +1342,7 @@
  179.18  //     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
  179.19  //   };
  179.20  
  179.21 -} //namespace hugo
  179.22 +} //namespace lemon
  179.23  
  179.24 -#endif //HUGO_GRAPH_WRAPPER_H
  179.25 +#endif //LEMON_GRAPH_WRAPPER_H
  179.26  
   180.1 --- a/src/work/marci/experiment/graph_wrapper_st_ostream_op.h	Wed Sep 29 14:12:26 2004 +0000
   180.2 +++ b/src/work/marci/experiment/graph_wrapper_st_ostream_op.h	Wed Sep 29 15:30:04 2004 +0000
   180.3 @@ -1,16 +1,16 @@
   180.4  // -*- c++ -*-
   180.5 -#ifndef HUGO_GRAPH_WRAPPER_H
   180.6 -#define HUGO_GRAPH_WRAPPER_H
   180.7 +#ifndef LEMON_GRAPH_WRAPPER_H
   180.8 +#define LEMON_GRAPH_WRAPPER_H
   180.9  
  180.10  #include <invalid.h>
  180.11  #include <iter_map.h>
  180.12  
  180.13 -namespace hugo {
  180.14 +namespace lemon {
  180.15  
  180.16    // Graph wrappers
  180.17  
  180.18    /// \addtogroup gwrappers
  180.19 -  /// A main parts of HUGOlib are the different graph structures, 
  180.20 +  /// A main parts of LEMON are the different graph structures, 
  180.21    /// generic graph algorithms, graph concepts which couple these, and 
  180.22    /// graph wrappers. While the previous ones are more or less clear, the 
  180.23    /// latter notion needs further explanation.
  180.24 @@ -1646,8 +1646,8 @@
  180.25  
  180.26    ///@}
  180.27  
  180.28 -} //namespace hugo
  180.29 +} //namespace lemon
  180.30  
  180.31  
  180.32 -#endif //HUGO_GRAPH_WRAPPER_H
  180.33 +#endif //LEMON_GRAPH_WRAPPER_H
  180.34  
   181.1 --- a/src/work/marci/experiment/iterator_bfs_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   181.2 +++ b/src/work/marci/experiment/iterator_bfs_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   181.3 @@ -8,7 +8,7 @@
   181.4  #include <bfs_iterator.h>
   181.5  #include <graph_wrapper.h>
   181.6  
   181.7 -using namespace hugo;
   181.8 +using namespace lemon;
   181.9  using std::cout; 
  181.10  using std::endl;
  181.11  using std::string;
   182.1 --- a/src/work/marci/experiment/iterator_bfs_demo_1.cc	Wed Sep 29 14:12:26 2004 +0000
   182.2 +++ b/src/work/marci/experiment/iterator_bfs_demo_1.cc	Wed Sep 29 15:30:04 2004 +0000
   182.3 @@ -8,7 +8,7 @@
   182.4  #include <bfs_iterator_1.h>
   182.5  #include <graph_wrapper_1.h>
   182.6  
   182.7 -using namespace hugo;
   182.8 +using namespace lemon;
   182.9  using std::cout; 
  182.10  using std::endl;
  182.11  using std::string;
   183.1 --- a/src/work/marci/experiment/list_graph.h	Wed Sep 29 14:12:26 2004 +0000
   183.2 +++ b/src/work/marci/experiment/list_graph.h	Wed Sep 29 15:30:04 2004 +0000
   183.3 @@ -1,13 +1,13 @@
   183.4  // -*- c++ -*-
   183.5 -#ifndef HUGO_LIST_GRAPH_H
   183.6 -#define HUGO_LIST_GRAPH_H
   183.7 +#ifndef LEMON_LIST_GRAPH_H
   183.8 +#define LEMON_LIST_GRAPH_H
   183.9  
  183.10  #include <iostream>
  183.11  #include <vector>
  183.12  
  183.13  #include <invalid.h>
  183.14  
  183.15 -namespace hugo {
  183.16 +namespace lemon {
  183.17  
  183.18    template <typename It>
  183.19    int count(It it) { 
  183.20 @@ -565,6 +565,6 @@
  183.21  //   }
  183.22  
  183.23  
  183.24 -} //namespace hugo
  183.25 +} //namespace lemon
  183.26  
  183.27 -#endif //HUGO_LIST_GRAPH_H
  183.28 +#endif //LEMON_LIST_GRAPH_H
   184.1 --- a/src/work/marci/for_each_macros.h	Wed Sep 29 14:12:26 2004 +0000
   184.2 +++ b/src/work/marci/for_each_macros.h	Wed Sep 29 15:30:04 2004 +0000
   184.3 @@ -1,19 +1,19 @@
   184.4  // -*- c++ -*-
   184.5 -#ifndef HUGO_FOR_EACH_MACROS_H
   184.6 -#define HUGO_FOR_EACH_MACROS_H
   184.7 +#ifndef LEMON_FOR_EACH_MACROS_H
   184.8 +#define LEMON_FOR_EACH_MACROS_H
   184.9  
  184.10  // /// \ingroup gwrappers
  184.11  /// \file
  184.12  /// \brief Iteration macros.
  184.13  ///
  184.14  /// This file contains several macros which make easier writting 
  184.15 -/// for cycles in HUGO using HUGO iterators.
  184.16 +/// for cycles in LEMON using LEMON iterators.
  184.17  ///
  184.18  /// \author Marton Makai
  184.19  
  184.20 -namespace hugo {
  184.21 +namespace lemon {
  184.22  
  184.23 -  /// This macro provides a comfortable interface for iterating with HUGO 
  184.24 +  /// This macro provides a comfortable interface for iterating with LEMON 
  184.25    /// iterators.
  184.26    /// \code
  184.27    /// Graph g;
  184.28 @@ -33,7 +33,7 @@
  184.29  /// \deprecated
  184.30  #define FOR_EACH_GLOB(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
  184.31  
  184.32 -  /// This macro provides a comfortable interface for iterating with HUGO 
  184.33 +  /// This macro provides a comfortable interface for iterating with LEMON 
  184.34    /// iterators.
  184.35    /// \code
  184.36    /// Graph g;
  184.37 @@ -125,7 +125,7 @@
  184.38  //     typename Graph::InEdgeIt e; g.first(e, n); return e; 
  184.39  //   }
  184.40  
  184.41 -  /// This macro provides a comfortable interface for iterating with HUGO 
  184.42 +  /// This macro provides a comfortable interface for iterating with LEMON 
  184.43    /// iterators.
  184.44    /// \code
  184.45    /// Graph g;
  184.46 @@ -143,7 +143,7 @@
  184.47  /// \deprecated
  184.48  #define FOR_EACH_LOC(Ittype, e, g) for(Ittype e=loopFirst(Ittype(), (g)); (g).valid(e); (g).next(e))
  184.49  
  184.50 -  /// This macro provides a comfortable interface for iterating with HUGO 
  184.51 +  /// This macro provides a comfortable interface for iterating with LEMON 
  184.52    /// iterators.
  184.53    /// \code
  184.54    /// Graph g;
  184.55 @@ -170,6 +170,6 @@
  184.56  // #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
  184.57  // #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
  184.58  
  184.59 -} //namespace hugo
  184.60 +} //namespace lemon
  184.61  
  184.62 -#endif //HUGO_FOR_EACH_MACROS_H
  184.63 +#endif //LEMON_FOR_EACH_MACROS_H
   185.1 --- a/src/work/marci/graph_concept.h	Wed Sep 29 14:12:26 2004 +0000
   185.2 +++ b/src/work/marci/graph_concept.h	Wed Sep 29 15:30:04 2004 +0000
   185.3 @@ -1,13 +1,13 @@
   185.4  // -*- c++ -*-
   185.5 -#ifndef HUGO_GRAPH_H
   185.6 -#define HUGO_GRAPH_H
   185.7 +#ifndef LEMON_GRAPH_H
   185.8 +#define LEMON_GRAPH_H
   185.9  
  185.10  ///\file
  185.11  ///\brief Declaration of GraphConcept.
  185.12  
  185.13 -#include <hugo/invalid.h>
  185.14 +#include <lemon/invalid.h>
  185.15  
  185.16 -namespace hugo {
  185.17 +namespace lemon {
  185.18  
  185.19    /// @defgroup empty_graph The GraphConcept class
  185.20    /// @{
  185.21 @@ -471,7 +471,7 @@
  185.22    
  185.23    /// @}
  185.24  
  185.25 -} //namespace hugo
  185.26 +} //namespace lemon
  185.27  
  185.28  
  185.29  
  185.30 @@ -491,4 +491,4 @@
  185.31  
  185.32  // }
  185.33  
  185.34 -#endif // HUGO_GRAPH_H
  185.35 +#endif // LEMON_GRAPH_H
   186.1 --- a/src/work/marci/graph_wrapper_time.cc	Wed Sep 29 14:12:26 2004 +0000
   186.2 +++ b/src/work/marci/graph_wrapper_time.cc	Wed Sep 29 15:30:04 2004 +0000
   186.3 @@ -7,14 +7,14 @@
   186.4  #include <fstream>
   186.5  #include <string>
   186.6  #include <vector>
   186.7 -#include <hugo/invalid.h>
   186.8 -#include <hugo/time_measure.h>
   186.9 -#include <hugo/graph_wrapper.h>
  186.10 -#include <hugo/preflow.h>
  186.11 -#include <hugo/dimacs.h>
  186.12 -#include <hugo/list_graph.h>
  186.13 +#include <lemon/invalid.h>
  186.14 +#include <lemon/time_measure.h>
  186.15 +#include <lemon/graph_wrapper.h>
  186.16 +#include <lemon/preflow.h>
  186.17 +#include <lemon/dimacs.h>
  186.18 +#include <lemon/list_graph.h>
  186.19  
  186.20 -using namespace hugo;
  186.21 +using namespace lemon;
  186.22  
  186.23  using std::cout;
  186.24  using std::endl;
   187.1 --- a/src/work/marci/gw_vs_not.cc	Wed Sep 29 14:12:26 2004 +0000
   187.2 +++ b/src/work/marci/gw_vs_not.cc	Wed Sep 29 15:30:04 2004 +0000
   187.3 @@ -9,7 +9,7 @@
   187.4  #include <time_measure.h>
   187.5  #include <graph_wrapper.h>
   187.6  
   187.7 -using namespace hugo;
   187.8 +using namespace lemon;
   187.9  
  187.10  // Use a DIMACS max flow file as stdin.
  187.11  // read_dimacs_demo < dimacs_max_flow_file
   188.1 --- a/src/work/marci/iterator_bfs_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   188.2 +++ b/src/work/marci/iterator_bfs_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   188.3 @@ -4,11 +4,11 @@
   188.4  #include <string>
   188.5  
   188.6  #include <sage_graph.h>
   188.7 -#include <hugo/smart_graph.h>
   188.8 +#include <lemon/smart_graph.h>
   188.9  #include <bfs_dfs.h>
  188.10 -#include <hugo/graph_wrapper.h>
  188.11 +#include <lemon/graph_wrapper.h>
  188.12  
  188.13 -using namespace hugo;
  188.14 +using namespace lemon;
  188.15  
  188.16  using std::cout; 
  188.17  using std::endl;
   189.1 --- a/src/work/marci/leda/bipartite_matching_comparison.cc	Wed Sep 29 14:12:26 2004 +0000
   189.2 +++ b/src/work/marci/leda/bipartite_matching_comparison.cc	Wed Sep 29 15:30:04 2004 +0000
   189.3 @@ -13,18 +13,18 @@
   189.4  #include <sage_graph.h>
   189.5  //#include <smart_graph.h>
   189.6  //#include <dimacs.h>
   189.7 -#include <hugo/time_measure.h>
   189.8 +#include <lemon/time_measure.h>
   189.9  #include <for_each_macros.h>
  189.10 -#include <hugo/graph_wrapper.h>
  189.11 +#include <lemon/graph_wrapper.h>
  189.12  #include <bipartite_graph_wrapper.h>
  189.13 -#include <hugo/maps.h>
  189.14 -#include <hugo/max_flow.h>
  189.15 +#include <lemon/maps.h>
  189.16 +#include <lemon/max_flow.h>
  189.17  
  189.18  using std::cin;
  189.19  using std::cout;
  189.20  using std::endl;
  189.21  
  189.22 -using namespace hugo;
  189.23 +using namespace lemon;
  189.24  
  189.25  int main() {
  189.26    //for leda graph
  189.27 @@ -91,7 +91,7 @@
  189.28    MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
  189.29      max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
  189.30    max_flow_test.run();
  189.31 -  cout << "HUGO max matching algorithm based on preflow." << endl 
  189.32 +  cout << "LEMON max matching algorithm based on preflow." << endl 
  189.33  	    << "Size of matching: " 
  189.34  	    << max_flow_test.flowValue() << endl;
  189.35    cout << "elapsed time: " << ts << endl << endl;
  189.36 @@ -107,7 +107,7 @@
  189.37  //   FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
  189.38  //   typedef SageGraph MutableGraph;
  189.39  //   while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { }
  189.40 -//   cout << "HUGO max matching algorithm based on blocking flow augmentation." 
  189.41 +//   cout << "LEMON max matching algorithm based on blocking flow augmentation." 
  189.42  // 	    << endl << "Matching size: " 
  189.43  // 	    << max_flow_test.flowValue() << endl;
  189.44  //   cout << "elapsed time: " << ts << endl << endl;
  189.45 @@ -141,7 +141,7 @@
  189.46      SageGraph::EdgeMap<int> > 
  189.47      max_flow_test(hg, s, t, cm, flow);
  189.48    max_flow_test.run();
  189.49 -  cout << "HUGO max matching algorithm on SageGraph by copying the graph, based on preflow." 
  189.50 +  cout << "LEMON max matching algorithm on SageGraph by copying the graph, based on preflow." 
  189.51  	    << endl 
  189.52  	    << "Size of matching: " 
  189.53  	    << max_flow_test.flowValue() << endl;
   190.1 --- a/src/work/marci/leda/bipartite_matching_leda.cc	Wed Sep 29 14:12:26 2004 +0000
   190.2 +++ b/src/work/marci/leda/bipartite_matching_leda.cc	Wed Sep 29 15:30:04 2004 +0000
   190.3 @@ -13,12 +13,12 @@
   190.4  #include <sage_graph.h>
   190.5  //#include <smart_graph.h>
   190.6  //#include <dimacs.h>
   190.7 -#include <hugo/time_measure.h>
   190.8 +#include <lemon/time_measure.h>
   190.9  #include <for_each_macros.h>
  190.10 -#include <hugo/graph_wrapper.h>
  190.11 +#include <lemon/graph_wrapper.h>
  190.12  #include <bipartite_graph_wrapper.h>
  190.13 -#include <hugo/maps.h>
  190.14 -#include <hugo/max_flow.h>
  190.15 +#include <lemon/maps.h>
  190.16 +#include <lemon/max_flow.h>
  190.17  
  190.18  /**
  190.19   * Inicializalja a veletlenszamgeneratort.
  190.20 @@ -42,7 +42,7 @@
  190.21    return int( double(m) * rand() / (RAND_MAX + 1.0) );
  190.22  }
  190.23  
  190.24 -using namespace hugo;
  190.25 +using namespace lemon;
  190.26  
  190.27  int main() {
  190.28    //for leda graph
   191.1 --- a/src/work/marci/leda/bipartite_matching_leda_gen.cc	Wed Sep 29 14:12:26 2004 +0000
   191.2 +++ b/src/work/marci/leda/bipartite_matching_leda_gen.cc	Wed Sep 29 15:30:04 2004 +0000
   191.3 @@ -13,12 +13,12 @@
   191.4  #include <sage_graph.h>
   191.5  //#include <smart_graph.h>
   191.6  //#include <dimacs.h>
   191.7 -#include <hugo/time_measure.h>
   191.8 +#include <lemon/time_measure.h>
   191.9  #include <for_each_macros.h>
  191.10 -#include <hugo/graph_wrapper.h>
  191.11 +#include <lemon/graph_wrapper.h>
  191.12  #include <bipartite_graph_wrapper.h>
  191.13 -#include <hugo/maps.h>
  191.14 -#include <hugo/max_flow.h>
  191.15 +#include <lemon/maps.h>
  191.16 +#include <lemon/max_flow.h>
  191.17  #include <augmenting_flow.h>
  191.18  
  191.19  /**
  191.20 @@ -43,7 +43,7 @@
  191.21    return int( double(m) * rand() / (RAND_MAX + 1.0) );
  191.22  }
  191.23  
  191.24 -using namespace hugo;
  191.25 +using namespace lemon;
  191.26  
  191.27  int main() {
  191.28    //for leda graph
  191.29 @@ -110,7 +110,7 @@
  191.30    MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
  191.31      max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
  191.32    max_flow_test.run();
  191.33 -  std::cout << "HUGO max matching algorithm based on preflow." << std::endl 
  191.34 +  std::cout << "LEMON max matching algorithm based on preflow." << std::endl 
  191.35  	    << "Size of matching: " 
  191.36  	    << max_flow_test.flowValue() << std::endl;
  191.37    std::cout << "elapsed time: " << ts << std::endl << std::endl;
  191.38 @@ -129,7 +129,7 @@
  191.39    AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> > 
  191.40      max_flow_test_1(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
  191.41    while (max_flow_test_1.augmentOnBlockingFlow<MutableGraph>()) { }
  191.42 -  std::cout << "HUGO max matching algorithm based on blocking flow augmentation." 
  191.43 +  std::cout << "LEMON max matching algorithm based on blocking flow augmentation." 
  191.44  	    << std::endl << "Matching size: " 
  191.45  	    << max_flow_test_1.flowValue() << std::endl;
  191.46    std::cout << "elapsed time: " << ts << std::endl;
   192.1 --- a/src/work/marci/leda/leda_graph_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   192.2 +++ b/src/work/marci/leda/leda_graph_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   192.3 @@ -1,6 +1,6 @@
   192.4  // -*- c++ -*-
   192.5 -#ifndef HUGO_LEDA_GRAPH_WRAPPER_H
   192.6 -#define HUGO_LEDA_GRAPH_WRAPPER_H
   192.7 +#ifndef LEMON_LEDA_GRAPH_WRAPPER_H
   192.8 +#define LEMON_LEDA_GRAPH_WRAPPER_H
   192.9  
  192.10  #include <LEDA/graph.h>
  192.11  #include <LEDA/node_array.h>
  192.12 @@ -14,15 +14,15 @@
  192.13  //using namespace leda;
  192.14  //#endif
  192.15  
  192.16 -#include <hugo/invalid.h>
  192.17 +#include <lemon/invalid.h>
  192.18  
  192.19 -namespace hugo {
  192.20 +namespace lemon {
  192.21  
  192.22 -  /// \brief A graph wrapper structure for wrapping LEDA graphs in HUGO.
  192.23 +  /// \brief A graph wrapper structure for wrapping LEDA graphs in LEMON.
  192.24    ///
  192.25    /// This graph wrapper class wraps LEDA graphs and LEDA parametrized graphs
  192.26 -  /// to satisfy HUGO graph concepts.
  192.27 -  /// Then the generic HUGOlib algorithms and wrappers can be used 
  192.28 +  /// to satisfy LEMON graph concepts.
  192.29 +  /// Then the generic LEMON algorithms and wrappers can be used 
  192.30    /// with LEDA graphs. 
  192.31    /// \ingroup gwrapper
  192.32    template<typename Graph>
  192.33 @@ -298,7 +298,7 @@
  192.34  
  192.35  
  192.36      /// This class is to wrap existing 
  192.37 -    /// LEDA node-maps to HUGO ones.
  192.38 +    /// LEDA node-maps to LEMON ones.
  192.39      template<typename T> class NodeMapWrapper
  192.40      {
  192.41        leda_node_array<T>* leda_stuff;
  192.42 @@ -320,7 +320,7 @@
  192.43      };
  192.44  
  192.45      /// This class is to wrap existing 
  192.46 -    /// LEDA edge-maps to HUGO ones.
  192.47 +    /// LEDA edge-maps to LEMON ones.
  192.48      template<typename T> class EdgeMapWrapper
  192.49      {
  192.50        leda_edge_array<T>* leda_stuff;
  192.51 @@ -379,6 +379,6 @@
  192.52      }
  192.53    };
  192.54  
  192.55 -} //namespace hugo
  192.56 +} //namespace lemon
  192.57  
  192.58 -#endif // HUGO_LEDA_GRAPH_WRAPPER_H
  192.59 +#endif // LEMON_LEDA_GRAPH_WRAPPER_H
   193.1 --- a/src/work/marci/leda/max_bipartite_matching_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   193.2 +++ b/src/work/marci/leda/max_bipartite_matching_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   193.3 @@ -36,7 +36,7 @@
   193.4  	return int( double(m) * rand() / (RAND_MAX + 1.0) );
   193.5  }
   193.6  
   193.7 -using namespace hugo;
   193.8 +using namespace lemon;
   193.9  
  193.10  using std::cout; 
  193.11  using std::cin; 
   194.1 --- a/src/work/marci/leda_bfs_dfs.cc	Wed Sep 29 14:12:26 2004 +0000
   194.2 +++ b/src/work/marci/leda_bfs_dfs.cc	Wed Sep 29 15:30:04 2004 +0000
   194.3 @@ -11,7 +11,7 @@
   194.4  #include <graph_wrapper.h>
   194.5  #include <leda_graph_wrapper.h>
   194.6  
   194.7 -using namespace hugo;
   194.8 +using namespace lemon;
   194.9  using std::cout; 
  194.10  using std::endl;
  194.11  using std::string;
   195.1 --- a/src/work/marci/leda_graph_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   195.2 +++ b/src/work/marci/leda_graph_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   195.3 @@ -8,7 +8,7 @@
   195.4  #include <time_measure.h>
   195.5  #include <edmonds_karp.h>
   195.6  
   195.7 -using namespace hugo;
   195.8 +using namespace lemon;
   195.9  
  195.10  using std::cout; 
  195.11  using std::endl;
   196.1 --- a/src/work/marci/lg_vs_sg_vs_sg.cc	Wed Sep 29 14:12:26 2004 +0000
   196.2 +++ b/src/work/marci/lg_vs_sg_vs_sg.cc	Wed Sep 29 15:30:04 2004 +0000
   196.3 @@ -4,15 +4,15 @@
   196.4  #include <string>
   196.5  
   196.6  #include <sage_graph.h>
   196.7 -#include <hugo/list_graph.h>
   196.8 -#include <hugo/smart_graph.h>
   196.9 -#include <hugo/dimacs.h>
  196.10 -#include <hugo/max_flow.h>
  196.11 +#include <lemon/list_graph.h>
  196.12 +#include <lemon/smart_graph.h>
  196.13 +#include <lemon/dimacs.h>
  196.14 +#include <lemon/max_flow.h>
  196.15  #include <augmenting_flow.h>
  196.16 -#include <hugo/time_measure.h>
  196.17 +#include <lemon/time_measure.h>
  196.18  #include <for_each_macros.h>
  196.19  
  196.20 -using namespace hugo;
  196.21 +using namespace lemon;
  196.22  
  196.23  // Use a DIMACS max flow file as stdin.
  196.24  // read_dimacs_demo dimacs_max_flow_file
   197.1 --- a/src/work/marci/lp/lp_solver_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   197.2 +++ b/src/work/marci/lp/lp_solver_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   197.3 @@ -1,6 +1,6 @@
   197.4  // -*- c++ -*-
   197.5 -#ifndef HUGO_LP_SOLVER_WRAPPER_H
   197.6 -#define HUGO_LP_SOLVER_WRAPPER
   197.7 +#ifndef LEMON_LP_SOLVER_WRAPPER_H
   197.8 +#define LEMON_LP_SOLVER_WRAPPER
   197.9  
  197.10  ///\ingroup misc
  197.11  ///\file
  197.12 @@ -20,12 +20,12 @@
  197.13  #include <utility>
  197.14  
  197.15  //#include <sage_graph.h>
  197.16 -//#include <hugo/list_graph.h>
  197.17 -//#include <hugo/graph_wrapper.h>
  197.18 -#include <hugo/invalid.h>
  197.19 +//#include <lemon/list_graph.h>
  197.20 +//#include <lemon/graph_wrapper.h>
  197.21 +#include <lemon/invalid.h>
  197.22  //#include <bfs_dfs.h>
  197.23  //#include <stp.h>
  197.24 -//#include <hugo/max_flow.h>
  197.25 +//#include <lemon/max_flow.h>
  197.26  //#include <augmenting_flow.h>
  197.27  //#include <iter_map.h>
  197.28  
  197.29 @@ -33,7 +33,7 @@
  197.30  using std::cin;
  197.31  using std::endl;
  197.32  
  197.33 -namespace hugo {
  197.34 +namespace lemon {
  197.35  
  197.36    
  197.37    /// \addtogroup misc
  197.38 @@ -44,7 +44,7 @@
  197.39    /// This class implements a container in which the data is stored in an 
  197.40    /// stl vector, the range is partitioned into sets and each set is 
  197.41    /// doubly linked in a list. 
  197.42 -  /// That is, each class is iterable by hugo iterators, and any member of 
  197.43 +  /// That is, each class is iterable by lemon iterators, and any member of 
  197.44    /// the vector can bo moved to an other class.
  197.45    template <typename T>
  197.46    class IterablePartition {
  197.47 @@ -63,7 +63,7 @@
  197.48    public:
  197.49      /// The classes are indexed by integers from \c 0 to \c classNum()-1.
  197.50      int classNum() const { return tips.size(); }
  197.51 -    /// This hugo style iterator iterates through a class. 
  197.52 +    /// This lemon style iterator iterates through a class. 
  197.53      class ClassIt;
  197.54      /// Constructor. The number of classes is to be given which is fixed 
  197.55      /// over the life of the container. 
  197.56 @@ -157,8 +157,8 @@
  197.57    
  197.58    /// \brief Wrappers for LP solvers
  197.59    /// 
  197.60 -  /// This class implements a hugo wrapper for glpk.
  197.61 -  /// Later other LP-solvers will be wrapped into hugo.
  197.62 +  /// This class implements a lemon wrapper for glpk.
  197.63 +  /// Later other LP-solvers will be wrapped into lemon.
  197.64    /// The aim of this class is to give a general surface to different 
  197.65    /// solvers, i.e. it makes possible to write algorithms using LP's, 
  197.66    /// in which the solver can be changed to an other one easily.
  197.67 @@ -424,6 +424,6 @@
  197.68    
  197.69    /// @}
  197.70  
  197.71 -} //namespace hugo
  197.72 +} //namespace lemon
  197.73  
  197.74 -#endif //HUGO_LP_SOLVER_WRAPPER_H
  197.75 +#endif //LEMON_LP_SOLVER_WRAPPER_H
   198.1 --- a/src/work/marci/lp/max_flow_by_lp.cc	Wed Sep 29 14:12:26 2004 +0000
   198.2 +++ b/src/work/marci/lp/max_flow_by_lp.cc	Wed Sep 29 15:30:04 2004 +0000
   198.3 @@ -3,17 +3,17 @@
   198.4  #include <fstream>
   198.5  
   198.6  #include <sage_graph.h>
   198.7 -#include <hugo/smart_graph.h>
   198.8 -#include <hugo/dimacs.h>
   198.9 -#include <hugo/time_measure.h>
  198.10 +#include <lemon/smart_graph.h>
  198.11 +#include <lemon/dimacs.h>
  198.12 +#include <lemon/time_measure.h>
  198.13  //#include <graph_wrapper.h>
  198.14 -#include <hugo/max_flow.h>
  198.15 +#include <lemon/max_flow.h>
  198.16  #include <augmenting_flow.h>
  198.17  //#include <preflow_res.h>
  198.18  #include <for_each_macros.h>
  198.19  #include <lp_solver_wrapper.h>
  198.20  
  198.21 -using namespace hugo;
  198.22 +using namespace lemon;
  198.23  
  198.24  // Use a DIMACS max flow file as stdin.
  198.25  // max_flow_demo < dimacs_max_flow_file
   199.1 --- a/src/work/marci/macro_test.cc	Wed Sep 29 14:12:26 2004 +0000
   199.2 +++ b/src/work/marci/macro_test.cc	Wed Sep 29 15:30:04 2004 +0000
   199.3 @@ -5,7 +5,7 @@
   199.4  #include <sage_graph.h>
   199.5  #include <for_each_macros.h>
   199.6  
   199.7 -using namespace hugo;
   199.8 +using namespace lemon;
   199.9  
  199.10  int main() 
  199.11  {
   200.1 --- a/src/work/marci/max_bipartite_matching.h	Wed Sep 29 14:12:26 2004 +0000
   200.2 +++ b/src/work/marci/max_bipartite_matching.h	Wed Sep 29 15:30:04 2004 +0000
   200.3 @@ -1,6 +1,6 @@
   200.4  // -*- c++ -*-
   200.5 -#ifndef HUGO_MAX_BIPARTITE_MATCHING_H
   200.6 -#define HUGO_MAX_BIPARTITE_MATCHING_H
   200.7 +#ifndef LEMON_MAX_BIPARTITE_MATCHING_H
   200.8 +#define LEMON_MAX_BIPARTITE_MATCHING_H
   200.9  
  200.10  /// \ingroup galgs
  200.11  /// \file
  200.12 @@ -14,10 +14,10 @@
  200.13  
  200.14  //#include <for_each_macros.h>
  200.15  #include <bipartite_graph_wrapper.h>
  200.16 -//#include <hugo/maps.h>
  200.17 -#include <hugo/max_flow.h>
  200.18 +//#include <lemon/maps.h>
  200.19 +#include <lemon/max_flow.h>
  200.20  
  200.21 -namespace hugo {
  200.22 +namespace lemon {
  200.23  
  200.24    // template <typename Graph, typename EdgeCap, typename NodeCap, 
  200.25    // 	  typename EdgeFlow, typename NodeFlow>
  200.26 @@ -135,6 +135,6 @@
  200.27      int matchingValue() const { return mf.flowValue(); }
  200.28    };
  200.29  
  200.30 -} //namespace hugo
  200.31 +} //namespace lemon
  200.32  
  200.33 -#endif //HUGO_MAX_BIPARTITE_MATCHING_H
  200.34 +#endif //LEMON_MAX_BIPARTITE_MATCHING_H
   201.1 --- a/src/work/marci/max_flow_1.cc	Wed Sep 29 14:12:26 2004 +0000
   201.2 +++ b/src/work/marci/max_flow_1.cc	Wed Sep 29 15:30:04 2004 +0000
   201.3 @@ -3,15 +3,15 @@
   201.4  #include <fstream>
   201.5  
   201.6  #include <sage_graph.h>
   201.7 -#include <hugo/smart_graph.h>
   201.8 -#include <hugo/dimacs.h>
   201.9 -#include <hugo/time_measure.h>
  201.10 +#include <lemon/smart_graph.h>
  201.11 +#include <lemon/dimacs.h>
  201.12 +#include <lemon/time_measure.h>
  201.13  //#include <graph_wrapper.h>
  201.14 -#include <hugo/max_flow.h>
  201.15 +#include <lemon/max_flow.h>
  201.16  //#include <preflow_res.h>
  201.17  #include <for_each_macros.h>
  201.18  
  201.19 -using namespace hugo;
  201.20 +using namespace lemon;
  201.21  
  201.22  // Use a DIMACS max flow file as stdin.
  201.23  // read_dimacs_demo < dimacs_max_flow_file
   202.1 --- a/src/work/marci/max_flow_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   202.2 +++ b/src/work/marci/max_flow_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   202.3 @@ -6,15 +6,15 @@
   202.4  #include <iostream>
   202.5  #include <fstream>
   202.6  
   202.7 -#include <hugo/smart_graph.h>
   202.8 -#include <hugo/list_graph.h>
   202.9 -#include <hugo/dimacs.h>
  202.10 -#include <hugo/time_measure.h>
  202.11 -#include <hugo/preflow.h>
  202.12 +#include <lemon/smart_graph.h>
  202.13 +#include <lemon/list_graph.h>
  202.14 +#include <lemon/dimacs.h>
  202.15 +#include <lemon/time_measure.h>
  202.16 +#include <lemon/preflow.h>
  202.17  #include <augmenting_flow.h>
  202.18  #include <graph_concept.h>
  202.19  
  202.20 -using namespace hugo;
  202.21 +using namespace lemon;
  202.22  
  202.23  int main(int, char **) {
  202.24  
   203.1 --- a/src/work/marci/merge_node_graph_wrapper.h	Wed Sep 29 14:12:26 2004 +0000
   203.2 +++ b/src/work/marci/merge_node_graph_wrapper.h	Wed Sep 29 15:30:04 2004 +0000
   203.3 @@ -1,5 +1,5 @@
   203.4  /* -*- C++ -*-
   203.5 - * src/hugo/merge_node_graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
   203.6 + * src/lemon/merge_node_graph_wrapper.h - Part of LEMON, a generic C++ optimization library
   203.7   *
   203.8   * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
   203.9   * (Egervary Combinatorial Optimization Research Group, EGRES).
  203.10 @@ -14,16 +14,16 @@
  203.11   *
  203.12   */
  203.13  
  203.14 -#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
  203.15 -#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
  203.16 +#ifndef LEMON_MERGE_NODE_GRAPH_WRAPPER_H
  203.17 +#define LEMON_MERGE_NODE_GRAPH_WRAPPER_H
  203.18  
  203.19 -#include <hugo/invalid.h>
  203.20 -#include <hugo/maps.h>
  203.21 -#include <hugo/map_defines.h>
  203.22 -#include <hugo/graph_wrapper.h>
  203.23 +#include <lemon/invalid.h>
  203.24 +#include <lemon/maps.h>
  203.25 +#include <lemon/map_defines.h>
  203.26 +#include <lemon/graph_wrapper.h>
  203.27  #include <iostream>
  203.28  
  203.29 -namespace hugo {
  203.30 +namespace lemon {
  203.31  
  203.32    template <typename Graph1, typename Graph2, typename Enable=void> 
  203.33    class MergeNodeGraphWrapper : 
  203.34 @@ -172,6 +172,6 @@
  203.35      
  203.36    };
  203.37  
  203.38 -} //namespace hugo
  203.39 +} //namespace lemon
  203.40  
  203.41 -#endif //HUGO_MERGE_NODE_GRAPH_WRAPPER_H
  203.42 +#endif //LEMON_MERGE_NODE_GRAPH_WRAPPER_H
   204.1 --- a/src/work/marci/merge_node_graph_wrapper_test.cc	Wed Sep 29 14:12:26 2004 +0000
   204.2 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc	Wed Sep 29 15:30:04 2004 +0000
   204.3 @@ -1,13 +1,13 @@
   204.4  #include <iostream>
   204.5  
   204.6 -#include <hugo/list_graph.h>
   204.7 -#include <hugo/smart_graph.h>
   204.8 +#include <lemon/list_graph.h>
   204.9 +#include <lemon/smart_graph.h>
  204.10  #include <merge_node_graph_wrapper.h>
  204.11  
  204.12  using std::cout;
  204.13  using std::endl;
  204.14  
  204.15 -using namespace hugo;
  204.16 +using namespace lemon;
  204.17  
  204.18  int main() {
  204.19    typedef SmartGraph Graph1;
   205.1 --- a/src/work/marci/oldies/edmonds_karp.h	Wed Sep 29 14:12:26 2004 +0000
   205.2 +++ b/src/work/marci/oldies/edmonds_karp.h	Wed Sep 29 15:30:04 2004 +0000
   205.3 @@ -1,6 +1,6 @@
   205.4  // -*- c++ -*-
   205.5 -#ifndef HUGO_EDMONDS_KARP_H
   205.6 -#define HUGO_EDMONDS_KARP_H
   205.7 +#ifndef LEMON_EDMONDS_KARP_H
   205.8 +#define LEMON_EDMONDS_KARP_H
   205.9  
  205.10  #include <algorithm>
  205.11  #include <list>
  205.12 @@ -12,7 +12,7 @@
  205.13  #include <maps.h>
  205.14  #include <for_each_macros.h>
  205.15  
  205.16 -namespace hugo {
  205.17 +namespace lemon {
  205.18  
  205.19    template <typename Graph, typename Num, 
  205.20  	    typename CapMap, typename FlowMap>
  205.21 @@ -951,6 +951,6 @@
  205.22  // //   };
  205.23  
  205.24  
  205.25 -} // namespace hugo
  205.26 +} // namespace lemon
  205.27  
  205.28 -#endif //HUGO_EDMONDS_KARP_H
  205.29 +#endif //LEMON_EDMONDS_KARP_H
   206.1 --- a/src/work/marci/oldies/marci_graph_demo.cc	Wed Sep 29 14:12:26 2004 +0000
   206.2 +++ b/src/work/marci/oldies/marci_graph_demo.cc	Wed Sep 29 15:30:04 2004 +0000
   206.3 @@ -6,7 +6,7 @@
   206.4  #include <bfs_iterator.h>
   206.5  #include <edmonds_karp.h>
   206.6  
   206.7 -using namespace hugo;
   206.8 +using namespace lemon;
   206.9  
  206.10  int main (int, char*[])
  206.11  {
   207.1 --- a/src/work/marci/preflow_bug.cc	Wed Sep 29 14:12:26 2004 +0000
   207.2 +++ b/src/work/marci/preflow_bug.cc	Wed Sep 29 15:30:04 2004 +0000
   207.3 @@ -3,11 +3,11 @@
   207.4  #include <fstream>
   207.5  
   207.6  #include <sage_graph.h>
   207.7 -#include <hugo/smart_graph.h>
   207.8 -#include <hugo/dimacs.h>
   207.9 -//#include <hugo/time_measure.h>
  207.10 +#include <lemon/smart_graph.h>
  207.11 +#include <lemon/dimacs.h>
  207.12 +//#include <lemon/time_measure.h>
  207.13  //#include <graph_wrapper.h>
  207.14 -#include <hugo/max_flow.h>
  207.15 +#include <lemon/max_flow.h>
  207.16  //#include <preflow_res.h>
  207.17  #include <for_each_macros.h>
  207.18  #include <graph_concept.h>
  207.19 @@ -15,7 +15,7 @@
  207.20  using std::cout;
  207.21  using std::endl;
  207.22  
  207.23 -using namespace hugo;
  207.24 +using namespace lemon;
  207.25  
  207.26  // Use a DIMACS min cost flow file as stdin.
  207.27  // read_dimacs_demo < dimacs_max_flow_file
   208.1 --- a/src/work/marci/preflow_demo_athos.cc	Wed Sep 29 14:12:26 2004 +0000
   208.2 +++ b/src/work/marci/preflow_demo_athos.cc	Wed Sep 29 15:30:04 2004 +0000
   208.3 @@ -6,7 +6,7 @@
   208.4  #include <preflow_push.hh>
   208.5  #include <time_measure.h>
   208.6  
   208.7 -using namespace hugo;
   208.8 +using namespace lemon;
   208.9  
  208.10  // Use a DIMACS max flow file as stdin.
  208.11  // read_dimacs_demo < dimacs_max_flow_file
   209.1 --- a/src/work/marci/preflow_demo_jacint.cc	Wed Sep 29 14:12:26 2004 +0000
   209.2 +++ b/src/work/marci/preflow_demo_jacint.cc	Wed Sep 29 15:30:04 2004 +0000
   209.3 @@ -7,7 +7,7 @@
   209.4  #include <preflow_push_hl.h>
   209.5  #include <time_measure.h>
   209.6  
   209.7 -using namespace hugo;
   209.8 +using namespace lemon;
   209.9  
  209.10  // Use a DIMACS max flow file as stdin.
  209.11  // read_dimacs_demo < dimacs_max_flow_file
   210.1 --- a/src/work/marci/top_sort_test.cc	Wed Sep 29 14:12:26 2004 +0000
   210.2 +++ b/src/work/marci/top_sort_test.cc	Wed Sep 29 15:30:04 2004 +0000
   210.3 @@ -3,14 +3,14 @@
   210.4  #include <fstream>
   210.5  #include <list>
   210.6  
   210.7 -#include <hugo/dimacs.h>
   210.8 +#include <lemon/dimacs.h>
   210.9  #include <bfs_dfs_misc.h>
  210.10  #include <sage_graph.h>
  210.11 -#include <hugo/graph_wrapper.h>
  210.12 -#include <hugo/maps.h>
  210.13 +#include <lemon/graph_wrapper.h>
  210.14 +#include <lemon/maps.h>
  210.15  #include <for_each_macros.h>
  210.16  
  210.17 -using namespace hugo;
  210.18 +using namespace lemon;
  210.19  
  210.20  using std::cout;
  210.21  using std::endl;
   211.1 --- a/src/work/peter/edgepathgraph.h	Wed Sep 29 14:12:26 2004 +0000
   211.2 +++ b/src/work/peter/edgepathgraph.h	Wed Sep 29 15:30:04 2004 +0000
   211.3 @@ -1,15 +1,15 @@
   211.4  // -*- c++ -*-
   211.5 -#ifndef HUGO_NET_GRAPH_H
   211.6 -#define HUGO_NET_GRAPH_H
   211.7 +#ifndef LEMON_NET_GRAPH_H
   211.8 +#define LEMON_NET_GRAPH_H
   211.9  
  211.10  ///\file
  211.11  ///\brief Declaration of EdgePathGraph.
  211.12  
  211.13 -#include <hugo/invalid.h>
  211.14 -#include <hugo/maps.h>
  211.15 +#include <lemon/invalid.h>
  211.16 +#include <lemon/maps.h>
  211.17  
  211.18 -/// The namespace of HugoLib
  211.19 -namespace hugo {
  211.20 +/// The namespace of LEMON
  211.21 +namespace lemon {
  211.22  
  211.23    // @defgroup empty_graph The EdgePathGraph class
  211.24    // @{
  211.25 @@ -401,7 +401,7 @@
  211.26    
  211.27    // @}
  211.28  
  211.29 -} //namespace hugo
  211.30 +} //namespace lemon
  211.31  
  211.32  
  211.33 -#endif // HUGO_SKELETON_GRAPH_H
  211.34 +#endif // LEMON_SKELETON_GRAPH_H
   212.1 --- a/src/work/peter/edgepathgraph_test.cc	Wed Sep 29 14:12:26 2004 +0000
   212.2 +++ b/src/work/peter/edgepathgraph_test.cc	Wed Sep 29 15:30:04 2004 +0000
   212.3 @@ -3,11 +3,11 @@
   212.4  #include <stdio.h>
   212.5  
   212.6  #include "edgepathgraph.h"
   212.7 -#include <hugo/list_graph.h>
   212.8 -#include <hugo/smart_graph.h>
   212.9 +#include <lemon/list_graph.h>
  212.10 +#include <lemon/smart_graph.h>
  212.11  #include <path.h>
  212.12  
  212.13 -using namespace hugo;
  212.14 +using namespace lemon;
  212.15  using namespace std;
  212.16  
  212.17  bool passed = true;
   213.1 --- a/src/work/peter/hierarchygraph.h	Wed Sep 29 14:12:26 2004 +0000
   213.2 +++ b/src/work/peter/hierarchygraph.h	Wed Sep 29 15:30:04 2004 +0000
   213.3 @@ -1,15 +1,15 @@
   213.4  // -*- c++ -*-
   213.5 -#ifndef HUGO_NET_GRAPH_H
   213.6 -#define HUGO_NET_GRAPH_H
   213.7 +#ifndef LEMON_NET_GRAPH_H
   213.8 +#define LEMON_NET_GRAPH_H
   213.9  
  213.10  ///\file
  213.11  ///\brief Declaration of HierarchyGraph.
  213.12  
  213.13 -#include <hugo/invalid.h>
  213.14 -#include <hugo/maps.h>
  213.15 +#include <lemon/invalid.h>
  213.16 +#include <lemon/maps.h>
  213.17  
  213.18 -/// The namespace of HugoLib
  213.19 -namespace hugo
  213.20 +/// The namespace of LEMON
  213.21 +namespace lemon
  213.22  {
  213.23  
  213.24    // @defgroup empty_graph The HierarchyGraph class
  213.25 @@ -575,7 +575,7 @@
  213.26  
  213.27    // @}
  213.28  
  213.29 -}				//namespace hugo
  213.30 +}				//namespace lemon
  213.31  
  213.32  
  213.33 -#endif // HUGO_SKELETON_GRAPH_H
  213.34 +#endif // LEMON_SKELETON_GRAPH_H
   214.1 --- a/src/work/peter/hierarchygraph_test.cc	Wed Sep 29 14:12:26 2004 +0000
   214.2 +++ b/src/work/peter/hierarchygraph_test.cc	Wed Sep 29 15:30:04 2004 +0000
   214.3 @@ -3,11 +3,11 @@
   214.4  #include <stdio.h>
   214.5  
   214.6  #include "hierarchygraph.h"
   214.7 -#include <hugo/list_graph.h>
   214.8 -#include <hugo/smart_graph.h>
   214.9 +#include <lemon/list_graph.h>
  214.10 +#include <lemon/smart_graph.h>
  214.11  #include <path.h>
  214.12  
  214.13 -using namespace hugo;
  214.14 +using namespace lemon;
  214.15  using namespace std;
  214.16  
  214.17  bool passed = true;
   215.1 --- a/src/work/peter/path/debug.h	Wed Sep 29 14:12:26 2004 +0000
   215.2 +++ b/src/work/peter/path/debug.h	Wed Sep 29 15:30:04 2004 +0000
   215.3 @@ -1,12 +1,12 @@
   215.4  // -*- C++ -*- //
   215.5  
   215.6 -#ifndef HUGO_DEBUG_H
   215.7 -#define HUGO_DEBUG_H
   215.8 +#ifndef LEMON_DEBUG_H
   215.9 +#define LEMON_DEBUG_H
  215.10  
  215.11  //! \file
  215.12  //! \brief Basic definitions for debug control.
  215.13  
  215.14 -namespace hugo {
  215.15 +namespace lemon {
  215.16  
  215.17    //! Debug mode for testing/debugging
  215.18  
  215.19 @@ -53,4 +53,4 @@
  215.20  #endif
  215.21  
  215.22  }
  215.23 -#endif // HUGO_DEBUG_H
  215.24 +#endif // LEMON_DEBUG_H
   216.1 --- a/src/work/peter/path/path.h	Wed Sep 29 14:12:26 2004 +0000
   216.2 +++ b/src/work/peter/path/path.h	Wed Sep 29 15:30:04 2004 +0000
   216.3 @@ -3,16 +3,16 @@
   216.4  /**
   216.5  @defgroup paths Path Structures
   216.6  @ingroup datas
   216.7 -\brief Path structures implemented in Hugo.
   216.8 +\brief Path structures implemented in LEMON.
   216.9  
  216.10 -Hugolib provides flexible data structures
  216.11 +LEMON provides flexible data structures
  216.12  to work with paths.
  216.13  
  216.14  All of them have the same interface, especially they can be built or extended
  216.15  using a standard Builder subclass. This make is easy to have e.g. the Dijkstra
  216.16  algorithm to store its result in any kind of path structure.
  216.17  
  216.18 -\sa hugo::skeleton::Path
  216.19 +\sa lemon::skeleton::Path
  216.20  
  216.21  */
  216.22  
  216.23 @@ -20,18 +20,18 @@
  216.24  ///\file
  216.25  ///\brief Classes for representing paths in graphs.
  216.26  
  216.27 -#ifndef HUGO_PATH_H
  216.28 -#define HUGO_PATH_H
  216.29 +#ifndef LEMON_PATH_H
  216.30 +#define LEMON_PATH_H
  216.31  
  216.32  #include <deque>
  216.33  #include <vector>
  216.34  #include <algorithm>
  216.35  
  216.36 -#include <hugo/invalid.h>
  216.37 -#include <hugo/error.h>
  216.38 +#include <lemon/invalid.h>
  216.39 +#include <lemon/error.h>
  216.40  #include <debug.h>
  216.41  
  216.42 -namespace hugo {
  216.43 +namespace lemon {
  216.44  
  216.45    /// \addtogroup paths
  216.46    /// @{
  216.47 @@ -1169,6 +1169,6 @@
  216.48  
  216.49    ///@}
  216.50  
  216.51 -} // namespace hugo
  216.52 +} // namespace lemon
  216.53  
  216.54 -#endif // HUGO_PATH_H
  216.55 +#endif // LEMON_PATH_H
   217.1 --- a/src/work/peter/path/path_skeleton.h	Wed Sep 29 14:12:26 2004 +0000
   217.2 +++ b/src/work/peter/path/path_skeleton.h	Wed Sep 29 15:30:04 2004 +0000
   217.3 @@ -5,12 +5,12 @@
   217.4  ///\file
   217.5  ///\brief Classes for representing paths in graphs.
   217.6  
   217.7 -#ifndef HUGO_PATH_H
   217.8 -#define HUGO_PATH_H
   217.9 +#ifndef LEMON_PATH_H
  217.10 +#define LEMON_PATH_H
  217.11  
  217.12 -#include <hugo/invalid.h>
  217.13 +#include <lemon/invalid.h>
  217.14  
  217.15 -namespace hugo {
  217.16 +namespace lemon {
  217.17    namespace skeleton {
  217.18      /// \addtogroup skeletons
  217.19      /// @{
  217.20 @@ -218,6 +218,6 @@
  217.21    ///@}
  217.22    }
  217.23    
  217.24 -} // namespace hugo
  217.25 +} // namespace lemon
  217.26  
  217.27 -#endif // HUGO_PATH_H
  217.28 +#endif // LEMON_PATH_H
   218.1 --- a/src/work/peter/path/path_test.cc	Wed Sep 29 14:12:26 2004 +0000
   218.2 +++ b/src/work/peter/path/path_test.cc	Wed Sep 29 15:30:04 2004 +0000
   218.3 @@ -5,7 +5,7 @@
   218.4  #include <list_graph.h>
   218.5  
   218.6  using namespace std;
   218.7 -using namespace hugo;
   218.8 +using namespace lemon;
   218.9  using namespace skeleton;
  218.10  
  218.11  bool passed = true;
   219.1 --- a/src/work/sage_graph.h	Wed Sep 29 14:12:26 2004 +0000
   219.2 +++ b/src/work/sage_graph.h	Wed Sep 29 15:30:04 2004 +0000
   219.3 @@ -1,13 +1,13 @@
   219.4  // -*- c++ -*-
   219.5 -#ifndef HUGO_SAGE_GRAPH_H
   219.6 -#define HUGO_SAGE_GRAPH_H
   219.7 +#ifndef LEMON_SAGE_GRAPH_H
   219.8 +#define LEMON_SAGE_GRAPH_H
   219.9  
  219.10  #include <iostream>
  219.11  #include <vector>
  219.12  
  219.13 -#include <hugo/invalid.h>
  219.14 +#include <lemon/invalid.h>
  219.15  
  219.16 -namespace hugo {
  219.17 +namespace lemon {
  219.18  
  219.19  //   template <typename It>
  219.20  //   int count(It it) { 
  219.21 @@ -536,6 +536,6 @@
  219.22      typedef SymEdgeIt InEdgeIt;
  219.23    };
  219.24  
  219.25 -} //namespace hugo
  219.26 +} //namespace lemon
  219.27  
  219.28 -#endif //HUGO_SAGE_GRAPH_H
  219.29 +#endif //LEMON_SAGE_GRAPH_H