# HG changeset patch # User Alpar Juttner # Date 1215975062 -3600 # Node ID 765619b7cbb28b545c57b8000f02a525482a02bc # Parent 4317d277ba21d108a1e925fccf496ec8565a840a Apply unify-sources.sh to the source tree diff -r 4317d277ba21 -r 765619b7cbb2 demo/arg_parser_demo.cc --- a/demo/arg_parser_demo.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/demo/arg_parser_demo.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -64,7 +64,7 @@ // Add non-parsed arguments (e.g. input files) ap.other("infile", "The input file.") .other("..."); - + // Perform the parsing process // (in case of any error it terminates the program) ap.parse(); @@ -84,7 +84,7 @@ if(ap.given("gra")) std::cout << " -gra is given\n"; if(ap.given("grb")) std::cout << " -grb is given\n"; if(ap.given("grc")) std::cout << " -grc is given\n"; - + switch(ap.files().size()) { case 0: std::cout << " No file argument was given.\n"; @@ -94,10 +94,10 @@ break; default: std::cout << " " - << ap.files().size() << " file arguments were given. They are:\n"; + << ap.files().size() << " file arguments were given. They are:\n"; } for(unsigned int i=0;i Point; - + Node n1=g.addNode(); Node n2=g.addNode(); Node n3=g.addNode(); @@ -62,13 +62,13 @@ ListDigraph::NodeMap shapes(g); ListDigraph::ArcMap acolors(g); ListDigraph::ArcMap widths(g); - + coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2; coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2; - + Arc a; a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1; @@ -78,7 +78,7 @@ a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1; a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2; a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1; - + IdMap id(g); // Create five .eps files showing the digraph with different options @@ -182,14 +182,14 @@ ListDigraph h; ListDigraph::NodeMap hcolors(h); ListDigraph::NodeMap hcoords(h); - + int cols=int(sqrt(double(palette.size()))); for(int i=0;i cap(g); SmartDigraph::Node s, t; - + try { digraphReader("digraph.lgf", g). // read the directed graph into g arcMap("capacity", cap). // read the 'capacity' arc map into cap diff -r 4317d277ba21 -r 765619b7cbb2 doc/coding_style.dox --- a/doc/coding_style.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/coding_style.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -18,7 +18,7 @@ /*! -\page coding_style LEMON Coding Style +\page coding_style LEMON Coding Style \section naming_conv Naming Conventions @@ -68,7 +68,7 @@ The name of a class or any type should look like the following. \code -AllWordsCapitalizedWithoutUnderscores +AllWordsCapitalizedWithoutUnderscores \endcode \subsection cs-func Methods and other functions @@ -76,7 +76,7 @@ The name of a function should look like the following. \code -firstWordLowerCaseRestCapitalizedWithoutUnderscores +firstWordLowerCaseRestCapitalizedWithoutUnderscores \endcode \subsection cs-funcs Constants, Macros @@ -84,15 +84,15 @@ The names of constants and macros should look like the following. \code -ALL_UPPER_CASE_WITH_UNDERSCORES +ALL_UPPER_CASE_WITH_UNDERSCORES \endcode -\subsection cs-loc-var Class and instance member variables, auto variables +\subsection cs-loc-var Class and instance member variables, auto variables The names of class and instance member variables and auto variables (=variables used locally in methods) should look like the following. \code -all_lower_case_with_underscores +all_lower_case_with_underscores \endcode \subsection pri-loc-var Private member variables diff -r 4317d277ba21 -r 765619b7cbb2 doc/dirs.dox --- a/doc/dirs.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/dirs.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -74,6 +74,6 @@ \brief Implementation helper files This directory contains some helper classes to implement graphs, maps and -some other classes. As a user you typically don't have to deal with these +some other classes. As a user you typically don't have to deal with these files. */ diff -r 4317d277ba21 -r 765619b7cbb2 doc/groups.dox --- a/doc/groups.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/groups.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -26,10 +26,10 @@ @ingroup datas \brief Graph structures implemented in LEMON. -The implementation of combinatorial algorithms heavily relies on -efficient graph implementations. LEMON offers data structures which are -planned to be easily used in an experimental phase of implementation studies, -and thereafter the program code can be made efficient by small modifications. +The implementation of combinatorial algorithms heavily relies on +efficient graph implementations. LEMON offers data structures which are +planned to be easily used in an experimental phase of implementation studies, +and thereafter the program code can be made efficient by small modifications. The most efficient implementation of diverse applications require the usage of different physical graph implementations. These differences @@ -40,21 +40,21 @@ running time or on memory usage, some structures may fail to provide some graph features like arc/edge or node deletion. -Alteration of standard containers need a very limited number of -operations, these together satisfy the everyday requirements. -In the case of graph structures, different operations are needed which do -not alter the physical graph, but gives another view. If some nodes or +Alteration of standard containers need a very limited number of +operations, these together satisfy the everyday requirements. +In the case of graph structures, different operations are needed which do +not alter the physical graph, but gives another view. If some nodes or arcs have to be hidden or the reverse oriented graph have to be used, then -this is the case. It also may happen that in a flow implementation -the residual graph can be accessed by another algorithm, or a node-set -is to be shrunk for another algorithm. -LEMON also provides a variety of graphs for these requirements called -\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only -in conjunction with other graph representations. +this is the case. It also may happen that in a flow implementation +the residual graph can be accessed by another algorithm, or a node-set +is to be shrunk for another algorithm. +LEMON also provides a variety of graphs for these requirements called +\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only +in conjunction with other graph representations. You are free to use the graph structure that fit your requirements the best, most graph algorithms and auxiliary data structures can be used -with any graph structures. +with any graph structures. */ /** @@ -63,12 +63,12 @@ \brief Graph types between real graphs and graph adaptors. This group describes some graph types between real graphs and graph adaptors. -These classes wrap graphs to give new functionality as the adaptors do it. +These classes wrap graphs to give new functionality as the adaptors do it. On the other hand they are not light-weight structures as the adaptors. */ /** -@defgroup maps Maps +@defgroup maps Maps @ingroup datas \brief Map structures implemented in LEMON. @@ -79,7 +79,7 @@ */ /** -@defgroup graph_maps Graph Maps +@defgroup graph_maps Graph Maps @ingroup maps \brief Special graph-related maps. @@ -115,14 +115,14 @@ return Color(0.0, 0.0, 0.0); } } - + Digraph::NodeMap degree_map(graph); - + digraphToEps(graph, "graph.eps") .coords(coords).scaleToA4().undirected() .nodeColors(composeMap(functorToMap(nodeColor), degree_map)) .run(); -\endcode +\endcode The \c functorToMap() function makes an \c int to \c Color map from the \e nodeColor() function. The \c composeMap() compose the \e degree_map and the previously created map. The composed map is a proper function to @@ -140,7 +140,7 @@ typedef DivMap TimeMap; TimeMap time(length, speed); - + Dijkstra dijkstra(graph, time); dijkstra.run(source, target); \endcode @@ -152,7 +152,7 @@ */ /** -@defgroup matrices Matrices +@defgroup matrices Matrices @ingroup datas \brief Two dimensional data storages implemented in LEMON. @@ -200,7 +200,7 @@ @ingroup algs \brief Common graph search algorithms. -This group describes the common graph search algorithms like +This group describes the common graph search algorithms like Breadth-first search (Bfs) and Depth-first search (Dfs). */ @@ -212,9 +212,9 @@ This group describes the algorithms for finding shortest paths in graphs. */ -/** -@defgroup max_flow Maximum Flow algorithms -@ingroup algs +/** +@defgroup max_flow Maximum Flow algorithms +@ingroup algs \brief Algorithms for finding maximum flows. This group describes the algorithms for finding maximum flows and @@ -231,7 +231,7 @@ \f[ \max \sum_{v\in\delta^{+}(s)}f_{uv} - \sum_{v\in\delta^{-}(s)}f_{vu}\f] LEMON contains several algorithms for solving maximum flow problems: -- \ref lemon::EdmondsKarp "Edmonds-Karp" +- \ref lemon::EdmondsKarp "Edmonds-Karp" - \ref lemon::Preflow "Goldberg's Preflow algorithm" - \ref lemon::DinitzSleatorTarjan "Dinitz's blocking flow algorithm with dynamic trees" - \ref lemon::GoldbergTarjan "Preflow algorithm with dynamic trees" @@ -250,12 +250,12 @@ \brief Algorithms for finding minimum cost flows and circulations. This group describes the algorithms for finding minimum cost flows and -circulations. +circulations. */ /** -@defgroup min_cut Minimum Cut algorithms -@ingroup algs +@defgroup min_cut Minimum Cut algorithms +@ingroup algs \brief Algorithms for finding minimum cut in graphs. @@ -272,7 +272,7 @@ LEMON contains several algorithms related to minimum cut problems: - \ref lemon::HaoOrlin "Hao-Orlin algorithm" to calculate minimum cut - in directed graphs + in directed graphs - \ref lemon::NagamochiIbaraki "Nagamochi-Ibaraki algorithm" to calculate minimum cut in undirected graphs - \ref lemon::GomoryHuTree "Gomory-Hu tree computation" to calculate all @@ -307,14 +307,14 @@ */ /** -@defgroup matching Matching algorithms +@defgroup matching Matching algorithms @ingroup algs \brief Algorithms for finding matchings in graphs and bipartite graphs. This group contains algorithm objects and functions to calculate matchings in graphs and bipartite graphs. The general matching problem is finding a subset of the arcs which does not shares common endpoints. - + There are several different algorithms for calculate matchings in graphs. The matching problems in bipartite graphs are generally easier than in general graphs. The goal of the matching optimization @@ -323,16 +323,16 @@ maximum cardinality matching. Lemon contains the next algorithms: -- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp - augmenting path algorithm for calculate maximum cardinality matching in +- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp + augmenting path algorithm for calculate maximum cardinality matching in bipartite graphs -- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel - algorithm for calculate maximum cardinality matching in bipartite graphs -- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" - Successive shortest path algorithm for calculate maximum weighted matching +- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel + algorithm for calculate maximum cardinality matching in bipartite graphs +- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" + Successive shortest path algorithm for calculate maximum weighted matching and maximum weighted bipartite matching in bipartite graph -- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" - Successive shortest path algorithm for calculate minimum cost maximum +- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" + Successive shortest path algorithm for calculate minimum cost maximum matching in bipartite graph - \ref lemon::MaxMatching "MaxMatching" Edmond's blossom shrinking algorithm for calculate maximum cardinality matching in general graph @@ -396,8 +396,8 @@ */ -/** -@defgroup lp_utils Tools for Lp and Mip solvers +/** +@defgroup lp_utils Tools for Lp and Mip solvers @ingroup lp_group \brief Helper tools to the Lp and Mip solvers. @@ -414,7 +414,7 @@ */ /** -@defgroup utils Tools and Utilities +@defgroup utils Tools and Utilities \brief Tools and utilities for programming in LEMON Tools and utilities for programming in LEMON. @@ -467,7 +467,7 @@ @defgroup io_group Input-Output \brief Graph Input-Output methods -This group describes the tools for importing and exporting graphs +This group describes the tools for importing and exporting graphs and graph related data. Now it supports the LEMON format, the \c DIMACS format and the encapsulated postscript (EPS) format. */ @@ -486,7 +486,7 @@ \brief General \c EPS drawer and graph exporter This group describes general \c EPS drawing methods and special -graph exporting tools. +graph exporting tools. */ @@ -498,7 +498,7 @@ classes implemented in LEMON. The purpose of the classes in this group is fourfold. - + - These classes contain the documentations of the concepts. In order to avoid document multiplications, an implementation of a concept simply refers to the corresponding concept class. @@ -551,9 +551,9 @@ /** @defgroup tools Standalone utility applications -Some utility applications are listed here. +Some utility applications are listed here. The standard compilation procedure (./configure;make) will compile -them, as well. +them, as well. */ diff -r 4317d277ba21 -r 765619b7cbb2 doc/lgf.dox --- a/doc/lgf.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/lgf.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -43,7 +43,7 @@ \e quoted. A plain token is just a sequence of non-whitespace characters, while a quoted token is a character sequence surrounded by double quotes, and it can also -contain whitespaces and escape sequences. +contain whitespaces and escape sequences. The \c \@nodes section describes a set of nodes and associated maps. The first is a header line, its columns are the names of the @@ -72,7 +72,7 @@ \code @arcs - capacity + capacity 1 2 16 1 3 12 2 3 18 diff -r 4317d277ba21 -r 765619b7cbb2 doc/license.dox --- a/doc/license.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/license.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 doc/mainpage.dox --- a/doc/mainpage.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/mainpage.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -41,15 +41,15 @@ \subsection howtoread How to read the documentation -If you want to get a quick start and see the most important features then +If you want to get a quick start and see the most important features then take a look at our \ref quicktour "Quick Tour to LEMON" which will guide you along. -If you already feel like using our library, see the page that tells you +If you already feel like using our library, see the page that tells you \ref getstart "How to start using LEMON". -If you -want to see how LEMON works, see +If you +want to see how LEMON works, see some \ref demoprograms "demo programs"! If you know what you are looking for then try to find it under the diff -r 4317d277ba21 -r 765619b7cbb2 doc/namespaces.dox --- a/doc/namespaces.dox Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/namespaces.dox Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 doc/template.h --- a/doc/template.h Sun Jul 13 16:46:56 2008 +0100 +++ b/doc/template.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 lemon/arg_parser.cc --- a/lemon/arg_parser.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/arg_parser.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -38,30 +38,30 @@ { for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) if(i->second.self_delete) - switch(i->second.type) { - case BOOL: - delete i->second.bool_p; - break; - case STRING: - delete i->second.string_p; - break; - case DOUBLE: - delete i->second.double_p; - break; - case INTEGER: - delete i->second.int_p; - break; - case UNKNOWN: - break; - case FUNC: - break; - } + switch(i->second.type) { + case BOOL: + delete i->second.bool_p; + break; + case STRING: + delete i->second.string_p; + break; + case DOUBLE: + delete i->second.double_p; + break; + case INTEGER: + delete i->second.int_p; + break; + case UNKNOWN: + break; + case FUNC: + break; + } } - + ArgParser &ArgParser::intOption(const std::string &name, - const std::string &help, - int value, bool obl) + const std::string &help, + int value, bool obl) { ParData p; p.int_p=new int(value); @@ -74,8 +74,8 @@ } ArgParser &ArgParser::doubleOption(const std::string &name, - const std::string &help, - double value, bool obl) + const std::string &help, + double value, bool obl) { ParData p; p.double_p=new double(value); @@ -88,8 +88,8 @@ } ArgParser &ArgParser::boolOption(const std::string &name, - const std::string &help, - bool value, bool obl) + const std::string &help, + bool value, bool obl) { ParData p; p.bool_p=new bool(value); @@ -102,8 +102,8 @@ } ArgParser &ArgParser::stringOption(const std::string &name, - const std::string &help, - std::string value, bool obl) + const std::string &help, + std::string value, bool obl) { ParData p; p.string_p=new std::string(value); @@ -116,8 +116,8 @@ } ArgParser &ArgParser::refOption(const std::string &name, - const std::string &help, - int &ref, bool obl) + const std::string &help, + int &ref, bool obl) { ParData p; p.int_p=&ref; @@ -161,8 +161,8 @@ } ArgParser &ArgParser::refOption(const std::string &name, - const std::string &help, - std::string &ref, bool obl) + const std::string &help, + std::string &ref, bool obl) { ParData p; p.string_p=&ref; @@ -175,8 +175,8 @@ } ArgParser &ArgParser::funcOption(const std::string &name, - const std::string &help, - void (*func)(void *),void *data) + const std::string &help, + void (*func)(void *),void *data) { ParData p; p.func_p.p=func; @@ -190,11 +190,11 @@ } ArgParser &ArgParser::optionGroup(const std::string &group, - const std::string &opt) + const std::string &opt) { Opts::iterator i = _opts.find(opt); LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'"); - LEMON_ASSERT(!(i->second.ingroup), + LEMON_ASSERT(!(i->second.ingroup), "Option already in option group: '"+opt+"'"); GroupData &g=_groups[group]; g.opts.push_back(opt); @@ -210,7 +210,7 @@ } ArgParser &ArgParser::synonym(const std::string &syn, - const std::string &opt) + const std::string &opt) { Opts::iterator o = _opts.find(opt); Opts::iterator s = _opts.find(syn); @@ -233,7 +233,7 @@ } ArgParser &ArgParser::other(const std::string &name, - const std::string &help) + const std::string &help) { _others_help.push_back(OtherArg(name,help)); return *this; @@ -244,8 +244,8 @@ os << "-" << i->first; if(i->second.has_syn) for(Opts::iterator j=_opts.begin();j!=_opts.end();++j) - if(j->second.syn&&j->second.help==i->first) - os << "|-" << j->first; + if(j->second.syn&&j->second.help==i->first) + os << "|-" << j->first; switch(i->second.type) { case STRING: os << " str"; @@ -270,7 +270,7 @@ if(o!=i->second.opts.end()) os<<'|'; } } - + void ArgParser::showHelp(Opts::iterator i) { if(i->second.help.size()==0||i->second.syn) return; @@ -283,9 +283,9 @@ { if(i->help.size()==0) return; std::cerr << " " << i->name << std::endl - << " " << i->help << std::endl; + << " " << i->help << std::endl; } - + void ArgParser::shortHelp() { const unsigned int LINE_LEN=77; @@ -299,62 +299,62 @@ show(cstr,g); if(!g->second.mandatory) cstr << ']'; if(pos+cstr.str().size()>LINE_LEN) { - std::cerr << std::endl << indent; - pos=indent.size(); + std::cerr << std::endl << indent; + pos=indent.size(); } std::cerr << cstr.str(); pos+=cstr.str().size(); } for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) if(!i->second.ingroup&&!i->second.syn) { - std::ostringstream cstr; - cstr << ' '; - if(!i->second.mandatory) cstr << '['; - show(cstr,i); - if(!i->second.mandatory) cstr << ']'; - if(pos+cstr.str().size()>LINE_LEN) { - std::cerr << std::endl << indent; - pos=indent.size(); - } - std::cerr << cstr.str(); - pos+=cstr.str().size(); + std::ostringstream cstr; + cstr << ' '; + if(!i->second.mandatory) cstr << '['; + show(cstr,i); + if(!i->second.mandatory) cstr << ']'; + if(pos+cstr.str().size()>LINE_LEN) { + std::cerr << std::endl << indent; + pos=indent.size(); + } + std::cerr << cstr.str(); + pos+=cstr.str().size(); } for(std::vector::iterator i=_others_help.begin(); - i!=_others_help.end();++i) + i!=_others_help.end();++i) { - std::ostringstream cstr; - cstr << ' ' << i->name; - - if(pos+cstr.str().size()>LINE_LEN) { - std::cerr << std::endl << indent; - pos=indent.size(); - } - std::cerr << cstr.str(); - pos+=cstr.str().size(); + std::ostringstream cstr; + cstr << ' ' << i->name; + + if(pos+cstr.str().size()>LINE_LEN) { + std::cerr << std::endl << indent; + pos=indent.size(); + } + std::cerr << cstr.str(); + pos+=cstr.str().size(); } std::cerr << std::endl; } - + void ArgParser::showHelp() { shortHelp(); std::cerr << "Where:\n"; for(std::vector::iterator i=_others_help.begin(); - i!=_others_help.end();++i) showHelp(i); + i!=_others_help.end();++i) showHelp(i); for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i); exit(1); } - - - void ArgParser::unknownOpt(std::string arg) + + + void ArgParser::unknownOpt(std::string arg) { std::cerr << "\nUnknown option: " << arg << "\n"; std::cerr << "\nType '" << _command_name << " --help' to obtain a short summary on the usage.\n\n"; exit(1); } - - void ArgParser::requiresValue(std::string arg, OptType t) + + void ArgParser::requiresValue(std::string arg, OptType t) { std::cerr << "Argument '" << arg << "' requires a"; switch(t) { @@ -373,47 +373,47 @@ std::cerr << " value\n\n"; showHelp(); } - + void ArgParser::checkMandatories() { bool ok=true; for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) - if(i->second.mandatory&&!i->second.set) - { - if(ok) - std::cerr << _command_name - << ": The following mandatory arguments are missing.\n"; - ok=false; - showHelp(i); - } + if(i->second.mandatory&&!i->second.set) + { + if(ok) + std::cerr << _command_name + << ": The following mandatory arguments are missing.\n"; + ok=false; + showHelp(i); + } for(Groups::iterator i=_groups.begin();i!=_groups.end();++i) if(i->second.mandatory||i->second.only_one) - { - int set=0; - for(GroupData::Opts::iterator o=i->second.opts.begin(); - o!=i->second.opts.end();++o) - if(_opts.find(*o)->second.set) ++set; - if(i->second.mandatory&&!set) { - std::cerr << _command_name - << ": At least one of the following arguments is mandatory.\n"; - ok=false; - for(GroupData::Opts::iterator o=i->second.opts.begin(); - o!=i->second.opts.end();++o) - showHelp(_opts.find(*o)); - } - if(i->second.only_one&&set>1) { - std::cerr << _command_name - << ": At most one of the following arguments can be given.\n"; - ok=false; - for(GroupData::Opts::iterator o=i->second.opts.begin(); - o!=i->second.opts.end();++o) - showHelp(_opts.find(*o)); - } - } + { + int set=0; + for(GroupData::Opts::iterator o=i->second.opts.begin(); + o!=i->second.opts.end();++o) + if(_opts.find(*o)->second.set) ++set; + if(i->second.mandatory&&!set) { + std::cerr << _command_name + << ": At least one of the following arguments is mandatory.\n"; + ok=false; + for(GroupData::Opts::iterator o=i->second.opts.begin(); + o!=i->second.opts.end();++o) + showHelp(_opts.find(*o)); + } + if(i->second.only_one&&set>1) { + std::cerr << _command_name + << ": At most one of the following arguments can be given.\n"; + ok=false; + for(GroupData::Opts::iterator o=i->second.opts.begin(); + o!=i->second.opts.end();++o) + showHelp(_opts.find(*o)); + } + } if(!ok) { std::cerr << "\nType '" << _command_name << - " --help' to obtain a short summary on the usage.\n\n"; + " --help' to obtain a short summary on the usage.\n\n"; exit(1); } } @@ -423,43 +423,43 @@ for(int ar=1; ar<_argc; ++ar) { std::string arg(_argv[ar]); if (arg[0] != '-' || arg.size() == 1) { - _file_args.push_back(arg); + _file_args.push_back(arg); } else { - Opts::iterator i = _opts.find(arg.substr(1)); - if(i==_opts.end()) unknownOpt(arg); - else { - if(i->second.syn) i=_opts.find(i->second.help); - ParData &p(i->second); - if (p.type==BOOL) *p.bool_p=true; - else if (p.type==FUNC) p.func_p.p(p.func_p.data); - else if(++ar==_argc) requiresValue(arg, p.type); - else { - std::string val(_argv[ar]); - std::istringstream vals(val); - switch(p.type) { - case STRING: - *p.string_p=val; - break; - case INTEGER: - vals >> *p.int_p; - break; - case DOUBLE: - vals >> *p.double_p; - break; - default: - break; - } - if(p.type!=STRING&&(!vals||!vals.eof())) - requiresValue(arg, p.type); - } - p.set = true; - } + Opts::iterator i = _opts.find(arg.substr(1)); + if(i==_opts.end()) unknownOpt(arg); + else { + if(i->second.syn) i=_opts.find(i->second.help); + ParData &p(i->second); + if (p.type==BOOL) *p.bool_p=true; + else if (p.type==FUNC) p.func_p.p(p.func_p.data); + else if(++ar==_argc) requiresValue(arg, p.type); + else { + std::string val(_argv[ar]); + std::istringstream vals(val); + switch(p.type) { + case STRING: + *p.string_p=val; + break; + case INTEGER: + vals >> *p.int_p; + break; + case DOUBLE: + vals >> *p.double_p; + break; + default: + break; + } + if(p.type!=STRING&&(!vals||!vals.eof())) + requiresValue(arg, p.type); + } + p.set = true; + } } } checkMandatories(); return *this; - } + } } diff -r 4317d277ba21 -r 765619b7cbb2 lemon/arg_parser.h --- a/lemon/arg_parser.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/arg_parser.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -41,27 +41,27 @@ /// ///For a complete example see the \ref arg_parser_demo.cc demo file. class ArgParser { - + static void _showHelp(void *p); protected: - + int _argc; const char **_argv; - + enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 }; - + class ParData { public: union { - bool *bool_p; - int *int_p; - double *double_p; - std::string *string_p; - struct { - void (*p)(void *); - void *data; - } func_p; - + bool *bool_p; + int *int_p; + double *double_p; + std::string *string_p; + struct { + void (*p)(void *); + void *data; + } func_p; + }; std::string help; bool mandatory; @@ -72,13 +72,13 @@ bool syn; bool self_delete; ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false), - has_syn(false), syn(false), self_delete(false) {} + has_syn(false), syn(false), self_delete(false) {} }; typedef std::map Opts; Opts _opts; - class GroupData + class GroupData { public: typedef std::list Opts; @@ -87,7 +87,7 @@ bool mandatory; GroupData() :only_one(false), mandatory(false) {} }; - + typedef std::map Groups; Groups _groups; @@ -98,12 +98,12 @@ OtherArg(std::string n, std::string h) :name(n), help(h) {} }; - + std::vector _others_help; std::vector _file_args; std::string _command_name; - + private: //Bind a function to an option. @@ -113,9 +113,9 @@ // must be of type "void f(void *)" //\param data Data to be passed to \c func ArgParser &funcOption(const std::string &name, - const std::string &help, - void (*func)(void *),void *data); - + const std::string &help, + void (*func)(void *),void *data); + public: ///Constructor @@ -136,8 +136,8 @@ ///\param value A default value for the option. ///\param obl Indicate if the option is mandatory. ArgParser &intOption(const std::string &name, - const std::string &help, - int value=0, bool obl=false); + const std::string &help, + int value=0, bool obl=false); ///Add a new floating point type option @@ -147,8 +147,8 @@ ///\param value A default value for the option. ///\param obl Indicate if the option is mandatory. ArgParser &doubleOption(const std::string &name, - const std::string &help, - double value=0, bool obl=false); + const std::string &help, + double value=0, bool obl=false); ///Add a new bool type option @@ -159,8 +159,8 @@ ///\param obl Indicate if the option is mandatory. ///\note A mandatory bool obtion is of very little use. ArgParser &boolOption(const std::string &name, - const std::string &help, - bool value=false, bool obl=false); + const std::string &help, + bool value=false, bool obl=false); ///Add a new string type option @@ -170,8 +170,8 @@ ///\param value A default value for the option. ///\param obl Indicate if the option is mandatory. ArgParser &stringOption(const std::string &name, - const std::string &help, - std::string value="", bool obl=false); + const std::string &help, + std::string value="", bool obl=false); ///Give help string for non-parsed arguments. @@ -179,8 +179,8 @@ ///The parameter \c name will be printed in the short usage line, while ///\c help gives a more detailed description. ArgParser &other(const std::string &name, - const std::string &help=""); - + const std::string &help=""); + ///@} ///\name Options with External Storage @@ -197,8 +197,8 @@ ///\param obl Indicate if the option is mandatory. ///\retval ref The value of the argument will be written to this variable. ArgParser &refOption(const std::string &name, - const std::string &help, - int &ref, bool obl=false); + const std::string &help, + int &ref, bool obl=false); ///Add a new floating type option with a storage reference @@ -208,8 +208,8 @@ ///\param obl Indicate if the option is mandatory. ///\retval ref The value of the argument will be written to this variable. ArgParser &refOption(const std::string &name, - const std::string &help, - double &ref, bool obl=false); + const std::string &help, + double &ref, bool obl=false); ///Add a new bool type option with a storage reference @@ -220,8 +220,8 @@ ///\retval ref The value of the argument will be written to this variable. ///\note A mandatory bool obtion is of very little use. ArgParser &refOption(const std::string &name, - const std::string &help, - bool &ref, bool obl=false); + const std::string &help, + bool &ref, bool obl=false); ///Add a new string type option with a storage reference @@ -231,14 +231,14 @@ ///\param obl Indicate if the option is mandatory. ///\retval ref The value of the argument will be written to this variable. ArgParser &refOption(const std::string &name, - const std::string &help, - std::string &ref, bool obl=false); - + const std::string &help, + std::string &ref, bool obl=false); + ///@} ///\name Option Groups and Synonyms /// - + ///@{ ///Bundle some options into a group @@ -248,27 +248,27 @@ ///\param group The group name. ///\param opt The option name. ArgParser &optionGroup(const std::string &group, - const std::string &opt); + const std::string &opt); ///Make the members of a group exclusive ///If you call this function for a group, than at most one of them can be ///given at the same time. ArgParser &onlyOneGroup(const std::string &group); - + ///Make a group mandatory ///Using this function, at least one of the members of \c group ///must be given. ArgParser &mandatoryGroup(const std::string &group); - + ///Create synonym to an option ///With this function you can create a synonym \c syn of the ///option \c opt. ArgParser &synonym(const std::string &syn, - const std::string &opt); - + const std::string &opt); + ///@} void show(std::ostream &os,Opts::iterator i); @@ -282,21 +282,21 @@ void requiresValue(std::string arg, OptType t); void checkMandatories(); - + ///Start the parsing process ArgParser &parse(); /// Synonym for parse() - ArgParser &run() + ArgParser &run() { return parse(); } - + ///Give back the command name (the 0th argument) const std::string &commandName() { return _command_name; } ///Check if an opion has been given to the command. - bool given(std::string op) + bool given(std::string op) { Opts::iterator i = _opts.find(op); return i!=_opts.end()?i->second.set:false; @@ -304,12 +304,12 @@ ///Magic type for operator[] - + ///This is the type of the return value of ArgParser::operator[](). ///It automatically converts to \c int, \c double, \c bool or ///\c std::string if the type of the option matches, otherwise it ///throws an exception (i.e. it performs runtime type checking). - class RefType + class RefType { ArgParser &_parser; std::string _name; @@ -317,65 +317,65 @@ ///\e RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {} ///\e - operator bool() + operator bool() { - Opts::iterator i = _parser._opts.find(_name); - LEMON_ASSERT(i!=_parser._opts.end(), - std::string()+"Unkown option: '"+_name+"'"); - LEMON_ASSERT(i->second.type==ArgParser::BOOL, - std::string()+"'"+_name+"' is a bool option"); - return *(i->second.bool_p); + Opts::iterator i = _parser._opts.find(_name); + LEMON_ASSERT(i!=_parser._opts.end(), + std::string()+"Unkown option: '"+_name+"'"); + LEMON_ASSERT(i->second.type==ArgParser::BOOL, + std::string()+"'"+_name+"' is a bool option"); + return *(i->second.bool_p); } ///\e operator std::string() { - Opts::iterator i = _parser._opts.find(_name); - LEMON_ASSERT(i!=_parser._opts.end(), - std::string()+"Unkown option: '"+_name+"'"); - LEMON_ASSERT(i->second.type==ArgParser::STRING, - std::string()+"'"+_name+"' is a string option"); - return *(i->second.string_p); + Opts::iterator i = _parser._opts.find(_name); + LEMON_ASSERT(i!=_parser._opts.end(), + std::string()+"Unkown option: '"+_name+"'"); + LEMON_ASSERT(i->second.type==ArgParser::STRING, + std::string()+"'"+_name+"' is a string option"); + return *(i->second.string_p); } ///\e - operator double() + operator double() { - Opts::iterator i = _parser._opts.find(_name); - LEMON_ASSERT(i!=_parser._opts.end(), - std::string()+"Unkown option: '"+_name+"'"); - LEMON_ASSERT(i->second.type==ArgParser::DOUBLE || - i->second.type==ArgParser::INTEGER, - std::string()+"'"+_name+"' is a floating point option"); - return i->second.type==ArgParser::DOUBLE ? - *(i->second.double_p) : *(i->second.int_p); + Opts::iterator i = _parser._opts.find(_name); + LEMON_ASSERT(i!=_parser._opts.end(), + std::string()+"Unkown option: '"+_name+"'"); + LEMON_ASSERT(i->second.type==ArgParser::DOUBLE || + i->second.type==ArgParser::INTEGER, + std::string()+"'"+_name+"' is a floating point option"); + return i->second.type==ArgParser::DOUBLE ? + *(i->second.double_p) : *(i->second.int_p); } ///\e - operator int() + operator int() { - Opts::iterator i = _parser._opts.find(_name); - LEMON_ASSERT(i!=_parser._opts.end(), - std::string()+"Unkown option: '"+_name+"'"); - LEMON_ASSERT(i->second.type==ArgParser::INTEGER, - std::string()+"'"+_name+"' is an integer option"); - return *(i->second.int_p); + Opts::iterator i = _parser._opts.find(_name); + LEMON_ASSERT(i!=_parser._opts.end(), + std::string()+"Unkown option: '"+_name+"'"); + LEMON_ASSERT(i->second.type==ArgParser::INTEGER, + std::string()+"'"+_name+"' is an integer option"); + return *(i->second.int_p); } }; ///Give back the value of an option - + ///Give back the value of an option. ///\sa RefType RefType operator[](const std::string &n) { return RefType(*this, n); - } + } ///Give back the non-option type arguments. ///Give back a reference to a vector consisting of the program arguments ///not starting with a '-' character. std::vector &files() { return _file_args; } - + }; } diff -r 4317d277ba21 -r 765619b7cbb2 lemon/assert.h --- a/lemon/assert.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/assert.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -28,7 +28,7 @@ namespace lemon { inline void assert_fail_log(const char *file, int line, const char *function, - const char *message, const char *assertion) + const char *message, const char *assertion) { std::cerr << file << ":" << line << ": "; if (function) @@ -40,23 +40,23 @@ } inline void assert_fail_abort(const char *file, int line, - const char *function, const char* message, - const char *assertion) + const char *function, const char* message, + const char *assertion) { assert_fail_log(file, line, function, message, assertion); std::abort(); } namespace _assert_bits { - - + + inline const char* cstringify(const std::string& str) { return str.c_str(); } inline const char* cstringify(const char* str) { return str; - } + } } } @@ -66,17 +66,17 @@ #undef LEMON_FIXME #undef LEMON_DEBUG -#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ - (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ +#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ + (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1 #error "LEMON assertion system is not set properly" #endif -#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ - (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ - (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ - defined(LEMON_ENABLE_ASSERTS)) && \ - (defined(LEMON_DISABLE_ASSERTS) || \ +#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ + (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ + (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ + defined(LEMON_ENABLE_ASSERTS)) && \ + (defined(LEMON_DISABLE_ASSERTS) || \ defined(NDEBUG)) #error "LEMON assertion system is not set properly" #endif @@ -136,12 +136,12 @@ /// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS' /// \endcode /// The checking is also disabled when the standard macro \c NDEBUG is defined. -/// +/// /// The LEMON assertion system has a wide range of customization /// properties. As a default behaviour the failed assertion prints a /// short log message to the standard error and aborts the execution. /// -/// The following modes can be used in the assertion system: +/// The following modes can be used in the assertion system: /// /// - \c LEMON_ASSERT_LOG The failed assertion prints a short log /// message to the standard error and continues the execution. @@ -155,7 +155,7 @@ /// const char* message, const char* assertion); /// \endcode /// The name of the function should be defined as the \c -/// LEMON_CUSTOM_ASSERT_HANDLER macro name. +/// LEMON_CUSTOM_ASSERT_HANDLER macro name. /// \code /// #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler /// \endcode @@ -166,11 +166,11 @@ /// If the macros are redefined with other settings and the /// \ref lemon/assert.h "assert.h" file is reincluded, then the /// behaviour is changed appropiately to the new settings. -# define LEMON_ASSERT(exp, msg) \ - (static_cast (!!(exp) ? 0 : ( \ - LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ - LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), #exp), 0))) +# define LEMON_ASSERT(exp, msg) \ + (static_cast (!!(exp) ? 0 : ( \ + LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ + LEMON_FUNCTION_NAME, \ + ::lemon::_assert_bits::cstringify(msg), #exp), 0))) /// \ingroup exceptions /// @@ -182,11 +182,11 @@ /// LEMON_ASSERT(false, msg); /// \endcode /// -/// \see LEMON_ASSERT -# define LEMON_FIXME(msg) \ - (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), \ - static_cast(0))) +/// \see LEMON_ASSERT +# define LEMON_FIXME(msg) \ + (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ + ::lemon::_assert_bits::cstringify(msg), \ + static_cast(0))) /// \ingroup exceptions /// @@ -210,12 +210,12 @@ /// current behaviour depends on the settings of \c LEMON_ASSERT /// macro. /// -/// \see LEMON_ASSERT -# define LEMON_DEBUG(exp, msg) \ - (static_cast (!!(exp) ? 0 : ( \ +/// \see LEMON_ASSERT +# define LEMON_DEBUG(exp, msg) \ + (static_cast (!!(exp) ? 0 : ( \ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ - LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), #exp), 0))) + LEMON_FUNCTION_NAME, \ + ::lemon::_assert_bits::cstringify(msg), #exp), 0))) #else @@ -224,24 +224,24 @@ # define LEMON_FIXME(msg) (static_cast(0)) # define LEMON_DEBUG(exp, msg) (static_cast(0)) # else -# define LEMON_ASSERT(exp, msg) \ - (static_cast (!!(exp) ? 0 : ( \ +# define LEMON_ASSERT(exp, msg) \ + (static_cast (!!(exp) ? 0 : ( \ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ - LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), \ - #exp), 0))) -# define LEMON_FIXME(msg) \ - (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), \ - static_cast(0))) + LEMON_FUNCTION_NAME, \ + ::lemon::_assert_bits::cstringify(msg), \ + #exp), 0))) +# define LEMON_FIXME(msg) \ + (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ + ::lemon::_assert_bits::cstringify(msg), \ + static_cast(0))) # if LEMON_ENABLE_DEBUG # define LEMON_DEBUG(exp, msg) (static_cast (!!(exp) ? 0 : ( \ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ LEMON_FUNCTION_NAME, \ - ::lemon::_assert_bits::cstringify(msg), \ - #exp), 0))) + ::lemon::_assert_bits::cstringify(msg), \ + #exp), 0))) # else # define LEMON_DEBUG(exp, msg) (static_cast(0)) # endif diff -r 4317d277ba21 -r 765619b7cbb2 lemon/base.cc --- a/lemon/base.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/base.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bfs.h --- a/lemon/bfs.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bfs.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -33,7 +33,7 @@ namespace lemon { - + ///Default traits class of Bfs class. ///Default traits class of Bfs class. @@ -41,34 +41,34 @@ template struct BfsDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///\brief The type of the map that stores the last ///arcs of the shortest paths. - /// + /// ///The type of the map that stores the last ///arcs of the shortest paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \ref PredMap. + + ///This function instantiates a \ref PredMap. ///\param G is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient to initialize - static PredMap *createPredMap(const GR &G) + static PredMap *createPredMap(const GR &G) { return new PredMap(G); } ///The type of the map that indicates which nodes are processed. - + ///The type of the map that indicates which nodes are processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \ref ProcessedMap. + + ///This function instantiates a \ref ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \ref ProcessedMap #ifdef DOXYGEN @@ -80,14 +80,14 @@ return new ProcessedMap(); } ///The type of the map that indicates which nodes are reached. - + ///The type of the map that indicates which nodes are reached. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef typename Digraph::template NodeMap ReachedMap; ///Instantiates a ReachedMap. - - ///This function instantiates a \ref ReachedMap. + + ///This function instantiates a \ref ReachedMap. ///\param G is the digraph, to which ///we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const GR &G) @@ -95,23 +95,23 @@ return new ReachedMap(G); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param G is the digraph, to which we would like to define the \ref DistMap static DistMap *createDistMap(const GR &G) { return new DistMap(G); } }; - + ///%BFS algorithm class. - + ///\ingroup search ///This class provides an efficient implementation of the %BFS algorithm. /// @@ -126,10 +126,10 @@ #ifdef DOXYGEN template + typename TR> #else template > + typename TR=BfsDefaultTraits > #endif class Bfs { public: @@ -142,14 +142,14 @@ class UninitializedParameter : public lemon::UninitializedParameter { public: virtual const char* what() const throw() { - return "lemon::Bfs::UninitializedParameter"; + return "lemon::Bfs::UninitializedParameter"; } }; typedef TR Traits; ///The type of the underlying digraph. typedef typename TR::Digraph Digraph; - + ///\brief The type of the map that stores the last ///arcs of the shortest paths. typedef typename TR::PredMap PredMap; @@ -190,34 +190,34 @@ int _curr_dist; ///Creates the maps if necessary. - + ///\todo Better memory allocation (instead of new). - void create_maps() + void create_maps() { if(!_pred) { - local_pred = true; - _pred = Traits::createPredMap(*G); + local_pred = true; + _pred = Traits::createPredMap(*G); } if(!_dist) { - local_dist = true; - _dist = Traits::createDistMap(*G); + local_dist = true; + _dist = Traits::createDistMap(*G); } if(!_reached) { - local_reached = true; - _reached = Traits::createReachedMap(*G); + local_reached = true; + _reached = Traits::createReachedMap(*G); } if(!_processed) { - local_processed = true; - _processed = Traits::createProcessedMap(*G); + local_processed = true; + _processed = Traits::createProcessedMap(*G); } } protected: - + Bfs() {} - + public: - + typedef Bfs Create; ///\name Named template parameters @@ -227,9 +227,9 @@ template struct DefPredMapTraits : public Traits { typedef T PredMap; - static PredMap *createPredMap(const Digraph &) + static PredMap *createPredMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -238,16 +238,16 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - struct DefPredMap : public Bfs< Digraph, DefPredMapTraits > { + struct DefPredMap : public Bfs< Digraph, DefPredMapTraits > { typedef Bfs< Digraph, DefPredMapTraits > Create; }; - + template struct DefDistMapTraits : public Traits { typedef T DistMap; - static DistMap *createDistMap(const Digraph &) + static DistMap *createDistMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -256,16 +256,16 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - struct DefDistMap : public Bfs< Digraph, DefDistMapTraits > { + struct DefDistMap : public Bfs< Digraph, DefDistMapTraits > { typedef Bfs< Digraph, DefDistMapTraits > Create; }; - + template struct DefReachedMapTraits : public Traits { typedef T ReachedMap; - static ReachedMap *createReachedMap(const Digraph &) + static ReachedMap *createReachedMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -274,16 +274,16 @@ ///\ref named-templ-param "Named parameter" for setting ReachedMap type /// template - struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits > { + struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits > { typedef Bfs< Digraph, DefReachedMapTraits > Create; }; - + template struct DefProcessedMapTraits : public Traits { typedef T ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &) + static ProcessedMap *createProcessedMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -295,12 +295,12 @@ struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits > { typedef Bfs< Digraph, DefProcessedMapTraits > Create; }; - + struct DefDigraphProcessedMapTraits : public Traits { typedef typename Digraph::template NodeMap ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &G) + static ProcessedMap *createProcessedMap(const Digraph &G) { - return new ProcessedMap(G); + return new ProcessedMap(G); } }; ///\brief \ref named-templ-param "Named parameter" @@ -311,16 +311,16 @@ ///If you don't set it explicitly, it will be automatically allocated. template struct DefProcessedMapToBeDefaultMap : - public Bfs< Digraph, DefDigraphProcessedMapTraits> { + public Bfs< Digraph, DefDigraphProcessedMapTraits> { typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create; }; - + ///@} - public: - + public: + ///Constructor. - + ///\param _G the digraph the algorithm will run on. /// Bfs(const Digraph& _G) : @@ -330,9 +330,9 @@ _reached(NULL), local_reached(false), _processed(NULL), local_processed(false) { } - + ///Destructor. - ~Bfs() + ~Bfs() { if(local_pred) delete _pred; if(local_dist) delete _dist; @@ -347,11 +347,11 @@ ///it will allocate one. The destructor deallocates this ///automatically allocated map, of course. ///\return (*this) - Bfs &predMap(PredMap &m) + Bfs &predMap(PredMap &m) { if(local_pred) { - delete _pred; - local_pred=false; + delete _pred; + local_pred=false; } _pred = &m; return *this; @@ -364,11 +364,11 @@ ///it will allocate one. The destructor deallocates this ///automatically allocated map, of course. ///\return (*this) - Bfs &reachedMap(ReachedMap &m) + Bfs &reachedMap(ReachedMap &m) { if(local_reached) { - delete _reached; - local_reached=false; + delete _reached; + local_reached=false; } _reached = &m; return *this; @@ -381,11 +381,11 @@ ///it will allocate one. The destructor deallocates this ///automatically allocated map, of course. ///\return (*this) - Bfs &processedMap(ProcessedMap &m) + Bfs &processedMap(ProcessedMap &m) { if(local_processed) { - delete _processed; - local_processed=false; + delete _processed; + local_processed=false; } _processed = &m; return *this; @@ -398,11 +398,11 @@ ///it will allocate one. The destructor deallocates this ///automatically allocated map, of course. ///\return (*this) - Bfs &distMap(DistMap &m) + Bfs &distMap(DistMap &m) { if(local_dist) { - delete _dist; - local_dist=false; + delete _dist; + local_dist=false; } _dist = &m; return *this; @@ -432,12 +432,12 @@ _queue_head=_queue_tail=0; _curr_dist=1; for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { - _pred->set(u,INVALID); - _reached->set(u,false); - _processed->set(u,false); + _pred->set(u,INVALID); + _reached->set(u,false); + _processed->set(u,false); } } - + ///Adds a new source node. ///Adds a new source node to the set of nodes to be processed. @@ -445,15 +445,15 @@ void addSource(Node s) { if(!(*_reached)[s]) - { - _reached->set(s,true); - _pred->set(s,INVALID); - _dist->set(s,0); - _queue[_queue_head++]=s; - _queue_next_dist=_queue_head; - } + { + _reached->set(s,true); + _pred->set(s,INVALID); + _dist->set(s,0); + _queue[_queue_head++]=s; + _queue_next_dist=_queue_head; + } } - + ///Processes the next node. ///Processes the next node. @@ -464,19 +464,19 @@ Node processNextNode() { if(_queue_tail==_queue_next_dist) { - _curr_dist++; - _queue_next_dist=_queue_head; + _curr_dist++; + _queue_next_dist=_queue_head; } Node n=_queue[_queue_tail++]; _processed->set(n,true); Node m; for(OutArcIt e(*G,n);e!=INVALID;++e) - if(!(*_reached)[m=G->target(e)]) { - _queue[_queue_head++]=m; - _reached->set(m,true); - _pred->set(m,e); - _dist->set(m,_curr_dist); - } + if(!(*_reached)[m=G->target(e)]) { + _queue[_queue_head++]=m; + _reached->set(m,true); + _pred->set(m,e); + _dist->set(m,_curr_dist); + } return n; } @@ -495,20 +495,20 @@ Node processNextNode(Node target, bool& reach) { if(_queue_tail==_queue_next_dist) { - _curr_dist++; - _queue_next_dist=_queue_head; + _curr_dist++; + _queue_next_dist=_queue_head; } Node n=_queue[_queue_tail++]; _processed->set(n,true); Node m; for(OutArcIt e(*G,n);e!=INVALID;++e) - if(!(*_reached)[m=G->target(e)]) { - _queue[_queue_head++]=m; - _reached->set(m,true); - _pred->set(m,e); - _dist->set(m,_curr_dist); + if(!(*_reached)[m=G->target(e)]) { + _queue[_queue_head++]=m; + _reached->set(m,true); + _pred->set(m,e); + _dist->set(m,_curr_dist); reach = reach || (target == m); - } + } return n; } @@ -528,23 +528,23 @@ Node processNextNode(const NM& nm, Node& rnode) { if(_queue_tail==_queue_next_dist) { - _curr_dist++; - _queue_next_dist=_queue_head; + _curr_dist++; + _queue_next_dist=_queue_head; } Node n=_queue[_queue_tail++]; _processed->set(n,true); Node m; for(OutArcIt e(*G,n);e!=INVALID;++e) - if(!(*_reached)[m=G->target(e)]) { - _queue[_queue_head++]=m; - _reached->set(m,true); - _pred->set(m,e); - _dist->set(m,_curr_dist); - if (nm[m] && rnode == INVALID) rnode = m; - } + if(!(*_reached)[m=G->target(e)]) { + _queue[_queue_head++]=m; + _reached->set(m,true); + _pred->set(m,e); + _dist->set(m,_curr_dist); + if (nm[m] && rnode == INVALID) rnode = m; + } return n; } - + ///Next node to be processed. ///Next node to be processed. @@ -552,10 +552,10 @@ ///\return The next node to be processed or INVALID if the queue is /// empty. Node nextNode() - { + { return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID; } - + ///\brief Returns \c false if there are nodes ///to be processed in the queue /// @@ -563,10 +563,10 @@ ///to be processed in the queue bool emptyQueue() { return _queue_tail==_queue_head; } ///Returns the number of the nodes to be processed. - + ///Returns the number of the nodes to be processed in the queue. int queueSize() { return _queue_head-_queue_tail; } - + ///Executes the algorithm. ///Executes the algorithm. @@ -584,7 +584,7 @@ { while ( !emptyQueue() ) processNextNode(); } - + ///Executes the algorithm until \c dest is reached. ///Executes the algorithm until \c dest is reached. @@ -602,7 +602,7 @@ bool reach = false; while ( !emptyQueue() && !reach ) processNextNode(dest, reach); } - + ///Executes the algorithm until a condition is met. ///Executes the algorithm until a condition is met. @@ -621,13 +621,13 @@ { Node rnode = INVALID; while ( !emptyQueue() && rnode == INVALID ) { - processNextNode(nm, rnode); + processNextNode(nm, rnode); } return rnode; } - + ///Runs %BFS algorithm from node \c s. - + ///This method runs the %BFS algorithm from a root node \c s ///in order to ///compute the @@ -646,9 +646,9 @@ addSource(s); start(); } - + ///Finds the shortest path between \c s and \c t. - + ///Finds the shortest path between \c s and \c t. /// ///\return The length of the shortest s---t path if there exists one, @@ -666,7 +666,7 @@ start(t); return reached(t) ? _curr_dist : 0; } - + ///@} ///\name Query Functions @@ -674,16 +674,16 @@ ///functions.\n ///Before the use of these functions, ///either run() or start() must be calleb. - + ///@{ typedef PredMapPath Path; ///Gives back the shortest path. - + ///Gives back the shortest path. ///\pre The \c t should be reachable from the source. - Path path(Node t) + Path path(Node t) { return Path(*G, *_pred, t); } @@ -722,15 +722,15 @@ ///\pre Either \ref run() or \ref start() must be called before ///using this function. Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: - G->source((*_pred)[v]); } - + G->source((*_pred)[v]); } + ///Returns a reference to the NodeMap of distances. ///Returns a reference to the NodeMap of distances. ///\pre Either \ref run() or \ref init() must ///be called before using this function. const DistMap &distMap() const { return *_dist;} - + ///Returns a reference to the shortest path tree map. ///Returns a reference to the NodeMap of the arcs of the @@ -738,7 +738,7 @@ ///\pre Either \ref run() or \ref init() ///must be called before using this function. const PredMap &predMap() const { return *_pred;} - + ///Checks if a node is reachable from the root. ///Returns \c true if \c v is reachable from the root. @@ -747,7 +747,7 @@ ///must be called before using this function. /// bool reached(Node v) { return (*_reached)[v]; } - + ///@} }; @@ -758,39 +758,39 @@ template struct BfsWizardDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///\brief The type of the map that stores the last ///arcs of the shortest paths. - /// + /// ///The type of the map that stores the last ///arcs of the shortest paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \ref PredMap. + + ///This function instantiates a \ref PredMap. ///\param g is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient to initialize #ifdef DOXYGEN - static PredMap *createPredMap(const GR &g) + static PredMap *createPredMap(const GR &g) #else - static PredMap *createPredMap(const GR &) + static PredMap *createPredMap(const GR &) #endif { return new PredMap(); } ///The type of the map that indicates which nodes are processed. - + ///The type of the map that indicates which nodes are processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \ref ProcessedMap. + + ///This function instantiates a \ref ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \ref ProcessedMap #ifdef DOXYGEN @@ -802,14 +802,14 @@ return new ProcessedMap(); } ///The type of the map that indicates which nodes are reached. - + ///The type of the map that indicates which nodes are reached. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef typename Digraph::template NodeMap ReachedMap; ///Instantiates a ReachedMap. - - ///This function instantiates a \ref ReachedMap. + + ///This function instantiates a \ref ReachedMap. ///\param G is the digraph, to which ///we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const GR &G) @@ -817,14 +817,14 @@ return new ReachedMap(G); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param g is the digraph, to which we would like to define the \ref DistMap #ifdef DOXYGEN static DistMap *createDistMap(const GR &g) @@ -835,7 +835,7 @@ return new DistMap(); } }; - + /// Default traits used by \ref BfsWizard /// To make it easier to use Bfs algorithm @@ -865,28 +865,28 @@ void *_dist; ///Pointer to the source node. Node _source; - + public: /// Constructor. - + /// This constructor does not require parameters, therefore it initiates /// all of the attributes to default values (0, INVALID). BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), - _dist(0), _source(INVALID) {} + _dist(0), _source(INVALID) {} /// Constructor. - + /// This constructor requires some parameters, /// listed in the parameters list. /// Others are initiated to 0. /// \param g is the initial value of \ref _g /// \param s is the initial value of \ref _source BfsWizardBase(const GR &g, Node s=INVALID) : - _g(reinterpret_cast(const_cast(&g))), + _g(reinterpret_cast(const_cast(&g))), _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {} }; - + /// A class to make the usage of Bfs algorithm easier /// This class is created to make it easier to use Bfs algorithm. @@ -921,7 +921,7 @@ typedef typename Digraph::Arc Arc; //\e typedef typename Digraph::OutArcIt OutArcIt; - + ///\brief The type of the map that stores ///the reached nodes typedef typename TR::ReachedMap ReachedMap; @@ -951,7 +951,7 @@ ~BfsWizard() {} ///Runs Bfs algorithm from a given node. - + ///Runs Bfs algorithm from a given node. ///The node can be given by the \ref source function. void run() @@ -959,12 +959,12 @@ if(Base::_source==INVALID) throw UninitializedParameter(); Bfs alg(*reinterpret_cast(Base::_g)); if(Base::_reached) - alg.reachedMap(*reinterpret_cast(Base::_reached)); - if(Base::_processed) + alg.reachedMap(*reinterpret_cast(Base::_reached)); + if(Base::_processed) alg.processedMap(*reinterpret_cast(Base::_processed)); - if(Base::_pred) + if(Base::_pred) alg.predMap(*reinterpret_cast(Base::_pred)); - if(Base::_dist) + if(Base::_dist) alg.distMap(*reinterpret_cast(Base::_dist)); alg.run(Base::_source); } @@ -985,7 +985,7 @@ static PredMap *createPredMap(const Digraph &) { return 0; }; DefPredMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting PredMap /// @@ -993,20 +993,20 @@ ///function for setting PredMap /// template - BfsWizard > predMap(const T &t) + BfsWizard > predMap(const T &t) { Base::_pred=reinterpret_cast(const_cast(&t)); return BfsWizard >(*this); } - - + + template struct DefReachedMapBase : public Base { typedef T ReachedMap; static ReachedMap *createReachedMap(const Digraph &) { return 0; }; DefReachedMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting ReachedMap /// @@ -1014,12 +1014,12 @@ ///function for setting ReachedMap /// template - BfsWizard > reachedMap(const T &t) + BfsWizard > reachedMap(const T &t) { Base::_reached=reinterpret_cast(const_cast(&t)); return BfsWizard >(*this); } - + template struct DefProcessedMapBase : public Base { @@ -1027,7 +1027,7 @@ static ProcessedMap *createProcessedMap(const Digraph &) { return 0; }; DefProcessedMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting ProcessedMap /// @@ -1035,20 +1035,20 @@ ///function for setting ProcessedMap /// template - BfsWizard > processedMap(const T &t) + BfsWizard > processedMap(const T &t) { Base::_processed=reinterpret_cast(const_cast(&t)); return BfsWizard >(*this); } - - + + template struct DefDistMapBase : public Base { typedef T DistMap; static DistMap *createDistMap(const Digraph &) { return 0; }; DefDistMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting DistMap type /// @@ -1056,24 +1056,24 @@ ///function for setting DistMap type /// template - BfsWizard > distMap(const T &t) + BfsWizard > distMap(const T &t) { Base::_dist=reinterpret_cast(const_cast(&t)); return BfsWizard >(*this); } - + /// Sets the source node, from which the Bfs algorithm runs. /// Sets the source node, from which the Bfs algorithm runs. /// \param s is the source node. - BfsWizard &source(Node s) + BfsWizard &source(Node s) { Base::_source=s; return *this; } - + }; - + ///Function type interface for Bfs algorithm. /// \ingroup search @@ -1100,7 +1100,7 @@ #ifdef DOXYGEN /// \brief Visitor class for bfs. - /// + /// /// This class defines the interface of the BfsVisit events, and /// it could be the base of a real Visitor class. template @@ -1109,26 +1109,26 @@ typedef typename Digraph::Arc Arc; typedef typename Digraph::Node Node; /// \brief Called when the arc reach a node. - /// + /// /// It is called when the bfs find an arc which target is not /// reached yet. void discover(const Arc& arc) {} /// \brief Called when the node reached first time. - /// + /// /// It is Called when the node reached first time. void reach(const Node& node) {} - /// \brief Called when the arc examined but target of the arc + /// \brief Called when the arc examined but target of the arc /// already discovered. - /// - /// It called when the arc examined but the target of the arc + /// + /// It called when the arc examined but the target of the arc /// already discovered. void examine(const Arc& arc) {} /// \brief Called for the source node of the bfs. - /// + /// /// It is called for the source node of the bfs. void start(const Node& node) {} /// \brief Called when the node processed. - /// + /// /// It is Called when the node processed. void process(const Node& node) {} }; @@ -1147,12 +1147,12 @@ template struct Constraints { void constraints() { - Arc arc; - Node node; - visitor.discover(arc); - visitor.reach(node); - visitor.examine(arc); - visitor.start(node); + Arc arc; + Node node; + visitor.discover(arc); + visitor.reach(node); + visitor.examine(arc); + visitor.start(node); visitor.process(node); } _Visitor& visitor; @@ -1167,11 +1167,11 @@ template struct BfsVisitDefaultTraits { - /// \brief The digraph type the algorithm runs on. + /// \brief The digraph type the algorithm runs on. typedef _Digraph Digraph; /// \brief The type of the map that indicates which nodes are reached. - /// + /// /// The type of the map that indicates which nodes are reached. /// It must meet the \ref concepts::WriteMap "WriteMap" concept. /// \todo named parameter to set this type, function to read and write. @@ -1179,7 +1179,7 @@ /// \brief Instantiates a ReachedMap. /// - /// This function instantiates a \ref ReachedMap. + /// This function instantiates a \ref ReachedMap. /// \param digraph is the digraph, to which /// we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const Digraph &digraph) { @@ -1189,24 +1189,24 @@ }; /// \ingroup search - /// + /// /// \brief %BFS Visit algorithm class. - /// + /// /// This class provides an efficient implementation of the %BFS algorithm /// with visitor interface. /// /// The %BfsVisit class provides an alternative interface to the Bfs /// class. It works with callback mechanism, the BfsVisit object calls - /// on every bfs event the \c Visitor class member functions. + /// on every bfs event the \c Visitor class member functions. /// /// \tparam _Digraph The digraph type the algorithm runs on. The default value is /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it /// is only passed to \ref BfsDefaultTraits. - /// \tparam _Visitor The Visitor object for the algorithm. The + /// \tparam _Visitor The Visitor object for the algorithm. The /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which /// does not observe the Bfs events. If you want to observe the bfs /// events you should implement your own Visitor class. - /// \tparam _Traits Traits class to set various data types used by the + /// \tparam _Traits Traits class to set various data types used by the /// algorithm. The default traits class is /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". /// See \ref BfsVisitDefaultTraits for the documentation of @@ -1215,21 +1215,21 @@ template #else template , - typename _Traits = BfsDefaultTraits<_Digraph> > + typename _Visitor = BfsVisitor<_Digraph>, + typename _Traits = BfsDefaultTraits<_Digraph> > #endif class BfsVisit { public: - + /// \brief \ref Exception for uninitialized parameters. /// /// This error represents problems in the initialization /// of the parameters of the algorithms. class UninitializedParameter : public lemon::UninitializedParameter { public: - virtual const char* what() const throw() + virtual const char* what() const throw() { - return "lemon::BfsVisit::UninitializedParameter"; + return "lemon::BfsVisit::UninitializedParameter"; } }; @@ -1266,15 +1266,15 @@ /// Creates the maps if necessary. void create_maps() { if(!_reached) { - local_reached = true; - _reached = Traits::createReachedMap(*_digraph); + local_reached = true; + _reached = Traits::createReachedMap(*_digraph); } } protected: BfsVisit() {} - + public: typedef BfsVisit Create; @@ -1286,22 +1286,22 @@ struct DefReachedMapTraits : public Traits { typedef T ReachedMap; static ReachedMap *createReachedMap(const Digraph &digraph) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; - /// \brief \ref named-templ-param "Named parameter" for setting + /// \brief \ref named-templ-param "Named parameter" for setting /// ReachedMap type /// /// \ref named-templ-param "Named parameter" for setting ReachedMap type template struct DefReachedMap : public BfsVisit< Digraph, Visitor, - DefReachedMapTraits > { + DefReachedMapTraits > { typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits > Create; }; ///@} - public: - + public: + /// \brief Constructor. /// /// Constructor. @@ -1309,10 +1309,10 @@ /// \param digraph the digraph the algorithm will run on. /// \param visitor The visitor of the algorithm. /// - BfsVisit(const Digraph& digraph, Visitor& visitor) + BfsVisit(const Digraph& digraph, Visitor& visitor) : _digraph(&digraph), _visitor(&visitor), - _reached(0), local_reached(false) {} - + _reached(0), local_reached(false) {} + /// \brief Destructor. /// /// Destructor. @@ -1329,8 +1329,8 @@ /// \return (*this) BfsVisit &reachedMap(ReachedMap &m) { if(local_reached) { - delete _reached; - local_reached = false; + delete _reached; + local_reached = false; } _reached = &m; return *this; @@ -1357,22 +1357,22 @@ _list.resize(countNodes(*_digraph)); _list_front = _list_back = -1; for (NodeIt u(*_digraph) ; u != INVALID ; ++u) { - _reached->set(u, false); + _reached->set(u, false); } } - + /// \brief Adds a new source node. /// /// Adds a new source node to the set of nodes to be processed. void addSource(Node s) { if(!(*_reached)[s]) { - _reached->set(s,true); - _visitor->start(s); - _visitor->reach(s); + _reached->set(s,true); + _visitor->start(s); + _visitor->reach(s); _list[++_list_back] = s; - } + } } - + /// \brief Processes the next node. /// /// Processes the next node. @@ -1380,7 +1380,7 @@ /// \return The processed node. /// /// \pre The queue must not be empty! - Node processNextNode() { + Node processNextNode() { Node n = _list[++_list_front]; _visitor->process(n); Arc e; @@ -1467,7 +1467,7 @@ /// /// \return The next node to be processed or INVALID if the stack is /// empty. - Node nextNode() { + Node nextNode() { return _list_front != _list_back ? _list[_list_front + 1] : INVALID; } @@ -1482,7 +1482,7 @@ /// /// Returns the number of the nodes to be processed in the queue. int queueSize() { return _list_back - _list_front; } - + /// \brief Executes the algorithm. /// /// Executes the algorithm. @@ -1492,7 +1492,7 @@ void start() { while ( !emptyQueue() ) processNextNode(); } - + /// \brief Executes the algorithm until \c dest is reached. /// /// Executes the algorithm until \c dest is reached. @@ -1503,7 +1503,7 @@ bool reach = false; while ( !emptyQueue() && !reach ) processNextNode(dest, reach); } - + /// \brief Executes the algorithm until a condition is met. /// /// Executes the algorithm until a condition is met. @@ -1521,7 +1521,7 @@ Node start(const NM &nm) { Node rnode = INVALID; while ( !emptyQueue() && rnode == INVALID ) { - processNextNode(nm, rnode); + processNextNode(nm, rnode); } return rnode; } @@ -1542,7 +1542,7 @@ } /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph. - /// + /// /// This method runs the %BFS algorithm in order to /// compute the %BFS path to each node. The algorithm computes /// - The %BFS tree. diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bin_heap.h --- a/lemon/bin_heap.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bin_heap.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -48,7 +48,7 @@ ///\sa FibHeap ///\sa Dijkstra template > + typename _Compare = std::less<_Prio> > class BinHeap { public: @@ -90,7 +90,7 @@ /// internally to handle the cross references. The value of the map /// should be PRE_HEAP (-1) for each element. explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {} - + /// \brief The constructor. /// /// The constructor. @@ -99,7 +99,7 @@ /// should be PRE_HEAP (-1) for each element. /// /// \param _comp The comparator function object. - BinHeap(ItemIntMap &_iim, const Compare &_comp) + BinHeap(ItemIntMap &_iim, const Compare &_comp) : iim(_iim), comp(_comp) {} @@ -107,20 +107,20 @@ /// /// \brief Returns the number of items stored in the heap. int size() const { return data.size(); } - + /// \brief Checks if the heap stores no items. /// /// Returns \c true if and only if the heap stores no items. bool empty() const { return data.empty(); } /// \brief Make empty this heap. - /// + /// /// Make empty this heap. It does not change the cross reference map. /// If you want to reuse what is not surely empty you should first clear /// the heap and after that you should set the cross reference map for /// each item to \c PRE_HEAP. - void clear() { - data.clear(); + void clear() { + data.clear(); } private: @@ -134,9 +134,9 @@ int bubble_up(int hole, Pair p) { int par = parent(hole); while( hole>0 && less(p,data[par]) ) { - move(data[par],hole); - hole = par; - par = parent(hole); + move(data[par],hole); + hole = par; + par = parent(hole); } move(p, hole); return hole; @@ -145,19 +145,19 @@ int bubble_down(int hole, Pair p, int length) { int child = second_child(hole); while(child < length) { - if( less(data[child-1], data[child]) ) { - --child; - } - if( !less(data[child], p) ) - goto ok; - move(data[child], hole); - hole = child; - child = second_child(hole); + if( less(data[child-1], data[child]) ) { + --child; + } + if( !less(data[child], p) ) + goto ok; + move(data[child], hole); + hole = child; + child = second_child(hole); } child--; if( child 0) { - bubble_down(0, data[n], n); + bubble_down(0, data[n], n); } data.pop_back(); } @@ -228,17 +228,17 @@ int n = data.size()-1; iim.set(data[h].first, POST_HEAP); if( h < n ) { - if ( bubble_up(h, data[n]) == h) { - bubble_down(h, data[n], n); - } + if ( bubble_up(h, data[n]) == h) { + bubble_down(h, data[n], n); + } } data.pop_back(); } - + /// \brief Returns the priority of \c i. /// - /// This function returns the priority of item \c i. + /// This function returns the priority of item \c i. /// \pre \c i must be in the heap. /// \param i The item. Prio operator[](const Item &i) const { @@ -246,7 +246,7 @@ return data[idx].second; } - /// \brief \c i gets to the heap with priority \c p independently + /// \brief \c i gets to the heap with priority \c p independently /// if \c i was already there. /// /// This method calls \ref push(\c i, \c p) if \c i is not stored @@ -256,13 +256,13 @@ void set(const Item &i, const Prio &p) { int idx = iim[i]; if( idx < 0 ) { - push(i,p); + push(i,p); } else if( comp(p, data[idx].second) ) { - bubble_up(idx, Pair(i,p)); + bubble_up(idx, Pair(i,p)); } else { - bubble_down(idx, Pair(i,p), data.size()); + bubble_down(idx, Pair(i,p), data.size()); } } @@ -277,10 +277,10 @@ int idx = iim[i]; bubble_up(idx, Pair(i,p)); } - + /// \brief Increases the priority of \c i to \c p. /// - /// This method sets the priority of item \c i to \c p. + /// This method sets the priority of item \c i to \c p. /// \pre \c i must be stored in the heap with priority at most \c /// p relative to \c Compare. /// \param i The item. @@ -290,7 +290,7 @@ bubble_down(idx, Pair(i,p), data.size()); } - /// \brief Returns if \c item is in, has already been in, or has + /// \brief Returns if \c item is in, has already been in, or has /// never been in the heap. /// /// This method returns PRE_HEAP if \c item has never been in the @@ -301,7 +301,7 @@ State state(const Item &i) const { int s = iim[i]; if( s>=0 ) - s=0; + s=0; return State(s); } @@ -311,7 +311,7 @@ /// manually clear the heap when it is important to achive the /// better time complexity. /// \param i The item. - /// \param st The state. It should not be \c IN_HEAP. + /// \param st The state. It should not be \c IN_HEAP. void state(const Item& i, State st) { switch (st) { case POST_HEAP: @@ -340,7 +340,7 @@ } }; // class BinHeap - + } // namespace lemon #endif // LEMON_BIN_HEAP_H diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/alteration_notifier.h --- a/lemon/bits/alteration_notifier.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/alteration_notifier.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -32,7 +32,7 @@ /// \ingroup graphbits /// - /// \brief Notifier class to notify observes about alterations in + /// \brief Notifier class to notify observes about alterations in /// a container. /// /// The simple graph's can be refered as two containers, one node container @@ -49,7 +49,7 @@ /// an alteration in the graph, which cause only drawback on the /// alteration of the graph. /// - /// This class provides an interface to the container. The \e first() and \e + /// This class provides an interface to the container. The \e first() and \e /// next() member functions make possible to iterate on the keys of the /// container. The \e id() function returns an integer id for each key. /// The \e maxId() function gives back an upper bound of the ids. @@ -60,7 +60,7 @@ /// \e erase() signals that only one or few items added or erased to or /// from the graph. If all items are erased from the graph or from an empty /// graph a new graph is builded then it can be signaled with the - /// clear() and build() members. Important rule that if we erase items + /// clear() and build() members. Important rule that if we erase items /// from graph we should first signal the alteration and after that erase /// them from the container, on the other way on item addition we should /// first extend the container and just after that signal the alteration. @@ -68,7 +68,7 @@ /// The alteration can be observed with a class inherited from the /// \e ObserverBase nested class. The signals can be handled with /// overriding the virtual functions defined in the base class. The - /// observer base can be attached to the notifier with the + /// observer base can be attached to the notifier with the /// \e attach() member and can be detached with detach() function. The /// alteration handlers should not call any function which signals /// an other alteration in the same notifier and should not @@ -79,13 +79,13 @@ /// observeres will not be notified and the fulfilled additions will /// be rolled back by calling the \e erase() or \e clear() /// functions. Thence the \e erase() and \e clear() should not throw - /// exception. Actullay, it can be throw only + /// exception. Actullay, it can be throw only /// \ref AlterationObserver::ImmediateDetach ImmediateDetach /// exception which detach the observer from the notifier. /// /// There are some place when the alteration observing is not completly /// reliable. If we want to carry out the node degree in the graph - /// as in the \ref InDegMap and we use the reverseEdge that cause + /// as in the \ref InDegMap and we use the reverseEdge that cause /// unreliable functionality. Because the alteration observing signals /// only erasing and adding but not the reversing it will stores bad /// degrees. The sub graph adaptors cannot signal the alterations because @@ -104,7 +104,7 @@ typedef _Container Container; typedef _Item Item; - /// \brief Exception which can be called from \e clear() and + /// \brief Exception which can be called from \e clear() and /// \e erase(). /// /// From the \e clear() and \e erase() function only this @@ -127,7 +127,7 @@ /// /// The build() and clear() members are to notify the observer /// about the container is built from an empty container or - /// is cleared to an empty container. + /// is cleared to an empty container. class ObserverBase { protected: @@ -138,7 +138,7 @@ /// \brief Default constructor. /// /// Default constructor for ObserverBase. - /// + /// ObserverBase() : _notifier(0) {} /// \brief Constructor which attach the observer into notifier. @@ -151,13 +151,13 @@ /// \brief Constructor which attach the obserever to the same notifier. /// /// Constructor which attach the obserever to the same notifier as - /// the other observer is attached to. + /// the other observer is attached to. ObserverBase(const ObserverBase& copy) { - if (copy.attached()) { + if (copy.attached()) { attach(*copy.notifier()); - } + } } - + /// \brief Destructor virtual ~ObserverBase() { if (attached()) { @@ -170,9 +170,9 @@ /// This member attaches the observer into an AlterationNotifier. /// void attach(AlterationNotifier& nf) { - nf.attach(*this); + nf.attach(*this); } - + /// \brief Detaches the observer into an AlterationNotifier. /// /// This member detaches the observer from an AlterationNotifier. @@ -180,15 +180,15 @@ void detach() { _notifier->detach(*this); } - - /// \brief Gives back a pointer to the notifier which the map + + /// \brief Gives back a pointer to the notifier which the map /// attached into. /// /// This function gives back a pointer to the notifier which the map /// attached into. /// Notifier* notifier() const { return const_cast(_notifier); } - + /// Gives back true when the observer is attached into a notifier. bool attached() const { return _notifier != 0; } @@ -197,7 +197,7 @@ ObserverBase& operator=(const ObserverBase& copy); protected: - + Notifier* _notifier; typename std::list::iterator _index; @@ -209,7 +209,7 @@ /// subclasses. virtual void add(const Item&) = 0; - /// \brief The member function to notificate the observer about + /// \brief The member function to notificate the observer about /// more item is added to the container. /// /// The add() member function notificates the observer about more item @@ -222,10 +222,10 @@ /// /// The erase() member function notificates the observer about an /// item is erased from the container. It have to be overrided in - /// the subclasses. + /// the subclasses. virtual void erase(const Item&) = 0; - /// \brief The member function to notificate the observer about + /// \brief The member function to notificate the observer about /// more item is erased from the container. /// /// The erase() member function notificates the observer about more item @@ -247,50 +247,50 @@ /// /// The clear() member function notificates the observer about all /// items are erased from the container. It have to be overrided in - /// the subclasses. + /// the subclasses. virtual void clear() = 0; }; - + protected: const Container* container; - typedef std::list Observers; + typedef std::list Observers; Observers _observers; - + public: /// \brief Default constructor. /// - /// The default constructor of the AlterationNotifier. + /// The default constructor of the AlterationNotifier. /// It creates an empty notifier. - AlterationNotifier() + AlterationNotifier() : container(0) {} /// \brief Constructor. /// /// Constructor with the observed container parameter. - AlterationNotifier(const Container& _container) + AlterationNotifier(const Container& _container) : container(&_container) {} - /// \brief Copy Constructor of the AlterationNotifier. + /// \brief Copy Constructor of the AlterationNotifier. /// - /// Copy constructor of the AlterationNotifier. + /// Copy constructor of the AlterationNotifier. /// It creates only an empty notifier because the copiable /// notifier's observers have to be registered still into that notifier. - AlterationNotifier(const AlterationNotifier& _notifier) + AlterationNotifier(const AlterationNotifier& _notifier) : container(_notifier.container) {} /// \brief Destructor. - /// + /// /// Destructor of the AlterationNotifier. /// ~AlterationNotifier() { typename Observers::iterator it; for (it = _observers.begin(); it != _observers.end(); ++it) { - (*it)->_notifier = 0; + (*it)->_notifier = 0; } } @@ -338,13 +338,13 @@ int maxId() const { return container->maxId(Item()); } - + protected: void attach(ObserverBase& observer) { observer._index = _observers.insert(_observers.begin(), &observer); observer._notifier = this; - } + } void detach(ObserverBase& observer) { _observers.erase(observer._index); @@ -353,13 +353,13 @@ } public: - - /// \brief Notifies all the registed observers about an item added to + + /// \brief Notifies all the registed observers about an item added to /// the container. /// - /// It notifies all the registed observers about an item added to + /// It notifies all the registed observers about an item added to /// the container. - /// + /// void add(const Item& item) { typename Observers::reverse_iterator it; try { @@ -373,14 +373,14 @@ } throw; } - } + } - /// \brief Notifies all the registed observers about more item added to + /// \brief Notifies all the registed observers about more item added to /// the container. /// - /// It notifies all the registed observers about more item added to + /// It notifies all the registed observers about more item added to /// the container. - /// + /// void add(const std::vector& items) { typename Observers::reverse_iterator it; try { @@ -394,14 +394,14 @@ } throw; } - } + } - /// \brief Notifies all the registed observers about an item erased from + /// \brief Notifies all the registed observers about an item erased from /// the container. - /// - /// It notifies all the registed observers about an item erased from + /// + /// It notifies all the registed observers about an item erased from /// the container. - /// + /// void erase(const Item& item) throw() { typename Observers::iterator it = _observers.begin(); while (it != _observers.end()) { @@ -416,12 +416,12 @@ } } - /// \brief Notifies all the registed observers about more item erased + /// \brief Notifies all the registed observers about more item erased /// from the container. - /// - /// It notifies all the registed observers about more item erased from + /// + /// It notifies all the registed observers about more item erased from /// the container. - /// + /// void erase(const std::vector& items) { typename Observers::iterator it = _observers.begin(); while (it != _observers.end()) { @@ -436,9 +436,9 @@ } } - /// \brief Notifies all the registed observers about the container is + /// \brief Notifies all the registed observers about the container is /// built. - /// + /// /// Notifies all the registed observers about the container is built /// from an empty container. void build() { @@ -456,7 +456,7 @@ } } - /// \brief Notifies all the registed observers about all items are + /// \brief Notifies all the registed observers about all items are /// erased. /// /// Notifies all the registed observers about all items are erased diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/array_map.h --- a/lemon/bits/array_map.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/array_map.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -38,16 +38,16 @@ /// /// The ArrayMap template class is graph map structure what /// automatically updates the map when a key is added to or erased from - /// the map. This map uses the allocators to implement + /// the map. This map uses the allocators to implement /// the container functionality. /// /// The template parameters are the Graph the current Item type and /// the Value type of the map. template - class ArrayMap + class ArrayMap : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { public: - /// The graph type of the maps. + /// The graph type of the maps. typedef _Graph Graph; /// The item type of the map. typedef _Item Item; @@ -69,7 +69,7 @@ /// The MapBase of the Map which imlements the core regisitry function. typedef typename Notifier::ObserverBase Parent; - + private: typedef std::allocator Allocator; @@ -84,31 +84,31 @@ Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); - } + int id = nf->id(it);; + allocator.construct(&(values[id]), Value()); + } } - /// \brief Constructor to use default value to initialize the map. + /// \brief Constructor to use default value to initialize the map. /// - /// It constructs a map and initialize all of the the map. + /// It constructs a map and initialize all of the the map. ArrayMap(const Graph& graph, const Value& value) { Parent::attach(graph.notifier(Item())); allocate_memory(); Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), value); - } + int id = nf->id(it);; + allocator.construct(&(values[id]), value); + } } /// \brief Constructor to copy a map of the same map type. /// - /// Constructor to copy a map of the same map type. + /// Constructor to copy a map of the same map type. ArrayMap(const ArrayMap& copy) : Parent() { if (copy.attached()) { - attach(*copy.notifier()); + attach(*copy.notifier()); } capacity = copy.capacity; if (capacity == 0) return; @@ -116,18 +116,18 @@ Notifier* nf = Parent::notifier(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), copy.values[id]); + int id = nf->id(it);; + allocator.construct(&(values[id]), copy.values[id]); } } /// \brief Assign operator. /// /// This operator assigns for each item in the map the - /// value mapped to the same item in the copied map. + /// value mapped to the same item in the copied map. /// The parameter map should be indiced with the same /// itemset because this assign operator does not change - /// the container of the map. + /// the container of the map. ArrayMap& operator=(const ArrayMap& cmap) { return operator=(cmap); } @@ -138,7 +138,7 @@ /// The given parameter should be conform to the ReadMap /// concecpt and could be indiced by the current item set of /// the NodeMap. In this case the value for each item - /// is assigned by the value of the given ReadMap. + /// is assigned by the value of the given ReadMap. template ArrayMap& operator=(const CMap& cmap) { checkConcept, CMap>(); @@ -151,15 +151,15 @@ } /// \brief The destructor of the map. - /// + /// /// The destructor of the map. - virtual ~ArrayMap() { + virtual ~ArrayMap() { if (attached()) { - clear(); - detach(); + clear(); + detach(); } } - + protected: using Parent::attach; @@ -168,26 +168,26 @@ public: - /// \brief The subscript operator. + /// \brief The subscript operator. /// /// The subscript operator. The map can be subscripted by the - /// actual keys of the graph. + /// actual keys of the graph. Value& operator[](const Key& key) { int id = Parent::notifier()->id(key); return values[id]; - } - + } + /// \brief The const subscript operator. /// /// The const subscript operator. The map can be subscripted by the - /// actual keys of the graph. + /// actual keys of the graph. const Value& operator[](const Key& key) const { int id = Parent::notifier()->id(key); return values[id]; } /// \brief Setter function of the map. - /// + /// /// Setter function of the map. Equivalent with map[key] = val. /// This is a compatibility feature with the not dereferable maps. void set(const Key& key, const Value& val) { @@ -197,81 +197,81 @@ protected: /// \brief Adds a new key to the map. - /// + /// /// It adds a new key to the map. It called by the observer notifier - /// and it overrides the add() member function of the observer base. + /// and it overrides the add() member function of the observer base. virtual void add(const Key& key) { Notifier* nf = Parent::notifier(); int id = nf->id(key); if (id >= capacity) { - int new_capacity = (capacity == 0 ? 1 : capacity); - while (new_capacity <= id) { - new_capacity <<= 1; - } - Value* new_values = allocator.allocate(new_capacity); - Item it; - for (nf->first(it); it != INVALID; nf->next(it)) { - int jd = nf->id(it);; - if (id != jd) { - allocator.construct(&(new_values[jd]), values[jd]); - allocator.destroy(&(values[jd])); - } - } - if (capacity != 0) allocator.deallocate(values, capacity); - values = new_values; - capacity = new_capacity; + int new_capacity = (capacity == 0 ? 1 : capacity); + while (new_capacity <= id) { + new_capacity <<= 1; + } + Value* new_values = allocator.allocate(new_capacity); + Item it; + for (nf->first(it); it != INVALID; nf->next(it)) { + int jd = nf->id(it);; + if (id != jd) { + allocator.construct(&(new_values[jd]), values[jd]); + allocator.destroy(&(values[jd])); + } + } + if (capacity != 0) allocator.deallocate(values, capacity); + values = new_values; + capacity = new_capacity; } allocator.construct(&(values[id]), Value()); } /// \brief Adds more new keys to the map. - /// + /// /// It adds more new keys to the map. It called by the observer notifier - /// and it overrides the add() member function of the observer base. + /// and it overrides the add() member function of the observer base. virtual void add(const std::vector& keys) { Notifier* nf = Parent::notifier(); int max_id = -1; for (int i = 0; i < int(keys.size()); ++i) { - int id = nf->id(keys[i]); - if (id > max_id) { - max_id = id; - } + int id = nf->id(keys[i]); + if (id > max_id) { + max_id = id; + } } if (max_id >= capacity) { - int new_capacity = (capacity == 0 ? 1 : capacity); - while (new_capacity <= max_id) { - new_capacity <<= 1; - } - Value* new_values = allocator.allocate(new_capacity); - Item it; - for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it); - bool found = false; - for (int i = 0; i < int(keys.size()); ++i) { - int jd = nf->id(keys[i]); - if (id == jd) { - found = true; - break; - } - } - if (found) continue; - allocator.construct(&(new_values[id]), values[id]); - allocator.destroy(&(values[id])); - } - if (capacity != 0) allocator.deallocate(values, capacity); - values = new_values; - capacity = new_capacity; + int new_capacity = (capacity == 0 ? 1 : capacity); + while (new_capacity <= max_id) { + new_capacity <<= 1; + } + Value* new_values = allocator.allocate(new_capacity); + Item it; + for (nf->first(it); it != INVALID; nf->next(it)) { + int id = nf->id(it); + bool found = false; + for (int i = 0; i < int(keys.size()); ++i) { + int jd = nf->id(keys[i]); + if (id == jd) { + found = true; + break; + } + } + if (found) continue; + allocator.construct(&(new_values[id]), values[id]); + allocator.destroy(&(values[id])); + } + if (capacity != 0) allocator.deallocate(values, capacity); + values = new_values; + capacity = new_capacity; } for (int i = 0; i < int(keys.size()); ++i) { - int id = nf->id(keys[i]); - allocator.construct(&(values[id]), Value()); + int id = nf->id(keys[i]); + allocator.construct(&(values[id]), Value()); } } - + /// \brief Erase a key from the map. /// /// Erase a key from the map. It called by the observer notifier - /// and it overrides the erase() member function of the observer base. + /// and it overrides the erase() member function of the observer base. virtual void erase(const Key& key) { int id = Parent::notifier()->id(key); allocator.destroy(&(values[id])); @@ -280,67 +280,67 @@ /// \brief Erase more keys from the map. /// /// Erase more keys from the map. It called by the observer notifier - /// and it overrides the erase() member function of the observer base. + /// and it overrides the erase() member function of the observer base. virtual void erase(const std::vector& keys) { for (int i = 0; i < int(keys.size()); ++i) { - int id = Parent::notifier()->id(keys[i]); - allocator.destroy(&(values[id])); + int id = Parent::notifier()->id(keys[i]); + allocator.destroy(&(values[id])); } } /// \brief Buildes the map. - /// + /// /// It buildes the map. It called by the observer notifier - /// and it overrides the build() member function of the observer base. + /// and it overrides the build() member function of the observer base. virtual void build() { Notifier* nf = Parent::notifier(); allocate_memory(); Item it; for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it);; - allocator.construct(&(values[id]), Value()); - } + int id = nf->id(it);; + allocator.construct(&(values[id]), Value()); + } } /// \brief Clear the map. /// /// It erase all items from the map. It called by the observer notifier - /// and it overrides the clear() member function of the observer base. - virtual void clear() { + /// and it overrides the clear() member function of the observer base. + virtual void clear() { Notifier* nf = Parent::notifier(); if (capacity != 0) { - Item it; - for (nf->first(it); it != INVALID; nf->next(it)) { - int id = nf->id(it); - allocator.destroy(&(values[id])); - } - allocator.deallocate(values, capacity); - capacity = 0; + Item it; + for (nf->first(it); it != INVALID; nf->next(it)) { + int id = nf->id(it); + allocator.destroy(&(values[id])); + } + allocator.deallocate(values, capacity); + capacity = 0; } } private: - + void allocate_memory() { int max_id = Parent::notifier()->maxId(); if (max_id == -1) { - capacity = 0; - values = 0; - return; + capacity = 0; + values = 0; + return; } capacity = 1; while (capacity <= max_id) { - capacity <<= 1; + capacity <<= 1; } - values = allocator.allocate(capacity); - } + values = allocator.allocate(capacity); + } int capacity; Value* values; Allocator allocator; - }; + }; } -#endif +#endif diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/base_extender.h --- a/lemon/bits/base_extender.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/base_extender.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -63,14 +63,14 @@ Arc(Invalid i) : Edge(i), forward(true) {} bool operator==(const Arc &that) const { - return forward==that.forward && Edge(*this)==Edge(that); + return forward==that.forward && Edge(*this)==Edge(that); } bool operator!=(const Arc &that) const { - return forward!=that.forward || Edge(*this)!=Edge(that); + return forward!=that.forward || Edge(*this)!=Edge(that); } bool operator<(const Arc &that) const { - return forward(node)); } - + int id(const Blue& node) const { return Parent::redId(node); } @@ -367,19 +367,19 @@ void firstInc(Edge& arc, bool& dir, const Node& node) const { if (Parent::red(node)) { - Parent::firstFromRed(arc, node); - dir = true; + Parent::firstFromRed(arc, node); + dir = true; } else { - Parent::firstFromBlue(arc, node); - dir = static_cast(arc) == INVALID; + Parent::firstFromBlue(arc, node); + dir = static_cast(arc) == INVALID; } } void nextInc(Edge& arc, bool& dir) const { if (dir) { - Parent::nextFromRed(arc); + Parent::nextFromRed(arc); } else { - Parent::nextFromBlue(arc); - if (arc == INVALID) dir = true; + Parent::nextFromBlue(arc); + if (arc == INVALID) dir = true; } } @@ -389,20 +389,20 @@ bool forward; Arc(const Edge& arc, bool _forward) - : Edge(arc), forward(_forward) {} + : Edge(arc), forward(_forward) {} public: Arc() {} Arc (Invalid) : Edge(INVALID), forward(true) {} bool operator==(const Arc& i) const { - return Edge::operator==(i) && forward == i.forward; + return Edge::operator==(i) && forward == i.forward; } bool operator!=(const Arc& i) const { - return Edge::operator!=(i) || forward != i.forward; + return Edge::operator!=(i) || forward != i.forward; } bool operator<(const Arc& i) const { - return Edge::operator<(i) || - (!(i.forward(arc)); + Parent::next(static_cast(arc)); } arc.forward = !arc.forward; } void firstOut(Arc& arc, const Node& node) const { if (Parent::red(node)) { - Parent::firstFromRed(arc, node); - arc.forward = true; + Parent::firstFromRed(arc, node); + arc.forward = true; } else { - Parent::firstFromBlue(arc, node); - arc.forward = static_cast(arc) == INVALID; + Parent::firstFromBlue(arc, node); + arc.forward = static_cast(arc) == INVALID; } } void nextOut(Arc& arc) const { if (arc.forward) { - Parent::nextFromRed(arc); + Parent::nextFromRed(arc); } else { - Parent::nextFromBlue(arc); + Parent::nextFromBlue(arc); arc.forward = static_cast(arc) == INVALID; } } void firstIn(Arc& arc, const Node& node) const { if (Parent::blue(node)) { - Parent::firstFromBlue(arc, node); - arc.forward = true; + Parent::firstFromBlue(arc, node); + arc.forward = true; } else { - Parent::firstFromRed(arc, node); - arc.forward = static_cast(arc) == INVALID; + Parent::firstFromRed(arc, node); + arc.forward = static_cast(arc) == INVALID; } } void nextIn(Arc& arc) const { if (arc.forward) { - Parent::nextFromBlue(arc); + Parent::nextFromBlue(arc); } else { - Parent::nextFromRed(arc); - arc.forward = static_cast(arc) == INVALID; + Parent::nextFromRed(arc); + arc.forward = static_cast(arc) == INVALID; } } @@ -462,7 +462,7 @@ } int id(const Arc& arc) const { - return (Parent::id(static_cast(arc)) << 1) + + return (Parent::id(static_cast(arc)) << 1) + (arc.forward ? 0 : 1); } Arc arcFromId(int ix) const { diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/bezier.h --- a/lemon/bits/bezier.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/bezier.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -44,7 +44,7 @@ Bezier1() {} Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {} - + Point operator()(double t) const { // return conv(conv(p1,p2,t),conv(p2,p3,t),t); @@ -54,7 +54,7 @@ { return Bezier1(p1,conv(p1,p2,t)); } - + Bezier1 after(double t) const { return Bezier1(conv(p1,p2,t),p2); @@ -87,7 +87,7 @@ Point r(conv(p2,p3,t)); return Bezier2(p1,q,conv(q,r,t)); } - + Bezier2 after(double t) const { Point q(conv(p1,p2,t)); @@ -110,16 +110,16 @@ Bezier3() {} Bezier3(Point _p1, Point _p2, Point _p3, Point _p4) : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {} - Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), - p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} + Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), + p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)), - p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} - - Point operator()(double t) const + p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} + + Point operator()(double t) const { // return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t); return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+ - (3*t*t*(1-t))*p3+(t*t*t)*p4; + (3*t*t*(1-t))*p3+(t*t*t)*p4; } Bezier3 before(double t) const { @@ -131,7 +131,7 @@ Point c(conv(a,b,t)); return Bezier3(p1,p,a,c); } - + Bezier3 after(double t) const { Point p(conv(p1,p2,t)); @@ -146,13 +146,13 @@ Bezier3 operator()(double a,double b) const { return before(b).after(a/b); } Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); } Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1), - 3.0*rot90(p3-p2), - 3.0*rot90(p4-p3)); } + 3.0*rot90(p3-p2), + 3.0*rot90(p4-p3)); } Point grad(double t) const { return grad()(t); } Point norm(double t) const { return rot90(grad(t)); } template - R recSplit(F &_f,const S &_s,D _d) const + R recSplit(F &_f,const S &_s,D _d) const { const Point a=(p1+p2)/2; const Point b=(p2+p3)/2; @@ -164,7 +164,7 @@ R f2=_f(Bezier3(e,d,c,p4),_d); return _s(f1,f2); } - + }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/default_map.h --- a/lemon/bits/default_map.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/default_map.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -29,8 +29,8 @@ ///\brief Graph maps that construct and destruct their elements dynamically. namespace lemon { - - + + //#ifndef LEMON_USE_DEBUG_MAP template @@ -140,28 +140,28 @@ typedef VectorMap<_Graph, _Item, _Ptr*> Map; }; -// #else +// #else // template // struct DefaultMapSelector { // typedef DebugMap<_Graph, _Item, _Value> Map; // }; -// #endif +// #endif /// \e template - class DefaultMap + class DefaultMap : public DefaultMapSelector<_Graph, _Item, _Value>::Map { public: typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; typedef DefaultMap<_Graph, _Item, _Value> Map; - + typedef typename Parent::Graph Graph; typedef typename Parent::Value Value; explicit DefaultMap(const Graph& graph) : Parent(graph) {} - DefaultMap(const Graph& graph, const Value& value) + DefaultMap(const Graph& graph, const Value& value) : Parent(graph, value) {} DefaultMap& operator=(const DefaultMap& cmap) { diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/graph_extender.h --- a/lemon/bits/graph_extender.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/graph_extender.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -66,11 +66,11 @@ Node oppositeNode(const Node &node, const Arc &arc) const { if (node == Parent::source(arc)) - return Parent::target(arc); + return Parent::target(arc); else if(node == Parent::target(arc)) - return Parent::source(arc); + return Parent::source(arc); else - return INVALID; + return INVALID; } // Alterable extension @@ -89,12 +89,12 @@ NodeNotifier& notifier(Node) const { return node_notifier; } - + ArcNotifier& notifier(Arc) const { return arc_notifier; } - class NodeIt : public Node { + class NodeIt : public Node { const Digraph* _digraph; public: @@ -103,21 +103,21 @@ NodeIt(Invalid i) : Node(i) { } explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) { - _digraph->first(static_cast(*this)); + _digraph->first(static_cast(*this)); } - NodeIt(const Digraph& digraph, const Node& node) - : Node(node), _digraph(&digraph) {} + NodeIt(const Digraph& digraph, const Node& node) + : Node(node), _digraph(&digraph) {} - NodeIt& operator++() { - _digraph->next(*this); - return *this; + NodeIt& operator++() { + _digraph->next(*this); + return *this; } }; - class ArcIt : public Arc { + class ArcIt : public Arc { const Digraph* _digraph; public: @@ -126,21 +126,21 @@ ArcIt(Invalid i) : Arc(i) { } explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) { - _digraph->first(static_cast(*this)); + _digraph->first(static_cast(*this)); } - ArcIt(const Digraph& digraph, const Arc& arc) : - Arc(arc), _digraph(&digraph) { } + ArcIt(const Digraph& digraph, const Arc& arc) : + Arc(arc), _digraph(&digraph) { } - ArcIt& operator++() { - _digraph->next(*this); - return *this; + ArcIt& operator++() { + _digraph->next(*this); + return *this; } }; - class OutArcIt : public Arc { + class OutArcIt : public Arc { const Digraph* _digraph; public: @@ -148,23 +148,23 @@ OutArcIt(Invalid i) : Arc(i) { } - OutArcIt(const Digraph& digraph, const Node& node) - : _digraph(&digraph) { - _digraph->firstOut(*this, node); + OutArcIt(const Digraph& digraph, const Node& node) + : _digraph(&digraph) { + _digraph->firstOut(*this, node); } - OutArcIt(const Digraph& digraph, const Arc& arc) - : Arc(arc), _digraph(&digraph) {} + OutArcIt(const Digraph& digraph, const Arc& arc) + : Arc(arc), _digraph(&digraph) {} - OutArcIt& operator++() { - _digraph->nextOut(*this); - return *this; + OutArcIt& operator++() { + _digraph->nextOut(*this); + return *this; } }; - class InArcIt : public Arc { + class InArcIt : public Arc { const Digraph* _digraph; public: @@ -172,17 +172,17 @@ InArcIt(Invalid i) : Arc(i) { } - InArcIt(const Digraph& digraph, const Node& node) - : _digraph(&digraph) { - _digraph->firstIn(*this, node); + InArcIt(const Digraph& digraph, const Node& node) + : _digraph(&digraph) { + _digraph->firstIn(*this, node); } - InArcIt(const Digraph& digraph, const Arc& arc) : - Arc(arc), _digraph(&digraph) {} + InArcIt(const Digraph& digraph, const Arc& arc) : + Arc(arc), _digraph(&digraph) {} - InArcIt& operator++() { - _digraph->nextIn(*this); - return *this; + InArcIt& operator++() { + _digraph->nextIn(*this); + return *this; } }; @@ -215,51 +215,51 @@ return Parent::source(arc); } - + template - class NodeMap + class NodeMap : public MapExtender > { public: typedef DigraphExtender Digraph; typedef MapExtender > Parent; - explicit NodeMap(const Digraph& digraph) - : Parent(digraph) {} - NodeMap(const Digraph& digraph, const _Value& value) - : Parent(digraph, value) {} + explicit NodeMap(const Digraph& digraph) + : Parent(digraph) {} + NodeMap(const Digraph& digraph, const _Value& value) + : Parent(digraph, value) {} NodeMap& operator=(const NodeMap& cmap) { - return operator=(cmap); + return operator=(cmap); } template NodeMap& operator=(const CMap& cmap) { Parent::operator=(cmap); - return *this; + return *this; } }; template - class ArcMap + class ArcMap : public MapExtender > { public: typedef DigraphExtender Digraph; typedef MapExtender > Parent; - explicit ArcMap(const Digraph& digraph) - : Parent(digraph) {} - ArcMap(const Digraph& digraph, const _Value& value) - : Parent(digraph, value) {} + explicit ArcMap(const Digraph& digraph) + : Parent(digraph) {} + ArcMap(const Digraph& digraph, const _Value& value) + : Parent(digraph, value) {} ArcMap& operator=(const ArcMap& cmap) { - return operator=(cmap); + return operator=(cmap); } template ArcMap& operator=(const CMap& cmap) { Parent::operator=(cmap); - return *this; + return *this; } }; @@ -269,7 +269,7 @@ notifier(Node()).add(node); return node; } - + Arc addArc(const Node& from, const Node& to) { Arc arc = Parent::addArc(from, to); notifier(Arc()).add(arc); @@ -293,20 +293,20 @@ Arc arc; Parent::firstOut(arc, node); while (arc != INVALID ) { - erase(arc); - Parent::firstOut(arc, node); - } + erase(arc); + Parent::firstOut(arc, node); + } Parent::firstIn(arc, node); while (arc != INVALID ) { - erase(arc); - Parent::firstIn(arc, node); + erase(arc); + Parent::firstIn(arc, node); } notifier(Node()).erase(node); Parent::erase(node); } - + void erase(const Arc& arc) { notifier(Arc()).erase(arc); Parent::erase(arc); @@ -315,8 +315,8 @@ DigraphExtender() { node_notifier.setContainer(*this); arc_notifier.setContainer(*this); - } - + } + ~DigraphExtender() { arc_notifier.clear(); @@ -327,10 +327,10 @@ /// \ingroup _graphbits /// /// \brief Extender for the Graphs - template + template class GraphExtender : public Base { public: - + typedef Base Parent; typedef GraphExtender Graph; @@ -340,7 +340,7 @@ typedef typename Parent::Arc Arc; typedef typename Parent::Edge Edge; - // Graph extension + // Graph extension int maxId(Node) const { return Parent::maxNodeId(); @@ -368,11 +368,11 @@ Node oppositeNode(const Node &n, const Edge &e) const { if( n == Parent::u(e)) - return Parent::v(e); + return Parent::v(e); else if( n == Parent::v(e)) - return Parent::u(e); + return Parent::u(e); else - return INVALID; + return INVALID; } Arc oppositeArc(const Arc &arc) const { @@ -402,7 +402,7 @@ NodeNotifier& notifier(Node) const { return node_notifier; } - + ArcNotifier& notifier(Arc) const { return arc_notifier; } @@ -413,7 +413,7 @@ - class NodeIt : public Node { + class NodeIt : public Node { const Graph* _graph; public: @@ -422,21 +422,21 @@ NodeIt(Invalid i) : Node(i) { } explicit NodeIt(const Graph& graph) : _graph(&graph) { - _graph->first(static_cast(*this)); + _graph->first(static_cast(*this)); } - NodeIt(const Graph& graph, const Node& node) - : Node(node), _graph(&graph) {} + NodeIt(const Graph& graph, const Node& node) + : Node(node), _graph(&graph) {} - NodeIt& operator++() { - _graph->next(*this); - return *this; + NodeIt& operator++() { + _graph->next(*this); + return *this; } }; - class ArcIt : public Arc { + class ArcIt : public Arc { const Graph* _graph; public: @@ -445,21 +445,21 @@ ArcIt(Invalid i) : Arc(i) { } explicit ArcIt(const Graph& graph) : _graph(&graph) { - _graph->first(static_cast(*this)); + _graph->first(static_cast(*this)); } - ArcIt(const Graph& graph, const Arc& arc) : - Arc(arc), _graph(&graph) { } + ArcIt(const Graph& graph, const Arc& arc) : + Arc(arc), _graph(&graph) { } - ArcIt& operator++() { - _graph->next(*this); - return *this; + ArcIt& operator++() { + _graph->next(*this); + return *this; } }; - class OutArcIt : public Arc { + class OutArcIt : public Arc { const Graph* _graph; public: @@ -467,23 +467,23 @@ OutArcIt(Invalid i) : Arc(i) { } - OutArcIt(const Graph& graph, const Node& node) - : _graph(&graph) { - _graph->firstOut(*this, node); + OutArcIt(const Graph& graph, const Node& node) + : _graph(&graph) { + _graph->firstOut(*this, node); } - OutArcIt(const Graph& graph, const Arc& arc) - : Arc(arc), _graph(&graph) {} + OutArcIt(const Graph& graph, const Arc& arc) + : Arc(arc), _graph(&graph) {} - OutArcIt& operator++() { - _graph->nextOut(*this); - return *this; + OutArcIt& operator++() { + _graph->nextOut(*this); + return *this; } }; - class InArcIt : public Arc { + class InArcIt : public Arc { const Graph* _graph; public: @@ -491,23 +491,23 @@ InArcIt(Invalid i) : Arc(i) { } - InArcIt(const Graph& graph, const Node& node) - : _graph(&graph) { - _graph->firstIn(*this, node); + InArcIt(const Graph& graph, const Node& node) + : _graph(&graph) { + _graph->firstIn(*this, node); } - InArcIt(const Graph& graph, const Arc& arc) : - Arc(arc), _graph(&graph) {} + InArcIt(const Graph& graph, const Arc& arc) : + Arc(arc), _graph(&graph) {} - InArcIt& operator++() { - _graph->nextIn(*this); - return *this; + InArcIt& operator++() { + _graph->nextIn(*this); + return *this; } }; - class EdgeIt : public Parent::Edge { + class EdgeIt : public Parent::Edge { const Graph* _graph; public: @@ -516,15 +516,15 @@ EdgeIt(Invalid i) : Edge(i) { } explicit EdgeIt(const Graph& graph) : _graph(&graph) { - _graph->first(static_cast(*this)); + _graph->first(static_cast(*this)); } - EdgeIt(const Graph& graph, const Edge& edge) : - Edge(edge), _graph(&graph) { } + EdgeIt(const Graph& graph, const Edge& edge) : + Edge(edge), _graph(&graph) { } - EdgeIt& operator++() { - _graph->next(*this); - return *this; + EdgeIt& operator++() { + _graph->next(*this); + return *this; } }; @@ -540,17 +540,17 @@ IncEdgeIt(Invalid i) : Edge(i), _direction(false) { } IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { - _graph->firstInc(*this, _direction, node); + _graph->firstInc(*this, _direction, node); } IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) - : _graph(&graph), Edge(edge) { - _direction = (_graph->source(edge) == node); + : _graph(&graph), Edge(edge) { + _direction = (_graph->source(edge) == node); } IncEdgeIt& operator++() { - _graph->nextInc(*this, _direction); - return *this; + _graph->nextInc(*this, _direction); + return *this; } }; @@ -598,74 +598,74 @@ // Mappable extension template - class NodeMap + class NodeMap : public MapExtender > { public: typedef GraphExtender Graph; typedef MapExtender > Parent; - NodeMap(const Graph& graph) - : Parent(graph) {} - NodeMap(const Graph& graph, const _Value& value) - : Parent(graph, value) {} + NodeMap(const Graph& graph) + : Parent(graph) {} + NodeMap(const Graph& graph, const _Value& value) + : Parent(graph, value) {} NodeMap& operator=(const NodeMap& cmap) { - return operator=(cmap); + return operator=(cmap); } template NodeMap& operator=(const CMap& cmap) { Parent::operator=(cmap); - return *this; + return *this; } }; template - class ArcMap + class ArcMap : public MapExtender > { public: typedef GraphExtender Graph; typedef MapExtender > Parent; - ArcMap(const Graph& graph) - : Parent(graph) {} - ArcMap(const Graph& graph, const _Value& value) - : Parent(graph, value) {} + ArcMap(const Graph& graph) + : Parent(graph) {} + ArcMap(const Graph& graph, const _Value& value) + : Parent(graph, value) {} ArcMap& operator=(const ArcMap& cmap) { - return operator=(cmap); + return operator=(cmap); } template ArcMap& operator=(const CMap& cmap) { Parent::operator=(cmap); - return *this; + return *this; } }; template - class EdgeMap + class EdgeMap : public MapExtender > { public: typedef GraphExtender Graph; typedef MapExtender > Parent; - EdgeMap(const Graph& graph) - : Parent(graph) {} + EdgeMap(const Graph& graph) + : Parent(graph) {} - EdgeMap(const Graph& graph, const _Value& value) - : Parent(graph, value) {} + EdgeMap(const Graph& graph, const _Value& value) + : Parent(graph, value) {} EdgeMap& operator=(const EdgeMap& cmap) { - return operator=(cmap); + return operator=(cmap); } template EdgeMap& operator=(const CMap& cmap) { Parent::operator=(cmap); - return *this; + return *this; } }; @@ -683,11 +683,11 @@ notifier(Edge()).add(edge); std::vector ev; ev.push_back(Parent::direct(edge, true)); - ev.push_back(Parent::direct(edge, false)); + ev.push_back(Parent::direct(edge, false)); notifier(Arc()).add(ev); return edge; } - + void clear() { notifier(Arc()).clear(); notifier(Edge()).clear(); @@ -696,7 +696,7 @@ } template - void build(const Graph& graph, NodeRefMap& nodeRef, + void build(const Graph& graph, NodeRefMap& nodeRef, EdgeRefMap& edgeRef) { Parent::build(graph, nodeRef, edgeRef); notifier(Node()).build(); @@ -708,14 +708,14 @@ Arc arc; Parent::firstOut(arc, node); while (arc != INVALID ) { - erase(arc); - Parent::firstOut(arc, node); - } + erase(arc); + Parent::firstOut(arc, node); + } Parent::firstIn(arc, node); while (arc != INVALID ) { - erase(arc); - Parent::firstIn(arc, node); + erase(arc); + Parent::firstIn(arc, node); } notifier(Node()).erase(node); @@ -725,23 +725,23 @@ void erase(const Edge& edge) { std::vector av; av.push_back(Parent::direct(edge, true)); - av.push_back(Parent::direct(edge, false)); + av.push_back(Parent::direct(edge, false)); notifier(Arc()).erase(av); notifier(Edge()).erase(edge); Parent::erase(edge); } GraphExtender() { - node_notifier.setContainer(*this); + node_notifier.setContainer(*this); arc_notifier.setContainer(*this); edge_notifier.setContainer(*this); - } + } ~GraphExtender() { edge_notifier.clear(); arc_notifier.clear(); - node_notifier.clear(); - } + node_notifier.clear(); + } }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/invalid.h --- a/lemon/bits/invalid.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/invalid.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -34,7 +34,7 @@ bool operator!=(Invalid) { return false; } bool operator< (Invalid) { return false; } }; - + /// \brief Invalid iterators. /// /// \ref Invalid is a global type that converts to each iterator @@ -52,4 +52,4 @@ } //namespace lemon #endif - + diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/map_extender.h --- a/lemon/bits/map_extender.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/map_extender.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -32,7 +32,7 @@ namespace lemon { /// \ingroup graphbits - /// + /// /// \brief Extender for maps template class MapExtender : public _Map { @@ -56,10 +56,10 @@ public: - MapExtender(const Graph& graph) + MapExtender(const Graph& graph) : Parent(graph) {} - MapExtender(const Graph& graph, const Value& value) + MapExtender(const Graph& graph, const Value& value) : Parent(graph, value) {} MapExtender& operator=(const MapExtender& cmap) { @@ -70,14 +70,14 @@ MapExtender& operator=(const CMap& cmap) { Parent::operator=(cmap); return *this; - } + } class MapIt : public Item { public: - + typedef Item Parent; typedef typename Map::Value Value; - + MapIt() {} MapIt(Invalid i) : Parent(i) { } @@ -86,29 +86,29 @@ map.notifier()->first(*this); } - MapIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + MapIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - MapIt& operator++() { - map.notifier()->next(*this); - return *this; + MapIt& operator++() { + map.notifier()->next(*this); + return *this; } - + typename MapTraits::ConstReturnValue operator*() const { - return map[*this]; + return map[*this]; } typename MapTraits::ReturnValue operator*() { - return map[*this]; + return map[*this]; } - + void set(const Value& value) { - map.set(*this, value); + map.set(*this, value); } - + protected: Map& map; - + }; class ConstMapIt : public Item { @@ -117,7 +117,7 @@ typedef Item Parent; typedef typename Map::Value Value; - + ConstMapIt() {} ConstMapIt(Invalid i) : Parent(i) { } @@ -126,16 +126,16 @@ map.notifier()->first(*this); } - ConstMapIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + ConstMapIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - ConstMapIt& operator++() { - map.notifier()->next(*this); - return *this; + ConstMapIt& operator++() { + map.notifier()->next(*this); + return *this; } typename MapTraits::ConstReturnValue operator*() const { - return map[*this]; + return map[*this]; } protected: @@ -144,9 +144,9 @@ class ItemIt : public Item { public: - + typedef Item Parent; - + ItemIt() {} ItemIt(Invalid i) : Parent(i) { } @@ -155,22 +155,22 @@ map.notifier()->first(*this); } - ItemIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + ItemIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - ItemIt& operator++() { - map.notifier()->next(*this); - return *this; + ItemIt& operator++() { + map.notifier()->next(*this); + return *this; } protected: const Map& map; - + }; }; /// \ingroup graphbits - /// + /// /// \brief Extender for maps which use a subset of the items. template class SubMapExtender : public _Map { @@ -194,10 +194,10 @@ public: - SubMapExtender(const Graph& _graph) + SubMapExtender(const Graph& _graph) : Parent(_graph), graph(_graph) {} - SubMapExtender(const Graph& _graph, const Value& _value) + SubMapExtender(const Graph& _graph, const Value& _value) : Parent(_graph, _value), graph(_graph) {} SubMapExtender& operator=(const SubMapExtender& cmap) { @@ -212,14 +212,14 @@ Parent::set(it, cmap[it]); } return *this; - } + } class MapIt : public Item { public: - + typedef Item Parent; typedef typename Map::Value Value; - + MapIt() {} MapIt(Invalid i) : Parent(i) { } @@ -228,29 +228,29 @@ map.graph.first(*this); } - MapIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + MapIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - MapIt& operator++() { - map.graph.next(*this); - return *this; + MapIt& operator++() { + map.graph.next(*this); + return *this; } - + typename MapTraits::ConstReturnValue operator*() const { - return map[*this]; + return map[*this]; } typename MapTraits::ReturnValue operator*() { - return map[*this]; + return map[*this]; } - + void set(const Value& value) { - map.set(*this, value); + map.set(*this, value); } - + protected: Map& map; - + }; class ConstMapIt : public Item { @@ -259,7 +259,7 @@ typedef Item Parent; typedef typename Map::Value Value; - + ConstMapIt() {} ConstMapIt(Invalid i) : Parent(i) { } @@ -268,16 +268,16 @@ map.graph.first(*this); } - ConstMapIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + ConstMapIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - ConstMapIt& operator++() { - map.graph.next(*this); - return *this; + ConstMapIt& operator++() { + map.graph.next(*this); + return *this; } typename MapTraits::ConstReturnValue operator*() const { - return map[*this]; + return map[*this]; } protected: @@ -286,9 +286,9 @@ class ItemIt : public Item { public: - + typedef Item Parent; - + ItemIt() {} ItemIt(Invalid i) : Parent(i) { } @@ -297,23 +297,23 @@ map.graph.first(*this); } - ItemIt(const Map& _map, const Item& item) - : Parent(item), map(_map) {} + ItemIt(const Map& _map, const Item& item) + : Parent(item), map(_map) {} - ItemIt& operator++() { - map.graph.next(*this); - return *this; + ItemIt& operator++() { + map.graph.next(*this); + return *this; } protected: const Map& map; - + }; - + private: const Graph& graph; - + }; } diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/path_dump.h --- a/lemon/bits/path_dump.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/path_dump.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -53,7 +53,7 @@ public: RevArcIt() {} RevArcIt(Invalid) : path(0), current(INVALID) {} - RevArcIt(const PredMapPath& _path) + RevArcIt(const PredMapPath& _path) : path(&_path), current(_path.target) { if (path->predMap[current] == INVALID) current = INVALID; } @@ -68,18 +68,18 @@ return *this; } - bool operator==(const RevArcIt& e) const { - return current == e.current; + bool operator==(const RevArcIt& e) const { + return current == e.current; } bool operator!=(const RevArcIt& e) const { - return current != e.current; + return current != e.current; } - bool operator<(const RevArcIt& e) const { - return current < e.current; + bool operator<(const RevArcIt& e) const { + return current < e.current; } - + private: const PredMapPath* path; typename Digraph::Node current; @@ -101,11 +101,11 @@ typedef typename Digraph::Arc Arc; typedef _PredMatrixMap PredMatrixMap; - PredMatrixMapPath(const Digraph& _digraph, + PredMatrixMapPath(const Digraph& _digraph, const PredMatrixMap& _predMatrixMap, - typename Digraph::Node _source, + typename Digraph::Node _source, typename Digraph::Node _target) - : digraph(_digraph), predMatrixMap(_predMatrixMap), + : digraph(_digraph), predMatrixMap(_predMatrixMap), source(_source), target(_target) {} int length() const { @@ -127,9 +127,9 @@ public: RevArcIt() {} RevArcIt(Invalid) : path(0), current(INVALID) {} - RevArcIt(const PredMatrixMapPath& _path) + RevArcIt(const PredMatrixMapPath& _path) : path(&_path), current(_path.target) { - if (path->predMatrixMap(path->source, current) == INVALID) + if (path->predMatrixMap(path->source, current) == INVALID) current = INVALID; } @@ -138,25 +138,25 @@ } RevArcIt& operator++() { - current = + current = path->digraph.source(path->predMatrixMap(path->source, current)); - if (path->predMatrixMap(path->source, current) == INVALID) + if (path->predMatrixMap(path->source, current) == INVALID) current = INVALID; return *this; } - bool operator==(const RevArcIt& e) const { - return current == e.current; + bool operator==(const RevArcIt& e) const { + return current == e.current; } bool operator!=(const RevArcIt& e) const { - return current != e.current; + return current != e.current; } - bool operator<(const RevArcIt& e) const { - return current < e.current; + bool operator<(const RevArcIt& e) const { + return current < e.current; } - + private: const PredMatrixMapPath* path; typename Digraph::Node current; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/traits.h --- a/lemon/bits/traits.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/traits.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,7 +1,6 @@ - -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -29,7 +28,7 @@ namespace lemon { template class ItemSetTraits {}; - + template struct NodeNotifierIndicator { @@ -37,16 +36,16 @@ }; template struct NodeNotifierIndicator< - Graph, + Graph, typename enable_if::type - > { + > { typedef typename Graph::NodeNotifier Type; }; template class ItemSetTraits<_Graph, typename _Graph::Node> { public: - + typedef _Graph Graph; typedef typename Graph::Node Item; @@ -57,13 +56,13 @@ template class Map : public Graph::template NodeMap<_Value> { public: - typedef typename Graph::template NodeMap<_Value> Parent; - typedef typename Graph::template NodeMap<_Value> Type; + typedef typename Graph::template NodeMap<_Value> Parent; + typedef typename Graph::template NodeMap<_Value> Type; typedef typename Parent::Value Value; Map(const Graph& _digraph) : Parent(_digraph) {} - Map(const Graph& _digraph, const Value& _value) - : Parent(_digraph, _value) {} + Map(const Graph& _digraph, const Value& _value) + : Parent(_digraph, _value) {} }; @@ -75,16 +74,16 @@ }; template struct ArcNotifierIndicator< - Graph, + Graph, typename enable_if::type - > { + > { typedef typename Graph::ArcNotifier Type; }; template class ItemSetTraits<_Graph, typename _Graph::Arc> { public: - + typedef _Graph Graph; typedef typename Graph::Arc Item; @@ -95,13 +94,13 @@ template class Map : public Graph::template ArcMap<_Value> { public: - typedef typename Graph::template ArcMap<_Value> Parent; - typedef typename Graph::template ArcMap<_Value> Type; + typedef typename Graph::template ArcMap<_Value> Parent; + typedef typename Graph::template ArcMap<_Value> Type; typedef typename Parent::Value Value; Map(const Graph& _digraph) : Parent(_digraph) {} - Map(const Graph& _digraph, const Value& _value) - : Parent(_digraph, _value) {} + Map(const Graph& _digraph, const Value& _value) + : Parent(_digraph, _value) {} }; }; @@ -112,16 +111,16 @@ }; template struct EdgeNotifierIndicator< - Graph, + Graph, typename enable_if::type - > { + > { typedef typename Graph::EdgeNotifier Type; }; template class ItemSetTraits<_Graph, typename _Graph::Edge> { public: - + typedef _Graph Graph; typedef typename Graph::Edge Item; @@ -132,13 +131,13 @@ template class Map : public Graph::template EdgeMap<_Value> { public: - typedef typename Graph::template EdgeMap<_Value> Parent; - typedef typename Graph::template EdgeMap<_Value> Type; + typedef typename Graph::template EdgeMap<_Value> Parent; + typedef typename Graph::template EdgeMap<_Value> Type; typedef typename Parent::Value Value; Map(const Graph& _digraph) : Parent(_digraph) {} - Map(const Graph& _digraph, const Value& _value) - : Parent(_digraph, _value) {} + Map(const Graph& _digraph, const Value& _value) + : Parent(_digraph, _value) {} }; }; @@ -156,17 +155,17 @@ template struct MapTraits< - Map, typename enable_if::type > + Map, typename enable_if::type > { typedef True ReferenceMapTag; - + typedef typename Map::Key Key; typedef typename Map::Value Value; typedef typename Map::ConstReference ConstReturnValue; typedef typename Map::Reference ReturnValue; - typedef typename Map::ConstReference ConstReference; + typedef typename Map::ConstReference ConstReference; typedef typename Map::Reference Reference; }; @@ -184,11 +183,11 @@ template struct MatrixMapTraits< - MatrixMap, typename enable_if::type > + MatrixMap, typename enable_if::type > { typedef True ReferenceMapTag; - + typedef typename MatrixMap::FirstKey FirstKey; typedef typename MatrixMap::SecondKey SecondKey; typedef typename MatrixMap::Value Value; @@ -196,7 +195,7 @@ typedef typename MatrixMap::ConstReference ConstReturnValue; typedef typename MatrixMap::Reference ReturnValue; - typedef typename MatrixMap::ConstReference ConstReference; + typedef typename MatrixMap::ConstReference ConstReference; typedef typename MatrixMap::Reference Reference; }; @@ -209,7 +208,7 @@ template struct NodeNumTagIndicator< - Graph, + Graph, typename enable_if::type > { static const bool value = true; @@ -222,7 +221,7 @@ template struct EdgeNumTagIndicator< - Graph, + Graph, typename enable_if::type > { static const bool value = true; @@ -235,7 +234,7 @@ template struct FindEdgeTagIndicator< - Graph, + Graph, typename enable_if::type > { static const bool value = true; @@ -248,7 +247,7 @@ template struct UndirectedTagIndicator< - Graph, + Graph, typename enable_if::type > { static const bool value = true; @@ -261,7 +260,7 @@ template struct BuildTagIndicator< - Graph, + Graph, typename enable_if::type > { static const bool value = true; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/utility.h --- a/lemon/bits/utility.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/utility.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -83,13 +83,13 @@ template struct dummy { dummy(int) {} }; /**************** enable_if from BOOST ****************/ - + template struct exists { typedef T type; }; - + template struct enable_if_c { typedef T type; @@ -98,7 +98,7 @@ template struct enable_if_c {}; - template + template struct enable_if : public enable_if_c {}; template @@ -109,7 +109,7 @@ template struct lazy_enable_if_c {}; - template + template struct lazy_enable_if : public lazy_enable_if_c {}; @@ -121,7 +121,7 @@ template struct disable_if_c {}; - template + template struct disable_if : public disable_if_c {}; template @@ -132,7 +132,7 @@ template struct lazy_disable_if_c {}; - template + template struct lazy_disable_if : public lazy_disable_if_c {}; } // namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/bits/vector_map.h --- a/lemon/bits/vector_map.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/bits/vector_map.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -49,16 +49,16 @@ /// \tparam _Value The value type of the map. /// \todo Fix the doc: there is _Graph parameter instead of _Notifier. template - class VectorMap + class VectorMap : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { private: - + /// The container type of the map. - typedef std::vector<_Value> Container; + typedef std::vector<_Value> Container; public: - /// The graph type of the map. + /// The graph type of the map. typedef _Graph Graph; /// The item type of the map. typedef _Item Item; @@ -93,9 +93,9 @@ container.resize(Parent::notifier()->maxId() + 1); } - /// \brief Constructor uses given value to initialize the map. + /// \brief Constructor uses given value to initialize the map. /// - /// It constructs a map uses a given value to initialize the map. + /// It constructs a map uses a given value to initialize the map. /// It adds all the items of the graph to the map. VectorMap(const Graph& graph, const Value& value) { Parent::attach(graph.notifier(Item())); @@ -107,18 +107,18 @@ /// Copy constructor. VectorMap(const VectorMap& _copy) : Parent() { if (_copy.attached()) { - Parent::attach(*_copy.notifier()); - container = _copy.container; + Parent::attach(*_copy.notifier()); + container = _copy.container; } } /// \brief Assign operator. /// /// This operator assigns for each item in the map the - /// value mapped to the same item in the copied map. + /// value mapped to the same item in the copied map. /// The parameter map should be indiced with the same /// itemset because this assign operator does not change - /// the container of the map. + /// the container of the map. VectorMap& operator=(const VectorMap& cmap) { return operator=(cmap); } @@ -129,7 +129,7 @@ /// The given parameter should be conform to the ReadMap /// concecpt and could be indiced by the current item set of /// the NodeMap. In this case the value for each item - /// is assigned by the value of the given ReadMap. + /// is assigned by the value of the given ReadMap. template VectorMap& operator=(const CMap& cmap) { checkConcept, CMap>(); @@ -140,21 +140,21 @@ } return *this; } - + public: /// \brief The subcript operator. /// /// The subscript operator. The map can be subscripted by the - /// actual items of the graph. + /// actual items of the graph. Reference operator[](const Key& key) { return container[Parent::notifier()->id(key)]; - } - + } + /// \brief The const subcript operator. /// /// The const subscript operator. The map can be subscripted by the - /// actual items of the graph. + /// actual items of the graph. ConstReference operator[](const Key& key) const { return container[Parent::notifier()->id(key)]; } @@ -170,20 +170,20 @@ protected: /// \brief Adds a new key to the map. - /// + /// /// It adds a new key to the map. It called by the observer notifier - /// and it overrides the add() member function of the observer base. + /// and it overrides the add() member function of the observer base. virtual void add(const Key& key) { int id = Parent::notifier()->id(key); if (id >= int(container.size())) { - container.resize(id + 1); + container.resize(id + 1); } } /// \brief Adds more new keys to the map. - /// + /// /// It adds more new keys to the map. It called by the observer notifier - /// and it overrides the add() member function of the observer base. + /// and it overrides the add() member function of the observer base. virtual void add(const std::vector& keys) { int max = container.size() - 1; for (int i = 0; i < int(keys.size()); ++i) { @@ -198,7 +198,7 @@ /// \brief Erase a key from the map. /// /// Erase a key from the map. It called by the observer notifier - /// and it overrides the erase() member function of the observer base. + /// and it overrides the erase() member function of the observer base. virtual void erase(const Key& key) { container[Parent::notifier()->id(key)] = Value(); } @@ -206,18 +206,18 @@ /// \brief Erase more keys from the map. /// /// Erase more keys from the map. It called by the observer notifier - /// and it overrides the erase() member function of the observer base. + /// and it overrides the erase() member function of the observer base. virtual void erase(const std::vector& keys) { for (int i = 0; i < int(keys.size()); ++i) { - container[Parent::notifier()->id(keys[i])] = Value(); + container[Parent::notifier()->id(keys[i])] = Value(); } } - + /// \brief Buildes the map. - /// + /// /// It buildes the map. It called by the observer notifier /// and it overrides the build() member function of the observer base. - virtual void build() { + virtual void build() { int size = Parent::notifier()->maxId() + 1; container.reserve(size); container.resize(size); @@ -226,13 +226,13 @@ /// \brief Clear the map. /// /// It erase all items from the map. It called by the observer notifier - /// and it overrides the clear() member function of the observer base. - virtual void clear() { + /// and it overrides the clear() member function of the observer base. + virtual void clear() { container.clear(); } - + private: - + Container container; }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/color.cc --- a/lemon/color.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/color.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -24,7 +24,7 @@ namespace lemon { const Color WHITE(1,1,1); - + const Color BLACK(0,0,0); const Color RED(1,0,0); const Color GREEN(0,1,0); @@ -40,5 +40,5 @@ const Color DARK_YELLOW(.5,.5,0); const Color DARK_MAGENTA(.5,0,.5); const Color DARK_CYAN(0,.5,.5); - + } //namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/color.h --- a/lemon/color.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/color.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -62,7 +62,7 @@ }; /// White color constant - extern const Color WHITE; + extern const Color WHITE; /// Black color constant extern const Color BLACK; /// Red color constant @@ -130,14 +130,14 @@ colors.push_back(Color(1,1,0)); colors.push_back(Color(1,0,1)); colors.push_back(Color(0,1,1)); - + colors.push_back(Color(.5,0,0)); colors.push_back(Color(0,.5,0)); colors.push_back(Color(0,0,.5)); colors.push_back(Color(.5,.5,0)); colors.push_back(Color(.5,0,.5)); colors.push_back(Color(0,.5,.5)); - + colors.push_back(Color(.5,.5,.5)); colors.push_back(Color(1,.5,.5)); colors.push_back(Color(.5,1,.5)); @@ -145,7 +145,7 @@ colors.push_back(Color(1,1,.5)); colors.push_back(Color(1,.5,1)); colors.push_back(Color(.5,1,1)); - + colors.push_back(Color(1,.5,0)); colors.push_back(Color(.5,1,0)); colors.push_back(Color(1,0,.5)); @@ -171,7 +171,7 @@ colors[i%colors.size()]=c; } ///Adds a new color to the end of the color list. - void add(const Color &c) + void add(const Color &c) { colors.push_back(c); } @@ -186,7 +186,7 @@ ///Returns a \ref Color which is as different from the given parameter ///as it is possible. - inline Color distantColor(const Color &c) + inline Color distantColor(const Color &c) { return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0); } diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concept_check.h --- a/lemon/concept_check.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concept_check.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -36,7 +36,7 @@ ///\file ///\brief Basic utilities for concept checking. /// -///\todo Are we still using BOOST concept checking utility? +///\todo Are we still using BOOST concept checking utility? ///Is the BOOST copyright notice necessary? #ifndef LEMON_CONCEPT_CHECK_H diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/digraph.h --- a/lemon/concepts/digraph.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/digraph.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -46,13 +46,13 @@ class Digraph { private: ///Digraphs are \e not copy constructible. Use DigraphCopy() instead. - + ///Digraphs are \e not copy constructible. Use DigraphCopy() instead. /// Digraph(const Digraph &) {}; ///\brief Assignment of \ref Digraph "Digraph"s to another ones are ///\e not allowed. Use DigraphCopy() instead. - + ///Assignment of \ref Digraph "Digraph"s to another ones are ///\e not allowed. Use DigraphCopy() instead. @@ -95,23 +95,23 @@ bool operator==(Node) const { return true; } /// Inequality operator - + /// \sa operator==(Node n) /// bool operator!=(Node) const { return true; } - /// Artificial ordering operator. - - /// To allow the use of digraph descriptors as key type in std::map or - /// similar associative container we require this. - /// - /// \note This operator only have to define some strict ordering of - /// the items; this order has nothing to do with the iteration - /// ordering of the items. - bool operator<(Node) const { return false; } + /// Artificial ordering operator. + + /// To allow the use of digraph descriptors as key type in std::map or + /// similar associative container we require this. + /// + /// \note This operator only have to define some strict ordering of + /// the items; this order has nothing to do with the iteration + /// ordering of the items. + bool operator<(Node) const { return false; } }; - + /// This iterator goes through each node. /// This iterator goes through each node. @@ -129,7 +129,7 @@ /// to an undefined value. NodeIt() { } /// Copy constructor. - + /// Copy constructor. /// NodeIt(const NodeIt& n) : Node(n) { } @@ -145,9 +145,9 @@ NodeIt(const Digraph&) { } /// Node -> NodeIt conversion. - /// Sets the iterator to the node of \c the digraph pointed by - /// the trivial iterator. - /// This feature necessitates that each time we + /// Sets the iterator to the node of \c the digraph pointed by + /// the trivial iterator. + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. NodeIt(const Digraph&, const Node&) { } /// Next node. @@ -156,8 +156,8 @@ /// NodeIt& operator++() { return *this; } }; - - + + /// Class for identifying an arc of the digraph /// This class identifies an arc of the digraph. It also serves @@ -191,17 +191,17 @@ /// bool operator!=(Arc) const { return true; } - /// Artificial ordering operator. - - /// To allow the use of digraph descriptors as key type in std::map or - /// similar associative container we require this. - /// - /// \note This operator only have to define some strict ordering of - /// the items; this order has nothing to do with the iteration - /// ordering of the items. - bool operator<(Arc) const { return false; } + /// Artificial ordering operator. + + /// To allow the use of digraph descriptors as key type in std::map or + /// similar associative container we require this. + /// + /// \note This operator only have to define some strict ordering of + /// the items; this order has nothing to do with the iteration + /// ordering of the items. + bool operator<(Arc) const { return false; } }; - + /// This iterator goes trough the outgoing arcs of a node. /// This iterator goes trough the \e outgoing arcs of a certain node @@ -213,7 +213,7 @@ /// int count=0; /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; ///\endcode - + class OutArcIt : public Arc { public: /// Default constructor @@ -232,19 +232,19 @@ /// OutArcIt(Invalid) { } /// This constructor sets the iterator to the first outgoing arc. - + /// This constructor sets the iterator to the first outgoing arc of /// the node. OutArcIt(const Digraph&, const Node&) { } /// Arc -> OutArcIt conversion /// Sets the iterator to the value of the trivial iterator. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. OutArcIt(const Digraph&, const Arc&) { } ///Next outgoing arc - - /// Assign the iterator to the next + + /// Assign the iterator to the next /// outgoing arc of the corresponding node. OutArcIt& operator++() { return *this; } }; @@ -279,14 +279,14 @@ /// InArcIt(Invalid) { } /// This constructor sets the iterator to first incoming arc. - + /// This constructor set the iterator to the first incoming arc of /// the node. InArcIt(const Digraph&, const Node&) { } /// Arc -> InArcIt conversion /// Sets the iterator to the value of the trivial iterator \c e. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. InArcIt(const Digraph&, const Arc&) { } /// Next incoming arc @@ -322,18 +322,18 @@ /// ArcIt(Invalid) { } /// This constructor sets the iterator to the first arc. - + /// This constructor sets the iterator to the first arc of \c g. ///@param g the digraph ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } /// Arc -> ArcIt conversion /// Sets the iterator to the value of the trivial iterator \c e. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. - ArcIt(const Digraph&, const Arc&) { } + ArcIt(const Digraph&, const Arc&) { } ///Next arc - + /// Assign the iterator to the next arc. ArcIt& operator++() { return *this; } }; @@ -349,26 +349,26 @@ Node source(Arc) const { return INVALID; } /// \brief Returns the ID of the node. - int id(Node) const { return -1; } + int id(Node) const { return -1; } /// \brief Returns the ID of the arc. - int id(Arc) const { return -1; } + int id(Arc) const { return -1; } /// \brief Returns the node with the given ID. /// /// \pre The argument should be a valid node ID in the graph. - Node nodeFromId(int) const { return INVALID; } + Node nodeFromId(int) const { return INVALID; } /// \brief Returns the arc with the given ID. /// /// \pre The argument should be a valid arc ID in the graph. - Arc arcFromId(int) const { return INVALID; } + Arc arcFromId(int) const { return INVALID; } /// \brief Returns an upper bound on the node IDs. - int maxNodeId() const { return -1; } + int maxNodeId() const { return -1; } /// \brief Returns an upper bound on the arc IDs. - int maxArcId() const { return -1; } + int maxArcId() const { return -1; } void first(Node&) const {} void next(Node&) const {} @@ -389,9 +389,9 @@ Arc fromId(int, Arc) const { return INVALID; } // Dummy parameter. - int maxId(Node) const { return -1; } + int maxId(Node) const { return -1; } // Dummy parameter. - int maxId(Arc) const { return -1; } + int maxId(Arc) const { return -1; } /// \brief The base node of the iterator. /// @@ -423,10 +423,10 @@ Node oppositeNode(const Node&, const Arc&) const { return INVALID; } /// \brief Read write map of the nodes to type \c T. - /// + /// /// ReadWrite map of the nodes to type \c T. /// \sa Reference - template + template class NodeMap : public ReadWriteMap< Node, T > { public: @@ -439,9 +439,9 @@ NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } ///Assignment operator template - NodeMap& operator=(const CMap&) { + NodeMap& operator=(const CMap&) { checkConcept, CMap>(); - return *this; + return *this; } }; @@ -449,7 +449,7 @@ /// /// Reference map of the arcs to type \c T. /// \sa Reference - template + template class ArcMap : public ReadWriteMap { public: @@ -461,9 +461,9 @@ ArcMap(const ArcMap& em) : ReadWriteMap(em) { } ///Assignment operator template - ArcMap& operator=(const CMap&) { + ArcMap& operator=(const CMap&) { checkConcept, CMap>(); - return *this; + return *this; } }; @@ -471,14 +471,14 @@ struct Constraints { void constraints() { checkConcept, _Digraph>(); - checkConcept, _Digraph>(); + checkConcept, _Digraph>(); checkConcept, _Digraph>(); } }; }; - - } //namespace concepts + + } //namespace concepts } //namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/graph.h --- a/lemon/concepts/graph.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/graph.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -65,23 +65,23 @@ /// OutArcIt iterates on the same edges but with opposite /// direction. The IncEdgeIt iterates also on the same edges /// as the OutArcIt and InArcIt but it is not convertible to Arc just - /// to Edge. + /// to Edge. class Graph { public: /// \brief The undirected graph should be tagged by the /// UndirectedTag. /// /// The undirected graph should be tagged by the UndirectedTag. This - /// tag helps the enable_if technics to make compile time - /// specializations for undirected graphs. + /// tag helps the enable_if technics to make compile time + /// specializations for undirected graphs. typedef True UndirectedTag; - /// \brief The base type of node iterators, + /// \brief The base type of node iterators, /// or in other words, the trivial node iterator. /// /// This is the base type of each node iterator, /// thus each kind of node iterator converts to this. - /// More precisely each kind of node iterator should be inherited + /// More precisely each kind of node iterator should be inherited /// from the trivial node iterator. class Node { public: @@ -108,23 +108,23 @@ bool operator==(Node) const { return true; } /// Inequality operator - + /// \sa operator==(Node n) /// bool operator!=(Node) const { return true; } - /// Artificial ordering operator. - - /// To allow the use of graph descriptors as key type in std::map or - /// similar associative container we require this. - /// - /// \note This operator only have to define some strict ordering of - /// the items; this order has nothing to do with the iteration - /// ordering of the items. - bool operator<(Node) const { return false; } + /// Artificial ordering operator. + + /// To allow the use of graph descriptors as key type in std::map or + /// similar associative container we require this. + /// + /// \note This operator only have to define some strict ordering of + /// the items; this order has nothing to do with the iteration + /// ordering of the items. + bool operator<(Node) const { return false; } }; - + /// This iterator goes through each node. /// This iterator goes through each node. @@ -142,7 +142,7 @@ /// to an undefined value. NodeIt() { } /// Copy constructor. - + /// Copy constructor. /// NodeIt(const NodeIt& n) : Node(n) { } @@ -158,9 +158,9 @@ NodeIt(const Graph&) { } /// Node -> NodeIt conversion. - /// Sets the iterator to the node of \c the graph pointed by - /// the trivial iterator. - /// This feature necessitates that each time we + /// Sets the iterator to the node of \c the graph pointed by + /// the trivial iterator. + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. NodeIt(const Graph&, const Node&) { } /// Next node. @@ -169,8 +169,8 @@ /// NodeIt& operator++() { return *this; } }; - - + + /// The base type of the edge iterators. /// The base type of the edge iterators. @@ -203,15 +203,15 @@ /// bool operator!=(Edge) const { return true; } - /// Artificial ordering operator. - - /// To allow the use of graph descriptors as key type in std::map or - /// similar associative container we require this. - /// - /// \note This operator only have to define some strict ordering of - /// the items; this order has nothing to do with the iteration - /// ordering of the items. - bool operator<(Edge) const { return false; } + /// Artificial ordering operator. + + /// To allow the use of graph descriptors as key type in std::map or + /// similar associative container we require this. + /// + /// \note This operator only have to define some strict ordering of + /// the items; this order has nothing to do with the iteration + /// ordering of the items. + bool operator<(Edge) const { return false; } }; /// This iterator goes through each edge. @@ -241,32 +241,32 @@ /// EdgeIt(Invalid) { } /// This constructor sets the iterator to the first edge. - + /// This constructor sets the iterator to the first edge. EdgeIt(const Graph&) { } /// Edge -> EdgeIt conversion /// Sets the iterator to the value of the trivial iterator. /// This feature necessitates that each time we - /// iterate the edge-set, the iteration order is the - /// same. - EdgeIt(const Graph&, const Edge&) { } + /// iterate the edge-set, the iteration order is the + /// same. + EdgeIt(const Graph&, const Edge&) { } /// Next edge - + /// Assign the iterator to the next edge. EdgeIt& operator++() { return *this; } }; - /// \brief This iterator goes trough the incident undirected + /// \brief This iterator goes trough the incident undirected /// arcs of a node. /// /// This iterator goes trough the incident edges - /// of a certain node of a graph. You should assume that the + /// of a certain node of a graph. You should assume that the /// loop arcs will be iterated twice. - /// + /// /// Its usage is quite simple, for example you can compute the /// degree (i.e. count the number of incident arcs of a node \c n - /// in graph \c g of type \c Graph as follows. + /// in graph \c g of type \c Graph as follows. /// ///\code /// int count=0; @@ -290,20 +290,20 @@ /// IncEdgeIt(Invalid) { } /// This constructor sets the iterator to first incident arc. - + /// This constructor set the iterator to the first incident arc of /// the node. IncEdgeIt(const Graph&, const Node&) { } /// Edge -> IncEdgeIt conversion /// Sets the iterator to the value of the trivial iterator \c e. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. IncEdgeIt(const Graph&, const Edge&) { } /// Next incident arc /// Assign the iterator to the next incident arc - /// of the corresponding node. + /// of the corresponding node. IncEdgeIt& operator++() { return *this; } }; @@ -340,17 +340,17 @@ /// bool operator!=(Arc) const { return true; } - /// Artificial ordering operator. - - /// To allow the use of graph descriptors as key type in std::map or - /// similar associative container we require this. - /// - /// \note This operator only have to define some strict ordering of - /// the items; this order has nothing to do with the iteration - /// ordering of the items. - bool operator<(Arc) const { return false; } - - }; + /// Artificial ordering operator. + + /// To allow the use of graph descriptors as key type in std::map or + /// similar associative container we require this. + /// + /// \note This operator only have to define some strict ordering of + /// the items; this order has nothing to do with the iteration + /// ordering of the items. + bool operator<(Arc) const { return false; } + + }; /// This iterator goes through each directed arc. /// This iterator goes through each arc of a graph. @@ -378,22 +378,22 @@ /// ArcIt(Invalid) { } /// This constructor sets the iterator to the first arc. - + /// This constructor sets the iterator to the first arc of \c g. ///@param g the graph ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } /// Arc -> ArcIt conversion /// Sets the iterator to the value of the trivial iterator \c e. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. - ArcIt(const Graph&, const Arc&) { } + ArcIt(const Graph&, const Arc&) { } ///Next arc - + /// Assign the iterator to the next arc. ArcIt& operator++() { return *this; } }; - + /// This iterator goes trough the outgoing directed arcs of a node. /// This iterator goes trough the \e outgoing arcs of a certain node @@ -405,7 +405,7 @@ /// int count=0; /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; ///\endcode - + class OutArcIt : public Arc { public: /// Default constructor @@ -424,24 +424,24 @@ /// OutArcIt(Invalid) { } /// This constructor sets the iterator to the first outgoing arc. - + /// This constructor sets the iterator to the first outgoing arc of /// the node. ///@param n the node ///@param g the graph OutArcIt(const Graph& n, const Node& g) { - ignore_unused_variable_warning(n); - ignore_unused_variable_warning(g); - } + ignore_unused_variable_warning(n); + ignore_unused_variable_warning(g); + } /// Arc -> OutArcIt conversion /// Sets the iterator to the value of the trivial iterator. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. OutArcIt(const Graph&, const Arc&) { } ///Next outgoing arc - - /// Assign the iterator to the next + + /// Assign the iterator to the next /// outgoing arc of the corresponding node. OutArcIt& operator++() { return *this; } }; @@ -476,19 +476,19 @@ /// InArcIt(Invalid) { } /// This constructor sets the iterator to first incoming arc. - + /// This constructor set the iterator to the first incoming arc of /// the node. ///@param n the node ///@param g the graph - InArcIt(const Graph& g, const Node& n) { - ignore_unused_variable_warning(n); - ignore_unused_variable_warning(g); - } + InArcIt(const Graph& g, const Node& n) { + ignore_unused_variable_warning(n); + ignore_unused_variable_warning(g); + } /// Arc -> InArcIt conversion /// Sets the iterator to the value of the trivial iterator \c e. - /// This feature necessitates that each time we + /// This feature necessitates that each time we /// iterate the arc-set, the iteration order is the same. InArcIt(const Graph&, const Arc&) { } /// Next incoming arc @@ -499,10 +499,10 @@ }; /// \brief Read write map of the nodes to type \c T. - /// + /// /// ReadWrite map of the nodes to type \c T. /// \sa Reference - template + template class NodeMap : public ReadWriteMap< Node, T > { public: @@ -516,9 +516,9 @@ NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } ///Assignment operator template - NodeMap& operator=(const CMap&) { + NodeMap& operator=(const CMap&) { checkConcept, CMap>(); - return *this; + return *this; } }; @@ -526,7 +526,7 @@ /// /// Reference map of the directed arcs to type \c T. /// \sa Reference - template + template class ArcMap : public ReadWriteMap { public: @@ -539,9 +539,9 @@ ArcMap(const ArcMap& em) : ReadWriteMap(em) { } ///Assignment operator template - ArcMap& operator=(const CMap&) { + ArcMap& operator=(const CMap&) { checkConcept, CMap>(); - return *this; + return *this; } }; @@ -549,7 +549,7 @@ /// Reference map of the arcs to type \c T. /// \sa Reference - template + template class EdgeMap : public ReadWriteMap { public: @@ -562,9 +562,9 @@ EdgeMap(const EdgeMap& em) : ReadWriteMap(em) {} ///Assignment operator template - EdgeMap& operator=(const CMap&) { + EdgeMap& operator=(const CMap&) { checkConcept, CMap>(); - return *this; + return *this; } }; @@ -573,7 +573,7 @@ /// Direct the given edge. The returned arc source /// will be the given node. Arc direct(const Edge&, const Node&) const { - return INVALID; + return INVALID; } /// \brief Direct the given edge. @@ -583,7 +583,7 @@ /// from the bool parameter. The source of the edge and /// the directed arc is the same when the given bool is true. Arc direct(const Edge&, bool) const { - return INVALID; + return INVALID; } /// \brief Returns true if the arc has default orientation. @@ -625,37 +625,37 @@ Node target(Arc) const { return INVALID; } /// \brief Returns the id of the node. - int id(Node) const { return -1; } + int id(Node) const { return -1; } /// \brief Returns the id of the edge. - int id(Edge) const { return -1; } + int id(Edge) const { return -1; } /// \brief Returns the id of the arc. - int id(Arc) const { return -1; } + int id(Arc) const { return -1; } /// \brief Returns the node with the given id. /// /// \pre The argument should be a valid node id in the graph. - Node nodeFromId(int) const { return INVALID; } + Node nodeFromId(int) const { return INVALID; } /// \brief Returns the edge with the given id. /// /// \pre The argument should be a valid edge id in the graph. - Edge edgeFromId(int) const { return INVALID; } + Edge edgeFromId(int) const { return INVALID; } /// \brief Returns the arc with the given id. /// /// \pre The argument should be a valid arc id in the graph. - Arc arcFromId(int) const { return INVALID; } + Arc arcFromId(int) const { return INVALID; } /// \brief Returns an upper bound on the node IDs. - int maxNodeId() const { return -1; } + int maxNodeId() const { return -1; } /// \brief Returns an upper bound on the edge IDs. - int maxEdgeId() const { return -1; } + int maxEdgeId() const { return -1; } /// \brief Returns an upper bound on the arc IDs. - int maxArcId() const { return -1; } + int maxArcId() const { return -1; } void first(Node&) const {} void next(Node&) const {} @@ -683,61 +683,61 @@ Arc fromId(int, Arc) const { return INVALID; } // Dummy parameter. - int maxId(Node) const { return -1; } + int maxId(Node) const { return -1; } // Dummy parameter. - int maxId(Edge) const { return -1; } + int maxId(Edge) const { return -1; } // Dummy parameter. - int maxId(Arc) const { return -1; } + int maxId(Arc) const { return -1; } /// \brief Base node of the iterator /// /// Returns the base node (the source in this case) of the iterator Node baseNode(OutArcIt e) const { - return source(e); + return source(e); } /// \brief Running node of the iterator /// /// Returns the running node (the target in this case) of the /// iterator Node runningNode(OutArcIt e) const { - return target(e); + return target(e); } /// \brief Base node of the iterator /// /// Returns the base node (the target in this case) of the iterator Node baseNode(InArcIt e) const { - return target(e); + return target(e); } /// \brief Running node of the iterator /// /// Returns the running node (the source in this case) of the /// iterator Node runningNode(InArcIt e) const { - return source(e); + return source(e); } /// \brief Base node of the iterator /// /// Returns the base node of the iterator Node baseNode(IncEdgeIt) const { - return INVALID; + return INVALID; } - + /// \brief Running node of the iterator /// /// Returns the running node of the iterator Node runningNode(IncEdgeIt) const { - return INVALID; + return INVALID; } template struct Constraints { - void constraints() { - checkConcept, _Graph>(); - checkConcept, _Graph>(); - checkConcept, _Graph>(); - } + void constraints() { + checkConcept, _Graph>(); + checkConcept, _Graph>(); + checkConcept, _Graph>(); + } }; }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/graph_components.h --- a/lemon/concepts/graph_components.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/graph_components.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -49,7 +49,7 @@ class GraphItem { public: /// \brief Default constructor. - /// + /// /// \warning The default constructor is not required to set /// the item to some well-defined value. So you should consider it /// as uninitialized. @@ -66,7 +66,7 @@ GraphItem(Invalid) {} /// \brief Assign operator for nodes. /// - /// The nodes are assignable. + /// The nodes are assignable. /// GraphItem& operator=(GraphItem const&) { return *this; } /// \brief Equality operator. @@ -92,27 +92,27 @@ template struct Constraints { - void constraints() { - _GraphItem i1; - _GraphItem i2 = i1; - _GraphItem i3 = INVALID; - - i1 = i2 = i3; + void constraints() { + _GraphItem i1; + _GraphItem i2 = i1; + _GraphItem i3 = INVALID; - bool b; - // b = (ia == ib) && (ia != ib) && (ia < ib); - b = (ia == ib) && (ia != ib); - b = (ia == INVALID) && (ib != INVALID); + i1 = i2 = i3; + + bool b; + // b = (ia == ib) && (ia != ib) && (ia < ib); + b = (ia == ib) && (ia != ib); + b = (ia == INVALID) && (ib != INVALID); b = (ia < ib); - } + } - const _GraphItem &ia; - const _GraphItem &ib; + const _GraphItem &ia; + const _GraphItem &ib; }; }; /// \brief An empty base directed graph class. - /// + /// /// This class provides the minimal set of features needed for a /// directed graph structure. All digraph concepts have to be /// conform to this base directed graph. It just provides types @@ -122,16 +122,16 @@ public: typedef BaseDigraphComponent Digraph; - + /// \brief Node class of the digraph. /// - /// This class represents the Nodes of the digraph. + /// This class represents the Nodes of the digraph. /// typedef GraphItem<'n'> Node; /// \brief Arc class of the digraph. /// - /// This class represents the Arcs of the digraph. + /// This class represents the Arcs of the digraph. /// typedef GraphItem<'e'> Arc; @@ -156,27 +156,27 @@ template struct Constraints { - typedef typename _Digraph::Node Node; - typedef typename _Digraph::Arc Arc; - - void constraints() { - checkConcept, Node>(); - checkConcept, Arc>(); - { - Node n; - Arc e(INVALID); - n = digraph.source(e); - n = digraph.target(e); + typedef typename _Digraph::Node Node; + typedef typename _Digraph::Arc Arc; + + void constraints() { + checkConcept, Node>(); + checkConcept, Arc>(); + { + Node n; + Arc e(INVALID); + n = digraph.source(e); + n = digraph.target(e); n = digraph.oppositeNode(n, e); - } - } - - const _Digraph& digraph; + } + } + + const _Digraph& digraph; }; }; /// \brief An empty base undirected graph class. - /// + /// /// This class provides the minimal set of features needed for an /// undirected graph structure. All undirected graph concepts have /// to be conform to this base graph. It just provides types for @@ -199,7 +199,7 @@ public: typedef GraphItem<'u'> Parent; /// \brief Default constructor. - /// + /// /// \warning The default constructor is not required to set /// the item to some well-defined value. So you should consider it /// as uninitialized. @@ -217,12 +217,12 @@ /// \brief Converter from arc to edge. /// /// Besides the core graph item functionality each arc should - /// be convertible to the represented edge. + /// be convertible to the represented edge. Edge(const Arc&) {} /// \brief Assign arc to edge. /// /// Besides the core graph item functionality each arc should - /// be convertible to the represented edge. + /// be convertible to the represented edge. Edge& operator=(const Arc&) { return *this; } }; @@ -237,13 +237,13 @@ /// /// Returns the directed arc from its direction and the /// represented edge. - Arc direct(const Edge&, bool) const { return INVALID;} + Arc direct(const Edge&, bool) const { return INVALID;} /// \brief Returns the directed arc. /// /// Returns the directed arc from its source and the /// represented edge. - Arc direct(const Edge&, const Node&) const { return INVALID;} + Arc direct(const Edge&, const Node&) const { return INVALID;} /// \brief Returns the opposite arc. /// @@ -260,38 +260,38 @@ /// /// Gives back the other ending of an edge. Node v(const Edge&) const { return INVALID;} - + template struct Constraints { - typedef typename _Graph::Node Node; - typedef typename _Graph::Arc Arc; - typedef typename _Graph::Edge Edge; - - void constraints() { + typedef typename _Graph::Node Node; + typedef typename _Graph::Arc Arc; + typedef typename _Graph::Edge Edge; + + void constraints() { checkConcept(); - checkConcept, Edge>(); - { - Node n; - Edge ue(INVALID); + checkConcept, Edge>(); + { + Node n; + Edge ue(INVALID); Arc e; - n = graph.u(ue); - n = graph.v(ue); + n = graph.u(ue); + n = graph.v(ue); e = graph.direct(ue, true); e = graph.direct(ue, n); e = graph.oppositeArc(e); ue = e; bool d = graph.direction(e); ignore_unused_variable_warning(d); - } - } - - const _Graph& graph; + } + } + + const _Graph& graph; }; }; /// \brief An empty idable base digraph class. - /// + /// /// This class provides beside the core digraph features /// core id functions for the digraph structure. /// The most of the base digraphs should be conform to this concept. @@ -304,9 +304,9 @@ typedef typename Base::Node Node; typedef typename Base::Arc Arc; - /// \brief Gives back an unique integer id for the Node. + /// \brief Gives back an unique integer id for the Node. /// - /// Gives back an unique integer id for the Node. + /// Gives back an unique integer id for the Node. /// int id(const Node&) const { return -1;} @@ -314,12 +314,12 @@ /// /// Gives back the node by the unique id. /// If the digraph does not contain node with the given id - /// then the result of the function is undetermined. + /// then the result of the function is undetermined. Node nodeFromId(int) const { return INVALID;} - /// \brief Gives back an unique integer id for the Arc. + /// \brief Gives back an unique integer id for the Arc. /// - /// Gives back an unique integer id for the Arc. + /// Gives back an unique integer id for the Arc. /// int id(const Arc&) const { return -1;} @@ -327,7 +327,7 @@ /// /// Gives back the arc by the unique id. /// If the digraph does not contain arc with the given id - /// then the result of the function is undetermined. + /// then the result of the function is undetermined. Arc arcFromId(int) const { return INVALID;} /// \brief Gives back an integer greater or equal to the maximum @@ -347,29 +347,29 @@ template struct Constraints { - void constraints() { - checkConcept(); - typename _Digraph::Node node; - int nid = digraph.id(node); - nid = digraph.id(node); - node = digraph.nodeFromId(nid); - typename _Digraph::Arc arc; - int eid = digraph.id(arc); - eid = digraph.id(arc); - arc = digraph.arcFromId(eid); + void constraints() { + checkConcept(); + typename _Digraph::Node node; + int nid = digraph.id(node); + nid = digraph.id(node); + node = digraph.nodeFromId(nid); + typename _Digraph::Arc arc; + int eid = digraph.id(arc); + eid = digraph.id(arc); + arc = digraph.arcFromId(eid); - nid = digraph.maxNodeId(); - ignore_unused_variable_warning(nid); - eid = digraph.maxArcId(); - ignore_unused_variable_warning(eid); - } + nid = digraph.maxNodeId(); + ignore_unused_variable_warning(nid); + eid = digraph.maxArcId(); + ignore_unused_variable_warning(eid); + } - const _Digraph& digraph; + const _Digraph& digraph; }; }; /// \brief An empty idable base undirected graph class. - /// + /// /// This class provides beside the core undirected graph features /// core id functions for the undirected graph structure. The /// most of the base undirected graphs should be conform to this @@ -383,9 +383,9 @@ using IDableDigraphComponent<_Base>::id; - /// \brief Gives back an unique integer id for the Edge. + /// \brief Gives back an unique integer id for the Edge. /// - /// Gives back an unique integer id for the Edge. + /// Gives back an unique integer id for the Edge. /// int id(const Edge&) const { return -1;} @@ -406,18 +406,18 @@ template struct Constraints { - void constraints() { - checkConcept(); - checkConcept, _Graph >(); - typename _Graph::Edge edge; - int ueid = graph.id(edge); - ueid = graph.id(edge); - edge = graph.edgeFromId(ueid); - ueid = graph.maxEdgeId(); - ignore_unused_variable_warning(ueid); - } + void constraints() { + checkConcept(); + checkConcept, _Graph >(); + typename _Graph::Edge edge; + int ueid = graph.id(edge); + ueid = graph.id(edge); + edge = graph.edgeFromId(ueid); + ueid = graph.maxEdgeId(); + ignore_unused_variable_warning(ueid); + } - const _Graph& graph; + const _Graph& graph; }; }; @@ -450,52 +450,52 @@ GraphItemIt(Invalid) {} /// \brief Assign operator for items. /// - /// The items are assignable. + /// The items are assignable. /// - GraphItemIt& operator=(const GraphItemIt&) { return *this; } + GraphItemIt& operator=(const GraphItemIt&) { return *this; } /// \brief Next item. - /// + /// /// Assign the iterator to the next item. /// GraphItemIt& operator++() { return *this; } /// \brief Equality operator - /// + /// /// Two iterators are equal if and only if they point to the /// same object or both are invalid. bool operator==(const GraphItemIt&) const { return true;} /// \brief Inequality operator - /// + /// /// \sa operator==(Node n) /// bool operator!=(const GraphItemIt&) const { return true;} - + template struct Constraints { - void constraints() { - _GraphItemIt it1(g); - _GraphItemIt it2; + void constraints() { + _GraphItemIt it1(g); + _GraphItemIt it2; - it2 = ++it1; - ++it2 = it1; - ++(++it1); + it2 = ++it1; + ++it2 = it1; + ++(++it1); - _Item bi = it1; - bi = it2; - } - _Graph& g; + _Item bi = it1; + bi = it2; + } + _Graph& g; }; }; /// \brief Skeleton class for graph InArcIt and OutArcIt /// /// \note Because InArcIt and OutArcIt may not inherit from the same - /// base class, the _selector is a additional template parameter. For - /// InArcIt you should instantiate it with character 'i' and for + /// base class, the _selector is a additional template parameter. For + /// InArcIt you should instantiate it with character 'i' and for /// OutArcIt with 'o'. template + typename _Item = typename _Graph::Arc, + typename _Base = typename _Graph::Node, + char _selector = '0'> class GraphIncIt : public _Item { public: /// \brief Default constructor. @@ -508,10 +508,10 @@ /// Copy constructor. /// GraphIncIt(GraphIncIt const& gi) : _Item(gi) {} - /// \brief Sets the iterator to the first arc incoming into or outgoing + /// \brief Sets the iterator to the first arc incoming into or outgoing /// from the node. /// - /// Sets the iterator to the first arc incoming into or outgoing + /// Sets the iterator to the first arc incoming into or outgoing /// from the node. /// explicit GraphIncIt(const _Graph&, const _Base&) {} @@ -522,9 +522,9 @@ GraphIncIt(Invalid) {} /// \brief Assign operator for iterators. /// - /// The iterators are assignable. + /// The iterators are assignable. /// - GraphIncIt& operator=(GraphIncIt const&) { return *this; } + GraphIncIt& operator=(GraphIncIt const&) { return *this; } /// \brief Next item. /// /// Assign the iterator to the next item. @@ -545,23 +545,23 @@ template struct Constraints { - void constraints() { - checkConcept, _GraphIncIt>(); - _GraphIncIt it1(graph, node); - _GraphIncIt it2; + void constraints() { + checkConcept, _GraphIncIt>(); + _GraphIncIt it1(graph, node); + _GraphIncIt it2; - it2 = ++it1; - ++it2 = it1; - ++(++it1); - _Item e = it1; - e = it2; + it2 = ++it1; + ++it2 = it1; + ++(++it1); + _Item e = it1; + e = it2; - } + } - _Item arc; - _Base node; - _Graph graph; - _GraphIncIt it; + _Item arc; + _Base node; + _Graph graph; + _GraphIncIt it; }; }; @@ -575,7 +575,7 @@ class IterableDigraphComponent : public _Base { public: - + typedef _Base Base; typedef typename Base::Node Node; typedef typename Base::Arc Arc; @@ -583,33 +583,33 @@ typedef IterableDigraphComponent Digraph; /// \name Base iteration - /// + /// /// This interface provides functions for iteration on digraph items /// - /// @{ + /// @{ /// \brief Gives back the first node in the iterating order. - /// + /// /// Gives back the first node in the iterating order. - /// + /// void first(Node&) const {} /// \brief Gives back the next node in the iterating order. /// /// Gives back the next node in the iterating order. - /// + /// void next(Node&) const {} /// \brief Gives back the first arc in the iterating order. /// /// Gives back the first arc in the iterating order. - /// + /// void first(Arc&) const {} /// \brief Gives back the next arc in the iterating order. /// /// Gives back the next arc in the iterating order. - /// + /// void next(Arc&) const {} @@ -617,7 +617,7 @@ /// node. /// /// Gives back the first of the arcs point to the given node. - /// + /// void firstIn(Arc&, const Node&) const {} /// \brief Gives back the next of the arcs points to the given @@ -629,22 +629,22 @@ /// \brief Gives back the first of the arcs start from the /// given node. - /// + /// /// Gives back the first of the arcs start from the given node. - /// + /// void firstOut(Arc&, const Node&) const {} /// \brief Gives back the next of the arcs start from the given /// node. /// /// Gives back the next of the arcs start from the given node. - /// + /// void nextOut(Arc&) const {} /// @} /// \name Class based iteration - /// + /// /// This interface provides functions for iteration on digraph items /// /// @{ @@ -699,13 +699,13 @@ /// @} - template + template struct Constraints { - void constraints() { - checkConcept(); + void constraints() { + checkConcept(); { - typename _Digraph::Node node(INVALID); + typename _Digraph::Node node(INVALID); typename _Digraph::Arc arc(INVALID); { digraph.first(node); @@ -723,16 +723,16 @@ digraph.firstOut(arc, node); digraph.nextOut(arc); } - } + } { checkConcept, typename _Digraph::ArcIt >(); checkConcept, typename _Digraph::NodeIt >(); - checkConcept, typename _Digraph::InArcIt>(); - checkConcept, typename _Digraph::OutArcIt>(); typename _Digraph::Node n; @@ -745,9 +745,9 @@ ignore_unused_variable_warning(n); } } - - const _Digraph& digraph; - + + const _Digraph& digraph; + }; }; @@ -765,13 +765,13 @@ typedef typename Base::Arc Arc; typedef typename Base::Edge Edge; - + typedef IterableGraphComponent Graph; /// \name Base iteration - /// + /// /// This interface provides functions for iteration on graph items - /// @{ + /// @{ using IterableDigraphComponent<_Base>::first; using IterableDigraphComponent<_Base>::next; @@ -780,14 +780,14 @@ /// order. /// /// Gives back the first edge in the iterating order. - /// + /// void first(Edge&) const {} /// \brief Gives back the next edge in the iterating /// order. /// /// Gives back the next edge in the iterating order. - /// + /// void next(Edge&) const {} @@ -814,7 +814,7 @@ /// @} /// \name Class based iteration - /// + /// /// This interface provides functions for iteration on graph items /// /// @{ @@ -841,10 +841,10 @@ /// @} - template + template struct Constraints { - void constraints() { - checkConcept, _Graph>(); + void constraints() { + checkConcept, _Graph>(); { typename _Graph::Node node(INVALID); @@ -858,29 +858,29 @@ graph.firstInc(edge, dir, node); graph.nextInc(edge, dir); } - - } - + + } + { checkConcept, typename _Graph::EdgeIt >(); - checkConcept, typename _Graph::IncEdgeIt>(); - + typename _Graph::Node n; typename _Graph::IncEdgeIt ueit(INVALID); n = graph.baseNode(ueit); n = graph.runningNode(ueit); } } - - const _Graph& graph; - + + const _Graph& graph; + }; }; /// \brief An empty alteration notifier digraph class. - /// + /// /// This class provides beside the core digraph features alteration /// notifier interface for the digraph structure. This implements /// an observer-notifier pattern for each digraph item. More @@ -897,48 +897,48 @@ /// The node observer registry. - typedef AlterationNotifier + typedef AlterationNotifier NodeNotifier; /// The arc observer registry. - typedef AlterationNotifier + typedef AlterationNotifier ArcNotifier; - + /// \brief Gives back the node alteration notifier. /// /// Gives back the node alteration notifier. NodeNotifier& notifier(Node) const { - return NodeNotifier(); + return NodeNotifier(); } - + /// \brief Gives back the arc alteration notifier. /// /// Gives back the arc alteration notifier. ArcNotifier& notifier(Arc) const { - return ArcNotifier(); + return ArcNotifier(); } - template + template struct Constraints { - void constraints() { - checkConcept(); - typename _Digraph::NodeNotifier& nn + void constraints() { + checkConcept(); + typename _Digraph::NodeNotifier& nn = digraph.notifier(typename _Digraph::Node()); - typename _Digraph::ArcNotifier& en + typename _Digraph::ArcNotifier& en = digraph.notifier(typename _Digraph::Arc()); - + ignore_unused_variable_warning(nn); ignore_unused_variable_warning(en); - } - - const _Digraph& digraph; - + } + + const _Digraph& digraph; + }; - + }; /// \brief An empty alteration notifier undirected graph class. - /// + /// /// This class provides beside the core graph features alteration /// notifier interface for the graph structure. This implements /// an observer-notifier pattern for each graph item. More @@ -954,33 +954,33 @@ /// The arc observer registry. - typedef AlterationNotifier + typedef AlterationNotifier EdgeNotifier; - + /// \brief Gives back the arc alteration notifier. /// /// Gives back the arc alteration notifier. EdgeNotifier& notifier(Edge) const { - return EdgeNotifier(); + return EdgeNotifier(); } - template + template struct Constraints { - void constraints() { - checkConcept, _Graph>(); - typename _Graph::EdgeNotifier& uen + void constraints() { + checkConcept, _Graph>(); + typename _Graph::EdgeNotifier& uen = graph.notifier(typename _Graph::Edge()); ignore_unused_variable_warning(uen); - } - - const _Graph& graph; - + } + + const _Graph& graph; + }; - + }; /// \brief Class describing the concept of graph maps - /// + /// /// This class describes the common interface of the graph maps /// (NodeMap, ArcMap), that is \ref maps-page "maps" which can be used to /// associate data to graph descriptors (nodes or arcs). @@ -1009,39 +1009,39 @@ /// /// Copy Constructor. GraphMap(const GraphMap&) : Parent() {} - + /// \brief Assign operator. /// /// Assign operator. It does not mofify the underlying graph, /// it just iterates on the current item set and set the map - /// with the value returned by the assigned map. + /// with the value returned by the assigned map. template - GraphMap& operator=(const CMap&) { + GraphMap& operator=(const CMap&) { checkConcept, CMap>(); return *this; } template struct Constraints { - void constraints() { - checkConcept, _Map >(); - // Construction with a graph parameter - _Map a(g); - // Constructor with a graph and a default value parameter - _Map a2(g,t); - // Copy constructor. - _Map b(c); - + void constraints() { + checkConcept, _Map >(); + // Construction with a graph parameter + _Map a(g); + // Constructor with a graph and a default value parameter + _Map a2(g,t); + // Copy constructor. + _Map b(c); + ReadMap cmap; b = cmap; - ignore_unused_variable_warning(a2); - ignore_unused_variable_warning(b); - } + ignore_unused_variable_warning(a2); + ignore_unused_variable_warning(b); + } - const _Map &c; - const Graph &g; - const typename GraphMap::Value &t; + const _Map &c; + const Graph &g; + const typename GraphMap::Value &t; }; }; @@ -1070,28 +1070,28 @@ public: typedef GraphMap Parent; - /// \brief Construct a new map. - /// - /// Construct a new map for the digraph. - explicit NodeMap(const MappableDigraphComponent& digraph) + /// \brief Construct a new map. + /// + /// Construct a new map for the digraph. + explicit NodeMap(const MappableDigraphComponent& digraph) : Parent(digraph) {} - /// \brief Construct a new map with default value. - /// - /// Construct a new map for the digraph and initalise the values. - NodeMap(const MappableDigraphComponent& digraph, const _Value& value) + /// \brief Construct a new map with default value. + /// + /// Construct a new map for the digraph and initalise the values. + NodeMap(const MappableDigraphComponent& digraph, const _Value& value) : Parent(digraph, value) {} - /// \brief Copy constructor. - /// - /// Copy Constructor. - NodeMap(const NodeMap& nm) : Parent(nm) {} + /// \brief Copy constructor. + /// + /// Copy Constructor. + NodeMap(const NodeMap& nm) : Parent(nm) {} - /// \brief Assign operator. - /// - /// Assign operator. + /// \brief Assign operator. + /// + /// Assign operator. template - NodeMap& operator=(const CMap&) { + NodeMap& operator=(const CMap&) { checkConcept, CMap>(); return *this; } @@ -1107,28 +1107,28 @@ public: typedef GraphMap Parent; - /// \brief Construct a new map. - /// - /// Construct a new map for the digraph. - explicit ArcMap(const MappableDigraphComponent& digraph) + /// \brief Construct a new map. + /// + /// Construct a new map for the digraph. + explicit ArcMap(const MappableDigraphComponent& digraph) : Parent(digraph) {} - /// \brief Construct a new map with default value. - /// - /// Construct a new map for the digraph and initalise the values. - ArcMap(const MappableDigraphComponent& digraph, const _Value& value) + /// \brief Construct a new map with default value. + /// + /// Construct a new map for the digraph and initalise the values. + ArcMap(const MappableDigraphComponent& digraph, const _Value& value) : Parent(digraph, value) {} - /// \brief Copy constructor. - /// - /// Copy Constructor. - ArcMap(const ArcMap& nm) : Parent(nm) {} + /// \brief Copy constructor. + /// + /// Copy Constructor. + ArcMap(const ArcMap& nm) : Parent(nm) {} - /// \brief Assign operator. - /// - /// Assign operator. + /// \brief Assign operator. + /// + /// Assign operator. template - ArcMap& operator=(const CMap&) { + ArcMap& operator=(const CMap&) { checkConcept, CMap>(); return *this; } @@ -1139,44 +1139,44 @@ template struct Constraints { - struct Dummy { - int value; - Dummy() : value(0) {} - Dummy(int _v) : value(_v) {} - }; + struct Dummy { + int value; + Dummy() : value(0) {} + Dummy(int _v) : value(_v) {} + }; - void constraints() { - checkConcept(); - { // int map test - typedef typename _Digraph::template NodeMap IntNodeMap; - checkConcept, - IntNodeMap >(); - } { // bool map test - typedef typename _Digraph::template NodeMap BoolNodeMap; - checkConcept, - BoolNodeMap >(); - } { // Dummy map test - typedef typename _Digraph::template NodeMap DummyNodeMap; - checkConcept, - DummyNodeMap >(); - } + void constraints() { + checkConcept(); + { // int map test + typedef typename _Digraph::template NodeMap IntNodeMap; + checkConcept, + IntNodeMap >(); + } { // bool map test + typedef typename _Digraph::template NodeMap BoolNodeMap; + checkConcept, + BoolNodeMap >(); + } { // Dummy map test + typedef typename _Digraph::template NodeMap DummyNodeMap; + checkConcept, + DummyNodeMap >(); + } - { // int map test - typedef typename _Digraph::template ArcMap IntArcMap; - checkConcept, - IntArcMap >(); - } { // bool map test - typedef typename _Digraph::template ArcMap BoolArcMap; - checkConcept, - BoolArcMap >(); - } { // Dummy map test - typedef typename _Digraph::template ArcMap DummyArcMap; - checkConcept, - DummyArcMap >(); - } - } + { // int map test + typedef typename _Digraph::template ArcMap IntArcMap; + checkConcept, + IntArcMap >(); + } { // bool map test + typedef typename _Digraph::template ArcMap BoolArcMap; + checkConcept, + BoolArcMap >(); + } { // Dummy map test + typedef typename _Digraph::template ArcMap DummyArcMap; + checkConcept, + DummyArcMap >(); + } + } - _Digraph& digraph; + _Digraph& digraph; }; }; @@ -1199,32 +1199,32 @@ /// ReadWrite map of the edges. /// template - class EdgeMap : public GraphMap { + class EdgeMap : public GraphMap { public: typedef GraphMap Parent; - /// \brief Construct a new map. - /// - /// Construct a new map for the graph. - explicit EdgeMap(const MappableGraphComponent& graph) + /// \brief Construct a new map. + /// + /// Construct a new map for the graph. + explicit EdgeMap(const MappableGraphComponent& graph) : Parent(graph) {} - /// \brief Construct a new map with default value. - /// - /// Construct a new map for the graph and initalise the values. - EdgeMap(const MappableGraphComponent& graph, const _Value& value) + /// \brief Construct a new map with default value. + /// + /// Construct a new map for the graph and initalise the values. + EdgeMap(const MappableGraphComponent& graph, const _Value& value) : Parent(graph, value) {} - /// \brief Copy constructor. - /// - /// Copy Constructor. - EdgeMap(const EdgeMap& nm) : Parent(nm) {} + /// \brief Copy constructor. + /// + /// Copy Constructor. + EdgeMap(const EdgeMap& nm) : Parent(nm) {} - /// \brief Assign operator. - /// - /// Assign operator. + /// \brief Assign operator. + /// + /// Assign operator. template - EdgeMap& operator=(const CMap&) { + EdgeMap& operator=(const CMap&) { checkConcept, CMap>(); return *this; } @@ -1235,31 +1235,31 @@ template struct Constraints { - struct Dummy { - int value; - Dummy() : value(0) {} - Dummy(int _v) : value(_v) {} - }; + struct Dummy { + int value; + Dummy() : value(0) {} + Dummy(int _v) : value(_v) {} + }; - void constraints() { - checkConcept, _Graph>(); + void constraints() { + checkConcept, _Graph>(); - { // int map test - typedef typename _Graph::template EdgeMap IntEdgeMap; - checkConcept, - IntEdgeMap >(); - } { // bool map test - typedef typename _Graph::template EdgeMap BoolEdgeMap; - checkConcept, - BoolEdgeMap >(); - } { // Dummy map test - typedef typename _Graph::template EdgeMap DummyEdgeMap; - checkConcept, - DummyEdgeMap >(); - } - } + { // int map test + typedef typename _Graph::template EdgeMap IntEdgeMap; + checkConcept, + IntEdgeMap >(); + } { // bool map test + typedef typename _Graph::template EdgeMap BoolEdgeMap; + checkConcept, + BoolEdgeMap >(); + } { // Dummy map test + typedef typename _Graph::template EdgeMap DummyEdgeMap; + checkConcept, + DummyEdgeMap >(); + } + } - _Graph& graph; + _Graph& graph; }; }; @@ -1282,28 +1282,28 @@ /// Adds a new node to the digraph. /// Node addNode() { - return INVALID; + return INVALID; } - + /// \brief Adds a new arc connects the given two nodes. /// /// Adds a new arc connects the the given two nodes. Arc addArc(const Node&, const Node&) { - return INVALID; + return INVALID; } template struct Constraints { - void constraints() { + void constraints() { checkConcept(); - typename _Digraph::Node node_a, node_b; - node_a = digraph.addNode(); - node_b = digraph.addNode(); - typename _Digraph::Arc arc; - arc = digraph.addArc(node_a, node_b); - } + typename _Digraph::Node node_a, node_b; + node_a = digraph.addNode(); + node_b = digraph.addNode(); + typename _Digraph::Arc arc; + arc = digraph.addArc(node_a, node_b); + } - _Digraph& digraph; + _Digraph& digraph; }; }; @@ -1327,33 +1327,33 @@ /// Adds a new node to the graph. /// Node addNode() { - return INVALID; + return INVALID; } - + /// \brief Adds a new arc connects the given two nodes. /// /// Adds a new arc connects the the given two nodes. Edge addArc(const Node&, const Node&) { - return INVALID; + return INVALID; } template struct Constraints { - void constraints() { - checkConcept(); - typename _Graph::Node node_a, node_b; - node_a = graph.addNode(); - node_b = graph.addNode(); - typename _Graph::Edge edge; - edge = graph.addEdge(node_a, node_b); - } + void constraints() { + checkConcept(); + typename _Graph::Node node_a, node_b; + node_a = graph.addNode(); + node_b = graph.addNode(); + typename _Graph::Edge edge; + edge = graph.addEdge(node_a, node_b); + } - _Graph& graph; + _Graph& graph; }; }; /// \brief An empty erasable digraph class. - /// + /// /// This class provides beside the core digraph features core erase /// functions for the digraph structure. The main difference between /// the base and this interface is that the digraph alterations @@ -1368,9 +1368,9 @@ /// \brief Erase a node from the digraph. /// - /// Erase a node from the digraph. This function should + /// Erase a node from the digraph. This function should /// erase all arcs connecting to the node. - void erase(const Node&) {} + void erase(const Node&) {} /// \brief Erase an arc from the digraph. /// @@ -1380,20 +1380,20 @@ template struct Constraints { - void constraints() { + void constraints() { checkConcept(); - typename _Digraph::Node node; - digraph.erase(node); - typename _Digraph::Arc arc; - digraph.erase(arc); - } + typename _Digraph::Node node; + digraph.erase(node); + typename _Digraph::Arc arc; + digraph.erase(arc); + } - _Digraph& digraph; + _Digraph& digraph; }; }; /// \brief An empty erasable base undirected graph class. - /// + /// /// This class provides beside the core undirected graph features /// core erase functions for the undirceted graph structure. The /// main difference between the base and this interface is that @@ -1410,7 +1410,7 @@ /// /// Erase a node from the graph. This function should erase /// arcs connecting to the node. - void erase(const Node&) {} + void erase(const Node&) {} /// \brief Erase an arc from the graph. /// @@ -1420,15 +1420,15 @@ template struct Constraints { - void constraints() { + void constraints() { checkConcept(); - typename _Graph::Node node; - graph.erase(node); - typename _Graph::Edge edge; - graph.erase(edge); - } + typename _Graph::Node node; + graph.erase(node); + typename _Graph::Edge edge; + graph.erase(edge); + } - _Graph& graph; + _Graph& graph; }; }; @@ -1448,16 +1448,16 @@ /// /// Erase all nodes and arcs from the digraph. /// - void clear() {} + void clear() {} template struct Constraints { - void constraints() { + void constraints() { checkConcept(); - digraph.clear(); - } + digraph.clear(); + } - _Digraph digraph; + _Digraph digraph; }; }; @@ -1475,11 +1475,11 @@ template struct Constraints { - void constraints() { + void constraints() { checkConcept, _Graph>(); - } + } - _Graph graph; + _Graph graph; }; }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/heap.h --- a/lemon/concepts/heap.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/heap.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -52,14 +52,14 @@ /// from the point of view of the heap, but may be useful for /// the user. /// - /// The \c ItemIntMap must be initialized in such a way, that it + /// The \c ItemIntMap must be initialized in such a way, that it /// assigns \c PRE_HEAP (-1) to every item. enum State { - IN_HEAP = 0, - PRE_HEAP = -1, - POST_HEAP = -2 + IN_HEAP = 0, + PRE_HEAP = -1, + POST_HEAP = -2 }; - + /// \brief The constructor. /// /// The constructor. @@ -85,8 +85,8 @@ void clear(); /// \brief Inserts an item into the heap with the given priority. - /// - /// Inserts the given item into the heap with the given priority. + /// + /// Inserts the given item into the heap with the given priority. /// \param i The item to insert. /// \param p The priority of the item. void push(const Item &i, const Prio &p) {} @@ -112,12 +112,12 @@ /// \brief Removes an item from the heap. /// /// Removes the given item from the heap if it is already stored. - /// \param i The item to delete. + /// \param i The item to delete. void erase(const Item &i) {} /// \brief The priority of an item. /// - /// Returns the priority of the given item. + /// Returns the priority of the given item. /// \pre \c i must be in the heap. /// \param i The item. Prio operator[](const Item &i) const {} @@ -133,7 +133,7 @@ /// \param i The item. /// \param p The priority. void set(const Item &i, const Prio &p) {} - + /// \brief Decreases the priority of an item to the given value. /// /// Decreases the priority of an item to the given value. @@ -174,69 +174,69 @@ template struct Constraints { public: - void constraints() { - typedef typename _Heap::Item OwnItem; - typedef typename _Heap::Prio OwnPrio; - typedef typename _Heap::State OwnState; + void constraints() { + typedef typename _Heap::Item OwnItem; + typedef typename _Heap::Prio OwnPrio; + typedef typename _Heap::State OwnState; - Item item; - Prio prio; - item=Item(); - prio=Prio(); - ignore_unused_variable_warning(item); - ignore_unused_variable_warning(prio); + Item item; + Prio prio; + item=Item(); + prio=Prio(); + ignore_unused_variable_warning(item); + ignore_unused_variable_warning(prio); - OwnItem own_item; - OwnPrio own_prio; - OwnState own_state; - own_item=Item(); - own_prio=Prio(); - ignore_unused_variable_warning(own_item); - ignore_unused_variable_warning(own_prio); - ignore_unused_variable_warning(own_state); + OwnItem own_item; + OwnPrio own_prio; + OwnState own_state; + own_item=Item(); + own_prio=Prio(); + ignore_unused_variable_warning(own_item); + ignore_unused_variable_warning(own_prio); + ignore_unused_variable_warning(own_state); - _Heap heap1(map); - _Heap heap2 = heap1; - ignore_unused_variable_warning(heap1); - ignore_unused_variable_warning(heap2); - - int s = heap.size(); - ignore_unused_variable_warning(s); - bool e = heap.empty(); - ignore_unused_variable_warning(e); + _Heap heap1(map); + _Heap heap2 = heap1; + ignore_unused_variable_warning(heap1); + ignore_unused_variable_warning(heap2); - prio = heap.prio(); - item = heap.top(); - prio = heap[item]; - own_prio = heap.prio(); - own_item = heap.top(); - own_prio = heap[own_item]; + int s = heap.size(); + ignore_unused_variable_warning(s); + bool e = heap.empty(); + ignore_unused_variable_warning(e); - heap.push(item, prio); - heap.push(own_item, own_prio); - heap.pop(); + prio = heap.prio(); + item = heap.top(); + prio = heap[item]; + own_prio = heap.prio(); + own_item = heap.top(); + own_prio = heap[own_item]; - heap.set(item, prio); - heap.decrease(item, prio); - heap.increase(item, prio); - heap.set(own_item, own_prio); - heap.decrease(own_item, own_prio); - heap.increase(own_item, own_prio); + heap.push(item, prio); + heap.push(own_item, own_prio); + heap.pop(); - heap.erase(item); - heap.erase(own_item); - heap.clear(); + heap.set(item, prio); + heap.decrease(item, prio); + heap.increase(item, prio); + heap.set(own_item, own_prio); + heap.decrease(own_item, own_prio); + heap.increase(own_item, own_prio); - own_state = heap.state(own_item); - heap.state(own_item, own_state); + heap.erase(item); + heap.erase(own_item); + heap.clear(); - own_state = _Heap::PRE_HEAP; - own_state = _Heap::IN_HEAP; - own_state = _Heap::POST_HEAP; - } + own_state = heap.state(own_item); + heap.state(own_item, own_state); - _Heap& heap; - ItemIntMap& map; + own_state = _Heap::PRE_HEAP; + own_state = _Heap::IN_HEAP; + own_state = _Heap::POST_HEAP; + } + + _Heap& heap; + ItemIntMap& map; }; }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/maps.h --- a/lemon/concepts/maps.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/maps.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -47,26 +47,26 @@ typedef T Value; /// Returns the value associated with the given key. - Value operator[](const Key &) const { + Value operator[](const Key &) const { return *static_cast(0); } template struct Constraints { - void constraints() { - Value val = m[key]; - val = m[key]; - typename _ReadMap::Value own_val = m[own_key]; - own_val = m[own_key]; + void constraints() { + Value val = m[key]; + val = m[key]; + typename _ReadMap::Value own_val = m[own_key]; + own_val = m[own_key]; - ignore_unused_variable_warning(key); - ignore_unused_variable_warning(val); - ignore_unused_variable_warning(own_key); - ignore_unused_variable_warning(own_val); - } - const Key& key; - const typename _ReadMap::Key& own_key; - const _ReadMap& m; + ignore_unused_variable_warning(key); + ignore_unused_variable_warning(val); + ignore_unused_variable_warning(own_key); + ignore_unused_variable_warning(own_val); + } + const Key& key; + const typename _ReadMap::Key& own_key; + const _ReadMap& m; }; }; @@ -93,20 +93,20 @@ template struct Constraints { - void constraints() { - m.set(key, val); - m.set(own_key, own_val); + void constraints() { + m.set(key, val); + m.set(own_key, own_val); - ignore_unused_variable_warning(key); - ignore_unused_variable_warning(val); - ignore_unused_variable_warning(own_key); - ignore_unused_variable_warning(own_val); - } - const Key& key; - const Value& val; - const typename _WriteMap::Key& own_key; - const typename _WriteMap::Value& own_val; - _WriteMap& m; + ignore_unused_variable_warning(key); + ignore_unused_variable_warning(val); + ignore_unused_variable_warning(own_key); + ignore_unused_variable_warning(own_val); + } + const Key& key; + const Value& val; + const typename _WriteMap::Key& own_key; + const typename _WriteMap::Value& own_val; + _WriteMap& m; }; }; @@ -116,7 +116,7 @@ /// template class ReadWriteMap : public ReadMap, - public WriteMap + public WriteMap { public: /// The key type of the map. @@ -125,7 +125,7 @@ typedef T Value; /// Returns the value associated with the given key. - Value operator[](const Key &) const { + Value operator[](const Key &) const { return *static_cast(0); } @@ -134,10 +134,10 @@ template struct Constraints { - void constraints() { - checkConcept, _ReadWriteMap >(); - checkConcept, _ReadWriteMap >(); - } + void constraints() { + checkConcept, _ReadWriteMap >(); + checkConcept, _ReadWriteMap >(); + } }; }; @@ -164,7 +164,7 @@ public: /// Returns a reference to the value associated with the given key. - Reference operator[](const Key &) { + Reference operator[](const Key &) { return *static_cast(0); } @@ -178,28 +178,28 @@ template struct Constraints { - void constraints() { - checkConcept, _ReferenceMap >(); - ref = m[key]; - m[key] = val; - m[key] = ref; - m[key] = cref; - own_ref = m[own_key]; - m[own_key] = own_val; - m[own_key] = own_ref; - m[own_key] = own_cref; - m[key] = m[own_key]; - m[own_key] = m[key]; - } - const Key& key; - Value& val; - Reference ref; - ConstReference cref; - const typename _ReferenceMap::Key& own_key; - typename _ReferenceMap::Value& own_val; - typename _ReferenceMap::Reference own_ref; - typename _ReferenceMap::ConstReference own_cref; - _ReferenceMap& m; + void constraints() { + checkConcept, _ReferenceMap >(); + ref = m[key]; + m[key] = val; + m[key] = ref; + m[key] = cref; + own_ref = m[own_key]; + m[own_key] = own_val; + m[own_key] = own_ref; + m[own_key] = own_cref; + m[key] = m[own_key]; + m[own_key] = m[key]; + } + const Key& key; + Value& val; + Reference ref; + ConstReference cref; + const typename _ReferenceMap::Key& own_key; + typename _ReferenceMap::Value& own_val; + typename _ReferenceMap::Reference own_ref; + typename _ReferenceMap::ConstReference own_cref; + _ReferenceMap& m; }; }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/concepts/path.h --- a/lemon/concepts/path.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/concepts/path.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -39,7 +39,7 @@ /// a digraph. /// /// A skeleton structure for representing directed paths in a - /// digraph. + /// digraph. /// \tparam _Digraph The digraph type in which the path is. /// /// In a sense, the path can be treated as a list of arcs. The @@ -83,25 +83,25 @@ /// This class is used to iterate on the arcs of the paths. class ArcIt { public: - /// Default constructor - ArcIt() {} - /// Invalid constructor - ArcIt(Invalid) {} - /// Constructor for first arc - ArcIt(const Path &) {} + /// Default constructor + ArcIt() {} + /// Invalid constructor + ArcIt(Invalid) {} + /// Constructor for first arc + ArcIt(const Path &) {} /// Conversion to Arc - operator Arc() const { return INVALID; } + operator Arc() const { return INVALID; } - /// Next arc - ArcIt& operator++() {return *this;} + /// Next arc + ArcIt& operator++() {return *this;} - /// Comparison operator - bool operator==(const ArcIt&) const {return true;} - /// Comparison operator - bool operator!=(const ArcIt&) const {return true;} - /// Comparison operator - bool operator<(const ArcIt&) const {return false;} + /// Comparison operator + bool operator==(const ArcIt&) const {return true;} + /// Comparison operator + bool operator!=(const ArcIt&) const {return true;} + /// Comparison operator + bool operator<(const ArcIt&) const {return false;} }; @@ -137,7 +137,7 @@ }; namespace _path_bits { - + template struct PathDumperConstraints { void constraints() { @@ -162,7 +162,7 @@ template struct PathDumperConstraints< - _Digraph, _Path, + _Digraph, _Path, typename enable_if::type > { void constraints() { @@ -184,7 +184,7 @@ } _Path& p; }; - + } @@ -209,7 +209,7 @@ /// /// The paths can be constructed from any path type by a /// template constructor or a template assignment operator. - /// + /// template class PathDumper { public: @@ -238,25 +238,25 @@ /// This class is used to iterate on the arcs of the paths. class ArcIt { public: - /// Default constructor - ArcIt() {} - /// Invalid constructor - ArcIt(Invalid) {} - /// Constructor for first arc - ArcIt(const PathDumper&) {} + /// Default constructor + ArcIt() {} + /// Invalid constructor + ArcIt(Invalid) {} + /// Constructor for first arc + ArcIt(const PathDumper&) {} /// Conversion to Arc - operator Arc() const { return INVALID; } + operator Arc() const { return INVALID; } - /// Next arc - ArcIt& operator++() {return *this;} + /// Next arc + ArcIt& operator++() {return *this;} - /// Comparison operator - bool operator==(const ArcIt&) const {return true;} - /// Comparison operator - bool operator!=(const ArcIt&) const {return true;} - /// Comparison operator - bool operator<(const ArcIt&) const {return false;} + /// Comparison operator + bool operator==(const ArcIt&) const {return true;} + /// Comparison operator + bool operator!=(const ArcIt&) const {return true;} + /// Comparison operator + bool operator<(const ArcIt&) const {return false;} }; @@ -266,25 +266,25 @@ /// reverse direction. class RevArcIt { public: - /// Default constructor - RevArcIt() {} - /// Invalid constructor - RevArcIt(Invalid) {} - /// Constructor for first arc - RevArcIt(const PathDumper &) {} + /// Default constructor + RevArcIt() {} + /// Invalid constructor + RevArcIt(Invalid) {} + /// Constructor for first arc + RevArcIt(const PathDumper &) {} /// Conversion to Arc - operator Arc() const { return INVALID; } + operator Arc() const { return INVALID; } - /// Next arc - RevArcIt& operator++() {return *this;} + /// Next arc + RevArcIt& operator++() {return *this;} - /// Comparison operator - bool operator==(const RevArcIt&) const {return true;} - /// Comparison operator - bool operator!=(const RevArcIt&) const {return true;} - /// Comparison operator - bool operator<(const RevArcIt&) const {return false;} + /// Comparison operator + bool operator==(const RevArcIt&) const {return true;} + /// Comparison operator + bool operator!=(const RevArcIt&) const {return true;} + /// Comparison operator + bool operator<(const RevArcIt&) const {return false;} }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/counter.h --- a/lemon/counter.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/counter.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -26,13 +26,13 @@ ///\file ///\brief Tools for counting steps and events -namespace lemon +namespace lemon { template class _NoSubCounter; template - class _SubCounter + class _SubCounter { P &_parent; std::string _title; @@ -49,7 +49,7 @@ : _parent(parent), _title(title), _os(os), count(0) {} _SubCounter(P &parent,const char *title,std::ostream &os=std::cerr) : _parent(parent), _title(title), _os(os), count(0) {} - ~_SubCounter() { + ~_SubCounter() { _os << _title << count < - class _NoSubCounter + class _NoSubCounter { P &_parent; public: typedef _NoSubCounter<_NoSubCounter

> SubCounter; typedef _NoSubCounter<_NoSubCounter

> NoSubCounter; - + _NoSubCounter(P &parent) :_parent(parent) {} - _NoSubCounter(P &parent,std::string,std::ostream &) + _NoSubCounter(P &parent,std::string,std::ostream &) :_parent(parent) {} - _NoSubCounter(P &parent,std::string) + _NoSubCounter(P &parent,std::string) :_parent(parent) {} _NoSubCounter(P &parent,const char *,std::ostream &) :_parent(parent) {} @@ -102,7 +102,7 @@ /// define subcounters for the different phases of the algorithm or /// for different types of operations. /// A report containing the given title and the value of the counter - /// is automatically printed on destruction. + /// is automatically printed on destruction. /// /// The following example shows the usage of counters and subcounters. /// \code @@ -133,7 +133,7 @@ /// \endcode /// /// \sa NoCounter - class Counter + class Counter { std::string _title; std::ostream &_os; @@ -141,13 +141,13 @@ public: /// SubCounter class - + /// This class can be used to setup subcounters for a \ref Counter /// to have finer reports. A subcounter provides exactly the same /// operations as the main \ref Counter, but it also increments and /// decrements the value of its parent. /// Subcounters can also have subcounters. - /// + /// /// The parent counter must be given as the first parameter of the /// constructor. Apart from that a title and an \c ostream object /// can also be given just like for the main \ref Counter. @@ -156,19 +156,19 @@ /// subcounter is automatically printed on destruction. If you /// would like to turn off this report, use \ref NoSubCounter /// instead. - /// + /// /// \sa NoSubCounter typedef _SubCounter SubCounter; - /// SubCounter class without printing report on destruction - + /// SubCounter class without printing report on destruction + /// This class can be used to setup subcounters for a \ref Counter. /// It is the same as \ref SubCounter but it does not print report /// on destruction. (It modifies the value of its parent, so 'No' /// only means 'do not print'.) /// /// Replacing \ref SubCounter "SubCounter"s with \ref NoSubCounter - /// "NoSubCounter"s makes it possible to turn off reporting + /// "NoSubCounter"s makes it possible to turn off reporting /// subcounter values without actually removing the definitions /// and the increment or decrement operators. /// @@ -178,7 +178,7 @@ /// Constructor. Counter() : _title(), _os(std::cerr), count(0) {} /// Constructor. - Counter(std::string title,std::ostream &os=std::cerr) + Counter(std::string title,std::ostream &os=std::cerr) : _title(title), _os(os), count(0) {} /// Constructor. Counter(const char *title,std::ostream &os=std::cerr) @@ -204,7 +204,7 @@ /// Resets the counter to the given value. /// \note This function does not reset the values of /// \ref SubCounter "SubCounter"s but it resets \ref NoSubCounter - /// "NoSubCounter"s along with the main counter. + /// "NoSubCounter"s along with the main counter. void reset(int c=0) {count=c;} /// Returns the value of the counter. operator int() {return count;} diff -r 4317d277ba21 -r 765619b7cbb2 lemon/dfs.h --- a/lemon/dfs.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/dfs.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -34,7 +34,7 @@ namespace lemon { - + ///Default traits class of Dfs class. ///Default traits class of Dfs class. @@ -42,35 +42,35 @@ template struct DfsDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///\brief The type of the map that stores the last ///arcs of the %DFS paths. - /// + /// ///The type of the map that stores the last ///arcs of the %DFS paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \ref PredMap. + + ///This function instantiates a \ref PredMap. ///\param G is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient to initialize - static PredMap *createPredMap(const GR &G) + static PredMap *createPredMap(const GR &G) { return new PredMap(G); } ///The type of the map that indicates which nodes are processed. - + ///The type of the map that indicates which nodes are processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \ref ProcessedMap. + + ///This function instantiates a \ref ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \ref ProcessedMap #ifdef DOXYGEN @@ -82,14 +82,14 @@ return new ProcessedMap(); } ///The type of the map that indicates which nodes are reached. - + ///The type of the map that indicates which nodes are reached. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef typename Digraph::template NodeMap ReachedMap; ///Instantiates a ReachedMap. - - ///This function instantiates a \ref ReachedMap. + + ///This function instantiates a \ref ReachedMap. ///\param G is the digraph, to which ///we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const GR &G) @@ -97,23 +97,23 @@ return new ReachedMap(G); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param G is the digraph, to which we would like to define the \ref DistMap static DistMap *createDistMap(const GR &G) { return new DistMap(G); } }; - + ///%DFS algorithm class. - + ///\ingroup search ///This class provides an efficient implementation of the %DFS algorithm. /// @@ -127,10 +127,10 @@ ///a Dfs traits class. #ifdef DOXYGEN template + typename TR> #else template > + typename TR=DfsDefaultTraits > #endif class Dfs { public: @@ -143,7 +143,7 @@ class UninitializedParameter : public lemon::UninitializedParameter { public: virtual const char* what() const throw() { - return "lemon::Dfs::UninitializedParameter"; + return "lemon::Dfs::UninitializedParameter"; } }; @@ -158,7 +158,7 @@ typedef typename Digraph::Arc Arc; ///\e typedef typename Digraph::OutArcIt OutArcIt; - + ///\brief The type of the map that stores the last ///arcs of the %DFS paths. typedef typename TR::PredMap PredMap; @@ -192,32 +192,32 @@ int _stack_head; ///Creates the maps if necessary. - + ///\todo Better memory allocation (instead of new). - void create_maps() + void create_maps() { if(!_pred) { - local_pred = true; - _pred = Traits::createPredMap(*G); + local_pred = true; + _pred = Traits::createPredMap(*G); } if(!_dist) { - local_dist = true; - _dist = Traits::createDistMap(*G); + local_dist = true; + _dist = Traits::createDistMap(*G); } if(!_reached) { - local_reached = true; - _reached = Traits::createReachedMap(*G); + local_reached = true; + _reached = Traits::createReachedMap(*G); } if(!_processed) { - local_processed = true; - _processed = Traits::createProcessedMap(*G); + local_processed = true; + _processed = Traits::createProcessedMap(*G); } } protected: Dfs() {} - + public: typedef Dfs Create; @@ -229,9 +229,9 @@ template struct DefPredMapTraits : public Traits { typedef T PredMap; - static PredMap *createPredMap(const Digraph &G) + static PredMap *createPredMap(const Digraph &G) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -243,14 +243,14 @@ struct DefPredMap : public Dfs > { typedef Dfs > Create; }; - - + + template struct DefDistMapTraits : public Traits { typedef T DistMap; - static DistMap *createDistMap(const Digraph &) + static DistMap *createDistMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -262,13 +262,13 @@ struct DefDistMap { typedef Dfs > Create; }; - + template struct DefReachedMapTraits : public Traits { typedef T ReachedMap; - static ReachedMap *createReachedMap(const Digraph &) + static ReachedMap *createReachedMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -284,9 +284,9 @@ template struct DefProcessedMapTraits : public Traits { typedef T ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &) + static ProcessedMap *createProcessedMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting @@ -295,15 +295,15 @@ ///\ref named-templ-param "Named parameter" for setting ProcessedMap type /// template - struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits > { + struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits > { typedef Dfs< Digraph, DefProcessedMapTraits > Create; }; - + struct DefDigraphProcessedMapTraits : public Traits { typedef typename Digraph::template NodeMap ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &G) + static ProcessedMap *createProcessedMap(const Digraph &G) { - return new ProcessedMap(G); + return new ProcessedMap(G); } }; ///\brief \ref named-templ-param "Named parameter" @@ -314,16 +314,16 @@ ///If you don't set it explicitely, it will be automatically allocated. template class DefProcessedMapToBeDefaultMap : - public Dfs< Digraph, DefDigraphProcessedMapTraits> { + public Dfs< Digraph, DefDigraphProcessedMapTraits> { typedef Dfs< Digraph, DefDigraphProcessedMapTraits> Create; }; - + ///@} - public: - + public: + ///Constructor. - + ///\param _G the digraph the algorithm will run on. /// Dfs(const Digraph& _G) : @@ -333,9 +333,9 @@ _reached(NULL), local_reached(false), _processed(NULL), local_processed(false) { } - + ///Destructor. - ~Dfs() + ~Dfs() { if(local_pred) delete _pred; if(local_dist) delete _dist; @@ -350,11 +350,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dfs &predMap(PredMap &m) + Dfs &predMap(PredMap &m) { if(local_pred) { - delete _pred; - local_pred=false; + delete _pred; + local_pred=false; } _pred = &m; return *this; @@ -367,11 +367,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dfs &distMap(DistMap &m) + Dfs &distMap(DistMap &m) { if(local_dist) { - delete _dist; - local_dist=false; + delete _dist; + local_dist=false; } _dist = &m; return *this; @@ -384,11 +384,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dfs &reachedMap(ReachedMap &m) + Dfs &reachedMap(ReachedMap &m) { if(local_reached) { - delete _reached; - local_reached=false; + delete _reached; + local_reached=false; } _reached = &m; return *this; @@ -401,11 +401,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dfs &processedMap(ProcessedMap &m) + Dfs &processedMap(ProcessedMap &m) { if(local_processed) { - delete _processed; - local_processed=false; + delete _processed; + local_processed=false; } _processed = &m; return *this; @@ -434,13 +434,13 @@ _stack.resize(countNodes(*G)); _stack_head=-1; for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { - _pred->set(u,INVALID); - // _predNode->set(u,INVALID); - _reached->set(u,false); - _processed->set(u,false); + _pred->set(u,INVALID); + // _predNode->set(u,INVALID); + _reached->set(u,false); + _processed->set(u,false); } } - + ///Adds a new source node. ///Adds a new source node to the set of nodes to be processed. @@ -450,21 +450,21 @@ void addSource(Node s) { if(!(*_reached)[s]) - { - _reached->set(s,true); - _pred->set(s,INVALID); - OutArcIt e(*G,s); - if(e!=INVALID) { - _stack[++_stack_head]=e; - _dist->set(s,_stack_head); - } - else { - _processed->set(s,true); - _dist->set(s,0); - } - } + { + _reached->set(s,true); + _pred->set(s,INVALID); + OutArcIt e(*G,s); + if(e!=INVALID) { + _stack[++_stack_head]=e; + _dist->set(s,_stack_head); + } + else { + _processed->set(s,true); + _dist->set(s,0); + } + } } - + ///Processes the next arc. ///Processes the next arc. @@ -473,27 +473,27 @@ /// ///\pre The stack must not be empty! Arc processNextArc() - { + { Node m; Arc e=_stack[_stack_head]; if(!(*_reached)[m=G->target(e)]) { - _pred->set(m,e); - _reached->set(m,true); - ++_stack_head; - _stack[_stack_head] = OutArcIt(*G, m); - _dist->set(m,_stack_head); + _pred->set(m,e); + _reached->set(m,true); + ++_stack_head; + _stack[_stack_head] = OutArcIt(*G, m); + _dist->set(m,_stack_head); } else { - m=G->source(e); - ++_stack[_stack_head]; + m=G->source(e); + ++_stack[_stack_head]; } while(_stack_head>=0 && _stack[_stack_head]==INVALID) { - _processed->set(m,true); - --_stack_head; - if(_stack_head>=0) { - m=G->source(_stack[_stack_head]); - ++_stack[_stack_head]; - } + _processed->set(m,true); + --_stack_head; + if(_stack_head>=0) { + m=G->source(_stack[_stack_head]); + ++_stack[_stack_head]; + } } return e; } @@ -504,7 +504,7 @@ ///\return The next arc to be processed or INVALID if the stack is /// empty. OutArcIt nextArc() - { + { return _stack_head>=0?_stack[_stack_head]:INVALID; } @@ -515,10 +515,10 @@ ///to be processed in the queue bool emptyQueue() { return _stack_head<0; } ///Returns the number of the nodes to be processed. - + ///Returns the number of the nodes to be processed in the queue. int queueSize() { return _stack_head+1; } - + ///Executes the algorithm. ///Executes the algorithm. @@ -537,7 +537,7 @@ { while ( !emptyQueue() ) processNextArc(); } - + ///Executes the algorithm until \c dest is reached. ///Executes the algorithm until \c dest is reached. @@ -554,10 +554,10 @@ /// void start(Node dest) { - while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest ) - processNextArc(); + while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest ) + processNextArc(); } - + ///Executes the algorithm until a condition is met. ///Executes the algorithm until a condition is met. @@ -582,7 +582,7 @@ } ///Runs %DFS algorithm to visit all nodes in the digraph. - + ///This method runs the %DFS algorithm in order to ///compute the ///%DFS path to each node. The algorithm computes @@ -610,7 +610,7 @@ } ///Runs %DFS algorithm from node \c s. - + ///This method runs the %DFS algorithm from a root node \c s ///in order to ///compute the @@ -629,9 +629,9 @@ addSource(s); start(); } - + ///Finds the %DFS path between \c s and \c t. - + ///Finds the %DFS path between \c s and \c t. /// ///\return The length of the %DFS s---t path if there exists one, @@ -649,7 +649,7 @@ start(t); return reached(t)?_stack_head+1:0; } - + ///@} ///\name Query Functions @@ -657,16 +657,16 @@ ///functions.\n ///Before the use of these functions, ///either run() or start() must be called. - + ///@{ typedef PredMapPath Path; ///Gives back the shortest path. - + ///Gives back the shortest path. ///\pre The \c t should be reachable from the source. - Path path(Node t) + Path path(Node t) { return Path(*G, *_pred, t); } @@ -675,7 +675,7 @@ ///Returns the distance of a node from the root(s). ///\pre \ref run() must be called before using this function. - ///\warning If node \c v is unreachable from the root(s) then the return + ///\warning If node \c v is unreachable from the root(s) then the return ///value of this funcion is undefined. int dist(Node v) const { return (*_dist)[v]; } @@ -705,15 +705,15 @@ ///\pre Either \ref run() or \ref start() must be called before ///using this function. Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: - G->source((*_pred)[v]); } - + G->source((*_pred)[v]); } + ///Returns a reference to the NodeMap of distances. ///Returns a reference to the NodeMap of distances. ///\pre Either \ref run() or \ref init() must ///be called before using this function. const DistMap &distMap() const { return *_dist;} - + ///Returns a reference to the %DFS arc-tree map. ///Returns a reference to the NodeMap of the arcs of the @@ -721,7 +721,7 @@ ///\pre Either \ref run() or \ref init() ///must be called before using this function. const PredMap &predMap() const { return *_pred;} - + ///Checks if a node is reachable from the root. ///Returns \c true if \c v is reachable from the root(s). @@ -730,7 +730,7 @@ ///must be called before using this function. /// bool reached(Node v) { return (*_reached)[v]; } - + ///@} }; @@ -741,39 +741,39 @@ template struct DfsWizardDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///\brief The type of the map that stores the last ///arcs of the %DFS paths. - /// + /// ///The type of the map that stores the last ///arcs of the %DFS paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \ref PredMap. + + ///This function instantiates a \ref PredMap. ///\param g is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient to initialize #ifdef DOXYGEN - static PredMap *createPredMap(const GR &g) + static PredMap *createPredMap(const GR &g) #else - static PredMap *createPredMap(const GR &) + static PredMap *createPredMap(const GR &) #endif { return new PredMap(); } ///The type of the map that indicates which nodes are processed. - + ///The type of the map that indicates which nodes are processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \ref ProcessedMap. + + ///This function instantiates a \ref ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \ref ProcessedMap #ifdef DOXYGEN @@ -785,14 +785,14 @@ return new ProcessedMap(); } ///The type of the map that indicates which nodes are reached. - + ///The type of the map that indicates which nodes are reached. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///\todo named parameter to set this type, function to read and write. typedef typename Digraph::template NodeMap ReachedMap; ///Instantiates a ReachedMap. - - ///This function instantiates a \ref ReachedMap. + + ///This function instantiates a \ref ReachedMap. ///\param G is the digraph, to which ///we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const GR &G) @@ -800,14 +800,14 @@ return new ReachedMap(G); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param g is the digraph, to which we would like to define the \ref DistMap #ifdef DOXYGEN static DistMap *createDistMap(const GR &g) @@ -818,7 +818,7 @@ return new DistMap(); } }; - + /// Default traits used by \ref DfsWizard /// To make it easier to use Dfs algorithm @@ -848,28 +848,28 @@ void *_dist; ///Pointer to the source node. Node _source; - + public: /// Constructor. - + /// This constructor does not require parameters, therefore it initiates /// all of the attributes to default values (0, INVALID). DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), - _dist(0), _source(INVALID) {} + _dist(0), _source(INVALID) {} /// Constructor. - + /// This constructor requires some parameters, /// listed in the parameters list. /// Others are initiated to 0. /// \param g is the initial value of \ref _g /// \param s is the initial value of \ref _source DfsWizardBase(const GR &g, Node s=INVALID) : - _g(reinterpret_cast(const_cast(&g))), + _g(reinterpret_cast(const_cast(&g))), _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {} }; - + /// A class to make the usage of the Dfs algorithm easier /// This class is created to make it easier to use the Dfs algorithm. @@ -904,7 +904,7 @@ typedef typename Digraph::Arc Arc; //\e typedef typename Digraph::OutArcIt OutArcIt; - + ///\brief The type of the map that stores ///the reached nodes typedef typename TR::ReachedMap ReachedMap; @@ -934,20 +934,20 @@ ~DfsWizard() {} ///Runs Dfs algorithm from a given node. - + ///Runs Dfs algorithm from a given node. ///The node can be given by the \ref source function. void run() { if(Base::_source==INVALID) throw UninitializedParameter(); Dfs alg(*reinterpret_cast(Base::_g)); - if(Base::_reached) + if(Base::_reached) alg.reachedMap(*reinterpret_cast(Base::_reached)); - if(Base::_processed) + if(Base::_processed) alg.processedMap(*reinterpret_cast(Base::_processed)); - if(Base::_pred) + if(Base::_pred) alg.predMap(*reinterpret_cast(Base::_pred)); - if(Base::_dist) + if(Base::_dist) alg.distMap(*reinterpret_cast(Base::_dist)); alg.run(Base::_source); } @@ -968,7 +968,7 @@ static PredMap *createPredMap(const Digraph &) { return 0; }; DefPredMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting PredMap type /// @@ -976,20 +976,20 @@ ///function for setting PredMap type /// template - DfsWizard > predMap(const T &t) + DfsWizard > predMap(const T &t) { Base::_pred=reinterpret_cast(const_cast(&t)); return DfsWizard >(*this); } - - + + template struct DefReachedMapBase : public Base { typedef T ReachedMap; static ReachedMap *createReachedMap(const Digraph &) { return 0; }; DefReachedMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting ReachedMap /// @@ -997,12 +997,12 @@ ///function for setting ReachedMap /// template - DfsWizard > reachedMap(const T &t) + DfsWizard > reachedMap(const T &t) { Base::_reached=reinterpret_cast(const_cast(&t)); return DfsWizard >(*this); } - + template struct DefProcessedMapBase : public Base { @@ -1010,7 +1010,7 @@ static ProcessedMap *createProcessedMap(const Digraph &) { return 0; }; DefProcessedMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting ProcessedMap /// @@ -1018,19 +1018,19 @@ ///function for setting ProcessedMap /// template - DfsWizard > processedMap(const T &t) + DfsWizard > processedMap(const T &t) { Base::_processed=reinterpret_cast(const_cast(&t)); return DfsWizard >(*this); } - + template struct DefDistMapBase : public Base { typedef T DistMap; static DistMap *createDistMap(const Digraph &) { return 0; }; DefDistMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting DistMap type /// @@ -1038,24 +1038,24 @@ ///function for setting DistMap type /// template - DfsWizard > distMap(const T &t) + DfsWizard > distMap(const T &t) { Base::_dist=reinterpret_cast(const_cast(&t)); return DfsWizard >(*this); } - + /// Sets the source node, from which the Dfs algorithm runs. /// Sets the source node, from which the Dfs algorithm runs. /// \param s is the source node. - DfsWizard &source(Node s) + DfsWizard &source(Node s) { Base::_source=s; return *this; } - + }; - + ///Function type interface for Dfs algorithm. ///\ingroup search @@ -1082,43 +1082,43 @@ #ifdef DOXYGEN /// \brief Visitor class for dfs. - /// - /// It gives a simple interface for a functional interface for dfs - /// traversal. The traversal on a linear data structure. + /// + /// It gives a simple interface for a functional interface for dfs + /// traversal. The traversal on a linear data structure. template struct DfsVisitor { typedef _Digraph Digraph; typedef typename Digraph::Arc Arc; typedef typename Digraph::Node Node; /// \brief Called when the arc reach a node. - /// + /// /// It is called when the dfs find an arc which target is not /// reached yet. void discover(const Arc& arc) {} /// \brief Called when the node reached first time. - /// + /// /// It is Called when the node reached first time. void reach(const Node& node) {} /// \brief Called when we step back on an arc. - /// + /// /// It is called when the dfs should step back on the arc. void backtrack(const Arc& arc) {} /// \brief Called when we step back from the node. - /// + /// /// It is called when we step back from the node. void leave(const Node& node) {} - /// \brief Called when the arc examined but target of the arc + /// \brief Called when the arc examined but target of the arc /// already discovered. - /// - /// It called when the arc examined but the target of the arc + /// + /// It called when the arc examined but the target of the arc /// already discovered. void examine(const Arc& arc) {} /// \brief Called for the source node of the dfs. - /// + /// /// It is called for the source node of the dfs. void start(const Node& node) {} /// \brief Called when we leave the source node of the dfs. - /// + /// /// It is called when we leave the source node of the dfs. void stop(const Node& node) {} @@ -1140,15 +1140,15 @@ template struct Constraints { void constraints() { - Arc arc; - Node node; - visitor.discover(arc); - visitor.reach(node); - visitor.backtrack(arc); - visitor.leave(node); - visitor.examine(arc); - visitor.start(node); - visitor.stop(arc); + Arc arc; + Node node; + visitor.discover(arc); + visitor.reach(node); + visitor.backtrack(arc); + visitor.leave(node); + visitor.examine(arc); + visitor.start(node); + visitor.stop(arc); } _Visitor& visitor; }; @@ -1162,11 +1162,11 @@ template struct DfsVisitDefaultTraits { - /// \brief The digraph type the algorithm runs on. + /// \brief The digraph type the algorithm runs on. typedef _Digraph Digraph; /// \brief The type of the map that indicates which nodes are reached. - /// + /// /// The type of the map that indicates which nodes are reached. /// It must meet the \ref concepts::WriteMap "WriteMap" concept. /// \todo named parameter to set this type, function to read and write. @@ -1174,7 +1174,7 @@ /// \brief Instantiates a ReachedMap. /// - /// This function instantiates a \ref ReachedMap. + /// This function instantiates a \ref ReachedMap. /// \param digraph is the digraph, to which /// we would like to define the \ref ReachedMap. static ReachedMap *createReachedMap(const Digraph &digraph) { @@ -1182,25 +1182,25 @@ } }; - + /// %DFS Visit algorithm class. - + /// \ingroup search /// This class provides an efficient implementation of the %DFS algorithm /// with visitor interface. /// /// The %DfsVisit class provides an alternative interface to the Dfs /// class. It works with callback mechanism, the DfsVisit object calls - /// on every dfs event the \c Visitor class member functions. + /// on every dfs event the \c Visitor class member functions. /// /// \tparam _Digraph The digraph type the algorithm runs on. The default value is /// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it /// is only passed to \ref DfsDefaultTraits. - /// \tparam _Visitor The Visitor object for the algorithm. The + /// \tparam _Visitor The Visitor object for the algorithm. The /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which /// does not observe the Dfs events. If you want to observe the dfs /// events you should implement your own Visitor class. - /// \tparam _Traits Traits class to set various data types used by the + /// \tparam _Traits Traits class to set various data types used by the /// algorithm. The default traits class is /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>". /// See \ref DfsVisitDefaultTraits for the documentation of @@ -1211,21 +1211,21 @@ template #else template , - typename _Traits = DfsDefaultTraits<_Digraph> > + typename _Visitor = DfsVisitor<_Digraph>, + typename _Traits = DfsDefaultTraits<_Digraph> > #endif class DfsVisit { public: - + /// \brief \ref Exception for uninitialized parameters. /// /// This error represents problems in the initialization /// of the parameters of the algorithms. class UninitializedParameter : public lemon::UninitializedParameter { public: - virtual const char* what() const throw() + virtual const char* what() const throw() { - return "lemon::DfsVisit::UninitializedParameter"; + return "lemon::DfsVisit::UninitializedParameter"; } }; @@ -1262,15 +1262,15 @@ /// Creates the maps if necessary. void create_maps() { if(!_reached) { - local_reached = true; - _reached = Traits::createReachedMap(*_digraph); + local_reached = true; + _reached = Traits::createReachedMap(*_digraph); } } protected: DfsVisit() {} - + public: typedef DfsVisit Create; @@ -1282,22 +1282,22 @@ struct DefReachedMapTraits : public Traits { typedef T ReachedMap; static ReachedMap *createReachedMap(const Digraph &digraph) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; - /// \brief \ref named-templ-param "Named parameter" for setting + /// \brief \ref named-templ-param "Named parameter" for setting /// ReachedMap type /// /// \ref named-templ-param "Named parameter" for setting ReachedMap type template struct DefReachedMap : public DfsVisit< Digraph, Visitor, - DefReachedMapTraits > { + DefReachedMapTraits > { typedef DfsVisit< Digraph, Visitor, DefReachedMapTraits > Create; }; ///@} - public: - + public: + /// \brief Constructor. /// /// Constructor. @@ -1305,10 +1305,10 @@ /// \param digraph the digraph the algorithm will run on. /// \param visitor The visitor of the algorithm. /// - DfsVisit(const Digraph& digraph, Visitor& visitor) + DfsVisit(const Digraph& digraph, Visitor& visitor) : _digraph(&digraph), _visitor(&visitor), - _reached(0), local_reached(false) {} - + _reached(0), local_reached(false) {} + /// \brief Destructor. /// /// Destructor. @@ -1325,8 +1325,8 @@ /// \return (*this) DfsVisit &reachedMap(ReachedMap &m) { if(local_reached) { - delete _reached; - local_reached=false; + delete _reached; + local_reached=false; } _reached = &m; return *this; @@ -1353,28 +1353,28 @@ _stack.resize(countNodes(*_digraph)); _stack_head = -1; for (NodeIt u(*_digraph) ; u != INVALID ; ++u) { - _reached->set(u, false); + _reached->set(u, false); } } - + /// \brief Adds a new source node. /// /// Adds a new source node to the set of nodes to be processed. void addSource(Node s) { if(!(*_reached)[s]) { - _reached->set(s,true); - _visitor->start(s); - _visitor->reach(s); - Arc e; - _digraph->firstOut(e, s); - if (e != INVALID) { - _stack[++_stack_head] = e; - } else { - _visitor->leave(s); - } - } + _reached->set(s,true); + _visitor->start(s); + _visitor->reach(s); + Arc e; + _digraph->firstOut(e, s); + if (e != INVALID) { + _stack[++_stack_head] = e; + } else { + _visitor->leave(s); + } + } } - + /// \brief Processes the next arc. /// /// Processes the next arc. @@ -1382,29 +1382,29 @@ /// \return The processed arc. /// /// \pre The stack must not be empty! - Arc processNextArc() { + Arc processNextArc() { Arc e = _stack[_stack_head]; Node m = _digraph->target(e); if(!(*_reached)[m]) { - _visitor->discover(e); - _visitor->reach(m); - _reached->set(m, true); - _digraph->firstOut(_stack[++_stack_head], m); + _visitor->discover(e); + _visitor->reach(m); + _reached->set(m, true); + _digraph->firstOut(_stack[++_stack_head], m); } else { - _visitor->examine(e); - m = _digraph->source(e); - _digraph->nextOut(_stack[_stack_head]); + _visitor->examine(e); + m = _digraph->source(e); + _digraph->nextOut(_stack[_stack_head]); } while (_stack_head>=0 && _stack[_stack_head] == INVALID) { - _visitor->leave(m); - --_stack_head; - if (_stack_head >= 0) { - _visitor->backtrack(_stack[_stack_head]); - m = _digraph->source(_stack[_stack_head]); - _digraph->nextOut(_stack[_stack_head]); - } else { - _visitor->stop(m); - } + _visitor->leave(m); + --_stack_head; + if (_stack_head >= 0) { + _visitor->backtrack(_stack[_stack_head]); + m = _digraph->source(_stack[_stack_head]); + _digraph->nextOut(_stack[_stack_head]); + } else { + _visitor->stop(m); + } } return e; } @@ -1415,7 +1415,7 @@ /// /// \return The next arc to be processed or INVALID if the stack is /// empty. - Arc nextArc() { + Arc nextArc() { return _stack_head >= 0 ? _stack[_stack_head] : INVALID; } @@ -1430,7 +1430,7 @@ /// /// Returns the number of the nodes to be processed in the queue. int queueSize() { return _stack_head + 1; } - + /// \brief Executes the algorithm. /// /// Executes the algorithm. @@ -1440,7 +1440,7 @@ void start() { while ( !emptyQueue() ) processNextArc(); } - + /// \brief Executes the algorithm until \c dest is reached. /// /// Executes the algorithm until \c dest is reached. @@ -1448,10 +1448,10 @@ /// \pre init() must be called and at least one node should be added /// with addSource() before using this function. void start(Node dest) { - while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != dest ) - processNextArc(); + while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != dest ) + processNextArc(); } - + /// \brief Executes the algorithm until a condition is met. /// /// Executes the algorithm until a condition is met. @@ -1490,7 +1490,7 @@ } /// \brief Runs %DFSVisit algorithm to visit all nodes in the digraph. - + /// This method runs the %DFS algorithm in order to /// compute the %DFS path to each node. The algorithm computes /// - The %DFS tree. diff -r 4317d277ba21 -r 765619b7cbb2 lemon/dijkstra.h --- a/lemon/dijkstra.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/dijkstra.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -34,7 +34,7 @@ namespace lemon { /// \brief Default OperationTraits for the Dijkstra algorithm class. - /// + /// /// It defines all computational operations and constants which are /// used in the Dijkstra algorithm. template @@ -54,7 +54,7 @@ }; /// \brief Widest path OperationTraits for the Dijkstra algorithm class. - /// + /// /// It defines all computational operations and constants which are /// used in the Dijkstra algorithm for widest path computation. template @@ -72,7 +72,7 @@ return left < right; } }; - + ///Default traits class of Dijkstra class. ///Default traits class of Dijkstra class. @@ -81,7 +81,7 @@ template struct DijkstraDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///The type of the map that stores the arc lengths. @@ -103,14 +103,14 @@ typedef typename Digraph::template NodeMap HeapCrossRef; ///Instantiates a HeapCrossRef. - ///This function instantiates a \c HeapCrossRef. - /// \param G is the digraph, to which we would like to define the + ///This function instantiates a \c HeapCrossRef. + /// \param G is the digraph, to which we would like to define the /// HeapCrossRef. - static HeapCrossRef *createHeapCrossRef(const GR &G) + static HeapCrossRef *createHeapCrossRef(const GR &G) { return new HeapCrossRef(G); } - + ///The heap type used by Dijkstra algorithm. ///The heap type used by Dijkstra algorithm. @@ -119,31 +119,31 @@ ///\sa Dijkstra typedef BinHeap > Heap; - static Heap *createHeap(HeapCrossRef& R) + static Heap *createHeap(HeapCrossRef& R) { return new Heap(R); } ///\brief The type of the map that stores the last ///arcs of the shortest paths. - /// + /// ///The type of the map that stores the last ///arcs of the shortest paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \c PredMap. + + ///This function instantiates a \c PredMap. ///\param G is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient for the initialization - static PredMap *createPredMap(const GR &G) + static PredMap *createPredMap(const GR &G) { return new PredMap(G); } ///The type of the map that stores whether a nodes is processed. - + ///The type of the map that stores whether a nodes is processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///By default it is a NullMap. @@ -152,8 +152,8 @@ ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \c ProcessedMap. + + ///This function instantiates a \c ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \c ProcessedMap #ifdef DOXYGEN @@ -165,23 +165,23 @@ return new ProcessedMap(); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef typename Digraph::template NodeMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param G is the digraph, to which we would like to define the \ref DistMap static DistMap *createDistMap(const GR &G) { return new DistMap(G); } }; - + ///%Dijkstra algorithm class. - + /// \ingroup shortest_path ///This class provides an efficient implementation of %Dijkstra algorithm. ///The arc lengths are passed to the algorithm using a @@ -202,7 +202,7 @@ ///it is necessary. The default map type is \ref ///concepts::Digraph::ArcMap "Digraph::ArcMap". The value ///of LM is not used directly by Dijkstra, it is only passed to \ref - ///DijkstraDefaultTraits. + ///DijkstraDefaultTraits. ///\tparam TR Traits class to set ///various data types used by the algorithm. The default traits ///class is \ref DijkstraDefaultTraits @@ -214,8 +214,8 @@ template #else template , - typename TR=DijkstraDefaultTraits > + typename LM=typename GR::template ArcMap, + typename TR=DijkstraDefaultTraits > #endif class Dijkstra { public: @@ -228,7 +228,7 @@ class UninitializedParameter : public lemon::UninitializedParameter { public: virtual const char* what() const throw() { - return "lemon::Dijkstra::UninitializedParameter"; + return "lemon::Dijkstra::UninitializedParameter"; } }; @@ -243,7 +243,7 @@ typedef typename Digraph::Arc Arc; ///\e typedef typename Digraph::OutArcIt OutArcIt; - + ///The type of the length of the arcs. typedef typename TR::LengthMap::Value Value; ///The type of the map that stores the arc lengths. @@ -288,36 +288,36 @@ bool local_heap; ///Creates the maps if necessary. - + ///\todo Better memory allocation (instead of new). - void create_maps() + void create_maps() { if(!_pred) { - local_pred = true; - _pred = Traits::createPredMap(*G); + local_pred = true; + _pred = Traits::createPredMap(*G); } if(!_dist) { - local_dist = true; - _dist = Traits::createDistMap(*G); + local_dist = true; + _dist = Traits::createDistMap(*G); } if(!_processed) { - local_processed = true; - _processed = Traits::createProcessedMap(*G); + local_processed = true; + _processed = Traits::createProcessedMap(*G); } if (!_heap_cross_ref) { - local_heap_cross_ref = true; - _heap_cross_ref = Traits::createHeapCrossRef(*G); + local_heap_cross_ref = true; + _heap_cross_ref = Traits::createHeapCrossRef(*G); } if (!_heap) { - local_heap = true; - _heap = Traits::createHeap(*_heap_cross_ref); + local_heap = true; + _heap = Traits::createHeap(*_heap_cross_ref); } } - + public : typedef Dijkstra Create; - + ///\name Named template parameters ///@{ @@ -327,7 +327,7 @@ typedef T PredMap; static PredMap *createPredMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\ref named-templ-param "Named parameter" for setting PredMap type @@ -335,17 +335,17 @@ ///\ref named-templ-param "Named parameter" for setting PredMap type /// template - struct DefPredMap - : public Dijkstra< Digraph, LengthMap, DefPredMapTraits > { - typedef Dijkstra< Digraph, LengthMap, DefPredMapTraits > Create; + struct DefPredMap + : public Dijkstra< Digraph, LengthMap, DefPredMapTraits > { + typedef Dijkstra< Digraph, LengthMap, DefPredMapTraits > Create; }; - + template struct DefDistMapTraits : public Traits { typedef T DistMap; static DistMap *createDistMap(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\ref named-templ-param "Named parameter" for setting DistMap type @@ -353,17 +353,17 @@ ///\ref named-templ-param "Named parameter" for setting DistMap type /// template - struct DefDistMap - : public Dijkstra< Digraph, LengthMap, DefDistMapTraits > { + struct DefDistMap + : public Dijkstra< Digraph, LengthMap, DefDistMapTraits > { typedef Dijkstra< Digraph, LengthMap, DefDistMapTraits > Create; }; - + template struct DefProcessedMapTraits : public Traits { typedef T ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &G) + static ProcessedMap *createProcessedMap(const Digraph &G) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\ref named-templ-param "Named parameter" for setting ProcessedMap type @@ -371,16 +371,16 @@ ///\ref named-templ-param "Named parameter" for setting ProcessedMap type /// template - struct DefProcessedMap - : public Dijkstra< Digraph, LengthMap, DefProcessedMapTraits > { - typedef Dijkstra< Digraph, LengthMap, DefProcessedMapTraits > Create; + struct DefProcessedMap + : public Dijkstra< Digraph, LengthMap, DefProcessedMapTraits > { + typedef Dijkstra< Digraph, LengthMap, DefProcessedMapTraits > Create; }; - + struct DefDigraphProcessedMapTraits : public Traits { typedef typename Digraph::template NodeMap ProcessedMap; - static ProcessedMap *createProcessedMap(const Digraph &G) + static ProcessedMap *createProcessedMap(const Digraph &G) { - return new ProcessedMap(G); + return new ProcessedMap(G); } }; ///\brief \ref named-templ-param "Named parameter" @@ -390,7 +390,7 @@ ///for setting the ProcessedMap type to be Digraph::NodeMap. ///If you don't set it explicitely, it will be automatically allocated. template - struct DefProcessedMapToBeDefaultMap + struct DefProcessedMapToBeDefaultMap : public Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> { typedef Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> Create; }; @@ -400,23 +400,23 @@ typedef CR HeapCrossRef; typedef H Heap; static HeapCrossRef *createHeapCrossRef(const Digraph &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } - static Heap *createHeap(HeapCrossRef &) + static Heap *createHeap(HeapCrossRef &) { - throw UninitializedParameter(); + throw UninitializedParameter(); } }; ///\brief \ref named-templ-param "Named parameter" for setting ///heap and cross reference type /// - ///\ref named-templ-param "Named parameter" for setting heap and cross + ///\ref named-templ-param "Named parameter" for setting heap and cross ///reference type /// template > struct DefHeap - : public Dijkstra< Digraph, LengthMap, DefHeapTraits > { - typedef Dijkstra< Digraph, LengthMap, DefHeapTraits > Create; + : public Dijkstra< Digraph, LengthMap, DefHeapTraits > { + typedef Dijkstra< Digraph, LengthMap, DefHeapTraits > Create; }; template @@ -424,24 +424,24 @@ typedef CR HeapCrossRef; typedef H Heap; static HeapCrossRef *createHeapCrossRef(const Digraph &G) { - return new HeapCrossRef(G); + return new HeapCrossRef(G); } - static Heap *createHeap(HeapCrossRef &R) + static Heap *createHeap(HeapCrossRef &R) { - return new Heap(R); + return new Heap(R); } }; ///\brief \ref named-templ-param "Named parameter" for setting ///heap and cross reference type with automatic allocation /// - ///\ref named-templ-param "Named parameter" for setting heap and cross - ///reference type. It can allocate the heap and the cross reference - ///object if the cross reference's constructor waits for the digraph as + ///\ref named-templ-param "Named parameter" for setting heap and cross + ///reference type. It can allocate the heap and the cross reference + ///object if the cross reference's constructor waits for the digraph as ///parameter and the heap's constructor waits for the cross reference. template > struct DefStandardHeap - : public Dijkstra< Digraph, LengthMap, DefStandardHeapTraits > { - typedef Dijkstra< Digraph, LengthMap, DefStandardHeapTraits > + : public Dijkstra< Digraph, LengthMap, DefStandardHeapTraits > { + typedef Dijkstra< Digraph, LengthMap, DefStandardHeapTraits > Create; }; @@ -449,8 +449,8 @@ struct DefOperationTraitsTraits : public Traits { typedef T OperationTraits; }; - - /// \brief \ref named-templ-param "Named parameter" for setting + + /// \brief \ref named-templ-param "Named parameter" for setting /// OperationTraits type /// /// \ref named-templ-param "Named parameter" for setting OperationTraits @@ -461,7 +461,7 @@ typedef Dijkstra > Create; }; - + ///@} @@ -469,10 +469,10 @@ Dijkstra() {} - public: - + public: + ///Constructor. - + ///\param _G the digraph the algorithm will run on. ///\param _length the length map used by the algorithm. Dijkstra(const Digraph& _G, const LengthMap& _length) : @@ -483,9 +483,9 @@ _heap_cross_ref(NULL), local_heap_cross_ref(false), _heap(NULL), local_heap(false) { } - + ///Destructor. - ~Dijkstra() + ~Dijkstra() { if(local_pred) delete _pred; if(local_dist) delete _dist; @@ -498,7 +498,7 @@ ///Sets the length map. ///\return (*this) - Dijkstra &lengthMap(const LengthMap &m) + Dijkstra &lengthMap(const LengthMap &m) { length = &m; return *this; @@ -511,11 +511,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dijkstra &predMap(PredMap &m) + Dijkstra &predMap(PredMap &m) { if(local_pred) { - delete _pred; - local_pred=false; + delete _pred; + local_pred=false; } _pred = &m; return *this; @@ -528,11 +528,11 @@ ///it will allocate one. The destuctor deallocates this ///automatically allocated map, of course. ///\return (*this) - Dijkstra &distMap(DistMap &m) + Dijkstra &distMap(DistMap &m) { if(local_dist) { - delete _dist; - local_dist=false; + delete _dist; + local_dist=false; } _dist = &m; return *this; @@ -548,13 +548,13 @@ Dijkstra &heap(Heap& hp, HeapCrossRef &cr) { if(local_heap_cross_ref) { - delete _heap_cross_ref; - local_heap_cross_ref=false; + delete _heap_cross_ref; + local_heap_cross_ref=false; } _heap_cross_ref = &cr; if(local_heap) { - delete _heap; - local_heap=false; + delete _heap; + local_heap=false; } _heap = &hp; return *this; @@ -592,12 +592,12 @@ create_maps(); _heap->clear(); for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { - _pred->set(u,INVALID); - _processed->set(u,false); - _heap_cross_ref->set(u,Heap::PRE_HEAP); + _pred->set(u,INVALID); + _processed->set(u,false); + _heap_cross_ref->set(u,Heap::PRE_HEAP); } } - + ///Adds a new source node. ///Adds a new source node to the priority heap. @@ -610,13 +610,13 @@ void addSource(Node s,Value dst=OperationTraits::zero()) { if(_heap->state(s) != Heap::IN_HEAP) { - _heap->push(s,dst); + _heap->push(s,dst); } else if(OperationTraits::less((*_heap)[s], dst)) { - _heap->set(s,dst); - _pred->set(s,INVALID); + _heap->set(s,dst); + _pred->set(s,INVALID); } } - + ///Processes the next node in the priority heap ///Processes the next node in the priority heap. @@ -626,45 +626,45 @@ ///\warning The priority heap must not be empty! Node processNextNode() { - Node v=_heap->top(); + Node v=_heap->top(); Value oldvalue=_heap->prio(); _heap->pop(); finalizeNodeData(v,oldvalue); - + for(OutArcIt e(*G,v); e!=INVALID; ++e) { - Node w=G->target(e); - switch(_heap->state(w)) { - case Heap::PRE_HEAP: - _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e])); - _pred->set(w,e); - break; - case Heap::IN_HEAP: - { - Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]); - if ( OperationTraits::less(newvalue, (*_heap)[w]) ) { - _heap->decrease(w, newvalue); - _pred->set(w,e); - } - } - break; - case Heap::POST_HEAP: - break; - } + Node w=G->target(e); + switch(_heap->state(w)) { + case Heap::PRE_HEAP: + _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e])); + _pred->set(w,e); + break; + case Heap::IN_HEAP: + { + Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]); + if ( OperationTraits::less(newvalue, (*_heap)[w]) ) { + _heap->decrease(w, newvalue); + _pred->set(w,e); + } + } + break; + case Heap::POST_HEAP: + break; + } } return v; } ///Next node to be processed. - + ///Next node to be processed. /// ///\return The next node to be processed or INVALID if the priority heap /// is empty. Node nextNode() - { + { return !_heap->empty()?_heap->top():INVALID; } - + ///\brief Returns \c false if there are nodes ///to be processed in the priority heap /// @@ -676,7 +676,7 @@ ///Returns the number of the nodes to be processed in the priority heap /// int queueSize() { return _heap->size(); } - + ///Executes the algorithm. ///Executes the algorithm. @@ -695,7 +695,7 @@ { while ( !_heap->empty() ) processNextNode(); } - + ///Executes the algorithm until \c dest is reached. ///Executes the algorithm until \c dest is reached. @@ -715,7 +715,7 @@ while ( !_heap->empty() && _heap->top()!=dest ) processNextNode(); if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio()); } - + ///Executes the algorithm until a condition is met. ///Executes the algorithm until a condition is met. @@ -736,9 +736,9 @@ finalizeNodeData(_heap->top(),_heap->prio()); return _heap->top(); } - + ///Runs %Dijkstra algorithm from node \c s. - + ///This method runs the %Dijkstra algorithm from a root node \c s ///in order to ///compute the @@ -757,9 +757,9 @@ addSource(s); start(); } - + ///Finds the shortest path between \c s and \c t. - + ///Finds the shortest path between \c s and \c t. /// ///\return The length of the shortest s---t path if there exists one, @@ -777,7 +777,7 @@ start(t); return (*_pred)[t]==INVALID?OperationTraits::zero():(*_dist)[t]; } - + ///@} ///\name Query Functions @@ -785,14 +785,14 @@ ///functions.\n ///Before the use of these functions, ///either run() or start() must be called. - + ///@{ ///Gives back the shortest path. - + ///Gives back the shortest path. ///\pre The \c t should be reachable from the source. - Path path(Node t) + Path path(Node t) { return Path(*G, *_pred, t); } @@ -832,21 +832,21 @@ ///tree used in \ref predArc(). \pre \ref run() must be called before ///using this function. Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: - G->source((*_pred)[v]); } - + G->source((*_pred)[v]); } + ///Returns a reference to the NodeMap of distances. ///Returns a reference to the NodeMap of distances. \pre \ref run() must ///be called before using this function. const DistMap &distMap() const { return *_dist;} - + ///Returns a reference to the shortest path tree map. ///Returns a reference to the NodeMap of the arcs of the ///shortest path tree. ///\pre \ref run() must be called before using this function. const PredMap &predMap() const { return *_pred;} - + ///Checks if a node is reachable from the root. ///Returns \c true if \c v is reachable from the root. @@ -862,14 +862,14 @@ ///\pre \ref run() must be called before using this function. /// bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; } - + ///@} }; - + ///Default traits class of Dijkstra function. ///Default traits class of Dijkstra function. @@ -878,7 +878,7 @@ template struct DijkstraWizardDefaultTraits { - ///The digraph type the algorithm runs on. + ///The digraph type the algorithm runs on. typedef GR Digraph; ///The type of the map that stores the arc lengths. @@ -901,15 +901,15 @@ typedef typename Digraph::template NodeMap HeapCrossRef; ///Instantiates a HeapCrossRef. - ///This function instantiates a \ref HeapCrossRef. - /// \param G is the digraph, to which we would like to define the + ///This function instantiates a \ref HeapCrossRef. + /// \param G is the digraph, to which we would like to define the /// HeapCrossRef. /// \todo The digraph alone may be insufficient for the initialization - static HeapCrossRef *createHeapCrossRef(const GR &G) + static HeapCrossRef *createHeapCrossRef(const GR &G) { return new HeapCrossRef(G); } - + ///The heap type used by Dijkstra algorithm. ///The heap type used by Dijkstra algorithm. @@ -917,36 +917,36 @@ ///\sa BinHeap ///\sa Dijkstra typedef BinHeap, - std::less > Heap; + std::less > Heap; - static Heap *createHeap(HeapCrossRef& R) + static Heap *createHeap(HeapCrossRef& R) { return new Heap(R); } ///\brief The type of the map that stores the last ///arcs of the shortest paths. - /// + /// ///The type of the map that stores the last ///arcs of the shortest paths. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap PredMap; ///Instantiates a PredMap. - - ///This function instantiates a \ref PredMap. + + ///This function instantiates a \ref PredMap. ///\param g is the digraph, to which we would like to define the PredMap. ///\todo The digraph alone may be insufficient for the initialization #ifdef DOXYGEN - static PredMap *createPredMap(const GR &g) + static PredMap *createPredMap(const GR &g) #else - static PredMap *createPredMap(const GR &) + static PredMap *createPredMap(const GR &) #endif { return new PredMap(); } ///The type of the map that stores whether a nodes is processed. - + ///The type of the map that stores whether a nodes is processed. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. ///By default it is a NullMap. @@ -955,8 +955,8 @@ ///\todo named parameter to set this type, function to read and write. typedef NullMap ProcessedMap; ///Instantiates a ProcessedMap. - - ///This function instantiates a \ref ProcessedMap. + + ///This function instantiates a \ref ProcessedMap. ///\param g is the digraph, to which ///we would like to define the \ref ProcessedMap #ifdef DOXYGEN @@ -968,14 +968,14 @@ return new ProcessedMap(); } ///The type of the map that stores the dists of the nodes. - + ///The type of the map that stores the dists of the nodes. ///It must meet the \ref concepts::WriteMap "WriteMap" concept. /// typedef NullMap DistMap; ///Instantiates a DistMap. - - ///This function instantiates a \ref DistMap. + + ///This function instantiates a \ref DistMap. ///\param g is the digraph, to which we would like to define the \ref DistMap #ifdef DOXYGEN static DistMap *createDistMap(const GR &g) @@ -986,7 +986,7 @@ return new DistMap(); } }; - + /// Default traits used by \ref DijkstraWizard /// To make it easier to use Dijkstra algorithm @@ -1018,14 +1018,14 @@ public: /// Constructor. - + /// This constructor does not require parameters, therefore it initiates /// all of the attributes to default values (0, INVALID). DijkstraWizardBase() : _g(0), _length(0), _pred(0), - _dist(0), _source(INVALID) {} + _dist(0), _source(INVALID) {} /// Constructor. - + /// This constructor requires some parameters, /// listed in the parameters list. /// Others are initiated to 0. @@ -1033,12 +1033,12 @@ /// \param l is the initial value of \ref _length /// \param s is the initial value of \ref _source DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) : - _g(reinterpret_cast(const_cast(&g))), - _length(reinterpret_cast(const_cast(&l))), + _g(reinterpret_cast(const_cast(&g))), + _length(reinterpret_cast(const_cast(&l))), _pred(0), _dist(0), _source(s) {} }; - + /// A class to make the usage of Dijkstra algorithm easier /// This class is created to make it easier to use Dijkstra algorithm. @@ -1056,7 +1056,7 @@ /// return the needed class. /// /// It does not have own \ref run method. When its \ref run method is called - /// it initiates a plain \ref Dijkstra class, and calls the \ref + /// it initiates a plain \ref Dijkstra class, and calls the \ref /// Dijkstra::run method of it. template class DijkstraWizard : public TR @@ -1073,7 +1073,7 @@ typedef typename Digraph::Arc Arc; //\e typedef typename Digraph::OutArcIt OutArcIt; - + ///The type of the map that stores the arc lengths. typedef typename TR::LengthMap LengthMap; ///The type of the length of the arcs. @@ -1102,14 +1102,14 @@ ~DijkstraWizard() {} ///Runs Dijkstra algorithm from a given node. - + ///Runs Dijkstra algorithm from a given node. ///The node can be given by the \ref source function. void run() { if(Base::_source==INVALID) throw UninitializedParameter(); - Dijkstra - dij(*reinterpret_cast(Base::_g), + Dijkstra + dij(*reinterpret_cast(Base::_g), *reinterpret_cast(Base::_length)); if(Base::_pred) dij.predMap(*reinterpret_cast(Base::_pred)); if(Base::_dist) dij.distMap(*reinterpret_cast(Base::_dist)); @@ -1132,7 +1132,7 @@ static PredMap *createPredMap(const Digraph &) { return 0; }; DefPredMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting PredMap type /// @@ -1140,19 +1140,19 @@ ///function for setting PredMap type /// template - DijkstraWizard > predMap(const T &t) + DijkstraWizard > predMap(const T &t) { Base::_pred=reinterpret_cast(const_cast(&t)); return DijkstraWizard >(*this); } - + template struct DefDistMapBase : public Base { typedef T DistMap; static DistMap *createDistMap(const Digraph &) { return 0; }; DefDistMapBase(const TR &b) : TR(b) {} }; - + ///\brief \ref named-templ-param "Named parameter" ///function for setting DistMap type /// @@ -1160,24 +1160,24 @@ ///function for setting DistMap type /// template - DijkstraWizard > distMap(const T &t) + DijkstraWizard > distMap(const T &t) { Base::_dist=reinterpret_cast(const_cast(&t)); return DijkstraWizard >(*this); } - + /// Sets the source node, from which the Dijkstra algorithm runs. /// Sets the source node, from which the Dijkstra algorithm runs. /// \param s is the source node. - DijkstraWizard &source(Node s) + DijkstraWizard &source(Node s) { Base::_source=s; return *this; } - + }; - + ///Function type interface for Dijkstra algorithm. /// \ingroup shortest_path diff -r 4317d277ba21 -r 765619b7cbb2 lemon/dim2.h --- a/lemon/dim2.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/dim2.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -24,7 +24,7 @@ ///\ingroup misc ///\file -///\brief A simple two dimensional vector and a bounding box implementation +///\brief A simple two dimensional vector and a bounding box implementation /// /// The class \ref lemon::dim2::Point "dim2::Point" implements /// a two dimensional vector with the usual operations. @@ -59,8 +59,8 @@ ///First coordinate T x; ///Second coordinate - T y; - + T y; + ///Default constructor Point() {} @@ -70,7 +70,7 @@ ///Returns the dimension of the vector (i.e. returns 2). ///The dimension of the vector. - ///This function always returns 2. + ///This function always returns 2. int size() const { return 2; } ///Subscripting operator @@ -92,14 +92,14 @@ T normSquare() const { return x*x+y*y; } - + ///Increment the left hand side by \c u Point& operator +=(const Point& u) { x += u.x; y += u.y; return *this; } - + ///Decrement the left hand side by \c u Point& operator -=(const Point& u) { x -= u.x; @@ -120,12 +120,12 @@ y /= u; return *this; } - + ///Return the scalar product of two vectors T operator *(const Point& u) const { return x*u.x+y*u.y; } - + ///Return the sum of two vectors Point operator+(const Point &u) const { Point b=*this; @@ -169,7 +169,7 @@ }; - ///Return a Point + ///Return a Point ///Return a Point. ///\relates Point @@ -259,7 +259,7 @@ return Point(z.y,-z.x); } - + /// A class to calculate or store the bounding box of plainvectors. @@ -270,15 +270,15 @@ Point bottom_left, top_right; bool _empty; public: - + ///Default constructor: creates an empty bounding box BoundingBox() { _empty = true; } ///Construct an instance from one point BoundingBox(Point a) { bottom_left=top_right=a; _empty = false; } - + ///Construct an instance from two points - + ///Construct an instance from two points. ///\param a The bottom left corner. ///\param b The top right corner. @@ -286,11 +286,11 @@ ///than those of the top right one. BoundingBox(Point a,Point b) { - bottom_left=a; - top_right=b; - _empty = false; + bottom_left=a; + top_right=b; + _empty = false; } - + ///Construct an instance from four numbers ///Construct an instance from four numbers. @@ -299,25 +299,25 @@ ///\param r The right side of the box. ///\param t The top of the box. ///\warning The left side must be no more than the right side and - ///bottom must be no more than the top. + ///bottom must be no more than the top. BoundingBox(T l,T b,T r,T t) { - bottom_left=Point(l,b); - top_right=Point(r,t); - _empty = false; + bottom_left=Point(l,b); + top_right=Point(r,t); + _empty = false; } - + ///Return \c true if the bounding box is empty. - + ///Return \c true if the bounding box is empty (i.e. return \c false ///if at least one point was added to the box or the coordinates of ///the box were set). /// - ///The coordinates of an empty bounding box are not defined. + ///The coordinates of an empty bounding box are not defined. bool empty() const { return _empty; } - + ///Make the BoundingBox empty void clear() { _empty=1; @@ -336,7 +336,7 @@ ///Set the bottom left corner of the box. ///It should only be used for non-empty box. void bottomLeft(Point p) { - bottom_left = p; + bottom_left = p; } ///Give back the top right corner of the box @@ -352,7 +352,7 @@ ///Set the top right corner of the box. ///It should only be used for non-empty box. void topRight(Point p) { - top_right = p; + top_right = p; } ///Give back the bottom right corner of the box @@ -368,10 +368,10 @@ ///Set the bottom right corner of the box. ///It should only be used for non-empty box. void bottomRight(Point p) { - top_right.x = p.x; - bottom_left.y = p.y; + top_right.x = p.x; + bottom_left.y = p.y; } - + ///Give back the top left corner of the box ///Give back the top left corner of the box. @@ -385,8 +385,8 @@ ///Set the top left corner of the box. ///It should only be used for non-empty box. void topLeft(Point p) { - top_right.y = p.y; - bottom_left.x = p.x; + top_right.y = p.y; + bottom_left.x = p.x; } ///Give back the bottom of the box @@ -402,7 +402,7 @@ ///Set the bottom of the box. ///It should only be used for non-empty box. void bottom(T t) { - bottom_left.y = t; + bottom_left.y = t; } ///Give back the top of the box @@ -418,7 +418,7 @@ ///Set the top of the box. ///It should only be used for non-empty box. void top(T t) { - top_right.y = t; + top_right.y = t; } ///Give back the left side of the box @@ -428,13 +428,13 @@ T left() const { return bottom_left.x; } - + ///Set the left side of the box ///Set the left side of the box. ///It should only be used for non-empty box. void left(T t) { - bottom_left.x = t; + bottom_left.x = t; } /// Give back the right side of the box @@ -450,7 +450,7 @@ ///Set the right side of the box. ///It should only be used for non-empty box. void right(T t) { - top_right.x = t; + top_right.x = t; } ///Give back the height of the box @@ -478,7 +478,7 @@ (u.y-bottom_left.y)*(top_right.y-u.y) >= 0 ); } } - + ///Increments a bounding box with a point ///Increments a bounding box with a point. @@ -496,19 +496,19 @@ } return *this; } - + ///Increments a bounding box to contain another bounding box - + ///Increments a bounding box to contain another bounding box. /// BoundingBox& add(const BoundingBox &u){ if ( !u.empty() ){ this->add(u.bottomLeft()); - this->add(u.topRight()); + this->add(u.topRight()); } return *this; } - + ///Intersection of two bounding boxes ///Intersection of two bounding boxes. @@ -516,15 +516,15 @@ BoundingBox operator&(const BoundingBox& u) const { BoundingBox b; if (this->_empty || u._empty) { - b._empty = true; - } else { - b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x); - b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y); - b.top_right.x = std::min(this->top_right.x,u.top_right.x); - b.top_right.y = std::min(this->top_right.y,u.top_right.y); - b._empty = b.bottom_left.x > b.top_right.x || - b.bottom_left.y > b.top_right.y; - } + b._empty = true; + } else { + b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x); + b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y); + b.top_right.x = std::min(this->top_right.x,u.top_right.x); + b.top_right.y = std::min(this->top_right.y,u.top_right.y); + b._empty = b.bottom_left.x > b.top_right.x || + b.bottom_left.y > b.top_right.y; + } return b; } @@ -537,7 +537,7 @@ ///Map of x-coordinates of a \ref Point "Point"-map. /// template - class XMap + class XMap { M& _map; public: @@ -549,21 +549,21 @@ Value operator[](Key k) const {return _map[k].x;} void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));} }; - + ///Returns an \ref XMap class ///This function just returns an \ref XMap class. /// ///\ingroup maps ///\relates XMap - template - inline XMap xMap(M &m) + template + inline XMap xMap(M &m) { return XMap(m); } - template - inline XMap xMap(const M &m) + template + inline XMap xMap(const M &m) { return XMap(m); } @@ -574,7 +574,7 @@ ///Constant (read only) version of \ref XMap /// template - class ConstXMap + class ConstXMap { const M& _map; public: @@ -585,26 +585,26 @@ ConstXMap(const M &map) : _map(map) {} Value operator[](Key k) const {return _map[k].x;} }; - + ///Returns a \ref ConstXMap class ///This function just returns a \ref ConstXMap class. /// ///\ingroup maps ///\relates ConstXMap - template - inline ConstXMap xMap(const M &m) + template + inline ConstXMap xMap(const M &m) { return ConstXMap(m); } ///Map of y-coordinates of a \ref Point "Point"-map - + ///\ingroup maps ///Map of y-coordinates of a \ref Point "Point"-map. /// template - class YMap + class YMap { M& _map; public: @@ -623,14 +623,14 @@ /// ///\ingroup maps ///\relates YMap - template - inline YMap yMap(M &m) + template + inline YMap yMap(M &m) { return YMap(m); } - template - inline YMap yMap(const M &m) + template + inline YMap yMap(const M &m) { return YMap(m); } @@ -641,7 +641,7 @@ ///Constant (read only) version of \ref YMap /// template - class ConstYMap + class ConstYMap { const M& _map; public: @@ -652,15 +652,15 @@ ConstYMap(const M &map) : _map(map) {} Value operator[](Key k) const {return _map[k].y;} }; - + ///Returns a \ref ConstYMap class ///This function just returns a \ref ConstYMap class. /// ///\ingroup maps ///\relates ConstYMap - template - inline ConstYMap yMap(const M &m) + template + inline ConstYMap yMap(const M &m) { return ConstYMap(m); } @@ -673,7 +673,7 @@ ///of a \ref Point "Point"-map. ///\ingroup maps template - class NormSquareMap + class NormSquareMap { const M& _map; public: @@ -684,15 +684,15 @@ NormSquareMap(const M &map) : _map(map) {} Value operator[](Key k) const {return _map[k].normSquare();} }; - + ///Returns a \ref NormSquareMap class ///This function just returns a \ref NormSquareMap class. /// ///\ingroup maps ///\relates NormSquareMap - template - inline NormSquareMap normSquareMap(const M &m) + template + inline NormSquareMap normSquareMap(const M &m) { return NormSquareMap(m); } @@ -700,7 +700,7 @@ /// @} } //namespce dim2 - + } //namespace lemon #endif //LEMON_DIM2_H diff -r 4317d277ba21 -r 765619b7cbb2 lemon/error.h --- a/lemon/error.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/error.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -45,39 +45,39 @@ ExceptionMember() throw() { try { - ptr.reset(new Type()); + ptr.reset(new Type()); } catch (...) {} } ExceptionMember(const Type& type) throw() { try { - ptr.reset(new Type()); - if (ptr.get() == 0) return; - *ptr = type; + ptr.reset(new Type()); + if (ptr.get() == 0) return; + *ptr = type; } catch (...) {} } ExceptionMember(const ExceptionMember& copy) throw() { try { - if (!copy.valid()) return; - ptr.reset(new Type()); - if (ptr.get() == 0) return; - *ptr = copy.get(); + if (!copy.valid()) return; + ptr.reset(new Type()); + if (ptr.get() == 0) return; + *ptr = copy.get(); } catch (...) {} } ExceptionMember& operator=(const ExceptionMember& copy) throw() { if (ptr.get() == 0) return; try { - if (!copy.valid()) return; - *ptr = copy.get(); + if (!copy.valid()) return; + *ptr = copy.get(); } catch (...) {} } void set(const Type& type) throw() { if (ptr.get() == 0) return; try { - *ptr = type; + *ptr = type; } catch (...) {} } @@ -109,10 +109,10 @@ ///\e bool init() throw() { try { - buf.reset(new std::ostringstream); + buf.reset(new std::ostringstream); } catch(...) { - buf.reset(); + buf.reset(); } return buf.get(); } @@ -142,10 +142,10 @@ if( ! buf.get() ) return *this; try { - *buf << t; + *buf << t; } catch(...) { - buf.reset(); + buf.reset(); } return *this; } @@ -156,7 +156,7 @@ const char* mes = 0; try { - mes = buf->str().c_str(); + mes = buf->str().c_str(); } catch(...) {} return mes; @@ -254,7 +254,7 @@ ///\e DataFormatError(const std::string &file_name, int line_num, - const char *the_message) + const char *the_message) : _message(the_message), _line(line_num) { file(file_name); } ///\e @@ -269,9 +269,9 @@ ///\e const char* message() const { if (_message.valid() && !_message.get().empty()) { - return _message.get().c_str(); + return _message.get().c_str(); } else { - return 0; + return 0; } } @@ -280,26 +280,26 @@ /// Returns \e null if the filename was not specified. const char* file() const { if (_file.valid() && !_file.get().empty()) { - return _file.get().c_str(); + return _file.get().c_str(); } else { - return 0; + return 0; } } ///\e virtual const char* what() const throw() { try { - std::ostringstream ostr; - ostr << "lemon:DataFormatError" << ": "; - if (message()) ostr << message(); - if( file() || line() != 0 ) { - ostr << " ("; - if( file() ) ostr << "in file '" << file() << "'"; - if( file() && line() != 0 ) ostr << " "; - if( line() != 0 ) ostr << "at line " << line(); - ostr << ")"; - } - _message_holder.set(ostr.str()); + std::ostringstream ostr; + ostr << "lemon:DataFormatError" << ": "; + if (message()) ostr << message(); + if( file() || line() != 0 ) { + ostr << " ("; + if( file() ) ostr << "in file '" << file() << "'"; + if( file() && line() != 0 ) ostr << " "; + if( line() != 0 ) ostr << "at line " << line(); + ostr << ")"; + } + _message_holder.set(ostr.str()); } catch (...) {} if( _message_holder.valid()) return _message_holder.get().c_str(); @@ -333,19 +333,19 @@ /// Returns \e null if the filename was not specified. const char* file() const { if (_file.valid() && !_file.get().empty()) { - return _file.get().c_str(); + return _file.get().c_str(); } else { - return 0; + return 0; } } ///\e virtual const char* what() const throw() { try { - std::ostringstream ostr; - ostr << "lemon::FileOpenError" << ": "; - ostr << "Cannot open file - " << file(); - _message_holder.set(ostr.str()); + std::ostringstream ostr; + ostr << "lemon::FileOpenError" << ": "; + ostr << "Cannot open file - " << file(); + _message_holder.set(ostr.str()); } catch (...) {} if( _message_holder.valid()) return _message_holder.get().c_str(); @@ -381,9 +381,9 @@ ///\e const char* message() const { if (_message.valid()) { - return _message.get().c_str(); + return _message.get().c_str(); } else { - return 0; + return 0; } } @@ -392,19 +392,19 @@ /// Returns \c 0 if the filename was not specified. const char* file() const { if (_file.valid()) { - return _file.get().c_str(); + return _file.get().c_str(); } else { - return 0; + return 0; } } ///\e virtual const char* what() const throw() { try { - std::ostringstream ostr; - if (message()) ostr << message(); - if (file()) ostr << "(when reading file '" << file() << "')"; - _message_holder.set(ostr.str()); + std::ostringstream ostr; + if (message()) ostr << message(); + if (file()) ostr << "(when reading file '" << file() << "')"; + _message_holder.set(ostr.str()); } catch (...) {} if( _message_holder.valid() ) return _message_holder.get().c_str(); diff -r 4317d277ba21 -r 765619b7cbb2 lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/graph_to_eps.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -60,7 +60,7 @@ Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);} }; } - + ///Default traits class of \ref GraphToEps ///Default traits class of \ref GraphToEps. @@ -76,12 +76,12 @@ typedef typename Graph::ArcIt ArcIt; typedef typename Graph::InArcIt InArcIt; typedef typename Graph::OutArcIt OutArcIt; - + const Graph &g; std::ostream& os; - + typedef ConstMap > CoordsMapType; CoordsMapType _coords; ConstMap _nodeSizes; @@ -93,28 +93,28 @@ ConstMap _arcWidths; double _arcWidthScale; - + double _nodeScale; double _xBorder, _yBorder; double _scale; double _nodeBorderQuotient; - + bool _drawArrows; double _arrowLength, _arrowWidth; - + bool _showNodes, _showArcs; bool _enableParallel; double _parArcDist; bool _showNodeText; - ConstMap _nodeTexts; + ConstMap _nodeTexts; double _nodeTextSize; bool _showNodePsText; - ConstMap _nodePsTexts; + ConstMap _nodePsTexts; char *_nodePsTextsPreamble; - + bool _undirected; bool _pleaseRemoveOsStream; @@ -124,7 +124,7 @@ std::string _title; std::string _copyright; - enum NodeTextColorType + enum NodeTextColorType { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType; ConstMap _nodeTextColors; @@ -146,7 +146,7 @@ ///\param _pros If it is \c true, then the \c ostream referenced by \c _os ///will be explicitly deallocated by the destructor. DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, - bool _pros=false) : + bool _pros=false) : g(_g), os(_os), _coords(dim2::Point(1,1)), _nodeSizes(1), _nodeShapes(0), _nodeColors(WHITE), _arcColors(BLACK), @@ -175,7 +175,7 @@ ///Auxiliary class to implement the named parameters of \ref graphToEps(). /// ///For detailed examples see the \ref graph_to_eps_demo.cc demo file. -template class GraphToEps : public T +template class GraphToEps : public T { // Can't believe it is required by the C++ standard using T::g; @@ -194,11 +194,11 @@ using T::_yBorder; using T::_scale; using T::_nodeBorderQuotient; - + using T::_drawArrows; using T::_arrowLength; using T::_arrowWidth; - + using T::_showNodes; using T::_showArcs; @@ -206,13 +206,13 @@ using T::_parArcDist; using T::_showNodeText; - using T::_nodeTexts; + using T::_nodeTexts; using T::_nodeTextSize; using T::_showNodePsText; - using T::_nodePsTexts; + using T::_nodePsTexts; using T::_nodePsTextsPreamble; - + using T::_undirected; using T::_pleaseRemoveOsStream; @@ -261,16 +261,16 @@ ///Node shapes. /// - enum NodeShapes { + enum NodeShapes { /// = 0 ///\image html nodeshape_0.png ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm - CIRCLE=0, + CIRCLE=0, /// = 1 ///\image html nodeshape_1.png ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm /// - SQUARE=1, + SQUARE=1, /// = 2 ///\image html nodeshape_2.png ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm @@ -293,41 +293,41 @@ const Graph &g; public: arcLess(const Graph &_g) : g(_g) {} - bool operator()(Arc a,Arc b) const + bool operator()(Arc a,Arc b) const { Node ai=std::min(g.source(a),g.target(a)); Node aa=std::max(g.source(a),g.target(a)); Node bi=std::min(g.source(b),g.target(b)); Node ba=std::max(g.source(b),g.target(b)); return ai - static std::string psOut(const dim2::Point &p) + static std::string psOut(const dim2::Point &p) { - std::ostringstream os; + std::ostringstream os; os << p.x << ' ' << p.y; return os.str(); } - static std::string psOut(const Color &c) + static std::string psOut(const Color &c) { - std::ostringstream os; + std::ostringstream os; os << c.red() << ' ' << c.green() << ' ' << c.blue(); return os.str(); } - + public: GraphToEps(const T &t) : T(t), dontPrint(false) {}; - + template struct CoordsTraits : public T { typedef X CoordsMapType; const X &_coords; @@ -337,7 +337,7 @@ ///Sets the map of the node coordinates. ///\param x must be a node map with \ref dim2::Point "dim2::Point" or - ///\ref dim2::Point "dim2::Point" values. + ///\ref dim2::Point "dim2::Point" values. template GraphToEps > coords(const X &x) { dontPrint=true; return GraphToEps >(CoordsTraits(*this,x)); @@ -349,7 +349,7 @@ ///Sets the map of the node sizes ///Sets the map of the node sizes. - ///\param x must be a node map with \c double (or convertible) values. + ///\param x must be a node map with \c double (or convertible) values. template GraphToEps > nodeSizes(const X &x) { dontPrint=true; @@ -364,7 +364,7 @@ ///Sets the map of the node shapes. ///The available shape values ///can be found in \ref NodeShapes "enum NodeShapes". - ///\param x must be a node map with \c int (or convertible) values. + ///\param x must be a node map with \c int (or convertible) values. ///\sa NodeShapes template GraphToEps > nodeShapes(const X &x) { @@ -379,7 +379,7 @@ ///Sets the text printed on the nodes. ///\param x must be a node map with type that can be pushed to a standard - ///\c ostream. + ///\c ostream. template GraphToEps > nodeTexts(const X &x) { dontPrint=true; @@ -417,7 +417,7 @@ ///Sets the map of the arc widths ///Sets the map of the arc widths. - ///\param x must be an arc map with \c double (or convertible) values. + ///\param x must be an arc map with \c double (or convertible) values. template GraphToEps > arcWidths(const X &x) { dontPrint=true; @@ -447,7 +447,7 @@ ///Sets the map of the node text colors ///Sets the map of the node text colors. - ///\param x must be a node map with \ref Color values. + ///\param x must be a node map with \ref Color values. /// ///\sa Palette template GraphToEps > @@ -465,7 +465,7 @@ ///Sets the map of the arc colors ///Sets the map of the arc colors. - ///\param x must be an arc map with \ref Color values. + ///\param x must be an arc map with \ref Color values. /// ///\sa Palette template GraphToEps > @@ -477,7 +477,7 @@ ///Sets a global scale factor for node sizes ///Sets a global scale factor for node sizes. - /// + /// /// If nodeSizes() is not given, this function simply sets the node /// sizes to \c d. If nodeSizes() is given, but /// autoNodeScale() is not, then the node size given by @@ -568,21 +568,21 @@ GraphToEps &arrowLength(double d=1.0) {_arrowLength*=d;return *this;} ///Sets the width of the arrowheads GraphToEps &arrowWidth(double d=.3) {_arrowWidth*=d;return *this;} - + ///Scales the drawing to fit to A4 page GraphToEps &scaleToA4() {_scaleToA4=true;return *this;} - + ///Enables parallel arcs GraphToEps &enableParallel(bool b=true) {_enableParallel=b;return *this;} - + ///Sets the distance between parallel arcs GraphToEps &parArcDist(double d) {_parArcDist*=d;return *this;} - + ///Hides the arcs GraphToEps &hideArcs(bool b=true) {_showArcs=!b;return *this;} ///Hides the nodes GraphToEps &hideNodes(bool b=true) {_showNodes=!b;return *this;} - + ///Sets the size of the node texts GraphToEps &nodeTextSize(double d) {_nodeTextSize=d;return *this;} @@ -600,7 +600,7 @@ {_nodeTextColorType=DIST_BW;return *this;} ///Gives a preamble block for node Postscript block. - + ///Gives a preamble block for node Postscript block. /// ///\sa nodePsTexts() @@ -625,7 +625,7 @@ /// ///\sa undirected() GraphToEps &directed(bool b=true) {_undirected=!b;return *this;} - + ///Sets the title. ///Sets the title of the generated image, @@ -640,7 +640,7 @@ GraphToEps ©right(const std::string &t) {_copyright=t;return *this;} protected: - bool isInsideNode(dim2::Point p, double r,int t) + bool isInsideNode(dim2::Point p, double r,int t) { switch(t) { case CIRCLE: @@ -657,7 +657,7 @@ public: ~GraphToEps() { } - + ///Draws the graph. ///Like other functions using @@ -668,7 +668,7 @@ //\todo better 'epsilon' would be nice here. const double EPSILON=1e-9; if(dontPrint) return; - + _graph_to_eps_bits::_NegY mycoords(_coords,_negY); @@ -677,8 +677,8 @@ if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n'; os << "%%Creator: LEMON, graphToEps()\n"; - { -#ifndef WIN32 + { +#ifndef WIN32 timeval tv; gettimeofday(&tv, 0); @@ -688,37 +688,37 @@ #else SYSTEMTIME time; char buf1[11], buf2[9], buf3[5]; - + GetSystemTime(&time); - if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "ddd MMM dd", buf1, 11) && - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, - "HH':'mm':'ss", buf2, 9) && - GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "yyyy", buf3, 5)) { - os << "%%CreationDate: " << buf1 << ' ' - << buf2 << ' ' << buf3 << std::endl; - } + if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + "ddd MMM dd", buf1, 11) && + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, + "HH':'mm':'ss", buf2, 9) && + GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + "yyyy", buf3, 5)) { + os << "%%CreationDate: " << buf1 << ' ' + << buf2 << ' ' << buf3 << std::endl; + } #endif } if (_autoArcWidthScale) { double max_w=0; for(ArcIt e(g);e!=INVALID;++e) - max_w=std::max(double(_arcWidths[e]),max_w); + max_w=std::max(double(_arcWidths[e]),max_w); //\todo better 'epsilon' would be nice here. if(max_w>EPSILON) { - _arcWidthScale/=max_w; + _arcWidthScale/=max_w; } } if (_autoNodeScale) { double max_s=0; for(NodeIt n(g);n!=INVALID;++n) - max_s=std::max(double(_nodeSizes[n]),max_s); + max_s=std::max(double(_nodeSizes[n]),max_s); //\todo better 'epsilon' would be nice here. if(max_s>EPSILON) { - _nodeScale/=max_s; + _nodeScale/=max_s; } } @@ -727,14 +727,14 @@ dim2::BoundingBox bb; for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); if (bb.empty()) { - bb = dim2::BoundingBox(dim2::Point(0,0)); + bb = dim2::BoundingBox(dim2::Point(0,0)); } diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare()); if(diag_len bb; for(NodeIt n(g);n!=INVALID;++n) { double ns=_nodeSizes[n]*_nodeScale; @@ -743,41 +743,41 @@ case CIRCLE: case SQUARE: case DIAMOND: - bb.add(p+mycoords[n]); - bb.add(-p+mycoords[n]); - break; + bb.add(p+mycoords[n]); + bb.add(-p+mycoords[n]); + break; case MALE: - bb.add(-p+mycoords[n]); - bb.add(dim2::Point(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]); - break; + bb.add(-p+mycoords[n]); + bb.add(dim2::Point(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]); + break; case FEMALE: - bb.add(p+mycoords[n]); - bb.add(dim2::Point(-ns,-3.01*ns)+mycoords[n]); - break; + bb.add(p+mycoords[n]); + bb.add(dim2::Point(-ns,-3.01*ns)+mycoords[n]); + break; } } if (bb.empty()) { bb = dim2::BoundingBox(dim2::Point(0,0)); } - + if(_scaleToA4) os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n"; else { if(_preScale) { - //Rescale so that BoundingBox won't be neither to big nor too small. - while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10; - while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10; + //Rescale so that BoundingBox won't be neither to big nor too small. + while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10; + while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10; } - + os << "%%BoundingBox: " - << int(floor(bb.left() * _scale - _xBorder)) << ' ' - << int(floor(bb.bottom() * _scale - _yBorder)) << ' ' - << int(ceil(bb.right() * _scale + _xBorder)) << ' ' - << int(ceil(bb.top() * _scale + _yBorder)) << '\n'; + << int(floor(bb.left() * _scale - _xBorder)) << ' ' + << int(floor(bb.bottom() * _scale - _yBorder)) << ' ' + << int(ceil(bb.right() * _scale + _xBorder)) << ' ' + << int(ceil(bb.top() * _scale + _yBorder)) << '\n'; } - + os << "%%EndComments\n"; - + //x1 y1 x2 y2 x3 y3 cr cg cb w os << "/lb { setlinewidth setrgbcolor newpath moveto\n" << " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; @@ -831,7 +831,7 @@ << " 5 index 5 index 5 index c fill\n" << " setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n" << " } bind def\n"; - + os << "/arrl " << _arrowLength << " def\n"; os << "/arrw " << _arrowWidth << " def\n"; @@ -840,7 +840,7 @@ //len w dx_norm dy_norm x1 y1 cr cg cb os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n" << " /w exch def /len exch def\n" - // << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke" + // << " 0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke" << " newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n" << " len w sub arrl sub dx dy lrl\n" << " arrw dy dx neg lrl\n" @@ -857,175 +857,175 @@ os << "\ngsave\n"; if(_scaleToA4) if(bb.height()>bb.width()) { - double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(), - (A4WIDTH-2*A4BORDER)/bb.width()); - os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' ' - << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER - << " translate\n" - << sc << " dup scale\n" - << -bb.left() << ' ' << -bb.bottom() << " translate\n"; + double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(), + (A4WIDTH-2*A4BORDER)/bb.width()); + os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' ' + << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER + << " translate\n" + << sc << " dup scale\n" + << -bb.left() << ' ' << -bb.bottom() << " translate\n"; } else { - //\todo Verify centering - double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(), - (A4WIDTH-2*A4BORDER)/bb.height()); - os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' ' - << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER - << " translate\n" - << sc << " dup scale\n90 rotate\n" - << -bb.left() << ' ' << -bb.top() << " translate\n"; - } + //\todo Verify centering + double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(), + (A4WIDTH-2*A4BORDER)/bb.height()); + os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' ' + << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER + << " translate\n" + << sc << " dup scale\n90 rotate\n" + << -bb.left() << ' ' << -bb.top() << " translate\n"; + } else if(_scale!=1.0) os << _scale << " dup scale\n"; - + if(_showArcs) { - os << "%Arcs:\ngsave\n"; + os << "%Arcs:\ngsave\n"; if(_enableParallel) { - std::vector el; - for(ArcIt e(g);e!=INVALID;++e) - if((!_undirected||g.source(e)0 - &&g.source(e)!=g.target(e)) - el.push_back(e); - std::sort(el.begin(),el.end(),arcLess(g)); - - typename std::vector::iterator j; - for(typename std::vector::iterator i=el.begin();i!=el.end();i=j) { - for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ; + std::vector el; + for(ArcIt e(g);e!=INVALID;++e) + if((!_undirected||g.source(e)0 + &&g.source(e)!=g.target(e)) + el.push_back(e); + std::sort(el.begin(),el.end(),arcLess(g)); - double sw=0; - for(typename std::vector::iterator e=i;e!=j;++e) - sw+=_arcWidths[*e]*_arcWidthScale+_parArcDist; - sw-=_parArcDist; - sw/=-2.0; - dim2::Point - dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]); - double l=std::sqrt(dvec.normSquare()); - //\todo better 'epsilon' would be nice here. - dim2::Point d(dvec/std::max(l,EPSILON)); - dim2::Point m; -// m=dim2::Point(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0; + typename std::vector::iterator j; + for(typename std::vector::iterator i=el.begin();i!=el.end();i=j) { + for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ; -// m=dim2::Point(mycoords[g.source(*i)])+ -// dvec*(double(_nodeSizes[g.source(*i)])/ -// (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)])); + double sw=0; + for(typename std::vector::iterator e=i;e!=j;++e) + sw+=_arcWidths[*e]*_arcWidthScale+_parArcDist; + sw-=_parArcDist; + sw/=-2.0; + dim2::Point + dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]); + double l=std::sqrt(dvec.normSquare()); + //\todo better 'epsilon' would be nice here. + dim2::Point d(dvec/std::max(l,EPSILON)); + dim2::Point m; +// m=dim2::Point(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0; - m=dim2::Point(mycoords[g.source(*i)])+ - d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0; +// m=dim2::Point(mycoords[g.source(*i)])+ +// dvec*(double(_nodeSizes[g.source(*i)])/ +// (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)])); - for(typename std::vector::iterator e=i;e!=j;++e) { - sw+=_arcWidths[*e]*_arcWidthScale/2.0; - dim2::Point mm=m+rot90(d)*sw/.75; - if(_drawArrows) { - int node_shape; - dim2::Point s=mycoords[g.source(*e)]; - dim2::Point t=mycoords[g.target(*e)]; - double rn=_nodeSizes[g.target(*e)]*_nodeScale; - node_shape=_nodeShapes[g.target(*e)]; - dim2::Bezier3 bez(s,mm,mm,t); - double t1=0,t2=1; - for(int ii=0;ii apoint=bez((t1+t2)/2); - rn = _arrowLength+_arcWidths[*e]*_arcWidthScale; - rn*=rn; - t2=(t1+t2)/2;t1=0; - for(int ii=0;iirn) t1=(t1+t2)/2; - else t2=(t1+t2)/2; - dim2::Point linend=bez((t1+t2)/2); - bez=bez.before((t1+t2)/2); -// rn=_nodeSizes[g.source(*e)]*_nodeScale; -// node_shape=_nodeShapes[g.source(*e)]; -// t1=0;t2=1; -// for(int i=0;i dd(rot90(linend-apoint)); - dd*=(.5*_arcWidths[*e]*_arcWidthScale+_arrowWidth)/ - std::sqrt(dd.normSquare()); - os << "newpath " << psOut(apoint) << " moveto " - << psOut(linend+dd) << " lineto " - << psOut(linend-dd) << " lineto closepath fill\n"; - } - else { - os << mycoords[g.source(*e)].x << ' ' - << mycoords[g.source(*e)].y << ' ' - << mm.x << ' ' << mm.y << ' ' - << mycoords[g.target(*e)].x << ' ' - << mycoords[g.target(*e)].y << ' ' - << _arcColors[*e].red() << ' ' - << _arcColors[*e].green() << ' ' - << _arcColors[*e].blue() << ' ' - << _arcWidths[*e]*_arcWidthScale << " lb\n"; - } - sw+=_arcWidths[*e]*_arcWidthScale/2.0+_parArcDist; - } - } + m=dim2::Point(mycoords[g.source(*i)])+ + d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0; + + for(typename std::vector::iterator e=i;e!=j;++e) { + sw+=_arcWidths[*e]*_arcWidthScale/2.0; + dim2::Point mm=m+rot90(d)*sw/.75; + if(_drawArrows) { + int node_shape; + dim2::Point s=mycoords[g.source(*e)]; + dim2::Point t=mycoords[g.target(*e)]; + double rn=_nodeSizes[g.target(*e)]*_nodeScale; + node_shape=_nodeShapes[g.target(*e)]; + dim2::Bezier3 bez(s,mm,mm,t); + double t1=0,t2=1; + for(int ii=0;ii apoint=bez((t1+t2)/2); + rn = _arrowLength+_arcWidths[*e]*_arcWidthScale; + rn*=rn; + t2=(t1+t2)/2;t1=0; + for(int ii=0;iirn) t1=(t1+t2)/2; + else t2=(t1+t2)/2; + dim2::Point linend=bez((t1+t2)/2); + bez=bez.before((t1+t2)/2); +// rn=_nodeSizes[g.source(*e)]*_nodeScale; +// node_shape=_nodeShapes[g.source(*e)]; +// t1=0;t2=1; +// for(int i=0;i dd(rot90(linend-apoint)); + dd*=(.5*_arcWidths[*e]*_arcWidthScale+_arrowWidth)/ + std::sqrt(dd.normSquare()); + os << "newpath " << psOut(apoint) << " moveto " + << psOut(linend+dd) << " lineto " + << psOut(linend-dd) << " lineto closepath fill\n"; + } + else { + os << mycoords[g.source(*e)].x << ' ' + << mycoords[g.source(*e)].y << ' ' + << mm.x << ' ' << mm.y << ' ' + << mycoords[g.target(*e)].x << ' ' + << mycoords[g.target(*e)].y << ' ' + << _arcColors[*e].red() << ' ' + << _arcColors[*e].green() << ' ' + << _arcColors[*e].blue() << ' ' + << _arcWidths[*e]*_arcWidthScale << " lb\n"; + } + sw+=_arcWidths[*e]*_arcWidthScale/2.0+_parArcDist; + } + } } else for(ArcIt e(g);e!=INVALID;++e) - if((!_undirected||g.source(e)0 - &&g.source(e)!=g.target(e)) { - if(_drawArrows) { - dim2::Point d(mycoords[g.target(e)]-mycoords[g.source(e)]); - double rn=_nodeSizes[g.target(e)]*_nodeScale; - int node_shape=_nodeShapes[g.target(e)]; - double t1=0,t2=1; - for(int i=0;i0 + &&g.source(e)!=g.target(e)) { + if(_drawArrows) { + dim2::Point d(mycoords[g.target(e)]-mycoords[g.source(e)]); + double rn=_nodeSizes[g.target(e)]*_nodeScale; + int node_shape=_nodeShapes[g.target(e)]; + double t1=0,t2=1; + for(int i=0;i &absoluteEdgeWidths(bool b=true) { return absoluteArcWidths(b); } - + ///An alias for parArcDist() GraphToEps &parEdgeDist(double d) {return parArcDist(d);} - + ///An alias for hideArcs() GraphToEps &hideEdges(bool b=true) {return hideArcs(b);} @@ -1143,13 +1143,13 @@ ///\sa GraphToEps ///\sa graphToEps(G &g, const char *file_name) template -GraphToEps > +GraphToEps > graphToEps(G &g, std::ostream& os=std::cout) { - return + return GraphToEps >(DefaultGraphToEpsTraits(g,os)); } - + ///Generates an EPS file from a graph ///\ingroup eps_io @@ -1159,7 +1159,7 @@ ///instead of a stream. ///\sa graphToEps(G &g, std::ostream& os) template -GraphToEps > +GraphToEps > graphToEps(G &g,const char *file_name) { return GraphToEps > @@ -1175,7 +1175,7 @@ ///instead of a stream. ///\sa graphToEps(G &g, std::ostream& os) template -GraphToEps > +GraphToEps > graphToEps(G &g,const std::string& file_name) { return GraphToEps > diff -r 4317d277ba21 -r 765619b7cbb2 lemon/graph_utils.h --- a/lemon/graph_utils.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/graph_utils.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -46,24 +46,24 @@ ///This \c \#define creates convenience typedefs for the following types ///of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, - ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, + ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. /// ///\note If the graph type is a dependent type, ie. the graph type depend ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() ///macro. -#define DIGRAPH_TYPEDEFS(Digraph) \ - typedef Digraph::Node Node; \ - typedef Digraph::NodeIt NodeIt; \ - typedef Digraph::Arc Arc; \ - typedef Digraph::ArcIt ArcIt; \ - typedef Digraph::InArcIt InArcIt; \ - typedef Digraph::OutArcIt OutArcIt; \ - typedef Digraph::NodeMap BoolNodeMap; \ - typedef Digraph::NodeMap IntNodeMap; \ - typedef Digraph::NodeMap DoubleNodeMap; \ - typedef Digraph::ArcMap BoolArcMap; \ - typedef Digraph::ArcMap IntArcMap; \ +#define DIGRAPH_TYPEDEFS(Digraph) \ + typedef Digraph::Node Node; \ + typedef Digraph::NodeIt NodeIt; \ + typedef Digraph::Arc Arc; \ + typedef Digraph::ArcIt ArcIt; \ + typedef Digraph::InArcIt InArcIt; \ + typedef Digraph::OutArcIt OutArcIt; \ + typedef Digraph::NodeMap BoolNodeMap; \ + typedef Digraph::NodeMap IntNodeMap; \ + typedef Digraph::NodeMap DoubleNodeMap; \ + typedef Digraph::ArcMap BoolArcMap; \ + typedef Digraph::ArcMap IntArcMap; \ typedef Digraph::ArcMap DoubleArcMap ///Creates convenience typedefs for the digraph types and iterators @@ -72,20 +72,20 @@ /// ///\note Use this macro, if the graph type is a dependent type, ///ie. the graph type depend on a template parameter. -#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph) \ - typedef typename Digraph::Node Node; \ - typedef typename Digraph::NodeIt NodeIt; \ - typedef typename Digraph::Arc Arc; \ - typedef typename Digraph::ArcIt ArcIt; \ - typedef typename Digraph::InArcIt InArcIt; \ - typedef typename Digraph::OutArcIt OutArcIt; \ - typedef typename Digraph::template NodeMap BoolNodeMap; \ - typedef typename Digraph::template NodeMap IntNodeMap; \ - typedef typename Digraph::template NodeMap DoubleNodeMap; \ - typedef typename Digraph::template ArcMap BoolArcMap; \ - typedef typename Digraph::template ArcMap IntArcMap; \ +#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph) \ + typedef typename Digraph::Node Node; \ + typedef typename Digraph::NodeIt NodeIt; \ + typedef typename Digraph::Arc Arc; \ + typedef typename Digraph::ArcIt ArcIt; \ + typedef typename Digraph::InArcIt InArcIt; \ + typedef typename Digraph::OutArcIt OutArcIt; \ + typedef typename Digraph::template NodeMap BoolNodeMap; \ + typedef typename Digraph::template NodeMap IntNodeMap; \ + typedef typename Digraph::template NodeMap DoubleNodeMap; \ + typedef typename Digraph::template ArcMap BoolArcMap; \ + typedef typename Digraph::template ArcMap IntArcMap; \ typedef typename Digraph::template ArcMap DoubleArcMap - + ///Creates convenience typedefs for the graph types and iterators ///This \c \#define creates the same convenience typedefs as defined @@ -96,13 +96,13 @@ ///\note If the graph type is a dependent type, ie. the graph type depend ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() ///macro. -#define GRAPH_TYPEDEFS(Graph) \ - DIGRAPH_TYPEDEFS(Graph); \ - typedef Graph::Edge Edge; \ - typedef Graph::EdgeIt EdgeIt; \ - typedef Graph::IncEdgeIt IncEdgeIt; \ - typedef Graph::EdgeMap BoolEdgeMap; \ - typedef Graph::EdgeMap IntEdgeMap; \ +#define GRAPH_TYPEDEFS(Graph) \ + DIGRAPH_TYPEDEFS(Graph); \ + typedef Graph::Edge Edge; \ + typedef Graph::EdgeIt EdgeIt; \ + typedef Graph::IncEdgeIt IncEdgeIt; \ + typedef Graph::EdgeMap BoolEdgeMap; \ + typedef Graph::EdgeMap IntEdgeMap; \ typedef Graph::EdgeMap DoubleEdgeMap ///Creates convenience typedefs for the graph types and iterators @@ -111,13 +111,13 @@ /// ///\note Use this macro, if the graph type is a dependent type, ///ie. the graph type depend on a template parameter. -#define TEMPLATE_GRAPH_TYPEDEFS(Graph) \ - TEMPLATE_DIGRAPH_TYPEDEFS(Graph); \ - typedef typename Graph::Edge Edge; \ - typedef typename Graph::EdgeIt EdgeIt; \ - typedef typename Graph::IncEdgeIt IncEdgeIt; \ - typedef typename Graph::template EdgeMap BoolEdgeMap; \ - typedef typename Graph::template EdgeMap IntEdgeMap; \ +#define TEMPLATE_GRAPH_TYPEDEFS(Graph) \ + TEMPLATE_DIGRAPH_TYPEDEFS(Graph); \ + typedef typename Graph::Edge Edge; \ + typedef typename Graph::EdgeIt EdgeIt; \ + typedef typename Graph::IncEdgeIt IncEdgeIt; \ + typedef typename Graph::template EdgeMap BoolEdgeMap; \ + typedef typename Graph::template EdgeMap IntEdgeMap; \ typedef typename Graph::template EdgeMap DoubleEdgeMap /// \brief Function to count the items in the graph. @@ -138,7 +138,7 @@ // Node counting: namespace _graph_utils_bits { - + template struct CountNodesSelector { static int count(const Graph &g) { @@ -148,13 +148,13 @@ template struct CountNodesSelector< - Graph, typename - enable_if::type> + Graph, typename + enable_if::type> { static int count(const Graph &g) { return g.nodeNum(); } - }; + }; } /// \brief Function to count the nodes in the graph. @@ -163,7 +163,7 @@ /// The complexity of the function is O(n) but for some /// graph structures it is specialized to run in O(1). /// - /// If the graph contains a \e nodeNum() member function and a + /// If the graph contains a \e nodeNum() member function and a /// \e NodeNumTag tag then this function calls directly the member /// function to query the cardinality of the node set. template @@ -174,7 +174,7 @@ // Arc counting: namespace _graph_utils_bits { - + template struct CountArcsSelector { static int count(const Graph &g) { @@ -184,13 +184,13 @@ template struct CountArcsSelector< - Graph, - typename enable_if::type> + Graph, + typename enable_if::type> { static int count(const Graph &g) { return g.arcNum(); } - }; + }; } /// \brief Function to count the arcs in the graph. @@ -199,7 +199,7 @@ /// The complexity of the function is O(e) but for some /// graph structures it is specialized to run in O(1). /// - /// If the graph contains a \e arcNum() member function and a + /// If the graph contains a \e arcNum() member function and a /// \e EdgeNumTag tag then this function calls directly the member /// function to query the cardinality of the arc set. template @@ -209,7 +209,7 @@ // Edge counting: namespace _graph_utils_bits { - + template struct CountEdgesSelector { static int count(const Graph &g) { @@ -219,13 +219,13 @@ template struct CountEdgesSelector< - Graph, - typename enable_if::type> + Graph, + typename enable_if::type> { static int count(const Graph &g) { return g.edgeNum(); } - }; + }; } /// \brief Function to count the edges in the graph. @@ -234,7 +234,7 @@ /// The complexity of the function is O(m) but for some /// graph structures it is specialized to run in O(1). /// - /// If the graph contains a \e edgeNum() member function and a + /// If the graph contains a \e edgeNum() member function and a /// \e EdgeNumTag tag then this function calls directly the member /// function to query the cardinality of the edge set. template @@ -256,7 +256,7 @@ /// \brief Function to count the number of the out-arcs from node \c n. /// /// This function counts the number of the out-arcs from node \c n - /// in the graph. + /// in the graph. template inline int countOutArcs(const Graph& _g, const typename Graph::Node& _n) { return countNodeDegree(_g, _n); @@ -265,7 +265,7 @@ /// \brief Function to count the number of the in-arcs to node \c n. /// /// This function counts the number of the in-arcs to node \c n - /// in the graph. + /// in the graph. template inline int countInArcs(const Graph& _g, const typename Graph::Node& _n) { return countNodeDegree(_g, _n); @@ -274,14 +274,14 @@ /// \brief Function to count the number of the inc-edges to node \c n. /// /// This function counts the number of the inc-edges to node \c n - /// in the graph. + /// in the graph. template inline int countIncEdges(const Graph& _g, const typename Graph::Node& _n) { return countNodeDegree(_g, _n); } namespace _graph_utils_bits { - + template struct FindArcSelector { typedef typename Graph::Node Node; @@ -301,15 +301,15 @@ template struct FindArcSelector< - Graph, - typename enable_if::type> + Graph, + typename enable_if::type> { typedef typename Graph::Node Node; typedef typename Graph::Arc Arc; static Arc find(const Graph &g, Node u, Node v, Arc prev) { return g.findArc(u, v, prev); } - }; + }; } /// \brief Finds an arc between two nodes of a graph. @@ -333,7 +333,7 @@ ///\sa DynArcLookUp ///\sa ConArcIt template - inline typename Graph::Arc + inline typename Graph::Arc findArc(const Graph &g, typename Graph::Node u, typename Graph::Node v, typename Graph::Arc prev = INVALID) { return _graph_utils_bits::FindArcSelector::find(g, u, v, prev); @@ -341,7 +341,7 @@ /// \brief Iterator for iterating on arcs connected the same nodes. /// - /// Iterator for iterating on arcs connected the same nodes. It is + /// Iterator for iterating on arcs connected the same nodes. It is /// higher level interface for the findArc() function. You can /// use it the following way: ///\code @@ -349,7 +349,7 @@ /// ... /// } ///\endcode - /// + /// ///\sa findArc() ///\sa ArcLookUp ///\sa AllArcLookUp @@ -374,16 +374,16 @@ /// \brief Constructor. /// - /// Construct a new ConArcIt which continues the iterating from + /// Construct a new ConArcIt which continues the iterating from /// the \c e arc. ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {} - + /// \brief Increment operator. /// /// It increments the iterator and gives back the next arc. ConArcIt& operator++() { - Parent::operator=(findArc(_graph, _graph.source(*this), - _graph.target(*this), *this)); + Parent::operator=(findArc(_graph, _graph.source(*this), + _graph.target(*this), *this)); return *this; } private: @@ -391,7 +391,7 @@ }; namespace _graph_utils_bits { - + template struct FindEdgeSelector { typedef typename Graph::Node Node; @@ -425,15 +425,15 @@ template struct FindEdgeSelector< - Graph, - typename enable_if::type> + Graph, + typename enable_if::type> { typedef typename Graph::Node Node; typedef typename Graph::Edge Edge; static Edge find(const Graph &g, Node u, Node v, Edge prev) { return g.findEdge(u, v, prev); } - }; + }; } /// \brief Finds an edge between two nodes of a graph. @@ -449,7 +449,7 @@ /// /// Thus you can iterate through each arc from \c u to \c v as it follows. ///\code - /// for(Edge e = findEdge(g,u,v); e != INVALID; + /// for(Edge e = findEdge(g,u,v); e != INVALID; /// e = findEdge(g,u,v,e)) { /// ... /// } @@ -458,7 +458,7 @@ ///\sa ConEdgeIt template - inline typename Graph::Edge + inline typename Graph::Edge findEdge(const Graph &g, typename Graph::Node u, typename Graph::Node v, typename Graph::Edge p = INVALID) { return _graph_utils_bits::FindEdgeSelector::find(g, u, v, p); @@ -466,7 +466,7 @@ /// \brief Iterator for iterating on edges connected the same nodes. /// - /// Iterator for iterating on edges connected the same nodes. It is + /// Iterator for iterating on edges connected the same nodes. It is /// higher level interface for the findEdge() function. You can /// use it the following way: ///\code @@ -496,16 +496,16 @@ /// \brief Constructor. /// - /// Construct a new ConEdgeIt which continues the iterating from + /// Construct a new ConEdgeIt which continues the iterating from /// the \c e edge. ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {} - + /// \brief Increment operator. /// /// It increments the iterator and gives back the next edge. ConEdgeIt& operator++() { - Parent::operator=(findEdge(_graph, _graph.u(*this), - _graph.v(*this), *this)); + Parent::operator=(findEdge(_graph, _graph.u(*this), + _graph.v(*this), *this)); return *this; } private: @@ -518,18 +518,18 @@ class MapCopyBase { public: virtual void copy(const Digraph& from, const RefMap& refMap) = 0; - + virtual ~MapCopyBase() {} }; - template class MapCopy : public MapCopyBase { public: - MapCopy(ToMap& tmap, const FromMap& map) + MapCopy(ToMap& tmap, const FromMap& map) : _tmap(tmap), _map(map) {} - + virtual void copy(const Digraph& digraph, const RefMap& refMap) { typedef typename ItemSetTraits::ItemIt ItemIt; for (ItemIt it(digraph); it != INVALID; ++it) { @@ -547,7 +547,7 @@ public: ItemCopy(It& it, const Item& item) : _it(it), _item(item) {} - + virtual void copy(const Digraph&, const RefMap& refMap) { _it = refMap[_item]; } @@ -562,7 +562,7 @@ public: RefCopy(Ref& map) : _map(map) {} - + virtual void copy(const Digraph& digraph, const RefMap& refMap) { typedef typename ItemSetTraits::ItemIt ItemIt; for (ItemIt it(digraph); it != INVALID; ++it) { @@ -574,13 +574,13 @@ Ref& _map; }; - template class CrossRefCopy : public MapCopyBase { public: CrossRefCopy(CrossRef& cmap) : _cmap(cmap) {} - + virtual void copy(const Digraph& digraph, const RefMap& refMap) { typedef typename ItemSetTraits::ItemIt ItemIt; for (ItemIt it(digraph); it != INVALID; ++it) { @@ -601,16 +601,16 @@ nodeRefMap[it] = to.addNode(); } for (typename From::ArcIt it(from); it != INVALID; ++it) { - arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], - nodeRefMap[from.target(it)]); + arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], + nodeRefMap[from.target(it)]); } } }; template struct DigraphCopySelector< - Digraph, - typename enable_if::type> + Digraph, + typename enable_if::type> { template static void copy(Digraph &to, const From& from, @@ -628,16 +628,16 @@ nodeRefMap[it] = to.addNode(); } for (typename From::EdgeIt it(from); it != INVALID; ++it) { - edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], - nodeRefMap[from.v(it)]); + edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], + nodeRefMap[from.v(it)]); } } }; template struct GraphCopySelector< - Graph, - typename enable_if::type> + Graph, + typename enable_if::type> { template static void copy(Graph &to, const From& from, @@ -697,16 +697,16 @@ typedef typename From::template NodeMap NodeRefMap; typedef typename From::template ArcMap ArcRefMap; - - - public: + + + public: /// \brief Constructor for the DigraphCopy. /// /// It copies the content of the \c _from digraph into the /// \c _to digraph. - DigraphCopy(To& to, const From& from) + DigraphCopy(To& to, const From& from) : _from(from), _to(to) {} /// \brief Destructor of the DigraphCopy @@ -730,8 +730,8 @@ /// destination graph. template DigraphCopy& nodeRef(NodeRef& map) { - _node_maps.push_back(new _graph_utils_bits::RefCopy(map)); + _node_maps.push_back(new _graph_utils_bits::RefCopy(map)); return *this; } @@ -744,7 +744,7 @@ template DigraphCopy& nodeCrossRef(NodeCrossRef& map) { _node_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); + NodeRefMap, NodeCrossRef>(map)); return *this; } @@ -755,8 +755,8 @@ /// and the copied map's key type is the source graph's node type. template DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { - _node_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); + _node_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); return *this; } @@ -764,8 +764,8 @@ /// /// Make a copy of the given node. DigraphCopy& node(TNode& tnode, const Node& snode) { - _node_maps.push_back(new _graph_utils_bits::ItemCopy(tnode, snode)); + _node_maps.push_back(new _graph_utils_bits::ItemCopy(tnode, snode)); return *this; } @@ -774,8 +774,8 @@ /// Copies the arc references into the given map. template DigraphCopy& arcRef(ArcRef& map) { - _arc_maps.push_back(new _graph_utils_bits::RefCopy(map)); + _arc_maps.push_back(new _graph_utils_bits::RefCopy(map)); return *this; } @@ -786,20 +786,20 @@ template DigraphCopy& arcCrossRef(ArcCrossRef& map) { _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); + ArcRefMap, ArcCrossRef>(map)); return *this; } /// \brief Make copy of the given map. /// - /// Makes copy of the given map for the newly created digraph. + /// Makes copy of the given map for the newly created digraph. /// The new map's key type is the to digraph's arc type, /// and the copied map's key type is the from digraph's arc - /// type. + /// type. template DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) { - _arc_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); + _arc_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); return *this; } @@ -807,8 +807,8 @@ /// /// Make a copy of the given arc. DigraphCopy& arc(TArc& tarc, const Arc& sarc) { - _arc_maps.push_back(new _graph_utils_bits::ItemCopy(tarc, sarc)); + _arc_maps.push_back(new _graph_utils_bits::ItemCopy(tarc, sarc)); return *this; } @@ -825,7 +825,7 @@ } for (int i = 0; i < int(_arc_maps.size()); ++i) { _arc_maps[i]->copy(_from, arcRefMap); - } + } } protected: @@ -834,10 +834,10 @@ const From& _from; To& _to; - std::vector<_graph_utils_bits::MapCopyBase* > + std::vector<_graph_utils_bits::MapCopyBase* > _node_maps; - std::vector<_graph_utils_bits::MapCopyBase* > + std::vector<_graph_utils_bits::MapCopyBase* > _arc_maps; }; @@ -850,13 +850,13 @@ ///\code /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); ///\endcode - /// + /// /// After the copy the \c nr map will contain the mapping from the /// nodes of the \c from digraph to the nodes of the \c to digraph and /// \c ecr will contain the mapping from the arcs of the \c to digraph /// to the arcs of the \c from digraph. /// - /// \see DigraphCopy + /// \see DigraphCopy template DigraphCopy copyDigraph(To& to, const From& from) { return DigraphCopy(to, from); @@ -917,8 +917,8 @@ struct ArcRefMap { ArcRefMap(const To& to, const From& from, - const EdgeRefMap& edge_ref, const NodeRefMap& node_ref) - : _to(to), _from(from), + const EdgeRefMap& edge_ref, const NodeRefMap& node_ref) + : _to(to), _from(from), _edge_ref(edge_ref), _node_ref(node_ref) {} typedef typename From::Arc Key; @@ -926,27 +926,27 @@ Value operator[](const Key& key) const { bool forward = _from.u(key) != _from.v(key) ? - _node_ref[_from.source(key)] == - _to.source(_to.direct(_edge_ref[key], true)) : - _from.direction(key); - return _to.direct(_edge_ref[key], forward); + _node_ref[_from.source(key)] == + _to.source(_to.direct(_edge_ref[key], true)) : + _from.direction(key); + return _to.direct(_edge_ref[key], forward); } - + const To& _to; const From& _from; const EdgeRefMap& _edge_ref; const NodeRefMap& _node_ref; }; - - public: + + public: /// \brief Constructor for the GraphCopy. /// /// It copies the content of the \c _from graph into the /// \c _to graph. - GraphCopy(To& to, const From& from) + GraphCopy(To& to, const From& from) : _from(from), _to(to) {} /// \brief Destructor of the GraphCopy @@ -970,8 +970,8 @@ /// Copies the node references into the given map. template GraphCopy& nodeRef(NodeRef& map) { - _node_maps.push_back(new _graph_utils_bits::RefCopy(map)); + _node_maps.push_back(new _graph_utils_bits::RefCopy(map)); return *this; } @@ -982,20 +982,20 @@ template GraphCopy& nodeCrossRef(NodeCrossRef& map) { _node_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); + NodeRefMap, NodeCrossRef>(map)); return *this; } /// \brief Make copy of the given map. /// - /// Makes copy of the given map for the newly created graph. + /// Makes copy of the given map for the newly created graph. /// The new map's key type is the to graph's node type, /// and the copied map's key type is the from graph's node - /// type. + /// type. template GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { - _node_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); + _node_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); return *this; } @@ -1003,8 +1003,8 @@ /// /// Make a copy of the given node. GraphCopy& node(TNode& tnode, const Node& snode) { - _node_maps.push_back(new _graph_utils_bits::ItemCopy(tnode, snode)); + _node_maps.push_back(new _graph_utils_bits::ItemCopy(tnode, snode)); return *this; } @@ -1013,8 +1013,8 @@ /// Copies the arc references into the given map. template GraphCopy& arcRef(ArcRef& map) { - _arc_maps.push_back(new _graph_utils_bits::RefCopy(map)); + _arc_maps.push_back(new _graph_utils_bits::RefCopy(map)); return *this; } @@ -1025,20 +1025,20 @@ template GraphCopy& arcCrossRef(ArcCrossRef& map) { _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); + ArcRefMap, ArcCrossRef>(map)); return *this; } /// \brief Make copy of the given map. /// - /// Makes copy of the given map for the newly created graph. + /// Makes copy of the given map for the newly created graph. /// The new map's key type is the to graph's arc type, /// and the copied map's key type is the from graph's arc - /// type. + /// type. template GraphCopy& arcMap(ToMap& tmap, const FromMap& map) { - _arc_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); + _arc_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); return *this; } @@ -1046,8 +1046,8 @@ /// /// Make a copy of the given arc. GraphCopy& arc(TArc& tarc, const Arc& sarc) { - _arc_maps.push_back(new _graph_utils_bits::ItemCopy(tarc, sarc)); + _arc_maps.push_back(new _graph_utils_bits::ItemCopy(tarc, sarc)); return *this; } @@ -1056,8 +1056,8 @@ /// Copies the edge references into the given map. template GraphCopy& edgeRef(EdgeRef& map) { - _edge_maps.push_back(new _graph_utils_bits::RefCopy(map)); + _edge_maps.push_back(new _graph_utils_bits::RefCopy(map)); return *this; } @@ -1067,21 +1067,21 @@ /// references) into the given map. template GraphCopy& edgeCrossRef(EdgeCrossRef& map) { - _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); + _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy(map)); return *this; } /// \brief Make copy of the given map. /// - /// Makes copy of the given map for the newly created graph. + /// Makes copy of the given map for the newly created graph. /// The new map's key type is the to graph's edge type, /// and the copied map's key type is the from graph's edge - /// type. + /// type. template GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) { - _edge_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); + _edge_maps.push_back(new _graph_utils_bits::MapCopy(tmap, map)); return *this; } @@ -1089,8 +1089,8 @@ /// /// Make a copy of the given edge. GraphCopy& edge(TEdge& tedge, const Edge& sedge) { - _edge_maps.push_back(new _graph_utils_bits::ItemCopy(tedge, sedge)); + _edge_maps.push_back(new _graph_utils_bits::ItemCopy(tedge, sedge)); return *this; } @@ -1115,17 +1115,17 @@ } private: - + const From& _from; To& _to; - std::vector<_graph_utils_bits::MapCopyBase* > + std::vector<_graph_utils_bits::MapCopyBase* > _node_maps; - std::vector<_graph_utils_bits::MapCopyBase* > + std::vector<_graph_utils_bits::MapCopyBase* > _arc_maps; - std::vector<_graph_utils_bits::MapCopyBase* > + std::vector<_graph_utils_bits::MapCopyBase* > _edge_maps; }; @@ -1138,15 +1138,15 @@ ///\code /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); ///\endcode - /// + /// /// After the copy the \c nr map will contain the mapping from the /// nodes of the \c from graph to the nodes of the \c to graph and /// \c ecr will contain the mapping from the arcs of the \c to graph /// to the arcs of the \c from graph. /// - /// \see GraphCopy + /// \see GraphCopy template - GraphCopy + GraphCopy copyGraph(To& to, const From& from) { return GraphCopy(to, from); } @@ -1214,7 +1214,7 @@ /// \brief Gives back the given item from its id. /// /// Gives back the given item from its id. - /// + /// Item operator[](int id) const { return _graph->fromId(id, Item());} private: @@ -1224,15 +1224,15 @@ /// \brief Gives back the inverse of the map. /// /// Gives back the inverse of the IdMap. - InverseMap inverse() const { return InverseMap(*_graph);} + InverseMap inverse() const { return InverseMap(*_graph);} }; - + /// \brief General invertable graph-map type. - /// This type provides simple invertable graph-maps. - /// The InvertableMap wraps an arbitrary ReadWriteMap + /// This type provides simple invertable graph-maps. + /// The InvertableMap wraps an arbitrary ReadWriteMap /// and if a key is set to a new value then store it /// in the inverse map. /// @@ -1247,15 +1247,15 @@ template class InvertableMap : protected DefaultMap<_Graph, _Item, _Value> { private: - + typedef DefaultMap<_Graph, _Item, _Value> Map; typedef _Graph Graph; typedef std::map<_Value, _Item> Container; - Container _inv_map; + Container _inv_map; public: - + /// The key type of InvertableMap (Node, Arc, Edge). typedef typename Map::Key Key; /// The value type of the InvertableMap. @@ -1267,7 +1267,7 @@ /// /// Construct a new InvertableMap for the graph. /// - explicit InvertableMap(const Graph& graph) : Map(graph) {} + explicit InvertableMap(const Graph& graph) : Map(graph) {} /// \brief Forward iterator for values. /// @@ -1275,21 +1275,21 @@ /// iterator on the values of the map. The values can /// be accessed in the [beginValue, endValue) range. /// - class ValueIterator + class ValueIterator : public std::iterator { friend class InvertableMap; private: - ValueIterator(typename Container::const_iterator _it) + ValueIterator(typename Container::const_iterator _it) : it(_it) {} public: - + ValueIterator() {} ValueIterator& operator++() { ++it; return *this; } - ValueIterator operator++(int) { - ValueIterator tmp(*this); + ValueIterator operator++(int) { + ValueIterator tmp(*this); operator++(); - return tmp; + return tmp; } const Value& operator*() const { return it->first; } @@ -1297,14 +1297,14 @@ bool operator==(ValueIterator jt) const { return it == jt.it; } bool operator!=(ValueIterator jt) const { return it != jt.it; } - + private: typename Container::const_iterator it; }; /// \brief Returns an iterator to the first value. /// - /// Returns an stl compatible iterator to the + /// Returns an stl compatible iterator to the /// first value of the map. The values of the /// map can be accessed in the [beginValue, endValue) /// range. @@ -1314,14 +1314,14 @@ /// \brief Returns an iterator after the last value. /// - /// Returns an stl compatible iterator after the + /// Returns an stl compatible iterator after the /// last value of the map. The values of the /// map can be accessed in the [beginValue, endValue) /// range. ValueIterator endValue() const { return ValueIterator(_inv_map.end()); } - + /// \brief The setter function of the map. /// /// Sets the mapped value. @@ -1329,8 +1329,8 @@ Value oldval = Map::operator[](key); typename Container::iterator it = _inv_map.find(oldval); if (it != _inv_map.end() && it->second == key) { - _inv_map.erase(it); - } + _inv_map.erase(it); + } _inv_map.insert(make_pair(val, key)); Map::set(key, val); } @@ -1338,7 +1338,7 @@ /// \brief The getter function of the map. /// /// It gives back the value associated with the key. - typename MapTraits::ConstReturnValue + typename MapTraits::ConstReturnValue operator[](const Key& key) const { return Map::operator[](key); } @@ -1361,7 +1361,7 @@ Value val = Map::operator[](key); typename Container::iterator it = _inv_map.find(val); if (it != _inv_map.end() && it->second == key) { - _inv_map.erase(it); + _inv_map.erase(it); } Map::erase(key); } @@ -1372,11 +1372,11 @@ /// \c AlterationNotifier. virtual void erase(const std::vector& keys) { for (int i = 0; i < int(keys.size()); ++i) { - Value val = Map::operator[](keys[i]); - typename Container::iterator it = _inv_map.find(val); - if (it != _inv_map.end() && it->second == keys[i]) { - _inv_map.erase(it); - } + Value val = Map::operator[](keys[i]); + typename Container::iterator it = _inv_map.find(val); + if (it != _inv_map.end() && it->second == keys[i]) { + _inv_map.erase(it); + } } Map::erase(keys); } @@ -1395,28 +1395,28 @@ /// \brief The inverse map type. /// /// The inverse of this map. The subscript operator of the map - /// gives back always the item what was last assigned to the value. + /// gives back always the item what was last assigned to the value. class InverseMap { public: /// \brief Constructor of the InverseMap. /// /// Constructor of the InverseMap. - explicit InverseMap(const InvertableMap& inverted) + explicit InverseMap(const InvertableMap& inverted) : _inverted(inverted) {} /// The value type of the InverseMap. typedef typename InvertableMap::Key Value; /// The key type of the InverseMap. - typedef typename InvertableMap::Value Key; - - /// \brief Subscript operator. + typedef typename InvertableMap::Value Key; + + /// \brief Subscript operator. /// - /// Subscript operator. It gives back always the item + /// Subscript operator. It gives back always the item /// what was last assigned to the value. Value operator[](const Key& key) const { - return _inverted(key); + return _inverted(key); } - + private: const InvertableMap& _inverted; }; @@ -1426,13 +1426,13 @@ /// It gives back the just readable inverse map. InverseMap inverse() const { return InverseMap(*this); - } - - - + } + + + }; - /// \brief Provides a mutable, continuous and unique descriptor for each + /// \brief Provides a mutable, continuous and unique descriptor for each /// item in the graph. /// /// The DescriptorMap class provides a unique and continuous (but mutable) @@ -1445,7 +1445,7 @@ /// with its member class \c InverseMap, or with the \c operator() member. /// /// \tparam _Graph The graph class the \c DescriptorMap belongs to. - /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or + /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or /// Edge. template class DescriptorMap : protected DefaultMap<_Graph, _Item, int> { @@ -1467,11 +1467,11 @@ /// Constructor for descriptor map. explicit DescriptorMap(const Graph& _graph) : Map(_graph) { Item it; - const typename Map::Notifier* nf = Map::notifier(); + const typename Map::Notifier* nf = Map::notifier(); for (nf->first(it); it != INVALID; nf->next(it)) { - Map::set(it, _inv_map.size()); - _inv_map.push_back(it); - } + Map::set(it, _inv_map.size()); + _inv_map.push_back(it); + } } protected: @@ -1493,8 +1493,8 @@ virtual void add(const std::vector& items) { Map::add(items); for (int i = 0; i < int(items.size()); ++i) { - Map::set(items[i], _inv_map.size()); - _inv_map.push_back(items[i]); + Map::set(items[i], _inv_map.size()); + _inv_map.push_back(items[i]); } } @@ -1515,9 +1515,9 @@ /// \c AlterationNotifier. virtual void erase(const std::vector& items) { for (int i = 0; i < int(items.size()); ++i) { - Map::set(_inv_map.back(), Map::operator[](items[i])); - _inv_map[Map::operator[](items[i])] = _inv_map.back(); - _inv_map.pop_back(); + Map::set(_inv_map.back(), Map::operator[](items[i])); + _inv_map[Map::operator[](items[i])] = _inv_map.back(); + _inv_map.pop_back(); } Map::erase(items); } @@ -1529,13 +1529,13 @@ virtual void build() { Map::build(); Item it; - const typename Map::Notifier* nf = Map::notifier(); + const typename Map::Notifier* nf = Map::notifier(); for (nf->first(it); it != INVALID; nf->next(it)) { - Map::set(it, _inv_map.size()); - _inv_map.push_back(it); - } + Map::set(it, _inv_map.size()); + _inv_map.push_back(it); + } } - + /// \brief Clear the keys from the map. /// /// Clear the keys from the map. It is called by the @@ -1579,7 +1579,7 @@ Item operator()(int id) const { return _inv_map[id]; } - + private: typedef std::vector Container; @@ -1594,30 +1594,30 @@ /// \brief Constructor of the InverseMap. /// /// Constructor of the InverseMap. - explicit InverseMap(const DescriptorMap& inverted) - : _inverted(inverted) {} + explicit InverseMap(const DescriptorMap& inverted) + : _inverted(inverted) {} /// The value type of the InverseMap. typedef typename DescriptorMap::Key Value; /// The key type of the InverseMap. - typedef typename DescriptorMap::Value Key; - - /// \brief Subscript operator. + typedef typename DescriptorMap::Value Key; + + /// \brief Subscript operator. /// - /// Subscript operator. It gives back the item + /// Subscript operator. It gives back the item /// that the descriptor belongs to currently. Value operator[](const Key& key) const { - return _inverted(key); + return _inverted(key); } /// \brief Size of the map. /// /// Returns the size of the map. unsigned int size() const { - return _inverted.size(); + return _inverted.size(); } - + private: const DescriptorMap& _inverted; }; @@ -1632,7 +1632,7 @@ /// \brief Returns the source of the given arc. /// - /// The SourceMap gives back the source Node of the given arc. + /// The SourceMap gives back the source Node of the given arc. /// \see TargetMap template class SourceMap { @@ -1650,8 +1650,8 @@ /// \brief The subscript operator. /// /// The subscript operator. - /// \param arc The arc - /// \return The source of the arc + /// \param arc The arc + /// \return The source of the arc Value operator[](const Key& arc) const { return _digraph.source(arc); } @@ -1667,11 +1667,11 @@ template inline SourceMap sourceMap(const Digraph& digraph) { return SourceMap(digraph); - } + } /// \brief Returns the target of the given arc. /// - /// The TargetMap gives back the target Node of the given arc. + /// The TargetMap gives back the target Node of the given arc. /// \see SourceMap template class TargetMap { @@ -1689,8 +1689,8 @@ /// \brief The subscript operator. /// /// The subscript operator. - /// \param e The arc - /// \return The target of the arc + /// \param e The arc + /// \return The target of the arc Value operator[](const Key& e) const { return _digraph.target(e); } @@ -1728,8 +1728,8 @@ /// \brief The subscript operator. /// /// The subscript operator. - /// \param key An edge - /// \return The "forward" directed arc view of edge + /// \param key An edge + /// \return The "forward" directed arc view of edge Value operator[](const Key& key) const { return _graph.direct(key, true); } @@ -1767,8 +1767,8 @@ /// \brief The subscript operator. /// /// The subscript operator. - /// \param key An edge - /// \return The "backward" directed arc view of edge + /// \param key An edge + /// \return The "backward" directed arc view of edge Value operator[](const Key& key) const { return _graph.direct(key, false); } @@ -1800,16 +1800,16 @@ /// \brief Constructor /// /// Contructor of the map - explicit PotentialDifferenceMap(const Digraph& digraph, - const NodeMap& potential) + explicit PotentialDifferenceMap(const Digraph& digraph, + const NodeMap& potential) : _digraph(digraph), _potential(potential) {} /// \brief Const subscription operator /// /// Const subscription operator Value operator[](const Key& arc) const { - return _potential[_digraph.target(arc)] - - _potential[_digraph.source(arc)]; + return _potential[_digraph.target(arc)] - + _potential[_digraph.source(arc)]; } private: @@ -1822,7 +1822,7 @@ /// This function just returns a PotentialDifferenceMap. /// \relates PotentialDifferenceMap template - PotentialDifferenceMap + PotentialDifferenceMap potentialDifferenceMap(const Digraph& digraph, const NodeMap& potential) { return PotentialDifferenceMap(digraph, potential); } @@ -1845,12 +1845,12 @@ /// \sa OutDegMap template - class InDegMap + class InDegMap : protected ItemSetTraits<_Digraph, typename _Digraph::Arc> ::ItemNotifier::ObserverBase { public: - + typedef _Digraph Digraph; typedef int Value; typedef typename Digraph::Node Key; @@ -1866,26 +1866,26 @@ typedef DefaultMap Parent; AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} - + virtual void add(const Key& key) { - Parent::add(key); - Parent::set(key, 0); + Parent::add(key); + Parent::set(key, 0); } virtual void add(const std::vector& keys) { - Parent::add(keys); - for (int i = 0; i < int(keys.size()); ++i) { - Parent::set(keys[i], 0); - } + Parent::add(keys); + for (int i = 0; i < int(keys.size()); ++i) { + Parent::set(keys[i], 0); + } } virtual void build() { - Parent::build(); - Key it; - typename Parent::Notifier* nf = Parent::notifier(); - for (nf->first(it); it != INVALID; nf->next(it)) { - Parent::set(it, 0); - } + Parent::build(); + Key it; + typename Parent::Notifier* nf = Parent::notifier(); + for (nf->first(it); it != INVALID; nf->next(it)) { + Parent::set(it, 0); + } } }; @@ -1894,22 +1894,22 @@ /// \brief Constructor. /// /// Constructor for creating in-degree map. - explicit InDegMap(const Digraph& digraph) + explicit InDegMap(const Digraph& digraph) : _digraph(digraph), _deg(digraph) { Parent::attach(_digraph.notifier(typename Digraph::Arc())); - + for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = countInArcs(_digraph, it); + _deg[it] = countInArcs(_digraph, it); } } - + /// Gives back the in-degree of a Node. int operator[](const Key& key) const { return _deg[key]; } protected: - + typedef typename Digraph::Arc Arc; virtual void add(const Arc& arc) { @@ -1934,17 +1934,17 @@ virtual void build() { for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = countInArcs(_digraph, it); - } + _deg[it] = countInArcs(_digraph, it); + } } virtual void clear() { for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = 0; + _deg[it] = 0; } } private: - + const Digraph& _digraph; AutoNodeMap _deg; }; @@ -1967,12 +1967,12 @@ /// \sa InDegMap template - class OutDegMap + class OutDegMap : protected ItemSetTraits<_Digraph, typename _Digraph::Arc> ::ItemNotifier::ObserverBase { public: - + typedef _Digraph Digraph; typedef int Value; typedef typename Digraph::Node Key; @@ -1988,24 +1988,24 @@ typedef DefaultMap Parent; AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} - + virtual void add(const Key& key) { - Parent::add(key); - Parent::set(key, 0); + Parent::add(key); + Parent::set(key, 0); } virtual void add(const std::vector& keys) { - Parent::add(keys); - for (int i = 0; i < int(keys.size()); ++i) { - Parent::set(keys[i], 0); - } + Parent::add(keys); + for (int i = 0; i < int(keys.size()); ++i) { + Parent::set(keys[i], 0); + } } virtual void build() { - Parent::build(); - Key it; - typename Parent::Notifier* nf = Parent::notifier(); - for (nf->first(it); it != INVALID; nf->next(it)) { - Parent::set(it, 0); - } + Parent::build(); + Key it; + typename Parent::Notifier* nf = Parent::notifier(); + for (nf->first(it); it != INVALID; nf->next(it)) { + Parent::set(it, 0); + } } }; @@ -2014,12 +2014,12 @@ /// \brief Constructor. /// /// Constructor for creating out-degree map. - explicit OutDegMap(const Digraph& digraph) + explicit OutDegMap(const Digraph& digraph) : _digraph(digraph), _deg(digraph) { Parent::attach(_digraph.notifier(typename Digraph::Arc())); - + for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = countOutArcs(_digraph, it); + _deg[it] = countOutArcs(_digraph, it); } } @@ -2029,7 +2029,7 @@ } protected: - + typedef typename Digraph::Arc Arc; virtual void add(const Arc& arc) { @@ -2054,24 +2054,24 @@ virtual void build() { for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = countOutArcs(_digraph, it); - } + _deg[it] = countOutArcs(_digraph, it); + } } virtual void clear() { for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { - _deg[it] = 0; + _deg[it] = 0; } } private: - + const Digraph& _digraph; AutoNodeMap _deg; }; ///Dynamic arc look up between given endpoints. - + ///\ingroup gutils ///Using this class, you can find an arc in a digraph from a given ///source to a given target in amortized time O(log d), @@ -2089,12 +2089,12 @@ ///optimal time bound in a constant factor for any distribution of ///queries. /// - ///\tparam G The type of the underlying digraph. + ///\tparam G The type of the underlying digraph. /// - ///\sa ArcLookUp - ///\sa AllArcLookUp + ///\sa ArcLookUp + ///\sa AllArcLookUp template - class DynArcLookUp + class DynArcLookUp : protected ItemSetTraits::ItemNotifier::ObserverBase { public: @@ -2112,26 +2112,26 @@ typedef DefaultMap Parent; AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {} - + virtual void add(const Node& node) { - Parent::add(node); - Parent::set(node, INVALID); + Parent::add(node); + Parent::set(node, INVALID); } virtual void add(const std::vector& nodes) { - Parent::add(nodes); - for (int i = 0; i < int(nodes.size()); ++i) { - Parent::set(nodes[i], INVALID); - } + Parent::add(nodes); + for (int i = 0; i < int(nodes.size()); ++i) { + Parent::set(nodes[i], INVALID); + } } virtual void build() { - Parent::build(); - Node it; - typename Parent::Notifier* nf = Parent::notifier(); - for (nf->first(it); it != INVALID; nf->next(it)) { - Parent::set(it, INVALID); - } + Parent::build(); + Node it; + typename Parent::Notifier* nf = Parent::notifier(); + for (nf->first(it); it != INVALID; nf->next(it)) { + Parent::set(it, INVALID); + } } }; @@ -2140,31 +2140,31 @@ typename Digraph::template ArcMap _parent; typename Digraph::template ArcMap _left; typename Digraph::template ArcMap _right; - + class ArcLess { const Digraph &g; public: ArcLess(const Digraph &_g) : g(_g) {} - bool operator()(Arc a,Arc b) const + bool operator()(Arc a,Arc b) const { - return g.target(a)& arcs) { for (int i = 0; i < int(arcs.size()); ++i) { - insert(arcs[i]); + insert(arcs[i]); } } @@ -2183,8 +2183,8 @@ virtual void erase(const std::vector& arcs) { for (int i = 0; i < int(arcs.size()); ++i) { - remove(arcs[i]); - } + remove(arcs[i]); + } } virtual void build() { @@ -2193,7 +2193,7 @@ virtual void clear() { for(NodeIt n(_g);n!=INVALID;++n) { - _head.set(n, INVALID); + _head.set(n, INVALID); } } @@ -2202,212 +2202,212 @@ Node t = _g.target(arc); _left.set(arc, INVALID); _right.set(arc, INVALID); - + Arc e = _head[s]; if (e == INVALID) { - _head.set(s, arc); - _parent.set(arc, INVALID); - return; + _head.set(s, arc); + _parent.set(arc, INVALID); + return; } while (true) { - if (t < _g.target(e)) { - if (_left[e] == INVALID) { - _left.set(e, arc); - _parent.set(arc, e); - splay(arc); - return; - } else { - e = _left[e]; - } - } else { - if (_right[e] == INVALID) { - _right.set(e, arc); - _parent.set(arc, e); - splay(arc); - return; - } else { - e = _right[e]; - } - } + if (t < _g.target(e)) { + if (_left[e] == INVALID) { + _left.set(e, arc); + _parent.set(arc, e); + splay(arc); + return; + } else { + e = _left[e]; + } + } else { + if (_right[e] == INVALID) { + _right.set(e, arc); + _parent.set(arc, e); + splay(arc); + return; + } else { + e = _right[e]; + } + } } } void remove(Arc arc) { if (_left[arc] == INVALID) { - if (_right[arc] != INVALID) { - _parent.set(_right[arc], _parent[arc]); - } - if (_parent[arc] != INVALID) { - if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], _right[arc]); - } else { - _right.set(_parent[arc], _right[arc]); - } - } else { - _head.set(_g.source(arc), _right[arc]); - } + if (_right[arc] != INVALID) { + _parent.set(_right[arc], _parent[arc]); + } + if (_parent[arc] != INVALID) { + if (_left[_parent[arc]] == arc) { + _left.set(_parent[arc], _right[arc]); + } else { + _right.set(_parent[arc], _right[arc]); + } + } else { + _head.set(_g.source(arc), _right[arc]); + } } else if (_right[arc] == INVALID) { - _parent.set(_left[arc], _parent[arc]); - if (_parent[arc] != INVALID) { - if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], _left[arc]); - } else { - _right.set(_parent[arc], _left[arc]); - } - } else { - _head.set(_g.source(arc), _left[arc]); - } + _parent.set(_left[arc], _parent[arc]); + if (_parent[arc] != INVALID) { + if (_left[_parent[arc]] == arc) { + _left.set(_parent[arc], _left[arc]); + } else { + _right.set(_parent[arc], _left[arc]); + } + } else { + _head.set(_g.source(arc), _left[arc]); + } } else { - Arc e = _left[arc]; - if (_right[e] != INVALID) { - e = _right[e]; - while (_right[e] != INVALID) { - e = _right[e]; - } - Arc s = _parent[e]; - _right.set(_parent[e], _left[e]); - if (_left[e] != INVALID) { - _parent.set(_left[e], _parent[e]); - } - - _left.set(e, _left[arc]); - _parent.set(_left[arc], e); - _right.set(e, _right[arc]); - _parent.set(_right[arc], e); - - _parent.set(e, _parent[arc]); - if (_parent[arc] != INVALID) { - if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], e); - } else { - _right.set(_parent[arc], e); - } - } - splay(s); - } else { - _right.set(e, _right[arc]); - _parent.set(_right[arc], e); - - if (_parent[arc] != INVALID) { - if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], e); - } else { - _right.set(_parent[arc], e); - } - } else { - _head.set(_g.source(arc), e); - } - } + Arc e = _left[arc]; + if (_right[e] != INVALID) { + e = _right[e]; + while (_right[e] != INVALID) { + e = _right[e]; + } + Arc s = _parent[e]; + _right.set(_parent[e], _left[e]); + if (_left[e] != INVALID) { + _parent.set(_left[e], _parent[e]); + } + + _left.set(e, _left[arc]); + _parent.set(_left[arc], e); + _right.set(e, _right[arc]); + _parent.set(_right[arc], e); + + _parent.set(e, _parent[arc]); + if (_parent[arc] != INVALID) { + if (_left[_parent[arc]] == arc) { + _left.set(_parent[arc], e); + } else { + _right.set(_parent[arc], e); + } + } + splay(s); + } else { + _right.set(e, _right[arc]); + _parent.set(_right[arc], e); + + if (_parent[arc] != INVALID) { + if (_left[_parent[arc]] == arc) { + _left.set(_parent[arc], e); + } else { + _right.set(_parent[arc], e); + } + } else { + _head.set(_g.source(arc), e); + } + } } } - Arc refreshRec(std::vector &v,int a,int b) + Arc refreshRec(std::vector &v,int a,int b) { int m=(a+b)/2; Arc me=v[m]; if (a < m) { - Arc left = refreshRec(v,a,m-1); - _left.set(me, left); - _parent.set(left, me); + Arc left = refreshRec(v,a,m-1); + _left.set(me, left); + _parent.set(left, me); } else { - _left.set(me, INVALID); + _left.set(me, INVALID); } if (m < b) { - Arc right = refreshRec(v,m+1,b); - _right.set(me, right); - _parent.set(right, me); + Arc right = refreshRec(v,m+1,b); + _right.set(me, right); + _parent.set(right, me); } else { - _right.set(me, INVALID); + _right.set(me, INVALID); } return me; } void refresh() { for(NodeIt n(_g);n!=INVALID;++n) { - std::vector v; - for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e); - if(v.size()) { - std::sort(v.begin(),v.end(),ArcLess(_g)); - Arc head = refreshRec(v,0,v.size()-1); - _head.set(n, head); - _parent.set(head, INVALID); - } - else _head.set(n, INVALID); + std::vector v; + for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e); + if(v.size()) { + std::sort(v.begin(),v.end(),ArcLess(_g)); + Arc head = refreshRec(v,0,v.size()-1); + _head.set(n, head); + _parent.set(head, INVALID); + } + else _head.set(n, INVALID); } } - void zig(Arc v) { + void zig(Arc v) { Arc w = _parent[v]; _parent.set(v, _parent[w]); _parent.set(w, v); _left.set(w, _right[v]); _right.set(v, w); if (_parent[v] != INVALID) { - if (_right[_parent[v]] == w) { - _right.set(_parent[v], v); - } else { - _left.set(_parent[v], v); - } + if (_right[_parent[v]] == w) { + _right.set(_parent[v], v); + } else { + _left.set(_parent[v], v); + } } if (_left[w] != INVALID){ - _parent.set(_left[w], w); + _parent.set(_left[w], w); } } - void zag(Arc v) { + void zag(Arc v) { Arc w = _parent[v]; _parent.set(v, _parent[w]); _parent.set(w, v); _right.set(w, _left[v]); _left.set(v, w); if (_parent[v] != INVALID){ - if (_left[_parent[v]] == w) { - _left.set(_parent[v], v); - } else { - _right.set(_parent[v], v); - } + if (_left[_parent[v]] == w) { + _left.set(_parent[v], v); + } else { + _right.set(_parent[v], v); + } } if (_right[w] != INVALID){ - _parent.set(_right[w], w); + _parent.set(_right[w], w); } } void splay(Arc v) { while (_parent[v] != INVALID) { - if (v == _left[_parent[v]]) { - if (_parent[_parent[v]] == INVALID) { - zig(v); - } else { - if (_parent[v] == _left[_parent[_parent[v]]]) { - zig(_parent[v]); - zig(v); - } else { - zig(v); - zag(v); - } - } - } else { - if (_parent[_parent[v]] == INVALID) { - zag(v); - } else { - if (_parent[v] == _left[_parent[_parent[v]]]) { - zag(v); - zig(v); - } else { - zag(_parent[v]); - zag(v); - } - } - } + if (v == _left[_parent[v]]) { + if (_parent[_parent[v]] == INVALID) { + zig(v); + } else { + if (_parent[v] == _left[_parent[_parent[v]]]) { + zig(_parent[v]); + zig(v); + } else { + zig(v); + zag(v); + } + } + } else { + if (_parent[_parent[v]] == INVALID) { + zag(v); + } else { + if (_parent[v] == _left[_parent[_parent[v]]]) { + zag(v); + zig(v); + } else { + zag(_parent[v]); + zag(v); + } + } + } } _head[_g.source(v)] = v; } public: - + ///Find an arc between two nodes. - + ///Find an arc between two nodes in time O(logd), where /// d is the number of outgoing arcs of \c s. ///\param s The source node @@ -2418,33 +2418,33 @@ { Arc a = _head[s]; while (true) { - if (_g.target(a) == t) { - const_cast(*this).splay(a); - return a; - } else if (t < _g.target(a)) { - if (_left[a] == INVALID) { - const_cast(*this).splay(a); - return INVALID; - } else { - a = _left[a]; - } - } else { - if (_right[a] == INVALID) { - const_cast(*this).splay(a); - return INVALID; - } else { - a = _right[a]; - } - } + if (_g.target(a) == t) { + const_cast(*this).splay(a); + return a; + } else if (t < _g.target(a)) { + if (_left[a] == INVALID) { + const_cast(*this).splay(a); + return INVALID; + } else { + a = _left[a]; + } + } else { + if (_right[a] == INVALID) { + const_cast(*this).splay(a); + return INVALID; + } else { + a = _right[a]; + } + } } } ///Find the first arc between two nodes. - + ///Find the first arc between two nodes in time /// O(logd), where d is the number of - /// outgoing arcs of \c s. - ///\param s The source node + /// outgoing arcs of \c s. + ///\param s The source node ///\param t The target node ///\return An arc from \c s to \c t if there exists, \ref INVALID /// otherwise. @@ -2453,33 +2453,33 @@ Arc a = _head[s]; Arc r = INVALID; while (true) { - if (_g.target(a) < t) { - if (_right[a] == INVALID) { - const_cast(*this).splay(a); - return r; - } else { - a = _right[a]; - } - } else { - if (_g.target(a) == t) { - r = a; - } - if (_left[a] == INVALID) { - const_cast(*this).splay(a); - return r; - } else { - a = _left[a]; - } - } + if (_g.target(a) < t) { + if (_right[a] == INVALID) { + const_cast(*this).splay(a); + return r; + } else { + a = _right[a]; + } + } else { + if (_g.target(a) == t) { + r = a; + } + if (_left[a] == INVALID) { + const_cast(*this).splay(a); + return r; + } else { + a = _left[a]; + } + } } } ///Find the next arc between two nodes. - + ///Find the next arc between two nodes in time /// O(logd), where d is the number of - /// outgoing arcs of \c s. - ///\param s The source node + /// outgoing arcs of \c s. + ///\param s The source node ///\param t The target node ///\return An arc from \c s to \c t if there exists, \ref INVALID /// otherwise. @@ -2493,30 +2493,30 @@ #endif { if (_right[a] != INVALID) { - a = _right[a]; - while (_left[a] != INVALID) { - a = _left[a]; - } - const_cast(*this).splay(a); + a = _right[a]; + while (_left[a] != INVALID) { + a = _left[a]; + } + const_cast(*this).splay(a); } else { - while (_parent[a] != INVALID && _right[_parent[a]] == a) { - a = _parent[a]; - } - if (_parent[a] == INVALID) { - return INVALID; - } else { - a = _parent[a]; - const_cast(*this).splay(a); - } + while (_parent[a] != INVALID && _right[_parent[a]] == a) { + a = _parent[a]; + } + if (_parent[a] == INVALID) { + return INVALID; + } else { + a = _parent[a]; + const_cast(*this).splay(a); + } } if (_g.target(a) == t) return a; - else return INVALID; + else return INVALID; } }; ///Fast arc look up between given endpoints. - + ///\ingroup gutils ///Using this class, you can find an arc in a digraph from a given ///source to a given target in time O(log d), @@ -2533,9 +2533,9 @@ ///\tparam G The type of the underlying digraph. /// ///\sa DynArcLookUp - ///\sa AllArcLookUp + ///\sa AllArcLookUp template - class ArcLookUp + class ArcLookUp { public: TEMPLATE_DIGRAPH_TYPEDEFS(G); @@ -2546,19 +2546,19 @@ typename Digraph::template NodeMap _head; typename Digraph::template ArcMap _left; typename Digraph::template ArcMap _right; - + class ArcLess { const Digraph &g; public: ArcLess(const Digraph &_g) : g(_g) {} - bool operator()(Arc a,Arc b) const + bool operator()(Arc a,Arc b) const { - return g.target(a) &v,int a,int b) + Arc refreshRec(std::vector &v,int a,int b) { int m=(a+b)/2; Arc me=v[m]; @@ -2583,13 +2583,13 @@ /// ///It runs in time O(dlogd), where d is ///the number of the outgoing arcs of \c n. - void refresh(Node n) + void refresh(Node n) { std::vector v; for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e); if(v.size()) { - std::sort(v.begin(),v.end(),ArcLess(_g)); - _head[n]=refreshRec(v,0,v.size()-1); + std::sort(v.begin(),v.end(),ArcLess(_g)); + _head[n]=refreshRec(v,0,v.size()-1); } else _head[n]=INVALID; } @@ -2602,13 +2602,13 @@ ///the number of the arcs of \c n and D is the maximum ///out-degree of the digraph. - void refresh() + void refresh() { for(NodeIt n(_g);n!=INVALID;++n) refresh(n); } - + ///Find an arc between two nodes. - + ///Find an arc between two nodes in time O(logd), where /// d is the number of outgoing arcs of \c s. ///\param s The source node @@ -2625,15 +2625,15 @@ { Arc e; for(e=_head[s]; - e!=INVALID&&_g.target(e)!=t; - e = t < _g.target(e)?_left[e]:_right[e]) ; + e!=INVALID&&_g.target(e)!=t; + e = t < _g.target(e)?_left[e]:_right[e]) ; return e; } }; ///Fast look up of all arcs between given endpoints. - + ///\ingroup gutils ///This class is the same as \ref ArcLookUp, with the addition ///that it makes it possible to find all arcs between given endpoints. @@ -2646,7 +2646,7 @@ ///\tparam G The type of the underlying digraph. /// ///\sa DynArcLookUp - ///\sa ArcLookUp + ///\sa ArcLookUp template class AllArcLookUp : public ArcLookUp { @@ -2657,26 +2657,26 @@ TEMPLATE_DIGRAPH_TYPEDEFS(G); typedef G Digraph; - + typename Digraph::template ArcMap _next; - + Arc refreshNext(Arc head,Arc next=INVALID) { if(head==INVALID) return next; else { - next=refreshNext(_right[head],next); -// _next[head]=next; - _next[head]=( next!=INVALID && _g.target(next)==_g.target(head)) - ? next : INVALID; - return refreshNext(_left[head],head); + next=refreshNext(_right[head],next); +// _next[head]=next; + _next[head]=( next!=INVALID && _g.target(next)==_g.target(head)) + ? next : INVALID; + return refreshNext(_left[head],head); } } - + void refreshNext() { for(NodeIt n(_g);n!=INVALID;++n) refreshNext(_head[n]); } - + public: ///Constructor @@ -2692,13 +2692,13 @@ /// ///It runs in time O(dlogd), where d is ///the number of the outgoing arcs of \c n. - - void refresh(Node n) + + void refresh(Node n) { ArcLookUp::refresh(n); refreshNext(_head[n]); } - + ///Refresh the full data structure. ///Build up the full search database. In fact, it simply calls @@ -2708,13 +2708,13 @@ ///the number of the arcs of \c n and D is the maximum ///out-degree of the digraph. - void refresh() + void refresh() { for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]); } - + ///Find an arc between two nodes. - + ///Find an arc between two nodes. ///\param s The source node ///\param t The target node @@ -2750,7 +2750,7 @@ return prev==INVALID?(*this)(s,t):_next[prev]; } #endif - + }; /// @} diff -r 4317d277ba21 -r 765619b7cbb2 lemon/kruskal.h --- a/lemon/kruskal.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/kruskal.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -45,18 +45,18 @@ template typename disable_if, - typename In::value_type::second_type >::type + typename In::value_type::second_type >::type kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) { typedef typename In::value_type::second_type Value; typedef typename Digraph::template NodeMap IndexMap; typedef typename Digraph::Node Node; - + IndexMap index(digraph); UnionFind uf(index); for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) { uf.insert(it); } - + Value tree_value = 0; for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) { if (uf.join(digraph.target(it->first),digraph.source(it->first))) { @@ -74,18 +74,18 @@ template typename enable_if, - typename In::value_type::second_type >::type + typename In::value_type::second_type >::type kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) { typedef typename In::value_type::second_type Value; typedef typename Graph::template NodeMap IndexMap; typedef typename Graph::Node Node; - + IndexMap index(graph); UnionFind uf(index); for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { uf.insert(it); } - + Value tree_value = 0; for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) { if (uf.join(graph.u(it->first),graph.v(it->first))) { @@ -104,7 +104,7 @@ struct PairComp { typedef typename Sequence::value_type Value; bool operator()(const Value& left, const Value& right) { - return left.second < right.second; + return left.second < right.second; } }; @@ -114,7 +114,7 @@ }; template - struct SequenceInputIndicator::type> { static const bool value = true; }; @@ -125,7 +125,7 @@ }; template - struct MapInputIndicator::type> { static const bool value = true; }; @@ -134,9 +134,9 @@ struct SequenceOutputIndicator { static const bool value = false; }; - + template - struct SequenceOutputIndicator::type> { static const bool value = true; }; @@ -147,7 +147,7 @@ }; template - struct MapOutputIndicator::type> { static const bool value = true; }; @@ -157,18 +157,18 @@ template struct KruskalValueSelector, void>::type> + typename enable_if, void>::type> { typedef typename In::value_type::second_type Value; - }; + }; template struct KruskalValueSelector, void>::type> + typename enable_if, void>::type> { typedef typename In::Value Value; - }; - + }; + template struct KruskalInputSelector {}; @@ -176,10 +176,10 @@ template struct KruskalOutputSelector {}; - + template struct KruskalInputSelector, void>::type > + typename enable_if, void>::type > { typedef typename In::value_type::second_type Value; @@ -192,7 +192,7 @@ template struct KruskalInputSelector, void>::type > + typename enable_if, void>::type > { typedef typename In::Value Value; static Value kruskal(const Graph& graph, const In& in, Out& out) { @@ -201,7 +201,7 @@ typedef typename ItemSetTraits::ItemIt MapArcIt; typedef std::vector > Sequence; Sequence seq; - + for (MapArcIt it(graph); it != INVALID; ++it) { seq.push_back(std::make_pair(it, in[it])); } @@ -224,7 +224,7 @@ template struct KruskalOutputSelector, void>::type > + typename enable_if, void>::type > { typedef typename In::value_type::second_type Value; @@ -238,7 +238,7 @@ template struct KruskalOutputSelector, void>::type > + typename enable_if, void>::type > { typedef typename In::value_type::second_type Value; @@ -254,17 +254,17 @@ /// \brief Kruskal algorithm to find a minimum cost spanning tree of /// a graph. /// - /// This function runs Kruskal's algorithm to find a minimum cost + /// This function runs Kruskal's algorithm to find a minimum cost /// spanning tree. /// Due to some C++ hacking, it accepts various input and output types. /// /// \param g The graph the algorithm runs on. - /// It can be either \ref concepts::Digraph "directed" or + /// It can be either \ref concepts::Digraph "directed" or /// \ref concepts::Graph "undirected". - /// If the graph is directed, the algorithm consider it to be + /// If the graph is directed, the algorithm consider it to be /// undirected by disregarding the direction of the arcs. /// - /// \param in This object is used to describe the arc/edge costs. + /// \param in This object is used to describe the arc/edge costs. /// It can be one of the following choices. /// - An STL compatible 'Forward Container' with /// std::pair or @@ -272,7 +272,7 @@ /// \c X is the type of the costs. The pairs indicates the arcs/edges /// along with the assigned cost. They must be in a /// cost-ascending order. - /// - Any readable arc/edge map. The values of the map indicate the + /// - Any readable arc/edge map. The values of the map indicate the /// arc/edge costs. /// /// \retval out Here we also have a choice. @@ -292,10 +292,10 @@ /// kruskal(g,cost,tree.begin()); ///\endcode /// Or if we don't know in advance the size of the tree, we can - /// write this. + /// write this. ///\code /// std::vector tree; - /// kruskal(g,cost,std::back_inserter(tree)); + /// kruskal(g,cost,std::back_inserter(tree)); ///\endcode /// /// \return The total cost of the found spanning tree. @@ -307,18 +307,18 @@ #ifdef DOXYGEN template Value kruskal(GR const& g, const In& in, Out& out) -#else +#else template - inline typename _kruskal_bits::KruskalValueSelector::Value - kruskal(const Graph& graph, const In& in, Out& out) + inline typename _kruskal_bits::KruskalValueSelector::Value + kruskal(const Graph& graph, const In& in, Out& out) #endif { return _kruskal_bits::KruskalInputSelector:: kruskal(graph, in, out); } - - + + template inline typename _kruskal_bits::KruskalValueSelector::Value @@ -326,7 +326,7 @@ { return _kruskal_bits::KruskalInputSelector:: kruskal(graph, in, out); - } + } } //namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/lgf_reader.h --- a/lemon/lgf_reader.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/lgf_reader.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -46,26 +46,26 @@ template struct DefaultConverter { Value operator()(const std::string& str) { - std::istringstream is(str); - Value value; - is >> value; - - char c; - if (is >> std::ws >> c) { - throw DataFormatError("Remaining characters in token"); - } - return value; + std::istringstream is(str); + Value value; + is >> value; + + char c; + if (is >> std::ws >> c) { + throw DataFormatError("Remaining characters in token"); + } + return value; } }; template <> struct DefaultConverter { std::string operator()(const std::string& str) { - return str; + return str; } }; - template + template class MapStorageBase { public: typedef _Item Item; @@ -78,30 +78,30 @@ }; - template > + template > class MapStorage : public MapStorageBase<_Item> { public: typedef _Map Map; typedef _Converter Converter; typedef _Item Item; - + private: Map& _map; Converter _converter; public: - MapStorage(Map& map, const Converter& converter = Converter()) - : _map(map), _converter(converter) {} + MapStorage(Map& map, const Converter& converter = Converter()) + : _map(map), _converter(converter) {} virtual ~MapStorage() {} virtual void set(const Item& item ,const std::string& value) { - _map.set(item, _converter(value)); + _map.set(item, _converter(value)); } }; - template > + template > class GraphArcMapStorage : public MapStorageBase { public: typedef _Map Map; @@ -109,20 +109,20 @@ typedef _Graph Graph; typedef typename Graph::Edge Item; static const bool dir = _dir; - + private: const Graph& _graph; Map& _map; Converter _converter; public: - GraphArcMapStorage(const Graph& graph, Map& map, - const Converter& converter = Converter()) - : _graph(graph), _map(map), _converter(converter) {} + GraphArcMapStorage(const Graph& graph, Map& map, + const Converter& converter = Converter()) + : _graph(graph), _map(map), _converter(converter) {} virtual ~GraphArcMapStorage() {} virtual void set(const Item& item ,const std::string& value) { - _map.set(_graph.direct(item, dir), _converter(value)); + _map.set(_graph.direct(item, dir), _converter(value)); } }; @@ -146,10 +146,10 @@ public: ValueStorage(Value& value, const Converter& converter = Converter()) - : _value(value), _converter(converter) {} + : _value(value), _converter(converter) {} virtual void set(const std::string& value) { - _value = _converter(value); + _value = _converter(value); } }; @@ -176,45 +176,45 @@ struct GraphArcLookUpConverter { const Graph& _graph; const std::map& _map; - - GraphArcLookUpConverter(const Graph& graph, - const std::map& map) - : _graph(graph), _map(map) {} - + + GraphArcLookUpConverter(const Graph& graph, + const std::map& map) + : _graph(graph), _map(map) {} + typename Graph::Arc operator()(const std::string& str) { - if (str.empty() || (str[0] != '+' && str[0] != '-')) { - throw DataFormatError("Item must start with '+' or '-'"); - } - typename std::map - ::const_iterator it = _map.find(str.substr(1)); - if (it == _map.end()) { - throw DataFormatError("Item not found"); - } - return _graph.direct(it->second, str[0] == '+'); + if (str.empty() || (str[0] != '+' && str[0] != '-')) { + throw DataFormatError("Item must start with '+' or '-'"); + } + typename std::map + ::const_iterator it = _map.find(str.substr(1)); + if (it == _map.end()) { + throw DataFormatError("Item not found"); + } + return _graph.direct(it->second, str[0] == '+'); } }; inline bool isWhiteSpace(char c) { - return c == ' ' || c == '\t' || c == '\v' || - c == '\n' || c == '\r' || c == '\f'; + return c == ' ' || c == '\t' || c == '\v' || + c == '\n' || c == '\r' || c == '\f'; } - + inline bool isOct(char c) { - return '0' <= c && c <='7'; + return '0' <= c && c <='7'; } - + inline int valueOct(char c) { LEMON_ASSERT(isOct(c), "The character is not octal."); return c - '0'; } inline bool isHex(char c) { - return ('0' <= c && c <= '9') || - ('a' <= c && c <= 'z') || - ('A' <= c && c <= 'Z'); + return ('0' <= c && c <= '9') || + ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z'); } - + inline int valueHex(char c) { LEMON_ASSERT(isHex(c), "The character is not hexadecimal."); if ('0' <= c && c <= '9') return c - '0'; @@ -224,95 +224,95 @@ inline bool isIdentifierFirstChar(char c) { return ('a' <= c && c <= 'z') || - ('A' <= c && c <= 'Z') || c == '_'; + ('A' <= c && c <= 'Z') || c == '_'; } inline bool isIdentifierChar(char c) { return isIdentifierFirstChar(c) || - ('0' <= c && c <= '9'); + ('0' <= c && c <= '9'); } inline char readEscape(std::istream& is) { char c; if (!is.get(c)) - throw DataFormatError("Escape format error"); + throw DataFormatError("Escape format error"); switch (c) { case '\\': - return '\\'; + return '\\'; case '\"': - return '\"'; + return '\"'; case '\'': - return '\''; + return '\''; case '\?': - return '\?'; + return '\?'; case 'a': - return '\a'; + return '\a'; case 'b': - return '\b'; + return '\b'; case 'f': - return '\f'; + return '\f'; case 'n': - return '\n'; + return '\n'; case 'r': - return '\r'; + return '\r'; case 't': - return '\t'; + return '\t'; case 'v': - return '\v'; + return '\v'; case 'x': - { - int code; - if (!is.get(c) || !isHex(c)) - throw DataFormatError("Escape format error"); - else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c); - else code = code * 16 + valueHex(c); - return code; - } + { + int code; + if (!is.get(c) || !isHex(c)) + throw DataFormatError("Escape format error"); + else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c); + else code = code * 16 + valueHex(c); + return code; + } default: - { - int code; - if (!isOct(c)) - throw DataFormatError("Escape format error"); - else if (code = valueOct(c), !is.get(c) || !isOct(c)) - is.putback(c); - else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) - is.putback(c); - else code = code * 8 + valueOct(c); - return code; - } - } + { + int code; + if (!isOct(c)) + throw DataFormatError("Escape format error"); + else if (code = valueOct(c), !is.get(c) || !isOct(c)) + is.putback(c); + else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) + is.putback(c); + else code = code * 8 + valueOct(c); + return code; + } + } } - + inline std::istream& readToken(std::istream& is, std::string& str) { std::ostringstream os; char c; is >> std::ws; - - if (!is.get(c)) - return is; + + if (!is.get(c)) + return is; if (c == '\"') { - while (is.get(c) && c != '\"') { - if (c == '\\') - c = readEscape(is); - os << c; - } - if (!is) - throw DataFormatError("Quoted format error"); + while (is.get(c) && c != '\"') { + if (c == '\\') + c = readEscape(is); + os << c; + } + if (!is) + throw DataFormatError("Quoted format error"); } else { - is.putback(c); - while (is.get(c) && !isWhiteSpace(c)) { - if (c == '\\') - c = readEscape(is); - os << c; - } - if (!is) { - is.clear(); - } else { - is.putback(c); - } + is.putback(c); + while (is.get(c) && !isWhiteSpace(c)) { + if (c == '\\') + c = readEscape(is); + os << c; + } + if (!is) { + is.clear(); + } else { + is.putback(c); + } } str = os.str(); return is; @@ -331,28 +331,28 @@ Functor _functor; public: - + LineSection(const Functor& functor) : _functor(functor) {} virtual ~LineSection() {} virtual void process(std::istream& is, int& line_num) { - char c; - std::string line; - while (is.get(c) && c != '@') { - if (c == '\n') { - ++line_num; - } else if (c == '#') { - getline(is, line); - ++line_num; - } else if (!isWhiteSpace(c)) { - is.putback(c); - getline(is, line); - _functor(line); - ++line_num; - } - } - if (is) is.putback(c); - else if (is.eof()) is.clear(); + char c; + std::string line; + while (is.get(c) && c != '@') { + if (c == '\n') { + ++line_num; + } else if (c == '#') { + getline(is, line); + ++line_num; + } else if (!isWhiteSpace(c)) { + is.putback(c); + getline(is, line); + _functor(line); + ++line_num; + } + } + if (is) is.putback(c); + else if (is.eof()) is.clear(); } }; @@ -363,27 +363,27 @@ Functor _functor; public: - + StreamSection(const Functor& functor) : _functor(functor) {} - virtual ~StreamSection() {} + virtual ~StreamSection() {} virtual void process(std::istream& is, int& line_num) { - _functor(is, line_num); - char c; - std::string line; - while (is.get(c) && c != '@') { - if (c == '\n') { - ++line_num; - } else if (!isWhiteSpace(c)) { - getline(is, line); - ++line_num; - } - } - if (is) is.putback(c); - else if (is.eof()) is.clear(); + _functor(is, line_num); + char c; + std::string line; + while (is.get(c) && c != '@') { + if (c == '\n') { + ++line_num; + } else if (!isWhiteSpace(c)) { + getline(is, line); + ++line_num; + } + } + if (is) is.putback(c); + else if (is.eof()) is.clear(); } }; - + } template @@ -399,7 +399,7 @@ DigraphReader digraphReader(const char *fn, Digraph& digraph); /// \ingroup lemon_io - /// + /// /// \brief \ref lgf-format "LGF" reader for directed graphs /// /// This utility reads an \ref lgf-format "LGF" file. @@ -453,7 +453,7 @@ typedef _Digraph Digraph; TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); - + private: @@ -470,16 +470,16 @@ NodeIndex _node_index; typedef std::map ArcIndex; ArcIndex _arc_index; - - typedef std::vector*> > NodeMaps; - NodeMaps _node_maps; + + typedef std::vector*> > NodeMaps; + NodeMaps _node_maps; typedef std::vector*> >ArcMaps; ArcMaps _arc_maps; - typedef std::multimap + typedef std::multimap Attributes; Attributes _attributes; @@ -498,69 +498,69 @@ /// /// Construct a directed graph reader, which reads from the given /// input stream. - DigraphReader(std::istream& is, Digraph& digraph) + DigraphReader(std::istream& is, Digraph& digraph) : _is(&is), local_is(false), _digraph(digraph), - _use_nodes(false), _use_arcs(false), - _skip_nodes(false), _skip_arcs(false) {} + _use_nodes(false), _use_arcs(false), + _skip_nodes(false), _skip_arcs(false) {} /// \brief Constructor /// /// Construct a directed graph reader, which reads from the given /// file. - DigraphReader(const std::string& fn, Digraph& digraph) + DigraphReader(const std::string& fn, Digraph& digraph) : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph), - _use_nodes(false), _use_arcs(false), - _skip_nodes(false), _skip_arcs(false) {} - + _use_nodes(false), _use_arcs(false), + _skip_nodes(false), _skip_arcs(false) {} + /// \brief Constructor /// /// Construct a directed graph reader, which reads from the given /// file. - DigraphReader(const char* fn, Digraph& digraph) + DigraphReader(const char* fn, Digraph& digraph) : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph), - _use_nodes(false), _use_arcs(false), - _skip_nodes(false), _skip_arcs(false) {} + _use_nodes(false), _use_arcs(false), + _skip_nodes(false), _skip_arcs(false) {} /// \brief Destructor ~DigraphReader() { - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - delete it->second; + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + delete it->second; } - for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { - delete it->second; + for (typename ArcMaps::iterator it = _arc_maps.begin(); + it != _arc_maps.end(); ++it) { + delete it->second; } - for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - delete it->second; + for (typename Attributes::iterator it = _attributes.begin(); + it != _attributes.end(); ++it) { + delete it->second; } if (local_is) { - delete _is; + delete _is; } } private: - friend DigraphReader digraphReader<>(std::istream& is, - Digraph& digraph); - friend DigraphReader digraphReader<>(const std::string& fn, - Digraph& digraph); - friend DigraphReader digraphReader<>(const char *fn, - Digraph& digraph); - - DigraphReader(DigraphReader& other) + friend DigraphReader digraphReader<>(std::istream& is, + Digraph& digraph); + friend DigraphReader digraphReader<>(const std::string& fn, + Digraph& digraph); + friend DigraphReader digraphReader<>(const char *fn, + Digraph& digraph); + + DigraphReader(DigraphReader& other) : _is(other._is), local_is(other.local_is), _digraph(other._digraph), - _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { + _use_nodes(other._use_nodes), _use_arcs(other._use_arcs), + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { other._is = 0; other.local_is = false; - + _node_index.swap(other._node_index); _arc_index.swap(other._arc_index); @@ -580,15 +580,15 @@ /// \name Reading rules /// @{ - + /// \brief Node map reading rule /// /// Add a node map reading rule to the reader. template DigraphReader& nodeMap(const std::string& caption, Map& map) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -598,11 +598,11 @@ /// Add a node map reading rule with specialized converter to the /// reader. template - DigraphReader& nodeMap(const std::string& caption, Map& map, - const Converter& converter = Converter()) { + DigraphReader& nodeMap(const std::string& caption, Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map, converter); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map, converter); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -613,8 +613,8 @@ template DigraphReader& arcMap(const std::string& caption, Map& map) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map); _arc_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -624,11 +624,11 @@ /// Add an arc map reading rule with specialized converter to the /// reader. template - DigraphReader& arcMap(const std::string& caption, Map& map, - const Converter& converter = Converter()) { + DigraphReader& arcMap(const std::string& caption, Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map, converter); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map, converter); _arc_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -638,8 +638,8 @@ /// Add an attribute reading rule to the reader. template DigraphReader& attribute(const std::string& caption, Value& value) { - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(value); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(value); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -649,10 +649,10 @@ /// Add an attribute reading rule with specialized converter to the /// reader. template - DigraphReader& attribute(const std::string& caption, Value& value, - const Converter& converter = Converter()) { - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(value, converter); + DigraphReader& attribute(const std::string& caption, Value& value, + const Converter& converter = Converter()) { + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(value, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -663,8 +663,8 @@ DigraphReader& node(const std::string& caption, Node& node) { typedef _reader_bits::MapLookUpConverter Converter; Converter converter(_node_index); - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(node, converter); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(node, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -675,8 +675,8 @@ DigraphReader& arc(const std::string& caption, Arc& arc) { typedef _reader_bits::MapLookUpConverter Converter; Converter converter(_arc_index); - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(arc, converter); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(arc, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -722,11 +722,11 @@ template DigraphReader& useNodes(const Map& map) { checkConcept, Map>(); - LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); + LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); _use_nodes = true; _writer_bits::DefaultConverter converter; for (NodeIt n(_digraph); n != INVALID; ++n) { - _node_index.insert(std::make_pair(converter(map[n]), n)); + _node_index.insert(std::make_pair(converter(map[n]), n)); } return *this; } @@ -737,13 +737,13 @@ /// label map and a functor which converts the label map values to /// \c std::string. template - DigraphReader& useNodes(const Map& map, - const Converter& converter = Converter()) { + DigraphReader& useNodes(const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); + LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); _use_nodes = true; for (NodeIt n(_digraph); n != INVALID; ++n) { - _node_index.insert(std::make_pair(converter(map[n]), n)); + _node_index.insert(std::make_pair(converter(map[n]), n)); } return *this; } @@ -759,7 +759,7 @@ _use_arcs = true; _writer_bits::DefaultConverter converter; for (ArcIt a(_digraph); a != INVALID; ++a) { - _arc_index.insert(std::make_pair(converter(map[a]), a)); + _arc_index.insert(std::make_pair(converter(map[a]), a)); } return *this; } @@ -770,13 +770,13 @@ /// label map and a functor which converts the label map values to /// \c std::string. template - DigraphReader& useArcs(const Map& map, - const Converter& converter = Converter()) { + DigraphReader& useArcs(const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member"); + LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member"); _use_arcs = true; for (ArcIt a(_digraph); a != INVALID; ++a) { - _arc_index.insert(std::make_pair(converter(map[a]), a)); + _arc_index.insert(std::make_pair(converter(map[a]), a)); } return *this; } @@ -790,7 +790,7 @@ /// Therefore \c skipArcs() function should also be used, or /// \c useNodes() should be used to specify the label of the nodes. DigraphReader& skipNodes() { - LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); + LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); _skip_nodes = true; return *this; } @@ -801,7 +801,7 @@ /// map reading rule will be abandoned, and the arcs of the graph /// will not be constructed. DigraphReader& skipArcs() { - LEMON_ASSERT(!_skip_arcs, "Skip arcs already set"); + LEMON_ASSERT(!_skip_arcs, "Skip arcs already set"); _skip_arcs = true; return *this; } @@ -813,12 +813,12 @@ bool readLine() { std::string str; while(++line_num, std::getline(*_is, str)) { - line.clear(); line.str(str); - char c; - if (line >> std::ws >> c && c != '#') { - line.putback(c); - return true; - } + line.clear(); line.str(str); + char c; + if (line >> std::ws >> c && c != '#') { + line.putback(c); + return true; + } } return false; } @@ -826,11 +826,11 @@ bool readSuccess() { return static_cast(*_is); } - + void skipSection() { char c; while (readSuccess() && line >> c && c != '@') { - readLine(); + readLine(); } line.putback(c); } @@ -842,89 +842,89 @@ char c; if (!readLine() || !(line >> c) || c == '@') { - if (readSuccess() && line) line.putback(c); - if (!_node_maps.empty()) - throw DataFormatError("Cannot find map names"); - return; + if (readSuccess() && line) line.putback(c); + if (!_node_maps.empty()) + throw DataFormatError("Cannot find map names"); + return; } line.putback(c); { - std::map maps; - - std::string map; - int index = 0; - while (_reader_bits::readToken(line, map)) { - if (maps.find(map) != maps.end()) { - std::ostringstream msg; - msg << "Multiple occurence of node map: " << map; - throw DataFormatError(msg.str().c_str()); - } - maps.insert(std::make_pair(map, index)); - ++index; - } - - for (int i = 0; i < static_cast(_node_maps.size()); ++i) { - std::map::iterator jt = - maps.find(_node_maps[i].first); - if (jt == maps.end()) { - std::ostringstream msg; - msg << "Map not found in file: " << _node_maps[i].first; - throw DataFormatError(msg.str().c_str()); - } - map_index[i] = jt->second; - } - - { - std::map::iterator jt = maps.find("label"); - if (jt != maps.end()) { - label_index = jt->second; - } else { - label_index = -1; - } - } - map_num = maps.size(); + std::map maps; + + std::string map; + int index = 0; + while (_reader_bits::readToken(line, map)) { + if (maps.find(map) != maps.end()) { + std::ostringstream msg; + msg << "Multiple occurence of node map: " << map; + throw DataFormatError(msg.str().c_str()); + } + maps.insert(std::make_pair(map, index)); + ++index; + } + + for (int i = 0; i < static_cast(_node_maps.size()); ++i) { + std::map::iterator jt = + maps.find(_node_maps[i].first); + if (jt == maps.end()) { + std::ostringstream msg; + msg << "Map not found in file: " << _node_maps[i].first; + throw DataFormatError(msg.str().c_str()); + } + map_index[i] = jt->second; + } + + { + std::map::iterator jt = maps.find("label"); + if (jt != maps.end()) { + label_index = jt->second; + } else { + label_index = -1; + } + } + map_num = maps.size(); } while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::vector tokens(map_num); - for (int i = 0; i < map_num; ++i) { - if (!_reader_bits::readToken(line, tokens[i])) { - std::ostringstream msg; - msg << "Column not found (" << i + 1 << ")"; - throw DataFormatError(msg.str().c_str()); - } - } - if (line >> std::ws >> c) - throw DataFormatError("Extra character on the end of line"); - - Node n; - if (!_use_nodes) { - n = _digraph.addNode(); - if (label_index != -1) - _node_index.insert(std::make_pair(tokens[label_index], n)); - } else { - if (label_index == -1) - throw DataFormatError("Label map not found in file"); - typename std::map::iterator it = - _node_index.find(tokens[label_index]); - if (it == _node_index.end()) { - std::ostringstream msg; - msg << "Node with label not found: " << tokens[label_index]; - throw DataFormatError(msg.str().c_str()); - } - n = it->second; - } - - for (int i = 0; i < static_cast(_node_maps.size()); ++i) { - _node_maps[i].second->set(n, tokens[map_index[i]]); - } + line.putback(c); + + std::vector tokens(map_num); + for (int i = 0; i < map_num; ++i) { + if (!_reader_bits::readToken(line, tokens[i])) { + std::ostringstream msg; + msg << "Column not found (" << i + 1 << ")"; + throw DataFormatError(msg.str().c_str()); + } + } + if (line >> std::ws >> c) + throw DataFormatError("Extra character on the end of line"); + + Node n; + if (!_use_nodes) { + n = _digraph.addNode(); + if (label_index != -1) + _node_index.insert(std::make_pair(tokens[label_index], n)); + } else { + if (label_index == -1) + throw DataFormatError("Label map not found in file"); + typename std::map::iterator it = + _node_index.find(tokens[label_index]); + if (it == _node_index.end()) { + std::ostringstream msg; + msg << "Node with label not found: " << tokens[label_index]; + throw DataFormatError(msg.str().c_str()); + } + n = it->second; + } + + for (int i = 0; i < static_cast(_node_maps.size()); ++i) { + _node_maps[i].second->set(n, tokens[map_index[i]]); + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } } @@ -935,78 +935,78 @@ char c; if (!readLine() || !(line >> c) || c == '@') { - if (readSuccess() && line) line.putback(c); - if (!_arc_maps.empty()) - throw DataFormatError("Cannot find map names"); - return; + if (readSuccess() && line) line.putback(c); + if (!_arc_maps.empty()) + throw DataFormatError("Cannot find map names"); + return; } line.putback(c); - + { - std::map maps; - - std::string map; - int index = 0; - while (_reader_bits::readToken(line, map)) { - if (maps.find(map) != maps.end()) { - std::ostringstream msg; - msg << "Multiple occurence of arc map: " << map; - throw DataFormatError(msg.str().c_str()); - } - maps.insert(std::make_pair(map, index)); - ++index; - } - - for (int i = 0; i < static_cast(_arc_maps.size()); ++i) { - std::map::iterator jt = - maps.find(_arc_maps[i].first); - if (jt == maps.end()) { - std::ostringstream msg; - msg << "Map not found in file: " << _arc_maps[i].first; - throw DataFormatError(msg.str().c_str()); - } - map_index[i] = jt->second; - } - - { - std::map::iterator jt = maps.find("label"); - if (jt != maps.end()) { - label_index = jt->second; - } else { - label_index = -1; - } - } - map_num = maps.size(); + std::map maps; + + std::string map; + int index = 0; + while (_reader_bits::readToken(line, map)) { + if (maps.find(map) != maps.end()) { + std::ostringstream msg; + msg << "Multiple occurence of arc map: " << map; + throw DataFormatError(msg.str().c_str()); + } + maps.insert(std::make_pair(map, index)); + ++index; + } + + for (int i = 0; i < static_cast(_arc_maps.size()); ++i) { + std::map::iterator jt = + maps.find(_arc_maps[i].first); + if (jt == maps.end()) { + std::ostringstream msg; + msg << "Map not found in file: " << _arc_maps[i].first; + throw DataFormatError(msg.str().c_str()); + } + map_index[i] = jt->second; + } + + { + std::map::iterator jt = maps.find("label"); + if (jt != maps.end()) { + label_index = jt->second; + } else { + label_index = -1; + } + } + map_num = maps.size(); } while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::string source_token; - std::string target_token; - - if (!_reader_bits::readToken(line, source_token)) - throw DataFormatError("Source not found"); - - if (!_reader_bits::readToken(line, target_token)) - throw DataFormatError("Target not found"); - - std::vector tokens(map_num); - for (int i = 0; i < map_num; ++i) { - if (!_reader_bits::readToken(line, tokens[i])) { - std::ostringstream msg; - msg << "Column not found (" << i + 1 << ")"; - throw DataFormatError(msg.str().c_str()); - } - } - if (line >> std::ws >> c) - throw DataFormatError("Extra character on the end of line"); - - Arc a; - if (!_use_arcs) { + line.putback(c); + + std::string source_token; + std::string target_token; + + if (!_reader_bits::readToken(line, source_token)) + throw DataFormatError("Source not found"); + + if (!_reader_bits::readToken(line, target_token)) + throw DataFormatError("Target not found"); + + std::vector tokens(map_num); + for (int i = 0; i < map_num; ++i) { + if (!_reader_bits::readToken(line, tokens[i])) { + std::ostringstream msg; + msg << "Column not found (" << i + 1 << ")"; + throw DataFormatError(msg.str().c_str()); + } + } + if (line >> std::ws >> c) + throw DataFormatError("Extra character on the end of line"); + + Arc a; + if (!_use_arcs) { typename NodeIndex::iterator it; - + it = _node_index.find(source_token); if (it == _node_index.end()) { std::ostringstream msg; @@ -1016,36 +1016,36 @@ Node source = it->second; it = _node_index.find(target_token); - if (it == _node_index.end()) { - std::ostringstream msg; + if (it == _node_index.end()) { + std::ostringstream msg; msg << "Item not found: " << target_token; throw DataFormatError(msg.str().c_str()); - } - Node target = it->second; - - a = _digraph.addArc(source, target); - if (label_index != -1) - _arc_index.insert(std::make_pair(tokens[label_index], a)); - } else { - if (label_index == -1) - throw DataFormatError("Label map not found in file"); - typename std::map::iterator it = - _arc_index.find(tokens[label_index]); - if (it == _arc_index.end()) { - std::ostringstream msg; - msg << "Arc with label not found: " << tokens[label_index]; - throw DataFormatError(msg.str().c_str()); - } - a = it->second; - } - - for (int i = 0; i < static_cast(_arc_maps.size()); ++i) { - _arc_maps[i].second->set(a, tokens[map_index[i]]); - } + } + Node target = it->second; + + a = _digraph.addArc(source, target); + if (label_index != -1) + _arc_index.insert(std::make_pair(tokens[label_index], a)); + } else { + if (label_index == -1) + throw DataFormatError("Label map not found in file"); + typename std::map::iterator it = + _arc_index.find(tokens[label_index]); + if (it == _arc_index.end()) { + std::ostringstream msg; + msg << "Arc with label not found: " << tokens[label_index]; + throw DataFormatError(msg.str().c_str()); + } + a = it->second; + } + + for (int i = 0; i < static_cast(_arc_maps.size()); ++i) { + _arc_maps[i].second->set(a, tokens[map_index[i]]); + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } } @@ -1055,51 +1055,51 @@ char c; while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::string attr, token; - if (!_reader_bits::readToken(line, attr)) - throw DataFormatError("Attribute name not found"); - if (!_reader_bits::readToken(line, token)) - throw DataFormatError("Attribute value not found"); - if (line >> c) - throw DataFormatError("Extra character on the end of line"); - - { - std::set::iterator it = read_attr.find(attr); - if (it != read_attr.end()) { - std::ostringstream msg; - msg << "Multiple occurence of attribute " << attr; - throw DataFormatError(msg.str().c_str()); - } - read_attr.insert(attr); - } - - { - typename Attributes::iterator it = _attributes.lower_bound(attr); - while (it != _attributes.end() && it->first == attr) { - it->second->set(token); - ++it; - } - } + line.putback(c); + + std::string attr, token; + if (!_reader_bits::readToken(line, attr)) + throw DataFormatError("Attribute name not found"); + if (!_reader_bits::readToken(line, token)) + throw DataFormatError("Attribute value not found"); + if (line >> c) + throw DataFormatError("Extra character on the end of line"); + + { + std::set::iterator it = read_attr.find(attr); + if (it != read_attr.end()) { + std::ostringstream msg; + msg << "Multiple occurence of attribute " << attr; + throw DataFormatError(msg.str().c_str()); + } + read_attr.insert(attr); + } + + { + typename Attributes::iterator it = _attributes.lower_bound(attr); + while (it != _attributes.end() && it->first == attr) { + it->second->set(token); + ++it; + } + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - if (read_attr.find(it->first) == read_attr.end()) { - std::ostringstream msg; - msg << "Attribute not found in file: " << it->first; - throw DataFormatError(msg.str().c_str()); - } + it != _attributes.end(); ++it) { + if (read_attr.find(it->first) == read_attr.end()) { + std::ostringstream msg; + msg << "Attribute not found in file: " << it->first; + throw DataFormatError(msg.str().c_str()); + } } } public: - /// \name Execution of the reader + /// \name Execution of the reader /// @{ /// \brief Start the batch processing @@ -1108,74 +1108,74 @@ void run() { LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); if (!*_is) { - throw DataFormatError("Cannot find file"); + throw DataFormatError("Cannot find file"); } - + bool nodes_done = _skip_nodes; bool arcs_done = _skip_arcs; bool attributes_done = false; - line_num = 0; + line_num = 0; readLine(); skipSection(); while (readSuccess()) { - try { - char c; - std::string section, caption; - line >> c; - _reader_bits::readToken(line, section); - _reader_bits::readToken(line, caption); - - if (line >> c) - throw DataFormatError("Extra character on the end of line"); - - if (section == "nodes" && !nodes_done) { - if (_nodes_caption.empty() || _nodes_caption == caption) { - readNodes(); - nodes_done = true; - } - } else if ((section == "arcs" || section == "edges") && - !arcs_done) { - if (_arcs_caption.empty() || _arcs_caption == caption) { - readArcs(); - arcs_done = true; - } - } else if (section == "attributes" && !attributes_done) { - if (_attributes_caption.empty() || _attributes_caption == caption) { - readAttributes(); - attributes_done = true; - } - } else { - readLine(); - skipSection(); - } - } catch (DataFormatError& error) { - error.line(line_num); - throw; - } + try { + char c; + std::string section, caption; + line >> c; + _reader_bits::readToken(line, section); + _reader_bits::readToken(line, caption); + + if (line >> c) + throw DataFormatError("Extra character on the end of line"); + + if (section == "nodes" && !nodes_done) { + if (_nodes_caption.empty() || _nodes_caption == caption) { + readNodes(); + nodes_done = true; + } + } else if ((section == "arcs" || section == "edges") && + !arcs_done) { + if (_arcs_caption.empty() || _arcs_caption == caption) { + readArcs(); + arcs_done = true; + } + } else if (section == "attributes" && !attributes_done) { + if (_attributes_caption.empty() || _attributes_caption == caption) { + readAttributes(); + attributes_done = true; + } + } else { + readLine(); + skipSection(); + } + } catch (DataFormatError& error) { + error.line(line_num); + throw; + } } if (!nodes_done) { - throw DataFormatError("Section @nodes not found"); + throw DataFormatError("Section @nodes not found"); } if (!arcs_done) { - throw DataFormatError("Section @arcs not found"); + throw DataFormatError("Section @arcs not found"); } if (!attributes_done && !_attributes.empty()) { - throw DataFormatError("Section @attributes not found"); + throw DataFormatError("Section @attributes not found"); } } /// @} - + }; /// \brief Return a \ref DigraphReader class - /// + /// /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template @@ -1185,18 +1185,18 @@ } /// \brief Return a \ref DigraphReader class - /// + /// /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template - DigraphReader digraphReader(const std::string& fn, - Digraph& digraph) { + DigraphReader digraphReader(const std::string& fn, + Digraph& digraph) { DigraphReader tmp(fn, digraph); return tmp; } /// \brief Return a \ref DigraphReader class - /// + /// /// This function just returns a \ref DigraphReader class. /// \relates DigraphReader template @@ -1209,16 +1209,16 @@ class GraphReader; template - GraphReader graphReader(std::istream& is, Graph& graph); + GraphReader graphReader(std::istream& is, Graph& graph); template - GraphReader graphReader(const std::string& fn, Graph& graph); + GraphReader graphReader(const std::string& fn, Graph& graph); template - GraphReader graphReader(const char *fn, Graph& graph); + GraphReader graphReader(const char *fn, Graph& graph); /// \ingroup lemon_io - /// + /// /// \brief \ref lgf-format "LGF" reader for undirected graphs /// /// This utility reads an \ref lgf-format "LGF" file. @@ -1238,7 +1238,7 @@ typedef _Graph Graph; TEMPLATE_GRAPH_TYPEDEFS(Graph); - + private: std::istream* _is; @@ -1254,16 +1254,16 @@ NodeIndex _node_index; typedef std::map EdgeIndex; EdgeIndex _edge_index; - - typedef std::vector*> > NodeMaps; - NodeMaps _node_maps; + + typedef std::vector*> > NodeMaps; + NodeMaps _node_maps; typedef std::vector*> > EdgeMaps; EdgeMaps _edge_maps; - typedef std::multimap + typedef std::multimap Attributes; Attributes _attributes; @@ -1282,66 +1282,66 @@ /// /// Construct an undirected graph reader, which reads from the given /// input stream. - GraphReader(std::istream& is, Graph& graph) + GraphReader(std::istream& is, Graph& graph) : _is(&is), local_is(false), _graph(graph), - _use_nodes(false), _use_edges(false), - _skip_nodes(false), _skip_edges(false) {} + _use_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) {} /// \brief Constructor /// /// Construct an undirected graph reader, which reads from the given /// file. - GraphReader(const std::string& fn, Graph& graph) + GraphReader(const std::string& fn, Graph& graph) : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph), - _use_nodes(false), _use_edges(false), - _skip_nodes(false), _skip_edges(false) {} - + _use_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) {} + /// \brief Constructor /// /// Construct an undirected graph reader, which reads from the given /// file. - GraphReader(const char* fn, Graph& graph) + GraphReader(const char* fn, Graph& graph) : _is(new std::ifstream(fn)), local_is(true), _graph(graph), - _use_nodes(false), _use_edges(false), - _skip_nodes(false), _skip_edges(false) {} + _use_nodes(false), _use_edges(false), + _skip_nodes(false), _skip_edges(false) {} /// \brief Destructor ~GraphReader() { - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - delete it->second; + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + delete it->second; } - for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { - delete it->second; + for (typename EdgeMaps::iterator it = _edge_maps.begin(); + it != _edge_maps.end(); ++it) { + delete it->second; } - for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - delete it->second; + for (typename Attributes::iterator it = _attributes.begin(); + it != _attributes.end(); ++it) { + delete it->second; } if (local_is) { - delete _is; + delete _is; } } private: - friend GraphReader graphReader<>(std::istream& is, Graph& graph); - friend GraphReader graphReader<>(const std::string& fn, - Graph& graph); - friend GraphReader graphReader<>(const char *fn, Graph& graph); - - GraphReader(GraphReader& other) + friend GraphReader graphReader<>(std::istream& is, Graph& graph); + friend GraphReader graphReader<>(const std::string& fn, + Graph& graph); + friend GraphReader graphReader<>(const char *fn, Graph& graph); + + GraphReader(GraphReader& other) : _is(other._is), local_is(other.local_is), _graph(other._graph), - _use_nodes(other._use_nodes), _use_edges(other._use_edges), - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { + _use_nodes(other._use_nodes), _use_edges(other._use_edges), + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { other._is = 0; other.local_is = false; - + _node_index.swap(other._node_index); _edge_index.swap(other._edge_index); @@ -1361,15 +1361,15 @@ /// \name Reading rules /// @{ - + /// \brief Node map reading rule /// /// Add a node map reading rule to the reader. template GraphReader& nodeMap(const std::string& caption, Map& map) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1379,11 +1379,11 @@ /// Add a node map reading rule with specialized converter to the /// reader. template - GraphReader& nodeMap(const std::string& caption, Map& map, - const Converter& converter = Converter()) { + GraphReader& nodeMap(const std::string& caption, Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map, converter); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map, converter); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1394,8 +1394,8 @@ template GraphReader& edgeMap(const std::string& caption, Map& map) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map); _edge_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1405,11 +1405,11 @@ /// Add an edge map reading rule with specialized converter to the /// reader. template - GraphReader& edgeMap(const std::string& caption, Map& map, - const Converter& converter = Converter()) { + GraphReader& edgeMap(const std::string& caption, Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _reader_bits::MapStorageBase* storage = - new _reader_bits::MapStorage(map, converter); + _reader_bits::MapStorageBase* storage = + new _reader_bits::MapStorage(map, converter); _edge_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1420,11 +1420,11 @@ template GraphReader& arcMap(const std::string& caption, Map& map) { checkConcept, Map>(); - _reader_bits::MapStorageBase* forward_storage = - new _reader_bits::GraphArcMapStorage(_graph, map); + _reader_bits::MapStorageBase* forward_storage = + new _reader_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); - _reader_bits::MapStorageBase* backward_storage = - new _reader_bits::GraphArcMapStorage(_graph, map); + _reader_bits::MapStorageBase* backward_storage = + new _reader_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; } @@ -1434,16 +1434,16 @@ /// Add an arc map reading rule with specialized converter to the /// reader. template - GraphReader& arcMap(const std::string& caption, Map& map, - const Converter& converter = Converter()) { + GraphReader& arcMap(const std::string& caption, Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _reader_bits::MapStorageBase* forward_storage = - new _reader_bits::GraphArcMapStorage - (_graph, map, converter); + _reader_bits::MapStorageBase* forward_storage = + new _reader_bits::GraphArcMapStorage + (_graph, map, converter); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); - _reader_bits::MapStorageBase* backward_storage = - new _reader_bits::GraphArcMapStorage - (_graph, map, converter); + _reader_bits::MapStorageBase* backward_storage = + new _reader_bits::GraphArcMapStorage + (_graph, map, converter); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; } @@ -1453,8 +1453,8 @@ /// Add an attribute reading rule to the reader. template GraphReader& attribute(const std::string& caption, Value& value) { - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(value); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(value); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -1464,10 +1464,10 @@ /// Add an attribute reading rule with specialized converter to the /// reader. template - GraphReader& attribute(const std::string& caption, Value& value, - const Converter& converter = Converter()) { - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(value, converter); + GraphReader& attribute(const std::string& caption, Value& value, + const Converter& converter = Converter()) { + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(value, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -1478,8 +1478,8 @@ GraphReader& node(const std::string& caption, Node& node) { typedef _reader_bits::MapLookUpConverter Converter; Converter converter(_node_index); - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(node, converter); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(node, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -1490,8 +1490,8 @@ GraphReader& edge(const std::string& caption, Edge& edge) { typedef _reader_bits::MapLookUpConverter Converter; Converter converter(_edge_index); - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(edge, converter); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(edge, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -1502,8 +1502,8 @@ GraphReader& arc(const std::string& caption, Arc& arc) { typedef _reader_bits::GraphArcLookUpConverter Converter; Converter converter(_graph, _edge_index); - _reader_bits::ValueStorageBase* storage = - new _reader_bits::ValueStorage(arc, converter); + _reader_bits::ValueStorageBase* storage = + new _reader_bits::ValueStorage(arc, converter); _attributes.insert(std::make_pair(caption, storage)); return *this; } @@ -1549,11 +1549,11 @@ template GraphReader& useNodes(const Map& map) { checkConcept, Map>(); - LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); + LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); _use_nodes = true; _writer_bits::DefaultConverter converter; for (NodeIt n(_graph); n != INVALID; ++n) { - _node_index.insert(std::make_pair(converter(map[n]), n)); + _node_index.insert(std::make_pair(converter(map[n]), n)); } return *this; } @@ -1564,13 +1564,13 @@ /// label map and a functor which converts the label map values to /// \c std::string. template - GraphReader& useNodes(const Map& map, - const Converter& converter = Converter()) { + GraphReader& useNodes(const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); + LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); _use_nodes = true; for (NodeIt n(_graph); n != INVALID; ++n) { - _node_index.insert(std::make_pair(converter(map[n]), n)); + _node_index.insert(std::make_pair(converter(map[n]), n)); } return *this; } @@ -1586,7 +1586,7 @@ _use_edges = true; _writer_bits::DefaultConverter converter; for (EdgeIt a(_graph); a != INVALID; ++a) { - _edge_index.insert(std::make_pair(converter(map[a]), a)); + _edge_index.insert(std::make_pair(converter(map[a]), a)); } return *this; } @@ -1597,13 +1597,13 @@ /// label map and a functor which converts the label map values to /// \c std::string. template - GraphReader& useEdges(const Map& map, - const Converter& converter = Converter()) { + GraphReader& useEdges(const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); + LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); _use_edges = true; for (EdgeIt a(_graph); a != INVALID; ++a) { - _edge_index.insert(std::make_pair(converter(map[a]), a)); + _edge_index.insert(std::make_pair(converter(map[a]), a)); } return *this; } @@ -1618,7 +1618,7 @@ /// Therefore \c skipEdges() function should also be used, or /// \c useNodes() should be used to specify the label of the nodes. GraphReader& skipNodes() { - LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); + LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); _skip_nodes = true; return *this; } @@ -1629,7 +1629,7 @@ /// map reading rule will be abandoned, and the edges of the graph /// will not be constructed. GraphReader& skipEdges() { - LEMON_ASSERT(!_skip_edges, "Skip edges already set"); + LEMON_ASSERT(!_skip_edges, "Skip edges already set"); _skip_edges = true; return *this; } @@ -1641,12 +1641,12 @@ bool readLine() { std::string str; while(++line_num, std::getline(*_is, str)) { - line.clear(); line.str(str); - char c; - if (line >> std::ws >> c && c != '#') { - line.putback(c); - return true; - } + line.clear(); line.str(str); + char c; + if (line >> std::ws >> c && c != '#') { + line.putback(c); + return true; + } } return false; } @@ -1654,11 +1654,11 @@ bool readSuccess() { return static_cast(*_is); } - + void skipSection() { char c; while (readSuccess() && line >> c && c != '@') { - readLine(); + readLine(); } line.putback(c); } @@ -1670,89 +1670,89 @@ char c; if (!readLine() || !(line >> c) || c == '@') { - if (readSuccess() && line) line.putback(c); - if (!_node_maps.empty()) - throw DataFormatError("Cannot find map names"); - return; + if (readSuccess() && line) line.putback(c); + if (!_node_maps.empty()) + throw DataFormatError("Cannot find map names"); + return; } line.putback(c); - + { - std::map maps; - - std::string map; - int index = 0; - while (_reader_bits::readToken(line, map)) { - if (maps.find(map) != maps.end()) { - std::ostringstream msg; - msg << "Multiple occurence of node map: " << map; - throw DataFormatError(msg.str().c_str()); - } - maps.insert(std::make_pair(map, index)); - ++index; - } - - for (int i = 0; i < static_cast(_node_maps.size()); ++i) { - std::map::iterator jt = - maps.find(_node_maps[i].first); - if (jt == maps.end()) { - std::ostringstream msg; - msg << "Map not found in file: " << _node_maps[i].first; - throw DataFormatError(msg.str().c_str()); - } - map_index[i] = jt->second; - } - - { - std::map::iterator jt = maps.find("label"); - if (jt != maps.end()) { - label_index = jt->second; - } else { - label_index = -1; - } - } - map_num = maps.size(); + std::map maps; + + std::string map; + int index = 0; + while (_reader_bits::readToken(line, map)) { + if (maps.find(map) != maps.end()) { + std::ostringstream msg; + msg << "Multiple occurence of node map: " << map; + throw DataFormatError(msg.str().c_str()); + } + maps.insert(std::make_pair(map, index)); + ++index; + } + + for (int i = 0; i < static_cast(_node_maps.size()); ++i) { + std::map::iterator jt = + maps.find(_node_maps[i].first); + if (jt == maps.end()) { + std::ostringstream msg; + msg << "Map not found in file: " << _node_maps[i].first; + throw DataFormatError(msg.str().c_str()); + } + map_index[i] = jt->second; + } + + { + std::map::iterator jt = maps.find("label"); + if (jt != maps.end()) { + label_index = jt->second; + } else { + label_index = -1; + } + } + map_num = maps.size(); } while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::vector tokens(map_num); - for (int i = 0; i < map_num; ++i) { - if (!_reader_bits::readToken(line, tokens[i])) { - std::ostringstream msg; - msg << "Column not found (" << i + 1 << ")"; - throw DataFormatError(msg.str().c_str()); - } - } - if (line >> std::ws >> c) - throw DataFormatError("Extra character on the end of line"); - - Node n; - if (!_use_nodes) { - n = _graph.addNode(); - if (label_index != -1) - _node_index.insert(std::make_pair(tokens[label_index], n)); - } else { - if (label_index == -1) - throw DataFormatError("Label map not found in file"); - typename std::map::iterator it = - _node_index.find(tokens[label_index]); - if (it == _node_index.end()) { - std::ostringstream msg; - msg << "Node with label not found: " << tokens[label_index]; - throw DataFormatError(msg.str().c_str()); - } - n = it->second; - } - - for (int i = 0; i < static_cast(_node_maps.size()); ++i) { - _node_maps[i].second->set(n, tokens[map_index[i]]); - } + line.putback(c); + + std::vector tokens(map_num); + for (int i = 0; i < map_num; ++i) { + if (!_reader_bits::readToken(line, tokens[i])) { + std::ostringstream msg; + msg << "Column not found (" << i + 1 << ")"; + throw DataFormatError(msg.str().c_str()); + } + } + if (line >> std::ws >> c) + throw DataFormatError("Extra character on the end of line"); + + Node n; + if (!_use_nodes) { + n = _graph.addNode(); + if (label_index != -1) + _node_index.insert(std::make_pair(tokens[label_index], n)); + } else { + if (label_index == -1) + throw DataFormatError("Label map not found in file"); + typename std::map::iterator it = + _node_index.find(tokens[label_index]); + if (it == _node_index.end()) { + std::ostringstream msg; + msg << "Node with label not found: " << tokens[label_index]; + throw DataFormatError(msg.str().c_str()); + } + n = it->second; + } + + for (int i = 0; i < static_cast(_node_maps.size()); ++i) { + _node_maps[i].second->set(n, tokens[map_index[i]]); + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } } @@ -1763,78 +1763,78 @@ char c; if (!readLine() || !(line >> c) || c == '@') { - if (readSuccess() && line) line.putback(c); - if (!_edge_maps.empty()) - throw DataFormatError("Cannot find map names"); - return; + if (readSuccess() && line) line.putback(c); + if (!_edge_maps.empty()) + throw DataFormatError("Cannot find map names"); + return; } line.putback(c); - + { - std::map maps; - - std::string map; - int index = 0; - while (_reader_bits::readToken(line, map)) { - if (maps.find(map) != maps.end()) { - std::ostringstream msg; - msg << "Multiple occurence of edge map: " << map; - throw DataFormatError(msg.str().c_str()); - } - maps.insert(std::make_pair(map, index)); - ++index; - } - - for (int i = 0; i < static_cast(_edge_maps.size()); ++i) { - std::map::iterator jt = - maps.find(_edge_maps[i].first); - if (jt == maps.end()) { - std::ostringstream msg; - msg << "Map not found in file: " << _edge_maps[i].first; - throw DataFormatError(msg.str().c_str()); - } - map_index[i] = jt->second; - } - - { - std::map::iterator jt = maps.find("label"); - if (jt != maps.end()) { - label_index = jt->second; - } else { - label_index = -1; - } - } - map_num = maps.size(); + std::map maps; + + std::string map; + int index = 0; + while (_reader_bits::readToken(line, map)) { + if (maps.find(map) != maps.end()) { + std::ostringstream msg; + msg << "Multiple occurence of edge map: " << map; + throw DataFormatError(msg.str().c_str()); + } + maps.insert(std::make_pair(map, index)); + ++index; + } + + for (int i = 0; i < static_cast(_edge_maps.size()); ++i) { + std::map::iterator jt = + maps.find(_edge_maps[i].first); + if (jt == maps.end()) { + std::ostringstream msg; + msg << "Map not found in file: " << _edge_maps[i].first; + throw DataFormatError(msg.str().c_str()); + } + map_index[i] = jt->second; + } + + { + std::map::iterator jt = maps.find("label"); + if (jt != maps.end()) { + label_index = jt->second; + } else { + label_index = -1; + } + } + map_num = maps.size(); } while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::string source_token; - std::string target_token; - - if (!_reader_bits::readToken(line, source_token)) - throw DataFormatError("Node u not found"); - - if (!_reader_bits::readToken(line, target_token)) - throw DataFormatError("Node v not found"); - - std::vector tokens(map_num); - for (int i = 0; i < map_num; ++i) { - if (!_reader_bits::readToken(line, tokens[i])) { - std::ostringstream msg; - msg << "Column not found (" << i + 1 << ")"; - throw DataFormatError(msg.str().c_str()); - } - } - if (line >> std::ws >> c) - throw DataFormatError("Extra character on the end of line"); - - Edge e; - if (!_use_edges) { + line.putback(c); + + std::string source_token; + std::string target_token; + + if (!_reader_bits::readToken(line, source_token)) + throw DataFormatError("Node u not found"); + + if (!_reader_bits::readToken(line, target_token)) + throw DataFormatError("Node v not found"); + + std::vector tokens(map_num); + for (int i = 0; i < map_num; ++i) { + if (!_reader_bits::readToken(line, tokens[i])) { + std::ostringstream msg; + msg << "Column not found (" << i + 1 << ")"; + throw DataFormatError(msg.str().c_str()); + } + } + if (line >> std::ws >> c) + throw DataFormatError("Extra character on the end of line"); + + Edge e; + if (!_use_edges) { typename NodeIndex::iterator it; - + it = _node_index.find(source_token); if (it == _node_index.end()) { std::ostringstream msg; @@ -1844,36 +1844,36 @@ Node source = it->second; it = _node_index.find(target_token); - if (it == _node_index.end()) { - std::ostringstream msg; + if (it == _node_index.end()) { + std::ostringstream msg; msg << "Item not found: " << target_token; throw DataFormatError(msg.str().c_str()); - } - Node target = it->second; - - e = _graph.addEdge(source, target); - if (label_index != -1) - _edge_index.insert(std::make_pair(tokens[label_index], e)); - } else { - if (label_index == -1) - throw DataFormatError("Label map not found in file"); - typename std::map::iterator it = - _edge_index.find(tokens[label_index]); - if (it == _edge_index.end()) { - std::ostringstream msg; - msg << "Edge with label not found: " << tokens[label_index]; - throw DataFormatError(msg.str().c_str()); - } - e = it->second; - } - - for (int i = 0; i < static_cast(_edge_maps.size()); ++i) { - _edge_maps[i].second->set(e, tokens[map_index[i]]); - } + } + Node target = it->second; + + e = _graph.addEdge(source, target); + if (label_index != -1) + _edge_index.insert(std::make_pair(tokens[label_index], e)); + } else { + if (label_index == -1) + throw DataFormatError("Label map not found in file"); + typename std::map::iterator it = + _edge_index.find(tokens[label_index]); + if (it == _edge_index.end()) { + std::ostringstream msg; + msg << "Edge with label not found: " << tokens[label_index]; + throw DataFormatError(msg.str().c_str()); + } + e = it->second; + } + + for (int i = 0; i < static_cast(_edge_maps.size()); ++i) { + _edge_maps[i].second->set(e, tokens[map_index[i]]); + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } } @@ -1883,125 +1883,125 @@ char c; while (readLine() && line >> c && c != '@') { - line.putback(c); - - std::string attr, token; - if (!_reader_bits::readToken(line, attr)) - throw DataFormatError("Attribute name not found"); - if (!_reader_bits::readToken(line, token)) - throw DataFormatError("Attribute value not found"); - if (line >> c) - throw DataFormatError("Extra character on the end of line"); - - { - std::set::iterator it = read_attr.find(attr); - if (it != read_attr.end()) { - std::ostringstream msg; - msg << "Multiple occurence of attribute " << attr; - throw DataFormatError(msg.str().c_str()); - } - read_attr.insert(attr); - } - - { - typename Attributes::iterator it = _attributes.lower_bound(attr); - while (it != _attributes.end() && it->first == attr) { - it->second->set(token); - ++it; - } - } + line.putback(c); + + std::string attr, token; + if (!_reader_bits::readToken(line, attr)) + throw DataFormatError("Attribute name not found"); + if (!_reader_bits::readToken(line, token)) + throw DataFormatError("Attribute value not found"); + if (line >> c) + throw DataFormatError("Extra character on the end of line"); + + { + std::set::iterator it = read_attr.find(attr); + if (it != read_attr.end()) { + std::ostringstream msg; + msg << "Multiple occurence of attribute " << attr; + throw DataFormatError(msg.str().c_str()); + } + read_attr.insert(attr); + } + + { + typename Attributes::iterator it = _attributes.lower_bound(attr); + while (it != _attributes.end() && it->first == attr) { + it->second->set(token); + ++it; + } + } } if (readSuccess()) { - line.putback(c); + line.putback(c); } for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - if (read_attr.find(it->first) == read_attr.end()) { - std::ostringstream msg; - msg << "Attribute not found in file: " << it->first; - throw DataFormatError(msg.str().c_str()); - } + it != _attributes.end(); ++it) { + if (read_attr.find(it->first) == read_attr.end()) { + std::ostringstream msg; + msg << "Attribute not found in file: " << it->first; + throw DataFormatError(msg.str().c_str()); + } } } public: - /// \name Execution of the reader + /// \name Execution of the reader /// @{ /// \brief Start the batch processing /// /// This function starts the batch processing void run() { - + LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); - + bool nodes_done = _skip_nodes; bool edges_done = _skip_edges; bool attributes_done = false; - line_num = 0; + line_num = 0; readLine(); skipSection(); while (readSuccess()) { - try { - char c; - std::string section, caption; - line >> c; - _reader_bits::readToken(line, section); - _reader_bits::readToken(line, caption); - - if (line >> c) - throw DataFormatError("Extra character on the end of line"); - - if (section == "nodes" && !nodes_done) { - if (_nodes_caption.empty() || _nodes_caption == caption) { - readNodes(); - nodes_done = true; - } - } else if ((section == "edges" || section == "arcs") && - !edges_done) { - if (_edges_caption.empty() || _edges_caption == caption) { - readEdges(); - edges_done = true; - } - } else if (section == "attributes" && !attributes_done) { - if (_attributes_caption.empty() || _attributes_caption == caption) { - readAttributes(); - attributes_done = true; - } - } else { - readLine(); - skipSection(); - } - } catch (DataFormatError& error) { - error.line(line_num); - throw; - } + try { + char c; + std::string section, caption; + line >> c; + _reader_bits::readToken(line, section); + _reader_bits::readToken(line, caption); + + if (line >> c) + throw DataFormatError("Extra character on the end of line"); + + if (section == "nodes" && !nodes_done) { + if (_nodes_caption.empty() || _nodes_caption == caption) { + readNodes(); + nodes_done = true; + } + } else if ((section == "edges" || section == "arcs") && + !edges_done) { + if (_edges_caption.empty() || _edges_caption == caption) { + readEdges(); + edges_done = true; + } + } else if (section == "attributes" && !attributes_done) { + if (_attributes_caption.empty() || _attributes_caption == caption) { + readAttributes(); + attributes_done = true; + } + } else { + readLine(); + skipSection(); + } + } catch (DataFormatError& error) { + error.line(line_num); + throw; + } } if (!nodes_done) { - throw DataFormatError("Section @nodes not found"); + throw DataFormatError("Section @nodes not found"); } if (!edges_done) { - throw DataFormatError("Section @edges not found"); + throw DataFormatError("Section @edges not found"); } if (!attributes_done && !_attributes.empty()) { - throw DataFormatError("Section @attributes not found"); + throw DataFormatError("Section @attributes not found"); } } /// @} - + }; /// \brief Return a \ref GraphReader class - /// + /// /// This function just returns a \ref GraphReader class. /// \relates GraphReader template @@ -2011,18 +2011,18 @@ } /// \brief Return a \ref GraphReader class - /// + /// /// This function just returns a \ref GraphReader class. /// \relates GraphReader template - GraphReader graphReader(const std::string& fn, - Graph& graph) { + GraphReader graphReader(const std::string& fn, + Graph& graph) { GraphReader tmp(fn, graph); return tmp; } /// \brief Return a \ref GraphReader class - /// + /// /// This function just returns a \ref GraphReader class. /// \relates GraphReader template @@ -2036,21 +2036,21 @@ SectionReader sectionReader(std::istream& is); SectionReader sectionReader(const std::string& fn); SectionReader sectionReader(const char* fn); - + /// \ingroup lemon_io /// /// \brief Section reader class /// - /// In the \ref lgf-format "LGF" file extra sections can be placed, + /// In the \ref lgf-format "LGF" file extra sections can be placed, /// which contain any data in arbitrary format. Such sections can be - /// read with this class. A reading rule can be added to the class + /// read with this class. A reading rule can be added to the class /// with two different functions. With the \c sectionLines() function a /// functor can process the section line-by-line, while with the \c /// sectionStream() member the section can be read from an input /// stream. class SectionReader { private: - + std::istream* _is; bool local_is; @@ -2066,30 +2066,30 @@ /// /// Construct a section reader, which reads from the given input /// stream. - SectionReader(std::istream& is) + SectionReader(std::istream& is) : _is(&is), local_is(false) {} /// \brief Constructor /// /// Construct a section reader, which reads from the given file. - SectionReader(const std::string& fn) + SectionReader(const std::string& fn) : _is(new std::ifstream(fn.c_str())), local_is(true) {} - + /// \brief Constructor /// /// Construct a section reader, which reads from the given file. - SectionReader(const char* fn) + SectionReader(const char* fn) : _is(new std::ifstream(fn)), local_is(true) {} /// \brief Destructor ~SectionReader() { - for (Sections::iterator it = _sections.begin(); - it != _sections.end(); ++it) { - delete it->second; + for (Sections::iterator it = _sections.begin(); + it != _sections.end(); ++it) { + delete it->second; } if (local_is) { - delete _is; + delete _is; } } @@ -2100,15 +2100,15 @@ friend SectionReader sectionReader(const std::string& fn); friend SectionReader sectionReader(const char* fn); - SectionReader(SectionReader& other) + SectionReader(SectionReader& other) : _is(other._is), local_is(other.local_is) { other._is = 0; other.local_is = false; - + _sections.swap(other._sections); } - + SectionReader& operator=(const SectionReader&); public: @@ -2148,14 +2148,14 @@ /// /// // ... /// - /// reader.sectionLines("numbers", NumberSection(vec)); + /// reader.sectionLines("numbers", NumberSection(vec)); ///\endcode template SectionReader& sectionLines(const std::string& type, Functor functor) { LEMON_ASSERT(!type.empty(), "Type is empty."); - LEMON_ASSERT(_sections.find(type) == _sections.end(), - "Multiple reading of section."); - _sections.insert(std::make_pair(type, + LEMON_ASSERT(_sections.find(type) == _sections.end(), + "Multiple reading of section."); + _sections.insert(std::make_pair(type, new _reader_bits::LineSection(functor))); return *this; } @@ -2171,13 +2171,13 @@ template SectionReader& sectionStream(const std::string& type, Functor functor) { LEMON_ASSERT(!type.empty(), "Type is empty."); - LEMON_ASSERT(_sections.find(type) == _sections.end(), - "Multiple reading of section."); - _sections.insert(std::make_pair(type, - new _reader_bits::StreamSection(functor))); + LEMON_ASSERT(_sections.find(type) == _sections.end(), + "Multiple reading of section."); + _sections.insert(std::make_pair(type, + new _reader_bits::StreamSection(functor))); return *this; - } - + } + /// @} private: @@ -2185,12 +2185,12 @@ bool readLine() { std::string str; while(++line_num, std::getline(*_is, str)) { - line.clear(); line.str(str); - char c; - if (line >> std::ws >> c && c != '#') { - line.putback(c); - return true; - } + line.clear(); line.str(str); + char c; + if (line >> std::ws >> c && c != '#') { + line.putback(c); + return true; + } } return false; } @@ -2198,11 +2198,11 @@ bool readSuccess() { return static_cast(*_is); } - + void skipSection() { char c; while (readSuccess() && line >> c && c != '@') { - readLine(); + readLine(); } line.putback(c); } @@ -2210,66 +2210,66 @@ public: - /// \name Execution of the reader + /// \name Execution of the reader /// @{ /// \brief Start the batch processing /// /// This function starts the batch processing. void run() { - + LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); - + std::set extra_sections; - line_num = 0; + line_num = 0; readLine(); skipSection(); while (readSuccess()) { - try { - char c; - std::string section, caption; - line >> c; - _reader_bits::readToken(line, section); - _reader_bits::readToken(line, caption); - - if (line >> c) - throw DataFormatError("Extra character on the end of line"); - - if (extra_sections.find(section) != extra_sections.end()) { - std::ostringstream msg; - msg << "Multiple occurence of section " << section; - throw DataFormatError(msg.str().c_str()); - } - Sections::iterator it = _sections.find(section); - if (it != _sections.end()) { - extra_sections.insert(section); - it->second->process(*_is, line_num); - } - readLine(); - skipSection(); - } catch (DataFormatError& error) { - error.line(line_num); - throw; - } + try { + char c; + std::string section, caption; + line >> c; + _reader_bits::readToken(line, section); + _reader_bits::readToken(line, caption); + + if (line >> c) + throw DataFormatError("Extra character on the end of line"); + + if (extra_sections.find(section) != extra_sections.end()) { + std::ostringstream msg; + msg << "Multiple occurence of section " << section; + throw DataFormatError(msg.str().c_str()); + } + Sections::iterator it = _sections.find(section); + if (it != _sections.end()) { + extra_sections.insert(section); + it->second->process(*_is, line_num); + } + readLine(); + skipSection(); + } catch (DataFormatError& error) { + error.line(line_num); + throw; + } } for (Sections::iterator it = _sections.begin(); - it != _sections.end(); ++it) { - if (extra_sections.find(it->first) == extra_sections.end()) { - std::ostringstream os; - os << "Cannot find section: " << it->first; - throw DataFormatError(os.str().c_str()); - } + it != _sections.end(); ++it) { + if (extra_sections.find(it->first) == extra_sections.end()) { + std::ostringstream os; + os << "Cannot find section: " << it->first; + throw DataFormatError(os.str().c_str()); + } } } /// @} - + }; /// \brief Return a \ref SectionReader class - /// + /// /// This function just returns a \ref SectionReader class. /// \relates SectionReader inline SectionReader sectionReader(std::istream& is) { @@ -2278,7 +2278,7 @@ } /// \brief Return a \ref SectionReader class - /// + /// /// This function just returns a \ref SectionReader class. /// \relates SectionReader inline SectionReader sectionReader(const std::string& fn) { @@ -2287,7 +2287,7 @@ } /// \brief Return a \ref SectionReader class - /// + /// /// This function just returns a \ref SectionReader class. /// \relates SectionReader inline SectionReader sectionReader(const char* fn) { @@ -2297,7 +2297,7 @@ /// \ingroup lemon_io /// - /// \brief Reader for the contents of the \ref lgf-format "LGF" file + /// \brief Reader for the contents of the \ref lgf-format "LGF" file /// /// This class can be used to read the sections, the map names and /// the attributes from a file. Usually, the Lemon programs know @@ -2307,8 +2307,8 @@ /// reads the graph and stores the appropriate information for /// reading the graph. /// - ///\code - /// LgfContents contents("graph.lgf"); + ///\code + /// LgfContents contents("graph.lgf"); /// contents.run(); /// /// // Does it contain any node section and arc section? @@ -2316,14 +2316,14 @@ /// std::cerr << "Failure, cannot find graph." << std::endl; /// return -1; /// } - /// std::cout << "The name of the default node section: " + /// std::cout << "The name of the default node section: " /// << contents.nodeSection(0) << std::endl; - /// std::cout << "The number of the arc maps: " + /// std::cout << "The number of the arc maps: " /// << contents.arcMaps(0).size() << std::endl; - /// std::cout << "The name of second arc map: " + /// std::cout << "The name of second arc map: " /// << contents.arcMaps(0)[1] << std::endl; ///\endcode - class LgfContents { + class LgfContents { private: std::istream* _is; @@ -2344,21 +2344,21 @@ int line_num; std::istringstream line; - + public: /// \brief Constructor /// /// Construct an \e LGF contents reader, which reads from the given /// input stream. - LgfContents(std::istream& is) + LgfContents(std::istream& is) : _is(&is), local_is(false) {} /// \brief Constructor /// /// Construct an \e LGF contents reader, which reads from the given /// file. - LgfContents(const std::string& fn) + LgfContents(const std::string& fn) : _is(new std::ifstream(fn.c_str())), local_is(true) {} /// \brief Constructor @@ -2367,14 +2367,14 @@ /// file. LgfContents(const char* fn) : _is(new std::ifstream(fn)), local_is(true) {} - + /// \brief Destructor ~LgfContents() { if (local_is) delete _is; } private: - + LgfContents(const LgfContents&); LgfContents& operator=(const LgfContents&); @@ -2391,9 +2391,9 @@ return _node_sections.size(); } - /// \brief Returns the node section name at the given position. + /// \brief Returns the node section name at the given position. /// - /// Returns the node section name at the given position. + /// Returns the node section name at the given position. const std::string& nodeSection(int i) const { return _node_sections[i]; } @@ -2407,7 +2407,7 @@ /// @} - /// \name Arc/Edge sections + /// \name Arc/Edge sections /// @{ /// \brief Gives back the number of arc/edge sections in the file. @@ -2418,9 +2418,9 @@ return _edge_sections.size(); } - /// \brief Returns the arc/edge section name at the given position. + /// \brief Returns the arc/edge section name at the given position. /// - /// Returns the arc/edge section name at the given position. + /// Returns the arc/edge section name at the given position. /// \note It is synonym of \c edgeSection(). const std::string& arcSection(int i) const { return _edge_sections[i]; @@ -2447,9 +2447,9 @@ return _edge_sections.size(); } - /// \brief Returns the section name at the given position. + /// \brief Returns the section name at the given position. /// - /// Returns the section name at the given position. + /// Returns the section name at the given position. /// \note It is synonym of \c arcSection(). const std::string& edgeSection(int i) const { return _edge_sections[i]; @@ -2465,7 +2465,7 @@ /// @} - /// \name Attribute sections + /// \name Attribute sections /// @{ /// \brief Gives back the number of attribute sections in the file. @@ -2475,9 +2475,9 @@ return _attribute_sections.size(); } - /// \brief Returns the attribute section name at the given position. + /// \brief Returns the attribute section name at the given position. /// - /// Returns the attribute section name at the given position. + /// Returns the attribute section name at the given position. const std::string& attributeSectionNames(int i) const { return _attribute_sections[i]; } @@ -2491,7 +2491,7 @@ /// @} - /// \name Extra sections + /// \name Extra sections /// @{ /// \brief Gives back the number of extra sections in the file. @@ -2501,9 +2501,9 @@ return _extra_sections.size(); } - /// \brief Returns the extra section type at the given position. + /// \brief Returns the extra section type at the given position. /// - /// Returns the section type at the given position. + /// Returns the section type at the given position. const std::string& extraSection(int i) const { return _extra_sections[i]; } @@ -2515,12 +2515,12 @@ bool readLine() { std::string str; while(++line_num, std::getline(*_is, str)) { - line.clear(); line.str(str); - char c; - if (line >> std::ws >> c && c != '#') { - line.putback(c); - return true; - } + line.clear(); line.str(str); + char c; + if (line >> std::ws >> c && c != '#') { + line.putback(c); + return true; + } } return false; } @@ -2532,7 +2532,7 @@ void skipSection() { char c; while (readSuccess() && line >> c && c != '@') { - readLine(); + readLine(); } line.putback(c); } @@ -2540,13 +2540,13 @@ void readMaps(std::vector& maps) { char c; if (!readLine() || !(line >> c) || c == '@') { - if (readSuccess() && line) line.putback(c); - return; + if (readSuccess() && line) line.putback(c); + return; } line.putback(c); std::string map; while (_reader_bits::readToken(line, map)) { - maps.push_back(map); + maps.push_back(map); } } @@ -2554,18 +2554,18 @@ readLine(); char c; while (readSuccess() && line >> c && c != '@') { - line.putback(c); - std::string attr; - _reader_bits::readToken(line, attr); - attrs.push_back(attr); - readLine(); + line.putback(c); + std::string attr; + _reader_bits::readToken(line, attr); + attrs.push_back(attr); + readLine(); } line.putback(c); } public: - /// \name Execution of the contents reader + /// \name Execution of the contents reader /// @{ /// \brief Starts the reading @@ -2578,37 +2578,37 @@ while (readSuccess()) { - char c; - line >> c; - - std::string section, caption; - _reader_bits::readToken(line, section); - _reader_bits::readToken(line, caption); - - if (section == "nodes") { - _node_sections.push_back(caption); - _node_maps.push_back(std::vector()); - readMaps(_node_maps.back()); - readLine(); skipSection(); - } else if (section == "arcs" || section == "edges") { - _edge_sections.push_back(caption); - _arc_sections.push_back(section == "arcs"); - _edge_maps.push_back(std::vector()); - readMaps(_edge_maps.back()); - readLine(); skipSection(); - } else if (section == "attributes") { - _attribute_sections.push_back(caption); - _attributes.push_back(std::vector()); - readAttributes(_attributes.back()); - } else { - _extra_sections.push_back(section); - readLine(); skipSection(); - } + char c; + line >> c; + + std::string section, caption; + _reader_bits::readToken(line, section); + _reader_bits::readToken(line, caption); + + if (section == "nodes") { + _node_sections.push_back(caption); + _node_maps.push_back(std::vector()); + readMaps(_node_maps.back()); + readLine(); skipSection(); + } else if (section == "arcs" || section == "edges") { + _edge_sections.push_back(caption); + _arc_sections.push_back(section == "arcs"); + _edge_maps.push_back(std::vector()); + readMaps(_edge_maps.back()); + readLine(); skipSection(); + } else if (section == "attributes") { + _attribute_sections.push_back(caption); + _attributes.push_back(std::vector()); + readAttributes(_attributes.back()); + } else { + _extra_sections.push_back(section); + readLine(); skipSection(); + } } } /// @} - + }; } diff -r 4317d277ba21 -r 765619b7cbb2 lemon/lgf_writer.h --- a/lemon/lgf_writer.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/lgf_writer.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -43,9 +43,9 @@ template struct DefaultConverter { std::string operator()(const Value& value) { - std::ostringstream os; - os << value; - return os.str(); + std::ostringstream os; + os << value; + return os.str(); } }; @@ -62,12 +62,12 @@ private: const Map& _map; - + public: MapLess(const Map& map) : _map(map) {} bool operator()(const Item& left, const Item& right) { - return _map[left] < _map[right]; + return _map[left] < _map[right]; } }; @@ -81,18 +81,18 @@ private: const Graph& _graph; const Map& _map; - + public: - GraphArcMapLess(const Graph& graph, const Map& map) - : _graph(graph), _map(map) {} + GraphArcMapLess(const Graph& graph, const Map& map) + : _graph(graph), _map(map) {} bool operator()(const Item& left, const Item& right) { - return _map[_graph.direct(left, _dir)] < - _map[_graph.direct(right, _dir)]; + return _map[_graph.direct(left, _dir)] < + _map[_graph.direct(right, _dir)]; } }; - template + template class MapStorageBase { public: typedef _Item Item; @@ -105,34 +105,34 @@ virtual void sort(std::vector&) = 0; }; - template > + template > class MapStorage : public MapStorageBase<_Item> { public: typedef _Map Map; typedef _Converter Converter; typedef _Item Item; - + private: const Map& _map; Converter _converter; public: - MapStorage(const Map& map, const Converter& converter = Converter()) - : _map(map), _converter(converter) {} + MapStorage(const Map& map, const Converter& converter = Converter()) + : _map(map), _converter(converter) {} virtual ~MapStorage() {} virtual std::string get(const Item& item) { - return _converter(_map[item]); + return _converter(_map[item]); } virtual void sort(std::vector& items) { - MapLess less(_map); - std::sort(items.begin(), items.end(), less); + MapLess less(_map); + std::sort(items.begin(), items.end(), less); } }; - template > + template > class GraphArcMapStorage : public MapStorageBase { public: typedef _Map Map; @@ -140,24 +140,24 @@ typedef _Graph Graph; typedef typename Graph::Edge Item; static const bool dir = _dir; - + private: const Graph& _graph; const Map& _map; Converter _converter; public: - GraphArcMapStorage(const Graph& graph, const Map& map, - const Converter& converter = Converter()) - : _graph(graph), _map(map), _converter(converter) {} + GraphArcMapStorage(const Graph& graph, const Map& map, + const Converter& converter = Converter()) + : _graph(graph), _map(map), _converter(converter) {} virtual ~GraphArcMapStorage() {} virtual std::string get(const Item& item) { - return _converter(_map[_graph.direct(item, dir)]); + return _converter(_map[_graph.direct(item, dir)]); } virtual void sort(std::vector& items) { - GraphArcMapLess less(_graph, _map); - std::sort(items.begin(), items.end(), less); + GraphArcMapLess less(_graph, _map); + std::sort(items.begin(), items.end(), less); } }; @@ -166,7 +166,7 @@ ValueStorageBase() {} virtual ~ValueStorageBase() {} - virtual std::string get() = 0; + virtual std::string get() = 0; }; template > @@ -181,27 +181,27 @@ public: ValueStorage(const Value& value, const Converter& converter = Converter()) - : _value(value), _converter(converter) {} + : _value(value), _converter(converter) {} virtual std::string get() { - return _converter(_value); + return _converter(_value); } }; template struct MapLookUpConverter { const std::map& _map; - - MapLookUpConverter(const std::map& map) - : _map(map) {} - + + MapLookUpConverter(const std::map& map) + : _map(map) {} + std::string operator()(const Value& str) { - typename std::map::const_iterator it = - _map.find(str); - if (it == _map.end()) { - throw DataFormatError("Item not found"); - } - return it->second; + typename std::map::const_iterator it = + _map.find(str); + if (it == _map.end()) { + throw DataFormatError("Item not found"); + } + return it->second; } }; @@ -209,71 +209,71 @@ struct GraphArcLookUpConverter { const Graph& _graph; const std::map& _map; - - GraphArcLookUpConverter(const Graph& graph, - const std::map& map) - : _graph(graph), _map(map) {} - + + GraphArcLookUpConverter(const Graph& graph, + const std::map& map) + : _graph(graph), _map(map) {} + std::string operator()(const typename Graph::Arc& val) { - typename std::map - ::const_iterator it = _map.find(val); - if (it == _map.end()) { - throw DataFormatError("Item not found"); - } - return (_graph.direction(val) ? '+' : '-') + it->second; + typename std::map + ::const_iterator it = _map.find(val); + if (it == _map.end()) { + throw DataFormatError("Item not found"); + } + return (_graph.direction(val) ? '+' : '-') + it->second; } }; inline bool isWhiteSpace(char c) { - return c == ' ' || c == '\t' || c == '\v' || - c == '\n' || c == '\r' || c == '\f'; + return c == ' ' || c == '\t' || c == '\v' || + c == '\n' || c == '\r' || c == '\f'; } inline bool isEscaped(char c) { - return c == '\\' || c == '\"' || c == '\'' || - c == '\a' || c == '\b'; + return c == '\\' || c == '\"' || c == '\'' || + c == '\a' || c == '\b'; } inline static void writeEscape(std::ostream& os, char c) { switch (c) { case '\\': - os << "\\\\"; - return; + os << "\\\\"; + return; case '\"': - os << "\\\""; - return; + os << "\\\""; + return; case '\a': - os << "\\a"; - return; + os << "\\a"; + return; case '\b': - os << "\\b"; - return; + os << "\\b"; + return; case '\f': - os << "\\f"; - return; + os << "\\f"; + return; case '\r': - os << "\\r"; - return; + os << "\\r"; + return; case '\n': - os << "\\n"; - return; + os << "\\n"; + return; case '\t': - os << "\\t"; - return; + os << "\\t"; + return; case '\v': - os << "\\v"; - return; + os << "\\v"; + return; default: - if (c < 0x20) { - std::ios::fmtflags flags = os.flags(); - os << '\\' << std::oct << static_cast(c); - os.flags(flags); - } else { - os << c; - } - return; - } + if (c < 0x20) { + std::ios::fmtflags flags = os.flags(); + os << '\\' << std::oct << static_cast(c); + os.flags(flags); + } else { + os << c; + } + return; + } } inline bool requireEscape(const std::string& str) { @@ -281,24 +281,24 @@ std::istringstream is(str); char c; while (is.get(c)) { - if (isWhiteSpace(c) || isEscaped(c)) { - return true; - } + if (isWhiteSpace(c) || isEscaped(c)) { + return true; + } } return false; } - + inline std::ostream& writeToken(std::ostream& os, const std::string& str) { if (requireEscape(str)) { - os << '\"'; - for (std::string::const_iterator it = str.begin(); - it != str.end(); ++it) { - writeEscape(os, *it); - } - os << '\"'; + os << '\"'; + for (std::string::const_iterator it = str.begin(); + it != str.end(); ++it) { + writeEscape(os, *it); + } + os << '\"'; } else { - os << str; + os << str; } return os; } @@ -309,19 +309,19 @@ class DigraphWriter; template - DigraphWriter digraphWriter(std::ostream& os, - const Digraph& digraph); + DigraphWriter digraphWriter(std::ostream& os, + const Digraph& digraph); template - DigraphWriter digraphWriter(const std::string& fn, - const Digraph& digraph); + DigraphWriter digraphWriter(const std::string& fn, + const Digraph& digraph); template - DigraphWriter digraphWriter(const char *fn, - const Digraph& digraph); - + DigraphWriter digraphWriter(const char *fn, + const Digraph& digraph); + /// \ingroup lemon_io - /// + /// /// \brief \ref lgf-format "LGF" writer for directed graphs /// /// This utility writes an \ref lgf-format "LGF" file. @@ -370,7 +370,7 @@ typedef _Digraph Digraph; TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); - + private: @@ -382,21 +382,21 @@ std::string _nodes_caption; std::string _arcs_caption; std::string _attributes_caption; - + typedef std::map NodeIndex; NodeIndex _node_index; typedef std::map ArcIndex; ArcIndex _arc_index; - typedef std::vector* > > NodeMaps; - NodeMaps _node_maps; + typedef std::vector* > > NodeMaps; + NodeMaps _node_maps; - typedef std::vector* > >ArcMaps; ArcMaps _arc_maps; - typedef std::vector > Attributes; Attributes _attributes; @@ -409,60 +409,60 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - DigraphWriter(std::ostream& is, const Digraph& digraph) + DigraphWriter(std::ostream& is, const Digraph& digraph) : _os(&is), local_os(false), _digraph(digraph), - _skip_nodes(false), _skip_arcs(false) {} + _skip_nodes(false), _skip_arcs(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const std::string& fn, const Digraph& digraph) + DigraphWriter(const std::string& fn, const Digraph& digraph) : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), - _skip_nodes(false), _skip_arcs(false) {} + _skip_nodes(false), _skip_arcs(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const char* fn, const Digraph& digraph) + DigraphWriter(const char* fn, const Digraph& digraph) : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), - _skip_nodes(false), _skip_arcs(false) {} + _skip_nodes(false), _skip_arcs(false) {} /// \brief Destructor ~DigraphWriter() { - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - delete it->second; + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + delete it->second; } - for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { - delete it->second; + for (typename ArcMaps::iterator it = _arc_maps.begin(); + it != _arc_maps.end(); ++it) { + delete it->second; } - for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - delete it->second; + for (typename Attributes::iterator it = _attributes.begin(); + it != _attributes.end(); ++it) { + delete it->second; } if (local_os) { - delete _os; + delete _os; } } private: - friend DigraphWriter digraphWriter<>(std::ostream& os, - const Digraph& digraph); - friend DigraphWriter digraphWriter<>(const std::string& fn, - const Digraph& digraph); - friend DigraphWriter digraphWriter<>(const char *fn, - const Digraph& digraph); + friend DigraphWriter digraphWriter<>(std::ostream& os, + const Digraph& digraph); + friend DigraphWriter digraphWriter<>(const std::string& fn, + const Digraph& digraph); + friend DigraphWriter digraphWriter<>(const char *fn, + const Digraph& digraph); - DigraphWriter(DigraphWriter& other) + DigraphWriter(DigraphWriter& other) : _os(other._os), local_os(other.local_os), _digraph(other._digraph), - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) { other._os = 0; other.local_os = false; @@ -478,22 +478,22 @@ _arcs_caption = other._arcs_caption; _attributes_caption = other._attributes_caption; } - + DigraphWriter& operator=(const DigraphWriter&); public: /// \name Writing rules /// @{ - + /// \brief Node map writing rule /// /// Add a node map writing rule to the writer. template DigraphWriter& nodeMap(const std::string& caption, const Map& map) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -503,11 +503,11 @@ /// Add a node map writing rule with specialized converter to the /// writer. template - DigraphWriter& nodeMap(const std::string& caption, const Map& map, - const Converter& converter = Converter()) { + DigraphWriter& nodeMap(const std::string& caption, const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map, converter); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map, converter); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -518,8 +518,8 @@ template DigraphWriter& arcMap(const std::string& caption, const Map& map) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map); _arc_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -529,11 +529,11 @@ /// Add an arc map writing rule with specialized converter to the /// writer. template - DigraphWriter& arcMap(const std::string& caption, const Map& map, - const Converter& converter = Converter()) { + DigraphWriter& arcMap(const std::string& caption, const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map, converter); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map, converter); _arc_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -543,8 +543,8 @@ /// Add an attribute writing rule to the writer. template DigraphWriter& attribute(const std::string& caption, const Value& value) { - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(value); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(value); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -554,10 +554,10 @@ /// Add an attribute writing rule with specialized converter to the /// writer. template - DigraphWriter& attribute(const std::string& caption, const Value& value, - const Converter& converter = Converter()) { - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(value, converter); + DigraphWriter& attribute(const std::string& caption, const Value& value, + const Converter& converter = Converter()) { + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(value, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -568,8 +568,8 @@ DigraphWriter& node(const std::string& caption, const Node& node) { typedef _writer_bits::MapLookUpConverter Converter; Converter converter(_node_index); - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(node, converter); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(node, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -580,8 +580,8 @@ DigraphWriter& arc(const std::string& caption, const Arc& arc) { typedef _writer_bits::MapLookUpConverter Converter; Converter converter(_arc_index); - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(arc, converter); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(arc, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -641,175 +641,175 @@ void writeNodes() { _writer_bits::MapStorageBase* label = 0; for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { + it != _node_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } *_os << "@nodes"; if (!_nodes_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _nodes_caption); + _writer_bits::writeToken(*_os << ' ', _nodes_caption); } *_os << std::endl; if (label == 0) { - *_os << "label" << '\t'; + *_os << "label" << '\t'; } for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << '\t'; + it != _node_maps.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << '\t'; } *_os << std::endl; std::vector nodes; for (NodeIt n(_digraph); n != INVALID; ++n) { - nodes.push_back(n); + nodes.push_back(n); } - + if (label == 0) { - IdMap id_map(_digraph); - _writer_bits::MapLess > id_less(id_map); - std::sort(nodes.begin(), nodes.end(), id_less); + IdMap id_map(_digraph); + _writer_bits::MapLess > id_less(id_map); + std::sort(nodes.begin(), nodes.end(), id_less); } else { - label->sort(nodes); + label->sort(nodes); } for (int i = 0; i < static_cast(nodes.size()); ++i) { - Node n = nodes[i]; - if (label == 0) { - std::ostringstream os; - os << _digraph.id(n); - _writer_bits::writeToken(*_os, os.str()); - *_os << '\t'; - _node_index.insert(std::make_pair(n, os.str())); - } - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - std::string value = it->second->get(n); - _writer_bits::writeToken(*_os, value); - if (it->first == "label") { - _node_index.insert(std::make_pair(n, value)); - } - *_os << '\t'; - } - *_os << std::endl; + Node n = nodes[i]; + if (label == 0) { + std::ostringstream os; + os << _digraph.id(n); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _node_index.insert(std::make_pair(n, os.str())); + } + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + std::string value = it->second->get(n); + _writer_bits::writeToken(*_os, value); + if (it->first == "label") { + _node_index.insert(std::make_pair(n, value)); + } + *_os << '\t'; + } + *_os << std::endl; } } void createNodeIndex() { _writer_bits::MapStorageBase* label = 0; for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { + it != _node_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } if (label == 0) { - for (NodeIt n(_digraph); n != INVALID; ++n) { - std::ostringstream os; - os << _digraph.id(n); - _node_index.insert(std::make_pair(n, os.str())); - } + for (NodeIt n(_digraph); n != INVALID; ++n) { + std::ostringstream os; + os << _digraph.id(n); + _node_index.insert(std::make_pair(n, os.str())); + } } else { - for (NodeIt n(_digraph); n != INVALID; ++n) { - std::string value = label->get(n); - _node_index.insert(std::make_pair(n, value)); - } + for (NodeIt n(_digraph); n != INVALID; ++n) { + std::string value = label->get(n); + _node_index.insert(std::make_pair(n, value)); + } } } void writeArcs() { _writer_bits::MapStorageBase* label = 0; for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { + it != _arc_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } *_os << "@arcs"; if (!_arcs_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _arcs_caption); + _writer_bits::writeToken(*_os << ' ', _arcs_caption); } *_os << std::endl; *_os << '\t' << '\t'; if (label == 0) { - *_os << "label" << '\t'; + *_os << "label" << '\t'; } for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << '\t'; + it != _arc_maps.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << '\t'; } *_os << std::endl; std::vector arcs; for (ArcIt n(_digraph); n != INVALID; ++n) { - arcs.push_back(n); + arcs.push_back(n); } - + if (label == 0) { - IdMap id_map(_digraph); - _writer_bits::MapLess > id_less(id_map); - std::sort(arcs.begin(), arcs.end(), id_less); + IdMap id_map(_digraph); + _writer_bits::MapLess > id_less(id_map); + std::sort(arcs.begin(), arcs.end(), id_less); } else { - label->sort(arcs); + label->sort(arcs); } for (int i = 0; i < static_cast(arcs.size()); ++i) { - Arc a = arcs[i]; - _writer_bits::writeToken(*_os, _node_index. - find(_digraph.source(a))->second); - *_os << '\t'; - _writer_bits::writeToken(*_os, _node_index. - find(_digraph.target(a))->second); - *_os << '\t'; - if (label == 0) { - std::ostringstream os; - os << _digraph.id(a); - _writer_bits::writeToken(*_os, os.str()); - *_os << '\t'; - _arc_index.insert(std::make_pair(a, os.str())); - } - for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { - std::string value = it->second->get(a); - _writer_bits::writeToken(*_os, value); - if (it->first == "label") { - _arc_index.insert(std::make_pair(a, value)); - } - *_os << '\t'; - } - *_os << std::endl; + Arc a = arcs[i]; + _writer_bits::writeToken(*_os, _node_index. + find(_digraph.source(a))->second); + *_os << '\t'; + _writer_bits::writeToken(*_os, _node_index. + find(_digraph.target(a))->second); + *_os << '\t'; + if (label == 0) { + std::ostringstream os; + os << _digraph.id(a); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _arc_index.insert(std::make_pair(a, os.str())); + } + for (typename ArcMaps::iterator it = _arc_maps.begin(); + it != _arc_maps.end(); ++it) { + std::string value = it->second->get(a); + _writer_bits::writeToken(*_os, value); + if (it->first == "label") { + _arc_index.insert(std::make_pair(a, value)); + } + *_os << '\t'; + } + *_os << std::endl; } } void createArcIndex() { _writer_bits::MapStorageBase* label = 0; for (typename ArcMaps::iterator it = _arc_maps.begin(); - it != _arc_maps.end(); ++it) { + it != _arc_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } if (label == 0) { - for (ArcIt a(_digraph); a != INVALID; ++a) { - std::ostringstream os; - os << _digraph.id(a); - _arc_index.insert(std::make_pair(a, os.str())); - } + for (ArcIt a(_digraph); a != INVALID; ++a) { + std::ostringstream os; + os << _digraph.id(a); + _arc_index.insert(std::make_pair(a, os.str())); + } } else { - for (ArcIt a(_digraph); a != INVALID; ++a) { - std::string value = label->get(a); - _arc_index.insert(std::make_pair(a, value)); - } + for (ArcIt a(_digraph); a != INVALID; ++a) { + std::string value = label->get(a); + _arc_index.insert(std::make_pair(a, value)); + } } } @@ -817,20 +817,20 @@ if (_attributes.empty()) return; *_os << "@attributes"; if (!_attributes_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _attributes_caption); + _writer_bits::writeToken(*_os << ' ', _attributes_caption); } *_os << std::endl; for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << ' '; - _writer_bits::writeToken(*_os, it->second->get()); - *_os << std::endl; + it != _attributes.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << ' '; + _writer_bits::writeToken(*_os, it->second->get()); + *_os << std::endl; } } - + public: - - /// \name Execution of the writer + + /// \name Execution of the writer /// @{ /// \brief Start the batch processing @@ -838,14 +838,14 @@ /// This function starts the batch processing. void run() { if (!_skip_nodes) { - writeNodes(); + writeNodes(); } else { - createNodeIndex(); + createNodeIndex(); } - if (!_skip_arcs) { - writeArcs(); + if (!_skip_arcs) { + writeArcs(); } else { - createArcIndex(); + createArcIndex(); } writeAttributes(); } @@ -861,34 +861,34 @@ }; /// \brief Return a \ref DigraphWriter class - /// + /// /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(std::ostream& os, - const Digraph& digraph) { + DigraphWriter digraphWriter(std::ostream& os, + const Digraph& digraph) { DigraphWriter tmp(os, digraph); return tmp; } /// \brief Return a \ref DigraphWriter class - /// + /// /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(const std::string& fn, - const Digraph& digraph) { + DigraphWriter digraphWriter(const std::string& fn, + const Digraph& digraph) { DigraphWriter tmp(fn, digraph); return tmp; } /// \brief Return a \ref DigraphWriter class - /// + /// /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter template - DigraphWriter digraphWriter(const char* fn, - const Digraph& digraph) { + DigraphWriter digraphWriter(const char* fn, + const Digraph& digraph) { DigraphWriter tmp(fn, digraph); return tmp; } @@ -897,16 +897,16 @@ class GraphWriter; template - GraphWriter graphWriter(std::ostream& os, const Graph& graph); + GraphWriter graphWriter(std::ostream& os, const Graph& graph); template - GraphWriter graphWriter(const std::string& fn, const Graph& graph); + GraphWriter graphWriter(const std::string& fn, const Graph& graph); template - GraphWriter graphWriter(const char *fn, const Graph& graph); + GraphWriter graphWriter(const char *fn, const Graph& graph); /// \ingroup lemon_io - /// + /// /// \brief \ref lgf-format "LGF" writer for directed graphs /// /// This utility writes an \ref lgf-format "LGF" file. @@ -926,7 +926,7 @@ typedef _Graph Graph; TEMPLATE_GRAPH_TYPEDEFS(Graph); - + private: @@ -938,21 +938,21 @@ std::string _nodes_caption; std::string _edges_caption; std::string _attributes_caption; - + typedef std::map NodeIndex; NodeIndex _node_index; typedef std::map EdgeIndex; EdgeIndex _edge_index; - typedef std::vector* > > NodeMaps; - NodeMaps _node_maps; + typedef std::vector* > > NodeMaps; + NodeMaps _node_maps; - typedef std::vector* > >EdgeMaps; EdgeMaps _edge_maps; - typedef std::vector > Attributes; Attributes _attributes; @@ -965,60 +965,60 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - GraphWriter(std::ostream& is, const Graph& graph) + GraphWriter(std::ostream& is, const Graph& graph) : _os(&is), local_os(false), _graph(graph), - _skip_nodes(false), _skip_edges(false) {} + _skip_nodes(false), _skip_edges(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const std::string& fn, const Graph& graph) + GraphWriter(const std::string& fn, const Graph& graph) : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), - _skip_nodes(false), _skip_edges(false) {} + _skip_nodes(false), _skip_edges(false) {} /// \brief Constructor /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const char* fn, const Graph& graph) + GraphWriter(const char* fn, const Graph& graph) : _os(new std::ofstream(fn)), local_os(true), _graph(graph), - _skip_nodes(false), _skip_edges(false) {} + _skip_nodes(false), _skip_edges(false) {} /// \brief Destructor ~GraphWriter() { - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - delete it->second; + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + delete it->second; } - for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { - delete it->second; + for (typename EdgeMaps::iterator it = _edge_maps.begin(); + it != _edge_maps.end(); ++it) { + delete it->second; } - for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - delete it->second; + for (typename Attributes::iterator it = _attributes.begin(); + it != _attributes.end(); ++it) { + delete it->second; } if (local_os) { - delete _os; + delete _os; } } - + private: - friend GraphWriter graphWriter<>(std::ostream& os, - const Graph& graph); - friend GraphWriter graphWriter<>(const std::string& fn, - const Graph& graph); - friend GraphWriter graphWriter<>(const char *fn, - const Graph& graph); + friend GraphWriter graphWriter<>(std::ostream& os, + const Graph& graph); + friend GraphWriter graphWriter<>(const std::string& fn, + const Graph& graph); + friend GraphWriter graphWriter<>(const char *fn, + const Graph& graph); - GraphWriter(GraphWriter& other) + GraphWriter(GraphWriter& other) : _os(other._os), local_os(other.local_os), _graph(other._graph), - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) { other._os = 0; other.local_os = false; @@ -1041,15 +1041,15 @@ /// \name Writing rules /// @{ - + /// \brief Node map writing rule /// /// Add a node map writing rule to the writer. template GraphWriter& nodeMap(const std::string& caption, const Map& map) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1059,11 +1059,11 @@ /// Add a node map writing rule with specialized converter to the /// writer. template - GraphWriter& nodeMap(const std::string& caption, const Map& map, - const Converter& converter = Converter()) { + GraphWriter& nodeMap(const std::string& caption, const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map, converter); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map, converter); _node_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1074,8 +1074,8 @@ template GraphWriter& edgeMap(const std::string& caption, const Map& map) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map); _edge_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1085,11 +1085,11 @@ /// Add an edge map writing rule with specialized converter to the /// writer. template - GraphWriter& edgeMap(const std::string& caption, const Map& map, - const Converter& converter = Converter()) { + GraphWriter& edgeMap(const std::string& caption, const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _writer_bits::MapStorageBase* storage = - new _writer_bits::MapStorage(map, converter); + _writer_bits::MapStorageBase* storage = + new _writer_bits::MapStorage(map, converter); _edge_maps.push_back(std::make_pair(caption, storage)); return *this; } @@ -1100,11 +1100,11 @@ template GraphWriter& arcMap(const std::string& caption, const Map& map) { checkConcept, Map>(); - _writer_bits::MapStorageBase* forward_storage = - new _writer_bits::GraphArcMapStorage(_graph, map); + _writer_bits::MapStorageBase* forward_storage = + new _writer_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); - _writer_bits::MapStorageBase* backward_storage = - new _writer_bits::GraphArcMapStorage(_graph, map); + _writer_bits::MapStorageBase* backward_storage = + new _writer_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; } @@ -1114,16 +1114,16 @@ /// Add an arc map writing rule with specialized converter to the /// writer. template - GraphWriter& arcMap(const std::string& caption, const Map& map, - const Converter& converter = Converter()) { + GraphWriter& arcMap(const std::string& caption, const Map& map, + const Converter& converter = Converter()) { checkConcept, Map>(); - _writer_bits::MapStorageBase* forward_storage = - new _writer_bits::GraphArcMapStorage - (_graph, map, converter); + _writer_bits::MapStorageBase* forward_storage = + new _writer_bits::GraphArcMapStorage + (_graph, map, converter); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); - _writer_bits::MapStorageBase* backward_storage = - new _writer_bits::GraphArcMapStorage - (_graph, map, converter); + _writer_bits::MapStorageBase* backward_storage = + new _writer_bits::GraphArcMapStorage + (_graph, map, converter); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; } @@ -1133,8 +1133,8 @@ /// Add an attribute writing rule to the writer. template GraphWriter& attribute(const std::string& caption, const Value& value) { - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(value); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(value); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -1144,10 +1144,10 @@ /// Add an attribute writing rule with specialized converter to the /// writer. template - GraphWriter& attribute(const std::string& caption, const Value& value, - const Converter& converter = Converter()) { - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(value, converter); + GraphWriter& attribute(const std::string& caption, const Value& value, + const Converter& converter = Converter()) { + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(value, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -1158,8 +1158,8 @@ GraphWriter& node(const std::string& caption, const Node& node) { typedef _writer_bits::MapLookUpConverter Converter; Converter converter(_node_index); - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(node, converter); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(node, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -1170,8 +1170,8 @@ GraphWriter& edge(const std::string& caption, const Edge& edge) { typedef _writer_bits::MapLookUpConverter Converter; Converter converter(_edge_index); - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(edge, converter); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(edge, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -1182,8 +1182,8 @@ GraphWriter& arc(const std::string& caption, const Arc& arc) { typedef _writer_bits::GraphArcLookUpConverter Converter; Converter converter(_graph, _edge_index); - _writer_bits::ValueStorageBase* storage = - new _writer_bits::ValueStorage(arc, converter); + _writer_bits::ValueStorageBase* storage = + new _writer_bits::ValueStorage(arc, converter); _attributes.push_back(std::make_pair(caption, storage)); return *this; } @@ -1243,175 +1243,175 @@ void writeNodes() { _writer_bits::MapStorageBase* label = 0; for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { + it != _node_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } *_os << "@nodes"; if (!_nodes_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _nodes_caption); + _writer_bits::writeToken(*_os << ' ', _nodes_caption); } *_os << std::endl; if (label == 0) { - *_os << "label" << '\t'; + *_os << "label" << '\t'; } for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << '\t'; + it != _node_maps.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << '\t'; } *_os << std::endl; std::vector nodes; for (NodeIt n(_graph); n != INVALID; ++n) { - nodes.push_back(n); + nodes.push_back(n); } - + if (label == 0) { - IdMap id_map(_graph); - _writer_bits::MapLess > id_less(id_map); - std::sort(nodes.begin(), nodes.end(), id_less); + IdMap id_map(_graph); + _writer_bits::MapLess > id_less(id_map); + std::sort(nodes.begin(), nodes.end(), id_less); } else { - label->sort(nodes); + label->sort(nodes); } for (int i = 0; i < static_cast(nodes.size()); ++i) { - Node n = nodes[i]; - if (label == 0) { - std::ostringstream os; - os << _graph.id(n); - _writer_bits::writeToken(*_os, os.str()); - *_os << '\t'; - _node_index.insert(std::make_pair(n, os.str())); - } - for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { - std::string value = it->second->get(n); - _writer_bits::writeToken(*_os, value); - if (it->first == "label") { - _node_index.insert(std::make_pair(n, value)); - } - *_os << '\t'; - } - *_os << std::endl; + Node n = nodes[i]; + if (label == 0) { + std::ostringstream os; + os << _graph.id(n); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _node_index.insert(std::make_pair(n, os.str())); + } + for (typename NodeMaps::iterator it = _node_maps.begin(); + it != _node_maps.end(); ++it) { + std::string value = it->second->get(n); + _writer_bits::writeToken(*_os, value); + if (it->first == "label") { + _node_index.insert(std::make_pair(n, value)); + } + *_os << '\t'; + } + *_os << std::endl; } } void createNodeIndex() { _writer_bits::MapStorageBase* label = 0; for (typename NodeMaps::iterator it = _node_maps.begin(); - it != _node_maps.end(); ++it) { + it != _node_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } if (label == 0) { - for (NodeIt n(_graph); n != INVALID; ++n) { - std::ostringstream os; - os << _graph.id(n); - _node_index.insert(std::make_pair(n, os.str())); - } + for (NodeIt n(_graph); n != INVALID; ++n) { + std::ostringstream os; + os << _graph.id(n); + _node_index.insert(std::make_pair(n, os.str())); + } } else { - for (NodeIt n(_graph); n != INVALID; ++n) { - std::string value = label->get(n); - _node_index.insert(std::make_pair(n, value)); - } + for (NodeIt n(_graph); n != INVALID; ++n) { + std::string value = label->get(n); + _node_index.insert(std::make_pair(n, value)); + } } } void writeEdges() { _writer_bits::MapStorageBase* label = 0; for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { + it != _edge_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } *_os << "@edges"; if (!_edges_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _edges_caption); + _writer_bits::writeToken(*_os << ' ', _edges_caption); } *_os << std::endl; *_os << '\t' << '\t'; if (label == 0) { - *_os << "label" << '\t'; + *_os << "label" << '\t'; } for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << '\t'; + it != _edge_maps.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << '\t'; } *_os << std::endl; std::vector edges; for (EdgeIt n(_graph); n != INVALID; ++n) { - edges.push_back(n); + edges.push_back(n); } - + if (label == 0) { - IdMap id_map(_graph); - _writer_bits::MapLess > id_less(id_map); - std::sort(edges.begin(), edges.end(), id_less); + IdMap id_map(_graph); + _writer_bits::MapLess > id_less(id_map); + std::sort(edges.begin(), edges.end(), id_less); } else { - label->sort(edges); + label->sort(edges); } for (int i = 0; i < static_cast(edges.size()); ++i) { - Edge e = edges[i]; - _writer_bits::writeToken(*_os, _node_index. - find(_graph.u(e))->second); - *_os << '\t'; - _writer_bits::writeToken(*_os, _node_index. - find(_graph.v(e))->second); - *_os << '\t'; - if (label == 0) { - std::ostringstream os; - os << _graph.id(e); - _writer_bits::writeToken(*_os, os.str()); - *_os << '\t'; - _edge_index.insert(std::make_pair(e, os.str())); - } - for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { - std::string value = it->second->get(e); - _writer_bits::writeToken(*_os, value); - if (it->first == "label") { - _edge_index.insert(std::make_pair(e, value)); - } - *_os << '\t'; - } - *_os << std::endl; + Edge e = edges[i]; + _writer_bits::writeToken(*_os, _node_index. + find(_graph.u(e))->second); + *_os << '\t'; + _writer_bits::writeToken(*_os, _node_index. + find(_graph.v(e))->second); + *_os << '\t'; + if (label == 0) { + std::ostringstream os; + os << _graph.id(e); + _writer_bits::writeToken(*_os, os.str()); + *_os << '\t'; + _edge_index.insert(std::make_pair(e, os.str())); + } + for (typename EdgeMaps::iterator it = _edge_maps.begin(); + it != _edge_maps.end(); ++it) { + std::string value = it->second->get(e); + _writer_bits::writeToken(*_os, value); + if (it->first == "label") { + _edge_index.insert(std::make_pair(e, value)); + } + *_os << '\t'; + } + *_os << std::endl; } } void createEdgeIndex() { _writer_bits::MapStorageBase* label = 0; for (typename EdgeMaps::iterator it = _edge_maps.begin(); - it != _edge_maps.end(); ++it) { + it != _edge_maps.end(); ++it) { if (it->first == "label") { - label = it->second; - break; - } + label = it->second; + break; + } } if (label == 0) { - for (EdgeIt e(_graph); e != INVALID; ++e) { - std::ostringstream os; - os << _graph.id(e); - _edge_index.insert(std::make_pair(e, os.str())); - } + for (EdgeIt e(_graph); e != INVALID; ++e) { + std::ostringstream os; + os << _graph.id(e); + _edge_index.insert(std::make_pair(e, os.str())); + } } else { - for (EdgeIt e(_graph); e != INVALID; ++e) { - std::string value = label->get(e); - _edge_index.insert(std::make_pair(e, value)); - } + for (EdgeIt e(_graph); e != INVALID; ++e) { + std::string value = label->get(e); + _edge_index.insert(std::make_pair(e, value)); + } } } @@ -1419,20 +1419,20 @@ if (_attributes.empty()) return; *_os << "@attributes"; if (!_attributes_caption.empty()) { - _writer_bits::writeToken(*_os << ' ', _attributes_caption); + _writer_bits::writeToken(*_os << ' ', _attributes_caption); } *_os << std::endl; for (typename Attributes::iterator it = _attributes.begin(); - it != _attributes.end(); ++it) { - _writer_bits::writeToken(*_os, it->first) << ' '; - _writer_bits::writeToken(*_os, it->second->get()); - *_os << std::endl; + it != _attributes.end(); ++it) { + _writer_bits::writeToken(*_os, it->first) << ' '; + _writer_bits::writeToken(*_os, it->second->get()); + *_os << std::endl; } } - + public: - - /// \name Execution of the writer + + /// \name Execution of the writer /// @{ /// \brief Start the batch processing @@ -1440,14 +1440,14 @@ /// This function starts the batch processing. void run() { if (!_skip_nodes) { - writeNodes(); + writeNodes(); } else { - createNodeIndex(); + createNodeIndex(); } - if (!_skip_edges) { - writeEdges(); + if (!_skip_edges) { + writeEdges(); } else { - createEdgeIndex(); + createEdgeIndex(); } writeAttributes(); } @@ -1463,7 +1463,7 @@ }; /// \brief Return a \ref GraphWriter class - /// + /// /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template @@ -1473,7 +1473,7 @@ } /// \brief Return a \ref GraphWriter class - /// + /// /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template @@ -1483,7 +1483,7 @@ } /// \brief Return a \ref GraphWriter class - /// + /// /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter template diff -r 4317d277ba21 -r 765619b7cbb2 lemon/list_graph.h --- a/lemon/list_graph.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/list_graph.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -37,7 +37,7 @@ int first_in, first_out; int prev, next; }; - + struct ArcT { int target, source; int prev_in, prev_out; @@ -53,11 +53,11 @@ std::vector arcs; int first_free_arc; - + public: - + typedef ListDigraphBase Digraph; - + class Node { friend class ListDigraphBase; protected: @@ -92,17 +92,17 @@ ListDigraphBase() : nodes(), first_node(-1), - first_free_node(-1), arcs(), first_free_arc(-1) {} + first_free_node(-1), arcs(), first_free_arc(-1) {} - - int maxNodeId() const { return nodes.size()-1; } + + int maxNodeId() const { return nodes.size()-1; } int maxArcId() const { return arcs.size()-1; } Node source(Arc e) const { return Node(arcs[e.id].source); } Node target(Arc e) const { return Node(arcs[e.id].target); } - void first(Node& node) const { + void first(Node& node) const { node.id = first_node; } @@ -111,24 +111,24 @@ } - void first(Arc& arc) const { + void first(Arc& arc) const { int n; - for(n = first_node; - n!=-1 && nodes[n].first_in == -1; - n = nodes[n].next) {} + for(n = first_node; + n!=-1 && nodes[n].first_in == -1; + n = nodes[n].next) {} arc.id = (n == -1) ? -1 : nodes[n].first_in; } void next(Arc& arc) const { if (arcs[arc.id].next_in != -1) { - arc.id = arcs[arc.id].next_in; + arc.id = arcs[arc.id].next_in; } else { - int n; - for(n = nodes[arcs[arc.id].target].next; - n!=-1 && nodes[n].first_in == -1; - n = nodes[n].next) {} - arc.id = (n == -1) ? -1 : nodes[n].first_in; - } + int n; + for(n = nodes[arcs[arc.id].target].next; + n!=-1 && nodes[n].first_in == -1; + n = nodes[n].next) {} + arc.id = (n == -1) ? -1 : nodes[n].first_in; + } } void firstOut(Arc &e, const Node& v) const { @@ -145,118 +145,118 @@ e.id=arcs[e.id].next_in; } - + static int id(Node v) { return v.id; } static int id(Arc e) { return e.id; } static Node nodeFromId(int id) { return Node(id);} static Arc arcFromId(int id) { return Arc(id);} - bool valid(Node n) const { - return n.id >= 0 && n.id < static_cast(nodes.size()) && - nodes[n.id].prev != -2; + bool valid(Node n) const { + return n.id >= 0 && n.id < static_cast(nodes.size()) && + nodes[n.id].prev != -2; } - bool valid(Arc a) const { - return a.id >= 0 && a.id < static_cast(arcs.size()) && - arcs[a.id].prev_in != -2; + bool valid(Arc a) const { + return a.id >= 0 && a.id < static_cast(arcs.size()) && + arcs[a.id].prev_in != -2; } - Node addNode() { + Node addNode() { int n; - + if(first_free_node==-1) { - n = nodes.size(); - nodes.push_back(NodeT()); + n = nodes.size(); + nodes.push_back(NodeT()); } else { - n = first_free_node; - first_free_node = nodes[n].next; + n = first_free_node; + first_free_node = nodes[n].next; } - + nodes[n].next = first_node; if(first_node != -1) nodes[first_node].prev = n; first_node = n; nodes[n].prev = -1; - + nodes[n].first_in = nodes[n].first_out = -1; - + return Node(n); } - + Arc addArc(Node u, Node v) { - int n; + int n; if (first_free_arc == -1) { - n = arcs.size(); - arcs.push_back(ArcT()); + n = arcs.size(); + arcs.push_back(ArcT()); } else { - n = first_free_arc; - first_free_arc = arcs[n].next_in; + n = first_free_arc; + first_free_arc = arcs[n].next_in; } - - arcs[n].source = u.id; + + arcs[n].source = u.id; arcs[n].target = v.id; arcs[n].next_out = nodes[u.id].first_out; if(nodes[u.id].first_out != -1) { - arcs[nodes[u.id].first_out].prev_out = n; + arcs[nodes[u.id].first_out].prev_out = n; } - + arcs[n].next_in = nodes[v.id].first_in; if(nodes[v.id].first_in != -1) { - arcs[nodes[v.id].first_in].prev_in = n; + arcs[nodes[v.id].first_in].prev_in = n; } - + arcs[n].prev_in = arcs[n].prev_out = -1; - + nodes[u.id].first_out = nodes[v.id].first_in = n; return Arc(n); } - + void erase(const Node& node) { int n = node.id; - + if(nodes[n].next != -1) { - nodes[nodes[n].next].prev = nodes[n].prev; + nodes[nodes[n].next].prev = nodes[n].prev; } - + if(nodes[n].prev != -1) { - nodes[nodes[n].prev].next = nodes[n].next; + nodes[nodes[n].prev].next = nodes[n].next; } else { - first_node = nodes[n].next; + first_node = nodes[n].next; } - + nodes[n].next = first_free_node; first_free_node = n; nodes[n].prev = -2; } - + void erase(const Arc& arc) { int n = arc.id; - + if(arcs[n].next_in!=-1) { - arcs[arcs[n].next_in].prev_in = arcs[n].prev_in; + arcs[arcs[n].next_in].prev_in = arcs[n].prev_in; } if(arcs[n].prev_in!=-1) { - arcs[arcs[n].prev_in].next_in = arcs[n].next_in; + arcs[arcs[n].prev_in].next_in = arcs[n].next_in; } else { - nodes[arcs[n].target].first_in = arcs[n].next_in; + nodes[arcs[n].target].first_in = arcs[n].next_in; } - + if(arcs[n].next_out!=-1) { - arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; - } + arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; + } if(arcs[n].prev_out!=-1) { - arcs[arcs[n].prev_out].next_out = arcs[n].next_out; + arcs[arcs[n].prev_out].next_out = arcs[n].next_out; } else { - nodes[arcs[n].source].first_out = arcs[n].next_out; + nodes[arcs[n].source].first_out = arcs[n].next_out; } - + arcs[n].next_in = first_free_arc; first_free_arc = n; arcs[n].prev_in = -2; @@ -269,30 +269,30 @@ } protected: - void changeTarget(Arc e, Node n) + void changeTarget(Arc e, Node n) { if(arcs[e.id].next_in != -1) - arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; + arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; if(arcs[e.id].prev_in != -1) - arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; + arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in; if (nodes[n.id].first_in != -1) { - arcs[nodes[n.id].first_in].prev_in = e.id; + arcs[nodes[n.id].first_in].prev_in = e.id; } arcs[e.id].target = n.id; arcs[e.id].prev_in = -1; arcs[e.id].next_in = nodes[n.id].first_in; nodes[n.id].first_in = e.id; } - void changeSource(Arc e, Node n) + void changeSource(Arc e, Node n) { if(arcs[e.id].next_out != -1) - arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; + arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; if(arcs[e.id].prev_out != -1) - arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; + arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out; if (nodes[n.id].first_out != -1) { - arcs[nodes[n.id].first_out].prev_out = e.id; + arcs[nodes[n.id].first_out].prev_out = e.id; } arcs[e.id].source = n.id; arcs[e.id].prev_out = -1; @@ -307,11 +307,11 @@ /// \addtogroup graphs /// @{ - ///A general directed graph structure. + ///A general directed graph structure. - ///\ref ListDigraph is a simple and fast directed graph - ///implementation based on static linked lists that are stored in - ///\c std::vector structures. + ///\ref ListDigraph is a simple and fast directed graph + ///implementation based on static linked lists that are stored in + ///\c std::vector structures. /// ///It conforms to the \ref concepts::Digraph "Digraph concept" and it ///also provides several useful additional functionalities. @@ -326,7 +326,7 @@ class ListDigraph : public ExtendedListDigraphBase { private: ///ListDigraph is \e not copy constructible. Use copyDigraph() instead. - + ///ListDigraph is \e not copy constructible. Use copyDigraph() instead. /// ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {}; @@ -341,30 +341,30 @@ typedef ExtendedListDigraphBase Parent; /// Constructor - + /// Constructor. /// ListDigraph() {} ///Add a new node to the digraph. - + ///Add a new node to the digraph. ///\return the new node. Node addNode() { return Parent::addNode(); } ///Add a new arc to the digraph. - + ///Add a new arc to the digraph with source node \c s ///and target node \c t. ///\return the new arc. - Arc addArc(const Node& s, const Node& t) { - return Parent::addArc(s, t); + Arc addArc(const Node& s, const Node& t) { + return Parent::addArc(s, t); } /// Node validity check /// This function gives back true if the given node is valid, - /// ie. it is a real node of the graph. + /// ie. it is a real node of the graph. /// /// \warning A Node pointing to a removed item /// could become valid again later if new nodes are @@ -374,7 +374,7 @@ /// Arc validity check /// This function gives back true if the given arc is valid, - /// ie. it is a real arc of the graph. + /// ie. it is a real arc of the graph. /// /// \warning An Arc pointing to a removed item /// could become valid again later if new nodes are @@ -391,8 +391,8 @@ /// ///\warning This functionality cannot be used together with the Snapshot ///feature. - void changeTarget(Arc e, Node n) { - Parent::changeTarget(e,n); + void changeTarget(Arc e, Node n) { + Parent::changeTarget(e,n); } /// Change the source of \c e to \c n @@ -404,7 +404,7 @@ /// ///\warning This functionality cannot be used together with the Snapshot ///feature. - void changeSource(Arc e, Node n) { + void changeSource(Arc e, Node n) { Parent::changeSource(e,n); } @@ -456,21 +456,21 @@ /// ///\warning This functionality cannot be used together with the Snapshot ///feature. - void contract(Node a, Node b, bool r = true) + void contract(Node a, Node b, bool r = true) { for(OutArcIt e(*this,b);e!=INVALID;) { - OutArcIt f=e; - ++f; - if(r && target(e)==a) erase(e); - else changeSource(e,a); - e=f; + OutArcIt f=e; + ++f; + if(r && target(e)==a) erase(e); + else changeSource(e,a); + e=f; } for(InArcIt e(*this,b);e!=INVALID;) { - InArcIt f=e; - ++f; - if(r && source(e)==a) erase(e); - else changeTarget(e,a); - e=f; + InArcIt f=e; + ++f; + if(r && source(e)==a) erase(e); + else changeTarget(e,a); + e=f; } erase(b); } @@ -485,7 +485,7 @@ /// ///\note The ArcIts referencing a moved arc remain ///valid. However InArcIts and OutArcIts may - ///be invalidated. + ///be invalidated. /// ///\warning This functionality cannot be used together with the ///Snapshot feature. @@ -494,15 +494,15 @@ Node split(Node n, bool connect = true) { Node b = addNode(); for(OutArcIt e(*this,n);e!=INVALID;) { - OutArcIt f=e; - ++f; - changeSource(e,b); - e=f; + OutArcIt f=e; + ++f; + changeSource(e,b); + e=f; } if (connect) addArc(n,b); return b; } - + ///Split an arc. ///This function splits an arc. First a new node \c b is added to @@ -519,7 +519,7 @@ changeTarget(e,b); return b; } - + /// \brief Class to make a snapshot of the digraph and restore /// it later. /// @@ -529,8 +529,8 @@ /// restore() function. /// /// \warning Arc and node deletions and other modifications (e.g. - /// contracting, splitting, reversing arcs or nodes) cannot be - /// restored. These events invalidate the snapshot. + /// contracting, splitting, reversing arcs or nodes) cannot be + /// restored. These events invalidate the snapshot. class Snapshot { protected: @@ -545,9 +545,9 @@ using NodeNotifier::ObserverBase::attach; using NodeNotifier::ObserverBase::detach; using NodeNotifier::ObserverBase::attached; - + protected: - + virtual void add(const Node& node) { snapshot.addNode(node); } @@ -567,7 +567,7 @@ virtual void build() { Node node; std::vector nodes; - for (notifier()->first(node); node != INVALID; + for (notifier()->first(node); node != INVALID; notifier()->next(node)) { nodes.push_back(node); } @@ -577,7 +577,7 @@ } virtual void clear() { Node node; - for (notifier()->first(node); node != INVALID; + for (notifier()->first(node); node != INVALID; notifier()->next(node)) { snapshot.eraseNode(node); } @@ -595,7 +595,7 @@ using ArcNotifier::ObserverBase::attach; using ArcNotifier::ObserverBase::detach; using ArcNotifier::ObserverBase::attached; - + protected: virtual void add(const Arc& arc) { @@ -617,7 +617,7 @@ virtual void build() { Arc arc; std::vector arcs; - for (notifier()->first(arc); arc != INVALID; + for (notifier()->first(arc); arc != INVALID; notifier()->next(arc)) { arcs.push_back(arc); } @@ -627,7 +627,7 @@ } virtual void clear() { Arc arc; - for (notifier()->first(arc); arc != INVALID; + for (notifier()->first(arc); arc != INVALID; notifier()->next(arc)) { snapshot.eraseArc(arc); } @@ -635,7 +635,7 @@ Snapshot& snapshot; }; - + ListDigraph *digraph; NodeObserverProxy node_observer_proxy; @@ -646,10 +646,10 @@ void addNode(const Node& node) { - added_nodes.push_front(node); + added_nodes.push_front(node); } void eraseNode(const Node& node) { - std::list::iterator it = + std::list::iterator it = std::find(added_nodes.begin(), added_nodes.end(), node); if (it == added_nodes.end()) { clear(); @@ -661,29 +661,29 @@ } void addArc(const Arc& arc) { - added_arcs.push_front(arc); + added_arcs.push_front(arc); } void eraseArc(const Arc& arc) { - std::list::iterator it = + std::list::iterator it = std::find(added_arcs.begin(), added_arcs.end(), arc); if (it == added_arcs.end()) { clear(); - node_observer_proxy.detach(); + node_observer_proxy.detach(); throw ArcNotifier::ImmediateDetach(); } else { added_arcs.erase(it); - } + } } void attach(ListDigraph &_digraph) { - digraph = &_digraph; - node_observer_proxy.attach(digraph->notifier(Node())); + digraph = &_digraph; + node_observer_proxy.attach(digraph->notifier(Node())); arc_observer_proxy.attach(digraph->notifier(Arc())); } - + void detach() { - node_observer_proxy.detach(); - arc_observer_proxy.detach(); + node_observer_proxy.detach(); + arc_observer_proxy.detach(); } bool attached() const { @@ -692,7 +692,7 @@ void clear() { added_nodes.clear(); - added_arcs.clear(); + added_arcs.clear(); } public: @@ -701,20 +701,20 @@ /// /// Default constructor. /// To actually make a snapshot you must call save(). - Snapshot() - : digraph(0), node_observer_proxy(*this), + Snapshot() + : digraph(0), node_observer_proxy(*this), arc_observer_proxy(*this) {} - + /// \brief Constructor that immediately makes a snapshot. - /// + /// /// This constructor immediately makes a snapshot of the digraph. /// \param _digraph The digraph we make a snapshot of. - Snapshot(ListDigraph &_digraph) - : node_observer_proxy(*this), + Snapshot(ListDigraph &_digraph) + : node_observer_proxy(*this), arc_observer_proxy(*this) { - attach(_digraph); + attach(_digraph); } - + /// \brief Make a snapshot. /// /// Make a snapshot of the digraph. @@ -729,20 +729,20 @@ } attach(_digraph); } - + /// \brief Undo the changes until the last snapshot. - // + // /// Undo the changes until the last snapshot created by save(). void restore() { - detach(); - for(std::list::iterator it = added_arcs.begin(); + detach(); + for(std::list::iterator it = added_arcs.begin(); it != added_arcs.end(); ++it) { - digraph->erase(*it); - } - for(std::list::iterator it = added_nodes.begin(); + digraph->erase(*it); + } + for(std::list::iterator it = added_nodes.begin(); it != added_nodes.end(); ++it) { - digraph->erase(*it); - } + digraph->erase(*it); + } clear(); } @@ -753,7 +753,7 @@ return attached(); } }; - + }; ///@} @@ -766,7 +766,7 @@ int first_out; int prev, next; }; - + struct ArcT { int target; int prev_out, next_out; @@ -781,15 +781,15 @@ std::vector arcs; int first_free_arc; - + public: - + typedef ListGraphBase Digraph; class Node; class Arc; class Edge; - + class Node { friend class ListGraphBase; protected: @@ -841,10 +841,10 @@ ListGraphBase() : nodes(), first_node(-1), - first_free_node(-1), arcs(), first_free_arc(-1) {} + first_free_node(-1), arcs(), first_free_arc(-1) {} - - int maxNodeId() const { return nodes.size()-1; } + + int maxNodeId() const { return nodes.size()-1; } int maxEdgeId() const { return arcs.size() / 2 - 1; } int maxArcId() const { return arcs.size()-1; } @@ -862,7 +862,7 @@ return Arc(e.id * 2 + (d ? 1 : 0)); } - void first(Node& node) const { + void first(Node& node) const { node.id = first_node; } @@ -870,7 +870,7 @@ node.id = nodes[node.id].next; } - void first(Arc& e) const { + void first(Arc& e) const { int n = first_node; while (n != -1 && nodes[n].first_out == -1) { n = nodes[n].next; @@ -880,17 +880,17 @@ void next(Arc& e) const { if (arcs[e.id].next_out != -1) { - e.id = arcs[e.id].next_out; + e.id = arcs[e.id].next_out; } else { - int n = nodes[arcs[e.id ^ 1].target].next; + int n = nodes[arcs[e.id ^ 1].target].next; while(n != -1 && nodes[n].first_out == -1) { n = nodes[n].next; } - e.id = (n == -1) ? -1 : nodes[n].first_out; - } + e.id = (n == -1) ? -1 : nodes[n].first_out; + } } - void first(Edge& e) const { + void first(Edge& e) const { int n = first_node; while (n != -1) { e.id = nodes[n].first_out; @@ -900,7 +900,7 @@ if (e.id != -1) { e.id /= 2; return; - } + } n = nodes[n].next; } e.id = -1; @@ -915,7 +915,7 @@ if (e.id != -1) { e.id /= 2; return; - } + } n = nodes[n].next; while (n != -1) { e.id = nodes[n].first_out; @@ -925,7 +925,7 @@ if (e.id != -1) { e.id /= 2; return; - } + } n = nodes[n].next; } e.id = -1; @@ -967,7 +967,7 @@ d = true; } } - + static int id(Node v) { return v.id; } static int id(Arc e) { return e.id; } static int id(Edge e) { return e.id; } @@ -976,117 +976,117 @@ static Arc arcFromId(int id) { return Arc(id);} static Edge edgeFromId(int id) { return Edge(id);} - bool valid(Node n) const { - return n.id >= 0 && n.id < static_cast(nodes.size()) && - nodes[n.id].prev != -2; + bool valid(Node n) const { + return n.id >= 0 && n.id < static_cast(nodes.size()) && + nodes[n.id].prev != -2; } - bool valid(Arc a) const { - return a.id >= 0 && a.id < static_cast(arcs.size()) && - arcs[a.id].prev_out != -2; + bool valid(Arc a) const { + return a.id >= 0 && a.id < static_cast(arcs.size()) && + arcs[a.id].prev_out != -2; } - bool valid(Edge e) const { - return e.id >= 0 && 2 * e.id < static_cast(arcs.size()) && - arcs[2 * e.id].prev_out != -2; + bool valid(Edge e) const { + return e.id >= 0 && 2 * e.id < static_cast(arcs.size()) && + arcs[2 * e.id].prev_out != -2; } - Node addNode() { + Node addNode() { int n; - + if(first_free_node==-1) { - n = nodes.size(); - nodes.push_back(NodeT()); + n = nodes.size(); + nodes.push_back(NodeT()); } else { - n = first_free_node; - first_free_node = nodes[n].next; + n = first_free_node; + first_free_node = nodes[n].next; } - + nodes[n].next = first_node; if (first_node != -1) nodes[first_node].prev = n; first_node = n; nodes[n].prev = -1; - + nodes[n].first_out = -1; - + return Node(n); } - + Edge addEdge(Node u, Node v) { - int n; + int n; if (first_free_arc == -1) { - n = arcs.size(); - arcs.push_back(ArcT()); - arcs.push_back(ArcT()); + n = arcs.size(); + arcs.push_back(ArcT()); + arcs.push_back(ArcT()); } else { - n = first_free_arc; - first_free_arc = arcs[n].next_out; + n = first_free_arc; + first_free_arc = arcs[n].next_out; } - + arcs[n].target = u.id; arcs[n | 1].target = v.id; arcs[n].next_out = nodes[v.id].first_out; if (nodes[v.id].first_out != -1) { - arcs[nodes[v.id].first_out].prev_out = n; - } + arcs[nodes[v.id].first_out].prev_out = n; + } arcs[n].prev_out = -1; nodes[v.id].first_out = n; - + arcs[n | 1].next_out = nodes[u.id].first_out; if (nodes[u.id].first_out != -1) { - arcs[nodes[u.id].first_out].prev_out = (n | 1); + arcs[nodes[u.id].first_out].prev_out = (n | 1); } - arcs[n | 1].prev_out = -1; + arcs[n | 1].prev_out = -1; nodes[u.id].first_out = (n | 1); return Edge(n / 2); } - + void erase(const Node& node) { int n = node.id; - + if(nodes[n].next != -1) { - nodes[nodes[n].next].prev = nodes[n].prev; + nodes[nodes[n].next].prev = nodes[n].prev; } - + if(nodes[n].prev != -1) { - nodes[nodes[n].prev].next = nodes[n].next; + nodes[nodes[n].prev].next = nodes[n].next; } else { - first_node = nodes[n].next; + first_node = nodes[n].next; } - + nodes[n].next = first_free_node; first_free_node = n; nodes[n].prev = -2; } - + void erase(const Edge& edge) { int n = edge.id * 2; - + if (arcs[n].next_out != -1) { - arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; - } + arcs[arcs[n].next_out].prev_out = arcs[n].prev_out; + } if (arcs[n].prev_out != -1) { - arcs[arcs[n].prev_out].next_out = arcs[n].next_out; + arcs[arcs[n].prev_out].next_out = arcs[n].next_out; } else { - nodes[arcs[n | 1].target].first_out = arcs[n].next_out; + nodes[arcs[n | 1].target].first_out = arcs[n].next_out; } if (arcs[n | 1].next_out != -1) { - arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out; - } + arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out; + } if (arcs[n | 1].prev_out != -1) { - arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out; + arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out; } else { - nodes[arcs[n].target].first_out = arcs[n | 1].next_out; + nodes[arcs[n].target].first_out = arcs[n | 1].next_out; } - + arcs[n].next_out = first_free_arc; - first_free_arc = n; + first_free_arc = n; arcs[n].prev_out = -2; arcs[n | 1].prev_out = -2; @@ -1102,18 +1102,18 @@ void changeTarget(Edge e, Node n) { if(arcs[2 * e.id].next_out != -1) { - arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; + arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out; } if(arcs[2 * e.id].prev_out != -1) { - arcs[arcs[2 * e.id].prev_out].next_out = + arcs[arcs[2 * e.id].prev_out].next_out = arcs[2 * e.id].next_out; } else { - nodes[arcs[(2 * e.id) | 1].target].first_out = + nodes[arcs[(2 * e.id) | 1].target].first_out = arcs[2 * e.id].next_out; } if (nodes[n.id].first_out != -1) { - arcs[nodes[n.id].first_out].prev_out = 2 * e.id; + arcs[nodes[n.id].first_out].prev_out = 2 * e.id; } arcs[(2 * e.id) | 1].target = n.id; arcs[2 * e.id].prev_out = -1; @@ -1123,19 +1123,19 @@ void changeSource(Edge e, Node n) { if(arcs[(2 * e.id) | 1].next_out != -1) { - arcs[arcs[(2 * e.id) | 1].next_out].prev_out = + arcs[arcs[(2 * e.id) | 1].next_out].prev_out = arcs[(2 * e.id) | 1].prev_out; } if(arcs[(2 * e.id) | 1].prev_out != -1) { - arcs[arcs[(2 * e.id) | 1].prev_out].next_out = + arcs[arcs[(2 * e.id) | 1].prev_out].next_out = arcs[(2 * e.id) | 1].next_out; } else { - nodes[arcs[2 * e.id].target].first_out = + nodes[arcs[2 * e.id].target].first_out = arcs[(2 * e.id) | 1].next_out; } if (nodes[n.id].first_out != -1) { - arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); + arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); } arcs[2 * e.id].target = n.id; arcs[(2 * e.id) | 1].prev_out = -1; @@ -1153,9 +1153,9 @@ ///A general undirected graph structure. - ///\ref ListGraph is a simple and fast undirected graph - ///implementation based on static linked lists that are stored in - ///\c std::vector structures. + ///\ref ListGraph is a simple and fast undirected graph + ///implementation based on static linked lists that are stored in + ///\c std::vector structures. /// ///It conforms to the \ref concepts::Graph "Graph concept" and it ///also provides several useful additional functionalities. @@ -1182,7 +1182,7 @@ void operator=(const ListGraph &) {} public: /// Constructor - + /// Constructor. /// ListGraph() {} @@ -1202,13 +1202,13 @@ /// Add a new edge to the graph with source node \c s /// and target node \c t. /// \return the new edge. - Edge addEdge(const Node& s, const Node& t) { - return Parent::addEdge(s, t); + Edge addEdge(const Node& s, const Node& t) { + return Parent::addEdge(s, t); } /// Node validity check /// This function gives back true if the given node is valid, - /// ie. it is a real node of the graph. + /// ie. it is a real node of the graph. /// /// \warning A Node pointing to a removed item /// could become valid again later if new nodes are @@ -1217,7 +1217,7 @@ /// Arc validity check /// This function gives back true if the given arc is valid, - /// ie. it is a real arc of the graph. + /// ie. it is a real arc of the graph. /// /// \warning An Arc pointing to a removed item /// could become valid again later if new edges are @@ -1226,7 +1226,7 @@ /// Edge validity check /// This function gives back true if the given edge is valid, - /// ie. it is a real arc of the graph. + /// ie. it is a real arc of the graph. /// /// \warning A Edge pointing to a removed item /// could become valid again later if new edges are @@ -1242,9 +1242,9 @@ /// ///\warning This functionality cannot be used together with the ///Snapshot feature. - void changeSource(Edge e, Node n) { - Parent::changeSource(e,n); - } + void changeSource(Edge e, Node n) { + Parent::changeSource(e,n); + } /// \brief Change the target of \c e to \c n /// /// This function changes the target of \c e to \c n. @@ -1254,12 +1254,12 @@ /// ///\warning This functionality cannot be used together with the ///Snapshot feature. - void changeTarget(Edge e, Node n) { - Parent::changeTarget(e,n); + void changeTarget(Edge e, Node n) { + Parent::changeTarget(e,n); } /// \brief Change the source of \c e to \c n /// - /// This function changes the source of \c e to \c n. + /// This function changes the source of \c e to \c n. /// It also changes the proper node of the represented edge. /// ///\note The ArcIts and InArcIts @@ -1268,16 +1268,16 @@ /// ///\warning This functionality cannot be used together with the ///Snapshot feature. - void changeSource(Arc e, Node n) { + void changeSource(Arc e, Node n) { if (Parent::direction(e)) { Parent::changeSource(e,n); } else { Parent::changeTarget(e,n); - } + } } /// \brief Change the target of \c e to \c n /// - /// This function changes the target of \c e to \c n. + /// This function changes the target of \c e to \c n. /// It also changes the proper node of the represented edge. /// ///\note The ArcIts and OutArcIts @@ -1286,12 +1286,12 @@ /// ///\warning This functionality cannot be used together with the ///Snapshot feature. - void changeTarget(Arc e, Node n) { + void changeTarget(Arc e, Node n) { if (Parent::direction(e)) { Parent::changeTarget(e,n); } else { Parent::changeSource(e,n); - } + } } /// \brief Contract two nodes. /// @@ -1308,15 +1308,15 @@ ///Snapshot feature. void contract(Node a, Node b, bool r = true) { for(IncEdgeIt e(*this, b); e!=INVALID;) { - IncEdgeIt f = e; ++f; - if (r && runningNode(e) == a) { - erase(e); - } else if (source(e) == b) { - changeSource(e, a); - } else { - changeTarget(e, a); - } - e = f; + IncEdgeIt f = e; ++f; + if (r && runningNode(e) == a) { + erase(e); + } else if (source(e) == b) { + changeSource(e, a); + } else { + changeTarget(e, a); + } + e = f; } erase(b); } @@ -1331,7 +1331,7 @@ /// using the restore() function. /// /// \warning Edge and node deletions and other modifications - /// (e.g. changing nodes of edges, contracting nodes) cannot be + /// (e.g. changing nodes of edges, contracting nodes) cannot be /// restored. These events invalidate the snapshot. class Snapshot { protected: @@ -1347,9 +1347,9 @@ using NodeNotifier::ObserverBase::attach; using NodeNotifier::ObserverBase::detach; using NodeNotifier::ObserverBase::attached; - + protected: - + virtual void add(const Node& node) { snapshot.addNode(node); } @@ -1369,7 +1369,7 @@ virtual void build() { Node node; std::vector nodes; - for (notifier()->first(node); node != INVALID; + for (notifier()->first(node); node != INVALID; notifier()->next(node)) { nodes.push_back(node); } @@ -1379,7 +1379,7 @@ } virtual void clear() { Node node; - for (notifier()->first(node); node != INVALID; + for (notifier()->first(node); node != INVALID; notifier()->next(node)) { snapshot.eraseNode(node); } @@ -1397,7 +1397,7 @@ using EdgeNotifier::ObserverBase::attach; using EdgeNotifier::ObserverBase::detach; using EdgeNotifier::ObserverBase::attached; - + protected: virtual void add(const Edge& edge) { @@ -1419,7 +1419,7 @@ virtual void build() { Edge edge; std::vector edges; - for (notifier()->first(edge); edge != INVALID; + for (notifier()->first(edge); edge != INVALID; notifier()->next(edge)) { edges.push_back(edge); } @@ -1429,7 +1429,7 @@ } virtual void clear() { Edge edge; - for (notifier()->first(edge); edge != INVALID; + for (notifier()->first(edge); edge != INVALID; notifier()->next(edge)) { snapshot.eraseEdge(edge); } @@ -1448,10 +1448,10 @@ void addNode(const Node& node) { - added_nodes.push_front(node); + added_nodes.push_front(node); } void eraseNode(const Node& node) { - std::list::iterator it = + std::list::iterator it = std::find(added_nodes.begin(), added_nodes.end(), node); if (it == added_nodes.end()) { clear(); @@ -1463,10 +1463,10 @@ } void addEdge(const Edge& edge) { - added_edges.push_front(edge); + added_edges.push_front(edge); } void eraseEdge(const Edge& edge) { - std::list::iterator it = + std::list::iterator it = std::find(added_edges.begin(), added_edges.end(), edge); if (it == added_edges.end()) { clear(); @@ -1478,14 +1478,14 @@ } void attach(ListGraph &_graph) { - graph = &_graph; - node_observer_proxy.attach(graph->notifier(Node())); + graph = &_graph; + node_observer_proxy.attach(graph->notifier(Node())); edge_observer_proxy.attach(graph->notifier(Edge())); } - + void detach() { - node_observer_proxy.detach(); - edge_observer_proxy.detach(); + node_observer_proxy.detach(); + edge_observer_proxy.detach(); } bool attached() const { @@ -1494,7 +1494,7 @@ void clear() { added_nodes.clear(); - added_edges.clear(); + added_edges.clear(); } public: @@ -1503,20 +1503,20 @@ /// /// Default constructor. /// To actually make a snapshot you must call save(). - Snapshot() - : graph(0), node_observer_proxy(*this), + Snapshot() + : graph(0), node_observer_proxy(*this), edge_observer_proxy(*this) {} - + /// \brief Constructor that immediately makes a snapshot. - /// + /// /// This constructor immediately makes a snapshot of the graph. /// \param _graph The graph we make a snapshot of. - Snapshot(ListGraph &_graph) - : node_observer_proxy(*this), + Snapshot(ListGraph &_graph) + : node_observer_proxy(*this), edge_observer_proxy(*this) { - attach(_graph); + attach(_graph); } - + /// \brief Make a snapshot. /// /// Make a snapshot of the graph. @@ -1531,20 +1531,20 @@ } attach(_graph); } - + /// \brief Undo the changes until the last snapshot. - // + // /// Undo the changes until the last snapshot created by save(). void restore() { - detach(); - for(std::list::iterator it = added_edges.begin(); + detach(); + for(std::list::iterator it = added_edges.begin(); it != added_edges.end(); ++it) { - graph->erase(*it); - } - for(std::list::iterator it = added_nodes.begin(); + graph->erase(*it); + } + for(std::list::iterator it = added_nodes.begin(); it != added_nodes.end(); ++it) { - graph->erase(*it); - } + graph->erase(*it); + } clear(); } @@ -1556,9 +1556,9 @@ } }; }; - - /// @} + + /// @} } //namespace lemon - + #endif diff -r 4317d277ba21 -r 765619b7cbb2 lemon/maps.h --- a/lemon/maps.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/maps.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -404,27 +404,27 @@ Reference operator[](const Key &k) { typename Map::iterator it = _map.lower_bound(k); if (it != _map.end() && !_map.key_comp()(k, it->first)) - return it->second; + return it->second; else - return _map.insert(it, std::make_pair(k, _value))->second; + return _map.insert(it, std::make_pair(k, _value))->second; } ///\e ConstReference operator[](const Key &k) const { typename Map::const_iterator it = _map.find(k); if (it != _map.end()) - return it->second; + return it->second; else - return _value; + return _value; } ///\e void set(const Key &k, const Value &v) { typename Map::iterator it = _map.lower_bound(k); if (it != _map.end() && !_map.key_comp()(k, it->first)) - it->second = v; + it->second = v; else - _map.insert(it, std::make_pair(k, v)); + _map.insert(it, std::make_pair(k, v)); } ///\e @@ -544,7 +544,7 @@ /// /// \todo Check the requirements. template + typename V = typename F::result_type> class CombineMap : public MapBase { const M1 &_m1; const M2 &_m2; @@ -615,8 +615,8 @@ /// /// \sa MapToFunctor template + typename K = typename F::argument_type, + typename V = typename F::result_type> class FunctorToMap : public MapBase { F _f; public: @@ -1317,7 +1317,7 @@ } /// @} - + // Logical maps and map adaptors: /// \addtogroup maps @@ -1715,7 +1715,7 @@ template #else template ::Value> + typename Ke=typename _maps_bits::IteratorTraits::Value> #endif class LoggerBoolMap { public: @@ -1741,7 +1741,7 @@ /// The set function of the map void set(const Key& key, Value value) { if (value) { - *_end++ = key; + *_end++ = key; } } @@ -1749,7 +1749,7 @@ Iterator _begin; Iterator _end; }; - + /// Returns a \ref LoggerBoolMap class /// This function just returns a \ref LoggerBoolMap class. diff -r 4317d277ba21 -r 765619b7cbb2 lemon/math.h --- a/lemon/math.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/math.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -33,7 +33,7 @@ /// \addtogroup misc /// @{ - + /// The Euler constant const long double E = 2.7182818284590452353602874713526625L; /// log_2(e) @@ -54,7 +54,7 @@ const long double SQRT2 = 1.4142135623730950488016887242096981L; /// 1/sqrt(2) const long double SQRT1_2 = 0.7071067811865475244008443621048490L; - + /// @} diff -r 4317d277ba21 -r 765619b7cbb2 lemon/path.h --- a/lemon/path.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/path.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -93,12 +93,12 @@ /// \brief Invalid constructor ArcIt(Invalid) : path(0), idx(-1) {} /// \brief Initializate the iterator to the first arc of path - ArcIt(const Path &_path) + ArcIt(const Path &_path) : path(&_path), idx(_path.empty() ? -1 : 0) {} private: - ArcIt(const Path &_path, int _idx) + ArcIt(const Path &_path, int _idx) : path(&_path), idx(_idx) {} public: @@ -109,10 +109,10 @@ } /// \brief Next arc - ArcIt& operator++() { + ArcIt& operator++() { ++idx; - if (idx >= path->length()) idx = -1; - return *this; + if (idx >= path->length()) idx = -1; + return *this; } /// \brief Comparison operator @@ -284,13 +284,13 @@ /// Invalid constructor ArcIt(Invalid) : path(0), idx(-1) {} /// \brief Initializate the constructor to the first arc of path - ArcIt(const SimplePath &_path) + ArcIt(const SimplePath &_path) : path(&_path), idx(_path.empty() ? -1 : 0) {} private: /// Constructor with starting point - ArcIt(const SimplePath &_path, int _idx) + ArcIt(const SimplePath &_path, int _idx) : idx(_idx), path(&_path) {} public: @@ -301,10 +301,10 @@ } /// Next arc - ArcIt& operator++() { + ArcIt& operator++() { ++idx; - if (idx >= path->length()) idx = -1; - return *this; + if (idx >= path->length()) idx = -1; + return *this; } /// Comparison operator @@ -413,7 +413,7 @@ protected: - // the std::list<> is incompatible + // the std::list<> is incompatible // hard to create invalid iterator struct Node { Arc arc; @@ -425,7 +425,7 @@ std::allocator alloc; public: - + /// \brief Default constructor /// /// Default constructor @@ -470,12 +470,12 @@ /// Invalid constructor ArcIt(Invalid) : path(0), node(0) {} /// \brief Initializate the constructor to the first arc of path - ArcIt(const ListPath &_path) + ArcIt(const ListPath &_path) : path(&_path), node(_path.first) {} protected: - ArcIt(const ListPath &_path, Node *_node) + ArcIt(const ListPath &_path, Node *_node) : path(&_path), node(_node) {} @@ -487,9 +487,9 @@ } /// Next arc - ArcIt& operator++() { + ArcIt& operator++() { node = node->next; - return *this; + return *this; } /// Comparison operator @@ -757,7 +757,7 @@ /// /// Default constructor StaticPath() : len(0), arcs(0) {} - + /// \brief Template copy constructor /// /// This path can be initialized from any other path type. @@ -796,13 +796,13 @@ /// Invalid constructor ArcIt(Invalid) : path(0), idx(-1) {} /// Initializate the constructor to the first arc of path - ArcIt(const StaticPath &_path) + ArcIt(const StaticPath &_path) : path(&_path), idx(_path.empty() ? -1 : 0) {} private: /// Constructor with starting point - ArcIt(const StaticPath &_path, int _idx) + ArcIt(const StaticPath &_path, int _idx) : idx(_idx), path(&_path) {} public: @@ -813,10 +813,10 @@ } /// Next arc - ArcIt& operator++() { + ArcIt& operator++() { ++idx; - if (idx >= path->length()) idx = -1; - return *this; + if (idx >= path->length()) idx = -1; + return *this; } /// Comparison operator @@ -909,7 +909,7 @@ template struct RevPathTagIndicator< - Path, + Path, typename enable_if::type > { static const bool value = true; @@ -922,15 +922,15 @@ template struct BuildTagIndicator< - Path, + Path, typename enable_if::type > { static const bool value = true; }; template ::value, - bool revEnable = RevPathTagIndicator::value> + bool buildEnable = BuildTagIndicator::value, + bool revEnable = RevPathTagIndicator::value> struct PathCopySelector { static void copy(Target& target, const Source& source) { target.clear(); @@ -981,8 +981,8 @@ /// \brief Check the consistency of a path. /// /// This function checks that the target of each arc is the same - /// as the source of the next one. - /// + /// as the source of the next one. + /// template bool checkPath(const Digraph& digraph, const Path& path) { typename Path::ArcIt it(path); @@ -1034,19 +1034,19 @@ typedef typename Path::Digraph Digraph; typedef typename Digraph::Node Node; - + /// Default constructor PathNodeIt() {} /// Invalid constructor - PathNodeIt(Invalid) + PathNodeIt(Invalid) : _digraph(0), _it(INVALID), _nd(INVALID) {} /// Constructor - PathNodeIt(const Digraph& digraph, const Path& path) + PathNodeIt(const Digraph& digraph, const Path& path) : _digraph(&digraph), _it(path) { _nd = (_it != INVALID ? _digraph->source(_it) : INVALID); } /// Constructor - PathNodeIt(const Digraph& digraph, const Path& path, const Node& src) + PathNodeIt(const Digraph& digraph, const Path& path, const Node& src) : _digraph(&digraph), _it(path), _nd(src) {} ///Conversion to Digraph::Node @@ -1058,27 +1058,27 @@ PathNodeIt& operator++() { if (_it == INVALID) _nd = INVALID; else { - _nd = _digraph->target(_it); - ++_it; + _nd = _digraph->target(_it); + ++_it; } return *this; } /// Comparison operator - bool operator==(const PathNodeIt& n) const { - return _it == n._it && _nd == n._nd; + bool operator==(const PathNodeIt& n) const { + return _it == n._it && _nd == n._nd; } /// Comparison operator - bool operator!=(const PathNodeIt& n) const { - return _it != n._it || _nd != n._nd; + bool operator!=(const PathNodeIt& n) const { + return _it != n._it || _nd != n._nd; } /// Comparison operator - bool operator<(const PathNodeIt& n) const { + bool operator<(const PathNodeIt& n) const { return (_it < n._it && _nd != INVALID); } - + }; - + ///@} } // namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/random.cc --- a/lemon/random.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/random.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 lemon/random.h --- a/lemon/random.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/random.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -21,9 +21,9 @@ * Generator of Matsumoto and Nishimura. * * See the appropriate copyright notice below. - * + * * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - * All rights reserved. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,8 +36,8 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * 3. The names of its contributors may not be used to endorse or promote - * products derived from this software without specific prior written + * 3. The names of its contributors may not be used to endorse or promote + * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -87,7 +87,7 @@ namespace lemon { namespace _random_bits { - + template ::digits> struct RandomTraits {}; @@ -99,7 +99,7 @@ static const int length = 624; static const int shift = 397; - + static const Word mul = 0x6c078965u; static const Word arrayInit = 0x012BD6AAu; static const Word arrayMul1 = 0x0019660Du; @@ -167,7 +167,7 @@ static const Word seedArray[4] = { 0x12345u, 0x23456u, 0x34567u, 0x45678u }; - + initState(seedArray, seedArray + 4); } @@ -175,7 +175,7 @@ static const Word mul = RandomTraits::mul; - current = state; + current = state; Word *curr = state + length - 1; curr[0] = seed; --curr; @@ -201,7 +201,7 @@ num = length > end - begin ? length : end - begin; while (num--) { - curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1)) + curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1)) + *it + cnt; ++it; ++cnt; if (it == end) { @@ -223,10 +223,10 @@ cnt = 1; } } - + state[length - 1] = Word(1) << (bits - 1); } - + void copyState(const RandomCore& other) { std::copy(other.state, other.state + length, state); current = state + (other.current - other.state); @@ -241,17 +241,17 @@ private: - + void fillState() { static const Word mask[2] = { 0x0ul, RandomTraits::mask }; static const Word loMask = RandomTraits::loMask; static const Word hiMask = RandomTraits::hiMask; - current = state + length; + current = state + length; register Word *curr = state + length - 1; register long num; - + num = length - shift; while (num--) { curr[0] = (((curr[0] & hiMask) | (curr[-1] & loMask)) >> 1) ^ @@ -269,14 +269,14 @@ } - + Word *current; Word state[length]; - + }; - template ::digits + 1) / 2> struct Masker { static Result mask(const Result& result) { @@ -284,7 +284,7 @@ mask(static_cast(result | (result >> shift))); } }; - + template struct Masker { static Result mask(const Result& result) { @@ -292,39 +292,39 @@ } }; - template ::digits, int shift = 0, + template ::digits, int shift = 0, bool last = rest <= std::numeric_limits::digits> struct IntConversion { static const int bits = std::numeric_limits::digits; - + static Result convert(RandomCore& rnd) { return static_cast(rnd() >> (bits - rest)) << shift; } - - }; - template + }; + + template struct IntConversion { static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { - return (static_cast(rnd()) << shift) | + return (static_cast(rnd()) << shift) | IntConversion::convert(rnd); } }; template ::digits < - std::numeric_limits::digits) > + bool one_word = (std::numeric_limits::digits < + std::numeric_limits::digits) > struct Mapping { static Result map(RandomCore& rnd, const Result& bound) { Word max = Word(bound - 1); Result mask = Masker::mask(bound - 1); Result num; do { - num = IntConversion::convert(rnd) & mask; + num = IntConversion::convert(rnd) & mask; } while (num > max); return num; } @@ -350,7 +350,7 @@ Result res = ShiftMultiplier::multiplier(); res *= res; if ((exp & 1) == 1) res *= static_cast(2.0); - return res; + return res; } }; @@ -360,42 +360,42 @@ Result res = ShiftMultiplier::multiplier(); res *= res; if ((exp & 1) == 1) res *= static_cast(0.5); - return res; + return res; } }; template struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0); + return static_cast(1.0); } }; template struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/1048576.0); + return static_cast(1.0/1048576.0); } }; - + template struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/424967296.0); + return static_cast(1.0/424967296.0); } }; template struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/9007199254740992.0); + return static_cast(1.0/9007199254740992.0); } }; template struct ShiftMultiplier { static const Result multiplier() { - return static_cast(1.0/18446744073709551616.0); + return static_cast(1.0/18446744073709551616.0); } }; @@ -407,9 +407,9 @@ }; template ::digits, int shift = 0, + int rest = std::numeric_limits::digits, int shift = 0, bool last = rest <= std::numeric_limits::digits> - struct RealConversion{ + struct RealConversion{ static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { @@ -419,7 +419,7 @@ }; template - struct RealConversion { + struct RealConversion { static const int bits = std::numeric_limits::digits; static Result convert(RandomCore& rnd) { @@ -458,7 +458,7 @@ struct BoolProducer { Word buffer; int num; - + BoolProducer() : num(0) {} bool convert(RandomCore& rnd) { @@ -529,10 +529,10 @@ // Architecture word typedef unsigned long Word; - + _random_bits::RandomCore core; _random_bits::BoolProducer bool_producer; - + public: @@ -554,7 +554,7 @@ /// Constructor with seed. The current number type will be converted /// to the architecture word type. template - Random(Number seed) { + Random(Number seed) { _random_bits::Initializer::init(core, seed); } @@ -564,7 +564,7 @@ /// any number type and the numbers will be converted to the /// architecture word type. template - Random(Iterator begin, Iterator end) { + Random(Iterator begin, Iterator end) { typedef typename std::iterator_traits::value_type Number; _random_bits::Initializer::init(core, begin, end); } @@ -597,7 +597,7 @@ /// Seeding the random sequence. The current number type will be /// converted to the architecture word type. template - void seed(Number seed) { + void seed(Number seed) { _random_bits::Initializer::init(core, seed); } @@ -607,7 +607,7 @@ /// any number type and the numbers will be converted to the /// architecture word type. template - void seed(Iterator begin, Iterator end) { + void seed(Iterator begin, Iterator end) { typedef typename std::iterator_traits::value_type Number; _random_bits::Initializer::init(core, begin, end); } @@ -625,7 +625,7 @@ if (seedFromTime()) return true; return false; } - + /// \brief Seeding from file /// /// Seeding the random sequence from file. The linux kernel has two @@ -640,9 +640,9 @@ /// \param offset The offset, from the file read. /// \return True when the seeding successes. #ifndef WIN32 - bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) + bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) #else - bool seedFromFile(const std::string& file = "", int offset = 0) + bool seedFromFile(const std::string& file = "", int offset = 0) #endif { std::ifstream rs(file.c_str()); @@ -660,7 +660,7 @@ /// current process id and the current time for initialize the /// random sequence. /// \return Currently always true. - bool seedFromTime() { + bool seedFromTime() { #ifndef WIN32 timeval tv; gettimeofday(&tv, 0); @@ -696,16 +696,16 @@ /// /// It returns a random real number from the range [0, b). template - Number real(Number b) { - return real() * b; + Number real(Number b) { + return real() * b; } /// \brief Returns a random real number from the range [a, b) /// /// It returns a random real number from the range [a, b). template - Number real(Number a, Number b) { - return real() * (b - a) + a; + Number real(Number a, Number b) { + return real() * (b - a) + a; } /// @} @@ -725,16 +725,16 @@ /// /// It returns a random real number from the range [0, b). template - Number operator()(Number b) { - return real() * b; + Number operator()(Number b) { + return real() * b; } /// \brief Returns a random real number from the range [a, b) /// /// It returns a random real number from the range [a, b). template - Number operator()(Number a, Number b) { - return real() * (b - a) + a; + Number operator()(Number a, Number b) { + return real() * (b - a) + a; } /// \brief Returns a random integer from a range @@ -784,7 +784,7 @@ /// function is \c int. template Number integer() { - static const int nb = std::numeric_limits::digits + + static const int nb = std::numeric_limits::digits + (std::numeric_limits::is_signed ? 1 : 0); return _random_bits::IntConversion::convert(core); } @@ -792,7 +792,7 @@ int integer() { return integer(); } - + /// \brief Returns a random bool /// /// It returns a random bool. The generator holds a buffer for @@ -806,9 +806,9 @@ ///\name Non-uniform distributions /// - + ///@{ - + /// \brief Returns a random bool /// /// It returns a random bool with given probability of true result. @@ -822,13 +822,13 @@ /// \note The Cartesian form of the Box-Muller /// transformation is used to generate a random normal distribution. /// \todo Consider using the "ziggurat" method instead. - double gauss() + double gauss() { double V1,V2,S; do { - V1=2*real()-1; - V2=2*real()-1; - S=V1*V1+V2*V2; + V1=2*real()-1; + V2=2*real()-1; + S=V1*V1+V2*V2; } while(S>=1); return std::sqrt(-2*std::log(S)/S)*V1; } @@ -854,19 +854,19 @@ /// Gamma distribution with given integer shape /// This function generates a gamma distribution random number. - /// + /// ///\param k shape parameter (k>0 integer) - double gamma(int k) + double gamma(int k) { double s = 0; for(int i=0;i()); return s; } - + /// Gamma distribution with given shape and scale parameter /// This function generates a gamma distribution random number. - /// + /// ///\param k shape parameter (k>0) ///\param theta scale parameter /// @@ -876,88 +876,88 @@ const double delta = k-std::floor(k); const double v0=E/(E-delta); do { - double V0=1.0-real(); - double V1=1.0-real(); - double V2=1.0-real(); - if(V2<=v0) - { - xi=std::pow(V1,1.0/delta); - nu=V0*std::pow(xi,delta-1.0); - } - else - { - xi=1.0-std::log(V1); - nu=V0*std::exp(-xi); - } + double V0=1.0-real(); + double V1=1.0-real(); + double V2=1.0-real(); + if(V2<=v0) + { + xi=std::pow(V1,1.0/delta); + nu=V0*std::pow(xi,delta-1.0); + } + else + { + xi=1.0-std::log(V1); + nu=V0*std::exp(-xi); + } } while(nu>std::pow(xi,delta-1.0)*std::exp(-xi)); return theta*(xi+gamma(int(std::floor(k)))); } - + /// Weibull distribution /// This function generates a Weibull distribution random number. - /// + /// ///\param k shape parameter (k>0) ///\param lambda scale parameter (lambda>0) /// double weibull(double k,double lambda) { return lambda*pow(-std::log(1.0-real()),1.0/k); - } - + } + /// Pareto distribution /// This function generates a Pareto distribution random number. - /// + /// ///\param k shape parameter (k>0) ///\param x_min location parameter (x_min>0) /// double pareto(double k,double x_min) { return exponential(gamma(k,1.0/x_min))+x_min; - } - + } + /// Poisson distribution /// This function generates a Poisson distribution random number with /// parameter \c lambda. - /// + /// /// The probability mass function of this distribusion is /// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f] /// \note The algorithm is taken from the book of Donald E. Knuth titled /// ''Seminumerical Algorithms'' (1969). Its running time is linear in the /// return value. - + int poisson(double lambda) { const double l = std::exp(-lambda); int k=0; double p = 1.0; do { - k++; - p*=real(); + k++; + p*=real(); } while (p>=l); return k-1; - } - + } + ///@} - + ///\name Two dimensional distributions /// ///@{ - + /// Uniform distribution on the full unit circle /// Uniform distribution on the full unit circle. /// - dim2::Point disc() + dim2::Point disc() { double V1,V2; do { - V1=2*real()-1; - V2=2*real()-1; - + V1=2*real()-1; + V2=2*real()-1; + } while(V1*V1+V2*V2>=1); return dim2::Point(V1,V2); } @@ -973,9 +973,9 @@ { double V1,V2,S; do { - V1=2*real()-1; - V2=2*real()-1; - S=V1*V1+V2*V2; + V1=2*real()-1; + V2=2*real()-1; + S=V1*V1+V2*V2; } while(S>=1); double W=std::sqrt(-2*std::log(S)/S); return dim2::Point(W*V1,W*V2); @@ -984,22 +984,22 @@ /// This function provides a turning symmetric two-dimensional distribution. /// The x-coordinate is of conditionally exponential distribution - /// with the condition that x is positive and y=0. If x is negative and + /// with the condition that x is positive and y=0. If x is negative and /// y=0 then, -x is of exponential distribution. The same is true for the /// y-coordinate. - dim2::Point exponential2() + dim2::Point exponential2() { double V1,V2,S; do { - V1=2*real()-1; - V2=2*real()-1; - S=V1*V1+V2*V2; + V1=2*real()-1; + V2=2*real()-1; + S=V1*V1+V2*V2; } while(S>=1); double W=-std::log(S)/S; return dim2::Point(W*V1,W*V2); } - ///@} + ///@} }; diff -r 4317d277ba21 -r 765619b7cbb2 lemon/smart_graph.h --- a/lemon/smart_graph.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/smart_graph.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -45,20 +45,20 @@ class SmartDigraphBase { protected: - struct NodeT + struct NodeT { - int first_in, first_out; + int first_in, first_out; NodeT() {} }; - struct ArcT + struct ArcT { - int target, source, next_in, next_out; - ArcT() {} + int target, source, next_in, next_out; + ArcT() {} }; std::vector nodes; std::vector arcs; - + public: typedef SmartDigraphBase Graph; @@ -69,9 +69,9 @@ public: SmartDigraphBase() : nodes(), arcs() { } - SmartDigraphBase(const SmartDigraphBase &_g) + SmartDigraphBase(const SmartDigraphBase &_g) : nodes(_g.nodes), arcs(_g.arcs) { } - + typedef True NodeNumTag; typedef True EdgeNumTag; @@ -82,17 +82,17 @@ int maxArcId() const { return arcs.size()-1; } Node addNode() { - int n = nodes.size(); + int n = nodes.size(); nodes.push_back(NodeT()); nodes[n].first_in = -1; nodes[n].first_out = -1; return Node(n); } - + Arc addArc(Node u, Node v) { - int n = arcs.size(); + int n = arcs.size(); arcs.push_back(ArcT()); - arcs[n].source = u._id; + arcs[n].source = u._id; arcs[n].target = v._id; arcs[n].next_out = nodes[u._id].first_out; arcs[n].next_in = nodes[v._id].first_in; @@ -115,11 +115,11 @@ static Node nodeFromId(int id) { return Node(id);} static Arc arcFromId(int id) { return Arc(id);} - bool valid(Node n) const { - return n._id >= 0 && n._id < static_cast(nodes.size()); + bool valid(Node n) const { + return n._id >= 0 && n._id < static_cast(nodes.size()); } - bool valid(Arc a) const { - return a._id >= 0 && a._id < static_cast(arcs.size()); + bool valid(Arc a) const { + return a._id >= 0 && a._id < static_cast(arcs.size()); } class Node { @@ -136,7 +136,7 @@ bool operator!=(const Node i) const {return _id != i._id;} bool operator<(const Node i) const {return _id < i._id;} }; - + class Arc { friend class SmartDigraphBase; @@ -180,7 +180,7 @@ void firstIn(Arc& arc, const Node& node) const { arc._id = nodes[node._id].first_in; } - + void nextIn(Arc& arc) const { arc._id = arcs[arc._id].next_in; } @@ -222,26 +222,26 @@ void operator=(const SmartDigraph &) {} public: - + /// Constructor - + /// Constructor. /// SmartDigraph() {}; - + ///Add a new node to the digraph. - + /// \return the new node. /// Node addNode() { return Parent::addNode(); } - + ///Add a new arc to the digraph. - + ///Add a new arc to the digraph with source node \c s ///and target node \c t. ///\return the new arc. - Arc addArc(const Node& s, const Node& t) { - return Parent::addArc(s, t); + Arc addArc(const Node& s, const Node& t) { + return Parent::addArc(s, t); } /// \brief Using this it is possible to avoid the superfluous memory @@ -269,7 +269,7 @@ /// \brief Node validity check /// /// This function gives back true if the given node is valid, - /// ie. it is a real node of the graph. + /// ie. it is a real node of the graph. /// /// \warning A removed node (using Snapshot) could become valid again /// when new nodes are added to the graph. @@ -278,14 +278,14 @@ /// \brief Arc validity check /// /// This function gives back true if the given arc is valid, - /// ie. it is a real arc of the graph. + /// ie. it is a real arc of the graph. /// /// \warning A removed arc (using Snapshot) could become valid again /// when new arcs are added to the graph. bool valid(Arc a) const { return Parent::valid(a); } ///Clear the digraph. - + ///Erase all the nodes and arcs from the digraph. /// void clear() { @@ -293,7 +293,7 @@ } ///Split a node. - + ///This function splits a node. First a new node is added to the digraph, ///then the source of each outgoing arc of \c n is moved to this new node. ///If \c connect is \c true (this is the default value), then a new arc @@ -318,7 +318,7 @@ } public: - + class Snapshot; protected: @@ -327,17 +327,17 @@ { while(s.arc_numnodes.size(); - arc_num=_graph->arcs.size(); + node_num=_graph->nodes.size(); + arc_num=_graph->arcs.size(); } ///Make a snapshot. @@ -385,15 +385,15 @@ ///This function can be called more than once. In case of a repeated ///call, the previous snapshot gets lost. ///\param _g The digraph we make the snapshot of. - void save(SmartDigraph &graph) + void save(SmartDigraph &graph) { - _graph=&graph; - node_num=_graph->nodes.size(); - arc_num=_graph->arcs.size(); + _graph=&graph; + node_num=_graph->nodes.size(); + arc_num=_graph->arcs.size(); } ///Undo the changes until a snapshot. - + ///Undo the changes until a snapshot created by save(). /// ///\note After you restored a state, you cannot restore @@ -401,7 +401,7 @@ ///by restore(). void restore() { - _graph->restoreSnapshot(*this); + _graph->restoreSnapshot(*this); } }; }; @@ -414,7 +414,7 @@ struct NodeT { int first_out; }; - + struct ArcT { int target; int next_out; @@ -424,15 +424,15 @@ std::vector arcs; int first_free_arc; - + public: - + typedef SmartGraphBase Digraph; class Node; class Arc; class Edge; - + class Node { friend class SmartGraphBase; protected: @@ -485,8 +485,8 @@ SmartGraphBase() : nodes(), arcs() {} - - int maxNodeId() const { return nodes.size()-1; } + + int maxNodeId() const { return nodes.size()-1; } int maxEdgeId() const { return arcs.size() / 2 - 1; } int maxArcId() const { return arcs.size()-1; } @@ -504,7 +504,7 @@ return Arc(e._id * 2 + (d ? 1 : 0)); } - void first(Node& node) const { + void first(Node& node) const { node._id = nodes.size() - 1; } @@ -512,7 +512,7 @@ --node._id; } - void first(Arc& arc) const { + void first(Arc& arc) const { arc._id = arcs.size() - 1; } @@ -520,7 +520,7 @@ --arc._id; } - void first(Edge& arc) const { + void first(Edge& arc) const { arc._id = arcs.size() / 2 - 1; } @@ -561,10 +561,10 @@ d = ((de & 1) == 1); } else { arc._id = -1; - d = true; + d = true; } } - + static int id(Node v) { return v._id; } static int id(Arc e) { return e._id; } static int id(Edge e) { return e._id; } @@ -573,41 +573,41 @@ static Arc arcFromId(int id) { return Arc(id);} static Edge edgeFromId(int id) { return Edge(id);} - bool valid(Node n) const { - return n._id >= 0 && n._id < static_cast(nodes.size()); + bool valid(Node n) const { + return n._id >= 0 && n._id < static_cast(nodes.size()); } - bool valid(Arc a) const { + bool valid(Arc a) const { return a._id >= 0 && a._id < static_cast(arcs.size()); } - bool valid(Edge e) const { - return e._id >= 0 && 2 * e._id < static_cast(arcs.size()); + bool valid(Edge e) const { + return e._id >= 0 && 2 * e._id < static_cast(arcs.size()); } - Node addNode() { + Node addNode() { int n = nodes.size(); nodes.push_back(NodeT()); nodes[n].first_out = -1; - + return Node(n); } - + Edge addEdge(Node u, Node v) { int n = arcs.size(); arcs.push_back(ArcT()); arcs.push_back(ArcT()); - + arcs[n].target = u._id; arcs[n | 1].target = v._id; arcs[n].next_out = nodes[v._id].first_out; nodes[v._id].first_out = n; - arcs[n | 1].next_out = nodes[u._id].first_out; + arcs[n | 1].next_out = nodes[u._id].first_out; nodes[u._id].first_out = (n | 1); return Edge(n / 2); } - + void clear() { arcs.clear(); nodes.clear(); @@ -625,7 +625,7 @@ /// It is also quite memory efficient, but at the price /// that it does support only limited (only stack-like) /// node and arc deletions. - /// Except from this it conforms to + /// Except from this it conforms to /// the \ref concepts::Graph "Graph concept". /// /// It also has an @@ -655,30 +655,30 @@ typedef ExtendedSmartGraphBase Parent; /// Constructor - + /// Constructor. /// SmartGraph() {} ///Add a new node to the graph. - + /// \return the new node. /// Node addNode() { return Parent::addNode(); } - + ///Add a new edge to the graph. - + ///Add a new edge to the graph with node \c s ///and \c t. ///\return the new edge. - Edge addEdge(const Node& s, const Node& t) { - return Parent::addEdge(s, t); + Edge addEdge(const Node& s, const Node& t) { + return Parent::addEdge(s, t); } /// \brief Node validity check /// /// This function gives back true if the given node is valid, - /// ie. it is a real node of the graph. + /// ie. it is a real node of the graph. /// /// \warning A removed node (using Snapshot) could become valid again /// when new nodes are added to the graph. @@ -687,7 +687,7 @@ /// \brief Arc validity check /// /// This function gives back true if the given arc is valid, - /// ie. it is a real arc of the graph. + /// ie. it is a real arc of the graph. /// /// \warning A removed arc (using Snapshot) could become valid again /// when new edges are added to the graph. @@ -696,14 +696,14 @@ /// \brief Edge validity check /// /// This function gives back true if the given edge is valid, - /// ie. it is a real edge of the graph. + /// ie. it is a real edge of the graph. /// /// \warning A removed edge (using Snapshot) could become valid again /// when new edges are added to the graph. bool valid(Edge e) const { return Parent::valid(e); } ///Clear the graph. - + ///Erase all the nodes and edges from the graph. /// void clear() { @@ -711,7 +711,7 @@ } public: - + class Snapshot; protected: @@ -728,23 +728,23 @@ while(s.arc_num dir; dir.push_back(arcFromId(n)); dir.push_back(arcFromId(n-1)); - Parent::notifier(Arc()).erase(dir); - nodes[arcs[n].target].first_out=arcs[n].next_out; - nodes[arcs[n-1].target].first_out=arcs[n-1].next_out; - arcs.pop_back(); - arcs.pop_back(); + Parent::notifier(Arc()).erase(dir); + nodes[arcs[n].target].first_out=arcs[n].next_out; + nodes[arcs[n-1].target].first_out=arcs[n-1].next_out; + arcs.pop_back(); + arcs.pop_back(); } while(s.node_numWIN32 platform this value is not calculated. + ///\note On WIN32 platform this value is not calculated. /// double cUserTime() const { @@ -213,7 +213,7 @@ } ///Gives back the user time of the process' children - ///\note On WIN32 platform this value is not calculated. + ///\note On WIN32 platform this value is not calculated. /// double cSystemTime() const { @@ -223,11 +223,11 @@ double realTime() const {return rtime;} }; - TimeStamp operator*(double b,const TimeStamp &t) + TimeStamp operator*(double b,const TimeStamp &t) { return t*b; } - + ///Prints the time counters ///Prints the time counters in the following form: @@ -299,10 +299,10 @@ int _running; //Timer is running iff _running>0; (_running>=0 always holds) TimeStamp start_time; //This is the relativ start-time if the timer //is _running, the collected _running time otherwise. - + void _reset() {if(_running) start_time.stamp(); else start_time.reset();} - - public: + + public: ///Constructor. ///\param run indicates whether or not the timer starts immediately. @@ -331,41 +331,41 @@ } ///Start the time counters - + ///This function starts the time counters. /// ///If the timer is started more than ones, it will remain running ///until the same amount of \ref stop() is called. ///\sa stop() - void start() + void start() { if(_running) _running++; else { - _running=1; - TimeStamp t; - t.stamp(); - start_time=t-start_time; + _running=1; + TimeStamp t; + t.stamp(); + start_time=t-start_time; } } - + ///Stop the time counters ///This function stops the time counters. If start() was executed more than ///once, then the same number of stop() execution is necessary the really ///stop the timer. - /// + /// ///\sa halt() ///\sa start() ///\sa restart() ///\sa reset() - void stop() + void stop() { if(_running && !--_running) { - TimeStamp t; - t.stamp(); - start_time=t-start_time; + TimeStamp t; + t.stamp(); + start_time=t-start_time; } } @@ -383,13 +383,13 @@ ///\sa restart() ///\sa reset() - void halt() + void halt() { if(_running) { - _running=0; - TimeStamp t; - t.stamp(); - start_time=t-start_time; + _running=0; + TimeStamp t; + t.stamp(); + start_time=t-start_time; } } @@ -402,19 +402,19 @@ ///(i.e. greater than ///zero). int running() { return _running; } - - + + ///Restart the time counters ///This function is a shorthand for ///a reset() and a start() calls. /// - void restart() + void restart() { reset(); start(); } - + ///@} ///\name Query Functions for the ellapsed time @@ -433,7 +433,7 @@ } ///Gives back the ellapsed user time of the process' children - ///\note On WIN32 platform this value is not calculated. + ///\note On WIN32 platform this value is not calculated. /// double cUserTime() const { @@ -441,7 +441,7 @@ } ///Gives back the ellapsed user time of the process' children - ///\note On WIN32 platform this value is not calculated. + ///\note On WIN32 platform this value is not calculated. /// double cSystemTime() const { @@ -487,7 +487,7 @@ ///\sa Timer ///\sa NoTimeReport ///\todo There is no test case for this - class TimeReport : public Timer + class TimeReport : public Timer { std::string _title; std::ostream &_os; @@ -498,15 +498,15 @@ ///\param os The stream to print the report to. ///\param run Sets whether the timer should start immediately. - TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) + TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) : Timer(run), _title(title), _os(os){} ///\e Prints the ellapsed time on destruction. - ~TimeReport() + ~TimeReport() { _os << _title << *this << std::endl; } }; - + ///'Do nothing' version of \ref TimeReport ///\sa TimeReport @@ -527,7 +527,7 @@ void reset() {} void start() {} void stop() {} - void halt() {} + void halt() {} int running() { return 0; } void restart() {} double userTime() const { return 0; } @@ -536,9 +536,9 @@ double cSystemTime() const { return 0; } double realTime() const { return 0; } }; - + ///Tool to measure the running time more exactly. - + ///This function calls \c f several times and returns the average ///running time. The number of the executions will be choosen in such a way ///that the full real running time will be roughly between \c min_time @@ -550,7 +550,7 @@ ///\retval full_time if it is not \c NULL, then the actual /// total running time will be written into *full_time. ///\return The average running time of \c f. - + template TimeStamp runningTimeTest(F f,double min_time=10,unsigned int *num = NULL, TimeStamp *full_time=NULL) @@ -566,8 +566,8 @@ if(full_time) *full_time=full; return full/total; } - - /// @} + + /// @} } //namespace lemon diff -r 4317d277ba21 -r 765619b7cbb2 lemon/tolerance.h --- a/lemon/tolerance.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/tolerance.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -31,7 +31,7 @@ /// \addtogroup misc /// @{ - + ///\brief A class to provide a basic way to ///handle the comparison of numbers that are obtained ///as a result of a probably inexact computation. @@ -40,8 +40,8 @@ ///handle the comparison of numbers that are obtained ///as a result of a probably inexact computation. /// - ///This is an abstract class, it should be specialized for all - ///numerical data types. These specialized classes like + ///This is an abstract class, it should be specialized for all + ///numerical data types. These specialized classes like ///Tolerance may offer additional tuning parameters. /// ///\sa Tolerance @@ -305,7 +305,7 @@ ///Returns zero static Value zero() {return 0;} }; - + ///Long integer specialization of Tolerance. diff -r 4317d277ba21 -r 765619b7cbb2 lemon/unionfind.h --- a/lemon/unionfind.h Sun Jul 13 16:46:56 2008 +0100 +++ b/lemon/unionfind.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -38,10 +38,10 @@ /// /// \brief A \e Union-Find data structure implementation /// - /// The class implements the \e Union-Find data structure. + /// The class implements the \e Union-Find data structure. /// The union operation uses rank heuristic, while /// the find operation uses path compression. - /// This is a very simple but efficient implementation, providing + /// This is a very simple but efficient implementation, providing /// only four methods: join (union), find, insert and size. /// For more features see the \ref UnionFindEnum class. /// @@ -50,7 +50,7 @@ /// \sa kruskal() /// /// \pre You need to add all the elements by the \ref insert() - /// method. + /// method. template class UnionFind { public: @@ -111,7 +111,7 @@ /// \brief Inserts a new element into the structure. /// - /// This method inserts a new element into the data structure. + /// This method inserts a new element into the data structure. /// /// The method returns the index of the new component. int insert(const Item& a) { @@ -123,7 +123,7 @@ /// \brief Joining the components of element \e a and element \e b. /// - /// This is the \e union operation of the Union-Find structure. + /// This is the \e union operation of the Union-Find structure. /// Joins the component of element \e a and component of /// element \e b. If \e a and \e b are in the same component then /// it returns false otherwise it returns true. @@ -131,15 +131,15 @@ int ka = repIndex(index[a]); int kb = repIndex(index[b]); - if ( ka == kb ) - return false; + if ( ka == kb ) + return false; if (items[ka] < items[kb]) { - items[ka] += items[kb]; - items[kb] = ka; + items[ka] += items[kb]; + items[kb] = ka; } else { - items[kb] += items[ka]; - items[ka] = kb; + items[kb] += items[ka]; + items[ka] = kb; } return true; } @@ -173,12 +173,12 @@ template class UnionFindEnum { public: - + typedef _ItemIntMap ItemIntMap; typedef typename ItemIntMap::Key Item; private: - + ItemIntMap& index; // If the parent stores negative value for an item then that item @@ -202,31 +202,31 @@ int firstItem; int next, prev; }; - + std::vector classes; int firstClass, firstFreeClass; int newClass() { if (firstFreeClass == -1) { - int cdx = classes.size(); - classes.push_back(ClassT()); - return cdx; + int cdx = classes.size(); + classes.push_back(ClassT()); + return cdx; } else { - int cdx = firstFreeClass; - firstFreeClass = classes[firstFreeClass].next; - return cdx; + int cdx = firstFreeClass; + firstFreeClass = classes[firstFreeClass].next; + return cdx; } } int newItem() { if (firstFreeItem == -1) { - int idx = items.size(); - items.push_back(ItemT()); - return idx; + int idx = items.size(); + items.push_back(ItemT()); + return idx; } else { - int idx = firstFreeItem; - firstFreeItem = items[firstFreeItem].next; - return idx; + int idx = firstFreeItem; + firstFreeItem = items[firstFreeItem].next; + return idx; } } @@ -267,7 +267,7 @@ void unlaceItem(int idx) { items[items[idx].prev].next = items[idx].next; items[items[idx].next].prev = items[idx].prev; - + items[idx].next = firstFreeItem; firstFreeItem = idx; } @@ -278,7 +278,7 @@ int tmp = items[ak].prev; items[ak].prev = items[bk].prev; items[bk].prev = tmp; - + } void laceClass(int cls) { @@ -288,7 +288,7 @@ classes[cls].next = firstClass; classes[cls].prev = -1; firstClass = cls; - } + } void unlaceClass(int cls) { if (classes[cls].prev != -1) { @@ -299,17 +299,17 @@ if (classes[cls].next != -1) { classes[classes[cls].next].prev = classes[cls].prev; } - + classes[cls].next = firstFreeClass; firstFreeClass = cls; - } + } public: - UnionFindEnum(ItemIntMap& _index) - : index(_index), items(), firstFreeItem(-1), - firstClass(-1), firstFreeClass(-1) {} - + UnionFindEnum(ItemIntMap& _index) + : index(_index), items(), firstFreeItem(-1), + firstClass(-1), firstFreeClass(-1) {} + /// \brief Inserts the given element into a new component. /// /// This method creates a new component consisting only of the @@ -332,14 +332,14 @@ classes[cdx].firstItem = idx; firstClass = cdx; - + return cdx; } /// \brief Inserts the given element into the component of the others. /// /// This methods inserts the element \e a into the component of the - /// element \e comp. + /// element \e comp. void insert(const Item& item, int cls) { int rdx = classes[cls].firstItem; int idx = newItem(); @@ -372,7 +372,7 @@ /// \brief Joining the component of element \e a and element \e b. /// - /// This is the \e union operation of the Union-Find structure. + /// This is the \e union operation of the Union-Find structure. /// Joins the component of element \e a and component of /// element \e b. If \e a and \e b are in the same component then /// returns -1 else returns the remaining class. @@ -382,7 +382,7 @@ int bk = repIndex(index[b]); if (ak == bk) { - return -1; + return -1; } int acx = ~(items[ak].parent); @@ -391,15 +391,15 @@ int rcx; if (classes[acx].size > classes[bcx].size) { - classes[acx].size += classes[bcx].size; - items[bk].parent = ak; + classes[acx].size += classes[bcx].size; + items[bk].parent = ak; unlaceClass(bcx); - rcx = acx; + rcx = acx; } else { - classes[bcx].size += classes[acx].size; - items[ak].parent = bk; + classes[bcx].size += classes[acx].size; + items[ak].parent = bk; unlaceClass(acx); - rcx = bcx; + rcx = bcx; } spliceItems(ak, bk); @@ -413,7 +413,7 @@ return classes[cls].size; } - /// \brief Splits up the component. + /// \brief Splits up the component. /// /// Splitting the component into singleton components (component /// of size one). @@ -423,15 +423,15 @@ while (idx != fdx) { int next = items[idx].next; - singletonItem(idx); + singletonItem(idx); - int cdx = newClass(); + int cdx = newClass(); items[idx].parent = ~cdx; - laceClass(cdx); - classes[cdx].size = 1; - classes[cdx].firstItem = idx; - + laceClass(cdx); + classes[cdx].size = 1; + classes[cdx].firstItem = idx; + idx = next; } @@ -439,7 +439,7 @@ items[idx].next = idx; classes[~(items[idx].parent)].size = 1; - + } /// \brief Removes the given element from the structure. @@ -457,22 +457,22 @@ int cdx = classIndex(idx); if (idx == fdx) { - unlaceClass(cdx); - items[idx].next = firstFreeItem; - firstFreeItem = idx; - return; + unlaceClass(cdx); + items[idx].next = firstFreeItem; + firstFreeItem = idx; + return; } else { - classes[cdx].firstItem = fdx; - --classes[cdx].size; - items[fdx].parent = ~cdx; + classes[cdx].firstItem = fdx; + --classes[cdx].size; + items[fdx].parent = ~cdx; - unlaceItem(idx); - idx = items[fdx].next; - while (idx != fdx) { - items[idx].parent = fdx; - idx = items[idx].next; - } - + unlaceItem(idx); + idx = items[fdx].next; + while (idx != fdx) { + items[idx].parent = fdx; + idx = items[idx].next; + } + } } @@ -514,7 +514,7 @@ /// /// Constructor to get invalid iterator ClassIt(Invalid) : unionFind(0), cdx(-1) {} - + /// \brief Increment operator /// /// It steps to the next representant item. @@ -522,7 +522,7 @@ cdx = unionFind->classes[cdx].next; return *this; } - + /// \brief Conversion operator /// /// It converts the iterator to the current representant item. @@ -533,17 +533,17 @@ /// \brief Equality operator /// /// Equality operator - bool operator==(const ClassIt& i) { + bool operator==(const ClassIt& i) { return i.cdx == cdx; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ClassIt& i) { + bool operator!=(const ClassIt& i) { return i.cdx != cdx; } - + private: const UnionFindEnum* unionFind; int cdx; @@ -577,7 +577,7 @@ /// /// Constructor to get invalid iterator ItemIt(Invalid) : unionFind(0), idx(-1) {} - + /// \brief Increment operator /// /// It steps to the next item in the class. @@ -586,7 +586,7 @@ if (idx == fdx) idx = -1; return *this; } - + /// \brief Conversion operator /// /// It converts the iterator to the current item. @@ -597,17 +597,17 @@ /// \brief Equality operator /// /// Equality operator - bool operator==(const ItemIt& i) { + bool operator==(const ItemIt& i) { return i.idx == idx; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ItemIt& i) { + bool operator!=(const ItemIt& i) { return i.idx != idx; } - + private: const UnionFindEnum* unionFind; int idx, fdx; @@ -630,12 +630,12 @@ template class ExtendFindEnum { public: - + typedef _ItemIntMap ItemIntMap; typedef typename ItemIntMap::Key Item; private: - + ItemIntMap& index; struct ItemT { @@ -658,33 +658,33 @@ int newClass() { if (firstFreeClass != -1) { - int cdx = firstFreeClass; - firstFreeClass = classes[cdx].next; - return cdx; + int cdx = firstFreeClass; + firstFreeClass = classes[cdx].next; + return cdx; } else { - classes.push_back(ClassT()); - return classes.size() - 1; + classes.push_back(ClassT()); + return classes.size() - 1; } } int newItem() { if (firstFreeItem != -1) { - int idx = firstFreeItem; - firstFreeItem = items[idx].next; - return idx; + int idx = firstFreeItem; + firstFreeItem = items[idx].next; + return idx; } else { - items.push_back(ItemT()); - return items.size() - 1; + items.push_back(ItemT()); + return items.size() - 1; } } public: /// \brief Constructor - ExtendFindEnum(ItemIntMap& _index) - : index(_index), items(), firstFreeItem(-1), - classes(), firstClass(-1), firstFreeClass(-1) {} - + ExtendFindEnum(ItemIntMap& _index) + : index(_index), items(), firstFreeItem(-1), + classes(), firstClass(-1), firstFreeClass(-1) {} + /// \brief Inserts the given element into a new component. /// /// This method creates a new component consisting only of the @@ -694,10 +694,10 @@ classes[cdx].prev = -1; classes[cdx].next = firstClass; if (firstClass != -1) { - classes[firstClass].prev = cdx; + classes[firstClass].prev = cdx; } firstClass = cdx; - + int idx = newItem(); items[idx].item = item; items[idx].cls = cdx; @@ -707,7 +707,7 @@ classes[cdx].firstItem = idx; index.set(item, idx); - + return cdx; } @@ -750,7 +750,7 @@ Item item(int cls) const { return items[classes[cls].firstItem].item; } - + /// \brief Removes the given element from the structure. /// /// Removes the element from its component and if the component becomes @@ -761,29 +761,29 @@ void erase(const Item &item) { int idx = index[item]; int cdx = items[idx].cls; - + if (idx == items[idx].next) { - if (classes[cdx].prev != -1) { - classes[classes[cdx].prev].next = classes[cdx].next; - } else { - firstClass = classes[cdx].next; - } - if (classes[cdx].next != -1) { - classes[classes[cdx].next].prev = classes[cdx].prev; - } - classes[cdx].next = firstFreeClass; - firstFreeClass = cdx; + if (classes[cdx].prev != -1) { + classes[classes[cdx].prev].next = classes[cdx].next; + } else { + firstClass = classes[cdx].next; + } + if (classes[cdx].next != -1) { + classes[classes[cdx].next].prev = classes[cdx].prev; + } + classes[cdx].next = firstFreeClass; + firstFreeClass = cdx; } else { - classes[cdx].firstItem = items[idx].next; - items[items[idx].next].prev = items[idx].prev; - items[items[idx].prev].next = items[idx].next; + classes[cdx].firstItem = items[idx].next; + items[items[idx].next].prev = items[idx].prev; + items[items[idx].prev].next = items[idx].next; } items[idx].next = firstFreeItem; firstFreeItem = idx; - - } - + } + + /// \brief Removes the component of the given element from the structure. /// /// Removes the component of the given element from the structure. @@ -796,12 +796,12 @@ firstFreeItem = idx; if (classes[cdx].prev != -1) { - classes[classes[cdx].prev].next = classes[cdx].next; + classes[classes[cdx].prev].next = classes[cdx].next; } else { - firstClass = classes[cdx].next; + firstClass = classes[cdx].next; } if (classes[cdx].next != -1) { - classes[classes[cdx].next].prev = classes[cdx].prev; + classes[classes[cdx].next].prev = classes[cdx].prev; } classes[cdx].next = firstFreeClass; firstFreeClass = cdx; @@ -824,7 +824,7 @@ /// /// Constructor to get invalid iterator ClassIt(Invalid) : extendFind(0), cdx(-1) {} - + /// \brief Increment operator /// /// It steps to the next representant item. @@ -832,7 +832,7 @@ cdx = extendFind->classes[cdx].next; return *this; } - + /// \brief Conversion operator /// /// It converts the iterator to the current class id. @@ -843,17 +843,17 @@ /// \brief Equality operator /// /// Equality operator - bool operator==(const ClassIt& i) { + bool operator==(const ClassIt& i) { return i.cdx == cdx; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ClassIt& i) { + bool operator!=(const ClassIt& i) { return i.cdx != cdx; } - + private: const ExtendFindEnum* extendFind; int cdx; @@ -887,16 +887,16 @@ /// /// Constructor to get invalid iterator ItemIt(Invalid) : extendFind(0), idx(-1) {} - + /// \brief Increment operator /// /// It steps to the next item in the class. ItemIt& operator++() { idx = extendFind->items[idx].next; - if (fdx == idx) idx = -1; + if (fdx == idx) idx = -1; return *this; } - + /// \brief Conversion operator /// /// It converts the iterator to the current item. @@ -907,17 +907,17 @@ /// \brief Equality operator /// /// Equality operator - bool operator==(const ItemIt& i) { + bool operator==(const ItemIt& i) { return i.idx == idx; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ItemIt& i) { + bool operator!=(const ItemIt& i) { return i.idx != idx; } - + private: const ExtendFindEnum* extendFind; int idx, fdx; @@ -949,11 +949,11 @@ /// \pre You need to add all the elements by the \ref insert() /// method. /// - template > class HeapUnionFind { public: - + typedef _Value Value; typedef typename _ItemIntMap::Key Item; @@ -1054,7 +1054,7 @@ } id = nodes[id].next; while (depth--) { - id = nodes[id].left; + id = nodes[id].left; } return id; } @@ -1132,7 +1132,7 @@ int kd = nodes[id].parent; nodes[kd].right = nodes[id].prev; nodes[nodes[id].prev].next = -1; - + nodes[jd].left = id; nodes[id].prev = -1; int num = 0; @@ -1141,7 +1141,7 @@ nodes[jd].right = id; id = nodes[id].next; ++num; - } + } nodes[kd].size -= num; nodes[jd].size = num; } @@ -1165,84 +1165,84 @@ void repairLeft(int id) { int jd = ~(classes[id].parent); while (nodes[jd].left != -1) { - int kd = nodes[jd].left; - if (nodes[jd].size == 1) { - if (nodes[jd].parent < 0) { - classes[id].parent = ~kd; - classes[id].depth -= 1; - nodes[kd].parent = ~id; - deleteNode(jd); - jd = kd; - } else { - int pd = nodes[jd].parent; - if (nodes[nodes[jd].next].size < cmax) { - pushLeft(nodes[jd].next, nodes[jd].left); - if (less(nodes[jd].left, nodes[jd].next)) { - nodes[nodes[jd].next].prio = nodes[nodes[jd].left].prio; - nodes[nodes[jd].next].item = nodes[nodes[jd].left].item; - } - popLeft(pd); - deleteNode(jd); - jd = pd; - } else { - int ld = nodes[nodes[jd].next].left; - popLeft(nodes[jd].next); - pushRight(jd, ld); - if (less(ld, nodes[jd].left)) { - nodes[jd].item = nodes[ld].item; - nodes[jd].prio = nodes[jd].prio; - } - if (nodes[nodes[jd].next].item == nodes[ld].item) { - setPrio(nodes[jd].next); - } - jd = nodes[jd].left; - } - } - } else { - jd = nodes[jd].left; - } + int kd = nodes[jd].left; + if (nodes[jd].size == 1) { + if (nodes[jd].parent < 0) { + classes[id].parent = ~kd; + classes[id].depth -= 1; + nodes[kd].parent = ~id; + deleteNode(jd); + jd = kd; + } else { + int pd = nodes[jd].parent; + if (nodes[nodes[jd].next].size < cmax) { + pushLeft(nodes[jd].next, nodes[jd].left); + if (less(nodes[jd].left, nodes[jd].next)) { + nodes[nodes[jd].next].prio = nodes[nodes[jd].left].prio; + nodes[nodes[jd].next].item = nodes[nodes[jd].left].item; + } + popLeft(pd); + deleteNode(jd); + jd = pd; + } else { + int ld = nodes[nodes[jd].next].left; + popLeft(nodes[jd].next); + pushRight(jd, ld); + if (less(ld, nodes[jd].left)) { + nodes[jd].item = nodes[ld].item; + nodes[jd].prio = nodes[jd].prio; + } + if (nodes[nodes[jd].next].item == nodes[ld].item) { + setPrio(nodes[jd].next); + } + jd = nodes[jd].left; + } + } + } else { + jd = nodes[jd].left; + } } - } + } void repairRight(int id) { int jd = ~(classes[id].parent); while (nodes[jd].right != -1) { - int kd = nodes[jd].right; - if (nodes[jd].size == 1) { - if (nodes[jd].parent < 0) { - classes[id].parent = ~kd; - classes[id].depth -= 1; - nodes[kd].parent = ~id; - deleteNode(jd); - jd = kd; - } else { - int pd = nodes[jd].parent; - if (nodes[nodes[jd].prev].size < cmax) { - pushRight(nodes[jd].prev, nodes[jd].right); - if (less(nodes[jd].right, nodes[jd].prev)) { - nodes[nodes[jd].prev].prio = nodes[nodes[jd].right].prio; - nodes[nodes[jd].prev].item = nodes[nodes[jd].right].item; - } - popRight(pd); - deleteNode(jd); - jd = pd; - } else { - int ld = nodes[nodes[jd].prev].right; - popRight(nodes[jd].prev); - pushLeft(jd, ld); - if (less(ld, nodes[jd].right)) { - nodes[jd].item = nodes[ld].item; - nodes[jd].prio = nodes[jd].prio; - } - if (nodes[nodes[jd].prev].item == nodes[ld].item) { - setPrio(nodes[jd].prev); - } - jd = nodes[jd].right; - } - } - } else { - jd = nodes[jd].right; - } + int kd = nodes[jd].right; + if (nodes[jd].size == 1) { + if (nodes[jd].parent < 0) { + classes[id].parent = ~kd; + classes[id].depth -= 1; + nodes[kd].parent = ~id; + deleteNode(jd); + jd = kd; + } else { + int pd = nodes[jd].parent; + if (nodes[nodes[jd].prev].size < cmax) { + pushRight(nodes[jd].prev, nodes[jd].right); + if (less(nodes[jd].right, nodes[jd].prev)) { + nodes[nodes[jd].prev].prio = nodes[nodes[jd].right].prio; + nodes[nodes[jd].prev].item = nodes[nodes[jd].right].item; + } + popRight(pd); + deleteNode(jd); + jd = pd; + } else { + int ld = nodes[nodes[jd].prev].right; + popRight(nodes[jd].prev); + pushLeft(jd, ld); + if (less(ld, nodes[jd].right)) { + nodes[jd].item = nodes[ld].item; + nodes[jd].prio = nodes[jd].prio; + } + if (nodes[nodes[jd].prev].item == nodes[ld].item) { + setPrio(nodes[jd].prev); + } + jd = nodes[jd].right; + } + } + } else { + jd = nodes[jd].right; + } } } @@ -1276,12 +1276,12 @@ /// \brief Constructs the union-find. /// - /// Constructs the union-find. + /// Constructs the union-find. /// \brief _index The index map of the union-find. The data /// structure uses internally for store references. - HeapUnionFind(ItemIntMap& _index) - : index(_index), first_class(-1), - first_free_class(-1), first_free_node(-1) {} + HeapUnionFind(ItemIntMap& _index) + : index(_index), first_class(-1), + first_free_class(-1), first_free_node(-1) {} /// \brief Insert a new node into a new component. /// @@ -1303,14 +1303,14 @@ nodes[id].item = item; index[item] = id; - + int class_id = newClass(); classes[class_id].parent = ~id; classes[class_id].depth = 0; classes[class_id].left = -1; classes[class_id].right = -1; - + if (first_class != -1) { classes[first_class].prev = class_id; } @@ -1319,7 +1319,7 @@ first_class = class_id; nodes[id].parent = ~class_id; - + return class_id; } @@ -1332,7 +1332,7 @@ int find(const Item& item) const { return findClass(index[item]); } - + /// \brief Joins the classes. /// /// The current function joins the given classes. The parameter is @@ -1371,13 +1371,13 @@ classes[classes[l].next].prev = classes[l].prev; } classes[classes[l].prev].next = classes[l].next; - + classes[l].prev = -1; classes[l].next = -1; classes[l].depth = leftNode(l); classes[l].parent = class_id; - + } { // merging of heap @@ -1455,7 +1455,7 @@ push(new_parent, ~(classes[r].parent)); pushLeft(new_parent, ~(classes[l].parent)); setPrio(new_parent); - + classes[r].parent = ~new_parent; classes[r].depth += 1; } else { @@ -1470,15 +1470,15 @@ classes[l].parent = classes[r].parent; classes[l].depth = classes[r].depth; } else { - if (classes[l].depth != 0 && - nodes[~(classes[l].parent)].size + + if (classes[l].depth != 0 && + nodes[~(classes[l].parent)].size + nodes[~(classes[r].parent)].size <= cmax) { splice(~(classes[l].parent), ~(classes[r].parent)); deleteNode(~(classes[r].parent)); if (less(~(classes[r].parent), ~(classes[l].parent))) { - nodes[~(classes[l].parent)].prio = + nodes[~(classes[l].parent)].prio = nodes[~(classes[r].parent)].prio; - nodes[~(classes[l].parent)].item = + nodes[~(classes[l].parent)].item = nodes[~(classes[r].parent)].item; } } else { @@ -1487,7 +1487,7 @@ push(new_parent, ~(classes[l].parent)); pushRight(new_parent, ~(classes[r].parent)); setPrio(new_parent); - + classes[l].parent = ~new_parent; classes[l].depth += 1; nodes[new_parent].parent = ~l; @@ -1542,12 +1542,12 @@ classes[classes[id].right].next = first_class; classes[first_class].prev = classes[id].right; first_class = classes[id].left; - + if (classes[id].next != -1) { classes[classes[id].next].prev = classes[id].prev; } classes[classes[id].prev].next = classes[id].next; - + deleteClass(id); } @@ -1557,7 +1557,7 @@ while (nodes[nodes[l].parent].left == l) { l = nodes[l].parent; } - int r = l; + int r = l; while (nodes[l].parent >= 0) { l = nodes[l].parent; int new_node = newNode(); @@ -1580,7 +1580,7 @@ repairRight(~(nodes[l].parent)); repairLeft(cs[i]); - + *out++ = cs[i]; } } @@ -1603,7 +1603,7 @@ increase(item, prio); } } - + /// \brief Increase the priority of the current item. /// /// Increase the priority of the current item. @@ -1630,7 +1630,7 @@ kd = nodes[kd].parent; } } - + /// \brief Gives back the minimum priority of the class. /// /// \return Gives back the minimum priority of the class. @@ -1646,9 +1646,9 @@ } /// \brief Gives back a representant item of the class. - /// + /// /// The representant is indpendent from the priorities of the - /// items. + /// items. /// \return Gives back a representant item of the class. const Item& classRep(int id) const { int parent = classes[id].parent; @@ -1674,12 +1674,12 @@ const HeapUnionFind* _huf; int _id, _lid; - + public: - /// \brief Default constructor + /// \brief Default constructor /// - /// Default constructor + /// Default constructor ItemIt() {} ItemIt(const HeapUnionFind& huf, int cls) : _huf(&huf) { @@ -1695,9 +1695,9 @@ } else { _id = _huf->leftNode(id); _lid = -1; - } + } } - + /// \brief Increment operator /// /// It steps to the next item in the class. @@ -1712,40 +1712,40 @@ operator const Item&() const { return _huf->nodes[_id].item; } - + /// \brief Equality operator /// /// Equality operator - bool operator==(const ItemIt& i) { + bool operator==(const ItemIt& i) { return i._id == _id; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ItemIt& i) { + bool operator!=(const ItemIt& i) { return i._id != _id; } /// \brief Equality operator /// /// Equality operator - bool operator==(Invalid) { + bool operator==(Invalid) { return _id == _lid; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(Invalid) { + bool operator!=(Invalid) { return _id != _lid; } - + }; /// \brief Class iterator /// - /// The iterator stores + /// The iterator stores class ClassIt { private: @@ -1754,37 +1754,37 @@ public: - ClassIt(const HeapUnionFind& huf) + ClassIt(const HeapUnionFind& huf) : _huf(&huf), _id(huf.first_class) {} - ClassIt(const HeapUnionFind& huf, int cls) + ClassIt(const HeapUnionFind& huf, int cls) : _huf(&huf), _id(huf.classes[cls].left) {} ClassIt(Invalid) : _huf(0), _id(-1) {} - + const ClassIt& operator++() { _id = _huf->classes[_id].next; - return *this; + return *this; } /// \brief Equality operator /// /// Equality operator - bool operator==(const ClassIt& i) { + bool operator==(const ClassIt& i) { return i._id == _id; } /// \brief Inequality operator /// /// Inequality operator - bool operator!=(const ClassIt& i) { + bool operator!=(const ClassIt& i) { return i._id != _id; - } - + } + operator int() const { - return _id; + return _id; } - + }; }; diff -r 4317d277ba21 -r 765619b7cbb2 test/bfs_test.cc --- a/test/bfs_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/bfs_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -27,11 +27,11 @@ using namespace lemon; -void checkBfsCompile() +void checkBfsCompile() { typedef concepts::Digraph Digraph; typedef Bfs BType; - + Digraph G; Digraph::Node n; Digraph::Arc e; @@ -40,11 +40,11 @@ BType::DistMap d(G); BType::PredMap p(G); // BType::PredNodeMap pn(G); - + BType bfs_test(G); - + bfs_test.run(n); - + l = bfs_test.dist(n); e = bfs_test.predArc(n); n = bfs_test.predNode(n); @@ -56,13 +56,13 @@ Path pp = bfs_test.path(n); } -void checkBfsFunctionCompile() +void checkBfsFunctionCompile() { typedef int VType; typedef concepts::Digraph Digraph; typedef Digraph::Arc Arc; typedef Digraph::Node Node; - + Digraph g; bfs(g,Node()).run(); bfs(g).source(Node()).run(); @@ -81,13 +81,13 @@ Digraph G; Node s, t; PetStruct ps = addPetersen(G, 5); - + s=ps.outer[2]; t=ps.inner[0]; - + Bfs bfs_test(G); bfs_test.run(s); - + check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t)); Path p = bfs_test.path(t); @@ -95,14 +95,14 @@ check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); - + for(ArcIt e(G); e==INVALID; ++e) { Node u=G.source(e); Node v=G.target(e); check( !bfs_test.reached(u) || - (bfs_test.dist(v) > bfs_test.dist(u)+1), - "Wrong output."); + (bfs_test.dist(v) > bfs_test.dist(u)+1), + "Wrong output."); } for(NodeIt v(G); v==INVALID; ++v) { @@ -112,9 +112,9 @@ Node u=G.source(e); check(u==bfs_test.predNode(v),"Wrong tree."); check(bfs_test.dist(v) - bfs_test.dist(u) == 1, - "Wrong distance. Difference: " - << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - - 1)); + "Wrong distance. Difference: " + << std::abs(bfs_test.dist(v) - bfs_test.dist(u) + - 1)); } } } diff -r 4317d277ba21 -r 765619b7cbb2 test/counter_test.cc --- a/test/counter_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/counter_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -75,14 +75,14 @@ void init(std::vector& v) { v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100; - v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; + v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; } int main() { counterTest(); counterTest(); - + std::vector x(10); init(x); bubbleSort(x); init(x); insertionSort(x); diff -r 4317d277ba21 -r 765619b7cbb2 test/dfs_test.cc --- a/test/dfs_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/dfs_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -27,11 +27,11 @@ using namespace lemon; -void checkDfsCompile() +void checkDfsCompile() { typedef concepts::Digraph Digraph; typedef Dfs DType; - + Digraph G; Digraph::Node n; Digraph::Arc e; @@ -40,11 +40,11 @@ DType::DistMap d(G); DType::PredMap p(G); // DType::PredNodeMap pn(G); - + DType dfs_test(G); - + dfs_test.run(n); - + l = dfs_test.dist(n); e = dfs_test.predArc(n); n = dfs_test.predNode(n); @@ -56,13 +56,13 @@ Path pp = dfs_test.path(n); } -void checkDfsFunctionCompile() +void checkDfsFunctionCompile() { typedef int VType; typedef concepts::Digraph Digraph; typedef Digraph::Arc Arc; typedef Digraph::Node Node; - + Digraph g; dfs(g,Node()).run(); dfs(g).source(Node()).run(); @@ -71,7 +71,7 @@ .distMap(concepts::WriteMap()) .reachedMap(concepts::ReadWriteMap()) .processedMap(concepts::WriteMap()) - .run(Node()); + .run(Node()); } template @@ -81,19 +81,19 @@ Digraph G; Node s, t; PetStruct ps = addPetersen(G, 5); - + s=ps.outer[2]; t=ps.inner[0]; - + Dfs dfs_test(G); - dfs_test.run(s); - + dfs_test.run(s); + Path p = dfs_test.path(t); check(p.length() == dfs_test.dist(t),"path() found a wrong path."); check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); - + for(NodeIt v(G); v!=INVALID; ++v) { check(dfs_test.reached(v),"Each node should be reached."); if ( dfs_test.predArc(v)!=INVALID ) { @@ -101,8 +101,8 @@ Node u=G.source(e); check(u==dfs_test.predNode(v),"Wrong tree."); check(dfs_test.dist(v) - dfs_test.dist(u) == 1, - "Wrong distance. (" << dfs_test.dist(u) << "->" - <" + <(); - checkConcept, + checkConcept, IDableDigraphComponent<> >(); - checkConcept, + checkConcept, IterableDigraphComponent<> >(); - checkConcept, + checkConcept, MappableDigraphComponent<> >(); } { // Checking skeleton digraph diff -r 4317d277ba21 -r 765619b7cbb2 test/dijkstra_test.cc --- a/test/dijkstra_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/dijkstra_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -28,13 +28,13 @@ using namespace lemon; -void checkDijkstraCompile() +void checkDijkstraCompile() { typedef int VType; typedef concepts::Digraph Digraph; typedef concepts::ReadMap LengthMap; typedef Dijkstra DType; - + Digraph G; Digraph::Node n; Digraph::Arc e; @@ -60,14 +60,14 @@ Path pp = dijkstra_test.path(n); } -void checkDijkstraFunctionCompile() +void checkDijkstraFunctionCompile() { typedef int VType; typedef concepts::Digraph Digraph; typedef Digraph::Arc Arc; typedef Digraph::Node Node; typedef concepts::ReadMap LengthMap; - + Digraph g; dijkstra(g,LengthMap(),Node()).run(); dijkstra(g,LengthMap()).source(Node()).run(); @@ -78,7 +78,7 @@ } template -void checkDijkstra() { +void checkDijkstra() { TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); typedef typename Digraph::template ArcMap LengthMap; @@ -86,7 +86,7 @@ Node s, t; LengthMap length(G); PetStruct ps = addPetersen(G, 5); - + for(int i=0;i<5;i++) { length[ps.outcir[i]]=4; length[ps.incir[i]]=1; @@ -94,11 +94,11 @@ } s=ps.outer[0]; t=ps.inner[1]; - - Dijkstra - dijkstra_test(G, length); + + Dijkstra + dijkstra_test(G, length); dijkstra_test.run(s); - + check(dijkstra_test.dist(t)==13,"Dijkstra found a wrong path."); Path p = dijkstra_test.path(t); @@ -106,12 +106,12 @@ check(checkPath(G, p),"path() found a wrong path."); check(pathSource(G, p) == s,"path() found a wrong path."); check(pathTarget(G, p) == t,"path() found a wrong path."); - + for(ArcIt e(G); e!=INVALID; ++e) { Node u=G.source(e); Node v=G.target(e); check( !dijkstra_test.reached(u) || (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]), - "dist(target)-dist(source)-arc_length= " << dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]); + "dist(target)-dist(source)-arc_length= " << dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]); } for(NodeIt v(G); v!=INVALID; ++v){ @@ -121,10 +121,10 @@ Node u=G.source(e); check(u==dijkstra_test.predNode(v),"Wrong tree."); check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e], - "Wrong distance! Difference: " << std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e])); + "Wrong distance! Difference: " << std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e])); } } - + { NullMap myPredMap; dijkstra(G,length).predMap(myPredMap).run(s); diff -r 4317d277ba21 -r 765619b7cbb2 test/dim_test.cc --- a/test/dim_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/dim_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 test/error_test.cc --- a/test/error_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/error_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -58,8 +58,8 @@ #define LEMON_ASSERT_CUSTOM static int cnt = 0; -void my_assert_handler(const char*, int, const char*, - const char*, const char*) { +void my_assert_handler(const char*, int, const char*, + const char*, const char*) { ++cnt; } diff -r 4317d277ba21 -r 765619b7cbb2 test/graph_copy_test.cc --- a/test/graph_copy_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/graph_copy_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -122,7 +122,7 @@ if (i == 0 && j == 0) fe = edge; } } - + ListGraph to; ListGraph::NodeMap tnm(to); ListGraph::ArcMap tam(to); @@ -160,12 +160,12 @@ for (SmartGraph::EdgeIt it(from); it != INVALID; ++it) { check(ecr[er[it]] == it, "Wrong copy."); check(fem[it] == tem[er[it]], "Wrong copy."); - check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]), - "Wrong copy."); - check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]), - "Wrong copy."); - check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])), - "Wrong copy."); + check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]), + "Wrong copy."); + check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]), + "Wrong copy."); + check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])), + "Wrong copy."); } for (ListGraph::NodeIt it(to); it != INVALID; ++it) { @@ -188,5 +188,5 @@ digraph_copy_test(); graph_copy_test(); - return 0; + return 0; } diff -r 4317d277ba21 -r 765619b7cbb2 test/graph_maps_test.h --- a/test/graph_maps_test.h Sun Jul 13 16:46:56 2008 +0100 +++ b/test/graph_maps_test.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -71,7 +71,7 @@ std::vector arcs; for (int i = 0; i < num; ++i) { for (int j = 0; j < i; ++j) { - arcs.push_back(graph.addArc(nodes[i], nodes[j])); + arcs.push_back(graph.addArc(nodes[i], nodes[j])); } } @@ -84,8 +84,8 @@ for (int i = 0; i < num; ++i) { for (int j = i + 1; j < num; ++j) { - arcs.push_back(graph.addArc(nodes[i], nodes[j])); - map[arcs.back()] = 23; + arcs.push_back(graph.addArc(nodes[i], nodes[j])); + map[arcs.back()] = 23; check(map[arcs.back()] == 23, "Wrong operator[]."); } } @@ -113,7 +113,7 @@ std::vector edges; for (int i = 0; i < num; ++i) { for (int j = 0; j < i; ++j) { - edges.push_back(graph.addEdge(nodes[i], nodes[j])); + edges.push_back(graph.addEdge(nodes[i], nodes[j])); } } @@ -126,8 +126,8 @@ for (int i = 0; i < num; ++i) { for (int j = i + 1; j < num; ++j) { - edges.push_back(graph.addEdge(nodes[i], nodes[j])); - map[edges.back()] = 23; + edges.push_back(graph.addEdge(nodes[i], nodes[j])); + map[edges.back()] = 23; check(map[edges.back()] == 23, "Wrong operator[]."); } } diff -r 4317d277ba21 -r 765619b7cbb2 test/graph_test.cc --- a/test/graph_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/graph_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -33,13 +33,13 @@ { // Checking graph components checkConcept(); - checkConcept, + checkConcept, IDableGraphComponent<> >(); - checkConcept, + checkConcept, IterableGraphComponent<> >(); - checkConcept, + checkConcept, MappableGraphComponent<> >(); } { // Checking skeleton graph @@ -134,7 +134,7 @@ // check(g.row(g(i, j)) == j, "Wrong row"); // } // } - + // for (int i = 0; i < w; ++i) { // for (int j = 0; j < h - 1; ++j) { // check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down"); @@ -154,17 +154,17 @@ // for (int j = 0; j < h; ++j) { // for (int i = 0; i < w - 1; ++i) { // check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right"); -// check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right"); +// check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right"); // } -// check(g.right(g(w - 1, j)) == INVALID, "Wrong right"); +// check(g.right(g(w - 1, j)) == INVALID, "Wrong right"); // } // for (int j = 0; j < h; ++j) { // for (int i = 1; i < w; ++i) { // check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left"); -// check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); +// check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left"); // } -// check(g.left(g(0, j)) == INVALID, "Wrong left"); +// check(g.left(g(0, j)) == INVALID, "Wrong left"); // } // } diff -r 4317d277ba21 -r 765619b7cbb2 test/graph_test.h --- a/test/graph_test.h Sun Jul 13 16:46:56 2008 +0100 +++ b/test/graph_test.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -217,7 +217,7 @@ n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%num])); n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%num])); } - + return n; } @@ -246,7 +246,7 @@ bidirDigraph(G); checkBidirPetersen(G, num); } - + template void checkGraph() { const int num = 5; diff -r 4317d277ba21 -r 765619b7cbb2 test/graph_utils_test.cc --- a/test/graph_utils_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/graph_utils_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -140,7 +140,7 @@ void checkDeg() { TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); - + const int nodeNum = 10; const int arcNum = 100; Digraph digraph; @@ -155,11 +155,11 @@ arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); } for (int i = 0; i < nodeNum; ++i) { - check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), + check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), "Wrong in degree map"); } for (int i = 0; i < nodeNum; ++i) { - check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), + check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), "Wrong out degree map"); } } @@ -172,15 +172,15 @@ Digraph g; Node n1=g.addNode(); Node n2=g.addNode(); - + InDegMap ind(g); - + g.addArc(n1,n2); - + typename Digraph::Snapshot snap(g); - + OutDegMap outd(g); - + check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value."); check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value."); diff -r 4317d277ba21 -r 765619b7cbb2 test/heap_test.cc --- a/test/heap_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/heap_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -40,42 +40,42 @@ typedef ListDigraph Digraph; DIGRAPH_TYPEDEFS(Digraph); -char test_lgf[] = - "@nodes\n" - "label\n" - "0\n" - "1\n" - "2\n" - "3\n" - "4\n" - "5\n" - "6\n" - "7\n" - "8\n" - "9\n" - "@arcs\n" - " label capacity\n" - "0 5 0 94\n" - "3 9 1 11\n" - "8 7 2 83\n" - "1 2 3 94\n" - "5 7 4 35\n" - "7 4 5 84\n" - "9 5 6 38\n" - "0 4 7 96\n" - "6 7 8 6\n" - "3 1 9 27\n" - "5 2 10 77\n" - "5 6 11 69\n" - "6 5 12 41\n" - "4 6 13 70\n" - "3 2 14 45\n" - "7 9 15 93\n" - "5 9 16 50\n" - "9 0 17 94\n" - "9 6 18 67\n" - "0 9 19 86\n" - "@attributes\n" +char test_lgf[] = + "@nodes\n" + "label\n" + "0\n" + "1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n" + "7\n" + "8\n" + "9\n" + "@arcs\n" + " label capacity\n" + "0 5 0 94\n" + "3 9 1 11\n" + "8 7 2 83\n" + "1 2 3 94\n" + "5 7 4 35\n" + "7 4 5 84\n" + "9 5 6 38\n" + "0 4 7 96\n" + "6 7 8 6\n" + "3 1 9 27\n" + "5 2 10 77\n" + "5 6 11 69\n" + "6 5 12 41\n" + "4 6 13 70\n" + "3 2 14 45\n" + "7 9 15 93\n" + "5 9 16 50\n" + "9 0 17 94\n" + "9 6 18 67\n" + "0 9 19 86\n" + "@attributes\n" "source 3\n"; int test_seq[] = { 2, 28, 19, 27, 33, 25, 13, 41, 10, 26, 1, 9, 4, 34}; @@ -88,7 +88,7 @@ RangeMap map(test_len, -1); Heap heap(map); - + std::vector v(test_len); for (int i = 0; i < test_len; ++i) { @@ -107,7 +107,7 @@ RangeMap map(test_len, -1); Heap heap(map); - + std::vector v(test_len); for (int i = 0; i < test_len; ++i) { @@ -128,20 +128,20 @@ template -void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length, - Node source) { - +void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length, + Node source) { + typename Dijkstra::template DefStandardHeap:: Create dijkstra(digraph, length); dijkstra.run(source); for(ArcIt a(digraph); a != INVALID; ++a) { - Node s = digraph.source(a); + Node s = digraph.source(a); Node t = digraph.target(a); if (dijkstra.reached(s)) { check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a], - "Error in a shortest path tree!"); + "Error in a shortest path tree!"); } } @@ -150,7 +150,7 @@ Arc a = dijkstra.predArc(n); Node s = digraph.source(a); check( dijkstra.dist(n) - dijkstra.dist(s) == length[a], - "Error in a shortest path tree!"); + "Error in a shortest path tree!"); } } @@ -161,7 +161,7 @@ typedef int Item; typedef int Prio; typedef RangeMap ItemIntMap; - + Digraph digraph; IntArcMap length(digraph); Node source; @@ -170,14 +170,14 @@ digraphReader(input, digraph). arcMap("capacity", length). node("source", source). - run(); - + run(); + { typedef BinHeap IntHeap; checkConcept, IntHeap>(); heapSortTest(); heapIncreaseTest(); - + typedef BinHeap NodeHeap; checkConcept, NodeHeap>(); dijkstraHeapTest(digraph, length, source); diff -r 4317d277ba21 -r 765619b7cbb2 test/kruskal_test.cc --- a/test/kruskal_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/kruskal_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -73,7 +73,7 @@ Node v3=G.addNode(); Node v4=G.addNode(); Node t=G.addNode(); - + Edge e1 = G.addEdge(s, v1); Edge e2 = G.addEdge(s, v2); Edge e3 = G.addEdge(v1, v2); @@ -90,14 +90,14 @@ ECostMap edge_cost_map(G, 2); EBoolMap tree_map(G); - + //Test with const map. check(kruskal(G, ConstMap(2), tree_map)==10, - "Total cost should be 10"); + "Total cost should be 10"); //Test with an edge map (filled with uniform costs). check(kruskal(G, edge_cost_map, tree_map)==10, - "Total cost should be 10"); + "Total cost should be 10"); edge_cost_map.set(e1, -10); edge_cost_map.set(e2, -9); @@ -114,34 +114,34 @@ //Test with a edge map and inserter. check(kruskal(G, edge_cost_map, - tree_edge_vec.begin()) - ==-31, - "Total cost should be -31."); - + tree_edge_vec.begin()) + ==-31, + "Total cost should be -31."); + tree_edge_vec.clear(); check(kruskal(G, edge_cost_map, - back_inserter(tree_edge_vec)) - ==-31, - "Total cost should be -31."); - + back_inserter(tree_edge_vec)) + ==-31, + "Total cost should be -31."); + // tree_edge_vec.clear(); - + // //The above test could also be coded like this: // check(kruskal(G, -// makeKruskalMapInput(G, edge_cost_map), -// makeKruskalSequenceOutput(back_inserter(tree_edge_vec))) -// ==-31, -// "Total cost should be -31."); +// makeKruskalMapInput(G, edge_cost_map), +// makeKruskalSequenceOutput(back_inserter(tree_edge_vec))) +// ==-31, +// "Total cost should be -31."); check(tree_edge_vec.size()==5,"The tree should have 5 edges."); check(tree_edge_vec[0]==e1 && - tree_edge_vec[1]==e2 && - tree_edge_vec[2]==e5 && - tree_edge_vec[3]==e7 && - tree_edge_vec[4]==e9, - "Wrong tree."); + tree_edge_vec[1]==e2 && + tree_edge_vec[2]==e5 && + tree_edge_vec[3]==e7 && + tree_edge_vec[4]==e9, + "Wrong tree."); return 0; } diff -r 4317d277ba21 -r 765619b7cbb2 test/maps_test.cc --- a/test/maps_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/maps_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -304,7 +304,7 @@ check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], "Something is wrong with EqualMap"); } - + // LoggerBoolMap { typedef std::vector vec; @@ -320,7 +320,7 @@ check(v1.size() == 3 && v2.size() == 10 && v1[0]==20 && v1[1]==50 && v1[2]==60 && v2[0]==20 && v2[1]==50 && v2[2]==60, "Something is wrong with LoggerBoolMap"); - + int i = 0; for ( LoggerBoolMap::Iterator it = map2.begin(); it != map2.end(); ++it ) diff -r 4317d277ba21 -r 765619b7cbb2 test/path_test.cc --- a/test/path_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/path_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -39,6 +39,6 @@ } int main() { - check_concepts(); + check_concepts(); return 0; } diff -r 4317d277ba21 -r 765619b7cbb2 test/random_test.cc --- a/test/random_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/random_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -33,8 +33,8 @@ a=lemon::rnd.poisson(.5); lemon::rnd.seed(100); - lemon::rnd.seed(seed_array, seed_array + - (sizeof(seed_array) / sizeof(seed_array[0]))); + lemon::rnd.seed(seed_array, seed_array + + (sizeof(seed_array) / sizeof(seed_array[0]))); return 0; } diff -r 4317d277ba21 -r 765619b7cbb2 test/test_tools.h --- a/test/test_tools.h Sun Jul 13 16:46:56 2008 +0100 +++ b/test/test_tools.h Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport diff -r 4317d277ba21 -r 765619b7cbb2 test/test_tools_fail.cc --- a/test/test_tools_fail.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/test_tools_fail.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -18,7 +18,7 @@ #include "test_tools.h" -int main() +int main() { check(false, "Don't panic. Failing is the right behaviour here."); return 0; diff -r 4317d277ba21 -r 765619b7cbb2 test/test_tools_pass.cc --- a/test/test_tools_pass.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/test_tools_pass.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -18,7 +18,7 @@ #include "test_tools.h" -int main() +int main() { check(true, "It should pass."); return 0; diff -r 4317d277ba21 -r 765619b7cbb2 test/time_measure_test.cc --- a/test/time_measure_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/time_measure_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -20,17 +20,17 @@ using namespace lemon; -void f() +void f() { double d=0; for(int i=0;i<1000;i++) d+=0.1; } -void g() +void g() { static Timer T; - + for(int i=0;i<1000;i++) TimeStamp x(T); } @@ -49,10 +49,10 @@ t=runningTimeTest(f,1,&n,&full); std::cout << t << " (" << n << " tests)\n"; std::cout << "Total: " << full << "\n"; - + t=runningTimeTest(g,1,&n,&full); std::cout << t << " (" << n << " tests)\n"; std::cout << "Total: " << full << "\n"; - + return 0; } diff -r 4317d277ba21 -r 765619b7cbb2 test/unionfind_test.cc --- a/test/unionfind_test.cc Sun Jul 13 16:46:56 2008 +0100 +++ b/test/unionfind_test.cc Sun Jul 13 19:51:02 2008 +0100 @@ -1,6 +1,6 @@ -/* -*- C++ -*- +/* -*- mode: C++; indent-tabs-mode: nil; -*- * - * This file is a part of LEMON, a generic C++ optimization library + * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport @@ -31,7 +31,7 @@ ListGraph::NodeMap base(g); UFE U(base); vector n; - + for(int i=0;i<20;i++) n.push_back(g.addNode()); U.insert(n[1]);