Changes in / [207:574b963d0275:206:4e22275a2b52] in lemon-1.2
- Files:
-
- 1 added
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
demo/arg_parser_demo.cc
r204 r137 30 30 int main(int argc, const char **argv) 31 31 { 32 // Initialize the argument parser 33 ArgParser ap(argc, argv); 32 ArgParser ap(argc,argv); 34 33 int i; 35 34 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.") 66 54 .other("..."); 67 55 68 // Perform the parsing process69 // (in case of any error it terminates the program)70 56 ap.parse(); 71 57 72 // Check each option if it has been given and print its value73 58 std::cout << "Parameters of '" << ap.commandName() << "':\n"; 74 59 75 std::cout << " Value of -n: " << i << std::endl;60 if(ap.given("n")) std::cout << " Value of -n: " << i << std::endl; 76 61 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 }81 62 if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl; 82 63 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; 84 65 if(ap.given("gra")) std::cout << " -gra is given\n"; 85 66 if(ap.given("grb")) std::cout << " -grb is given\n"; 86 67 if(ap.given("grc")) std::cout << " -grc is given\n"; 87 68 88 69 switch(ap.files().size()) { 89 70 case 0: … … 100 81 std::cout << " '" << ap.files()[i] << "'\n"; 101 82 102 return 0;103 83 } -
demo/lgf_demo.cc
r193 r164 21 21 ///\brief Demonstrating graph input and output 22 22 /// 23 /// This program gives an example of how to read and write a digraph24 /// an d additional maps from/to a stream or a file using the25 /// \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. 26 26 /// 27 27 /// The \c "digraph.lgf" file: 28 28 /// \include digraph.lgf 29 29 /// 30 /// And the program which reads it and prints the digraph to the 31 /// standard output: 30 /// And the program which reads it: 32 31 /// \include lgf_demo.cc 33 32 … … 36 35 #include <lemon/lgf_reader.h> 37 36 #include <lemon/lgf_writer.h> 37 #include <lemon/random.h> 38 38 39 39 40 using namespace lemon; … … 43 44 SmartDigraph::ArcMap<int> cap(g); 44 45 SmartDigraph::Node s, t; 45 46 try {47 digraphReader("digraph.lgf", g). // read the directed graph into g48 arcMap("capacity", cap). // read the 'capacity' arc map into cap49 node("source", s). // read 'source' node to s50 node("target", t). // read 'target' node to t51 run();52 } catch (DataFormatError& error) { // check if there was any error53 std::cerr << "Error: " << error.what() << std::endl;54 return -1;55 }56 46 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; 58 54 std::cout << "Number of nodes: " << countNodes(g) << std::endl; 59 55 std::cout << "Number of arcs: " << countArcs(g) << std::endl; -
doc/groups.dox
r192 r156 476 476 @defgroup lemon_io Lemon Input-Output 477 477 @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 480 This group describes methods for reading and writing LEMON format. 481 You can find more about this format on the \ref graph-io-page "Graph Input-Output" 482 tutorial pages. 481 483 */ 482 484 -
doc/lgf.dox
r201 r162 47 47 48 48 The \c \@nodes section describes a set of nodes and associated 49 maps. The first is a header line, it scolumns are the names of the49 maps. The first is a header line, it columns are the names of the 50 50 maps appearing in the following lines. 51 51 One of the maps must be called \c … … 65 65 66 66 The \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,67 it again starts with a header line describing the names of the arc, 68 68 but the \c "label" map is not obligatory here. The following lines 69 69 describe the arcs. The first two tokens of each line are … … 79 79 \endcode 80 80 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. 81 The \c \@edges is just a synonym of \c \@arcs. 86 82 87 83 The \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. 84 consists of two tokens, an attribute name, and then an attribute value. 93 85 94 86 \code -
lemon/Makefile.am
r195 r166 33 33 lemon/kruskal.h \ 34 34 lemon/lgf_reader.h \ 35 lemon/lgf_writer.h \36 35 lemon/list_graph.h \ 37 36 lemon/maps.h \ … … 61 60 lemon/concepts/digraph.h \ 62 61 lemon/concepts/graph.h \ 63 lemon/concepts/graph_components.h \64 62 lemon/concepts/heap.h \ 65 63 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 119 119 public: 120 120 121 /// Constructor121 ///\e 122 122 ArgParser(int argc, const char **argv); 123 123 124 124 ~ArgParser(); 125 125 126 ///\name Options127 ///128 129 ///@{130 131 126 ///Add a new integer type option 132 127 133 ///Add a new integer type option.134 128 ///\param name The name of the option. The leading '-' must be omitted. 135 129 ///\param help A help string. … … 142 136 ///Add a new floating point type option 143 137 144 ///Add a new floating point type option.145 138 ///\param name The name of the option. The leading '-' must be omitted. 146 139 ///\param help A help string. … … 153 146 ///Add a new bool type option 154 147 155 ///Add a new bool type option.156 148 ///\param name The name of the option. The leading '-' must be omitted. 157 149 ///\param help A help string. … … 165 157 ///Add a new string type option 166 158 167 ///Add a new string type option.168 159 ///\param name The name of the option. The leading '-' must be omitted. 169 160 ///\param help A help string. … … 174 165 std::string value="", bool obl=false); 175 166 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 187 168 ///Using this functions, the value of the option will be directly written 188 169 ///into a variable once the option appears in the command line. … … 192 173 ///Add a new integer type option with a storage reference 193 174 194 ///Add a new integer type option with a storage reference.195 175 ///\param name The name of the option. The leading '-' must be omitted. 196 176 ///\param help A help string. … … 203 183 ///Add a new floating type option with a storage reference 204 184 205 ///Add a new floating type option with a storage reference.206 185 ///\param name The name of the option. The leading '-' must be omitted. 207 186 ///\param help A help string. … … 214 193 ///Add a new bool type option with a storage reference 215 194 216 ///Add a new bool type option with a storage reference.217 195 ///\param name The name of the option. The leading '-' must be omitted. 218 196 ///\param help A help string. … … 226 204 ///Add a new string type option with a storage reference 227 205 228 ///Add a new string type option with a storage reference.229 206 ///\param name The name of the option. The leading '-' must be omitted. 230 207 ///\param help A help string. … … 242 219 ///@{ 243 220 244 ///B undle some options into a group221 ///Boundle some options into a group 245 222 246 223 /// You can group some option by calling this function repeatedly for each … … 254 231 255 232 ///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 257 234 ArgParser &onlyOneGroup(const std::string &group); 258 235 … … 271 248 272 249 ///@} 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; } 273 267 274 268 void show(std::ostream &os,Opts::iterator i); … … 293 287 } 294 288 295 ///Give back the command name (the 0th argument)296 const std::string &commandName() { return _command_name; }297 298 289 ///Check if an opion has been given to the command. 299 290 bool given(std::string op) … … 370 361 return RefType(*this, n); 371 362 } 372 373 ///Give back the non-option type arguments.374 375 ///Give back a reference to a vector consisting of the program arguments376 ///not starting with a '-' character.377 std::vector<std::string> &files() { return _file_args; }378 363 379 364 }; 380 365 } 381 366 382 #endif // LEMON_ARG_PARSER 367 368 369 #endif // LEMON_MAIN_PARAMS -
lemon/concepts/heap.h
r203 r113 182 182 Item item; 183 183 Prio prio; 184 State state; 184 185 item=Item(); 185 186 prio=Prio(); 186 187 ignore_unused_variable_warning(item); 187 188 ignore_unused_variable_warning(prio); 189 ignore_unused_variable_warning(state); 188 190 189 191 OwnItem own_item; … … 202 204 203 205 int s = heap.size(); 204 ignore_unused_variable_warning(s);205 206 bool e = heap.empty(); 206 ignore_unused_variable_warning(e);207 207 208 208 prio = heap.prio(); … … 228 228 heap.clear(); 229 229 230 own_state = heap.state(own_item); 230 state = heap.state(item); 231 heap.state(item, state); 232 state = heap.state(own_item); 231 233 heap.state(own_item, own_state); 232 234 235 state = _Heap::PRE_HEAP; 236 state = _Heap::IN_HEAP; 237 state = _Heap::POST_HEAP; 233 238 own_state = _Heap::PRE_HEAP; 234 239 own_state = _Heap::IN_HEAP; -
lemon/graph_utils.h
r199 r169 603 603 for (typename From::ArcIt it(from); it != INVALID; ++it) { 604 604 arcRefMap[it] = to.addArc(nodeRefMap[from.source(it)], 605 605 nodeRefMap[from.target(it)]); 606 606 } 607 607 } … … 629 629 } 630 630 for (typename From::EdgeIt it(from); it != INVALID; ++it) { 631 edgeRefMap[it] = to.add Edge(nodeRefMap[from.u(it)],632 nodeRefMap[from.v(it)]);631 edgeRefMap[it] = to.addArc(nodeRefMap[from.source(it)], 632 nodeRefMap[from.target(it)]); 633 633 } 634 634 } … … 926 926 927 927 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]))); 932 931 return _to.direct(_edge_ref[key], forward); 933 932 } -
lemon/kruskal.h
r194 r167 33 33 ///\ingroup spantree 34 34 ///\file 35 ///\brief Kruskal's algorithm to compute a minimum cost spanningtree35 ///\brief Kruskal's algorithm to compute a minimum cost tree 36 36 /// 37 ///Kruskal's algorithm to compute a minimum cost spanningtree.37 ///Kruskal's algorithm to compute a minimum cost tree. 38 38 /// 39 39 … … 252 252 /// \ingroup spantree 253 253 /// 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. 259 257 /// Due to some C++ hacking, it accepts various input and output types. 260 258 /// … … 265 263 /// undirected by disregarding the direction of the arcs. 266 264 /// 267 /// \param in This object is used to describe the arc /edge costs.268 /// It can be oneof the following choices.265 /// \param in This object is used to describe the arc costs. It can be one 266 /// of the following choices. 269 267 /// - An STL compatible 'Forward Container' with 270 /// <tt>std::pair<GR:: Arc,X></tt> or271 /// <tt>std::pair<GR:: Edge,X></tt> as its <tt>value_type</tt>, where272 /// \c X is the type of the costs. The pairs indicates the arcs /edges268 /// <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 273 271 /// along with the assigned cost. <em>They must be in a 274 272 /// 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 282 279 /// to the tree, otherwise it will be set to \c false. The value of 283 /// each arc /edgewill be set exactly once.280 /// each arc will be set exactly once. 284 281 /// - It can also be an iteraror of an STL Container with 285 /// <tt>GR:: Arc</tt> or <tt>GR::Edge</tt> as its282 /// <tt>GR::Edge</tt> or <tt>GR::Arc</tt> as its 286 283 /// <tt>value_type</tt>. The algorithm copies the elements of the 287 284 /// found tree into this sequence. For example, if we know that the … … 294 291 /// Or if we don't know in advance the size of the tree, we can 295 292 /// write this. 296 ///\code 297 /// std::vector<Arc> tree; 293 ///\code std::vector<Arc> tree; 298 294 /// kruskal(g,cost,std::back_inserter(tree)); 299 295 ///\endcode 300 296 /// 301 /// \return The total cost of the found spanningtree.302 /// 303 /// \warning If Kruskal runs on an be consistent of using the same297 /// \return The total cost of the found tree. 298 /// 299 /// \warning If kruskal runs on an be consistent of using the same 304 300 /// Arc type for input and output. 305 301 /// -
lemon/lgf_reader.h
r201 r190 19 19 ///\ingroup lemon_io 20 20 ///\file 21 ///\brief \ref lgf-format "Lemon Graph Format"reader.21 ///\brief Lemon Graph Format reader. 22 22 23 23 … … 196 196 }; 197 197 198 inlinebool isWhiteSpace(char c) {198 bool isWhiteSpace(char c) { 199 199 return c == ' ' || c == '\t' || c == '\v' || 200 200 c == '\n' || c == '\r' || c == '\f'; 201 201 } 202 202 203 inlinebool isOct(char c) {203 bool isOct(char c) { 204 204 return '0' <= c && c <='7'; 205 205 } 206 206 207 in line int valueOct(char c) {207 int valueOct(char c) { 208 208 LEMON_ASSERT(isOct(c), "The character is not octal."); 209 209 return c - '0'; 210 210 } 211 211 212 inlinebool isHex(char c) {212 bool isHex(char c) { 213 213 return ('0' <= c && c <= '9') || 214 214 ('a' <= c && c <= 'z') || … … 216 216 } 217 217 218 in line int valueHex(char c) {218 int valueHex(char c) { 219 219 LEMON_ASSERT(isHex(c), "The character is not hexadecimal."); 220 220 if ('0' <= c && c <= '9') return c - '0'; … … 223 223 } 224 224 225 inlinebool isIdentifierFirstChar(char c) {225 bool isIdentifierFirstChar(char c) { 226 226 return ('a' <= c && c <= 'z') || 227 227 ('A' <= c && c <= 'Z') || c == '_'; 228 228 } 229 229 230 inlinebool isIdentifierChar(char c) {230 bool isIdentifierChar(char c) { 231 231 return isIdentifierFirstChar(c) || 232 232 ('0' <= c && c <= '9'); 233 233 } 234 234 235 inlinechar readEscape(std::istream& is) {235 char readEscape(std::istream& is) { 236 236 char c; 237 237 if (!is.get(c)) … … 285 285 } 286 286 287 inlinestd::istream& readToken(std::istream& is, std::string& str) {287 std::istream& readToken(std::istream& is, std::string& str) { 288 288 std::ostringstream os; 289 289 … … 401 401 /// \ingroup lemon_io 402 402 /// 403 /// \brief \ref lgf-format "LGF"reader for directed graphs403 /// \brief LGF reader for directed graphs 404 404 /// 405 405 /// This utility reads an \ref lgf-format "LGF" file. … … 411 411 /// with the \c nodeMap() or \c arcMap() members. An optional 412 412 /// converter parameter can also be added as a standard functor 413 /// converting from \cstd::string to the value type of the map. If it413 /// converting from std::string to the value type of the map. If it 414 414 /// 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, 416 416 /// then a default conversion will be used. One map can be read into 417 417 /// multiple map objects at the same time. The \c attribute(), \c … … 420 420 /// 421 421 ///\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(); 429 429 ///\endcode 430 430 /// … … 438 438 /// graph) during the reading, but instead the label map of the items 439 439 /// are given as a parameter of these functions. An 440 /// application of these function sis multipass reading, which is441 /// important if two \ c\@arcs sections must be read from the442 /// file. In this case the first phase would read the node set and one440 /// 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 443 443 /// of the arc sets, while the second phase would read the second arc 444 444 /// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet). 445 445 /// The previously read label node map should be passed to the \c 446 446 /// useNodes() functions. Another application of multipass reading when 447 /// paths are given as a node map or an arc map. It is impossible toread this in447 /// paths are given as a node map or an arc map. It is impossible read this in 448 448 /// a single pass, because the arcs are not constructed when the node 449 449 /// maps are read. … … 736 736 /// Use previously constructed node set, and specify the node 737 737 /// label map and a functor which converts the label map values to 738 /// \cstd::string.738 /// std::string. 739 739 template <typename Map, typename Converter> 740 740 DigraphReader& useNodes(const Map& map, … … 769 769 /// Use previously constructed arc set, and specify the arc 770 770 /// label map and a functor which converts the label map values to 771 /// \cstd::string.771 /// std::string. 772 772 template <typename Map, typename Converter> 773 773 DigraphReader& useArcs(const Map& map, … … 785 785 /// 786 786 /// Omit the reading of the node section. This implies that each node 787 /// map reading rule will be aban doned, and the nodes of the graph787 /// map reading rule will be abanoned, and the nodes of the graph 788 788 /// 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. 792 793 DigraphReader& skipNodes() { 793 794 LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); … … 799 800 /// 800 801 /// Omit the reading of the arc section. This implies that each arc 801 /// map reading rule will be aban doned, and the arcs of the graph802 /// map reading rule will be abanoned, and the arcs of the graph 802 803 /// will not be constructed. 803 804 DigraphReader& skipArcs() { … … 1175 1176 }; 1176 1177 1177 /// \brief Return a \ref DigraphReader class1178 ///1179 /// This function just returns a \ref DigraphReader class.1180 1178 /// \relates DigraphReader 1181 1179 template <typename Digraph> … … 1185 1183 } 1186 1184 1187 /// \brief Return a \ref DigraphReader class1188 ///1189 /// This function just returns a \ref DigraphReader class.1190 1185 /// \relates DigraphReader 1191 1186 template <typename Digraph> … … 1196 1191 } 1197 1192 1198 /// \brief Return a \ref DigraphReader class1199 ///1200 /// This function just returns a \ref DigraphReader class.1201 1193 /// \relates DigraphReader 1202 1194 template <typename Digraph> … … 1220 1212 /// \ingroup lemon_io 1221 1213 /// 1222 /// \brief \ref lgf-format "LGF"reader for undirected graphs1214 /// \brief LGF reader for undirected graphs 1223 1215 /// 1224 1216 /// 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 and1228 /// edge maps as well as arcs and arc maps.1229 ///1230 /// The columns in the \c \@edges (or \c \@arcs) section are the1231 /// edge maps. However, if there are two maps with the same name1232 /// prefixed with \c '+' and \c '-', then these can be read into an1233 /// arc map. Similarly, an attribute can be read into an arc, if1234 /// it's value is an edge label prefixed with \c '+' or \c '-'.1235 1217 template <typename _Graph> 1236 1218 class GraphReader { … … 1281 1263 /// \brief Constructor 1282 1264 /// 1283 /// Construct a nundirected graph reader, which reads from the given1265 /// Construct a undirected graph reader, which reads from the given 1284 1266 /// input stream. 1285 1267 GraphReader(std::istream& is, Graph& graph) … … 1290 1272 /// \brief Constructor 1291 1273 /// 1292 /// Construct a nundirected graph reader, which reads from the given1274 /// Construct a undirected graph reader, which reads from the given 1293 1275 /// file. 1294 1276 GraphReader(const std::string& fn, Graph& graph) … … 1299 1281 /// \brief Constructor 1300 1282 /// 1301 /// Construct a nundirected graph reader, which reads from the given1283 /// Construct a undirected graph reader, which reads from the given 1302 1284 /// file. 1303 1285 GraphReader(const char* fn, Graph& graph) … … 1516 1498 /// \brief Set \c \@nodes section to be read 1517 1499 /// 1518 /// Set \c \@nodes section to be read .1500 /// Set \c \@nodes section to be read 1519 1501 GraphReader& nodes(const std::string& caption) { 1520 1502 _nodes_caption = caption; … … 1524 1506 /// \brief Set \c \@edges section to be read 1525 1507 /// 1526 /// Set \c \@edges section to be read .1508 /// Set \c \@edges section to be read 1527 1509 GraphReader& edges(const std::string& caption) { 1528 1510 _edges_caption = caption; … … 1532 1514 /// \brief Set \c \@attributes section to be read 1533 1515 /// 1534 /// Set \c \@attributes section to be read .1516 /// Set \c \@attributes section to be read 1535 1517 GraphReader& attributes(const std::string& caption) { 1536 1518 _attributes_caption = caption; … … 1563 1545 /// Use previously constructed node set, and specify the node 1564 1546 /// label map and a functor which converts the label map values to 1565 /// \cstd::string.1547 /// std::string. 1566 1548 template <typename Map, typename Converter> 1567 1549 GraphReader& useNodes(const Map& map, … … 1596 1578 /// Use previously constructed edge set, and specify the edge 1597 1579 /// label map and a functor which converts the label map values to 1598 /// \cstd::string.1580 /// std::string. 1599 1581 template <typename Map, typename Converter> 1600 1582 GraphReader& useEdges(const Map& map, … … 1609 1591 } 1610 1592 1611 /// \brief Skip the reading of node section1593 /// \brief Skips the reading of node section 1612 1594 /// 1613 1595 /// Omit the reading of the node section. This implies that each node 1614 /// map reading rule will be aban doned, and the nodes of the graph1596 /// map reading rule will be abanoned, and the nodes of the graph 1615 1597 /// will not be constructed, which usually cause that the edge set 1616 1598 /// 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, or1619 /// \c useNodes() should be used to specify thelabel 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. 1620 1602 GraphReader& skipNodes() { 1621 1603 LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); … … 1624 1606 } 1625 1607 1626 /// \brief Skip the reading of edge section1608 /// \brief Skips the reading of edge section 1627 1609 /// 1628 1610 /// Omit the reading of the edge section. This implies that each edge 1629 /// map reading rule will be aban doned, and the edges of the graph1611 /// map reading rule will be abanoned, and the edges of the graph 1630 1612 /// will not be constructed. 1631 1613 GraphReader& skipEdges() { … … 2001 1983 }; 2002 1984 2003 /// \brief Return a \ref GraphReader class2004 ///2005 /// This function just returns a \ref GraphReader class.2006 1985 /// \relates GraphReader 2007 1986 template <typename Graph> … … 2011 1990 } 2012 1991 2013 /// \brief Return a \ref GraphReader class2014 ///2015 /// This function just returns a \ref GraphReader class.2016 1992 /// \relates GraphReader 2017 1993 template <typename Graph> … … 2022 1998 } 2023 1999 2024 /// \brief Return a \ref GraphReader class2025 ///2026 /// This function just returns a \ref GraphReader class.2027 2000 /// \relates GraphReader 2028 2001 template <typename Graph> … … 2038 2011 SectionReader sectionReader(const char* fn); 2039 2012 2040 /// \ingroup lemon_io2041 ///2042 2013 /// \brief Section reader class 2043 2014 /// 2044 /// In the \ ref lgf-format "LGF" file extra sections can be placed,2045 /// which contain any data in arbitrary format. Such sections can be2046 /// read with this class. A reading rule can be added to the class2047 /// with two different functions. With the \c sectionLines() function a2048 /// functor can process the section line-by-line, while with the \c2015 /// 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 2049 2020 /// sectionStream() member the section can be read from an input 2050 2021 /// stream. … … 2135 2106 ///\endcode 2136 2107 /// 2137 /// The functor is implemented as a struct:2108 /// The functor is implemented as an struct: 2138 2109 ///\code 2139 2110 /// struct NumberSection { … … 2153 2124 template <typename Functor> 2154 2125 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."); 2156 2127 LEMON_ASSERT(_sections.find(type) == _sections.end(), 2157 2128 "Multiple reading of section."); … … 2165 2136 /// 2166 2137 /// The first parameter is the type of the section, the second is 2167 /// a functor, which takes an \c std::istream& and an \cint&2138 /// a functor, which takes an \c std::istream& and an int& 2168 2139 /// parameter, the latter regard to the line number of stream. The 2169 2140 /// functor can read the input while the section go on, and the … … 2171 2142 template <typename Functor> 2172 2143 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."); 2174 2145 LEMON_ASSERT(_sections.find(type) == _sections.end(), 2175 2146 "Multiple reading of section."); … … 2216 2187 /// \brief Start the batch processing 2217 2188 /// 2218 /// This function starts the batch processing .2189 /// This function starts the batch processing 2219 2190 void run() { 2220 2191 … … 2269 2240 }; 2270 2241 2271 /// \brief Return a \ref SectionReader class2272 ///2273 /// This function just returns a \ref SectionReader class.2274 2242 /// \relates SectionReader 2275 2243 inline SectionReader sectionReader(std::istream& is) { … … 2278 2246 } 2279 2247 2280 /// \brief Return a \ref SectionReader class2281 ///2282 /// This function just returns a \ref SectionReader class.2283 2248 /// \relates SectionReader 2284 2249 inline SectionReader sectionReader(const std::string& fn) { … … 2287 2252 } 2288 2253 2289 /// \brief Return a \ref SectionReader class2290 ///2291 /// This function just returns a \ref SectionReader class.2292 2254 /// \relates SectionReader 2293 2255 inline SectionReader sectionReader(const char* fn) { … … 2308 2270 /// reading the graph. 2309 2271 /// 2310 ///\code 2311 /// LgfContents contents("graph.lgf"); 2272 ///\code LgfContents contents("graph.lgf"); 2312 2273 /// contents.run(); 2313 2274 /// 2314 /// // Does it contain any node section and arc section?2275 /// // does it contain any node section and arc section 2315 2276 /// if (contents.nodeSectionNum() == 0 || contents.arcSectionNum()) { 2316 /// std::cerr << "Failure, cannot find graph ." << std::endl;2277 /// std::cerr << "Failure, cannot find graph" << std::endl; 2317 2278 /// return -1; 2318 2279 /// } 2319 /// std::cout << "The name of the default node section : "2280 /// std::cout << "The name of the default node section : " 2320 2281 /// << contents.nodeSection(0) << std::endl; 2321 /// std::cout << "The number of the arc maps : "2282 /// std::cout << "The number of the arc maps : " 2322 2283 /// << contents.arcMaps(0).size() << std::endl; 2323 /// std::cout << "The name of second arc map : "2284 /// std::cout << "The name of second arc map : " 2324 2285 /// << contents.arcMaps(0)[1] << std::endl; 2325 2286 ///\endcode … … 2392 2353 } 2393 2354 2394 /// \brief Returns the nodesection name at the given position.2395 /// 2396 /// Returns the nodesection 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. 2397 2358 const std::string& nodeSection(int i) const { 2398 2359 return _node_sections[i]; … … 2419 2380 } 2420 2381 2421 /// \brief Returns the arc/edgesection name at the given position.2422 /// 2423 /// Returns the arc/edgesection 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. 2424 2385 /// \note It is synonym of \c edgeSection(). 2425 2386 const std::string& arcSection(int i) const { … … 2476 2437 } 2477 2438 2478 /// \brief Returns the attributesection name at the given position.2479 /// 2480 /// Returns the attributesection 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. 2481 2442 const std::string& attributeSectionNames(int i) const { 2482 2443 return _attribute_sections[i]; … … 2569 2530 /// @{ 2570 2531 2571 /// \brief Start sthe reading2572 /// 2573 /// This function starts the reading .2532 /// \brief Start the reading 2533 /// 2534 /// This function starts the reading 2574 2535 void run() { 2575 2536 -
lemon/lgf_writer.h
r201 r190 19 19 ///\ingroup lemon_io 20 20 ///\file 21 ///\brief \ref lgf-format "Lemon Graph Format"writer.21 ///\brief Lemon Graph Format writer. 22 22 23 23 … … 226 226 }; 227 227 228 inlinebool isWhiteSpace(char c) {228 bool isWhiteSpace(char c) { 229 229 return c == ' ' || c == '\t' || c == '\v' || 230 230 c == '\n' || c == '\r' || c == '\f'; 231 231 } 232 232 233 inlinebool isEscaped(char c) {233 bool isEscaped(char c) { 234 234 return c == '\\' || c == '\"' || c == '\'' || 235 235 c == '\a' || c == '\b'; 236 236 } 237 237 238 inlinestatic void writeEscape(std::ostream& os, char c) {238 static void writeEscape(std::ostream& os, char c) { 239 239 switch (c) { 240 240 case '\\': … … 277 277 } 278 278 279 inlinebool requireEscape(const std::string& str) {279 bool requireEscape(const std::string& str) { 280 280 if (str.empty() || str[0] == '@') return true; 281 281 std::istringstream is(str); … … 289 289 } 290 290 291 inlinestd::ostream& writeToken(std::ostream& os, const std::string& str) {291 std::ostream& writeToken(std::ostream& os, const std::string& str) { 292 292 293 293 if (requireEscape(str)) { … … 323 323 /// \ingroup lemon_io 324 324 /// 325 /// \brief \ref lgf-format "LGF"writer for directed graphs325 /// \brief LGF writer for directed graphs 326 326 /// 327 327 /// This utility writes an \ref lgf-format "LGF" file. … … 333 333 /// with the \c nodeMap() or \c arcMap() members. An optional 334 334 /// converter parameter can also be added as a standard functor 335 /// converting from the value type of the map to \cstd::string. If it336 /// is set, it will determine how the value type of the mapis written to335 /// 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 337 337 /// the output stream. If the functor is not set, then a default 338 338 /// conversion will be used. The \c attribute(), \c node() and \c … … 340 340 /// 341 341 ///\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(); 351 351 ///\endcode 352 352 /// … … 487 487 /// @{ 488 488 489 /// \brief Node map writing rule490 /// 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. 492 492 template <typename Map> 493 493 DigraphWriter& nodeMap(const std::string& caption, const Map& map) { … … 587 587 } 588 588 589 /// \name Se ction captions589 /// \name Select section by name 590 590 /// @{ 591 591 592 /// \brief Add an additional caption to the \c \@nodes section593 /// 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 595 595 DigraphWriter& nodes(const std::string& caption) { 596 596 _nodes_caption = caption; … … 598 598 } 599 599 600 /// \brief Add an additional caption to the \c \@arcs section601 /// 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 603 603 DigraphWriter& arcs(const std::string& caption) { 604 604 _arcs_caption = caption; … … 606 606 } 607 607 608 /// \brief Add an additional caption to the \c \@attributes section609 /// 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 611 611 DigraphWriter& attributes(const std::string& caption) { 612 612 _attributes_caption = caption; … … 619 619 /// \brief Skip writing the node set 620 620 /// 621 /// The \c \@nodes section will not bewritten to the stream.621 /// The \c \@nodes section will be not written to the stream. 622 622 DigraphWriter& skipNodes() { 623 623 LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member"); … … 628 628 /// \brief Skip writing arc set 629 629 /// 630 /// The \c \@arcs section will not bewritten to the stream.630 /// The \c \@arcs section will be not written to the stream. 631 631 DigraphWriter& skipArcs() { 632 632 LEMON_ASSERT(!_skip_arcs, "Multiple usage of skipArcs() member"); … … 836 836 /// \brief Start the batch processing 837 837 /// 838 /// This function starts the batch processing .838 /// This function starts the batch processing 839 839 void run() { 840 840 if (!_skip_nodes) { … … 851 851 } 852 852 853 /// \brief Give back the stream of the writer854 /// 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 856 856 std::ostream& ostream() { 857 857 return *_os; … … 861 861 }; 862 862 863 /// \brief Return a \ref DigraphWriter class864 ///865 /// This function just returns a \ref DigraphWriter class.866 863 /// \relates DigraphWriter 867 864 template <typename Digraph> … … 872 869 } 873 870 874 /// \brief Return a \ref DigraphWriter class875 ///876 /// This function just returns a \ref DigraphWriter class.877 871 /// \relates DigraphWriter 878 872 template <typename Digraph> … … 883 877 } 884 878 885 /// \brief Return a \ref DigraphWriter class886 ///887 /// This function just returns a \ref DigraphWriter class.888 879 /// \relates DigraphWriter 889 880 template <typename Digraph> … … 908 899 /// \ingroup lemon_io 909 900 /// 910 /// \brief \ref lgf-format "LGF"writer for directed graphs901 /// \brief LGF writer for directed graphs 911 902 /// 912 903 /// 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 and916 /// edge maps as well as arcs and arc maps.917 ///918 /// The arc maps are written into the file as two columns, the919 /// caption of the columns are the name of the map prefixed with \c920 /// '+' and \c '-'. The arcs are written into the \c \@attributes921 /// section as a \c '+' or a \c '-' prefix (depends on the direction922 /// of the arc) and the label of corresponding edge.923 904 template <typename _Graph> 924 905 class GraphWriter { … … 1043 1024 /// @{ 1044 1025 1045 /// \brief Node map writing rule1046 /// 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. 1048 1029 template <typename Map> 1049 1030 GraphWriter& nodeMap(const std::string& caption, const Map& map) { … … 1189 1170 } 1190 1171 1191 /// \name Se ction captions1172 /// \name Select section by name 1192 1173 /// @{ 1193 1174 1194 /// \brief Add an additional caption to the \c \@nodes section1195 /// 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 1197 1178 GraphWriter& nodes(const std::string& caption) { 1198 1179 _nodes_caption = caption; … … 1200 1181 } 1201 1182 1202 /// \brief Add an additional caption to the \c \@arcs section1203 /// 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 1205 1186 GraphWriter& edges(const std::string& caption) { 1206 1187 _edges_caption = caption; … … 1208 1189 } 1209 1190 1210 /// \brief Add an additional caption to the \c \@attributes section1211 /// 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 1213 1194 GraphWriter& attributes(const std::string& caption) { 1214 1195 _attributes_caption = caption; … … 1221 1202 /// \brief Skip writing the node set 1222 1203 /// 1223 /// The \c \@nodes section will not bewritten to the stream.1204 /// The \c \@nodes section will be not written to the stream. 1224 1205 GraphWriter& skipNodes() { 1225 1206 LEMON_ASSERT(!_skip_nodes, "Multiple usage of skipNodes() member"); … … 1230 1211 /// \brief Skip writing edge set 1231 1212 /// 1232 /// The \c \@edges section will not bewritten to the stream.1213 /// The \c \@edges section will be not written to the stream. 1233 1214 GraphWriter& skipEdges() { 1234 1215 LEMON_ASSERT(!_skip_edges, "Multiple usage of skipEdges() member"); … … 1438 1419 /// \brief Start the batch processing 1439 1420 /// 1440 /// This function starts the batch processing .1421 /// This function starts the batch processing 1441 1422 void run() { 1442 1423 if (!_skip_nodes) { … … 1453 1434 } 1454 1435 1455 /// \brief Give back the stream of the writer1456 /// 1457 /// Give back the stream of the writer1436 /// \brief Gives back the stream of the writer 1437 /// 1438 /// Gives back the stream of the writer 1458 1439 std::ostream& ostream() { 1459 1440 return *_os; … … 1463 1444 }; 1464 1445 1465 /// \brief Return a \ref GraphWriter class1466 ///1467 /// This function just returns a \ref GraphWriter class.1468 1446 /// \relates GraphWriter 1469 1447 template <typename Graph> … … 1473 1451 } 1474 1452 1475 /// \brief Return a \ref GraphWriter class1476 ///1477 /// This function just returns a \ref GraphWriter class.1478 1453 /// \relates GraphWriter 1479 1454 template <typename Graph> … … 1483 1458 } 1484 1459 1485 /// \brief Return a \ref GraphWriter class1486 ///1487 /// This function just returns a \ref GraphWriter class.1488 1460 /// \relates GraphWriter 1489 1461 template <typename Graph> -
test/CMakeLists.txt
r203 r171 11 11 dim_test 12 12 error_test 13 graph_copy_test14 13 graph_test 15 14 graph_utils_test 16 heap_test17 15 kruskal_test 18 16 maps_test -
test/Makefile.am
r203 r171 4 4 noinst_HEADERS += \ 5 5 test/graph_test.h \ 6 test/heap_test.h \ 6 7 test/graph_maps_test.h \ 7 8 test/test_tools.h … … 15 16 test/dim_test \ 16 17 test/error_test \ 17 test/graph_copy_test \18 18 test/graph_test \ 19 19 test/graph_utils_test \ 20 test/heap_test \21 20 test/kruskal_test \ 22 21 test/maps_test \ … … 38 37 test_dim_test_SOURCES = test/dim_test.cc 39 38 test_error_test_SOURCES = test/error_test.cc 40 test_graph_copy_test_SOURCES = test/graph_copy_test.cc41 39 test_graph_test_SOURCES = test/graph_test.cc 42 40 test_graph_utils_test_SOURCES = test/graph_utils_test.cc 43 test_heap_test_SOURCES = test/heap_test.cc41 # test_heap_test_SOURCES = test/heap_test.cc 44 42 test_kruskal_test_SOURCES = test/kruskal_test.cc 45 43 test_maps_test_SOURCES = test/maps_test.cc -
test/heap_test.cc
r203 r171 25 25 #include <lemon/concepts/heap.h> 26 26 27 #include <lemon/ smart_graph.h>27 #include <lemon/list_graph.h> 28 28 29 #include <lemon/lgf_reader.h> 30 #include <lemon/dijkstra.h> 31 #include <lemon/maps.h> 29 #include <lemon/digraph_reader.h> 32 30 33 31 #include <lemon/bin_heap.h> 32 #include <lemon/fib_heap.h> 33 #include <lemon/radix_heap.h> 34 #include <lemon/bucket_heap.h> 34 35 35 36 #include "test_tools.h" 36 37 38 #include "heap_test.h" 39 40 #include <lemon/time_measure.h> 41 37 42 using namespace lemon; 38 43 using 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 }158 44 159 45 int main() { … … 161 47 typedef int Item; 162 48 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"; 164 70 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). 173 76 run(); 174 77 175 78 { 79 std::cout << "Checking Bin Heap" << std::endl; 80 176 81 typedef BinHeap<Prio, ItemIntMap> IntHeap; 177 82 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); 178 heapSortTest<IntHeap>( );179 heapIncreaseTest<IntHeap>( );83 heapSortTest<IntHeap>(100); 84 heapIncreaseTest<IntHeap>(100); 180 85 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; 184 134 } 185 135
Note: See TracChangeset
for help on using the changeset viewer.