[Lemon-commits] [lemon_svn] klao: r1318 - in hugo/branches/graph_factory: . doc src/lemon src/test src/work src/work/akos src/work/alpar src/work/marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:35 CET 2006
Author: klao
Date: Wed Oct 27 15:39:16 2004
New Revision: 1318
Added:
hugo/branches/graph_factory/src/work/akos/simann.h
- copied unchanged from r1315, /hugo/trunk/src/work/akos/simann.h
hugo/branches/graph_factory/src/work/marci/bfs_mm.h
- copied unchanged from r1315, /hugo/trunk/src/work/marci/bfs_mm.h
hugo/branches/graph_factory/src/work/marci/bfs_mm_test.cc
- copied unchanged from r1315, /hugo/trunk/src/work/marci/bfs_mm_test.cc
Removed:
hugo/branches/graph_factory/src/work/akos/SimAnn.h
Modified:
hugo/branches/graph_factory/configure.ac
hugo/branches/graph_factory/doc/Doxyfile
hugo/branches/graph_factory/src/lemon/min_cost_flow.h
hugo/branches/graph_factory/src/lemon/suurballe.h
hugo/branches/graph_factory/src/test/min_cost_flow_test.cc
hugo/branches/graph_factory/src/test/preflow_test.cc
hugo/branches/graph_factory/src/test/suurballe_test.cc
hugo/branches/graph_factory/src/work/Doxyfile
hugo/branches/graph_factory/src/work/akos/simann_test.cc
hugo/branches/graph_factory/src/work/alpar/bfs-named-param.cc
hugo/branches/graph_factory/src/work/marci/augmenting_flow.h
hugo/branches/graph_factory/src/work/marci/bfsit_vs_byhand.cc
hugo/branches/graph_factory/src/work/marci/makefile
Log:
trunk -r 1266:1315 merged to branches/graph_factory
Modified: hugo/branches/graph_factory/configure.ac
==============================================================================
--- hugo/branches/graph_factory/configure.ac (original)
+++ hugo/branches/graph_factory/configure.ac Wed Oct 27 15:39:16 2004
@@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
-AC_INIT([LEMON], [0.2], [etik-ol at cs.elte.hu], [lemon])
+AC_INIT([LEMON], [0.3], [etik-ol at cs.elte.hu], [lemon])
AC_CONFIG_AUX_DIR([config])
AM_INIT_AUTOMAKE(1.7)
AC_CONFIG_SRCDIR([src/lemon/invalid.h])
Modified: hugo/branches/graph_factory/doc/Doxyfile
==============================================================================
--- hugo/branches/graph_factory/doc/Doxyfile (original)
+++ hugo/branches/graph_factory/doc/Doxyfile Wed Oct 27 15:39:16 2004
@@ -1,4 +1,4 @@
-# Doxyfile 1.3.6
+# Doxyfile 1.3.9
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project
@@ -23,7 +23,7 @@
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 0.2
+PROJECT_NUMBER = 0.3
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
@@ -32,14 +32,24 @@
OUTPUT_DIRECTORY =
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of source
+# files, where putting all generated files in the same directory would otherwise
+# cause performance problems for the file system.
+
+CREATE_SUBDIRS = NO
+
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
# documentation generated by doxygen is written. Doxygen will use this
# information to generate all constant output in the proper language.
# The default language is English, other supported languages are:
-# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch,
-# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en
-# (Japanese with English messages), Korean, Korean-en, Norwegian, Polish, Portuguese,
-# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian.
+# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish,
+# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese,
+# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish,
+# Swedish, and Ukrainian.
OUTPUT_LANGUAGE = English
@@ -95,16 +105,25 @@
# path before files name in the file list and in the header files. If set
# to NO the shortest path that makes the file name unique will be used.
-FULL_PATH_NAMES = NO
+FULL_PATH_NAMES = YES
# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
# can be used to strip a user-defined part of the path. Stripping is
# only done if one of the specified strings matches the left-hand part of
-# the path. It is allowed to use relative paths in the argument list.
+# the path. The tag can be used to show relative paths in the file list.
# If left blank the directory from which doxygen is run is used as the
# path to strip.
-STRIP_FROM_PATH =
+STRIP_FROM_PATH = ../src
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH = ../src
# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
# (but less readable) file names. This can be useful is your file systems
@@ -211,6 +230,13 @@
EXTRACT_LOCAL_CLASSES = YES
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS = NO
+
# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
# undocumented members of documented classes, files or namespaces.
# If set to NO (the default) these members will be included in the
@@ -251,7 +277,7 @@
# file names in lower-case letters. If set to YES upper-case letters are also
# allowed. This is useful if you have classes or files whose names only differ
# in case and if your file system supports case sensitive file names. Windows
-# users are advised to set this option to NO.
+# and Mac users are advised to set this option to NO.
CASE_SENSE_NAMES = YES
@@ -341,6 +367,12 @@
SHOW_USED_FILES = YES
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation.
+
+SHOW_DIRECTORIES = YES
+
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
@@ -392,7 +424,7 @@
# with spaces.
INPUT = mainpage.dox \
- graphs.dox \
+ graphs.dox \
maps.dox \
coding_style.dox \
groups.dox \
@@ -406,7 +438,7 @@
# and *.h) to filter out the source-files in the directories. If left
# blank the following patterns are tested:
# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp
-# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc
+# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm
FILE_PATTERNS =
@@ -464,10 +496,20 @@
# by executing (via popen()) the command <filter> <input-file>, where <filter>
# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
# input file. Doxygen will then use the output that the filter program writes
-# to standard output.
+# to standard output. If FILTER_PATTERNS is specified, this tag will be
+# ignored.
INPUT_FILTER =
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS =
+
# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
# INPUT_FILTER) will be used to filter the input files when producing source
# files to browse (i.e. when SOURCE_BROWSER is set to YES).
@@ -920,7 +962,9 @@
# are defined before the preprocessor is started (similar to the -D option of
# gcc). The argument of the tag is a list of macros of the form: name
# or name=definition (no spaces). If the definition and the = are
-# omitted =1 is assumed.
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
PREDEFINED = DOXYGEN
Modified: hugo/branches/graph_factory/src/lemon/min_cost_flow.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/min_cost_flow.h (original)
+++ hugo/branches/graph_factory/src/lemon/min_cost_flow.h Wed Oct 27 15:39:16 2004
@@ -70,108 +70,85 @@
typedef typename Graph::OutEdgeIt OutEdgeIt;
typedef typename Graph::template EdgeMap<int> EdgeIntMap;
-
typedef ResGraphWrapper<const Graph,int,CapacityMap,EdgeIntMap> ResGW;
typedef typename ResGW::Edge ResGraphEdge;
+ protected:
+
+ const Graph& g;
+ const LengthMap& length;
+ const CapacityMap& capacity;
+
+ EdgeIntMap flow;
+ typedef typename Graph::template NodeMap<Length> PotentialMap;
+ PotentialMap potential;
+
+ Node s;
+ Node t;
+
+ Length total_length;
+
class ModLengthMap {
typedef typename Graph::template NodeMap<Length> NodeMap;
- const ResGW& G;
- const LengthMap &ol;
+ const ResGW& g;
+ const LengthMap &length;
const NodeMap &pot;
public :
typedef typename LengthMap::KeyType KeyType;
typedef typename LengthMap::ValueType ValueType;
+
+ ModLengthMap(const ResGW& _g,
+ const LengthMap &_length, const NodeMap &_pot) :
+ g(_g), /*rev(_rev),*/ length(_length), pot(_pot) { }
ValueType operator[](typename ResGW::Edge e) const {
- if (G.forward(e))
- return ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);
+ if (g.forward(e))
+ return length[e]-(pot[g.head(e)]-pot[g.tail(e)]);
else
- return -ol[e]-(pot[G.head(e)]-pot[G.tail(e)]);
+ return -length[e]-(pot[g.head(e)]-pot[g.tail(e)]);
}
- ModLengthMap(const ResGW& _G,
- const LengthMap &o, const NodeMap &p) :
- G(_G), /*rev(_rev),*/ ol(o), pot(p){};
- };//ModLengthMap
+ }; //ModLengthMap
+ ResGW res_graph;
+ ModLengthMap mod_length;
+ Dijkstra<ResGW, ModLengthMap> dijkstra;
- protected:
-
- //Input
- const Graph& G;
- const LengthMap& length;
- const CapacityMap& capacity;
-
-
- //auxiliary variables
+ public :
- //To store the flow
- EdgeIntMap flow;
- //To store the potential (dual variables)
- typedef typename Graph::template NodeMap<Length> PotentialMap;
- PotentialMap potential;
+ /*! \brief The constructor of the class.
+ \param _g The directed graph the algorithm runs on.
+ \param _length The length (weight or cost) of the edges.
+ \param _cap The capacity of the edges.
+ \param _s Source node.
+ \param _t Target node.
+ */
+ MinCostFlow(Graph& _g, LengthMap& _length, CapacityMap& _cap,
+ Node _s, Node _t) :
+ g(_g), length(_length), capacity(_cap), flow(_g), potential(_g),
+ s(_s), t(_t),
+ res_graph(g, capacity, flow),
+ mod_length(res_graph, length, potential),
+ dijkstra(res_graph, mod_length) {
+ reset();
+ }
- Length total_length;
-
+ /*! Tries to augment the flow between s and t by 1.
+ The return value shows if the augmentation is successful.
+ */
+ bool augment() {
+ dijkstra.run(s);
+ if (!dijkstra.reached(t)) {
+
+ //Unsuccessful augmentation.
+ return false;
+ } else {
- public :
-
- /// The constructor of the class.
-
- ///\param _G The directed graph the algorithm runs on.
- ///\param _length The length (weight or cost) of the edges.
- ///\param _cap The capacity of the edges.
- MinCostFlow(Graph& _G, LengthMap& _length, CapacityMap& _cap) : G(_G),
- length(_length), capacity(_cap), flow(_G), potential(_G){ }
-
-
- ///Runs the algorithm.
-
- ///Runs the algorithm.
- ///Returns k if there is a flow of value at least k edge-disjoint
- ///from s to t.
- ///Otherwise it returns the maximum value of a flow from s to t.
- ///
- ///\param s The source node.
- ///\param t The target node.
- ///\param k The value of the flow we are looking for.
- ///
- ///\todo May be it does make sense to be able to start with a nonzero
- /// feasible primal-dual solution pair as well.
- int run(Node s, Node t, int k) {
-
- //Resetting variables from previous runs
- total_length = 0;
-
- for (typename Graph::EdgeIt e(G); e!=INVALID; ++e) flow.set(e, 0);
-
- //Initialize the potential to zero
- for (typename Graph::NodeIt n(G); n!=INVALID; ++n) potential.set(n, 0);
-
-
- //We need a residual graph
- ResGW res_graph(G, capacity, flow);
-
-
- ModLengthMap mod_length(res_graph, length, potential);
-
- Dijkstra<ResGW, ModLengthMap> dijkstra(res_graph, mod_length);
-
- int i;
- for (i=0; i<k; ++i){
- dijkstra.run(s);
- if (!dijkstra.reached(t)){
- //There are no flow of value k from s to t
- break;
- };
-
//We have to change the potential
- for(typename ResGW::NodeIt n(res_graph); n!=INVALID; ++n)
+ for(typename ResGW::NodeIt n(res_graph); n!=INVALID; ++n)
potential[n] += dijkstra.distMap()[n];
-
-
+
//Augmenting on the sortest path
Node n=t;
ResGraphEdge e;
@@ -186,19 +163,51 @@
total_length -= length[e];
}
-
+ return true;
}
-
-
- return i;
+ }
+
+ /*! \brief Runs the algorithm.
+
+ Runs the algorithm.
+ Returns k if there is a flow of value at least k from s to t.
+ Otherwise it returns the maximum value of a flow from s to t.
+
+ \param k The value of the flow we are looking for.
+
+ \todo May be it does make sense to be able to start with a nonzero
+ feasible primal-dual solution pair as well.
+
+ \todo If the actual flow value is bigger than k, then everything is
+ cleared and the algorithm starts from zero flow. Is it a good approach?
+ */
+ int run(int k) {
+ if (flowValue()>k) reset();
+ while (flowValue()<k && augment()) { }
+ return flowValue();
}
+ /*! \brief The class is reset to zero flow and potential.
+ The class is reset to zero flow and potential.
+ */
+ void reset() {
+ total_length=0;
+ for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
+ for (typename Graph::NodeIt n(g); n!=INVALID; ++n) potential.set(n, 0);
+ }
+ /*! Returns the value of the actual flow.
+ */
+ int flowValue() const {
+ int i=0;
+ for (typename Graph::OutEdgeIt e(g, s); e!=INVALID; ++e) i+=flow[e];
+ for (typename Graph::InEdgeIt e(g, s); e!=INVALID; ++e) i-=flow[e];
+ return i;
+ }
- /// Gives back the total weight of the found flow.
+ /// Total weight of the found flow.
- ///This function gives back the total weight of the found flow.
- ///Assumes that \c run() has been run and nothing changed since then.
+ /// This function gives back the total weight of the found flow.
Length totalLength(){
return total_length;
}
@@ -206,29 +215,27 @@
///Returns a const reference to the EdgeMap \c flow.
///Returns a const reference to the EdgeMap \c flow.
- ///\pre \ref run() must
- ///be called before using this function.
const EdgeIntMap &getFlow() const { return flow;}
- ///Returns a const reference to the NodeMap \c potential (the dual solution).
+ /*! \brief Returns a const reference to the NodeMap \c potential (the dual solution).
- ///Returns a const reference to the NodeMap \c potential (the dual solution).
- /// \pre \ref run() must be called before using this function.
+ Returns a const reference to the NodeMap \c potential (the dual solution).
+ */
const PotentialMap &getPotential() const { return potential;}
- /// Checking the complementary slackness optimality criteria
+ /*! \brief Checking the complementary slackness optimality criteria.
- ///This function checks, whether the given solution is optimal
- ///If executed after the call of \c run() then it should return with true.
- ///This function only checks optimality, doesn't bother with feasibility.
- ///It is meant for testing purposes.
- ///
+ This function checks, whether the given flow and potential
+ satisfiy the complementary slackness cnditions (i.e. these are optimal).
+ This function only checks optimality, doesn't bother with feasibility.
+ For testing purpose.
+ */
bool checkComplementarySlackness(){
Length mod_pot;
Length fl_e;
- for(typename Graph::EdgeIt e(G); e!=INVALID; ++e) {
+ for(typename Graph::EdgeIt e(g); e!=INVALID; ++e) {
//C^{\Pi}_{i,j}
- mod_pot = length[e]-potential[G.head(e)]+potential[G.tail(e)];
+ mod_pot = length[e]-potential[g.head(e)]+potential[g.tail(e)];
fl_e = flow[e];
if (0<fl_e && fl_e<capacity[e]) {
/// \todo better comparison is needed for real types, moreover,
@@ -246,7 +253,6 @@
return true;
}
-
}; //class MinCostFlow
///@}
Modified: hugo/branches/graph_factory/src/lemon/suurballe.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/suurballe.h (original)
+++ hugo/branches/graph_factory/src/lemon/suurballe.h Wed Oct 27 15:39:16 2004
@@ -68,14 +68,16 @@
typedef ConstMap<Edge,int> ConstMap;
- //Input
const Graph& G;
+ Node s;
+ Node t;
+
//Auxiliary variables
//This is the capacity map for the mincostflow problem
ConstMap const1map;
//This MinCostFlow instance will actually solve the problem
- MinCostFlow<Graph, LengthMap, ConstMap> mincost_flow;
+ MinCostFlow<Graph, LengthMap, ConstMap> min_cost_flow;
//Container to store found paths
std::vector< std::vector<Edge> > paths;
@@ -83,39 +85,40 @@
public :
- /// The constructor of the class.
+ /*! \brief The constructor of the class.
- ///\param _G The directed graph the algorithm runs on.
- ///\param _length The length (weight or cost) of the edges.
- Suurballe(Graph& _G, LengthMap& _length) : G(_G),
- const1map(1), mincost_flow(_G, _length, const1map){}
+ \param _G The directed graph the algorithm runs on.
+ \param _length The length (weight or cost) of the edges.
+ \param _s Source node.
+ \param _t Target node.
+ */
+ Suurballe(Graph& _G, LengthMap& _length, Node _s, Node _t) :
+ G(_G), s(_s), t(_t), const1map(1),
+ min_cost_flow(_G, _length, const1map, _s, _t) { }
///Runs the algorithm.
///Runs the algorithm.
///Returns k if there are at least k edge-disjoint paths from s to t.
- ///Otherwise it returns the number of found edge-disjoint paths from s to t.
+ ///Otherwise it returns the number of edge-disjoint paths found
+ ///from s to t.
///
- ///\param s The source node.
- ///\param t The target node.
///\param k How many paths are we looking for?
///
- int run(Node s, Node t, int k) {
-
- int i = mincost_flow.run(s,t,k);
-
+ int run(int k) {
+ int i = min_cost_flow.run(k);
//Let's find the paths
//We put the paths into stl vectors (as an inner representation).
//In the meantime we lose the information stored in 'reversed'.
//We suppose the lengths to be positive now.
- //We don't want to change the flow of mincost_flow, so we make a copy
+ //We don't want to change the flow of min_cost_flow, so we make a copy
//The name here suggests that the flow has only 0/1 values.
EdgeIntMap reversed(G);
for(typename Graph::EdgeIt e(G); e!=INVALID; ++e)
- reversed[e] = mincost_flow.getFlow()[e];
+ reversed[e] = min_cost_flow.getFlow()[e];
paths.clear();
//total_length=0;
@@ -141,39 +144,32 @@
}
- ///Returns the total length of the paths
+ ///Returns the total length of the paths.
///This function gives back the total length of the found paths.
- ///\pre \ref run() must
- ///be called before using this function.
Length totalLength(){
- return mincost_flow.totalLength();
+ return min_cost_flow.totalLength();
}
///Returns the found flow.
///This function returns a const reference to the EdgeMap \c flow.
- ///\pre \ref run() must
- ///be called before using this function.
- const EdgeIntMap &getFlow() const { return mincost_flow.flow;}
+ const EdgeIntMap &getFlow() const { return min_cost_flow.flow;}
/// Returns the optimal dual solution
///This function returns a const reference to the NodeMap
///\c potential (the dual solution).
- /// \pre \ref run() must be called before using this function.
- const EdgeIntMap &getPotential() const { return mincost_flow.potential;}
+ const EdgeIntMap &getPotential() const { return min_cost_flow.potential;}
///Checks whether the complementary slackness holds.
///This function checks, whether the given solution is optimal.
- ///It should return true after calling \ref run()
///Currently this function only checks optimality,
///doesn't bother with feasibility
///It is meant for testing purposes.
- ///
bool checkComplementarySlackness(){
- return mincost_flow.checkComplementarySlackness();
+ return min_cost_flow.checkComplementarySlackness();
}
///Read the found paths.
Modified: hugo/branches/graph_factory/src/test/min_cost_flow_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/min_cost_flow_test.cc (original)
+++ hugo/branches/graph_factory/src/test/min_cost_flow_test.cc Wed Oct 27 15:39:16 2004
@@ -21,11 +21,9 @@
//#include <path.h>
//#include <maps.h>
-using namespace std;
using namespace lemon;
-
bool passed = true;
/*
void check(bool rc, char *msg="") {
@@ -41,11 +39,11 @@
int main()
{
+ typedef ListGraph Graph;
+ typedef Graph::Node Node;
+ typedef Graph::Edge Edge;
- typedef ListGraph::Node Node;
- typedef ListGraph::Edge Edge;
-
- ListGraph graph;
+ Graph graph;
//Ahuja könyv példája
@@ -67,7 +65,7 @@
Edge v5_t=graph.addEdge(v5, t);
- ListGraph::EdgeMap<int> length(graph);
+ Graph::EdgeMap<int> length(graph);
length.set(s_v1, 6);
length.set(v1_v2, 4);
@@ -78,7 +76,7 @@
length.set(v4_t, 8);
length.set(v5_t, 8);
- ListGraph::EdgeMap<int> capacity(graph);
+ Graph::EdgeMap<int> capacity(graph);
capacity.set(s_v1, 2);
capacity.set(v1_v2, 2);
@@ -92,31 +90,36 @@
// ConstMap<Edge, int> const1map(1);
std::cout << "Mincostflows algorithm test..." << std::endl;
- MinCostFlow< ListGraph, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> >
- surb_test(graph, length, capacity);
+ MinCostFlow< Graph, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
+ surb_test(graph, length, capacity, s, t);
int k=1;
- check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
+ surb_test.augment();
+ check( surb_test.flowValue() == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
+
+ check( surb_test.run(k) == 1 && surb_test.totalLength() == 19,"One path, total length should be 19");
check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
k=2;
- check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41");
+ check( surb_test.run(k) == 2 && surb_test.totalLength() == 41,"Two paths, total length should be 41");
check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
-
+ surb_test.augment();
+ surb_test.augment();
+ surb_test.augment();
k=4;
- check( surb_test.run(s,t,k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64");
+ check( surb_test.run(k) == 3 && surb_test.totalLength() == 64,"Three paths, total length should be 64");
check(surb_test.checkComplementarySlackness(), "Is the primal-dual solution pair really optimal?");
- cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
- << endl;
+ std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
+ << std::endl;
return passed ? 0 : 1;
Modified: hugo/branches/graph_factory/src/test/preflow_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/preflow_test.cc (original)
+++ hugo/branches/graph_factory/src/test/preflow_test.cc Wed Oct 27 15:39:16 2004
@@ -39,13 +39,13 @@
typedef Preflow<Graph, int, CapMap, FlowMap> PType;
- Graph G;
+ Graph g;
Node n;
CapMap cap;
FlowMap flow;
CutMap cut;
- PType preflow_test(G,n,n,cap,flow);
+ PType preflow_test(g,n,n,cap,flow);
preflow_test.run();
preflow_test.flowValue();
@@ -62,12 +62,12 @@
preflow_test.maxMinCut(cut);
}
-int cut_value ( SmartGraph& G, SmartGraph::NodeMap<bool>& cut,
+int cut_value ( SmartGraph& g, SmartGraph::NodeMap<bool>& cut,
SmartGraph::EdgeMap<int>& cap) {
int c=0;
- for(SmartGraph::EdgeIt e(G); e!=INVALID; ++e) {
- if (cut[G.tail(e)] && !cut[G.head(e)]) c+=cap[e];
+ for(SmartGraph::EdgeIt e(g); e!=INVALID; ++e) {
+ if (cut[g.tail(e)] && !cut[g.head(e)]) c+=cap[e];
}
return c;
}
@@ -97,29 +97,29 @@
check(file, "Input file '" << f_name << "' not found.");
- Graph G;
+ Graph g;
Node s, t;
- CapMap cap(G);
- readDimacs(file, G, cap, s, t);
+ CapMap cap(g);
+ readDimacs(file, g, cap, s, t);
- FlowMap flow(G,0);
+ FlowMap flow(g,0);
- PType preflow_test(G, s, t, cap, flow);
+ PType preflow_test(g, s, t, cap, flow);
preflow_test.run(PType::ZERO_FLOW);
- CutMap mincut(G,false);
- preflow_test.minCut(mincut);
- int min_cut_value=cut_value(G,mincut,cap);
-
- CutMap minmincut(G,false);
- preflow_test.minMinCut(minmincut);
- int min_min_cut_value=cut_value(G,minmincut,cap);
-
- CutMap maxmincut(G,false);
- preflow_test.maxMinCut(maxmincut);
- int max_min_cut_value=cut_value(G,maxmincut,cap);
+ CutMap min_cut(g,false);
+ preflow_test.minCut(min_cut);
+ int min_cut_value=cut_value(g,min_cut,cap);
+
+ CutMap min_min_cut(g,false);
+ preflow_test.minMinCut(min_min_cut);
+ int min_min_cut_value=cut_value(g,min_min_cut,cap);
+
+ CutMap max_min_cut(g,false);
+ preflow_test.maxMinCut(max_min_cut);
+ int max_min_cut_value=cut_value(g,max_min_cut,cap);
check(preflow_test.flowValue() == min_cut_value &&
min_cut_value == min_min_cut_value &&
@@ -130,14 +130,14 @@
- for(EdgeIt e(G); e!=INVALID; ++e) cap[e]=2*cap[e];
+ for(EdgeIt e(g); e!=INVALID; ++e) cap[e]=2*cap[e];
preflow_test.setCap(cap);
preflow_test.phase1(PType::PRE_FLOW);
- CutMap mincut1(G,false);
- preflow_test.minCut(mincut1);
- min_cut_value=cut_value(G,mincut1,cap);
+ CutMap min_cut1(g,false);
+ preflow_test.minCut(min_cut1);
+ min_cut_value=cut_value(g,min_cut1,cap);
check(preflow_test.flowValue() == min_cut_value &&
min_cut_value == 2*flow_value,
@@ -145,16 +145,16 @@
preflow_test.phase2();
- CutMap mincut2(G,false);
- preflow_test.minCut(mincut2);
- min_cut_value=cut_value(G,mincut2,cap);
-
- CutMap minmincut2(G,false);
- preflow_test.minMinCut(minmincut2);
- min_min_cut_value=cut_value(G,minmincut2,cap);
+ CutMap min_cut2(g,false);
+ preflow_test.minCut(min_cut2);
+ min_cut_value=cut_value(g,min_cut2,cap);
+
+ CutMap min_min_cut2(g,false);
+ preflow_test.minMinCut(min_min_cut2);
+ min_min_cut_value=cut_value(g,min_min_cut2,cap);
- preflow_test.maxMinCut(maxmincut);
- max_min_cut_value=cut_value(G,maxmincut,cap);
+ preflow_test.maxMinCut(max_min_cut);
+ max_min_cut_value=cut_value(g,max_min_cut,cap);
check(preflow_test.flowValue() == min_cut_value &&
min_cut_value == min_min_cut_value &&
@@ -164,7 +164,7 @@
- EdgeIt e(G);
+ EdgeIt e(g);
for( int i=1; i==10; ++i ) {
flow.set(e,0);
++e;
@@ -172,11 +172,11 @@
preflow_test.setFlow(flow);
- NodeIt tmp1(G,s);
+ NodeIt tmp1(g,s);
++tmp1;
if ( tmp1 != INVALID ) s=tmp1;
- NodeIt tmp2(G,t);
+ NodeIt tmp2(g,t);
++tmp2;
if ( tmp2 != INVALID ) t=tmp2;
@@ -185,16 +185,16 @@
preflow_test.run();
- CutMap mincut3(G,false);
- preflow_test.minCut(mincut3);
- min_cut_value=cut_value(G,mincut3,cap);
-
- CutMap minmincut3(G,false);
- preflow_test.minMinCut(minmincut3);
- min_min_cut_value=cut_value(G,minmincut3,cap);
+ CutMap min_cut3(g,false);
+ preflow_test.minCut(min_cut3);
+ min_cut_value=cut_value(g,min_cut3,cap);
+
+ CutMap min_min_cut3(g,false);
+ preflow_test.minMinCut(min_min_cut3);
+ min_min_cut_value=cut_value(g,min_min_cut3,cap);
- preflow_test.maxMinCut(maxmincut);
- max_min_cut_value=cut_value(G,maxmincut,cap);
+ preflow_test.maxMinCut(max_min_cut);
+ max_min_cut_value=cut_value(g,max_min_cut,cap);
check(preflow_test.flowValue() == min_cut_value &&
min_cut_value == min_min_cut_value &&
Modified: hugo/branches/graph_factory/src/test/suurballe_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/suurballe_test.cc (original)
+++ hugo/branches/graph_factory/src/test/suurballe_test.cc Wed Oct 27 15:39:16 2004
@@ -20,21 +20,19 @@
//#include <path.h>
#include "test_tools.h"
-using namespace std;
using namespace lemon;
-
bool passed = true;
int main()
{
+ typedef ListGraph Graph;
+ typedef Graph::Node Node;
+ typedef Graph::Edge Edge;
- typedef ListGraph::Node Node;
- typedef ListGraph::Edge Edge;
-
- ListGraph graph;
+ Graph graph;
//Ahuja könyv példája
@@ -56,7 +54,7 @@
Edge v5_t=graph.addEdge(v5, t);
- ListGraph::EdgeMap<int> length(graph);
+ Graph::EdgeMap<int> length(graph);
length.set(s_v1, 6);
length.set(v1_v2, 4);
@@ -71,29 +69,29 @@
int k=3;
- Suurballe< ListGraph, ListGraph::EdgeMap<int> >
- surb_test(graph, length);
+ Suurballe< Graph, Graph::EdgeMap<int> >
+ surb_test(graph, length, s, t);
- check( surb_test.run(s,t,k) == 2 && surb_test.totalLength() == 46,
+ check( surb_test.run(k) == 2 && surb_test.totalLength() == 46,
"Two paths, total length should be 46");
check( surb_test.checkComplementarySlackness(),
"Complementary slackness conditions are not met.");
- // typedef DirPath<ListGraph> DPath;
+ // typedef DirPath<Graph> DPath;
// DPath P(graph);
/*
surb_test.getPath(P,0);
check(P.length() == 4, "First path should contain 4 edges.");
- cout<<P.length()<<endl;
+ std::cout<<P.length()<<std::endl;
surb_test.getPath(P,1);
check(P.length() == 3, "Second path: 3 edges.");
- cout<<P.length()<<endl;
+ std::cout<<P.length()<<std::endl;
*/
k=1;
- check( surb_test.run(s,t,k) == 1 && surb_test.totalLength() == 19,
+ check( surb_test.run(k) == 1 && surb_test.totalLength() == 19,
"One path, total length should be 19");
check( surb_test.checkComplementarySlackness(),
@@ -102,8 +100,8 @@
// surb_test.getPath(P,0);
// check(P.length() == 4, "First path should contain 4 edges.");
- cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
- << endl;
+ std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
+ << std::endl;
return passed ? 0 : 1;
Modified: hugo/branches/graph_factory/src/work/Doxyfile
==============================================================================
--- hugo/branches/graph_factory/src/work/Doxyfile (original)
+++ hugo/branches/graph_factory/src/work/Doxyfile Wed Oct 27 15:39:16 2004
@@ -23,7 +23,7 @@
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 0.2
+PROJECT_NUMBER = 0.3
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
Modified: hugo/branches/graph_factory/src/work/akos/simann_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/work/akos/simann_test.cc (original)
+++ hugo/branches/graph_factory/src/work/akos/simann_test.cc Wed Oct 27 15:39:16 2004
@@ -1,39 +1,50 @@
-#include "SimAnn.h"
+#include "simann.h"
#include <cstdlib>
#include <cmath>
#include <iostream>
+using namespace lemon;
+
class MyController : public SimAnnBase::Controller {
public:
- long MaxIter, MaxNoImpr;
- double af;
+ long iter, last_impr, max_iter, max_no_impr;
+ double temp, annealing_factor;
MyController() {
- MaxIter = 500000;
- MaxNoImpr = 20000;
- af = 0.9999;
- T = 1000;
+ iter = last_impr = 0;
+ max_iter = 500000;
+ max_no_impr = 20000;
+ annealing_factor = 0.9999;
+ temp = 1000;
+ }
+ void acceptEvent() {
+ iter++;
+ }
+ void improveEvent() {
+ last_impr = iter;
+ }
+ void rejectEvent() {
+ iter++;
}
bool next() {
- T *= af;
- std::cout << T << std::endl;
- return !((sab->getIter() > MaxIter) || (sab->getIter() - sab->getLastImpr() > MaxNoImpr));
+ temp *= annealing_factor;
+ bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
+ return !quit;
}
- bool accept(double cost) {
- return (drand48() <= exp(cost / T));
+ bool accept(double cost_diff) {
+ return (drand48() <= exp(cost_diff / temp));
}
};
class MyEntity {
public:
- void init() {}
double mutate() { return 10.0; }
};
int main() {
- SimAnn<MyEntity> sa;
- MyController c;
- sa.setController(c);
+ SimAnn<MyEntity> simann;
+ MyController ctrl;
+ simann.setController(ctrl);
MyEntity ent;
- sa.setEnt(ent);
- sa.run();
+ simann.setEntity(ent);
+ simann.run();
}
Modified: hugo/branches/graph_factory/src/work/alpar/bfs-named-param.cc
==============================================================================
--- hugo/branches/graph_factory/src/work/alpar/bfs-named-param.cc (original)
+++ hugo/branches/graph_factory/src/work/alpar/bfs-named-param.cc Wed Oct 27 15:39:16 2004
@@ -54,7 +54,7 @@
int Qh=0;
int Qt=0;
- for(typename Graph::NodeIt n(_graph);_graph.valid(n);_graph.next(n))
+ for(typename Graph::NodeIt n(_graph);n!=INVALID;++n)
_visited->set(n,false);
Q[Qh++]=_source;
@@ -62,7 +62,7 @@
do {
Node m;
Node n=Q[Qt++];
- for(OutEdgeIt e(_graph,n);_graph.valid(e);_graph.next(e))
+ for(OutEdgeIt e(_graph,n);e!=INVALID;++e)
if(!(*_visited)[m=_graph.head(e)]) {
Q[Qh++]=m;
_visited->set(m,true);
Modified: hugo/branches/graph_factory/src/work/marci/augmenting_flow.h
==============================================================================
--- hugo/branches/graph_factory/src/work/marci/augmenting_flow.h (original)
+++ hugo/branches/graph_factory/src/work/marci/augmenting_flow.h Wed Oct 27 15:39:16 2004
@@ -6,16 +6,19 @@
#include <iostream>
#include <lemon/graph_wrapper.h>
-#include <bfs_dfs.h>
+//#include <bfs_dfs.h>
+#include <bfs_mm.h>
#include <lemon/invalid.h>
#include <lemon/maps.h>
-#include <lemon/tight_edge_filter_map.h>
+#include <demo/tight_edge_filter_map.h>
/// \file
/// \brief Maximum flow algorithms.
/// \ingroup galgs
namespace lemon {
+ using lemon::marci::BfsIterator;
+ using lemon::marci::DfsIterator;
/// \addtogroup galgs
/// @{
@@ -109,6 +112,8 @@
IntMap* map;
int* number_of_augmentations;
public:
+ typedef Node KeyType;
+ typedef bool ValueType;
TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) :
map(&_map), number_of_augmentations(&_number_of_augmentations) { }
void set(const Node& n, bool b) {
Modified: hugo/branches/graph_factory/src/work/marci/bfsit_vs_byhand.cc
==============================================================================
--- hugo/branches/graph_factory/src/work/marci/bfsit_vs_byhand.cc (original)
+++ hugo/branches/graph_factory/src/work/marci/bfsit_vs_byhand.cc Wed Oct 27 15:39:16 2004
@@ -2,12 +2,14 @@
#include <iostream>
#include <fstream>
-#include <sage_graph.h>
+//#include <sage_graph.h>
#include <lemon/smart_graph.h>
+#include <lemon/list_graph.h>
#include <lemon/dimacs.h>
#include <lemon/time_measure.h>
//#include <lemon/for_each_macros.h>
-#include <bfs_dfs.h>
+#include <bfs_mm.h>
+#include <lemon/bfs.h>
using namespace lemon;
@@ -15,7 +17,9 @@
using std::endl;
int main() {
- typedef SageGraph Graph;
+ // typedef SageGraph Graph;
+ typedef SmartGraph Graph ;
+ //typedef ListGraph Graph;
typedef Graph::Node Node;
typedef Graph::NodeIt NodeIt;
typedef Graph::Edge Edge;
@@ -23,12 +27,8 @@
typedef Graph::OutEdgeIt OutEdgeIt;
Graph g;
- //Node s;
- //Graph::EdgeMap<int> cap(g);
- //readDimacsMaxFlow(std::cin, g, s, t, cap);
readDimacs(std::cin, g);
- NodeIt s;
- g.first(s);
+ NodeIt s(g);
cout << g.nodeNum() << endl;
cout << g.edgeNum() << endl;
@@ -36,8 +36,9 @@
Graph::NodeMap<Edge> pred(g);
cout << "iteration time of bfs written by hand..." << endl;
Timer ts;
+ ts.reset();
+ for (int i=0; i<100; ++i)
{
- ts.reset();
Graph::NodeMap<bool> reached(g);
reached.set(s, true);
pred.set(s, INVALID);
@@ -46,8 +47,7 @@
while (!bfs_queue.empty()) {
Node v=bfs_queue.front();
bfs_queue.pop();
- OutEdgeIt e;
- for(g.first(e,v); g.valid(e); g.next(e)) {
+ for(OutEdgeIt e(g,v); e!=INVALID; ++e) {
Node w=g.head(e);
if (!reached[w]) {
bfs_queue.push(w);
@@ -56,23 +56,35 @@
}
}
}
-
- std::cout << ts << std::endl;
}
+ std::cout << ts << std::endl;
cout << "iteration time with bfs iterator..." << endl;
+ ts.reset();
+ for (int i=0; i<100; ++i)
{
- ts.reset();
- BfsIterator< Graph, Graph::NodeMap<bool> > bfs(g);
+ Graph::NodeMap<bool> reached(g);
+ marci::BfsIterator< Graph, Graph::NodeMap<bool> > bfs(g, reached);
bfs.pushAndSetReached(s);
pred.set(s, INVALID);
while (!bfs.finished()) {
++bfs;
- if (g.valid(bfs) && bfs.isBNodeNewlyReached())
+ if (Graph::Edge(bfs)!=INVALID && bfs.isBNodeNewlyReached())
pred.set(bfs.head(), Graph::Edge(bfs));
}
- std::cout << ts << std::endl;
}
+ std::cout << ts << std::endl;
+
+ cout << "iteration time with bfs aplar..." << endl;
+ ts.reset();
+ for (int i=0; i<100; ++i)
+ {
+ Bfs<Graph> bfs(g);
+ bfs.setPredMap(pred);
+ bfs.run(s);
+ }
+ std::cout << ts << std::endl;
+
return 0;
}
Modified: hugo/branches/graph_factory/src/work/marci/makefile
==============================================================================
--- hugo/branches/graph_factory/src/work/marci/makefile (original)
+++ hugo/branches/graph_factory/src/work/marci/makefile Wed Oct 27 15:39:16 2004
@@ -4,7 +4,7 @@
INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT)
LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
-BINARIES = merge_node_graph_wrapper_test#sub_graph_wrapper_demo.cc graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10
+BINARIES = bfsit_vs_byhand max_flow_demo bfs_mm_test#merge_node_graph_wrapper_test sub_graph_wrapper_demo.cc graph_wrapper_time iterator_bfs_demo macro_test lg_vs_sg_vs_sg bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10
#BINARIES = preflow_bug
#gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
More information about the Lemon-commits
mailing list