COIN-OR::LEMON - Graph Library

Changes in / [207:574b963d0275:206:4e22275a2b52] in lemon-1.2


Ignore:
Files:
1 added
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • demo/arg_parser_demo.cc

    r204 r137  
    3030int main(int argc, const char **argv)
    3131{
    32   // Initialize the argument parser
    33   ArgParser ap(argc, argv);
     32  ArgParser ap(argc,argv);
    3433  int i;
    3534  std::string s;
    36   double d = 1.0;
    37   bool b, nh;
    38   bool g1, g2, g3;
    39 
    40   // Add a mandatory integer option with storage reference
    41   ap.refOption("n", "An integer input.", i, true);
    42   // Add a double option with storage reference (the default value is 1.0)
    43   ap.refOption("val", "A double input.", d);
    44   // Add a double option without storage reference (the default value is 3.14)
    45   ap.doubleOption("val2", "A double input.", 3.14);
    46   // Set synonym for -val option
    47   ap.synonym("vals", "val");
    48   // Add a string option
    49   ap.refOption("name", "A string input.", s);
    50   // Add bool options
    51   ap.refOption("f", "A switch.", b)
    52     .refOption("nohelp", "", nh)
    53     .refOption("gra", "Choice A", g1)
    54     .refOption("grb", "Choice B", g2)
    55     .refOption("grc", "Choice C", g3);
    56   // Bundle -gr* options into a group
    57   ap.optionGroup("gr", "gra")
    58     .optionGroup("gr", "grb")
    59     .optionGroup("gr", "grc");
    60   // Set the group mandatory
    61   ap.mandatoryGroup("gr");
    62   // Set the options of the group exclusive (only one option can be given)
    63   ap.onlyOneGroup("gr");
    64   // Add non-parsed arguments (e.g. input files)
    65   ap.other("infile", "The input file.")
     35  double d;
     36  bool b,sil;
     37  bool g1,g2,g3;
     38  ap.refOption("n", "An integer input.", i, true)
     39    .refOption("val", "A double input.", d)
     40    .doubleOption("val2", "A double input.", d)
     41    .synonym("vals","val")
     42    .refOption("name", "A string input.", s)
     43    .refOption("f", "A switch.", b)
     44    .refOption("nohelp", "", sil)
     45    .refOption("gra","Choice A",g1)
     46    .refOption("grb","Choice B",g2)
     47    .refOption("grc","Choice C",g3)
     48    .optionGroup("gr","gra")
     49    .optionGroup("gr","grb")
     50    .optionGroup("gr","grc")
     51    .mandatoryGroup("gr")
     52    .onlyOneGroup("gr")
     53    .other("infile","The input file.")
    6654    .other("...");
    6755 
    68   // Perform the parsing process
    69   // (in case of any error it terminates the program)
    7056  ap.parse();
    7157
    72   // Check each option if it has been given and print its value
    7358  std::cout << "Parameters of '" << ap.commandName() << "':\n";
    7459
    75   std::cout << "  Value of -n: " << i << std::endl;
     60  if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
    7661  if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
    77   if(ap.given("val2")) {
    78     d = ap["val2"];
    79     std::cout << "  Value of -val2: " << d << std::endl;
    80   }
    8162  if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
    8263  if(ap.given("f")) std::cout << "  -f is given\n";
    83   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << nh << std::endl;
     64  if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
    8465  if(ap.given("gra")) std::cout << "  -gra is given\n";
    8566  if(ap.given("grb")) std::cout << "  -grb is given\n";
    8667  if(ap.given("grc")) std::cout << "  -grc is given\n";
    87  
     68                                     
    8869  switch(ap.files().size()) {
    8970  case 0:
     
    10081    std::cout << "    '" << ap.files()[i] << "'\n";
    10182 
    102   return 0;
    10383}
  • demo/lgf_demo.cc

    r193 r164  
    2121///\brief Demonstrating graph input and output
    2222///
    23 /// 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
    25 /// \ref lgf-format "LGF" format.
     23/// This program gives an example of how to load a directed graph from
     24/// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
     25/// "DigraphReader" class.
    2626///
    2727/// The \c "digraph.lgf" file:
    2828/// \include digraph.lgf
    2929///
    30 /// And the program which reads it and prints the digraph to the
    31 /// standard output:
     30/// And the program which reads it:
    3231/// \include lgf_demo.cc
    3332
     
    3635#include <lemon/lgf_reader.h>
    3736#include <lemon/lgf_writer.h>
     37#include <lemon/random.h>
     38
    3839
    3940using namespace lemon;
     
    4344  SmartDigraph::ArcMap<int> cap(g);
    4445  SmartDigraph::Node s, t;
    45  
    46   try {
    47     digraphReader("digraph.lgf", g). // read the directed graph into g
    48       arcMap("capacity", cap).       // read the 'capacity' arc map into cap
    49       node("source", s).             // read 'source' node to s
    50       node("target", t).             // read 'target' node to t
    51       run();
    52   } catch (DataFormatError& error) { // check if there was any error
    53     std::cerr << "Error: " << error.what() << std::endl;
    54     return -1;
    55   }
    5646
    57   std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
     47  digraphReader("digraph.lgf", g). // read the directeg graph into g
     48    arcMap("capacity", cap).       // read the 'capacity' arc map into cap
     49    node("source", s).             // read 'source' node to s
     50    node("target", t).             // read 'target' node to t
     51    run();
     52
     53  std::cout << "Digraph read from 'digraph.lgf'" << std::endl;
    5854  std::cout << "Number of nodes: " << countNodes(g) << std::endl;
    5955  std::cout << "Number of arcs: " << countArcs(g) << std::endl;
  • doc/groups.dox

    r192 r156  
    476476@defgroup lemon_io Lemon Input-Output
    477477@ingroup io_group
    478 \brief Reading and writing \ref lgf-format "Lemon Graph Format".
    479 
    480 This group describes methods for reading and writing \ref lgf-format "Lemon Graph Format".
     478\brief Reading and writing LEMON format
     479
     480This group describes methods for reading and writing LEMON format.
     481You can find more about this format on the \ref graph-io-page "Graph Input-Output"
     482tutorial pages.
    481483*/
    482484
  • doc/lgf.dox

    r201 r162  
    4747
    4848The \c \@nodes section describes a set of nodes and associated
    49 maps. The first is a header line, its columns are the names of the
     49maps. The first is a header line, it columns are the names of the
    5050maps appearing in the following lines.
    5151One of the maps must be called \c
     
    6565
    6666The \c \@arcs section is very similar to the \c \@nodes section,
    67 it again starts with a header line describing the names of the maps,
     67it again starts with a header line describing the names of the arc,
    6868but the \c "label" map is not obligatory here. The following lines
    6969describe the arcs. The first two tokens of each line are
     
    7979\endcode
    8080
    81 The \c \@edges is just a synonym of \c \@arcs. The @arcs section can
    82 also store the edge set of an undirected graph. In such case there is
    83 a conventional method for store arc maps in the file, if two columns
    84 has the same caption with \c '+' and \c '-' prefix, then these columns
    85 can be regarded as the values of an arc map.
     81The \c \@edges is just a synonym of \c \@arcs.
    8682
    8783The \c \@attributes section contains key-value pairs, each line
    88 consists of two tokens, an attribute name, and then an attribute
    89 value. The value of the attribute could be also a label value of a
    90 node or an edge, or even an edge label prefixed with \c '+' or \c '-',
    91 which regards to the forward or backward directed arc of the
    92 corresponding edge.
     84consists of two tokens, an attribute name, and then an attribute value.
    9385
    9486\code
  • lemon/Makefile.am

    r195 r166  
    3333        lemon/kruskal.h \
    3434        lemon/lgf_reader.h \
    35         lemon/lgf_writer.h \
    3635        lemon/list_graph.h \
    3736        lemon/maps.h \
     
    6160        lemon/concepts/digraph.h \
    6261        lemon/concepts/graph.h \
    63         lemon/concepts/graph_components.h \
    6462        lemon/concepts/heap.h \
    6563        lemon/concepts/maps.h \
    66         lemon/concepts/path.h
     64        lemon/concepts/path.h \
     65        lemon/concepts/graph_components.h
  • lemon/arg_parser.h

    r204 r108  
    119119  public:
    120120
    121     ///Constructor
     121    ///\e
    122122    ArgParser(int argc, const char **argv);
    123123
    124124    ~ArgParser();
    125125
    126     ///\name Options
    127     ///
    128 
    129     ///@{
    130 
    131126    ///Add a new integer type option
    132127
    133     ///Add a new integer type option.
    134128    ///\param name The name of the option. The leading '-' must be omitted.
    135129    ///\param help A help string.
     
    142136    ///Add a new floating point type option
    143137
    144     ///Add a new floating point type option.
    145138    ///\param name The name of the option. The leading '-' must be omitted.
    146139    ///\param help A help string.
     
    153146    ///Add a new bool type option
    154147
    155     ///Add a new bool type option.
    156148    ///\param name The name of the option. The leading '-' must be omitted.
    157149    ///\param help A help string.
     
    165157    ///Add a new string type option
    166158
    167     ///Add a new string type option.
    168159    ///\param name The name of the option. The leading '-' must be omitted.
    169160    ///\param help A help string.
     
    174165                      std::string value="", bool obl=false);
    175166
    176     ///Give help string for non-parsed arguments.
    177 
    178     ///With this function you can give help string for non-parsed arguments.
    179     ///The parameter \c name will be printed in the short usage line, while
    180     ///\c help gives a more detailed description.
    181     ArgParser &other(const std::string &name,
    182                      const std::string &help="");
    183    
    184     ///@}
    185 
    186     ///\name Options with External Storage
     167    ///\name Options with external storage
    187168    ///Using this functions, the value of the option will be directly written
    188169    ///into a variable once the option appears in the command line.
     
    192173    ///Add a new integer type option with a storage reference
    193174
    194     ///Add a new integer type option with a storage reference.
    195175    ///\param name The name of the option. The leading '-' must be omitted.
    196176    ///\param help A help string.
     
    203183    ///Add a new floating type option with a storage reference
    204184
    205     ///Add a new floating type option with a storage reference.
    206185    ///\param name The name of the option. The leading '-' must be omitted.
    207186    ///\param help A help string.
     
    214193    ///Add a new bool type option with a storage reference
    215194
    216     ///Add a new bool type option with a storage reference.
    217195    ///\param name The name of the option. The leading '-' must be omitted.
    218196    ///\param help A help string.
     
    226204    ///Add a new string type option with a storage reference
    227205
    228     ///Add a new string type option with a storage reference.
    229206    ///\param name The name of the option. The leading '-' must be omitted.
    230207    ///\param help A help string.
     
    242219    ///@{
    243220
    244     ///Bundle some options into a group
     221    ///Boundle some options into a group
    245222
    246223    /// You can group some option by calling this function repeatedly for each
     
    254231
    255232    ///If you call this function for a group, than at most one of them can be
    256     ///given at the same time.
     233    ///given at the same time
    257234    ArgParser &onlyOneGroup(const std::string &group);
    258235 
     
    271248   
    272249    ///@}
     250
     251    ///Give help string for non-parsed arguments.
     252
     253    ///With this function you can give help string for non-parsed arguments.
     254    ///The parameter \c name will be printed in the short usage line, while
     255    ///\c help gives a more detailed description.
     256    ArgParser &other(const std::string &name,
     257                     const std::string &help="");
     258   
     259    ///Give back the non-option type arguments.
     260
     261    ///Give back a reference to a vector consisting of the program arguments
     262    ///not starting with a '-' character.
     263    std::vector<std::string> &files() { return _file_args; }
     264
     265    ///Give back the command name (the 0th argument)
     266    const std::string &commandName() { return _command_name; }
    273267
    274268    void show(std::ostream &os,Opts::iterator i);
     
    293287    }
    294288   
    295     ///Give back the command name (the 0th argument)
    296     const std::string &commandName() { return _command_name; }
    297 
    298289    ///Check if an opion has been given to the command.
    299290    bool given(std::string op)
     
    370361      return RefType(*this, n);
    371362    }   
    372 
    373     ///Give back the non-option type arguments.
    374 
    375     ///Give back a reference to a vector consisting of the program arguments
    376     ///not starting with a '-' character.
    377     std::vector<std::string> &files() { return _file_args; }
    378363 
    379364  };
    380365}
    381366
    382 #endif // LEMON_ARG_PARSER
     367   
     368
     369#endif // LEMON_MAIN_PARAMS
  • lemon/concepts/heap.h

    r203 r113  
    182182          Item item;
    183183          Prio prio;
     184          State state;
    184185          item=Item();
    185186          prio=Prio();
    186187          ignore_unused_variable_warning(item);
    187188          ignore_unused_variable_warning(prio);
     189          ignore_unused_variable_warning(state);
    188190
    189191          OwnItem own_item;
     
    202204         
    203205          int s = heap.size();
    204           ignore_unused_variable_warning(s);
    205206          bool e = heap.empty();
    206           ignore_unused_variable_warning(e);
    207207
    208208          prio = heap.prio();
     
    228228          heap.clear();
    229229
    230           own_state = heap.state(own_item);
     230          state = heap.state(item);
     231          heap.state(item, state);
     232          state = heap.state(own_item);
    231233          heap.state(own_item, own_state);
    232234
     235          state = _Heap::PRE_HEAP;
     236          state = _Heap::IN_HEAP;
     237          state = _Heap::POST_HEAP;
    233238          own_state = _Heap::PRE_HEAP;
    234239          own_state = _Heap::IN_HEAP;
  • lemon/graph_utils.h

    r199 r169  
    603603        for (typename From::ArcIt it(from); it != INVALID; ++it) {
    604604          arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)],
    605                                     nodeRefMap[from.target(it)]);
     605                                          nodeRefMap[from.target(it)]);
    606606        }
    607607      }
     
    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.addArc(nodeRefMap[from.source(it)],
     632                                       nodeRefMap[from.target(it)]);
    633633        }
    634634      }
     
    926926
    927927      Value operator[](const Key& key) const {
    928         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);
     928        bool forward =
     929          (_from.direction(key) ==
     930           (_node_ref[_from.source(key)] == _to.source(_edge_ref[key])));
    932931        return _to.direct(_edge_ref[key], forward);
    933932      }
  • lemon/kruskal.h

    r194 r167  
    3333///\ingroup spantree
    3434///\file
    35 ///\brief Kruskal's algorithm to compute a minimum cost spanning tree
     35///\brief Kruskal's algorithm to compute a minimum cost tree
    3636///
    37 ///Kruskal's algorithm to compute a minimum cost spanning tree.
     37///Kruskal's algorithm to compute a minimum cost tree.
    3838///
    3939
     
    252252  /// \ingroup spantree
    253253  ///
    254   /// \brief Kruskal algorithm to find a minimum cost spanning tree of
    255   /// a graph.
    256   ///
    257   /// This function runs Kruskal's algorithm to find a minimum cost
    258   /// spanning tree.
     254  /// \brief Kruskal's algorithm to find a minimum cost tree of a graph.
     255  ///
     256  /// This function runs Kruskal's algorithm to find a minimum cost tree.
    259257  /// Due to some C++ hacking, it accepts various input and output types.
    260258  ///
     
    265263  /// undirected by disregarding the direction of the arcs.
    266264  ///
    267   /// \param in This object is used to describe the arc/edge costs.
    268   /// It can be one of the following choices.
     265  /// \param in This object is used to describe the arc costs. It can be one
     266  /// of the following choices.
    269267  /// - An STL compatible 'Forward Container' with
    270   /// <tt>std::pair<GR::Arc,X></tt> or
    271   /// <tt>std::pair<GR::Edge,X></tt> as its <tt>value_type</tt>, where
    272   /// \c X is the type of the costs. The pairs indicates the arcs/edges
     268  /// <tt>std::pair<GR::Edge,X></tt> or
     269  /// <tt>std::pair<GR::Arc,X></tt> as its <tt>value_type</tt>, where
     270  /// \c X is the type of the costs. The pairs indicates the arcs
    273271  /// along with the assigned cost. <em>They must be in a
    274272  /// cost-ascending order.</em>
    275   /// - Any readable arc/edge map. The values of the map indicate the
    276   /// arc/edge costs.
    277   ///
    278   /// \retval out Here we also have a choice.
    279   /// - It can be a writable \c bool arc/edge map. After running the
    280   /// algorithm it will contain the found minimum cost spanning
    281   /// tree: the value of an arc/edge will be set to \c true if it belongs
     273  /// - Any readable Arc map. The values of the map indicate the arc costs.
     274  ///
     275  /// \retval out Here we also have a choise.
     276  /// - It can be a writable \c bool arc map.  After running the
     277  /// algorithm this will contain the found minimum cost spanning
     278  /// tree: the value of an arc will be set to \c true if it belongs
    282279  /// to the tree, otherwise it will be set to \c false. The value of
    283   /// each arc/edge will be set exactly once.
     280  /// each arc will be set exactly once.
    284281  /// - It can also be an iteraror of an STL Container with
    285   /// <tt>GR::Arc</tt> or <tt>GR::Edge</tt> as its
     282  /// <tt>GR::Edge</tt> or <tt>GR::Arc</tt> as its
    286283  /// <tt>value_type</tt>.  The algorithm copies the elements of the
    287284  /// found tree into this sequence.  For example, if we know that the
     
    294291  /// Or if we don't know in advance the size of the tree, we can
    295292  /// write this. 
    296   ///\code
    297   /// std::vector<Arc> tree;
     293  ///\code std::vector<Arc> tree;
    298294  /// kruskal(g,cost,std::back_inserter(tree));
    299295  ///\endcode
    300296  ///
    301   /// \return The total cost of the found spanning tree.
    302   ///
    303   /// \warning If Kruskal runs on an be consistent of using the same
     297  /// \return The total cost of the found tree.
     298  ///
     299  /// \warning If kruskal runs on an be consistent of using the same
    304300  /// Arc type for input and output.
    305301  ///
  • lemon/lgf_reader.h

    r201 r190  
    1919///\ingroup lemon_io
    2020///\file
    21 ///\brief \ref lgf-format "Lemon Graph Format" reader.
     21///\brief Lemon Graph Format reader.
    2222
    2323
     
    196196    };
    197197
    198     inline bool isWhiteSpace(char c) {
     198    bool isWhiteSpace(char c) {
    199199      return c == ' ' || c == '\t' || c == '\v' ||
    200200        c == '\n' || c == '\r' || c == '\f';
    201201    }
    202202   
    203     inline bool isOct(char c) {
     203    bool isOct(char c) {
    204204      return '0' <= c && c <='7';
    205205    }
    206206   
    207     inline int valueOct(char c) {
     207    int valueOct(char c) {
    208208      LEMON_ASSERT(isOct(c), "The character is not octal.");
    209209      return c - '0';
    210210    }
    211211
    212     inline bool isHex(char c) {
     212    bool isHex(char c) {
    213213      return ('0' <= c && c <= '9') ||
    214214        ('a' <= c && c <= 'z') ||
     
    216216    }
    217217   
    218     inline int valueHex(char c) {
     218    int valueHex(char c) {
    219219      LEMON_ASSERT(isHex(c), "The character is not hexadecimal.");
    220220      if ('0' <= c && c <= '9') return c - '0';
     
    223223    }
    224224
    225     inline bool isIdentifierFirstChar(char c) {
     225    bool isIdentifierFirstChar(char c) {
    226226      return ('a' <= c && c <= 'z') ||
    227227        ('A' <= c && c <= 'Z') || c == '_';
    228228    }
    229229
    230     inline bool isIdentifierChar(char c) {
     230    bool isIdentifierChar(char c) {
    231231      return isIdentifierFirstChar(c) ||
    232232        ('0' <= c && c <= '9');
    233233    }
    234234
    235     inline char readEscape(std::istream& is) {
     235    char readEscape(std::istream& is) {
    236236      char c;
    237237      if (!is.get(c))
     
    285285    }
    286286   
    287     inline std::istream& readToken(std::istream& is, std::string& str) {
     287    std::istream& readToken(std::istream& is, std::string& str) {
    288288      std::ostringstream os;
    289289
     
    401401  /// \ingroup lemon_io
    402402  /// 
    403   /// \brief \ref lgf-format "LGF" reader for directed graphs
     403  /// \brief LGF reader for directed graphs
    404404  ///
    405405  /// This utility reads an \ref lgf-format "LGF" file.
     
    411411  /// with the \c nodeMap() or \c arcMap() members. An optional
    412412  /// converter parameter can also be added as a standard functor
    413   /// converting from \c std::string to the value type of the map. If it
     413  /// converting from std::string to the value type of the map. If it
    414414  /// is set, it will determine how the tokens in the file should be
    415   /// converted to the value type of the map. If the functor is not set,
     415  /// is converted to the map's value type. If the functor is not set,
    416416  /// then a default conversion will be used. One map can be read into
    417417  /// multiple map objects at the same time. The \c attribute(), \c
     
    420420  ///
    421421  ///\code
    422   /// DigraphReader<Digraph>(std::cin, digraph).
    423   ///   nodeMap("coordinates", coord_map).
    424   ///   arcMap("capacity", cap_map).
    425   ///   node("source", src).
    426   ///   node("target", trg).
    427   ///   attribute("caption", caption).
    428   ///   run();
     422  ///     DigraphReader<Digraph>(std::cin, digraph).
     423  ///       nodeMap("coordinates", coord_map).
     424  ///       arcMap("capacity", cap_map).
     425  ///       node("source", src).
     426  ///       node("target", trg).
     427  ///       attribute("caption", caption).
     428  ///       run();
    429429  ///\endcode
    430430  ///
     
    438438  /// graph) during the reading, but instead the label map of the items
    439439  /// are given as a parameter of these functions. An
    440   /// application of these functions is multipass reading, which is
    441   /// important if two \c \@arcs sections must be read from the
    442   /// file. In this case the first phase would read the node set and one
     440  /// application of these function is multipass reading, which is
     441  /// important if two \e \@arcs sections must be read from the
     442  /// file. In this example the first phase would read the node set and one
    443443  /// of the arc sets, while the second phase would read the second arc
    444444  /// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet).
    445445  /// The previously read label node map should be passed to the \c
    446446  /// useNodes() functions. Another application of multipass reading when
    447   /// paths are given as a node map or an arc map. It is impossible to read this in
     447  /// paths are given as a node map or an arc map. It is impossible read this in
    448448  /// a single pass, because the arcs are not constructed when the node
    449449  /// maps are read.
     
    736736    /// Use previously constructed node set, and specify the node
    737737    /// label map and a functor which converts the label map values to
    738     /// \c std::string.
     738    /// std::string.
    739739    template <typename Map, typename Converter>
    740740    DigraphReader& useNodes(const Map& map,
     
    769769    /// Use previously constructed arc set, and specify the arc
    770770    /// label map and a functor which converts the label map values to
    771     /// \c std::string.
     771    /// std::string.
    772772    template <typename Map, typename Converter>
    773773    DigraphReader& useArcs(const Map& map,
     
    785785    ///
    786786    /// Omit the reading of the node section. This implies that each node
    787     /// map reading rule will be abandoned, and the nodes of the graph
     787    /// map reading rule will be abanoned, and the nodes of the graph
    788788    /// will not be constructed, which usually cause that the arc set
    789     /// could not be read due to lack of node name resolving.
    790     /// Therefore \c skipArcs() function should also be used, or
    791     /// \c useNodes() should be used to specify the label of the nodes.
     789    /// could not be read due to lack of node name
     790    /// resolving. Therefore, the \c skipArcs() should be used too, or
     791    /// the useNodes() member function should be used to specify the
     792    /// label of the nodes.
    792793    DigraphReader& skipNodes() {
    793794      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     
    799800    ///
    800801    /// Omit the reading of the arc section. This implies that each arc
    801     /// map reading rule will be abandoned, and the arcs of the graph
     802    /// map reading rule will be abanoned, and the arcs of the graph
    802803    /// will not be constructed.
    803804    DigraphReader& skipArcs() {
     
    11751176  };
    11761177
    1177   /// \brief Return a \ref DigraphReader class
    1178   ///
    1179   /// This function just returns a \ref DigraphReader class.
    11801178  /// \relates DigraphReader
    11811179  template <typename Digraph>
     
    11851183  }
    11861184
    1187   /// \brief Return a \ref DigraphReader class
    1188   ///
    1189   /// This function just returns a \ref DigraphReader class.
    11901185  /// \relates DigraphReader
    11911186  template <typename Digraph>
     
    11961191  }
    11971192
    1198   /// \brief Return a \ref DigraphReader class
    1199   ///
    1200   /// This function just returns a \ref DigraphReader class.
    12011193  /// \relates DigraphReader
    12021194  template <typename Digraph>
     
    12201212  /// \ingroup lemon_io
    12211213  /// 
    1222   /// \brief \ref lgf-format "LGF" reader for undirected graphs
     1214  /// \brief LGF reader for undirected graphs
    12231215  ///
    12241216  /// This utility reads an \ref lgf-format "LGF" file.
    1225   ///
    1226   /// It can be used almost the same way as \c DigraphReader.
    1227   /// The only difference is that this class can handle edges and
    1228   /// edge maps as well as arcs and arc maps.
    1229   ///
    1230   /// The columns in the \c \@edges (or \c \@arcs) section are the
    1231   /// edge maps. However, if there are two maps with the same name
    1232   /// prefixed with \c '+' and \c '-', then these can be read into an
    1233   /// arc map.  Similarly, an attribute can be read into an arc, if
    1234   /// it's value is an edge label prefixed with \c '+' or \c '-'.
    12351217  template <typename _Graph>
    12361218  class GraphReader {
     
    12811263    /// \brief Constructor
    12821264    ///
    1283     /// Construct an undirected graph reader, which reads from the given
     1265    /// Construct a undirected graph reader, which reads from the given
    12841266    /// input stream.
    12851267    GraphReader(std::istream& is, Graph& graph)
     
    12901272    /// \brief Constructor
    12911273    ///
    1292     /// Construct an undirected graph reader, which reads from the given
     1274    /// Construct a undirected graph reader, which reads from the given
    12931275    /// file.
    12941276    GraphReader(const std::string& fn, Graph& graph)
     
    12991281    /// \brief Constructor
    13001282    ///
    1301     /// Construct an undirected graph reader, which reads from the given
     1283    /// Construct a undirected graph reader, which reads from the given
    13021284    /// file.
    13031285    GraphReader(const char* fn, Graph& graph)
     
    15161498    /// \brief Set \c \@nodes section to be read
    15171499    ///
    1518     /// Set \c \@nodes section to be read.
     1500    /// Set \c \@nodes section to be read
    15191501    GraphReader& nodes(const std::string& caption) {
    15201502      _nodes_caption = caption;
     
    15241506    /// \brief Set \c \@edges section to be read
    15251507    ///
    1526     /// Set \c \@edges section to be read.
     1508    /// Set \c \@edges section to be read
    15271509    GraphReader& edges(const std::string& caption) {
    15281510      _edges_caption = caption;
     
    15321514    /// \brief Set \c \@attributes section to be read
    15331515    ///
    1534     /// Set \c \@attributes section to be read.
     1516    /// Set \c \@attributes section to be read
    15351517    GraphReader& attributes(const std::string& caption) {
    15361518      _attributes_caption = caption;
     
    15631545    /// Use previously constructed node set, and specify the node
    15641546    /// label map and a functor which converts the label map values to
    1565     /// \c std::string.
     1547    /// std::string.
    15661548    template <typename Map, typename Converter>
    15671549    GraphReader& useNodes(const Map& map,
     
    15961578    /// Use previously constructed edge set, and specify the edge
    15971579    /// label map and a functor which converts the label map values to
    1598     /// \c std::string.
     1580    /// std::string.
    15991581    template <typename Map, typename Converter>
    16001582    GraphReader& useEdges(const Map& map,
     
    16091591    }
    16101592
    1611     /// \brief Skip the reading of node section
     1593    /// \brief Skips the reading of node section
    16121594    ///
    16131595    /// Omit the reading of the node section. This implies that each node
    1614     /// map reading rule will be abandoned, and the nodes of the graph
     1596    /// map reading rule will be abanoned, and the nodes of the graph
    16151597    /// will not be constructed, which usually cause that the edge set
    16161598    /// could not be read due to lack of node name
    1617     /// could not be read due to lack of node name resolving.
    1618     /// Therefore \c skipEdges() function should also be used, or
    1619     /// \c useNodes() should be used to specify the label of the nodes.
     1599    /// resolving. Therefore, the \c skipEdges() should be used too, or
     1600    /// the useNodes() member function should be used to specify the
     1601    /// label of the nodes.
    16201602    GraphReader& skipNodes() {
    16211603      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
     
    16241606    }
    16251607
    1626     /// \brief Skip the reading of edge section
     1608    /// \brief Skips the reading of edge section
    16271609    ///
    16281610    /// Omit the reading of the edge section. This implies that each edge
    1629     /// map reading rule will be abandoned, and the edges of the graph
     1611    /// map reading rule will be abanoned, and the edges of the graph
    16301612    /// will not be constructed.
    16311613    GraphReader& skipEdges() {
     
    20011983  };
    20021984
    2003   /// \brief Return a \ref GraphReader class
    2004   ///
    2005   /// This function just returns a \ref GraphReader class.
    20061985  /// \relates GraphReader
    20071986  template <typename Graph>
     
    20111990  }
    20121991
    2013   /// \brief Return a \ref GraphReader class
    2014   ///
    2015   /// This function just returns a \ref GraphReader class.
    20161992  /// \relates GraphReader
    20171993  template <typename Graph>
     
    20221998  }
    20231999
    2024   /// \brief Return a \ref GraphReader class
    2025   ///
    2026   /// This function just returns a \ref GraphReader class.
    20272000  /// \relates GraphReader
    20282001  template <typename Graph>
     
    20382011  SectionReader sectionReader(const char* fn);
    20392012 
    2040   /// \ingroup lemon_io
    2041   ///
    20422013  /// \brief Section reader class
    20432014  ///
    2044   /// In the \ref lgf-format "LGF" file extra sections can be placed,
    2045   /// 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
    2047   /// with two different functions. With the \c sectionLines() function a
    2048   /// functor can process the section line-by-line, while with the \c
     2015  /// In the \e LGF file extra sections can be placed, which contain
     2016  /// any data in arbitrary format. Such sections can be read with
     2017  /// this class. A reading rule can be added with two different
     2018  /// functions, with the \c sectionLines() function a functor can
     2019  /// process the section line-by-line. While with the \c
    20492020  /// sectionStream() member the section can be read from an input
    20502021  /// stream.
     
    21352106    ///\endcode
    21362107    ///
    2137     /// The functor is implemented as a struct:
     2108    /// The functor is implemented as an struct:
    21382109    ///\code
    21392110    ///  struct NumberSection {
     
    21532124    template <typename Functor>
    21542125    SectionReader& sectionLines(const std::string& type, Functor functor) {
    2155       LEMON_ASSERT(!type.empty(), "Type is empty.");
     2126      LEMON_ASSERT(!type.empty(), "Type is not empty.");
    21562127      LEMON_ASSERT(_sections.find(type) == _sections.end(),
    21572128                   "Multiple reading of section.");
     
    21652136    ///
    21662137    /// The first parameter is the type of the section, the second is
    2167     /// a functor, which takes an \c std::istream& and an \c int&
     2138    /// a functor, which takes an \c std::istream& and an int&
    21682139    /// parameter, the latter regard to the line number of stream. The
    21692140    /// functor can read the input while the section go on, and the
     
    21712142    template <typename Functor>
    21722143    SectionReader& sectionStream(const std::string& type, Functor functor) {
    2173       LEMON_ASSERT(!type.empty(), "Type is empty.");
     2144      LEMON_ASSERT(!type.empty(), "Type is not empty.");
    21742145      LEMON_ASSERT(_sections.find(type) == _sections.end(),
    21752146                   "Multiple reading of section.");
     
    22162187    /// \brief Start the batch processing
    22172188    ///
    2218     /// This function starts the batch processing.
     2189    /// This function starts the batch processing
    22192190    void run() {
    22202191     
     
    22692240  };
    22702241
    2271   /// \brief Return a \ref SectionReader class
    2272   ///
    2273   /// This function just returns a \ref SectionReader class.
    22742242  /// \relates SectionReader
    22752243  inline SectionReader sectionReader(std::istream& is) {
     
    22782246  }
    22792247
    2280   /// \brief Return a \ref SectionReader class
    2281   ///
    2282   /// This function just returns a \ref SectionReader class.
    22832248  /// \relates SectionReader
    22842249  inline SectionReader sectionReader(const std::string& fn) {
     
    22872252  }
    22882253
    2289   /// \brief Return a \ref SectionReader class
    2290   ///
    2291   /// This function just returns a \ref SectionReader class.
    22922254  /// \relates SectionReader
    22932255  inline SectionReader sectionReader(const char* fn) {
     
    23082270  /// reading the graph.
    23092271  ///
    2310   ///\code
    2311   /// LgfContents contents("graph.lgf");
     2272  ///\code LgfContents contents("graph.lgf");
    23122273  /// contents.run();
    23132274  ///
    2314   /// // Does it contain any node section and arc section?
     2275  /// // does it contain any node section and arc section
    23152276  /// if (contents.nodeSectionNum() == 0 || contents.arcSectionNum()) {
    2316   ///   std::cerr << "Failure, cannot find graph." << std::endl;
     2277  ///   std::cerr << "Failure, cannot find graph" << std::endl;
    23172278  ///   return -1;
    23182279  /// }
    2319   /// std::cout << "The name of the default node section: "
     2280  /// std::cout << "The name of the default node section : "
    23202281  ///           << contents.nodeSection(0) << std::endl;
    2321   /// std::cout << "The number of the arc maps: "
     2282  /// std::cout << "The number of the arc maps : "
    23222283  ///           << contents.arcMaps(0).size() << std::endl;
    2323   /// std::cout << "The name of second arc map: "
     2284  /// std::cout << "The name of second arc map : "
    23242285  ///           << contents.arcMaps(0)[1] << std::endl;
    23252286  ///\endcode
     
    23922353    }
    23932354
    2394     /// \brief Returns the node section name at the given position.
    2395     ///
    2396     /// Returns the node section name at the given position.
     2355    /// \brief Returns the section name at the given position.
     2356    ///
     2357    /// Returns the section name at the given position.
    23972358    const std::string& nodeSection(int i) const {
    23982359      return _node_sections[i];
     
    24192380    }
    24202381
    2421     /// \brief Returns the arc/edge section name at the given position.
    2422     ///
    2423     /// Returns the arc/edge section name at the given position.
     2382    /// \brief Returns the section name at the given position.
     2383    ///
     2384    /// Returns the section name at the given position.
    24242385    /// \note It is synonym of \c edgeSection().
    24252386    const std::string& arcSection(int i) const {
     
    24762437    }
    24772438
    2478     /// \brief Returns the attribute section name at the given position.
    2479     ///
    2480     /// Returns the attribute section name at the given position.
     2439    /// \brief Returns the section name at the given position.
     2440    ///
     2441    /// Returns the section name at the given position.
    24812442    const std::string& attributeSectionNames(int i) const {
    24822443      return _attribute_sections[i];
     
    25692530    /// @{
    25702531
    2571     /// \brief Starts the reading
    2572     ///
    2573     /// This function starts the reading.
     2532    /// \brief Start the reading
     2533    ///
     2534    /// This function starts the reading
    25742535    void run() {
    25752536
  • lemon/lgf_writer.h

    r201 r190  
    1919///\ingroup lemon_io
    2020///\file
    21 ///\brief \ref lgf-format "Lemon Graph Format" writer.
     21///\brief Lemon Graph Format writer.
    2222
    2323
     
    226226    };
    227227
    228     inline bool isWhiteSpace(char c) {
     228    bool isWhiteSpace(char c) {
    229229      return c == ' ' || c == '\t' || c == '\v' ||
    230230        c == '\n' || c == '\r' || c == '\f';
    231231    }
    232232
    233     inline bool isEscaped(char c) {
     233    bool isEscaped(char c) {
    234234      return c == '\\' || c == '\"' || c == '\'' ||
    235235        c == '\a' || c == '\b';
    236236    }
    237237
    238     inline static void writeEscape(std::ostream& os, char c) {
     238    static void writeEscape(std::ostream& os, char c) {
    239239      switch (c) {
    240240      case '\\':
     
    277277    }
    278278
    279     inline bool requireEscape(const std::string& str) {
     279    bool requireEscape(const std::string& str) {
    280280      if (str.empty() || str[0] == '@') return true;
    281281      std::istringstream is(str);
     
    289289    }
    290290   
    291     inline std::ostream& writeToken(std::ostream& os, const std::string& str) {
     291    std::ostream& writeToken(std::ostream& os, const std::string& str) {
    292292
    293293      if (requireEscape(str)) {
     
    323323  /// \ingroup lemon_io
    324324  /// 
    325   /// \brief \ref lgf-format "LGF" writer for directed graphs
     325  /// \brief LGF writer for directed graphs
    326326  ///
    327327  /// This utility writes an \ref lgf-format "LGF" file.
     
    333333  /// with the \c nodeMap() or \c arcMap() members. An optional
    334334  /// converter parameter can also be added as a standard functor
    335   /// converting from the value type of the map to \c std::string. If it
    336   /// is set, it will determine how the value type of the map is written to
     335  /// converting from the value type of the map to std::string. If it
     336  /// is set, it will determine how the map's value type is written to
    337337  /// the output stream. If the functor is not set, then a default
    338338  /// conversion will be used. The \c attribute(), \c node() and \c
     
    340340  ///
    341341  ///\code
    342   /// DigraphWriter<Digraph>(std::cout, digraph).
    343   ///   nodeMap("coordinates", coord_map).
    344   ///   nodeMap("size", size).
    345   ///   nodeMap("title", title).
    346   ///   arcMap("capacity", cap_map).
    347   ///   node("source", src).
    348   ///   node("target", trg).
    349   ///   attribute("caption", caption).
    350   ///   run();
     342  ///     DigraphWriter<Digraph>(std::cout, digraph).
     343  ///       nodeMap("coordinates", coord_map).
     344  ///       nodeMap("size", size).
     345  ///       nodeMap("title", title).
     346  ///       arcMap("capacity", cap_map).
     347  ///       node("source", src).
     348  ///       node("target", trg).
     349  ///       attribute("caption", caption).
     350  ///       run();
    351351  ///\endcode
    352352  ///
     
    487487    /// @{
    488488   
    489     /// \brief Node map writing rule
    490     ///
    491     /// Add a node map writing rule to the writer.
     489    /// \brief Node map reading rule
     490    ///
     491    /// Add a node map reading rule to the writer.
    492492    template <typename Map>
    493493    DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
     
    587587    }
    588588
    589     /// \name Section captions
     589    /// \name Select section by name
    590590    /// @{
    591591
    592     /// \brief Add an additional caption to the \c \@nodes section
    593     ///
    594     /// Add an additional caption to the \c \@nodes section.
     592    /// \brief Set \c \@nodes section to be read
     593    ///
     594    /// Set \c \@nodes section to be read
    595595    DigraphWriter& nodes(const std::string& caption) {
    596596      _nodes_caption = caption;
     
    598598    }
    599599
    600     /// \brief Add an additional caption to the \c \@arcs section
    601     ///
    602     /// Add an additional caption to the \c \@arcs section.
     600    /// \brief Set \c \@arcs section to be read
     601    ///
     602    /// Set \c \@arcs section to be read
    603603    DigraphWriter& arcs(const std::string& caption) {
    604604      _arcs_caption = caption;
     
    606606    }
    607607
    608     /// \brief Add an additional caption to the \c \@attributes section
    609     ///
    610     /// Add an additional caption to the \c \@attributes section.
     608    /// \brief Set \c \@attributes section to be read
     609    ///
     610    /// Set \c \@attributes section to be read
    611611    DigraphWriter& attributes(const std::string& caption) {
    612612      _attributes_caption = caption;
     
    619619    /// \brief Skip writing the node set
    620620    ///
    621     /// The \c \@nodes section will not be written to the stream.
     621    /// The \c \@nodes section will be not written to the stream.
    622622    DigraphWriter& skipNodes() {
    623623      LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
     
    628628    /// \brief Skip writing arc set
    629629    ///
    630     /// The \c \@arcs section will not be written to the stream.
     630    /// The \c \@arcs section will be not written to the stream.
    631631    DigraphWriter& skipArcs() {
    632632      LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member");
     
    836836    /// \brief Start the batch processing
    837837    ///
    838     /// This function starts the batch processing.
     838    /// This function starts the batch processing
    839839    void run() {
    840840      if (!_skip_nodes) {
     
    851851    }
    852852
    853     /// \brief Give back the stream of the writer
    854     ///
    855     /// Give back the stream of the writer.
     853    /// \brief Gives back the stream of the writer
     854    ///
     855    /// Gives back the stream of the writer
    856856    std::ostream& ostream() {
    857857      return *_os;
     
    861861  };
    862862
    863   /// \brief Return a \ref DigraphWriter class
    864   ///
    865   /// This function just returns a \ref DigraphWriter class.
    866863  /// \relates DigraphWriter
    867864  template <typename Digraph>
     
    872869  }
    873870
    874   /// \brief Return a \ref DigraphWriter class
    875   ///
    876   /// This function just returns a \ref DigraphWriter class.
    877871  /// \relates DigraphWriter
    878872  template <typename Digraph>
     
    883877  }
    884878
    885   /// \brief Return a \ref DigraphWriter class
    886   ///
    887   /// This function just returns a \ref DigraphWriter class.
    888879  /// \relates DigraphWriter
    889880  template <typename Digraph>
     
    908899  /// \ingroup lemon_io
    909900  /// 
    910   /// \brief \ref lgf-format "LGF" writer for directed graphs
     901  /// \brief LGF writer for directed graphs
    911902  ///
    912903  /// This utility writes an \ref lgf-format "LGF" file.
    913   ///
    914   /// It can be used almost the same way as \c DigraphWriter.
    915   /// The only difference is that this class can handle edges and
    916   /// edge maps as well as arcs and arc maps.
    917   ///
    918   /// The arc maps are written into the file as two columns, the
    919   /// caption of the columns are the name of the map prefixed with \c
    920   /// '+' and \c '-'. The arcs are written into the \c \@attributes
    921   /// section as a \c '+' or a \c '-' prefix (depends on the direction
    922   /// of the arc) and the label of corresponding edge.
    923904  template <typename _Graph>
    924905  class GraphWriter {
     
    10431024    /// @{
    10441025   
    1045     /// \brief Node map writing rule
    1046     ///
    1047     /// Add a node map writing rule to the writer.
     1026    /// \brief Node map reading rule
     1027    ///
     1028    /// Add a node map reading rule to the writer.
    10481029    template <typename Map>
    10491030    GraphWriter& nodeMap(const std::string& caption, const Map& map) {
     
    11891170    }
    11901171
    1191     /// \name Section captions
     1172    /// \name Select section by name
    11921173    /// @{
    11931174
    1194     /// \brief Add an additional caption to the \c \@nodes section
    1195     ///
    1196     /// Add an additional caption to the \c \@nodes section.
     1175    /// \brief Set \c \@nodes section to be read
     1176    ///
     1177    /// Set \c \@nodes section to be read
    11971178    GraphWriter& nodes(const std::string& caption) {
    11981179      _nodes_caption = caption;
     
    12001181    }
    12011182
    1202     /// \brief Add an additional caption to the \c \@arcs section
    1203     ///
    1204     /// Add an additional caption to the \c \@arcs section.
     1183    /// \brief Set \c \@edges section to be read
     1184    ///
     1185    /// Set \c \@edges section to be read
    12051186    GraphWriter& edges(const std::string& caption) {
    12061187      _edges_caption = caption;
     
    12081189    }
    12091190
    1210     /// \brief Add an additional caption to the \c \@attributes section
    1211     ///
    1212     /// Add an additional caption to the \c \@attributes section.
     1191    /// \brief Set \c \@attributes section to be read
     1192    ///
     1193    /// Set \c \@attributes section to be read
    12131194    GraphWriter& attributes(const std::string& caption) {
    12141195      _attributes_caption = caption;
     
    12211202    /// \brief Skip writing the node set
    12221203    ///
    1223     /// The \c \@nodes section will not be written to the stream.
     1204    /// The \c \@nodes section will be not written to the stream.
    12241205    GraphWriter& skipNodes() {
    12251206      LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member");
     
    12301211    /// \brief Skip writing edge set
    12311212    ///
    1232     /// The \c \@edges section will not be written to the stream.
     1213    /// The \c \@edges section will be not written to the stream.
    12331214    GraphWriter& skipEdges() {
    12341215      LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member");
     
    14381419    /// \brief Start the batch processing
    14391420    ///
    1440     /// This function starts the batch processing.
     1421    /// This function starts the batch processing
    14411422    void run() {
    14421423      if (!_skip_nodes) {
     
    14531434    }
    14541435
    1455     /// \brief Give back the stream of the writer
    1456     ///
    1457     /// Give back the stream of the writer
     1436    /// \brief Gives back the stream of the writer
     1437    ///
     1438    /// Gives back the stream of the writer
    14581439    std::ostream& ostream() {
    14591440      return *_os;
     
    14631444  };
    14641445
    1465   /// \brief Return a \ref GraphWriter class
    1466   ///
    1467   /// This function just returns a \ref GraphWriter class.
    14681446  /// \relates GraphWriter
    14691447  template <typename Graph>
     
    14731451  }
    14741452
    1475   /// \brief Return a \ref GraphWriter class
    1476   ///
    1477   /// This function just returns a \ref GraphWriter class.
    14781453  /// \relates GraphWriter
    14791454  template <typename Graph>
     
    14831458  }
    14841459
    1485   /// \brief Return a \ref GraphWriter class
    1486   ///
    1487   /// This function just returns a \ref GraphWriter class.
    14881460  /// \relates GraphWriter
    14891461  template <typename Graph>
  • test/CMakeLists.txt

    r203 r171  
    1111  dim_test
    1212  error_test
    13   graph_copy_test
    1413  graph_test
    1514  graph_utils_test
    16   heap_test
    1715  kruskal_test
    1816  maps_test
  • test/Makefile.am

    r203 r171  
    44noinst_HEADERS += \
    55        test/graph_test.h \
     6        test/heap_test.h \
    67        test/graph_maps_test.h \
    78        test/test_tools.h
     
    1516        test/dim_test \
    1617        test/error_test \
    17         test/graph_copy_test \
    1818        test/graph_test \
    1919        test/graph_utils_test \
    20         test/heap_test \
    2120        test/kruskal_test \
    2221        test/maps_test \
     
    3837test_dim_test_SOURCES = test/dim_test.cc
    3938test_error_test_SOURCES = test/error_test.cc
    40 test_graph_copy_test_SOURCES = test/graph_copy_test.cc
    4139test_graph_test_SOURCES = test/graph_test.cc
    4240test_graph_utils_test_SOURCES = test/graph_utils_test.cc
    43 test_heap_test_SOURCES = test/heap_test.cc
     41# test_heap_test_SOURCES = test/heap_test.cc
    4442test_kruskal_test_SOURCES = test/kruskal_test.cc
    4543test_maps_test_SOURCES = test/maps_test.cc
  • test/heap_test.cc

    r203 r171  
    2525#include <lemon/concepts/heap.h>
    2626
    27 #include <lemon/smart_graph.h>
     27#include <lemon/list_graph.h>
    2828
    29 #include <lemon/lgf_reader.h>
    30 #include <lemon/dijkstra.h>
    31 #include <lemon/maps.h>
     29#include <lemon/digraph_reader.h>
    3230
    3331#include <lemon/bin_heap.h>
     32#include <lemon/fib_heap.h>
     33#include <lemon/radix_heap.h>
     34#include <lemon/bucket_heap.h>
    3435
    3536#include "test_tools.h"
    3637
     38#include "heap_test.h"
     39
     40#include <lemon/time_measure.h>
     41
    3742using namespace lemon;
    3843using namespace lemon::concepts;
    39 
    40 typedef ListDigraph Digraph;
    41 DIGRAPH_TYPEDEFS(Digraph);
    42 
    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"
    79   "source 3\n";
    80 
    81 int test_seq[] = { 2, 28, 19, 27, 33, 25, 13, 41, 10, 26,  1,  9,  4, 34};
    82 int test_inc[] = {20, 28, 34, 16,  0, 46, 44,  0, 42, 32, 14,  8,  6, 37};
    83 
    84 int test_len = sizeof(test_seq) / sizeof(test_seq[0]);
    85 
    86 template <typename Heap>
    87 void heapSortTest() {
    88   RangeMap<int> map(test_len, -1);
    89 
    90   Heap heap(map);
    91  
    92   std::vector<int> v(test_len);
    93 
    94   for (int i = 0; i < test_len; ++i) {
    95     v[i] = test_seq[i];
    96     heap.push(i, v[i]);
    97   }
    98   std::sort(v.begin(), v.end());
    99   for (int i = 0; i < test_len; ++i) {
    100     check(v[i] == heap.prio() ,"Wrong order in heap sort.");
    101     heap.pop();
    102   }
    103 }
    104 
    105 template <typename Heap>
    106 void heapIncreaseTest() {
    107   RangeMap<int> map(test_len, -1);
    108 
    109   Heap heap(map);
    110  
    111   std::vector<int> v(test_len);
    112 
    113   for (int i = 0; i < test_len; ++i) {
    114     v[i] = test_seq[i];
    115     heap.push(i, v[i]);
    116   }
    117   for (int i = 0; i < test_len; ++i) {
    118     v[i] += test_inc[i];
    119     heap.increase(i, v[i]);
    120   }
    121   std::sort(v.begin(), v.end());
    122   for (int i = 0; i < test_len; ++i) {
    123     check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
    124     heap.pop();
    125   }
    126 }
    127 
    128 
    129 
    130 template <typename Heap>
    131 void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
    132                       Node source) {
    133  
    134   typename Dijkstra<Digraph, IntArcMap>::template DefStandardHeap<Heap>::
    135     Create dijkstra(digraph, length);
    136 
    137   dijkstra.run(source);
    138 
    139   for(ArcIt a(digraph); a != INVALID; ++a) {
    140     Node s = digraph.source(a);
    141     Node t = digraph.target(a);
    142     if (dijkstra.reached(s)) {
    143       check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
    144              "Error in a shortest path tree!");
    145     }
    146   }
    147 
    148   for(NodeIt n(digraph); n != INVALID; ++n) {
    149     if ( dijkstra.reached(n) && dijkstra.predArc(n) != INVALID ) {
    150       Arc a = dijkstra.predArc(n);
    151       Node s = digraph.source(a);
    152       check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
    153              "Error in a shortest path tree!");
    154     }
    155   }
    156 
    157 }
    15844
    15945int main() {
     
    16147  typedef int Item;
    16248  typedef int Prio;
    163   typedef RangeMap<int> ItemIntMap;
     49  typedef IntIntMap ItemIntMap;
     50
     51  typedef ListDigraph Digraph;
     52
     53  typedef Digraph::Arc Arc;
     54  typedef Digraph::Node Node;
     55  typedef Digraph::ArcIt ArcIt;
     56  typedef Digraph::NodeIt NodeIt;
     57  typedef Digraph::ArcMap<int> LengthMap;
     58
     59  Digraph digraph;
     60  LengthMap length(digraph);
     61  Node start;
     62
     63  /// \todo create own test digraph
     64
     65  std::string f_name;
     66  if( getenv("srcdir") )
     67    f_name = std::string(getenv("srcdir"));
     68  else f_name = ".";
     69  f_name += "/test/dijkstra_test.lgf";
    16470 
    165   Digraph digraph;
    166   IntArcMap length(digraph);
    167   Node source;
    168 
    169   std::istringstream input(test_lgf);
    170   digraphReader(input, digraph).
    171     arcMap("capacity", length).
    172     node("source", source).
     71  std::ifstream input(f_name.c_str());
     72  check(input, "Input file '" << f_name << "' not found.");
     73  DigraphReader<Digraph>(input, digraph).
     74    readArcMap("capacity", length).
     75    readNode("source", start).
    17376    run(); 
    17477 
    17578  {
     79    std::cout << "Checking Bin Heap" << std::endl;
     80
    17681    typedef BinHeap<Prio, ItemIntMap> IntHeap;
    17782    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
    178     heapSortTest<IntHeap>();
    179     heapIncreaseTest<IntHeap>();
     83    heapSortTest<IntHeap>(100);
     84    heapIncreaseTest<IntHeap>(100);
    18085   
    181     typedef BinHeap<Prio, IntNodeMap > NodeHeap;
    182     checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
    183     dijkstraHeapTest<NodeHeap>(digraph, length, source);
     86    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
     87    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
     88    Timer timer;
     89    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
     90    std::cout << timer << std::endl;
     91  }
     92  {
     93    std::cout << "Checking Fib Heap" << std::endl;
     94
     95    typedef FibHeap<Prio, ItemIntMap> IntHeap;
     96    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     97    heapSortTest<IntHeap>(100);
     98    heapIncreaseTest<IntHeap>(100);
     99
     100    typedef FibHeap<Prio, Digraph::NodeMap<int> > NodeHeap;
     101    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
     102    Timer timer;
     103    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
     104    std::cout << timer << std::endl;
     105  }
     106  {
     107    std::cout << "Checking Radix Heap" << std::endl;
     108
     109    typedef RadixHeap<ItemIntMap> IntHeap;
     110    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     111    heapSortTest<IntHeap>(100);
     112    heapIncreaseTest<IntHeap>(100);
     113
     114    typedef RadixHeap<Digraph::NodeMap<int> > NodeHeap;
     115    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
     116    Timer timer;
     117    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
     118    std::cout << timer << std::endl;
     119  }
     120
     121  {
     122    std::cout << "Checking Bucket Heap" << std::endl;
     123
     124    typedef BucketHeap<ItemIntMap> IntHeap;
     125    checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
     126    heapSortTest<IntHeap>(100);
     127    heapIncreaseTest<IntHeap>(100);
     128
     129    typedef BucketHeap<Digraph::NodeMap<int> > NodeHeap;
     130    checkConcept<Heap<Prio, Digraph::NodeMap<int> >, NodeHeap>();
     131    Timer timer;
     132    dijkstraHeapTest<Digraph, LengthMap, NodeHeap>(digraph, length, start);
     133    std::cout << timer << std::endl;
    184134  }
    185135
Note: See TracChangeset for help on using the changeset viewer.