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