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