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