dimacs.hh goes to oldies
authormarci
Wed, 21 Apr 2004 17:14:59 +0000
changeset 364749a831c6a8f
parent 363 7a05119c121a
child 365 9ca84022df34
dimacs.hh goes to oldies
src/work/marci/dimacs.hh
src/work/marci/oldies/dimacs.hh
     1.1 --- a/src/work/marci/dimacs.hh	Wed Apr 21 16:22:50 2004 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,61 +0,0 @@
     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 hugo {
    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.update();
    1.56 -	capacity.set(e, cap);
    1.57 -	break;
    1.58 -      }
    1.59 -    }
    1.60 -  }
    1.61 -  
    1.62 -} //namespace hugo
    1.63 -
    1.64 -#endif //DIMACS_HH
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/marci/oldies/dimacs.hh	Wed Apr 21 17:14:59 2004 +0000
     2.3 @@ -0,0 +1,61 @@
     2.4 +#ifndef DIMACS_HH
     2.5 +#define DIMACS_HH
     2.6 +
     2.7 +#include <iostream>
     2.8 +#include <string>
     2.9 +#include <vector>
    2.10 +
    2.11 +namespace hugo {
    2.12 +
    2.13 +  template<typename Graph, typename CapacityMap>
    2.14 +  void readDimacsMaxFlow(std::istream& is, Graph &G, typename Graph::NodeIt &s, typename Graph::NodeIt &t, CapacityMap& capacity) {
    2.15 +    G.clear();
    2.16 +    int cap;
    2.17 +    char d;
    2.18 +    std::string problem;
    2.19 +    char c;
    2.20 +    int i, j;
    2.21 +    std::string str;
    2.22 +    int n, m; 
    2.23 +    std::vector<typename Graph::NodeIt> nodes;
    2.24 +    while (is>>c) {
    2.25 +      switch (c) {
    2.26 +      case 'c': //comment
    2.27 +	getline(is, str);
    2.28 +	break;
    2.29 +      case 't': //type
    2.30 +	getline(is, str);
    2.31 +	break;
    2.32 +      case 'p': //problem definition
    2.33 +	is >> problem >> n >> m;
    2.34 +	getline(is, str);
    2.35 +	nodes.resize(n+1);
    2.36 +	for (int k=1; k<=n; ++k) nodes[k]=G.addNode();
    2.37 +	break;
    2.38 +      case 'n': //node definition
    2.39 +	if (problem=="sp") { //shortest path problem
    2.40 +	  is >> i;
    2.41 +	  getline(is, str);
    2.42 +	  s=nodes[i];
    2.43 +	}
    2.44 +	if (problem=="max") { //max flow problem
    2.45 +	  is >> i >> d;
    2.46 +	  getline(is, str);
    2.47 +	  if (d=='s') s=nodes[i];
    2.48 +	  if (d=='t') t=nodes[i];
    2.49 +	}
    2.50 +	break;
    2.51 +      case 'a':
    2.52 +	is >> i >> j >> cap;
    2.53 +	getline(is, str);
    2.54 +	typename Graph::EdgeIt e=G.addEdge(nodes[i], nodes[j]);
    2.55 +	capacity.update();
    2.56 +	capacity.set(e, cap);
    2.57 +	break;
    2.58 +      }
    2.59 +    }
    2.60 +  }
    2.61 +  
    2.62 +} //namespace hugo
    2.63 +
    2.64 +#endif //DIMACS_HH