1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/marci/dimacs.hh Mon Feb 09 13:11:10 2004 +0000
1.3 @@ -0,0 +1,61 @@
1.4 +#ifndef DIMACS_HH
1.5 +#define DIMACS_HH
1.6 +
1.7 +#include <iostream>
1.8 +#include <string>
1.9 +#include <vector>
1.10 +
1.11 +namespace marci {
1.12 +
1.13 + template<typename Graph, typename CapacityMap>
1.14 + void readDimacsMaxFlow(std::istream& is, Graph &G, typename Graph::NodeIt &s, typename Graph::NodeIt &t, CapacityMap& capacity) {
1.15 + G.clear();
1.16 + int cap;
1.17 + char d;
1.18 + std::string problem;
1.19 + char c;
1.20 + int i, j;
1.21 + std::string str;
1.22 + int n, m;
1.23 + std::vector<typename Graph::NodeIt> nodes;
1.24 + while (is>>c) {
1.25 + switch (c) {
1.26 + case 'c': //comment
1.27 + getline(is, str);
1.28 + break;
1.29 + case 't': //type
1.30 + getline(is, str);
1.31 + break;
1.32 + case 'p': //problem definition
1.33 + is >> problem >> n >> m;
1.34 + getline(is, str);
1.35 + nodes.resize(n+1);
1.36 + for (int k=1; k<=n; ++k) nodes[k]=G.addNode();
1.37 + break;
1.38 + case 'n': //node definition
1.39 + if (problem=="sp") { //shortest path problem
1.40 + is >> i;
1.41 + getline(is, str);
1.42 + s=nodes[i];
1.43 + }
1.44 + if (problem=="max") { //max flow problem
1.45 + is >> i >> d;
1.46 + getline(is, str);
1.47 + if (d=='s') s=nodes[i];
1.48 + if (d=='t') t=nodes[i];
1.49 + }
1.50 + break;
1.51 + case 'a':
1.52 + is >> i >> j >> cap;
1.53 + getline(is, str);
1.54 + typename Graph::EdgeIt e=G.addEdge(nodes[i], nodes[j]);
1.55 + capacity.resize();
1.56 + capacity.set(e, cap);
1.57 + break;
1.58 + }
1.59 + }
1.60 + }
1.61 +
1.62 +} //namespace marci
1.63 +
1.64 +#endif //DIMACS_HH