jacint@131: #ifndef DIMACS_HH jacint@131: #define DIMACS_HH jacint@131: jacint@131: #include jacint@131: #include jacint@131: #include jacint@131: jacint@131: namespace hugo { jacint@131: jacint@131: template jacint@131: void readDimacsMaxFlow(std::istream& is, Graph &G, typename Graph::TrivNodeIt &s, typename Graph::TrivNodeIt &t, CapacityMap& capacity) { jacint@131: G.clear(); jacint@131: int cap; jacint@131: char d; jacint@131: std::string problem; jacint@131: char c; jacint@131: int i, j; jacint@131: std::string str; jacint@131: int n, m; jacint@131: std::vector nodes; jacint@131: while (is>>c) { jacint@131: switch (c) { jacint@131: case 'c': //comment jacint@131: getline(is, str); jacint@131: break; jacint@131: case 't': //type jacint@131: getline(is, str); jacint@131: break; jacint@131: case 'p': //problem definition jacint@131: is >> problem >> n >> m; jacint@131: getline(is, str); jacint@131: nodes.resize(n+1); jacint@131: for (int k=1; k<=n; ++k) nodes[k]=G.addNode(); jacint@131: break; jacint@131: case 'n': //node definition jacint@131: if (problem=="sp") { //shortest path problem jacint@131: is >> i; jacint@131: getline(is, str); jacint@131: s=nodes[i]; jacint@131: } jacint@131: if (problem=="max") { //max flow problem jacint@131: is >> i >> d; jacint@131: getline(is, str); jacint@131: if (d=='s') s=nodes[i]; jacint@131: if (d=='t') t=nodes[i]; jacint@131: } jacint@131: break; jacint@131: case 'a': jacint@131: is >> i >> j >> cap; jacint@131: getline(is, str); jacint@131: typename Graph::TrivEdgeIt e=G.addEdge(nodes[i], nodes[j]); jacint@131: capacity.update(); jacint@131: capacity.set(e, cap); jacint@131: break; jacint@131: } jacint@131: } jacint@131: } jacint@131: jacint@131: } //namespace marci jacint@131: jacint@131: #endif //DIMACS_HH