COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon-main


Ignore:
Timestamp:
07/13/08 20:51:02 (17 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

Files:
80 edited

Legend:

Unmodified
Added
Removed
  • demo/arg_parser_demo.cc

    r204 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6565  ap.other("infile", "The input file.")
    6666    .other("...");
    67  
     67
    6868  // Perform the parsing process
    6969  // (in case of any error it terminates the program)
     
    8585  if(ap.given("grb")) std::cout << "  -grb is given\n";
    8686  if(ap.given("grc")) std::cout << "  -grc is given\n";
    87  
     87
    8888  switch(ap.files().size()) {
    8989  case 0:
     
    9595  default:
    9696    std::cout << "  "
    97               << ap.files().size() << " file arguments were given. They are:\n";
     97              << ap.files().size() << " file arguments were given. They are:\n";
    9898  }
    9999  for(unsigned int i=0;i<ap.files().size();++i)
    100100    std::cout << "    '" << ap.files()[i] << "'\n";
    101  
     101
    102102  return 0;
    103103}
  • demo/graph_to_eps_demo.cc

    r206 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5050  typedef ListDigraph::Arc Arc;
    5151  typedef dim2::Point<int> Point;
    52  
     52
    5353  Node n1=g.addNode();
    5454  Node n2=g.addNode();
     
    6363  ListDigraph::ArcMap<int> acolors(g);
    6464  ListDigraph::ArcMap<int> widths(g);
    65  
     65
    6666  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
    6767  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
     
    6969  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
    7070  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
    71  
     71
    7272  Arc a;
    7373
     
    7979  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
    8080  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
    81  
     81
    8282  IdMap<ListDigraph,Node> id(g);
    8383
     
    183183  ListDigraph::NodeMap<int> hcolors(h);
    184184  ListDigraph::NodeMap<Point> hcoords(h);
    185  
     185
    186186  int cols=int(sqrt(double(palette.size())));
    187187  for(int i=0;i<int(paletteW.size());i++) {
     
    190190    hcolors[n]=i;
    191191  }
    192  
     192
    193193  cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl;
    194194  graphToEps(h,"graph_to_eps_demo_out_6_colors.eps").
     
    203203    nodeColors(composeMap(paletteW,hcolors)).
    204204    run();
    205    
     205
    206206  return 0;
    207207}
  • demo/lgf_demo.cc

    r193 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2222///
    2323/// This program gives an example of how to read and write a digraph
    24 /// and additional maps from/to a stream or a file using the 
     24/// and additional maps from/to a stream or a file using the
    2525/// \ref lgf-format "LGF" format.
    2626///
     
    4343  SmartDigraph::ArcMap<int> cap(g);
    4444  SmartDigraph::Node s, t;
    45  
     45
    4646  try {
    4747    digraphReader("digraph.lgf", g). // read the directed graph into g
  • doc/coding_style.dox

    r41 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    1919/*!
    2020
    21 \page coding_style LEMON Coding Style 
     21\page coding_style LEMON Coding Style
    2222
    2323\section naming_conv Naming Conventions
     
    6969
    7070\code
    71 AllWordsCapitalizedWithoutUnderscores 
     71AllWordsCapitalizedWithoutUnderscores
    7272\endcode
    7373
     
    7777
    7878\code
    79 firstWordLowerCaseRestCapitalizedWithoutUnderscores 
     79firstWordLowerCaseRestCapitalizedWithoutUnderscores
    8080\endcode
    8181
     
    8585
    8686\code
    87 ALL_UPPER_CASE_WITH_UNDERSCORES 
     87ALL_UPPER_CASE_WITH_UNDERSCORES
    8888\endcode
    8989
    90 \subsection cs-loc-var Class and instance member variables, auto variables 
     90\subsection cs-loc-var Class and instance member variables, auto variables
    9191
    9292The names of class and instance member variables and auto variables (=variables used locally in methods) should look like the following.
    9393
    9494\code
    95 all_lower_case_with_underscores 
     95all_lower_case_with_underscores
    9696\endcode
    9797
  • doc/dirs.dox

    r40 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    7575
    7676This directory contains some helper classes to implement graphs, maps and
    77 some other classes. As a user you typically don't have to deal with these 
     77some other classes. As a user you typically don't have to deal with these
    7878files.
    7979*/
  • doc/groups.dox

    r192 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2727\brief Graph structures implemented in LEMON.
    2828
    29 The implementation of combinatorial algorithms heavily relies on 
    30 efficient graph implementations. LEMON offers data structures which are 
    31 planned to be easily used in an experimental phase of implementation studies, 
    32 and thereafter the program code can be made efficient by small modifications. 
     29The implementation of combinatorial algorithms heavily relies on
     30efficient graph implementations. LEMON offers data structures which are
     31planned to be easily used in an experimental phase of implementation studies,
     32and thereafter the program code can be made efficient by small modifications.
    3333
    3434The most efficient implementation of diverse applications require the
     
    4141some graph features like arc/edge or node deletion.
    4242
    43 Alteration of standard containers need a very limited number of 
    44 operations, these together satisfy the everyday requirements. 
    45 In the case of graph structures, different operations are needed which do 
    46 not alter the physical graph, but gives another view. If some nodes or 
     43Alteration of standard containers need a very limited number of
     44operations, these together satisfy the everyday requirements.
     45In the case of graph structures, different operations are needed which do
     46not alter the physical graph, but gives another view. If some nodes or
    4747arcs have to be hidden or the reverse oriented graph have to be used, then
    48 this is the case. It also may happen that in a flow implementation 
    49 the residual graph can be accessed by another algorithm, or a node-set 
    50 is to be shrunk for another algorithm. 
    51 LEMON also provides a variety of graphs for these requirements called 
    52 \ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only 
    53 in conjunction with other graph representations. 
     48this is the case. It also may happen that in a flow implementation
     49the residual graph can be accessed by another algorithm, or a node-set
     50is to be shrunk for another algorithm.
     51LEMON also provides a variety of graphs for these requirements called
     52\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only
     53in conjunction with other graph representations.
    5454
    5555You are free to use the graph structure that fit your requirements
    5656the best, most graph algorithms and auxiliary data structures can be used
    57 with any graph structures. 
     57with any graph structures.
    5858*/
    5959
     
    6464
    6565This group describes some graph types between real graphs and graph adaptors.
    66 These classes wrap graphs to give new functionality as the adaptors do it. 
     66These classes wrap graphs to give new functionality as the adaptors do it.
    6767On the other hand they are not light-weight structures as the adaptors.
    6868*/
    6969
    7070/**
    71 @defgroup maps Maps 
     71@defgroup maps Maps
    7272@ingroup datas
    7373\brief Map structures implemented in LEMON.
     
    8080
    8181/**
    82 @defgroup graph_maps Graph Maps 
     82@defgroup graph_maps Graph Maps
    8383@ingroup maps
    8484\brief Special graph-related maps.
     
    116116    }
    117117  }
    118  
     118
    119119  Digraph::NodeMap<int> degree_map(graph);
    120  
     120
    121121  digraphToEps(graph, "graph.eps")
    122122    .coords(coords).scaleToA4().undirected()
    123123    .nodeColors(composeMap(functorToMap(nodeColor), degree_map))
    124124    .run();
    125 \endcode 
     125\endcode
    126126The \c functorToMap() function makes an \c int to \c Color map from the
    127127\e nodeColor() function. The \c composeMap() compose the \e degree_map
     
    141141  typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap;
    142142  TimeMap time(length, speed);
    143  
     143
    144144  Dijkstra<Digraph, TimeMap> dijkstra(graph, time);
    145145  dijkstra.run(source, target);
     
    153153
    154154/**
    155 @defgroup matrices Matrices 
     155@defgroup matrices Matrices
    156156@ingroup datas
    157157\brief Two dimensional data storages implemented in LEMON.
     
    201201\brief Common graph search algorithms.
    202202
    203 This group describes the common graph search algorithms like 
     203This group describes the common graph search algorithms like
    204204Breadth-first search (Bfs) and Depth-first search (Dfs).
    205205*/
     
    213213*/
    214214
    215 /** 
    216 @defgroup max_flow Maximum Flow algorithms 
    217 @ingroup algs 
     215/**
     216@defgroup max_flow Maximum Flow algorithms
     217@ingroup algs
    218218\brief Algorithms for finding maximum flows.
    219219
     
    232232
    233233LEMON contains several algorithms for solving maximum flow problems:
    234 - \ref lemon::EdmondsKarp "Edmonds-Karp" 
     234- \ref lemon::EdmondsKarp "Edmonds-Karp"
    235235- \ref lemon::Preflow "Goldberg's Preflow algorithm"
    236236- \ref lemon::DinitzSleatorTarjan "Dinitz's blocking flow algorithm with dynamic trees"
     
    251251
    252252This group describes the algorithms for finding minimum cost flows and
    253 circulations. 
    254 */
    255 
    256 /**
    257 @defgroup min_cut Minimum Cut algorithms 
    258 @ingroup algs 
     253circulations.
     254*/
     255
     256/**
     257@defgroup min_cut Minimum Cut algorithms
     258@ingroup algs
    259259
    260260\brief Algorithms for finding minimum cut in graphs.
     
    273273
    274274- \ref lemon::HaoOrlin "Hao-Orlin algorithm" to calculate minimum cut
    275   in directed graphs 
     275  in directed graphs
    276276- \ref lemon::NagamochiIbaraki "Nagamochi-Ibaraki algorithm" to
    277277  calculate minimum cut in undirected graphs
     
    308308
    309309/**
    310 @defgroup matching Matching algorithms 
     310@defgroup matching Matching algorithms
    311311@ingroup algs
    312312\brief Algorithms for finding matchings in graphs and bipartite graphs.
     
    315315matchings in graphs and bipartite graphs. The general matching problem is
    316316finding a subset of the arcs which does not shares common endpoints.
    317  
     317
    318318There are several different algorithms for calculate matchings in
    319319graphs.  The matching problems in bipartite graphs are generally
     
    324324
    325325Lemon contains the next algorithms:
    326 - \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp 
    327   augmenting path algorithm for calculate maximum cardinality matching in 
     326- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp
     327  augmenting path algorithm for calculate maximum cardinality matching in
    328328  bipartite graphs
    329 - \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel 
    330   algorithm for calculate maximum cardinality matching in bipartite graphs 
    331 - \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" 
    332   Successive shortest path algorithm for calculate maximum weighted matching 
     329- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel
     330  algorithm for calculate maximum cardinality matching in bipartite graphs
     331- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching"
     332  Successive shortest path algorithm for calculate maximum weighted matching
    333333  and maximum weighted bipartite matching in bipartite graph
    334 - \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" 
    335   Successive shortest path algorithm for calculate minimum cost maximum 
     334- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching"
     335  Successive shortest path algorithm for calculate minimum cost maximum
    336336  matching in bipartite graph
    337337- \ref lemon::MaxMatching "MaxMatching" Edmond's blossom shrinking algorithm
     
    397397*/
    398398
    399 /** 
    400 @defgroup lp_utils Tools for Lp and Mip solvers 
     399/**
     400@defgroup lp_utils Tools for Lp and Mip solvers
    401401@ingroup lp_group
    402402\brief Helper tools to the Lp and Mip solvers.
     
    415415
    416416/**
    417 @defgroup utils Tools and Utilities 
     417@defgroup utils Tools and Utilities
    418418\brief Tools and utilities for programming in LEMON
    419419
     
    468468\brief Graph Input-Output methods
    469469
    470 This group describes the tools for importing and exporting graphs 
     470This group describes the tools for importing and exporting graphs
    471471and graph related data. Now it supports the LEMON format, the
    472472\c DIMACS format and the encapsulated postscript (EPS) format.
     
    487487
    488488This group describes general \c EPS drawing methods and special
    489 graph exporting tools. 
     489graph exporting tools.
    490490*/
    491491
     
    499499
    500500The purpose of the classes in this group is fourfold.
    501  
     501
    502502- These classes contain the documentations of the concepts. In order
    503503  to avoid document multiplications, an implementation of a concept
     
    552552@defgroup tools Standalone utility applications
    553553
    554 Some utility applications are listed here. 
     554Some utility applications are listed here.
    555555
    556556The standard compilation procedure (<tt>./configure;make</tt>) will compile
    557 them, as well. 
    558 */
    559 
     557them, as well.
     558*/
     559
  • doc/lgf.dox

    r201 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4444while a quoted token is a
    4545character sequence surrounded by double quotes, and it can also
    46 contain whitespaces and escape sequences. 
     46contain whitespaces and escape sequences.
    4747
    4848The \c \@nodes section describes a set of nodes and associated
     
    7373\code
    7474 @arcs
    75               capacity
     75               capacity
    7676 1   2   16
    7777 1   3   12
  • doc/license.dox

    r40 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • doc/mainpage.dox

    r40 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4242\subsection howtoread How to read the documentation
    4343
    44 If you want to get a quick start and see the most important features then 
     44If you want to get a quick start and see the most important features then
    4545take a look at our \ref quicktour
    4646"Quick Tour to LEMON" which will guide you along.
    4747
    48 If you already feel like using our library, see the page that tells you 
     48If you already feel like using our library, see the page that tells you
    4949\ref getstart "How to start using LEMON".
    5050
    51 If you 
    52 want to see how LEMON works, see 
     51If you
     52want to see how LEMON works, see
    5353some \ref demoprograms "demo programs"!
    5454
  • doc/namespaces.dox

    r40 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • doc/template.h

    r40 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • lemon/arg_parser.cc

    r137 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3939    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
    4040      if(i->second.self_delete)
    41         switch(i->second.type) {
    42         case BOOL:
    43           delete i->second.bool_p;
    44           break;
    45         case STRING:
    46           delete i->second.string_p;
    47           break;
    48         case DOUBLE:
    49           delete i->second.double_p;
    50           break;
    51         case INTEGER:
    52           delete i->second.int_p;
    53           break;
    54         case UNKNOWN:
    55           break;
    56         case FUNC:
    57           break;
    58         }
    59   }
    60  
     41        switch(i->second.type) {
     42        case BOOL:
     43          delete i->second.bool_p;
     44          break;
     45        case STRING:
     46          delete i->second.string_p;
     47          break;
     48        case DOUBLE:
     49          delete i->second.double_p;
     50          break;
     51        case INTEGER:
     52          delete i->second.int_p;
     53          break;
     54        case UNKNOWN:
     55          break;
     56        case FUNC:
     57          break;
     58        }
     59  }
     60
    6161
    6262  ArgParser &ArgParser::intOption(const std::string &name,
    63                                const std::string &help,
    64                                int value, bool obl)
     63                               const std::string &help,
     64                               int value, bool obl)
    6565  {
    6666    ParData p;
     
    7575
    7676  ArgParser &ArgParser::doubleOption(const std::string &name,
    77                                const std::string &help,
    78                                double value, bool obl)
     77                               const std::string &help,
     78                               double value, bool obl)
    7979  {
    8080    ParData p;
     
    8989
    9090  ArgParser &ArgParser::boolOption(const std::string &name,
    91                                const std::string &help,
    92                                bool value, bool obl)
     91                               const std::string &help,
     92                               bool value, bool obl)
    9393  {
    9494    ParData p;
     
    103103
    104104  ArgParser &ArgParser::stringOption(const std::string &name,
    105                                const std::string &help,
    106                                std::string value, bool obl)
     105                               const std::string &help,
     106                               std::string value, bool obl)
    107107  {
    108108    ParData p;
     
    117117
    118118  ArgParser &ArgParser::refOption(const std::string &name,
    119                                const std::string &help,
    120                                int &ref, bool obl)
     119                               const std::string &help,
     120                               int &ref, bool obl)
    121121  {
    122122    ParData p;
     
    162162
    163163  ArgParser &ArgParser::refOption(const std::string &name,
    164                                const std::string &help,
    165                                std::string &ref, bool obl)
     164                               const std::string &help,
     165                               std::string &ref, bool obl)
    166166  {
    167167    ParData p;
     
    176176
    177177  ArgParser &ArgParser::funcOption(const std::string &name,
    178                                const std::string &help,
    179                                void (*func)(void *),void *data)
     178                               const std::string &help,
     179                               void (*func)(void *),void *data)
    180180  {
    181181    ParData p;
     
    191191
    192192  ArgParser &ArgParser::optionGroup(const std::string &group,
    193                                     const std::string &opt)
     193                                    const std::string &opt)
    194194  {
    195195    Opts::iterator i = _opts.find(opt);
    196196    LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'");
    197     LEMON_ASSERT(!(i->second.ingroup), 
     197    LEMON_ASSERT(!(i->second.ingroup),
    198198                 "Option already in option group: '"+opt+"'");
    199199    GroupData &g=_groups[group];
     
    211211
    212212  ArgParser &ArgParser::synonym(const std::string &syn,
    213                                 const std::string &opt)
     213                                const std::string &opt)
    214214  {
    215215    Opts::iterator o = _opts.find(opt);
     
    234234
    235235  ArgParser &ArgParser::other(const std::string &name,
    236                               const std::string &help)
     236                              const std::string &help)
    237237  {
    238238    _others_help.push_back(OtherArg(name,help));
     
    245245    if(i->second.has_syn)
    246246      for(Opts::iterator j=_opts.begin();j!=_opts.end();++j)
    247         if(j->second.syn&&j->second.help==i->first)
    248           os << "|-" << j->first;
     247        if(j->second.syn&&j->second.help==i->first)
     248          os << "|-" << j->first;
    249249    switch(i->second.type) {
    250250    case STRING:
     
    271271    }
    272272  }
    273    
     273
    274274  void ArgParser::showHelp(Opts::iterator i)
    275275  {
     
    284284    if(i->help.size()==0) return;
    285285    std::cerr << "  " << i->name << std::endl
    286               << "     " << i->help << std::endl;
    287   }
    288    
     286              << "     " << i->help << std::endl;
     287  }
     288
    289289  void ArgParser::shortHelp()
    290290  {
     
    300300      if(!g->second.mandatory) cstr << ']';
    301301      if(pos+cstr.str().size()>LINE_LEN) {
    302         std::cerr << std::endl << indent;
    303         pos=indent.size();
     302        std::cerr << std::endl << indent;
     303        pos=indent.size();
    304304      }
    305305      std::cerr << cstr.str();
     
    308308    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
    309309      if(!i->second.ingroup&&!i->second.syn) {
    310         std::ostringstream cstr;
    311         cstr << ' ';
    312         if(!i->second.mandatory) cstr << '[';
    313         show(cstr,i);
    314         if(!i->second.mandatory) cstr << ']';
    315         if(pos+cstr.str().size()>LINE_LEN) {
    316           std::cerr << std::endl << indent;
    317           pos=indent.size();
    318         }
    319         std::cerr << cstr.str();
    320         pos+=cstr.str().size();
     310        std::ostringstream cstr;
     311        cstr << ' ';
     312        if(!i->second.mandatory) cstr << '[';
     313        show(cstr,i);
     314        if(!i->second.mandatory) cstr << ']';
     315        if(pos+cstr.str().size()>LINE_LEN) {
     316          std::cerr << std::endl << indent;
     317          pos=indent.size();
     318        }
     319        std::cerr << cstr.str();
     320        pos+=cstr.str().size();
    321321      }
    322322    for(std::vector<OtherArg>::iterator i=_others_help.begin();
    323         i!=_others_help.end();++i)
     323        i!=_others_help.end();++i)
    324324      {
    325         std::ostringstream cstr;
    326         cstr << ' ' << i->name;
    327      
    328         if(pos+cstr.str().size()>LINE_LEN) {
    329           std::cerr << std::endl << indent;
    330           pos=indent.size();
    331         }
    332         std::cerr << cstr.str();
    333         pos+=cstr.str().size();
     325        std::ostringstream cstr;
     326        cstr << ' ' << i->name;
     327
     328        if(pos+cstr.str().size()>LINE_LEN) {
     329          std::cerr << std::endl << indent;
     330          pos=indent.size();
     331        }
     332        std::cerr << cstr.str();
     333        pos+=cstr.str().size();
    334334      }
    335335    std::cerr << std::endl;
    336336  }
    337    
     337
    338338  void ArgParser::showHelp()
    339339  {
     
    341341    std::cerr << "Where:\n";
    342342    for(std::vector<OtherArg>::iterator i=_others_help.begin();
    343         i!=_others_help.end();++i) showHelp(i);
     343        i!=_others_help.end();++i) showHelp(i);
    344344    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
    345345    exit(1);
    346346  }
    347    
    348      
    349   void ArgParser::unknownOpt(std::string arg) 
     347
     348
     349  void ArgParser::unknownOpt(std::string arg)
    350350  {
    351351    std::cerr << "\nUnknown option: " << arg << "\n";
     
    354354    exit(1);
    355355  }
    356    
    357   void ArgParser::requiresValue(std::string arg, OptType t) 
     356
     357  void ArgParser::requiresValue(std::string arg, OptType t)
    358358  {
    359359    std::cerr << "Argument '" << arg << "' requires a";
     
    374374    showHelp();
    375375  }
    376    
     376
    377377
    378378  void ArgParser::checkMandatories()
     
    380380    bool ok=true;
    381381    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
    382       if(i->second.mandatory&&!i->second.set) 
    383         {
    384           if(ok)
    385             std::cerr << _command_name
    386                       << ": The following mandatory arguments are missing.\n";
    387           ok=false;
    388           showHelp(i);
    389         }
     382      if(i->second.mandatory&&!i->second.set)
     383        {
     384          if(ok)
     385            std::cerr << _command_name
     386                      << ": The following mandatory arguments are missing.\n";
     387          ok=false;
     388          showHelp(i);
     389        }
    390390    for(Groups::iterator i=_groups.begin();i!=_groups.end();++i)
    391391      if(i->second.mandatory||i->second.only_one)
    392         {
    393           int set=0;
    394           for(GroupData::Opts::iterator o=i->second.opts.begin();
    395               o!=i->second.opts.end();++o)
    396             if(_opts.find(*o)->second.set) ++set;
    397           if(i->second.mandatory&&!set) {
    398             std::cerr << _command_name
    399                       << ": At least one of the following arguments is mandatory.\n";
    400             ok=false;
    401             for(GroupData::Opts::iterator o=i->second.opts.begin();
    402                 o!=i->second.opts.end();++o)
    403               showHelp(_opts.find(*o));
    404           }
    405           if(i->second.only_one&&set>1) {
    406             std::cerr << _command_name
    407                       << ": At most one of the following arguments can be given.\n";
    408             ok=false;
    409             for(GroupData::Opts::iterator o=i->second.opts.begin();
    410                 o!=i->second.opts.end();++o)
    411               showHelp(_opts.find(*o));
    412           }
    413         }
     392        {
     393          int set=0;
     394          for(GroupData::Opts::iterator o=i->second.opts.begin();
     395              o!=i->second.opts.end();++o)
     396            if(_opts.find(*o)->second.set) ++set;
     397          if(i->second.mandatory&&!set) {
     398            std::cerr << _command_name
     399                      << ": At least one of the following arguments is mandatory.\n";
     400            ok=false;
     401            for(GroupData::Opts::iterator o=i->second.opts.begin();
     402                o!=i->second.opts.end();++o)
     403              showHelp(_opts.find(*o));
     404          }
     405          if(i->second.only_one&&set>1) {
     406            std::cerr << _command_name
     407                      << ": At most one of the following arguments can be given.\n";
     408            ok=false;
     409            for(GroupData::Opts::iterator o=i->second.opts.begin();
     410                o!=i->second.opts.end();++o)
     411              showHelp(_opts.find(*o));
     412          }
     413        }
    414414    if(!ok) {
    415415      std::cerr << "\nType '" << _command_name <<
    416         " --help' to obtain a short summary on the usage.\n\n";
     416        " --help' to obtain a short summary on the usage.\n\n";
    417417      exit(1);
    418418    }
     
    424424      std::string arg(_argv[ar]);
    425425      if (arg[0] != '-' || arg.size() == 1) {
    426         _file_args.push_back(arg);
     426        _file_args.push_back(arg);
    427427      }
    428428      else {
    429         Opts::iterator i = _opts.find(arg.substr(1));
    430         if(i==_opts.end()) unknownOpt(arg);
    431         else {
    432           if(i->second.syn) i=_opts.find(i->second.help);
    433           ParData &p(i->second);
    434           if (p.type==BOOL) *p.bool_p=true;
    435           else if (p.type==FUNC) p.func_p.p(p.func_p.data);
    436           else if(++ar==_argc) requiresValue(arg, p.type);
    437           else {
    438             std::string val(_argv[ar]);
    439             std::istringstream vals(val);
    440             switch(p.type) {
    441             case STRING:
    442               *p.string_p=val;
    443               break;
    444             case INTEGER:
    445               vals >> *p.int_p;
    446               break;
    447             case DOUBLE:
    448               vals >> *p.double_p;
    449               break;
    450             default:
    451               break;
    452             }
    453             if(p.type!=STRING&&(!vals||!vals.eof()))
    454               requiresValue(arg, p.type);
    455           }
    456           p.set = true;
    457         }
     429        Opts::iterator i = _opts.find(arg.substr(1));
     430        if(i==_opts.end()) unknownOpt(arg);
     431        else {
     432          if(i->second.syn) i=_opts.find(i->second.help);
     433          ParData &p(i->second);
     434          if (p.type==BOOL) *p.bool_p=true;
     435          else if (p.type==FUNC) p.func_p.p(p.func_p.data);
     436          else if(++ar==_argc) requiresValue(arg, p.type);
     437          else {
     438            std::string val(_argv[ar]);
     439            std::istringstream vals(val);
     440            switch(p.type) {
     441            case STRING:
     442              *p.string_p=val;
     443              break;
     444            case INTEGER:
     445              vals >> *p.int_p;
     446              break;
     447            case DOUBLE:
     448              vals >> *p.double_p;
     449              break;
     450            default:
     451              break;
     452            }
     453            if(p.type!=STRING&&(!vals||!vals.eof()))
     454              requiresValue(arg, p.type);
     455          }
     456          p.set = true;
     457        }
    458458      }
    459459    }
     
    461461
    462462    return *this;
    463   } 
     463  }
    464464
    465465}
  • lemon/arg_parser.h

    r204 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4242  ///For a complete example see the \ref arg_parser_demo.cc demo file.
    4343  class ArgParser {
    44    
     44
    4545    static void _showHelp(void *p);
    4646  protected:
    47    
     47
    4848    int _argc;
    4949    const char **_argv;
    50    
     50
    5151    enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 };
    52    
     52
    5353    class ParData {
    5454    public:
    5555      union {
    56         bool *bool_p;
    57         int *int_p;
    58         double *double_p;
    59         std::string *string_p;
    60         struct {
    61           void (*p)(void *);
    62           void *data;
    63         } func_p;
    64          
     56        bool *bool_p;
     57        int *int_p;
     58        double *double_p;
     59        std::string *string_p;
     60        struct {
     61          void (*p)(void *);
     62          void *data;
     63        } func_p;
     64
    6565      };
    6666      std::string help;
     
    7373      bool self_delete;
    7474      ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false),
    75                   has_syn(false), syn(false), self_delete(false) {}
     75                  has_syn(false), syn(false), self_delete(false) {}
    7676    };
    7777
     
    7979    Opts _opts;
    8080
    81     class GroupData 
     81    class GroupData
    8282    {
    8383    public:
     
    8888      GroupData() :only_one(false), mandatory(false) {}
    8989    };
    90      
     90
    9191    typedef std::map<std::string,GroupData> Groups;
    9292    Groups _groups;
     
    9999
    100100    };
    101      
     101
    102102    std::vector<OtherArg> _others_help;
    103103    std::vector<std::string> _file_args;
    104104    std::string _command_name;
    105105
    106    
     106
    107107  private:
    108108    //Bind a function to an option.
     
    114114    //\param data Data to be passed to \c func
    115115    ArgParser &funcOption(const std::string &name,
    116                     const std::string &help,
    117                     void (*func)(void *),void *data);
    118    
     116                    const std::string &help,
     117                    void (*func)(void *),void *data);
     118
    119119  public:
    120120
     
    137137    ///\param obl Indicate if the option is mandatory.
    138138    ArgParser &intOption(const std::string &name,
    139                     const std::string &help,
    140                     int value=0, bool obl=false);
     139                    const std::string &help,
     140                    int value=0, bool obl=false);
    141141
    142142    ///Add a new floating point type option
     
    148148    ///\param obl Indicate if the option is mandatory.
    149149    ArgParser &doubleOption(const std::string &name,
    150                       const std::string &help,
    151                       double value=0, bool obl=false);
     150                      const std::string &help,
     151                      double value=0, bool obl=false);
    152152
    153153    ///Add a new bool type option
     
    160160    ///\note A mandatory bool obtion is of very little use.
    161161    ArgParser &boolOption(const std::string &name,
    162                       const std::string &help,
    163                       bool value=false, bool obl=false);
     162                      const std::string &help,
     163                      bool value=false, bool obl=false);
    164164
    165165    ///Add a new string type option
     
    171171    ///\param obl Indicate if the option is mandatory.
    172172    ArgParser &stringOption(const std::string &name,
    173                       const std::string &help,
    174                       std::string value="", bool obl=false);
     173                      const std::string &help,
     174                      std::string value="", bool obl=false);
    175175
    176176    ///Give help string for non-parsed arguments.
     
    180180    ///\c help gives a more detailed description.
    181181    ArgParser &other(const std::string &name,
    182                      const std::string &help="");
    183    
     182                     const std::string &help="");
     183
    184184    ///@}
    185185
     
    198198    ///\retval ref The value of the argument will be written to this variable.
    199199    ArgParser &refOption(const std::string &name,
    200                     const std::string &help,
    201                     int &ref, bool obl=false);
     200                    const std::string &help,
     201                    int &ref, bool obl=false);
    202202
    203203    ///Add a new floating type option with a storage reference
     
    209209    ///\retval ref The value of the argument will be written to this variable.
    210210    ArgParser &refOption(const std::string &name,
    211                       const std::string &help,
    212                       double &ref, bool obl=false);
     211                      const std::string &help,
     212                      double &ref, bool obl=false);
    213213
    214214    ///Add a new bool type option with a storage reference
     
    221221    ///\note A mandatory bool obtion is of very little use.
    222222    ArgParser &refOption(const std::string &name,
    223                       const std::string &help,
    224                       bool &ref, bool obl=false);
     223                      const std::string &help,
     224                      bool &ref, bool obl=false);
    225225
    226226    ///Add a new string type option with a storage reference
     
    232232    ///\retval ref The value of the argument will be written to this variable.
    233233    ArgParser &refOption(const std::string &name,
    234                       const std::string &help,
    235                       std::string &ref, bool obl=false);
    236    
     234                      const std::string &help,
     235                      std::string &ref, bool obl=false);
     236
    237237    ///@}
    238238
    239239    ///\name Option Groups and Synonyms
    240240    ///
    241    
     241
    242242    ///@{
    243243
     
    249249    ///\param opt The option name.
    250250    ArgParser &optionGroup(const std::string &group,
    251                            const std::string &opt);
     251                           const std::string &opt);
    252252
    253253    ///Make the members of a group exclusive
     
    256256    ///given at the same time.
    257257    ArgParser &onlyOneGroup(const std::string &group);
    258  
     258
    259259    ///Make a group mandatory
    260260
     
    262262    ///must be given.
    263263    ArgParser &mandatoryGroup(const std::string &group);
    264    
     264
    265265    ///Create synonym to an option
    266266
     
    268268    ///option \c opt.
    269269    ArgParser &synonym(const std::string &syn,
    270                            const std::string &opt);
    271    
     270                           const std::string &opt);
     271
    272272    ///@}
    273273
     
    283283    void requiresValue(std::string arg, OptType t);
    284284    void checkMandatories();
    285    
     285
    286286    ///Start the parsing process
    287287    ArgParser &parse();
    288288
    289289    /// Synonym for parse()
    290     ArgParser &run() 
     290    ArgParser &run()
    291291    {
    292292      return parse();
    293293    }
    294    
     294
    295295    ///Give back the command name (the 0th argument)
    296296    const std::string &commandName() { return _command_name; }
    297297
    298298    ///Check if an opion has been given to the command.
    299     bool given(std::string op) 
     299    bool given(std::string op)
    300300    {
    301301      Opts::iterator i = _opts.find(op);
     
    305305
    306306    ///Magic type for operator[]
    307    
     307
    308308    ///This is the type of the return value of ArgParser::operator[]().
    309309    ///It automatically converts to \c int, \c double, \c bool or
    310310    ///\c std::string if the type of the option matches, otherwise it
    311311    ///throws an exception (i.e. it performs runtime type checking).
    312     class RefType 
     312    class RefType
    313313    {
    314314      ArgParser &_parser;
     
    318318      RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
    319319      ///\e
    320       operator bool() 
     320      operator bool()
    321321      {
    322         Opts::iterator i = _parser._opts.find(_name);
    323         LEMON_ASSERT(i!=_parser._opts.end(),
    324                      std::string()+"Unkown option: '"+_name+"'");
    325         LEMON_ASSERT(i->second.type==ArgParser::BOOL,
    326                      std::string()+"'"+_name+"' is a bool option");
    327         return *(i->second.bool_p);
     322        Opts::iterator i = _parser._opts.find(_name);
     323        LEMON_ASSERT(i!=_parser._opts.end(),
     324                     std::string()+"Unkown option: '"+_name+"'");
     325        LEMON_ASSERT(i->second.type==ArgParser::BOOL,
     326                     std::string()+"'"+_name+"' is a bool option");
     327        return *(i->second.bool_p);
    328328      }
    329329      ///\e
    330330      operator std::string()
    331331      {
    332         Opts::iterator i = _parser._opts.find(_name);
    333         LEMON_ASSERT(i!=_parser._opts.end(),
    334                      std::string()+"Unkown option: '"+_name+"'");
    335         LEMON_ASSERT(i->second.type==ArgParser::STRING,
    336                      std::string()+"'"+_name+"' is a string option");
    337         return *(i->second.string_p);
     332        Opts::iterator i = _parser._opts.find(_name);
     333        LEMON_ASSERT(i!=_parser._opts.end(),
     334                     std::string()+"Unkown option: '"+_name+"'");
     335        LEMON_ASSERT(i->second.type==ArgParser::STRING,
     336                     std::string()+"'"+_name+"' is a string option");
     337        return *(i->second.string_p);
    338338      }
    339339      ///\e
    340       operator double() 
     340      operator double()
    341341      {
    342         Opts::iterator i = _parser._opts.find(_name);
    343         LEMON_ASSERT(i!=_parser._opts.end(),
    344                      std::string()+"Unkown option: '"+_name+"'");
    345         LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
    346                      i->second.type==ArgParser::INTEGER,
    347                      std::string()+"'"+_name+"' is a floating point option");
    348         return i->second.type==ArgParser::DOUBLE ?
    349           *(i->second.double_p) : *(i->second.int_p);
     342        Opts::iterator i = _parser._opts.find(_name);
     343        LEMON_ASSERT(i!=_parser._opts.end(),
     344                     std::string()+"Unkown option: '"+_name+"'");
     345        LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
     346                     i->second.type==ArgParser::INTEGER,
     347                     std::string()+"'"+_name+"' is a floating point option");
     348        return i->second.type==ArgParser::DOUBLE ?
     349          *(i->second.double_p) : *(i->second.int_p);
    350350      }
    351351      ///\e
    352       operator int() 
     352      operator int()
    353353      {
    354         Opts::iterator i = _parser._opts.find(_name);
    355         LEMON_ASSERT(i!=_parser._opts.end(),
    356                      std::string()+"Unkown option: '"+_name+"'");
    357         LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
    358                      std::string()+"'"+_name+"' is an integer option");
    359         return *(i->second.int_p);
     354        Opts::iterator i = _parser._opts.find(_name);
     355        LEMON_ASSERT(i!=_parser._opts.end(),
     356                     std::string()+"Unkown option: '"+_name+"'");
     357        LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
     358                     std::string()+"'"+_name+"' is an integer option");
     359        return *(i->second.int_p);
    360360      }
    361361
     
    363363
    364364    ///Give back the value of an option
    365    
     365
    366366    ///Give back the value of an option.
    367367    ///\sa RefType
     
    369369    {
    370370      return RefType(*this, n);
    371     }   
     371    }
    372372
    373373    ///Give back the non-option type arguments.
     
    376376    ///not starting with a '-' character.
    377377    std::vector<std::string> &files() { return _file_args; }
    378  
     378
    379379  };
    380380}
  • lemon/assert.h

    r142 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2929
    3030  inline void assert_fail_log(const char *file, int line, const char *function,
    31                               const char *message, const char *assertion)
     31                              const char *message, const char *assertion)
    3232  {
    3333    std::cerr << file << ":" << line << ": ";
     
    4141
    4242  inline void assert_fail_abort(const char *file, int line,
    43                                 const char *function, const char* message,
    44                                 const char *assertion)
     43                                const char *function, const char* message,
     44                                const char *assertion)
    4545  {
    4646    assert_fail_log(file, line, function, message, assertion);
     
    4949
    5050  namespace _assert_bits {
    51    
    52    
     51
     52
    5353    inline const char* cstringify(const std::string& str) {
    5454      return str.c_str();
     
    5757    inline const char* cstringify(const char* str) {
    5858      return str;
    59     }   
     59    }
    6060  }
    6161}
     
    6767#undef LEMON_DEBUG
    6868
    69 #if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +               \
    70   (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
     69#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) +                \
     70  (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +                \
    7171  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
    7272#error "LEMON assertion system is not set properly"
    7373#endif
    7474
    75 #if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +              \
    76      (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
    77      (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
    78      defined(LEMON_ENABLE_ASSERTS)) &&                  \
    79   (defined(LEMON_DISABLE_ASSERTS) ||                    \
     75#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) +                \
     76     (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +                \
     77     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||        \
     78     defined(LEMON_ENABLE_ASSERTS)) &&                        \
     79  (defined(LEMON_DISABLE_ASSERTS) ||                        \
    8080   defined(NDEBUG))
    8181#error "LEMON assertion system is not set properly"
     
    137137/// \endcode
    138138/// The checking is also disabled when the standard macro \c NDEBUG is defined.
    139 /// 
     139///
    140140/// The LEMON assertion system has a wide range of customization
    141141/// properties. As a default behaviour the failed assertion prints a
    142142/// short log message to the standard error and aborts the execution.
    143143///
    144 /// The following modes can be used in the assertion system: 
     144/// The following modes can be used in the assertion system:
    145145///
    146146/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
     
    156156///   \endcode
    157157///   The name of the function should be defined as the \c
    158 ///   LEMON_CUSTOM_ASSERT_HANDLER macro name. 
     158///   LEMON_CUSTOM_ASSERT_HANDLER macro name.
    159159///   \code
    160160///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
     
    167167/// \ref lemon/assert.h "assert.h" file is reincluded, then the
    168168/// behaviour is changed appropiately to the new settings.
    169 #  define LEMON_ASSERT(exp, msg)                                        \
    170   (static_cast<void> (!!(exp) ? 0 : (                                   \
    171     LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
    172                          LEMON_FUNCTION_NAME,                           \
    173                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
     169#  define LEMON_ASSERT(exp, msg)                                        \
     170  (static_cast<void> (!!(exp) ? 0 : (                                        \
     171    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                                \
     172                         LEMON_FUNCTION_NAME,                                \
     173                        ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
    174174
    175175/// \ingroup exceptions
     
    183183/// \endcode
    184184///
    185 /// \see LEMON_ASSERT 
    186 #  define LEMON_FIXME(msg)                                              \
    187   (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
    188                         ::lemon::_assert_bits::cstringify(msg),         \
    189                         static_cast<const char*>(0)))
     185/// \see LEMON_ASSERT
     186#  define LEMON_FIXME(msg)                                                \
     187  (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
     188                        ::lemon::_assert_bits::cstringify(msg),                \
     189                        static_cast<const char*>(0)))
    190190
    191191/// \ingroup exceptions
     
    211211/// macro.
    212212///
    213 /// \see LEMON_ASSERT 
    214 #  define LEMON_DEBUG(exp, msg)                                         \
    215   (static_cast<void> (!!(exp) ? 0 : (                                   \
     213/// \see LEMON_ASSERT
     214#  define LEMON_DEBUG(exp, msg)                                                \
     215  (static_cast<void> (!!(exp) ? 0 : (                                        \
    216216    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
    217                          LEMON_FUNCTION_NAME,                           \
    218                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
     217                         LEMON_FUNCTION_NAME,                                \
     218                        ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
    219219
    220220#else
     
    225225#    define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
    226226#  else
    227 #    define LEMON_ASSERT(exp, msg)                                      \
    228        (static_cast<void> (!!(exp) ? 0 : (                              \
     227#    define LEMON_ASSERT(exp, msg)                                        \
     228       (static_cast<void> (!!(exp) ? 0 : (                                \
    229229        LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                        \
    230                              LEMON_FUNCTION_NAME,                       \
    231                              ::lemon::_assert_bits::cstringify(msg),    \
    232                              #exp), 0)))
    233 #    define LEMON_FIXME(msg)                                            \
    234        (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,   \
    235                              ::lemon::_assert_bits::cstringify(msg),    \
    236                              static_cast<const char*>(0)))
     230                             LEMON_FUNCTION_NAME,                        \
     231                             ::lemon::_assert_bits::cstringify(msg),        \
     232                             #exp), 0)))
     233#    define LEMON_FIXME(msg)                                                \
     234       (LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME,        \
     235                             ::lemon::_assert_bits::cstringify(msg),        \
     236                             static_cast<const char*>(0)))
    237237
    238238#    if LEMON_ENABLE_DEBUG
     
    241241           LEMON_ASSERT_HANDLER(__FILE__, __LINE__,  \
    242242                                LEMON_FUNCTION_NAME, \
    243                                 ::lemon::_assert_bits::cstringify(msg), \
    244                                 #exp), 0)))
     243                                ::lemon::_assert_bits::cstringify(msg),        \
     244                                #exp), 0)))
    245245#    else
    246246#      define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
  • lemon/base.cc

    r49 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • lemon/bfs.h

    r158 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434
    3535
    36  
     36
    3737  ///Default traits class of Bfs class.
    3838
     
    4242  struct BfsDefaultTraits
    4343  {
    44     ///The digraph type the algorithm runs on. 
     44    ///The digraph type the algorithm runs on.
    4545    typedef GR Digraph;
    4646    ///\brief The type of the map that stores the last
    4747    ///arcs of the shortest paths.
    48     /// 
     48    ///
    4949    ///The type of the map that stores the last
    5050    ///arcs of the shortest paths.
     
    5353    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
    5454    ///Instantiates a PredMap.
    55  
    56     ///This function instantiates a \ref PredMap. 
     55
     56    ///This function instantiates a \ref PredMap.
    5757    ///\param G is the digraph, to which we would like to define the PredMap.
    5858    ///\todo The digraph alone may be insufficient to initialize
    59     static PredMap *createPredMap(const GR &G) 
     59    static PredMap *createPredMap(const GR &G)
    6060    {
    6161      return new PredMap(G);
    6262    }
    6363    ///The type of the map that indicates which nodes are processed.
    64  
     64
    6565    ///The type of the map that indicates which nodes are processed.
    6666    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    6868    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    6969    ///Instantiates a ProcessedMap.
    70  
    71     ///This function instantiates a \ref ProcessedMap. 
     70
     71    ///This function instantiates a \ref ProcessedMap.
    7272    ///\param g is the digraph, to which
    7373    ///we would like to define the \ref ProcessedMap
     
    8181    }
    8282    ///The type of the map that indicates which nodes are reached.
    83  
     83
    8484    ///The type of the map that indicates which nodes are reached.
    8585    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    8787    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    8888    ///Instantiates a ReachedMap.
    89  
    90     ///This function instantiates a \ref ReachedMap. 
     89
     90    ///This function instantiates a \ref ReachedMap.
    9191    ///\param G is the digraph, to which
    9292    ///we would like to define the \ref ReachedMap.
     
    9696    }
    9797    ///The type of the map that stores the dists of the nodes.
    98  
     98
    9999    ///The type of the map that stores the dists of the nodes.
    100100    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    102102    typedef typename Digraph::template NodeMap<int> DistMap;
    103103    ///Instantiates a DistMap.
    104  
    105     ///This function instantiates a \ref DistMap. 
     104
     105    ///This function instantiates a \ref DistMap.
    106106    ///\param G is the digraph, to which we would like to define the \ref DistMap
    107107    static DistMap *createDistMap(const GR &G)
     
    110110    }
    111111  };
    112  
     112
    113113  ///%BFS algorithm class.
    114  
     114
    115115  ///\ingroup search
    116116  ///This class provides an efficient implementation of the %BFS algorithm.
     
    127127#ifdef DOXYGEN
    128128  template <typename GR,
    129             typename TR>
     129            typename TR>
    130130#else
    131131  template <typename GR=ListDigraph,
    132             typename TR=BfsDefaultTraits<GR> >
     132            typename TR=BfsDefaultTraits<GR> >
    133133#endif
    134134  class Bfs {
     
    143143    public:
    144144      virtual const char* what() const throw() {
    145         return "lemon::Bfs::UninitializedParameter";
     145        return "lemon::Bfs::UninitializedParameter";
    146146      }
    147147    };
     
    150150    ///The type of the underlying digraph.
    151151    typedef typename TR::Digraph Digraph;
    152    
     152
    153153    ///\brief The type of the map that stores the last
    154154    ///arcs of the shortest paths.
     
    191191
    192192    ///Creates the maps if necessary.
    193    
     193
    194194    ///\todo Better memory allocation (instead of new).
    195     void create_maps() 
     195    void create_maps()
    196196    {
    197197      if(!_pred) {
    198         local_pred = true;
    199         _pred = Traits::createPredMap(*G);
     198        local_pred = true;
     199        _pred = Traits::createPredMap(*G);
    200200      }
    201201      if(!_dist) {
    202         local_dist = true;
    203         _dist = Traits::createDistMap(*G);
     202        local_dist = true;
     203        _dist = Traits::createDistMap(*G);
    204204      }
    205205      if(!_reached) {
    206         local_reached = true;
    207         _reached = Traits::createReachedMap(*G);
     206        local_reached = true;
     207        _reached = Traits::createReachedMap(*G);
    208208      }
    209209      if(!_processed) {
    210         local_processed = true;
    211         _processed = Traits::createProcessedMap(*G);
     210        local_processed = true;
     211        _processed = Traits::createProcessedMap(*G);
    212212      }
    213213    }
    214214
    215215  protected:
    216    
     216
    217217    Bfs() {}
    218    
     218
    219219  public:
    220  
     220
    221221    typedef Bfs Create;
    222222
     
    228228    struct DefPredMapTraits : public Traits {
    229229      typedef T PredMap;
    230       static PredMap *createPredMap(const Digraph &) 
     230      static PredMap *createPredMap(const Digraph &)
    231231      {
    232         throw UninitializedParameter();
     232        throw UninitializedParameter();
    233233      }
    234234    };
     
    239239    ///
    240240    template <class T>
    241     struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > { 
     241    struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
    242242      typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
    243243    };
    244    
     244
    245245    template <class T>
    246246    struct DefDistMapTraits : public Traits {
    247247      typedef T DistMap;
    248       static DistMap *createDistMap(const Digraph &) 
     248      static DistMap *createDistMap(const Digraph &)
    249249      {
    250         throw UninitializedParameter();
     250        throw UninitializedParameter();
    251251      }
    252252    };
     
    257257    ///
    258258    template <class T>
    259     struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > { 
     259    struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {
    260260      typedef Bfs< Digraph, DefDistMapTraits<T> > Create;
    261261    };
    262    
     262
    263263    template <class T>
    264264    struct DefReachedMapTraits : public Traits {
    265265      typedef T ReachedMap;
    266       static ReachedMap *createReachedMap(const Digraph &) 
     266      static ReachedMap *createReachedMap(const Digraph &)
    267267      {
    268         throw UninitializedParameter();
     268        throw UninitializedParameter();
    269269      }
    270270    };
     
    275275    ///
    276276    template <class T>
    277     struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > { 
     277    struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {
    278278      typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;
    279279    };
    280    
     280
    281281    template <class T>
    282282    struct DefProcessedMapTraits : public Traits {
    283283      typedef T ProcessedMap;
    284       static ProcessedMap *createProcessedMap(const Digraph &) 
     284      static ProcessedMap *createProcessedMap(const Digraph &)
    285285      {
    286         throw UninitializedParameter();
     286        throw UninitializedParameter();
    287287      }
    288288    };
     
    296296      typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;
    297297    };
    298    
     298
    299299    struct DefDigraphProcessedMapTraits : public Traits {
    300300      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    301       static ProcessedMap *createProcessedMap(const Digraph &G) 
     301      static ProcessedMap *createProcessedMap(const Digraph &G)
    302302      {
    303         return new ProcessedMap(G);
     303        return new ProcessedMap(G);
    304304      }
    305305    };
     
    312312    template <class T>
    313313    struct DefProcessedMapToBeDefaultMap :
    314       public Bfs< Digraph, DefDigraphProcessedMapTraits> { 
     314      public Bfs< Digraph, DefDigraphProcessedMapTraits> {
    315315      typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create;
    316316    };
    317    
     317
    318318    ///@}
    319319
    320   public:     
    321    
     320  public:
     321
    322322    ///Constructor.
    323    
     323
    324324    ///\param _G the digraph the algorithm will run on.
    325325    ///
     
    331331      _processed(NULL), local_processed(false)
    332332    { }
    333    
     333
    334334    ///Destructor.
    335     ~Bfs() 
     335    ~Bfs()
    336336    {
    337337      if(local_pred) delete _pred;
     
    348348    ///automatically allocated map, of course.
    349349    ///\return <tt> (*this) </tt>
    350     Bfs &predMap(PredMap &m) 
     350    Bfs &predMap(PredMap &m)
    351351    {
    352352      if(local_pred) {
    353         delete _pred;
    354         local_pred=false;
     353        delete _pred;
     354        local_pred=false;
    355355      }
    356356      _pred = &m;
     
    365365    ///automatically allocated map, of course.
    366366    ///\return <tt> (*this) </tt>
    367     Bfs &reachedMap(ReachedMap &m) 
     367    Bfs &reachedMap(ReachedMap &m)
    368368    {
    369369      if(local_reached) {
    370         delete _reached;
    371         local_reached=false;
     370        delete _reached;
     371        local_reached=false;
    372372      }
    373373      _reached = &m;
     
    382382    ///automatically allocated map, of course.
    383383    ///\return <tt> (*this) </tt>
    384     Bfs &processedMap(ProcessedMap &m) 
     384    Bfs &processedMap(ProcessedMap &m)
    385385    {
    386386      if(local_processed) {
    387         delete _processed;
    388         local_processed=false;
     387        delete _processed;
     388        local_processed=false;
    389389      }
    390390      _processed = &m;
     
    399399    ///automatically allocated map, of course.
    400400    ///\return <tt> (*this) </tt>
    401     Bfs &distMap(DistMap &m) 
     401    Bfs &distMap(DistMap &m)
    402402    {
    403403      if(local_dist) {
    404         delete _dist;
    405         local_dist=false;
     404        delete _dist;
     405        local_dist=false;
    406406      }
    407407      _dist = &m;
     
    433433      _curr_dist=1;
    434434      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
    435         _pred->set(u,INVALID);
    436         _reached->set(u,false);
    437         _processed->set(u,false);
    438       }
    439     }
    440    
     435        _pred->set(u,INVALID);
     436        _reached->set(u,false);
     437        _processed->set(u,false);
     438      }
     439    }
     440
    441441    ///Adds a new source node.
    442442
     
    446446    {
    447447      if(!(*_reached)[s])
    448         {
    449           _reached->set(s,true);
    450           _pred->set(s,INVALID);
    451           _dist->set(s,0);
    452           _queue[_queue_head++]=s;
    453           _queue_next_dist=_queue_head;
    454         }
    455     }
    456    
     448        {
     449          _reached->set(s,true);
     450          _pred->set(s,INVALID);
     451          _dist->set(s,0);
     452          _queue[_queue_head++]=s;
     453          _queue_next_dist=_queue_head;
     454        }
     455    }
     456
    457457    ///Processes the next node.
    458458
     
    465465    {
    466466      if(_queue_tail==_queue_next_dist) {
    467         _curr_dist++;
    468         _queue_next_dist=_queue_head;
     467        _curr_dist++;
     468        _queue_next_dist=_queue_head;
    469469      }
    470470      Node n=_queue[_queue_tail++];
     
    472472      Node m;
    473473      for(OutArcIt e(*G,n);e!=INVALID;++e)
    474         if(!(*_reached)[m=G->target(e)]) {
    475           _queue[_queue_head++]=m;
    476           _reached->set(m,true);
    477           _pred->set(m,e);
    478           _dist->set(m,_curr_dist);
    479         }
     474        if(!(*_reached)[m=G->target(e)]) {
     475          _queue[_queue_head++]=m;
     476          _reached->set(m,true);
     477          _pred->set(m,e);
     478          _dist->set(m,_curr_dist);
     479        }
    480480      return n;
    481481    }
     
    496496    {
    497497      if(_queue_tail==_queue_next_dist) {
    498         _curr_dist++;
    499         _queue_next_dist=_queue_head;
     498        _curr_dist++;
     499        _queue_next_dist=_queue_head;
    500500      }
    501501      Node n=_queue[_queue_tail++];
     
    503503      Node m;
    504504      for(OutArcIt e(*G,n);e!=INVALID;++e)
    505         if(!(*_reached)[m=G->target(e)]) {
    506           _queue[_queue_head++]=m;
    507           _reached->set(m,true);
    508           _pred->set(m,e);
    509           _dist->set(m,_curr_dist);
     505        if(!(*_reached)[m=G->target(e)]) {
     506          _queue[_queue_head++]=m;
     507          _reached->set(m,true);
     508          _pred->set(m,e);
     509          _dist->set(m,_curr_dist);
    510510          reach = reach || (target == m);
    511         }
     511        }
    512512      return n;
    513513    }
     
    529529    {
    530530      if(_queue_tail==_queue_next_dist) {
    531         _curr_dist++;
    532         _queue_next_dist=_queue_head;
     531        _curr_dist++;
     532        _queue_next_dist=_queue_head;
    533533      }
    534534      Node n=_queue[_queue_tail++];
     
    536536      Node m;
    537537      for(OutArcIt e(*G,n);e!=INVALID;++e)
    538         if(!(*_reached)[m=G->target(e)]) {
    539           _queue[_queue_head++]=m;
    540           _reached->set(m,true);
    541           _pred->set(m,e);
    542           _dist->set(m,_curr_dist);
    543           if (nm[m] && rnode == INVALID) rnode = m;
    544         }
     538        if(!(*_reached)[m=G->target(e)]) {
     539          _queue[_queue_head++]=m;
     540          _reached->set(m,true);
     541          _pred->set(m,e);
     542          _dist->set(m,_curr_dist);
     543          if (nm[m] && rnode == INVALID) rnode = m;
     544        }
    545545      return n;
    546546    }
    547      
     547
    548548    ///Next node to be processed.
    549549
     
    553553    /// empty.
    554554    Node nextNode()
    555     { 
     555    {
    556556      return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID;
    557557    }
    558  
     558
    559559    ///\brief Returns \c false if there are nodes
    560560    ///to be processed in the queue
     
    564564    bool emptyQueue() { return _queue_tail==_queue_head; }
    565565    ///Returns the number of the nodes to be processed.
    566    
     566
    567567    ///Returns the number of the nodes to be processed in the queue.
    568568    int queueSize() { return _queue_head-_queue_tail; }
    569    
     569
    570570    ///Executes the algorithm.
    571571
     
    585585      while ( !emptyQueue() ) processNextNode();
    586586    }
    587    
     587
    588588    ///Executes the algorithm until \c dest is reached.
    589589
     
    603603      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    604604    }
    605    
     605
    606606    ///Executes the algorithm until a condition is met.
    607607
     
    622622      Node rnode = INVALID;
    623623      while ( !emptyQueue() && rnode == INVALID ) {
    624         processNextNode(nm, rnode);
     624        processNextNode(nm, rnode);
    625625      }
    626626      return rnode;
    627627    }
    628    
     628
    629629    ///Runs %BFS algorithm from node \c s.
    630    
     630
    631631    ///This method runs the %BFS algorithm from a root node \c s
    632632    ///in order to
     
    647647      start();
    648648    }
    649    
     649
    650650    ///Finds the shortest path between \c s and \c t.
    651    
     651
    652652    ///Finds the shortest path between \c s and \c t.
    653653    ///
     
    667667      return reached(t) ? _curr_dist : 0;
    668668    }
    669    
     669
    670670    ///@}
    671671
     
    675675    ///Before the use of these functions,
    676676    ///either run() or start() must be calleb.
    677    
     677
    678678    ///@{
    679679
     
    681681
    682682    ///Gives back the shortest path.
    683    
     683
    684684    ///Gives back the shortest path.
    685685    ///\pre The \c t should be reachable from the source.
    686     Path path(Node t) 
     686    Path path(Node t)
    687687    {
    688688      return Path(*G, *_pred, t);
     
    723723    ///using this function.
    724724    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
    725                                   G->source((*_pred)[v]); }
    726    
     725                                  G->source((*_pred)[v]); }
     726
    727727    ///Returns a reference to the NodeMap of distances.
    728728
     
    731731    ///be called before using this function.
    732732    const DistMap &distMap() const { return *_dist;}
    733  
     733
    734734    ///Returns a reference to the shortest path tree map.
    735735
     
    739739    ///must be called before using this function.
    740740    const PredMap &predMap() const { return *_pred;}
    741  
     741
    742742    ///Checks if a node is reachable from the root.
    743743
     
    748748    ///
    749749    bool reached(Node v) { return (*_reached)[v]; }
    750    
     750
    751751    ///@}
    752752  };
     
    759759  struct BfsWizardDefaultTraits
    760760  {
    761     ///The digraph type the algorithm runs on. 
     761    ///The digraph type the algorithm runs on.
    762762    typedef GR Digraph;
    763763    ///\brief The type of the map that stores the last
    764764    ///arcs of the shortest paths.
    765     /// 
     765    ///
    766766    ///The type of the map that stores the last
    767767    ///arcs of the shortest paths.
     
    770770    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
    771771    ///Instantiates a PredMap.
    772  
    773     ///This function instantiates a \ref PredMap. 
     772
     773    ///This function instantiates a \ref PredMap.
    774774    ///\param g is the digraph, to which we would like to define the PredMap.
    775775    ///\todo The digraph alone may be insufficient to initialize
    776776#ifdef DOXYGEN
    777     static PredMap *createPredMap(const GR &g) 
     777    static PredMap *createPredMap(const GR &g)
    778778#else
    779     static PredMap *createPredMap(const GR &) 
     779    static PredMap *createPredMap(const GR &)
    780780#endif
    781781    {
     
    784784
    785785    ///The type of the map that indicates which nodes are processed.
    786  
     786
    787787    ///The type of the map that indicates which nodes are processed.
    788788    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    790790    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    791791    ///Instantiates a ProcessedMap.
    792  
    793     ///This function instantiates a \ref ProcessedMap. 
     792
     793    ///This function instantiates a \ref ProcessedMap.
    794794    ///\param g is the digraph, to which
    795795    ///we would like to define the \ref ProcessedMap
     
    803803    }
    804804    ///The type of the map that indicates which nodes are reached.
    805  
     805
    806806    ///The type of the map that indicates which nodes are reached.
    807807    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    809809    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    810810    ///Instantiates a ReachedMap.
    811  
    812     ///This function instantiates a \ref ReachedMap. 
     811
     812    ///This function instantiates a \ref ReachedMap.
    813813    ///\param G is the digraph, to which
    814814    ///we would like to define the \ref ReachedMap.
     
    818818    }
    819819    ///The type of the map that stores the dists of the nodes.
    820  
     820
    821821    ///The type of the map that stores the dists of the nodes.
    822822    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    824824    typedef NullMap<typename Digraph::Node,int> DistMap;
    825825    ///Instantiates a DistMap.
    826  
    827     ///This function instantiates a \ref DistMap. 
     826
     827    ///This function instantiates a \ref DistMap.
    828828    ///\param g is the digraph, to which we would like to define the \ref DistMap
    829829#ifdef DOXYGEN
     
    836836    }
    837837  };
    838  
     838
    839839  /// Default traits used by \ref BfsWizard
    840840
     
    866866    ///Pointer to the source node.
    867867    Node _source;
    868    
     868
    869869    public:
    870870    /// Constructor.
    871    
     871
    872872    /// This constructor does not require parameters, therefore it initiates
    873873    /// all of the attributes to default values (0, INVALID).
    874874    BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    875                            _dist(0), _source(INVALID) {}
     875                           _dist(0), _source(INVALID) {}
    876876
    877877    /// Constructor.
    878    
     878
    879879    /// This constructor requires some parameters,
    880880    /// listed in the parameters list.
     
    883883    /// \param s is the initial value of  \ref _source
    884884    BfsWizardBase(const GR &g, Node s=INVALID) :
    885       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
     885      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    886886      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
    887887
    888888  };
    889  
     889
    890890  /// A class to make the usage of Bfs algorithm easier
    891891
     
    922922    //\e
    923923    typedef typename Digraph::OutArcIt OutArcIt;
    924    
     924
    925925    ///\brief The type of the map that stores
    926926    ///the reached nodes
     
    952952
    953953    ///Runs Bfs algorithm from a given node.
    954    
     954
    955955    ///Runs Bfs algorithm from a given node.
    956956    ///The node can be given by the \ref source function.
     
    960960      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    961961      if(Base::_reached)
    962         alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    963       if(Base::_processed) 
     962        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
     963      if(Base::_processed)
    964964        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    965       if(Base::_pred) 
     965      if(Base::_pred)
    966966        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    967       if(Base::_dist) 
     967      if(Base::_dist)
    968968        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    969969      alg.run(Base::_source);
     
    986986      DefPredMapBase(const TR &b) : TR(b) {}
    987987    };
    988    
     988
    989989    ///\brief \ref named-templ-param "Named parameter"
    990990    ///function for setting PredMap
     
    994994    ///
    995995    template<class T>
    996     BfsWizard<DefPredMapBase<T> > predMap(const T &t) 
     996    BfsWizard<DefPredMapBase<T> > predMap(const T &t)
    997997    {
    998998      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    999999      return BfsWizard<DefPredMapBase<T> >(*this);
    10001000    }
    1001    
    1002  
     1001
     1002
    10031003    template<class T>
    10041004    struct DefReachedMapBase : public Base {
     
    10071007      DefReachedMapBase(const TR &b) : TR(b) {}
    10081008    };
    1009    
     1009
    10101010    ///\brief \ref named-templ-param "Named parameter"
    10111011    ///function for setting ReachedMap
     
    10151015    ///
    10161016    template<class T>
    1017     BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
     1017    BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
    10181018    {
    10191019      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    10201020      return BfsWizard<DefReachedMapBase<T> >(*this);
    10211021    }
    1022    
     1022
    10231023
    10241024    template<class T>
     
    10281028      DefProcessedMapBase(const TR &b) : TR(b) {}
    10291029    };
    1030    
     1030
    10311031    ///\brief \ref named-templ-param "Named parameter"
    10321032    ///function for setting ProcessedMap
     
    10361036    ///
    10371037    template<class T>
    1038     BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
     1038    BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
    10391039    {
    10401040      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    10411041      return BfsWizard<DefProcessedMapBase<T> >(*this);
    10421042    }
    1043    
    1044    
     1043
     1044
    10451045    template<class T>
    10461046    struct DefDistMapBase : public Base {
     
    10491049      DefDistMapBase(const TR &b) : TR(b) {}
    10501050    };
    1051    
     1051
    10521052    ///\brief \ref named-templ-param "Named parameter"
    10531053    ///function for setting DistMap type
     
    10571057    ///
    10581058    template<class T>
    1059     BfsWizard<DefDistMapBase<T> > distMap(const T &t) 
     1059    BfsWizard<DefDistMapBase<T> > distMap(const T &t)
    10601060    {
    10611061      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    10621062      return BfsWizard<DefDistMapBase<T> >(*this);
    10631063    }
    1064    
     1064
    10651065    /// Sets the source node, from which the Bfs algorithm runs.
    10661066
    10671067    /// Sets the source node, from which the Bfs algorithm runs.
    10681068    /// \param s is the source node.
    1069     BfsWizard<TR> &source(Node s) 
     1069    BfsWizard<TR> &source(Node s)
    10701070    {
    10711071      Base::_source=s;
    10721072      return *this;
    10731073    }
    1074    
     1074
    10751075  };
    1076  
     1076
    10771077  ///Function type interface for Bfs algorithm.
    10781078
     
    11011101#ifdef DOXYGEN
    11021102  /// \brief Visitor class for bfs.
    1103   /// 
     1103  ///
    11041104  /// This class defines the interface of the BfsVisit events, and
    11051105  /// it could be the base of a real Visitor class.
     
    11101110    typedef typename Digraph::Node Node;
    11111111    /// \brief Called when the arc reach a node.
    1112     /// 
     1112    ///
    11131113    /// It is called when the bfs find an arc which target is not
    11141114    /// reached yet.
    11151115    void discover(const Arc& arc) {}
    11161116    /// \brief Called when the node reached first time.
    1117     /// 
     1117    ///
    11181118    /// It is Called when the node reached first time.
    11191119    void reach(const Node& node) {}
    1120     /// \brief Called when the arc examined but target of the arc 
     1120    /// \brief Called when the arc examined but target of the arc
    11211121    /// already discovered.
    1122     /// 
    1123     /// It called when the arc examined but the target of the arc 
     1122    ///
     1123    /// It called when the arc examined but the target of the arc
    11241124    /// already discovered.
    11251125    void examine(const Arc& arc) {}
    11261126    /// \brief Called for the source node of the bfs.
    1127     /// 
     1127    ///
    11281128    /// It is called for the source node of the bfs.
    11291129    void start(const Node& node) {}
    11301130    /// \brief Called when the node processed.
    1131     /// 
     1131    ///
    11321132    /// It is Called when the node processed.
    11331133    void process(const Node& node) {}
     
    11481148    struct Constraints {
    11491149      void constraints() {
    1150         Arc arc;
    1151         Node node;
    1152         visitor.discover(arc);
    1153         visitor.reach(node);
    1154         visitor.examine(arc);
    1155         visitor.start(node);
     1150        Arc arc;
     1151        Node node;
     1152        visitor.discover(arc);
     1153        visitor.reach(node);
     1154        visitor.examine(arc);
     1155        visitor.start(node);
    11561156        visitor.process(node);
    11571157      }
     
    11681168  struct BfsVisitDefaultTraits {
    11691169
    1170     /// \brief The digraph type the algorithm runs on. 
     1170    /// \brief The digraph type the algorithm runs on.
    11711171    typedef _Digraph Digraph;
    11721172
    11731173    /// \brief The type of the map that indicates which nodes are reached.
    1174     /// 
     1174    ///
    11751175    /// The type of the map that indicates which nodes are reached.
    11761176    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    11801180    /// \brief Instantiates a ReachedMap.
    11811181    ///
    1182     /// This function instantiates a \ref ReachedMap. 
     1182    /// This function instantiates a \ref ReachedMap.
    11831183    /// \param digraph is the digraph, to which
    11841184    /// we would like to define the \ref ReachedMap.
     
    11901190
    11911191  /// \ingroup search
    1192   /// 
     1192  ///
    11931193  /// \brief %BFS Visit algorithm class.
    1194   /// 
     1194  ///
    11951195  /// This class provides an efficient implementation of the %BFS algorithm
    11961196  /// with visitor interface.
     
    11981198  /// The %BfsVisit class provides an alternative interface to the Bfs
    11991199  /// class. It works with callback mechanism, the BfsVisit object calls
    1200   /// on every bfs event the \c Visitor class member functions. 
     1200  /// on every bfs event the \c Visitor class member functions.
    12011201  ///
    12021202  /// \tparam _Digraph The digraph type the algorithm runs on. The default value is
    12031203  /// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it
    12041204  /// is only passed to \ref BfsDefaultTraits.
    1205   /// \tparam _Visitor The Visitor object for the algorithm. The 
     1205  /// \tparam _Visitor The Visitor object for the algorithm. The
    12061206  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which
    12071207  /// does not observe the Bfs events. If you want to observe the bfs
    12081208  /// events you should implement your own Visitor class.
    1209   /// \tparam _Traits Traits class to set various data types used by the 
     1209  /// \tparam _Traits Traits class to set various data types used by the
    12101210  /// algorithm. The default traits class is
    12111211  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
     
    12161216#else
    12171217  template <typename _Digraph = ListDigraph,
    1218             typename _Visitor = BfsVisitor<_Digraph>,
    1219             typename _Traits = BfsDefaultTraits<_Digraph> >
     1218            typename _Visitor = BfsVisitor<_Digraph>,
     1219            typename _Traits = BfsDefaultTraits<_Digraph> >
    12201220#endif
    12211221  class BfsVisit {
    12221222  public:
    1223    
     1223
    12241224    /// \brief \ref Exception for uninitialized parameters.
    12251225    ///
     
    12281228    class UninitializedParameter : public lemon::UninitializedParameter {
    12291229    public:
    1230       virtual const char* what() const throw() 
     1230      virtual const char* what() const throw()
    12311231      {
    1232         return "lemon::BfsVisit::UninitializedParameter";
     1232        return "lemon::BfsVisit::UninitializedParameter";
    12331233      }
    12341234    };
     
    12671267    void create_maps() {
    12681268      if(!_reached) {
    1269         local_reached = true;
    1270         _reached = Traits::createReachedMap(*_digraph);
     1269        local_reached = true;
     1270        _reached = Traits::createReachedMap(*_digraph);
    12711271      }
    12721272    }
     
    12751275
    12761276    BfsVisit() {}
    1277    
     1277
    12781278  public:
    12791279
     
    12871287      typedef T ReachedMap;
    12881288      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1289         throw UninitializedParameter();
    1290       }
    1291     };
    1292     /// \brief \ref named-templ-param "Named parameter" for setting 
     1289        throw UninitializedParameter();
     1290      }
     1291    };
     1292    /// \brief \ref named-templ-param "Named parameter" for setting
    12931293    /// ReachedMap type
    12941294    ///
     
    12961296    template <class T>
    12971297    struct DefReachedMap : public BfsVisit< Digraph, Visitor,
    1298                                             DefReachedMapTraits<T> > {
     1298                                            DefReachedMapTraits<T> > {
    12991299      typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
    13001300    };
    13011301    ///@}
    13021302
    1303   public:     
    1304    
     1303  public:
     1304
    13051305    /// \brief Constructor.
    13061306    ///
     
    13101310    /// \param visitor The visitor of the algorithm.
    13111311    ///
    1312     BfsVisit(const Digraph& digraph, Visitor& visitor) 
     1312    BfsVisit(const Digraph& digraph, Visitor& visitor)
    13131313      : _digraph(&digraph), _visitor(&visitor),
    1314         _reached(0), local_reached(false) {}
    1315    
     1314        _reached(0), local_reached(false) {}
     1315
    13161316    /// \brief Destructor.
    13171317    ///
     
    13301330    BfsVisit &reachedMap(ReachedMap &m) {
    13311331      if(local_reached) {
    1332         delete _reached;
    1333         local_reached = false;
     1332        delete _reached;
     1333        local_reached = false;
    13341334      }
    13351335      _reached = &m;
     
    13581358      _list_front = _list_back = -1;
    13591359      for (NodeIt u(*_digraph) ; u != INVALID ; ++u) {
    1360         _reached->set(u, false);
    1361       }
    1362     }
    1363    
     1360        _reached->set(u, false);
     1361      }
     1362    }
     1363
    13641364    /// \brief Adds a new source node.
    13651365    ///
     
    13671367    void addSource(Node s) {
    13681368      if(!(*_reached)[s]) {
    1369           _reached->set(s,true);
    1370           _visitor->start(s);
    1371           _visitor->reach(s);
     1369          _reached->set(s,true);
     1370          _visitor->start(s);
     1371          _visitor->reach(s);
    13721372          _list[++_list_back] = s;
    1373         }
    1374     }
    1375    
     1373        }
     1374    }
     1375
    13761376    /// \brief Processes the next node.
    13771377    ///
     
    13811381    ///
    13821382    /// \pre The queue must not be empty!
    1383     Node processNextNode() { 
     1383    Node processNextNode() {
    13841384      Node n = _list[++_list_front];
    13851385      _visitor->process(n);
     
    14681468    /// \return The next node to be processed or INVALID if the stack is
    14691469    /// empty.
    1470     Node nextNode() { 
     1470    Node nextNode() {
    14711471      return _list_front != _list_back ? _list[_list_front + 1] : INVALID;
    14721472    }
     
    14831483    /// Returns the number of the nodes to be processed in the queue.
    14841484    int queueSize() { return _list_back - _list_front; }
    1485    
     1485
    14861486    /// \brief Executes the algorithm.
    14871487    ///
     
    14931493      while ( !emptyQueue() ) processNextNode();
    14941494    }
    1495    
     1495
    14961496    /// \brief Executes the algorithm until \c dest is reached.
    14971497    ///
     
    15041504      while ( !emptyQueue() && !reach ) processNextNode(dest, reach);
    15051505    }
    1506    
     1506
    15071507    /// \brief Executes the algorithm until a condition is met.
    15081508    ///
     
    15221522      Node rnode = INVALID;
    15231523      while ( !emptyQueue() && rnode == INVALID ) {
    1524         processNextNode(nm, rnode);
     1524        processNextNode(nm, rnode);
    15251525      }
    15261526      return rnode;
     
    15431543
    15441544    /// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph.
    1545     ///   
     1545    ///
    15461546    /// This method runs the %BFS algorithm in order to
    15471547    /// compute the %BFS path to each node. The algorithm computes
  • lemon/bin_heap.h

    r157 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4949  ///\sa Dijkstra
    5050  template <typename _Prio, typename _ItemIntMap,
    51             typename _Compare = std::less<_Prio> >
     51            typename _Compare = std::less<_Prio> >
    5252  class BinHeap {
    5353
     
    9191    /// should be PRE_HEAP (-1) for each element.
    9292    explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {}
    93    
     93
    9494    /// \brief The constructor.
    9595    ///
     
    100100    ///
    101101    /// \param _comp The comparator function object.
    102     BinHeap(ItemIntMap &_iim, const Compare &_comp) 
     102    BinHeap(ItemIntMap &_iim, const Compare &_comp)
    103103      : iim(_iim), comp(_comp) {}
    104104
     
    108108    /// \brief Returns the number of items stored in the heap.
    109109    int size() const { return data.size(); }
    110    
     110
    111111    /// \brief Checks if the heap stores no items.
    112112    ///
     
    115115
    116116    /// \brief Make empty this heap.
    117     /// 
     117    ///
    118118    /// Make empty this heap. It does not change the cross reference map.
    119119    /// If you want to reuse what is not surely empty you should first clear
    120120    /// the heap and after that you should set the cross reference map for
    121121    /// each item to \c PRE_HEAP.
    122     void clear() { 
    123       data.clear(); 
     122    void clear() {
     123      data.clear();
    124124    }
    125125
     
    135135      int par = parent(hole);
    136136      while( hole>0 && less(p,data[par]) ) {
    137         move(data[par],hole);
    138         hole = par;
    139         par = parent(hole);
     137        move(data[par],hole);
     138        hole = par;
     139        par = parent(hole);
    140140      }
    141141      move(p, hole);
     
    146146      int child = second_child(hole);
    147147      while(child < length) {
    148         if( less(data[child-1], data[child]) ) {
    149           --child;
    150         }
    151         if( !less(data[child], p) )
    152           goto ok;
    153         move(data[child], hole);
    154         hole = child;
    155         child = second_child(hole);
     148        if( less(data[child-1], data[child]) ) {
     149          --child;
     150        }
     151        if( !less(data[child], p) )
     152          goto ok;
     153        move(data[child], hole);
     154        hole = child;
     155        child = second_child(hole);
    156156      }
    157157      child--;
    158158      if( child<length && less(data[child], p) ) {
    159         move(data[child], hole);
    160         hole=child;
     159        move(data[child], hole);
     160        hole=child;
    161161      }
    162162    ok:
     
    182182
    183183    /// \brief Insert an item into the heap with the given heap.
    184     ///   
    185     /// Adds \c i to the heap with priority \c p. 
     184    ///
     185    /// Adds \c i to the heap with priority \c p.
    186186    /// \param i The item to insert.
    187187    /// \param p The priority of the item.
     
    191191    ///
    192192    /// This method returns the item with minimum priority relative to \c
    193     /// Compare. 
    194     /// \pre The heap must be nonempty. 
     193    /// Compare.
     194    /// \pre The heap must be nonempty.
    195195    Item top() const {
    196196      return data[0].first;
     
    208208    ///
    209209    /// This method deletes the item with minimum priority relative to \c
    210     /// Compare from the heap. 
    211     /// \pre The heap must be non-empty. 
     210    /// Compare from the heap.
     211    /// \pre The heap must be non-empty.
    212212    void pop() {
    213213      int n = data.size()-1;
    214214      iim.set(data[0].first, POST_HEAP);
    215215      if (n > 0) {
    216         bubble_down(0, data[n], n);
     216        bubble_down(0, data[n], n);
    217217      }
    218218      data.pop_back();
     
    229229      iim.set(data[h].first, POST_HEAP);
    230230      if( h < n ) {
    231         if ( bubble_up(h, data[n]) == h) {
    232           bubble_down(h, data[n], n);
    233         }
     231        if ( bubble_up(h, data[n]) == h) {
     232          bubble_down(h, data[n], n);
     233        }
    234234      }
    235235      data.pop_back();
    236236    }
    237237
    238    
     238
    239239    /// \brief Returns the priority of \c i.
    240240    ///
    241     /// This function returns the priority of item \c i. 
     241    /// This function returns the priority of item \c i.
    242242    /// \pre \c i must be in the heap.
    243243    /// \param i The item.
     
    247247    }
    248248
    249     /// \brief \c i gets to the heap with priority \c p independently 
     249    /// \brief \c i gets to the heap with priority \c p independently
    250250    /// if \c i was already there.
    251251    ///
     
    257257      int idx = iim[i];
    258258      if( idx < 0 ) {
    259         push(i,p);
     259        push(i,p);
    260260      }
    261261      else if( comp(p, data[idx].second) ) {
    262         bubble_up(idx, Pair(i,p));
     262        bubble_up(idx, Pair(i,p));
    263263      }
    264264      else {
    265         bubble_down(idx, Pair(i,p), data.size());
     265        bubble_down(idx, Pair(i,p), data.size());
    266266      }
    267267    }
     
    278278      bubble_up(idx, Pair(i,p));
    279279    }
    280    
     280
    281281    /// \brief Increases the priority of \c i to \c p.
    282282    ///
    283     /// This method sets the priority of item \c i to \c p. 
     283    /// This method sets the priority of item \c i to \c p.
    284284    /// \pre \c i must be stored in the heap with priority at most \c
    285285    /// p relative to \c Compare.
     
    291291    }
    292292
    293     /// \brief Returns if \c item is in, has already been in, or has 
     293    /// \brief Returns if \c item is in, has already been in, or has
    294294    /// never been in the heap.
    295295    ///
     
    302302      int s = iim[i];
    303303      if( s>=0 )
    304         s=0;
     304        s=0;
    305305      return State(s);
    306306    }
     
    312312    /// better time complexity.
    313313    /// \param i The item.
    314     /// \param st The state. It should not be \c IN_HEAP. 
     314    /// \param st The state. It should not be \c IN_HEAP.
    315315    void state(const Item& i, State st) {
    316316      switch (st) {
     
    341341
    342342  }; // class BinHeap
    343  
     343
    344344} // namespace lemon
    345345
  • lemon/bits/alteration_notifier.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3333  /// \ingroup graphbits
    3434  ///
    35   /// \brief Notifier class to notify observes about alterations in 
     35  /// \brief Notifier class to notify observes about alterations in
    3636  /// a container.
    3737  ///
     
    5050  /// alteration of the graph.
    5151  ///
    52   /// This class provides an interface to the container. The \e first() and \e 
     52  /// This class provides an interface to the container. The \e first() and \e
    5353  /// next() member functions make possible to iterate on the keys of the
    5454  /// container. The \e id() function returns an integer id for each key.
     
    6161  /// from the graph. If all items are erased from the graph or from an empty
    6262  /// graph a new graph is builded then it can be signaled with the
    63   /// clear() and build() members. Important rule that if we erase items 
     63  /// clear() and build() members. Important rule that if we erase items
    6464  /// from graph we should first signal the alteration and after that erase
    6565  /// them from the container, on the other way on item addition we should
     
    6969  /// \e ObserverBase nested class. The signals can be handled with
    7070  /// overriding the virtual functions defined in the base class.  The
    71   /// observer base can be attached to the notifier with the 
     71  /// observer base can be attached to the notifier with the
    7272  /// \e attach() member and can be detached with detach() function. The
    7373  /// alteration handlers should not call any function which signals
     
    8080  /// be rolled back by calling the \e erase() or \e clear()
    8181  /// functions. Thence the \e erase() and \e clear() should not throw
    82   /// exception. Actullay, it can be throw only 
     82  /// exception. Actullay, it can be throw only
    8383  /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
    8484  /// exception which detach the observer from the notifier.
     
    8686  /// There are some place when the alteration observing is not completly
    8787  /// reliable. If we want to carry out the node degree in the graph
    88   /// as in the \ref InDegMap and we use the reverseEdge that cause 
     88  /// as in the \ref InDegMap and we use the reverseEdge that cause
    8989  /// unreliable functionality. Because the alteration observing signals
    9090  /// only erasing and adding but not the reversing it will stores bad
     
    105105    typedef _Item Item;
    106106
    107     /// \brief Exception which can be called from \e clear() and 
     107    /// \brief Exception which can be called from \e clear() and
    108108    /// \e erase().
    109109    ///
     
    128128    /// The build() and clear() members are to notify the observer
    129129    /// about the container is built from an empty container or
    130     /// is cleared to an empty container. 
     130    /// is cleared to an empty container.
    131131
    132132    class ObserverBase {
     
    139139      ///
    140140      /// Default constructor for ObserverBase.
    141       /// 
     141      ///
    142142      ObserverBase() : _notifier(0) {}
    143143
     
    152152      ///
    153153      /// Constructor which attach the obserever to the same notifier as
    154       /// the other observer is attached to. 
     154      /// the other observer is attached to.
    155155      ObserverBase(const ObserverBase& copy) {
    156         if (copy.attached()) {
     156        if (copy.attached()) {
    157157          attach(*copy.notifier());
    158         }
    159       }
    160        
     158        }
     159      }
     160
    161161      /// \brief Destructor
    162162      virtual ~ObserverBase() {
     
    171171      ///
    172172      void attach(AlterationNotifier& nf) {
    173         nf.attach(*this);
    174       }
    175      
     173        nf.attach(*this);
     174      }
     175
    176176      /// \brief Detaches the observer into an AlterationNotifier.
    177177      ///
     
    181181        _notifier->detach(*this);
    182182      }
    183      
    184       /// \brief Gives back a pointer to the notifier which the map 
     183
     184      /// \brief Gives back a pointer to the notifier which the map
    185185      /// attached into.
    186186      ///
     
    189189      ///
    190190      Notifier* notifier() const { return const_cast<Notifier*>(_notifier); }
    191      
     191
    192192      /// Gives back true when the observer is attached into a notifier.
    193193      bool attached() const { return _notifier != 0; }
     
    198198
    199199    protected:
    200      
     200
    201201      Notifier* _notifier;
    202202      typename std::list<ObserverBase*>::iterator _index;
     
    210210      virtual void add(const Item&) = 0;
    211211
    212       /// \brief The member function to notificate the observer about 
     212      /// \brief The member function to notificate the observer about
    213213      /// more item is added to the container.
    214214      ///
     
    223223      /// The erase() member function notificates the observer about an
    224224      /// item is erased from the container. It have to be overrided in
    225       /// the subclasses.       
     225      /// the subclasses.
    226226      virtual void erase(const Item&) = 0;
    227227
    228       /// \brief The member function to notificate the observer about 
     228      /// \brief The member function to notificate the observer about
    229229      /// more item is erased from the container.
    230230      ///
     
    248248      /// The clear() member function notificates the observer about all
    249249      /// items are erased from the container. It have to be overrided in
    250       /// the subclasses.     
     250      /// the subclasses.
    251251      virtual void clear() = 0;
    252252
    253253    };
    254        
     254
    255255  protected:
    256256
    257257    const Container* container;
    258258
    259     typedef std::list<ObserverBase*> Observers; 
     259    typedef std::list<ObserverBase*> Observers;
    260260    Observers _observers;
    261261
    262                
     262
    263263  public:
    264264
    265265    /// \brief Default constructor.
    266266    ///
    267     /// The default constructor of the AlterationNotifier. 
     267    /// The default constructor of the AlterationNotifier.
    268268    /// It creates an empty notifier.
    269     AlterationNotifier() 
     269    AlterationNotifier()
    270270      : container(0) {}
    271271
     
    273273    ///
    274274    /// Constructor with the observed container parameter.
    275     AlterationNotifier(const Container& _container) 
     275    AlterationNotifier(const Container& _container)
    276276      : container(&_container) {}
    277277
    278     /// \brief Copy Constructor of the AlterationNotifier. 
    279     ///
    280     /// Copy constructor of the AlterationNotifier. 
     278    /// \brief Copy Constructor of the AlterationNotifier.
     279    ///
     280    /// Copy constructor of the AlterationNotifier.
    281281    /// It creates only an empty notifier because the copiable
    282282    /// notifier's observers have to be registered still into that notifier.
    283     AlterationNotifier(const AlterationNotifier& _notifier) 
     283    AlterationNotifier(const AlterationNotifier& _notifier)
    284284      : container(_notifier.container) {}
    285285
    286286    /// \brief Destructor.
    287     ///         
     287    ///
    288288    /// Destructor of the AlterationNotifier.
    289289    ///
     
    291291      typename Observers::iterator it;
    292292      for (it = _observers.begin(); it != _observers.end(); ++it) {
    293         (*it)->_notifier = 0;
     293        (*it)->_notifier = 0;
    294294      }
    295295    }
     
    339339      return container->maxId(Item());
    340340    }
    341                
     341
    342342  protected:
    343343
     
    345345      observer._index = _observers.insert(_observers.begin(), &observer);
    346346      observer._notifier = this;
    347     } 
     347    }
    348348
    349349    void detach(ObserverBase& observer) {
     
    354354
    355355  public:
    356        
    357     /// \brief Notifies all the registed observers about an item added to 
    358     /// the container.
    359     ///
    360     /// It notifies all the registed observers about an item added to 
    361     /// the container.
    362     /// 
     356
     357    /// \brief Notifies all the registed observers about an item added to
     358    /// the container.
     359    ///
     360    /// It notifies all the registed observers about an item added to
     361    /// the container.
     362    ///
    363363    void add(const Item& item) {
    364364      typename Observers::reverse_iterator it;
     
    374374        throw;
    375375      }
    376     }   
    377 
    378     /// \brief Notifies all the registed observers about more item added to 
    379     /// the container.
    380     ///
    381     /// It notifies all the registed observers about more item added to 
    382     /// the container.
    383     /// 
     376    }
     377
     378    /// \brief Notifies all the registed observers about more item added to
     379    /// the container.
     380    ///
     381    /// It notifies all the registed observers about more item added to
     382    /// the container.
     383    ///
    384384    void add(const std::vector<Item>& items) {
    385385      typename Observers::reverse_iterator it;
     
    395395        throw;
    396396      }
    397     }   
    398 
    399     /// \brief Notifies all the registed observers about an item erased from 
    400     /// the container.
    401     /// 
    402     /// It notifies all the registed observers about an item erased from 
    403     /// the container.
    404     /// 
     397    }
     398
     399    /// \brief Notifies all the registed observers about an item erased from
     400    /// the container.
     401    ///
     402    /// It notifies all the registed observers about an item erased from
     403    /// the container.
     404    ///
    405405    void erase(const Item& item) throw() {
    406406      typename Observers::iterator it = _observers.begin();
     
    417417    }
    418418
    419     /// \brief Notifies all the registed observers about more item erased 
     419    /// \brief Notifies all the registed observers about more item erased
    420420    /// from the container.
    421     /// 
    422     /// It notifies all the registed observers about more item erased from 
    423     /// the container.
    424     /// 
     421    ///
     422    /// It notifies all the registed observers about more item erased from
     423    /// the container.
     424    ///
    425425    void erase(const std::vector<Item>& items) {
    426426      typename Observers::iterator it = _observers.begin();
     
    437437    }
    438438
    439     /// \brief Notifies all the registed observers about the container is 
     439    /// \brief Notifies all the registed observers about the container is
    440440    /// built.
    441     ///         
     441    ///
    442442    /// Notifies all the registed observers about the container is built
    443443    /// from an empty container.
     
    457457    }
    458458
    459     /// \brief Notifies all the registed observers about all items are 
     459    /// \brief Notifies all the registed observers about all items are
    460460    /// erased.
    461461    ///
  • lemon/bits/array_map.h

    r107 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3939  /// The ArrayMap template class is graph map structure what
    4040  /// automatically updates the map when a key is added to or erased from
    41   /// the map. This map uses the allocators to implement 
     41  /// the map. This map uses the allocators to implement
    4242  /// the container functionality.
    4343  ///
     
    4545  /// the Value type of the map.
    4646  template <typename _Graph, typename _Item, typename _Value>
    47   class ArrayMap 
     47  class ArrayMap
    4848    : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
    4949  public:
    50     /// The graph type of the maps. 
     50    /// The graph type of the maps.
    5151    typedef _Graph Graph;
    5252    /// The item type of the map.
     
    7070    /// The MapBase of the Map which imlements the core regisitry function.
    7171    typedef typename Notifier::ObserverBase Parent;
    72                
     72
    7373  private:
    7474    typedef std::allocator<Value> Allocator;
     
    8585      Item it;
    8686      for (nf->first(it); it != INVALID; nf->next(it)) {
    87         int id = nf->id(it);;
    88         allocator.construct(&(values[id]), Value());
    89       }                                                         
    90     }
    91 
    92     /// \brief Constructor to use default value to initialize the map. 
    93     ///
    94     /// It constructs a map and initialize all of the the map. 
     87        int id = nf->id(it);;
     88        allocator.construct(&(values[id]), Value());
     89      }
     90    }
     91
     92    /// \brief Constructor to use default value to initialize the map.
     93    ///
     94    /// It constructs a map and initialize all of the the map.
    9595    ArrayMap(const Graph& graph, const Value& value) {
    9696      Parent::attach(graph.notifier(Item()));
     
    9999      Item it;
    100100      for (nf->first(it); it != INVALID; nf->next(it)) {
    101         int id = nf->id(it);;
    102         allocator.construct(&(values[id]), value);
    103       }                                                         
     101        int id = nf->id(it);;
     102        allocator.construct(&(values[id]), value);
     103      }
    104104    }
    105105
    106106    /// \brief Constructor to copy a map of the same map type.
    107107    ///
    108     /// Constructor to copy a map of the same map type.     
     108    /// Constructor to copy a map of the same map type.
    109109    ArrayMap(const ArrayMap& copy) : Parent() {
    110110      if (copy.attached()) {
    111         attach(*copy.notifier());
     111        attach(*copy.notifier());
    112112      }
    113113      capacity = copy.capacity;
     
    117117      Item it;
    118118      for (nf->first(it); it != INVALID; nf->next(it)) {
    119         int id = nf->id(it);;
    120         allocator.construct(&(values[id]), copy.values[id]);
     119        int id = nf->id(it);;
     120        allocator.construct(&(values[id]), copy.values[id]);
    121121      }
    122122    }
     
    125125    ///
    126126    /// This operator assigns for each item in the map the
    127     /// value mapped to the same item in the copied map. 
     127    /// value mapped to the same item in the copied map.
    128128    /// The parameter map should be indiced with the same
    129129    /// itemset because this assign operator does not change
    130     /// the container of the map. 
     130    /// the container of the map.
    131131    ArrayMap& operator=(const ArrayMap& cmap) {
    132132      return operator=<ArrayMap>(cmap);
     
    139139    /// concecpt and could be indiced by the current item set of
    140140    /// the NodeMap. In this case the value for each item
    141     /// is assigned by the value of the given ReadMap. 
     141    /// is assigned by the value of the given ReadMap.
    142142    template <typename CMap>
    143143    ArrayMap& operator=(const CMap& cmap) {
     
    152152
    153153    /// \brief The destructor of the map.
    154     ///     
     154    ///
    155155    /// The destructor of the map.
    156     virtual ~ArrayMap() {     
     156    virtual ~ArrayMap() {
    157157      if (attached()) {
    158         clear();
    159         detach();
    160       }
    161     }
    162                
     158        clear();
     159        detach();
     160      }
     161    }
     162
    163163  protected:
    164164
     
    169169  public:
    170170
    171     /// \brief The subscript operator. 
     171    /// \brief The subscript operator.
    172172    ///
    173173    /// The subscript operator. The map can be subscripted by the
    174     /// actual keys of the graph. 
     174    /// actual keys of the graph.
    175175    Value& operator[](const Key& key) {
    176176      int id = Parent::notifier()->id(key);
    177177      return values[id];
    178     } 
    179                
     178    }
     179
    180180    /// \brief The const subscript operator.
    181181    ///
    182182    /// The const subscript operator. The map can be subscripted by the
    183     /// actual keys of the graph. 
     183    /// actual keys of the graph.
    184184    const Value& operator[](const Key& key) const {
    185185      int id = Parent::notifier()->id(key);
     
    188188
    189189    /// \brief Setter function of the map.
    190     /// 
     190    ///
    191191    /// Setter function of the map. Equivalent with map[key] = val.
    192192    /// This is a compatibility feature with the not dereferable maps.
     
    198198
    199199    /// \brief Adds a new key to the map.
    200     ///         
     200    ///
    201201    /// It adds a new key to the map. It called by the observer notifier
    202     /// and it overrides the add() member function of the observer base.     
     202    /// and it overrides the add() member function of the observer base.
    203203    virtual void add(const Key& key) {
    204204      Notifier* nf = Parent::notifier();
    205205      int id = nf->id(key);
    206206      if (id >= capacity) {
    207         int new_capacity = (capacity == 0 ? 1 : capacity);
    208         while (new_capacity <= id) {
    209           new_capacity <<= 1;
    210         }
    211         Value* new_values = allocator.allocate(new_capacity);
    212         Item it;
    213         for (nf->first(it); it != INVALID; nf->next(it)) {
    214           int jd = nf->id(it);;
    215           if (id != jd) {
    216             allocator.construct(&(new_values[jd]), values[jd]);
    217             allocator.destroy(&(values[jd]));
    218           }
    219         }
    220         if (capacity != 0) allocator.deallocate(values, capacity);
    221         values = new_values;
    222         capacity = new_capacity;
     207        int new_capacity = (capacity == 0 ? 1 : capacity);
     208        while (new_capacity <= id) {
     209          new_capacity <<= 1;
     210        }
     211        Value* new_values = allocator.allocate(new_capacity);
     212        Item it;
     213        for (nf->first(it); it != INVALID; nf->next(it)) {
     214          int jd = nf->id(it);;
     215          if (id != jd) {
     216            allocator.construct(&(new_values[jd]), values[jd]);
     217            allocator.destroy(&(values[jd]));
     218          }
     219        }
     220        if (capacity != 0) allocator.deallocate(values, capacity);
     221        values = new_values;
     222        capacity = new_capacity;
    223223      }
    224224      allocator.construct(&(values[id]), Value());
     
    226226
    227227    /// \brief Adds more new keys to the map.
    228     ///         
     228    ///
    229229    /// It adds more new keys to the map. It called by the observer notifier
    230     /// and it overrides the add() member function of the observer base.     
     230    /// and it overrides the add() member function of the observer base.
    231231    virtual void add(const std::vector<Key>& keys) {
    232232      Notifier* nf = Parent::notifier();
    233233      int max_id = -1;
    234234      for (int i = 0; i < int(keys.size()); ++i) {
    235         int id = nf->id(keys[i]);
    236         if (id > max_id) {
    237           max_id = id;
    238         }
     235        int id = nf->id(keys[i]);
     236        if (id > max_id) {
     237          max_id = id;
     238        }
    239239      }
    240240      if (max_id >= capacity) {
    241         int new_capacity = (capacity == 0 ? 1 : capacity);
    242         while (new_capacity <= max_id) {
    243           new_capacity <<= 1;
    244         }
    245         Value* new_values = allocator.allocate(new_capacity);
    246         Item it;
    247         for (nf->first(it); it != INVALID; nf->next(it)) {
    248           int id = nf->id(it);
    249           bool found = false;
    250           for (int i = 0; i < int(keys.size()); ++i) {
    251             int jd = nf->id(keys[i]);
    252             if (id == jd) {
    253               found = true;
    254               break;
    255             }
    256           }
    257           if (found) continue;
    258           allocator.construct(&(new_values[id]), values[id]);
    259           allocator.destroy(&(values[id]));
    260         }
    261         if (capacity != 0) allocator.deallocate(values, capacity);
    262         values = new_values;
    263         capacity = new_capacity;
     241        int new_capacity = (capacity == 0 ? 1 : capacity);
     242        while (new_capacity <= max_id) {
     243          new_capacity <<= 1;
     244        }
     245        Value* new_values = allocator.allocate(new_capacity);
     246        Item it;
     247        for (nf->first(it); it != INVALID; nf->next(it)) {
     248          int id = nf->id(it);
     249          bool found = false;
     250          for (int i = 0; i < int(keys.size()); ++i) {
     251            int jd = nf->id(keys[i]);
     252            if (id == jd) {
     253              found = true;
     254              break;
     255            }
     256          }
     257          if (found) continue;
     258          allocator.construct(&(new_values[id]), values[id]);
     259          allocator.destroy(&(values[id]));
     260        }
     261        if (capacity != 0) allocator.deallocate(values, capacity);
     262        values = new_values;
     263        capacity = new_capacity;
    264264      }
    265265      for (int i = 0; i < int(keys.size()); ++i) {
    266         int id = nf->id(keys[i]);
    267         allocator.construct(&(values[id]), Value());
    268       }
    269     }
    270                
     266        int id = nf->id(keys[i]);
     267        allocator.construct(&(values[id]), Value());
     268      }
     269    }
     270
    271271    /// \brief Erase a key from the map.
    272272    ///
    273273    /// Erase a key from the map. It called by the observer notifier
    274     /// and it overrides the erase() member function of the observer base.     
     274    /// and it overrides the erase() member function of the observer base.
    275275    virtual void erase(const Key& key) {
    276276      int id = Parent::notifier()->id(key);
     
    281281    ///
    282282    /// Erase more keys from the map. It called by the observer notifier
    283     /// and it overrides the erase() member function of the observer base.     
     283    /// and it overrides the erase() member function of the observer base.
    284284    virtual void erase(const std::vector<Key>& keys) {
    285285      for (int i = 0; i < int(keys.size()); ++i) {
    286         int id = Parent::notifier()->id(keys[i]);
    287         allocator.destroy(&(values[id]));
     286        int id = Parent::notifier()->id(keys[i]);
     287        allocator.destroy(&(values[id]));
    288288      }
    289289    }
    290290
    291291    /// \brief Buildes the map.
    292     /// 
     292    ///
    293293    /// It buildes the map. It called by the observer notifier
    294     /// and it overrides the build() member function of the observer base. 
     294    /// and it overrides the build() member function of the observer base.
    295295    virtual void build() {
    296296      Notifier* nf = Parent::notifier();
     
    298298      Item it;
    299299      for (nf->first(it); it != INVALID; nf->next(it)) {
    300         int id = nf->id(it);;
    301         allocator.construct(&(values[id]), Value());
    302       }                                                         
     300        int id = nf->id(it);;
     301        allocator.construct(&(values[id]), Value());
     302      }
    303303    }
    304304
     
    306306    ///
    307307    /// It erase all items from the map. It called by the observer notifier
    308     /// and it overrides the clear() member function of the observer base.     
    309     virtual void clear() {     
     308    /// and it overrides the clear() member function of the observer base.
     309    virtual void clear() {
    310310      Notifier* nf = Parent::notifier();
    311311      if (capacity != 0) {
    312         Item it;
    313         for (nf->first(it); it != INVALID; nf->next(it)) {
    314           int id = nf->id(it);
    315           allocator.destroy(&(values[id]));
    316         }                                                               
    317         allocator.deallocate(values, capacity);
    318         capacity = 0;
     312        Item it;
     313        for (nf->first(it); it != INVALID; nf->next(it)) {
     314          int id = nf->id(it);
     315          allocator.destroy(&(values[id]));
     316        }
     317        allocator.deallocate(values, capacity);
     318        capacity = 0;
    319319      }
    320320    }
    321321
    322322  private:
    323      
     323
    324324    void allocate_memory() {
    325325      int max_id = Parent::notifier()->maxId();
    326326      if (max_id == -1) {
    327         capacity = 0;
    328         values = 0;
    329         return;
     327        capacity = 0;
     328        values = 0;
     329        return;
    330330      }
    331331      capacity = 1;
    332332      while (capacity <= max_id) {
    333         capacity <<= 1;
    334       }
    335       values = allocator.allocate(capacity);   
    336     }     
     333        capacity <<= 1;
     334      }
     335      values = allocator.allocate(capacity);
     336    }
    337337
    338338    int capacity;
     
    340340    Allocator allocator;
    341341
    342   };           
     342  };
    343343
    344344}
    345345
    346 #endif 
     346#endif
  • lemon/bits/base_extender.h

    r107 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6464
    6565      bool operator==(const Arc &that) const {
    66         return forward==that.forward && Edge(*this)==Edge(that);
     66        return forward==that.forward && Edge(*this)==Edge(that);
    6767      }
    6868      bool operator!=(const Arc &that) const {
    69         return forward!=that.forward || Edge(*this)!=Edge(that);
     69        return forward!=that.forward || Edge(*this)!=Edge(that);
    7070      }
    7171      bool operator<(const Arc &that) const {
    72         return forward<that.forward ||
    73           (!(that.forward<forward) && Edge(*this)<Edge(that));
     72        return forward<that.forward ||
     73          (!(that.forward<forward) && Edge(*this)<Edge(that));
    7474      }
    7575    };
     
    118118    void next(Arc &e) const {
    119119      if( e.forward ) {
    120         e.forward = false;
     120        e.forward = false;
    121121      }
    122122      else {
    123         Parent::next(e);
    124         e.forward = true;
     123        Parent::next(e);
     124        e.forward = true;
    125125      }
    126126    }
     
    129129      Parent::firstIn(e,n);
    130130      if( Edge(e) != INVALID ) {
    131         e.forward = false;
     131        e.forward = false;
    132132      }
    133133      else {
    134         Parent::firstOut(e,n);
    135         e.forward = true;
     134        Parent::firstOut(e,n);
     135        e.forward = true;
    136136      }
    137137    }
    138138    void nextOut(Arc &e) const {
    139139      if( ! e.forward ) {
    140         Node n = Parent::target(e);
    141         Parent::nextIn(e);
    142         if( Edge(e) == INVALID ) {
    143           Parent::firstOut(e, n);
    144           e.forward = true;
    145         }
     140        Node n = Parent::target(e);
     141        Parent::nextIn(e);
     142        if( Edge(e) == INVALID ) {
     143          Parent::firstOut(e, n);
     144          e.forward = true;
     145        }
    146146      }
    147147      else {
    148         Parent::nextOut(e);
     148        Parent::nextOut(e);
    149149      }
    150150    }
     
    153153      Parent::firstOut(e,n);
    154154      if( Edge(e) != INVALID ) {
    155         e.forward = false;
     155        e.forward = false;
    156156      }
    157157      else {
    158         Parent::firstIn(e,n);
    159         e.forward = true;
     158        Parent::firstIn(e,n);
     159        e.forward = true;
    160160      }
    161161    }
    162162    void nextIn(Arc &e) const {
    163163      if( ! e.forward ) {
    164         Node n = Parent::source(e);
    165         Parent::nextOut(e);
    166         if( Edge(e) == INVALID ) {
    167           Parent::firstIn(e, n);
    168           e.forward = true;
    169         }
     164        Node n = Parent::source(e);
     165        Parent::nextOut(e);
     166        if( Edge(e) == INVALID ) {
     167          Parent::firstIn(e, n);
     168          e.forward = true;
     169        }
    170170      }
    171171      else {
    172         Parent::nextIn(e);
     172        Parent::nextIn(e);
    173173      }
    174174    }
     
    184184    void nextInc(Edge &e, bool &d) const {
    185185      if (d) {
    186         Node s = Parent::source(e);
    187         Parent::nextOut(e);
    188         if (e != INVALID) return;
    189         d = false;
    190         Parent::firstIn(e, s);
    191       } else {
    192         Parent::nextIn(e);
     186        Node s = Parent::source(e);
     187        Parent::nextOut(e);
     188        if (e != INVALID) return;
     189        d = false;
     190        Parent::firstIn(e, s);
     191      } else {
     192        Parent::nextIn(e);
    193193      }
    194194    }
     
    241241    Arc findArc(Node s, Node t, Arc p = INVALID) const {
    242242      if (p == INVALID) {
    243         Edge arc = Parent::findArc(s, t);
    244         if (arc != INVALID) return direct(arc, true);
    245         arc = Parent::findArc(t, s);
    246         if (arc != INVALID) return direct(arc, false);
     243        Edge arc = Parent::findArc(s, t);
     244        if (arc != INVALID) return direct(arc, true);
     245        arc = Parent::findArc(t, s);
     246        if (arc != INVALID) return direct(arc, false);
    247247      } else if (direction(p)) {
    248         Edge arc = Parent::findArc(s, t, p);
    249         if (arc != INVALID) return direct(arc, true);
    250         arc = Parent::findArc(t, s);
    251         if (arc != INVALID) return direct(arc, false); 
    252       } else {
    253         Edge arc = Parent::findArc(t, s, p);
    254         if (arc != INVALID) return direct(arc, false);       
     248        Edge arc = Parent::findArc(s, t, p);
     249        if (arc != INVALID) return direct(arc, true);
     250        arc = Parent::findArc(t, s);
     251        if (arc != INVALID) return direct(arc, false);
     252      } else {
     253        Edge arc = Parent::findArc(t, s, p);
     254        if (arc != INVALID) return direct(arc, false);
    255255      }
    256256      return INVALID;
     
    268268          if (arc != INVALID) return arc;
    269269          arc = Parent::findArc(t, s);
    270           if (arc != INVALID) return arc;       
     270          if (arc != INVALID) return arc;
    271271        } else {
    272272          Edge arc = Parent::findArc(t, s, p);
    273           if (arc != INVALID) return arc;             
     273          if (arc != INVALID) return arc;
    274274        }
    275275      } else {
     
    300300      Red() {}
    301301      Red(const Node& node) : Node(node) {
    302         LEMON_ASSERT(Parent::red(node) || node == INVALID,
    303                      typename Parent::NodeSetError());
     302        LEMON_ASSERT(Parent::red(node) || node == INVALID,
     303                     typename Parent::NodeSetError());
    304304      }
    305305      Red& operator=(const Node& node) {
    306         LEMON_ASSERT(Parent::red(node) || node == INVALID,
    307                      typename Parent::NodeSetError());
     306        LEMON_ASSERT(Parent::red(node) || node == INVALID,
     307                     typename Parent::NodeSetError());
    308308        Node::operator=(node);
    309309        return *this;
     
    332332      Blue() {}
    333333      Blue(const Node& node) : Node(node) {
    334         LEMON_ASSERT(Parent::blue(node) || node == INVALID,
    335                      typename Parent::NodeSetError());
     334        LEMON_ASSERT(Parent::blue(node) || node == INVALID,
     335                     typename Parent::NodeSetError());
    336336      }
    337337      Blue& operator=(const Node& node) {
    338         LEMON_ASSERT(Parent::blue(node) || node == INVALID,
    339                      typename Parent::NodeSetError());
     338        LEMON_ASSERT(Parent::blue(node) || node == INVALID,
     339                     typename Parent::NodeSetError());
    340340        Node::operator=(node);
    341341        return *this;
     
    354354      Parent::nextBlue(static_cast<Node&>(node));
    355355    }
    356  
     356
    357357    int id(const Blue& node) const {
    358358      return Parent::redId(node);
     
    368368    void firstInc(Edge& arc, bool& dir, const Node& node) const {
    369369      if (Parent::red(node)) {
    370         Parent::firstFromRed(arc, node);
    371         dir = true;
    372       } else {
    373         Parent::firstFromBlue(arc, node);
    374         dir = static_cast<Edge&>(arc) == INVALID;
     370        Parent::firstFromRed(arc, node);
     371        dir = true;
     372      } else {
     373        Parent::firstFromBlue(arc, node);
     374        dir = static_cast<Edge&>(arc) == INVALID;
    375375      }
    376376    }
    377377    void nextInc(Edge& arc, bool& dir) const {
    378378      if (dir) {
    379         Parent::nextFromRed(arc);
    380       } else {
    381         Parent::nextFromBlue(arc);
    382         if (arc == INVALID) dir = true;
     379        Parent::nextFromRed(arc);
     380      } else {
     381        Parent::nextFromBlue(arc);
     382        if (arc == INVALID) dir = true;
    383383      }
    384384    }
     
    390390
    391391      Arc(const Edge& arc, bool _forward)
    392         : Edge(arc), forward(_forward) {}
     392        : Edge(arc), forward(_forward) {}
    393393
    394394    public:
     
    396396      Arc (Invalid) : Edge(INVALID), forward(true) {}
    397397      bool operator==(const Arc& i) const {
    398         return Edge::operator==(i) && forward == i.forward;
     398        return Edge::operator==(i) && forward == i.forward;
    399399      }
    400400      bool operator!=(const Arc& i) const {
    401         return Edge::operator!=(i) || forward != i.forward;
     401        return Edge::operator!=(i) || forward != i.forward;
    402402      }
    403403      bool operator<(const Arc& i) const {
    404         return Edge::operator<(i) ||
    405           (!(i.forward<forward) && Edge(*this)<Edge(i));
     404        return Edge::operator<(i) ||
     405          (!(i.forward<forward) && Edge(*this)<Edge(i));
    406406      }
    407407    };
     
    414414    void next(Arc& arc) const {
    415415      if (!arc.forward) {
    416         Parent::next(static_cast<Edge&>(arc));
     416        Parent::next(static_cast<Edge&>(arc));
    417417      }
    418418      arc.forward = !arc.forward;
     
    421421    void firstOut(Arc& arc, const Node& node) const {
    422422      if (Parent::red(node)) {
    423         Parent::firstFromRed(arc, node);
    424         arc.forward = true;
    425       } else {
    426         Parent::firstFromBlue(arc, node);
    427         arc.forward = static_cast<Edge&>(arc) == INVALID;
     423        Parent::firstFromRed(arc, node);
     424        arc.forward = true;
     425      } else {
     426        Parent::firstFromBlue(arc, node);
     427        arc.forward = static_cast<Edge&>(arc) == INVALID;
    428428      }
    429429    }
    430430    void nextOut(Arc& arc) const {
    431431      if (arc.forward) {
    432         Parent::nextFromRed(arc);
    433       } else {
    434         Parent::nextFromBlue(arc);
     432        Parent::nextFromRed(arc);
     433      } else {
     434        Parent::nextFromBlue(arc);
    435435        arc.forward = static_cast<Edge&>(arc) == INVALID;
    436436      }
     
    439439    void firstIn(Arc& arc, const Node& node) const {
    440440      if (Parent::blue(node)) {
    441         Parent::firstFromBlue(arc, node);
    442         arc.forward = true;     
    443       } else {
    444         Parent::firstFromRed(arc, node);
    445         arc.forward = static_cast<Edge&>(arc) == INVALID;
     441        Parent::firstFromBlue(arc, node);
     442        arc.forward = true;
     443      } else {
     444        Parent::firstFromRed(arc, node);
     445        arc.forward = static_cast<Edge&>(arc) == INVALID;
    446446      }
    447447    }
    448448    void nextIn(Arc& arc) const {
    449449      if (arc.forward) {
    450         Parent::nextFromBlue(arc);
    451       } else {
    452         Parent::nextFromRed(arc);
    453         arc.forward = static_cast<Edge&>(arc) == INVALID;
     450        Parent::nextFromBlue(arc);
     451      } else {
     452        Parent::nextFromRed(arc);
     453        arc.forward = static_cast<Edge&>(arc) == INVALID;
    454454      }
    455455    }
     
    463463
    464464    int id(const Arc& arc) const {
    465       return (Parent::id(static_cast<const Edge&>(arc)) << 1) + 
     465      return (Parent::id(static_cast<const Edge&>(arc)) << 1) +
    466466        (arc.forward ? 0 : 1);
    467467    }
  • lemon/bits/bezier.h

    r184 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4545  Bezier1() {}
    4646  Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {}
    47  
     47
    4848  Point operator()(double t) const
    4949  {
     
    5555    return Bezier1(p1,conv(p1,p2,t));
    5656  }
    57  
     57
    5858  Bezier1 after(double t) const
    5959  {
     
    8888    return Bezier2(p1,q,conv(q,r,t));
    8989  }
    90  
     90
    9191  Bezier2 after(double t) const
    9292  {
     
    111111  Bezier3(Point _p1, Point _p2, Point _p3, Point _p4)
    112112    : p1(_p1), p2(_p2), p3(_p3), p4(_p4) {}
    113   Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), 
    114                               p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {}
     113  Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)),
     114                              p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {}
    115115  Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)),
    116                               p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {}
    117  
    118   Point operator()(double t) const 
     116                              p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {}
     117
     118  Point operator()(double t) const
    119119    {
    120120      //    return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t);
    121121      return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+
    122         (3*t*t*(1-t))*p3+(t*t*t)*p4;
     122        (3*t*t*(1-t))*p3+(t*t*t)*p4;
    123123    }
    124124  Bezier3 before(double t) const
     
    132132      return Bezier3(p1,p,a,c);
    133133    }
    134  
     134
    135135  Bezier3 after(double t) const
    136136    {
     
    147147  Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); }
    148148  Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1),
    149                                   3.0*rot90(p3-p2),
    150                                   3.0*rot90(p4-p3)); }
     149                                  3.0*rot90(p3-p2),
     150                                  3.0*rot90(p4-p3)); }
    151151  Point grad(double t) const { return grad()(t); }
    152152  Point norm(double t) const { return rot90(grad(t)); }
    153153
    154154  template<class R,class F,class S,class D>
    155   R recSplit(F &_f,const S &_s,D _d) const 
     155  R recSplit(F &_f,const S &_s,D _d) const
    156156  {
    157157    const Point a=(p1+p2)/2;
     
    165165    return _s(f1,f2);
    166166  }
    167  
     167
    168168};
    169169
  • lemon/bits/default_map.h

    r107 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3030
    3131namespace lemon {
    32  
    33  
     32
     33
    3434  //#ifndef LEMON_USE_DEBUG_MAP
    3535
     
    141141  };
    142142
    143 // #else 
     143// #else
    144144
    145145//   template <typename _Graph, typename _Item, typename _Value>
     
    148148//   };
    149149
    150 // #endif 
     150// #endif
    151151
    152152  /// \e
    153153  template <typename _Graph, typename _Item, typename _Value>
    154   class DefaultMap 
     154  class DefaultMap
    155155    : public DefaultMapSelector<_Graph, _Item, _Value>::Map {
    156156  public:
    157157    typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
    158158    typedef DefaultMap<_Graph, _Item, _Value> Map;
    159    
     159
    160160    typedef typename Parent::Graph Graph;
    161161    typedef typename Parent::Value Value;
    162162
    163163    explicit DefaultMap(const Graph& graph) : Parent(graph) {}
    164     DefaultMap(const Graph& graph, const Value& value) 
     164    DefaultMap(const Graph& graph, const Value& value)
    165165      : Parent(graph, value) {}
    166166
  • lemon/bits/graph_extender.h

    r125 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6767    Node oppositeNode(const Node &node, const Arc &arc) const {
    6868      if (node == Parent::source(arc))
    69         return Parent::target(arc);
     69        return Parent::target(arc);
    7070      else if(node == Parent::target(arc))
    71         return Parent::source(arc);
     71        return Parent::source(arc);
    7272      else
    73         return INVALID;
     73        return INVALID;
    7474    }
    7575
     
    9090      return node_notifier;
    9191    }
    92    
     92
    9393    ArcNotifier& notifier(Arc) const {
    9494      return arc_notifier;
    9595    }
    9696
    97     class NodeIt : public Node { 
     97    class NodeIt : public Node {
    9898      const Digraph* _digraph;
    9999    public:
     
    104104
    105105      explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) {
    106         _digraph->first(static_cast<Node&>(*this));
    107       }
    108 
    109       NodeIt(const Digraph& digraph, const Node& node) 
    110         : Node(node), _digraph(&digraph) {}
    111 
    112       NodeIt& operator++() { 
    113         _digraph->next(*this);
    114         return *this;
    115       }
    116 
    117     };
    118 
    119 
    120     class ArcIt : public Arc { 
     106        _digraph->first(static_cast<Node&>(*this));
     107      }
     108
     109      NodeIt(const Digraph& digraph, const Node& node)
     110        : Node(node), _digraph(&digraph) {}
     111
     112      NodeIt& operator++() {
     113        _digraph->next(*this);
     114        return *this;
     115      }
     116
     117    };
     118
     119
     120    class ArcIt : public Arc {
    121121      const Digraph* _digraph;
    122122    public:
     
    127127
    128128      explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) {
    129         _digraph->first(static_cast<Arc&>(*this));
    130       }
    131 
    132       ArcIt(const Digraph& digraph, const Arc& arc) : 
    133         Arc(arc), _digraph(&digraph) { }
    134 
    135       ArcIt& operator++() { 
    136         _digraph->next(*this);
    137         return *this;
    138       }
    139 
    140     };
    141 
    142 
    143     class OutArcIt : public Arc { 
     129        _digraph->first(static_cast<Arc&>(*this));
     130      }
     131
     132      ArcIt(const Digraph& digraph, const Arc& arc) :
     133        Arc(arc), _digraph(&digraph) { }
     134
     135      ArcIt& operator++() {
     136        _digraph->next(*this);
     137        return *this;
     138      }
     139
     140    };
     141
     142
     143    class OutArcIt : public Arc {
    144144      const Digraph* _digraph;
    145145    public:
     
    149149      OutArcIt(Invalid i) : Arc(i) { }
    150150
    151       OutArcIt(const Digraph& digraph, const Node& node) 
    152         : _digraph(&digraph) {
    153         _digraph->firstOut(*this, node);
    154       }
    155 
    156       OutArcIt(const Digraph& digraph, const Arc& arc) 
    157         : Arc(arc), _digraph(&digraph) {}
    158 
    159       OutArcIt& operator++() { 
    160         _digraph->nextOut(*this);
    161         return *this;
    162       }
    163 
    164     };
    165 
    166 
    167     class InArcIt : public Arc { 
     151      OutArcIt(const Digraph& digraph, const Node& node)
     152        : _digraph(&digraph) {
     153        _digraph->firstOut(*this, node);
     154      }
     155
     156      OutArcIt(const Digraph& digraph, const Arc& arc)
     157        : Arc(arc), _digraph(&digraph) {}
     158
     159      OutArcIt& operator++() {
     160        _digraph->nextOut(*this);
     161        return *this;
     162      }
     163
     164    };
     165
     166
     167    class InArcIt : public Arc {
    168168      const Digraph* _digraph;
    169169    public:
     
    173173      InArcIt(Invalid i) : Arc(i) { }
    174174
    175       InArcIt(const Digraph& digraph, const Node& node) 
    176         : _digraph(&digraph) {
    177         _digraph->firstIn(*this, node);
    178       }
    179 
    180       InArcIt(const Digraph& digraph, const Arc& arc) : 
    181         Arc(arc), _digraph(&digraph) {}
    182 
    183       InArcIt& operator++() { 
    184         _digraph->nextIn(*this);
    185         return *this;
     175      InArcIt(const Digraph& digraph, const Node& node)
     176        : _digraph(&digraph) {
     177        _digraph->firstIn(*this, node);
     178      }
     179
     180      InArcIt(const Digraph& digraph, const Arc& arc) :
     181        Arc(arc), _digraph(&digraph) {}
     182
     183      InArcIt& operator++() {
     184        _digraph->nextIn(*this);
     185        return *this;
    186186      }
    187187
     
    216216    }
    217217
    218    
     218
    219219    template <typename _Value>
    220     class NodeMap 
     220    class NodeMap
    221221      : public MapExtender<DefaultMap<Digraph, Node, _Value> > {
    222222    public:
     
    224224      typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent;
    225225
    226       explicit NodeMap(const Digraph& digraph) 
    227         : Parent(digraph) {}
    228       NodeMap(const Digraph& digraph, const _Value& value) 
    229         : Parent(digraph, value) {}
     226      explicit NodeMap(const Digraph& digraph)
     227        : Parent(digraph) {}
     228      NodeMap(const Digraph& digraph, const _Value& value)
     229        : Parent(digraph, value) {}
    230230
    231231      NodeMap& operator=(const NodeMap& cmap) {
    232         return operator=<NodeMap>(cmap);
     232        return operator=<NodeMap>(cmap);
    233233      }
    234234
     
    236236      NodeMap& operator=(const CMap& cmap) {
    237237        Parent::operator=(cmap);
    238         return *this;
     238        return *this;
    239239      }
    240240
     
    242242
    243243    template <typename _Value>
    244     class ArcMap 
     244    class ArcMap
    245245      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
    246246    public:
     
    248248      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
    249249
    250       explicit ArcMap(const Digraph& digraph) 
    251         : Parent(digraph) {}
    252       ArcMap(const Digraph& digraph, const _Value& value) 
    253         : Parent(digraph, value) {}
     250      explicit ArcMap(const Digraph& digraph)
     251        : Parent(digraph) {}
     252      ArcMap(const Digraph& digraph, const _Value& value)
     253        : Parent(digraph, value) {}
    254254
    255255      ArcMap& operator=(const ArcMap& cmap) {
    256         return operator=<ArcMap>(cmap);
     256        return operator=<ArcMap>(cmap);
    257257      }
    258258
     
    260260      ArcMap& operator=(const CMap& cmap) {
    261261        Parent::operator=(cmap);
    262         return *this;
     262        return *this;
    263263      }
    264264    };
     
    270270      return node;
    271271    }
    272    
     272
    273273    Arc addArc(const Node& from, const Node& to) {
    274274      Arc arc = Parent::addArc(from, to);
     
    294294      Parent::firstOut(arc, node);
    295295      while (arc != INVALID ) {
    296         erase(arc);
    297         Parent::firstOut(arc, node);
    298       } 
     296        erase(arc);
     297        Parent::firstOut(arc, node);
     298      }
    299299
    300300      Parent::firstIn(arc, node);
    301301      while (arc != INVALID ) {
    302         erase(arc);
    303         Parent::firstIn(arc, node);
     302        erase(arc);
     303        Parent::firstIn(arc, node);
    304304      }
    305305
     
    307307      Parent::erase(node);
    308308    }
    309    
     309
    310310    void erase(const Arc& arc) {
    311311      notifier(Arc()).erase(arc);
     
    316316      node_notifier.setContainer(*this);
    317317      arc_notifier.setContainer(*this);
    318     } 
    319    
     318    }
     319
    320320
    321321    ~DigraphExtender() {
     
    328328  ///
    329329  /// \brief Extender for the Graphs
    330   template <typename Base> 
     330  template <typename Base>
    331331  class GraphExtender : public Base {
    332332  public:
    333    
     333
    334334    typedef Base Parent;
    335335    typedef GraphExtender Graph;
     
    341341    typedef typename Parent::Edge Edge;
    342342
    343     // Graph extension   
     343    // Graph extension
    344344
    345345    int maxId(Node) const {
     
    369369    Node oppositeNode(const Node &n, const Edge &e) const {
    370370      if( n == Parent::u(e))
    371         return Parent::v(e);
     371        return Parent::v(e);
    372372      else if( n == Parent::v(e))
    373         return Parent::u(e);
     373        return Parent::u(e);
    374374      else
    375         return INVALID;
     375        return INVALID;
    376376    }
    377377
     
    403403      return node_notifier;
    404404    }
    405    
     405
    406406    ArcNotifier& notifier(Arc) const {
    407407      return arc_notifier;
     
    414414
    415415
    416     class NodeIt : public Node { 
     416    class NodeIt : public Node {
    417417      const Graph* _graph;
    418418    public:
     
    423423
    424424      explicit NodeIt(const Graph& graph) : _graph(&graph) {
    425         _graph->first(static_cast<Node&>(*this));
    426       }
    427 
    428       NodeIt(const Graph& graph, const Node& node) 
    429         : Node(node), _graph(&graph) {}
    430 
    431       NodeIt& operator++() { 
    432         _graph->next(*this);
    433         return *this;
    434       }
    435 
    436     };
    437 
    438 
    439     class ArcIt : public Arc { 
     425        _graph->first(static_cast<Node&>(*this));
     426      }
     427
     428      NodeIt(const Graph& graph, const Node& node)
     429        : Node(node), _graph(&graph) {}
     430
     431      NodeIt& operator++() {
     432        _graph->next(*this);
     433        return *this;
     434      }
     435
     436    };
     437
     438
     439    class ArcIt : public Arc {
    440440      const Graph* _graph;
    441441    public:
     
    446446
    447447      explicit ArcIt(const Graph& graph) : _graph(&graph) {
    448         _graph->first(static_cast<Arc&>(*this));
    449       }
    450 
    451       ArcIt(const Graph& graph, const Arc& arc) : 
    452         Arc(arc), _graph(&graph) { }
    453 
    454       ArcIt& operator++() { 
    455         _graph->next(*this);
    456         return *this;
    457       }
    458 
    459     };
    460 
    461 
    462     class OutArcIt : public Arc { 
     448        _graph->first(static_cast<Arc&>(*this));
     449      }
     450
     451      ArcIt(const Graph& graph, const Arc& arc) :
     452        Arc(arc), _graph(&graph) { }
     453
     454      ArcIt& operator++() {
     455        _graph->next(*this);
     456        return *this;
     457      }
     458
     459    };
     460
     461
     462    class OutArcIt : public Arc {
    463463      const Graph* _graph;
    464464    public:
     
    468468      OutArcIt(Invalid i) : Arc(i) { }
    469469
    470       OutArcIt(const Graph& graph, const Node& node) 
    471         : _graph(&graph) {
    472         _graph->firstOut(*this, node);
    473       }
    474 
    475       OutArcIt(const Graph& graph, const Arc& arc) 
    476         : Arc(arc), _graph(&graph) {}
    477 
    478       OutArcIt& operator++() { 
    479         _graph->nextOut(*this);
    480         return *this;
    481       }
    482 
    483     };
    484 
    485 
    486     class InArcIt : public Arc { 
     470      OutArcIt(const Graph& graph, const Node& node)
     471        : _graph(&graph) {
     472        _graph->firstOut(*this, node);
     473      }
     474
     475      OutArcIt(const Graph& graph, const Arc& arc)
     476        : Arc(arc), _graph(&graph) {}
     477
     478      OutArcIt& operator++() {
     479        _graph->nextOut(*this);
     480        return *this;
     481      }
     482
     483    };
     484
     485
     486    class InArcIt : public Arc {
    487487      const Graph* _graph;
    488488    public:
     
    492492      InArcIt(Invalid i) : Arc(i) { }
    493493
    494       InArcIt(const Graph& graph, const Node& node) 
    495         : _graph(&graph) {
    496         _graph->firstIn(*this, node);
    497       }
    498 
    499       InArcIt(const Graph& graph, const Arc& arc) : 
    500         Arc(arc), _graph(&graph) {}
    501 
    502       InArcIt& operator++() { 
    503         _graph->nextIn(*this);
    504         return *this;
    505       }
    506 
    507     };
    508 
    509 
    510     class EdgeIt : public Parent::Edge { 
     494      InArcIt(const Graph& graph, const Node& node)
     495        : _graph(&graph) {
     496        _graph->firstIn(*this, node);
     497      }
     498
     499      InArcIt(const Graph& graph, const Arc& arc) :
     500        Arc(arc), _graph(&graph) {}
     501
     502      InArcIt& operator++() {
     503        _graph->nextIn(*this);
     504        return *this;
     505      }
     506
     507    };
     508
     509
     510    class EdgeIt : public Parent::Edge {
    511511      const Graph* _graph;
    512512    public:
     
    517517
    518518      explicit EdgeIt(const Graph& graph) : _graph(&graph) {
    519         _graph->first(static_cast<Edge&>(*this));
    520       }
    521 
    522       EdgeIt(const Graph& graph, const Edge& edge) : 
    523         Edge(edge), _graph(&graph) { }
    524 
    525       EdgeIt& operator++() { 
    526         _graph->next(*this);
    527         return *this;
     519        _graph->first(static_cast<Edge&>(*this));
     520      }
     521
     522      EdgeIt(const Graph& graph, const Edge& edge) :
     523        Edge(edge), _graph(&graph) { }
     524
     525      EdgeIt& operator++() {
     526        _graph->next(*this);
     527        return *this;
    528528      }
    529529
     
    541541
    542542      IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) {
    543         _graph->firstInc(*this, _direction, node);
     543        _graph->firstInc(*this, _direction, node);
    544544      }
    545545
    546546      IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node)
    547         : _graph(&graph), Edge(edge) {
    548         _direction = (_graph->source(edge) == node);
     547        : _graph(&graph), Edge(edge) {
     548        _direction = (_graph->source(edge) == node);
    549549      }
    550550
    551551      IncEdgeIt& operator++() {
    552         _graph->nextInc(*this, _direction);
    553         return *this;
     552        _graph->nextInc(*this, _direction);
     553        return *this;
    554554      }
    555555    };
     
    599599
    600600    template <typename _Value>
    601     class NodeMap 
     601    class NodeMap
    602602      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
    603603    public:
     
    605605      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
    606606
    607       NodeMap(const Graph& graph) 
    608         : Parent(graph) {}
    609       NodeMap(const Graph& graph, const _Value& value) 
    610         : Parent(graph, value) {}
     607      NodeMap(const Graph& graph)
     608        : Parent(graph) {}
     609      NodeMap(const Graph& graph, const _Value& value)
     610        : Parent(graph, value) {}
    611611
    612612      NodeMap& operator=(const NodeMap& cmap) {
    613         return operator=<NodeMap>(cmap);
     613        return operator=<NodeMap>(cmap);
    614614      }
    615615
     
    617617      NodeMap& operator=(const CMap& cmap) {
    618618        Parent::operator=(cmap);
    619         return *this;
     619        return *this;
    620620      }
    621621
     
    623623
    624624    template <typename _Value>
    625     class ArcMap 
     625    class ArcMap
    626626      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
    627627    public:
     
    629629      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
    630630
    631       ArcMap(const Graph& graph) 
    632         : Parent(graph) {}
    633       ArcMap(const Graph& graph, const _Value& value) 
    634         : Parent(graph, value) {}
     631      ArcMap(const Graph& graph)
     632        : Parent(graph) {}
     633      ArcMap(const Graph& graph, const _Value& value)
     634        : Parent(graph, value) {}
    635635
    636636      ArcMap& operator=(const ArcMap& cmap) {
    637         return operator=<ArcMap>(cmap);
     637        return operator=<ArcMap>(cmap);
    638638      }
    639639
     
    641641      ArcMap& operator=(const CMap& cmap) {
    642642        Parent::operator=(cmap);
    643         return *this;
     643        return *this;
    644644      }
    645645    };
     
    647647
    648648    template <typename _Value>
    649     class EdgeMap 
     649    class EdgeMap
    650650      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
    651651    public:
     
    653653      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    654654
    655       EdgeMap(const Graph& graph) 
    656         : Parent(graph) {}
    657 
    658       EdgeMap(const Graph& graph, const _Value& value) 
    659         : Parent(graph, value) {}
     655      EdgeMap(const Graph& graph)
     656        : Parent(graph) {}
     657
     658      EdgeMap(const Graph& graph, const _Value& value)
     659        : Parent(graph, value) {}
    660660
    661661      EdgeMap& operator=(const EdgeMap& cmap) {
    662         return operator=<EdgeMap>(cmap);
     662        return operator=<EdgeMap>(cmap);
    663663      }
    664664
     
    666666      EdgeMap& operator=(const CMap& cmap) {
    667667        Parent::operator=(cmap);
    668         return *this;
     668        return *this;
    669669      }
    670670
     
    684684      std::vector<Arc> ev;
    685685      ev.push_back(Parent::direct(edge, true));
    686       ev.push_back(Parent::direct(edge, false));     
     686      ev.push_back(Parent::direct(edge, false));
    687687      notifier(Arc()).add(ev);
    688688      return edge;
    689689    }
    690    
     690
    691691    void clear() {
    692692      notifier(Arc()).clear();
     
    697697
    698698    template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
    699     void build(const Graph& graph, NodeRefMap& nodeRef, 
     699    void build(const Graph& graph, NodeRefMap& nodeRef,
    700700               EdgeRefMap& edgeRef) {
    701701      Parent::build(graph, nodeRef, edgeRef);
     
    709709      Parent::firstOut(arc, node);
    710710      while (arc != INVALID ) {
    711         erase(arc);
    712         Parent::firstOut(arc, node);
    713       } 
     711        erase(arc);
     712        Parent::firstOut(arc, node);
     713      }
    714714
    715715      Parent::firstIn(arc, node);
    716716      while (arc != INVALID ) {
    717         erase(arc);
    718         Parent::firstIn(arc, node);
     717        erase(arc);
     718        Parent::firstIn(arc, node);
    719719      }
    720720
     
    726726      std::vector<Arc> av;
    727727      av.push_back(Parent::direct(edge, true));
    728       av.push_back(Parent::direct(edge, false));     
     728      av.push_back(Parent::direct(edge, false));
    729729      notifier(Arc()).erase(av);
    730730      notifier(Edge()).erase(edge);
     
    733733
    734734    GraphExtender() {
    735       node_notifier.setContainer(*this); 
     735      node_notifier.setContainer(*this);
    736736      arc_notifier.setContainer(*this);
    737737      edge_notifier.setContainer(*this);
    738     } 
     738    }
    739739
    740740    ~GraphExtender() {
    741741      edge_notifier.clear();
    742742      arc_notifier.clear();
    743       node_notifier.clear(); 
    744     } 
     743      node_notifier.clear();
     744    }
    745745
    746746  };
  • lemon/bits/invalid.h

    r49 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3535    bool operator< (Invalid) { return false; }
    3636  };
    37  
     37
    3838  /// \brief Invalid iterators.
    3939  ///
     
    5353
    5454#endif
    55  
     55
  • lemon/bits/map_extender.h

    r107 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3333
    3434  /// \ingroup graphbits
    35   /// 
     35  ///
    3636  /// \brief Extender for maps
    3737  template <typename _Map>
     
    5757  public:
    5858
    59     MapExtender(const Graph& graph) 
     59    MapExtender(const Graph& graph)
    6060      : Parent(graph) {}
    6161
    62     MapExtender(const Graph& graph, const Value& value) 
     62    MapExtender(const Graph& graph, const Value& value)
    6363      : Parent(graph, value) {}
    6464
     
    7171      Parent::operator=(cmap);
    7272      return *this;
    73     } 
     73    }
    7474
    7575    class MapIt : public Item {
    7676    public:
    77      
     77
    7878      typedef Item Parent;
    7979      typedef typename Map::Value Value;
    80      
     80
    8181      MapIt() {}
    8282
     
    8787      }
    8888
    89       MapIt(const Map& _map, const Item& item) 
    90         : Parent(item), map(_map) {}
    91 
    92       MapIt& operator++() { 
    93         map.notifier()->next(*this);
    94         return *this;
    95       }
    96      
     89      MapIt(const Map& _map, const Item& item)
     90        : Parent(item), map(_map) {}
     91
     92      MapIt& operator++() {
     93        map.notifier()->next(*this);
     94        return *this;
     95      }
     96
    9797      typename MapTraits<Map>::ConstReturnValue operator*() const {
    98         return map[*this];
     98        return map[*this];
    9999      }
    100100
    101101      typename MapTraits<Map>::ReturnValue operator*() {
    102         return map[*this];
    103       }
    104      
     102        return map[*this];
     103      }
     104
    105105      void set(const Value& value) {
    106         map.set(*this, value);
    107       }
    108      
     106        map.set(*this, value);
     107      }
     108
    109109    protected:
    110110      Map& map;
    111      
     111
    112112    };
    113113
     
    118118
    119119      typedef typename Map::Value Value;
    120      
     120
    121121      ConstMapIt() {}
    122122
     
    127127      }
    128128
    129       ConstMapIt(const Map& _map, const Item& item) 
    130         : Parent(item), map(_map) {}
    131 
    132       ConstMapIt& operator++() { 
    133         map.notifier()->next(*this);
    134         return *this;
     129      ConstMapIt(const Map& _map, const Item& item)
     130        : Parent(item), map(_map) {}
     131
     132      ConstMapIt& operator++() {
     133        map.notifier()->next(*this);
     134        return *this;
    135135      }
    136136
    137137      typename MapTraits<Map>::ConstReturnValue operator*() const {
    138         return map[*this];
     138        return map[*this];
    139139      }
    140140
     
    145145    class ItemIt : public Item {
    146146    public:
    147      
    148       typedef Item Parent;
    149      
     147
     148      typedef Item Parent;
     149
    150150      ItemIt() {}
    151151
     
    156156      }
    157157
    158       ItemIt(const Map& _map, const Item& item) 
    159         : Parent(item), map(_map) {}
    160 
    161       ItemIt& operator++() { 
    162         map.notifier()->next(*this);
    163         return *this;
     158      ItemIt(const Map& _map, const Item& item)
     159        : Parent(item), map(_map) {}
     160
     161      ItemIt& operator++() {
     162        map.notifier()->next(*this);
     163        return *this;
    164164      }
    165165
    166166    protected:
    167167      const Map& map;
    168      
     168
    169169    };
    170170  };
    171171
    172172  /// \ingroup graphbits
    173   /// 
     173  ///
    174174  /// \brief Extender for maps which use a subset of the items.
    175175  template <typename _Graph, typename _Map>
     
    195195  public:
    196196
    197     SubMapExtender(const Graph& _graph) 
     197    SubMapExtender(const Graph& _graph)
    198198      : Parent(_graph), graph(_graph) {}
    199199
    200     SubMapExtender(const Graph& _graph, const Value& _value) 
     200    SubMapExtender(const Graph& _graph, const Value& _value)
    201201      : Parent(_graph, _value), graph(_graph) {}
    202202
     
    213213      }
    214214      return *this;
    215     } 
     215    }
    216216
    217217    class MapIt : public Item {
    218218    public:
    219      
     219
    220220      typedef Item Parent;
    221221      typedef typename Map::Value Value;
    222      
     222
    223223      MapIt() {}
    224224
     
    229229      }
    230230
    231       MapIt(const Map& _map, const Item& item) 
    232         : Parent(item), map(_map) {}
    233 
    234       MapIt& operator++() { 
    235         map.graph.next(*this);
    236         return *this;
    237       }
    238      
     231      MapIt(const Map& _map, const Item& item)
     232        : Parent(item), map(_map) {}
     233
     234      MapIt& operator++() {
     235        map.graph.next(*this);
     236        return *this;
     237      }
     238
    239239      typename MapTraits<Map>::ConstReturnValue operator*() const {
    240         return map[*this];
     240        return map[*this];
    241241      }
    242242
    243243      typename MapTraits<Map>::ReturnValue operator*() {
    244         return map[*this];
    245       }
    246      
     244        return map[*this];
     245      }
     246
    247247      void set(const Value& value) {
    248         map.set(*this, value);
    249       }
    250      
     248        map.set(*this, value);
     249      }
     250
    251251    protected:
    252252      Map& map;
    253      
     253
    254254    };
    255255
     
    260260
    261261      typedef typename Map::Value Value;
    262      
     262
    263263      ConstMapIt() {}
    264264
     
    269269      }
    270270
    271       ConstMapIt(const Map& _map, const Item& item) 
    272         : Parent(item), map(_map) {}
    273 
    274       ConstMapIt& operator++() { 
    275         map.graph.next(*this);
    276         return *this;
     271      ConstMapIt(const Map& _map, const Item& item)
     272        : Parent(item), map(_map) {}
     273
     274      ConstMapIt& operator++() {
     275        map.graph.next(*this);
     276        return *this;
    277277      }
    278278
    279279      typename MapTraits<Map>::ConstReturnValue operator*() const {
    280         return map[*this];
     280        return map[*this];
    281281      }
    282282
     
    287287    class ItemIt : public Item {
    288288    public:
    289      
    290       typedef Item Parent;
    291      
     289
     290      typedef Item Parent;
     291
    292292      ItemIt() {}
    293293
     
    298298      }
    299299
    300       ItemIt(const Map& _map, const Item& item) 
    301         : Parent(item), map(_map) {}
    302 
    303       ItemIt& operator++() { 
    304         map.graph.next(*this);
    305         return *this;
     300      ItemIt(const Map& _map, const Item& item)
     301        : Parent(item), map(_map) {}
     302
     303      ItemIt& operator++() {
     304        map.graph.next(*this);
     305        return *this;
    306306      }
    307307
    308308    protected:
    309309      const Map& map;
    310      
    311     };
    312    
     310
     311    };
     312
    313313  private:
    314314
    315315    const Graph& graph;
    316    
     316
    317317  };
    318318
  • lemon/bits/path_dump.h

    r100 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5454      RevArcIt() {}
    5555      RevArcIt(Invalid) : path(0), current(INVALID) {}
    56       RevArcIt(const PredMapPath& _path) 
     56      RevArcIt(const PredMapPath& _path)
    5757        : path(&_path), current(_path.target) {
    5858        if (path->predMap[current] == INVALID) current = INVALID;
     
    6969      }
    7070
    71       bool operator==(const RevArcIt& e) const { 
    72         return current == e.current; 
     71      bool operator==(const RevArcIt& e) const {
     72        return current == e.current;
    7373      }
    7474
    7575      bool operator!=(const RevArcIt& e) const {
    76         return current != e.current; 
     76        return current != e.current;
    7777      }
    7878
    79       bool operator<(const RevArcIt& e) const { 
    80         return current < e.current; 
     79      bool operator<(const RevArcIt& e) const {
     80        return current < e.current;
    8181      }
    82      
     82
    8383    private:
    8484      const PredMapPath* path;
     
    102102    typedef _PredMatrixMap PredMatrixMap;
    103103
    104     PredMatrixMapPath(const Digraph& _digraph, 
     104    PredMatrixMapPath(const Digraph& _digraph,
    105105                      const PredMatrixMap& _predMatrixMap,
    106                       typename Digraph::Node _source, 
     106                      typename Digraph::Node _source,
    107107                      typename Digraph::Node _target)
    108       : digraph(_digraph), predMatrixMap(_predMatrixMap), 
     108      : digraph(_digraph), predMatrixMap(_predMatrixMap),
    109109        source(_source), target(_target) {}
    110110
     
    128128      RevArcIt() {}
    129129      RevArcIt(Invalid) : path(0), current(INVALID) {}
    130       RevArcIt(const PredMatrixMapPath& _path) 
     130      RevArcIt(const PredMatrixMapPath& _path)
    131131        : path(&_path), current(_path.target) {
    132         if (path->predMatrixMap(path->source, current) == INVALID) 
     132        if (path->predMatrixMap(path->source, current) == INVALID)
    133133          current = INVALID;
    134134      }
     
    139139
    140140      RevArcIt& operator++() {
    141         current = 
     141        current =
    142142          path->digraph.source(path->predMatrixMap(path->source, current));
    143         if (path->predMatrixMap(path->source, current) == INVALID) 
     143        if (path->predMatrixMap(path->source, current) == INVALID)
    144144          current = INVALID;
    145145        return *this;
    146146      }
    147147
    148       bool operator==(const RevArcIt& e) const { 
    149         return current == e.current; 
     148      bool operator==(const RevArcIt& e) const {
     149        return current == e.current;
    150150      }
    151151
    152152      bool operator!=(const RevArcIt& e) const {
    153         return current != e.current; 
     153        return current != e.current;
    154154      }
    155155
    156       bool operator<(const RevArcIt& e) const { 
    157         return current < e.current; 
     156      bool operator<(const RevArcIt& e) const {
     157        return current < e.current;
    158158      }
    159      
     159
    160160    private:
    161161      const PredMatrixMapPath* path;
  • lemon/bits/traits.h

    r184 r209  
    1 
    2 /* -*- C++ -*-
    3  *
    4  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    54 *
    65 * Copyright (C) 2003-2008
     
    3029  template <typename _Graph, typename _Item>
    3130  class ItemSetTraits {};
    32  
     31
    3332
    3433  template <typename Graph, typename Enable = void>
     
    3837  template <typename Graph>
    3938  struct NodeNotifierIndicator<
    40     Graph, 
     39    Graph,
    4140    typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type
    42   > { 
     41  > {
    4342    typedef typename Graph::NodeNotifier Type;
    4443  };
     
    4746  class ItemSetTraits<_Graph, typename _Graph::Node> {
    4847  public:
    49    
     48
    5049    typedef _Graph Graph;
    5150
     
    5857    class Map : public Graph::template NodeMap<_Value> {
    5958    public:
    60       typedef typename Graph::template NodeMap<_Value> Parent; 
    61       typedef typename Graph::template NodeMap<_Value> Type; 
     59      typedef typename Graph::template NodeMap<_Value> Parent;
     60      typedef typename Graph::template NodeMap<_Value> Type;
    6261      typedef typename Parent::Value Value;
    6362
    6463      Map(const Graph& _digraph) : Parent(_digraph) {}
    65       Map(const Graph& _digraph, const Value& _value) 
    66         : Parent(_digraph, _value) {}
     64      Map(const Graph& _digraph, const Value& _value)
     65        : Parent(_digraph, _value) {}
    6766
    6867     };
     
    7675  template <typename Graph>
    7776  struct ArcNotifierIndicator<
    78     Graph, 
     77    Graph,
    7978    typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type
    80   > { 
     79  > {
    8180    typedef typename Graph::ArcNotifier Type;
    8281  };
     
    8584  class ItemSetTraits<_Graph, typename _Graph::Arc> {
    8685  public:
    87    
     86
    8887    typedef _Graph Graph;
    8988
     
    9695    class Map : public Graph::template ArcMap<_Value> {
    9796    public:
    98       typedef typename Graph::template ArcMap<_Value> Parent; 
    99       typedef typename Graph::template ArcMap<_Value> Type; 
     97      typedef typename Graph::template ArcMap<_Value> Parent;
     98      typedef typename Graph::template ArcMap<_Value> Type;
    10099      typedef typename Parent::Value Value;
    101100
    102101      Map(const Graph& _digraph) : Parent(_digraph) {}
    103       Map(const Graph& _digraph, const Value& _value) 
    104         : Parent(_digraph, _value) {}
     102      Map(const Graph& _digraph, const Value& _value)
     103        : Parent(_digraph, _value) {}
    105104    };
    106105
     
    113112  template <typename Graph>
    114113  struct EdgeNotifierIndicator<
    115     Graph, 
     114    Graph,
    116115    typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type
    117   > { 
     116  > {
    118117    typedef typename Graph::EdgeNotifier Type;
    119118  };
     
    122121  class ItemSetTraits<_Graph, typename _Graph::Edge> {
    123122  public:
    124    
     123
    125124    typedef _Graph Graph;
    126125
     
    133132    class Map : public Graph::template EdgeMap<_Value> {
    134133    public:
    135       typedef typename Graph::template EdgeMap<_Value> Parent; 
    136       typedef typename Graph::template EdgeMap<_Value> Type; 
     134      typedef typename Graph::template EdgeMap<_Value> Parent;
     135      typedef typename Graph::template EdgeMap<_Value> Type;
    137136      typedef typename Parent::Value Value;
    138137
    139138      Map(const Graph& _digraph) : Parent(_digraph) {}
    140       Map(const Graph& _digraph, const Value& _value) 
    141         : Parent(_digraph, _value) {}
     139      Map(const Graph& _digraph, const Value& _value)
     140        : Parent(_digraph, _value) {}
    142141    };
    143142
     
    157156  template <typename Map>
    158157  struct MapTraits<
    159     Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > 
     158    Map, typename enable_if<typename Map::ReferenceMapTag, void>::type >
    160159  {
    161160    typedef True ReferenceMapTag;
    162    
     161
    163162    typedef typename Map::Key Key;
    164163    typedef typename Map::Value Value;
     
    167166    typedef typename Map::Reference ReturnValue;
    168167
    169     typedef typename Map::ConstReference ConstReference; 
     168    typedef typename Map::ConstReference ConstReference;
    170169    typedef typename Map::Reference Reference;
    171170 };
     
    185184  template <typename MatrixMap>
    186185  struct MatrixMapTraits<
    187     MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, 
    188                                   void>::type > 
     186    MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
     187                                  void>::type >
    189188  {
    190189    typedef True ReferenceMapTag;
    191    
     190
    192191    typedef typename MatrixMap::FirstKey FirstKey;
    193192    typedef typename MatrixMap::SecondKey SecondKey;
     
    197196    typedef typename MatrixMap::Reference ReturnValue;
    198197
    199     typedef typename MatrixMap::ConstReference ConstReference; 
     198    typedef typename MatrixMap::ConstReference ConstReference;
    200199    typedef typename MatrixMap::Reference Reference;
    201200 };
     
    210209  template <typename Graph>
    211210  struct NodeNumTagIndicator<
    212     Graph, 
     211    Graph,
    213212    typename enable_if<typename Graph::NodeNumTag, void>::type
    214213  > {
     
    223222  template <typename Graph>
    224223  struct EdgeNumTagIndicator<
    225     Graph, 
     224    Graph,
    226225    typename enable_if<typename Graph::EdgeNumTag, void>::type
    227226  > {
     
    236235  template <typename Graph>
    237236  struct FindEdgeTagIndicator<
    238     Graph, 
     237    Graph,
    239238    typename enable_if<typename Graph::FindEdgeTag, void>::type
    240239  > {
     
    249248  template <typename Graph>
    250249  struct UndirectedTagIndicator<
    251     Graph, 
     250    Graph,
    252251    typename enable_if<typename Graph::UndirectedTag, void>::type
    253252  > {
     
    262261  template <typename Graph>
    263262  struct BuildTagIndicator<
    264     Graph, 
     263    Graph,
    265264    typename enable_if<typename Graph::BuildTag, void>::type
    266265  > {
  • lemon/bits/utility.h

    r117 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    8484
    8585  /**************** enable_if from BOOST ****************/
    86  
     86
    8787  template <typename Type, typename T = void>
    8888  struct exists {
     
    9090  };
    9191
    92  
     92
    9393  template <bool B, class T = void>
    9494  struct enable_if_c {
     
    9999  struct enable_if_c<false, T> {};
    100100
    101   template <class Cond, class T = void> 
     101  template <class Cond, class T = void>
    102102  struct enable_if : public enable_if_c<Cond::value, T> {};
    103103
     
    110110  struct lazy_enable_if_c<false, T> {};
    111111
    112   template <class Cond, class T> 
     112  template <class Cond, class T>
    113113  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
    114114
     
    122122  struct disable_if_c<true, T> {};
    123123
    124   template <class Cond, class T = void> 
     124  template <class Cond, class T = void>
    125125  struct disable_if : public disable_if_c<Cond::value, T> {};
    126126
     
    133133  struct lazy_disable_if_c<true, T> {};
    134134
    135   template <class Cond, class T> 
     135  template <class Cond, class T>
    136136  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
    137137
  • lemon/bits/vector_map.h

    r157 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5050  /// \todo Fix the doc: there is _Graph parameter instead of _Notifier.
    5151  template <typename _Graph, typename _Item, typename _Value>
    52   class VectorMap 
     52  class VectorMap
    5353    : public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
    5454  private:
    55                
     55
    5656    /// The container type of the map.
    57     typedef std::vector<_Value> Container;     
     57    typedef std::vector<_Value> Container;
    5858
    5959  public:
    6060
    61     /// The graph type of the map. 
     61    /// The graph type of the map.
    6262    typedef _Graph Graph;
    6363    /// The item type of the map.
     
    9494    }
    9595
    96     /// \brief Constructor uses given value to initialize the map. 
    97     ///
    98     /// It constructs a map uses a given value to initialize the map. 
     96    /// \brief Constructor uses given value to initialize the map.
     97    ///
     98    /// It constructs a map uses a given value to initialize the map.
    9999    /// It adds all the items of the graph to the map.
    100100    VectorMap(const Graph& graph, const Value& value) {
     
    108108    VectorMap(const VectorMap& _copy) : Parent() {
    109109      if (_copy.attached()) {
    110         Parent::attach(*_copy.notifier());
    111         container = _copy.container;
     110        Parent::attach(*_copy.notifier());
     111        container = _copy.container;
    112112      }
    113113    }
     
    116116    ///
    117117    /// This operator assigns for each item in the map the
    118     /// value mapped to the same item in the copied map. 
     118    /// value mapped to the same item in the copied map.
    119119    /// The parameter map should be indiced with the same
    120120    /// itemset because this assign operator does not change
    121     /// the container of the map. 
     121    /// the container of the map.
    122122    VectorMap& operator=(const VectorMap& cmap) {
    123123      return operator=<VectorMap>(cmap);
     
    130130    /// concecpt and could be indiced by the current item set of
    131131    /// the NodeMap. In this case the value for each item
    132     /// is assigned by the value of the given ReadMap. 
     132    /// is assigned by the value of the given ReadMap.
    133133    template <typename CMap>
    134134    VectorMap& operator=(const CMap& cmap) {
     
    141141      return *this;
    142142    }
    143    
     143
    144144  public:
    145145
     
    147147    ///
    148148    /// The subscript operator. The map can be subscripted by the
    149     /// actual items of the graph.     
     149    /// actual items of the graph.
    150150    Reference operator[](const Key& key) {
    151151      return container[Parent::notifier()->id(key)];
    152     } 
    153                
     152    }
     153
    154154    /// \brief The const subcript operator.
    155155    ///
    156156    /// The const subscript operator. The map can be subscripted by the
    157     /// actual items of the graph. 
     157    /// actual items of the graph.
    158158    ConstReference operator[](const Key& key) const {
    159159      return container[Parent::notifier()->id(key)];
     
    171171
    172172    /// \brief Adds a new key to the map.
    173     ///         
     173    ///
    174174    /// It adds a new key to the map. It called by the observer notifier
    175     /// and it overrides the add() member function of the observer base.     
     175    /// and it overrides the add() member function of the observer base.
    176176    virtual void add(const Key& key) {
    177177      int id = Parent::notifier()->id(key);
    178178      if (id >= int(container.size())) {
    179         container.resize(id + 1);
     179        container.resize(id + 1);
    180180      }
    181181    }
    182182
    183183    /// \brief Adds more new keys to the map.
    184     ///         
     184    ///
    185185    /// It adds more new keys to the map. It called by the observer notifier
    186     /// and it overrides the add() member function of the observer base.     
     186    /// and it overrides the add() member function of the observer base.
    187187    virtual void add(const std::vector<Key>& keys) {
    188188      int max = container.size() - 1;
     
    199199    ///
    200200    /// Erase a key from the map. It called by the observer notifier
    201     /// and it overrides the erase() member function of the observer base.     
     201    /// and it overrides the erase() member function of the observer base.
    202202    virtual void erase(const Key& key) {
    203203      container[Parent::notifier()->id(key)] = Value();
     
    207207    ///
    208208    /// Erase more keys from the map. It called by the observer notifier
    209     /// and it overrides the erase() member function of the observer base.     
     209    /// and it overrides the erase() member function of the observer base.
    210210    virtual void erase(const std::vector<Key>& keys) {
    211211      for (int i = 0; i < int(keys.size()); ++i) {
    212         container[Parent::notifier()->id(keys[i])] = Value();
    213       }
    214     }
    215    
     212        container[Parent::notifier()->id(keys[i])] = Value();
     213      }
     214    }
     215
    216216    /// \brief Buildes the map.
    217     /// 
     217    ///
    218218    /// It buildes the map. It called by the observer notifier
    219219    /// and it overrides the build() member function of the observer base.
    220     virtual void build() { 
     220    virtual void build() {
    221221      int size = Parent::notifier()->maxId() + 1;
    222222      container.reserve(size);
     
    227227    ///
    228228    /// It erase all items from the map. It called by the observer notifier
    229     /// and it overrides the clear() member function of the observer base.     
    230     virtual void clear() { 
     229    /// and it overrides the clear() member function of the observer base.
     230    virtual void clear() {
    231231      container.clear();
    232232    }
    233    
     233
    234234  private:
    235                
     235
    236236    Container container;
    237237
  • lemon/color.cc

    r128 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2525
    2626  const Color WHITE(1,1,1);
    27  
     27
    2828  const Color BLACK(0,0,0);
    2929  const Color RED(1,0,0);
     
    4141  const Color DARK_MAGENTA(.5,0,.5);
    4242  const Color DARK_CYAN(0,.5,.5);
    43    
     43
    4444} //namespace lemon
  • lemon/color.h

    r206 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6363
    6464  /// White color constant
    65   extern const Color WHITE; 
     65  extern const Color WHITE;
    6666  /// Black color constant
    6767  extern const Color BLACK;
     
    131131        colors.push_back(Color(1,0,1));
    132132        colors.push_back(Color(0,1,1));
    133      
     133
    134134        colors.push_back(Color(.5,0,0));
    135135        colors.push_back(Color(0,.5,0));
     
    138138        colors.push_back(Color(.5,0,.5));
    139139        colors.push_back(Color(0,.5,.5));
    140      
     140
    141141        colors.push_back(Color(.5,.5,.5));
    142142        colors.push_back(Color(1,.5,.5));
     
    146146        colors.push_back(Color(1,.5,1));
    147147        colors.push_back(Color(.5,1,1));
    148      
     148
    149149        colors.push_back(Color(1,.5,0));
    150150        colors.push_back(Color(.5,1,0));
     
    172172    }
    173173    ///Adds a new color to the end of the color list.
    174     void add(const Color &c) 
     174    void add(const Color &c)
    175175    {
    176176      colors.push_back(c);
     
    187187  ///Returns a \ref Color which is as different from the given parameter
    188188  ///as it is possible.
    189   inline Color distantColor(const Color &c) 
     189  inline Color distantColor(const Color &c)
    190190  {
    191191    return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
  • lemon/concept_check.h

    r53 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3737///\brief Basic utilities for concept checking.
    3838///
    39 ///\todo Are we still using BOOST concept checking utility? 
     39///\todo Are we still using BOOST concept checking utility?
    4040///Is the BOOST copyright notice necessary?
    4141
  • lemon/concepts/digraph.h

    r125 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4747    private:
    4848      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
    49      
     49
    5050      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
    5151      ///
     
    5353      ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
    5454      ///\e not allowed. Use DigraphCopy() instead.
    55      
     55
    5656      ///Assignment of \ref Digraph "Digraph"s to another ones are
    5757      ///\e not allowed.  Use DigraphCopy() instead.
     
    9696
    9797        /// Inequality operator
    98        
     98
    9999        /// \sa operator==(Node n)
    100100        ///
    101101        bool operator!=(Node) const { return true; }
    102102
    103         /// Artificial ordering operator.
    104        
    105         /// To allow the use of digraph descriptors as key type in std::map or
    106         /// similar associative container we require this.
    107         ///
    108         /// \note This operator only have to define some strict ordering of
    109         /// the items; this order has nothing to do with the iteration
    110         /// ordering of the items.
    111         bool operator<(Node) const { return false; }
    112 
    113       };
    114    
     103        /// Artificial ordering operator.
     104
     105        /// To allow the use of digraph descriptors as key type in std::map or
     106        /// similar associative container we require this.
     107        ///
     108        /// \note This operator only have to define some strict ordering of
     109        /// the items; this order has nothing to do with the iteration
     110        /// ordering of the items.
     111        bool operator<(Node) const { return false; }
     112
     113      };
     114
    115115      /// This iterator goes through each node.
    116116
     
    130130        NodeIt() { }
    131131        /// Copy constructor.
    132        
     132
    133133        /// Copy constructor.
    134134        ///
     
    146146        /// Node -> NodeIt conversion.
    147147
    148         /// Sets the iterator to the node of \c the digraph pointed by 
    149         /// the trivial iterator.
    150         /// This feature necessitates that each time we 
     148        /// Sets the iterator to the node of \c the digraph pointed by
     149        /// the trivial iterator.
     150        /// This feature necessitates that each time we
    151151        /// iterate the arc-set, the iteration order is the same.
    152152        NodeIt(const Digraph&, const Node&) { }
     
    157157        NodeIt& operator++() { return *this; }
    158158      };
    159    
    160    
     159
     160
    161161      /// Class for identifying an arc of the digraph
    162162
     
    192192        bool operator!=(Arc) const { return true; }
    193193
    194         /// Artificial ordering operator.
    195        
    196         /// To allow the use of digraph descriptors as key type in std::map or
    197         /// similar associative container we require this.
    198         ///
    199         /// \note This operator only have to define some strict ordering of
    200         /// the items; this order has nothing to do with the iteration
    201         /// ordering of the items.
    202         bool operator<(Arc) const { return false; }
    203       };
    204    
     194        /// Artificial ordering operator.
     195
     196        /// To allow the use of digraph descriptors as key type in std::map or
     197        /// similar associative container we require this.
     198        ///
     199        /// \note This operator only have to define some strict ordering of
     200        /// the items; this order has nothing to do with the iteration
     201        /// ordering of the items.
     202        bool operator<(Arc) const { return false; }
     203      };
     204
    205205      /// This iterator goes trough the outgoing arcs of a node.
    206206
     
    214214      /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
    215215      ///\endcode
    216    
     216
    217217      class OutArcIt : public Arc {
    218218      public:
     
    233233        OutArcIt(Invalid) { }
    234234        /// This constructor sets the iterator to the first outgoing arc.
    235    
     235
    236236        /// This constructor sets the iterator to the first outgoing arc of
    237237        /// the node.
     
    240240
    241241        /// Sets the iterator to the value of the trivial iterator.
    242         /// This feature necessitates that each time we
     242        /// This feature necessitates that each time we
    243243        /// iterate the arc-set, the iteration order is the same.
    244244        OutArcIt(const Digraph&, const Arc&) { }
    245245        ///Next outgoing arc
    246        
    247         /// Assign the iterator to the next 
     246
     247        /// Assign the iterator to the next
    248248        /// outgoing arc of the corresponding node.
    249249        OutArcIt& operator++() { return *this; }
     
    280280        InArcIt(Invalid) { }
    281281        /// This constructor sets the iterator to first incoming arc.
    282    
     282
    283283        /// This constructor set the iterator to the first incoming arc of
    284284        /// the node.
     
    287287
    288288        /// Sets the iterator to the value of the trivial iterator \c e.
    289         /// This feature necessitates that each time we 
     289        /// This feature necessitates that each time we
    290290        /// iterate the arc-set, the iteration order is the same.
    291291        InArcIt(const Digraph&, const Arc&) { }
     
    323323        ArcIt(Invalid) { }
    324324        /// This constructor sets the iterator to the first arc.
    325    
     325
    326326        /// This constructor sets the iterator to the first arc of \c g.
    327327        ///@param g the digraph
     
    330330
    331331        /// Sets the iterator to the value of the trivial iterator \c e.
    332         /// This feature necessitates that each time we 
     332        /// This feature necessitates that each time we
    333333        /// iterate the arc-set, the iteration order is the same.
    334         ArcIt(const Digraph&, const Arc&) { } 
     334        ArcIt(const Digraph&, const Arc&) { }
    335335        ///Next arc
    336        
     336
    337337        /// Assign the iterator to the next arc.
    338338        ArcIt& operator++() { return *this; }
     
    350350
    351351      /// \brief Returns the ID of the node.
    352       int id(Node) const { return -1; } 
     352      int id(Node) const { return -1; }
    353353
    354354      /// \brief Returns the ID of the arc.
    355       int id(Arc) const { return -1; } 
     355      int id(Arc) const { return -1; }
    356356
    357357      /// \brief Returns the node with the given ID.
    358358      ///
    359359      /// \pre The argument should be a valid node ID in the graph.
    360       Node nodeFromId(int) const { return INVALID; } 
     360      Node nodeFromId(int) const { return INVALID; }
    361361
    362362      /// \brief Returns the arc with the given ID.
    363363      ///
    364364      /// \pre The argument should be a valid arc ID in the graph.
    365       Arc arcFromId(int) const { return INVALID; } 
     365      Arc arcFromId(int) const { return INVALID; }
    366366
    367367      /// \brief Returns an upper bound on the node IDs.
    368       int maxNodeId() const { return -1; } 
     368      int maxNodeId() const { return -1; }
    369369
    370370      /// \brief Returns an upper bound on the arc IDs.
    371       int maxArcId() const { return -1; } 
     371      int maxArcId() const { return -1; }
    372372
    373373      void first(Node&) const {}
     
    390390
    391391      // Dummy parameter.
    392       int maxId(Node) const { return -1; } 
     392      int maxId(Node) const { return -1; }
    393393      // Dummy parameter.
    394       int maxId(Arc) const { return -1; } 
     394      int maxId(Arc) const { return -1; }
    395395
    396396      /// \brief The base node of the iterator.
     
    424424
    425425      /// \brief Read write map of the nodes to type \c T.
    426       /// 
     426      ///
    427427      /// ReadWrite map of the nodes to type \c T.
    428428      /// \sa Reference
    429       template<class T> 
     429      template<class T>
    430430      class NodeMap : public ReadWriteMap< Node, T > {
    431431      public:
     
    440440        ///Assignment operator
    441441        template <typename CMap>
    442         NodeMap& operator=(const CMap&) { 
     442        NodeMap& operator=(const CMap&) {
    443443          checkConcept<ReadMap<Node, T>, CMap>();
    444           return *this; 
     444          return *this;
    445445        }
    446446      };
     
    450450      /// Reference map of the arcs to type \c T.
    451451      /// \sa Reference
    452       template<class T> 
     452      template<class T>
    453453      class ArcMap : public ReadWriteMap<Arc,T> {
    454454      public:
     
    462462        ///Assignment operator
    463463        template <typename CMap>
    464         ArcMap& operator=(const CMap&) { 
     464        ArcMap& operator=(const CMap&) {
    465465          checkConcept<ReadMap<Arc, T>, CMap>();
    466           return *this; 
     466          return *this;
    467467        }
    468468      };
     
    472472        void constraints() {
    473473          checkConcept<IterableDigraphComponent<>, _Digraph>();
    474           checkConcept<IDableDigraphComponent<>, _Digraph>();
     474          checkConcept<IDableDigraphComponent<>, _Digraph>();
    475475          checkConcept<MappableDigraphComponent<>, _Digraph>();
    476476        }
     
    478478
    479479    };
    480    
    481   } //namespace concepts 
     480
     481  } //namespace concepts
    482482} //namespace lemon
    483483
  • lemon/concepts/graph.h

    r125 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6666    /// direction. The IncEdgeIt iterates also on the same edges
    6767    /// as the OutArcIt and InArcIt but it is not convertible to Arc just
    68     /// to Edge. 
     68    /// to Edge.
    6969    class Graph {
    7070    public:
     
    7373      ///
    7474      /// The undirected graph should be tagged by the UndirectedTag. This
    75       /// tag helps the enable_if technics to make compile time 
    76       /// specializations for undirected graphs. 
     75      /// tag helps the enable_if technics to make compile time
     76      /// specializations for undirected graphs.
    7777      typedef True UndirectedTag;
    7878
    79       /// \brief The base type of node iterators, 
     79      /// \brief The base type of node iterators,
    8080      /// or in other words, the trivial node iterator.
    8181      ///
    8282      /// This is the base type of each node iterator,
    8383      /// thus each kind of node iterator converts to this.
    84       /// More precisely each kind of node iterator should be inherited 
     84      /// More precisely each kind of node iterator should be inherited
    8585      /// from the trivial node iterator.
    8686      class Node {
     
    109109
    110110        /// Inequality operator
    111        
     111
    112112        /// \sa operator==(Node n)
    113113        ///
    114114        bool operator!=(Node) const { return true; }
    115115
    116         /// Artificial ordering operator.
    117        
    118         /// To allow the use of graph descriptors as key type in std::map or
    119         /// similar associative container we require this.
    120         ///
    121         /// \note This operator only have to define some strict ordering of
    122         /// the items; this order has nothing to do with the iteration
    123         /// ordering of the items.
    124         bool operator<(Node) const { return false; }
    125 
    126       };
    127    
     116        /// Artificial ordering operator.
     117
     118        /// To allow the use of graph descriptors as key type in std::map or
     119        /// similar associative container we require this.
     120        ///
     121        /// \note This operator only have to define some strict ordering of
     122        /// the items; this order has nothing to do with the iteration
     123        /// ordering of the items.
     124        bool operator<(Node) const { return false; }
     125
     126      };
     127
    128128      /// This iterator goes through each node.
    129129
     
    143143        NodeIt() { }
    144144        /// Copy constructor.
    145        
     145
    146146        /// Copy constructor.
    147147        ///
     
    159159        /// Node -> NodeIt conversion.
    160160
    161         /// Sets the iterator to the node of \c the graph pointed by 
    162         /// the trivial iterator.
    163         /// This feature necessitates that each time we 
     161        /// Sets the iterator to the node of \c the graph pointed by
     162        /// the trivial iterator.
     163        /// This feature necessitates that each time we
    164164        /// iterate the arc-set, the iteration order is the same.
    165165        NodeIt(const Graph&, const Node&) { }
     
    170170        NodeIt& operator++() { return *this; }
    171171      };
    172    
    173    
     172
     173
    174174      /// The base type of the edge iterators.
    175175
     
    204204        bool operator!=(Edge) const { return true; }
    205205
    206         /// Artificial ordering operator.
    207        
    208         /// To allow the use of graph descriptors as key type in std::map or
    209         /// similar associative container we require this.
    210         ///
    211         /// \note This operator only have to define some strict ordering of
    212         /// the items; this order has nothing to do with the iteration
    213         /// ordering of the items.
    214         bool operator<(Edge) const { return false; }
     206        /// Artificial ordering operator.
     207
     208        /// To allow the use of graph descriptors as key type in std::map or
     209        /// similar associative container we require this.
     210        ///
     211        /// \note This operator only have to define some strict ordering of
     212        /// the items; this order has nothing to do with the iteration
     213        /// ordering of the items.
     214        bool operator<(Edge) const { return false; }
    215215      };
    216216
     
    242242        EdgeIt(Invalid) { }
    243243        /// This constructor sets the iterator to the first edge.
    244    
     244
    245245        /// This constructor sets the iterator to the first edge.
    246246        EdgeIt(const Graph&) { }
     
    249249        /// Sets the iterator to the value of the trivial iterator.
    250250        /// This feature necessitates that each time we
    251         /// iterate the edge-set, the iteration order is the 
    252         /// same.
    253         EdgeIt(const Graph&, const Edge&) { } 
     251        /// iterate the edge-set, the iteration order is the
     252        /// same.
     253        EdgeIt(const Graph&, const Edge&) { }
    254254        /// Next edge
    255        
     255
    256256        /// Assign the iterator to the next edge.
    257257        EdgeIt& operator++() { return *this; }
    258258      };
    259259
    260       /// \brief This iterator goes trough the incident undirected 
     260      /// \brief This iterator goes trough the incident undirected
    261261      /// arcs of a node.
    262262      ///
    263263      /// This iterator goes trough the incident edges
    264       /// of a certain node of a graph. You should assume that the 
     264      /// of a certain node of a graph. You should assume that the
    265265      /// loop arcs will be iterated twice.
    266       /// 
     266      ///
    267267      /// Its usage is quite simple, for example you can compute the
    268268      /// degree (i.e. count the number of incident arcs of a node \c n
    269       /// in graph \c g of type \c Graph as follows. 
     269      /// in graph \c g of type \c Graph as follows.
    270270      ///
    271271      ///\code
     
    291291        IncEdgeIt(Invalid) { }
    292292        /// This constructor sets the iterator to first incident arc.
    293    
     293
    294294        /// This constructor set the iterator to the first incident arc of
    295295        /// the node.
     
    298298
    299299        /// Sets the iterator to the value of the trivial iterator \c e.
    300         /// This feature necessitates that each time we 
     300        /// This feature necessitates that each time we
    301301        /// iterate the arc-set, the iteration order is the same.
    302302        IncEdgeIt(const Graph&, const Edge&) { }
     
    304304
    305305        /// Assign the iterator to the next incident arc
    306         /// of the corresponding node.
     306        /// of the corresponding node.
    307307        IncEdgeIt& operator++() { return *this; }
    308308      };
     
    341341        bool operator!=(Arc) const { return true; }
    342342
    343         /// Artificial ordering operator.
    344        
    345         /// To allow the use of graph descriptors as key type in std::map or
    346         /// similar associative container we require this.
    347         ///
    348         /// \note This operator only have to define some strict ordering of
    349         /// the items; this order has nothing to do with the iteration
    350         /// ordering of the items.
    351         bool operator<(Arc) const { return false; }
    352        
    353       }; 
     343        /// Artificial ordering operator.
     344
     345        /// To allow the use of graph descriptors as key type in std::map or
     346        /// similar associative container we require this.
     347        ///
     348        /// \note This operator only have to define some strict ordering of
     349        /// the items; this order has nothing to do with the iteration
     350        /// ordering of the items.
     351        bool operator<(Arc) const { return false; }
     352
     353      };
    354354      /// This iterator goes through each directed arc.
    355355
     
    379379        ArcIt(Invalid) { }
    380380        /// This constructor sets the iterator to the first arc.
    381    
     381
    382382        /// This constructor sets the iterator to the first arc of \c g.
    383383        ///@param g the graph
     
    386386
    387387        /// Sets the iterator to the value of the trivial iterator \c e.
    388         /// This feature necessitates that each time we 
     388        /// This feature necessitates that each time we
    389389        /// iterate the arc-set, the iteration order is the same.
    390         ArcIt(const Graph&, const Arc&) { } 
     390        ArcIt(const Graph&, const Arc&) { }
    391391        ///Next arc
    392        
     392
    393393        /// Assign the iterator to the next arc.
    394394        ArcIt& operator++() { return *this; }
    395395      };
    396    
     396
    397397      /// This iterator goes trough the outgoing directed arcs of a node.
    398398
     
    406406      /// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
    407407      ///\endcode
    408    
     408
    409409      class OutArcIt : public Arc {
    410410      public:
     
    425425        OutArcIt(Invalid) { }
    426426        /// This constructor sets the iterator to the first outgoing arc.
    427    
     427
    428428        /// This constructor sets the iterator to the first outgoing arc of
    429429        /// the node.
     
    431431        ///@param g the graph
    432432        OutArcIt(const Graph& n, const Node& g) {
    433           ignore_unused_variable_warning(n);
    434           ignore_unused_variable_warning(g);
    435         }
     433          ignore_unused_variable_warning(n);
     434          ignore_unused_variable_warning(g);
     435        }
    436436        /// Arc -> OutArcIt conversion
    437437
    438438        /// Sets the iterator to the value of the trivial iterator.
    439         /// This feature necessitates that each time we
     439        /// This feature necessitates that each time we
    440440        /// iterate the arc-set, the iteration order is the same.
    441441        OutArcIt(const Graph&, const Arc&) { }
    442442        ///Next outgoing arc
    443        
    444         /// Assign the iterator to the next 
     443
     444        /// Assign the iterator to the next
    445445        /// outgoing arc of the corresponding node.
    446446        OutArcIt& operator++() { return *this; }
     
    477477        InArcIt(Invalid) { }
    478478        /// This constructor sets the iterator to first incoming arc.
    479    
     479
    480480        /// This constructor set the iterator to the first incoming arc of
    481481        /// the node.
    482482        ///@param n the node
    483483        ///@param g the graph
    484         InArcIt(const Graph& g, const Node& n) { 
    485           ignore_unused_variable_warning(n);
    486           ignore_unused_variable_warning(g);
    487         }
     484        InArcIt(const Graph& g, const Node& n) {
     485          ignore_unused_variable_warning(n);
     486          ignore_unused_variable_warning(g);
     487        }
    488488        /// Arc -> InArcIt conversion
    489489
    490490        /// Sets the iterator to the value of the trivial iterator \c e.
    491         /// This feature necessitates that each time we 
     491        /// This feature necessitates that each time we
    492492        /// iterate the arc-set, the iteration order is the same.
    493493        InArcIt(const Graph&, const Arc&) { }
     
    500500
    501501      /// \brief Read write map of the nodes to type \c T.
    502       /// 
     502      ///
    503503      /// ReadWrite map of the nodes to type \c T.
    504504      /// \sa Reference
    505       template<class T> 
     505      template<class T>
    506506      class NodeMap : public ReadWriteMap< Node, T >
    507507      {
     
    517517        ///Assignment operator
    518518        template <typename CMap>
    519         NodeMap& operator=(const CMap&) { 
     519        NodeMap& operator=(const CMap&) {
    520520          checkConcept<ReadMap<Node, T>, CMap>();
    521           return *this; 
     521          return *this;
    522522        }
    523523      };
     
    527527      /// Reference map of the directed arcs to type \c T.
    528528      /// \sa Reference
    529       template<class T> 
     529      template<class T>
    530530      class ArcMap : public ReadWriteMap<Arc,T>
    531531      {
     
    540540        ///Assignment operator
    541541        template <typename CMap>
    542         ArcMap& operator=(const CMap&) { 
     542        ArcMap& operator=(const CMap&) {
    543543          checkConcept<ReadMap<Arc, T>, CMap>();
    544           return *this; 
     544          return *this;
    545545        }
    546546      };
     
    550550      /// Reference map of the arcs to type \c T.
    551551      /// \sa Reference
    552       template<class T> 
     552      template<class T>
    553553      class EdgeMap : public ReadWriteMap<Edge,T>
    554554      {
     
    563563        ///Assignment operator
    564564        template <typename CMap>
    565         EdgeMap& operator=(const CMap&) { 
     565        EdgeMap& operator=(const CMap&) {
    566566          checkConcept<ReadMap<Edge, T>, CMap>();
    567           return *this; 
     567          return *this;
    568568        }
    569569      };
     
    574574      /// will be the given node.
    575575      Arc direct(const Edge&, const Node&) const {
    576         return INVALID;
     576        return INVALID;
    577577      }
    578578
     
    584584      /// the directed arc is the same when the given bool is true.
    585585      Arc direct(const Edge&, bool) const {
    586         return INVALID;
     586        return INVALID;
    587587      }
    588588
     
    626626
    627627      /// \brief Returns the id of the node.
    628       int id(Node) const { return -1; } 
     628      int id(Node) const { return -1; }
    629629
    630630      /// \brief Returns the id of the edge.
    631       int id(Edge) const { return -1; } 
     631      int id(Edge) const { return -1; }
    632632
    633633      /// \brief Returns the id of the arc.
    634       int id(Arc) const { return -1; } 
     634      int id(Arc) const { return -1; }
    635635
    636636      /// \brief Returns the node with the given id.
    637637      ///
    638638      /// \pre The argument should be a valid node id in the graph.
    639       Node nodeFromId(int) const { return INVALID; } 
     639      Node nodeFromId(int) const { return INVALID; }
    640640
    641641      /// \brief Returns the edge with the given id.
    642642      ///
    643643      /// \pre The argument should be a valid edge id in the graph.
    644       Edge edgeFromId(int) const { return INVALID; } 
     644      Edge edgeFromId(int) const { return INVALID; }
    645645
    646646      /// \brief Returns the arc with the given id.
    647647      ///
    648648      /// \pre The argument should be a valid arc id in the graph.
    649       Arc arcFromId(int) const { return INVALID; } 
     649      Arc arcFromId(int) const { return INVALID; }
    650650
    651651      /// \brief Returns an upper bound on the node IDs.
    652       int maxNodeId() const { return -1; } 
     652      int maxNodeId() const { return -1; }
    653653
    654654      /// \brief Returns an upper bound on the edge IDs.
    655       int maxEdgeId() const { return -1; } 
     655      int maxEdgeId() const { return -1; }
    656656
    657657      /// \brief Returns an upper bound on the arc IDs.
    658       int maxArcId() const { return -1; } 
     658      int maxArcId() const { return -1; }
    659659
    660660      void first(Node&) const {}
     
    684684
    685685      // Dummy parameter.
    686       int maxId(Node) const { return -1; } 
     686      int maxId(Node) const { return -1; }
    687687      // Dummy parameter.
    688       int maxId(Edge) const { return -1; } 
     688      int maxId(Edge) const { return -1; }
    689689      // Dummy parameter.
    690       int maxId(Arc) const { return -1; } 
     690      int maxId(Arc) const { return -1; }
    691691
    692692      /// \brief Base node of the iterator
     
    694694      /// Returns the base node (the source in this case) of the iterator
    695695      Node baseNode(OutArcIt e) const {
    696         return source(e);
     696        return source(e);
    697697      }
    698698      /// \brief Running node of the iterator
     
    701701      /// iterator
    702702      Node runningNode(OutArcIt e) const {
    703         return target(e);
     703        return target(e);
    704704      }
    705705
     
    708708      /// Returns the base node (the target in this case) of the iterator
    709709      Node baseNode(InArcIt e) const {
    710         return target(e);
     710        return target(e);
    711711      }
    712712      /// \brief Running node of the iterator
     
    715715      /// iterator
    716716      Node runningNode(InArcIt e) const {
    717         return source(e);
     717        return source(e);
    718718      }
    719719
     
    722722      /// Returns the base node of the iterator
    723723      Node baseNode(IncEdgeIt) const {
    724         return INVALID;
     724        return INVALID;
    725725      }
    726      
     726
    727727      /// \brief Running node of the iterator
    728728      ///
    729729      /// Returns the running node of the iterator
    730730      Node runningNode(IncEdgeIt) const {
    731         return INVALID;
     731        return INVALID;
    732732      }
    733733
    734734      template <typename _Graph>
    735735      struct Constraints {
    736         void constraints() {
    737           checkConcept<IterableGraphComponent<>, _Graph>();
    738           checkConcept<IDableGraphComponent<>, _Graph>();
    739           checkConcept<MappableGraphComponent<>, _Graph>();
    740         }
     736        void constraints() {
     737          checkConcept<IterableGraphComponent<>, _Graph>();
     738          checkConcept<IDableGraphComponent<>, _Graph>();
     739          checkConcept<MappableGraphComponent<>, _Graph>();
     740        }
    741741      };
    742742
  • lemon/concepts/graph_components.h

    r169 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5050    public:
    5151      /// \brief Default constructor.
    52       ///     
     52      ///
    5353      /// \warning The default constructor is not required to set
    5454      /// the item to some well-defined value. So you should consider it
     
    6767      /// \brief Assign operator for nodes.
    6868      ///
    69       /// The nodes are assignable. 
     69      /// The nodes are assignable.
    7070      ///
    7171      GraphItem& operator=(GraphItem const&) { return *this; }
     
    9393      template<typename _GraphItem>
    9494      struct Constraints {
    95         void constraints() {
    96           _GraphItem i1;
    97           _GraphItem i2 = i1;
    98           _GraphItem i3 = INVALID;
    99          
    100           i1 = i2 = i3;
    101 
    102           bool b;
    103           //      b = (ia == ib) && (ia != ib) && (ia < ib);
    104           b = (ia == ib) && (ia != ib);
    105           b = (ia == INVALID) && (ib != INVALID);
     95        void constraints() {
     96          _GraphItem i1;
     97          _GraphItem i2 = i1;
     98          _GraphItem i3 = INVALID;
     99
     100          i1 = i2 = i3;
     101
     102          bool b;
     103          //          b = (ia == ib) && (ia != ib) && (ia < ib);
     104          b = (ia == ib) && (ia != ib);
     105          b = (ia == INVALID) && (ib != INVALID);
    106106          b = (ia < ib);
    107         }
    108 
    109         const _GraphItem &ia;
    110         const _GraphItem &ib;
     107        }
     108
     109        const _GraphItem &ia;
     110        const _GraphItem &ib;
    111111      };
    112112    };
    113113
    114114    /// \brief An empty base directed graph class.
    115     /// 
     115    ///
    116116    /// This class provides the minimal set of features needed for a
    117117    /// directed graph structure. All digraph concepts have to be
     
    123123
    124124      typedef BaseDigraphComponent Digraph;
    125      
     125
    126126      /// \brief Node class of the digraph.
    127127      ///
    128       /// This class represents the Nodes of the digraph. 
     128      /// This class represents the Nodes of the digraph.
    129129      ///
    130130      typedef GraphItem<'n'> Node;
     
    132132      /// \brief Arc class of the digraph.
    133133      ///
    134       /// This class represents the Arcs of the digraph. 
     134      /// This class represents the Arcs of the digraph.
    135135      ///
    136136      typedef GraphItem<'e'> Arc;
     
    157157      template <typename _Digraph>
    158158      struct Constraints {
    159         typedef typename _Digraph::Node Node;
    160         typedef typename _Digraph::Arc Arc;
    161      
    162         void constraints() {
    163           checkConcept<GraphItem<'n'>, Node>();
    164           checkConcept<GraphItem<'a'>, Arc>();
    165           {
    166             Node n;
    167             Arc e(INVALID);
    168             n = digraph.source(e);
    169             n = digraph.target(e);
     159        typedef typename _Digraph::Node Node;
     160        typedef typename _Digraph::Arc Arc;
     161
     162        void constraints() {
     163          checkConcept<GraphItem<'n'>, Node>();
     164          checkConcept<GraphItem<'a'>, Arc>();
     165          {
     166            Node n;
     167            Arc e(INVALID);
     168            n = digraph.source(e);
     169            n = digraph.target(e);
    170170            n = digraph.oppositeNode(n, e);
    171           }     
    172         }
    173      
    174         const _Digraph& digraph;
     171          }
     172        }
     173
     174        const _Digraph& digraph;
    175175      };
    176176    };
    177177
    178178    /// \brief An empty base undirected graph class.
    179     /// 
     179    ///
    180180    /// This class provides the minimal set of features needed for an
    181181    /// undirected graph structure. All undirected graph concepts have
     
    200200        typedef GraphItem<'u'> Parent;
    201201        /// \brief Default constructor.
    202         ///     
     202        ///
    203203        /// \warning The default constructor is not required to set
    204204        /// the item to some well-defined value. So you should consider it
     
    218218        ///
    219219        /// Besides the core graph item functionality each arc should
    220         /// be convertible to the represented edge. 
     220        /// be convertible to the represented edge.
    221221        Edge(const Arc&) {}
    222222        /// \brief Assign arc to edge.
    223223        ///
    224224        /// Besides the core graph item functionality each arc should
    225         /// be convertible to the represented edge. 
     225        /// be convertible to the represented edge.
    226226        Edge& operator=(const Arc&) { return *this; }
    227227      };
     
    238238      /// Returns the directed arc from its direction and the
    239239      /// represented edge.
    240       Arc direct(const Edge&, bool) const { return INVALID;} 
     240      Arc direct(const Edge&, bool) const { return INVALID;}
    241241
    242242      /// \brief Returns the directed arc.
     
    244244      /// Returns the directed arc from its source and the
    245245      /// represented edge.
    246       Arc direct(const Edge&, const Node&) const { return INVALID;} 
     246      Arc direct(const Edge&, const Node&) const { return INVALID;}
    247247
    248248      /// \brief Returns the opposite arc.
     
    261261      /// Gives back the other ending of an edge.
    262262      Node v(const Edge&) const { return INVALID;}
    263      
     263
    264264      template <typename _Graph>
    265265      struct Constraints {
    266         typedef typename _Graph::Node Node;
    267         typedef typename _Graph::Arc Arc;
    268         typedef typename _Graph::Edge Edge;
    269      
    270         void constraints() {
     266        typedef typename _Graph::Node Node;
     267        typedef typename _Graph::Arc Arc;
     268        typedef typename _Graph::Edge Edge;
     269
     270        void constraints() {
    271271          checkConcept<BaseDigraphComponent, _Graph>();
    272           checkConcept<GraphItem<'u'>, Edge>();
    273           {
    274             Node n;
    275             Edge ue(INVALID);
     272          checkConcept<GraphItem<'u'>, Edge>();
     273          {
     274            Node n;
     275            Edge ue(INVALID);
    276276            Arc e;
    277             n = graph.u(ue);
    278             n = graph.v(ue);
     277            n = graph.u(ue);
     278            n = graph.v(ue);
    279279            e = graph.direct(ue, true);
    280280            e = graph.direct(ue, n);
     
    283283            bool d = graph.direction(e);
    284284            ignore_unused_variable_warning(d);
    285           }     
    286         }
    287      
    288         const _Graph& graph;
     285          }
     286        }
     287
     288        const _Graph& graph;
    289289      };
    290290
     
    292292
    293293    /// \brief An empty idable base digraph class.
    294     /// 
     294    ///
    295295    /// This class provides beside the core digraph features
    296296    /// core id functions for the digraph structure.
     
    305305      typedef typename Base::Arc Arc;
    306306
    307       /// \brief Gives back an unique integer id for the Node. 
    308       ///
    309       /// Gives back an unique integer id for the Node. 
     307      /// \brief Gives back an unique integer id for the Node.
     308      ///
     309      /// Gives back an unique integer id for the Node.
    310310      ///
    311311      int id(const Node&) const { return -1;}
     
    315315      /// Gives back the node by the unique id.
    316316      /// If the digraph does not contain node with the given id
    317       /// then the result of the function is undetermined. 
     317      /// then the result of the function is undetermined.
    318318      Node nodeFromId(int) const { return INVALID;}
    319319
    320       /// \brief Gives back an unique integer id for the Arc. 
    321       ///
    322       /// Gives back an unique integer id for the Arc. 
     320      /// \brief Gives back an unique integer id for the Arc.
     321      ///
     322      /// Gives back an unique integer id for the Arc.
    323323      ///
    324324      int id(const Arc&) const { return -1;}
     
    328328      /// Gives back the arc by the unique id.
    329329      /// If the digraph does not contain arc with the given id
    330       /// then the result of the function is undetermined. 
     330      /// then the result of the function is undetermined.
    331331      Arc arcFromId(int) const { return INVALID;}
    332332
     
    348348      struct Constraints {
    349349
    350         void constraints() {
    351           checkConcept<Base, _Digraph >();
    352           typename _Digraph::Node node;
    353           int nid = digraph.id(node);
    354           nid = digraph.id(node);
    355           node = digraph.nodeFromId(nid);
    356           typename _Digraph::Arc arc;
    357           int eid = digraph.id(arc);
    358           eid = digraph.id(arc);
    359           arc = digraph.arcFromId(eid);
    360 
    361           nid = digraph.maxNodeId();
    362           ignore_unused_variable_warning(nid);
    363           eid = digraph.maxArcId();
    364           ignore_unused_variable_warning(eid);
    365         }
    366 
    367         const _Digraph& digraph;
     350        void constraints() {
     351          checkConcept<Base, _Digraph >();
     352          typename _Digraph::Node node;
     353          int nid = digraph.id(node);
     354          nid = digraph.id(node);
     355          node = digraph.nodeFromId(nid);
     356          typename _Digraph::Arc arc;
     357          int eid = digraph.id(arc);
     358          eid = digraph.id(arc);
     359          arc = digraph.arcFromId(eid);
     360
     361          nid = digraph.maxNodeId();
     362          ignore_unused_variable_warning(nid);
     363          eid = digraph.maxArcId();
     364          ignore_unused_variable_warning(eid);
     365        }
     366
     367        const _Digraph& digraph;
    368368      };
    369369    };
    370370
    371371    /// \brief An empty idable base undirected graph class.
    372     /// 
     372    ///
    373373    /// This class provides beside the core undirected graph features
    374374    /// core id functions for the undirected graph structure.  The
     
    384384      using IDableDigraphComponent<_Base>::id;
    385385
    386       /// \brief Gives back an unique integer id for the Edge. 
    387       ///
    388       /// Gives back an unique integer id for the Edge. 
     386      /// \brief Gives back an unique integer id for the Edge.
     387      ///
     388      /// Gives back an unique integer id for the Edge.
    389389      ///
    390390      int id(const Edge&) const { return -1;}
     
    407407      struct Constraints {
    408408
    409         void constraints() {
    410           checkConcept<Base, _Graph >();
    411           checkConcept<IDableDigraphComponent<Base>, _Graph >();
    412           typename _Graph::Edge edge;
    413           int ueid = graph.id(edge);
    414           ueid = graph.id(edge);
    415           edge = graph.edgeFromId(ueid);
    416           ueid = graph.maxEdgeId();
    417           ignore_unused_variable_warning(ueid);
    418         }
    419 
    420         const _Graph& graph;
     409        void constraints() {
     410          checkConcept<Base, _Graph >();
     411          checkConcept<IDableDigraphComponent<Base>, _Graph >();
     412          typename _Graph::Edge edge;
     413          int ueid = graph.id(edge);
     414          ueid = graph.id(edge);
     415          edge = graph.edgeFromId(ueid);
     416          ueid = graph.maxEdgeId();
     417          ignore_unused_variable_warning(ueid);
     418        }
     419
     420        const _Graph& graph;
    421421      };
    422422    };
     
    451451      /// \brief Assign operator for items.
    452452      ///
    453       /// The items are assignable. 
    454       ///
    455       GraphItemIt& operator=(const GraphItemIt&) { return *this; }     
     453      /// The items are assignable.
     454      ///
     455      GraphItemIt& operator=(const GraphItemIt&) { return *this; }
    456456      /// \brief Next item.
    457       /// 
     457      ///
    458458      /// Assign the iterator to the next item.
    459459      ///
    460460      GraphItemIt& operator++() { return *this; }
    461461      /// \brief Equality operator
    462       /// 
     462      ///
    463463      /// Two iterators are equal if and only if they point to the
    464464      /// same object or both are invalid.
    465465      bool operator==(const GraphItemIt&) const { return true;}
    466466      /// \brief Inequality operator
    467       ///       
     467      ///
    468468      /// \sa operator==(Node n)
    469469      ///
    470470      bool operator!=(const GraphItemIt&) const { return true;}
    471      
     471
    472472      template<typename _GraphItemIt>
    473473      struct Constraints {
    474         void constraints() {
    475           _GraphItemIt it1(g); 
    476           _GraphItemIt it2;
    477 
    478           it2 = ++it1;
    479           ++it2 = it1;
    480           ++(++it1);
    481 
    482           _Item bi = it1;
    483           bi = it2;
    484         }
    485         _Graph& g;
     474        void constraints() {
     475          _GraphItemIt it1(g);
     476          _GraphItemIt it2;
     477
     478          it2 = ++it1;
     479          ++it2 = it1;
     480          ++(++it1);
     481
     482          _Item bi = it1;
     483          bi = it2;
     484        }
     485        _Graph& g;
    486486      };
    487487    };
     
    490490    ///
    491491    /// \note Because InArcIt and OutArcIt may not inherit from the same
    492     /// base class, the _selector is a additional template parameter. For 
    493     /// InArcIt you should instantiate it with character 'i' and for 
     492    /// base class, the _selector is a additional template parameter. For
     493    /// InArcIt you should instantiate it with character 'i' and for
    494494    /// OutArcIt with 'o'.
    495495    template <typename _Graph,
    496               typename _Item = typename _Graph::Arc,
    497               typename _Base = typename _Graph::Node, 
    498               char _selector = '0'>
     496              typename _Item = typename _Graph::Arc,
     497              typename _Base = typename _Graph::Node,
     498              char _selector = '0'>
    499499    class GraphIncIt : public _Item {
    500500    public:
     
    509509      ///
    510510      GraphIncIt(GraphIncIt const& gi) : _Item(gi) {}
    511       /// \brief Sets the iterator to the first arc incoming into or outgoing 
     511      /// \brief Sets the iterator to the first arc incoming into or outgoing
    512512      /// from the node.
    513513      ///
    514       /// Sets the iterator to the first arc incoming into or outgoing 
     514      /// Sets the iterator to the first arc incoming into or outgoing
    515515      /// from the node.
    516516      ///
     
    523523      /// \brief Assign operator for iterators.
    524524      ///
    525       /// The iterators are assignable. 
    526       ///
    527       GraphIncIt& operator=(GraphIncIt const&) { return *this; }     
     525      /// The iterators are assignable.
     526      ///
     527      GraphIncIt& operator=(GraphIncIt const&) { return *this; }
    528528      /// \brief Next item.
    529529      ///
     
    546546      template <typename _GraphIncIt>
    547547      struct Constraints {
    548         void constraints() {
    549           checkConcept<GraphItem<_selector>, _GraphIncIt>();
    550           _GraphIncIt it1(graph, node);
    551           _GraphIncIt it2;
    552 
    553           it2 = ++it1;
    554           ++it2 = it1;
    555           ++(++it1);
    556           _Item e = it1;
    557           e = it2;
    558 
    559         }
    560 
    561         _Item arc;
    562         _Base node;
    563         _Graph graph;
    564         _GraphIncIt it;
     548        void constraints() {
     549          checkConcept<GraphItem<_selector>, _GraphIncIt>();
     550          _GraphIncIt it1(graph, node);
     551          _GraphIncIt it2;
     552
     553          it2 = ++it1;
     554          ++it2 = it1;
     555          ++(++it1);
     556          _Item e = it1;
     557          e = it2;
     558
     559        }
     560
     561        _Item arc;
     562        _Base node;
     563        _Graph graph;
     564        _GraphIncIt it;
    565565      };
    566566    };
     
    576576
    577577    public:
    578    
     578
    579579      typedef _Base Base;
    580580      typedef typename Base::Node Node;
     
    584584
    585585      /// \name Base iteration
    586       /// 
     586      ///
    587587      /// This interface provides functions for iteration on digraph items
    588588      ///
    589       /// @{ 
     589      /// @{
    590590
    591591      /// \brief Gives back the first node in the iterating order.
    592       ///     
     592      ///
    593593      /// Gives back the first node in the iterating order.
    594       ///     
     594      ///
    595595      void first(Node&) const {}
    596596
     
    598598      ///
    599599      /// Gives back the next node in the iterating order.
    600       ///     
     600      ///
    601601      void next(Node&) const {}
    602602
     
    604604      ///
    605605      /// Gives back the first arc in the iterating order.
    606       ///     
     606      ///
    607607      void first(Arc&) const {}
    608608
     
    610610      ///
    611611      /// Gives back the next arc in the iterating order.
    612       ///     
     612      ///
    613613      void next(Arc&) const {}
    614614
     
    618618      ///
    619619      /// Gives back the first of the arcs point to the given node.
    620       ///     
     620      ///
    621621      void firstIn(Arc&, const Node&) const {}
    622622
     
    630630      /// \brief Gives back the first of the arcs start from the
    631631      /// given node.
    632       ///     
     632      ///
    633633      /// Gives back the first of the arcs start from the given node.
    634       ///     
     634      ///
    635635      void firstOut(Arc&, const Node&) const {}
    636636
     
    639639      ///
    640640      /// Gives back the next of the arcs start from the given node.
    641       ///     
     641      ///
    642642      void nextOut(Arc&) const {}
    643643
     
    645645
    646646      /// \name Class based iteration
    647       /// 
     647      ///
    648648      /// This interface provides functions for iteration on digraph items
    649649      ///
     
    700700      /// @}
    701701
    702       template <typename _Digraph> 
    703       struct Constraints {
    704         void constraints() {
    705           checkConcept<Base, _Digraph>();
     702      template <typename _Digraph>
     703      struct Constraints {
     704        void constraints() {
     705          checkConcept<Base, _Digraph>();
    706706
    707707          {
    708             typename _Digraph::Node node(INVALID);     
     708            typename _Digraph::Node node(INVALID);
    709709            typename _Digraph::Arc arc(INVALID);
    710710            {
     
    724724              digraph.nextOut(arc);
    725725            }
    726           }           
     726          }
    727727
    728728          {
     
    731731            checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
    732732              typename _Digraph::NodeIt >();
    733             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, 
     733            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
    734734              typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
    735             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, 
     735            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
    736736              typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
    737737
     
    746746          }
    747747        }
    748        
    749         const _Digraph& digraph;
    750        
     748
     749        const _Digraph& digraph;
     750
    751751      };
    752752    };
     
    766766      typedef typename Base::Edge Edge;
    767767
    768    
     768
    769769      typedef IterableGraphComponent Graph;
    770770
    771771      /// \name Base iteration
    772       /// 
     772      ///
    773773      /// This interface provides functions for iteration on graph items
    774       /// @{ 
     774      /// @{
    775775
    776776      using IterableDigraphComponent<_Base>::first;
     
    781781      ///
    782782      /// Gives back the first edge in the iterating order.
    783       ///     
     783      ///
    784784      void first(Edge&) const {}
    785785
     
    788788      ///
    789789      /// Gives back the next edge in the iterating order.
    790       ///     
     790      ///
    791791      void next(Edge&) const {}
    792792
     
    815815
    816816      /// \name Class based iteration
    817       /// 
     817      ///
    818818      /// This interface provides functions for iteration on graph items
    819819      ///
     
    842842      /// @}
    843843
    844       template <typename _Graph> 
    845       struct Constraints {
    846         void constraints() {
    847           checkConcept<IterableDigraphComponent<Base>, _Graph>();
     844      template <typename _Graph>
     845      struct Constraints {
     846        void constraints() {
     847          checkConcept<IterableDigraphComponent<Base>, _Graph>();
    848848
    849849          {
     
    859859              graph.nextInc(edge, dir);
    860860            }
    861            
    862           }     
    863  
     861
     862          }
     863
    864864          {
    865865            checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
    866866              typename _Graph::EdgeIt >();
    867             checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, 
     867            checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
    868868              typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
    869            
     869
    870870            typename _Graph::Node n;
    871871            typename _Graph::IncEdgeIt ueit(INVALID);
     
    874874          }
    875875        }
    876        
    877         const _Graph& graph;
    878        
     876
     877        const _Graph& graph;
     878
    879879      };
    880880    };
    881881
    882882    /// \brief An empty alteration notifier digraph class.
    883     /// 
     883    ///
    884884    /// This class provides beside the core digraph features alteration
    885885    /// notifier interface for the digraph structure.  This implements
     
    898898
    899899      /// The node observer registry.
    900       typedef AlterationNotifier<AlterableDigraphComponent, Node> 
     900      typedef AlterationNotifier<AlterableDigraphComponent, Node>
    901901      NodeNotifier;
    902902      /// The arc observer registry.
    903       typedef AlterationNotifier<AlterableDigraphComponent, Arc> 
     903      typedef AlterationNotifier<AlterableDigraphComponent, Arc>
    904904      ArcNotifier;
    905      
     905
    906906      /// \brief Gives back the node alteration notifier.
    907907      ///
    908908      /// Gives back the node alteration notifier.
    909909      NodeNotifier& notifier(Node) const {
    910         return NodeNotifier();
     910        return NodeNotifier();
    911911      }
    912      
     912
    913913      /// \brief Gives back the arc alteration notifier.
    914914      ///
    915915      /// Gives back the arc alteration notifier.
    916916      ArcNotifier& notifier(Arc) const {
    917         return ArcNotifier();
     917        return ArcNotifier();
    918918      }
    919919
    920       template <typename _Digraph> 
    921       struct Constraints {
    922         void constraints() {
    923           checkConcept<Base, _Digraph>();
    924           typename _Digraph::NodeNotifier& nn 
     920      template <typename _Digraph>
     921      struct Constraints {
     922        void constraints() {
     923          checkConcept<Base, _Digraph>();
     924          typename _Digraph::NodeNotifier& nn
    925925            = digraph.notifier(typename _Digraph::Node());
    926926
    927           typename _Digraph::ArcNotifier& en 
     927          typename _Digraph::ArcNotifier& en
    928928            = digraph.notifier(typename _Digraph::Arc());
    929          
     929
    930930          ignore_unused_variable_warning(nn);
    931931          ignore_unused_variable_warning(en);
    932         }
    933        
    934         const _Digraph& digraph;
    935        
    936       };
    937      
     932        }
     933
     934        const _Digraph& digraph;
     935
     936      };
     937
    938938    };
    939939
    940940    /// \brief An empty alteration notifier undirected graph class.
    941     /// 
     941    ///
    942942    /// This class provides beside the core graph features alteration
    943943    /// notifier interface for the graph structure.  This implements
     
    955955
    956956      /// The arc observer registry.
    957       typedef AlterationNotifier<AlterableGraphComponent, Edge> 
     957      typedef AlterationNotifier<AlterableGraphComponent, Edge>
    958958      EdgeNotifier;
    959      
     959
    960960      /// \brief Gives back the arc alteration notifier.
    961961      ///
    962962      /// Gives back the arc alteration notifier.
    963963      EdgeNotifier& notifier(Edge) const {
    964         return EdgeNotifier();
     964        return EdgeNotifier();
    965965      }
    966966
    967       template <typename _Graph> 
    968       struct Constraints {
    969         void constraints() {
    970           checkConcept<AlterableGraphComponent<Base>, _Graph>();
    971           typename _Graph::EdgeNotifier& uen 
     967      template <typename _Graph>
     968      struct Constraints {
     969        void constraints() {
     970          checkConcept<AlterableGraphComponent<Base>, _Graph>();
     971          typename _Graph::EdgeNotifier& uen
    972972            = graph.notifier(typename _Graph::Edge());
    973973          ignore_unused_variable_warning(uen);
    974         }
    975        
    976         const _Graph& graph;
    977        
    978       };
    979      
     974        }
     975
     976        const _Graph& graph;
     977
     978      };
     979
    980980    };
    981981
    982982    /// \brief Class describing the concept of graph maps
    983     /// 
     983    ///
    984984    /// This class describes the common interface of the graph maps
    985985    /// (NodeMap, ArcMap), that is \ref maps-page "maps" which can be used to
     
    10101010      /// Copy Constructor.
    10111011      GraphMap(const GraphMap&) : Parent() {}
    1012      
     1012
    10131013      /// \brief Assign operator.
    10141014      ///
    10151015      /// Assign operator. It does not mofify the underlying graph,
    10161016      /// it just iterates on the current item set and set the  map
    1017       /// with the value returned by the assigned map. 
     1017      /// with the value returned by the assigned map.
    10181018      template <typename CMap>
    1019       GraphMap& operator=(const CMap&) { 
     1019      GraphMap& operator=(const CMap&) {
    10201020        checkConcept<ReadMap<Key, Value>, CMap>();
    10211021        return *this;
     
    10241024      template<typename _Map>
    10251025      struct Constraints {
    1026         void constraints() {
    1027           checkConcept<ReadWriteMap<Key, Value>, _Map >();
    1028           // Construction with a graph parameter
    1029           _Map a(g);
    1030           // Constructor with a graph and a default value parameter
    1031           _Map a2(g,t);
    1032           // Copy constructor.
    1033           _Map b(c);
    1034          
     1026        void constraints() {
     1027          checkConcept<ReadWriteMap<Key, Value>, _Map >();
     1028          // Construction with a graph parameter
     1029          _Map a(g);
     1030          // Constructor with a graph and a default value parameter
     1031          _Map a2(g,t);
     1032          // Copy constructor.
     1033          _Map b(c);
     1034
    10351035          ReadMap<Key, Value> cmap;
    10361036          b = cmap;
    10371037
    1038           ignore_unused_variable_warning(a2);
    1039           ignore_unused_variable_warning(b);
    1040         }
    1041 
    1042         const _Map &c;
    1043         const Graph &g;
    1044         const typename GraphMap::Value &t;
     1038          ignore_unused_variable_warning(a2);
     1039          ignore_unused_variable_warning(b);
     1040        }
     1041
     1042        const _Map &c;
     1043        const Graph &g;
     1044        const typename GraphMap::Value &t;
    10451045      };
    10461046
     
    10711071        typedef GraphMap<MappableDigraphComponent, Node, _Value> Parent;
    10721072
    1073         /// \brief Construct a new map.
    1074         ///
    1075         /// Construct a new map for the digraph.
    1076         explicit NodeMap(const MappableDigraphComponent& digraph)
     1073        /// \brief Construct a new map.
     1074        ///
     1075        /// Construct a new map for the digraph.
     1076        explicit NodeMap(const MappableDigraphComponent& digraph)
    10771077          : Parent(digraph) {}
    10781078
    1079         /// \brief Construct a new map with default value.
    1080         ///
    1081         /// Construct a new map for the digraph and initalise the values.
    1082         NodeMap(const MappableDigraphComponent& digraph, const _Value& value)
     1079        /// \brief Construct a new map with default value.
     1080        ///
     1081        /// Construct a new map for the digraph and initalise the values.
     1082        NodeMap(const MappableDigraphComponent& digraph, const _Value& value)
    10831083          : Parent(digraph, value) {}
    10841084
    1085         /// \brief Copy constructor.
    1086         ///
    1087         /// Copy Constructor.
    1088         NodeMap(const NodeMap& nm) : Parent(nm) {}
    1089 
    1090         /// \brief Assign operator.
    1091         ///
    1092         /// Assign operator.
     1085        /// \brief Copy constructor.
     1086        ///
     1087        /// Copy Constructor.
     1088        NodeMap(const NodeMap& nm) : Parent(nm) {}
     1089
     1090        /// \brief Assign operator.
     1091        ///
     1092        /// Assign operator.
    10931093        template <typename CMap>
    1094         NodeMap& operator=(const CMap&) { 
     1094        NodeMap& operator=(const CMap&) {
    10951095          checkConcept<ReadMap<Node, _Value>, CMap>();
    10961096          return *this;
     
    11081108        typedef GraphMap<MappableDigraphComponent, Arc, _Value> Parent;
    11091109
    1110         /// \brief Construct a new map.
    1111         ///
    1112         /// Construct a new map for the digraph.
    1113         explicit ArcMap(const MappableDigraphComponent& digraph)
     1110        /// \brief Construct a new map.
     1111        ///
     1112        /// Construct a new map for the digraph.
     1113        explicit ArcMap(const MappableDigraphComponent& digraph)
    11141114          : Parent(digraph) {}
    11151115
    1116         /// \brief Construct a new map with default value.
    1117         ///
    1118         /// Construct a new map for the digraph and initalise the values.
    1119         ArcMap(const MappableDigraphComponent& digraph, const _Value& value)
     1116        /// \brief Construct a new map with default value.
     1117        ///
     1118        /// Construct a new map for the digraph and initalise the values.
     1119        ArcMap(const MappableDigraphComponent& digraph, const _Value& value)
    11201120          : Parent(digraph, value) {}
    11211121
    1122         /// \brief Copy constructor.
    1123         ///
    1124         /// Copy Constructor.
    1125         ArcMap(const ArcMap& nm) : Parent(nm) {}
    1126 
    1127         /// \brief Assign operator.
    1128         ///
    1129         /// Assign operator.
     1122        /// \brief Copy constructor.
     1123        ///
     1124        /// Copy Constructor.
     1125        ArcMap(const ArcMap& nm) : Parent(nm) {}
     1126
     1127        /// \brief Assign operator.
     1128        ///
     1129        /// Assign operator.
    11301130        template <typename CMap>
    1131         ArcMap& operator=(const CMap&) { 
     1131        ArcMap& operator=(const CMap&) {
    11321132          checkConcept<ReadMap<Arc, _Value>, CMap>();
    11331133          return *this;
     
    11401140      struct Constraints {
    11411141
    1142         struct Dummy {
    1143           int value;
    1144           Dummy() : value(0) {}
    1145           Dummy(int _v) : value(_v) {}
    1146         };
    1147 
    1148         void constraints() {
    1149           checkConcept<Base, _Digraph>();
    1150           { // int map test
    1151             typedef typename _Digraph::template NodeMap<int> IntNodeMap;
    1152             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
    1153               IntNodeMap >();
    1154           } { // bool map test
    1155             typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
    1156             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
    1157               BoolNodeMap >();
    1158           } { // Dummy map test
    1159             typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
    1160             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
    1161               DummyNodeMap >();
    1162           }
    1163 
    1164           { // int map test
    1165             typedef typename _Digraph::template ArcMap<int> IntArcMap;
    1166             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
    1167               IntArcMap >();
    1168           } { // bool map test
    1169             typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
    1170             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
    1171               BoolArcMap >();
    1172           } { // Dummy map test
    1173             typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
    1174             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
    1175               DummyArcMap >();
    1176           }
    1177         }
    1178 
    1179         _Digraph& digraph;
     1142        struct Dummy {
     1143          int value;
     1144          Dummy() : value(0) {}
     1145          Dummy(int _v) : value(_v) {}
     1146        };
     1147
     1148        void constraints() {
     1149          checkConcept<Base, _Digraph>();
     1150          { // int map test
     1151            typedef typename _Digraph::template NodeMap<int> IntNodeMap;
     1152            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
     1153              IntNodeMap >();
     1154          } { // bool map test
     1155            typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
     1156            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
     1157              BoolNodeMap >();
     1158          } { // Dummy map test
     1159            typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
     1160            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
     1161              DummyNodeMap >();
     1162          }
     1163
     1164          { // int map test
     1165            typedef typename _Digraph::template ArcMap<int> IntArcMap;
     1166            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
     1167              IntArcMap >();
     1168          } { // bool map test
     1169            typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
     1170            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
     1171              BoolArcMap >();
     1172          } { // Dummy map test
     1173            typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
     1174            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
     1175              DummyArcMap >();
     1176          }
     1177        }
     1178
     1179        _Digraph& digraph;
    11801180      };
    11811181    };
     
    12001200      ///
    12011201      template <typename _Value>
    1202       class EdgeMap : public GraphMap<Graph, Edge, _Value> { 
     1202      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
    12031203      public:
    12041204        typedef GraphMap<MappableGraphComponent, Edge, _Value> Parent;
    12051205
    1206         /// \brief Construct a new map.
    1207         ///
    1208         /// Construct a new map for the graph.
    1209         explicit EdgeMap(const MappableGraphComponent& graph)
     1206        /// \brief Construct a new map.
     1207        ///
     1208        /// Construct a new map for the graph.
     1209        explicit EdgeMap(const MappableGraphComponent& graph)
    12101210          : Parent(graph) {}
    12111211
    1212         /// \brief Construct a new map with default value.
    1213         ///
    1214         /// Construct a new map for the graph and initalise the values.
    1215         EdgeMap(const MappableGraphComponent& graph, const _Value& value)
     1212        /// \brief Construct a new map with default value.
     1213        ///
     1214        /// Construct a new map for the graph and initalise the values.
     1215        EdgeMap(const MappableGraphComponent& graph, const _Value& value)
    12161216          : Parent(graph, value) {}
    12171217
    1218         /// \brief Copy constructor.
    1219         ///
    1220         /// Copy Constructor.
    1221         EdgeMap(const EdgeMap& nm) : Parent(nm) {}
    1222 
    1223         /// \brief Assign operator.
    1224         ///
    1225         /// Assign operator.
     1218        /// \brief Copy constructor.
     1219        ///
     1220        /// Copy Constructor.
     1221        EdgeMap(const EdgeMap& nm) : Parent(nm) {}
     1222
     1223        /// \brief Assign operator.
     1224        ///
     1225        /// Assign operator.
    12261226        template <typename CMap>
    1227         EdgeMap& operator=(const CMap&) { 
     1227        EdgeMap& operator=(const CMap&) {
    12281228          checkConcept<ReadMap<Edge, _Value>, CMap>();
    12291229          return *this;
     
    12361236      struct Constraints {
    12371237
    1238         struct Dummy {
    1239           int value;
    1240           Dummy() : value(0) {}
    1241           Dummy(int _v) : value(_v) {}
    1242         };
    1243 
    1244         void constraints() {
    1245           checkConcept<MappableGraphComponent<Base>, _Graph>();
    1246 
    1247           { // int map test
    1248             typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
    1249             checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
    1250               IntEdgeMap >();
    1251           } { // bool map test
    1252             typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
    1253             checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
    1254               BoolEdgeMap >();
    1255           } { // Dummy map test
    1256             typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
    1257             checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
    1258               DummyEdgeMap >();
    1259           }
    1260         }
    1261 
    1262         _Graph& graph;
     1238        struct Dummy {
     1239          int value;
     1240          Dummy() : value(0) {}
     1241          Dummy(int _v) : value(_v) {}
     1242        };
     1243
     1244        void constraints() {
     1245          checkConcept<MappableGraphComponent<Base>, _Graph>();
     1246
     1247          { // int map test
     1248            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
     1249            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
     1250              IntEdgeMap >();
     1251          } { // bool map test
     1252            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
     1253            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
     1254              BoolEdgeMap >();
     1255          } { // Dummy map test
     1256            typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
     1257            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
     1258              DummyEdgeMap >();
     1259          }
     1260        }
     1261
     1262        _Graph& graph;
    12631263      };
    12641264    };
     
    12831283      ///
    12841284      Node addNode() {
    1285         return INVALID;
     1285        return INVALID;
    12861286      }
    1287    
     1287
    12881288      /// \brief Adds a new arc connects the given two nodes.
    12891289      ///
    12901290      /// Adds a new arc connects the the given two nodes.
    12911291      Arc addArc(const Node&, const Node&) {
    1292         return INVALID;
     1292        return INVALID;
    12931293      }
    12941294
    12951295      template <typename _Digraph>
    12961296      struct Constraints {
    1297         void constraints() {
     1297        void constraints() {
    12981298          checkConcept<Base, _Digraph>();
    1299           typename _Digraph::Node node_a, node_b;
    1300           node_a = digraph.addNode();
    1301           node_b = digraph.addNode();
    1302           typename _Digraph::Arc arc;
    1303           arc = digraph.addArc(node_a, node_b);
    1304         }
    1305 
    1306         _Digraph& digraph;
     1299          typename _Digraph::Node node_a, node_b;
     1300          node_a = digraph.addNode();
     1301          node_b = digraph.addNode();
     1302          typename _Digraph::Arc arc;
     1303          arc = digraph.addArc(node_a, node_b);
     1304        }
     1305
     1306        _Digraph& digraph;
    13071307      };
    13081308    };
     
    13281328      ///
    13291329      Node addNode() {
    1330         return INVALID;
     1330        return INVALID;
    13311331      }
    1332    
     1332
    13331333      /// \brief Adds a new arc connects the given two nodes.
    13341334      ///
    13351335      /// Adds a new arc connects the the given two nodes.
    13361336      Edge addArc(const Node&, const Node&) {
    1337         return INVALID;
     1337        return INVALID;
    13381338      }
    13391339
    13401340      template <typename _Graph>
    13411341      struct Constraints {
    1342         void constraints() {
    1343           checkConcept<Base, _Graph>();
    1344           typename _Graph::Node node_a, node_b;
    1345           node_a = graph.addNode();
    1346           node_b = graph.addNode();
    1347           typename _Graph::Edge edge;
    1348           edge = graph.addEdge(node_a, node_b);
    1349         }
    1350 
    1351         _Graph& graph;
     1342        void constraints() {
     1343          checkConcept<Base, _Graph>();
     1344          typename _Graph::Node node_a, node_b;
     1345          node_a = graph.addNode();
     1346          node_b = graph.addNode();
     1347          typename _Graph::Edge edge;
     1348          edge = graph.addEdge(node_a, node_b);
     1349        }
     1350
     1351        _Graph& graph;
    13521352      };
    13531353    };
    13541354
    13551355    /// \brief An empty erasable digraph class.
    1356     /// 
     1356    ///
    13571357    /// This class provides beside the core digraph features core erase
    13581358    /// functions for the digraph structure. The main difference between
     
    13691369      /// \brief Erase a node from the digraph.
    13701370      ///
    1371       /// Erase a node from the digraph. This function should 
     1371      /// Erase a node from the digraph. This function should
    13721372      /// erase all arcs connecting to the node.
    1373       void erase(const Node&) {}   
     1373      void erase(const Node&) {}
    13741374
    13751375      /// \brief Erase an arc from the digraph.
     
    13811381      template <typename _Digraph>
    13821382      struct Constraints {
    1383         void constraints() {
     1383        void constraints() {
    13841384          checkConcept<Base, _Digraph>();
    1385           typename _Digraph::Node node;
    1386           digraph.erase(node);
    1387           typename _Digraph::Arc arc;
    1388           digraph.erase(arc);
    1389         }
    1390 
    1391         _Digraph& digraph;
     1385          typename _Digraph::Node node;
     1386          digraph.erase(node);
     1387          typename _Digraph::Arc arc;
     1388          digraph.erase(arc);
     1389        }
     1390
     1391        _Digraph& digraph;
    13921392      };
    13931393    };
    13941394
    13951395    /// \brief An empty erasable base undirected graph class.
    1396     /// 
     1396    ///
    13971397    /// This class provides beside the core undirected graph features
    13981398    /// core erase functions for the undirceted graph structure. The
     
    14111411      /// Erase a node from the graph. This function should erase
    14121412      /// arcs connecting to the node.
    1413       void erase(const Node&) {}   
     1413      void erase(const Node&) {}
    14141414
    14151415      /// \brief Erase an arc from the graph.
     
    14211421      template <typename _Graph>
    14221422      struct Constraints {
    1423         void constraints() {
     1423        void constraints() {
    14241424          checkConcept<Base, _Graph>();
    1425           typename _Graph::Node node;
    1426           graph.erase(node);
    1427           typename _Graph::Edge edge;
    1428           graph.erase(edge);
    1429         }
    1430 
    1431         _Graph& graph;
     1425          typename _Graph::Node node;
     1426          graph.erase(node);
     1427          typename _Graph::Edge edge;
     1428          graph.erase(edge);
     1429        }
     1430
     1431        _Graph& graph;
    14321432      };
    14331433    };
     
    14491449      /// Erase all nodes and arcs from the digraph.
    14501450      ///
    1451       void clear() {}   
     1451      void clear() {}
    14521452
    14531453      template <typename _Digraph>
    14541454      struct Constraints {
    1455         void constraints() {
     1455        void constraints() {
    14561456          checkConcept<Base, _Digraph>();
    1457           digraph.clear();
    1458         }
    1459 
    1460         _Digraph digraph;
     1457          digraph.clear();
     1458        }
     1459
     1460        _Digraph digraph;
    14611461      };
    14621462    };
     
    14761476      template <typename _Graph>
    14771477      struct Constraints {
    1478         void constraints() {
     1478        void constraints() {
    14791479          checkConcept<ClearableGraphComponent<Base>, _Graph>();
    1480         }
    1481 
    1482         _Graph graph;
     1480        }
     1481
     1482        _Graph graph;
    14831483      };
    14841484    };
  • lemon/concepts/heap.h

    r203 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5353      /// the user.
    5454      ///
    55       /// The \c ItemIntMap must be initialized in such a way, that it 
     55      /// The \c ItemIntMap must be initialized in such a way, that it
    5656      /// assigns \c PRE_HEAP (<tt>-1</tt>) to every item.
    5757      enum State {
    58         IN_HEAP = 0,
    59         PRE_HEAP = -1,
    60         POST_HEAP = -2
     58        IN_HEAP = 0,
     59        PRE_HEAP = -1,
     60        POST_HEAP = -2
    6161      };
    62      
     62
    6363      /// \brief The constructor.
    6464      ///
     
    8686
    8787      /// \brief Inserts an item into the heap with the given priority.
    88       ///   
    89       /// Inserts the given item into the heap with the given priority. 
     88      ///
     89      /// Inserts the given item into the heap with the given priority.
    9090      /// \param i The item to insert.
    9191      /// \param p The priority of the item.
     
    113113      ///
    114114      /// Removes the given item from the heap if it is already stored.
    115       /// \param i The item to delete. 
     115      /// \param i The item to delete.
    116116      void erase(const Item &i) {}
    117117
    118118      /// \brief The priority of an item.
    119119      ///
    120       /// Returns the priority of the given item. 
     120      /// Returns the priority of the given item.
    121121      /// \pre \c i must be in the heap.
    122122      /// \param i The item.
     
    134134      /// \param p The priority.
    135135      void set(const Item &i, const Prio &p) {}
    136      
     136
    137137      /// \brief Decreases the priority of an item to the given value.
    138138      ///
     
    175175      struct Constraints {
    176176      public:
    177         void constraints() {
    178           typedef typename _Heap::Item OwnItem;
    179           typedef typename _Heap::Prio OwnPrio;
    180           typedef typename _Heap::State OwnState;
    181 
    182           Item item;
    183           Prio prio;
    184           item=Item();
    185           prio=Prio();
    186           ignore_unused_variable_warning(item);
    187           ignore_unused_variable_warning(prio);
    188 
    189           OwnItem own_item;
    190           OwnPrio own_prio;
    191           OwnState own_state;
    192           own_item=Item();
    193           own_prio=Prio();
    194           ignore_unused_variable_warning(own_item);
    195           ignore_unused_variable_warning(own_prio);
    196           ignore_unused_variable_warning(own_state);
    197 
    198           _Heap heap1(map);
    199           _Heap heap2 = heap1;
    200           ignore_unused_variable_warning(heap1);
    201           ignore_unused_variable_warning(heap2);
    202          
    203           int s = heap.size();
    204           ignore_unused_variable_warning(s);
    205           bool e = heap.empty();
    206           ignore_unused_variable_warning(e);
    207 
    208           prio = heap.prio();
    209           item = heap.top();
    210           prio = heap[item];
    211           own_prio = heap.prio();
    212           own_item = heap.top();
    213           own_prio = heap[own_item];
    214 
    215           heap.push(item, prio);
    216           heap.push(own_item, own_prio);
    217           heap.pop();
    218 
    219           heap.set(item, prio);
    220           heap.decrease(item, prio);
    221           heap.increase(item, prio);
    222           heap.set(own_item, own_prio);
    223           heap.decrease(own_item, own_prio);
    224           heap.increase(own_item, own_prio);
    225 
    226           heap.erase(item);
    227           heap.erase(own_item);
    228           heap.clear();
    229 
    230           own_state = heap.state(own_item);
    231           heap.state(own_item, own_state);
    232 
    233           own_state = _Heap::PRE_HEAP;
    234           own_state = _Heap::IN_HEAP;
    235           own_state = _Heap::POST_HEAP;
    236         }
    237 
    238         _Heap& heap;
    239         ItemIntMap& map;
     177        void constraints() {
     178          typedef typename _Heap::Item OwnItem;
     179          typedef typename _Heap::Prio OwnPrio;
     180          typedef typename _Heap::State OwnState;
     181
     182          Item item;
     183          Prio prio;
     184          item=Item();
     185          prio=Prio();
     186          ignore_unused_variable_warning(item);
     187          ignore_unused_variable_warning(prio);
     188
     189          OwnItem own_item;
     190          OwnPrio own_prio;
     191          OwnState own_state;
     192          own_item=Item();
     193          own_prio=Prio();
     194          ignore_unused_variable_warning(own_item);
     195          ignore_unused_variable_warning(own_prio);
     196          ignore_unused_variable_warning(own_state);
     197
     198          _Heap heap1(map);
     199          _Heap heap2 = heap1;
     200          ignore_unused_variable_warning(heap1);
     201          ignore_unused_variable_warning(heap2);
     202
     203          int s = heap.size();
     204          ignore_unused_variable_warning(s);
     205          bool e = heap.empty();
     206          ignore_unused_variable_warning(e);
     207
     208          prio = heap.prio();
     209          item = heap.top();
     210          prio = heap[item];
     211          own_prio = heap.prio();
     212          own_item = heap.top();
     213          own_prio = heap[own_item];
     214
     215          heap.push(item, prio);
     216          heap.push(own_item, own_prio);
     217          heap.pop();
     218
     219          heap.set(item, prio);
     220          heap.decrease(item, prio);
     221          heap.increase(item, prio);
     222          heap.set(own_item, own_prio);
     223          heap.decrease(own_item, own_prio);
     224          heap.increase(own_item, own_prio);
     225
     226          heap.erase(item);
     227          heap.erase(own_item);
     228          heap.clear();
     229
     230          own_state = heap.state(own_item);
     231          heap.state(own_item, own_state);
     232
     233          own_state = _Heap::PRE_HEAP;
     234          own_state = _Heap::IN_HEAP;
     235          own_state = _Heap::POST_HEAP;
     236        }
     237
     238        _Heap& heap;
     239        ItemIntMap& map;
    240240      };
    241241    };
  • lemon/concepts/maps.h

    r114 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4848
    4949      /// Returns the value associated with the given key.
    50       Value operator[](const Key &) const { 
     50      Value operator[](const Key &) const {
    5151        return *static_cast<Value *>(0);
    5252      }
     
    5454      template<typename _ReadMap>
    5555      struct Constraints {
    56         void constraints() {
    57           Value val = m[key];
    58           val = m[key];
    59           typename _ReadMap::Value own_val = m[own_key];
    60           own_val = m[own_key];
    61 
    62           ignore_unused_variable_warning(key);
    63           ignore_unused_variable_warning(val);
    64           ignore_unused_variable_warning(own_key);
    65           ignore_unused_variable_warning(own_val);
    66         }
    67         const Key& key;
    68         const typename _ReadMap::Key& own_key;
    69         const _ReadMap& m;
     56        void constraints() {
     57          Value val = m[key];
     58          val = m[key];
     59          typename _ReadMap::Value own_val = m[own_key];
     60          own_val = m[own_key];
     61
     62          ignore_unused_variable_warning(key);
     63          ignore_unused_variable_warning(val);
     64          ignore_unused_variable_warning(own_key);
     65          ignore_unused_variable_warning(own_val);
     66        }
     67        const Key& key;
     68        const typename _ReadMap::Key& own_key;
     69        const _ReadMap& m;
    7070      };
    7171
     
    9494      template <typename _WriteMap>
    9595      struct Constraints {
    96         void constraints() {
    97           m.set(key, val);
    98           m.set(own_key, own_val);
    99 
    100           ignore_unused_variable_warning(key);
    101           ignore_unused_variable_warning(val);
    102           ignore_unused_variable_warning(own_key);
    103           ignore_unused_variable_warning(own_val);
    104         }
    105         const Key& key;
    106         const Value& val;
    107         const typename _WriteMap::Key& own_key;
    108         const typename _WriteMap::Value& own_val;
    109         _WriteMap& m;
     96        void constraints() {
     97          m.set(key, val);
     98          m.set(own_key, own_val);
     99
     100          ignore_unused_variable_warning(key);
     101          ignore_unused_variable_warning(val);
     102          ignore_unused_variable_warning(own_key);
     103          ignore_unused_variable_warning(own_val);
     104        }
     105        const Key& key;
     106        const Value& val;
     107        const typename _WriteMap::Key& own_key;
     108        const typename _WriteMap::Value& own_val;
     109        _WriteMap& m;
    110110      };
    111111    };
     
    117117    template<typename K, typename T>
    118118    class ReadWriteMap : public ReadMap<K,T>,
    119                         public WriteMap<K,T>
     119                        public WriteMap<K,T>
    120120    {
    121121    public:
     
    126126
    127127      /// Returns the value associated with the given key.
    128       Value operator[](const Key &) const { 
     128      Value operator[](const Key &) const {
    129129        return *static_cast<Value *>(0);
    130130      }
     
    135135      template<typename _ReadWriteMap>
    136136      struct Constraints {
    137         void constraints() {
    138           checkConcept<ReadMap<K, T>, _ReadWriteMap >();
    139           checkConcept<WriteMap<K, T>, _ReadWriteMap >();
    140         }
     137        void constraints() {
     138          checkConcept<ReadMap<K, T>, _ReadWriteMap >();
     139          checkConcept<WriteMap<K, T>, _ReadWriteMap >();
     140        }
    141141      };
    142142    };
     
    165165
    166166      /// Returns a reference to the value associated with the given key.
    167       Reference operator[](const Key &) { 
     167      Reference operator[](const Key &) {
    168168        return *static_cast<Value *>(0);
    169169      }
     
    179179      template<typename _ReferenceMap>
    180180      struct Constraints {
    181         void constraints() {
    182           checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
    183           ref = m[key];
    184           m[key] = val;
    185           m[key] = ref;
    186           m[key] = cref;
    187           own_ref = m[own_key];
    188           m[own_key] = own_val;
    189           m[own_key] = own_ref;
    190           m[own_key] = own_cref;
    191           m[key] = m[own_key];
    192           m[own_key] = m[key];
    193         }
    194         const Key& key;
    195         Value& val;
    196         Reference ref;
    197         ConstReference cref;
    198         const typename _ReferenceMap::Key& own_key;
    199         typename _ReferenceMap::Value& own_val;
    200         typename _ReferenceMap::Reference own_ref;
    201         typename _ReferenceMap::ConstReference own_cref;
    202         _ReferenceMap& m;
     181        void constraints() {
     182          checkConcept<ReadWriteMap<K, T>, _ReferenceMap >();
     183          ref = m[key];
     184          m[key] = val;
     185          m[key] = ref;
     186          m[key] = cref;
     187          own_ref = m[own_key];
     188          m[own_key] = own_val;
     189          m[own_key] = own_ref;
     190          m[own_key] = own_cref;
     191          m[key] = m[own_key];
     192          m[own_key] = m[key];
     193        }
     194        const Key& key;
     195        Value& val;
     196        Reference ref;
     197        ConstReference cref;
     198        const typename _ReferenceMap::Key& own_key;
     199        typename _ReferenceMap::Value& own_val;
     200        typename _ReferenceMap::Reference own_ref;
     201        typename _ReferenceMap::ConstReference own_cref;
     202        _ReferenceMap& m;
    203203      };
    204204    };
  • lemon/concepts/path.h

    r157 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4040    ///
    4141    /// A skeleton structure for representing directed paths in a
    42     /// digraph. 
     42    /// digraph.
    4343    /// \tparam _Digraph The digraph type in which the path is.
    4444    ///
     
    8484      class ArcIt {
    8585      public:
    86         /// Default constructor
    87         ArcIt() {}
    88         /// Invalid constructor
    89         ArcIt(Invalid) {}
    90         /// Constructor for first arc
    91         ArcIt(const Path &) {}
     86        /// Default constructor
     87        ArcIt() {}
     88        /// Invalid constructor
     89        ArcIt(Invalid) {}
     90        /// Constructor for first arc
     91        ArcIt(const Path &) {}
    9292
    9393        /// Conversion to Arc
    94         operator Arc() const { return INVALID; }
    95 
    96         /// Next arc
    97         ArcIt& operator++() {return *this;}
    98 
    99         /// Comparison operator
    100         bool operator==(const ArcIt&) const {return true;}
    101         /// Comparison operator
    102         bool operator!=(const ArcIt&) const {return true;}
    103         /// Comparison operator
    104         bool operator<(const ArcIt&) const {return false;}
     94        operator Arc() const { return INVALID; }
     95
     96        /// Next arc
     97        ArcIt& operator++() {return *this;}
     98
     99        /// Comparison operator
     100        bool operator==(const ArcIt&) const {return true;}
     101        /// Comparison operator
     102        bool operator!=(const ArcIt&) const {return true;}
     103         /// Comparison operator
     104         bool operator<(const ArcIt&) const {return false;}
    105105
    106106      };
     
    138138
    139139    namespace _path_bits {
    140      
     140
    141141      template <typename _Digraph, typename _Path, typename RevPathTag = void>
    142142      struct PathDumperConstraints {
     
    163163      template <typename _Digraph, typename _Path>
    164164      struct PathDumperConstraints<
    165         _Digraph, _Path, 
     165        _Digraph, _Path,
    166166        typename enable_if<typename _Path::RevPathTag, void>::type
    167167      > {
     
    185185        _Path& p;
    186186      };
    187    
     187
    188188    }
    189189
     
    210210    /// The paths can be constructed from any path type by a
    211211    /// template constructor or a template assignment operator.
    212     /// 
     212    ///
    213213    template <typename _Digraph>
    214214    class PathDumper {
     
    239239      class ArcIt {
    240240      public:
    241         /// Default constructor
    242         ArcIt() {}
    243         /// Invalid constructor
    244         ArcIt(Invalid) {}
    245         /// Constructor for first arc
    246         ArcIt(const PathDumper&) {}
     241        /// Default constructor
     242        ArcIt() {}
     243        /// Invalid constructor
     244        ArcIt(Invalid) {}
     245        /// Constructor for first arc
     246        ArcIt(const PathDumper&) {}
    247247
    248248        /// Conversion to Arc
    249         operator Arc() const { return INVALID; }
    250 
    251         /// Next arc
    252         ArcIt& operator++() {return *this;}
    253 
    254         /// Comparison operator
    255         bool operator==(const ArcIt&) const {return true;}
    256         /// Comparison operator
    257         bool operator!=(const ArcIt&) const {return true;}
    258         /// Comparison operator
    259         bool operator<(const ArcIt&) const {return false;}
     249        operator Arc() const { return INVALID; }
     250
     251        /// Next arc
     252        ArcIt& operator++() {return *this;}
     253
     254        /// Comparison operator
     255        bool operator==(const ArcIt&) const {return true;}
     256        /// Comparison operator
     257        bool operator!=(const ArcIt&) const {return true;}
     258         /// Comparison operator
     259         bool operator<(const ArcIt&) const {return false;}
    260260
    261261      };
     
    267267      class RevArcIt {
    268268      public:
    269         /// Default constructor
    270         RevArcIt() {}
    271         /// Invalid constructor
    272         RevArcIt(Invalid) {}
    273         /// Constructor for first arc
    274         RevArcIt(const PathDumper &) {}
     269        /// Default constructor
     270        RevArcIt() {}
     271        /// Invalid constructor
     272        RevArcIt(Invalid) {}
     273        /// Constructor for first arc
     274        RevArcIt(const PathDumper &) {}
    275275
    276276        /// Conversion to Arc
    277         operator Arc() const { return INVALID; }
    278 
    279         /// Next arc
    280         RevArcIt& operator++() {return *this;}
    281 
    282         /// Comparison operator
    283         bool operator==(const RevArcIt&) const {return true;}
    284         /// Comparison operator
    285         bool operator!=(const RevArcIt&) const {return true;}
    286         /// Comparison operator
    287         bool operator<(const RevArcIt&) const {return false;}
     277        operator Arc() const { return INVALID; }
     278
     279        /// Next arc
     280        RevArcIt& operator++() {return *this;}
     281
     282        /// Comparison operator
     283        bool operator==(const RevArcIt&) const {return true;}
     284        /// Comparison operator
     285        bool operator!=(const RevArcIt&) const {return true;}
     286         /// Comparison operator
     287         bool operator<(const RevArcIt&) const {return false;}
    288288
    289289      };
  • lemon/counter.h

    r168 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2727///\brief Tools for counting steps and events
    2828
    29 namespace lemon 
     29namespace lemon
    3030{
    3131
     
    3333
    3434  template<class P>
    35   class _SubCounter 
     35  class _SubCounter
    3636  {
    3737    P &_parent;
     
    5050    _SubCounter(P &parent,const char *title,std::ostream &os=std::cerr)
    5151      : _parent(parent), _title(title), _os(os), count(0) {}
    52     ~_SubCounter() { 
     52    ~_SubCounter() {
    5353      _os << _title << count <<std::endl;
    5454      _parent+=count;
     
    6464
    6565  template<class P>
    66   class _NoSubCounter 
     66  class _NoSubCounter
    6767  {
    6868    P &_parent;
     
    7070    typedef _NoSubCounter<_NoSubCounter<P> > SubCounter;
    7171    typedef _NoSubCounter<_NoSubCounter<P> > NoSubCounter;
    72  
     72
    7373    _NoSubCounter(P &parent) :_parent(parent) {}
    74     _NoSubCounter(P &parent,std::string,std::ostream &) 
    75       :_parent(parent) {}
    76     _NoSubCounter(P &parent,std::string) 
     74    _NoSubCounter(P &parent,std::string,std::ostream &)
     75      :_parent(parent) {}
     76    _NoSubCounter(P &parent,std::string)
    7777      :_parent(parent) {}
    7878    _NoSubCounter(P &parent,const char *,std::ostream &)
     
    103103  /// for different types of operations.
    104104  /// A report containing the given title and the value of the counter
    105   /// is automatically printed on destruction. 
     105  /// is automatically printed on destruction.
    106106  ///
    107107  /// The following example shows the usage of counters and subcounters.
     
    134134  ///
    135135  /// \sa NoCounter
    136   class Counter 
     136  class Counter
    137137  {
    138138    std::string _title;
     
    142142
    143143    /// SubCounter class
    144    
     144
    145145    /// This class can be used to setup subcounters for a \ref Counter
    146146    /// to have finer reports. A subcounter provides exactly the same
     
    148148    /// decrements the value of its parent.
    149149    /// Subcounters can also have subcounters.
    150     /// 
     150    ///
    151151    /// The parent counter must be given as the first parameter of the
    152152    /// constructor. Apart from that a title and an \c ostream object
     
    157157    /// would like to turn off this report, use \ref NoSubCounter
    158158    /// instead.
    159     /// 
     159    ///
    160160    /// \sa NoSubCounter
    161161    typedef _SubCounter<Counter> SubCounter;
    162162
    163     /// SubCounter class without printing report on destruction 
    164    
     163    /// SubCounter class without printing report on destruction
     164
    165165    /// This class can be used to setup subcounters for a \ref Counter.
    166166    /// It is the same as \ref SubCounter but it does not print report
     
    169169    ///
    170170    /// Replacing \ref SubCounter "SubCounter"s with \ref NoSubCounter
    171     /// "NoSubCounter"s makes it possible to turn off reporting 
     171    /// "NoSubCounter"s makes it possible to turn off reporting
    172172    /// subcounter values without actually removing the definitions
    173173    /// and the increment or decrement operators.
     
    179179    Counter() : _title(), _os(std::cerr), count(0) {}
    180180    /// Constructor.
    181     Counter(std::string title,std::ostream &os=std::cerr) 
     181    Counter(std::string title,std::ostream &os=std::cerr)
    182182      : _title(title), _os(os), count(0) {}
    183183    /// Constructor.
     
    205205    /// \note This function does not reset the values of
    206206    /// \ref SubCounter "SubCounter"s but it resets \ref NoSubCounter
    207     /// "NoSubCounter"s along with the main counter. 
     207    /// "NoSubCounter"s along with the main counter.
    208208    void reset(int c=0) {count=c;}
    209209    /// Returns the value of the counter.
  • lemon/dfs.h

    r158 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3535namespace lemon {
    3636
    37  
     37
    3838  ///Default traits class of Dfs class.
    3939
     
    4343  struct DfsDefaultTraits
    4444  {
    45     ///The digraph type the algorithm runs on. 
     45    ///The digraph type the algorithm runs on.
    4646    typedef GR Digraph;
    4747    ///\brief The type of the map that stores the last
    4848    ///arcs of the %DFS paths.
    49     /// 
     49    ///
    5050    ///The type of the map that stores the last
    5151    ///arcs of the %DFS paths.
     
    5454    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
    5555    ///Instantiates a PredMap.
    56  
    57     ///This function instantiates a \ref PredMap. 
     56
     57    ///This function instantiates a \ref PredMap.
    5858    ///\param G is the digraph, to which we would like to define the PredMap.
    5959    ///\todo The digraph alone may be insufficient to initialize
    60     static PredMap *createPredMap(const GR &G) 
     60    static PredMap *createPredMap(const GR &G)
    6161    {
    6262      return new PredMap(G);
     
    6464
    6565    ///The type of the map that indicates which nodes are processed.
    66  
     66
    6767    ///The type of the map that indicates which nodes are processed.
    6868    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    7070    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    7171    ///Instantiates a ProcessedMap.
    72  
    73     ///This function instantiates a \ref ProcessedMap. 
     72
     73    ///This function instantiates a \ref ProcessedMap.
    7474    ///\param g is the digraph, to which
    7575    ///we would like to define the \ref ProcessedMap
     
    8383    }
    8484    ///The type of the map that indicates which nodes are reached.
    85  
     85
    8686    ///The type of the map that indicates which nodes are reached.
    8787    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    8989    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    9090    ///Instantiates a ReachedMap.
    91  
    92     ///This function instantiates a \ref ReachedMap. 
     91
     92    ///This function instantiates a \ref ReachedMap.
    9393    ///\param G is the digraph, to which
    9494    ///we would like to define the \ref ReachedMap.
     
    9898    }
    9999    ///The type of the map that stores the dists of the nodes.
    100  
     100
    101101    ///The type of the map that stores the dists of the nodes.
    102102    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    104104    typedef typename Digraph::template NodeMap<int> DistMap;
    105105    ///Instantiates a DistMap.
    106  
    107     ///This function instantiates a \ref DistMap. 
     106
     107    ///This function instantiates a \ref DistMap.
    108108    ///\param G is the digraph, to which we would like to define the \ref DistMap
    109109    static DistMap *createDistMap(const GR &G)
     
    112112    }
    113113  };
    114  
     114
    115115  ///%DFS algorithm class.
    116  
     116
    117117  ///\ingroup search
    118118  ///This class provides an efficient implementation of the %DFS algorithm.
     
    128128#ifdef DOXYGEN
    129129  template <typename GR,
    130             typename TR>
     130            typename TR>
    131131#else
    132132  template <typename GR=ListDigraph,
    133             typename TR=DfsDefaultTraits<GR> >
     133            typename TR=DfsDefaultTraits<GR> >
    134134#endif
    135135  class Dfs {
     
    144144    public:
    145145      virtual const char* what() const throw() {
    146         return "lemon::Dfs::UninitializedParameter";
     146        return "lemon::Dfs::UninitializedParameter";
    147147      }
    148148    };
     
    159159    ///\e
    160160    typedef typename Digraph::OutArcIt OutArcIt;
    161    
     161
    162162    ///\brief The type of the map that stores the last
    163163    ///arcs of the %DFS paths.
     
    193193
    194194    ///Creates the maps if necessary.
    195    
     195
    196196    ///\todo Better memory allocation (instead of new).
    197     void create_maps() 
     197    void create_maps()
    198198    {
    199199      if(!_pred) {
    200         local_pred = true;
    201         _pred = Traits::createPredMap(*G);
     200        local_pred = true;
     201        _pred = Traits::createPredMap(*G);
    202202      }
    203203      if(!_dist) {
    204         local_dist = true;
    205         _dist = Traits::createDistMap(*G);
     204        local_dist = true;
     205        _dist = Traits::createDistMap(*G);
    206206      }
    207207      if(!_reached) {
    208         local_reached = true;
    209         _reached = Traits::createReachedMap(*G);
     208        local_reached = true;
     209        _reached = Traits::createReachedMap(*G);
    210210      }
    211211      if(!_processed) {
    212         local_processed = true;
    213         _processed = Traits::createProcessedMap(*G);
     212        local_processed = true;
     213        _processed = Traits::createProcessedMap(*G);
    214214      }
    215215    }
     
    218218
    219219    Dfs() {}
    220    
     220
    221221  public:
    222222
     
    230230    struct DefPredMapTraits : public Traits {
    231231      typedef T PredMap;
    232       static PredMap *createPredMap(const Digraph &G) 
     232      static PredMap *createPredMap(const Digraph &G)
    233233      {
    234         throw UninitializedParameter();
     234        throw UninitializedParameter();
    235235      }
    236236    };
     
    244244      typedef Dfs<Digraph, DefPredMapTraits<T> > Create;
    245245    };
    246    
    247    
     246
     247
    248248    template <class T>
    249249    struct DefDistMapTraits : public Traits {
    250250      typedef T DistMap;
    251       static DistMap *createDistMap(const Digraph &) 
     251      static DistMap *createDistMap(const Digraph &)
    252252      {
    253         throw UninitializedParameter();
     253        throw UninitializedParameter();
    254254      }
    255255    };
     
    263263      typedef Dfs<Digraph, DefDistMapTraits<T> > Create;
    264264    };
    265    
     265
    266266    template <class T>
    267267    struct DefReachedMapTraits : public Traits {
    268268      typedef T ReachedMap;
    269       static ReachedMap *createReachedMap(const Digraph &) 
     269      static ReachedMap *createReachedMap(const Digraph &)
    270270      {
    271         throw UninitializedParameter();
     271        throw UninitializedParameter();
    272272      }
    273273    };
     
    285285    struct DefProcessedMapTraits : public Traits {
    286286      typedef T ProcessedMap;
    287       static ProcessedMap *createProcessedMap(const Digraph &) 
     287      static ProcessedMap *createProcessedMap(const Digraph &)
    288288      {
    289         throw UninitializedParameter();
     289        throw UninitializedParameter();
    290290      }
    291291    };
     
    296296    ///
    297297    template <class T>
    298     struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits<T> > { 
     298    struct DefProcessedMap : public Dfs< Digraph, DefProcessedMapTraits<T> > {
    299299      typedef Dfs< Digraph, DefProcessedMapTraits<T> > Create;
    300300    };
    301    
     301
    302302    struct DefDigraphProcessedMapTraits : public Traits {
    303303      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    304       static ProcessedMap *createProcessedMap(const Digraph &G) 
     304      static ProcessedMap *createProcessedMap(const Digraph &G)
    305305      {
    306         return new ProcessedMap(G);
     306        return new ProcessedMap(G);
    307307      }
    308308    };
     
    315315    template <class T>
    316316    class DefProcessedMapToBeDefaultMap :
    317       public Dfs< Digraph, DefDigraphProcessedMapTraits> { 
     317      public Dfs< Digraph, DefDigraphProcessedMapTraits> {
    318318      typedef Dfs< Digraph, DefDigraphProcessedMapTraits> Create;
    319319    };
    320    
     320
    321321    ///@}
    322322
    323   public:     
    324    
     323  public:
     324
    325325    ///Constructor.
    326    
     326
    327327    ///\param _G the digraph the algorithm will run on.
    328328    ///
     
    334334      _processed(NULL), local_processed(false)
    335335    { }
    336    
     336
    337337    ///Destructor.
    338     ~Dfs() 
     338    ~Dfs()
    339339    {
    340340      if(local_pred) delete _pred;
     
    351351    ///automatically allocated map, of course.
    352352    ///\return <tt> (*this) </tt>
    353     Dfs &predMap(PredMap &m) 
     353    Dfs &predMap(PredMap &m)
    354354    {
    355355      if(local_pred) {
    356         delete _pred;
    357         local_pred=false;
     356        delete _pred;
     357        local_pred=false;
    358358      }
    359359      _pred = &m;
     
    368368    ///automatically allocated map, of course.
    369369    ///\return <tt> (*this) </tt>
    370     Dfs &distMap(DistMap &m) 
     370    Dfs &distMap(DistMap &m)
    371371    {
    372372      if(local_dist) {
    373         delete _dist;
    374         local_dist=false;
     373        delete _dist;
     374        local_dist=false;
    375375      }
    376376      _dist = &m;
     
    385385    ///automatically allocated map, of course.
    386386    ///\return <tt> (*this) </tt>
    387     Dfs &reachedMap(ReachedMap &m) 
     387    Dfs &reachedMap(ReachedMap &m)
    388388    {
    389389      if(local_reached) {
    390         delete _reached;
    391         local_reached=false;
     390        delete _reached;
     391        local_reached=false;
    392392      }
    393393      _reached = &m;
     
    402402    ///automatically allocated map, of course.
    403403    ///\return <tt> (*this) </tt>
    404     Dfs &processedMap(ProcessedMap &m) 
     404    Dfs &processedMap(ProcessedMap &m)
    405405    {
    406406      if(local_processed) {
    407         delete _processed;
    408         local_processed=false;
     407        delete _processed;
     408        local_processed=false;
    409409      }
    410410      _processed = &m;
     
    435435      _stack_head=-1;
    436436      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
    437         _pred->set(u,INVALID);
    438         // _predNode->set(u,INVALID);
    439         _reached->set(u,false);
    440         _processed->set(u,false);
    441       }
    442     }
    443    
     437        _pred->set(u,INVALID);
     438        // _predNode->set(u,INVALID);
     439        _reached->set(u,false);
     440        _processed->set(u,false);
     441      }
     442    }
     443
    444444    ///Adds a new source node.
    445445
     
    451451    {
    452452      if(!(*_reached)[s])
    453         {
    454           _reached->set(s,true);
    455           _pred->set(s,INVALID);
    456           OutArcIt e(*G,s);
    457           if(e!=INVALID) {
    458             _stack[++_stack_head]=e;
    459             _dist->set(s,_stack_head);
    460           }
    461           else {
    462             _processed->set(s,true);
    463             _dist->set(s,0);
    464           }
    465         }
    466     }
    467    
     453        {
     454          _reached->set(s,true);
     455          _pred->set(s,INVALID);
     456          OutArcIt e(*G,s);
     457          if(e!=INVALID) {
     458            _stack[++_stack_head]=e;
     459            _dist->set(s,_stack_head);
     460          }
     461          else {
     462            _processed->set(s,true);
     463            _dist->set(s,0);
     464          }
     465        }
     466    }
     467
    468468    ///Processes the next arc.
    469469
     
    474474    ///\pre The stack must not be empty!
    475475    Arc processNextArc()
    476     { 
     476    {
    477477      Node m;
    478478      Arc e=_stack[_stack_head];
    479479      if(!(*_reached)[m=G->target(e)]) {
    480         _pred->set(m,e);
    481         _reached->set(m,true);
    482         ++_stack_head;
    483         _stack[_stack_head] = OutArcIt(*G, m);
    484         _dist->set(m,_stack_head);
     480        _pred->set(m,e);
     481        _reached->set(m,true);
     482        ++_stack_head;
     483        _stack[_stack_head] = OutArcIt(*G, m);
     484        _dist->set(m,_stack_head);
    485485      }
    486486      else {
    487         m=G->source(e);
    488         ++_stack[_stack_head];
     487        m=G->source(e);
     488        ++_stack[_stack_head];
    489489      }
    490490      while(_stack_head>=0 && _stack[_stack_head]==INVALID) {
    491         _processed->set(m,true);
    492         --_stack_head;
    493         if(_stack_head>=0) {
    494           m=G->source(_stack[_stack_head]);
    495           ++_stack[_stack_head];
    496         }
     491        _processed->set(m,true);
     492        --_stack_head;
     493        if(_stack_head>=0) {
     494          m=G->source(_stack[_stack_head]);
     495          ++_stack[_stack_head];
     496        }
    497497      }
    498498      return e;
     
    505505    /// empty.
    506506    OutArcIt nextArc()
    507     { 
     507    {
    508508      return _stack_head>=0?_stack[_stack_head]:INVALID;
    509509    }
     
    516516    bool emptyQueue() { return _stack_head<0; }
    517517    ///Returns the number of the nodes to be processed.
    518    
     518
    519519    ///Returns the number of the nodes to be processed in the queue.
    520520    int queueSize() { return _stack_head+1; }
    521    
     521
    522522    ///Executes the algorithm.
    523523
     
    538538      while ( !emptyQueue() ) processNextArc();
    539539    }
    540    
     540
    541541    ///Executes the algorithm until \c dest is reached.
    542542
     
    555555    void start(Node dest)
    556556    {
    557       while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest ) 
    558         processNextArc();
    559     }
    560    
     557      while ( !emptyQueue() && G->target(_stack[_stack_head])!=dest )
     558        processNextArc();
     559    }
     560
    561561    ///Executes the algorithm until a condition is met.
    562562
     
    583583
    584584    ///Runs %DFS algorithm to visit all nodes in the digraph.
    585    
     585
    586586    ///This method runs the %DFS algorithm in order to
    587587    ///compute the
     
    611611
    612612    ///Runs %DFS algorithm from node \c s.
    613    
     613
    614614    ///This method runs the %DFS algorithm from a root node \c s
    615615    ///in order to
     
    630630      start();
    631631    }
    632    
     632
    633633    ///Finds the %DFS path between \c s and \c t.
    634    
     634
    635635    ///Finds the %DFS path between \c s and \c t.
    636636    ///
     
    650650      return reached(t)?_stack_head+1:0;
    651651    }
    652    
     652
    653653    ///@}
    654654
     
    658658    ///Before the use of these functions,
    659659    ///either run() or start() must be called.
    660    
     660
    661661    ///@{
    662662
     
    664664
    665665    ///Gives back the shortest path.
    666    
     666
    667667    ///Gives back the shortest path.
    668668    ///\pre The \c t should be reachable from the source.
    669     Path path(Node t) 
     669    Path path(Node t)
    670670    {
    671671      return Path(*G, *_pred, t);
     
    676676    ///Returns the distance of a node from the root(s).
    677677    ///\pre \ref run() must be called before using this function.
    678     ///\warning If node \c v is unreachable from the root(s) then the return 
     678    ///\warning If node \c v is unreachable from the root(s) then the return
    679679    ///value of this funcion is undefined.
    680680    int dist(Node v) const { return (*_dist)[v]; }
     
    706706    ///using this function.
    707707    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
    708                                   G->source((*_pred)[v]); }
    709    
     708                                  G->source((*_pred)[v]); }
     709
    710710    ///Returns a reference to the NodeMap of distances.
    711711
     
    714714    ///be called before using this function.
    715715    const DistMap &distMap() const { return *_dist;}
    716  
     716
    717717    ///Returns a reference to the %DFS arc-tree map.
    718718
     
    722722    ///must be called before using this function.
    723723    const PredMap &predMap() const { return *_pred;}
    724  
     724
    725725    ///Checks if a node is reachable from the root.
    726726
     
    731731    ///
    732732    bool reached(Node v) { return (*_reached)[v]; }
    733    
     733
    734734    ///@}
    735735  };
     
    742742  struct DfsWizardDefaultTraits
    743743  {
    744     ///The digraph type the algorithm runs on. 
     744    ///The digraph type the algorithm runs on.
    745745    typedef GR Digraph;
    746746    ///\brief The type of the map that stores the last
    747747    ///arcs of the %DFS paths.
    748     /// 
     748    ///
    749749    ///The type of the map that stores the last
    750750    ///arcs of the %DFS paths.
     
    753753    typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap;
    754754    ///Instantiates a PredMap.
    755  
    756     ///This function instantiates a \ref PredMap. 
     755
     756    ///This function instantiates a \ref PredMap.
    757757    ///\param g is the digraph, to which we would like to define the PredMap.
    758758    ///\todo The digraph alone may be insufficient to initialize
    759759#ifdef DOXYGEN
    760     static PredMap *createPredMap(const GR &g) 
     760    static PredMap *createPredMap(const GR &g)
    761761#else
    762     static PredMap *createPredMap(const GR &) 
     762    static PredMap *createPredMap(const GR &)
    763763#endif
    764764    {
     
    767767
    768768    ///The type of the map that indicates which nodes are processed.
    769  
     769
    770770    ///The type of the map that indicates which nodes are processed.
    771771    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    773773    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    774774    ///Instantiates a ProcessedMap.
    775  
    776     ///This function instantiates a \ref ProcessedMap. 
     775
     776    ///This function instantiates a \ref ProcessedMap.
    777777    ///\param g is the digraph, to which
    778778    ///we would like to define the \ref ProcessedMap
     
    786786    }
    787787    ///The type of the map that indicates which nodes are reached.
    788  
     788
    789789    ///The type of the map that indicates which nodes are reached.
    790790    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    792792    typedef typename Digraph::template NodeMap<bool> ReachedMap;
    793793    ///Instantiates a ReachedMap.
    794  
    795     ///This function instantiates a \ref ReachedMap. 
     794
     795    ///This function instantiates a \ref ReachedMap.
    796796    ///\param G is the digraph, to which
    797797    ///we would like to define the \ref ReachedMap.
     
    801801    }
    802802    ///The type of the map that stores the dists of the nodes.
    803  
     803
    804804    ///The type of the map that stores the dists of the nodes.
    805805    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    807807    typedef NullMap<typename Digraph::Node,int> DistMap;
    808808    ///Instantiates a DistMap.
    809  
    810     ///This function instantiates a \ref DistMap. 
     809
     810    ///This function instantiates a \ref DistMap.
    811811    ///\param g is the digraph, to which we would like to define the \ref DistMap
    812812#ifdef DOXYGEN
     
    819819    }
    820820  };
    821  
     821
    822822  /// Default traits used by \ref DfsWizard
    823823
     
    849849    ///Pointer to the source node.
    850850    Node _source;
    851    
     851
    852852    public:
    853853    /// Constructor.
    854    
     854
    855855    /// This constructor does not require parameters, therefore it initiates
    856856    /// all of the attributes to default values (0, INVALID).
    857857    DfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0),
    858                            _dist(0), _source(INVALID) {}
     858                           _dist(0), _source(INVALID) {}
    859859
    860860    /// Constructor.
    861    
     861
    862862    /// This constructor requires some parameters,
    863863    /// listed in the parameters list.
     
    866866    /// \param s is the initial value of  \ref _source
    867867    DfsWizardBase(const GR &g, Node s=INVALID) :
    868       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
     868      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
    869869      _reached(0), _processed(0), _pred(0), _dist(0), _source(s) {}
    870870
    871871  };
    872  
     872
    873873  /// A class to make the usage of the Dfs algorithm easier
    874874
     
    905905    //\e
    906906    typedef typename Digraph::OutArcIt OutArcIt;
    907    
     907
    908908    ///\brief The type of the map that stores
    909909    ///the reached nodes
     
    935935
    936936    ///Runs Dfs algorithm from a given node.
    937    
     937
    938938    ///Runs Dfs algorithm from a given node.
    939939    ///The node can be given by the \ref source function.
     
    942942      if(Base::_source==INVALID) throw UninitializedParameter();
    943943      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    944       if(Base::_reached) 
     944      if(Base::_reached)
    945945        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
    946       if(Base::_processed) 
     946      if(Base::_processed)
    947947        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
    948       if(Base::_pred) 
     948      if(Base::_pred)
    949949        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
    950       if(Base::_dist) 
     950      if(Base::_dist)
    951951        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
    952952      alg.run(Base::_source);
     
    969969      DefPredMapBase(const TR &b) : TR(b) {}
    970970    };
    971    
     971
    972972    ///\brief \ref named-templ-param "Named parameter"
    973973    ///function for setting PredMap type
     
    977977    ///
    978978    template<class T>
    979     DfsWizard<DefPredMapBase<T> > predMap(const T &t) 
     979    DfsWizard<DefPredMapBase<T> > predMap(const T &t)
    980980    {
    981981      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    982982      return DfsWizard<DefPredMapBase<T> >(*this);
    983983    }
    984    
    985  
     984
     985
    986986    template<class T>
    987987    struct DefReachedMapBase : public Base {
     
    990990      DefReachedMapBase(const TR &b) : TR(b) {}
    991991    };
    992    
     992
    993993    ///\brief \ref named-templ-param "Named parameter"
    994994    ///function for setting ReachedMap
     
    998998    ///
    999999    template<class T>
    1000     DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
     1000    DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t)
    10011001    {
    10021002      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
    10031003      return DfsWizard<DefReachedMapBase<T> >(*this);
    10041004    }
    1005    
     1005
    10061006
    10071007    template<class T>
     
    10111011      DefProcessedMapBase(const TR &b) : TR(b) {}
    10121012    };
    1013    
     1013
    10141014    ///\brief \ref named-templ-param "Named parameter"
    10151015    ///function for setting ProcessedMap
     
    10191019    ///
    10201020    template<class T>
    1021     DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
     1021    DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t)
    10221022    {
    10231023      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
    10241024      return DfsWizard<DefProcessedMapBase<T> >(*this);
    10251025    }
    1026    
     1026
    10271027    template<class T>
    10281028    struct DefDistMapBase : public Base {
     
    10311031      DefDistMapBase(const TR &b) : TR(b) {}
    10321032    };
    1033    
     1033
    10341034    ///\brief \ref named-templ-param "Named parameter"
    10351035    ///function for setting DistMap type
     
    10391039    ///
    10401040    template<class T>
    1041     DfsWizard<DefDistMapBase<T> > distMap(const T &t) 
     1041    DfsWizard<DefDistMapBase<T> > distMap(const T &t)
    10421042    {
    10431043      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    10441044      return DfsWizard<DefDistMapBase<T> >(*this);
    10451045    }
    1046    
     1046
    10471047    /// Sets the source node, from which the Dfs algorithm runs.
    10481048
    10491049    /// Sets the source node, from which the Dfs algorithm runs.
    10501050    /// \param s is the source node.
    1051     DfsWizard<TR> &source(Node s) 
     1051    DfsWizard<TR> &source(Node s)
    10521052    {
    10531053      Base::_source=s;
    10541054      return *this;
    10551055    }
    1056    
     1056
    10571057  };
    1058  
     1058
    10591059  ///Function type interface for Dfs algorithm.
    10601060
     
    10831083#ifdef DOXYGEN
    10841084  /// \brief Visitor class for dfs.
    1085   /// 
    1086   /// It gives a simple interface for a functional interface for dfs 
    1087   /// traversal. The traversal on a linear data structure. 
     1085  ///
     1086  /// It gives a simple interface for a functional interface for dfs
     1087  /// traversal. The traversal on a linear data structure.
    10881088  template <typename _Digraph>
    10891089  struct DfsVisitor {
     
    10921092    typedef typename Digraph::Node Node;
    10931093    /// \brief Called when the arc reach a node.
    1094     /// 
     1094    ///
    10951095    /// It is called when the dfs find an arc which target is not
    10961096    /// reached yet.
    10971097    void discover(const Arc& arc) {}
    10981098    /// \brief Called when the node reached first time.
    1099     /// 
     1099    ///
    11001100    /// It is Called when the node reached first time.
    11011101    void reach(const Node& node) {}
    11021102    /// \brief Called when we step back on an arc.
    1103     /// 
     1103    ///
    11041104    /// It is called when the dfs should step back on the arc.
    11051105    void backtrack(const Arc& arc) {}
    11061106    /// \brief Called when we step back from the node.
    1107     /// 
     1107    ///
    11081108    /// It is called when we step back from the node.
    11091109    void leave(const Node& node) {}
    1110     /// \brief Called when the arc examined but target of the arc 
     1110    /// \brief Called when the arc examined but target of the arc
    11111111    /// already discovered.
    1112     /// 
    1113     /// It called when the arc examined but the target of the arc 
     1112    ///
     1113    /// It called when the arc examined but the target of the arc
    11141114    /// already discovered.
    11151115    void examine(const Arc& arc) {}
    11161116    /// \brief Called for the source node of the dfs.
    1117     /// 
     1117    ///
    11181118    /// It is called for the source node of the dfs.
    11191119    void start(const Node& node) {}
    11201120    /// \brief Called when we leave the source node of the dfs.
    1121     /// 
     1121    ///
    11221122    /// It is called when we leave the source node of the dfs.
    11231123    void stop(const Node& node) {}
     
    11411141    struct Constraints {
    11421142      void constraints() {
    1143         Arc arc;
    1144         Node node;
    1145         visitor.discover(arc);
    1146         visitor.reach(node);
    1147         visitor.backtrack(arc);
    1148         visitor.leave(node);
    1149         visitor.examine(arc);
    1150         visitor.start(node);
    1151         visitor.stop(arc);
     1143        Arc arc;
     1144        Node node;
     1145        visitor.discover(arc);
     1146        visitor.reach(node);
     1147        visitor.backtrack(arc);
     1148        visitor.leave(node);
     1149        visitor.examine(arc);
     1150        visitor.start(node);
     1151        visitor.stop(arc);
    11521152      }
    11531153      _Visitor& visitor;
     
    11631163  struct DfsVisitDefaultTraits {
    11641164
    1165     /// \brief The digraph type the algorithm runs on. 
     1165    /// \brief The digraph type the algorithm runs on.
    11661166    typedef _Digraph Digraph;
    11671167
    11681168    /// \brief The type of the map that indicates which nodes are reached.
    1169     /// 
     1169    ///
    11701170    /// The type of the map that indicates which nodes are reached.
    11711171    /// It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    11751175    /// \brief Instantiates a ReachedMap.
    11761176    ///
    1177     /// This function instantiates a \ref ReachedMap. 
     1177    /// This function instantiates a \ref ReachedMap.
    11781178    /// \param digraph is the digraph, to which
    11791179    /// we would like to define the \ref ReachedMap.
     
    11831183
    11841184  };
    1185  
     1185
    11861186  /// %DFS Visit algorithm class.
    1187  
     1187
    11881188  /// \ingroup search
    11891189  /// This class provides an efficient implementation of the %DFS algorithm
     
    11921192  /// The %DfsVisit class provides an alternative interface to the Dfs
    11931193  /// class. It works with callback mechanism, the DfsVisit object calls
    1194   /// on every dfs event the \c Visitor class member functions. 
     1194  /// on every dfs event the \c Visitor class member functions.
    11951195  ///
    11961196  /// \tparam _Digraph The digraph type the algorithm runs on. The default value is
    11971197  /// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it
    11981198  /// is only passed to \ref DfsDefaultTraits.
    1199   /// \tparam _Visitor The Visitor object for the algorithm. The 
     1199  /// \tparam _Visitor The Visitor object for the algorithm. The
    12001200  /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which
    12011201  /// does not observe the Dfs events. If you want to observe the dfs
    12021202  /// events you should implement your own Visitor class.
    1203   /// \tparam _Traits Traits class to set various data types used by the 
     1203  /// \tparam _Traits Traits class to set various data types used by the
    12041204  /// algorithm. The default traits class is
    12051205  /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>".
     
    12121212#else
    12131213  template <typename _Digraph = ListDigraph,
    1214             typename _Visitor = DfsVisitor<_Digraph>,
    1215             typename _Traits = DfsDefaultTraits<_Digraph> >
     1214            typename _Visitor = DfsVisitor<_Digraph>,
     1215            typename _Traits = DfsDefaultTraits<_Digraph> >
    12161216#endif
    12171217  class DfsVisit {
    12181218  public:
    1219    
     1219
    12201220    /// \brief \ref Exception for uninitialized parameters.
    12211221    ///
     
    12241224    class UninitializedParameter : public lemon::UninitializedParameter {
    12251225    public:
    1226       virtual const char* what() const throw() 
     1226      virtual const char* what() const throw()
    12271227      {
    1228         return "lemon::DfsVisit::UninitializedParameter";
     1228        return "lemon::DfsVisit::UninitializedParameter";
    12291229      }
    12301230    };
     
    12631263    void create_maps() {
    12641264      if(!_reached) {
    1265         local_reached = true;
    1266         _reached = Traits::createReachedMap(*_digraph);
     1265        local_reached = true;
     1266        _reached = Traits::createReachedMap(*_digraph);
    12671267      }
    12681268    }
     
    12711271
    12721272    DfsVisit() {}
    1273    
     1273
    12741274  public:
    12751275
     
    12831283      typedef T ReachedMap;
    12841284      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1285         throw UninitializedParameter();
    1286       }
    1287     };
    1288     /// \brief \ref named-templ-param "Named parameter" for setting 
     1285        throw UninitializedParameter();
     1286      }
     1287    };
     1288    /// \brief \ref named-templ-param "Named parameter" for setting
    12891289    /// ReachedMap type
    12901290    ///
     
    12921292    template <class T>
    12931293    struct DefReachedMap : public DfsVisit< Digraph, Visitor,
    1294                                             DefReachedMapTraits<T> > {
     1294                                            DefReachedMapTraits<T> > {
    12951295      typedef DfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create;
    12961296    };
    12971297    ///@}
    12981298
    1299   public:     
    1300    
     1299  public:
     1300
    13011301    /// \brief Constructor.
    13021302    ///
     
    13061306    /// \param visitor The visitor of the algorithm.
    13071307    ///
    1308     DfsVisit(const Digraph& digraph, Visitor& visitor) 
     1308    DfsVisit(const Digraph& digraph, Visitor& visitor)
    13091309      : _digraph(&digraph), _visitor(&visitor),
    1310         _reached(0), local_reached(false) {}
    1311    
     1310        _reached(0), local_reached(false) {}
     1311
    13121312    /// \brief Destructor.
    13131313    ///
     
    13261326    DfsVisit &reachedMap(ReachedMap &m) {
    13271327      if(local_reached) {
    1328         delete _reached;
    1329         local_reached=false;
     1328        delete _reached;
     1329        local_reached=false;
    13301330      }
    13311331      _reached = &m;
     
    13541354      _stack_head = -1;
    13551355      for (NodeIt u(*_digraph) ; u != INVALID ; ++u) {
    1356         _reached->set(u, false);
    1357       }
    1358     }
    1359    
     1356        _reached->set(u, false);
     1357      }
     1358    }
     1359
    13601360    /// \brief Adds a new source node.
    13611361    ///
     
    13631363    void addSource(Node s) {
    13641364      if(!(*_reached)[s]) {
    1365           _reached->set(s,true);
    1366           _visitor->start(s);
    1367           _visitor->reach(s);
    1368           Arc e;
    1369           _digraph->firstOut(e, s);
    1370           if (e != INVALID) {
    1371             _stack[++_stack_head] = e;
    1372           } else {
    1373             _visitor->leave(s);
    1374           }
    1375         }
    1376     }
    1377    
     1365          _reached->set(s,true);
     1366          _visitor->start(s);
     1367          _visitor->reach(s);
     1368          Arc e;
     1369          _digraph->firstOut(e, s);
     1370          if (e != INVALID) {
     1371            _stack[++_stack_head] = e;
     1372          } else {
     1373            _visitor->leave(s);
     1374          }
     1375        }
     1376    }
     1377
    13781378    /// \brief Processes the next arc.
    13791379    ///
     
    13831383    ///
    13841384    /// \pre The stack must not be empty!
    1385     Arc processNextArc() { 
     1385    Arc processNextArc() {
    13861386      Arc e = _stack[_stack_head];
    13871387      Node m = _digraph->target(e);
    13881388      if(!(*_reached)[m]) {
    1389         _visitor->discover(e);
    1390         _visitor->reach(m);
    1391         _reached->set(m, true);
    1392         _digraph->firstOut(_stack[++_stack_head], m);
     1389        _visitor->discover(e);
     1390        _visitor->reach(m);
     1391        _reached->set(m, true);
     1392        _digraph->firstOut(_stack[++_stack_head], m);
    13931393      } else {
    1394         _visitor->examine(e);
    1395         m = _digraph->source(e);
    1396         _digraph->nextOut(_stack[_stack_head]);
     1394        _visitor->examine(e);
     1395        m = _digraph->source(e);
     1396        _digraph->nextOut(_stack[_stack_head]);
    13971397      }
    13981398      while (_stack_head>=0 && _stack[_stack_head] == INVALID) {
    1399         _visitor->leave(m);
    1400         --_stack_head;
    1401         if (_stack_head >= 0) {
    1402           _visitor->backtrack(_stack[_stack_head]);
    1403           m = _digraph->source(_stack[_stack_head]);
    1404           _digraph->nextOut(_stack[_stack_head]);
    1405         } else {
    1406           _visitor->stop(m);     
    1407         }
     1399        _visitor->leave(m);
     1400        --_stack_head;
     1401        if (_stack_head >= 0) {
     1402          _visitor->backtrack(_stack[_stack_head]);
     1403          m = _digraph->source(_stack[_stack_head]);
     1404          _digraph->nextOut(_stack[_stack_head]);
     1405        } else {
     1406          _visitor->stop(m);
     1407        }
    14081408      }
    14091409      return e;
     
    14161416    /// \return The next arc to be processed or INVALID if the stack is
    14171417    /// empty.
    1418     Arc nextArc() { 
     1418    Arc nextArc() {
    14191419      return _stack_head >= 0 ? _stack[_stack_head] : INVALID;
    14201420    }
     
    14311431    /// Returns the number of the nodes to be processed in the queue.
    14321432    int queueSize() { return _stack_head + 1; }
    1433    
     1433
    14341434    /// \brief Executes the algorithm.
    14351435    ///
     
    14411441      while ( !emptyQueue() ) processNextArc();
    14421442    }
    1443    
     1443
    14441444    /// \brief Executes the algorithm until \c dest is reached.
    14451445    ///
     
    14491449    /// with addSource() before using this function.
    14501450    void start(Node dest) {
    1451       while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != dest ) 
    1452         processNextArc();
    1453     }
    1454    
     1451      while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != dest )
     1452        processNextArc();
     1453    }
     1454
    14551455    /// \brief Executes the algorithm until a condition is met.
    14561456    ///
     
    14911491
    14921492    /// \brief Runs %DFSVisit algorithm to visit all nodes in the digraph.
    1493    
     1493
    14941494    /// This method runs the %DFS algorithm in order to
    14951495    /// compute the %DFS path to each node. The algorithm computes
  • lemon/dijkstra.h

    r184 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3535
    3636  /// \brief Default OperationTraits for the Dijkstra algorithm class.
    37   /// 
     37  ///
    3838  /// It defines all computational operations and constants which are
    3939  /// used in the Dijkstra algorithm.
     
    5555
    5656  /// \brief Widest path OperationTraits for the Dijkstra algorithm class.
    57   /// 
     57  ///
    5858  /// It defines all computational operations and constants which are
    5959  /// used in the Dijkstra algorithm for widest path computation.
     
    7373    }
    7474  };
    75  
     75
    7676  ///Default traits class of Dijkstra class.
    7777
     
    8282  struct DijkstraDefaultTraits
    8383  {
    84     ///The digraph type the algorithm runs on. 
     84    ///The digraph type the algorithm runs on.
    8585    typedef GR Digraph;
    8686    ///The type of the map that stores the arc lengths.
     
    104104    ///Instantiates a HeapCrossRef.
    105105
    106     ///This function instantiates a \c HeapCrossRef. 
    107     /// \param G is the digraph, to which we would like to define the 
     106    ///This function instantiates a \c HeapCrossRef.
     107    /// \param G is the digraph, to which we would like to define the
    108108    /// HeapCrossRef.
    109     static HeapCrossRef *createHeapCrossRef(const GR &G) 
     109    static HeapCrossRef *createHeapCrossRef(const GR &G)
    110110    {
    111111      return new HeapCrossRef(G);
    112112    }
    113    
     113
    114114    ///The heap type used by Dijkstra algorithm.
    115115
     
    120120    typedef BinHeap<typename LM::Value, HeapCrossRef, std::less<Value> > Heap;
    121121
    122     static Heap *createHeap(HeapCrossRef& R) 
     122    static Heap *createHeap(HeapCrossRef& R)
    123123    {
    124124      return new Heap(R);
     
    127127    ///\brief The type of the map that stores the last
    128128    ///arcs of the shortest paths.
    129     /// 
     129    ///
    130130    ///The type of the map that stores the last
    131131    ///arcs of the shortest paths.
     
    134134    typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
    135135    ///Instantiates a PredMap.
    136  
    137     ///This function instantiates a \c PredMap. 
     136
     137    ///This function instantiates a \c PredMap.
    138138    ///\param G is the digraph, to which we would like to define the PredMap.
    139139    ///\todo The digraph alone may be insufficient for the initialization
    140     static PredMap *createPredMap(const GR &G) 
     140    static PredMap *createPredMap(const GR &G)
    141141    {
    142142      return new PredMap(G);
     
    144144
    145145    ///The type of the map that stores whether a nodes is processed.
    146  
     146
    147147    ///The type of the map that stores whether a nodes is processed.
    148148    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    153153    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    154154    ///Instantiates a ProcessedMap.
    155  
    156     ///This function instantiates a \c ProcessedMap. 
     155
     156    ///This function instantiates a \c ProcessedMap.
    157157    ///\param g is the digraph, to which
    158158    ///we would like to define the \c ProcessedMap
     
    166166    }
    167167    ///The type of the map that stores the dists of the nodes.
    168  
     168
    169169    ///The type of the map that stores the dists of the nodes.
    170170    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    172172    typedef typename Digraph::template NodeMap<typename LM::Value> DistMap;
    173173    ///Instantiates a DistMap.
    174  
    175     ///This function instantiates a \ref DistMap. 
     174
     175    ///This function instantiates a \ref DistMap.
    176176    ///\param G is the digraph, to which we would like to define the \ref DistMap
    177177    static DistMap *createDistMap(const GR &G)
     
    180180    }
    181181  };
    182  
     182
    183183  ///%Dijkstra algorithm class.
    184  
     184
    185185  /// \ingroup shortest_path
    186186  ///This class provides an efficient implementation of %Dijkstra algorithm.
     
    203203  ///concepts::Digraph::ArcMap "Digraph::ArcMap<int>".  The value
    204204  ///of LM is not used directly by Dijkstra, it is only passed to \ref
    205   ///DijkstraDefaultTraits. 
     205  ///DijkstraDefaultTraits.
    206206  ///\tparam TR Traits class to set
    207207  ///various data types used by the algorithm.  The default traits
     
    215215#else
    216216  template <typename GR=ListDigraph,
    217             typename LM=typename GR::template ArcMap<int>,
    218             typename TR=DijkstraDefaultTraits<GR,LM> >
     217            typename LM=typename GR::template ArcMap<int>,
     218            typename TR=DijkstraDefaultTraits<GR,LM> >
    219219#endif
    220220  class Dijkstra {
     
    229229    public:
    230230      virtual const char* what() const throw() {
    231         return "lemon::Dijkstra::UninitializedParameter";
     231        return "lemon::Dijkstra::UninitializedParameter";
    232232      }
    233233    };
     
    244244    ///\e
    245245    typedef typename Digraph::OutArcIt OutArcIt;
    246    
     246
    247247    ///The type of the length of the arcs.
    248248    typedef typename TR::LengthMap::Value Value;
     
    289289
    290290    ///Creates the maps if necessary.
    291    
     291
    292292    ///\todo Better memory allocation (instead of new).
    293     void create_maps() 
     293    void create_maps()
    294294    {
    295295      if(!_pred) {
    296         local_pred = true;
    297         _pred = Traits::createPredMap(*G);
     296        local_pred = true;
     297        _pred = Traits::createPredMap(*G);
    298298      }
    299299      if(!_dist) {
    300         local_dist = true;
    301         _dist = Traits::createDistMap(*G);
     300        local_dist = true;
     301        _dist = Traits::createDistMap(*G);
    302302      }
    303303      if(!_processed) {
    304         local_processed = true;
    305         _processed = Traits::createProcessedMap(*G);
     304        local_processed = true;
     305        _processed = Traits::createProcessedMap(*G);
    306306      }
    307307      if (!_heap_cross_ref) {
    308         local_heap_cross_ref = true;
    309         _heap_cross_ref = Traits::createHeapCrossRef(*G);
     308        local_heap_cross_ref = true;
     309        _heap_cross_ref = Traits::createHeapCrossRef(*G);
    310310      }
    311311      if (!_heap) {
    312         local_heap = true;
    313         _heap = Traits::createHeap(*_heap_cross_ref);
    314       }
    315     }
    316    
     312        local_heap = true;
     313        _heap = Traits::createHeap(*_heap_cross_ref);
     314      }
     315    }
     316
    317317  public :
    318318
    319319    typedef Dijkstra Create;
    320  
     320
    321321    ///\name Named template parameters
    322322
     
    328328      static PredMap *createPredMap(const Digraph &)
    329329      {
    330         throw UninitializedParameter();
     330        throw UninitializedParameter();
    331331      }
    332332    };
     
    336336    ///
    337337    template <class T>
    338     struct DefPredMap 
    339       : public Dijkstra< Digraph,       LengthMap, DefPredMapTraits<T> > {
    340       typedef Dijkstra< Digraph,        LengthMap, DefPredMapTraits<T> > Create;
    341     };
    342    
     338    struct DefPredMap
     339      : public Dijkstra< Digraph,        LengthMap, DefPredMapTraits<T> > {
     340      typedef Dijkstra< Digraph,        LengthMap, DefPredMapTraits<T> > Create;
     341    };
     342
    343343    template <class T>
    344344    struct DefDistMapTraits : public Traits {
     
    346346      static DistMap *createDistMap(const Digraph &)
    347347      {
    348         throw UninitializedParameter();
     348        throw UninitializedParameter();
    349349      }
    350350    };
     
    354354    ///
    355355    template <class T>
    356     struct DefDistMap 
    357       : public Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > { 
     356    struct DefDistMap
     357      : public Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > {
    358358      typedef Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > Create;
    359359    };
    360    
     360
    361361    template <class T>
    362362    struct DefProcessedMapTraits : public Traits {
    363363      typedef T ProcessedMap;
    364       static ProcessedMap *createProcessedMap(const Digraph &G) 
     364      static ProcessedMap *createProcessedMap(const Digraph &G)
    365365      {
    366         throw UninitializedParameter();
     366        throw UninitializedParameter();
    367367      }
    368368    };
     
    372372    ///
    373373    template <class T>
    374     struct DefProcessedMap 
    375       : public Dijkstra< Digraph,       LengthMap, DefProcessedMapTraits<T> > {
    376       typedef Dijkstra< Digraph,        LengthMap, DefProcessedMapTraits<T> > Create;
    377     };
    378    
     374    struct DefProcessedMap
     375      : public Dijkstra< Digraph,        LengthMap, DefProcessedMapTraits<T> > {
     376      typedef Dijkstra< Digraph,        LengthMap, DefProcessedMapTraits<T> > Create;
     377    };
     378
    379379    struct DefDigraphProcessedMapTraits : public Traits {
    380380      typedef typename Digraph::template NodeMap<bool> ProcessedMap;
    381       static ProcessedMap *createProcessedMap(const Digraph &G) 
     381      static ProcessedMap *createProcessedMap(const Digraph &G)
    382382      {
    383         return new ProcessedMap(G);
     383        return new ProcessedMap(G);
    384384      }
    385385    };
     
    391391    ///If you don't set it explicitely, it will be automatically allocated.
    392392    template <class T>
    393     struct DefProcessedMapToBeDefaultMap 
     393    struct DefProcessedMapToBeDefaultMap
    394394      : public Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> {
    395395      typedef Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> Create;
     
    401401      typedef H Heap;
    402402      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
    403         throw UninitializedParameter();
    404       }
    405       static Heap *createHeap(HeapCrossRef &) 
     403        throw UninitializedParameter();
     404      }
     405      static Heap *createHeap(HeapCrossRef &)
    406406      {
    407         throw UninitializedParameter();
     407        throw UninitializedParameter();
    408408      }
    409409    };
     
    411411    ///heap and cross reference type
    412412    ///
    413     ///\ref named-templ-param "Named parameter" for setting heap and cross 
     413    ///\ref named-templ-param "Named parameter" for setting heap and cross
    414414    ///reference type
    415415    ///
    416416    template <class H, class CR = typename Digraph::template NodeMap<int> >
    417417    struct DefHeap
    418       : public Dijkstra< Digraph,       LengthMap, DefHeapTraits<H, CR> > {
    419       typedef Dijkstra< Digraph,        LengthMap, DefHeapTraits<H, CR> > Create;
     418      : public Dijkstra< Digraph,        LengthMap, DefHeapTraits<H, CR> > {
     419      typedef Dijkstra< Digraph,        LengthMap, DefHeapTraits<H, CR> > Create;
    420420    };
    421421
     
    425425      typedef H Heap;
    426426      static HeapCrossRef *createHeapCrossRef(const Digraph &G) {
    427         return new HeapCrossRef(G);
    428       }
    429       static Heap *createHeap(HeapCrossRef &R) 
     427        return new HeapCrossRef(G);
     428      }
     429      static Heap *createHeap(HeapCrossRef &R)
    430430      {
    431         return new Heap(R);
     431        return new Heap(R);
    432432      }
    433433    };
     
    435435    ///heap and cross reference type with automatic allocation
    436436    ///
    437     ///\ref named-templ-param "Named parameter" for setting heap and cross 
    438     ///reference type. It can allocate the heap and the cross reference 
    439     ///object if the cross reference's constructor waits for the digraph as 
     437    ///\ref named-templ-param "Named parameter" for setting heap and cross
     438    ///reference type. It can allocate the heap and the cross reference
     439    ///object if the cross reference's constructor waits for the digraph as
    440440    ///parameter and the heap's constructor waits for the cross reference.
    441441    template <class H, class CR = typename Digraph::template NodeMap<int> >
    442442    struct DefStandardHeap
    443       : public Dijkstra< Digraph,       LengthMap, DefStandardHeapTraits<H, CR> > {
    444       typedef Dijkstra< Digraph,        LengthMap, DefStandardHeapTraits<H, CR> >
     443      : public Dijkstra< Digraph,        LengthMap, DefStandardHeapTraits<H, CR> > {
     444      typedef Dijkstra< Digraph,        LengthMap, DefStandardHeapTraits<H, CR> >
    445445      Create;
    446446    };
     
    450450      typedef T OperationTraits;
    451451    };
    452    
    453     /// \brief \ref named-templ-param "Named parameter" for setting 
     452
     453    /// \brief \ref named-templ-param "Named parameter" for setting
    454454    /// OperationTraits type
    455455    ///
     
    462462      Create;
    463463    };
    464    
     464
    465465    ///@}
    466466
     
    470470    Dijkstra() {}
    471471
    472   public:     
    473    
     472  public:
     473
    474474    ///Constructor.
    475    
     475
    476476    ///\param _G the digraph the algorithm will run on.
    477477    ///\param _length the length map used by the algorithm.
     
    484484      _heap(NULL), local_heap(false)
    485485    { }
    486    
     486
    487487    ///Destructor.
    488     ~Dijkstra() 
     488    ~Dijkstra()
    489489    {
    490490      if(local_pred) delete _pred;
     
    499499    ///Sets the length map.
    500500    ///\return <tt> (*this) </tt>
    501     Dijkstra &lengthMap(const LengthMap &m) 
     501    Dijkstra &lengthMap(const LengthMap &m)
    502502    {
    503503      length = &m;
     
    512512    ///automatically allocated map, of course.
    513513    ///\return <tt> (*this) </tt>
    514     Dijkstra &predMap(PredMap &m) 
     514    Dijkstra &predMap(PredMap &m)
    515515    {
    516516      if(local_pred) {
    517         delete _pred;
    518         local_pred=false;
     517        delete _pred;
     518        local_pred=false;
    519519      }
    520520      _pred = &m;
     
    529529    ///automatically allocated map, of course.
    530530    ///\return <tt> (*this) </tt>
    531     Dijkstra &distMap(DistMap &m) 
     531    Dijkstra &distMap(DistMap &m)
    532532    {
    533533      if(local_dist) {
    534         delete _dist;
    535         local_dist=false;
     534        delete _dist;
     535        local_dist=false;
    536536      }
    537537      _dist = &m;
     
    549549    {
    550550      if(local_heap_cross_ref) {
    551         delete _heap_cross_ref;
    552         local_heap_cross_ref=false;
     551        delete _heap_cross_ref;
     552        local_heap_cross_ref=false;
    553553      }
    554554      _heap_cross_ref = &cr;
    555555      if(local_heap) {
    556         delete _heap;
    557         local_heap=false;
     556        delete _heap;
     557        local_heap=false;
    558558      }
    559559      _heap = &hp;
     
    593593      _heap->clear();
    594594      for ( NodeIt u(*G) ; u!=INVALID ; ++u ) {
    595         _pred->set(u,INVALID);
    596         _processed->set(u,false);
    597         _heap_cross_ref->set(u,Heap::PRE_HEAP);
    598       }
    599     }
    600    
     595        _pred->set(u,INVALID);
     596        _processed->set(u,false);
     597        _heap_cross_ref->set(u,Heap::PRE_HEAP);
     598      }
     599    }
     600
    601601    ///Adds a new source node.
    602602
     
    611611    {
    612612      if(_heap->state(s) != Heap::IN_HEAP) {
    613         _heap->push(s,dst);
     613        _heap->push(s,dst);
    614614      } else if(OperationTraits::less((*_heap)[s], dst)) {
    615         _heap->set(s,dst);
    616         _pred->set(s,INVALID);
    617       }
    618     }
    619    
     615        _heap->set(s,dst);
     616        _pred->set(s,INVALID);
     617      }
     618    }
     619
    620620    ///Processes the next node in the priority heap
    621621
     
    627627    Node processNextNode()
    628628    {
    629       Node v=_heap->top(); 
     629      Node v=_heap->top();
    630630      Value oldvalue=_heap->prio();
    631631      _heap->pop();
    632632      finalizeNodeData(v,oldvalue);
    633      
     633
    634634      for(OutArcIt e(*G,v); e!=INVALID; ++e) {
    635         Node w=G->target(e);
    636         switch(_heap->state(w)) {
    637         case Heap::PRE_HEAP:
    638           _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e]));
    639           _pred->set(w,e);
    640           break;
    641         case Heap::IN_HEAP:
    642           {
    643             Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]);
    644             if ( OperationTraits::less(newvalue, (*_heap)[w]) ) {
    645               _heap->decrease(w, newvalue);
    646               _pred->set(w,e);
    647             }
    648           }
    649           break;
    650         case Heap::POST_HEAP:
    651           break;
    652         }
     635        Node w=G->target(e);
     636        switch(_heap->state(w)) {
     637        case Heap::PRE_HEAP:
     638          _heap->push(w,OperationTraits::plus(oldvalue, (*length)[e]));
     639          _pred->set(w,e);
     640          break;
     641        case Heap::IN_HEAP:
     642          {
     643            Value newvalue = OperationTraits::plus(oldvalue, (*length)[e]);
     644            if ( OperationTraits::less(newvalue, (*_heap)[w]) ) {
     645              _heap->decrease(w, newvalue);
     646              _pred->set(w,e);
     647            }
     648          }
     649          break;
     650        case Heap::POST_HEAP:
     651          break;
     652        }
    653653      }
    654654      return v;
     
    656656
    657657    ///Next node to be processed.
    658    
     658
    659659    ///Next node to be processed.
    660660    ///
     
    662662    /// is empty.
    663663    Node nextNode()
    664     { 
     664    {
    665665      return !_heap->empty()?_heap->top():INVALID;
    666666    }
    667  
     667
    668668    ///\brief Returns \c false if there are nodes
    669669    ///to be processed in the priority heap
     
    677677    ///
    678678    int queueSize() { return _heap->size(); }
    679    
     679
    680680    ///Executes the algorithm.
    681681
     
    696696      while ( !_heap->empty() ) processNextNode();
    697697    }
    698    
     698
    699699    ///Executes the algorithm until \c dest is reached.
    700700
     
    716716      if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
    717717    }
    718    
     718
    719719    ///Executes the algorithm until a condition is met.
    720720
     
    737737      return _heap->top();
    738738    }
    739    
     739
    740740    ///Runs %Dijkstra algorithm from node \c s.
    741    
     741
    742742    ///This method runs the %Dijkstra algorithm from a root node \c s
    743743    ///in order to
     
    758758      start();
    759759    }
    760    
     760
    761761    ///Finds the shortest path between \c s and \c t.
    762    
     762
    763763    ///Finds the shortest path between \c s and \c t.
    764764    ///
     
    778778      return (*_pred)[t]==INVALID?OperationTraits::zero():(*_dist)[t];
    779779    }
    780    
     780
    781781    ///@}
    782782
     
    786786    ///Before the use of these functions,
    787787    ///either run() or start() must be called.
    788    
     788
    789789    ///@{
    790790
    791791    ///Gives back the shortest path.
    792    
     792
    793793    ///Gives back the shortest path.
    794794    ///\pre The \c t should be reachable from the source.
    795     Path path(Node t) 
     795    Path path(Node t)
    796796    {
    797797      return Path(*G, *_pred, t);
     
    833833    ///using this function.
    834834    Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
    835                                   G->source((*_pred)[v]); }
    836    
     835                                  G->source((*_pred)[v]); }
     836
    837837    ///Returns a reference to the NodeMap of distances.
    838838
     
    840840    ///be called before using this function.
    841841    const DistMap &distMap() const { return *_dist;}
    842  
     842
    843843    ///Returns a reference to the shortest path tree map.
    844844
     
    847847    ///\pre \ref run() must be called before using this function.
    848848    const PredMap &predMap() const { return *_pred;}
    849  
     849
    850850    ///Checks if a node is reachable from the root.
    851851
     
    863863    ///
    864864    bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
    865    
     865
    866866    ///@}
    867867  };
     
    870870
    871871
    872  
     872
    873873  ///Default traits class of Dijkstra function.
    874874
     
    879879  struct DijkstraWizardDefaultTraits
    880880  {
    881     ///The digraph type the algorithm runs on. 
     881    ///The digraph type the algorithm runs on.
    882882    typedef GR Digraph;
    883883    ///The type of the map that stores the arc lengths.
     
    902902    ///Instantiates a HeapCrossRef.
    903903
    904     ///This function instantiates a \ref HeapCrossRef. 
    905     /// \param G is the digraph, to which we would like to define the 
     904    ///This function instantiates a \ref HeapCrossRef.
     905    /// \param G is the digraph, to which we would like to define the
    906906    /// HeapCrossRef.
    907907    /// \todo The digraph alone may be insufficient for the initialization
    908     static HeapCrossRef *createHeapCrossRef(const GR &G) 
     908    static HeapCrossRef *createHeapCrossRef(const GR &G)
    909909    {
    910910      return new HeapCrossRef(G);
    911911    }
    912    
     912
    913913    ///The heap type used by Dijkstra algorithm.
    914914
     
    918918    ///\sa Dijkstra
    919919    typedef BinHeap<typename LM::Value, typename GR::template NodeMap<int>,
    920                     std::less<Value> > Heap;
    921 
    922     static Heap *createHeap(HeapCrossRef& R) 
     920                    std::less<Value> > Heap;
     921
     922    static Heap *createHeap(HeapCrossRef& R)
    923923    {
    924924      return new Heap(R);
     
    927927    ///\brief The type of the map that stores the last
    928928    ///arcs of the shortest paths.
    929     /// 
     929    ///
    930930    ///The type of the map that stores the last
    931931    ///arcs of the shortest paths.
     
    934934    typedef NullMap <typename GR::Node,typename GR::Arc> PredMap;
    935935    ///Instantiates a PredMap.
    936  
    937     ///This function instantiates a \ref PredMap. 
     936
     937    ///This function instantiates a \ref PredMap.
    938938    ///\param g is the digraph, to which we would like to define the PredMap.
    939939    ///\todo The digraph alone may be insufficient for the initialization
    940940#ifdef DOXYGEN
    941     static PredMap *createPredMap(const GR &g) 
     941    static PredMap *createPredMap(const GR &g)
    942942#else
    943     static PredMap *createPredMap(const GR &) 
     943    static PredMap *createPredMap(const GR &)
    944944#endif
    945945    {
     
    947947    }
    948948    ///The type of the map that stores whether a nodes is processed.
    949  
     949
    950950    ///The type of the map that stores whether a nodes is processed.
    951951    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    956956    typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
    957957    ///Instantiates a ProcessedMap.
    958  
    959     ///This function instantiates a \ref ProcessedMap. 
     958
     959    ///This function instantiates a \ref ProcessedMap.
    960960    ///\param g is the digraph, to which
    961961    ///we would like to define the \ref ProcessedMap
     
    969969    }
    970970    ///The type of the map that stores the dists of the nodes.
    971  
     971
    972972    ///The type of the map that stores the dists of the nodes.
    973973    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
     
    975975    typedef NullMap<typename Digraph::Node,typename LM::Value> DistMap;
    976976    ///Instantiates a DistMap.
    977  
    978     ///This function instantiates a \ref DistMap. 
     977
     978    ///This function instantiates a \ref DistMap.
    979979    ///\param g is the digraph, to which we would like to define the \ref DistMap
    980980#ifdef DOXYGEN
     
    987987    }
    988988  };
    989  
     989
    990990  /// Default traits used by \ref DijkstraWizard
    991991
     
    10191019    public:
    10201020    /// Constructor.
    1021    
     1021
    10221022    /// This constructor does not require parameters, therefore it initiates
    10231023    /// all of the attributes to default values (0, INVALID).
    10241024    DijkstraWizardBase() : _g(0), _length(0), _pred(0),
    1025                            _dist(0), _source(INVALID) {}
     1025                           _dist(0), _source(INVALID) {}
    10261026
    10271027    /// Constructor.
    1028    
     1028
    10291029    /// This constructor requires some parameters,
    10301030    /// listed in the parameters list.
     
    10341034    /// \param s is the initial value of  \ref _source
    10351035    DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) :
    1036       _g(reinterpret_cast<void*>(const_cast<GR*>(&g))), 
    1037       _length(reinterpret_cast<void*>(const_cast<LM*>(&l))), 
     1036      _g(reinterpret_cast<void*>(const_cast<GR*>(&g))),
     1037      _length(reinterpret_cast<void*>(const_cast<LM*>(&l))),
    10381038      _pred(0), _dist(0), _source(s) {}
    10391039
    10401040  };
    1041  
     1041
    10421042  /// A class to make the usage of Dijkstra algorithm easier
    10431043
     
    10571057  ///
    10581058  /// It does not have own \ref run method. When its \ref run method is called
    1059   /// it initiates a plain \ref Dijkstra class, and calls the \ref 
     1059  /// it initiates a plain \ref Dijkstra class, and calls the \ref
    10601060  /// Dijkstra::run method of it.
    10611061  template<class TR>
     
    10741074    //\e
    10751075    typedef typename Digraph::OutArcIt OutArcIt;
    1076    
     1076
    10771077    ///The type of the map that stores the arc lengths.
    10781078    typedef typename TR::LengthMap LengthMap;
     
    11031103
    11041104    ///Runs Dijkstra algorithm from a given node.
    1105    
     1105
    11061106    ///Runs Dijkstra algorithm from a given node.
    11071107    ///The node can be given by the \ref source function.
     
    11091109    {
    11101110      if(Base::_source==INVALID) throw UninitializedParameter();
    1111       Dijkstra<Digraph,LengthMap,TR> 
    1112         dij(*reinterpret_cast<const Digraph*>(Base::_g),
     1111      Dijkstra<Digraph,LengthMap,TR>
     1112        dij(*reinterpret_cast<const Digraph*>(Base::_g),
    11131113            *reinterpret_cast<const LengthMap*>(Base::_length));
    11141114      if(Base::_pred) dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
     
    11331133      DefPredMapBase(const TR &b) : TR(b) {}
    11341134    };
    1135    
     1135
    11361136    ///\brief \ref named-templ-param "Named parameter"
    11371137    ///function for setting PredMap type
     
    11411141    ///
    11421142    template<class T>
    1143     DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) 
     1143    DijkstraWizard<DefPredMapBase<T> > predMap(const T &t)
    11441144    {
    11451145      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
    11461146      return DijkstraWizard<DefPredMapBase<T> >(*this);
    11471147    }
    1148    
     1148
    11491149    template<class T>
    11501150    struct DefDistMapBase : public Base {
     
    11531153      DefDistMapBase(const TR &b) : TR(b) {}
    11541154    };
    1155    
     1155
    11561156    ///\brief \ref named-templ-param "Named parameter"
    11571157    ///function for setting DistMap type
     
    11611161    ///
    11621162    template<class T>
    1163     DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) 
     1163    DijkstraWizard<DefDistMapBase<T> > distMap(const T &t)
    11641164    {
    11651165      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
    11661166      return DijkstraWizard<DefDistMapBase<T> >(*this);
    11671167    }
    1168    
     1168
    11691169    /// Sets the source node, from which the Dijkstra algorithm runs.
    11701170
    11711171    /// Sets the source node, from which the Dijkstra algorithm runs.
    11721172    /// \param s is the source node.
    1173     DijkstraWizard<TR> &source(Node s) 
     1173    DijkstraWizard<TR> &source(Node s)
    11741174    {
    11751175      Base::_source=s;
    11761176      return *this;
    11771177    }
    1178    
     1178
    11791179  };
    1180  
     1180
    11811181  ///Function type interface for Dijkstra algorithm.
    11821182
  • lemon/dim2.h

    r49 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2525///\ingroup misc
    2626///\file
    27 ///\brief A simple two dimensional vector and a bounding box implementation 
     27///\brief A simple two dimensional vector and a bounding box implementation
    2828///
    2929/// The class \ref lemon::dim2::Point "dim2::Point" implements
     
    6060      T x;
    6161      ///Second coordinate
    62       T y;     
    63      
     62      T y;
     63
    6464      ///Default constructor
    6565      Point() {}
     
    7171
    7272      ///The dimension of the vector.
    73       ///This function always returns 2. 
     73      ///This function always returns 2.
    7474      int size() const { return 2; }
    7575
     
    9393        return x*x+y*y;
    9494      }
    95  
     95
    9696      ///Increment the left hand side by \c u
    9797      Point<T>& operator +=(const Point<T>& u) {
     
    100100        return *this;
    101101      }
    102  
     102
    103103      ///Decrement the left hand side by \c u
    104104      Point<T>& operator -=(const Point<T>& u) {
     
    121121        return *this;
    122122      }
    123  
     123
    124124      ///Return the scalar product of two vectors
    125125      T operator *(const Point<T>& u) const {
    126126        return x*u.x+y*u.y;
    127127      }
    128  
     128
    129129      ///Return the sum of two vectors
    130130      Point<T> operator+(const Point<T> &u) const {
     
    170170    };
    171171
    172   ///Return a Point 
     172  ///Return a Point
    173173
    174174  ///Return a Point.
     
    260260  }
    261261
    262  
     262
    263263
    264264  /// A class to calculate or store the bounding box of plainvectors.
     
    271271      bool _empty;
    272272    public:
    273      
     273
    274274      ///Default constructor: creates an empty bounding box
    275275      BoundingBox() { _empty = true; }
     
    277277      ///Construct an instance from one point
    278278      BoundingBox(Point<T> a) { bottom_left=top_right=a; _empty = false; }
    279      
     279
    280280      ///Construct an instance from two points
    281      
     281
    282282      ///Construct an instance from two points.
    283283      ///\param a The bottom left corner.
     
    287287      BoundingBox(Point<T> a,Point<T> b)
    288288      {
    289         bottom_left=a;
    290         top_right=b;
    291         _empty = false;
    292       }
    293      
     289        bottom_left=a;
     290        top_right=b;
     291        _empty = false;
     292      }
     293
    294294      ///Construct an instance from four numbers
    295295
     
    300300      ///\param t The top of the box.
    301301      ///\warning The left side must be no more than the right side and
    302       ///bottom must be no more than the top. 
     302      ///bottom must be no more than the top.
    303303      BoundingBox(T l,T b,T r,T t)
    304304      {
    305         bottom_left=Point<T>(l,b);
    306         top_right=Point<T>(r,t);
    307         _empty = false;
    308       }
    309      
     305        bottom_left=Point<T>(l,b);
     306        top_right=Point<T>(r,t);
     307        _empty = false;
     308      }
     309
    310310      ///Return \c true if the bounding box is empty.
    311      
     311
    312312      ///Return \c true if the bounding box is empty (i.e. return \c false
    313313      ///if at least one point was added to the box or the coordinates of
    314314      ///the box were set).
    315315      ///
    316       ///The coordinates of an empty bounding box are not defined. 
     316      ///The coordinates of an empty bounding box are not defined.
    317317      bool empty() const {
    318318        return _empty;
    319319      }
    320      
     320
    321321      ///Make the BoundingBox empty
    322322      void clear() {
     
    337337      ///It should only be used for non-empty box.
    338338      void bottomLeft(Point<T> p) {
    339         bottom_left = p;
     339        bottom_left = p;
    340340      }
    341341
     
    353353      ///It should only be used for non-empty box.
    354354      void topRight(Point<T> p) {
    355         top_right = p;
     355        top_right = p;
    356356      }
    357357
     
    369369      ///It should only be used for non-empty box.
    370370      void bottomRight(Point<T> p) {
    371         top_right.x = p.x;
    372         bottom_left.y = p.y;
    373       }
    374  
     371        top_right.x = p.x;
     372        bottom_left.y = p.y;
     373      }
     374
    375375      ///Give back the top left corner of the box
    376376
     
    386386      ///It should only be used for non-empty box.
    387387      void topLeft(Point<T> p) {
    388         top_right.y = p.y;
    389         bottom_left.x = p.x;
     388        top_right.y = p.y;
     389        bottom_left.x = p.x;
    390390      }
    391391
     
    403403      ///It should only be used for non-empty box.
    404404      void bottom(T t) {
    405         bottom_left.y = t;
     405        bottom_left.y = t;
    406406      }
    407407
     
    419419      ///It should only be used for non-empty box.
    420420      void top(T t) {
    421         top_right.y = t;
     421        top_right.y = t;
    422422      }
    423423
     
    429429        return bottom_left.x;
    430430      }
    431  
     431
    432432      ///Set the left side of the box
    433433
     
    435435      ///It should only be used for non-empty box.
    436436      void left(T t) {
    437         bottom_left.x = t;
     437        bottom_left.x = t;
    438438      }
    439439
     
    451451      ///It should only be used for non-empty box.
    452452      void right(T t) {
    453         top_right.x = t;
     453        top_right.x = t;
    454454      }
    455455
     
    479479        }
    480480      }
    481  
     481
    482482      ///Increments a bounding box with a point
    483483
     
    497497        return *this;
    498498      }
    499    
     499
    500500      ///Increments a bounding box to contain another bounding box
    501      
     501
    502502      ///Increments a bounding box to contain another bounding box.
    503503      ///
     
    505505        if ( !u.empty() ){
    506506          this->add(u.bottomLeft());
    507           this->add(u.topRight());
     507          this->add(u.topRight());
    508508        }
    509509        return *this;
    510510      }
    511  
     511
    512512      ///Intersection of two bounding boxes
    513513
     
    517517        BoundingBox b;
    518518        if (this->_empty || u._empty) {
    519           b._empty = true;
    520         } else {
    521           b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
    522           b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
    523           b.top_right.x = std::min(this->top_right.x,u.top_right.x);
    524           b.top_right.y = std::min(this->top_right.y,u.top_right.y);
    525           b._empty = b.bottom_left.x > b.top_right.x ||
    526                      b.bottom_left.y > b.top_right.y;
    527         }
     519          b._empty = true;
     520        } else {
     521          b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
     522          b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
     523          b.top_right.x = std::min(this->top_right.x,u.top_right.x);
     524          b.top_right.y = std::min(this->top_right.y,u.top_right.y);
     525          b._empty = b.bottom_left.x > b.top_right.x ||
     526                     b.bottom_left.y > b.top_right.y;
     527        }
    528528        return b;
    529529      }
     
    538538  ///
    539539  template<class M>
    540   class XMap 
     540  class XMap
    541541  {
    542542    M& _map;
     
    550550    void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
    551551  };
    552    
     552
    553553  ///Returns an \ref XMap class
    554554
     
    557557  ///\ingroup maps
    558558  ///\relates XMap
    559   template<class M> 
    560   inline XMap<M> xMap(M &m) 
     559  template<class M>
     560  inline XMap<M> xMap(M &m)
    561561  {
    562562    return XMap<M>(m);
    563563  }
    564564
    565   template<class M> 
    566   inline XMap<M> xMap(const M &m) 
     565  template<class M>
     566  inline XMap<M> xMap(const M &m)
    567567  {
    568568    return XMap<M>(m);
     
    575575  ///
    576576  template<class M>
    577   class ConstXMap 
     577  class ConstXMap
    578578  {
    579579    const M& _map;
     
    586586    Value operator[](Key k) const {return _map[k].x;}
    587587  };
    588    
     588
    589589  ///Returns a \ref ConstXMap class
    590590
     
    593593  ///\ingroup maps
    594594  ///\relates ConstXMap
    595   template<class M> 
    596   inline ConstXMap<M> xMap(const M &m) 
     595  template<class M>
     596  inline ConstXMap<M> xMap(const M &m)
    597597  {
    598598    return ConstXMap<M>(m);
     
    600600
    601601  ///Map of y-coordinates of a \ref Point "Point"-map
    602    
     602
    603603  ///\ingroup maps
    604604  ///Map of y-coordinates of a \ref Point "Point"-map.
    605605  ///
    606606  template<class M>
    607   class YMap 
     607  class YMap
    608608  {
    609609    M& _map;
     
    624624  ///\ingroup maps
    625625  ///\relates YMap
    626   template<class M> 
    627   inline YMap<M> yMap(M &m) 
     626  template<class M>
     627  inline YMap<M> yMap(M &m)
    628628  {
    629629    return YMap<M>(m);
    630630  }
    631631
    632   template<class M> 
    633   inline YMap<M> yMap(const M &m) 
     632  template<class M>
     633  inline YMap<M> yMap(const M &m)
    634634  {
    635635    return YMap<M>(m);
     
    642642  ///
    643643  template<class M>
    644   class ConstYMap 
     644  class ConstYMap
    645645  {
    646646    const M& _map;
     
    653653    Value operator[](Key k) const {return _map[k].y;}
    654654  };
    655    
     655
    656656  ///Returns a \ref ConstYMap class
    657657
     
    660660  ///\ingroup maps
    661661  ///\relates ConstYMap
    662   template<class M> 
    663   inline ConstYMap<M> yMap(const M &m) 
     662  template<class M>
     663  inline ConstYMap<M> yMap(const M &m)
    664664  {
    665665    return ConstYMap<M>(m);
     
    674674  ///\ingroup maps
    675675  template<class M>
    676   class NormSquareMap 
     676  class NormSquareMap
    677677  {
    678678    const M& _map;
     
    685685    Value operator[](Key k) const {return _map[k].normSquare();}
    686686  };
    687    
     687
    688688  ///Returns a \ref NormSquareMap class
    689689
     
    692692  ///\ingroup maps
    693693  ///\relates NormSquareMap
    694   template<class M> 
    695   inline NormSquareMap<M> normSquareMap(const M &m) 
     694  template<class M>
     695  inline NormSquareMap<M> normSquareMap(const M &m)
    696696  {
    697697    return NormSquareMap<M>(m);
     
    701701
    702702  } //namespce dim2
    703  
     703
    704704} //namespace lemon
    705705
  • lemon/error.h

    r108 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4646    ExceptionMember() throw() {
    4747      try {
    48         ptr.reset(new Type());
     48        ptr.reset(new Type());
    4949      } catch (...) {}
    5050    }
     
    5252    ExceptionMember(const Type& type) throw() {
    5353      try {
    54         ptr.reset(new Type());
    55         if (ptr.get() == 0) return;
    56         *ptr = type;
     54        ptr.reset(new Type());
     55        if (ptr.get() == 0) return;
     56        *ptr = type;
    5757      } catch (...) {}
    5858    }
     
    6060    ExceptionMember(const ExceptionMember& copy) throw() {
    6161      try {
    62         if (!copy.valid()) return;
    63         ptr.reset(new Type());
    64         if (ptr.get() == 0) return;
    65         *ptr = copy.get();
     62        if (!copy.valid()) return;
     63        ptr.reset(new Type());
     64        if (ptr.get() == 0) return;
     65        *ptr = copy.get();
    6666      } catch (...) {}
    6767    }
     
    7070      if (ptr.get() == 0) return;
    7171      try {
    72         if (!copy.valid()) return;
    73         *ptr = copy.get();
     72        if (!copy.valid()) return;
     73         *ptr = copy.get();
    7474      } catch (...) {}
    7575    }
     
    7878      if (ptr.get() == 0) return;
    7979      try {
    80         *ptr = type;
     80        *ptr = type;
    8181      } catch (...) {}
    8282    }
     
    110110    bool init() throw() {
    111111      try {
    112         buf.reset(new std::ostringstream);
     112        buf.reset(new std::ostringstream);
    113113      }
    114114      catch(...) {
    115         buf.reset();
     115        buf.reset();
    116116      }
    117117      return buf.get();
     
    143143
    144144      try {
    145         *buf << t;
     145        *buf << t;
    146146      }
    147147      catch(...) {
    148         buf.reset();
     148        buf.reset();
    149149      }
    150150      return *this;
     
    157157      const char* mes = 0;
    158158      try {
    159         mes = buf->str().c_str();
     159        mes = buf->str().c_str();
    160160      }
    161161      catch(...) {}
     
    255255    ///\e
    256256    DataFormatError(const std::string &file_name, int line_num,
    257                     const char *the_message)
     257                    const char *the_message)
    258258      : _message(the_message), _line(line_num) { file(file_name); }
    259259
     
    270270    const char* message() const {
    271271      if (_message.valid() && !_message.get().empty()) {
    272         return _message.get().c_str();
     272        return _message.get().c_str();
    273273      } else {
    274         return 0;
     274        return 0;
    275275      }
    276276    }
     
    281281    const char* file() const {
    282282      if (_file.valid() && !_file.get().empty()) {
    283         return _file.get().c_str();
     283        return _file.get().c_str();
    284284      } else {
    285         return 0;
    286       }
    287     }
    288 
    289     ///\e
    290     virtual const char* what() const throw() {
    291       try {
    292         std::ostringstream ostr;
    293         ostr << "lemon:DataFormatError" << ": ";
    294         if (message()) ostr << message();
    295         if( file() || line() != 0 ) {
    296           ostr << " (";
    297           if( file() ) ostr << "in file '" << file() << "'";
    298           if( file() && line() != 0 ) ostr << " ";
    299           if( line() != 0 ) ostr << "at line " << line();
    300           ostr << ")";
    301         }
    302         _message_holder.set(ostr.str());
     285        return 0;
     286      }
     287    }
     288
     289    ///\e
     290    virtual const char* what() const throw() {
     291      try {
     292        std::ostringstream ostr;
     293        ostr << "lemon:DataFormatError" << ": ";
     294        if (message()) ostr << message();
     295        if( file() || line() != 0 ) {
     296          ostr << " (";
     297          if( file() ) ostr << "in file '" << file() << "'";
     298          if( file() && line() != 0 ) ostr << " ";
     299          if( line() != 0 ) ostr << "at line " << line();
     300          ostr << ")";
     301        }
     302        _message_holder.set(ostr.str());
    303303      }
    304304      catch (...) {}
     
    334334    const char* file() const {
    335335      if (_file.valid() && !_file.get().empty()) {
    336         return _file.get().c_str();
     336        return _file.get().c_str();
    337337      } else {
    338         return 0;
    339       }
    340     }
    341 
    342     ///\e
    343     virtual const char* what() const throw() {
    344       try {
    345         std::ostringstream ostr;
    346         ostr << "lemon::FileOpenError" << ": ";
    347         ostr << "Cannot open file - " << file();
    348         _message_holder.set(ostr.str());
     338        return 0;
     339      }
     340    }
     341
     342    ///\e
     343    virtual const char* what() const throw() {
     344      try {
     345        std::ostringstream ostr;
     346        ostr << "lemon::FileOpenError" << ": ";
     347        ostr << "Cannot open file - " << file();
     348        _message_holder.set(ostr.str());
    349349      }
    350350      catch (...) {}
     
    382382    const char* message() const {
    383383      if (_message.valid()) {
    384         return _message.get().c_str();
     384        return _message.get().c_str();
    385385      } else {
    386         return 0;
     386        return 0;
    387387      }
    388388    }
     
    393393    const char* file() const {
    394394      if (_file.valid()) {
    395         return _file.get().c_str();
     395        return _file.get().c_str();
    396396      } else {
    397         return 0;
    398       }
    399     }
    400 
    401     ///\e
    402     virtual const char* what() const throw() {
    403       try {
    404         std::ostringstream ostr;
    405         if (message()) ostr << message();
    406         if (file()) ostr << "(when reading file '" << file() << "')";
    407         _message_holder.set(ostr.str());
     397        return 0;
     398      }
     399    }
     400
     401    ///\e
     402    virtual const char* what() const throw() {
     403      try {
     404        std::ostringstream ostr;
     405        if (message()) ostr << message();
     406        if (file()) ostr << "(when reading file '" << file() << "')";
     407        _message_holder.set(ostr.str());
    408408      }
    409409      catch (...) {}
  • lemon/graph_to_eps.h

    r206 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6161    };
    6262  }
    63  
     63
    6464///Default traits class of \ref GraphToEps
    6565
     
    7777  typedef typename Graph::InArcIt InArcIt;
    7878  typedef typename Graph::OutArcIt OutArcIt;
    79  
     79
    8080
    8181  const Graph &g;
    8282
    8383  std::ostream& os;
    84  
     84
    8585  typedef ConstMap<typename Graph::Node,dim2::Point<double> > CoordsMapType;
    8686  CoordsMapType _coords;
     
    9494
    9595  double _arcWidthScale;
    96  
     96
    9797  double _nodeScale;
    9898  double _xBorder, _yBorder;
    9999  double _scale;
    100100  double _nodeBorderQuotient;
    101  
     101
    102102  bool _drawArrows;
    103103  double _arrowLength, _arrowWidth;
    104  
     104
    105105  bool _showNodes, _showArcs;
    106106
     
    109109
    110110  bool _showNodeText;
    111   ConstMap<typename Graph::Node,bool > _nodeTexts; 
     111  ConstMap<typename Graph::Node,bool > _nodeTexts;
    112112  double _nodeTextSize;
    113113
    114114  bool _showNodePsText;
    115   ConstMap<typename Graph::Node,bool > _nodePsTexts; 
     115  ConstMap<typename Graph::Node,bool > _nodePsTexts;
    116116  char *_nodePsTextsPreamble;
    117  
     117
    118118  bool _undirected;
    119119
     
    125125  std::string _copyright;
    126126
    127   enum NodeTextColorType 
     127  enum NodeTextColorType
    128128    { DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType;
    129129  ConstMap<typename Graph::Node,Color > _nodeTextColors;
     
    147147  ///will be explicitly deallocated by the destructor.
    148148  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
    149                           bool _pros=false) :
     149                          bool _pros=false) :
    150150    g(_g), os(_os),
    151151    _coords(dim2::Point<double>(1,1)), _nodeSizes(1), _nodeShapes(0),
     
    176176///
    177177///For detailed examples see the \ref graph_to_eps_demo.cc demo file.
    178 template<class T> class GraphToEps : public T 
     178template<class T> class GraphToEps : public T
    179179{
    180180  // Can't believe it is required by the C++ standard
     
    195195  using T::_scale;
    196196  using T::_nodeBorderQuotient;
    197  
     197
    198198  using T::_drawArrows;
    199199  using T::_arrowLength;
    200200  using T::_arrowWidth;
    201  
     201
    202202  using T::_showNodes;
    203203  using T::_showArcs;
     
    207207
    208208  using T::_showNodeText;
    209   using T::_nodeTexts; 
     209  using T::_nodeTexts;
    210210  using T::_nodeTextSize;
    211211
    212212  using T::_showNodePsText;
    213   using T::_nodePsTexts; 
     213  using T::_nodePsTexts;
    214214  using T::_nodePsTextsPreamble;
    215  
     215
    216216  using T::_undirected;
    217217
     
    262262  ///Node shapes.
    263263  ///
    264   enum NodeShapes { 
     264  enum NodeShapes {
    265265    /// = 0
    266266    ///\image html nodeshape_0.png
    267267    ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
    268     CIRCLE=0, 
     268    CIRCLE=0,
    269269    /// = 1
    270270    ///\image html nodeshape_1.png
    271271    ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
    272272    ///
    273     SQUARE=1, 
     273    SQUARE=1,
    274274    /// = 2
    275275    ///\image html nodeshape_2.png
     
    294294  public:
    295295    arcLess(const Graph &_g) : g(_g) {}
    296     bool operator()(Arc a,Arc b) const 
     296    bool operator()(Arc a,Arc b) const
    297297    {
    298298      Node ai=std::min(g.source(a),g.target(a));
     
    301301      Node ba=std::max(g.source(b),g.target(b));
    302302      return ai<bi ||
    303         (ai==bi && (aa < ba ||
    304                     (aa==ba && ai==g.source(a) && bi==g.target(b))));
     303        (ai==bi && (aa < ba ||
     304                    (aa==ba && ai==g.source(a) && bi==g.target(b))));
    305305    }
    306306  };
     
    308308  {
    309309    return (g.source(e)==g.source(f)&&
    310             g.target(e)==g.target(f)) ||
     310            g.target(e)==g.target(f)) ||
    311311      (g.source(e)==g.target(f)&&
    312312       g.target(e)==g.source(f));
    313313  }
    314314  template<class TT>
    315   static std::string psOut(const dim2::Point<TT> &p) 
     315  static std::string psOut(const dim2::Point<TT> &p)
    316316    {
    317       std::ostringstream os;   
     317      std::ostringstream os;
    318318      os << p.x << ' ' << p.y;
    319319      return os.str();
    320320    }
    321   static std::string psOut(const Color &c) 
     321  static std::string psOut(const Color &c)
    322322    {
    323       std::ostringstream os;   
     323      std::ostringstream os;
    324324      os << c.red() << ' ' << c.green() << ' ' << c.blue();
    325325      return os.str();
    326326    }
    327  
     327
    328328public:
    329329  GraphToEps(const T &t) : T(t), dontPrint(false) {};
    330  
     330
    331331  template<class X> struct CoordsTraits : public T {
    332332  typedef X CoordsMapType;
     
    338338  ///Sets the map of the node coordinates.
    339339  ///\param x must be a node map with \ref dim2::Point "dim2::Point<double>" or
    340   ///\ref dim2::Point "dim2::Point<int>" values. 
     340  ///\ref dim2::Point "dim2::Point<int>" values.
    341341  template<class X> GraphToEps<CoordsTraits<X> > coords(const X &x) {
    342342    dontPrint=true;
     
    350350
    351351  ///Sets the map of the node sizes.
    352   ///\param x must be a node map with \c double (or convertible) values. 
     352  ///\param x must be a node map with \c double (or convertible) values.
    353353  template<class X> GraphToEps<NodeSizesTraits<X> > nodeSizes(const X &x)
    354354  {
     
    365365  ///The available shape values
    366366  ///can be found in \ref NodeShapes "enum NodeShapes".
    367   ///\param x must be a node map with \c int (or convertible) values. 
     367  ///\param x must be a node map with \c int (or convertible) values.
    368368  ///\sa NodeShapes
    369369  template<class X> GraphToEps<NodeShapesTraits<X> > nodeShapes(const X &x)
     
    380380  ///Sets the text printed on the nodes.
    381381  ///\param x must be a node map with type that can be pushed to a standard
    382   ///\c ostream. 
     382  ///\c ostream.
    383383  template<class X> GraphToEps<NodeTextsTraits<X> > nodeTexts(const X &x)
    384384  {
     
    418418
    419419  ///Sets the map of the arc widths.
    420   ///\param x must be an arc map with \c double (or convertible) values. 
     420  ///\param x must be an arc map with \c double (or convertible) values.
    421421  template<class X> GraphToEps<ArcWidthsTraits<X> > arcWidths(const X &x)
    422422  {
     
    448448
    449449  ///Sets the map of the node text colors.
    450   ///\param x must be a node map with \ref Color values. 
     450  ///\param x must be a node map with \ref Color values.
    451451  ///
    452452  ///\sa Palette
     
    466466
    467467  ///Sets the map of the arc colors.
    468   ///\param x must be an arc map with \ref Color values. 
     468  ///\param x must be an arc map with \ref Color values.
    469469  ///
    470470  ///\sa Palette
     
    478478
    479479  ///Sets a global scale factor for node sizes.
    480   /// 
     480  ///
    481481  /// If nodeSizes() is not given, this function simply sets the node
    482482  /// sizes to \c d.  If nodeSizes() is given, but
     
    569569  ///Sets the width of the arrowheads
    570570  GraphToEps<T> &arrowWidth(double d=.3) {_arrowWidth*=d;return *this;}
    571  
     571
    572572  ///Scales the drawing to fit to A4 page
    573573  GraphToEps<T> &scaleToA4() {_scaleToA4=true;return *this;}
    574  
     574
    575575  ///Enables parallel arcs
    576576  GraphToEps<T> &enableParallel(bool b=true) {_enableParallel=b;return *this;}
    577  
     577
    578578  ///Sets the distance between parallel arcs
    579579  GraphToEps<T> &parArcDist(double d) {_parArcDist*=d;return *this;}
    580  
     580
    581581  ///Hides the arcs
    582582  GraphToEps<T> &hideArcs(bool b=true) {_showArcs=!b;return *this;}
    583583  ///Hides the nodes
    584584  GraphToEps<T> &hideNodes(bool b=true) {_showNodes=!b;return *this;}
    585  
     585
    586586  ///Sets the size of the node texts
    587587  GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
     
    601601
    602602  ///Gives a preamble block for node Postscript block.
    603  
     603
    604604  ///Gives a preamble block for node Postscript block.
    605605  ///
     
    626626  ///\sa undirected()
    627627  GraphToEps<T> &directed(bool b=true) {_undirected=!b;return *this;}
    628  
     628
    629629  ///Sets the title.
    630630
     
    641641
    642642protected:
    643   bool isInsideNode(dim2::Point<double> p, double r,int t) 
     643  bool isInsideNode(dim2::Point<double> p, double r,int t)
    644644  {
    645645    switch(t) {
     
    658658public:
    659659  ~GraphToEps() { }
    660  
     660
    661661  ///Draws the graph.
    662662
     
    669669    const double EPSILON=1e-9;
    670670    if(dontPrint) return;
    671    
     671
    672672    _graph_to_eps_bits::_NegY<typename T::CoordsMapType>
    673673      mycoords(_coords,_negY);
     
    678678    os << "%%Creator: LEMON, graphToEps()\n";
    679679
    680     {   
    681 #ifndef WIN32 
     680    {
     681#ifndef WIN32
    682682      timeval tv;
    683683      gettimeofday(&tv, 0);
     
    689689      SYSTEMTIME time;
    690690      char buf1[11], buf2[9], buf3[5];
    691      
     691
    692692      GetSystemTime(&time);
    693       if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 
    694                         "ddd MMM dd", buf1, 11) &&
    695           GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
    696                         "HH':'mm':'ss", buf2, 9) &&
    697           GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
    698                                 "yyyy", buf3, 5)) {
    699         os << "%%CreationDate: " << buf1 << ' '
    700            << buf2 << ' ' << buf3 << std::endl;
    701       }   
     693      if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     694                        "ddd MMM dd", buf1, 11) &&
     695          GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
     696                        "HH':'mm':'ss", buf2, 9) &&
     697          GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     698                                "yyyy", buf3, 5)) {
     699        os << "%%CreationDate: " << buf1 << ' '
     700           << buf2 << ' ' << buf3 << std::endl;
     701      }
    702702#endif
    703703    }
     
    706706      double max_w=0;
    707707      for(ArcIt e(g);e!=INVALID;++e)
    708         max_w=std::max(double(_arcWidths[e]),max_w);
     708        max_w=std::max(double(_arcWidths[e]),max_w);
    709709      //\todo better 'epsilon' would be nice here.
    710710      if(max_w>EPSILON) {
    711         _arcWidthScale/=max_w;
     711        _arcWidthScale/=max_w;
    712712      }
    713713    }
     
    716716      double max_s=0;
    717717      for(NodeIt n(g);n!=INVALID;++n)
    718         max_s=std::max(double(_nodeSizes[n]),max_s);
     718        max_s=std::max(double(_nodeSizes[n]),max_s);
    719719      //\todo better 'epsilon' would be nice here.
    720720      if(max_s>EPSILON) {
    721         _nodeScale/=max_s;
     721        _nodeScale/=max_s;
    722722      }
    723723    }
     
    728728      for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]);
    729729      if (bb.empty()) {
    730         bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0));
     730        bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0));
    731731      }
    732732      diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare());
     
    735735      if(!_absoluteArcWidths) _arcWidthScale*=diag_len;
    736736    }
    737    
     737
    738738    dim2::BoundingBox<double> bb;
    739739    for(NodeIt n(g);n!=INVALID;++n) {
     
    744744      case SQUARE:
    745745      case DIAMOND:
    746         bb.add(p+mycoords[n]);
    747         bb.add(-p+mycoords[n]);
    748         break;
     746        bb.add(p+mycoords[n]);
     747        bb.add(-p+mycoords[n]);
     748        break;
    749749      case MALE:
    750         bb.add(-p+mycoords[n]);
    751         bb.add(dim2::Point<double>(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]);
    752         break;
     750        bb.add(-p+mycoords[n]);
     751        bb.add(dim2::Point<double>(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]);
     752        break;
    753753      case FEMALE:
    754         bb.add(p+mycoords[n]);
    755         bb.add(dim2::Point<double>(-ns,-3.01*ns)+mycoords[n]);
    756         break;
     754        bb.add(p+mycoords[n]);
     755        bb.add(dim2::Point<double>(-ns,-3.01*ns)+mycoords[n]);
     756        break;
    757757      }
    758758    }
     
    760760      bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0));
    761761    }
    762    
     762
    763763    if(_scaleToA4)
    764764      os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
    765765    else {
    766766      if(_preScale) {
    767         //Rescale so that BoundingBox won't be neither to big nor too small.
    768         while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10;
    769         while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10;
     767        //Rescale so that BoundingBox won't be neither to big nor too small.
     768        while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10;
     769        while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10;
    770770      }
    771      
     771
    772772      os << "%%BoundingBox: "
    773         << int(floor(bb.left()   * _scale - _xBorder)) << ' '
    774         << int(floor(bb.bottom() * _scale - _yBorder)) << ' '
    775         << int(ceil(bb.right()  * _scale + _xBorder)) << ' '
    776         << int(ceil(bb.top()    * _scale + _yBorder)) << '\n';
    777     }
    778    
     773        << int(floor(bb.left()   * _scale - _xBorder)) << ' '
     774        << int(floor(bb.bottom() * _scale - _yBorder)) << ' '
     775        << int(ceil(bb.right()  * _scale + _xBorder)) << ' '
     776        << int(ceil(bb.top()    * _scale + _yBorder)) << '\n';
     777    }
     778
    779779    os << "%%EndComments\n";
    780    
     780
    781781    //x1 y1 x2 y2 x3 y3 cr cg cb w
    782782    os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
     
    832832       << "  setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
    833833       << "  } bind def\n";
    834    
     834
    835835
    836836    os << "/arrl " << _arrowLength << " def\n";
     
    841841    os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def\n"
    842842       << "       /w exch def /len exch def\n"
    843       //        << "       0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
     843      //        << "       0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke"
    844844       << "       newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n"
    845845       << "       len w sub arrl sub dx dy lrl\n"
     
    858858    if(_scaleToA4)
    859859      if(bb.height()>bb.width()) {
    860         double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(),
    861                   (A4WIDTH-2*A4BORDER)/bb.width());
    862         os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
    863            << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER
    864            << " translate\n"
    865            << sc << " dup scale\n"
    866            << -bb.left() << ' ' << -bb.bottom() << " translate\n";
     860        double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(),
     861                  (A4WIDTH-2*A4BORDER)/bb.width());
     862        os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' '
     863           << ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER
     864           << " translate\n"
     865           << sc << " dup scale\n"
     866           << -bb.left() << ' ' << -bb.bottom() << " translate\n";
    867867      }
    868868      else {
    869         //\todo Verify centering
    870         double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(),
    871                   (A4WIDTH-2*A4BORDER)/bb.height());
    872         os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
    873            << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER
    874            << " translate\n"
    875            << sc << " dup scale\n90 rotate\n"
    876            << -bb.left() << ' ' << -bb.top() << " translate\n";
    877         }
     869        //\todo Verify centering
     870        double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(),
     871                  (A4WIDTH-2*A4BORDER)/bb.height());
     872        os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' '
     873           << ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER
     874           << " translate\n"
     875           << sc << " dup scale\n90 rotate\n"
     876           << -bb.left() << ' ' << -bb.top() << " translate\n";
     877        }
    878878    else if(_scale!=1.0) os << _scale << " dup scale\n";
    879    
     879
    880880    if(_showArcs) {
    881       os << "%Arcs:\ngsave\n";     
     881      os << "%Arcs:\ngsave\n";
    882882      if(_enableParallel) {
    883         std::vector<Arc> el;
    884         for(ArcIt e(g);e!=INVALID;++e)
    885           if((!_undirected||g.source(e)<g.target(e))&&_arcWidths[e]>0
    886              &&g.source(e)!=g.target(e))
    887             el.push_back(e);
    888         std::sort(el.begin(),el.end(),arcLess(g));
    889        
    890         typename std::vector<Arc>::iterator j;
    891         for(typename std::vector<Arc>::iterator i=el.begin();i!=el.end();i=j) {
    892           for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
    893 
    894           double sw=0;
    895           for(typename std::vector<Arc>::iterator e=i;e!=j;++e)
    896             sw+=_arcWidths[*e]*_arcWidthScale+_parArcDist;
    897           sw-=_parArcDist;
    898           sw/=-2.0;
    899           dim2::Point<double>
    900             dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
    901           double l=std::sqrt(dvec.normSquare());
    902           //\todo better 'epsilon' would be nice here.
    903           dim2::Point<double> d(dvec/std::max(l,EPSILON));
    904           dim2::Point<double> m;
    905 //        m=dim2::Point<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
    906 
    907 //        m=dim2::Point<double>(mycoords[g.source(*i)])+
    908 //          dvec*(double(_nodeSizes[g.source(*i)])/
    909 //             (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
    910 
    911           m=dim2::Point<double>(mycoords[g.source(*i)])+
    912             d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
    913 
    914           for(typename std::vector<Arc>::iterator e=i;e!=j;++e) {
    915             sw+=_arcWidths[*e]*_arcWidthScale/2.0;
    916             dim2::Point<double> mm=m+rot90(d)*sw/.75;
    917             if(_drawArrows) {
    918               int node_shape;
    919               dim2::Point<double> s=mycoords[g.source(*e)];
    920               dim2::Point<double> t=mycoords[g.target(*e)];
    921               double rn=_nodeSizes[g.target(*e)]*_nodeScale;
    922               node_shape=_nodeShapes[g.target(*e)];
    923               dim2::Bezier3 bez(s,mm,mm,t);
    924               double t1=0,t2=1;
    925               for(int ii=0;ii<INTERPOL_PREC;++ii)
    926                 if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
    927                 else t1=(t1+t2)/2;
    928               dim2::Point<double> apoint=bez((t1+t2)/2);
    929               rn = _arrowLength+_arcWidths[*e]*_arcWidthScale;
    930               rn*=rn;
    931               t2=(t1+t2)/2;t1=0;
    932               for(int ii=0;ii<INTERPOL_PREC;++ii)
    933                 if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
    934                 else t2=(t1+t2)/2;
    935               dim2::Point<double> linend=bez((t1+t2)/2);             
    936               bez=bez.before((t1+t2)/2);
    937 //            rn=_nodeSizes[g.source(*e)]*_nodeScale;
    938 //            node_shape=_nodeShapes[g.source(*e)];
    939 //            t1=0;t2=1;
    940 //            for(int i=0;i<INTERPOL_PREC;++i)
    941 //              if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
    942 //              else t2=(t1+t2)/2;
    943 //            bez=bez.after((t1+t2)/2);
    944               os << _arcWidths[*e]*_arcWidthScale << " setlinewidth "
    945                 << _arcColors[*e].red() << ' '
    946                 << _arcColors[*e].green() << ' '
    947                 << _arcColors[*e].blue() << " setrgbcolor newpath\n"
    948                 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
    949                 << bez.p2.x << ' ' << bez.p2.y << ' '
    950                 << bez.p3.x << ' ' << bez.p3.y << ' '
    951                 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
    952               dim2::Point<double> dd(rot90(linend-apoint));
    953               dd*=(.5*_arcWidths[*e]*_arcWidthScale+_arrowWidth)/
    954                 std::sqrt(dd.normSquare());
    955               os << "newpath " << psOut(apoint) << " moveto "
    956                 << psOut(linend+dd) << " lineto "
    957                 << psOut(linend-dd) << " lineto closepath fill\n";
    958             }
    959             else {
    960               os << mycoords[g.source(*e)].x << ' '
    961                 << mycoords[g.source(*e)].y << ' '
    962                 << mm.x << ' ' << mm.y << ' '
    963                 << mycoords[g.target(*e)].x << ' '
    964                 << mycoords[g.target(*e)].y << ' '
    965                 << _arcColors[*e].red() << ' '
    966                 << _arcColors[*e].green() << ' '
    967                 << _arcColors[*e].blue() << ' '
    968                 << _arcWidths[*e]*_arcWidthScale << " lb\n";
    969             }
    970             sw+=_arcWidths[*e]*_arcWidthScale/2.0+_parArcDist;
    971           }
    972         }
     883        std::vector<Arc> el;
     884        for(ArcIt e(g);e!=INVALID;++e)
     885          if((!_undirected||g.source(e)<g.target(e))&&_arcWidths[e]>0
     886             &&g.source(e)!=g.target(e))
     887            el.push_back(e);
     888        std::sort(el.begin(),el.end(),arcLess(g));
     889
     890        typename std::vector<Arc>::iterator j;
     891        for(typename std::vector<Arc>::iterator i=el.begin();i!=el.end();i=j) {
     892          for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ;
     893
     894          double sw=0;
     895          for(typename std::vector<Arc>::iterator e=i;e!=j;++e)
     896            sw+=_arcWidths[*e]*_arcWidthScale+_parArcDist;
     897          sw-=_parArcDist;
     898          sw/=-2.0;
     899          dim2::Point<double>
     900            dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
     901          double l=std::sqrt(dvec.normSquare());
     902          //\todo better 'epsilon' would be nice here.
     903          dim2::Point<double> d(dvec/std::max(l,EPSILON));
     904           dim2::Point<double> m;
     905//           m=dim2::Point<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
     906
     907//            m=dim2::Point<double>(mycoords[g.source(*i)])+
     908//             dvec*(double(_nodeSizes[g.source(*i)])/
     909//                (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
     910
     911           m=dim2::Point<double>(mycoords[g.source(*i)])+
     912            d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
     913
     914          for(typename std::vector<Arc>::iterator e=i;e!=j;++e) {
     915            sw+=_arcWidths[*e]*_arcWidthScale/2.0;
     916            dim2::Point<double> mm=m+rot90(d)*sw/.75;
     917            if(_drawArrows) {
     918              int node_shape;
     919              dim2::Point<double> s=mycoords[g.source(*e)];
     920              dim2::Point<double> t=mycoords[g.target(*e)];
     921              double rn=_nodeSizes[g.target(*e)]*_nodeScale;
     922              node_shape=_nodeShapes[g.target(*e)];
     923              dim2::Bezier3 bez(s,mm,mm,t);
     924              double t1=0,t2=1;
     925              for(int ii=0;ii<INTERPOL_PREC;++ii)
     926                if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2;
     927                else t1=(t1+t2)/2;
     928              dim2::Point<double> apoint=bez((t1+t2)/2);
     929              rn = _arrowLength+_arcWidths[*e]*_arcWidthScale;
     930              rn*=rn;
     931              t2=(t1+t2)/2;t1=0;
     932              for(int ii=0;ii<INTERPOL_PREC;++ii)
     933                if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2;
     934                else t2=(t1+t2)/2;
     935              dim2::Point<double> linend=bez((t1+t2)/2);
     936              bez=bez.before((t1+t2)/2);
     937//               rn=_nodeSizes[g.source(*e)]*_nodeScale;
     938//               node_shape=_nodeShapes[g.source(*e)];
     939//               t1=0;t2=1;
     940//               for(int i=0;i<INTERPOL_PREC;++i)
     941//                 if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
     942//                 else t2=(t1+t2)/2;
     943//               bez=bez.after((t1+t2)/2);
     944              os << _arcWidths[*e]*_arcWidthScale << " setlinewidth "
     945                << _arcColors[*e].red() << ' '
     946                << _arcColors[*e].green() << ' '
     947                << _arcColors[*e].blue() << " setrgbcolor newpath\n"
     948                << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
     949                << bez.p2.x << ' ' << bez.p2.y << ' '
     950                << bez.p3.x << ' ' << bez.p3.y << ' '
     951                << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
     952              dim2::Point<double> dd(rot90(linend-apoint));
     953              dd*=(.5*_arcWidths[*e]*_arcWidthScale+_arrowWidth)/
     954                std::sqrt(dd.normSquare());
     955              os << "newpath " << psOut(apoint) << " moveto "
     956                << psOut(linend+dd) << " lineto "
     957                << psOut(linend-dd) << " lineto closepath fill\n";
     958            }
     959            else {
     960              os << mycoords[g.source(*e)].x << ' '
     961                << mycoords[g.source(*e)].y << ' '
     962                << mm.x << ' ' << mm.y << ' '
     963                << mycoords[g.target(*e)].x << ' '
     964                << mycoords[g.target(*e)].y << ' '
     965                << _arcColors[*e].red() << ' '
     966                << _arcColors[*e].green() << ' '
     967                << _arcColors[*e].blue() << ' '
     968                << _arcWidths[*e]*_arcWidthScale << " lb\n";
     969            }
     970            sw+=_arcWidths[*e]*_arcWidthScale/2.0+_parArcDist;
     971          }
     972        }
    973973      }
    974974      else for(ArcIt e(g);e!=INVALID;++e)
    975         if((!_undirected||g.source(e)<g.target(e))&&_arcWidths[e]>0
    976            &&g.source(e)!=g.target(e)) {
    977           if(_drawArrows) {
    978             dim2::Point<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
    979             double rn=_nodeSizes[g.target(e)]*_nodeScale;
    980             int node_shape=_nodeShapes[g.target(e)];
    981             double t1=0,t2=1;
    982             for(int i=0;i<INTERPOL_PREC;++i)
    983               if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
    984               else t2=(t1+t2)/2;
    985             double l=std::sqrt(d.normSquare());
    986             d/=l;
    987            
    988             os << l*(1-(t1+t2)/2) << ' '
    989                << _arcWidths[e]*_arcWidthScale << ' '
    990                << d.x << ' ' << d.y << ' '
    991                << mycoords[g.source(e)].x << ' '
    992                << mycoords[g.source(e)].y << ' '
    993                << _arcColors[e].red() << ' '
    994                << _arcColors[e].green() << ' '
    995                << _arcColors[e].blue() << " arr\n";
    996           }
    997           else os << mycoords[g.source(e)].x << ' '
    998                   << mycoords[g.source(e)].y << ' '
    999                   << mycoords[g.target(e)].x << ' '
    1000                   << mycoords[g.target(e)].y << ' '
    1001                   << _arcColors[e].red() << ' '
    1002                   << _arcColors[e].green() << ' '
    1003                   << _arcColors[e].blue() << ' '
    1004                   << _arcWidths[e]*_arcWidthScale << " l\n";
    1005         }
     975        if((!_undirected||g.source(e)<g.target(e))&&_arcWidths[e]>0
     976           &&g.source(e)!=g.target(e)) {
     977          if(_drawArrows) {
     978            dim2::Point<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
     979            double rn=_nodeSizes[g.target(e)]*_nodeScale;
     980            int node_shape=_nodeShapes[g.target(e)];
     981            double t1=0,t2=1;
     982            for(int i=0;i<INTERPOL_PREC;++i)
     983              if(isInsideNode((-(t1+t2)/2)*d,rn,node_shape)) t1=(t1+t2)/2;
     984              else t2=(t1+t2)/2;
     985            double l=std::sqrt(d.normSquare());
     986            d/=l;
     987
     988            os << l*(1-(t1+t2)/2) << ' '
     989               << _arcWidths[e]*_arcWidthScale << ' '
     990               << d.x << ' ' << d.y << ' '
     991               << mycoords[g.source(e)].x << ' '
     992               << mycoords[g.source(e)].y << ' '
     993               << _arcColors[e].red() << ' '
     994               << _arcColors[e].green() << ' '
     995               << _arcColors[e].blue() << " arr\n";
     996          }
     997          else os << mycoords[g.source(e)].x << ' '
     998                  << mycoords[g.source(e)].y << ' '
     999                  << mycoords[g.target(e)].x << ' '
     1000                  << mycoords[g.target(e)].y << ' '
     1001                  << _arcColors[e].red() << ' '
     1002                  << _arcColors[e].green() << ' '
     1003                  << _arcColors[e].blue() << ' '
     1004                  << _arcWidths[e]*_arcWidthScale << " l\n";
     1005        }
    10061006      os << "grestore\n";
    10071007    }
     
    10091009      os << "%Nodes:\ngsave\n";
    10101010      for(NodeIt n(g);n!=INVALID;++n) {
    1011         os << mycoords[n].x << ' ' << mycoords[n].y << ' '
    1012            << _nodeSizes[n]*_nodeScale << ' '
    1013            << _nodeColors[n].red() << ' '
    1014            << _nodeColors[n].green() << ' '
    1015            << _nodeColors[n].blue() << ' ';
    1016         switch(_nodeShapes[n]) {
    1017         case CIRCLE:
    1018           os<< "nc";break;
    1019         case SQUARE:
    1020           os<< "nsq";break;
    1021         case DIAMOND:
    1022           os<< "ndi";break;
    1023         case MALE:
    1024           os<< "nmale";break;
    1025         case FEMALE:
    1026           os<< "nfemale";break;
    1027         }
    1028         os<<'\n';
     1011        os << mycoords[n].x << ' ' << mycoords[n].y << ' '
     1012           << _nodeSizes[n]*_nodeScale << ' '
     1013           << _nodeColors[n].red() << ' '
     1014           << _nodeColors[n].green() << ' '
     1015           << _nodeColors[n].blue() << ' ';
     1016        switch(_nodeShapes[n]) {
     1017        case CIRCLE:
     1018          os<< "nc";break;
     1019        case SQUARE:
     1020          os<< "nsq";break;
     1021        case DIAMOND:
     1022          os<< "ndi";break;
     1023        case MALE:
     1024          os<< "nmale";break;
     1025        case FEMALE:
     1026          os<< "nfemale";break;
     1027        }
     1028        os<<'\n';
    10291029      }
    10301030      os << "grestore\n";
     
    10351035      os << "(Helvetica) findfont fosi scalefont setfont\n";
    10361036      for(NodeIt n(g);n!=INVALID;++n) {
    1037         switch(_nodeTextColorType) {
    1038         case DIST_COL:
    1039           os << psOut(distantColor(_nodeColors[n])) << " setrgbcolor\n";
    1040           break;
    1041         case DIST_BW:
    1042           os << psOut(distantBW(_nodeColors[n])) << " setrgbcolor\n";
    1043           break;
    1044         case CUST_COL:
    1045           os << psOut(distantColor(_nodeTextColors[n])) << " setrgbcolor\n";
    1046           break;
    1047         default:
    1048           os << "0 0 0 setrgbcolor\n";
    1049         }
    1050         os << mycoords[n].x << ' ' << mycoords[n].y
    1051            << " (" << _nodeTexts[n] << ") cshow\n";
     1037        switch(_nodeTextColorType) {
     1038        case DIST_COL:
     1039          os << psOut(distantColor(_nodeColors[n])) << " setrgbcolor\n";
     1040          break;
     1041        case DIST_BW:
     1042          os << psOut(distantBW(_nodeColors[n])) << " setrgbcolor\n";
     1043          break;
     1044        case CUST_COL:
     1045          os << psOut(distantColor(_nodeTextColors[n])) << " setrgbcolor\n";
     1046          break;
     1047        default:
     1048          os << "0 0 0 setrgbcolor\n";
     1049        }
     1050        os << mycoords[n].x << ' ' << mycoords[n].y
     1051           << " (" << _nodeTexts[n] << ") cshow\n";
    10521052      }
    10531053      os << "grestore\n";
     
    10561056      os << "%Node PS blocks:\ngsave\n";
    10571057      for(NodeIt n(g);n!=INVALID;++n)
    1058         os << mycoords[n].x << ' ' << mycoords[n].y
    1059            << " moveto\n" << _nodePsTexts[n] << "\n";
     1058        os << mycoords[n].x << ' ' << mycoords[n].y
     1059           << " moveto\n" << _nodePsTexts[n] << "\n";
    10601060      os << "grestore\n";
    10611061    }
    1062    
     1062
    10631063    os << "grestore\nshowpage\n";
    10641064
     
    10931093    return autoArcWidthScale(b);
    10941094  }
    1095  
     1095
    10961096  ///An alias for absoluteArcWidths()
    10971097  GraphToEps<T> &absoluteEdgeWidths(bool b=true)
     
    10991099    return absoluteArcWidths(b);
    11001100  }
    1101  
     1101
    11021102  ///An alias for parArcDist()
    11031103  GraphToEps<T> &parEdgeDist(double d) {return parArcDist(d);}
    1104  
     1104
    11051105  ///An alias for hideArcs()
    11061106  GraphToEps<T> &hideEdges(bool b=true) {return hideArcs(b);}
     
    11441144///\sa graphToEps(G &g, const char *file_name)
    11451145template<class G>
    1146 GraphToEps<DefaultGraphToEpsTraits<G> > 
     1146GraphToEps<DefaultGraphToEpsTraits<G> >
    11471147graphToEps(G &g, std::ostream& os=std::cout)
    11481148{
    1149   return 
     1149  return
    11501150    GraphToEps<DefaultGraphToEpsTraits<G> >(DefaultGraphToEpsTraits<G>(g,os));
    11511151}
    1152  
     1152
    11531153///Generates an EPS file from a graph
    11541154
     
    11601160///\sa graphToEps(G &g, std::ostream& os)
    11611161template<class G>
    1162 GraphToEps<DefaultGraphToEpsTraits<G> > 
     1162GraphToEps<DefaultGraphToEpsTraits<G> >
    11631163graphToEps(G &g,const char *file_name)
    11641164{
     
    11761176///\sa graphToEps(G &g, std::ostream& os)
    11771177template<class G>
    1178 GraphToEps<DefaultGraphToEpsTraits<G> > 
     1178GraphToEps<DefaultGraphToEpsTraits<G> >
    11791179graphToEps(G &g,const std::string& file_name)
    11801180{
  • lemon/graph_utils.h

    r199 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4747  ///This \c \#define creates convenience typedefs for the following types
    4848  ///of \c Digraph: \c Node,  \c NodeIt, \c Arc, \c ArcIt, \c InArcIt,
    49   ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, 
     49  ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap,
    5050  ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap.
    5151  ///
     
    5353  ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS()
    5454  ///macro.
    55 #define DIGRAPH_TYPEDEFS(Digraph)                                       \
    56   typedef Digraph::Node Node;                                           \
    57   typedef Digraph::NodeIt NodeIt;                                       \
    58   typedef Digraph::Arc Arc;                                             \
    59   typedef Digraph::ArcIt ArcIt;                                         \
    60   typedef Digraph::InArcIt InArcIt;                                     \
    61   typedef Digraph::OutArcIt OutArcIt;                                   \
    62   typedef Digraph::NodeMap<bool> BoolNodeMap;                           \
    63   typedef Digraph::NodeMap<int> IntNodeMap;                             \
    64   typedef Digraph::NodeMap<double> DoubleNodeMap;                       \
    65   typedef Digraph::ArcMap<bool> BoolArcMap;                             \
    66   typedef Digraph::ArcMap<int> IntArcMap;                               \
     55#define DIGRAPH_TYPEDEFS(Digraph)                                        \
     56  typedef Digraph::Node Node;                                                \
     57  typedef Digraph::NodeIt NodeIt;                                        \
     58  typedef Digraph::Arc Arc;                                                \
     59  typedef Digraph::ArcIt ArcIt;                                                \
     60  typedef Digraph::InArcIt InArcIt;                                        \
     61  typedef Digraph::OutArcIt OutArcIt;                                        \
     62  typedef Digraph::NodeMap<bool> BoolNodeMap;                                \
     63  typedef Digraph::NodeMap<int> IntNodeMap;                                \
     64  typedef Digraph::NodeMap<double> DoubleNodeMap;                        \
     65  typedef Digraph::ArcMap<bool> BoolArcMap;                                \
     66  typedef Digraph::ArcMap<int> IntArcMap;                                \
    6767  typedef Digraph::ArcMap<double> DoubleArcMap
    6868
     
    7373  ///\note Use this macro, if the graph type is a dependent type,
    7474  ///ie. the graph type depend on a template parameter.
    75 #define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph)                              \
    76   typedef typename Digraph::Node Node;                                  \
    77   typedef typename Digraph::NodeIt NodeIt;                              \
    78   typedef typename Digraph::Arc Arc;                                    \
    79   typedef typename Digraph::ArcIt ArcIt;                                \
    80   typedef typename Digraph::InArcIt InArcIt;                            \
    81   typedef typename Digraph::OutArcIt OutArcIt;                          \
    82   typedef typename Digraph::template NodeMap<bool> BoolNodeMap;         \
    83   typedef typename Digraph::template NodeMap<int> IntNodeMap;           \
    84   typedef typename Digraph::template NodeMap<double> DoubleNodeMap;     \
    85   typedef typename Digraph::template ArcMap<bool> BoolArcMap;           \
    86   typedef typename Digraph::template ArcMap<int> IntArcMap;             \
     75#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph)                                \
     76  typedef typename Digraph::Node Node;                                        \
     77  typedef typename Digraph::NodeIt NodeIt;                                \
     78  typedef typename Digraph::Arc Arc;                                        \
     79  typedef typename Digraph::ArcIt ArcIt;                                \
     80  typedef typename Digraph::InArcIt InArcIt;                                \
     81  typedef typename Digraph::OutArcIt OutArcIt;                                \
     82  typedef typename Digraph::template NodeMap<bool> BoolNodeMap;                \
     83  typedef typename Digraph::template NodeMap<int> IntNodeMap;                \
     84  typedef typename Digraph::template NodeMap<double> DoubleNodeMap;        \
     85  typedef typename Digraph::template ArcMap<bool> BoolArcMap;                \
     86  typedef typename Digraph::template ArcMap<int> IntArcMap;                \
    8787  typedef typename Digraph::template ArcMap<double> DoubleArcMap
    88  
     88
    8989  ///Creates convenience typedefs for the graph types and iterators
    9090
     
    9797  ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS()
    9898  ///macro.
    99 #define GRAPH_TYPEDEFS(Graph)                                           \
    100   DIGRAPH_TYPEDEFS(Graph);                                              \
    101   typedef Graph::Edge Edge;                                             \
    102   typedef Graph::EdgeIt EdgeIt;                                         \
    103   typedef Graph::IncEdgeIt IncEdgeIt;                                   \
    104   typedef Graph::EdgeMap<bool> BoolEdgeMap;                             \
    105   typedef Graph::EdgeMap<int> IntEdgeMap;                               \
     99#define GRAPH_TYPEDEFS(Graph)                                                \
     100  DIGRAPH_TYPEDEFS(Graph);                                                \
     101  typedef Graph::Edge Edge;                                                \
     102  typedef Graph::EdgeIt EdgeIt;                                                \
     103  typedef Graph::IncEdgeIt IncEdgeIt;                                        \
     104  typedef Graph::EdgeMap<bool> BoolEdgeMap;                                \
     105  typedef Graph::EdgeMap<int> IntEdgeMap;                                \
    106106  typedef Graph::EdgeMap<double> DoubleEdgeMap
    107107
     
    112112  ///\note Use this macro, if the graph type is a dependent type,
    113113  ///ie. the graph type depend on a template parameter.
    114 #define TEMPLATE_GRAPH_TYPEDEFS(Graph)                                  \
    115   TEMPLATE_DIGRAPH_TYPEDEFS(Graph);                                     \
    116   typedef typename Graph::Edge Edge;                                    \
    117   typedef typename Graph::EdgeIt EdgeIt;                                \
    118   typedef typename Graph::IncEdgeIt IncEdgeIt;                          \
    119   typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;           \
    120   typedef typename Graph::template EdgeMap<int> IntEdgeMap;             \
     114#define TEMPLATE_GRAPH_TYPEDEFS(Graph)                                        \
     115  TEMPLATE_DIGRAPH_TYPEDEFS(Graph);                                        \
     116  typedef typename Graph::Edge Edge;                                        \
     117  typedef typename Graph::EdgeIt EdgeIt;                                \
     118  typedef typename Graph::IncEdgeIt IncEdgeIt;                                \
     119  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;                \
     120  typedef typename Graph::template EdgeMap<int> IntEdgeMap;                \
    121121  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
    122122
     
    139139
    140140  namespace _graph_utils_bits {
    141    
     141
    142142    template <typename Graph, typename Enable = void>
    143143    struct CountNodesSelector {
     
    149149    template <typename Graph>
    150150    struct CountNodesSelector<
    151       Graph, typename 
    152       enable_if<typename Graph::NodeNumTag, void>::type> 
     151      Graph, typename
     152      enable_if<typename Graph::NodeNumTag, void>::type>
    153153    {
    154154      static int count(const Graph &g) {
    155155        return g.nodeNum();
    156156      }
    157     };   
     157    };
    158158  }
    159159
     
    164164  /// graph structures it is specialized to run in O(1).
    165165  ///
    166   /// If the graph contains a \e nodeNum() member function and a 
     166  /// If the graph contains a \e nodeNum() member function and a
    167167  /// \e NodeNumTag tag then this function calls directly the member
    168168  /// function to query the cardinality of the node set.
     
    175175
    176176  namespace _graph_utils_bits {
    177    
     177
    178178    template <typename Graph, typename Enable = void>
    179179    struct CountArcsSelector {
     
    185185    template <typename Graph>
    186186    struct CountArcsSelector<
    187       Graph, 
    188       typename enable_if<typename Graph::ArcNumTag, void>::type> 
     187      Graph,
     188      typename enable_if<typename Graph::ArcNumTag, void>::type>
    189189    {
    190190      static int count(const Graph &g) {
    191191        return g.arcNum();
    192192      }
    193     };   
     193    };
    194194  }
    195195
     
    200200  /// graph structures it is specialized to run in O(1).
    201201  ///
    202   /// If the graph contains a \e arcNum() member function and a 
     202  /// If the graph contains a \e arcNum() member function and a
    203203  /// \e EdgeNumTag tag then this function calls directly the member
    204204  /// function to query the cardinality of the arc set.
     
    210210  // Edge counting:
    211211  namespace _graph_utils_bits {
    212    
     212
    213213    template <typename Graph, typename Enable = void>
    214214    struct CountEdgesSelector {
     
    220220    template <typename Graph>
    221221    struct CountEdgesSelector<
    222       Graph, 
    223       typename enable_if<typename Graph::EdgeNumTag, void>::type> 
     222      Graph,
     223      typename enable_if<typename Graph::EdgeNumTag, void>::type>
    224224    {
    225225      static int count(const Graph &g) {
    226226        return g.edgeNum();
    227227      }
    228     };   
     228    };
    229229  }
    230230
     
    235235  /// graph structures it is specialized to run in O(1).
    236236  ///
    237   /// If the graph contains a \e edgeNum() member function and a 
     237  /// If the graph contains a \e edgeNum() member function and a
    238238  /// \e EdgeNumTag tag then this function calls directly the member
    239239  /// function to query the cardinality of the edge set.
     
    257257  ///
    258258  /// This function counts the number of the out-arcs from node \c n
    259   /// in the graph. 
     259  /// in the graph.
    260260  template <typename Graph>
    261261  inline int countOutArcs(const Graph& _g,  const typename Graph::Node& _n) {
     
    266266  ///
    267267  /// This function counts the number of the in-arcs to node \c n
    268   /// in the graph. 
     268  /// in the graph.
    269269  template <typename Graph>
    270270  inline int countInArcs(const Graph& _g,  const typename Graph::Node& _n) {
     
    275275  ///
    276276  /// This function counts the number of the inc-edges to node \c n
    277   /// in the graph. 
     277  /// in the graph.
    278278  template <typename Graph>
    279279  inline int countIncEdges(const Graph& _g,  const typename Graph::Node& _n) {
     
    282282
    283283  namespace _graph_utils_bits {
    284    
     284
    285285    template <typename Graph, typename Enable = void>
    286286    struct FindArcSelector {
     
    302302    template <typename Graph>
    303303    struct FindArcSelector<
    304       Graph, 
    305       typename enable_if<typename Graph::FindEdgeTag, void>::type> 
     304      Graph,
     305      typename enable_if<typename Graph::FindEdgeTag, void>::type>
    306306    {
    307307      typedef typename Graph::Node Node;
     
    310310        return g.findArc(u, v, prev);
    311311      }
    312     };   
     312    };
    313313  }
    314314
     
    334334  ///\sa ConArcIt
    335335  template <typename Graph>
    336   inline typename Graph::Arc 
     336  inline typename Graph::Arc
    337337  findArc(const Graph &g, typename Graph::Node u, typename Graph::Node v,
    338338           typename Graph::Arc prev = INVALID) {
     
    342342  /// \brief Iterator for iterating on arcs connected the same nodes.
    343343  ///
    344   /// Iterator for iterating on arcs connected the same nodes. It is 
     344  /// Iterator for iterating on arcs connected the same nodes. It is
    345345  /// higher level interface for the findArc() function. You can
    346346  /// use it the following way:
     
    350350  /// }
    351351  ///\endcode
    352   /// 
     352  ///
    353353  ///\sa findArc()
    354354  ///\sa ArcLookUp
     
    375375    /// \brief Constructor.
    376376    ///
    377     /// Construct a new ConArcIt which continues the iterating from 
     377    /// Construct a new ConArcIt which continues the iterating from
    378378    /// the \c e arc.
    379379    ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {}
    380    
     380
    381381    /// \brief Increment operator.
    382382    ///
    383383    /// It increments the iterator and gives back the next arc.
    384384    ConArcIt& operator++() {
    385       Parent::operator=(findArc(_graph, _graph.source(*this), 
    386                                 _graph.target(*this), *this));
     385      Parent::operator=(findArc(_graph, _graph.source(*this),
     386                                _graph.target(*this), *this));
    387387      return *this;
    388388    }
     
    392392
    393393  namespace _graph_utils_bits {
    394    
     394
    395395    template <typename Graph, typename Enable = void>
    396396    struct FindEdgeSelector {
     
    426426    template <typename Graph>
    427427    struct FindEdgeSelector<
    428       Graph, 
    429       typename enable_if<typename Graph::FindEdgeTag, void>::type> 
     428      Graph,
     429      typename enable_if<typename Graph::FindEdgeTag, void>::type>
    430430    {
    431431      typedef typename Graph::Node Node;
     
    434434        return g.findEdge(u, v, prev);
    435435      }
    436     };   
     436    };
    437437  }
    438438
     
    450450  /// Thus you can iterate through each arc from \c u to \c v as it follows.
    451451  ///\code
    452   /// for(Edge e = findEdge(g,u,v); e != INVALID; 
     452  /// for(Edge e = findEdge(g,u,v); e != INVALID;
    453453  ///     e = findEdge(g,u,v,e)) {
    454454  ///   ...
     
    459459
    460460  template <typename Graph>
    461   inline typename Graph::Edge 
     461  inline typename Graph::Edge
    462462  findEdge(const Graph &g, typename Graph::Node u, typename Graph::Node v,
    463463            typename Graph::Edge p = INVALID) {
     
    467467  /// \brief Iterator for iterating on edges connected the same nodes.
    468468  ///
    469   /// Iterator for iterating on edges connected the same nodes. It is 
     469  /// Iterator for iterating on edges connected the same nodes. It is
    470470  /// higher level interface for the findEdge() function. You can
    471471  /// use it the following way:
     
    497497    /// \brief Constructor.
    498498    ///
    499     /// Construct a new ConEdgeIt which continues the iterating from 
     499    /// Construct a new ConEdgeIt which continues the iterating from
    500500    /// the \c e edge.
    501501    ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {}
    502    
     502
    503503    /// \brief Increment operator.
    504504    ///
    505505    /// It increments the iterator and gives back the next edge.
    506506    ConEdgeIt& operator++() {
    507       Parent::operator=(findEdge(_graph, _graph.u(*this), 
    508                                 _graph.v(*this), *this));
     507      Parent::operator=(findEdge(_graph, _graph.u(*this),
     508                                _graph.v(*this), *this));
    509509      return *this;
    510510    }
     
    519519    public:
    520520      virtual void copy(const Digraph& from, const RefMap& refMap) = 0;
    521      
     521
    522522      virtual ~MapCopyBase() {}
    523523    };
    524524
    525     template <typename Digraph, typename Item, typename RefMap, 
     525    template <typename Digraph, typename Item, typename RefMap,
    526526              typename ToMap, typename FromMap>
    527527    class MapCopy : public MapCopyBase<Digraph, Item, RefMap> {
    528528    public:
    529529
    530       MapCopy(ToMap& tmap, const FromMap& map) 
     530      MapCopy(ToMap& tmap, const FromMap& map)
    531531        : _tmap(tmap), _map(map) {}
    532      
     532
    533533      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
    534534        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
     
    548548
    549549      ItemCopy(It& it, const Item& item) : _it(it), _item(item) {}
    550      
     550
    551551      virtual void copy(const Digraph&, const RefMap& refMap) {
    552552        _it = refMap[_item];
     
    563563
    564564      RefCopy(Ref& map) : _map(map) {}
    565      
     565
    566566      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
    567567        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
     
    575575    };
    576576
    577     template <typename Digraph, typename Item, typename RefMap, 
     577    template <typename Digraph, typename Item, typename RefMap,
    578578              typename CrossRef>
    579579    class CrossRefCopy : public MapCopyBase<Digraph, Item, RefMap> {
     
    581581
    582582      CrossRefCopy(CrossRef& cmap) : _cmap(cmap) {}
    583      
     583
    584584      virtual void copy(const Digraph& digraph, const RefMap& refMap) {
    585585        typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt;
     
    602602        }
    603603        for (typename From::ArcIt it(from); it != INVALID; ++it) {
    604           arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], 
    605                                     nodeRefMap[from.target(it)]);
     604          arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)],
     605                                    nodeRefMap[from.target(it)]);
    606606        }
    607607      }
     
    610610    template <typename Digraph>
    611611    struct DigraphCopySelector<
    612       Digraph, 
    613       typename enable_if<typename Digraph::BuildTag, void>::type> 
     612      Digraph,
     613      typename enable_if<typename Digraph::BuildTag, void>::type>
    614614    {
    615615      template <typename From, typename NodeRefMap, typename ArcRefMap>
     
    629629        }
    630630        for (typename From::EdgeIt it(from); it != INVALID; ++it) {
    631           edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)], 
    632                                       nodeRefMap[from.v(it)]);
     631          edgeRefMap[it] = to.addEdge(nodeRefMap[from.u(it)],
     632                                      nodeRefMap[from.v(it)]);
    633633        }
    634634      }
     
    637637    template <typename Graph>
    638638    struct GraphCopySelector<
    639       Graph, 
    640       typename enable_if<typename Graph::BuildTag, void>::type> 
     639      Graph,
     640      typename enable_if<typename Graph::BuildTag, void>::type>
    641641    {
    642642      template <typename From, typename NodeRefMap, typename EdgeRefMap>
     
    698698    typedef typename From::template NodeMap<TNode> NodeRefMap;
    699699    typedef typename From::template ArcMap<TArc> ArcRefMap;
    700    
    701    
    702   public: 
     700
     701
     702  public:
    703703
    704704
     
    707707    /// It copies the content of the \c _from digraph into the
    708708    /// \c _to digraph.
    709     DigraphCopy(To& to, const From& from) 
     709    DigraphCopy(To& to, const From& from)
    710710      : _from(from), _to(to) {}
    711711
     
    731731    template <typename NodeRef>
    732732    DigraphCopy& nodeRef(NodeRef& map) {
    733       _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node, 
    734                            NodeRefMap, NodeRef>(map));
     733      _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node,
     734                           NodeRefMap, NodeRef>(map));
    735735      return *this;
    736736    }
     
    745745    DigraphCopy& nodeCrossRef(NodeCrossRef& map) {
    746746      _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,
    747                            NodeRefMap, NodeCrossRef>(map));
     747                           NodeRefMap, NodeCrossRef>(map));
    748748      return *this;
    749749    }
     
    756756    template <typename ToMap, typename FromMap>
    757757    DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
    758       _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node, 
    759                            NodeRefMap, ToMap, FromMap>(tmap, map));
     758      _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node,
     759                           NodeRefMap, ToMap, FromMap>(tmap, map));
    760760      return *this;
    761761    }
     
    765765    /// Make a copy of the given node.
    766766    DigraphCopy& node(TNode& tnode, const Node& snode) {
    767       _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node, 
    768                            NodeRefMap, TNode>(tnode, snode));
     767      _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node,
     768                           NodeRefMap, TNode>(tnode, snode));
    769769      return *this;
    770770    }
     
    775775    template <typename ArcRef>
    776776    DigraphCopy& arcRef(ArcRef& map) {
    777       _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc, 
    778                           ArcRefMap, ArcRef>(map));
     777      _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc,
     778                          ArcRefMap, ArcRef>(map));
    779779      return *this;
    780780    }
     
    787787    DigraphCopy& arcCrossRef(ArcCrossRef& map) {
    788788      _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc,
    789                           ArcRefMap, ArcCrossRef>(map));
     789                          ArcRefMap, ArcCrossRef>(map));
    790790      return *this;
    791791    }
     
    793793    /// \brief Make copy of the given map.
    794794    ///
    795     /// Makes copy of the given map for the newly created digraph. 
     795    /// Makes copy of the given map for the newly created digraph.
    796796    /// The new map's key type is the to digraph's arc type,
    797797    /// and the copied map's key type is the from digraph's arc
    798     /// type. 
     798    /// type.
    799799    template <typename ToMap, typename FromMap>
    800800    DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) {
    801       _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc, 
    802                           ArcRefMap, ToMap, FromMap>(tmap, map));
     801      _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc,
     802                          ArcRefMap, ToMap, FromMap>(tmap, map));
    803803      return *this;
    804804    }
     
    808808    /// Make a copy of the given arc.
    809809    DigraphCopy& arc(TArc& tarc, const Arc& sarc) {
    810       _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc, 
    811                           ArcRefMap, TArc>(tarc, sarc));
     810      _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc,
     811                          ArcRefMap, TArc>(tarc, sarc));
    812812      return *this;
    813813    }
     
    826826      for (int i = 0; i < int(_arc_maps.size()); ++i) {
    827827        _arc_maps[i]->copy(_from, arcRefMap);
    828       }     
     828      }
    829829    }
    830830
     
    835835    To& _to;
    836836
    837     std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
     837    std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* >
    838838    _node_maps;
    839839
    840     std::vector<_graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 
     840    std::vector<_graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* >
    841841    _arc_maps;
    842842
     
    851851  /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();
    852852  ///\endcode
    853   /// 
     853  ///
    854854  /// After the copy the \c nr map will contain the mapping from the
    855855  /// nodes of the \c from digraph to the nodes of the \c to digraph and
     
    857857  /// to the arcs of the \c from digraph.
    858858  ///
    859   /// \see DigraphCopy 
     859  /// \see DigraphCopy
    860860  template <typename To, typename From>
    861861  DigraphCopy<To, From> copyDigraph(To& to, const From& from) {
     
    918918    struct ArcRefMap {
    919919      ArcRefMap(const To& to, const From& from,
    920                 const EdgeRefMap& edge_ref, const NodeRefMap& node_ref)
    921         : _to(to), _from(from), 
     920                const EdgeRefMap& edge_ref, const NodeRefMap& node_ref)
     921        : _to(to), _from(from),
    922922          _edge_ref(edge_ref), _node_ref(node_ref) {}
    923923
     
    927927      Value operator[](const Key& key) const {
    928928        bool forward = _from.u(key) != _from.v(key) ?
    929           _node_ref[_from.source(key)] ==
    930           _to.source(_to.direct(_edge_ref[key], true)) :
    931           _from.direction(key);
    932         return _to.direct(_edge_ref[key], forward);
    933       }
    934      
     929          _node_ref[_from.source(key)] ==
     930          _to.source(_to.direct(_edge_ref[key], true)) :
     931          _from.direction(key);
     932        return _to.direct(_edge_ref[key], forward);
     933      }
     934
    935935      const To& _to;
    936936      const From& _from;
     
    939939    };
    940940
    941    
    942   public: 
     941
     942  public:
    943943
    944944
     
    947947    /// It copies the content of the \c _from graph into the
    948948    /// \c _to graph.
    949     GraphCopy(To& to, const From& from) 
     949    GraphCopy(To& to, const From& from)
    950950      : _from(from), _to(to) {}
    951951
     
    971971    template <typename NodeRef>
    972972    GraphCopy& nodeRef(NodeRef& map) {
    973       _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node, 
    974                            NodeRefMap, NodeRef>(map));
     973      _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node,
     974                           NodeRefMap, NodeRef>(map));
    975975      return *this;
    976976    }
     
    983983    GraphCopy& nodeCrossRef(NodeCrossRef& map) {
    984984      _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,
    985                            NodeRefMap, NodeCrossRef>(map));
     985                           NodeRefMap, NodeCrossRef>(map));
    986986      return *this;
    987987    }
     
    989989    /// \brief Make copy of the given map.
    990990    ///
    991     /// Makes copy of the given map for the newly created graph. 
     991    /// Makes copy of the given map for the newly created graph.
    992992    /// The new map's key type is the to graph's node type,
    993993    /// and the copied map's key type is the from graph's node
    994     /// type. 
     994    /// type.
    995995    template <typename ToMap, typename FromMap>
    996996    GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
    997       _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node, 
    998                            NodeRefMap, ToMap, FromMap>(tmap, map));
     997      _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node,
     998                           NodeRefMap, ToMap, FromMap>(tmap, map));
    999999      return *this;
    10001000    }
     
    10041004    /// Make a copy of the given node.
    10051005    GraphCopy& node(TNode& tnode, const Node& snode) {
    1006       _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node, 
    1007                            NodeRefMap, TNode>(tnode, snode));
     1006      _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node,
     1007                           NodeRefMap, TNode>(tnode, snode));
    10081008      return *this;
    10091009    }
     
    10141014    template <typename ArcRef>
    10151015    GraphCopy& arcRef(ArcRef& map) {
    1016       _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc, 
    1017                           ArcRefMap, ArcRef>(map));
     1016      _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc,
     1017                          ArcRefMap, ArcRef>(map));
    10181018      return *this;
    10191019    }
     
    10261026    GraphCopy& arcCrossRef(ArcCrossRef& map) {
    10271027      _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc,
    1028                           ArcRefMap, ArcCrossRef>(map));
     1028                          ArcRefMap, ArcCrossRef>(map));
    10291029      return *this;
    10301030    }
     
    10321032    /// \brief Make copy of the given map.
    10331033    ///
    1034     /// Makes copy of the given map for the newly created graph. 
     1034    /// Makes copy of the given map for the newly created graph.
    10351035    /// The new map's key type is the to graph's arc type,
    10361036    /// and the copied map's key type is the from graph's arc
    1037     /// type. 
     1037    /// type.
    10381038    template <typename ToMap, typename FromMap>
    10391039    GraphCopy& arcMap(ToMap& tmap, const FromMap& map) {
    1040       _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc, 
    1041                           ArcRefMap, ToMap, FromMap>(tmap, map));
     1040      _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc,
     1041                          ArcRefMap, ToMap, FromMap>(tmap, map));
    10421042      return *this;
    10431043    }
     
    10471047    /// Make a copy of the given arc.
    10481048    GraphCopy& arc(TArc& tarc, const Arc& sarc) {
    1049       _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc, 
    1050                           ArcRefMap, TArc>(tarc, sarc));
     1049      _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc,
     1050                          ArcRefMap, TArc>(tarc, sarc));
    10511051      return *this;
    10521052    }
     
    10571057    template <typename EdgeRef>
    10581058    GraphCopy& edgeRef(EdgeRef& map) {
    1059       _edge_maps.push_back(new _graph_utils_bits::RefCopy<From, Edge, 
    1060                            EdgeRefMap, EdgeRef>(map));
     1059      _edge_maps.push_back(new _graph_utils_bits::RefCopy<From, Edge,
     1060                           EdgeRefMap, EdgeRef>(map));
    10611061      return *this;
    10621062    }
     
    10681068    template <typename EdgeCrossRef>
    10691069    GraphCopy& edgeCrossRef(EdgeCrossRef& map) {
    1070       _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, 
    1071                            Edge, EdgeRefMap, EdgeCrossRef>(map));
     1070      _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy<From,
     1071                           Edge, EdgeRefMap, EdgeCrossRef>(map));
    10721072      return *this;
    10731073    }
     
    10751075    /// \brief Make copy of the given map.
    10761076    ///
    1077     /// Makes copy of the given map for the newly created graph. 
     1077    /// Makes copy of the given map for the newly created graph.
    10781078    /// The new map's key type is the to graph's edge type,
    10791079    /// and the copied map's key type is the from graph's edge
    1080     /// type. 
     1080    /// type.
    10811081    template <typename ToMap, typename FromMap>
    10821082    GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
    1083       _edge_maps.push_back(new _graph_utils_bits::MapCopy<From, Edge, 
    1084                            EdgeRefMap, ToMap, FromMap>(tmap, map));
     1083      _edge_maps.push_back(new _graph_utils_bits::MapCopy<From, Edge,
     1084                           EdgeRefMap, ToMap, FromMap>(tmap, map));
    10851085      return *this;
    10861086    }
     
    10901090    /// Make a copy of the given edge.
    10911091    GraphCopy& edge(TEdge& tedge, const Edge& sedge) {
    1092       _edge_maps.push_back(new _graph_utils_bits::ItemCopy<From, Edge, 
    1093                            EdgeRefMap, TEdge>(tedge, sedge));
     1092      _edge_maps.push_back(new _graph_utils_bits::ItemCopy<From, Edge,
     1093                           EdgeRefMap, TEdge>(tedge, sedge));
    10941094      return *this;
    10951095    }
     
    11161116
    11171117  private:
    1118    
     1118
    11191119    const From& _from;
    11201120    To& _to;
    11211121
    1122     std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
     1122    std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* >
    11231123    _node_maps;
    11241124
    1125     std::vector<_graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 
     1125    std::vector<_graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* >
    11261126    _arc_maps;
    11271127
    1128     std::vector<_graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
     1128    std::vector<_graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* >
    11291129    _edge_maps;
    11301130
     
    11391139  /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run();
    11401140  ///\endcode
    1141   /// 
     1141  ///
    11421142  /// After the copy the \c nr map will contain the mapping from the
    11431143  /// nodes of the \c from graph to the nodes of the \c to graph and
     
    11451145  /// to the arcs of the \c from graph.
    11461146  ///
    1147   /// \see GraphCopy 
     1147  /// \see GraphCopy
    11481148  template <typename To, typename From>
    1149   GraphCopy<To, From> 
     1149  GraphCopy<To, From>
    11501150  copyGraph(To& to, const From& from) {
    11511151    return GraphCopy<To, From>(to, from);
     
    12151215      ///
    12161216      /// Gives back the given item from its id.
    1217       /// 
     1217      ///
    12181218      Item operator[](int id) const { return _graph->fromId(id, Item());}
    12191219
     
    12251225    ///
    12261226    /// Gives back the inverse of the IdMap.
    1227     InverseMap inverse() const { return InverseMap(*_graph);} 
     1227    InverseMap inverse() const { return InverseMap(*_graph);}
    12281228
    12291229  };
    12301230
    1231  
     1231
    12321232  /// \brief General invertable graph-map type.
    12331233
    1234   /// This type provides simple invertable graph-maps. 
    1235   /// The InvertableMap wraps an arbitrary ReadWriteMap 
     1234  /// This type provides simple invertable graph-maps.
     1235  /// The InvertableMap wraps an arbitrary ReadWriteMap
    12361236  /// and if a key is set to a new value then store it
    12371237  /// in the inverse map.
     
    12481248  class InvertableMap : protected DefaultMap<_Graph, _Item, _Value> {
    12491249  private:
    1250    
     1250
    12511251    typedef DefaultMap<_Graph, _Item, _Value> Map;
    12521252    typedef _Graph Graph;
    12531253
    12541254    typedef std::map<_Value, _Item> Container;
    1255     Container _inv_map;   
     1255    Container _inv_map;
    12561256
    12571257  public:
    1258  
     1258
    12591259    /// The key type of InvertableMap (Node, Arc, Edge).
    12601260    typedef typename Map::Key Key;
     
    12681268    /// Construct a new InvertableMap for the graph.
    12691269    ///
    1270     explicit InvertableMap(const Graph& graph) : Map(graph) {} 
     1270    explicit InvertableMap(const Graph& graph) : Map(graph) {}
    12711271
    12721272    /// \brief Forward iterator for values.
     
    12761276    /// be accessed in the [beginValue, endValue) range.
    12771277    ///
    1278     class ValueIterator 
     1278    class ValueIterator
    12791279      : public std::iterator<std::forward_iterator_tag, Value> {
    12801280      friend class InvertableMap;
    12811281    private:
    1282       ValueIterator(typename Container::const_iterator _it) 
     1282      ValueIterator(typename Container::const_iterator _it)
    12831283        : it(_it) {}
    12841284    public:
    1285      
     1285
    12861286      ValueIterator() {}
    12871287
    12881288      ValueIterator& operator++() { ++it; return *this; }
    1289       ValueIterator operator++(int) { 
    1290         ValueIterator tmp(*this); 
     1289      ValueIterator operator++(int) {
     1290        ValueIterator tmp(*this);
    12911291        operator++();
    1292         return tmp; 
     1292        return tmp;
    12931293      }
    12941294
     
    12981298      bool operator==(ValueIterator jt) const { return it == jt.it; }
    12991299      bool operator!=(ValueIterator jt) const { return it != jt.it; }
    1300      
     1300
    13011301    private:
    13021302      typename Container::const_iterator it;
     
    13051305    /// \brief Returns an iterator to the first value.
    13061306    ///
    1307     /// Returns an stl compatible iterator to the 
     1307    /// Returns an stl compatible iterator to the
    13081308    /// first value of the map. The values of the
    13091309    /// map can be accessed in the [beginValue, endValue)
     
    13151315    /// \brief Returns an iterator after the last value.
    13161316    ///
    1317     /// Returns an stl compatible iterator after the 
     1317    /// Returns an stl compatible iterator after the
    13181318    /// last value of the map. The values of the
    13191319    /// map can be accessed in the [beginValue, endValue)
     
    13221322      return ValueIterator(_inv_map.end());
    13231323    }
    1324    
     1324
    13251325    /// \brief The setter function of the map.
    13261326    ///
     
    13301330      typename Container::iterator it = _inv_map.find(oldval);
    13311331      if (it != _inv_map.end() && it->second == key) {
    1332         _inv_map.erase(it);
    1333       }     
     1332        _inv_map.erase(it);
     1333      }
    13341334      _inv_map.insert(make_pair(val, key));
    13351335      Map::set(key, val);
     
    13391339    ///
    13401340    /// It gives back the value associated with the key.
    1341     typename MapTraits<Map>::ConstReturnValue 
     1341    typename MapTraits<Map>::ConstReturnValue
    13421342    operator[](const Key& key) const {
    13431343      return Map::operator[](key);
     
    13621362      typename Container::iterator it = _inv_map.find(val);
    13631363      if (it != _inv_map.end() && it->second == key) {
    1364         _inv_map.erase(it);
     1364        _inv_map.erase(it);
    13651365      }
    13661366      Map::erase(key);
     
    13731373    virtual void erase(const std::vector<Key>& keys) {
    13741374      for (int i = 0; i < int(keys.size()); ++i) {
    1375         Value val = Map::operator[](keys[i]);
    1376         typename Container::iterator it = _inv_map.find(val);
    1377         if (it != _inv_map.end() && it->second == keys[i]) {
    1378           _inv_map.erase(it);
    1379         }
     1375        Value val = Map::operator[](keys[i]);
     1376        typename Container::iterator it = _inv_map.find(val);
     1377        if (it != _inv_map.end() && it->second == keys[i]) {
     1378          _inv_map.erase(it);
     1379        }
    13801380      }
    13811381      Map::erase(keys);
     
    13961396    ///
    13971397    /// The inverse of this map. The subscript operator of the map
    1398     /// gives back always the item what was last assigned to the value. 
     1398    /// gives back always the item what was last assigned to the value.
    13991399    class InverseMap {
    14001400    public:
     
    14021402      ///
    14031403      /// Constructor of the InverseMap.
    1404       explicit InverseMap(const InvertableMap& inverted) 
     1404      explicit InverseMap(const InvertableMap& inverted)
    14051405        : _inverted(inverted) {}
    14061406
     
    14081408      typedef typename InvertableMap::Key Value;
    14091409      /// The key type of the InverseMap.
    1410       typedef typename InvertableMap::Value Key; 
    1411 
    1412       /// \brief Subscript operator. 
     1410      typedef typename InvertableMap::Value Key;
     1411
     1412      /// \brief Subscript operator.
    14131413      ///
    1414       /// Subscript operator. It gives back always the item 
     1414      /// Subscript operator. It gives back always the item
    14151415      /// what was last assigned to the value.
    14161416      Value operator[](const Key& key) const {
    1417         return _inverted(key);
    1418       }
    1419      
     1417        return _inverted(key);
     1418      }
     1419
    14201420    private:
    14211421      const InvertableMap& _inverted;
     
    14271427    InverseMap inverse() const {
    14281428      return InverseMap(*this);
    1429     } 
    1430 
    1431 
    1432    
     1429    }
     1430
     1431
     1432
    14331433  };
    14341434
    1435   /// \brief Provides a mutable, continuous and unique descriptor for each 
     1435  /// \brief Provides a mutable, continuous and unique descriptor for each
    14361436  /// item in the graph.
    14371437  ///
     
    14461446  ///
    14471447  /// \tparam _Graph The graph class the \c DescriptorMap belongs to.
    1448   /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or 
     1448  /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or
    14491449  /// Edge.
    14501450  template <typename _Graph, typename _Item>
     
    14681468    explicit DescriptorMap(const Graph& _graph) : Map(_graph) {
    14691469      Item it;
    1470       const typename Map::Notifier* nf = Map::notifier(); 
     1470      const typename Map::Notifier* nf = Map::notifier();
    14711471      for (nf->first(it); it != INVALID; nf->next(it)) {
    1472         Map::set(it, _inv_map.size());
    1473         _inv_map.push_back(it);
    1474       }     
     1472        Map::set(it, _inv_map.size());
     1473        _inv_map.push_back(it);
     1474      }
    14751475    }
    14761476
     
    14941494      Map::add(items);
    14951495      for (int i = 0; i < int(items.size()); ++i) {
    1496         Map::set(items[i], _inv_map.size());
    1497         _inv_map.push_back(items[i]);
     1496        Map::set(items[i], _inv_map.size());
     1497        _inv_map.push_back(items[i]);
    14981498      }
    14991499    }
     
    15161516    virtual void erase(const std::vector<Item>& items) {
    15171517      for (int i = 0; i < int(items.size()); ++i) {
    1518         Map::set(_inv_map.back(), Map::operator[](items[i]));
    1519         _inv_map[Map::operator[](items[i])] = _inv_map.back();
    1520         _inv_map.pop_back();
     1518        Map::set(_inv_map.back(), Map::operator[](items[i]));
     1519        _inv_map[Map::operator[](items[i])] = _inv_map.back();
     1520        _inv_map.pop_back();
    15211521      }
    15221522      Map::erase(items);
     
    15301530      Map::build();
    15311531      Item it;
    1532       const typename Map::Notifier* nf = Map::notifier(); 
     1532      const typename Map::Notifier* nf = Map::notifier();
    15331533      for (nf->first(it); it != INVALID; nf->next(it)) {
    1534         Map::set(it, _inv_map.size());
    1535         _inv_map.push_back(it);
    1536       }     
    1537     }
    1538    
     1534        Map::set(it, _inv_map.size());
     1535        _inv_map.push_back(it);
     1536      }
     1537    }
     1538
    15391539    /// \brief Clear the keys from the map.
    15401540    ///
     
    15801580      return _inv_map[id];
    15811581    }
    1582    
     1582
    15831583  private:
    15841584
     
    15951595      ///
    15961596      /// Constructor of the InverseMap.
    1597       explicit InverseMap(const DescriptorMap& inverted) 
    1598         : _inverted(inverted) {}
     1597      explicit InverseMap(const DescriptorMap& inverted)
     1598        : _inverted(inverted) {}
    15991599
    16001600
     
    16021602      typedef typename DescriptorMap::Key Value;
    16031603      /// The key type of the InverseMap.
    1604       typedef typename DescriptorMap::Value Key; 
    1605 
    1606       /// \brief Subscript operator. 
     1604      typedef typename DescriptorMap::Value Key;
     1605
     1606      /// \brief Subscript operator.
    16071607      ///
    1608       /// Subscript operator. It gives back the item 
     1608      /// Subscript operator. It gives back the item
    16091609      /// that the descriptor belongs to currently.
    16101610      Value operator[](const Key& key) const {
    1611         return _inverted(key);
     1611        return _inverted(key);
    16121612      }
    16131613
     
    16161616      /// Returns the size of the map.
    16171617      unsigned int size() const {
    1618         return _inverted.size();
    1619       }
    1620      
     1618        return _inverted.size();
     1619      }
     1620
    16211621    private:
    16221622      const DescriptorMap& _inverted;
     
    16331633  /// \brief Returns the source of the given arc.
    16341634  ///
    1635   /// The SourceMap gives back the source Node of the given arc. 
     1635  /// The SourceMap gives back the source Node of the given arc.
    16361636  /// \see TargetMap
    16371637  template <typename Digraph>
     
    16511651    ///
    16521652    /// The subscript operator.
    1653     /// \param arc The arc 
    1654     /// \return The source of the arc 
     1653    /// \param arc The arc
     1654    /// \return The source of the arc
    16551655    Value operator[](const Key& arc) const {
    16561656      return _digraph.source(arc);
     
    16681668  inline SourceMap<Digraph> sourceMap(const Digraph& digraph) {
    16691669    return SourceMap<Digraph>(digraph);
    1670   } 
     1670  }
    16711671
    16721672  /// \brief Returns the target of the given arc.
    16731673  ///
    1674   /// The TargetMap gives back the target Node of the given arc. 
     1674  /// The TargetMap gives back the target Node of the given arc.
    16751675  /// \see SourceMap
    16761676  template <typename Digraph>
     
    16901690    ///
    16911691    /// The subscript operator.
    1692     /// \param e The arc 
    1693     /// \return The target of the arc 
     1692    /// \param e The arc
     1693    /// \return The target of the arc
    16941694    Value operator[](const Key& e) const {
    16951695      return _digraph.target(e);
     
    17291729    ///
    17301730    /// The subscript operator.
    1731     /// \param key An edge 
    1732     /// \return The "forward" directed arc view of edge 
     1731    /// \param key An edge
     1732    /// \return The "forward" directed arc view of edge
    17331733    Value operator[](const Key& key) const {
    17341734      return _graph.direct(key, true);
     
    17681768    ///
    17691769    /// The subscript operator.
    1770     /// \param key An edge 
    1771     /// \return The "backward" directed arc view of edge 
     1770    /// \param key An edge
     1771    /// \return The "backward" directed arc view of edge
    17721772    Value operator[](const Key& key) const {
    17731773      return _graph.direct(key, false);
     
    18011801    ///
    18021802    /// Contructor of the map
    1803     explicit PotentialDifferenceMap(const Digraph& digraph, 
    1804                                     const NodeMap& potential) 
     1803    explicit PotentialDifferenceMap(const Digraph& digraph,
     1804                                    const NodeMap& potential)
    18051805      : _digraph(digraph), _potential(potential) {}
    18061806
     
    18091809    /// Const subscription operator
    18101810    Value operator[](const Key& arc) const {
    1811       return _potential[_digraph.target(arc)] - 
    1812         _potential[_digraph.source(arc)];
     1811      return _potential[_digraph.target(arc)] -
     1812        _potential[_digraph.source(arc)];
    18131813    }
    18141814
     
    18231823  /// \relates PotentialDifferenceMap
    18241824  template <typename Digraph, typename NodeMap>
    1825   PotentialDifferenceMap<Digraph, NodeMap> 
     1825  PotentialDifferenceMap<Digraph, NodeMap>
    18261826  potentialDifferenceMap(const Digraph& digraph, const NodeMap& potential) {
    18271827    return PotentialDifferenceMap<Digraph, NodeMap>(digraph, potential);
     
    18461846
    18471847  template <typename _Digraph>
    1848   class InDegMap 
     1848  class InDegMap
    18491849    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
    18501850      ::ItemNotifier::ObserverBase {
    18511851
    18521852  public:
    1853    
     1853
    18541854    typedef _Digraph Digraph;
    18551855    typedef int Value;
     
    18671867
    18681868      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
    1869      
     1869
    18701870      virtual void add(const Key& key) {
    1871         Parent::add(key);
    1872         Parent::set(key, 0);
     1871        Parent::add(key);
     1872        Parent::set(key, 0);
    18731873      }
    18741874
    18751875      virtual void add(const std::vector<Key>& keys) {
    1876         Parent::add(keys);
    1877         for (int i = 0; i < int(keys.size()); ++i) {
    1878           Parent::set(keys[i], 0);
    1879         }
     1876        Parent::add(keys);
     1877        for (int i = 0; i < int(keys.size()); ++i) {
     1878          Parent::set(keys[i], 0);
     1879        }
    18801880      }
    18811881
    18821882      virtual void build() {
    1883         Parent::build();
    1884         Key it;
    1885         typename Parent::Notifier* nf = Parent::notifier();
    1886         for (nf->first(it); it != INVALID; nf->next(it)) {
    1887           Parent::set(it, 0);
    1888         }
     1883        Parent::build();
     1884        Key it;
     1885        typename Parent::Notifier* nf = Parent::notifier();
     1886        for (nf->first(it); it != INVALID; nf->next(it)) {
     1887          Parent::set(it, 0);
     1888        }
    18891889      }
    18901890    };
     
    18951895    ///
    18961896    /// Constructor for creating in-degree map.
    1897     explicit InDegMap(const Digraph& digraph) 
     1897    explicit InDegMap(const Digraph& digraph)
    18981898      : _digraph(digraph), _deg(digraph) {
    18991899      Parent::attach(_digraph.notifier(typename Digraph::Arc()));
    1900      
     1900
    19011901      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    1902         _deg[it] = countInArcs(_digraph, it);
    1903       }
    1904     }
    1905    
     1902        _deg[it] = countInArcs(_digraph, it);
     1903      }
     1904    }
     1905
    19061906    /// Gives back the in-degree of a Node.
    19071907    int operator[](const Key& key) const {
     
    19101910
    19111911  protected:
    1912    
     1912
    19131913    typedef typename Digraph::Arc Arc;
    19141914
     
    19351935    virtual void build() {
    19361936      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    1937         _deg[it] = countInArcs(_digraph, it);
    1938       }     
     1937        _deg[it] = countInArcs(_digraph, it);
     1938      }
    19391939    }
    19401940
    19411941    virtual void clear() {
    19421942      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    1943         _deg[it] = 0;
     1943        _deg[it] = 0;
    19441944      }
    19451945    }
    19461946  private:
    1947    
     1947
    19481948    const Digraph& _digraph;
    19491949    AutoNodeMap _deg;
     
    19681968
    19691969  template <typename _Digraph>
    1970   class OutDegMap 
     1970  class OutDegMap
    19711971    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
    19721972      ::ItemNotifier::ObserverBase {
    19731973
    19741974  public:
    1975    
     1975
    19761976    typedef _Digraph Digraph;
    19771977    typedef int Value;
     
    19891989
    19901990      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
    1991      
     1991
    19921992      virtual void add(const Key& key) {
    1993         Parent::add(key);
    1994         Parent::set(key, 0);
     1993        Parent::add(key);
     1994        Parent::set(key, 0);
    19951995      }
    19961996      virtual void add(const std::vector<Key>& keys) {
    1997         Parent::add(keys);
    1998         for (int i = 0; i < int(keys.size()); ++i) {
    1999           Parent::set(keys[i], 0);
    2000         }
     1997        Parent::add(keys);
     1998        for (int i = 0; i < int(keys.size()); ++i) {
     1999          Parent::set(keys[i], 0);
     2000        }
    20012001      }
    20022002      virtual void build() {
    2003         Parent::build();
    2004         Key it;
    2005         typename Parent::Notifier* nf = Parent::notifier();
    2006         for (nf->first(it); it != INVALID; nf->next(it)) {
    2007           Parent::set(it, 0);
    2008         }
     2003        Parent::build();
     2004        Key it;
     2005        typename Parent::Notifier* nf = Parent::notifier();
     2006        for (nf->first(it); it != INVALID; nf->next(it)) {
     2007          Parent::set(it, 0);
     2008        }
    20092009      }
    20102010    };
     
    20152015    ///
    20162016    /// Constructor for creating out-degree map.
    2017     explicit OutDegMap(const Digraph& digraph) 
     2017    explicit OutDegMap(const Digraph& digraph)
    20182018      : _digraph(digraph), _deg(digraph) {
    20192019      Parent::attach(_digraph.notifier(typename Digraph::Arc()));
    2020      
     2020
    20212021      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    2022         _deg[it] = countOutArcs(_digraph, it);
     2022        _deg[it] = countOutArcs(_digraph, it);
    20232023      }
    20242024    }
     
    20302030
    20312031  protected:
    2032    
     2032
    20332033    typedef typename Digraph::Arc Arc;
    20342034
     
    20552055    virtual void build() {
    20562056      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    2057         _deg[it] = countOutArcs(_digraph, it);
    2058       }     
     2057        _deg[it] = countOutArcs(_digraph, it);
     2058      }
    20592059    }
    20602060
    20612061    virtual void clear() {
    20622062      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
    2063         _deg[it] = 0;
     2063        _deg[it] = 0;
    20642064      }
    20652065    }
    20662066  private:
    2067    
     2067
    20682068    const Digraph& _digraph;
    20692069    AutoNodeMap _deg;
     
    20722072
    20732073  ///Dynamic arc look up between given endpoints.
    2074  
     2074
    20752075  ///\ingroup gutils
    20762076  ///Using this class, you can find an arc in a digraph from a given
     
    20902090  ///queries.
    20912091  ///
    2092   ///\tparam G The type of the underlying digraph. 
    2093   ///
    2094   ///\sa ArcLookUp 
    2095   ///\sa AllArcLookUp 
     2092  ///\tparam G The type of the underlying digraph.
     2093  ///
     2094  ///\sa ArcLookUp
     2095  ///\sa AllArcLookUp
    20962096  template<class G>
    2097   class DynArcLookUp 
     2097  class DynArcLookUp
    20982098    : protected ItemSetTraits<G, typename G::Arc>::ItemNotifier::ObserverBase
    20992099  {
     
    21132113
    21142114      AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {}
    2115      
     2115
    21162116      virtual void add(const Node& node) {
    2117         Parent::add(node);
    2118         Parent::set(node, INVALID);
     2117        Parent::add(node);
     2118        Parent::set(node, INVALID);
    21192119      }
    21202120
    21212121      virtual void add(const std::vector<Node>& nodes) {
    2122         Parent::add(nodes);
    2123         for (int i = 0; i < int(nodes.size()); ++i) {
    2124           Parent::set(nodes[i], INVALID);
    2125         }
     2122        Parent::add(nodes);
     2123        for (int i = 0; i < int(nodes.size()); ++i) {
     2124          Parent::set(nodes[i], INVALID);
     2125        }
    21262126      }
    21272127
    21282128      virtual void build() {
    2129         Parent::build();
    2130         Node it;
    2131         typename Parent::Notifier* nf = Parent::notifier();
    2132         for (nf->first(it); it != INVALID; nf->next(it)) {
    2133           Parent::set(it, INVALID);
    2134         }
     2129        Parent::build();
     2130        Node it;
     2131        typename Parent::Notifier* nf = Parent::notifier();
     2132        for (nf->first(it); it != INVALID; nf->next(it)) {
     2133          Parent::set(it, INVALID);
     2134        }
    21352135      }
    21362136    };
     
    21412141    typename Digraph::template ArcMap<Arc> _left;
    21422142    typename Digraph::template ArcMap<Arc> _right;
    2143    
     2143
    21442144    class ArcLess {
    21452145      const Digraph &g;
    21462146    public:
    21472147      ArcLess(const Digraph &_g) : g(_g) {}
    2148       bool operator()(Arc a,Arc b) const 
     2148      bool operator()(Arc a,Arc b) const
    21492149      {
    2150         return g.target(a)<g.target(b);
    2151       }
    2152     };
    2153    
     2150        return g.target(a)<g.target(b);
     2151      }
     2152    };
     2153
    21542154  public:
    2155    
     2155
    21562156    ///Constructor
    21572157
     
    21592159    ///
    21602160    ///It builds up the search database.
    2161     DynArcLookUp(const Digraph &g) 
    2162       : _g(g),_head(g),_parent(g),_left(g),_right(g) 
    2163     { 
     2161    DynArcLookUp(const Digraph &g)
     2162      : _g(g),_head(g),_parent(g),_left(g),_right(g)
     2163    {
    21642164      Parent::attach(_g.notifier(typename Digraph::Arc()));
    2165       refresh(); 
    2166     }
    2167    
     2165      refresh();
     2166    }
     2167
    21682168  protected:
    21692169
     
    21742174    virtual void add(const std::vector<Arc>& arcs) {
    21752175      for (int i = 0; i < int(arcs.size()); ++i) {
    2176         insert(arcs[i]);
     2176        insert(arcs[i]);
    21772177      }
    21782178    }
     
    21842184    virtual void erase(const std::vector<Arc>& arcs) {
    21852185      for (int i = 0; i < int(arcs.size()); ++i) {
    2186         remove(arcs[i]);
    2187       }     
     2186        remove(arcs[i]);
     2187      }
    21882188    }
    21892189
     
    21942194    virtual void clear() {
    21952195      for(NodeIt n(_g);n!=INVALID;++n) {
    2196         _head.set(n, INVALID);
     2196        _head.set(n, INVALID);
    21972197      }
    21982198    }
     
    22032203      _left.set(arc, INVALID);
    22042204      _right.set(arc, INVALID);
    2205      
     2205
    22062206      Arc e = _head[s];
    22072207      if (e == INVALID) {
    2208         _head.set(s, arc);
    2209         _parent.set(arc, INVALID);
    2210         return;
     2208        _head.set(s, arc);
     2209        _parent.set(arc, INVALID);
     2210        return;
    22112211      }
    22122212      while (true) {
    2213         if (t < _g.target(e)) {
    2214           if (_left[e] == INVALID) {
    2215             _left.set(e, arc);
    2216             _parent.set(arc, e);
    2217             splay(arc);
    2218             return;
    2219           } else {
    2220             e = _left[e];
    2221           }
    2222         } else {
    2223           if (_right[e] == INVALID) {
    2224             _right.set(e, arc);
    2225             _parent.set(arc, e);
    2226             splay(arc);
    2227             return;
    2228           } else {
    2229             e = _right[e];
    2230           }
    2231         }
     2213        if (t < _g.target(e)) {
     2214          if (_left[e] == INVALID) {
     2215            _left.set(e, arc);
     2216            _parent.set(arc, e);
     2217            splay(arc);
     2218            return;
     2219          } else {
     2220            e = _left[e];
     2221          }
     2222        } else {
     2223          if (_right[e] == INVALID) {
     2224            _right.set(e, arc);
     2225            _parent.set(arc, e);
     2226            splay(arc);
     2227            return;
     2228          } else {
     2229            e = _right[e];
     2230          }
     2231        }
    22322232      }
    22332233    }
     
    22352235    void remove(Arc arc) {
    22362236      if (_left[arc] == INVALID) {
    2237         if (_right[arc] != INVALID) {
    2238           _parent.set(_right[arc], _parent[arc]);
    2239         }
    2240         if (_parent[arc] != INVALID) {
    2241           if (_left[_parent[arc]] == arc) {
    2242             _left.set(_parent[arc], _right[arc]);
    2243           } else {
    2244             _right.set(_parent[arc], _right[arc]);
    2245           }
    2246         } else {
    2247           _head.set(_g.source(arc), _right[arc]);
    2248         }
     2237        if (_right[arc] != INVALID) {
     2238          _parent.set(_right[arc], _parent[arc]);
     2239        }
     2240        if (_parent[arc] != INVALID) {
     2241          if (_left[_parent[arc]] == arc) {
     2242            _left.set(_parent[arc], _right[arc]);
     2243          } else {
     2244            _right.set(_parent[arc], _right[arc]);
     2245          }
     2246        } else {
     2247          _head.set(_g.source(arc), _right[arc]);
     2248        }
    22492249      } else if (_right[arc] == INVALID) {
    2250         _parent.set(_left[arc], _parent[arc]);
    2251         if (_parent[arc] != INVALID) {
    2252           if (_left[_parent[arc]] == arc) {
    2253             _left.set(_parent[arc], _left[arc]);
    2254           } else {
    2255             _right.set(_parent[arc], _left[arc]);
    2256           }
    2257         } else {
    2258           _head.set(_g.source(arc), _left[arc]);
    2259         }
     2250        _parent.set(_left[arc], _parent[arc]);
     2251        if (_parent[arc] != INVALID) {
     2252          if (_left[_parent[arc]] == arc) {
     2253            _left.set(_parent[arc], _left[arc]);
     2254          } else {
     2255            _right.set(_parent[arc], _left[arc]);
     2256          }
     2257        } else {
     2258          _head.set(_g.source(arc), _left[arc]);
     2259        }
    22602260      } else {
    2261         Arc e = _left[arc];
    2262         if (_right[e] != INVALID) {
    2263           e = _right[e];         
    2264           while (_right[e] != INVALID) {
    2265             e = _right[e];
    2266           }
    2267           Arc s = _parent[e];
    2268           _right.set(_parent[e], _left[e]);
    2269           if (_left[e] != INVALID) {
    2270             _parent.set(_left[e], _parent[e]);
    2271           }
    2272          
    2273           _left.set(e, _left[arc]);
    2274           _parent.set(_left[arc], e);
    2275           _right.set(e, _right[arc]);
    2276           _parent.set(_right[arc], e);
    2277 
    2278           _parent.set(e, _parent[arc]);
    2279           if (_parent[arc] != INVALID) {
    2280             if (_left[_parent[arc]] == arc) {
    2281               _left.set(_parent[arc], e);
    2282             } else {
    2283               _right.set(_parent[arc], e);
    2284             }
    2285           }
    2286           splay(s);
    2287         } else {
    2288           _right.set(e, _right[arc]);
    2289           _parent.set(_right[arc], e);
    2290 
    2291           if (_parent[arc] != INVALID) {
    2292             if (_left[_parent[arc]] == arc) {
    2293               _left.set(_parent[arc], e);
    2294             } else {
    2295               _right.set(_parent[arc], e);
    2296             }
    2297           } else {
    2298             _head.set(_g.source(arc), e);
    2299           }
    2300         }
    2301       }
    2302     }
    2303 
    2304     Arc refreshRec(std::vector<Arc> &v,int a,int b) 
     2261        Arc e = _left[arc];
     2262        if (_right[e] != INVALID) {
     2263          e = _right[e];
     2264          while (_right[e] != INVALID) {
     2265            e = _right[e];
     2266          }
     2267          Arc s = _parent[e];
     2268          _right.set(_parent[e], _left[e]);
     2269          if (_left[e] != INVALID) {
     2270            _parent.set(_left[e], _parent[e]);
     2271          }
     2272
     2273          _left.set(e, _left[arc]);
     2274          _parent.set(_left[arc], e);
     2275          _right.set(e, _right[arc]);
     2276          _parent.set(_right[arc], e);
     2277
     2278          _parent.set(e, _parent[arc]);
     2279          if (_parent[arc] != INVALID) {
     2280            if (_left[_parent[arc]] == arc) {
     2281              _left.set(_parent[arc], e);
     2282            } else {
     2283              _right.set(_parent[arc], e);
     2284            }
     2285          }
     2286          splay(s);
     2287        } else {
     2288          _right.set(e, _right[arc]);
     2289          _parent.set(_right[arc], e);
     2290
     2291          if (_parent[arc] != INVALID) {
     2292            if (_left[_parent[arc]] == arc) {
     2293              _left.set(_parent[arc], e);
     2294            } else {
     2295              _right.set(_parent[arc], e);
     2296            }
     2297          } else {
     2298            _head.set(_g.source(arc), e);
     2299          }
     2300        }
     2301      }
     2302    }
     2303
     2304    Arc refreshRec(std::vector<Arc> &v,int a,int b)
    23052305    {
    23062306      int m=(a+b)/2;
    23072307      Arc me=v[m];
    23082308      if (a < m) {
    2309         Arc left = refreshRec(v,a,m-1);
    2310         _left.set(me, left);
    2311         _parent.set(left, me);
     2309        Arc left = refreshRec(v,a,m-1);
     2310        _left.set(me, left);
     2311        _parent.set(left, me);
    23122312      } else {
    2313         _left.set(me, INVALID);
     2313        _left.set(me, INVALID);
    23142314      }
    23152315      if (m < b) {
    2316         Arc right = refreshRec(v,m+1,b);
    2317         _right.set(me, right);
    2318         _parent.set(right, me);
     2316        Arc right = refreshRec(v,m+1,b);
     2317        _right.set(me, right);
     2318        _parent.set(right, me);
    23192319      } else {
    2320         _right.set(me, INVALID);
     2320        _right.set(me, INVALID);
    23212321      }
    23222322      return me;
     
    23252325    void refresh() {
    23262326      for(NodeIt n(_g);n!=INVALID;++n) {
    2327         std::vector<Arc> v;
    2328         for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
    2329         if(v.size()) {
    2330           std::sort(v.begin(),v.end(),ArcLess(_g));
    2331           Arc head = refreshRec(v,0,v.size()-1);
    2332           _head.set(n, head);
    2333           _parent.set(head, INVALID);
    2334         }
    2335         else _head.set(n, INVALID);
    2336       }
    2337     }
    2338 
    2339     void zig(Arc v) {       
     2327        std::vector<Arc> v;
     2328        for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
     2329        if(v.size()) {
     2330          std::sort(v.begin(),v.end(),ArcLess(_g));
     2331          Arc head = refreshRec(v,0,v.size()-1);
     2332          _head.set(n, head);
     2333          _parent.set(head, INVALID);
     2334        }
     2335        else _head.set(n, INVALID);
     2336      }
     2337    }
     2338
     2339    void zig(Arc v) {
    23402340      Arc w = _parent[v];
    23412341      _parent.set(v, _parent[w]);
     
    23442344      _right.set(v, w);
    23452345      if (_parent[v] != INVALID) {
    2346         if (_right[_parent[v]] == w) {
    2347           _right.set(_parent[v], v);
    2348         } else {
    2349           _left.set(_parent[v], v);
    2350         }
     2346        if (_right[_parent[v]] == w) {
     2347          _right.set(_parent[v], v);
     2348        } else {
     2349          _left.set(_parent[v], v);
     2350        }
    23512351      }
    23522352      if (_left[w] != INVALID){
    2353         _parent.set(_left[w], w);
    2354       }
    2355     }
    2356 
    2357     void zag(Arc v) {       
     2353        _parent.set(_left[w], w);
     2354      }
     2355    }
     2356
     2357    void zag(Arc v) {
    23582358      Arc w = _parent[v];
    23592359      _parent.set(v, _parent[w]);
     
    23622362      _left.set(v, w);
    23632363      if (_parent[v] != INVALID){
    2364         if (_left[_parent[v]] == w) {
    2365           _left.set(_parent[v], v);
    2366         } else {
    2367           _right.set(_parent[v], v);
    2368         }
     2364        if (_left[_parent[v]] == w) {
     2365          _left.set(_parent[v], v);
     2366        } else {
     2367          _right.set(_parent[v], v);
     2368        }
    23692369      }
    23702370      if (_right[w] != INVALID){
    2371         _parent.set(_right[w], w);
     2371        _parent.set(_right[w], w);
    23722372      }
    23732373    }
     
    23752375    void splay(Arc v) {
    23762376      while (_parent[v] != INVALID) {
    2377         if (v == _left[_parent[v]]) {
    2378           if (_parent[_parent[v]] == INVALID) {
    2379             zig(v);
    2380           } else {
    2381             if (_parent[v] == _left[_parent[_parent[v]]]) {
    2382               zig(_parent[v]);
    2383               zig(v);
    2384             } else {
    2385               zig(v);
    2386               zag(v);
    2387             }
    2388           }
    2389         } else {
    2390           if (_parent[_parent[v]] == INVALID) {
    2391             zag(v);
    2392           } else {
    2393             if (_parent[v] == _left[_parent[_parent[v]]]) {
    2394               zag(v);
    2395               zig(v);
    2396             } else {
    2397               zag(_parent[v]);
    2398               zag(v);
    2399             }
    2400           }
    2401         }
     2377        if (v == _left[_parent[v]]) {
     2378          if (_parent[_parent[v]] == INVALID) {
     2379            zig(v);
     2380          } else {
     2381            if (_parent[v] == _left[_parent[_parent[v]]]) {
     2382              zig(_parent[v]);
     2383              zig(v);
     2384            } else {
     2385              zig(v);
     2386              zag(v);
     2387            }
     2388          }
     2389        } else {
     2390          if (_parent[_parent[v]] == INVALID) {
     2391            zag(v);
     2392          } else {
     2393            if (_parent[v] == _left[_parent[_parent[v]]]) {
     2394              zag(v);
     2395              zig(v);
     2396            } else {
     2397              zag(_parent[v]);
     2398              zag(v);
     2399            }
     2400          }
     2401        }
    24022402      }
    24032403      _head[_g.source(v)] = v;
     
    24062406
    24072407  public:
    2408    
     2408
    24092409    ///Find an arc between two nodes.
    2410    
     2410
    24112411    ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where
    24122412    /// <em>d</em> is the number of outgoing arcs of \c s.
     
    24192419      Arc a = _head[s];
    24202420      while (true) {
    2421         if (_g.target(a) == t) {
    2422           const_cast<DynArcLookUp&>(*this).splay(a);
    2423           return a;
    2424         } else if (t < _g.target(a)) {
    2425           if (_left[a] == INVALID) {
    2426             const_cast<DynArcLookUp&>(*this).splay(a);
    2427             return INVALID;
    2428           } else {
    2429             a = _left[a];
    2430           }
    2431         } else  {
    2432           if (_right[a] == INVALID) {
    2433             const_cast<DynArcLookUp&>(*this).splay(a);
    2434             return INVALID;
    2435           } else {
    2436             a = _right[a];
    2437           }
    2438         }
     2421        if (_g.target(a) == t) {
     2422          const_cast<DynArcLookUp&>(*this).splay(a);
     2423          return a;
     2424        } else if (t < _g.target(a)) {
     2425          if (_left[a] == INVALID) {
     2426            const_cast<DynArcLookUp&>(*this).splay(a);
     2427            return INVALID;
     2428          } else {
     2429            a = _left[a];
     2430          }
     2431        } else  {
     2432          if (_right[a] == INVALID) {
     2433            const_cast<DynArcLookUp&>(*this).splay(a);
     2434            return INVALID;
     2435          } else {
     2436            a = _right[a];
     2437          }
     2438        }
    24392439      }
    24402440    }
    24412441
    24422442    ///Find the first arc between two nodes.
    2443    
     2443
    24442444    ///Find the first arc between two nodes in time
    24452445    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
    2446     /// outgoing arcs of \c s. 
    2447     ///\param s The source node 
     2446    /// outgoing arcs of \c s.
     2447    ///\param s The source node
    24482448    ///\param t The target node
    24492449    ///\return An arc from \c s to \c t if there exists, \ref INVALID
     
    24542454      Arc r = INVALID;
    24552455      while (true) {
    2456         if (_g.target(a) < t) {
    2457           if (_right[a] == INVALID) {
    2458             const_cast<DynArcLookUp&>(*this).splay(a);
    2459             return r;
    2460           } else {
    2461             a = _right[a];
    2462           }
    2463         } else {
    2464           if (_g.target(a) == t) {
    2465             r = a;
    2466           }
    2467           if (_left[a] == INVALID) {
    2468             const_cast<DynArcLookUp&>(*this).splay(a);
    2469             return r;
    2470           } else {
    2471             a = _left[a];
    2472           }
    2473         }
     2456        if (_g.target(a) < t) {
     2457          if (_right[a] == INVALID) {
     2458            const_cast<DynArcLookUp&>(*this).splay(a);
     2459            return r;
     2460          } else {
     2461            a = _right[a];
     2462          }
     2463        } else {
     2464          if (_g.target(a) == t) {
     2465            r = a;
     2466          }
     2467          if (_left[a] == INVALID) {
     2468            const_cast<DynArcLookUp&>(*this).splay(a);
     2469            return r;
     2470          } else {
     2471            a = _left[a];
     2472          }
     2473        }
    24742474      }
    24752475    }
    24762476
    24772477    ///Find the next arc between two nodes.
    2478    
     2478
    24792479    ///Find the next arc between two nodes in time
    24802480    /// <em>O(</em>log<em>d)</em>, where <em>d</em> is the number of
    2481     /// outgoing arcs of \c s. 
    2482     ///\param s The source node 
     2481    /// outgoing arcs of \c s.
     2482    ///\param s The source node
    24832483    ///\param t The target node
    24842484    ///\return An arc from \c s to \c t if there exists, \ref INVALID
     
    24942494    {
    24952495      if (_right[a] != INVALID) {
    2496         a = _right[a];
    2497         while (_left[a] != INVALID) {
    2498           a = _left[a];
    2499         }
    2500         const_cast<DynArcLookUp&>(*this).splay(a);
     2496        a = _right[a];
     2497        while (_left[a] != INVALID) {
     2498          a = _left[a];
     2499        }
     2500        const_cast<DynArcLookUp&>(*this).splay(a);
    25012501      } else {
    2502         while (_parent[a] != INVALID && _right[_parent[a]] ==  a) {
    2503           a = _parent[a];
    2504         }
    2505         if (_parent[a] == INVALID) {
    2506           return INVALID;
    2507         } else {
    2508           a = _parent[a];
    2509           const_cast<DynArcLookUp&>(*this).splay(a);
    2510         }
     2502        while (_parent[a] != INVALID && _right[_parent[a]] ==  a) {
     2503          a = _parent[a];
     2504        }
     2505        if (_parent[a] == INVALID) {
     2506          return INVALID;
     2507        } else {
     2508          a = _parent[a];
     2509          const_cast<DynArcLookUp&>(*this).splay(a);
     2510        }
    25112511      }
    25122512      if (_g.target(a) == t) return a;
    2513       else return INVALID;   
     2513      else return INVALID;
    25142514    }
    25152515
     
    25172517
    25182518  ///Fast arc look up between given endpoints.
    2519  
     2519
    25202520  ///\ingroup gutils
    25212521  ///Using this class, you can find an arc in a digraph from a given
     
    25342534  ///
    25352535  ///\sa DynArcLookUp
    2536   ///\sa AllArcLookUp 
     2536  ///\sa AllArcLookUp
    25372537  template<class G>
    2538   class ArcLookUp 
     2538  class ArcLookUp
    25392539  {
    25402540  public:
     
    25472547    typename Digraph::template ArcMap<Arc> _left;
    25482548    typename Digraph::template ArcMap<Arc> _right;
    2549    
     2549
    25502550    class ArcLess {
    25512551      const Digraph &g;
    25522552    public:
    25532553      ArcLess(const Digraph &_g) : g(_g) {}
    2554       bool operator()(Arc a,Arc b) const 
     2554      bool operator()(Arc a,Arc b) const
    25552555      {
    2556         return g.target(a)<g.target(b);
    2557       }
    2558     };
    2559    
     2556        return g.target(a)<g.target(b);
     2557      }
     2558    };
     2559
    25602560  public:
    2561    
     2561
    25622562    ///Constructor
    25632563
     
    25672567    ///changes.
    25682568    ArcLookUp(const Digraph &g) :_g(g),_head(g),_left(g),_right(g) {refresh();}
    2569    
     2569
    25702570  private:
    2571     Arc refreshRec(std::vector<Arc> &v,int a,int b) 
     2571    Arc refreshRec(std::vector<Arc> &v,int a,int b)
    25722572    {
    25732573      int m=(a+b)/2;
     
    25842584    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
    25852585    ///the number of the outgoing arcs of \c n.
    2586     void refresh(Node n) 
     2586    void refresh(Node n)
    25872587    {
    25882588      std::vector<Arc> v;
    25892589      for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e);
    25902590      if(v.size()) {
    2591         std::sort(v.begin(),v.end(),ArcLess(_g));
    2592         _head[n]=refreshRec(v,0,v.size()-1);
     2591        std::sort(v.begin(),v.end(),ArcLess(_g));
     2592        _head[n]=refreshRec(v,0,v.size()-1);
    25932593      }
    25942594      else _head[n]=INVALID;
     
    26032603    ///out-degree of the digraph.
    26042604
    2605     void refresh() 
     2605    void refresh()
    26062606    {
    26072607      for(NodeIt n(_g);n!=INVALID;++n) refresh(n);
    26082608    }
    2609    
     2609
    26102610    ///Find an arc between two nodes.
    2611    
     2611
    26122612    ///Find an arc between two nodes in time <em>O(</em>log<em>d)</em>, where
    26132613    /// <em>d</em> is the number of outgoing arcs of \c s.
     
    26262626      Arc e;
    26272627      for(e=_head[s];
    2628           e!=INVALID&&_g.target(e)!=t;
    2629           e = t < _g.target(e)?_left[e]:_right[e]) ;
     2628          e!=INVALID&&_g.target(e)!=t;
     2629          e = t < _g.target(e)?_left[e]:_right[e]) ;
    26302630      return e;
    26312631    }
     
    26342634
    26352635  ///Fast look up of all arcs between given endpoints.
    2636  
     2636
    26372637  ///\ingroup gutils
    26382638  ///This class is the same as \ref ArcLookUp, with the addition
     
    26472647  ///
    26482648  ///\sa DynArcLookUp
    2649   ///\sa ArcLookUp 
     2649  ///\sa ArcLookUp
    26502650  template<class G>
    26512651  class AllArcLookUp : public ArcLookUp<G>
     
    26582658    TEMPLATE_DIGRAPH_TYPEDEFS(G);
    26592659    typedef G Digraph;
    2660    
     2660
    26612661    typename Digraph::template ArcMap<Arc> _next;
    2662    
     2662
    26632663    Arc refreshNext(Arc head,Arc next=INVALID)
    26642664    {
    26652665      if(head==INVALID) return next;
    26662666      else {
    2667         next=refreshNext(_right[head],next);
    2668 //      _next[head]=next;
    2669         _next[head]=( next!=INVALID && _g.target(next)==_g.target(head))
    2670           ? next : INVALID;
    2671         return refreshNext(_left[head],head);
    2672       }
    2673     }
    2674    
     2667        next=refreshNext(_right[head],next);
     2668//         _next[head]=next;
     2669        _next[head]=( next!=INVALID && _g.target(next)==_g.target(head))
     2670          ? next : INVALID;
     2671        return refreshNext(_left[head],head);
     2672      }
     2673    }
     2674
    26752675    void refreshNext()
    26762676    {
    26772677      for(NodeIt n(_g);n!=INVALID;++n) refreshNext(_head[n]);
    26782678    }
    2679    
     2679
    26802680  public:
    26812681    ///Constructor
     
    26932693    ///It runs in time <em>O(d</em>log<em>d)</em>, where <em>d</em> is
    26942694    ///the number of the outgoing arcs of \c n.
    2695    
    2696     void refresh(Node n) 
     2695
     2696    void refresh(Node n)
    26972697    {
    26982698      ArcLookUp<G>::refresh(n);
    26992699      refreshNext(_head[n]);
    27002700    }
    2701    
     2701
    27022702    ///Refresh the full data structure.
    27032703
     
    27092709    ///out-degree of the digraph.
    27102710
    2711     void refresh() 
     2711    void refresh()
    27122712    {
    27132713      for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]);
    27142714    }
    2715    
     2715
    27162716    ///Find an arc between two nodes.
    2717    
     2717
    27182718    ///Find an arc between two nodes.
    27192719    ///\param s The source node
     
    27512751    }
    27522752#endif
    2753      
     2753
    27542754  };
    27552755
  • lemon/kruskal.h

    r194 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4646    template <typename Digraph, typename In, typename Out>
    4747    typename disable_if<lemon::UndirectedTagIndicator<Digraph>,
    48                        typename In::value_type::second_type >::type
     48                       typename In::value_type::second_type >::type
    4949    kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) {
    5050      typedef typename In::value_type::second_type Value;
    5151      typedef typename Digraph::template NodeMap<int> IndexMap;
    5252      typedef typename Digraph::Node Node;
    53      
     53
    5454      IndexMap index(digraph);
    5555      UnionFind<IndexMap> uf(index);
     
    5757        uf.insert(it);
    5858      }
    59      
     59
    6060      Value tree_value = 0;
    6161      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
     
    7575    template <typename Graph, typename In, typename Out>
    7676    typename enable_if<lemon::UndirectedTagIndicator<Graph>,
    77                        typename In::value_type::second_type >::type
     77                       typename In::value_type::second_type >::type
    7878    kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) {
    7979      typedef typename In::value_type::second_type Value;
    8080      typedef typename Graph::template NodeMap<int> IndexMap;
    8181      typedef typename Graph::Node Node;
    82      
     82
    8383      IndexMap index(graph);
    8484      UnionFind<IndexMap> uf(index);
     
    8686        uf.insert(it);
    8787      }
    88      
     88
    8989      Value tree_value = 0;
    9090      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
     
    105105      typedef typename Sequence::value_type Value;
    106106      bool operator()(const Value& left, const Value& right) {
    107         return left.second < right.second;
     107        return left.second < right.second;
    108108      }
    109109    };
     
    115115
    116116    template <typename In>
    117     struct SequenceInputIndicator<In, 
     117    struct SequenceInputIndicator<In,
    118118      typename exists<typename In::value_type::first_type>::type> {
    119119      static const bool value = true;
     
    126126
    127127    template <typename In>
    128     struct MapInputIndicator<In, 
     128    struct MapInputIndicator<In,
    129129      typename exists<typename In::Value>::type> {
    130130      static const bool value = true;
     
    135135      static const bool value = false;
    136136    };
    137  
     137
    138138    template <typename Out>
    139     struct SequenceOutputIndicator<Out, 
     139    struct SequenceOutputIndicator<Out,
    140140      typename exists<typename Out::value_type>::type> {
    141141      static const bool value = true;
     
    148148
    149149    template <typename Out>
    150     struct MapOutputIndicator<Out, 
     150    struct MapOutputIndicator<Out,
    151151      typename exists<typename Out::Value>::type> {
    152152      static const bool value = true;
     
    158158    template <typename In>
    159159    struct KruskalValueSelector<In,
    160       typename enable_if<SequenceInputIndicator<In>, void>::type> 
    161     {
    162       typedef typename In::value_type::second_type Value;
    163     };   
     160      typename enable_if<SequenceInputIndicator<In>, void>::type>
     161    {
     162      typedef typename In::value_type::second_type Value;
     163    };
    164164
    165165    template <typename In>
    166166    struct KruskalValueSelector<In,
    167       typename enable_if<MapInputIndicator<In>, void>::type> 
     167      typename enable_if<MapInputIndicator<In>, void>::type>
    168168    {
    169169      typedef typename In::Value Value;
    170     };   
    171    
     170    };
     171
    172172    template <typename Graph, typename In, typename Out,
    173173              typename InEnable = void>
     
    177177              typename InEnable = void>
    178178    struct KruskalOutputSelector {};
    179    
     179
    180180    template <typename Graph, typename In, typename Out>
    181181    struct KruskalInputSelector<Graph, In, Out,
    182       typename enable_if<SequenceInputIndicator<In>, void>::type > 
     182      typename enable_if<SequenceInputIndicator<In>, void>::type >
    183183    {
    184184      typedef typename In::value_type::second_type Value;
     
    193193    template <typename Graph, typename In, typename Out>
    194194    struct KruskalInputSelector<Graph, In, Out,
    195       typename enable_if<MapInputIndicator<In>, void>::type > 
     195      typename enable_if<MapInputIndicator<In>, void>::type >
    196196    {
    197197      typedef typename In::Value Value;
     
    202202        typedef std::vector<std::pair<MapArc, Value> > Sequence;
    203203        Sequence seq;
    204        
     204
    205205        for (MapArcIt it(graph); it != INVALID; ++it) {
    206206          seq.push_back(std::make_pair(it, in[it]));
     
    225225    template <typename Graph, typename In, typename Out>
    226226    struct KruskalOutputSelector<Graph, In, Out,
    227       typename enable_if<SequenceOutputIndicator<Out>, void>::type > 
     227      typename enable_if<SequenceOutputIndicator<Out>, void>::type >
    228228    {
    229229      typedef typename In::value_type::second_type Value;
     
    239239    template <typename Graph, typename In, typename Out>
    240240    struct KruskalOutputSelector<Graph, In, Out,
    241       typename enable_if<MapOutputIndicator<Out>, void>::type > 
     241      typename enable_if<MapOutputIndicator<Out>, void>::type >
    242242    {
    243243      typedef typename In::value_type::second_type Value;
     
    255255  /// a graph.
    256256  ///
    257   /// This function runs Kruskal's algorithm to find a minimum cost 
     257  /// This function runs Kruskal's algorithm to find a minimum cost
    258258  /// spanning tree.
    259259  /// Due to some C++ hacking, it accepts various input and output types.
    260260  ///
    261261  /// \param g The graph the algorithm runs on.
    262   /// It can be either \ref concepts::Digraph "directed" or 
     262  /// It can be either \ref concepts::Digraph "directed" or
    263263  /// \ref concepts::Graph "undirected".
    264   /// If the graph is directed, the algorithm consider it to be 
     264  /// If the graph is directed, the algorithm consider it to be
    265265  /// undirected by disregarding the direction of the arcs.
    266266  ///
    267   /// \param in This object is used to describe the arc/edge costs. 
     267  /// \param in This object is used to describe the arc/edge costs.
    268268  /// It can be one of the following choices.
    269269  /// - An STL compatible 'Forward Container' with
     
    273273  /// along with the assigned cost. <em>They must be in a
    274274  /// cost-ascending order.</em>
    275   /// - Any readable arc/edge map. The values of the map indicate the 
     275  /// - Any readable arc/edge map. The values of the map indicate the
    276276  /// arc/edge costs.
    277277  ///
     
    293293  ///\endcode
    294294  /// Or if we don't know in advance the size of the tree, we can
    295   /// write this. 
     295  /// write this.
    296296  ///\code
    297297  /// std::vector<Arc> tree;
    298   /// kruskal(g,cost,std::back_inserter(tree)); 
     298  /// kruskal(g,cost,std::back_inserter(tree));
    299299  ///\endcode
    300300  ///
     
    308308  template <class Graph, class In, class Out>
    309309  Value kruskal(GR const& g, const In& in, Out& out)
    310 #else 
     310#else
    311311  template <class Graph, class In, class Out>
    312   inline typename _kruskal_bits::KruskalValueSelector<In>::Value 
    313   kruskal(const Graph& graph, const In& in, Out& out) 
     312  inline typename _kruskal_bits::KruskalValueSelector<In>::Value
     313  kruskal(const Graph& graph, const In& in, Out& out)
    314314#endif
    315315  {
     
    318318  }
    319319
    320  
    321  
     320
     321
    322322
    323323  template <class Graph, class In, class Out>
     
    327327    return _kruskal_bits::KruskalInputSelector<Graph, In, const Out>::
    328328      kruskal(graph, in, out);
    329   } 
     329  }
    330330
    331331} //namespace lemon
  • lemon/lgf_reader.h

    r201 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4747    struct DefaultConverter {
    4848      Value operator()(const std::string& str) {
    49         std::istringstream is(str);
    50         Value value;
    51         is >> value;
    52 
    53         char c;
    54         if (is >> std::ws >> c) {
    55           throw DataFormatError("Remaining characters in token");
    56         }
    57         return value;
     49        std::istringstream is(str);
     50        Value value;
     51        is >> value;
     52
     53        char c;
     54        if (is >> std::ws >> c) {
     55          throw DataFormatError("Remaining characters in token");
     56        }
     57        return value;
    5858      }
    5959    };
     
    6262    struct DefaultConverter<std::string> {
    6363      std::string operator()(const std::string& str) {
    64         return str;
     64        return str;
    6565      }
    6666    };
    6767
    68     template <typename _Item>   
     68    template <typename _Item>
    6969    class MapStorageBase {
    7070    public:
     
    7979    };
    8080
    81     template <typename _Item, typename _Map, 
    82               typename _Converter = DefaultConverter<typename _Map::Value> >
     81    template <typename _Item, typename _Map,
     82              typename _Converter = DefaultConverter<typename _Map::Value> >
    8383    class MapStorage : public MapStorageBase<_Item> {
    8484    public:
     
    8686      typedef _Converter Converter;
    8787      typedef _Item Item;
    88      
     88
    8989    private:
    9090      Map& _map;
     
    9292
    9393    public:
    94       MapStorage(Map& map, const Converter& converter = Converter()) 
    95         : _map(map), _converter(converter) {}
     94      MapStorage(Map& map, const Converter& converter = Converter())
     95        : _map(map), _converter(converter) {}
    9696      virtual ~MapStorage() {}
    9797
    9898      virtual void set(const Item& item ,const std::string& value) {
    99         _map.set(item, _converter(value));
     99        _map.set(item, _converter(value));
    100100      }
    101101    };
    102102
    103     template <typename _Graph, bool _dir, typename _Map, 
    104               typename _Converter = DefaultConverter<typename _Map::Value> >
     103    template <typename _Graph, bool _dir, typename _Map,
     104              typename _Converter = DefaultConverter<typename _Map::Value> >
    105105    class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
    106106    public:
     
    110110      typedef typename Graph::Edge Item;
    111111      static const bool dir = _dir;
    112      
     112
    113113    private:
    114114      const Graph& _graph;
     
    117117
    118118    public:
    119       GraphArcMapStorage(const Graph& graph, Map& map, 
    120                          const Converter& converter = Converter())
    121         : _graph(graph), _map(map), _converter(converter) {}
     119      GraphArcMapStorage(const Graph& graph, Map& map,
     120                         const Converter& converter = Converter())
     121        : _graph(graph), _map(map), _converter(converter) {}
    122122      virtual ~GraphArcMapStorage() {}
    123123
    124124      virtual void set(const Item& item ,const std::string& value) {
    125         _map.set(_graph.direct(item, dir), _converter(value));
     125        _map.set(_graph.direct(item, dir), _converter(value));
    126126      }
    127127    };
     
    147147    public:
    148148      ValueStorage(Value& value, const Converter& converter = Converter())
    149         : _value(value), _converter(converter) {}
     149         : _value(value), _converter(converter) {}
    150150
    151151      virtual void set(const std::string& value) {
    152         _value = _converter(value);
     152        _value = _converter(value);
    153153      }
    154154    };
     
    177177      const Graph& _graph;
    178178      const std::map<std::string, typename Graph::Edge>& _map;
    179      
    180       GraphArcLookUpConverter(const Graph& graph, 
    181                               const std::map<std::string,
    182                                              typename Graph::Edge>& map)
    183         : _graph(graph), _map(map) {}
    184      
     179
     180      GraphArcLookUpConverter(const Graph& graph,
     181                              const std::map<std::string,
     182                                             typename Graph::Edge>& map)
     183        : _graph(graph), _map(map) {}
     184
    185185      typename Graph::Arc operator()(const std::string& str) {
    186         if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    187           throw DataFormatError("Item must start with '+' or '-'");
    188         }
    189         typename std::map<std::string, typename Graph::Edge>
    190           ::const_iterator it = _map.find(str.substr(1));
    191         if (it == _map.end()) {
    192           throw DataFormatError("Item not found");
    193         }
    194         return _graph.direct(it->second, str[0] == '+');
     186        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
     187          throw DataFormatError("Item must start with '+' or '-'");
     188        }
     189        typename std::map<std::string, typename Graph::Edge>
     190          ::const_iterator it = _map.find(str.substr(1));
     191        if (it == _map.end()) {
     192          throw DataFormatError("Item not found");
     193        }
     194        return _graph.direct(it->second, str[0] == '+');
    195195      }
    196196    };
    197197
    198198    inline bool isWhiteSpace(char c) {
    199       return c == ' ' || c == '\t' || c == '\v' || 
    200         c == '\n' || c == '\r' || c == '\f'; 
    201     }
    202    
     199      return c == ' ' || c == '\t' || c == '\v' ||
     200        c == '\n' || c == '\r' || c == '\f';
     201    }
     202
    203203    inline bool isOct(char c) {
    204       return '0' <= c && c <='7'; 
    205     }
    206    
     204      return '0' <= c && c <='7';
     205    }
     206
    207207    inline int valueOct(char c) {
    208208      LEMON_ASSERT(isOct(c), "The character is not octal.");
     
    211211
    212212    inline bool isHex(char c) {
    213       return ('0' <= c && c <= '9') || 
    214         ('a' <= c && c <= 'z') ||
    215         ('A' <= c && c <= 'Z');
    216     }
    217    
     213      return ('0' <= c && c <= '9') ||
     214        ('a' <= c && c <= 'z') ||
     215        ('A' <= c && c <= 'Z');
     216    }
     217
    218218    inline int valueHex(char c) {
    219219      LEMON_ASSERT(isHex(c), "The character is not hexadecimal.");
     
    225225    inline bool isIdentifierFirstChar(char c) {
    226226      return ('a' <= c && c <= 'z') ||
    227         ('A' <= c && c <= 'Z') || c == '_';
     227        ('A' <= c && c <= 'Z') || c == '_';
    228228    }
    229229
    230230    inline bool isIdentifierChar(char c) {
    231231      return isIdentifierFirstChar(c) ||
    232         ('0' <= c && c <= '9');
     232        ('0' <= c && c <= '9');
    233233    }
    234234
     
    236236      char c;
    237237      if (!is.get(c))
    238         throw DataFormatError("Escape format error");
     238        throw DataFormatError("Escape format error");
    239239
    240240      switch (c) {
    241241      case '\\':
    242         return '\\';
     242        return '\\';
    243243      case '\"':
    244         return '\"';
     244        return '\"';
    245245      case '\'':
    246         return '\'';
     246        return '\'';
    247247      case '\?':
    248         return '\?';
     248        return '\?';
    249249      case 'a':
    250         return '\a';
     250        return '\a';
    251251      case 'b':
    252         return '\b';
     252        return '\b';
    253253      case 'f':
    254         return '\f';
     254        return '\f';
    255255      case 'n':
    256         return '\n';
     256        return '\n';
    257257      case 'r':
    258         return '\r';
     258        return '\r';
    259259      case 't':
    260         return '\t';
     260        return '\t';
    261261      case 'v':
    262         return '\v';
     262        return '\v';
    263263      case 'x':
    264         {
    265           int code;
    266           if (!is.get(c) || !isHex(c))
    267             throw DataFormatError("Escape format error");
    268           else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
    269           else code = code * 16 + valueHex(c);
    270           return code;
    271         }
     264        {
     265          int code;
     266          if (!is.get(c) || !isHex(c))
     267            throw DataFormatError("Escape format error");
     268          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
     269          else code = code * 16 + valueHex(c);
     270          return code;
     271        }
    272272      default:
    273         {
    274           int code;
    275           if (!isOct(c))
    276             throw DataFormatError("Escape format error");
    277           else if (code = valueOct(c), !is.get(c) || !isOct(c))
    278             is.putback(c);
    279           else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
    280             is.putback(c);
    281           else code = code * 8 + valueOct(c);
    282           return code;
    283         }             
    284       } 
    285     }
    286    
     273        {
     274          int code;
     275          if (!isOct(c))
     276            throw DataFormatError("Escape format error");
     277          else if (code = valueOct(c), !is.get(c) || !isOct(c))
     278            is.putback(c);
     279          else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
     280            is.putback(c);
     281          else code = code * 8 + valueOct(c);
     282          return code;
     283        }
     284      }
     285    }
     286
    287287    inline std::istream& readToken(std::istream& is, std::string& str) {
    288288      std::ostringstream os;
     
    290290      char c;
    291291      is >> std::ws;
    292      
    293       if (!is.get(c)) 
    294         return is;
     292
     293      if (!is.get(c))
     294        return is;
    295295
    296296      if (c == '\"') {
    297         while (is.get(c) && c != '\"') {
    298           if (c == '\\')
    299             c = readEscape(is);
    300           os << c;
    301         }
    302         if (!is)
    303           throw DataFormatError("Quoted format error");
     297        while (is.get(c) && c != '\"') {
     298          if (c == '\\')
     299            c = readEscape(is);
     300          os << c;
     301        }
     302        if (!is)
     303          throw DataFormatError("Quoted format error");
    304304      } else {
    305         is.putback(c);
    306         while (is.get(c) && !isWhiteSpace(c)) {
    307           if (c == '\\')
    308             c = readEscape(is);
    309           os << c;
    310         }
    311         if (!is) {
    312           is.clear();
    313         } else {
    314           is.putback(c);
    315         }
     305        is.putback(c);
     306        while (is.get(c) && !isWhiteSpace(c)) {
     307          if (c == '\\')
     308            c = readEscape(is);
     309          os << c;
     310        }
     311        if (!is) {
     312          is.clear();
     313        } else {
     314          is.putback(c);
     315        }
    316316      }
    317317      str = os.str();
     
    332332
    333333    public:
    334      
     334
    335335      LineSection(const Functor& functor) : _functor(functor) {}
    336336      virtual ~LineSection() {}
    337337
    338338      virtual void process(std::istream& is, int& line_num) {
    339         char c;
    340         std::string line;
    341         while (is.get(c) && c != '@') {
    342           if (c == '\n') {
    343             ++line_num;
    344           } else if (c == '#') {
    345             getline(is, line);
    346             ++line_num;
    347           } else if (!isWhiteSpace(c)) {
    348             is.putback(c);
    349             getline(is, line);
    350             _functor(line);
    351             ++line_num;
    352           }
    353         }
    354         if (is) is.putback(c);
    355         else if (is.eof()) is.clear();
     339        char c;
     340        std::string line;
     341        while (is.get(c) && c != '@') {
     342          if (c == '\n') {
     343            ++line_num;
     344          } else if (c == '#') {
     345            getline(is, line);
     346            ++line_num;
     347          } else if (!isWhiteSpace(c)) {
     348            is.putback(c);
     349            getline(is, line);
     350            _functor(line);
     351            ++line_num;
     352          }
     353        }
     354        if (is) is.putback(c);
     355        else if (is.eof()) is.clear();
    356356      }
    357357    };
     
    364364
    365365    public:
    366      
     366
    367367      StreamSection(const Functor& functor) : _functor(functor) {}
    368       virtual ~StreamSection() {} 
     368      virtual ~StreamSection() {}
    369369
    370370      virtual void process(std::istream& is, int& line_num) {
    371         _functor(is, line_num);
    372         char c;
    373         std::string line;
    374         while (is.get(c) && c != '@') {
    375           if (c == '\n') {
    376             ++line_num;
    377           } else if (!isWhiteSpace(c)) {
    378             getline(is, line);
    379             ++line_num;
    380           }
    381         }
    382         if (is) is.putback(c);
    383         else if (is.eof()) is.clear(); 
     371        _functor(is, line_num);
     372        char c;
     373        std::string line;
     374        while (is.get(c) && c != '@') {
     375          if (c == '\n') {
     376            ++line_num;
     377          } else if (!isWhiteSpace(c)) {
     378            getline(is, line);
     379            ++line_num;
     380          }
     381        }
     382        if (is) is.putback(c);
     383        else if (is.eof()) is.clear();
    384384      }
    385385    };
    386    
     386
    387387  }
    388388
     
    400400
    401401  /// \ingroup lemon_io
    402   /// 
     402  ///
    403403  /// \brief \ref lgf-format "LGF" reader for directed graphs
    404404  ///
     
    454454    typedef _Digraph Digraph;
    455455    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    456    
     456
    457457  private:
    458458
     
    471471    typedef std::map<std::string, Arc> ArcIndex;
    472472    ArcIndex _arc_index;
    473    
    474     typedef std::vector<std::pair<std::string, 
    475       _reader_bits::MapStorageBase<Node>*> > NodeMaps;   
    476     NodeMaps _node_maps; 
     473
     474    typedef std::vector<std::pair<std::string,
     475      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
     476    NodeMaps _node_maps;
    477477
    478478    typedef std::vector<std::pair<std::string,
     
    480480    ArcMaps _arc_maps;
    481481
    482     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
     482    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*>
    483483      Attributes;
    484484    Attributes _attributes;
     
    499499    /// Construct a directed graph reader, which reads from the given
    500500    /// input stream.
    501     DigraphReader(std::istream& is, Digraph& digraph) 
     501    DigraphReader(std::istream& is, Digraph& digraph)
    502502      : _is(&is), local_is(false), _digraph(digraph),
    503         _use_nodes(false), _use_arcs(false),
    504         _skip_nodes(false), _skip_arcs(false) {}
     503        _use_nodes(false), _use_arcs(false),
     504        _skip_nodes(false), _skip_arcs(false) {}
    505505
    506506    /// \brief Constructor
     
    508508    /// Construct a directed graph reader, which reads from the given
    509509    /// file.
    510     DigraphReader(const std::string& fn, Digraph& digraph) 
     510    DigraphReader(const std::string& fn, Digraph& digraph)
    511511      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    512         _use_nodes(false), _use_arcs(false),
    513         _skip_nodes(false), _skip_arcs(false) {}
    514    
     512            _use_nodes(false), _use_arcs(false),
     513        _skip_nodes(false), _skip_arcs(false) {}
     514
    515515    /// \brief Constructor
    516516    ///
    517517    /// Construct a directed graph reader, which reads from the given
    518518    /// file.
    519     DigraphReader(const char* fn, Digraph& digraph) 
     519    DigraphReader(const char* fn, Digraph& digraph)
    520520      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    521         _use_nodes(false), _use_arcs(false),
    522         _skip_nodes(false), _skip_arcs(false) {}
     521            _use_nodes(false), _use_arcs(false),
     522        _skip_nodes(false), _skip_arcs(false) {}
    523523
    524524    /// \brief Destructor
    525525    ~DigraphReader() {
    526       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    527            it != _node_maps.end(); ++it) {
    528         delete it->second;
    529       }
    530 
    531       for (typename ArcMaps::iterator it = _arc_maps.begin(); 
    532            it != _arc_maps.end(); ++it) {
    533         delete it->second;
    534       }
    535 
    536       for (typename Attributes::iterator it = _attributes.begin(); 
    537            it != _attributes.end(); ++it) {
    538         delete it->second;
     526      for (typename NodeMaps::iterator it = _node_maps.begin();
     527           it != _node_maps.end(); ++it) {
     528        delete it->second;
     529      }
     530
     531      for (typename ArcMaps::iterator it = _arc_maps.begin();
     532           it != _arc_maps.end(); ++it) {
     533        delete it->second;
     534      }
     535
     536      for (typename Attributes::iterator it = _attributes.begin();
     537           it != _attributes.end(); ++it) {
     538        delete it->second;
    539539      }
    540540
    541541      if (local_is) {
    542         delete _is;
     542        delete _is;
    543543      }
    544544
     
    547547  private:
    548548
    549     friend DigraphReader<Digraph> digraphReader<>(std::istream& is, 
    550                                                   Digraph& digraph);   
    551     friend DigraphReader<Digraph> digraphReader<>(const std::string& fn, 
    552                                                   Digraph& digraph);   
    553     friend DigraphReader<Digraph> digraphReader<>(const char *fn, 
    554                                                   Digraph& digraph);   
    555 
    556     DigraphReader(DigraphReader& other) 
     549    friend DigraphReader<Digraph> digraphReader<>(std::istream& is,
     550                                                  Digraph& digraph);
     551    friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
     552                                                  Digraph& digraph);
     553    friend DigraphReader<Digraph> digraphReader<>(const char *fn,
     554                                                  Digraph& digraph);
     555
     556    DigraphReader(DigraphReader& other)
    557557      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    558         _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
    559         _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
     558        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
     559        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    560560
    561561      other._is = 0;
    562562      other.local_is = false;
    563      
     563
    564564      _node_index.swap(other._node_index);
    565565      _arc_index.swap(other._arc_index);
     
    581581    /// \name Reading rules
    582582    /// @{
    583    
     583
    584584    /// \brief Node map reading rule
    585585    ///
     
    588588    DigraphReader& nodeMap(const std::string& caption, Map& map) {
    589589      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    590       _reader_bits::MapStorageBase<Node>* storage = 
    591         new _reader_bits::MapStorage<Node, Map>(map);
     590      _reader_bits::MapStorageBase<Node>* storage =
     591        new _reader_bits::MapStorage<Node, Map>(map);
    592592      _node_maps.push_back(std::make_pair(caption, storage));
    593593      return *this;
     
    599599    /// reader.
    600600    template <typename Map, typename Converter>
    601     DigraphReader& nodeMap(const std::string& caption, Map& map, 
    602                            const Converter& converter = Converter()) {
     601    DigraphReader& nodeMap(const std::string& caption, Map& map,
     602                           const Converter& converter = Converter()) {
    603603      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    604       _reader_bits::MapStorageBase<Node>* storage = 
    605         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
     604      _reader_bits::MapStorageBase<Node>* storage =
     605        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
    606606      _node_maps.push_back(std::make_pair(caption, storage));
    607607      return *this;
     
    614614    DigraphReader& arcMap(const std::string& caption, Map& map) {
    615615      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    616       _reader_bits::MapStorageBase<Arc>* storage = 
    617         new _reader_bits::MapStorage<Arc, Map>(map);
     616      _reader_bits::MapStorageBase<Arc>* storage =
     617        new _reader_bits::MapStorage<Arc, Map>(map);
    618618      _arc_maps.push_back(std::make_pair(caption, storage));
    619619      return *this;
     
    625625    /// reader.
    626626    template <typename Map, typename Converter>
    627     DigraphReader& arcMap(const std::string& caption, Map& map, 
    628                           const Converter& converter = Converter()) {
     627    DigraphReader& arcMap(const std::string& caption, Map& map,
     628                          const Converter& converter = Converter()) {
    629629      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    630       _reader_bits::MapStorageBase<Arc>* storage = 
    631         new _reader_bits::MapStorage<Arc, Map, Converter>(map, converter);
     630      _reader_bits::MapStorageBase<Arc>* storage =
     631        new _reader_bits::MapStorage<Arc, Map, Converter>(map, converter);
    632632      _arc_maps.push_back(std::make_pair(caption, storage));
    633633      return *this;
     
    639639    template <typename Value>
    640640    DigraphReader& attribute(const std::string& caption, Value& value) {
    641       _reader_bits::ValueStorageBase* storage = 
    642         new _reader_bits::ValueStorage<Value>(value);
     641      _reader_bits::ValueStorageBase* storage =
     642        new _reader_bits::ValueStorage<Value>(value);
    643643      _attributes.insert(std::make_pair(caption, storage));
    644644      return *this;
     
    650650    /// reader.
    651651    template <typename Value, typename Converter>
    652     DigraphReader& attribute(const std::string& caption, Value& value, 
    653                              const Converter& converter = Converter()) {
    654       _reader_bits::ValueStorageBase* storage = 
    655         new _reader_bits::ValueStorage<Value, Converter>(value, converter);
     652    DigraphReader& attribute(const std::string& caption, Value& value,
     653                             const Converter& converter = Converter()) {
     654      _reader_bits::ValueStorageBase* storage =
     655        new _reader_bits::ValueStorage<Value, Converter>(value, converter);
    656656      _attributes.insert(std::make_pair(caption, storage));
    657657      return *this;
     
    664664      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    665665      Converter converter(_node_index);
    666       _reader_bits::ValueStorageBase* storage = 
    667         new _reader_bits::ValueStorage<Node, Converter>(node, converter);
     666      _reader_bits::ValueStorageBase* storage =
     667        new _reader_bits::ValueStorage<Node, Converter>(node, converter);
    668668      _attributes.insert(std::make_pair(caption, storage));
    669669      return *this;
     
    676676      typedef _reader_bits::MapLookUpConverter<Arc> Converter;
    677677      Converter converter(_arc_index);
    678       _reader_bits::ValueStorageBase* storage = 
    679         new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
     678      _reader_bits::ValueStorageBase* storage =
     679        new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
    680680      _attributes.insert(std::make_pair(caption, storage));
    681681      return *this;
     
    723723    DigraphReader& useNodes(const Map& map) {
    724724      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    725       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     725      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    726726      _use_nodes = true;
    727727      _writer_bits::DefaultConverter<typename Map::Value> converter;
    728728      for (NodeIt n(_digraph); n != INVALID; ++n) {
    729         _node_index.insert(std::make_pair(converter(map[n]), n));
     729        _node_index.insert(std::make_pair(converter(map[n]), n));
    730730      }
    731731      return *this;
     
    738738    /// \c std::string.
    739739    template <typename Map, typename Converter>
    740     DigraphReader& useNodes(const Map& map, 
    741                             const Converter& converter = Converter()) {
     740    DigraphReader& useNodes(const Map& map,
     741                            const Converter& converter = Converter()) {
    742742      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    743       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     743      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    744744      _use_nodes = true;
    745745      for (NodeIt n(_digraph); n != INVALID; ++n) {
    746         _node_index.insert(std::make_pair(converter(map[n]), n));
     746        _node_index.insert(std::make_pair(converter(map[n]), n));
    747747      }
    748748      return *this;
     
    760760      _writer_bits::DefaultConverter<typename Map::Value> converter;
    761761      for (ArcIt a(_digraph); a != INVALID; ++a) {
    762         _arc_index.insert(std::make_pair(converter(map[a]), a));
     762        _arc_index.insert(std::make_pair(converter(map[a]), a));
    763763      }
    764764      return *this;
     
    771771    /// \c std::string.
    772772    template <typename Map, typename Converter>
    773     DigraphReader& useArcs(const Map& map, 
    774                            const Converter& converter = Converter()) {
     773    DigraphReader& useArcs(const Map& map,
     774                           const Converter& converter = Converter()) {
    775775      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    776       LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member"); 
     776      LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member");
    777777      _use_arcs = true;
    778778      for (ArcIt a(_digraph); a != INVALID; ++a) {
    779         _arc_index.insert(std::make_pair(converter(map[a]), a));
     779        _arc_index.insert(std::make_pair(converter(map[a]), a));
    780780      }
    781781      return *this;
     
    791791    /// \c useNodes() should be used to specify the label of the nodes.
    792792    DigraphReader& skipNodes() {
    793       LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); 
     793      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
    794794      _skip_nodes = true;
    795795      return *this;
     
    802802    /// will not be constructed.
    803803    DigraphReader& skipArcs() {
    804       LEMON_ASSERT(!_skip_arcs, "Skip arcs already set"); 
     804      LEMON_ASSERT(!_skip_arcs, "Skip arcs already set");
    805805      _skip_arcs = true;
    806806      return *this;
     
    814814      std::string str;
    815815      while(++line_num, std::getline(*_is, str)) {
    816         line.clear(); line.str(str);
    817         char c;
    818         if (line >> std::ws >> c && c != '#') {
    819           line.putback(c);
    820           return true;
    821         }
     816        line.clear(); line.str(str);
     817        char c;
     818        if (line >> std::ws >> c && c != '#') {
     819          line.putback(c);
     820          return true;
     821        }
    822822      }
    823823      return false;
     
    827827      return static_cast<bool>(*_is);
    828828    }
    829    
     829
    830830    void skipSection() {
    831831      char c;
    832832      while (readSuccess() && line >> c && c != '@') {
    833         readLine();
     833        readLine();
    834834      }
    835835      line.putback(c);
     
    843843      char c;
    844844      if (!readLine() || !(line >> c) || c == '@') {
    845         if (readSuccess() && line) line.putback(c);
    846         if (!_node_maps.empty())
    847           throw DataFormatError("Cannot find map names");
    848         return;
     845        if (readSuccess() && line) line.putback(c);
     846        if (!_node_maps.empty())
     847          throw DataFormatError("Cannot find map names");
     848        return;
    849849      }
    850850      line.putback(c);
    851851
    852852      {
    853         std::map<std::string, int> maps;
    854        
    855         std::string map;
    856         int index = 0;
    857         while (_reader_bits::readToken(line, map)) {
    858           if (maps.find(map) != maps.end()) {
    859             std::ostringstream msg;
    860             msg << "Multiple occurence of node map: " << map;
    861             throw DataFormatError(msg.str().c_str());
    862           }
    863           maps.insert(std::make_pair(map, index));
    864           ++index;
    865         }
    866        
    867         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    868           std::map<std::string, int>::iterator jt =
    869             maps.find(_node_maps[i].first);
    870           if (jt == maps.end()) {
    871             std::ostringstream msg;
    872             msg << "Map not found in file: " << _node_maps[i].first;
    873             throw DataFormatError(msg.str().c_str());
    874           }
    875           map_index[i] = jt->second;
    876         }
    877 
    878         {
    879           std::map<std::string, int>::iterator jt = maps.find("label");
    880           if (jt != maps.end()) {
    881             label_index = jt->second;
    882           } else {
    883             label_index = -1;
    884           }
    885         }
    886         map_num = maps.size();
     853        std::map<std::string, int> maps;
     854
     855        std::string map;
     856        int index = 0;
     857        while (_reader_bits::readToken(line, map)) {
     858          if (maps.find(map) != maps.end()) {
     859            std::ostringstream msg;
     860            msg << "Multiple occurence of node map: " << map;
     861            throw DataFormatError(msg.str().c_str());
     862          }
     863          maps.insert(std::make_pair(map, index));
     864          ++index;
     865        }
     866
     867        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     868          std::map<std::string, int>::iterator jt =
     869            maps.find(_node_maps[i].first);
     870          if (jt == maps.end()) {
     871            std::ostringstream msg;
     872            msg << "Map not found in file: " << _node_maps[i].first;
     873            throw DataFormatError(msg.str().c_str());
     874          }
     875          map_index[i] = jt->second;
     876        }
     877
     878        {
     879          std::map<std::string, int>::iterator jt = maps.find("label");
     880          if (jt != maps.end()) {
     881            label_index = jt->second;
     882          } else {
     883            label_index = -1;
     884          }
     885        }
     886        map_num = maps.size();
    887887      }
    888888
    889889      while (readLine() && line >> c && c != '@') {
    890         line.putback(c);
    891 
    892         std::vector<std::string> tokens(map_num);
    893         for (int i = 0; i < map_num; ++i) {
    894           if (!_reader_bits::readToken(line, tokens[i])) {
    895             std::ostringstream msg;
    896             msg << "Column not found (" << i + 1 << ")";
    897             throw DataFormatError(msg.str().c_str());
    898           }
    899         }
    900         if (line >> std::ws >> c)
    901           throw DataFormatError("Extra character on the end of line");
    902        
    903         Node n;
    904         if (!_use_nodes) {
    905           n = _digraph.addNode();
    906           if (label_index != -1)
    907             _node_index.insert(std::make_pair(tokens[label_index], n));
    908         } else {
    909           if (label_index == -1)
    910             throw DataFormatError("Label map not found in file");
    911           typename std::map<std::string, Node>::iterator it =
    912             _node_index.find(tokens[label_index]);
    913           if (it == _node_index.end()) {
    914             std::ostringstream msg;
    915             msg << "Node with label not found: " << tokens[label_index];
    916             throw DataFormatError(msg.str().c_str());       
    917           }
    918           n = it->second;
    919         }
    920 
    921         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    922           _node_maps[i].second->set(n, tokens[map_index[i]]);
    923         }
     890        line.putback(c);
     891
     892        std::vector<std::string> tokens(map_num);
     893        for (int i = 0; i < map_num; ++i) {
     894          if (!_reader_bits::readToken(line, tokens[i])) {
     895            std::ostringstream msg;
     896            msg << "Column not found (" << i + 1 << ")";
     897            throw DataFormatError(msg.str().c_str());
     898          }
     899        }
     900        if (line >> std::ws >> c)
     901          throw DataFormatError("Extra character on the end of line");
     902
     903        Node n;
     904        if (!_use_nodes) {
     905          n = _digraph.addNode();
     906          if (label_index != -1)
     907            _node_index.insert(std::make_pair(tokens[label_index], n));
     908        } else {
     909          if (label_index == -1)
     910            throw DataFormatError("Label map not found in file");
     911          typename std::map<std::string, Node>::iterator it =
     912            _node_index.find(tokens[label_index]);
     913          if (it == _node_index.end()) {
     914            std::ostringstream msg;
     915            msg << "Node with label not found: " << tokens[label_index];
     916            throw DataFormatError(msg.str().c_str());
     917          }
     918          n = it->second;
     919        }
     920
     921        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     922          _node_maps[i].second->set(n, tokens[map_index[i]]);
     923        }
    924924
    925925      }
    926926      if (readSuccess()) {
    927         line.putback(c);
     927        line.putback(c);
    928928      }
    929929    }
     
    936936      char c;
    937937      if (!readLine() || !(line >> c) || c == '@') {
    938         if (readSuccess() && line) line.putback(c);
    939         if (!_arc_maps.empty())
    940           throw DataFormatError("Cannot find map names");
    941         return;
     938        if (readSuccess() && line) line.putback(c);
     939        if (!_arc_maps.empty())
     940          throw DataFormatError("Cannot find map names");
     941        return;
    942942      }
    943943      line.putback(c);
    944      
     944
    945945      {
    946         std::map<std::string, int> maps;
    947        
    948         std::string map;
    949         int index = 0;
    950         while (_reader_bits::readToken(line, map)) {
    951           if (maps.find(map) != maps.end()) {
    952             std::ostringstream msg;
    953             msg << "Multiple occurence of arc map: " << map;
    954             throw DataFormatError(msg.str().c_str());
    955           }
    956           maps.insert(std::make_pair(map, index));
    957           ++index;
    958         }
    959        
    960         for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
    961           std::map<std::string, int>::iterator jt =
    962             maps.find(_arc_maps[i].first);
    963           if (jt == maps.end()) {
    964             std::ostringstream msg;
    965             msg << "Map not found in file: " << _arc_maps[i].first;
    966             throw DataFormatError(msg.str().c_str());
    967           }
    968           map_index[i] = jt->second;
    969         }
    970 
    971         {
    972           std::map<std::string, int>::iterator jt = maps.find("label");
    973           if (jt != maps.end()) {
    974             label_index = jt->second;
    975           } else {
    976             label_index = -1;
    977           }
    978         }
    979         map_num = maps.size();
     946        std::map<std::string, int> maps;
     947
     948        std::string map;
     949        int index = 0;
     950        while (_reader_bits::readToken(line, map)) {
     951          if (maps.find(map) != maps.end()) {
     952            std::ostringstream msg;
     953            msg << "Multiple occurence of arc map: " << map;
     954            throw DataFormatError(msg.str().c_str());
     955          }
     956          maps.insert(std::make_pair(map, index));
     957          ++index;
     958        }
     959
     960        for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
     961          std::map<std::string, int>::iterator jt =
     962            maps.find(_arc_maps[i].first);
     963          if (jt == maps.end()) {
     964            std::ostringstream msg;
     965            msg << "Map not found in file: " << _arc_maps[i].first;
     966            throw DataFormatError(msg.str().c_str());
     967          }
     968          map_index[i] = jt->second;
     969        }
     970
     971        {
     972          std::map<std::string, int>::iterator jt = maps.find("label");
     973          if (jt != maps.end()) {
     974            label_index = jt->second;
     975          } else {
     976            label_index = -1;
     977          }
     978        }
     979        map_num = maps.size();
    980980      }
    981981
    982982      while (readLine() && line >> c && c != '@') {
    983         line.putback(c);
    984 
    985         std::string source_token;
    986         std::string target_token;
    987 
    988         if (!_reader_bits::readToken(line, source_token))
    989           throw DataFormatError("Source not found");
    990 
    991         if (!_reader_bits::readToken(line, target_token))
    992           throw DataFormatError("Target not found");
    993        
    994         std::vector<std::string> tokens(map_num);
    995         for (int i = 0; i < map_num; ++i) {
    996           if (!_reader_bits::readToken(line, tokens[i])) {
    997             std::ostringstream msg;
    998             msg << "Column not found (" << i + 1 << ")";
    999             throw DataFormatError(msg.str().c_str());
    1000           }
    1001         }
    1002         if (line >> std::ws >> c)
    1003           throw DataFormatError("Extra character on the end of line");
    1004        
    1005         Arc a;
    1006         if (!_use_arcs) {
     983        line.putback(c);
     984
     985        std::string source_token;
     986        std::string target_token;
     987
     988        if (!_reader_bits::readToken(line, source_token))
     989          throw DataFormatError("Source not found");
     990
     991        if (!_reader_bits::readToken(line, target_token))
     992          throw DataFormatError("Target not found");
     993
     994        std::vector<std::string> tokens(map_num);
     995        for (int i = 0; i < map_num; ++i) {
     996          if (!_reader_bits::readToken(line, tokens[i])) {
     997            std::ostringstream msg;
     998            msg << "Column not found (" << i + 1 << ")";
     999            throw DataFormatError(msg.str().c_str());
     1000          }
     1001        }
     1002        if (line >> std::ws >> c)
     1003          throw DataFormatError("Extra character on the end of line");
     1004
     1005        Arc a;
     1006        if (!_use_arcs) {
    10071007
    10081008          typename NodeIndex::iterator it;
    1009  
     1009
    10101010          it = _node_index.find(source_token);
    10111011          if (it == _node_index.end()) {
     
    10171017
    10181018          it = _node_index.find(target_token);
    1019           if (it == _node_index.end()) {       
    1020             std::ostringstream msg;           
     1019          if (it == _node_index.end()) {
     1020            std::ostringstream msg;
    10211021            msg << "Item not found: " << target_token;
    10221022            throw DataFormatError(msg.str().c_str());
    1023           }                                         
    1024           Node target = it->second;                           
    1025 
    1026           a = _digraph.addArc(source, target);
    1027           if (label_index != -1)
    1028             _arc_index.insert(std::make_pair(tokens[label_index], a));
    1029         } else {
    1030           if (label_index == -1)
    1031             throw DataFormatError("Label map not found in file");
    1032           typename std::map<std::string, Arc>::iterator it =
    1033             _arc_index.find(tokens[label_index]);
    1034           if (it == _arc_index.end()) {
    1035             std::ostringstream msg;
    1036             msg << "Arc with label not found: " << tokens[label_index];
    1037             throw DataFormatError(msg.str().c_str());       
    1038           }
    1039           a = it->second;
    1040         }
    1041 
    1042         for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
    1043           _arc_maps[i].second->set(a, tokens[map_index[i]]);
    1044         }
     1023          }
     1024          Node target = it->second;
     1025
     1026          a = _digraph.addArc(source, target);
     1027          if (label_index != -1)
     1028            _arc_index.insert(std::make_pair(tokens[label_index], a));
     1029        } else {
     1030          if (label_index == -1)
     1031            throw DataFormatError("Label map not found in file");
     1032          typename std::map<std::string, Arc>::iterator it =
     1033            _arc_index.find(tokens[label_index]);
     1034          if (it == _arc_index.end()) {
     1035            std::ostringstream msg;
     1036            msg << "Arc with label not found: " << tokens[label_index];
     1037            throw DataFormatError(msg.str().c_str());
     1038          }
     1039          a = it->second;
     1040        }
     1041
     1042        for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
     1043          _arc_maps[i].second->set(a, tokens[map_index[i]]);
     1044        }
    10451045
    10461046      }
    10471047      if (readSuccess()) {
    1048         line.putback(c);
     1048        line.putback(c);
    10491049      }
    10501050    }
     
    10561056      char c;
    10571057      while (readLine() && line >> c && c != '@') {
    1058         line.putback(c);
    1059        
    1060         std::string attr, token;
    1061         if (!_reader_bits::readToken(line, attr))
    1062           throw DataFormatError("Attribute name not found");
    1063         if (!_reader_bits::readToken(line, token))
    1064           throw DataFormatError("Attribute value not found");
    1065         if (line >> c)
    1066           throw DataFormatError("Extra character on the end of line");   
    1067 
    1068         {
    1069           std::set<std::string>::iterator it = read_attr.find(attr);
    1070           if (it != read_attr.end()) {
    1071             std::ostringstream msg;
    1072             msg << "Multiple occurence of attribute " << attr;
    1073             throw DataFormatError(msg.str().c_str());
    1074           }
    1075           read_attr.insert(attr);
    1076         }
    1077        
    1078         {
    1079           typename Attributes::iterator it = _attributes.lower_bound(attr);
    1080           while (it != _attributes.end() && it->first == attr) {
    1081             it->second->set(token);
    1082             ++it;
    1083           }
    1084         }
     1058        line.putback(c);
     1059
     1060        std::string attr, token;
     1061        if (!_reader_bits::readToken(line, attr))
     1062          throw DataFormatError("Attribute name not found");
     1063        if (!_reader_bits::readToken(line, token))
     1064          throw DataFormatError("Attribute value not found");
     1065        if (line >> c)
     1066          throw DataFormatError("Extra character on the end of line");
     1067
     1068        {
     1069          std::set<std::string>::iterator it = read_attr.find(attr);
     1070          if (it != read_attr.end()) {
     1071            std::ostringstream msg;
     1072            msg << "Multiple occurence of attribute " << attr;
     1073            throw DataFormatError(msg.str().c_str());
     1074          }
     1075          read_attr.insert(attr);
     1076        }
     1077
     1078        {
     1079          typename Attributes::iterator it = _attributes.lower_bound(attr);
     1080          while (it != _attributes.end() && it->first == attr) {
     1081            it->second->set(token);
     1082            ++it;
     1083          }
     1084        }
    10851085
    10861086      }
    10871087      if (readSuccess()) {
    1088         line.putback(c);
     1088        line.putback(c);
    10891089      }
    10901090      for (typename Attributes::iterator it = _attributes.begin();
    1091            it != _attributes.end(); ++it) {
    1092         if (read_attr.find(it->first) == read_attr.end()) {
    1093           std::ostringstream msg;
    1094           msg << "Attribute not found in file: " << it->first;
    1095           throw DataFormatError(msg.str().c_str());
    1096         }       
     1091           it != _attributes.end(); ++it) {
     1092        if (read_attr.find(it->first) == read_attr.end()) {
     1093          std::ostringstream msg;
     1094          msg << "Attribute not found in file: " << it->first;
     1095          throw DataFormatError(msg.str().c_str());
     1096        }
    10971097      }
    10981098    }
     
    11001100  public:
    11011101
    1102     /// \name Execution of the reader   
     1102    /// \name Execution of the reader
    11031103    /// @{
    11041104
     
    11091109      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    11101110      if (!*_is) {
    1111         throw DataFormatError("Cannot find file");
    1112       }
    1113      
     1111        throw DataFormatError("Cannot find file");
     1112      }
     1113
    11141114      bool nodes_done = _skip_nodes;
    11151115      bool arcs_done = _skip_arcs;
    11161116      bool attributes_done = false;
    11171117
    1118       line_num = 0;     
     1118      line_num = 0;
    11191119      readLine();
    11201120      skipSection();
    11211121
    11221122      while (readSuccess()) {
    1123         try {
    1124           char c;
    1125           std::string section, caption;
    1126           line >> c;
    1127           _reader_bits::readToken(line, section);
    1128           _reader_bits::readToken(line, caption);
    1129 
    1130           if (line >> c)
    1131             throw DataFormatError("Extra character on the end of line");
    1132 
    1133           if (section == "nodes" && !nodes_done) {
    1134             if (_nodes_caption.empty() || _nodes_caption == caption) {
    1135               readNodes();
    1136               nodes_done = true;
    1137             }
    1138           } else if ((section == "arcs" || section == "edges") &&
    1139                      !arcs_done) {
    1140             if (_arcs_caption.empty() || _arcs_caption == caption) {
    1141               readArcs();
    1142               arcs_done = true;
    1143             }
    1144           } else if (section == "attributes" && !attributes_done) {
    1145             if (_attributes_caption.empty() || _attributes_caption == caption) {
    1146               readAttributes();
    1147               attributes_done = true;
    1148             }
    1149           } else {
    1150             readLine();
    1151             skipSection();
    1152           }
    1153         } catch (DataFormatError& error) {
    1154           error.line(line_num);
    1155           throw;
    1156         }       
     1123        try {
     1124          char c;
     1125          std::string section, caption;
     1126          line >> c;
     1127          _reader_bits::readToken(line, section);
     1128          _reader_bits::readToken(line, caption);
     1129
     1130          if (line >> c)
     1131            throw DataFormatError("Extra character on the end of line");
     1132
     1133          if (section == "nodes" && !nodes_done) {
     1134            if (_nodes_caption.empty() || _nodes_caption == caption) {
     1135              readNodes();
     1136              nodes_done = true;
     1137            }
     1138          } else if ((section == "arcs" || section == "edges") &&
     1139                     !arcs_done) {
     1140            if (_arcs_caption.empty() || _arcs_caption == caption) {
     1141              readArcs();
     1142              arcs_done = true;
     1143            }
     1144          } else if (section == "attributes" && !attributes_done) {
     1145            if (_attributes_caption.empty() || _attributes_caption == caption) {
     1146              readAttributes();
     1147              attributes_done = true;
     1148            }
     1149          } else {
     1150            readLine();
     1151            skipSection();
     1152          }
     1153        } catch (DataFormatError& error) {
     1154          error.line(line_num);
     1155          throw;
     1156        }
    11571157      }
    11581158
    11591159      if (!nodes_done) {
    1160         throw DataFormatError("Section @nodes not found");
     1160        throw DataFormatError("Section @nodes not found");
    11611161      }
    11621162
    11631163      if (!arcs_done) {
    1164         throw DataFormatError("Section @arcs not found");
     1164        throw DataFormatError("Section @arcs not found");
    11651165      }
    11661166
    11671167      if (!attributes_done && !_attributes.empty()) {
    1168         throw DataFormatError("Section @attributes not found");
     1168        throw DataFormatError("Section @attributes not found");
    11691169      }
    11701170
     
    11721172
    11731173    /// @}
    1174    
     1174
    11751175  };
    11761176
    11771177  /// \brief Return a \ref DigraphReader class
    1178   /// 
     1178  ///
    11791179  /// This function just returns a \ref DigraphReader class.
    11801180  /// \relates DigraphReader
     
    11861186
    11871187  /// \brief Return a \ref DigraphReader class
    1188   /// 
     1188  ///
    11891189  /// This function just returns a \ref DigraphReader class.
    11901190  /// \relates DigraphReader
    11911191  template <typename Digraph>
    1192   DigraphReader<Digraph> digraphReader(const std::string& fn, 
    1193                                        Digraph& digraph) {
     1192  DigraphReader<Digraph> digraphReader(const std::string& fn,
     1193                                       Digraph& digraph) {
    11941194    DigraphReader<Digraph> tmp(fn, digraph);
    11951195    return tmp;
     
    11971197
    11981198  /// \brief Return a \ref DigraphReader class
    1199   /// 
     1199  ///
    12001200  /// This function just returns a \ref DigraphReader class.
    12011201  /// \relates DigraphReader
     
    12101210
    12111211  template <typename Graph>
    1212   GraphReader<Graph> graphReader(std::istream& is, Graph& graph);   
     1212  GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
    12131213
    12141214  template <typename Graph>
    1215   GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);   
     1215  GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
    12161216
    12171217  template <typename Graph>
    1218   GraphReader<Graph> graphReader(const char *fn, Graph& graph);   
     1218  GraphReader<Graph> graphReader(const char *fn, Graph& graph);
    12191219
    12201220  /// \ingroup lemon_io
    1221   /// 
     1221  ///
    12221222  /// \brief \ref lgf-format "LGF" reader for undirected graphs
    12231223  ///
     
    12391239    typedef _Graph Graph;
    12401240    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    1241    
     1241
    12421242  private:
    12431243
     
    12551255    typedef std::map<std::string, Edge> EdgeIndex;
    12561256    EdgeIndex _edge_index;
    1257    
    1258     typedef std::vector<std::pair<std::string, 
    1259       _reader_bits::MapStorageBase<Node>*> > NodeMaps;   
    1260     NodeMaps _node_maps; 
     1257
     1258    typedef std::vector<std::pair<std::string,
     1259      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
     1260    NodeMaps _node_maps;
    12611261
    12621262    typedef std::vector<std::pair<std::string,
     
    12641264    EdgeMaps _edge_maps;
    12651265
    1266     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
     1266    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*>
    12671267      Attributes;
    12681268    Attributes _attributes;
     
    12831283    /// Construct an undirected graph reader, which reads from the given
    12841284    /// input stream.
    1285     GraphReader(std::istream& is, Graph& graph) 
     1285    GraphReader(std::istream& is, Graph& graph)
    12861286      : _is(&is), local_is(false), _graph(graph),
    1287         _use_nodes(false), _use_edges(false),
    1288         _skip_nodes(false), _skip_edges(false) {}
     1287        _use_nodes(false), _use_edges(false),
     1288        _skip_nodes(false), _skip_edges(false) {}
    12891289
    12901290    /// \brief Constructor
     
    12921292    /// Construct an undirected graph reader, which reads from the given
    12931293    /// file.
    1294     GraphReader(const std::string& fn, Graph& graph) 
     1294    GraphReader(const std::string& fn, Graph& graph)
    12951295      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
    1296         _use_nodes(false), _use_edges(false),
    1297         _skip_nodes(false), _skip_edges(false) {}
    1298    
     1296            _use_nodes(false), _use_edges(false),
     1297        _skip_nodes(false), _skip_edges(false) {}
     1298
    12991299    /// \brief Constructor
    13001300    ///
    13011301    /// Construct an undirected graph reader, which reads from the given
    13021302    /// file.
    1303     GraphReader(const char* fn, Graph& graph) 
     1303    GraphReader(const char* fn, Graph& graph)
    13041304      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
    1305         _use_nodes(false), _use_edges(false),
    1306         _skip_nodes(false), _skip_edges(false) {}
     1305            _use_nodes(false), _use_edges(false),
     1306        _skip_nodes(false), _skip_edges(false) {}
    13071307
    13081308    /// \brief Destructor
    13091309    ~GraphReader() {
    1310       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    1311            it != _node_maps.end(); ++it) {
    1312         delete it->second;
    1313       }
    1314 
    1315       for (typename EdgeMaps::iterator it = _edge_maps.begin(); 
    1316            it != _edge_maps.end(); ++it) {
    1317         delete it->second;
    1318       }
    1319 
    1320       for (typename Attributes::iterator it = _attributes.begin(); 
    1321            it != _attributes.end(); ++it) {
    1322         delete it->second;
     1310      for (typename NodeMaps::iterator it = _node_maps.begin();
     1311           it != _node_maps.end(); ++it) {
     1312        delete it->second;
     1313      }
     1314
     1315      for (typename EdgeMaps::iterator it = _edge_maps.begin();
     1316           it != _edge_maps.end(); ++it) {
     1317        delete it->second;
     1318      }
     1319
     1320      for (typename Attributes::iterator it = _attributes.begin();
     1321           it != _attributes.end(); ++it) {
     1322        delete it->second;
    13231323      }
    13241324
    13251325      if (local_is) {
    1326         delete _is;
     1326        delete _is;
    13271327      }
    13281328
     
    13301330
    13311331  private:
    1332     friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);   
    1333     friend GraphReader<Graph> graphReader<>(const std::string& fn, 
    1334                                             Graph& graph);   
    1335     friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);   
    1336 
    1337     GraphReader(GraphReader& other) 
     1332    friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);
     1333    friend GraphReader<Graph> graphReader<>(const std::string& fn,
     1334                                            Graph& graph);
     1335    friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
     1336
     1337    GraphReader(GraphReader& other)
    13381338      : _is(other._is), local_is(other.local_is), _graph(other._graph),
    1339         _use_nodes(other._use_nodes), _use_edges(other._use_edges),
    1340         _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
     1339        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
     1340        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
    13411341
    13421342      other._is = 0;
    13431343      other.local_is = false;
    1344      
     1344
    13451345      _node_index.swap(other._node_index);
    13461346      _edge_index.swap(other._edge_index);
     
    13621362    /// \name Reading rules
    13631363    /// @{
    1364    
     1364
    13651365    /// \brief Node map reading rule
    13661366    ///
     
    13691369    GraphReader& nodeMap(const std::string& caption, Map& map) {
    13701370      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    1371       _reader_bits::MapStorageBase<Node>* storage = 
    1372         new _reader_bits::MapStorage<Node, Map>(map);
     1371      _reader_bits::MapStorageBase<Node>* storage =
     1372        new _reader_bits::MapStorage<Node, Map>(map);
    13731373      _node_maps.push_back(std::make_pair(caption, storage));
    13741374      return *this;
     
    13801380    /// reader.
    13811381    template <typename Map, typename Converter>
    1382     GraphReader& nodeMap(const std::string& caption, Map& map, 
    1383                            const Converter& converter = Converter()) {
     1382    GraphReader& nodeMap(const std::string& caption, Map& map,
     1383                           const Converter& converter = Converter()) {
    13841384      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    1385       _reader_bits::MapStorageBase<Node>* storage = 
    1386         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
     1385      _reader_bits::MapStorageBase<Node>* storage =
     1386        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
    13871387      _node_maps.push_back(std::make_pair(caption, storage));
    13881388      return *this;
     
    13951395    GraphReader& edgeMap(const std::string& caption, Map& map) {
    13961396      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
    1397       _reader_bits::MapStorageBase<Edge>* storage = 
    1398         new _reader_bits::MapStorage<Edge, Map>(map);
     1397      _reader_bits::MapStorageBase<Edge>* storage =
     1398        new _reader_bits::MapStorage<Edge, Map>(map);
    13991399      _edge_maps.push_back(std::make_pair(caption, storage));
    14001400      return *this;
     
    14061406    /// reader.
    14071407    template <typename Map, typename Converter>
    1408     GraphReader& edgeMap(const std::string& caption, Map& map, 
    1409                           const Converter& converter = Converter()) {
     1408    GraphReader& edgeMap(const std::string& caption, Map& map,
     1409                          const Converter& converter = Converter()) {
    14101410      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
    1411       _reader_bits::MapStorageBase<Edge>* storage = 
    1412         new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter);
     1411      _reader_bits::MapStorageBase<Edge>* storage =
     1412        new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter);
    14131413      _edge_maps.push_back(std::make_pair(caption, storage));
    14141414      return *this;
     
    14211421    GraphReader& arcMap(const std::string& caption, Map& map) {
    14221422      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    1423       _reader_bits::MapStorageBase<Edge>* forward_storage = 
    1424         new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
     1423      _reader_bits::MapStorageBase<Edge>* forward_storage =
     1424        new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
    14251425      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1426       _reader_bits::MapStorageBase<Edge>* backward_storage = 
    1427         new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1426      _reader_bits::MapStorageBase<Edge>* backward_storage =
     1427        new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    14281428      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14291429      return *this;
     
    14351435    /// reader.
    14361436    template <typename Map, typename Converter>
    1437     GraphReader& arcMap(const std::string& caption, Map& map, 
    1438                           const Converter& converter = Converter()) {
     1437    GraphReader& arcMap(const std::string& caption, Map& map,
     1438                          const Converter& converter = Converter()) {
    14391439      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    1440       _reader_bits::MapStorageBase<Edge>* forward_storage = 
    1441         new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    1442         (_graph, map, converter);
     1440      _reader_bits::MapStorageBase<Edge>* forward_storage =
     1441        new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1442        (_graph, map, converter);
    14431443      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1444       _reader_bits::MapStorageBase<Edge>* backward_storage = 
    1445         new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    1446         (_graph, map, converter);
     1444      _reader_bits::MapStorageBase<Edge>* backward_storage =
     1445        new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1446        (_graph, map, converter);
    14471447      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14481448      return *this;
     
    14541454    template <typename Value>
    14551455    GraphReader& attribute(const std::string& caption, Value& value) {
    1456       _reader_bits::ValueStorageBase* storage = 
    1457         new _reader_bits::ValueStorage<Value>(value);
     1456      _reader_bits::ValueStorageBase* storage =
     1457        new _reader_bits::ValueStorage<Value>(value);
    14581458      _attributes.insert(std::make_pair(caption, storage));
    14591459      return *this;
     
    14651465    /// reader.
    14661466    template <typename Value, typename Converter>
    1467     GraphReader& attribute(const std::string& caption, Value& value, 
    1468                              const Converter& converter = Converter()) {
    1469       _reader_bits::ValueStorageBase* storage = 
    1470         new _reader_bits::ValueStorage<Value, Converter>(value, converter);
     1467    GraphReader& attribute(const std::string& caption, Value& value,
     1468                             const Converter& converter = Converter()) {
     1469      _reader_bits::ValueStorageBase* storage =
     1470        new _reader_bits::ValueStorage<Value, Converter>(value, converter);
    14711471      _attributes.insert(std::make_pair(caption, storage));
    14721472      return *this;
     
    14791479      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    14801480      Converter converter(_node_index);
    1481       _reader_bits::ValueStorageBase* storage = 
    1482         new _reader_bits::ValueStorage<Node, Converter>(node, converter);
     1481      _reader_bits::ValueStorageBase* storage =
     1482        new _reader_bits::ValueStorage<Node, Converter>(node, converter);
    14831483      _attributes.insert(std::make_pair(caption, storage));
    14841484      return *this;
     
    14911491      typedef _reader_bits::MapLookUpConverter<Edge> Converter;
    14921492      Converter converter(_edge_index);
    1493       _reader_bits::ValueStorageBase* storage = 
    1494         new _reader_bits::ValueStorage<Edge, Converter>(edge, converter);
     1493      _reader_bits::ValueStorageBase* storage =
     1494        new _reader_bits::ValueStorage<Edge, Converter>(edge, converter);
    14951495      _attributes.insert(std::make_pair(caption, storage));
    14961496      return *this;
     
    15031503      typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter;
    15041504      Converter converter(_graph, _edge_index);
    1505       _reader_bits::ValueStorageBase* storage = 
    1506         new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
     1505      _reader_bits::ValueStorageBase* storage =
     1506        new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
    15071507      _attributes.insert(std::make_pair(caption, storage));
    15081508      return *this;
     
    15501550    GraphReader& useNodes(const Map& map) {
    15511551      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1552       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     1552      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    15531553      _use_nodes = true;
    15541554      _writer_bits::DefaultConverter<typename Map::Value> converter;
    15551555      for (NodeIt n(_graph); n != INVALID; ++n) {
    1556         _node_index.insert(std::make_pair(converter(map[n]), n));
     1556        _node_index.insert(std::make_pair(converter(map[n]), n));
    15571557      }
    15581558      return *this;
     
    15651565    /// \c std::string.
    15661566    template <typename Map, typename Converter>
    1567     GraphReader& useNodes(const Map& map, 
    1568                             const Converter& converter = Converter()) {
     1567    GraphReader& useNodes(const Map& map,
     1568                            const Converter& converter = Converter()) {
    15691569      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1570       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     1570      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    15711571      _use_nodes = true;
    15721572      for (NodeIt n(_graph); n != INVALID; ++n) {
    1573         _node_index.insert(std::make_pair(converter(map[n]), n));
     1573        _node_index.insert(std::make_pair(converter(map[n]), n));
    15741574      }
    15751575      return *this;
     
    15871587      _writer_bits::DefaultConverter<typename Map::Value> converter;
    15881588      for (EdgeIt a(_graph); a != INVALID; ++a) {
    1589         _edge_index.insert(std::make_pair(converter(map[a]), a));
     1589        _edge_index.insert(std::make_pair(converter(map[a]), a));
    15901590      }
    15911591      return *this;
     
    15981598    /// \c std::string.
    15991599    template <typename Map, typename Converter>
    1600     GraphReader& useEdges(const Map& map, 
    1601                             const Converter& converter = Converter()) {
     1600    GraphReader& useEdges(const Map& map,
     1601                            const Converter& converter = Converter()) {
    16021602      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1603       LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); 
     1603      LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member");
    16041604      _use_edges = true;
    16051605      for (EdgeIt a(_graph); a != INVALID; ++a) {
    1606         _edge_index.insert(std::make_pair(converter(map[a]), a));
     1606        _edge_index.insert(std::make_pair(converter(map[a]), a));
    16071607      }
    16081608      return *this;
     
    16191619    /// \c useNodes() should be used to specify the label of the nodes.
    16201620    GraphReader& skipNodes() {
    1621       LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); 
     1621      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
    16221622      _skip_nodes = true;
    16231623      return *this;
     
    16301630    /// will not be constructed.
    16311631    GraphReader& skipEdges() {
    1632       LEMON_ASSERT(!_skip_edges, "Skip edges already set"); 
     1632      LEMON_ASSERT(!_skip_edges, "Skip edges already set");
    16331633      _skip_edges = true;
    16341634      return *this;
     
    16421642      std::string str;
    16431643      while(++line_num, std::getline(*_is, str)) {
    1644         line.clear(); line.str(str);
    1645         char c;
    1646         if (line >> std::ws >> c && c != '#') {
    1647           line.putback(c);
    1648           return true;
    1649         }
     1644        line.clear(); line.str(str);
     1645        char c;
     1646        if (line >> std::ws >> c && c != '#') {
     1647          line.putback(c);
     1648          return true;
     1649        }
    16501650      }
    16511651      return false;
     
    16551655      return static_cast<bool>(*_is);
    16561656    }
    1657    
     1657
    16581658    void skipSection() {
    16591659      char c;
    16601660      while (readSuccess() && line >> c && c != '@') {
    1661         readLine();
     1661        readLine();
    16621662      }
    16631663      line.putback(c);
     
    16711671      char c;
    16721672      if (!readLine() || !(line >> c) || c == '@') {
    1673         if (readSuccess() && line) line.putback(c);
    1674         if (!_node_maps.empty())
    1675           throw DataFormatError("Cannot find map names");
    1676         return;
     1673        if (readSuccess() && line) line.putback(c);
     1674        if (!_node_maps.empty())
     1675          throw DataFormatError("Cannot find map names");
     1676        return;
    16771677      }
    16781678      line.putback(c);
    1679      
     1679
    16801680      {
    1681         std::map<std::string, int> maps;
    1682        
    1683         std::string map;
    1684         int index = 0;
    1685         while (_reader_bits::readToken(line, map)) {
    1686           if (maps.find(map) != maps.end()) {
    1687             std::ostringstream msg;
    1688             msg << "Multiple occurence of node map: " << map;
    1689             throw DataFormatError(msg.str().c_str());
    1690           }
    1691           maps.insert(std::make_pair(map, index));
    1692           ++index;
    1693         }
    1694        
    1695         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    1696           std::map<std::string, int>::iterator jt =
    1697             maps.find(_node_maps[i].first);
    1698           if (jt == maps.end()) {
    1699             std::ostringstream msg;
    1700             msg << "Map not found in file: " << _node_maps[i].first;
    1701             throw DataFormatError(msg.str().c_str());
    1702           }
    1703           map_index[i] = jt->second;
    1704         }
    1705 
    1706         {
    1707           std::map<std::string, int>::iterator jt = maps.find("label");
    1708           if (jt != maps.end()) {
    1709             label_index = jt->second;
    1710           } else {
    1711             label_index = -1;
    1712           }
    1713         }
    1714         map_num = maps.size();
     1681        std::map<std::string, int> maps;
     1682
     1683        std::string map;
     1684        int index = 0;
     1685        while (_reader_bits::readToken(line, map)) {
     1686          if (maps.find(map) != maps.end()) {
     1687            std::ostringstream msg;
     1688            msg << "Multiple occurence of node map: " << map;
     1689            throw DataFormatError(msg.str().c_str());
     1690          }
     1691          maps.insert(std::make_pair(map, index));
     1692          ++index;
     1693        }
     1694
     1695        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     1696          std::map<std::string, int>::iterator jt =
     1697            maps.find(_node_maps[i].first);
     1698          if (jt == maps.end()) {
     1699            std::ostringstream msg;
     1700            msg << "Map not found in file: " << _node_maps[i].first;
     1701            throw DataFormatError(msg.str().c_str());
     1702          }
     1703          map_index[i] = jt->second;
     1704        }
     1705
     1706        {
     1707          std::map<std::string, int>::iterator jt = maps.find("label");
     1708          if (jt != maps.end()) {
     1709            label_index = jt->second;
     1710          } else {
     1711            label_index = -1;
     1712          }
     1713        }
     1714        map_num = maps.size();
    17151715      }
    17161716
    17171717      while (readLine() && line >> c && c != '@') {
    1718         line.putback(c);
    1719 
    1720         std::vector<std::string> tokens(map_num);
    1721         for (int i = 0; i < map_num; ++i) {
    1722           if (!_reader_bits::readToken(line, tokens[i])) {
    1723             std::ostringstream msg;
    1724             msg << "Column not found (" << i + 1 << ")";
    1725             throw DataFormatError(msg.str().c_str());
    1726           }
    1727         }
    1728         if (line >> std::ws >> c)
    1729           throw DataFormatError("Extra character on the end of line");
    1730        
    1731         Node n;
    1732         if (!_use_nodes) {
    1733           n = _graph.addNode();
    1734           if (label_index != -1)
    1735             _node_index.insert(std::make_pair(tokens[label_index], n));
    1736         } else {
    1737           if (label_index == -1)
    1738             throw DataFormatError("Label map not found in file");
    1739           typename std::map<std::string, Node>::iterator it =
    1740             _node_index.find(tokens[label_index]);
    1741           if (it == _node_index.end()) {
    1742             std::ostringstream msg;
    1743             msg << "Node with label not found: " << tokens[label_index];
    1744             throw DataFormatError(msg.str().c_str());       
    1745           }
    1746           n = it->second;
    1747         }
    1748 
    1749         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    1750           _node_maps[i].second->set(n, tokens[map_index[i]]);
    1751         }
     1718        line.putback(c);
     1719
     1720        std::vector<std::string> tokens(map_num);
     1721        for (int i = 0; i < map_num; ++i) {
     1722          if (!_reader_bits::readToken(line, tokens[i])) {
     1723            std::ostringstream msg;
     1724            msg << "Column not found (" << i + 1 << ")";
     1725            throw DataFormatError(msg.str().c_str());
     1726          }
     1727        }
     1728        if (line >> std::ws >> c)
     1729          throw DataFormatError("Extra character on the end of line");
     1730
     1731        Node n;
     1732        if (!_use_nodes) {
     1733          n = _graph.addNode();
     1734          if (label_index != -1)
     1735            _node_index.insert(std::make_pair(tokens[label_index], n));
     1736        } else {
     1737          if (label_index == -1)
     1738            throw DataFormatError("Label map not found in file");
     1739          typename std::map<std::string, Node>::iterator it =
     1740            _node_index.find(tokens[label_index]);
     1741          if (it == _node_index.end()) {
     1742            std::ostringstream msg;
     1743            msg << "Node with label not found: " << tokens[label_index];
     1744            throw DataFormatError(msg.str().c_str());
     1745          }
     1746          n = it->second;
     1747        }
     1748
     1749        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     1750          _node_maps[i].second->set(n, tokens[map_index[i]]);
     1751        }
    17521752
    17531753      }
    17541754      if (readSuccess()) {
    1755         line.putback(c);
     1755        line.putback(c);
    17561756      }
    17571757    }
     
    17641764      char c;
    17651765      if (!readLine() || !(line >> c) || c == '@') {
    1766         if (readSuccess() && line) line.putback(c);
    1767         if (!_edge_maps.empty())
    1768           throw DataFormatError("Cannot find map names");
    1769         return;
     1766        if (readSuccess() && line) line.putback(c);
     1767        if (!_edge_maps.empty())
     1768          throw DataFormatError("Cannot find map names");
     1769        return;
    17701770      }
    17711771      line.putback(c);
    1772      
     1772
    17731773      {
    1774         std::map<std::string, int> maps;
    1775        
    1776         std::string map;
    1777         int index = 0;
    1778         while (_reader_bits::readToken(line, map)) {
    1779           if (maps.find(map) != maps.end()) {
    1780             std::ostringstream msg;
    1781             msg << "Multiple occurence of edge map: " << map;
    1782             throw DataFormatError(msg.str().c_str());
    1783           }
    1784           maps.insert(std::make_pair(map, index));
    1785           ++index;
    1786         }
    1787        
    1788         for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
    1789           std::map<std::string, int>::iterator jt =
    1790             maps.find(_edge_maps[i].first);
    1791           if (jt == maps.end()) {
    1792             std::ostringstream msg;
    1793             msg << "Map not found in file: " << _edge_maps[i].first;
    1794             throw DataFormatError(msg.str().c_str());
    1795           }
    1796           map_index[i] = jt->second;
    1797         }
    1798 
    1799         {
    1800           std::map<std::string, int>::iterator jt = maps.find("label");
    1801           if (jt != maps.end()) {
    1802             label_index = jt->second;
    1803           } else {
    1804             label_index = -1;
    1805           }
    1806         }
    1807         map_num = maps.size();
     1774        std::map<std::string, int> maps;
     1775
     1776        std::string map;
     1777        int index = 0;
     1778        while (_reader_bits::readToken(line, map)) {
     1779          if (maps.find(map) != maps.end()) {
     1780            std::ostringstream msg;
     1781            msg << "Multiple occurence of edge map: " << map;
     1782            throw DataFormatError(msg.str().c_str());
     1783          }
     1784          maps.insert(std::make_pair(map, index));
     1785          ++index;
     1786        }
     1787
     1788        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
     1789          std::map<std::string, int>::iterator jt =
     1790            maps.find(_edge_maps[i].first);
     1791          if (jt == maps.end()) {
     1792            std::ostringstream msg;
     1793            msg << "Map not found in file: " << _edge_maps[i].first;
     1794            throw DataFormatError(msg.str().c_str());
     1795          }
     1796          map_index[i] = jt->second;
     1797        }
     1798
     1799        {
     1800          std::map<std::string, int>::iterator jt = maps.find("label");
     1801          if (jt != maps.end()) {
     1802            label_index = jt->second;
     1803          } else {
     1804            label_index = -1;
     1805          }
     1806        }
     1807        map_num = maps.size();
    18081808      }
    18091809
    18101810      while (readLine() && line >> c && c != '@') {
    1811         line.putback(c);
    1812 
    1813         std::string source_token;
    1814         std::string target_token;
    1815 
    1816         if (!_reader_bits::readToken(line, source_token))
    1817           throw DataFormatError("Node u not found");
    1818 
    1819         if (!_reader_bits::readToken(line, target_token))
    1820           throw DataFormatError("Node v not found");
    1821        
    1822         std::vector<std::string> tokens(map_num);
    1823         for (int i = 0; i < map_num; ++i) {
    1824           if (!_reader_bits::readToken(line, tokens[i])) {
    1825             std::ostringstream msg;
    1826             msg << "Column not found (" << i + 1 << ")";
    1827             throw DataFormatError(msg.str().c_str());
    1828           }
    1829         }
    1830         if (line >> std::ws >> c)
    1831           throw DataFormatError("Extra character on the end of line");
    1832        
    1833         Edge e;
    1834         if (!_use_edges) {
     1811        line.putback(c);
     1812
     1813        std::string source_token;
     1814        std::string target_token;
     1815
     1816        if (!_reader_bits::readToken(line, source_token))
     1817          throw DataFormatError("Node u not found");
     1818
     1819        if (!_reader_bits::readToken(line, target_token))
     1820          throw DataFormatError("Node v not found");
     1821
     1822        std::vector<std::string> tokens(map_num);
     1823        for (int i = 0; i < map_num; ++i) {
     1824          if (!_reader_bits::readToken(line, tokens[i])) {
     1825            std::ostringstream msg;
     1826            msg << "Column not found (" << i + 1 << ")";
     1827            throw DataFormatError(msg.str().c_str());
     1828          }
     1829        }
     1830        if (line >> std::ws >> c)
     1831          throw DataFormatError("Extra character on the end of line");
     1832
     1833        Edge e;
     1834        if (!_use_edges) {
    18351835
    18361836          typename NodeIndex::iterator it;
    1837  
     1837
    18381838          it = _node_index.find(source_token);
    18391839          if (it == _node_index.end()) {
     
    18451845
    18461846          it = _node_index.find(target_token);
    1847           if (it == _node_index.end()) {       
    1848             std::ostringstream msg;           
     1847          if (it == _node_index.end()) {
     1848            std::ostringstream msg;
    18491849            msg << "Item not found: " << target_token;
    18501850            throw DataFormatError(msg.str().c_str());
    1851           }                                         
    1852           Node target = it->second;                           
    1853 
    1854           e = _graph.addEdge(source, target);
    1855           if (label_index != -1)
    1856             _edge_index.insert(std::make_pair(tokens[label_index], e));
    1857         } else {
    1858           if (label_index == -1)
    1859             throw DataFormatError("Label map not found in file");
    1860           typename std::map<std::string, Edge>::iterator it =
    1861             _edge_index.find(tokens[label_index]);
    1862           if (it == _edge_index.end()) {
    1863             std::ostringstream msg;
    1864             msg << "Edge with label not found: " << tokens[label_index];
    1865             throw DataFormatError(msg.str().c_str());       
    1866           }
    1867           e = it->second;
    1868         }
    1869 
    1870         for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
    1871           _edge_maps[i].second->set(e, tokens[map_index[i]]);
    1872         }
     1851          }
     1852          Node target = it->second;
     1853
     1854          e = _graph.addEdge(source, target);
     1855          if (label_index != -1)
     1856            _edge_index.insert(std::make_pair(tokens[label_index], e));
     1857        } else {
     1858          if (label_index == -1)
     1859            throw DataFormatError("Label map not found in file");
     1860          typename std::map<std::string, Edge>::iterator it =
     1861            _edge_index.find(tokens[label_index]);
     1862          if (it == _edge_index.end()) {
     1863            std::ostringstream msg;
     1864            msg << "Edge with label not found: " << tokens[label_index];
     1865            throw DataFormatError(msg.str().c_str());
     1866          }
     1867          e = it->second;
     1868        }
     1869
     1870        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
     1871          _edge_maps[i].second->set(e, tokens[map_index[i]]);
     1872        }
    18731873
    18741874      }
    18751875      if (readSuccess()) {
    1876         line.putback(c);
     1876        line.putback(c);
    18771877      }
    18781878    }
     
    18841884      char c;
    18851885      while (readLine() && line >> c && c != '@') {
    1886         line.putback(c);
    1887        
    1888         std::string attr, token;
    1889         if (!_reader_bits::readToken(line, attr))
    1890           throw DataFormatError("Attribute name not found");
    1891         if (!_reader_bits::readToken(line, token))
    1892           throw DataFormatError("Attribute value not found");
    1893         if (line >> c)
    1894           throw DataFormatError("Extra character on the end of line");   
    1895 
    1896         {
    1897           std::set<std::string>::iterator it = read_attr.find(attr);
    1898           if (it != read_attr.end()) {
    1899             std::ostringstream msg;
    1900             msg << "Multiple occurence of attribute " << attr;
    1901             throw DataFormatError(msg.str().c_str());
    1902           }
    1903           read_attr.insert(attr);
    1904         }
    1905        
    1906         {
    1907           typename Attributes::iterator it = _attributes.lower_bound(attr);
    1908           while (it != _attributes.end() && it->first == attr) {
    1909             it->second->set(token);
    1910             ++it;
    1911           }
    1912         }
     1886        line.putback(c);
     1887
     1888        std::string attr, token;
     1889        if (!_reader_bits::readToken(line, attr))
     1890          throw DataFormatError("Attribute name not found");
     1891        if (!_reader_bits::readToken(line, token))
     1892          throw DataFormatError("Attribute value not found");
     1893        if (line >> c)
     1894          throw DataFormatError("Extra character on the end of line");
     1895
     1896        {
     1897          std::set<std::string>::iterator it = read_attr.find(attr);
     1898          if (it != read_attr.end()) {
     1899            std::ostringstream msg;
     1900            msg << "Multiple occurence of attribute " << attr;
     1901            throw DataFormatError(msg.str().c_str());
     1902          }
     1903          read_attr.insert(attr);
     1904        }
     1905
     1906        {
     1907          typename Attributes::iterator it = _attributes.lower_bound(attr);
     1908          while (it != _attributes.end() && it->first == attr) {
     1909            it->second->set(token);
     1910            ++it;
     1911          }
     1912        }
    19131913
    19141914      }
    19151915      if (readSuccess()) {
    1916         line.putback(c);
     1916        line.putback(c);
    19171917      }
    19181918      for (typename Attributes::iterator it = _attributes.begin();
    1919            it != _attributes.end(); ++it) {
    1920         if (read_attr.find(it->first) == read_attr.end()) {
    1921           std::ostringstream msg;
    1922           msg << "Attribute not found in file: " << it->first;
    1923           throw DataFormatError(msg.str().c_str());
    1924         }       
     1919           it != _attributes.end(); ++it) {
     1920        if (read_attr.find(it->first) == read_attr.end()) {
     1921          std::ostringstream msg;
     1922          msg << "Attribute not found in file: " << it->first;
     1923          throw DataFormatError(msg.str().c_str());
     1924        }
    19251925      }
    19261926    }
     
    19281928  public:
    19291929
    1930     /// \name Execution of the reader   
     1930    /// \name Execution of the reader
    19311931    /// @{
    19321932
     
    19351935    /// This function starts the batch processing
    19361936    void run() {
    1937      
     1937
    19381938      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    1939      
     1939
    19401940      bool nodes_done = _skip_nodes;
    19411941      bool edges_done = _skip_edges;
    19421942      bool attributes_done = false;
    19431943
    1944       line_num = 0;     
     1944      line_num = 0;
    19451945      readLine();
    19461946      skipSection();
    19471947
    19481948      while (readSuccess()) {
    1949         try {
    1950           char c;
    1951           std::string section, caption;
    1952           line >> c;
    1953           _reader_bits::readToken(line, section);
    1954           _reader_bits::readToken(line, caption);
    1955 
    1956           if (line >> c)
    1957             throw DataFormatError("Extra character on the end of line");
    1958 
    1959           if (section == "nodes" && !nodes_done) {
    1960             if (_nodes_caption.empty() || _nodes_caption == caption) {
    1961               readNodes();
    1962               nodes_done = true;
    1963             }
    1964           } else if ((section == "edges" || section == "arcs") &&
    1965                      !edges_done) {
    1966             if (_edges_caption.empty() || _edges_caption == caption) {
    1967               readEdges();
    1968               edges_done = true;
    1969             }
    1970           } else if (section == "attributes" && !attributes_done) {
    1971             if (_attributes_caption.empty() || _attributes_caption == caption) {
    1972               readAttributes();
    1973               attributes_done = true;
    1974             }
    1975           } else {
    1976             readLine();
    1977             skipSection();
    1978           }
    1979         } catch (DataFormatError& error) {
    1980           error.line(line_num);
    1981           throw;
    1982         }       
     1949        try {
     1950          char c;
     1951          std::string section, caption;
     1952          line >> c;
     1953          _reader_bits::readToken(line, section);
     1954          _reader_bits::readToken(line, caption);
     1955
     1956          if (line >> c)
     1957            throw DataFormatError("Extra character on the end of line");
     1958
     1959          if (section == "nodes" && !nodes_done) {
     1960            if (_nodes_caption.empty() || _nodes_caption == caption) {
     1961              readNodes();
     1962              nodes_done = true;
     1963            }
     1964          } else if ((section == "edges" || section == "arcs") &&
     1965                     !edges_done) {
     1966            if (_edges_caption.empty() || _edges_caption == caption) {
     1967              readEdges();
     1968              edges_done = true;
     1969            }
     1970          } else if (section == "attributes" && !attributes_done) {
     1971            if (_attributes_caption.empty() || _attributes_caption == caption) {
     1972              readAttributes();
     1973              attributes_done = true;
     1974            }
     1975          } else {
     1976            readLine();
     1977            skipSection();
     1978          }
     1979        } catch (DataFormatError& error) {
     1980          error.line(line_num);
     1981          throw;
     1982        }
    19831983      }
    19841984
    19851985      if (!nodes_done) {
    1986         throw DataFormatError("Section @nodes not found");
     1986        throw DataFormatError("Section @nodes not found");
    19871987      }
    19881988
    19891989      if (!edges_done) {
    1990         throw DataFormatError("Section @edges not found");
     1990        throw DataFormatError("Section @edges not found");
    19911991      }
    19921992
    19931993      if (!attributes_done && !_attributes.empty()) {
    1994         throw DataFormatError("Section @attributes not found");
     1994        throw DataFormatError("Section @attributes not found");
    19951995      }
    19961996
     
    19981998
    19991999    /// @}
    2000    
     2000
    20012001  };
    20022002
    20032003  /// \brief Return a \ref GraphReader class
    2004   /// 
     2004  ///
    20052005  /// This function just returns a \ref GraphReader class.
    20062006  /// \relates GraphReader
     
    20122012
    20132013  /// \brief Return a \ref GraphReader class
    2014   /// 
     2014  ///
    20152015  /// This function just returns a \ref GraphReader class.
    20162016  /// \relates GraphReader
    20172017  template <typename Graph>
    2018   GraphReader<Graph> graphReader(const std::string& fn, 
    2019                                        Graph& graph) {
     2018  GraphReader<Graph> graphReader(const std::string& fn,
     2019                                       Graph& graph) {
    20202020    GraphReader<Graph> tmp(fn, graph);
    20212021    return tmp;
     
    20232023
    20242024  /// \brief Return a \ref GraphReader class
    2025   /// 
     2025  ///
    20262026  /// This function just returns a \ref GraphReader class.
    20272027  /// \relates GraphReader
     
    20372037  SectionReader sectionReader(const std::string& fn);
    20382038  SectionReader sectionReader(const char* fn);
    2039  
     2039
    20402040  /// \ingroup lemon_io
    20412041  ///
    20422042  /// \brief Section reader class
    20432043  ///
    2044   /// In the \ref lgf-format "LGF" file extra sections can be placed, 
     2044  /// In the \ref lgf-format "LGF" file extra sections can be placed,
    20452045  /// which contain any data in arbitrary format. Such sections can be
    2046   /// read with this class. A reading rule can be added to the class 
     2046  /// read with this class. A reading rule can be added to the class
    20472047  /// with two different functions. With the \c sectionLines() function a
    20482048  /// functor can process the section line-by-line, while with the \c
     
    20512051  class SectionReader {
    20522052  private:
    2053    
     2053
    20542054    std::istream* _is;
    20552055    bool local_is;
     
    20672067    /// Construct a section reader, which reads from the given input
    20682068    /// stream.
    2069     SectionReader(std::istream& is) 
     2069    SectionReader(std::istream& is)
    20702070      : _is(&is), local_is(false) {}
    20712071
     
    20732073    ///
    20742074    /// Construct a section reader, which reads from the given file.
    2075     SectionReader(const std::string& fn) 
     2075    SectionReader(const std::string& fn)
    20762076      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    2077    
     2077
    20782078    /// \brief Constructor
    20792079    ///
    20802080    /// Construct a section reader, which reads from the given file.
    2081     SectionReader(const char* fn) 
     2081    SectionReader(const char* fn)
    20822082      : _is(new std::ifstream(fn)), local_is(true) {}
    20832083
    20842084    /// \brief Destructor
    20852085    ~SectionReader() {
    2086       for (Sections::iterator it = _sections.begin(); 
    2087            it != _sections.end(); ++it) {
    2088         delete it->second;
     2086      for (Sections::iterator it = _sections.begin();
     2087           it != _sections.end(); ++it) {
     2088        delete it->second;
    20892089      }
    20902090
    20912091      if (local_is) {
    2092         delete _is;
     2092        delete _is;
    20932093      }
    20942094
     
    21012101    friend SectionReader sectionReader(const char* fn);
    21022102
    2103     SectionReader(SectionReader& other) 
     2103    SectionReader(SectionReader& other)
    21042104      : _is(other._is), local_is(other.local_is) {
    21052105
    21062106      other._is = 0;
    21072107      other.local_is = false;
    2108      
     2108
    21092109      _sections.swap(other._sections);
    21102110    }
    2111    
     2111
    21122112    SectionReader& operator=(const SectionReader&);
    21132113
     
    21492149    ///  // ...
    21502150    ///
    2151     ///  reader.sectionLines("numbers", NumberSection(vec)); 
     2151    ///  reader.sectionLines("numbers", NumberSection(vec));
    21522152    ///\endcode
    21532153    template <typename Functor>
    21542154    SectionReader& sectionLines(const std::string& type, Functor functor) {
    21552155      LEMON_ASSERT(!type.empty(), "Type is empty.");
    2156       LEMON_ASSERT(_sections.find(type) == _sections.end(), 
    2157                    "Multiple reading of section.");
    2158       _sections.insert(std::make_pair(type, 
     2156      LEMON_ASSERT(_sections.find(type) == _sections.end(),
     2157                   "Multiple reading of section.");
     2158      _sections.insert(std::make_pair(type,
    21592159        new _reader_bits::LineSection<Functor>(functor)));
    21602160      return *this;
     
    21722172    SectionReader& sectionStream(const std::string& type, Functor functor) {
    21732173      LEMON_ASSERT(!type.empty(), "Type is empty.");
    2174       LEMON_ASSERT(_sections.find(type) == _sections.end(), 
    2175                    "Multiple reading of section.");
    2176       _sections.insert(std::make_pair(type, 
    2177         new _reader_bits::StreamSection<Functor>(functor)));
    2178       return *this;
    2179     }   
    2180    
     2174      LEMON_ASSERT(_sections.find(type) == _sections.end(),
     2175                   "Multiple reading of section.");
     2176      _sections.insert(std::make_pair(type,
     2177        new _reader_bits::StreamSection<Functor>(functor)));
     2178      return *this;
     2179    }
     2180
    21812181    /// @}
    21822182
     
    21862186      std::string str;
    21872187      while(++line_num, std::getline(*_is, str)) {
    2188         line.clear(); line.str(str);
    2189         char c;
    2190         if (line >> std::ws >> c && c != '#') {
    2191           line.putback(c);
    2192           return true;
    2193         }
     2188        line.clear(); line.str(str);
     2189        char c;
     2190        if (line >> std::ws >> c && c != '#') {
     2191          line.putback(c);
     2192          return true;
     2193        }
    21942194      }
    21952195      return false;
     
    21992199      return static_cast<bool>(*_is);
    22002200    }
    2201    
     2201
    22022202    void skipSection() {
    22032203      char c;
    22042204      while (readSuccess() && line >> c && c != '@') {
    2205         readLine();
     2205        readLine();
    22062206      }
    22072207      line.putback(c);
     
    22112211
    22122212
    2213     /// \name Execution of the reader   
     2213    /// \name Execution of the reader
    22142214    /// @{
    22152215
     
    22182218    /// This function starts the batch processing.
    22192219    void run() {
    2220      
     2220
    22212221      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    2222      
     2222
    22232223      std::set<std::string> extra_sections;
    22242224
    2225       line_num = 0;     
     2225      line_num = 0;
    22262226      readLine();
    22272227      skipSection();
    22282228
    22292229      while (readSuccess()) {
    2230         try {
    2231           char c;
    2232           std::string section, caption;
    2233           line >> c;
    2234           _reader_bits::readToken(line, section);
    2235           _reader_bits::readToken(line, caption);
    2236 
    2237           if (line >> c)
    2238             throw DataFormatError("Extra character on the end of line");
    2239 
    2240           if (extra_sections.find(section) != extra_sections.end()) {
    2241             std::ostringstream msg;
    2242             msg << "Multiple occurence of section " << section;
    2243             throw DataFormatError(msg.str().c_str());
    2244           }
    2245           Sections::iterator it = _sections.find(section);
    2246           if (it != _sections.end()) {
    2247             extra_sections.insert(section);
    2248             it->second->process(*_is, line_num);
    2249           }
    2250           readLine();
    2251           skipSection();
    2252         } catch (DataFormatError& error) {
    2253           error.line(line_num);
    2254           throw;
    2255         }       
     2230        try {
     2231          char c;
     2232          std::string section, caption;
     2233          line >> c;
     2234          _reader_bits::readToken(line, section);
     2235          _reader_bits::readToken(line, caption);
     2236
     2237          if (line >> c)
     2238            throw DataFormatError("Extra character on the end of line");
     2239
     2240          if (extra_sections.find(section) != extra_sections.end()) {
     2241            std::ostringstream msg;
     2242            msg << "Multiple occurence of section " << section;
     2243            throw DataFormatError(msg.str().c_str());
     2244          }
     2245          Sections::iterator it = _sections.find(section);
     2246          if (it != _sections.end()) {
     2247            extra_sections.insert(section);
     2248            it->second->process(*_is, line_num);
     2249          }
     2250          readLine();
     2251          skipSection();
     2252        } catch (DataFormatError& error) {
     2253          error.line(line_num);
     2254          throw;
     2255        }
    22562256      }
    22572257      for (Sections::iterator it = _sections.begin();
    2258            it != _sections.end(); ++it) {
    2259         if (extra_sections.find(it->first) == extra_sections.end()) {
    2260           std::ostringstream os;
    2261           os << "Cannot find section: " << it->first;
    2262           throw DataFormatError(os.str().c_str());
    2263         }
     2258           it != _sections.end(); ++it) {
     2259        if (extra_sections.find(it->first) == extra_sections.end()) {
     2260          std::ostringstream os;
     2261          os << "Cannot find section: " << it->first;
     2262          throw DataFormatError(os.str().c_str());
     2263        }
    22642264      }
    22652265    }
    22662266
    22672267    /// @}
    2268        
     2268
    22692269  };
    22702270
    22712271  /// \brief Return a \ref SectionReader class
    2272   /// 
     2272  ///
    22732273  /// This function just returns a \ref SectionReader class.
    22742274  /// \relates SectionReader
     
    22792279
    22802280  /// \brief Return a \ref SectionReader class
    2281   /// 
     2281  ///
    22822282  /// This function just returns a \ref SectionReader class.
    22832283  /// \relates SectionReader
     
    22882288
    22892289  /// \brief Return a \ref SectionReader class
    2290   /// 
     2290  ///
    22912291  /// This function just returns a \ref SectionReader class.
    22922292  /// \relates SectionReader
     
    22982298  /// \ingroup lemon_io
    22992299  ///
    2300   /// \brief Reader for the contents of the \ref lgf-format "LGF" file 
     2300  /// \brief Reader for the contents of the \ref lgf-format "LGF" file
    23012301  ///
    23022302  /// This class can be used to read the sections, the map names and
     
    23082308  /// reading the graph.
    23092309  ///
    2310   ///\code 
    2311   /// LgfContents contents("graph.lgf"); 
     2310  ///\code
     2311  /// LgfContents contents("graph.lgf");
    23122312  /// contents.run();
    23132313  ///
     
    23172317  ///   return -1;
    23182318  /// }
    2319   /// std::cout << "The name of the default node section: " 
     2319  /// std::cout << "The name of the default node section: "
    23202320  ///           << contents.nodeSection(0) << std::endl;
    2321   /// std::cout << "The number of the arc maps: " 
     2321  /// std::cout << "The number of the arc maps: "
    23222322  ///           << contents.arcMaps(0).size() << std::endl;
    2323   /// std::cout << "The name of second arc map: " 
     2323  /// std::cout << "The name of second arc map: "
    23242324  ///           << contents.arcMaps(0)[1] << std::endl;
    23252325  ///\endcode
    2326   class LgfContents {   
     2326  class LgfContents {
    23272327  private:
    23282328
     
    23452345    int line_num;
    23462346    std::istringstream line;
    2347    
     2347
    23482348  public:
    23492349
     
    23522352    /// Construct an \e LGF contents reader, which reads from the given
    23532353    /// input stream.
    2354     LgfContents(std::istream& is) 
     2354    LgfContents(std::istream& is)
    23552355      : _is(&is), local_is(false) {}
    23562356
     
    23592359    /// Construct an \e LGF contents reader, which reads from the given
    23602360    /// file.
    2361     LgfContents(const std::string& fn) 
     2361    LgfContents(const std::string& fn)
    23622362      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    23632363
     
    23682368    LgfContents(const char* fn)
    23692369      : _is(new std::ifstream(fn)), local_is(true) {}
    2370    
     2370
    23712371    /// \brief Destructor
    23722372    ~LgfContents() {
     
    23752375
    23762376  private:
    2377    
     2377
    23782378    LgfContents(const LgfContents&);
    23792379    LgfContents& operator=(const LgfContents&);
     
    23922392    }
    23932393
    2394     /// \brief Returns the node section name at the given position. 
    2395     ///
    2396     /// Returns the node section name at the given position. 
     2394    /// \brief Returns the node section name at the given position.
     2395    ///
     2396    /// Returns the node section name at the given position.
    23972397    const std::string& nodeSection(int i) const {
    23982398      return _node_sections[i];
     
    24082408    /// @}
    24092409
    2410     /// \name Arc/Edge sections 
     2410    /// \name Arc/Edge sections
    24112411    /// @{
    24122412
     
    24192419    }
    24202420
    2421     /// \brief Returns the arc/edge section name at the given position. 
    2422     ///
    2423     /// Returns the arc/edge section name at the given position. 
     2421    /// \brief Returns the arc/edge section name at the given position.
     2422    ///
     2423    /// Returns the arc/edge section name at the given position.
    24242424    /// \note It is synonym of \c edgeSection().
    24252425    const std::string& arcSection(int i) const {
     
    24482448    }
    24492449
    2450     /// \brief Returns the section name at the given position. 
    2451     ///
    2452     /// Returns the section name at the given position. 
     2450    /// \brief Returns the section name at the given position.
     2451    ///
     2452    /// Returns the section name at the given position.
    24532453    /// \note It is synonym of \c arcSection().
    24542454    const std::string& edgeSection(int i) const {
     
    24662466    /// @}
    24672467
    2468     /// \name Attribute sections   
     2468    /// \name Attribute sections
    24692469    /// @{
    24702470
     
    24762476    }
    24772477
    2478     /// \brief Returns the attribute section name at the given position. 
    2479     ///
    2480     /// Returns the attribute section name at the given position. 
     2478    /// \brief Returns the attribute section name at the given position.
     2479    ///
     2480    /// Returns the attribute section name at the given position.
    24812481    const std::string& attributeSectionNames(int i) const {
    24822482      return _attribute_sections[i];
     
    24922492    /// @}
    24932493
    2494     /// \name Extra sections   
     2494    /// \name Extra sections
    24952495    /// @{
    24962496
     
    25022502    }
    25032503
    2504     /// \brief Returns the extra section type at the given position. 
    2505     ///
    2506     /// Returns the section type at the given position. 
     2504    /// \brief Returns the extra section type at the given position.
     2505    ///
     2506    /// Returns the section type at the given position.
    25072507    const std::string& extraSection(int i) const {
    25082508      return _extra_sections[i];
     
    25162516      std::string str;
    25172517      while(++line_num, std::getline(*_is, str)) {
    2518         line.clear(); line.str(str);
    2519         char c;
    2520         if (line >> std::ws >> c && c != '#') {
    2521           line.putback(c);
    2522           return true;
    2523         }
     2518        line.clear(); line.str(str);
     2519        char c;
     2520        if (line >> std::ws >> c && c != '#') {
     2521          line.putback(c);
     2522          return true;
     2523        }
    25242524      }
    25252525      return false;
     
    25332533      char c;
    25342534      while (readSuccess() && line >> c && c != '@') {
    2535         readLine();
     2535        readLine();
    25362536      }
    25372537      line.putback(c);
     
    25412541      char c;
    25422542      if (!readLine() || !(line >> c) || c == '@') {
    2543         if (readSuccess() && line) line.putback(c);
    2544         return;
     2543        if (readSuccess() && line) line.putback(c);
     2544        return;
    25452545      }
    25462546      line.putback(c);
    25472547      std::string map;
    25482548      while (_reader_bits::readToken(line, map)) {
    2549         maps.push_back(map);
     2549        maps.push_back(map);
    25502550      }
    25512551    }
     
    25552555      char c;
    25562556      while (readSuccess() && line >> c && c != '@') {
    2557         line.putback(c);
    2558         std::string attr;
    2559         _reader_bits::readToken(line, attr);
    2560         attrs.push_back(attr);
    2561         readLine();
     2557        line.putback(c);
     2558        std::string attr;
     2559        _reader_bits::readToken(line, attr);
     2560        attrs.push_back(attr);
     2561        readLine();
    25622562      }
    25632563      line.putback(c);
     
    25662566  public:
    25672567
    2568     /// \name Execution of the contents reader   
     2568    /// \name Execution of the contents reader
    25692569    /// @{
    25702570
     
    25792579      while (readSuccess()) {
    25802580
    2581         char c;
    2582         line >> c;
    2583 
    2584         std::string section, caption;
    2585         _reader_bits::readToken(line, section);
    2586         _reader_bits::readToken(line, caption);
    2587 
    2588         if (section == "nodes") {
    2589           _node_sections.push_back(caption);
    2590           _node_maps.push_back(std::vector<std::string>());
    2591           readMaps(_node_maps.back());
    2592           readLine(); skipSection();
    2593         } else if (section == "arcs" || section == "edges") {
    2594           _edge_sections.push_back(caption);
    2595           _arc_sections.push_back(section == "arcs");
    2596           _edge_maps.push_back(std::vector<std::string>());
    2597           readMaps(_edge_maps.back());
    2598           readLine(); skipSection();
    2599         } else if (section == "attributes") {
    2600           _attribute_sections.push_back(caption);
    2601           _attributes.push_back(std::vector<std::string>());
    2602           readAttributes(_attributes.back());
    2603         } else {
    2604           _extra_sections.push_back(section);
    2605           readLine(); skipSection();
    2606         }
     2581        char c;
     2582        line >> c;
     2583
     2584        std::string section, caption;
     2585        _reader_bits::readToken(line, section);
     2586        _reader_bits::readToken(line, caption);
     2587
     2588        if (section == "nodes") {
     2589          _node_sections.push_back(caption);
     2590          _node_maps.push_back(std::vector<std::string>());
     2591          readMaps(_node_maps.back());
     2592          readLine(); skipSection();
     2593        } else if (section == "arcs" || section == "edges") {
     2594          _edge_sections.push_back(caption);
     2595          _arc_sections.push_back(section == "arcs");
     2596          _edge_maps.push_back(std::vector<std::string>());
     2597          readMaps(_edge_maps.back());
     2598          readLine(); skipSection();
     2599        } else if (section == "attributes") {
     2600          _attribute_sections.push_back(caption);
     2601          _attributes.push_back(std::vector<std::string>());
     2602          readAttributes(_attributes.back());
     2603        } else {
     2604          _extra_sections.push_back(section);
     2605          readLine(); skipSection();
     2606        }
    26072607      }
    26082608    }
    26092609
    26102610    /// @}
    2611    
     2611
    26122612  };
    26132613}
  • lemon/lgf_writer.h

    r201 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4444    struct DefaultConverter {
    4545      std::string operator()(const Value& value) {
    46         std::ostringstream os;
    47         os << value;
    48         return os.str();
     46        std::ostringstream os;
     47        os << value;
     48        return os.str();
    4949      }
    5050    };
     
    6363    private:
    6464      const Map& _map;
    65      
     65
    6666    public:
    6767      MapLess(const Map& map) : _map(map) {}
    6868
    6969      bool operator()(const Item& left, const Item& right) {
    70         return _map[left] < _map[right];
     70        return _map[left] < _map[right];
    7171      }
    7272    };
     
    8282      const Graph& _graph;
    8383      const Map& _map;
    84      
     84
    8585    public:
    86       GraphArcMapLess(const Graph& graph, const Map& map) 
    87         : _graph(graph), _map(map) {}
     86      GraphArcMapLess(const Graph& graph, const Map& map)
     87        : _graph(graph), _map(map) {}
    8888
    8989      bool operator()(const Item& left, const Item& right) {
    90         return _map[_graph.direct(left, _dir)] <
    91           _map[_graph.direct(right, _dir)];
     90        return _map[_graph.direct(left, _dir)] <
     91          _map[_graph.direct(right, _dir)];
    9292      }
    9393    };
    9494
    95     template <typename _Item>   
     95    template <typename _Item>
    9696    class MapStorageBase {
    9797    public:
     
    106106    };
    107107
    108     template <typename _Item, typename _Map, 
    109               typename _Converter = DefaultConverter<typename _Map::Value> >
     108    template <typename _Item, typename _Map,
     109              typename _Converter = DefaultConverter<typename _Map::Value> >
    110110    class MapStorage : public MapStorageBase<_Item> {
    111111    public:
     
    113113      typedef _Converter Converter;
    114114      typedef _Item Item;
    115      
     115
    116116    private:
    117117      const Map& _map;
     
    119119
    120120    public:
    121       MapStorage(const Map& map, const Converter& converter = Converter()) 
    122         : _map(map), _converter(converter) {}
     121      MapStorage(const Map& map, const Converter& converter = Converter())
     122        : _map(map), _converter(converter) {}
    123123      virtual ~MapStorage() {}
    124124
    125125      virtual std::string get(const Item& item) {
    126         return _converter(_map[item]);
     126        return _converter(_map[item]);
    127127      }
    128128      virtual void sort(std::vector<Item>& items) {
    129         MapLess<Map> less(_map);
    130         std::sort(items.begin(), items.end(), less);
     129        MapLess<Map> less(_map);
     130        std::sort(items.begin(), items.end(), less);
    131131      }
    132132    };
    133133
    134     template <typename _Graph, bool _dir, typename _Map, 
    135               typename _Converter = DefaultConverter<typename _Map::Value> >
     134    template <typename _Graph, bool _dir, typename _Map,
     135              typename _Converter = DefaultConverter<typename _Map::Value> >
    136136    class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
    137137    public:
     
    141141      typedef typename Graph::Edge Item;
    142142      static const bool dir = _dir;
    143      
     143
    144144    private:
    145145      const Graph& _graph;
     
    148148
    149149    public:
    150       GraphArcMapStorage(const Graph& graph, const Map& map, 
    151                          const Converter& converter = Converter())
    152         : _graph(graph), _map(map), _converter(converter) {}
     150      GraphArcMapStorage(const Graph& graph, const Map& map,
     151                         const Converter& converter = Converter())
     152        : _graph(graph), _map(map), _converter(converter) {}
    153153      virtual ~GraphArcMapStorage() {}
    154154
    155155      virtual std::string get(const Item& item) {
    156         return _converter(_map[_graph.direct(item, dir)]);
     156        return _converter(_map[_graph.direct(item, dir)]);
    157157      }
    158158      virtual void sort(std::vector<Item>& items) {
    159         GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
    160         std::sort(items.begin(), items.end(), less);
     159        GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
     160        std::sort(items.begin(), items.end(), less);
    161161      }
    162162    };
     
    167167      virtual ~ValueStorageBase() {}
    168168
    169       virtual std::string get() = 0;     
     169      virtual std::string get() = 0;
    170170    };
    171171
     
    182182    public:
    183183      ValueStorage(const Value& value, const Converter& converter = Converter())
    184         : _value(value), _converter(converter) {}
     184         : _value(value), _converter(converter) {}
    185185
    186186      virtual std::string get() {
    187         return _converter(_value);
     187        return _converter(_value);
    188188      }
    189189    };
     
    192192    struct MapLookUpConverter {
    193193      const std::map<Value, std::string>& _map;
    194      
    195       MapLookUpConverter(const std::map<Value, std::string>& map) 
    196         : _map(map) {}
    197      
     194
     195      MapLookUpConverter(const std::map<Value, std::string>& map)
     196        : _map(map) {}
     197
    198198      std::string operator()(const Value& str) {
    199         typename std::map<Value, std::string>::const_iterator it =
    200           _map.find(str);
    201         if (it == _map.end()) {
    202           throw DataFormatError("Item not found");
    203         }
    204         return it->second;
     199        typename std::map<Value, std::string>::const_iterator it =
     200          _map.find(str);
     201        if (it == _map.end()) {
     202          throw DataFormatError("Item not found");
     203        }
     204        return it->second;
    205205      }
    206206    };
     
    210210      const Graph& _graph;
    211211      const std::map<typename Graph::Edge, std::string>& _map;
    212      
    213       GraphArcLookUpConverter(const Graph& graph, 
    214                               const std::map<typename Graph::Edge,
    215                                              std::string>& map)
    216         : _graph(graph), _map(map) {}
    217      
     212
     213      GraphArcLookUpConverter(const Graph& graph,
     214                              const std::map<typename Graph::Edge,
     215                                             std::string>& map)
     216        : _graph(graph), _map(map) {}
     217
    218218      std::string operator()(const typename Graph::Arc& val) {
    219         typename std::map<typename Graph::Edge, std::string>
    220           ::const_iterator it = _map.find(val);
    221         if (it == _map.end()) {
    222           throw DataFormatError("Item not found");
    223         }
    224         return (_graph.direction(val) ? '+' : '-') + it->second;
     219        typename std::map<typename Graph::Edge, std::string>
     220          ::const_iterator it = _map.find(val);
     221        if (it == _map.end()) {
     222          throw DataFormatError("Item not found");
     223        }
     224        return (_graph.direction(val) ? '+' : '-') + it->second;
    225225      }
    226226    };
    227227
    228228    inline bool isWhiteSpace(char c) {
    229       return c == ' ' || c == '\t' || c == '\v' || 
    230         c == '\n' || c == '\r' || c == '\f'; 
     229      return c == ' ' || c == '\t' || c == '\v' ||
     230        c == '\n' || c == '\r' || c == '\f';
    231231    }
    232232
    233233    inline bool isEscaped(char c) {
    234       return c == '\\' || c == '\"' || c == '\'' || 
    235         c == '\a' || c == '\b';
     234      return c == '\\' || c == '\"' || c == '\'' ||
     235        c == '\a' || c == '\b';
    236236    }
    237237
     
    239239      switch (c) {
    240240      case '\\':
    241         os << "\\\\";
    242         return;
     241        os << "\\\\";
     242        return;
    243243      case '\"':
    244         os << "\\\"";
    245         return;
     244        os << "\\\"";
     245        return;
    246246      case '\a':
    247         os << "\\a";
    248         return;
     247        os << "\\a";
     248        return;
    249249      case '\b':
    250         os << "\\b";
    251         return;
     250        os << "\\b";
     251        return;
    252252      case '\f':
    253         os << "\\f";
    254         return;
     253        os << "\\f";
     254        return;
    255255      case '\r':
    256         os << "\\r";
    257         return;
     256        os << "\\r";
     257        return;
    258258      case '\n':
    259         os << "\\n";
    260         return;
     259        os << "\\n";
     260        return;
    261261      case '\t':
    262         os << "\\t";
    263         return;
     262        os << "\\t";
     263        return;
    264264      case '\v':
    265         os << "\\v";
    266         return;
     265        os << "\\v";
     266        return;
    267267      default:
    268         if (c < 0x20) {
    269           std::ios::fmtflags flags = os.flags();
    270           os << '\\' << std::oct << static_cast<int>(c);
    271           os.flags(flags);
    272         } else {
    273           os << c;
    274         }
    275         return;
    276       }     
     268        if (c < 0x20) {
     269          std::ios::fmtflags flags = os.flags();
     270          os << '\\' << std::oct << static_cast<int>(c);
     271          os.flags(flags);
     272        } else {
     273          os << c;
     274        }
     275        return;
     276      }
    277277    }
    278278
     
    282282      char c;
    283283      while (is.get(c)) {
    284         if (isWhiteSpace(c) || isEscaped(c)) {
    285           return true;
    286         }
     284        if (isWhiteSpace(c) || isEscaped(c)) {
     285          return true;
     286        }
    287287      }
    288288      return false;
    289289    }
    290    
     290
    291291    inline std::ostream& writeToken(std::ostream& os, const std::string& str) {
    292292
    293293      if (requireEscape(str)) {
    294         os << '\"';
    295         for (std::string::const_iterator it = str.begin();
    296              it != str.end(); ++it) {
    297           writeEscape(os, *it);
    298         }       
    299         os << '\"';
     294        os << '\"';
     295        for (std::string::const_iterator it = str.begin();
     296             it != str.end(); ++it) {
     297          writeEscape(os, *it);
     298        }
     299        os << '\"';
    300300      } else {
    301         os << str;
     301        os << str;
    302302      }
    303303      return os;
     
    310310
    311311  template <typename Digraph>
    312   DigraphWriter<Digraph> digraphWriter(std::ostream& os, 
    313                                        const Digraph& digraph);
     312  DigraphWriter<Digraph> digraphWriter(std::ostream& os,
     313                                       const Digraph& digraph);
    314314
    315315  template <typename Digraph>
    316   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
    317                                        const Digraph& digraph);
     316  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
     317                                       const Digraph& digraph);
    318318
    319319  template <typename Digraph>
    320   DigraphWriter<Digraph> digraphWriter(const char *fn, 
    321                                        const Digraph& digraph);
    322  
     320  DigraphWriter<Digraph> digraphWriter(const char *fn,
     321                                       const Digraph& digraph);
     322
    323323  /// \ingroup lemon_io
    324   /// 
     324  ///
    325325  /// \brief \ref lgf-format "LGF" writer for directed graphs
    326326  ///
     
    371371    typedef _Digraph Digraph;
    372372    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    373    
     373
    374374  private:
    375375
     
    383383    std::string _arcs_caption;
    384384    std::string _attributes_caption;
    385    
     385
    386386    typedef std::map<Node, std::string> NodeIndex;
    387387    NodeIndex _node_index;
     
    389389    ArcIndex _arc_index;
    390390
    391     typedef std::vector<std::pair<std::string, 
    392       _writer_bits::MapStorageBase<Node>* > > NodeMaps;   
    393     NodeMaps _node_maps; 
    394 
    395     typedef std::vector<std::pair<std::string, 
     391    typedef std::vector<std::pair<std::string,
     392      _writer_bits::MapStorageBase<Node>* > > NodeMaps;
     393    NodeMaps _node_maps;
     394
     395    typedef std::vector<std::pair<std::string,
    396396      _writer_bits::MapStorageBase<Arc>* > >ArcMaps;
    397397    ArcMaps _arc_maps;
    398398
    399     typedef std::vector<std::pair<std::string, 
     399    typedef std::vector<std::pair<std::string,
    400400      _writer_bits::ValueStorageBase*> > Attributes;
    401401    Attributes _attributes;
     
    410410    /// Construct a directed graph writer, which writes to the given
    411411    /// output stream.
    412     DigraphWriter(std::ostream& is, const Digraph& digraph) 
     412    DigraphWriter(std::ostream& is, const Digraph& digraph)
    413413      : _os(&is), local_os(false), _digraph(digraph),
    414         _skip_nodes(false), _skip_arcs(false) {}
     414        _skip_nodes(false), _skip_arcs(false) {}
    415415
    416416    /// \brief Constructor
     
    418418    /// Construct a directed graph writer, which writes to the given
    419419    /// output file.
    420     DigraphWriter(const std::string& fn, const Digraph& digraph) 
     420    DigraphWriter(const std::string& fn, const Digraph& digraph)
    421421      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    422         _skip_nodes(false), _skip_arcs(false) {}
     422        _skip_nodes(false), _skip_arcs(false) {}
    423423
    424424    /// \brief Constructor
     
    426426    /// Construct a directed graph writer, which writes to the given
    427427    /// output file.
    428     DigraphWriter(const char* fn, const Digraph& digraph) 
     428    DigraphWriter(const char* fn, const Digraph& digraph)
    429429      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    430         _skip_nodes(false), _skip_arcs(false) {}
     430        _skip_nodes(false), _skip_arcs(false) {}
    431431
    432432    /// \brief Destructor
    433433    ~DigraphWriter() {
    434       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    435            it != _node_maps.end(); ++it) {
    436         delete it->second;
    437       }
    438 
    439       for (typename ArcMaps::iterator it = _arc_maps.begin(); 
    440            it != _arc_maps.end(); ++it) {
    441         delete it->second;
    442       }
    443 
    444       for (typename Attributes::iterator it = _attributes.begin(); 
    445            it != _attributes.end(); ++it) {
    446         delete it->second;
     434      for (typename NodeMaps::iterator it = _node_maps.begin();
     435           it != _node_maps.end(); ++it) {
     436        delete it->second;
     437      }
     438
     439      for (typename ArcMaps::iterator it = _arc_maps.begin();
     440           it != _arc_maps.end(); ++it) {
     441        delete it->second;
     442      }
     443
     444      for (typename Attributes::iterator it = _attributes.begin();
     445           it != _attributes.end(); ++it) {
     446        delete it->second;
    447447      }
    448448
    449449      if (local_os) {
    450         delete _os;
     450        delete _os;
    451451      }
    452452    }
     
    454454  private:
    455455
    456     friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os, 
    457                                                   const Digraph& digraph);
    458     friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn, 
    459                                                   const Digraph& digraph);   
    460     friend DigraphWriter<Digraph> digraphWriter<>(const char *fn, 
    461                                                   const Digraph& digraph);
    462 
    463     DigraphWriter(DigraphWriter& other) 
     456    friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
     457                                                  const Digraph& digraph);
     458    friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
     459                                                  const Digraph& digraph);
     460    friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
     461                                                  const Digraph& digraph);
     462
     463    DigraphWriter(DigraphWriter& other)
    464464      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
    465         _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
     465        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    466466
    467467      other._os = 0;
     
    479479      _attributes_caption = other._attributes_caption;
    480480    }
    481    
     481
    482482    DigraphWriter& operator=(const DigraphWriter&);
    483483
     
    486486    /// \name Writing rules
    487487    /// @{
    488    
     488
    489489    /// \brief Node map writing rule
    490490    ///
     
    493493    DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
    494494      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    495       _writer_bits::MapStorageBase<Node>* storage = 
    496         new _writer_bits::MapStorage<Node, Map>(map);
     495      _writer_bits::MapStorageBase<Node>* storage =
     496        new _writer_bits::MapStorage<Node, Map>(map);
    497497      _node_maps.push_back(std::make_pair(caption, storage));
    498498      return *this;
     
    504504    /// writer.
    505505    template <typename Map, typename Converter>
    506     DigraphWriter& nodeMap(const std::string& caption, const Map& map, 
    507                            const Converter& converter = Converter()) {
     506    DigraphWriter& nodeMap(const std::string& caption, const Map& map,
     507                           const Converter& converter = Converter()) {
    508508      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    509       _writer_bits::MapStorageBase<Node>* storage = 
    510         new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
     509      _writer_bits::MapStorageBase<Node>* storage =
     510        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
    511511      _node_maps.push_back(std::make_pair(caption, storage));
    512512      return *this;
     
    519519    DigraphWriter& arcMap(const std::string& caption, const Map& map) {
    520520      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    521       _writer_bits::MapStorageBase<Arc>* storage = 
    522         new _writer_bits::MapStorage<Arc, Map>(map);
     521      _writer_bits::MapStorageBase<Arc>* storage =
     522        new _writer_bits::MapStorage<Arc, Map>(map);
    523523      _arc_maps.push_back(std::make_pair(caption, storage));
    524524      return *this;
     
    530530    /// writer.
    531531    template <typename Map, typename Converter>
    532     DigraphWriter& arcMap(const std::string& caption, const Map& map, 
    533                           const Converter& converter = Converter()) {
     532    DigraphWriter& arcMap(const std::string& caption, const Map& map,
     533                          const Converter& converter = Converter()) {
    534534      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    535       _writer_bits::MapStorageBase<Arc>* storage = 
    536         new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
     535      _writer_bits::MapStorageBase<Arc>* storage =
     536        new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
    537537      _arc_maps.push_back(std::make_pair(caption, storage));
    538538      return *this;
     
    544544    template <typename Value>
    545545    DigraphWriter& attribute(const std::string& caption, const Value& value) {
    546       _writer_bits::ValueStorageBase* storage = 
    547         new _writer_bits::ValueStorage<Value>(value);
     546      _writer_bits::ValueStorageBase* storage =
     547        new _writer_bits::ValueStorage<Value>(value);
    548548      _attributes.push_back(std::make_pair(caption, storage));
    549549      return *this;
     
    555555    /// writer.
    556556    template <typename Value, typename Converter>
    557     DigraphWriter& attribute(const std::string& caption, const Value& value, 
    558                              const Converter& converter = Converter()) {
    559       _writer_bits::ValueStorageBase* storage = 
    560         new _writer_bits::ValueStorage<Value, Converter>(value, converter);
     557    DigraphWriter& attribute(const std::string& caption, const Value& value,
     558                             const Converter& converter = Converter()) {
     559      _writer_bits::ValueStorageBase* storage =
     560        new _writer_bits::ValueStorage<Value, Converter>(value, converter);
    561561      _attributes.push_back(std::make_pair(caption, storage));
    562562      return *this;
     
    569569      typedef _writer_bits::MapLookUpConverter<Node> Converter;
    570570      Converter converter(_node_index);
    571       _writer_bits::ValueStorageBase* storage = 
    572         new _writer_bits::ValueStorage<Node, Converter>(node, converter);
     571      _writer_bits::ValueStorageBase* storage =
     572        new _writer_bits::ValueStorage<Node, Converter>(node, converter);
    573573      _attributes.push_back(std::make_pair(caption, storage));
    574574      return *this;
     
    581581      typedef _writer_bits::MapLookUpConverter<Arc> Converter;
    582582      Converter converter(_arc_index);
    583       _writer_bits::ValueStorageBase* storage = 
    584         new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
     583      _writer_bits::ValueStorageBase* storage =
     584        new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
    585585      _attributes.push_back(std::make_pair(caption, storage));
    586586      return *this;
     
    642642      _writer_bits::MapStorageBase<Node>* label = 0;
    643643      for (typename NodeMaps::iterator it = _node_maps.begin();
    644            it != _node_maps.end(); ++it) {
     644           it != _node_maps.end(); ++it) {
    645645        if (it->first == "label") {
    646           label = it->second;
    647           break;
    648         }
     646          label = it->second;
     647          break;
     648        }
    649649      }
    650650
    651651      *_os << "@nodes";
    652652      if (!_nodes_caption.empty()) {
    653         _writer_bits::writeToken(*_os << ' ', _nodes_caption);
     653        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
    654654      }
    655655      *_os << std::endl;
    656656
    657657      if (label == 0) {
    658         *_os << "label" << '\t';
     658        *_os << "label" << '\t';
    659659      }
    660660      for (typename NodeMaps::iterator it = _node_maps.begin();
    661            it != _node_maps.end(); ++it) {
    662         _writer_bits::writeToken(*_os, it->first) << '\t';
     661           it != _node_maps.end(); ++it) {
     662        _writer_bits::writeToken(*_os, it->first) << '\t';
    663663      }
    664664      *_os << std::endl;
     
    666666      std::vector<Node> nodes;
    667667      for (NodeIt n(_digraph); n != INVALID; ++n) {
    668         nodes.push_back(n);
    669       }
    670      
     668        nodes.push_back(n);
     669      }
     670
    671671      if (label == 0) {
    672         IdMap<Digraph, Node> id_map(_digraph);
    673         _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
    674         std::sort(nodes.begin(), nodes.end(), id_less);
     672        IdMap<Digraph, Node> id_map(_digraph);
     673        _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
     674        std::sort(nodes.begin(), nodes.end(), id_less);
    675675      } else {
    676         label->sort(nodes);
     676        label->sort(nodes);
    677677      }
    678678
    679679      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
    680         Node n = nodes[i];
    681         if (label == 0) {
    682           std::ostringstream os;
    683           os << _digraph.id(n);
    684           _writer_bits::writeToken(*_os, os.str());
    685           *_os << '\t';
    686           _node_index.insert(std::make_pair(n, os.str()));
    687         }
    688         for (typename NodeMaps::iterator it = _node_maps.begin();
    689              it != _node_maps.end(); ++it) {
    690           std::string value = it->second->get(n);
    691           _writer_bits::writeToken(*_os, value);
    692           if (it->first == "label") {
    693             _node_index.insert(std::make_pair(n, value));
    694           }
    695           *_os << '\t';
    696         }
    697         *_os << std::endl;
     680        Node n = nodes[i];
     681        if (label == 0) {
     682          std::ostringstream os;
     683          os << _digraph.id(n);
     684          _writer_bits::writeToken(*_os, os.str());
     685          *_os << '\t';
     686          _node_index.insert(std::make_pair(n, os.str()));
     687        }
     688        for (typename NodeMaps::iterator it = _node_maps.begin();
     689             it != _node_maps.end(); ++it) {
     690          std::string value = it->second->get(n);
     691          _writer_bits::writeToken(*_os, value);
     692          if (it->first == "label") {
     693            _node_index.insert(std::make_pair(n, value));
     694          }
     695          *_os << '\t';
     696        }
     697        *_os << std::endl;
    698698      }
    699699    }
     
    702702      _writer_bits::MapStorageBase<Node>* label = 0;
    703703      for (typename NodeMaps::iterator it = _node_maps.begin();
    704            it != _node_maps.end(); ++it) {
     704           it != _node_maps.end(); ++it) {
    705705        if (it->first == "label") {
    706           label = it->second;
    707           break;
    708         }
     706          label = it->second;
     707          break;
     708        }
    709709      }
    710710
    711711      if (label == 0) {
    712         for (NodeIt n(_digraph); n != INVALID; ++n) {
    713           std::ostringstream os;
    714           os << _digraph.id(n);
    715           _node_index.insert(std::make_pair(n, os.str()));       
    716         }       
     712        for (NodeIt n(_digraph); n != INVALID; ++n) {
     713          std::ostringstream os;
     714          os << _digraph.id(n);
     715          _node_index.insert(std::make_pair(n, os.str()));
     716        }
    717717      } else {
    718         for (NodeIt n(_digraph); n != INVALID; ++n) {
    719           std::string value = label->get(n);     
    720           _node_index.insert(std::make_pair(n, value));
    721         }
     718        for (NodeIt n(_digraph); n != INVALID; ++n) {
     719          std::string value = label->get(n);
     720          _node_index.insert(std::make_pair(n, value));
     721        }
    722722      }
    723723    }
     
    726726      _writer_bits::MapStorageBase<Arc>* label = 0;
    727727      for (typename ArcMaps::iterator it = _arc_maps.begin();
    728            it != _arc_maps.end(); ++it) {
     728           it != _arc_maps.end(); ++it) {
    729729        if (it->first == "label") {
    730           label = it->second;
    731           break;
    732         }
     730          label = it->second;
     731          break;
     732        }
    733733      }
    734734
    735735      *_os << "@arcs";
    736736      if (!_arcs_caption.empty()) {
    737         _writer_bits::writeToken(*_os << ' ', _arcs_caption);
     737        _writer_bits::writeToken(*_os << ' ', _arcs_caption);
    738738      }
    739739      *_os << std::endl;
     
    741741      *_os << '\t' << '\t';
    742742      if (label == 0) {
    743         *_os << "label" << '\t';
     743        *_os << "label" << '\t';
    744744      }
    745745      for (typename ArcMaps::iterator it = _arc_maps.begin();
    746            it != _arc_maps.end(); ++it) {
    747         _writer_bits::writeToken(*_os, it->first) << '\t';
     746           it != _arc_maps.end(); ++it) {
     747        _writer_bits::writeToken(*_os, it->first) << '\t';
    748748      }
    749749      *_os << std::endl;
     
    751751      std::vector<Arc> arcs;
    752752      for (ArcIt n(_digraph); n != INVALID; ++n) {
    753         arcs.push_back(n);
    754       }
    755      
     753        arcs.push_back(n);
     754      }
     755
    756756      if (label == 0) {
    757         IdMap<Digraph, Arc> id_map(_digraph);
    758         _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
    759         std::sort(arcs.begin(), arcs.end(), id_less);
     757        IdMap<Digraph, Arc> id_map(_digraph);
     758        _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
     759        std::sort(arcs.begin(), arcs.end(), id_less);
    760760      } else {
    761         label->sort(arcs);
     761        label->sort(arcs);
    762762      }
    763763
    764764      for (int i = 0; i < static_cast<int>(arcs.size()); ++i) {
    765         Arc a = arcs[i];
    766         _writer_bits::writeToken(*_os, _node_index.
    767                                 find(_digraph.source(a))->second);
    768         *_os << '\t';
    769         _writer_bits::writeToken(*_os, _node_index.
    770                                 find(_digraph.target(a))->second);
    771         *_os << '\t';
    772         if (label == 0) {
    773           std::ostringstream os;
    774           os << _digraph.id(a);
    775           _writer_bits::writeToken(*_os, os.str());
    776           *_os << '\t';
    777           _arc_index.insert(std::make_pair(a, os.str()));
    778         }
    779         for (typename ArcMaps::iterator it = _arc_maps.begin();
    780              it != _arc_maps.end(); ++it) {
    781           std::string value = it->second->get(a);
    782           _writer_bits::writeToken(*_os, value);
    783           if (it->first == "label") {
    784             _arc_index.insert(std::make_pair(a, value));
    785           }
    786           *_os << '\t';
    787         }
    788         *_os << std::endl;
     765        Arc a = arcs[i];
     766        _writer_bits::writeToken(*_os, _node_index.
     767                                find(_digraph.source(a))->second);
     768        *_os << '\t';
     769        _writer_bits::writeToken(*_os, _node_index.
     770                                find(_digraph.target(a))->second);
     771        *_os << '\t';
     772        if (label == 0) {
     773          std::ostringstream os;
     774          os << _digraph.id(a);
     775          _writer_bits::writeToken(*_os, os.str());
     776          *_os << '\t';
     777          _arc_index.insert(std::make_pair(a, os.str()));
     778        }
     779        for (typename ArcMaps::iterator it = _arc_maps.begin();
     780             it != _arc_maps.end(); ++it) {
     781          std::string value = it->second->get(a);
     782          _writer_bits::writeToken(*_os, value);
     783          if (it->first == "label") {
     784            _arc_index.insert(std::make_pair(a, value));
     785          }
     786          *_os << '\t';
     787        }
     788        *_os << std::endl;
    789789      }
    790790    }
     
    793793      _writer_bits::MapStorageBase<Arc>* label = 0;
    794794      for (typename ArcMaps::iterator it = _arc_maps.begin();
    795            it != _arc_maps.end(); ++it) {
     795           it != _arc_maps.end(); ++it) {
    796796        if (it->first == "label") {
    797           label = it->second;
    798           break;
    799         }
     797          label = it->second;
     798          break;
     799        }
    800800      }
    801801
    802802      if (label == 0) {
    803         for (ArcIt a(_digraph); a != INVALID; ++a) {
    804           std::ostringstream os;
    805           os << _digraph.id(a);
    806           _arc_index.insert(std::make_pair(a, os.str()));         
    807         }       
     803        for (ArcIt a(_digraph); a != INVALID; ++a) {
     804          std::ostringstream os;
     805          os << _digraph.id(a);
     806          _arc_index.insert(std::make_pair(a, os.str()));
     807        }
    808808      } else {
    809         for (ArcIt a(_digraph); a != INVALID; ++a) {
    810           std::string value = label->get(a);     
    811           _arc_index.insert(std::make_pair(a, value));
    812         }
     809        for (ArcIt a(_digraph); a != INVALID; ++a) {
     810          std::string value = label->get(a);
     811          _arc_index.insert(std::make_pair(a, value));
     812        }
    813813      }
    814814    }
     
    818818      *_os << "@attributes";
    819819      if (!_attributes_caption.empty()) {
    820         _writer_bits::writeToken(*_os << ' ', _attributes_caption);
     820        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
    821821      }
    822822      *_os << std::endl;
    823823      for (typename Attributes::iterator it = _attributes.begin();
    824            it != _attributes.end(); ++it) {
    825         _writer_bits::writeToken(*_os, it->first) << ' ';
    826         _writer_bits::writeToken(*_os, it->second->get());
    827         *_os << std::endl;
    828       }
    829     }
    830    
     824           it != _attributes.end(); ++it) {
     825        _writer_bits::writeToken(*_os, it->first) << ' ';
     826        _writer_bits::writeToken(*_os, it->second->get());
     827        *_os << std::endl;
     828      }
     829    }
     830
    831831  public:
    832    
    833     /// \name Execution of the writer   
     832
     833    /// \name Execution of the writer
    834834    /// @{
    835835
     
    839839    void run() {
    840840      if (!_skip_nodes) {
    841         writeNodes();
     841        writeNodes();
    842842      } else {
    843         createNodeIndex();
    844       }
    845       if (!_skip_arcs) {     
    846         writeArcs();
     843        createNodeIndex();
     844      }
     845      if (!_skip_arcs) {
     846        writeArcs();
    847847      } else {
    848         createArcIndex();
     848        createArcIndex();
    849849      }
    850850      writeAttributes();
     
    862862
    863863  /// \brief Return a \ref DigraphWriter class
    864   /// 
     864  ///
    865865  /// This function just returns a \ref DigraphWriter class.
    866866  /// \relates DigraphWriter
    867867  template <typename Digraph>
    868   DigraphWriter<Digraph> digraphWriter(std::ostream& os, 
    869                                        const Digraph& digraph) {
     868  DigraphWriter<Digraph> digraphWriter(std::ostream& os,
     869                                       const Digraph& digraph) {
    870870    DigraphWriter<Digraph> tmp(os, digraph);
    871871    return tmp;
     
    873873
    874874  /// \brief Return a \ref DigraphWriter class
    875   /// 
     875  ///
    876876  /// This function just returns a \ref DigraphWriter class.
    877877  /// \relates DigraphWriter
    878878  template <typename Digraph>
    879   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
    880                                        const Digraph& digraph) {
     879  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
     880                                       const Digraph& digraph) {
    881881    DigraphWriter<Digraph> tmp(fn, digraph);
    882882    return tmp;
     
    884884
    885885  /// \brief Return a \ref DigraphWriter class
    886   /// 
     886  ///
    887887  /// This function just returns a \ref DigraphWriter class.
    888888  /// \relates DigraphWriter
    889889  template <typename Digraph>
    890   DigraphWriter<Digraph> digraphWriter(const char* fn, 
    891                                        const Digraph& digraph) {
     890  DigraphWriter<Digraph> digraphWriter(const char* fn,
     891                                       const Digraph& digraph) {
    892892    DigraphWriter<Digraph> tmp(fn, digraph);
    893893    return tmp;
     
    898898
    899899  template <typename Graph>
    900   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);   
     900  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
    901901
    902902  template <typename Graph>
    903   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);   
     903  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
    904904
    905905  template <typename Graph>
    906   GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);   
     906  GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
    907907
    908908  /// \ingroup lemon_io
    909   /// 
     909  ///
    910910  /// \brief \ref lgf-format "LGF" writer for directed graphs
    911911  ///
     
    927927    typedef _Graph Graph;
    928928    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    929    
     929
    930930  private:
    931931
     
    939939    std::string _edges_caption;
    940940    std::string _attributes_caption;
    941    
     941
    942942    typedef std::map<Node, std::string> NodeIndex;
    943943    NodeIndex _node_index;
     
    945945    EdgeIndex _edge_index;
    946946
    947     typedef std::vector<std::pair<std::string, 
    948       _writer_bits::MapStorageBase<Node>* > > NodeMaps;   
    949     NodeMaps _node_maps; 
    950 
    951     typedef std::vector<std::pair<std::string, 
     947    typedef std::vector<std::pair<std::string,
     948      _writer_bits::MapStorageBase<Node>* > > NodeMaps;
     949    NodeMaps _node_maps;
     950
     951    typedef std::vector<std::pair<std::string,
    952952      _writer_bits::MapStorageBase<Edge>* > >EdgeMaps;
    953953    EdgeMaps _edge_maps;
    954954
    955     typedef std::vector<std::pair<std::string, 
     955    typedef std::vector<std::pair<std::string,
    956956      _writer_bits::ValueStorageBase*> > Attributes;
    957957    Attributes _attributes;
     
    966966    /// Construct a directed graph writer, which writes to the given
    967967    /// output stream.
    968     GraphWriter(std::ostream& is, const Graph& graph) 
     968    GraphWriter(std::ostream& is, const Graph& graph)
    969969      : _os(&is), local_os(false), _graph(graph),
    970         _skip_nodes(false), _skip_edges(false) {}
     970        _skip_nodes(false), _skip_edges(false) {}
    971971
    972972    /// \brief Constructor
     
    974974    /// Construct a directed graph writer, which writes to the given
    975975    /// output file.
    976     GraphWriter(const std::string& fn, const Graph& graph) 
     976    GraphWriter(const std::string& fn, const Graph& graph)
    977977      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    978         _skip_nodes(false), _skip_edges(false) {}
     978        _skip_nodes(false), _skip_edges(false) {}
    979979
    980980    /// \brief Constructor
     
    982982    /// Construct a directed graph writer, which writes to the given
    983983    /// output file.
    984     GraphWriter(const char* fn, const Graph& graph) 
     984    GraphWriter(const char* fn, const Graph& graph)
    985985      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    986         _skip_nodes(false), _skip_edges(false) {}
     986        _skip_nodes(false), _skip_edges(false) {}
    987987
    988988    /// \brief Destructor
    989989    ~GraphWriter() {
    990       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    991            it != _node_maps.end(); ++it) {
    992         delete it->second;
    993       }
    994 
    995       for (typename EdgeMaps::iterator it = _edge_maps.begin(); 
    996            it != _edge_maps.end(); ++it) {
    997         delete it->second;
    998       }
    999 
    1000       for (typename Attributes::iterator it = _attributes.begin(); 
    1001            it != _attributes.end(); ++it) {
    1002         delete it->second;
     990      for (typename NodeMaps::iterator it = _node_maps.begin();
     991           it != _node_maps.end(); ++it) {
     992        delete it->second;
     993      }
     994
     995      for (typename EdgeMaps::iterator it = _edge_maps.begin();
     996           it != _edge_maps.end(); ++it) {
     997        delete it->second;
     998      }
     999
     1000      for (typename Attributes::iterator it = _attributes.begin();
     1001           it != _attributes.end(); ++it) {
     1002        delete it->second;
    10031003      }
    10041004
    10051005      if (local_os) {
    1006         delete _os;
    1007       }
    1008     }
    1009    
     1006        delete _os;
     1007      }
     1008    }
     1009
    10101010  private:
    10111011
    1012     friend GraphWriter<Graph> graphWriter<>(std::ostream& os, 
    1013                                             const Graph& graph);   
    1014     friend GraphWriter<Graph> graphWriter<>(const std::string& fn, 
    1015                                             const Graph& graph);   
    1016     friend GraphWriter<Graph> graphWriter<>(const char *fn, 
    1017                                             const Graph& graph);   
    1018 
    1019     GraphWriter(GraphWriter& other) 
     1012    friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
     1013                                            const Graph& graph);
     1014    friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
     1015                                            const Graph& graph);
     1016    friend GraphWriter<Graph> graphWriter<>(const char *fn,
     1017                                            const Graph& graph);
     1018
     1019    GraphWriter(GraphWriter& other)
    10201020      : _os(other._os), local_os(other.local_os), _graph(other._graph),
    1021         _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
     1021        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
    10221022
    10231023      other._os = 0;
     
    10421042    /// \name Writing rules
    10431043    /// @{
    1044    
     1044
    10451045    /// \brief Node map writing rule
    10461046    ///
     
    10491049    GraphWriter& nodeMap(const std::string& caption, const Map& map) {
    10501050      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1051       _writer_bits::MapStorageBase<Node>* storage = 
    1052         new _writer_bits::MapStorage<Node, Map>(map);
     1051      _writer_bits::MapStorageBase<Node>* storage =
     1052        new _writer_bits::MapStorage<Node, Map>(map);
    10531053      _node_maps.push_back(std::make_pair(caption, storage));
    10541054      return *this;
     
    10601060    /// writer.
    10611061    template <typename Map, typename Converter>
    1062     GraphWriter& nodeMap(const std::string& caption, const Map& map, 
    1063                            const Converter& converter = Converter()) {
     1062    GraphWriter& nodeMap(const std::string& caption, const Map& map,
     1063                           const Converter& converter = Converter()) {
    10641064      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1065       _writer_bits::MapStorageBase<Node>* storage = 
    1066         new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
     1065      _writer_bits::MapStorageBase<Node>* storage =
     1066        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
    10671067      _node_maps.push_back(std::make_pair(caption, storage));
    10681068      return *this;
     
    10751075    GraphWriter& edgeMap(const std::string& caption, const Map& map) {
    10761076      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1077       _writer_bits::MapStorageBase<Edge>* storage = 
    1078         new _writer_bits::MapStorage<Edge, Map>(map);
     1077      _writer_bits::MapStorageBase<Edge>* storage =
     1078        new _writer_bits::MapStorage<Edge, Map>(map);
    10791079      _edge_maps.push_back(std::make_pair(caption, storage));
    10801080      return *this;
     
    10861086    /// writer.
    10871087    template <typename Map, typename Converter>
    1088     GraphWriter& edgeMap(const std::string& caption, const Map& map, 
    1089                           const Converter& converter = Converter()) {
     1088    GraphWriter& edgeMap(const std::string& caption, const Map& map,
     1089                          const Converter& converter = Converter()) {
    10901090      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1091       _writer_bits::MapStorageBase<Edge>* storage = 
    1092         new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
     1091      _writer_bits::MapStorageBase<Edge>* storage =
     1092        new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
    10931093      _edge_maps.push_back(std::make_pair(caption, storage));
    10941094      return *this;
     
    11011101    GraphWriter& arcMap(const std::string& caption, const Map& map) {
    11021102      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    1103       _writer_bits::MapStorageBase<Edge>* forward_storage = 
    1104         new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
     1103      _writer_bits::MapStorageBase<Edge>* forward_storage =
     1104        new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
    11051105      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1106       _writer_bits::MapStorageBase<Edge>* backward_storage = 
    1107         new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1106      _writer_bits::MapStorageBase<Edge>* backward_storage =
     1107        new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    11081108      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11091109      return *this;
     
    11151115    /// writer.
    11161116    template <typename Map, typename Converter>
    1117     GraphWriter& arcMap(const std::string& caption, const Map& map, 
    1118                           const Converter& converter = Converter()) {
     1117    GraphWriter& arcMap(const std::string& caption, const Map& map,
     1118                          const Converter& converter = Converter()) {
    11191119      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    1120       _writer_bits::MapStorageBase<Edge>* forward_storage = 
    1121         new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    1122         (_graph, map, converter);
     1120      _writer_bits::MapStorageBase<Edge>* forward_storage =
     1121        new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1122        (_graph, map, converter);
    11231123      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1124       _writer_bits::MapStorageBase<Edge>* backward_storage = 
    1125         new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    1126         (_graph, map, converter);
     1124      _writer_bits::MapStorageBase<Edge>* backward_storage =
     1125        new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1126        (_graph, map, converter);
    11271127      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11281128      return *this;
     
    11341134    template <typename Value>
    11351135    GraphWriter& attribute(const std::string& caption, const Value& value) {
    1136       _writer_bits::ValueStorageBase* storage = 
    1137         new _writer_bits::ValueStorage<Value>(value);
     1136      _writer_bits::ValueStorageBase* storage =
     1137        new _writer_bits::ValueStorage<Value>(value);
    11381138      _attributes.push_back(std::make_pair(caption, storage));
    11391139      return *this;
     
    11451145    /// writer.
    11461146    template <typename Value, typename Converter>
    1147     GraphWriter& attribute(const std::string& caption, const Value& value, 
    1148                              const Converter& converter = Converter()) {
    1149       _writer_bits::ValueStorageBase* storage = 
    1150         new _writer_bits::ValueStorage<Value, Converter>(value, converter);
     1147    GraphWriter& attribute(const std::string& caption, const Value& value,
     1148                             const Converter& converter = Converter()) {
     1149      _writer_bits::ValueStorageBase* storage =
     1150        new _writer_bits::ValueStorage<Value, Converter>(value, converter);
    11511151      _attributes.push_back(std::make_pair(caption, storage));
    11521152      return *this;
     
    11591159      typedef _writer_bits::MapLookUpConverter<Node> Converter;
    11601160      Converter converter(_node_index);
    1161       _writer_bits::ValueStorageBase* storage = 
    1162         new _writer_bits::ValueStorage<Node, Converter>(node, converter);
     1161      _writer_bits::ValueStorageBase* storage =
     1162        new _writer_bits::ValueStorage<Node, Converter>(node, converter);
    11631163      _attributes.push_back(std::make_pair(caption, storage));
    11641164      return *this;
     
    11711171      typedef _writer_bits::MapLookUpConverter<Edge> Converter;
    11721172      Converter converter(_edge_index);
    1173       _writer_bits::ValueStorageBase* storage = 
    1174         new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
     1173      _writer_bits::ValueStorageBase* storage =
     1174        new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
    11751175      _attributes.push_back(std::make_pair(caption, storage));
    11761176      return *this;
     
    11831183      typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
    11841184      Converter converter(_graph, _edge_index);
    1185       _writer_bits::ValueStorageBase* storage = 
    1186         new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
     1185      _writer_bits::ValueStorageBase* storage =
     1186        new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
    11871187      _attributes.push_back(std::make_pair(caption, storage));
    11881188      return *this;
     
    12441244      _writer_bits::MapStorageBase<Node>* label = 0;
    12451245      for (typename NodeMaps::iterator it = _node_maps.begin();
    1246            it != _node_maps.end(); ++it) {
     1246           it != _node_maps.end(); ++it) {
    12471247        if (it->first == "label") {
    1248           label = it->second;
    1249           break;
    1250         }
     1248          label = it->second;
     1249          break;
     1250        }
    12511251      }
    12521252
    12531253      *_os << "@nodes";
    12541254      if (!_nodes_caption.empty()) {
    1255         _writer_bits::writeToken(*_os << ' ', _nodes_caption);
     1255        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
    12561256      }
    12571257      *_os << std::endl;
    12581258
    12591259      if (label == 0) {
    1260         *_os << "label" << '\t';
     1260        *_os << "label" << '\t';
    12611261      }
    12621262      for (typename NodeMaps::iterator it = _node_maps.begin();
    1263            it != _node_maps.end(); ++it) {
    1264         _writer_bits::writeToken(*_os, it->first) << '\t';
     1263           it != _node_maps.end(); ++it) {
     1264        _writer_bits::writeToken(*_os, it->first) << '\t';
    12651265      }
    12661266      *_os << std::endl;
     
    12681268      std::vector<Node> nodes;
    12691269      for (NodeIt n(_graph); n != INVALID; ++n) {
    1270         nodes.push_back(n);
    1271       }
    1272      
     1270        nodes.push_back(n);
     1271      }
     1272
    12731273      if (label == 0) {
    1274         IdMap<Graph, Node> id_map(_graph);
    1275         _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
    1276         std::sort(nodes.begin(), nodes.end(), id_less);
     1274        IdMap<Graph, Node> id_map(_graph);
     1275        _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
     1276        std::sort(nodes.begin(), nodes.end(), id_less);
    12771277      } else {
    1278         label->sort(nodes);
     1278        label->sort(nodes);
    12791279      }
    12801280
    12811281      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
    1282         Node n = nodes[i];
    1283         if (label == 0) {
    1284           std::ostringstream os;
    1285           os << _graph.id(n);
    1286           _writer_bits::writeToken(*_os, os.str());
    1287           *_os << '\t';
    1288           _node_index.insert(std::make_pair(n, os.str()));
    1289         }
    1290         for (typename NodeMaps::iterator it = _node_maps.begin();
    1291              it != _node_maps.end(); ++it) {
    1292           std::string value = it->second->get(n);
    1293           _writer_bits::writeToken(*_os, value);
    1294           if (it->first == "label") {
    1295             _node_index.insert(std::make_pair(n, value));
    1296           }
    1297           *_os << '\t';
    1298         }
    1299         *_os << std::endl;
     1282        Node n = nodes[i];
     1283        if (label == 0) {
     1284          std::ostringstream os;
     1285          os << _graph.id(n);
     1286          _writer_bits::writeToken(*_os, os.str());
     1287          *_os << '\t';
     1288          _node_index.insert(std::make_pair(n, os.str()));
     1289        }
     1290        for (typename NodeMaps::iterator it = _node_maps.begin();
     1291             it != _node_maps.end(); ++it) {
     1292          std::string value = it->second->get(n);
     1293          _writer_bits::writeToken(*_os, value);
     1294          if (it->first == "label") {
     1295            _node_index.insert(std::make_pair(n, value));
     1296          }
     1297          *_os << '\t';
     1298        }
     1299        *_os << std::endl;
    13001300      }
    13011301    }
     
    13041304      _writer_bits::MapStorageBase<Node>* label = 0;
    13051305      for (typename NodeMaps::iterator it = _node_maps.begin();
    1306            it != _node_maps.end(); ++it) {
     1306           it != _node_maps.end(); ++it) {
    13071307        if (it->first == "label") {
    1308           label = it->second;
    1309           break;
    1310         }
     1308          label = it->second;
     1309          break;
     1310        }
    13111311      }
    13121312
    13131313      if (label == 0) {
    1314         for (NodeIt n(_graph); n != INVALID; ++n) {
    1315           std::ostringstream os;
    1316           os << _graph.id(n);
    1317           _node_index.insert(std::make_pair(n, os.str()));       
    1318         }       
     1314        for (NodeIt n(_graph); n != INVALID; ++n) {
     1315          std::ostringstream os;
     1316          os << _graph.id(n);
     1317          _node_index.insert(std::make_pair(n, os.str()));
     1318        }
    13191319      } else {
    1320         for (NodeIt n(_graph); n != INVALID; ++n) {
    1321           std::string value = label->get(n);     
    1322           _node_index.insert(std::make_pair(n, value));
    1323         }
     1320        for (NodeIt n(_graph); n != INVALID; ++n) {
     1321          std::string value = label->get(n);
     1322          _node_index.insert(std::make_pair(n, value));
     1323        }
    13241324      }
    13251325    }
     
    13281328      _writer_bits::MapStorageBase<Edge>* label = 0;
    13291329      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1330            it != _edge_maps.end(); ++it) {
     1330           it != _edge_maps.end(); ++it) {
    13311331        if (it->first == "label") {
    1332           label = it->second;
    1333           break;
    1334         }
     1332          label = it->second;
     1333          break;
     1334        }
    13351335      }
    13361336
    13371337      *_os << "@edges";
    13381338      if (!_edges_caption.empty()) {
    1339         _writer_bits::writeToken(*_os << ' ', _edges_caption);
     1339        _writer_bits::writeToken(*_os << ' ', _edges_caption);
    13401340      }
    13411341      *_os << std::endl;
     
    13431343      *_os << '\t' << '\t';
    13441344      if (label == 0) {
    1345         *_os << "label" << '\t';
     1345        *_os << "label" << '\t';
    13461346      }
    13471347      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1348            it != _edge_maps.end(); ++it) {
    1349         _writer_bits::writeToken(*_os, it->first) << '\t';
     1348           it != _edge_maps.end(); ++it) {
     1349        _writer_bits::writeToken(*_os, it->first) << '\t';
    13501350      }
    13511351      *_os << std::endl;
     
    13531353      std::vector<Edge> edges;
    13541354      for (EdgeIt n(_graph); n != INVALID; ++n) {
    1355         edges.push_back(n);
    1356       }
    1357      
     1355        edges.push_back(n);
     1356      }
     1357
    13581358      if (label == 0) {
    1359         IdMap<Graph, Edge> id_map(_graph);
    1360         _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
    1361         std::sort(edges.begin(), edges.end(), id_less);
     1359        IdMap<Graph, Edge> id_map(_graph);
     1360        _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
     1361        std::sort(edges.begin(), edges.end(), id_less);
    13621362      } else {
    1363         label->sort(edges);
     1363        label->sort(edges);
    13641364      }
    13651365
    13661366      for (int i = 0; i < static_cast<int>(edges.size()); ++i) {
    1367         Edge e = edges[i];
    1368         _writer_bits::writeToken(*_os, _node_index.
    1369                                 find(_graph.u(e))->second);
    1370         *_os << '\t';
    1371         _writer_bits::writeToken(*_os, _node_index.
    1372                                 find(_graph.v(e))->second);
    1373         *_os << '\t';
    1374         if (label == 0) {
    1375           std::ostringstream os;
    1376           os << _graph.id(e);
    1377           _writer_bits::writeToken(*_os, os.str());
    1378           *_os << '\t';
    1379           _edge_index.insert(std::make_pair(e, os.str()));
    1380         }
    1381         for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1382              it != _edge_maps.end(); ++it) {
    1383           std::string value = it->second->get(e);
    1384           _writer_bits::writeToken(*_os, value);
    1385           if (it->first == "label") {
    1386             _edge_index.insert(std::make_pair(e, value));
    1387           }
    1388           *_os << '\t';
    1389         }
    1390         *_os << std::endl;
     1367        Edge e = edges[i];
     1368        _writer_bits::writeToken(*_os, _node_index.
     1369                                find(_graph.u(e))->second);
     1370        *_os << '\t';
     1371        _writer_bits::writeToken(*_os, _node_index.
     1372                                find(_graph.v(e))->second);
     1373        *_os << '\t';
     1374        if (label == 0) {
     1375          std::ostringstream os;
     1376          os << _graph.id(e);
     1377          _writer_bits::writeToken(*_os, os.str());
     1378          *_os << '\t';
     1379          _edge_index.insert(std::make_pair(e, os.str()));
     1380        }
     1381        for (typename EdgeMaps::iterator it = _edge_maps.begin();
     1382             it != _edge_maps.end(); ++it) {
     1383          std::string value = it->second->get(e);
     1384          _writer_bits::writeToken(*_os, value);
     1385          if (it->first == "label") {
     1386            _edge_index.insert(std::make_pair(e, value));
     1387          }
     1388          *_os << '\t';
     1389        }
     1390        *_os << std::endl;
    13911391      }
    13921392    }
     
    13951395      _writer_bits::MapStorageBase<Edge>* label = 0;
    13961396      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1397            it != _edge_maps.end(); ++it) {
     1397           it != _edge_maps.end(); ++it) {
    13981398        if (it->first == "label") {
    1399           label = it->second;
    1400           break;
    1401         }
     1399          label = it->second;
     1400          break;
     1401        }
    14021402      }
    14031403
    14041404      if (label == 0) {
    1405         for (EdgeIt e(_graph); e != INVALID; ++e) {
    1406           std::ostringstream os;
    1407           os << _graph.id(e);
    1408           _edge_index.insert(std::make_pair(e, os.str()));       
    1409         }       
     1405        for (EdgeIt e(_graph); e != INVALID; ++e) {
     1406          std::ostringstream os;
     1407          os << _graph.id(e);
     1408          _edge_index.insert(std::make_pair(e, os.str()));
     1409        }
    14101410      } else {
    1411         for (EdgeIt e(_graph); e != INVALID; ++e) {
    1412           std::string value = label->get(e);     
    1413           _edge_index.insert(std::make_pair(e, value));
    1414         }
     1411        for (EdgeIt e(_graph); e != INVALID; ++e) {
     1412          std::string value = label->get(e);
     1413          _edge_index.insert(std::make_pair(e, value));
     1414        }
    14151415      }
    14161416    }
     
    14201420      *_os << "@attributes";
    14211421      if (!_attributes_caption.empty()) {
    1422         _writer_bits::writeToken(*_os << ' ', _attributes_caption);
     1422        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
    14231423      }
    14241424      *_os << std::endl;
    14251425      for (typename Attributes::iterator it = _attributes.begin();
    1426            it != _attributes.end(); ++it) {
    1427         _writer_bits::writeToken(*_os, it->first) << ' ';
    1428         _writer_bits::writeToken(*_os, it->second->get());
    1429         *_os << std::endl;
    1430       }
    1431     }
    1432    
     1426           it != _attributes.end(); ++it) {
     1427        _writer_bits::writeToken(*_os, it->first) << ' ';
     1428        _writer_bits::writeToken(*_os, it->second->get());
     1429        *_os << std::endl;
     1430      }
     1431    }
     1432
    14331433  public:
    1434    
    1435     /// \name Execution of the writer   
     1434
     1435    /// \name Execution of the writer
    14361436    /// @{
    14371437
     
    14411441    void run() {
    14421442      if (!_skip_nodes) {
    1443         writeNodes();
     1443        writeNodes();
    14441444      } else {
    1445         createNodeIndex();
    1446       }
    1447       if (!_skip_edges) {     
    1448         writeEdges();
     1445        createNodeIndex();
     1446      }
     1447      if (!_skip_edges) {
     1448        writeEdges();
    14491449      } else {
    1450         createEdgeIndex();
     1450        createEdgeIndex();
    14511451      }
    14521452      writeAttributes();
     
    14641464
    14651465  /// \brief Return a \ref GraphWriter class
    1466   /// 
     1466  ///
    14671467  /// This function just returns a \ref GraphWriter class.
    14681468  /// \relates GraphWriter
     
    14741474
    14751475  /// \brief Return a \ref GraphWriter class
    1476   /// 
     1476  ///
    14771477  /// This function just returns a \ref GraphWriter class.
    14781478  /// \relates GraphWriter
     
    14841484
    14851485  /// \brief Return a \ref GraphWriter class
    1486   /// 
     1486  ///
    14871487  /// This function just returns a \ref GraphWriter class.
    14881488  /// \relates GraphWriter
  • lemon/list_graph.h

    r184 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3838      int prev, next;
    3939    };
    40  
     40
    4141    struct ArcT {
    4242      int target, source;
     
    5454
    5555    int first_free_arc;
    56    
     56
    5757  public:
    58    
     58
    5959    typedef ListDigraphBase Digraph;
    60    
     60
    6161    class Node {
    6262      friend class ListDigraphBase;
     
    9393    ListDigraphBase()
    9494      : nodes(), first_node(-1),
    95         first_free_node(-1), arcs(), first_free_arc(-1) {}
    96 
    97    
    98     int maxNodeId() const { return nodes.size()-1; } 
     95        first_free_node(-1), arcs(), first_free_arc(-1) {}
     96
     97
     98    int maxNodeId() const { return nodes.size()-1; }
    9999    int maxArcId() const { return arcs.size()-1; }
    100100
     
    103103
    104104
    105     void first(Node& node) const { 
     105    void first(Node& node) const {
    106106      node.id = first_node;
    107107    }
     
    112112
    113113
    114     void first(Arc& arc) const { 
     114    void first(Arc& arc) const {
    115115      int n;
    116       for(n = first_node; 
    117           n!=-1 && nodes[n].first_in == -1;
    118           n = nodes[n].next) {}
     116      for(n = first_node;
     117          n!=-1 && nodes[n].first_in == -1;
     118          n = nodes[n].next) {}
    119119      arc.id = (n == -1) ? -1 : nodes[n].first_in;
    120120    }
     
    122122    void next(Arc& arc) const {
    123123      if (arcs[arc.id].next_in != -1) {
    124         arc.id = arcs[arc.id].next_in;
    125       } else {
    126         int n;
    127         for(n = nodes[arcs[arc.id].target].next;
    128             n!=-1 && nodes[n].first_in == -1;
    129             n = nodes[n].next) {}
    130         arc.id = (n == -1) ? -1 : nodes[n].first_in;
    131       }     
     124        arc.id = arcs[arc.id].next_in;
     125      } else {
     126        int n;
     127        for(n = nodes[arcs[arc.id].target].next;
     128            n!=-1 && nodes[n].first_in == -1;
     129            n = nodes[n].next) {}
     130        arc.id = (n == -1) ? -1 : nodes[n].first_in;
     131      }
    132132    }
    133133
     
    146146    }
    147147
    148    
     148
    149149    static int id(Node v) { return v.id; }
    150150    static int id(Arc e) { return e.id; }
     
    153153    static Arc arcFromId(int id) { return Arc(id);}
    154154
    155     bool valid(Node n) const { 
    156       return n.id >= 0 && n.id < static_cast<int>(nodes.size()) && 
    157         nodes[n.id].prev != -2;
    158     }
    159 
    160     bool valid(Arc a) const { 
    161       return a.id >= 0 && a.id < static_cast<int>(arcs.size()) && 
    162         arcs[a.id].prev_in != -2;
    163     }
    164 
    165     Node addNode() {     
     155    bool valid(Node n) const {
     156      return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
     157        nodes[n.id].prev != -2;
     158    }
     159
     160    bool valid(Arc a) const {
     161      return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
     162        arcs[a.id].prev_in != -2;
     163    }
     164
     165    Node addNode() {
    166166      int n;
    167      
     167
    168168      if(first_free_node==-1) {
    169         n = nodes.size();
    170         nodes.push_back(NodeT());
    171       } else {
    172         n = first_free_node;
    173         first_free_node = nodes[n].next;
    174       }
    175      
     169        n = nodes.size();
     170        nodes.push_back(NodeT());
     171      } else {
     172        n = first_free_node;
     173        first_free_node = nodes[n].next;
     174      }
     175
    176176      nodes[n].next = first_node;
    177177      if(first_node != -1) nodes[first_node].prev = n;
    178178      first_node = n;
    179179      nodes[n].prev = -1;
    180      
     180
    181181      nodes[n].first_in = nodes[n].first_out = -1;
    182      
     182
    183183      return Node(n);
    184184    }
    185    
     185
    186186    Arc addArc(Node u, Node v) {
    187       int n;     
     187      int n;
    188188
    189189      if (first_free_arc == -1) {
    190         n = arcs.size();
    191         arcs.push_back(ArcT());
    192       } else {
    193         n = first_free_arc;
    194         first_free_arc = arcs[n].next_in;
    195       }
    196      
    197       arcs[n].source = u.id; 
     190        n = arcs.size();
     191        arcs.push_back(ArcT());
     192      } else {
     193        n = first_free_arc;
     194        first_free_arc = arcs[n].next_in;
     195      }
     196
     197      arcs[n].source = u.id;
    198198      arcs[n].target = v.id;
    199199
    200200      arcs[n].next_out = nodes[u.id].first_out;
    201201      if(nodes[u.id].first_out != -1) {
    202         arcs[nodes[u.id].first_out].prev_out = n;
    203       }
    204      
     202        arcs[nodes[u.id].first_out].prev_out = n;
     203      }
     204
    205205      arcs[n].next_in = nodes[v.id].first_in;
    206206      if(nodes[v.id].first_in != -1) {
    207         arcs[nodes[v.id].first_in].prev_in = n;
    208       }
    209      
     207        arcs[nodes[v.id].first_in].prev_in = n;
     208      }
     209
    210210      arcs[n].prev_in = arcs[n].prev_out = -1;
    211        
     211
    212212      nodes[u.id].first_out = nodes[v.id].first_in = n;
    213213
    214214      return Arc(n);
    215215    }
    216    
     216
    217217    void erase(const Node& node) {
    218218      int n = node.id;
    219      
     219
    220220      if(nodes[n].next != -1) {
    221         nodes[nodes[n].next].prev = nodes[n].prev;
    222       }
    223      
     221        nodes[nodes[n].next].prev = nodes[n].prev;
     222      }
     223
    224224      if(nodes[n].prev != -1) {
    225         nodes[nodes[n].prev].next = nodes[n].next;
    226       } else {
    227         first_node = nodes[n].next;
    228       }
    229      
     225        nodes[nodes[n].prev].next = nodes[n].next;
     226      } else {
     227        first_node = nodes[n].next;
     228      }
     229
    230230      nodes[n].next = first_free_node;
    231231      first_free_node = n;
     
    233233
    234234    }
    235    
     235
    236236    void erase(const Arc& arc) {
    237237      int n = arc.id;
    238      
     238
    239239      if(arcs[n].next_in!=-1) {
    240         arcs[arcs[n].next_in].prev_in = arcs[n].prev_in;
     240        arcs[arcs[n].next_in].prev_in = arcs[n].prev_in;
    241241      }
    242242
    243243      if(arcs[n].prev_in!=-1) {
    244         arcs[arcs[n].prev_in].next_in = arcs[n].next_in;
    245       } else {
    246         nodes[arcs[n].target].first_in = arcs[n].next_in;
    247       }
    248 
    249      
     244        arcs[arcs[n].prev_in].next_in = arcs[n].next_in;
     245      } else {
     246        nodes[arcs[n].target].first_in = arcs[n].next_in;
     247      }
     248
     249
    250250      if(arcs[n].next_out!=-1) {
    251         arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
    252       } 
     251        arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
     252      }
    253253
    254254      if(arcs[n].prev_out!=-1) {
    255         arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
    256       } else {
    257         nodes[arcs[n].source].first_out = arcs[n].next_out;
    258       }
    259      
     255        arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
     256      } else {
     257        nodes[arcs[n].source].first_out = arcs[n].next_out;
     258      }
     259
    260260      arcs[n].next_in = first_free_arc;
    261261      first_free_arc = n;
     
    270270
    271271  protected:
    272     void changeTarget(Arc e, Node n) 
     272    void changeTarget(Arc e, Node n)
    273273    {
    274274      if(arcs[e.id].next_in != -1)
    275         arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in;
     275        arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in;
    276276      if(arcs[e.id].prev_in != -1)
    277         arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in;
     277        arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in;
    278278      else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in;
    279279      if (nodes[n.id].first_in != -1) {
    280         arcs[nodes[n.id].first_in].prev_in = e.id;
     280        arcs[nodes[n.id].first_in].prev_in = e.id;
    281281      }
    282282      arcs[e.id].target = n.id;
     
    285285      nodes[n.id].first_in = e.id;
    286286    }
    287     void changeSource(Arc e, Node n) 
     287    void changeSource(Arc e, Node n)
    288288    {
    289289      if(arcs[e.id].next_out != -1)
    290         arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out;
     290        arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out;
    291291      if(arcs[e.id].prev_out != -1)
    292         arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out;
     292        arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out;
    293293      else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out;
    294294      if (nodes[n.id].first_out != -1) {
    295         arcs[nodes[n.id].first_out].prev_out = e.id;
     295        arcs[nodes[n.id].first_out].prev_out = e.id;
    296296      }
    297297      arcs[e.id].source = n.id;
     
    308308  /// @{
    309309
    310   ///A general directed graph structure. 
    311 
    312   ///\ref ListDigraph is a simple and fast <em>directed graph</em> 
    313   ///implementation based on static linked lists that are stored in 
    314   ///\c std::vector structures.   
     310  ///A general directed graph structure.
     311
     312  ///\ref ListDigraph is a simple and fast <em>directed graph</em>
     313  ///implementation based on static linked lists that are stored in
     314  ///\c std::vector structures.
    315315  ///
    316316  ///It conforms to the \ref concepts::Digraph "Digraph concept" and it
     
    327327  private:
    328328    ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
    329    
     329
    330330    ///ListDigraph is \e not copy constructible. Use copyDigraph() instead.
    331331    ///
     
    342342
    343343    /// Constructor
    344    
     344
    345345    /// Constructor.
    346346    ///
     
    348348
    349349    ///Add a new node to the digraph.
    350    
     350
    351351    ///Add a new node to the digraph.
    352352    ///\return the new node.
     
    354354
    355355    ///Add a new arc to the digraph.
    356    
     356
    357357    ///Add a new arc to the digraph with source node \c s
    358358    ///and target node \c t.
    359359    ///\return the new arc.
    360     Arc addArc(const Node& s, const Node& t) { 
    361       return Parent::addArc(s, t); 
     360    Arc addArc(const Node& s, const Node& t) {
     361      return Parent::addArc(s, t);
    362362    }
    363363
     
    365365
    366366    /// This function gives back true if the given node is valid,
    367     /// ie. it is a real node of the graph. 
     367    /// ie. it is a real node of the graph.
    368368    ///
    369369    /// \warning A Node pointing to a removed item
     
    375375
    376376    /// This function gives back true if the given arc is valid,
    377     /// ie. it is a real arc of the graph. 
     377    /// ie. it is a real arc of the graph.
    378378    ///
    379379    /// \warning An Arc pointing to a removed item
     
    392392    ///\warning This functionality cannot be used together with the Snapshot
    393393    ///feature.
    394     void changeTarget(Arc e, Node n) { 
    395       Parent::changeTarget(e,n); 
     394    void changeTarget(Arc e, Node n) {
     395      Parent::changeTarget(e,n);
    396396    }
    397397    /// Change the source of \c e to \c n
     
    405405    ///\warning This functionality cannot be used together with the Snapshot
    406406    ///feature.
    407     void changeSource(Arc e, Node n) { 
     407    void changeSource(Arc e, Node n) {
    408408      Parent::changeSource(e,n);
    409409    }
     
    457457    ///\warning This functionality cannot be used together with the Snapshot
    458458    ///feature.
    459     void contract(Node a, Node b, bool r = true) 
     459    void contract(Node a, Node b, bool r = true)
    460460    {
    461461      for(OutArcIt e(*this,b);e!=INVALID;) {
    462         OutArcIt f=e;
    463         ++f;
    464         if(r && target(e)==a) erase(e);
    465         else changeSource(e,a);
    466         e=f;
     462        OutArcIt f=e;
     463        ++f;
     464        if(r && target(e)==a) erase(e);
     465        else changeSource(e,a);
     466        e=f;
    467467      }
    468468      for(InArcIt e(*this,b);e!=INVALID;) {
    469         InArcIt f=e;
    470         ++f;
    471         if(r && source(e)==a) erase(e);
    472         else changeTarget(e,a);
    473         e=f;
     469        InArcIt f=e;
     470        ++f;
     471        if(r && source(e)==a) erase(e);
     472        else changeTarget(e,a);
     473        e=f;
    474474      }
    475475      erase(b);
     
    486486    ///\note The <tt>ArcIt</tt>s referencing a moved arc remain
    487487    ///valid. However <tt>InArcIt</tt>s and <tt>OutArcIt</tt>s may
    488     ///be invalidated. 
     488    ///be invalidated.
    489489    ///
    490490    ///\warning This functionality cannot be used together with the
     
    495495      Node b = addNode();
    496496      for(OutArcIt e(*this,n);e!=INVALID;) {
    497         OutArcIt f=e;
    498         ++f;
    499         changeSource(e,b);
    500         e=f;
     497         OutArcIt f=e;
     498        ++f;
     499        changeSource(e,b);
     500        e=f;
    501501      }
    502502      if (connect) addArc(n,b);
    503503      return b;
    504504    }
    505      
     505
    506506    ///Split an arc.
    507507
     
    520520      return b;
    521521    }
    522      
     522
    523523    /// \brief Class to make a snapshot of the digraph and restore
    524524    /// it later.
     
    530530    ///
    531531    /// \warning Arc and node deletions and other modifications (e.g.
    532     /// contracting, splitting, reversing arcs or nodes) cannot be 
    533     /// restored. These events invalidate the snapshot. 
     532    /// contracting, splitting, reversing arcs or nodes) cannot be
     533    /// restored. These events invalidate the snapshot.
    534534    class Snapshot {
    535535    protected:
     
    546546        using NodeNotifier::ObserverBase::detach;
    547547        using NodeNotifier::ObserverBase::attached;
    548        
     548
    549549      protected:
    550        
     550
    551551        virtual void add(const Node& node) {
    552552          snapshot.addNode(node);
     
    568568          Node node;
    569569          std::vector<Node> nodes;
    570           for (notifier()->first(node); node != INVALID; 
     570          for (notifier()->first(node); node != INVALID;
    571571               notifier()->next(node)) {
    572572            nodes.push_back(node);
     
    578578        virtual void clear() {
    579579          Node node;
    580           for (notifier()->first(node); node != INVALID; 
     580          for (notifier()->first(node); node != INVALID;
    581581               notifier()->next(node)) {
    582582            snapshot.eraseNode(node);
     
    596596        using ArcNotifier::ObserverBase::detach;
    597597        using ArcNotifier::ObserverBase::attached;
    598        
     598
    599599      protected:
    600600
     
    618618          Arc arc;
    619619          std::vector<Arc> arcs;
    620           for (notifier()->first(arc); arc != INVALID; 
     620          for (notifier()->first(arc); arc != INVALID;
    621621               notifier()->next(arc)) {
    622622            arcs.push_back(arc);
     
    628628        virtual void clear() {
    629629          Arc arc;
    630           for (notifier()->first(arc); arc != INVALID; 
     630          for (notifier()->first(arc); arc != INVALID;
    631631               notifier()->next(arc)) {
    632632            snapshot.eraseArc(arc);
     
    636636        Snapshot& snapshot;
    637637      };
    638      
     638
    639639      ListDigraph *digraph;
    640640
     
    647647
    648648      void addNode(const Node& node) {
    649         added_nodes.push_front(node);       
     649        added_nodes.push_front(node);
    650650      }
    651651      void eraseNode(const Node& node) {
    652         std::list<Node>::iterator it = 
     652        std::list<Node>::iterator it =
    653653          std::find(added_nodes.begin(), added_nodes.end(), node);
    654654        if (it == added_nodes.end()) {
     
    662662
    663663      void addArc(const Arc& arc) {
    664         added_arcs.push_front(arc);       
     664        added_arcs.push_front(arc);
    665665      }
    666666      void eraseArc(const Arc& arc) {
    667         std::list<Arc>::iterator it = 
     667        std::list<Arc>::iterator it =
    668668          std::find(added_arcs.begin(), added_arcs.end(), arc);
    669669        if (it == added_arcs.end()) {
    670670          clear();
    671           node_observer_proxy.detach(); 
     671          node_observer_proxy.detach();
    672672          throw ArcNotifier::ImmediateDetach();
    673673        } else {
    674674          added_arcs.erase(it);
    675         }       
     675        }
    676676      }
    677677
    678678      void attach(ListDigraph &_digraph) {
    679         digraph = &_digraph;
    680         node_observer_proxy.attach(digraph->notifier(Node()));
     679        digraph = &_digraph;
     680        node_observer_proxy.attach(digraph->notifier(Node()));
    681681        arc_observer_proxy.attach(digraph->notifier(Arc()));
    682682      }
    683            
     683
    684684      void detach() {
    685         node_observer_proxy.detach();
    686         arc_observer_proxy.detach();
     685        node_observer_proxy.detach();
     686        arc_observer_proxy.detach();
    687687      }
    688688
     
    693693      void clear() {
    694694        added_nodes.clear();
    695         added_arcs.clear();       
     695        added_arcs.clear();
    696696      }
    697697
     
    702702      /// Default constructor.
    703703      /// To actually make a snapshot you must call save().
    704       Snapshot() 
    705         : digraph(0), node_observer_proxy(*this), 
     704      Snapshot()
     705        : digraph(0), node_observer_proxy(*this),
    706706          arc_observer_proxy(*this) {}
    707      
     707
    708708      /// \brief Constructor that immediately makes a snapshot.
    709       ///     
     709      ///
    710710      /// This constructor immediately makes a snapshot of the digraph.
    711711      /// \param _digraph The digraph we make a snapshot of.
    712       Snapshot(ListDigraph &_digraph) 
    713         : node_observer_proxy(*this), 
     712      Snapshot(ListDigraph &_digraph)
     713        : node_observer_proxy(*this),
    714714          arc_observer_proxy(*this) {
    715         attach(_digraph);
    716       }
    717      
     715        attach(_digraph);
     716      }
     717
    718718      /// \brief Make a snapshot.
    719719      ///
     
    730730        attach(_digraph);
    731731      }
    732      
     732
    733733      /// \brief Undo the changes until the last snapshot.
    734       // 
     734      //
    735735      /// Undo the changes until the last snapshot created by save().
    736736      void restore() {
    737         detach();
    738         for(std::list<Arc>::iterator it = added_arcs.begin();
     737        detach();
     738        for(std::list<Arc>::iterator it = added_arcs.begin();
    739739            it != added_arcs.end(); ++it) {
    740           digraph->erase(*it);
    741         }
    742         for(std::list<Node>::iterator it = added_nodes.begin();
     740          digraph->erase(*it);
     741        }
     742        for(std::list<Node>::iterator it = added_nodes.begin();
    743743            it != added_nodes.end(); ++it) {
    744           digraph->erase(*it);
    745         }
     744          digraph->erase(*it);
     745        }
    746746        clear();
    747747      }
     
    754754      }
    755755    };
    756    
     756
    757757  };
    758758
     
    767767      int prev, next;
    768768    };
    769  
     769
    770770    struct ArcT {
    771771      int target;
     
    782782
    783783    int first_free_arc;
    784    
     784
    785785  public:
    786    
     786
    787787    typedef ListGraphBase Digraph;
    788788
     
    790790    class Arc;
    791791    class Edge;
    792    
     792
    793793    class Node {
    794794      friend class ListGraphBase;
     
    842842    ListGraphBase()
    843843      : nodes(), first_node(-1),
    844         first_free_node(-1), arcs(), first_free_arc(-1) {}
    845 
    846    
    847     int maxNodeId() const { return nodes.size()-1; } 
     844        first_free_node(-1), arcs(), first_free_arc(-1) {}
     845
     846
     847    int maxNodeId() const { return nodes.size()-1; }
    848848    int maxEdgeId() const { return arcs.size() / 2 - 1; }
    849849    int maxArcId() const { return arcs.size()-1; }
     
    863863    }
    864864
    865     void first(Node& node) const { 
     865    void first(Node& node) const {
    866866      node.id = first_node;
    867867    }
     
    871871    }
    872872
    873     void first(Arc& e) const { 
     873    void first(Arc& e) const {
    874874      int n = first_node;
    875875      while (n != -1 && nodes[n].first_out == -1) {
     
    881881    void next(Arc& e) const {
    882882      if (arcs[e.id].next_out != -1) {
    883         e.id = arcs[e.id].next_out;
    884       } else {
    885         int n = nodes[arcs[e.id ^ 1].target].next;
     883        e.id = arcs[e.id].next_out;
     884      } else {
     885        int n = nodes[arcs[e.id ^ 1].target].next;
    886886        while(n != -1 && nodes[n].first_out == -1) {
    887887          n = nodes[n].next;
    888888        }
    889         e.id = (n == -1) ? -1 : nodes[n].first_out;
    890       }     
    891     }
    892 
    893     void first(Edge& e) const { 
     889        e.id = (n == -1) ? -1 : nodes[n].first_out;
     890      }
     891    }
     892
     893    void first(Edge& e) const {
    894894      int n = first_node;
    895895      while (n != -1) {
     
    901901          e.id /= 2;
    902902          return;
    903         } 
     903        }
    904904        n = nodes[n].next;
    905905      }
     
    916916        e.id /= 2;
    917917        return;
    918       } 
     918      }
    919919      n = nodes[n].next;
    920920      while (n != -1) {
     
    926926          e.id /= 2;
    927927          return;
    928         } 
     928        }
    929929        n = nodes[n].next;
    930930      }
     
    968968      }
    969969    }
    970    
     970
    971971    static int id(Node v) { return v.id; }
    972972    static int id(Arc e) { return e.id; }
     
    977977    static Edge edgeFromId(int id) { return Edge(id);}
    978978
    979     bool valid(Node n) const { 
    980       return n.id >= 0 && n.id < static_cast<int>(nodes.size()) && 
    981         nodes[n.id].prev != -2;
    982     }
    983 
    984     bool valid(Arc a) const { 
    985       return a.id >= 0 && a.id < static_cast<int>(arcs.size()) && 
    986         arcs[a.id].prev_out != -2;
    987     }
    988 
    989     bool valid(Edge e) const { 
    990       return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) && 
    991         arcs[2 * e.id].prev_out != -2;
    992     }
    993 
    994     Node addNode() {     
     979    bool valid(Node n) const {
     980      return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
     981        nodes[n.id].prev != -2;
     982    }
     983
     984    bool valid(Arc a) const {
     985      return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
     986        arcs[a.id].prev_out != -2;
     987    }
     988
     989    bool valid(Edge e) const {
     990      return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) &&
     991        arcs[2 * e.id].prev_out != -2;
     992    }
     993
     994    Node addNode() {
    995995      int n;
    996      
     996
    997997      if(first_free_node==-1) {
    998         n = nodes.size();
    999         nodes.push_back(NodeT());
    1000       } else {
    1001         n = first_free_node;
    1002         first_free_node = nodes[n].next;
    1003       }
    1004      
     998        n = nodes.size();
     999        nodes.push_back(NodeT());
     1000      } else {
     1001        n = first_free_node;
     1002        first_free_node = nodes[n].next;
     1003      }
     1004
    10051005      nodes[n].next = first_node;
    10061006      if (first_node != -1) nodes[first_node].prev = n;
    10071007      first_node = n;
    10081008      nodes[n].prev = -1;
    1009      
     1009
    10101010      nodes[n].first_out = -1;
    1011      
     1011
    10121012      return Node(n);
    10131013    }
    1014    
     1014
    10151015    Edge addEdge(Node u, Node v) {
    1016       int n;     
     1016      int n;
    10171017
    10181018      if (first_free_arc == -1) {
    1019         n = arcs.size();
    1020         arcs.push_back(ArcT());
    1021         arcs.push_back(ArcT());
    1022       } else {
    1023         n = first_free_arc;
    1024         first_free_arc = arcs[n].next_out;
    1025       }
    1026      
     1019        n = arcs.size();
     1020        arcs.push_back(ArcT());
     1021        arcs.push_back(ArcT());
     1022      } else {
     1023        n = first_free_arc;
     1024        first_free_arc = arcs[n].next_out;
     1025      }
     1026
    10271027      arcs[n].target = u.id;
    10281028      arcs[n | 1].target = v.id;
     
    10301030      arcs[n].next_out = nodes[v.id].first_out;
    10311031      if (nodes[v.id].first_out != -1) {
    1032         arcs[nodes[v.id].first_out].prev_out = n;
    1033       }     
     1032        arcs[nodes[v.id].first_out].prev_out = n;
     1033      }
    10341034      arcs[n].prev_out = -1;
    10351035      nodes[v.id].first_out = n;
    1036      
     1036
    10371037      arcs[n | 1].next_out = nodes[u.id].first_out;
    10381038      if (nodes[u.id].first_out != -1) {
    1039         arcs[nodes[u.id].first_out].prev_out = (n | 1);
    1040       }
    1041       arcs[n | 1].prev_out = -1;     
     1039        arcs[nodes[u.id].first_out].prev_out = (n | 1);
     1040      }
     1041      arcs[n | 1].prev_out = -1;
    10421042      nodes[u.id].first_out = (n | 1);
    10431043
    10441044      return Edge(n / 2);
    10451045    }
    1046    
     1046
    10471047    void erase(const Node& node) {
    10481048      int n = node.id;
    1049      
     1049
    10501050      if(nodes[n].next != -1) {
    1051         nodes[nodes[n].next].prev = nodes[n].prev;
    1052       }
    1053      
     1051        nodes[nodes[n].next].prev = nodes[n].prev;
     1052      }
     1053
    10541054      if(nodes[n].prev != -1) {
    1055         nodes[nodes[n].prev].next = nodes[n].next;
    1056       } else {
    1057         first_node = nodes[n].next;
    1058       }
    1059      
     1055        nodes[nodes[n].prev].next = nodes[n].next;
     1056      } else {
     1057        first_node = nodes[n].next;
     1058      }
     1059
    10601060      nodes[n].next = first_free_node;
    10611061      first_free_node = n;
    10621062      nodes[n].prev = -2;
    10631063    }
    1064    
     1064
    10651065    void erase(const Edge& edge) {
    10661066      int n = edge.id * 2;
    1067      
     1067
    10681068      if (arcs[n].next_out != -1) {
    1069         arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
    1070       } 
     1069        arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
     1070      }
    10711071
    10721072      if (arcs[n].prev_out != -1) {
    1073         arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
    1074       } else {
    1075         nodes[arcs[n | 1].target].first_out = arcs[n].next_out;
     1073        arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
     1074      } else {
     1075        nodes[arcs[n | 1].target].first_out = arcs[n].next_out;
    10761076      }
    10771077
    10781078      if (arcs[n | 1].next_out != -1) {
    1079         arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out;
    1080       } 
     1079        arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out;
     1080      }
    10811081
    10821082      if (arcs[n | 1].prev_out != -1) {
    1083         arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out;
    1084       } else {
    1085         nodes[arcs[n].target].first_out = arcs[n | 1].next_out;
    1086       }
    1087      
     1083        arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out;
     1084      } else {
     1085        nodes[arcs[n].target].first_out = arcs[n | 1].next_out;
     1086      }
     1087
    10881088      arcs[n].next_out = first_free_arc;
    1089       first_free_arc = n;     
     1089      first_free_arc = n;
    10901090      arcs[n].prev_out = -2;
    10911091      arcs[n | 1].prev_out = -2;
     
    11031103    void changeTarget(Edge e, Node n) {
    11041104      if(arcs[2 * e.id].next_out != -1) {
    1105         arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out;
     1105        arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out;
    11061106      }
    11071107      if(arcs[2 * e.id].prev_out != -1) {
    1108         arcs[arcs[2 * e.id].prev_out].next_out =
     1108        arcs[arcs[2 * e.id].prev_out].next_out =
    11091109          arcs[2 * e.id].next_out;
    11101110      } else {
    1111         nodes[arcs[(2 * e.id) | 1].target].first_out = 
     1111        nodes[arcs[(2 * e.id) | 1].target].first_out =
    11121112          arcs[2 * e.id].next_out;
    11131113      }
    11141114
    11151115      if (nodes[n.id].first_out != -1) {
    1116         arcs[nodes[n.id].first_out].prev_out = 2 * e.id;
     1116        arcs[nodes[n.id].first_out].prev_out = 2 * e.id;
    11171117      }
    11181118      arcs[(2 * e.id) | 1].target = n.id;
     
    11241124    void changeSource(Edge e, Node n) {
    11251125      if(arcs[(2 * e.id) | 1].next_out != -1) {
    1126         arcs[arcs[(2 * e.id) | 1].next_out].prev_out =
     1126        arcs[arcs[(2 * e.id) | 1].next_out].prev_out =
    11271127          arcs[(2 * e.id) | 1].prev_out;
    11281128      }
    11291129      if(arcs[(2 * e.id) | 1].prev_out != -1) {
    1130         arcs[arcs[(2 * e.id) | 1].prev_out].next_out =
     1130        arcs[arcs[(2 * e.id) | 1].prev_out].next_out =
    11311131          arcs[(2 * e.id) | 1].next_out;
    11321132      } else {
    1133         nodes[arcs[2 * e.id].target].first_out = 
     1133        nodes[arcs[2 * e.id].target].first_out =
    11341134          arcs[(2 * e.id) | 1].next_out;
    11351135      }
    11361136
    11371137      if (nodes[n.id].first_out != -1) {
    1138         arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);
     1138        arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);
    11391139      }
    11401140      arcs[2 * e.id].target = n.id;
     
    11541154  ///A general undirected graph structure.
    11551155
    1156   ///\ref ListGraph is a simple and fast <em>undirected graph</em> 
    1157   ///implementation based on static linked lists that are stored in 
    1158   ///\c std::vector structures. 
     1156  ///\ref ListGraph is a simple and fast <em>undirected graph</em>
     1157  ///implementation based on static linked lists that are stored in
     1158  ///\c std::vector structures.
    11591159  ///
    11601160  ///It conforms to the \ref concepts::Graph "Graph concept" and it
     
    11831183  public:
    11841184    /// Constructor
    1185    
     1185
    11861186    /// Constructor.
    11871187    ///
     
    12031203    /// and target node \c t.
    12041204    /// \return the new edge.
    1205     Edge addEdge(const Node& s, const Node& t) { 
    1206       return Parent::addEdge(s, t); 
     1205    Edge addEdge(const Node& s, const Node& t) {
     1206      return Parent::addEdge(s, t);
    12071207    }
    12081208    /// Node validity check
    12091209
    12101210    /// This function gives back true if the given node is valid,
    1211     /// ie. it is a real node of the graph. 
     1211    /// ie. it is a real node of the graph.
    12121212    ///
    12131213    /// \warning A Node pointing to a removed item
     
    12181218
    12191219    /// This function gives back true if the given arc is valid,
    1220     /// ie. it is a real arc of the graph. 
     1220    /// ie. it is a real arc of the graph.
    12211221    ///
    12221222    /// \warning An Arc pointing to a removed item
     
    12271227
    12281228    /// This function gives back true if the given edge is valid,
    1229     /// ie. it is a real arc of the graph. 
     1229    /// ie. it is a real arc of the graph.
    12301230    ///
    12311231    /// \warning A Edge pointing to a removed item
     
    12431243    ///\warning This functionality cannot be used together with the
    12441244    ///Snapshot feature.
    1245     void changeSource(Edge e, Node n) { 
    1246       Parent::changeSource(e,n); 
    1247     }   
     1245    void changeSource(Edge e, Node n) {
     1246      Parent::changeSource(e,n);
     1247    }
    12481248    /// \brief Change the target of \c e to \c n
    12491249    ///
     
    12551255    ///\warning This functionality cannot be used together with the
    12561256    ///Snapshot feature.
    1257     void changeTarget(Edge e, Node n) { 
    1258       Parent::changeTarget(e,n); 
     1257    void changeTarget(Edge e, Node n) {
     1258      Parent::changeTarget(e,n);
    12591259    }
    12601260    /// \brief Change the source of \c e to \c n
    12611261    ///
    1262     /// This function changes the source of \c e to \c n. 
     1262    /// This function changes the source of \c e to \c n.
    12631263    /// It also changes the proper node of the represented edge.
    12641264    ///
     
    12691269    ///\warning This functionality cannot be used together with the
    12701270    ///Snapshot feature.
    1271     void changeSource(Arc e, Node n) { 
     1271    void changeSource(Arc e, Node n) {
    12721272      if (Parent::direction(e)) {
    12731273        Parent::changeSource(e,n);
    12741274      } else {
    12751275        Parent::changeTarget(e,n);
    1276       } 
     1276      }
    12771277    }
    12781278    /// \brief Change the target of \c e to \c n
    12791279    ///
    1280     /// This function changes the target of \c e to \c n. 
     1280    /// This function changes the target of \c e to \c n.
    12811281    /// It also changes the proper node of the represented edge.
    12821282    ///
     
    12871287    ///\warning This functionality cannot be used together with the
    12881288    ///Snapshot feature.
    1289     void changeTarget(Arc e, Node n) { 
     1289    void changeTarget(Arc e, Node n) {
    12901290      if (Parent::direction(e)) {
    12911291        Parent::changeTarget(e,n);
    12921292      } else {
    12931293        Parent::changeSource(e,n);
    1294       } 
     1294      }
    12951295    }
    12961296    /// \brief Contract two nodes.
     
    13091309    void contract(Node a, Node b, bool r = true) {
    13101310      for(IncEdgeIt e(*this, b); e!=INVALID;) {
    1311         IncEdgeIt f = e; ++f;
    1312         if (r && runningNode(e) == a) {
    1313           erase(e);
    1314         } else if (source(e) == b) {
    1315           changeSource(e, a);
    1316         } else {
    1317           changeTarget(e, a);
    1318         }
    1319         e = f;
     1311        IncEdgeIt f = e; ++f;
     1312        if (r && runningNode(e) == a) {
     1313          erase(e);
     1314        } else if (source(e) == b) {
     1315          changeSource(e, a);
     1316        } else {
     1317          changeTarget(e, a);
     1318        }
     1319        e = f;
    13201320      }
    13211321      erase(b);
     
    13321332    ///
    13331333    /// \warning Edge and node deletions and other modifications
    1334     /// (e.g. changing nodes of edges, contracting nodes) cannot be 
     1334    /// (e.g. changing nodes of edges, contracting nodes) cannot be
    13351335    /// restored. These events invalidate the snapshot.
    13361336    class Snapshot {
     
    13481348        using NodeNotifier::ObserverBase::detach;
    13491349        using NodeNotifier::ObserverBase::attached;
    1350        
     1350
    13511351      protected:
    1352        
     1352
    13531353        virtual void add(const Node& node) {
    13541354          snapshot.addNode(node);
     
    13701370          Node node;
    13711371          std::vector<Node> nodes;
    1372           for (notifier()->first(node); node != INVALID; 
     1372          for (notifier()->first(node); node != INVALID;
    13731373               notifier()->next(node)) {
    13741374            nodes.push_back(node);
     
    13801380        virtual void clear() {
    13811381          Node node;
    1382           for (notifier()->first(node); node != INVALID; 
     1382          for (notifier()->first(node); node != INVALID;
    13831383               notifier()->next(node)) {
    13841384            snapshot.eraseNode(node);
     
    13981398        using EdgeNotifier::ObserverBase::detach;
    13991399        using EdgeNotifier::ObserverBase::attached;
    1400        
     1400
    14011401      protected:
    14021402
     
    14201420          Edge edge;
    14211421          std::vector<Edge> edges;
    1422           for (notifier()->first(edge); edge != INVALID; 
     1422          for (notifier()->first(edge); edge != INVALID;
    14231423               notifier()->next(edge)) {
    14241424            edges.push_back(edge);
     
    14301430        virtual void clear() {
    14311431          Edge edge;
    1432           for (notifier()->first(edge); edge != INVALID; 
     1432          for (notifier()->first(edge); edge != INVALID;
    14331433               notifier()->next(edge)) {
    14341434            snapshot.eraseEdge(edge);
     
    14491449
    14501450      void addNode(const Node& node) {
    1451         added_nodes.push_front(node);       
     1451        added_nodes.push_front(node);
    14521452      }
    14531453      void eraseNode(const Node& node) {
    1454         std::list<Node>::iterator it = 
     1454        std::list<Node>::iterator it =
    14551455          std::find(added_nodes.begin(), added_nodes.end(), node);
    14561456        if (it == added_nodes.end()) {
     
    14641464
    14651465      void addEdge(const Edge& edge) {
    1466         added_edges.push_front(edge);       
     1466        added_edges.push_front(edge);
    14671467      }
    14681468      void eraseEdge(const Edge& edge) {
    1469         std::list<Edge>::iterator it = 
     1469        std::list<Edge>::iterator it =
    14701470          std::find(added_edges.begin(), added_edges.end(), edge);
    14711471        if (it == added_edges.end()) {
     
    14791479
    14801480      void attach(ListGraph &_graph) {
    1481         graph = &_graph;
    1482         node_observer_proxy.attach(graph->notifier(Node()));
     1481        graph = &_graph;
     1482        node_observer_proxy.attach(graph->notifier(Node()));
    14831483        edge_observer_proxy.attach(graph->notifier(Edge()));
    14841484      }
    1485            
     1485
    14861486      void detach() {
    1487         node_observer_proxy.detach();
    1488         edge_observer_proxy.detach();
     1487        node_observer_proxy.detach();
     1488        edge_observer_proxy.detach();
    14891489      }
    14901490
     
    14951495      void clear() {
    14961496        added_nodes.clear();
    1497         added_edges.clear();       
     1497        added_edges.clear();
    14981498      }
    14991499
     
    15041504      /// Default constructor.
    15051505      /// To actually make a snapshot you must call save().
    1506       Snapshot() 
    1507         : graph(0), node_observer_proxy(*this), 
     1506      Snapshot()
     1507        : graph(0), node_observer_proxy(*this),
    15081508          edge_observer_proxy(*this) {}
    1509      
     1509
    15101510      /// \brief Constructor that immediately makes a snapshot.
    1511       ///     
     1511      ///
    15121512      /// This constructor immediately makes a snapshot of the graph.
    15131513      /// \param _graph The graph we make a snapshot of.
    1514       Snapshot(ListGraph &_graph) 
    1515         : node_observer_proxy(*this), 
     1514      Snapshot(ListGraph &_graph)
     1515        : node_observer_proxy(*this),
    15161516          edge_observer_proxy(*this) {
    1517         attach(_graph);
    1518       }
    1519      
     1517        attach(_graph);
     1518      }
     1519
    15201520      /// \brief Make a snapshot.
    15211521      ///
     
    15321532        attach(_graph);
    15331533      }
    1534      
     1534
    15351535      /// \brief Undo the changes until the last snapshot.
    1536       // 
     1536      //
    15371537      /// Undo the changes until the last snapshot created by save().
    15381538      void restore() {
    1539         detach();
    1540         for(std::list<Edge>::iterator it = added_edges.begin();
     1539        detach();
     1540        for(std::list<Edge>::iterator it = added_edges.begin();
    15411541            it != added_edges.end(); ++it) {
    1542           graph->erase(*it);
    1543         }
    1544         for(std::list<Node>::iterator it = added_nodes.begin();
     1542          graph->erase(*it);
     1543        }
     1544        for(std::list<Node>::iterator it = added_nodes.begin();
    15451545            it != added_nodes.end(); ++it) {
    1546           graph->erase(*it);
    1547         }
     1546          graph->erase(*it);
     1547        }
    15481548        clear();
    15491549      }
     
    15571557    };
    15581558  };
    1559  
    1560   /// @} 
     1559
     1560  /// @}
    15611561} //namespace lemon
    1562  
     1562
    15631563
    15641564#endif
  • lemon/maps.h

    r167 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    405405      typename Map::iterator it = _map.lower_bound(k);
    406406      if (it != _map.end() && !_map.key_comp()(k, it->first))
    407         return it->second;
     407        return it->second;
    408408      else
    409         return _map.insert(it, std::make_pair(k, _value))->second;
     409        return _map.insert(it, std::make_pair(k, _value))->second;
    410410    }
    411411
     
    414414      typename Map::const_iterator it = _map.find(k);
    415415      if (it != _map.end())
    416         return it->second;
     416        return it->second;
    417417      else
    418         return _value;
     418        return _value;
    419419    }
    420420
     
    423423      typename Map::iterator it = _map.lower_bound(k);
    424424      if (it != _map.end() && !_map.key_comp()(k, it->first))
    425         it->second = v;
     425        it->second = v;
    426426      else
    427         _map.insert(it, std::make_pair(k, v));
     427        _map.insert(it, std::make_pair(k, v));
    428428    }
    429429
     
    545545  /// \todo Check the requirements.
    546546  template<typename M1, typename M2, typename F,
    547            typename V = typename F::result_type>
     547           typename V = typename F::result_type>
    548548  class CombineMap : public MapBase<typename M1::Key, V> {
    549549    const M1 &_m1;
     
    616616  /// \sa MapToFunctor
    617617  template<typename F,
    618            typename K = typename F::argument_type,
    619            typename V = typename F::result_type>
     618           typename K = typename F::argument_type,
     619           typename V = typename F::result_type>
    620620  class FunctorToMap : public MapBase<K, V> {
    621621    F _f;
     
    13181318
    13191319  /// @}
    1320  
     1320
    13211321  // Logical maps and map adaptors:
    13221322
     
    17161716#else
    17171717  template <typename It,
    1718             typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
     1718            typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
    17191719#endif
    17201720  class LoggerBoolMap {
     
    17421742    void set(const Key& key, Value value) {
    17431743      if (value) {
    1744         *_end++ = key;
     1744        *_end++ = key;
    17451745      }
    17461746    }
     
    17501750    Iterator _end;
    17511751  };
    1752  
     1752
    17531753  /// Returns a \ref LoggerBoolMap class
    17541754
  • lemon/math.h

    r68 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434  /// \addtogroup misc
    3535  /// @{
    36  
     36
    3737  /// The Euler constant
    3838  const long double E       = 2.7182818284590452353602874713526625L;
     
    5555  /// 1/sqrt(2)
    5656  const long double SQRT1_2 = 0.7071067811865475244008443621048490L;
    57  
     57
    5858
    5959  /// @}
  • lemon/path.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    9494      ArcIt(Invalid) : path(0), idx(-1) {}
    9595      /// \brief Initializate the iterator to the first arc of path
    96       ArcIt(const Path &_path) 
     96      ArcIt(const Path &_path)
    9797        : path(&_path), idx(_path.empty() ? -1 : 0) {}
    9898
    9999    private:
    100100
    101       ArcIt(const Path &_path, int _idx) 
     101      ArcIt(const Path &_path, int _idx)
    102102        : path(&_path), idx(_idx) {}
    103103
     
    110110
    111111      /// \brief Next arc
    112       ArcIt& operator++() { 
     112      ArcIt& operator++() {
    113113        ++idx;
    114         if (idx >= path->length()) idx = -1; 
    115         return *this; 
     114        if (idx >= path->length()) idx = -1;
     115        return *this;
    116116      }
    117117
     
    285285      ArcIt(Invalid) : path(0), idx(-1) {}
    286286      /// \brief Initializate the constructor to the first arc of path
    287       ArcIt(const SimplePath &_path) 
     287      ArcIt(const SimplePath &_path)
    288288        : path(&_path), idx(_path.empty() ? -1 : 0) {}
    289289
     
    291291
    292292      /// Constructor with starting point
    293       ArcIt(const SimplePath &_path, int _idx) 
     293      ArcIt(const SimplePath &_path, int _idx)
    294294        : idx(_idx), path(&_path) {}
    295295
     
    302302
    303303      /// Next arc
    304       ArcIt& operator++() { 
     304      ArcIt& operator++() {
    305305        ++idx;
    306         if (idx >= path->length()) idx = -1; 
    307         return *this; 
     306        if (idx >= path->length()) idx = -1;
     307        return *this;
    308308      }
    309309
     
    414414  protected:
    415415
    416     // the std::list<> is incompatible 
     416    // the std::list<> is incompatible
    417417    // hard to create invalid iterator
    418418    struct Node {
     
    426426
    427427  public:
    428  
     428
    429429    /// \brief Default constructor
    430430    ///
     
    471471      ArcIt(Invalid) : path(0), node(0) {}
    472472      /// \brief Initializate the constructor to the first arc of path
    473       ArcIt(const ListPath &_path) 
     473      ArcIt(const ListPath &_path)
    474474        : path(&_path), node(_path.first) {}
    475475
    476476    protected:
    477477
    478       ArcIt(const ListPath &_path, Node *_node) 
     478      ArcIt(const ListPath &_path, Node *_node)
    479479        : path(&_path), node(_node) {}
    480480
     
    488488
    489489      /// Next arc
    490       ArcIt& operator++() { 
     490      ArcIt& operator++() {
    491491        node = node->next;
    492         return *this; 
     492        return *this;
    493493      }
    494494
     
    758758    /// Default constructor
    759759    StaticPath() : len(0), arcs(0) {}
    760    
     760
    761761    /// \brief Template copy constructor
    762762    ///
     
    797797      ArcIt(Invalid) : path(0), idx(-1) {}
    798798      /// Initializate the constructor to the first arc of path
    799       ArcIt(const StaticPath &_path) 
     799      ArcIt(const StaticPath &_path)
    800800        : path(&_path), idx(_path.empty() ? -1 : 0) {}
    801801
     
    803803
    804804      /// Constructor with starting point
    805       ArcIt(const StaticPath &_path, int _idx) 
     805      ArcIt(const StaticPath &_path, int _idx)
    806806        : idx(_idx), path(&_path) {}
    807807
     
    814814
    815815      /// Next arc
    816       ArcIt& operator++() { 
     816      ArcIt& operator++() {
    817817        ++idx;
    818         if (idx >= path->length()) idx = -1; 
    819         return *this; 
     818        if (idx >= path->length()) idx = -1;
     819        return *this;
    820820      }
    821821
     
    910910    template <typename Path>
    911911    struct RevPathTagIndicator<
    912       Path, 
     912      Path,
    913913      typename enable_if<typename Path::RevPathTag, void>::type
    914914      > {
     
    923923    template <typename Path>
    924924    struct BuildTagIndicator<
    925       Path, 
     925      Path,
    926926      typename enable_if<typename Path::BuildTag, void>::type
    927927    > {
     
    930930
    931931    template <typename Target, typename Source,
    932               bool buildEnable = BuildTagIndicator<Target>::value,
    933               bool revEnable = RevPathTagIndicator<Source>::value>
     932              bool buildEnable = BuildTagIndicator<Target>::value,
     933              bool revEnable = RevPathTagIndicator<Source>::value>
    934934    struct PathCopySelector {
    935935      static void copy(Target& target, const Source& source) {
     
    982982  ///
    983983  /// This function checks that the target of each arc is the same
    984   /// as the source of the next one. 
    985   /// 
     984  /// as the source of the next one.
     985  ///
    986986  template <typename Digraph, typename Path>
    987987  bool checkPath(const Digraph& digraph, const Path& path) {
     
    10351035    typedef typename Path::Digraph Digraph;
    10361036    typedef typename Digraph::Node Node;
    1037    
     1037
    10381038    /// Default constructor
    10391039    PathNodeIt() {}
    10401040    /// Invalid constructor
    1041     PathNodeIt(Invalid) 
     1041    PathNodeIt(Invalid)
    10421042      : _digraph(0), _it(INVALID), _nd(INVALID) {}
    10431043    /// Constructor
    1044     PathNodeIt(const Digraph& digraph, const Path& path) 
     1044    PathNodeIt(const Digraph& digraph, const Path& path)
    10451045      : _digraph(&digraph), _it(path) {
    10461046      _nd = (_it != INVALID ? _digraph->source(_it) : INVALID);
    10471047    }
    10481048    /// Constructor
    1049     PathNodeIt(const Digraph& digraph, const Path& path, const Node& src) 
     1049    PathNodeIt(const Digraph& digraph, const Path& path, const Node& src)
    10501050      : _digraph(&digraph), _it(path), _nd(src) {}
    10511051
     
    10591059      if (_it == INVALID) _nd = INVALID;
    10601060      else {
    1061         _nd = _digraph->target(_it);
    1062         ++_it;
     1061        _nd = _digraph->target(_it);
     1062        ++_it;
    10631063      }
    10641064      return *this;
     
    10661066
    10671067    /// Comparison operator
    1068     bool operator==(const PathNodeIt& n) const { 
    1069       return _it == n._it && _nd == n._nd; 
     1068    bool operator==(const PathNodeIt& n) const {
     1069      return _it == n._it && _nd == n._nd;
    10701070    }
    10711071    /// Comparison operator
    1072     bool operator!=(const PathNodeIt& n) const { 
    1073       return _it != n._it || _nd != n._nd; 
     1072    bool operator!=(const PathNodeIt& n) const {
     1073      return _it != n._it || _nd != n._nd;
    10741074    }
    10751075    /// Comparison operator
    1076     bool operator<(const PathNodeIt& n) const { 
     1076    bool operator<(const PathNodeIt& n) const {
    10771077      return (_it < n._it && _nd != INVALID);
    10781078    }
    1079    
     1079
    10801080  };
    1081  
     1081
    10821082  ///@}
    10831083
  • lemon/random.cc

    r39 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • lemon/random.h

    r178 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2222 *
    2323 * See the appropriate copyright notice below.
    24  * 
     24 *
    2525 * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
    26  * All rights reserved.                         
     26 * All rights reserved.
    2727 *
    2828 * Redistribution and use in source and binary forms, with or without
     
    3737 *    documentation and/or other materials provided with the distribution.
    3838 *
    39  * 3. The names of its contributors may not be used to endorse or promote 
    40  *    products derived from this software without specific prior written 
     39 * 3. The names of its contributors may not be used to endorse or promote
     40 *    products derived from this software without specific prior written
    4141 *    permission.
    4242 *
     
    8888
    8989  namespace _random_bits {
    90    
     90
    9191    template <typename _Word, int _bits = std::numeric_limits<_Word>::digits>
    9292    struct RandomTraits {};
     
    100100      static const int length = 624;
    101101      static const int shift = 397;
    102      
     102
    103103      static const Word mul = 0x6c078965u;
    104104      static const Word arrayInit = 0x012BD6AAu;
     
    168168          0x12345u, 0x23456u, 0x34567u, 0x45678u
    169169        };
    170    
     170
    171171        initState(seedArray, seedArray + 4);
    172172      }
     
    176176        static const Word mul = RandomTraits<Word>::mul;
    177177
    178         current = state; 
     178        current = state;
    179179
    180180        Word *curr = state + length - 1;
     
    202202        num = length > end - begin ? length : end - begin;
    203203        while (num--) {
    204           curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1)) 
     204          curr[0] = (curr[0] ^ ((curr[1] ^ (curr[1] >> (bits - 2))) * mul1))
    205205            + *it + cnt;
    206206          ++it; ++cnt;
     
    224224          }
    225225        }
    226        
     226
    227227        state[length - 1] = Word(1) << (bits - 1);
    228228      }
    229      
     229
    230230      void copyState(const RandomCore& other) {
    231231        std::copy(other.state, other.state + length, state);
     
    242242    private:
    243243
    244  
     244
    245245      void fillState() {
    246246        static const Word mask[2] = { 0x0ul, RandomTraits<Word>::mask };
     
    248248        static const Word hiMask = RandomTraits<Word>::hiMask;
    249249
    250         current = state + length; 
     250        current = state + length;
    251251
    252252        register Word *curr = state + length - 1;
    253253        register long num;
    254      
     254
    255255        num = length - shift;
    256256        while (num--) {
     
    270270      }
    271271
    272  
     272
    273273      Word *current;
    274274      Word state[length];
    275      
    276     };
    277 
    278 
    279     template <typename Result, 
     275
     276    };
     277
     278
     279    template <typename Result,
    280280              int shift = (std::numeric_limits<Result>::digits + 1) / 2>
    281281    struct Masker {
     
    285285      }
    286286    };
    287    
     287
    288288    template <typename Result>
    289289    struct Masker<Result, 1> {
     
    293293    };
    294294
    295     template <typename Result, typename Word, 
    296               int rest = std::numeric_limits<Result>::digits, int shift = 0, 
     295    template <typename Result, typename Word,
     296              int rest = std::numeric_limits<Result>::digits, int shift = 0,
    297297              bool last = rest <= std::numeric_limits<Word>::digits>
    298298    struct IntConversion {
    299299      static const int bits = std::numeric_limits<Word>::digits;
    300    
     300
    301301      static Result convert(RandomCore<Word>& rnd) {
    302302        return static_cast<Result>(rnd() >> (bits - rest)) << shift;
    303303      }
    304      
    305     }; 
    306 
    307     template <typename Result, typename Word, int rest, int shift> 
     304
     305    };
     306
     307    template <typename Result, typename Word, int rest, int shift>
    308308    struct IntConversion<Result, Word, rest, shift, false> {
    309309      static const int bits = std::numeric_limits<Word>::digits;
    310310
    311311      static Result convert(RandomCore<Word>& rnd) {
    312         return (static_cast<Result>(rnd()) << shift) | 
     312        return (static_cast<Result>(rnd()) << shift) |
    313313          IntConversion<Result, Word, rest - bits, shift + bits>::convert(rnd);
    314314      }
     
    317317
    318318    template <typename Result, typename Word,
    319               bool one_word = (std::numeric_limits<Word>::digits < 
    320                                std::numeric_limits<Result>::digits) >
     319              bool one_word = (std::numeric_limits<Word>::digits <
     320                               std::numeric_limits<Result>::digits) >
    321321    struct Mapping {
    322322      static Result map(RandomCore<Word>& rnd, const Result& bound) {
     
    325325        Result num;
    326326        do {
    327           num = IntConversion<Result, Word>::convert(rnd) & mask; 
     327          num = IntConversion<Result, Word>::convert(rnd) & mask;
    328328        } while (num > max);
    329329        return num;
     
    351351        res *= res;
    352352        if ((exp & 1) == 1) res *= static_cast<Result>(2.0);
    353         return res; 
     353        return res;
    354354      }
    355355    };
     
    361361        res *= res;
    362362        if ((exp & 1) == 1) res *= static_cast<Result>(0.5);
    363         return res; 
     363        return res;
    364364      }
    365365    };
     
    368368    struct ShiftMultiplier<Result, 0, true> {
    369369      static const Result multiplier() {
    370         return static_cast<Result>(1.0); 
     370        return static_cast<Result>(1.0);
    371371      }
    372372    };
     
    375375    struct ShiftMultiplier<Result, -20, true> {
    376376      static const Result multiplier() {
    377         return static_cast<Result>(1.0/1048576.0); 
    378       }
    379     };
    380    
     377        return static_cast<Result>(1.0/1048576.0);
     378      }
     379    };
     380
    381381    template <typename Result>
    382382    struct ShiftMultiplier<Result, -32, true> {
    383383      static const Result multiplier() {
    384         return static_cast<Result>(1.0/424967296.0); 
     384        return static_cast<Result>(1.0/424967296.0);
    385385      }
    386386    };
     
    389389    struct ShiftMultiplier<Result, -53, true> {
    390390      static const Result multiplier() {
    391         return static_cast<Result>(1.0/9007199254740992.0); 
     391        return static_cast<Result>(1.0/9007199254740992.0);
    392392      }
    393393    };
     
    396396    struct ShiftMultiplier<Result, -64, true> {
    397397      static const Result multiplier() {
    398         return static_cast<Result>(1.0/18446744073709551616.0); 
     398        return static_cast<Result>(1.0/18446744073709551616.0);
    399399      }
    400400    };
     
    408408
    409409    template <typename Result, typename Word,
    410               int rest = std::numeric_limits<Result>::digits, int shift = 0, 
     410              int rest = std::numeric_limits<Result>::digits, int shift = 0,
    411411              bool last = rest <= std::numeric_limits<Word>::digits>
    412     struct RealConversion{ 
     412    struct RealConversion{
    413413      static const int bits = std::numeric_limits<Word>::digits;
    414414
     
    420420
    421421    template <typename Result, typename Word, int rest, int shift>
    422     struct RealConversion<Result, Word, rest, shift, false> { 
     422    struct RealConversion<Result, Word, rest, shift, false> {
    423423      static const int bits = std::numeric_limits<Word>::digits;
    424424
     
    459459      Word buffer;
    460460      int num;
    461      
     461
    462462      BoolProducer() : num(0) {}
    463463
     
    530530    // Architecture word
    531531    typedef unsigned long Word;
    532    
     532
    533533    _random_bits::RandomCore<Word> core;
    534534    _random_bits::BoolProducer<Word> bool_producer;
    535    
     535
    536536
    537537  public:
     
    555555    /// to the architecture word type.
    556556    template <typename Number>
    557     Random(Number seed) { 
     557    Random(Number seed) {
    558558      _random_bits::Initializer<Number, Word>::init(core, seed);
    559559    }
     
    565565    /// architecture word type.
    566566    template <typename Iterator>
    567     Random(Iterator begin, Iterator end) { 
     567    Random(Iterator begin, Iterator end) {
    568568      typedef typename std::iterator_traits<Iterator>::value_type Number;
    569569      _random_bits::Initializer<Number, Word>::init(core, begin, end);
     
    598598    /// converted to the architecture word type.
    599599    template <typename Number>
    600     void seed(Number seed) { 
     600    void seed(Number seed) {
    601601      _random_bits::Initializer<Number, Word>::init(core, seed);
    602602    }
     
    608608    /// architecture word type.
    609609    template <typename Iterator>
    610     void seed(Iterator begin, Iterator end) { 
     610    void seed(Iterator begin, Iterator end) {
    611611      typedef typename std::iterator_traits<Iterator>::value_type Number;
    612612      _random_bits::Initializer<Number, Word>::init(core, begin, end);
     
    626626      return false;
    627627    }
    628    
     628
    629629    /// \brief Seeding from file
    630630    ///
     
    641641    /// \return True when the seeding successes.
    642642#ifndef WIN32
    643     bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0) 
     643    bool seedFromFile(const std::string& file = "/dev/urandom", int offset = 0)
    644644#else
    645     bool seedFromFile(const std::string& file = "", int offset = 0) 
     645    bool seedFromFile(const std::string& file = "", int offset = 0)
    646646#endif
    647647    {
     
    661661    /// random sequence.
    662662    /// \return Currently always true.
    663     bool seedFromTime() {       
     663    bool seedFromTime() {
    664664#ifndef WIN32
    665665      timeval tv;
     
    697697    /// It returns a random real number from the range [0, b).
    698698    template <typename Number>
    699     Number real(Number b) { 
    700       return real<Number>() * b; 
     699    Number real(Number b) {
     700      return real<Number>() * b;
    701701    }
    702702
     
    705705    /// It returns a random real number from the range [a, b).
    706706    template <typename Number>
    707     Number real(Number a, Number b) { 
    708       return real<Number>() * (b - a) + a; 
     707    Number real(Number a, Number b) {
     708      return real<Number>() * (b - a) + a;
    709709    }
    710710
     
    726726    /// It returns a random real number from the range [0, b).
    727727    template <typename Number>
    728     Number operator()(Number b) { 
    729       return real<Number>() * b; 
     728    Number operator()(Number b) {
     729      return real<Number>() * b;
    730730    }
    731731
     
    734734    /// It returns a random real number from the range [a, b).
    735735    template <typename Number>
    736     Number operator()(Number a, Number b) { 
    737       return real<Number>() * (b - a) + a; 
     736    Number operator()(Number a, Number b) {
     737      return real<Number>() * (b - a) + a;
    738738    }
    739739
     
    785785    template <typename Number>
    786786    Number integer() {
    787       static const int nb = std::numeric_limits<Number>::digits + 
     787      static const int nb = std::numeric_limits<Number>::digits +
    788788        (std::numeric_limits<Number>::is_signed ? 1 : 0);
    789789      return _random_bits::IntConversion<Number, Word, nb>::convert(core);
     
    793793      return integer<int>();
    794794    }
    795    
     795
    796796    /// \brief Returns a random bool
    797797    ///
     
    807807    ///\name Non-uniform distributions
    808808    ///
    809    
     809
    810810    ///@{
    811    
     811
    812812    /// \brief Returns a random bool
    813813    ///
     
    823823    /// transformation is used to generate a random normal distribution.
    824824    /// \todo Consider using the "ziggurat" method instead.
    825     double gauss() 
     825    double gauss()
    826826    {
    827827      double V1,V2,S;
    828828      do {
    829         V1=2*real<double>()-1;
    830         V2=2*real<double>()-1;
    831         S=V1*V1+V2*V2;
     829        V1=2*real<double>()-1;
     830        V2=2*real<double>()-1;
     831        S=V1*V1+V2*V2;
    832832      } while(S>=1);
    833833      return std::sqrt(-2*std::log(S)/S)*V1;
     
    855855
    856856    /// This function generates a gamma distribution random number.
    857     /// 
     857    ///
    858858    ///\param k shape parameter (<tt>k>0</tt> integer)
    859     double gamma(int k) 
     859    double gamma(int k)
    860860    {
    861861      double s = 0;
     
    863863      return s;
    864864    }
    865    
     865
    866866    /// Gamma distribution with given shape and scale parameter
    867867
    868868    /// This function generates a gamma distribution random number.
    869     /// 
     869    ///
    870870    ///\param k shape parameter (<tt>k>0</tt>)
    871871    ///\param theta scale parameter
     
    877877      const double v0=E/(E-delta);
    878878      do {
    879         double V0=1.0-real<double>();
    880         double V1=1.0-real<double>();
    881         double V2=1.0-real<double>();
    882         if(V2<=v0)
    883           {
    884             xi=std::pow(V1,1.0/delta);
    885             nu=V0*std::pow(xi,delta-1.0);
    886           }
    887         else
    888           {
    889             xi=1.0-std::log(V1);
    890             nu=V0*std::exp(-xi);
    891           }
     879        double V0=1.0-real<double>();
     880        double V1=1.0-real<double>();
     881        double V2=1.0-real<double>();
     882        if(V2<=v0)
     883          {
     884            xi=std::pow(V1,1.0/delta);
     885            nu=V0*std::pow(xi,delta-1.0);
     886          }
     887        else
     888          {
     889            xi=1.0-std::log(V1);
     890            nu=V0*std::exp(-xi);
     891          }
    892892      } while(nu>std::pow(xi,delta-1.0)*std::exp(-xi));
    893893      return theta*(xi+gamma(int(std::floor(k))));
    894894    }
    895    
     895
    896896    /// Weibull distribution
    897897
    898898    /// This function generates a Weibull distribution random number.
    899     /// 
     899    ///
    900900    ///\param k shape parameter (<tt>k>0</tt>)
    901901    ///\param lambda scale parameter (<tt>lambda>0</tt>)
     
    904904    {
    905905      return lambda*pow(-std::log(1.0-real<double>()),1.0/k);
    906     } 
    907      
     906    }
     907
    908908    /// Pareto distribution
    909909
    910910    /// This function generates a Pareto distribution random number.
    911     /// 
     911    ///
    912912    ///\param k shape parameter (<tt>k>0</tt>)
    913913    ///\param x_min location parameter (<tt>x_min>0</tt>)
     
    916916    {
    917917      return exponential(gamma(k,1.0/x_min))+x_min;
    918     } 
    919      
     918    }
     919
    920920    /// Poisson distribution
    921921
    922922    /// This function generates a Poisson distribution random number with
    923923    /// parameter \c lambda.
    924     /// 
     924    ///
    925925    /// The probability mass function of this distribusion is
    926926    /// \f[ \frac{e^{-\lambda}\lambda^k}{k!} \f]
     
    928928    /// ''Seminumerical Algorithms'' (1969). Its running time is linear in the
    929929    /// return value.
    930    
     930
    931931    int poisson(double lambda)
    932932    {
     
    935935      double p = 1.0;
    936936      do {
    937         k++;
    938         p*=real<double>();
     937        k++;
     938        p*=real<double>();
    939939      } while (p>=l);
    940940      return k-1;
    941     } 
    942      
     941    }
     942
    943943    ///@}
    944    
     944
    945945    ///\name Two dimensional distributions
    946946    ///
    947947
    948948    ///@{
    949    
     949
    950950    /// Uniform distribution on the full unit circle
    951951
    952952    /// Uniform distribution on the full unit circle.
    953953    ///
    954     dim2::Point<double> disc() 
     954    dim2::Point<double> disc()
    955955    {
    956956      double V1,V2;
    957957      do {
    958         V1=2*real<double>()-1;
    959         V2=2*real<double>()-1;
    960        
     958        V1=2*real<double>()-1;
     959        V2=2*real<double>()-1;
     960
    961961      } while(V1*V1+V2*V2>=1);
    962962      return dim2::Point<double>(V1,V2);
     
    974974      double V1,V2,S;
    975975      do {
    976         V1=2*real<double>()-1;
    977         V2=2*real<double>()-1;
    978         S=V1*V1+V2*V2;
     976        V1=2*real<double>()-1;
     977        V2=2*real<double>()-1;
     978        S=V1*V1+V2*V2;
    979979      } while(S>=1);
    980980      double W=std::sqrt(-2*std::log(S)/S);
     
    985985    /// This function provides a turning symmetric two-dimensional distribution.
    986986    /// The x-coordinate is of conditionally exponential distribution
    987     /// with the condition that x is positive and y=0. If x is negative and 
     987    /// with the condition that x is positive and y=0. If x is negative and
    988988    /// y=0 then, -x is of exponential distribution. The same is true for the
    989989    /// y-coordinate.
    990     dim2::Point<double> exponential2() 
     990    dim2::Point<double> exponential2()
    991991    {
    992992      double V1,V2,S;
    993993      do {
    994         V1=2*real<double>()-1;
    995         V2=2*real<double>()-1;
    996         S=V1*V1+V2*V2;
     994        V1=2*real<double>()-1;
     995        V2=2*real<double>()-1;
     996        S=V1*V1+V2*V2;
    997997      } while(S>=1);
    998998      double W=-std::log(S)/S;
     
    10001000    }
    10011001
    1002     ///@}   
     1002    ///@}
    10031003  };
    10041004
  • lemon/smart_graph.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4646  protected:
    4747
    48     struct NodeT 
     48    struct NodeT
    4949    {
    50       int first_in, first_out;     
     50      int first_in, first_out;
    5151      NodeT() {}
    5252    };
    53     struct ArcT 
     53    struct ArcT
    5454    {
    55       int target, source, next_in, next_out;     
    56       ArcT() {} 
     55      int target, source, next_in, next_out;
     56      ArcT() {}
    5757    };
    5858
    5959    std::vector<NodeT> nodes;
    6060    std::vector<ArcT> arcs;
    61        
     61
    6262  public:
    6363
     
    7070
    7171    SmartDigraphBase() : nodes(), arcs() { }
    72     SmartDigraphBase(const SmartDigraphBase &_g) 
     72    SmartDigraphBase(const SmartDigraphBase &_g)
    7373      : nodes(_g.nodes), arcs(_g.arcs) { }
    74    
     74
    7575    typedef True NodeNumTag;
    7676    typedef True EdgeNumTag;
     
    8383
    8484    Node addNode() {
    85       int n = nodes.size();     
     85      int n = nodes.size();
    8686      nodes.push_back(NodeT());
    8787      nodes[n].first_in = -1;
     
    8989      return Node(n);
    9090    }
    91    
     91
    9292    Arc addArc(Node u, Node v) {
    93       int n = arcs.size(); 
     93      int n = arcs.size();
    9494      arcs.push_back(ArcT());
    95       arcs[n].source = u._id; 
     95      arcs[n].source = u._id;
    9696      arcs[n].target = v._id;
    9797      arcs[n].next_out = nodes[u._id].first_out;
     
    116116    static Arc arcFromId(int id) { return Arc(id);}
    117117
    118     bool valid(Node n) const { 
    119       return n._id >= 0 && n._id < static_cast<int>(nodes.size()); 
    120     }
    121     bool valid(Arc a) const { 
    122       return a._id >= 0 && a._id < static_cast<int>(arcs.size()); 
     118    bool valid(Node n) const {
     119      return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     120    }
     121    bool valid(Arc a) const {
     122      return a._id >= 0 && a._id < static_cast<int>(arcs.size());
    123123    }
    124124
     
    137137      bool operator<(const Node i) const {return _id < i._id;}
    138138    };
    139    
     139
    140140
    141141    class Arc {
     
    181181      arc._id = nodes[node._id].first_in;
    182182    }
    183    
     183
    184184    void nextIn(Arc& arc) const {
    185185      arc._id = arcs[arc._id].next_in;
     
    223223
    224224  public:
    225    
     225
    226226    /// Constructor
    227    
     227
    228228    /// Constructor.
    229229    ///
    230230    SmartDigraph() {};
    231    
     231
    232232    ///Add a new node to the digraph.
    233    
     233
    234234    /// \return the new node.
    235235    ///
    236236    Node addNode() { return Parent::addNode(); }
    237    
     237
    238238    ///Add a new arc to the digraph.
    239    
     239
    240240    ///Add a new arc to the digraph with source node \c s
    241241    ///and target node \c t.
    242242    ///\return the new arc.
    243     Arc addArc(const Node& s, const Node& t) { 
    244       return Parent::addArc(s, t); 
     243    Arc addArc(const Node& s, const Node& t) {
     244      return Parent::addArc(s, t);
    245245    }
    246246
     
    270270    ///
    271271    /// This function gives back true if the given node is valid,
    272     /// ie. it is a real node of the graph. 
     272    /// ie. it is a real node of the graph.
    273273    ///
    274274    /// \warning A removed node (using Snapshot) could become valid again
     
    279279    ///
    280280    /// This function gives back true if the given arc is valid,
    281     /// ie. it is a real arc of the graph. 
     281    /// ie. it is a real arc of the graph.
    282282    ///
    283283    /// \warning A removed arc (using Snapshot) could become valid again
     
    286286
    287287    ///Clear the digraph.
    288    
     288
    289289    ///Erase all the nodes and arcs from the digraph.
    290290    ///
     
    294294
    295295    ///Split a node.
    296    
     296
    297297    ///This function splits a node. First a new node is added to the digraph,
    298298    ///then the source of each outgoing arc of \c n is moved to this new node.
     
    319319
    320320  public:
    321    
     321
    322322    class Snapshot;
    323323
     
    328328      while(s.arc_num<arcs.size()) {
    329329        Arc arc = arcFromId(arcs.size()-1);
    330         Parent::notifier(Arc()).erase(arc);
    331         nodes[arcs.back().source].first_out=arcs.back().next_out;
    332         nodes[arcs.back().target].first_in=arcs.back().next_in;
    333         arcs.pop_back();
     330        Parent::notifier(Arc()).erase(arc);
     331        nodes[arcs.back().source].first_out=arcs.back().next_out;
     332        nodes[arcs.back().target].first_in=arcs.back().next_in;
     333        arcs.pop_back();
    334334      }
    335335      while(s.node_num<nodes.size()) {
    336336        Node node = nodeFromId(nodes.size()-1);
    337         Parent::notifier(Node()).erase(node);
    338         nodes.pop_back();
    339       }
    340     }   
     337        Parent::notifier(Node()).erase(node);
     338        nodes.pop_back();
     339      }
     340    }
    341341
    342342  public:
     
    356356    ///not the restored digraph or no change. Because the runtime performance
    357357    ///the validity of the snapshot is not stored.
    358     class Snapshot 
     358    class Snapshot
    359359    {
    360360      SmartDigraph *_graph;
     
    365365    public:
    366366      ///Default constructor.
    367      
     367
    368368      ///Default constructor.
    369369      ///To actually make a snapshot you must call save().
     
    371371      Snapshot() : _graph(0) {}
    372372      ///Constructor that immediately makes a snapshot
    373      
     373
    374374      ///This constructor immediately makes a snapshot of the digraph.
    375375      ///\param _g The digraph we make a snapshot of.
    376376      Snapshot(SmartDigraph &graph) : _graph(&graph) {
    377         node_num=_graph->nodes.size();
    378         arc_num=_graph->arcs.size();
     377        node_num=_graph->nodes.size();
     378        arc_num=_graph->arcs.size();
    379379      }
    380380
     
    386386      ///call, the previous snapshot gets lost.
    387387      ///\param _g The digraph we make the snapshot of.
    388       void save(SmartDigraph &graph) 
     388      void save(SmartDigraph &graph)
    389389      {
    390         _graph=&graph;
    391         node_num=_graph->nodes.size();
    392         arc_num=_graph->arcs.size();
     390        _graph=&graph;
     391        node_num=_graph->nodes.size();
     392        arc_num=_graph->arcs.size();
    393393      }
    394394
    395395      ///Undo the changes until a snapshot.
    396      
     396
    397397      ///Undo the changes until a snapshot created by save().
    398398      ///
     
    402402      void restore()
    403403      {
    404         _graph->restoreSnapshot(*this);
     404        _graph->restoreSnapshot(*this);
    405405      }
    406406    };
     
    415415      int first_out;
    416416    };
    417  
     417
    418418    struct ArcT {
    419419      int target;
     
    425425
    426426    int first_free_arc;
    427    
    428   public:
    429    
     427
     428  public:
     429
    430430    typedef SmartGraphBase Digraph;
    431431
     
    433433    class Arc;
    434434    class Edge;
    435    
     435
    436436    class Node {
    437437      friend class SmartGraphBase;
     
    486486      : nodes(), arcs() {}
    487487
    488    
    489     int maxNodeId() const { return nodes.size()-1; } 
     488
     489    int maxNodeId() const { return nodes.size()-1; }
    490490    int maxEdgeId() const { return arcs.size() / 2 - 1; }
    491491    int maxArcId() const { return arcs.size()-1; }
     
    505505    }
    506506
    507     void first(Node& node) const { 
     507    void first(Node& node) const {
    508508      node._id = nodes.size() - 1;
    509509    }
     
    513513    }
    514514
    515     void first(Arc& arc) const { 
     515    void first(Arc& arc) const {
    516516      arc._id = arcs.size() - 1;
    517517    }
     
    521521    }
    522522
    523     void first(Edge& arc) const { 
     523    void first(Edge& arc) const {
    524524      arc._id = arcs.size() / 2 - 1;
    525525    }
     
    562562      } else {
    563563        arc._id = -1;
    564         d = true;     
    565       }
    566     }
    567    
     564        d = true;
     565      }
     566    }
     567
    568568    static int id(Node v) { return v._id; }
    569569    static int id(Arc e) { return e._id; }
     
    574574    static Edge edgeFromId(int id) { return Edge(id);}
    575575
    576     bool valid(Node n) const { 
    577       return n._id >= 0 && n._id < static_cast<int>(nodes.size()); 
    578     }
    579     bool valid(Arc a) const { 
     576    bool valid(Node n) const {
     577      return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     578    }
     579    bool valid(Arc a) const {
    580580      return a._id >= 0 && a._id < static_cast<int>(arcs.size());
    581581    }
    582     bool valid(Edge e) const { 
    583       return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size()); 
    584     }
    585 
    586     Node addNode() {     
     582    bool valid(Edge e) const {
     583      return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size());
     584    }
     585
     586    Node addNode() {
    587587      int n = nodes.size();
    588588      nodes.push_back(NodeT());
    589589      nodes[n].first_out = -1;
    590      
     590
    591591      return Node(n);
    592592    }
    593    
     593
    594594    Edge addEdge(Node u, Node v) {
    595595      int n = arcs.size();
    596596      arcs.push_back(ArcT());
    597597      arcs.push_back(ArcT());
    598      
     598
    599599      arcs[n].target = u._id;
    600600      arcs[n | 1].target = v._id;
     
    603603      nodes[v._id].first_out = n;
    604604
    605       arcs[n | 1].next_out = nodes[u._id].first_out;   
     605      arcs[n | 1].next_out = nodes[u._id].first_out;
    606606      nodes[u._id].first_out = (n | 1);
    607607
    608608      return Edge(n / 2);
    609609    }
    610    
     610
    611611    void clear() {
    612612      arcs.clear();
     
    626626  /// that <b> it does support only limited (only stack-like)
    627627  /// node and arc deletions</b>.
    628   /// Except from this it conforms to 
     628  /// Except from this it conforms to
    629629  /// the \ref concepts::Graph "Graph concept".
    630630  ///
     
    656656
    657657    /// Constructor
    658    
     658
    659659    /// Constructor.
    660660    ///
     
    662662
    663663    ///Add a new node to the graph.
    664    
     664
    665665    /// \return the new node.
    666666    ///
    667667    Node addNode() { return Parent::addNode(); }
    668    
     668
    669669    ///Add a new edge to the graph.
    670    
     670
    671671    ///Add a new edge to the graph with node \c s
    672672    ///and \c t.
    673673    ///\return the new edge.
    674     Edge addEdge(const Node& s, const Node& t) { 
    675       return Parent::addEdge(s, t); 
     674    Edge addEdge(const Node& s, const Node& t) {
     675      return Parent::addEdge(s, t);
    676676    }
    677677
     
    679679    ///
    680680    /// This function gives back true if the given node is valid,
    681     /// ie. it is a real node of the graph. 
     681    /// ie. it is a real node of the graph.
    682682    ///
    683683    /// \warning A removed node (using Snapshot) could become valid again
     
    688688    ///
    689689    /// This function gives back true if the given arc is valid,
    690     /// ie. it is a real arc of the graph. 
     690    /// ie. it is a real arc of the graph.
    691691    ///
    692692    /// \warning A removed arc (using Snapshot) could become valid again
     
    697697    ///
    698698    /// This function gives back true if the given edge is valid,
    699     /// ie. it is a real edge of the graph. 
     699    /// ie. it is a real edge of the graph.
    700700    ///
    701701    /// \warning A removed edge (using Snapshot) could become valid again
     
    704704
    705705    ///Clear the graph.
    706    
     706
    707707    ///Erase all the nodes and edges from the graph.
    708708    ///
     
    712712
    713713  public:
    714    
     714
    715715    class Snapshot;
    716716
     
    729729        int n=arcs.size()-1;
    730730        Edge arc=edgeFromId(n/2);
    731         Parent::notifier(Edge()).erase(arc);
     731        Parent::notifier(Edge()).erase(arc);
    732732        std::vector<Arc> dir;
    733733        dir.push_back(arcFromId(n));
    734734        dir.push_back(arcFromId(n-1));
    735         Parent::notifier(Arc()).erase(dir);
    736         nodes[arcs[n].target].first_out=arcs[n].next_out;
    737         nodes[arcs[n-1].target].first_out=arcs[n-1].next_out;
    738         arcs.pop_back();
    739         arcs.pop_back();
     735        Parent::notifier(Arc()).erase(dir);
     736        nodes[arcs[n].target].first_out=arcs[n].next_out;
     737        nodes[arcs[n-1].target].first_out=arcs[n-1].next_out;
     738        arcs.pop_back();
     739        arcs.pop_back();
    740740      }
    741741      while(s.node_num<nodes.size()) {
    742742        int n=nodes.size()-1;
    743743        Node node = nodeFromId(n);
    744         Parent::notifier(Node()).erase(node);
    745         nodes.pop_back();
    746       }
    747     }   
     744        Parent::notifier(Node()).erase(node);
     745        nodes.pop_back();
     746      }
     747    }
    748748
    749749  public:
     
    764764    ///not the restored digraph or no change. Because the runtime performance
    765765    ///the validity of the snapshot is not stored.
    766     class Snapshot 
     766    class Snapshot
    767767    {
    768768      SmartGraph *_graph;
     
    773773    public:
    774774      ///Default constructor.
    775      
     775
    776776      ///Default constructor.
    777777      ///To actually make a snapshot you must call save().
     
    779779      Snapshot() : _graph(0) {}
    780780      ///Constructor that immediately makes a snapshot
    781      
     781
    782782      ///This constructor immediately makes a snapshot of the digraph.
    783783      ///\param g The digraph we make a snapshot of.
     
    793793      ///call, the previous snapshot gets lost.
    794794      ///\param g The digraph we make the snapshot of.
    795       void save(SmartGraph &graph) 
     795      void save(SmartGraph &graph)
    796796      {
    797797        graph.saveSnapshot(*this);
     
    799799
    800800      ///Undo the changes until a snapshot.
    801      
     801
    802802      ///Undo the changes until a snapshot created by save().
    803803      ///
     
    811811    };
    812812  };
    813  
     813
    814814} //namespace lemon
    815815
  • lemon/time_measure.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6565    double cstime;
    6666    double rtime;
    67  
    68     void _reset() { 
     67
     68    void _reset() {
    6969      utime = stime = cutime = cstime = rtime = 0;
    7070    }
     
    9797      FILETIME create, exit, kernel, user;
    9898      if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
    99         utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
    100         stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
    101         cutime = 0;
    102         cstime = 0;
     99        utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
     100        stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
     101        cutime = 0;
     102        cstime = 0;
    103103      } else {
    104         rtime = 0;
    105         utime = 0;
    106         stime = 0;
    107         cutime = 0;
    108         cstime = 0;
     104        rtime = 0;
     105        utime = 0;
     106        stime = 0;
     107        cutime = 0;
     108        cstime = 0;
    109109      }
    110 #endif     
    111     }
    112  
     110#endif
     111    }
     112
    113113    /// Constructor initializing with zero
    114114    TimeStamp()
     
    116116    ///Constructor initializing with the current time values of the process
    117117    TimeStamp(void *) { stamp();}
    118  
     118
    119119    ///Set every time value to zero
    120120    TimeStamp &reset() {_reset();return *this;}
     
    191191      return t-*this;
    192192    }
    193  
     193
    194194    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    195  
     195
    196196    ///Gives back the user time of the process
    197197    double userTime() const
     
    206206    ///Gives back the user time of the process' children
    207207
    208     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     208    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    209209    ///
    210210    double cUserTime() const
     
    214214    ///Gives back the user time of the process' children
    215215
    216     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     216    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    217217    ///
    218218    double cSystemTime() const
     
    224224  };
    225225
    226   TimeStamp operator*(double b,const TimeStamp &t) 
     226  TimeStamp operator*(double b,const TimeStamp &t)
    227227  {
    228228    return t*b;
    229229  }
    230  
     230
    231231  ///Prints the time counters
    232232
     
    300300    TimeStamp start_time; //This is the relativ start-time if the timer
    301301                          //is _running, the collected _running time otherwise.
    302    
     302
    303303    void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
    304  
    305   public: 
     304
     305  public:
    306306    ///Constructor.
    307307
     
    332332
    333333    ///Start the time counters
    334    
     334
    335335    ///This function starts the time counters.
    336336    ///
     
    338338    ///until the same amount of \ref stop() is called.
    339339    ///\sa stop()
    340     void start() 
     340    void start()
    341341    {
    342342      if(_running) _running++;
    343343      else {
    344         _running=1;
    345         TimeStamp t;
    346         t.stamp();
    347         start_time=t-start_time;
     344        _running=1;
     345        TimeStamp t;
     346        t.stamp();
     347        start_time=t-start_time;
    348348      }
    349349    }
    350350
    351    
     351
    352352    ///Stop the time counters
    353353
     
    355355    ///once, then the same number of stop() execution is necessary the really
    356356    ///stop the timer.
    357     /// 
     357    ///
    358358    ///\sa halt()
    359359    ///\sa start()
     
    361361    ///\sa reset()
    362362
    363     void stop() 
     363    void stop()
    364364    {
    365365      if(_running && !--_running) {
    366         TimeStamp t;
    367         t.stamp();
    368         start_time=t-start_time;
     366        TimeStamp t;
     367        t.stamp();
     368        start_time=t-start_time;
    369369      }
    370370    }
     
    384384    ///\sa reset()
    385385
    386     void halt() 
     386    void halt()
    387387    {
    388388      if(_running) {
    389         _running=0;
    390         TimeStamp t;
    391         t.stamp();
    392         start_time=t-start_time;
     389        _running=0;
     390        TimeStamp t;
     391        t.stamp();
     392        start_time=t-start_time;
    393393      }
    394394    }
     
    403403    ///zero).
    404404    int running()  { return _running; }
    405    
    406    
     405
     406
    407407    ///Restart the time counters
    408408
     
    410410    ///a reset() and a start() calls.
    411411    ///
    412     void restart() 
     412    void restart()
    413413    {
    414414      reset();
    415415      start();
    416416    }
    417    
     417
    418418    ///@}
    419419
     
    434434    ///Gives back the ellapsed user time of the process' children
    435435
    436     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     436    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    437437    ///
    438438    double cUserTime() const
     
    442442    ///Gives back the ellapsed user time of the process' children
    443443
    444     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     444    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    445445    ///
    446446    double cSystemTime() const
     
    488488  ///\sa NoTimeReport
    489489  ///\todo There is no test case for this
    490   class TimeReport : public Timer 
     490  class TimeReport : public Timer
    491491  {
    492492    std::string _title;
     
    499499    ///\param run Sets whether the timer should start immediately.
    500500
    501     TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 
     501    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true)
    502502      : Timer(run), _title(title), _os(os){}
    503503    ///\e Prints the ellapsed time on destruction.
    504     ~TimeReport() 
     504    ~TimeReport()
    505505    {
    506506      _os << _title << *this << std::endl;
    507507    }
    508508  };
    509      
     509
    510510  ///'Do nothing' version of \ref TimeReport
    511511
     
    528528    void start() {}
    529529    void stop() {}
    530     void halt() {} 
     530    void halt() {}
    531531    int running() { return 0; }
    532532    void restart() {}
     
    537537    double realTime() const { return 0; }
    538538  };
    539      
     539
    540540  ///Tool to measure the running time more exactly.
    541  
     541
    542542  ///This function calls \c f several times and returns the average
    543543  ///running time. The number of the executions will be choosen in such a way
     
    551551  ///        total running time will be written into <tt>*full_time</tt>.
    552552  ///\return The average running time of \c f.
    553  
     553
    554554  template<class F>
    555555  TimeStamp runningTimeTest(F f,double min_time=10,unsigned int *num = NULL,
     
    567567    return full/total;
    568568  }
    569  
    570   /// @} 
     569
     570  /// @}
    571571
    572572
  • lemon/tolerance.h

    r72 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3232  /// \addtogroup misc
    3333  /// @{
    34  
     34
    3535  ///\brief A class to provide a basic way to
    3636  ///handle the comparison of numbers that are obtained
     
    4141  ///as a result of a probably inexact computation.
    4242  ///
    43   ///This is an abstract class, it should be specialized for all 
    44   ///numerical data types. These specialized classes like 
     43  ///This is an abstract class, it should be specialized for all
     44  ///numerical data types. These specialized classes like
    4545  ///Tolerance<double> may offer additional tuning parameters.
    4646  ///
     
    306306    static Value zero() {return 0;}
    307307  };
    308  
     308
    309309
    310310  ///Long integer specialization of Tolerance.
  • lemon/unionfind.h

    r103 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3939  /// \brief A \e Union-Find data structure implementation
    4040  ///
    41   /// The class implements the \e Union-Find data structure. 
     41  /// The class implements the \e Union-Find data structure.
    4242  /// The union operation uses rank heuristic, while
    4343  /// the find operation uses path compression.
    44   /// This is a very simple but efficient implementation, providing 
     44  /// This is a very simple but efficient implementation, providing
    4545  /// only four methods: join (union), find, insert and size.
    4646  /// For more features see the \ref UnionFindEnum class.
     
    5151  ///
    5252  /// \pre You need to add all the elements by the \ref insert()
    53   /// method. 
     53  /// method.
    5454  template <typename _ItemIntMap>
    5555  class UnionFind {
     
    112112    /// \brief Inserts a new element into the structure.
    113113    ///
    114     /// This method inserts a new element into the data structure. 
     114    /// This method inserts a new element into the data structure.
    115115    ///
    116116    /// The method returns the index of the new component.
     
    124124    /// \brief Joining the components of element \e a and element \e b.
    125125    ///
    126     /// This is the \e union operation of the Union-Find structure. 
     126    /// This is the \e union operation of the Union-Find structure.
    127127    /// Joins the component of element \e a and component of
    128128    /// element \e b. If \e a and \e b are in the same component then
     
    132132      int kb = repIndex(index[b]);
    133133
    134       if ( ka == kb ) 
    135         return false;
     134      if ( ka == kb )
     135        return false;
    136136
    137137      if (items[ka] < items[kb]) {
    138         items[ka] += items[kb];
    139         items[kb] = ka;
     138        items[ka] += items[kb];
     139        items[kb] = ka;
    140140      } else {
    141         items[kb] += items[ka];
    142         items[ka] = kb;
     141        items[kb] += items[ka];
     142        items[ka] = kb;
    143143      }
    144144      return true;
     
    174174  class UnionFindEnum {
    175175  public:
    176    
     176
    177177    typedef _ItemIntMap ItemIntMap;
    178178    typedef typename ItemIntMap::Key Item;
    179179
    180180  private:
    181    
     181
    182182    ItemIntMap& index;
    183183
     
    203203      int next, prev;
    204204    };
    205    
     205
    206206    std::vector<ClassT> classes;
    207207    int firstClass, firstFreeClass;
     
    209209    int newClass() {
    210210      if (firstFreeClass == -1) {
    211         int cdx = classes.size();
    212         classes.push_back(ClassT());
    213         return cdx;
     211        int cdx = classes.size();
     212        classes.push_back(ClassT());
     213        return cdx;
    214214      } else {
    215         int cdx = firstFreeClass;
    216         firstFreeClass = classes[firstFreeClass].next;
    217         return cdx;
     215        int cdx = firstFreeClass;
     216        firstFreeClass = classes[firstFreeClass].next;
     217        return cdx;
    218218      }
    219219    }
     
    221221    int newItem() {
    222222      if (firstFreeItem == -1) {
    223         int idx = items.size();
    224         items.push_back(ItemT());
    225         return idx;
     223        int idx = items.size();
     224        items.push_back(ItemT());
     225        return idx;
    226226      } else {
    227         int idx = firstFreeItem;
    228         firstFreeItem = items[firstFreeItem].next;
    229         return idx;
     227        int idx = firstFreeItem;
     228        firstFreeItem = items[firstFreeItem].next;
     229        return idx;
    230230      }
    231231    }
     
    268268      items[items[idx].prev].next = items[idx].next;
    269269      items[items[idx].next].prev = items[idx].prev;
    270      
     270
    271271      items[idx].next = firstFreeItem;
    272272      firstFreeItem = idx;
     
    279279      items[ak].prev = items[bk].prev;
    280280      items[bk].prev = tmp;
    281        
     281
    282282    }
    283283
     
    289289      classes[cls].prev = -1;
    290290      firstClass = cls;
    291     } 
     291    }
    292292
    293293    void unlaceClass(int cls) {
     
    300300        classes[classes[cls].next].prev = classes[cls].prev;
    301301      }
    302      
     302
    303303      classes[cls].next = firstFreeClass;
    304304      firstFreeClass = cls;
    305     } 
     305    }
    306306
    307307  public:
    308308
    309     UnionFindEnum(ItemIntMap& _index) 
    310       : index(_index), items(), firstFreeItem(-1), 
    311         firstClass(-1), firstFreeClass(-1) {}
    312    
     309    UnionFindEnum(ItemIntMap& _index)
     310      : index(_index), items(), firstFreeItem(-1),
     311        firstClass(-1), firstFreeClass(-1) {}
     312
    313313    /// \brief Inserts the given element into a new component.
    314314    ///
     
    333333
    334334      firstClass = cdx;
    335      
     335
    336336      return cdx;
    337337    }
     
    340340    ///
    341341    /// This methods inserts the element \e a into the component of the
    342     /// element \e comp. 
     342    /// element \e comp.
    343343    void insert(const Item& item, int cls) {
    344344      int rdx = classes[cls].firstItem;
     
    373373    /// \brief Joining the component of element \e a and element \e b.
    374374    ///
    375     /// This is the \e union operation of the Union-Find structure. 
     375    /// This is the \e union operation of the Union-Find structure.
    376376    /// Joins the component of element \e a and component of
    377377    /// element \e b. If \e a and \e b are in the same component then
     
    383383
    384384      if (ak == bk) {
    385         return -1;
     385        return -1;
    386386      }
    387387
     
    392392
    393393      if (classes[acx].size > classes[bcx].size) {
    394         classes[acx].size += classes[bcx].size;
    395         items[bk].parent = ak;
     394        classes[acx].size += classes[bcx].size;
     395        items[bk].parent = ak;
    396396        unlaceClass(bcx);
    397         rcx = acx;
     397        rcx = acx;
    398398      } else {
    399         classes[bcx].size += classes[acx].size;
    400         items[ak].parent = bk;
     399        classes[bcx].size += classes[acx].size;
     400        items[ak].parent = bk;
    401401        unlaceClass(acx);
    402         rcx = bcx;
     402        rcx = bcx;
    403403      }
    404404      spliceItems(ak, bk);
     
    414414    }
    415415
    416     /// \brief Splits up the component. 
     416    /// \brief Splits up the component.
    417417    ///
    418418    /// Splitting the component into singleton components (component
     
    424424        int next = items[idx].next;
    425425
    426         singletonItem(idx);
    427 
    428         int cdx = newClass();       
     426        singletonItem(idx);
     427
     428        int cdx = newClass();
    429429        items[idx].parent = ~cdx;
    430430
    431         laceClass(cdx);
    432         classes[cdx].size = 1;
    433         classes[cdx].firstItem = idx;
    434        
     431        laceClass(cdx);
     432        classes[cdx].size = 1;
     433        classes[cdx].firstItem = idx;
     434
    435435        idx = next;
    436436      }
     
    440440
    441441      classes[~(items[idx].parent)].size = 1;
    442      
     442
    443443    }
    444444
     
    458458      int cdx = classIndex(idx);
    459459      if (idx == fdx) {
    460         unlaceClass(cdx);
    461         items[idx].next = firstFreeItem;
    462         firstFreeItem = idx;
    463         return;
     460        unlaceClass(cdx);
     461        items[idx].next = firstFreeItem;
     462        firstFreeItem = idx;
     463        return;
    464464      } else {
    465         classes[cdx].firstItem = fdx;
    466         --classes[cdx].size;
    467         items[fdx].parent = ~cdx;
    468 
    469         unlaceItem(idx);
    470         idx = items[fdx].next;
    471         while (idx != fdx) {
    472           items[idx].parent = fdx;
    473           idx = items[idx].next;
    474         }
    475          
     465        classes[cdx].firstItem = fdx;
     466        --classes[cdx].size;
     467        items[fdx].parent = ~cdx;
     468
     469        unlaceItem(idx);
     470        idx = items[fdx].next;
     471        while (idx != fdx) {
     472          items[idx].parent = fdx;
     473          idx = items[idx].next;
     474        }
     475
    476476      }
    477477
     
    515515      /// Constructor to get invalid iterator
    516516      ClassIt(Invalid) : unionFind(0), cdx(-1) {}
    517      
     517
    518518      /// \brief Increment operator
    519519      ///
     
    523523        return *this;
    524524      }
    525      
     525
    526526      /// \brief Conversion operator
    527527      ///
     
    534534      ///
    535535      /// Equality operator
    536       bool operator==(const ClassIt& i) { 
     536      bool operator==(const ClassIt& i) {
    537537        return i.cdx == cdx;
    538538      }
     
    541541      ///
    542542      /// Inequality operator
    543       bool operator!=(const ClassIt& i) { 
     543      bool operator!=(const ClassIt& i) {
    544544        return i.cdx != cdx;
    545545      }
    546      
     546
    547547    private:
    548548      const UnionFindEnum* unionFind;
     
    578578      /// Constructor to get invalid iterator
    579579      ItemIt(Invalid) : unionFind(0), idx(-1) {}
    580      
     580
    581581      /// \brief Increment operator
    582582      ///
     
    587587        return *this;
    588588      }
    589      
     589
    590590      /// \brief Conversion operator
    591591      ///
     
    598598      ///
    599599      /// Equality operator
    600       bool operator==(const ItemIt& i) { 
     600      bool operator==(const ItemIt& i) {
    601601        return i.idx == idx;
    602602      }
     
    605605      ///
    606606      /// Inequality operator
    607       bool operator!=(const ItemIt& i) { 
     607      bool operator!=(const ItemIt& i) {
    608608        return i.idx != idx;
    609609      }
    610      
     610
    611611    private:
    612612      const UnionFindEnum* unionFind;
     
    631631  class ExtendFindEnum {
    632632  public:
    633    
     633
    634634    typedef _ItemIntMap ItemIntMap;
    635635    typedef typename ItemIntMap::Key Item;
    636636
    637637  private:
    638    
     638
    639639    ItemIntMap& index;
    640640
     
    659659    int newClass() {
    660660      if (firstFreeClass != -1) {
    661         int cdx = firstFreeClass;
    662         firstFreeClass = classes[cdx].next;
    663         return cdx;
     661        int cdx = firstFreeClass;
     662        firstFreeClass = classes[cdx].next;
     663        return cdx;
    664664      } else {
    665         classes.push_back(ClassT());
    666         return classes.size() - 1;
     665        classes.push_back(ClassT());
     666        return classes.size() - 1;
    667667      }
    668668    }
     
    670670    int newItem() {
    671671      if (firstFreeItem != -1) {
    672         int idx = firstFreeItem;
    673         firstFreeItem = items[idx].next;
    674         return idx;
     672        int idx = firstFreeItem;
     673        firstFreeItem = items[idx].next;
     674        return idx;
    675675      } else {
    676         items.push_back(ItemT());
    677         return items.size() - 1;
     676        items.push_back(ItemT());
     677        return items.size() - 1;
    678678      }
    679679    }
     
    682682
    683683    /// \brief Constructor
    684     ExtendFindEnum(ItemIntMap& _index) 
    685       : index(_index), items(), firstFreeItem(-1), 
    686         classes(), firstClass(-1), firstFreeClass(-1) {}
    687    
     684    ExtendFindEnum(ItemIntMap& _index)
     685      : index(_index), items(), firstFreeItem(-1),
     686        classes(), firstClass(-1), firstFreeClass(-1) {}
     687
    688688    /// \brief Inserts the given element into a new component.
    689689    ///
     
    695695      classes[cdx].next = firstClass;
    696696      if (firstClass != -1) {
    697         classes[firstClass].prev = cdx;
     697        classes[firstClass].prev = cdx;
    698698      }
    699699      firstClass = cdx;
    700      
     700
    701701      int idx = newItem();
    702702      items[idx].item = item;
     
    708708
    709709      index.set(item, idx);
    710      
     710
    711711      return cdx;
    712712    }
     
    751751      return items[classes[cls].firstItem].item;
    752752    }
    753    
     753
    754754    /// \brief Removes the given element from the structure.
    755755    ///
     
    762762      int idx = index[item];
    763763      int cdx = items[idx].cls;
    764      
     764
    765765      if (idx == items[idx].next) {
    766         if (classes[cdx].prev != -1) {
    767           classes[classes[cdx].prev].next = classes[cdx].next;
    768         } else {
    769           firstClass = classes[cdx].next;
    770         }
    771         if (classes[cdx].next != -1) {
    772           classes[classes[cdx].next].prev = classes[cdx].prev;
    773         }
    774         classes[cdx].next = firstFreeClass;
    775         firstFreeClass = cdx;
     766        if (classes[cdx].prev != -1) {
     767          classes[classes[cdx].prev].next = classes[cdx].next;
     768        } else {
     769          firstClass = classes[cdx].next;
     770        }
     771        if (classes[cdx].next != -1) {
     772          classes[classes[cdx].next].prev = classes[cdx].prev;
     773        }
     774        classes[cdx].next = firstFreeClass;
     775        firstFreeClass = cdx;
    776776      } else {
    777         classes[cdx].firstItem = items[idx].next;
    778         items[items[idx].next].prev = items[idx].prev;
    779         items[items[idx].prev].next = items[idx].next;
     777        classes[cdx].firstItem = items[idx].next;
     778        items[items[idx].next].prev = items[idx].prev;
     779        items[items[idx].prev].next = items[idx].next;
    780780      }
    781781      items[idx].next = firstFreeItem;
    782782      firstFreeItem = idx;
    783        
    784     }   
    785 
    786    
     783
     784    }
     785
     786
    787787    /// \brief Removes the component of the given element from the structure.
    788788    ///
     
    797797
    798798      if (classes[cdx].prev != -1) {
    799         classes[classes[cdx].prev].next = classes[cdx].next;
     799        classes[classes[cdx].prev].next = classes[cdx].next;
    800800      } else {
    801         firstClass = classes[cdx].next;
     801        firstClass = classes[cdx].next;
    802802      }
    803803      if (classes[cdx].next != -1) {
    804         classes[classes[cdx].next].prev = classes[cdx].prev;
     804        classes[classes[cdx].next].prev = classes[cdx].prev;
    805805      }
    806806      classes[cdx].next = firstFreeClass;
     
    825825      /// Constructor to get invalid iterator
    826826      ClassIt(Invalid) : extendFind(0), cdx(-1) {}
    827      
     827
    828828      /// \brief Increment operator
    829829      ///
     
    833833        return *this;
    834834      }
    835      
     835
    836836      /// \brief Conversion operator
    837837      ///
     
    844844      ///
    845845      /// Equality operator
    846       bool operator==(const ClassIt& i) { 
     846      bool operator==(const ClassIt& i) {
    847847        return i.cdx == cdx;
    848848      }
     
    851851      ///
    852852      /// Inequality operator
    853       bool operator!=(const ClassIt& i) { 
     853      bool operator!=(const ClassIt& i) {
    854854        return i.cdx != cdx;
    855855      }
    856      
     856
    857857    private:
    858858      const ExtendFindEnum* extendFind;
     
    888888      /// Constructor to get invalid iterator
    889889      ItemIt(Invalid) : extendFind(0), idx(-1) {}
    890      
     890
    891891      /// \brief Increment operator
    892892      ///
     
    894894      ItemIt& operator++() {
    895895        idx = extendFind->items[idx].next;
    896         if (fdx == idx) idx = -1;
     896        if (fdx == idx) idx = -1;
    897897        return *this;
    898898      }
    899      
     899
    900900      /// \brief Conversion operator
    901901      ///
     
    908908      ///
    909909      /// Equality operator
    910       bool operator==(const ItemIt& i) { 
     910      bool operator==(const ItemIt& i) {
    911911        return i.idx == idx;
    912912      }
     
    915915      ///
    916916      /// Inequality operator
    917       bool operator!=(const ItemIt& i) { 
     917      bool operator!=(const ItemIt& i) {
    918918        return i.idx != idx;
    919919      }
    920      
     920
    921921    private:
    922922      const ExtendFindEnum* extendFind;
     
    950950  /// method.
    951951  ///
    952   template <typename _Value, typename _ItemIntMap, 
     952  template <typename _Value, typename _ItemIntMap,
    953953            typename _Comp = std::less<_Value> >
    954954  class HeapUnionFind {
    955955  public:
    956    
     956
    957957    typedef _Value Value;
    958958    typedef typename _ItemIntMap::Key Item;
     
    10551055      id = nodes[id].next;
    10561056      while (depth--) {
    1057         id = nodes[id].left;     
     1057        id = nodes[id].left;
    10581058      }
    10591059      return id;
     
    11331133      nodes[kd].right = nodes[id].prev;
    11341134      nodes[nodes[id].prev].next = -1;
    1135      
     1135
    11361136      nodes[jd].left = id;
    11371137      nodes[id].prev = -1;
     
    11421142        id = nodes[id].next;
    11431143        ++num;
    1144       }     
     1144      }
    11451145      nodes[kd].size -= num;
    11461146      nodes[jd].size = num;
     
    11661166      int jd = ~(classes[id].parent);
    11671167      while (nodes[jd].left != -1) {
    1168         int kd = nodes[jd].left;
    1169         if (nodes[jd].size == 1) {
    1170           if (nodes[jd].parent < 0) {
    1171             classes[id].parent = ~kd;
    1172             classes[id].depth -= 1;
    1173             nodes[kd].parent = ~id;
    1174             deleteNode(jd);
    1175             jd = kd;
    1176           } else {
    1177             int pd = nodes[jd].parent;
    1178             if (nodes[nodes[jd].next].size < cmax) {
    1179               pushLeft(nodes[jd].next, nodes[jd].left);
    1180               if (less(nodes[jd].left, nodes[jd].next)) {
    1181                 nodes[nodes[jd].next].prio = nodes[nodes[jd].left].prio;
    1182                 nodes[nodes[jd].next].item = nodes[nodes[jd].left].item;
    1183               }
    1184               popLeft(pd);
    1185               deleteNode(jd);
    1186               jd = pd;
    1187             } else {
    1188               int ld = nodes[nodes[jd].next].left;
    1189               popLeft(nodes[jd].next);
    1190               pushRight(jd, ld);
    1191               if (less(ld, nodes[jd].left)) {
    1192                 nodes[jd].item = nodes[ld].item;
    1193                 nodes[jd].prio = nodes[jd].prio;
    1194               }
    1195               if (nodes[nodes[jd].next].item == nodes[ld].item) {
    1196                 setPrio(nodes[jd].next);
    1197               }
    1198               jd = nodes[jd].left;
    1199             }
    1200           }
    1201         } else {
    1202           jd = nodes[jd].left;
    1203         }
    1204       }
    1205     }   
     1168        int kd = nodes[jd].left;
     1169        if (nodes[jd].size == 1) {
     1170          if (nodes[jd].parent < 0) {
     1171            classes[id].parent = ~kd;
     1172            classes[id].depth -= 1;
     1173            nodes[kd].parent = ~id;
     1174            deleteNode(jd);
     1175            jd = kd;
     1176          } else {
     1177            int pd = nodes[jd].parent;
     1178            if (nodes[nodes[jd].next].size < cmax) {
     1179              pushLeft(nodes[jd].next, nodes[jd].left);
     1180              if (less(nodes[jd].left, nodes[jd].next)) {
     1181                nodes[nodes[jd].next].prio = nodes[nodes[jd].left].prio;
     1182                nodes[nodes[jd].next].item = nodes[nodes[jd].left].item;
     1183              }
     1184              popLeft(pd);
     1185              deleteNode(jd);
     1186              jd = pd;
     1187            } else {
     1188              int ld = nodes[nodes[jd].next].left;
     1189              popLeft(nodes[jd].next);
     1190              pushRight(jd, ld);
     1191              if (less(ld, nodes[jd].left)) {
     1192                nodes[jd].item = nodes[ld].item;
     1193                nodes[jd].prio = nodes[jd].prio;
     1194              }
     1195              if (nodes[nodes[jd].next].item == nodes[ld].item) {
     1196                setPrio(nodes[jd].next);
     1197              }
     1198              jd = nodes[jd].left;
     1199            }
     1200          }
     1201        } else {
     1202          jd = nodes[jd].left;
     1203        }
     1204      }
     1205    }
    12061206
    12071207    void repairRight(int id) {
    12081208      int jd = ~(classes[id].parent);
    12091209      while (nodes[jd].right != -1) {
    1210         int kd = nodes[jd].right;
    1211         if (nodes[jd].size == 1) {
    1212           if (nodes[jd].parent < 0) {
    1213             classes[id].parent = ~kd;
    1214             classes[id].depth -= 1;
    1215             nodes[kd].parent = ~id;
    1216             deleteNode(jd);
    1217             jd = kd;
    1218           } else {
    1219             int pd = nodes[jd].parent;
    1220             if (nodes[nodes[jd].prev].size < cmax) {
    1221               pushRight(nodes[jd].prev, nodes[jd].right);
    1222               if (less(nodes[jd].right, nodes[jd].prev)) {
    1223                 nodes[nodes[jd].prev].prio = nodes[nodes[jd].right].prio;
    1224                 nodes[nodes[jd].prev].item = nodes[nodes[jd].right].item;
    1225               }
    1226               popRight(pd);
    1227               deleteNode(jd);
    1228               jd = pd;
    1229             } else {
    1230               int ld = nodes[nodes[jd].prev].right;
    1231               popRight(nodes[jd].prev);
    1232               pushLeft(jd, ld);
    1233               if (less(ld, nodes[jd].right)) {
    1234                 nodes[jd].item = nodes[ld].item;
    1235                 nodes[jd].prio = nodes[jd].prio;
    1236               }
    1237               if (nodes[nodes[jd].prev].item == nodes[ld].item) {
    1238                 setPrio(nodes[jd].prev);
    1239               }
    1240               jd = nodes[jd].right;
    1241             }
    1242           }
    1243         } else {
    1244           jd = nodes[jd].right;
    1245         }
     1210        int kd = nodes[jd].right;
     1211        if (nodes[jd].size == 1) {
     1212          if (nodes[jd].parent < 0) {
     1213            classes[id].parent = ~kd;
     1214            classes[id].depth -= 1;
     1215            nodes[kd].parent = ~id;
     1216            deleteNode(jd);
     1217            jd = kd;
     1218          } else {
     1219            int pd = nodes[jd].parent;
     1220            if (nodes[nodes[jd].prev].size < cmax) {
     1221              pushRight(nodes[jd].prev, nodes[jd].right);
     1222              if (less(nodes[jd].right, nodes[jd].prev)) {
     1223                nodes[nodes[jd].prev].prio = nodes[nodes[jd].right].prio;
     1224                nodes[nodes[jd].prev].item = nodes[nodes[jd].right].item;
     1225              }
     1226              popRight(pd);
     1227              deleteNode(jd);
     1228              jd = pd;
     1229            } else {
     1230              int ld = nodes[nodes[jd].prev].right;
     1231              popRight(nodes[jd].prev);
     1232              pushLeft(jd, ld);
     1233              if (less(ld, nodes[jd].right)) {
     1234                nodes[jd].item = nodes[ld].item;
     1235                nodes[jd].prio = nodes[jd].prio;
     1236              }
     1237              if (nodes[nodes[jd].prev].item == nodes[ld].item) {
     1238                setPrio(nodes[jd].prev);
     1239              }
     1240              jd = nodes[jd].right;
     1241            }
     1242          }
     1243        } else {
     1244          jd = nodes[jd].right;
     1245        }
    12461246      }
    12471247    }
     
    12771277    /// \brief Constructs the union-find.
    12781278    ///
    1279     /// Constructs the union-find. 
     1279    /// Constructs the union-find.
    12801280    /// \brief _index The index map of the union-find. The data
    12811281    /// structure uses internally for store references.
    1282     HeapUnionFind(ItemIntMap& _index) 
    1283       : index(_index), first_class(-1), 
    1284         first_free_class(-1), first_free_node(-1) {}
     1282    HeapUnionFind(ItemIntMap& _index)
     1283      : index(_index), first_class(-1),
     1284        first_free_class(-1), first_free_node(-1) {}
    12851285
    12861286    /// \brief Insert a new node into a new component.
     
    13041304      nodes[id].item = item;
    13051305      index[item] = id;
    1306      
     1306
    13071307      int class_id = newClass();
    13081308      classes[class_id].parent = ~id;
     
    13111311      classes[class_id].left = -1;
    13121312      classes[class_id].right = -1;
    1313      
     1313
    13141314      if (first_class != -1) {
    13151315        classes[first_class].prev = class_id;
     
    13201320
    13211321      nodes[id].parent = ~class_id;
    1322      
     1322
    13231323      return class_id;
    13241324    }
     
    13331333      return findClass(index[item]);
    13341334    }
    1335    
     1335
    13361336    /// \brief Joins the classes.
    13371337    ///
     
    13721372        }
    13731373        classes[classes[l].prev].next = classes[l].next;
    1374        
     1374
    13751375        classes[l].prev = -1;
    13761376        classes[l].next = -1;
     
    13781378        classes[l].depth = leftNode(l);
    13791379        classes[l].parent = class_id;
    1380        
     1380
    13811381      }
    13821382
     
    14561456              pushLeft(new_parent, ~(classes[l].parent));
    14571457              setPrio(new_parent);
    1458              
     1458
    14591459              classes[r].parent = ~new_parent;
    14601460              classes[r].depth += 1;
     
    14711471            classes[l].depth = classes[r].depth;
    14721472          } else {
    1473             if (classes[l].depth != 0 && 
    1474                 nodes[~(classes[l].parent)].size + 
     1473            if (classes[l].depth != 0 &&
     1474                nodes[~(classes[l].parent)].size +
    14751475                nodes[~(classes[r].parent)].size <= cmax) {
    14761476              splice(~(classes[l].parent), ~(classes[r].parent));
    14771477              deleteNode(~(classes[r].parent));
    14781478              if (less(~(classes[r].parent), ~(classes[l].parent))) {
    1479                 nodes[~(classes[l].parent)].prio = 
     1479                nodes[~(classes[l].parent)].prio =
    14801480                  nodes[~(classes[r].parent)].prio;
    1481                 nodes[~(classes[l].parent)].item = 
     1481                nodes[~(classes[l].parent)].item =
    14821482                  nodes[~(classes[r].parent)].item;
    14831483              }
     
    14881488              pushRight(new_parent, ~(classes[r].parent));
    14891489              setPrio(new_parent);
    1490            
     1490
    14911491              classes[l].parent = ~new_parent;
    14921492              classes[l].depth += 1;
     
    15431543        classes[first_class].prev = classes[id].right;
    15441544        first_class = classes[id].left;
    1545        
     1545
    15461546        if (classes[id].next != -1) {
    15471547          classes[classes[id].next].prev = classes[id].prev;
    15481548        }
    15491549        classes[classes[id].prev].next = classes[id].next;
    1550        
     1550
    15511551        deleteClass(id);
    15521552      }
     
    15581558            l = nodes[l].parent;
    15591559          }
    1560           int r = l;   
     1560          int r = l;
    15611561          while (nodes[l].parent >= 0) {
    15621562            l = nodes[l].parent;
     
    15811581          repairRight(~(nodes[l].parent));
    15821582          repairLeft(cs[i]);
    1583          
     1583
    15841584          *out++ = cs[i];
    15851585        }
     
    16041604      }
    16051605    }
    1606      
     1606
    16071607    /// \brief Increase the priority of the current item.
    16081608    ///
     
    16311631      }
    16321632    }
    1633    
     1633
    16341634    /// \brief Gives back the minimum priority of the class.
    16351635    ///
     
    16471647
    16481648    /// \brief Gives back a representant item of the class.
    1649     /// 
     1649    ///
    16501650    /// The representant is indpendent from the priorities of the
    1651     /// items. 
     1651    /// items.
    16521652    /// \return Gives back a representant item of the class.
    16531653    const Item& classRep(int id) const {
     
    16751675      const HeapUnionFind* _huf;
    16761676      int _id, _lid;
    1677      
     1677
    16781678    public:
    16791679
    1680       /// \brief Default constructor 
    1681       ///
    1682       /// Default constructor 
     1680      /// \brief Default constructor
     1681      ///
     1682      /// Default constructor
    16831683      ItemIt() {}
    16841684
     
    16961696          _id = _huf->leftNode(id);
    16971697          _lid = -1;
    1698         } 
    1699       }
    1700      
     1698        }
     1699      }
     1700
    17011701      /// \brief Increment operator
    17021702      ///
     
    17131713        return _huf->nodes[_id].item;
    17141714      }
    1715      
     1715
    17161716      /// \brief Equality operator
    17171717      ///
    17181718      /// Equality operator
    1719       bool operator==(const ItemIt& i) { 
     1719      bool operator==(const ItemIt& i) {
    17201720        return i._id == _id;
    17211721      }
     
    17241724      ///
    17251725      /// Inequality operator
    1726       bool operator!=(const ItemIt& i) { 
     1726      bool operator!=(const ItemIt& i) {
    17271727        return i._id != _id;
    17281728      }
     
    17311731      ///
    17321732      /// Equality operator
    1733       bool operator==(Invalid) { 
     1733      bool operator==(Invalid) {
    17341734        return _id == _lid;
    17351735      }
     
    17381738      ///
    17391739      /// Inequality operator
    1740       bool operator!=(Invalid) { 
     1740      bool operator!=(Invalid) {
    17411741        return _id != _lid;
    17421742      }
    1743      
     1743
    17441744    };
    17451745
    17461746    /// \brief Class iterator
    17471747    ///
    1748     /// The iterator stores 
     1748    /// The iterator stores
    17491749    class ClassIt {
    17501750    private:
     
    17551755    public:
    17561756
    1757       ClassIt(const HeapUnionFind& huf) 
     1757      ClassIt(const HeapUnionFind& huf)
    17581758        : _huf(&huf), _id(huf.first_class) {}
    17591759
    1760       ClassIt(const HeapUnionFind& huf, int cls) 
     1760      ClassIt(const HeapUnionFind& huf, int cls)
    17611761        : _huf(&huf), _id(huf.classes[cls].left) {}
    17621762
    17631763      ClassIt(Invalid) : _huf(0), _id(-1) {}
    1764      
     1764
    17651765      const ClassIt& operator++() {
    17661766        _id = _huf->classes[_id].next;
    1767         return *this;
     1767        return *this;
    17681768      }
    17691769
     
    17711771      ///
    17721772      /// Equality operator
    1773       bool operator==(const ClassIt& i) { 
     1773      bool operator==(const ClassIt& i) {
    17741774        return i._id == _id;
    17751775      }
     
    17781778      ///
    17791779      /// Inequality operator
    1780       bool operator!=(const ClassIt& i) { 
     1780      bool operator!=(const ClassIt& i) {
    17811781        return i._id != _id;
    1782       }     
    1783      
     1782      }
     1783
    17841784      operator int() const {
    1785         return _id;
    1786       }
    1787            
     1785        return _id;
     1786      }
     1787
    17881788    };
    17891789
  • test/bfs_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2828using namespace lemon;
    2929
    30 void checkBfsCompile() 
     30void checkBfsCompile()
    3131{
    3232  typedef concepts::Digraph Digraph;
    3333  typedef Bfs<Digraph> BType;
    34  
     34
    3535  Digraph G;
    3636  Digraph::Node n;
     
    4141  BType::PredMap p(G);
    4242  //  BType::PredNodeMap pn(G);
    43  
     43
    4444  BType bfs_test(G);
    45  
     45
    4646  bfs_test.run(n);
    47  
     47
    4848  l  = bfs_test.dist(n);
    4949  e  = bfs_test.predArc(n);
     
    5757}
    5858
    59 void checkBfsFunctionCompile() 
     59void checkBfsFunctionCompile()
    6060{
    6161  typedef int VType;
     
    6363  typedef Digraph::Arc Arc;
    6464  typedef Digraph::Node Node;
    65    
     65
    6666  Digraph g;
    6767  bfs(g,Node()).run();
     
    8282  Node s, t;
    8383  PetStruct<Digraph> ps = addPetersen(G, 5);
    84    
     84
    8585  s=ps.outer[2];
    8686  t=ps.inner[0];
    87  
     87
    8888  Bfs<Digraph> bfs_test(G);
    8989  bfs_test.run(s);
    90  
     90
    9191  check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t));
    9292
     
    9696  check(pathSource(G, p) == s,"path() found a wrong path.");
    9797  check(pathTarget(G, p) == t,"path() found a wrong path.");
    98  
     98
    9999
    100100  for(ArcIt e(G); e==INVALID; ++e) {
     
    102102    Node v=G.target(e);
    103103    check( !bfs_test.reached(u) ||
    104            (bfs_test.dist(v) > bfs_test.dist(u)+1),
    105            "Wrong output.");
     104           (bfs_test.dist(v) > bfs_test.dist(u)+1),
     105           "Wrong output.");
    106106  }
    107107
     
    113113      check(u==bfs_test.predNode(v),"Wrong tree.");
    114114      check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
    115             "Wrong distance. Difference: "
    116             << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
    117                         - 1));
     115            "Wrong distance. Difference: "
     116            << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
     117                        - 1));
    118118    }
    119119  }
  • test/counter_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    7676void init(std::vector<int>& v) {
    7777  v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100;
    78   v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; 
     78  v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70;
    7979}
    8080
     
    8383  counterTest<Counter>();
    8484  counterTest<NoCounter>();
    85  
     85
    8686  std::vector<int> x(10);
    8787  init(x); bubbleSort(x);
  • test/dfs_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2828using namespace lemon;
    2929
    30 void checkDfsCompile() 
     30void checkDfsCompile()
    3131{
    3232  typedef concepts::Digraph Digraph;
    3333  typedef Dfs<Digraph> DType;
    34  
     34
    3535  Digraph G;
    3636  Digraph::Node n;
     
    4141  DType::PredMap p(G);
    4242  //  DType::PredNodeMap pn(G);
    43  
     43
    4444  DType dfs_test(G);
    45  
     45
    4646  dfs_test.run(n);
    47  
     47
    4848  l  = dfs_test.dist(n);
    4949  e  = dfs_test.predArc(n);
     
    5757}
    5858
    59 void checkDfsFunctionCompile() 
     59void checkDfsFunctionCompile()
    6060{
    6161  typedef int VType;
     
    6363  typedef Digraph::Arc Arc;
    6464  typedef Digraph::Node Node;
    65    
     65
    6666  Digraph g;
    6767  dfs(g,Node()).run();
     
    7272    .reachedMap(concepts::ReadWriteMap<Node,bool>())
    7373    .processedMap(concepts::WriteMap<Node,bool>())
    74     .run(Node()); 
     74    .run(Node());
    7575}
    7676
     
    8282  Node s, t;
    8383  PetStruct<Digraph> ps = addPetersen(G, 5);
    84    
     84
    8585  s=ps.outer[2];
    8686  t=ps.inner[0];
    87  
     87
    8888  Dfs<Digraph> dfs_test(G);
    89   dfs_test.run(s); 
    90  
     89  dfs_test.run(s);
     90
    9191  Path<Digraph> p = dfs_test.path(t);
    9292  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
     
    9494  check(pathSource(G, p) == s,"path() found a wrong path.");
    9595  check(pathTarget(G, p) == t,"path() found a wrong path.");
    96  
     96
    9797  for(NodeIt v(G); v!=INVALID; ++v) {
    9898    check(dfs_test.reached(v),"Each node should be reached.");
     
    102102      check(u==dfs_test.predNode(v),"Wrong tree.");
    103103      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
    104             "Wrong distance. (" << dfs_test.dist(u) << "->"
    105             <<dfs_test.dist(v) << ')');
     104            "Wrong distance. (" << dfs_test.dist(u) << "->"
     105            <<dfs_test.dist(v) << ')');
    106106    }
    107107  }
  • test/digraph_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
    3535
    36     checkConcept<IDableDigraphComponent<>, 
     36    checkConcept<IDableDigraphComponent<>,
    3737      IDableDigraphComponent<> >();
    3838
    39     checkConcept<IterableDigraphComponent<>, 
     39    checkConcept<IterableDigraphComponent<>,
    4040      IterableDigraphComponent<> >();
    4141
    42     checkConcept<MappableDigraphComponent<>, 
     42    checkConcept<MappableDigraphComponent<>,
    4343      MappableDigraphComponent<> >();
    4444  }
  • test/dijkstra_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2929using namespace lemon;
    3030
    31 void checkDijkstraCompile() 
     31void checkDijkstraCompile()
    3232{
    3333  typedef int VType;
     
    3535  typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
    3636  typedef Dijkstra<Digraph, LengthMap> DType;
    37  
     37
    3838  Digraph G;
    3939  Digraph::Node n;
     
    6161}
    6262
    63 void checkDijkstraFunctionCompile() 
     63void checkDijkstraFunctionCompile()
    6464{
    6565  typedef int VType;
     
    6868  typedef Digraph::Node Node;
    6969  typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap;
    70    
     70
    7171  Digraph g;
    7272  dijkstra(g,LengthMap(),Node()).run();
     
    7979
    8080template <class Digraph>
    81 void checkDijkstra() {   
     81void checkDijkstra() {
    8282  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    8383  typedef typename Digraph::template ArcMap<int> LengthMap;
     
    8787  LengthMap length(G);
    8888  PetStruct<Digraph> ps = addPetersen(G, 5);
    89    
     89
    9090  for(int i=0;i<5;i++) {
    9191    length[ps.outcir[i]]=4;
     
    9595  s=ps.outer[0];
    9696  t=ps.inner[1];
    97  
    98   Dijkstra<Digraph, LengthMap> 
    99         dijkstra_test(G, length);
     97
     98  Dijkstra<Digraph, LengthMap>
     99        dijkstra_test(G, length);
    100100  dijkstra_test.run(s);
    101  
     101
    102102  check(dijkstra_test.dist(t)==13,"Dijkstra found a wrong path.");
    103103
     
    107107  check(pathSource(G, p) == s,"path() found a wrong path.");
    108108  check(pathTarget(G, p) == t,"path() found a wrong path.");
    109  
     109
    110110  for(ArcIt e(G); e!=INVALID; ++e) {
    111111    Node u=G.source(e);
    112112    Node v=G.target(e);
    113113    check( !dijkstra_test.reached(u) || (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]),
    114            "dist(target)-dist(source)-arc_length= " << dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
     114           "dist(target)-dist(source)-arc_length= " << dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]);
    115115  }
    116116
     
    122122      check(u==dijkstra_test.predNode(v),"Wrong tree.");
    123123      check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e],
    124             "Wrong distance! Difference: " << std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]));
     124            "Wrong distance! Difference: " << std::abs(dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]));
    125125    }
    126126  }
    127  
     127
    128128  {
    129129    NullMap<Node,Arc> myPredMap;
  • test/dim_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • test/error_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    5959
    6060static int cnt = 0;
    61 void my_assert_handler(const char*, int, const char*, 
    62                        const char*, const char*) {
     61void my_assert_handler(const char*, int, const char*,
     62                       const char*, const char*) {
    6363  ++cnt;
    6464}
  • test/graph_copy_test.cc

    r200 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    123123    }
    124124  }
    125  
     125
    126126  ListGraph to;
    127127  ListGraph::NodeMap<int> tnm(to);
     
    161161    check(ecr[er[it]] == it, "Wrong copy.");
    162162    check(fem[it] == tem[er[it]], "Wrong copy.");
    163     check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]), 
    164           "Wrong copy.");
    165     check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]), 
    166           "Wrong copy.");
    167     check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])), 
    168           "Wrong copy.");
     163    check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
     164          "Wrong copy.");
     165    check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
     166          "Wrong copy.");
     167    check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
     168          "Wrong copy.");
    169169  }
    170170
     
    189189  graph_copy_test();
    190190
    191   return 0; 
     191  return 0;
    192192}
  • test/graph_maps_test.h

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    7272    for (int i = 0; i < num; ++i) {
    7373      for (int j = 0; j < i; ++j) {
    74         arcs.push_back(graph.addArc(nodes[i], nodes[j]));
     74        arcs.push_back(graph.addArc(nodes[i], nodes[j]));
    7575      }
    7676    }
     
    8585    for (int i = 0; i < num; ++i) {
    8686      for (int j = i + 1; j < num; ++j) {
    87         arcs.push_back(graph.addArc(nodes[i], nodes[j]));
    88         map[arcs.back()] = 23;
     87        arcs.push_back(graph.addArc(nodes[i], nodes[j]));
     88        map[arcs.back()] = 23;
    8989        check(map[arcs.back()] == 23, "Wrong operator[].");
    9090      }
     
    114114    for (int i = 0; i < num; ++i) {
    115115      for (int j = 0; j < i; ++j) {
    116         edges.push_back(graph.addEdge(nodes[i], nodes[j]));
     116        edges.push_back(graph.addEdge(nodes[i], nodes[j]));
    117117      }
    118118    }
     
    127127    for (int i = 0; i < num; ++i) {
    128128      for (int j = i + 1; j < num; ++j) {
    129         edges.push_back(graph.addEdge(nodes[i], nodes[j]));
    130         map[edges.back()] = 23;
     129        edges.push_back(graph.addEdge(nodes[i], nodes[j]));
     130        map[edges.back()] = 23;
    131131        check(map[edges.back()] == 23, "Wrong operator[].");
    132132      }
  • test/graph_test.cc

    r171 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434    checkConcept<BaseGraphComponent, BaseGraphComponent >();
    3535
    36     checkConcept<IDableGraphComponent<>, 
     36    checkConcept<IDableGraphComponent<>,
    3737      IDableGraphComponent<> >();
    3838
    39     checkConcept<IterableGraphComponent<>, 
     39    checkConcept<IterableGraphComponent<>,
    4040      IterableGraphComponent<> >();
    4141
    42     checkConcept<MappableGraphComponent<>, 
     42    checkConcept<MappableGraphComponent<>,
    4343      MappableGraphComponent<> >();
    4444  }
     
    135135//     }
    136136//   }
    137  
     137
    138138//   for (int i = 0; i < w; ++i) {
    139139//     for (int j = 0; j < h - 1; ++j) {
     
    155155//     for (int i = 0; i < w - 1; ++i) {
    156156//       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
    157 //       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");     
    158 //     }
    159 //     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");   
     157//       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
     158//     }
     159//     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
    160160//   }
    161161
     
    163163//     for (int i = 1; i < w; ++i) {
    164164//       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
    165 //       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");     
    166 //     }
    167 //     check(g.left(g(0, j)) == INVALID, "Wrong left");   
     165//       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
     166//     }
     167//     check(g.left(g(0, j)) == INVALID, "Wrong left");
    168168//   }
    169169// }
  • test/graph_test.h

    r171 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    218218      n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%num]));
    219219    }
    220    
     220
    221221    return n;
    222222  }
     
    247247    checkBidirPetersen(G, num);
    248248  }
    249  
     249
    250250  template <class Graph>
    251251  void checkGraph() {
  • test/graph_utils_test.cc

    r171 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    141141{
    142142  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    143  
     143
    144144  const int nodeNum = 10;
    145145  const int arcNum = 100;
     
    156156  }
    157157  for (int i = 0; i < nodeNum; ++i) {
    158     check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), 
     158    check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]),
    159159          "Wrong in degree map");
    160160  }
    161161  for (int i = 0; i < nodeNum; ++i) {
    162     check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]), 
     162    check(outDeg[nodes[i]] == countOutArcs(digraph, nodes[i]),
    163163          "Wrong out degree map");
    164164  }
     
    173173  Node n1=g.addNode();
    174174  Node n2=g.addNode();
    175  
     175
    176176  InDegMap<Digraph> ind(g);
    177  
     177
    178178  g.addArc(n1,n2);
    179  
     179
    180180  typename Digraph::Snapshot snap(g);
    181  
     181
    182182  OutDegMap<Digraph> outd(g);
    183  
     183
    184184  check(ind[n1]==0 && ind[n2]==1, "Wrong InDegMap value.");
    185185  check(outd[n1]==1 && outd[n2]==0, "Wrong OutDegMap value.");
  • test/heap_test.cc

    r203 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4141DIGRAPH_TYPEDEFS(Digraph);
    4242
    43 char test_lgf[] = 
    44   "@nodes\n" 
    45   "label\n"     
    46   "0\n" 
    47   "1\n" 
    48   "2\n" 
    49   "3\n" 
    50   "4\n" 
    51   "5\n" 
    52   "6\n" 
    53   "7\n" 
    54   "8\n" 
    55   "9\n" 
    56   "@arcs\n" 
    57   "             label   capacity\n"     
    58   "0    5       0       94\n"   
    59   "3    9       1       11\n"   
    60   "8    7       2       83\n"   
    61   "1    2       3       94\n"   
    62   "5    7       4       35\n"   
    63   "7    4       5       84\n"   
    64   "9    5       6       38\n"   
    65   "0    4       7       96\n"   
    66   "6    7       8       6\n"   
    67   "3    1       9       27\n"   
    68   "5    2       10      77\n"   
    69   "5    6       11      69\n"   
    70   "6    5       12      41\n"   
    71   "4    6       13      70\n"   
    72   "3    2       14      45\n"   
    73   "7    9       15      93\n"   
    74   "5    9       16      50\n"   
    75   "9    0       17      94\n"   
    76   "9    6       18      67\n"   
    77   "0    9       19      86\n"   
    78   "@attributes\n" 
     43char test_lgf[] =
     44  "@nodes\n"
     45  "label\n"
     46  "0\n"
     47  "1\n"
     48  "2\n"
     49  "3\n"
     50  "4\n"
     51  "5\n"
     52  "6\n"
     53  "7\n"
     54  "8\n"
     55  "9\n"
     56  "@arcs\n"
     57  "                label        capacity\n"
     58  "0        5        0        94\n"
     59  "3        9        1        11\n"
     60  "8        7        2        83\n"
     61  "1        2        3        94\n"
     62  "5        7        4        35\n"
     63  "7        4        5        84\n"
     64  "9        5        6        38\n"
     65  "0        4        7        96\n"
     66  "6        7        8        6\n"
     67  "3        1        9        27\n"
     68  "5        2        10        77\n"
     69  "5        6        11        69\n"
     70  "6        5        12        41\n"
     71  "4        6        13        70\n"
     72  "3        2        14        45\n"
     73  "7        9        15        93\n"
     74  "5        9        16        50\n"
     75  "9        0        17        94\n"
     76  "9        6        18        67\n"
     77  "0        9        19        86\n"
     78  "@attributes\n"
    7979  "source 3\n";
    8080
     
    8989
    9090  Heap heap(map);
    91  
     91
    9292  std::vector<int> v(test_len);
    9393
     
    108108
    109109  Heap heap(map);
    110  
     110
    111111  std::vector<int> v(test_len);
    112112
     
    129129
    130130template <typename Heap>
    131 void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length, 
    132                       Node source) {
    133  
     131void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
     132                      Node source) {
     133
    134134  typename Dijkstra<Digraph, IntArcMap>::template DefStandardHeap<Heap>::
    135135    Create dijkstra(digraph, length);
     
    138138
    139139  for(ArcIt a(digraph); a != INVALID; ++a) {
    140     Node s = digraph.source(a); 
     140    Node s = digraph.source(a);
    141141    Node t = digraph.target(a);
    142142    if (dijkstra.reached(s)) {
    143143      check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
    144              "Error in a shortest path tree!");
     144                   "Error in a shortest path tree!");
    145145    }
    146146  }
     
    151151      Node s = digraph.source(a);
    152152      check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
    153              "Error in a shortest path tree!");
     153             "Error in a shortest path tree!");
    154154    }
    155155  }
     
    162162  typedef int Prio;
    163163  typedef RangeMap<int> ItemIntMap;
    164  
     164
    165165  Digraph digraph;
    166166  IntArcMap length(digraph);
     
    171171    arcMap("capacity", length).
    172172    node("source", source).
    173     run(); 
    174  
     173    run();
     174
    175175  {
    176176    typedef BinHeap<Prio, ItemIntMap> IntHeap;
     
    178178    heapSortTest<IntHeap>();
    179179    heapIncreaseTest<IntHeap>();
    180    
     180
    181181    typedef BinHeap<Prio, IntNodeMap > NodeHeap;
    182182    checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
  • test/kruskal_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    7474  Node v4=G.addNode();
    7575  Node t=G.addNode();
    76  
     76
    7777  Edge e1 = G.addEdge(s, v1);
    7878  Edge e2 = G.addEdge(s, v2);
     
    9191  ECostMap edge_cost_map(G, 2);
    9292  EBoolMap tree_map(G);
    93  
     93
    9494
    9595  //Test with const map.
    9696  check(kruskal(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10,
    97         "Total cost should be 10");
     97        "Total cost should be 10");
    9898  //Test with an edge map (filled with uniform costs).
    9999  check(kruskal(G, edge_cost_map, tree_map)==10,
    100         "Total cost should be 10");
     100        "Total cost should be 10");
    101101
    102102  edge_cost_map.set(e1, -10);
     
    115115  //Test with a edge map and inserter.
    116116  check(kruskal(G, edge_cost_map,
    117                 tree_edge_vec.begin())
    118         ==-31,
    119         "Total cost should be -31.");
    120  
     117                tree_edge_vec.begin())
     118        ==-31,
     119        "Total cost should be -31.");
     120
    121121  tree_edge_vec.clear();
    122122
    123123  check(kruskal(G, edge_cost_map,
    124                 back_inserter(tree_edge_vec))
    125         ==-31,
    126         "Total cost should be -31.");
    127  
     124                back_inserter(tree_edge_vec))
     125        ==-31,
     126        "Total cost should be -31.");
     127
    128128//   tree_edge_vec.clear();
    129  
     129
    130130//   //The above test could also be coded like this:
    131131//   check(kruskal(G,
    132 //              makeKruskalMapInput(G, edge_cost_map),
    133 //              makeKruskalSequenceOutput(back_inserter(tree_edge_vec)))
    134 //      ==-31,
    135 //      "Total cost should be -31.");
     132//                 makeKruskalMapInput(G, edge_cost_map),
     133//                 makeKruskalSequenceOutput(back_inserter(tree_edge_vec)))
     134//         ==-31,
     135//         "Total cost should be -31.");
    136136
    137137  check(tree_edge_vec.size()==5,"The tree should have 5 edges.");
    138138
    139139  check(tree_edge_vec[0]==e1 &&
    140         tree_edge_vec[1]==e2 &&
    141         tree_edge_vec[2]==e5 &&
    142         tree_edge_vec[3]==e7 &&
    143         tree_edge_vec[4]==e9,
    144         "Wrong tree.");
     140        tree_edge_vec[1]==e2 &&
     141        tree_edge_vec[2]==e5 &&
     142        tree_edge_vec[3]==e7 &&
     143        tree_edge_vec[4]==e9,
     144        "Wrong tree.");
    145145
    146146  return 0;
  • test/maps_test.cc

    r167 r209  
    1 /* -*- C++ -*-
    2  *
    3  * This file is a part of LEMON, a generic C++ optimization library
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    305305          "Something is wrong with EqualMap");
    306306  }
    307  
     307
    308308  // LoggerBoolMap
    309309  {
     
    321321          v1[0]==20 && v1[1]==50 && v1[2]==60 && v2[0]==20 && v2[1]==50 && v2[2]==60,
    322322          "Something is wrong with LoggerBoolMap");
    323          
     323
    324324    int i = 0;
    325325    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
  • test/path_test.cc

    r96 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4040
    4141int main() {
    42   check_concepts(); 
     42  check_concepts();
    4343  return 0;
    4444}
  • test/random_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3434
    3535  lemon::rnd.seed(100);
    36   lemon::rnd.seed(seed_array, seed_array + 
    37                   (sizeof(seed_array) / sizeof(seed_array[0])));
     36  lemon::rnd.seed(seed_array, seed_array +
     37                  (sizeof(seed_array) / sizeof(seed_array[0])));
    3838
    3939  return 0;
  • test/test_tools.h

    r184 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
  • test/test_tools_fail.cc

    r39 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    1919#include "test_tools.h"
    2020
    21 int main() 
     21int main()
    2222{
    2323  check(false, "Don't panic. Failing is the right behaviour here.");
  • test/test_tools_pass.cc

    r39 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    1919#include "test_tools.h"
    2020
    21 int main() 
     21int main()
    2222{
    2323  check(true, "It should pass.");
  • test/time_measure_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2121using namespace lemon;
    2222
    23 void f() 
     23void f()
    2424{
    2525  double d=0;
     
    2828}
    2929
    30 void g() 
     30void g()
    3131{
    3232  static Timer T;
    33  
     33
    3434  for(int i=0;i<1000;i++)
    3535    TimeStamp x(T);
     
    5050  std::cout << t << " (" << n << " tests)\n";
    5151  std::cout << "Total: " << full << "\n";
    52  
     52
    5353  t=runningTimeTest(g,1,&n,&full);
    5454  std::cout << t << " (" << n << " tests)\n";
    5555  std::cout << "Total: " << full << "\n";
    56  
     56
    5757  return 0;
    5858}
  • test/unionfind_test.cc

    r171 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    3232  UFE U(base);
    3333  vector<ListGraph::Node> n;
    34  
     34
    3535  for(int i=0;i<20;i++) n.push_back(g.addNode());
    3636
Note: See TracChangeset for help on using the changeset viewer.