author | marci |
Wed, 26 Jan 2005 15:54:06 +0000 | |
changeset 1097 | c91e765266d7 |
parent 316 | d9691d0102bd |
permissions | -rw-r--r-- |
marci@315 | 1 |
// -*- c++ -*- |
marci@315 | 2 |
//compile it with |
marci@315 | 3 |
//g++ -ansi -pedantic |
marci@315 | 4 |
//and with |
marci@315 | 5 |
//g++ |
marci@315 | 6 |
//I did with g++ ver 3.0.4, suse 8.0 |
marci@315 | 7 |
//If the template is removed from NodeMap, then it works well. |
marci@315 | 8 |
//athos@cs.elte.hu |
marci@315 | 9 |
//klao@cs.elte.hu |
marci@315 | 10 |
//marci@cs.elte.hu |
marci@315 | 11 |
|
marci@315 | 12 |
class ListGraph { |
marci@315 | 13 |
public: |
marci@315 | 14 |
ListGraph() { } |
marci@315 | 15 |
|
marci@315 | 16 |
template <typename T> class NodeMap { |
marci@315 | 17 |
const ListGraph& G; |
marci@315 | 18 |
public: |
marci@315 | 19 |
NodeMap(const ListGraph& _G) : G(_G) { } |
marci@315 | 20 |
}; |
marci@315 | 21 |
|
marci@315 | 22 |
}; |
marci@315 | 23 |
|
marci@315 | 24 |
template<typename Graph> class GraphWrapper { |
marci@315 | 25 |
protected: |
marci@315 | 26 |
Graph* graph; |
marci@315 | 27 |
public: |
marci@315 | 28 |
GraphWrapper(Graph& _graph) : graph(&_graph) { } |
marci@315 | 29 |
|
klao@383 | 30 |
template<typename T> class NodeMap : public Graph::template NodeMap<T> { |
klao@383 | 31 |
typedef typename Graph::template NodeMap<T> Parent; |
marci@315 | 32 |
public: |
marci@315 | 33 |
NodeMap(const GraphWrapper<Graph>& _G) : |
klao@383 | 34 |
Parent(*(_G.graph)) { } |
marci@315 | 35 |
}; |
marci@315 | 36 |
}; |
marci@315 | 37 |
|
marci@315 | 38 |
template<typename Graph> |
marci@315 | 39 |
class ResGraphWrapper : public GraphWrapper<Graph> { |
marci@315 | 40 |
public: |
marci@315 | 41 |
ResGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } |
marci@315 | 42 |
}; |
marci@315 | 43 |
|
marci@315 | 44 |
template <typename Graph> class MaxFlow { |
marci@315 | 45 |
const Graph* g; |
marci@315 | 46 |
typedef ResGraphWrapper<const Graph> ResGW; |
marci@315 | 47 |
public: |
marci@315 | 48 |
MaxFlow(const Graph& _g) : g(&_g) { } |
marci@315 | 49 |
void augmentOnShortestPath() { |
marci@315 | 50 |
ResGW res_graph(*g); |
klao@383 | 51 |
typename ResGW::template NodeMap<int> pred(res_graph); |
marci@315 | 52 |
} |
marci@315 | 53 |
}; |
marci@315 | 54 |
|
marci@315 | 55 |
int main(int, char **) { |
marci@315 | 56 |
ListGraph G; |
marci@315 | 57 |
MaxFlow<ListGraph> max_flow_test(G); |
marci@315 | 58 |
max_flow_test.augmentOnShortestPath(); |
marci@315 | 59 |
return 0; |
marci@315 | 60 |
} |