Changeset 599:f63e87b9748e in lemon-1.2 for lemon/lgf_reader.h
- Timestamp:
- 04/21/09 11:34:49 (15 years ago)
- Branch:
- default
- Parents:
- 598:a3402913cffe (diff), 597:2ca0cdb5f366 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lgf_reader.h
r584 r599 102 102 }; 103 103 104 template <typename _G raph, bool _dir, typename _Map,104 template <typename _GR, bool _dir, typename _Map, 105 105 typename _Converter = DefaultConverter<typename _Map::Value> > 106 class GraphArcMapStorage : public MapStorageBase<typename _G raph::Edge> {106 class GraphArcMapStorage : public MapStorageBase<typename _GR::Edge> { 107 107 public: 108 108 typedef _Map Map; 109 109 typedef _Converter Converter; 110 typedef _G raph Graph;111 typedef typename G raph::Edge Item;110 typedef _GR GR; 111 typedef typename GR::Edge Item; 112 112 static const bool dir = _dir; 113 113 114 114 private: 115 const G raph& _graph;115 const GR& _graph; 116 116 Map& _map; 117 117 Converter _converter; 118 118 119 119 public: 120 GraphArcMapStorage(const G raph& graph, Map& map,120 GraphArcMapStorage(const GR& graph, Map& map, 121 121 const Converter& converter = Converter()) 122 122 : _graph(graph), _map(map), _converter(converter) {} … … 174 174 }; 175 175 176 template <typename G raph>176 template <typename GR> 177 177 struct GraphArcLookUpConverter { 178 const G raph& _graph;179 const std::map<std::string, typename G raph::Edge>& _map;180 181 GraphArcLookUpConverter(const G raph& graph,178 const GR& _graph; 179 const std::map<std::string, typename GR::Edge>& _map; 180 181 GraphArcLookUpConverter(const GR& graph, 182 182 const std::map<std::string, 183 typename G raph::Edge>& map)183 typename GR::Edge>& map) 184 184 : _graph(graph), _map(map) {} 185 185 186 typename G raph::Arc operator()(const std::string& str) {186 typename GR::Arc operator()(const std::string& str) { 187 187 if (str.empty() || (str[0] != '+' && str[0] != '-')) { 188 188 throw FormatError("Item must start with '+' or '-'"); 189 189 } 190 typename std::map<std::string, typename G raph::Edge>190 typename std::map<std::string, typename GR::Edge> 191 191 ::const_iterator it = _map.find(str.substr(1)); 192 192 if (it == _map.end()) { … … 388 388 } 389 389 390 template <typename D igraph>390 template <typename DGR> 391 391 class DigraphReader; 392 392 393 template <typename Digraph> 394 DigraphReader<Digraph> digraphReader(Digraph& digraph, 395 std::istream& is = std::cin); 396 template <typename Digraph> 397 DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn); 398 template <typename Digraph> 399 DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn); 393 template <typename TDGR> 394 DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is = std::cin); 395 template <typename TDGR> 396 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn); 397 template <typename TDGR> 398 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); 400 399 401 400 /// \ingroup lemon_io … … 420 419 /// 421 420 ///\code 422 /// DigraphReader<D igraph>(digraph, std::cin).421 /// DigraphReader<DGR>(digraph, std::cin). 423 422 /// nodeMap("coordinates", coord_map). 424 423 /// arcMap("capacity", cap_map). … … 449 448 /// a single pass, because the arcs are not constructed when the node 450 449 /// maps are read. 451 template <typename GR>450 template <typename DGR> 452 451 class DigraphReader { 453 452 public: 454 453 455 typedef GR Digraph;454 typedef DGR Digraph; 456 455 457 456 private: 458 457 459 TEMPLATE_DIGRAPH_TYPEDEFS(D igraph);458 TEMPLATE_DIGRAPH_TYPEDEFS(DGR); 460 459 461 460 std::istream* _is; … … 463 462 std::string _filename; 464 463 465 D igraph& _digraph;464 DGR& _digraph; 466 465 467 466 std::string _nodes_caption; … … 501 500 /// Construct a directed graph reader, which reads from the given 502 501 /// input stream. 503 DigraphReader(D igraph& digraph, std::istream& is = std::cin)502 DigraphReader(DGR& digraph, std::istream& is = std::cin) 504 503 : _is(&is), local_is(false), _digraph(digraph), 505 504 _use_nodes(false), _use_arcs(false), … … 510 509 /// Construct a directed graph reader, which reads from the given 511 510 /// file. 512 DigraphReader(D igraph& digraph, const std::string& fn)511 DigraphReader(DGR& digraph, const std::string& fn) 513 512 : _is(new std::ifstream(fn.c_str())), local_is(true), 514 513 _filename(fn), _digraph(digraph), … … 525 524 /// Construct a directed graph reader, which reads from the given 526 525 /// file. 527 DigraphReader(D igraph& digraph, const char* fn)526 DigraphReader(DGR& digraph, const char* fn) 528 527 : _is(new std::ifstream(fn)), local_is(true), 529 528 _filename(fn), _digraph(digraph), … … 561 560 private: 562 561 563 template <typename DGR>564 friend DigraphReader< DGR> digraphReader(DGR& digraph, std::istream& is);565 template <typename DGR>566 friend DigraphReader< DGR> digraphReader(DGR& digraph,567 const std::string& fn);568 template <typename DGR>569 friend DigraphReader< DGR> digraphReader(DGR& digraph, const char *fn);562 template <typename TDGR> 563 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is); 564 template <typename TDGR> 565 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, 566 const std::string& fn); 567 template <typename TDGR> 568 friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn); 570 569 571 570 DigraphReader(DigraphReader& other) … … 1189 1188 1190 1189 }; 1190 1191 /// \ingroup lemon_io 1192 /// 1193 /// \brief Return a \ref DigraphReader class 1194 /// 1195 /// This function just returns a \ref DigraphReader class. 1196 /// 1197 /// With this function a digraph can be read from an 1198 /// \ref lgf-format "LGF" file or input stream with several maps and 1199 /// attributes. For example, there is network flow problem on a 1200 /// digraph, i.e. a digraph with a \e capacity map on the arcs and 1201 /// \e source and \e target nodes. This digraph can be read with the 1202 /// following code: 1203 /// 1204 ///\code 1205 ///ListDigraph digraph; 1206 ///ListDigraph::ArcMap<int> cm(digraph); 1207 ///ListDigraph::Node src, trg; 1208 ///digraphReader(digraph, std::cin). 1209 /// arcMap("capacity", cap). 1210 /// node("source", src). 1211 /// node("target", trg). 1212 /// run(); 1213 ///\endcode 1214 /// 1215 /// For a complete documentation, please see the \ref DigraphReader 1216 /// class documentation. 1217 /// \warning Don't forget to put the \ref DigraphReader::run() "run()" 1218 /// to the end of the parameter list. 1219 /// \relates DigraphReader 1220 /// \sa digraphReader(TDGR& digraph, const std::string& fn) 1221 /// \sa digraphReader(TDGR& digraph, const char* fn) 1222 template <typename TDGR> 1223 DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is) { 1224 DigraphReader<TDGR> tmp(digraph, is); 1225 return tmp; 1226 } 1191 1227 1192 1228 /// \brief Return a \ref DigraphReader class … … 1194 1230 /// This function just returns a \ref DigraphReader class. 1195 1231 /// \relates DigraphReader 1196 template <typename Digraph> 1197 DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) { 1198 DigraphReader<Digraph> tmp(digraph, is); 1232 /// \sa digraphReader(TDGR& digraph, std::istream& is) 1233 template <typename TDGR> 1234 DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) { 1235 DigraphReader<TDGR> tmp(digraph, fn); 1199 1236 return tmp; 1200 1237 } … … 1204 1241 /// This function just returns a \ref DigraphReader class. 1205 1242 /// \relates DigraphReader 1206 template <typename Digraph>1207 DigraphReader<Digraph> digraphReader(Digraph& digraph,1208 const std::string&fn) {1209 DigraphReader< Digraph> tmp(digraph, fn);1243 /// \sa digraphReader(TDGR& digraph, std::istream& is) 1244 template <typename TDGR> 1245 DigraphReader<TDGR> digraphReader(TDGR& digraph, const char* fn) { 1246 DigraphReader<TDGR> tmp(digraph, fn); 1210 1247 return tmp; 1211 1248 } 1212 1249 1213 /// \brief Return a \ref DigraphReader class 1214 /// 1215 /// This function just returns a \ref DigraphReader class. 1216 /// \relates DigraphReader 1217 template <typename Digraph> 1218 DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) { 1219 DigraphReader<Digraph> tmp(digraph, fn); 1220 return tmp; 1221 } 1222 1223 template <typename Graph> 1250 template <typename GR> 1224 1251 class GraphReader; 1225 1252 1226 template <typename Graph> 1227 GraphReader<Graph> graphReader(Graph& graph, 1228 std::istream& is = std::cin); 1229 template <typename Graph> 1230 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn); 1231 template <typename Graph> 1232 GraphReader<Graph> graphReader(Graph& graph, const char *fn); 1253 template <typename TGR> 1254 GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin); 1255 template <typename TGR> 1256 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); 1257 template <typename TGR> 1258 GraphReader<TGR> graphReader(TGR& graph, const char *fn); 1233 1259 1234 1260 /// \ingroup lemon_io … … 1255 1281 private: 1256 1282 1257 TEMPLATE_GRAPH_TYPEDEFS(G raph);1283 TEMPLATE_GRAPH_TYPEDEFS(GR); 1258 1284 1259 1285 std::istream* _is; … … 1261 1287 std::string _filename; 1262 1288 1263 G raph& _graph;1289 GR& _graph; 1264 1290 1265 1291 std::string _nodes_caption; … … 1299 1325 /// Construct an undirected graph reader, which reads from the given 1300 1326 /// input stream. 1301 GraphReader(G raph& graph, std::istream& is = std::cin)1327 GraphReader(GR& graph, std::istream& is = std::cin) 1302 1328 : _is(&is), local_is(false), _graph(graph), 1303 1329 _use_nodes(false), _use_edges(false), … … 1308 1334 /// Construct an undirected graph reader, which reads from the given 1309 1335 /// file. 1310 GraphReader(G raph& graph, const std::string& fn)1336 GraphReader(GR& graph, const std::string& fn) 1311 1337 : _is(new std::ifstream(fn.c_str())), local_is(true), 1312 1338 _filename(fn), _graph(graph), … … 1323 1349 /// Construct an undirected graph reader, which reads from the given 1324 1350 /// file. 1325 GraphReader(G raph& graph, const char* fn)1351 GraphReader(GR& graph, const char* fn) 1326 1352 : _is(new std::ifstream(fn)), local_is(true), 1327 1353 _filename(fn), _graph(graph), … … 1358 1384 1359 1385 private: 1360 template <typename Graph>1361 friend GraphReader< Graph> graphReader(Graph& graph, std::istream& is);1362 template <typename Graph>1363 friend GraphReader< Graph> graphReader(Graph& graph, const std::string& fn);1364 template <typename Graph>1365 friend GraphReader< Graph> graphReader(Graph& graph, const char *fn);1386 template <typename TGR> 1387 friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is); 1388 template <typename TGR> 1389 friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn); 1390 template <typename TGR> 1391 friend GraphReader<TGR> graphReader(TGR& graph, const char *fn); 1366 1392 1367 1393 GraphReader(GraphReader& other) … … 1455 1481 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1456 1482 _reader_bits::MapStorageBase<Edge>* backward_storage = 1457 new _reader_bits::GraphArcMapStorage<G raph, false, Map>(_graph, map);1483 new _reader_bits::GraphArcMapStorage<GR, false, Map>(_graph, map); 1458 1484 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); 1459 1485 return *this; … … 1469 1495 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); 1470 1496 _reader_bits::MapStorageBase<Edge>* forward_storage = 1471 new _reader_bits::GraphArcMapStorage<G raph, true, Map, Converter>1497 new _reader_bits::GraphArcMapStorage<GR, true, Map, Converter> 1472 1498 (_graph, map, converter); 1473 1499 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); 1474 1500 _reader_bits::MapStorageBase<Edge>* backward_storage = 1475 new _reader_bits::GraphArcMapStorage<G raph, false, Map, Converter>1501 new _reader_bits::GraphArcMapStorage<GR, false, Map, Converter> 1476 1502 (_graph, map, converter); 1477 1503 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); … … 1531 1557 /// Add an arc reading rule to reader. 1532 1558 GraphReader& arc(const std::string& caption, Arc& arc) { 1533 typedef _reader_bits::GraphArcLookUpConverter<G raph> Converter;1559 typedef _reader_bits::GraphArcLookUpConverter<GR> Converter; 1534 1560 Converter converter(_graph, _edge_index); 1535 1561 _reader_bits::ValueStorageBase* storage = … … 2034 2060 }; 2035 2061 2062 /// \ingroup lemon_io 2063 /// 2064 /// \brief Return a \ref GraphReader class 2065 /// 2066 /// This function just returns a \ref GraphReader class. 2067 /// 2068 /// With this function a graph can be read from an 2069 /// \ref lgf-format "LGF" file or input stream with several maps and 2070 /// attributes. For example, there is weighted matching problem on a 2071 /// graph, i.e. a graph with a \e weight map on the edges. This 2072 /// graph can be read with the following code: 2073 /// 2074 ///\code 2075 ///ListGraph graph; 2076 ///ListGraph::EdgeMap<int> weight(graph); 2077 ///graphReader(graph, std::cin). 2078 /// edgeMap("weight", weight). 2079 /// run(); 2080 ///\endcode 2081 /// 2082 /// For a complete documentation, please see the \ref GraphReader 2083 /// class documentation. 2084 /// \warning Don't forget to put the \ref GraphReader::run() "run()" 2085 /// to the end of the parameter list. 2086 /// \relates GraphReader 2087 /// \sa graphReader(TGR& graph, const std::string& fn) 2088 /// \sa graphReader(TGR& graph, const char* fn) 2089 template <typename TGR> 2090 GraphReader<TGR> graphReader(TGR& graph, std::istream& is) { 2091 GraphReader<TGR> tmp(graph, is); 2092 return tmp; 2093 } 2094 2036 2095 /// \brief Return a \ref GraphReader class 2037 2096 /// 2038 2097 /// This function just returns a \ref GraphReader class. 2039 2098 /// \relates GraphReader 2040 template <typename Graph> 2041 GraphReader<Graph> graphReader(Graph& graph, std::istream& is) { 2042 GraphReader<Graph> tmp(graph, is); 2099 /// \sa graphReader(TGR& graph, std::istream& is) 2100 template <typename TGR> 2101 GraphReader<TGR> graphReader(TGR& graph, const std::string& fn) { 2102 GraphReader<TGR> tmp(graph, fn); 2043 2103 return tmp; 2044 2104 } … … 2048 2108 /// This function just returns a \ref GraphReader class. 2049 2109 /// \relates GraphReader 2050 template <typename Graph> 2051 GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) { 2052 GraphReader<Graph> tmp(graph, fn); 2053 return tmp; 2054 } 2055 2056 /// \brief Return a \ref GraphReader class 2057 /// 2058 /// This function just returns a \ref GraphReader class. 2059 /// \relates GraphReader 2060 template <typename Graph> 2061 GraphReader<Graph> graphReader(Graph& graph, const char* fn) { 2062 GraphReader<Graph> tmp(graph, fn); 2110 /// \sa graphReader(TGR& graph, std::istream& is) 2111 template <typename TGR> 2112 GraphReader<TGR> graphReader(TGR& graph, const char* fn) { 2113 GraphReader<TGR> tmp(graph, fn); 2063 2114 return tmp; 2064 2115 } … … 2317 2368 }; 2318 2369 2370 /// \ingroup lemon_io 2371 /// 2319 2372 /// \brief Return a \ref SectionReader class 2320 2373 /// 2321 2374 /// This function just returns a \ref SectionReader class. 2375 /// 2376 /// Please see SectionReader documentation about the custom section 2377 /// input. 2378 /// 2322 2379 /// \relates SectionReader 2380 /// \sa sectionReader(const std::string& fn) 2381 /// \sa sectionReader(const char *fn) 2323 2382 inline SectionReader sectionReader(std::istream& is) { 2324 2383 SectionReader tmp(is); … … 2330 2389 /// This function just returns a \ref SectionReader class. 2331 2390 /// \relates SectionReader 2391 /// \sa sectionReader(std::istream& is) 2332 2392 inline SectionReader sectionReader(const std::string& fn) { 2333 2393 SectionReader tmp(fn); … … 2339 2399 /// This function just returns a \ref SectionReader class. 2340 2400 /// \relates SectionReader 2401 /// \sa sectionReader(std::istream& is) 2341 2402 inline SectionReader sectionReader(const char* fn) { 2342 2403 SectionReader tmp(fn); -
lemon/lgf_reader.h
r598 r599 593 593 public: 594 594 595 /// \name Reading rules595 /// \name Reading Rules 596 596 /// @{ 597 597 … … 698 698 /// @} 699 699 700 /// \name Select section by name700 /// \name Select Section by Name 701 701 /// @{ 702 702 … … 727 727 /// @} 728 728 729 /// \name Using previously constructed node or arc set729 /// \name Using Previously Constructed Node or Arc Set 730 730 /// @{ 731 731 … … 1116 1116 public: 1117 1117 1118 /// \name Execution of the reader1118 /// \name Execution of the Reader 1119 1119 /// @{ 1120 1120 … … 1416 1416 public: 1417 1417 1418 /// \name Reading rules1418 /// \name Reading Rules 1419 1419 /// @{ 1420 1420 … … 1567 1567 /// @} 1568 1568 1569 /// \name Select section by name1569 /// \name Select Section by Name 1570 1570 /// @{ 1571 1571 … … 1596 1596 /// @} 1597 1597 1598 /// \name Using previously constructed node or edge set1598 /// \name Using Previously Constructed Node or Edge Set 1599 1599 /// @{ 1600 1600 … … 1986 1986 public: 1987 1987 1988 /// \name Execution of the reader1988 /// \name Execution of the Reader 1989 1989 /// @{ 1990 1990 … … 2210 2210 public: 2211 2211 2212 /// \name Section readers2212 /// \name Section Readers 2213 2213 /// @{ 2214 2214 … … 2309 2309 2310 2310 2311 /// \name Execution of the reader2311 /// \name Execution of the Reader 2312 2312 /// @{ 2313 2313 … … 2501 2501 2502 2502 2503 /// \name Node sections2503 /// \name Node Sections 2504 2504 /// @{ 2505 2505 … … 2527 2527 /// @} 2528 2528 2529 /// \name Arc/Edge sections2529 /// \name Arc/Edge Sections 2530 2530 /// @{ 2531 2531 … … 2585 2585 /// @} 2586 2586 2587 /// \name Attribute sections2587 /// \name Attribute Sections 2588 2588 /// @{ 2589 2589 … … 2611 2611 /// @} 2612 2612 2613 /// \name Extra sections2613 /// \name Extra Sections 2614 2614 /// @{ 2615 2615 … … 2687 2687 public: 2688 2688 2689 /// \name Execution of the contents reader2689 /// \name Execution of the Contents Reader 2690 2690 /// @{ 2691 2691
Note: See TracChangeset
for help on using the changeset viewer.