marci@174
|
1 |
// -*- c++ -*-
|
marci@76
|
2 |
#ifndef GRAPH_WRAPPER_H
|
marci@76
|
3 |
#define GRAPH_WRAPPER_H
|
marci@76
|
4 |
|
marci@174
|
5 |
#include <invalid.h>
|
marci@174
|
6 |
|
alpar@105
|
7 |
namespace hugo {
|
marci@76
|
8 |
|
marci@76
|
9 |
template<typename Graph>
|
marci@76
|
10 |
class TrivGraphWrapper {
|
marci@199
|
11 |
protected:
|
marci@76
|
12 |
Graph* graph;
|
marci@76
|
13 |
|
marci@76
|
14 |
public:
|
marci@76
|
15 |
typedef Graph BaseGraph;
|
marci@76
|
16 |
|
marci@174
|
17 |
typedef typename Graph::Node Node;
|
marci@76
|
18 |
typedef typename Graph::NodeIt NodeIt;
|
marci@76
|
19 |
|
marci@174
|
20 |
typedef typename Graph::Edge Edge;
|
marci@76
|
21 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
marci@76
|
22 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
marci@155
|
23 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
24 |
typedef typename Graph::EdgeIt EdgeIt;
|
marci@168
|
25 |
|
marci@168
|
26 |
//TrivGraphWrapper() : graph(0) { }
|
marci@168
|
27 |
TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@168
|
28 |
|
marci@168
|
29 |
void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@168
|
30 |
Graph& getGraph() const { return (*graph); }
|
marci@76
|
31 |
|
marci@212
|
32 |
template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@212
|
33 |
template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
34 |
return graph->first(i, p); }
|
marci@155
|
35 |
|
marci@155
|
36 |
template<typename I> I getNext(const I& i) const {
|
marci@155
|
37 |
return graph->getNext(i); }
|
marci@155
|
38 |
template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@76
|
39 |
|
marci@76
|
40 |
template< typename It > It first() const {
|
marci@212
|
41 |
It e; first(e); return e; }
|
marci@76
|
42 |
|
marci@174
|
43 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
44 |
It e; first(e, v); return e; }
|
marci@76
|
45 |
|
marci@174
|
46 |
Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
47 |
Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@155
|
48 |
|
marci@155
|
49 |
template<typename I> bool valid(const I& i) const
|
marci@155
|
50 |
{ return graph->valid(i); }
|
marci@155
|
51 |
|
marci@155
|
52 |
//template<typename I> void setInvalid(const I &i);
|
marci@155
|
53 |
//{ return graph->setInvalid(i); }
|
marci@155
|
54 |
|
marci@155
|
55 |
int nodeNum() const { return graph->nodeNum(); }
|
marci@155
|
56 |
int edgeNum() const { return graph->edgeNum(); }
|
marci@76
|
57 |
|
marci@174
|
58 |
template<typename I> Node aNode(const I& e) const {
|
marci@76
|
59 |
return graph->aNode(e); }
|
marci@174
|
60 |
template<typename I> Node bNode(const I& e) const {
|
marci@76
|
61 |
return graph->bNode(e); }
|
marci@76
|
62 |
|
marci@174
|
63 |
Node addNode() const { return graph->addNode(); }
|
marci@174
|
64 |
Edge addEdge(const Node& tail, const Node& head) const {
|
marci@76
|
65 |
return graph->addEdge(tail, head); }
|
marci@76
|
66 |
|
marci@76
|
67 |
template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@76
|
68 |
|
marci@76
|
69 |
void clear() const { graph->clear(); }
|
marci@155
|
70 |
|
marci@76
|
71 |
template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@76
|
72 |
public:
|
marci@155
|
73 |
NodeMap(const TrivGraphWrapper<Graph>& _G) :
|
marci@158
|
74 |
Graph::NodeMap<T>(_G.getGraph()) { }
|
marci@155
|
75 |
NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
|
marci@158
|
76 |
Graph::NodeMap<T>(_G.getGraph(), a) { }
|
marci@76
|
77 |
};
|
marci@168
|
78 |
|
marci@155
|
79 |
template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@155
|
80 |
public:
|
marci@155
|
81 |
EdgeMap(const TrivGraphWrapper<Graph>& _G) :
|
marci@158
|
82 |
Graph::EdgeMap<T>(_G.getGraph()) { }
|
marci@155
|
83 |
EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
|
marci@158
|
84 |
Graph::EdgeMap<T>(_G.getGraph(), a) { }
|
marci@155
|
85 |
};
|
marci@76
|
86 |
};
|
marci@76
|
87 |
|
marci@212
|
88 |
template<typename GraphWrapper>
|
marci@212
|
89 |
class GraphWrapperSkeleton {
|
marci@212
|
90 |
protected:
|
marci@212
|
91 |
GraphWrapper gw;
|
marci@212
|
92 |
|
marci@212
|
93 |
public:
|
marci@212
|
94 |
typedef typename GraphWrapper::BaseGraph BaseGraph;
|
marci@212
|
95 |
|
marci@212
|
96 |
typedef typename GraphWrapper::Node Node;
|
marci@212
|
97 |
typedef typename GraphWrapper::NodeIt NodeIt;
|
marci@212
|
98 |
|
marci@212
|
99 |
typedef typename GraphWrapper::Edge Edge;
|
marci@212
|
100 |
typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
|
marci@212
|
101 |
typedef typename GraphWrapper::InEdgeIt InEdgeIt;
|
marci@212
|
102 |
//typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
|
marci@212
|
103 |
typedef typename GraphWrapper::EdgeIt EdgeIt;
|
marci@212
|
104 |
|
marci@212
|
105 |
//GraphWrapperSkeleton() : gw() { }
|
marci@230
|
106 |
GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
|
marci@212
|
107 |
|
marci@212
|
108 |
void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
|
marci@212
|
109 |
BaseGraph& getGraph() const { return gw.getGraph(); }
|
marci@212
|
110 |
|
marci@212
|
111 |
template<typename I> I& first(I& i) const { return gw.first(i); }
|
marci@212
|
112 |
template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
113 |
return gw.first(i, p); }
|
marci@212
|
114 |
|
marci@212
|
115 |
template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
|
marci@212
|
116 |
template<typename I> I& next(I &i) const { return gw.next(i); }
|
marci@212
|
117 |
|
marci@212
|
118 |
template< typename It > It first() const {
|
marci@212
|
119 |
It e; this->first(e); return e; }
|
marci@212
|
120 |
|
marci@212
|
121 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
122 |
It e; this->first(e, v); return e; }
|
marci@212
|
123 |
|
marci@212
|
124 |
Node head(const Edge& e) const { return gw.head(e); }
|
marci@212
|
125 |
Node tail(const Edge& e) const { return gw.tail(e); }
|
marci@212
|
126 |
|
marci@212
|
127 |
template<typename I> bool valid(const I& i) const { return gw.valid(i); }
|
marci@212
|
128 |
|
marci@212
|
129 |
//template<typename I> void setInvalid(const I &i);
|
marci@212
|
130 |
//{ return graph->setInvalid(i); }
|
marci@212
|
131 |
|
marci@212
|
132 |
int nodeNum() const { return gw.nodeNum(); }
|
marci@212
|
133 |
int edgeNum() const { return gw.edgeNum(); }
|
marci@212
|
134 |
|
marci@212
|
135 |
template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
|
marci@212
|
136 |
template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
|
marci@212
|
137 |
|
marci@212
|
138 |
Node addNode() const { return gw.addNode(); }
|
marci@212
|
139 |
Edge addEdge(const Node& tail, const Node& head) const {
|
marci@212
|
140 |
return gw.addEdge(tail, head); }
|
marci@212
|
141 |
|
marci@212
|
142 |
template<typename I> void erase(const I& i) const { gw.erase(i); }
|
marci@212
|
143 |
|
marci@212
|
144 |
void clear() const { gw.clear(); }
|
marci@212
|
145 |
|
marci@212
|
146 |
template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
|
marci@212
|
147 |
public:
|
marci@212
|
148 |
NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
|
marci@212
|
149 |
GraphWrapper::NodeMap<T>(_G.gw) { }
|
marci@212
|
150 |
NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
|
marci@212
|
151 |
GraphWrapper::NodeMap<T>(_G.gw, a) { }
|
marci@212
|
152 |
};
|
marci@212
|
153 |
|
marci@212
|
154 |
template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
|
marci@212
|
155 |
public:
|
marci@212
|
156 |
EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
|
marci@212
|
157 |
GraphWrapper::EdgeMap<T>(_G.gw) { }
|
marci@212
|
158 |
EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
|
marci@212
|
159 |
GraphWrapper::EdgeMap<T>(_G.gw, a) { }
|
marci@212
|
160 |
};
|
marci@212
|
161 |
};
|
marci@212
|
162 |
|
marci@230
|
163 |
// template<typename Graph>
|
marci@230
|
164 |
// class RevGraphWrapper
|
marci@230
|
165 |
// {
|
marci@230
|
166 |
// protected:
|
marci@230
|
167 |
// Graph* graph;
|
marci@230
|
168 |
|
marci@230
|
169 |
// public:
|
marci@230
|
170 |
// typedef Graph BaseGraph;
|
marci@230
|
171 |
|
marci@230
|
172 |
// typedef typename Graph::Node Node;
|
marci@230
|
173 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@230
|
174 |
|
marci@230
|
175 |
// typedef typename Graph::Edge Edge;
|
marci@230
|
176 |
// typedef typename Graph::OutEdgeIt InEdgeIt;
|
marci@230
|
177 |
// typedef typename Graph::InEdgeIt OutEdgeIt;
|
marci@230
|
178 |
// //typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@230
|
179 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@230
|
180 |
|
marci@230
|
181 |
// //RevGraphWrapper() : graph(0) { }
|
marci@230
|
182 |
// RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@230
|
183 |
|
marci@230
|
184 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@230
|
185 |
// Graph& getGraph() const { return (*graph); }
|
marci@230
|
186 |
|
marci@230
|
187 |
// template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@230
|
188 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@230
|
189 |
// return graph->first(i, p); }
|
marci@230
|
190 |
|
marci@230
|
191 |
// template<typename I> I getNext(const I& i) const {
|
marci@230
|
192 |
// return graph->getNext(i); }
|
marci@230
|
193 |
// template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@230
|
194 |
|
marci@230
|
195 |
// template< typename It > It first() const {
|
marci@230
|
196 |
// It e; first(e); return e; }
|
marci@230
|
197 |
|
marci@230
|
198 |
// template< typename It > It first(const Node& v) const {
|
marci@230
|
199 |
// It e; first(e, v); return e; }
|
marci@230
|
200 |
|
marci@230
|
201 |
// Node head(const Edge& e) const { return graph->tail(e); }
|
marci@230
|
202 |
// Node tail(const Edge& e) const { return graph->head(e); }
|
marci@230
|
203 |
|
marci@230
|
204 |
// template<typename I> bool valid(const I& i) const
|
marci@230
|
205 |
// { return graph->valid(i); }
|
marci@230
|
206 |
|
marci@230
|
207 |
// //template<typename I> void setInvalid(const I &i);
|
marci@230
|
208 |
// //{ return graph->setInvalid(i); }
|
marci@230
|
209 |
|
marci@230
|
210 |
// template<typename I> Node aNode(const I& e) const {
|
marci@230
|
211 |
// return graph->aNode(e); }
|
marci@230
|
212 |
// template<typename I> Node bNode(const I& e) const {
|
marci@230
|
213 |
// return graph->bNode(e); }
|
marci@230
|
214 |
|
marci@230
|
215 |
// Node addNode() const { return graph->addNode(); }
|
marci@230
|
216 |
// Edge addEdge(const Node& tail, const Node& head) const {
|
marci@230
|
217 |
// return graph->addEdge(tail, head); }
|
marci@230
|
218 |
|
marci@230
|
219 |
// int nodeNum() const { return graph->nodeNum(); }
|
marci@230
|
220 |
// int edgeNum() const { return graph->edgeNum(); }
|
marci@230
|
221 |
|
marci@230
|
222 |
// template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@230
|
223 |
|
marci@230
|
224 |
// void clear() const { graph->clear(); }
|
marci@230
|
225 |
|
marci@230
|
226 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@230
|
227 |
// public:
|
marci@230
|
228 |
// NodeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
229 |
// Graph::NodeMap<T>(_G.getGraph()) { }
|
marci@230
|
230 |
// NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
231 |
// Graph::NodeMap<T>(_G.getGraph(), a) { }
|
marci@230
|
232 |
// };
|
marci@230
|
233 |
|
marci@230
|
234 |
// template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@230
|
235 |
// public:
|
marci@230
|
236 |
// EdgeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
237 |
// Graph::EdgeMap<T>(_G.getGraph()) { }
|
marci@230
|
238 |
// EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
239 |
// Graph::EdgeMap<T>(_G.getGraph(), a) { }
|
marci@230
|
240 |
// };
|
marci@230
|
241 |
// };
|
marci@230
|
242 |
|
marci@76
|
243 |
template<typename Graph>
|
marci@230
|
244 |
class RevGraphWrapper :
|
marci@230
|
245 |
public GraphWrapperSkeleton< TrivGraphWrapper<Graph> > {
|
marci@199
|
246 |
protected:
|
marci@230
|
247 |
//Graph* graph;
|
marci@230
|
248 |
|
marci@230
|
249 |
public:
|
marci@230
|
250 |
//typedef Graph BaseGraph;
|
marci@230
|
251 |
|
marci@230
|
252 |
//typedef typename Graph::Node Node;
|
marci@230
|
253 |
//typedef typename Graph::NodeIt NodeIt;
|
marci@76
|
254 |
|
marci@230
|
255 |
//typedef typename Graph::Edge Edge;
|
marci@230
|
256 |
typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::OutEdgeIt InEdgeIt;
|
marci@230
|
257 |
typedef typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::InEdgeIt OutEdgeIt;
|
marci@155
|
258 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@230
|
259 |
//typedef typename Graph::EdgeIt EdgeIt;
|
marci@168
|
260 |
|
marci@168
|
261 |
//RevGraphWrapper() : graph(0) { }
|
marci@230
|
262 |
RevGraphWrapper(Graph& _graph) : GraphWrapperSkeleton< TrivGraphWrapper<Graph> >(TrivGraphWrapper<Graph>(_graph)) { }
|
marci@230
|
263 |
|
marci@230
|
264 |
//void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@230
|
265 |
//Graph& getGraph() const { return (*graph); }
|
marci@230
|
266 |
|
marci@230
|
267 |
//template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@230
|
268 |
//template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@230
|
269 |
// return graph->first(i, p); }
|
marci@168
|
270 |
|
marci@230
|
271 |
//template<typename I> I getNext(const I& i) const {
|
marci@230
|
272 |
// return graph->getNext(i); }
|
marci@230
|
273 |
//template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@155
|
274 |
|
marci@230
|
275 |
//template< typename It > It first() const {
|
marci@230
|
276 |
// It e; first(e); return e; }
|
marci@76
|
277 |
|
marci@230
|
278 |
//template< typename It > It first(const Node& v) const {
|
marci@230
|
279 |
// It e; first(e, v); return e; }
|
marci@76
|
280 |
|
marci@230
|
281 |
//Node head(const Edge& e) const { return graph->tail(e); }
|
marci@230
|
282 |
//Node tail(const Edge& e) const { return graph->head(e); }
|
marci@76
|
283 |
|
marci@230
|
284 |
//template<typename I> bool valid(const I& i) const
|
marci@230
|
285 |
// { return graph->valid(i); }
|
marci@155
|
286 |
|
marci@155
|
287 |
//template<typename I> void setInvalid(const I &i);
|
marci@155
|
288 |
//{ return graph->setInvalid(i); }
|
marci@155
|
289 |
|
marci@230
|
290 |
//template<typename I> Node aNode(const I& e) const {
|
marci@230
|
291 |
// return graph->aNode(e); }
|
marci@230
|
292 |
//template<typename I> Node bNode(const I& e) const {
|
marci@230
|
293 |
// return graph->bNode(e); }
|
marci@155
|
294 |
|
marci@230
|
295 |
//Node addNode() const { return graph->addNode(); }
|
marci@230
|
296 |
//Edge addEdge(const Node& tail, const Node& head) const {
|
marci@230
|
297 |
// return graph->addEdge(tail, head); }
|
marci@76
|
298 |
|
marci@230
|
299 |
//int nodeNum() const { return graph->nodeNum(); }
|
marci@230
|
300 |
//int edgeNum() const { return graph->edgeNum(); }
|
marci@76
|
301 |
|
marci@230
|
302 |
//template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@76
|
303 |
|
marci@230
|
304 |
//void clear() const { graph->clear(); }
|
marci@155
|
305 |
|
marci@230
|
306 |
template<typename T> class NodeMap :
|
marci@230
|
307 |
public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>
|
marci@230
|
308 |
{
|
marci@155
|
309 |
public:
|
marci@155
|
310 |
NodeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
311 |
GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G) { }
|
marci@155
|
312 |
NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
313 |
GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::NodeMap<T>(_G, a) { }
|
marci@155
|
314 |
};
|
marci@230
|
315 |
|
marci@230
|
316 |
template<typename T> class EdgeMap :
|
marci@230
|
317 |
public GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T> {
|
marci@155
|
318 |
public:
|
marci@155
|
319 |
EdgeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
320 |
GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G) { }
|
marci@155
|
321 |
EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
322 |
GraphWrapperSkeleton< TrivGraphWrapper<Graph> >::EdgeMap<T>(_G, a) { }
|
marci@155
|
323 |
};
|
marci@76
|
324 |
};
|
marci@76
|
325 |
|
marci@155
|
326 |
|
marci@158
|
327 |
template<typename Graph>
|
marci@158
|
328 |
class UndirGraphWrapper {
|
marci@199
|
329 |
protected:
|
marci@158
|
330 |
Graph* graph;
|
marci@158
|
331 |
|
marci@158
|
332 |
public:
|
marci@158
|
333 |
typedef Graph BaseGraph;
|
marci@158
|
334 |
|
marci@174
|
335 |
typedef typename Graph::Node Node;
|
marci@158
|
336 |
typedef typename Graph::NodeIt NodeIt;
|
marci@158
|
337 |
|
marci@174
|
338 |
//typedef typename Graph::Edge Edge;
|
marci@158
|
339 |
//typedef typename Graph::OutEdgeIt OutEdgeIt;
|
marci@158
|
340 |
//typedef typename Graph::InEdgeIt InEdgeIt;
|
marci@158
|
341 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
342 |
//typedef typename Graph::EdgeIt EdgeIt;
|
marci@158
|
343 |
|
marci@158
|
344 |
//private:
|
marci@174
|
345 |
typedef typename Graph::Edge GraphEdge;
|
marci@158
|
346 |
typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
|
marci@158
|
347 |
typedef typename Graph::InEdgeIt GraphInEdgeIt;
|
marci@158
|
348 |
//public:
|
marci@158
|
349 |
|
marci@168
|
350 |
//UndirGraphWrapper() : graph(0) { }
|
marci@168
|
351 |
UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@168
|
352 |
|
marci@168
|
353 |
void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@168
|
354 |
Graph& getGraph() const { return (*graph); }
|
marci@168
|
355 |
|
marci@174
|
356 |
class Edge {
|
marci@158
|
357 |
friend class UndirGraphWrapper<Graph>;
|
marci@158
|
358 |
bool out_or_in; //true iff out
|
marci@158
|
359 |
GraphOutEdgeIt out;
|
marci@158
|
360 |
GraphInEdgeIt in;
|
marci@158
|
361 |
public:
|
marci@174
|
362 |
Edge() : out_or_in(), out(), in() { }
|
marci@174
|
363 |
Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
|
marci@174
|
364 |
operator GraphEdge() const {
|
marci@158
|
365 |
if (out_or_in) return(out); else return(in);
|
marci@158
|
366 |
}
|
marci@174
|
367 |
friend bool operator==(const Edge& u, const Edge& v) {
|
marci@174
|
368 |
if (v.out_or_in)
|
marci@174
|
369 |
return (u.out_or_in && u.out==v.out);
|
marci@174
|
370 |
else
|
marci@174
|
371 |
return (!u.out_or_in && u.in==v.in);
|
marci@174
|
372 |
}
|
marci@174
|
373 |
friend bool operator!=(const Edge& u, const Edge& v) {
|
marci@174
|
374 |
if (v.out_or_in)
|
marci@174
|
375 |
return (!u.out_or_in || u.out!=v.out);
|
marci@174
|
376 |
else
|
marci@174
|
377 |
return (u.out_or_in || u.in!=v.in);
|
marci@174
|
378 |
}
|
marci@158
|
379 |
};
|
marci@158
|
380 |
|
marci@174
|
381 |
class OutEdgeIt : public Edge {
|
marci@158
|
382 |
friend class UndirGraphWrapper<Graph>;
|
marci@158
|
383 |
public:
|
marci@174
|
384 |
OutEdgeIt() : Edge() { }
|
marci@174
|
385 |
OutEdgeIt(const Invalid& i) : Edge(i) { }
|
marci@174
|
386 |
OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
|
marci@174
|
387 |
out_or_in=true;
|
marci@212
|
388 |
_G.graph->first(out, n);
|
marci@158
|
389 |
if (!(_G.graph->valid(out))) {
|
marci@158
|
390 |
out_or_in=false;
|
marci@212
|
391 |
_G.graph->first(in, n);
|
marci@158
|
392 |
}
|
marci@158
|
393 |
}
|
marci@158
|
394 |
};
|
marci@158
|
395 |
|
marci@212
|
396 |
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@158
|
397 |
e.out_or_in=true;
|
marci@212
|
398 |
graph->first(e.out, n);
|
marci@158
|
399 |
if (!(graph->valid(e.out))) {
|
marci@158
|
400 |
e.out_or_in=false;
|
marci@212
|
401 |
graph->first(e.in, n);
|
marci@158
|
402 |
}
|
marci@158
|
403 |
return e;
|
marci@158
|
404 |
}
|
marci@158
|
405 |
|
marci@158
|
406 |
OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@158
|
407 |
if (e.out_or_in) {
|
marci@174
|
408 |
Node n=graph->tail(e.out);
|
marci@158
|
409 |
graph->next(e.out);
|
marci@158
|
410 |
if (!graph->valid(e.out)) {
|
marci@158
|
411 |
e.out_or_in=false;
|
marci@212
|
412 |
graph->first(e.in, n);
|
marci@158
|
413 |
}
|
marci@158
|
414 |
} else {
|
marci@158
|
415 |
graph->next(e.in);
|
marci@158
|
416 |
}
|
marci@158
|
417 |
return e;
|
marci@158
|
418 |
}
|
marci@158
|
419 |
|
marci@174
|
420 |
Node aNode(const OutEdgeIt& e) const {
|
marci@158
|
421 |
if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
|
marci@174
|
422 |
Node bNode(const OutEdgeIt& e) const {
|
marci@158
|
423 |
if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
|
marci@158
|
424 |
|
marci@158
|
425 |
typedef OutEdgeIt InEdgeIt;
|
marci@158
|
426 |
|
marci@212
|
427 |
template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@212
|
428 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
429 |
// return graph->first(i, p); }
|
marci@158
|
430 |
|
marci@158
|
431 |
template<typename I> I getNext(const I& i) const {
|
marci@158
|
432 |
return graph->getNext(i); }
|
marci@158
|
433 |
template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@158
|
434 |
|
marci@158
|
435 |
template< typename It > It first() const {
|
marci@212
|
436 |
It e; first(e); return e; }
|
marci@158
|
437 |
|
marci@174
|
438 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
439 |
It e; first(e, v); return e; }
|
marci@158
|
440 |
|
marci@174
|
441 |
Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
442 |
Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@158
|
443 |
|
marci@158
|
444 |
template<typename I> bool valid(const I& i) const
|
marci@158
|
445 |
{ return graph->valid(i); }
|
marci@158
|
446 |
|
marci@158
|
447 |
//template<typename I> void setInvalid(const I &i);
|
marci@158
|
448 |
//{ return graph->setInvalid(i); }
|
marci@158
|
449 |
|
marci@158
|
450 |
int nodeNum() const { return graph->nodeNum(); }
|
marci@158
|
451 |
int edgeNum() const { return graph->edgeNum(); }
|
marci@158
|
452 |
|
marci@174
|
453 |
// template<typename I> Node aNode(const I& e) const {
|
marci@158
|
454 |
// return graph->aNode(e); }
|
marci@174
|
455 |
// template<typename I> Node bNode(const I& e) const {
|
marci@158
|
456 |
// return graph->bNode(e); }
|
marci@158
|
457 |
|
marci@174
|
458 |
Node addNode() const { return graph->addNode(); }
|
marci@231
|
459 |
// FIXME: ez igy nem jo, mert nem
|
marci@231
|
460 |
// Edge addEdge(const Node& tail, const Node& head) const {
|
marci@231
|
461 |
// return graph->addEdge(tail, head); }
|
marci@158
|
462 |
|
marci@158
|
463 |
template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@158
|
464 |
|
marci@158
|
465 |
void clear() const { graph->clear(); }
|
marci@158
|
466 |
|
marci@158
|
467 |
template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@158
|
468 |
public:
|
marci@158
|
469 |
NodeMap(const UndirGraphWrapper<Graph>& _G) :
|
marci@158
|
470 |
Graph::NodeMap<T>(_G.getGraph()) { }
|
marci@158
|
471 |
NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
|
marci@158
|
472 |
Graph::NodeMap<T>(_G.getGraph(), a) { }
|
marci@158
|
473 |
};
|
marci@168
|
474 |
|
marci@158
|
475 |
template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@158
|
476 |
public:
|
marci@158
|
477 |
EdgeMap(const UndirGraphWrapper<Graph>& _G) :
|
marci@158
|
478 |
Graph::EdgeMap<T>(_G.getGraph()) { }
|
marci@158
|
479 |
EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
|
marci@158
|
480 |
Graph::EdgeMap<T>(_G.getGraph(), a) { }
|
marci@158
|
481 |
};
|
marci@158
|
482 |
};
|
marci@158
|
483 |
|
marci@158
|
484 |
|
marci@158
|
485 |
|
marci@155
|
486 |
// template<typename Graph>
|
marci@155
|
487 |
// class SymGraphWrapper
|
marci@155
|
488 |
// {
|
marci@155
|
489 |
// Graph* graph;
|
marci@76
|
490 |
|
marci@155
|
491 |
// public:
|
marci@155
|
492 |
// typedef Graph BaseGraph;
|
marci@155
|
493 |
|
marci@174
|
494 |
// typedef typename Graph::Node Node;
|
marci@174
|
495 |
// typedef typename Graph::Edge Edge;
|
marci@174
|
496 |
|
marci@155
|
497 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@155
|
498 |
|
marci@155
|
499 |
// //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
|
marci@155
|
500 |
// //iranyitatlant, ami van
|
marci@155
|
501 |
// //mert csak 1 dolgot lehet be typedef-elni
|
marci@155
|
502 |
// typedef typename Graph::OutEdgeIt SymEdgeIt;
|
marci@155
|
503 |
// //typedef typename Graph::InEdgeIt SymEdgeIt;
|
marci@155
|
504 |
// //typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
505 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@155
|
506 |
|
marci@155
|
507 |
// int nodeNum() const { return graph->nodeNum(); }
|
marci@155
|
508 |
// int edgeNum() const { return graph->edgeNum(); }
|
marci@155
|
509 |
|
marci@212
|
510 |
// template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@212
|
511 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
512 |
// return graph->first(i, p); }
|
marci@155
|
513 |
// //template<typename I> I next(const I i); { return graph->goNext(i); }
|
marci@155
|
514 |
// //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
|
marci@155
|
515 |
|
marci@155
|
516 |
// template< typename It > It first() const {
|
marci@212
|
517 |
// It e; first(e); return e; }
|
marci@155
|
518 |
|
marci@174
|
519 |
// template< typename It > It first(Node v) const {
|
marci@212
|
520 |
// It e; first(e, v); return e; }
|
marci@155
|
521 |
|
marci@174
|
522 |
// Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
523 |
// Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@155
|
524 |
|
marci@174
|
525 |
// template<typename I> Node aNode(const I& e) const {
|
marci@155
|
526 |
// return graph->aNode(e); }
|
marci@174
|
527 |
// template<typename I> Node bNode(const I& e) const {
|
marci@155
|
528 |
// return graph->bNode(e); }
|
marci@155
|
529 |
|
marci@155
|
530 |
// //template<typename I> bool valid(const I i);
|
marci@155
|
531 |
// //{ return graph->valid(i); }
|
marci@155
|
532 |
|
marci@155
|
533 |
// //template<typename I> void setInvalid(const I &i);
|
marci@155
|
534 |
// //{ return graph->setInvalid(i); }
|
marci@155
|
535 |
|
marci@174
|
536 |
// Node addNode() { return graph->addNode(); }
|
marci@174
|
537 |
// Edge addEdge(const Node& tail, const Node& head) {
|
marci@155
|
538 |
// return graph->addEdge(tail, head); }
|
marci@155
|
539 |
|
marci@155
|
540 |
// template<typename I> void erase(const I& i) { graph->erase(i); }
|
marci@155
|
541 |
|
marci@155
|
542 |
// void clear() { graph->clear(); }
|
marci@155
|
543 |
|
marci@155
|
544 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> { };
|
marci@155
|
545 |
// template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
|
marci@155
|
546 |
|
marci@155
|
547 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@155
|
548 |
// Graph& getGraph() { return (*graph); }
|
marci@155
|
549 |
|
marci@155
|
550 |
// //SymGraphWrapper() : graph(0) { }
|
marci@155
|
551 |
// SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@155
|
552 |
// };
|
marci@155
|
553 |
|
marci@155
|
554 |
|
marci@155
|
555 |
template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
|
marci@155
|
556 |
class ResGraphWrapper {
|
marci@76
|
557 |
public:
|
marci@76
|
558 |
typedef Graph BaseGraph;
|
marci@174
|
559 |
typedef typename Graph::Node Node;
|
marci@155
|
560 |
typedef typename Graph::NodeIt NodeIt;
|
marci@155
|
561 |
private:
|
marci@155
|
562 |
typedef typename Graph::OutEdgeIt OldOutEdgeIt;
|
marci@155
|
563 |
typedef typename Graph::InEdgeIt OldInEdgeIt;
|
marci@199
|
564 |
protected:
|
marci@174
|
565 |
const Graph* graph;
|
marci@155
|
566 |
FlowMap* flow;
|
marci@155
|
567 |
const CapacityMap* capacity;
|
marci@155
|
568 |
public:
|
marci@168
|
569 |
|
marci@155
|
570 |
ResGraphWrapper(const Graph& _G, FlowMap& _flow,
|
marci@155
|
571 |
const CapacityMap& _capacity) :
|
marci@174
|
572 |
graph(&_G), flow(&_flow), capacity(&_capacity) { }
|
marci@168
|
573 |
|
marci@168
|
574 |
void setGraph(const Graph& _graph) { graph = &_graph; }
|
marci@174
|
575 |
const Graph& getGraph() const { return (*graph); }
|
marci@168
|
576 |
|
marci@174
|
577 |
class Edge;
|
marci@155
|
578 |
class OutEdgeIt;
|
marci@174
|
579 |
friend class Edge;
|
marci@155
|
580 |
friend class OutEdgeIt;
|
marci@76
|
581 |
|
marci@174
|
582 |
class Edge {
|
marci@155
|
583 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@155
|
584 |
protected:
|
marci@168
|
585 |
bool out_or_in; //true, iff out
|
marci@155
|
586 |
OldOutEdgeIt out;
|
marci@155
|
587 |
OldInEdgeIt in;
|
marci@155
|
588 |
public:
|
marci@174
|
589 |
Edge() : out_or_in(true) { }
|
marci@174
|
590 |
Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
|
marci@168
|
591 |
// bool valid() const {
|
marci@168
|
592 |
// return out_or_in && out.valid() || in.valid(); }
|
marci@174
|
593 |
friend bool operator==(const Edge& u, const Edge& v) {
|
marci@174
|
594 |
if (v.out_or_in)
|
marci@174
|
595 |
return (u.out_or_in && u.out==v.out);
|
marci@174
|
596 |
else
|
marci@174
|
597 |
return (!u.out_or_in && u.in==v.in);
|
marci@174
|
598 |
}
|
marci@174
|
599 |
friend bool operator!=(const Edge& u, const Edge& v) {
|
marci@174
|
600 |
if (v.out_or_in)
|
marci@174
|
601 |
return (!u.out_or_in || u.out!=v.out);
|
marci@174
|
602 |
else
|
marci@174
|
603 |
return (u.out_or_in || u.in!=v.in);
|
marci@174
|
604 |
}
|
marci@155
|
605 |
};
|
marci@155
|
606 |
|
marci@155
|
607 |
|
marci@174
|
608 |
class OutEdgeIt : public Edge {
|
marci@155
|
609 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@155
|
610 |
public:
|
marci@155
|
611 |
OutEdgeIt() { }
|
marci@168
|
612 |
//FIXME
|
marci@174
|
613 |
OutEdgeIt(const Edge& e) : Edge(e) { }
|
marci@174
|
614 |
OutEdgeIt(const Invalid& i) : Edge(i) { }
|
marci@155
|
615 |
private:
|
marci@174
|
616 |
OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
|
marci@212
|
617 |
resG.graph->first(out, v);
|
marci@174
|
618 |
while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
|
marci@174
|
619 |
if (!resG.graph->valid(out)) {
|
marci@155
|
620 |
out_or_in=0;
|
marci@212
|
621 |
resG.graph->first(in, v);
|
marci@174
|
622 |
while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
|
marci@155
|
623 |
}
|
marci@155
|
624 |
}
|
marci@168
|
625 |
// public:
|
marci@168
|
626 |
// OutEdgeIt& operator++() {
|
marci@168
|
627 |
// if (out_or_in) {
|
marci@174
|
628 |
// Node v=/*resG->*/G->aNode(out);
|
marci@168
|
629 |
// ++out;
|
marci@174
|
630 |
// while( out.valid() && !(Edge::free()>0) ) { ++out; }
|
marci@168
|
631 |
// if (!out.valid()) {
|
marci@168
|
632 |
// out_or_in=0;
|
marci@212
|
633 |
// G->first(in, v);
|
marci@174
|
634 |
// while( in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
635 |
// }
|
marci@168
|
636 |
// } else {
|
marci@168
|
637 |
// ++in;
|
marci@174
|
638 |
// while( in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
639 |
// }
|
marci@168
|
640 |
// return *this;
|
marci@168
|
641 |
// }
|
marci@155
|
642 |
};
|
marci@155
|
643 |
|
marci@174
|
644 |
class EdgeIt : public Edge {
|
marci@155
|
645 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@174
|
646 |
typename Graph::NodeIt v;
|
marci@155
|
647 |
public:
|
marci@174
|
648 |
EdgeIt() { }
|
marci@174
|
649 |
//EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
|
marci@174
|
650 |
EdgeIt(const Invalid& i) : Edge(i) { }
|
marci@174
|
651 |
EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
|
marci@212
|
652 |
resG.graph->first(v);
|
marci@212
|
653 |
if (resG.graph->valid(v)) resG.graph->first(out, v); else out=OldOutEdgeIt(INVALID);
|
marci@174
|
654 |
while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
|
marci@174
|
655 |
while (resG.graph->valid(v) && !resG.graph->valid(out)) {
|
marci@174
|
656 |
resG.graph->next(v);
|
marci@212
|
657 |
if (resG.graph->valid(v)) resG.graph->first(out, v);
|
marci@174
|
658 |
while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
|
marci@155
|
659 |
}
|
marci@174
|
660 |
if (!resG.graph->valid(out)) {
|
marci@155
|
661 |
out_or_in=0;
|
marci@212
|
662 |
resG.graph->first(v);
|
marci@212
|
663 |
if (resG.graph->valid(v)) resG.graph->first(in, v); else in=OldInEdgeIt(INVALID);
|
marci@174
|
664 |
while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
|
marci@174
|
665 |
while (resG.graph->valid(v) && !resG.graph->valid(in)) {
|
marci@174
|
666 |
resG.graph->next(v);
|
marci@212
|
667 |
if (resG.graph->valid(v)) resG.graph->first(in, v);
|
marci@174
|
668 |
while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
|
marci@155
|
669 |
}
|
marci@155
|
670 |
}
|
marci@155
|
671 |
}
|
marci@174
|
672 |
// EdgeIt& operator++() {
|
marci@168
|
673 |
// if (out_or_in) {
|
marci@168
|
674 |
// ++out;
|
marci@174
|
675 |
// while (out.valid() && !(Edge::free()>0) ) { ++out; }
|
marci@168
|
676 |
// while (v.valid() && !out.valid()) {
|
marci@168
|
677 |
// ++v;
|
marci@212
|
678 |
// if (v.valid()) G->first(out, v);
|
marci@174
|
679 |
// while (out.valid() && !(Edge::free()>0) ) { ++out; }
|
marci@168
|
680 |
// }
|
marci@168
|
681 |
// if (!out.valid()) {
|
marci@168
|
682 |
// out_or_in=0;
|
marci@212
|
683 |
// G->first(v);
|
marci@212
|
684 |
// if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
|
marci@174
|
685 |
// while (in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
686 |
// while (v.valid() && !in.valid()) {
|
marci@168
|
687 |
// ++v;
|
marci@212
|
688 |
// if (v.valid()) G->first(in, v);
|
marci@174
|
689 |
// while (in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
690 |
// }
|
marci@168
|
691 |
// }
|
marci@168
|
692 |
// } else {
|
marci@168
|
693 |
// ++in;
|
marci@174
|
694 |
// while (in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
695 |
// while (v.valid() && !in.valid()) {
|
marci@168
|
696 |
// ++v;
|
marci@212
|
697 |
// if (v.valid()) G->first(in, v);
|
marci@174
|
698 |
// while (in.valid() && !(Edge::free()>0) ) { ++in; }
|
marci@168
|
699 |
// }
|
marci@168
|
700 |
// }
|
marci@168
|
701 |
// return *this;
|
marci@168
|
702 |
// }
|
marci@155
|
703 |
};
|
marci@155
|
704 |
|
marci@212
|
705 |
NodeIt& first(NodeIt& v) const { return graph->first(v); }
|
marci@212
|
706 |
OutEdgeIt& first(OutEdgeIt& e, Node v) const {
|
marci@168
|
707 |
e=OutEdgeIt(*this, v);
|
marci@174
|
708 |
return e;
|
marci@155
|
709 |
}
|
marci@212
|
710 |
EdgeIt& first(EdgeIt& e) const {
|
marci@174
|
711 |
e=EdgeIt(*this);
|
marci@174
|
712 |
return e;
|
marci@155
|
713 |
}
|
marci@155
|
714 |
|
marci@174
|
715 |
NodeIt& next(NodeIt& n) const { return graph->next(n); }
|
marci@155
|
716 |
|
marci@155
|
717 |
OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@155
|
718 |
if (e.out_or_in) {
|
marci@174
|
719 |
Node v=graph->aNode(e.out);
|
marci@174
|
720 |
graph->next(e.out);
|
marci@174
|
721 |
while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
|
marci@174
|
722 |
if (!graph->valid(e.out)) {
|
marci@155
|
723 |
e.out_or_in=0;
|
marci@212
|
724 |
graph->first(e.in, v);
|
marci@174
|
725 |
while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
726 |
}
|
marci@155
|
727 |
} else {
|
marci@174
|
728 |
graph->next(e.in);
|
marci@174
|
729 |
while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
730 |
}
|
marci@155
|
731 |
return e;
|
marci@155
|
732 |
}
|
marci@155
|
733 |
|
marci@174
|
734 |
EdgeIt& next(EdgeIt& e) const {
|
marci@155
|
735 |
if (e.out_or_in) {
|
marci@174
|
736 |
graph->next(e.out);
|
marci@174
|
737 |
while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
|
marci@174
|
738 |
while (graph->valid(e.v) && !graph->valid(e.out)) {
|
marci@174
|
739 |
graph->next(e.v);
|
marci@212
|
740 |
if (graph->valid(e.v)) graph->first(e.out, e.v);
|
marci@174
|
741 |
while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
|
marci@155
|
742 |
}
|
marci@174
|
743 |
if (!graph->valid(e.out)) {
|
marci@155
|
744 |
e.out_or_in=0;
|
marci@212
|
745 |
graph->first(e.v);
|
marci@212
|
746 |
if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=OldInEdgeIt(INVALID);
|
marci@174
|
747 |
while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@174
|
748 |
while (graph->valid(e.v) && !graph->valid(e.in)) {
|
marci@174
|
749 |
graph->next(e.v);
|
marci@212
|
750 |
if (graph->valid(e.v)) graph->first(e.in, e.v);
|
marci@174
|
751 |
while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
752 |
}
|
marci@155
|
753 |
}
|
marci@155
|
754 |
} else {
|
marci@174
|
755 |
graph->next(e.in);
|
marci@174
|
756 |
while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@174
|
757 |
while (graph->valid(e.v) && !graph->valid(e.in)) {
|
marci@174
|
758 |
graph->next(e.v);
|
marci@212
|
759 |
if (graph->valid(e.v)) graph->first(e.in, e.v);
|
marci@174
|
760 |
while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
761 |
}
|
marci@155
|
762 |
}
|
marci@155
|
763 |
return e;
|
marci@155
|
764 |
}
|
marci@76
|
765 |
|
marci@76
|
766 |
|
marci@155
|
767 |
template< typename It >
|
marci@155
|
768 |
It first() const {
|
marci@155
|
769 |
It e;
|
marci@212
|
770 |
first(e);
|
marci@155
|
771 |
return e;
|
marci@155
|
772 |
}
|
marci@76
|
773 |
|
marci@155
|
774 |
template< typename It >
|
marci@174
|
775 |
It first(Node v) const {
|
marci@155
|
776 |
It e;
|
marci@212
|
777 |
first(e, v);
|
marci@155
|
778 |
return e;
|
marci@155
|
779 |
}
|
marci@76
|
780 |
|
marci@174
|
781 |
Node tail(Edge e) const {
|
marci@174
|
782 |
return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
|
marci@174
|
783 |
Node head(Edge e) const {
|
marci@174
|
784 |
return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
|
marci@76
|
785 |
|
marci@174
|
786 |
Node aNode(OutEdgeIt e) const {
|
marci@174
|
787 |
return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
|
marci@174
|
788 |
Node bNode(OutEdgeIt e) const {
|
marci@174
|
789 |
return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
|
marci@76
|
790 |
|
marci@174
|
791 |
int id(Node v) const { return graph->id(v); }
|
marci@155
|
792 |
|
marci@174
|
793 |
bool valid(Node n) const { return graph->valid(n); }
|
marci@174
|
794 |
bool valid(Edge e) const {
|
marci@174
|
795 |
return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); }
|
marci@155
|
796 |
|
marci@174
|
797 |
void augment(const Edge& e, Number a) const {
|
marci@168
|
798 |
if (e.out_or_in)
|
marci@168
|
799 |
flow->set(e.out, flow->get(e.out)+a);
|
marci@168
|
800 |
else
|
marci@168
|
801 |
flow->set(e.in, flow->get(e.in)-a);
|
marci@168
|
802 |
}
|
marci@168
|
803 |
|
marci@174
|
804 |
Number free(const Edge& e) const {
|
marci@168
|
805 |
if (e.out_or_in)
|
marci@168
|
806 |
return (capacity->get(e.out)-flow->get(e.out));
|
marci@168
|
807 |
else
|
marci@168
|
808 |
return (flow->get(e.in));
|
marci@168
|
809 |
}
|
marci@168
|
810 |
|
marci@168
|
811 |
Number free(OldOutEdgeIt out) const {
|
marci@168
|
812 |
return (capacity->get(out)-flow->get(out));
|
marci@168
|
813 |
}
|
marci@168
|
814 |
|
marci@168
|
815 |
Number free(OldInEdgeIt in) const {
|
marci@168
|
816 |
return (flow->get(in));
|
marci@168
|
817 |
}
|
marci@168
|
818 |
|
marci@155
|
819 |
template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@155
|
820 |
public:
|
marci@155
|
821 |
NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
|
marci@158
|
822 |
: Graph::NodeMap<T>(_G.getGraph()) { }
|
marci@155
|
823 |
NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
|
marci@158
|
824 |
T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
|
marci@155
|
825 |
};
|
marci@155
|
826 |
|
marci@155
|
827 |
// template <typename T>
|
marci@155
|
828 |
// class NodeMap {
|
marci@155
|
829 |
// typename Graph::NodeMap<T> node_map;
|
marci@155
|
830 |
// public:
|
marci@174
|
831 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
|
marci@174
|
832 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
|
marci@174
|
833 |
// void set(Node nit, T a) { node_map.set(nit, a); }
|
marci@174
|
834 |
// T get(Node nit) const { return node_map.get(nit); }
|
marci@155
|
835 |
// };
|
marci@155
|
836 |
|
marci@155
|
837 |
template <typename T>
|
marci@155
|
838 |
class EdgeMap {
|
marci@155
|
839 |
typename Graph::EdgeMap<T> forward_map, backward_map;
|
marci@155
|
840 |
public:
|
marci@158
|
841 |
EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { }
|
marci@158
|
842 |
EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { }
|
marci@174
|
843 |
void set(Edge e, T a) {
|
marci@155
|
844 |
if (e.out_or_in)
|
marci@155
|
845 |
forward_map.set(e.out, a);
|
marci@155
|
846 |
else
|
marci@155
|
847 |
backward_map.set(e.in, a);
|
marci@155
|
848 |
}
|
marci@174
|
849 |
T get(Edge e) {
|
marci@155
|
850 |
if (e.out_or_in)
|
marci@155
|
851 |
return forward_map.get(e.out);
|
marci@155
|
852 |
else
|
marci@155
|
853 |
return backward_map.get(e.in);
|
marci@155
|
854 |
}
|
marci@155
|
855 |
};
|
marci@168
|
856 |
};
|
marci@168
|
857 |
|
marci@168
|
858 |
template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
|
marci@168
|
859 |
class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
|
marci@168
|
860 |
protected:
|
marci@168
|
861 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
|
marci@168
|
862 |
//ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
|
marci@168
|
863 |
public:
|
marci@168
|
864 |
ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
|
marci@168
|
865 |
const CapacityMap& _capacity) :
|
marci@168
|
866 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
|
marci@168
|
867 |
first_out_edges(*this) /*, dist(*this)*/ {
|
marci@174
|
868 |
for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
|
marci@168
|
869 |
OutEdgeIt e;
|
marci@212
|
870 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
|
marci@168
|
871 |
first_out_edges.set(n, e);
|
marci@168
|
872 |
}
|
marci@168
|
873 |
}
|
marci@168
|
874 |
|
marci@168
|
875 |
//void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@168
|
876 |
//Graph& getGraph() const { return (*graph); }
|
marci@168
|
877 |
|
marci@168
|
878 |
//TrivGraphWrapper() : graph(0) { }
|
marci@168
|
879 |
//ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@168
|
880 |
|
marci@168
|
881 |
//typedef Graph BaseGraph;
|
marci@168
|
882 |
|
marci@174
|
883 |
//typedef typename Graph::Node Node;
|
marci@168
|
884 |
//typedef typename Graph::NodeIt NodeIt;
|
marci@168
|
885 |
|
marci@174
|
886 |
//typedef typename Graph::Edge Edge;
|
marci@168
|
887 |
//typedef typename Graph::OutEdgeIt OutEdgeIt;
|
marci@168
|
888 |
//typedef typename Graph::InEdgeIt InEdgeIt;
|
marci@168
|
889 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
890 |
//typedef typename Graph::EdgeIt EdgeIt;
|
marci@168
|
891 |
|
marci@174
|
892 |
typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
|
marci@168
|
893 |
typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
|
marci@168
|
894 |
|
marci@174
|
895 |
typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
|
marci@168
|
896 |
typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
|
marci@168
|
897 |
//typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
|
marci@168
|
898 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
899 |
//typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
|
marci@168
|
900 |
|
marci@212
|
901 |
NodeIt& first(NodeIt& n) const {
|
marci@212
|
902 |
return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
|
marci@168
|
903 |
}
|
marci@168
|
904 |
|
marci@212
|
905 |
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@168
|
906 |
e=first_out_edges.get(n);
|
marci@168
|
907 |
return e;
|
marci@168
|
908 |
}
|
marci@168
|
909 |
|
marci@212
|
910 |
//ROSSZ template<typename I> I& first(I& i) const { return first(i); }
|
marci@212
|
911 |
//ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
912 |
// return first(i, p); }
|
marci@168
|
913 |
|
marci@168
|
914 |
//template<typename I> I getNext(const I& i) const {
|
marci@168
|
915 |
// return graph->getNext(i); }
|
marci@168
|
916 |
//template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@168
|
917 |
|
marci@168
|
918 |
template< typename It > It first() const {
|
marci@212
|
919 |
It e; first(e); return e; }
|
marci@168
|
920 |
|
marci@174
|
921 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
922 |
It e; first(e, v); return e; }
|
marci@168
|
923 |
|
marci@174
|
924 |
//Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
925 |
//Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@168
|
926 |
|
marci@168
|
927 |
//template<typename I> bool valid(const I& i) const
|
marci@168
|
928 |
// { return graph->valid(i); }
|
marci@168
|
929 |
|
marci@168
|
930 |
//int nodeNum() const { return graph->nodeNum(); }
|
marci@168
|
931 |
//int edgeNum() const { return graph->edgeNum(); }
|
marci@168
|
932 |
|
marci@174
|
933 |
//template<typename I> Node aNode(const I& e) const {
|
marci@168
|
934 |
// return graph->aNode(e); }
|
marci@174
|
935 |
//template<typename I> Node bNode(const I& e) const {
|
marci@168
|
936 |
// return graph->bNode(e); }
|
marci@168
|
937 |
|
marci@174
|
938 |
//Node addNode() const { return graph->addNode(); }
|
marci@174
|
939 |
//Edge addEdge(const Node& tail, const Node& head) const {
|
marci@168
|
940 |
// return graph->addEdge(tail, head); }
|
marci@168
|
941 |
|
marci@168
|
942 |
//void erase(const OutEdgeIt& e) {
|
marci@168
|
943 |
// first_out_edge(this->tail(e))=e;
|
marci@168
|
944 |
//}
|
marci@174
|
945 |
void erase(const Edge& e) {
|
marci@168
|
946 |
OutEdgeIt f(e);
|
marci@168
|
947 |
next(f);
|
marci@168
|
948 |
first_out_edges.set(this->tail(e), f);
|
marci@168
|
949 |
}
|
marci@168
|
950 |
//template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@168
|
951 |
|
marci@168
|
952 |
//void clear() const { graph->clear(); }
|
marci@168
|
953 |
|
marci@168
|
954 |
template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
|
marci@168
|
955 |
public:
|
marci@168
|
956 |
NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
|
marci@168
|
957 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
|
marci@168
|
958 |
NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
|
marci@168
|
959 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
|
marci@168
|
960 |
};
|
marci@168
|
961 |
|
marci@168
|
962 |
template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
|
marci@168
|
963 |
public:
|
marci@168
|
964 |
EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
|
marci@168
|
965 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
|
marci@168
|
966 |
EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
|
marci@168
|
967 |
ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
|
marci@168
|
968 |
};
|
marci@168
|
969 |
};
|
marci@168
|
970 |
|
marci@168
|
971 |
template<typename GraphWrapper>
|
marci@168
|
972 |
class FilterGraphWrapper {
|
marci@168
|
973 |
};
|
marci@168
|
974 |
|
marci@168
|
975 |
template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
|
marci@168
|
976 |
class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
|
marci@168
|
977 |
|
marci@168
|
978 |
//Graph* graph;
|
marci@168
|
979 |
|
marci@168
|
980 |
public:
|
marci@168
|
981 |
//typedef Graph BaseGraph;
|
marci@168
|
982 |
|
marci@174
|
983 |
typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
|
marci@168
|
984 |
typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
|
marci@168
|
985 |
|
marci@174
|
986 |
typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
|
marci@168
|
987 |
typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
|
marci@168
|
988 |
//typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
|
marci@168
|
989 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
990 |
typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
|
marci@168
|
991 |
|
marci@168
|
992 |
//FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
|
marci@168
|
993 |
|
marci@168
|
994 |
public:
|
marci@168
|
995 |
FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
|
marci@168
|
996 |
const CapacityMap& _capacity) :
|
marci@199
|
997 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) {
|
marci@168
|
998 |
}
|
marci@168
|
999 |
|
marci@212
|
1000 |
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@212
|
1001 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
|
marci@199
|
1002 |
while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
|
marci@168
|
1003 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
|
marci@168
|
1004 |
return e;
|
marci@168
|
1005 |
}
|
marci@168
|
1006 |
|
marci@174
|
1007 |
NodeIt& next(NodeIt& e) const {
|
marci@168
|
1008 |
return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
|
marci@168
|
1009 |
}
|
marci@168
|
1010 |
|
marci@168
|
1011 |
OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@168
|
1012 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
|
marci@199
|
1013 |
while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
|
marci@168
|
1014 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
|
marci@168
|
1015 |
return e;
|
marci@168
|
1016 |
}
|
marci@168
|
1017 |
|
marci@212
|
1018 |
NodeIt& first(NodeIt& n) const {
|
marci@212
|
1019 |
return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
|
marci@168
|
1020 |
}
|
marci@168
|
1021 |
|
marci@174
|
1022 |
void erase(const Edge& e) {
|
marci@168
|
1023 |
OutEdgeIt f(e);
|
marci@168
|
1024 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
|
marci@199
|
1025 |
while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
|
marci@168
|
1026 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
|
marci@168
|
1027 |
first_out_edges.set(this->tail(e), f);
|
marci@168
|
1028 |
}
|
marci@168
|
1029 |
|
marci@168
|
1030 |
//TrivGraphWrapper() : graph(0) { }
|
marci@168
|
1031 |
//TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@168
|
1032 |
|
marci@168
|
1033 |
//void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@168
|
1034 |
//Graph& getGraph() const { return (*graph); }
|
marci@168
|
1035 |
|
marci@212
|
1036 |
//template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@212
|
1037 |
//template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
1038 |
// return graph->first(i, p); }
|
marci@168
|
1039 |
|
marci@168
|
1040 |
//template<typename I> I getNext(const I& i) const {
|
marci@168
|
1041 |
// return graph->getNext(i); }
|
marci@168
|
1042 |
//template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@168
|
1043 |
|
marci@168
|
1044 |
template< typename It > It first() const {
|
marci@212
|
1045 |
It e; first(e); return e; }
|
marci@168
|
1046 |
|
marci@174
|
1047 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
1048 |
It e; first(e, v); return e; }
|
marci@168
|
1049 |
|
marci@174
|
1050 |
//Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
1051 |
//Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@168
|
1052 |
|
marci@168
|
1053 |
//template<typename I> bool valid(const I& i) const
|
marci@168
|
1054 |
// { return graph->valid(i); }
|
marci@168
|
1055 |
|
marci@168
|
1056 |
//template<typename I> void setInvalid(const I &i);
|
marci@168
|
1057 |
//{ return graph->setInvalid(i); }
|
marci@168
|
1058 |
|
marci@168
|
1059 |
//int nodeNum() const { return graph->nodeNum(); }
|
marci@168
|
1060 |
//int edgeNum() const { return graph->edgeNum(); }
|
marci@168
|
1061 |
|
marci@174
|
1062 |
//template<typename I> Node aNode(const I& e) const {
|
marci@168
|
1063 |
// return graph->aNode(e); }
|
marci@174
|
1064 |
//template<typename I> Node bNode(const I& e) const {
|
marci@168
|
1065 |
// return graph->bNode(e); }
|
marci@168
|
1066 |
|
marci@174
|
1067 |
//Node addNode() const { return graph->addNode(); }
|
marci@174
|
1068 |
//Edge addEdge(const Node& tail, const Node& head) const {
|
marci@168
|
1069 |
// return graph->addEdge(tail, head); }
|
marci@168
|
1070 |
|
marci@168
|
1071 |
//template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@168
|
1072 |
|
marci@168
|
1073 |
//void clear() const { graph->clear(); }
|
marci@168
|
1074 |
|
marci@168
|
1075 |
template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
|
marci@168
|
1076 |
public:
|
marci@168
|
1077 |
NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
|
marci@168
|
1078 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
|
marci@168
|
1079 |
NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
|
marci@168
|
1080 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
|
marci@168
|
1081 |
};
|
marci@168
|
1082 |
|
marci@168
|
1083 |
template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
|
marci@168
|
1084 |
public:
|
marci@168
|
1085 |
EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
|
marci@168
|
1086 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
|
marci@168
|
1087 |
EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
|
marci@168
|
1088 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
|
marci@168
|
1089 |
};
|
marci@168
|
1090 |
|
marci@168
|
1091 |
public:
|
marci@168
|
1092 |
ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
|
marci@155
|
1093 |
|
marci@76
|
1094 |
};
|
marci@76
|
1095 |
|
marci@76
|
1096 |
|
marci@148
|
1097 |
|
marci@148
|
1098 |
// // FIXME: comparison should be made better!!!
|
marci@148
|
1099 |
// template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
|
marci@148
|
1100 |
// class ResGraphWrapper
|
marci@148
|
1101 |
// {
|
marci@148
|
1102 |
// Graph* graph;
|
marci@76
|
1103 |
|
marci@148
|
1104 |
// public:
|
marci@148
|
1105 |
// typedef Graph BaseGraph;
|
marci@76
|
1106 |
|
marci@174
|
1107 |
// typedef typename Graph::Node Node;
|
marci@174
|
1108 |
// typedef typename Graph::Edge Edge;
|
marci@174
|
1109 |
|
marci@148
|
1110 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@76
|
1111 |
|
marci@148
|
1112 |
// class OutEdgeIt {
|
marci@148
|
1113 |
// public:
|
marci@174
|
1114 |
// //Graph::Node n;
|
marci@148
|
1115 |
// bool out_or_in;
|
marci@148
|
1116 |
// typename Graph::OutEdgeIt o;
|
marci@148
|
1117 |
// typename Graph::InEdgeIt i;
|
marci@148
|
1118 |
// };
|
marci@148
|
1119 |
// class InEdgeIt {
|
marci@148
|
1120 |
// public:
|
marci@174
|
1121 |
// //Graph::Node n;
|
marci@148
|
1122 |
// bool out_or_in;
|
marci@148
|
1123 |
// typename Graph::OutEdgeIt o;
|
marci@148
|
1124 |
// typename Graph::InEdgeIt i;
|
marci@148
|
1125 |
// };
|
marci@148
|
1126 |
// typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
1127 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@76
|
1128 |
|
marci@148
|
1129 |
// int nodeNum() const { return graph->nodeNum(); }
|
marci@148
|
1130 |
// int edgeNum() const { return graph->edgeNum(); }
|
marci@76
|
1131 |
|
marci@212
|
1132 |
// Node& first(Node& n) const { return graph->first(n); }
|
marci@76
|
1133 |
|
marci@174
|
1134 |
// // Edge and SymEdge is missing!!!!
|
marci@174
|
1135 |
// // Edge <-> In/OutEdgeIt conversion is missing!!!!
|
marci@76
|
1136 |
|
marci@148
|
1137 |
// //FIXME
|
marci@212
|
1138 |
// OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
|
marci@148
|
1139 |
// {
|
marci@148
|
1140 |
// e.n=n;
|
marci@212
|
1141 |
// graph->first(e.o,n);
|
marci@148
|
1142 |
// while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
|
marci@148
|
1143 |
// graph->goNext(e.o);
|
marci@148
|
1144 |
// if(!graph->valid(e.o)) {
|
marci@212
|
1145 |
// graph->first(e.i,n);
|
marci@148
|
1146 |
// while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
|
marci@148
|
1147 |
// graph->goNext(e.i);
|
marci@148
|
1148 |
// }
|
marci@148
|
1149 |
// return e;
|
marci@148
|
1150 |
// }
|
marci@148
|
1151 |
// /*
|
marci@148
|
1152 |
// OutEdgeIt &goNext(OutEdgeIt &e)
|
marci@148
|
1153 |
// {
|
marci@148
|
1154 |
// if(graph->valid(e.o)) {
|
marci@148
|
1155 |
// while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
|
marci@148
|
1156 |
// graph->goNext(e.o);
|
marci@148
|
1157 |
// if(graph->valid(e.o)) return e;
|
marci@212
|
1158 |
// else graph->first(e.i,e.n);
|
marci@148
|
1159 |
// }
|
marci@148
|
1160 |
// else {
|
marci@148
|
1161 |
// while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
|
marci@148
|
1162 |
// graph->goNext(e.i);
|
marci@148
|
1163 |
// return e;
|
marci@148
|
1164 |
// }
|
marci@148
|
1165 |
// }
|
marci@148
|
1166 |
// OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
|
marci@148
|
1167 |
// */
|
marci@148
|
1168 |
// //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
|
marci@76
|
1169 |
|
marci@148
|
1170 |
// //FIXME
|
marci@212
|
1171 |
// InEdgeIt& first(InEdgeIt& e, const Node& n) const
|
marci@148
|
1172 |
// {
|
marci@148
|
1173 |
// e.n=n;
|
marci@212
|
1174 |
// graph->first(e.i,n);
|
marci@148
|
1175 |
// while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
|
marci@148
|
1176 |
// graph->goNext(e.i);
|
marci@148
|
1177 |
// if(!graph->valid(e.i)) {
|
marci@212
|
1178 |
// graph->first(e.o,n);
|
marci@148
|
1179 |
// while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
|
marci@148
|
1180 |
// graph->goNext(e.o);
|
marci@148
|
1181 |
// }
|
marci@148
|
1182 |
// return e;
|
marci@148
|
1183 |
// }
|
marci@148
|
1184 |
// /*
|
marci@148
|
1185 |
// InEdgeIt &goNext(InEdgeIt &e)
|
marci@148
|
1186 |
// {
|
marci@148
|
1187 |
// if(graph->valid(e.i)) {
|
marci@148
|
1188 |
// while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
|
marci@148
|
1189 |
// graph->goNext(e.i);
|
marci@148
|
1190 |
// if(graph->valid(e.i)) return e;
|
marci@212
|
1191 |
// else graph->first(e.o,e.n);
|
marci@148
|
1192 |
// }
|
marci@148
|
1193 |
// else {
|
marci@148
|
1194 |
// while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
|
marci@148
|
1195 |
// graph->goNext(e.o);
|
marci@148
|
1196 |
// return e;
|
marci@148
|
1197 |
// }
|
marci@148
|
1198 |
// }
|
marci@148
|
1199 |
// InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
|
marci@148
|
1200 |
// */
|
marci@148
|
1201 |
// //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
|
marci@76
|
1202 |
|
marci@148
|
1203 |
// //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
|
marci@148
|
1204 |
// //template<typename I> I next(const I i); { return graph->goNext(i); }
|
marci@76
|
1205 |
|
marci@148
|
1206 |
// template< typename It > It first() const {
|
marci@212
|
1207 |
// It e; first(e); return e; }
|
marci@76
|
1208 |
|
marci@174
|
1209 |
// template< typename It > It first(Node v) const {
|
marci@212
|
1210 |
// It e; first(e, v); return e; }
|
marci@76
|
1211 |
|
marci@174
|
1212 |
// Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
1213 |
// Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@76
|
1214 |
|
marci@174
|
1215 |
// template<typename I> Node aNode(const I& e) const {
|
marci@148
|
1216 |
// return graph->aNode(e); }
|
marci@174
|
1217 |
// template<typename I> Node bNode(const I& e) const {
|
marci@148
|
1218 |
// return graph->bNode(e); }
|
marci@76
|
1219 |
|
marci@148
|
1220 |
// //template<typename I> bool valid(const I i);
|
marci@148
|
1221 |
// //{ return graph->valid(i); }
|
marci@76
|
1222 |
|
marci@148
|
1223 |
// //template<typename I> void setInvalid(const I &i);
|
marci@148
|
1224 |
// //{ return graph->setInvalid(i); }
|
marci@76
|
1225 |
|
marci@174
|
1226 |
// Node addNode() { return graph->addNode(); }
|
marci@174
|
1227 |
// Edge addEdge(const Node& tail, const Node& head) {
|
marci@148
|
1228 |
// return graph->addEdge(tail, head); }
|
marci@76
|
1229 |
|
marci@148
|
1230 |
// template<typename I> void erase(const I& i) { graph->erase(i); }
|
marci@76
|
1231 |
|
marci@148
|
1232 |
// void clear() { graph->clear(); }
|
marci@76
|
1233 |
|
marci@148
|
1234 |
// template<typename S> class NodeMap : public Graph::NodeMap<S> { };
|
marci@148
|
1235 |
// template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
|
marci@76
|
1236 |
|
marci@148
|
1237 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@148
|
1238 |
// Graph& getGraph() { return (*graph); }
|
marci@76
|
1239 |
|
marci@148
|
1240 |
// //ResGraphWrapper() : graph(0) { }
|
marci@148
|
1241 |
// ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@148
|
1242 |
// };
|
marci@76
|
1243 |
|
alpar@105
|
1244 |
} //namespace hugo
|
marci@76
|
1245 |
|
marci@76
|
1246 |
#endif //GRAPH_WRAPPER_H
|
marci@76
|
1247 |
|