# source:lemon-0.x/src/work/marci/dimacs.h@255:45107782cbca

Last change on this file since 255:45107782cbca was 206:47f62d789fe7, checked in by marci, 17 years ago

.

File size: 1.2 KB
Line
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;
21    typename Graph::Edge e;
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 'p': //problem definition
29        is >> problem >> n >> m;
30        getline(is, str);
31        nodes.resize(n+1);
32        for (int k=1; k<=n; ++k) nodes[k]=G.addNode();
33        break;
34      case 'n': //node definition
35        if (problem=="sp") { //shortest path problem
36          is >> i;
37          getline(is, str);
38          s=nodes[i];
39        }
40        if (problem=="max") { //max flow problem
41          is >> i >> d;
42          getline(is, str);
43          if (d=='s') s=nodes[i];
44          if (d=='t') t=nodes[i];
45        }
46        break;
47      case 'a':
48        is >> i >> j >> cap;
49        getline(is, str);