COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/marci/dimacs.h @ 180:95f0c5f3fc70

Last change on this file since 180:95f0c5f3fc70 was 180:95f0c5f3fc70, checked in by marci, 17 years ago

.

File size: 1.3 KB
RevLine 
[174]1// -*- c++ -*-
2#ifndef DIMACS_H
3#define DIMACS_H
4
5#include <iostream>
6#include <string>
7#include <vector>
8
9namespace hugo {
10
11  template<typename Graph, typename CapacityMap>
12  void readDimacsMaxFlow(std::istream& is, Graph &G, typename Graph::Node &s, typename Graph::Node &t, CapacityMap& capacity) {
13    G.clear();
14    int cap;
15    char d;
16    std::string problem;
17    char c;
18    int i, j;
19    std::string str;
20    int n, m;
[180]21    typename Graph::Edge e;
[174]22    std::vector<typename Graph::Node> nodes;
23    while (is>>c) {
24      switch (c) {
25      case 'c': //comment
26        getline(is, str);
27        break;
28//       case 't': //type
29//      getline(is, str);
30//      break;
31      case 'p': //problem definition
32        is >> problem >> n >> m;
33        getline(is, str);
34        nodes.resize(n+1);
35        for (int k=1; k<=n; ++k) nodes[k]=G.addNode();
36        break;
37      case 'n': //node definition
38        if (problem=="sp") { //shortest path problem
39          is >> i;
40          getline(is, str);
41          s=nodes[i];
42        }
43        if (problem=="max") { //max flow problem
44          is >> i >> d;
45          getline(is, str);
46          if (d=='s') s=nodes[i];
47          if (d=='t') t=nodes[i];
48        }
49        break;
50      case 'a':
51        is >> i >> j >> cap;
52        getline(is, str);
[180]53        e=G.addEdge(nodes[i], nodes[j]);
[174]54        capacity.update();
55        capacity.set(e, cap);
56        break;
57      }
58    }
59  }
60 
61} //namespace hugo
62
63#endif //DIMACS_H
Note: See TracBrowser for help on using the repository browser.