author | klao |
Thu, 26 Feb 2004 16:07:40 +0000 | |
changeset 132 | 1ac27e476e25 |
permissions | -rw-r--r-- |
jacint@131 | 1 |
#ifndef DIMACS_HH |
jacint@131 | 2 |
#define DIMACS_HH |
jacint@131 | 3 |
|
jacint@131 | 4 |
#include <iostream> |
jacint@131 | 5 |
#include <string> |
jacint@131 | 6 |
#include <vector> |
jacint@131 | 7 |
|
jacint@131 | 8 |
namespace hugo { |
jacint@131 | 9 |
|
jacint@131 | 10 |
template<typename Graph, typename CapacityMap> |
jacint@131 | 11 |
void readDimacsMaxFlow(std::istream& is, Graph &G, typename Graph::TrivNodeIt &s, typename Graph::TrivNodeIt &t, CapacityMap& capacity) { |
jacint@131 | 12 |
G.clear(); |
jacint@131 | 13 |
int cap; |
jacint@131 | 14 |
char d; |
jacint@131 | 15 |
std::string problem; |
jacint@131 | 16 |
char c; |
jacint@131 | 17 |
int i, j; |
jacint@131 | 18 |
std::string str; |
jacint@131 | 19 |
int n, m; |
jacint@131 | 20 |
std::vector<typename Graph::TrivNodeIt> nodes; |
jacint@131 | 21 |
while (is>>c) { |
jacint@131 | 22 |
switch (c) { |
jacint@131 | 23 |
case 'c': //comment |
jacint@131 | 24 |
getline(is, str); |
jacint@131 | 25 |
break; |
jacint@131 | 26 |
case 't': //type |
jacint@131 | 27 |
getline(is, str); |
jacint@131 | 28 |
break; |
jacint@131 | 29 |
case 'p': //problem definition |
jacint@131 | 30 |
is >> problem >> n >> m; |
jacint@131 | 31 |
getline(is, str); |
jacint@131 | 32 |
nodes.resize(n+1); |
jacint@131 | 33 |
for (int k=1; k<=n; ++k) nodes[k]=G.addNode(); |
jacint@131 | 34 |
break; |
jacint@131 | 35 |
case 'n': //node definition |
jacint@131 | 36 |
if (problem=="sp") { //shortest path problem |
jacint@131 | 37 |
is >> i; |
jacint@131 | 38 |
getline(is, str); |
jacint@131 | 39 |
s=nodes[i]; |
jacint@131 | 40 |
} |
jacint@131 | 41 |
if (problem=="max") { //max flow problem |
jacint@131 | 42 |
is >> i >> d; |
jacint@131 | 43 |
getline(is, str); |
jacint@131 | 44 |
if (d=='s') s=nodes[i]; |
jacint@131 | 45 |
if (d=='t') t=nodes[i]; |
jacint@131 | 46 |
} |
jacint@131 | 47 |
break; |
jacint@131 | 48 |
case 'a': |
jacint@131 | 49 |
is >> i >> j >> cap; |
jacint@131 | 50 |
getline(is, str); |
jacint@131 | 51 |
typename Graph::TrivEdgeIt e=G.addEdge(nodes[i], nodes[j]); |
jacint@131 | 52 |
capacity.update(); |
jacint@131 | 53 |
capacity.set(e, cap); |
jacint@131 | 54 |
break; |
jacint@131 | 55 |
} |
jacint@131 | 56 |
} |
jacint@131 | 57 |
} |
jacint@131 | 58 |
|
jacint@131 | 59 |
} //namespace marci |
jacint@131 | 60 |
|
jacint@131 | 61 |
#endif //DIMACS_HH |