alpar@906
|
1 |
/* -*- C++ -*-
|
ladanyi@1435
|
2 |
* lemon/default_map.h - Part of LEMON, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@1875
|
4 |
* Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1359
|
5 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
alpar@921
|
17 |
#ifndef LEMON_DEFAULT_MAP_H
|
alpar@921
|
18 |
#define LEMON_DEFAULT_MAP_H
|
deba@822
|
19 |
|
deba@822
|
20 |
|
deba@1307
|
21 |
#include <lemon/bits/array_map.h>
|
deba@1307
|
22 |
#include <lemon/bits/vector_map.h>
|
deba@822
|
23 |
|
alpar@1587
|
24 |
///\ingroup graphmapfactory
|
deba@822
|
25 |
///\file
|
klao@946
|
26 |
///\brief Graph maps that construct and destruct
|
deba@822
|
27 |
///their elements dynamically.
|
deba@822
|
28 |
|
alpar@921
|
29 |
namespace lemon {
|
deba@822
|
30 |
|
deba@822
|
31 |
|
deba@1267
|
32 |
template <typename _Graph, typename _Item, typename _Value>
|
klao@946
|
33 |
struct DefaultMapSelector {
|
deba@1267
|
34 |
typedef ArrayMap<_Graph, _Item, _Value> Map;
|
klao@946
|
35 |
};
|
deba@822
|
36 |
|
klao@946
|
37 |
// bool
|
deba@1267
|
38 |
template <typename _Graph, typename _Item>
|
deba@1267
|
39 |
struct DefaultMapSelector<_Graph, _Item, bool> {
|
deba@980
|
40 |
typedef VectorMap<_Graph, _Item, bool> Map;
|
klao@946
|
41 |
};
|
deba@822
|
42 |
|
klao@946
|
43 |
// char
|
deba@1267
|
44 |
template <typename _Graph, typename _Item>
|
deba@1267
|
45 |
struct DefaultMapSelector<_Graph, _Item, char> {
|
deba@980
|
46 |
typedef VectorMap<_Graph, _Item, char> Map;
|
klao@946
|
47 |
};
|
deba@822
|
48 |
|
deba@1267
|
49 |
template <typename _Graph, typename _Item>
|
deba@1267
|
50 |
struct DefaultMapSelector<_Graph, _Item, signed char> {
|
deba@980
|
51 |
typedef VectorMap<_Graph, _Item, signed char> Map;
|
klao@946
|
52 |
};
|
deba@822
|
53 |
|
deba@1267
|
54 |
template <typename _Graph, typename _Item>
|
deba@1267
|
55 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> {
|
deba@980
|
56 |
typedef VectorMap<_Graph, _Item, unsigned char> Map;
|
klao@946
|
57 |
};
|
deba@822
|
58 |
|
deba@822
|
59 |
|
klao@946
|
60 |
// int
|
deba@1267
|
61 |
template <typename _Graph, typename _Item>
|
deba@1267
|
62 |
struct DefaultMapSelector<_Graph, _Item, signed int> {
|
deba@980
|
63 |
typedef VectorMap<_Graph, _Item, signed int> Map;
|
klao@946
|
64 |
};
|
deba@822
|
65 |
|
deba@1267
|
66 |
template <typename _Graph, typename _Item>
|
deba@1267
|
67 |
struct DefaultMapSelector<_Graph, _Item, unsigned int> {
|
deba@980
|
68 |
typedef VectorMap<_Graph, _Item, unsigned int> Map;
|
klao@946
|
69 |
};
|
deba@822
|
70 |
|
deba@822
|
71 |
|
klao@946
|
72 |
// short
|
deba@1267
|
73 |
template <typename _Graph, typename _Item>
|
deba@1267
|
74 |
struct DefaultMapSelector<_Graph, _Item, signed short> {
|
deba@980
|
75 |
typedef VectorMap<_Graph, _Item, signed short> Map;
|
klao@946
|
76 |
};
|
deba@822
|
77 |
|
deba@1267
|
78 |
template <typename _Graph, typename _Item>
|
deba@1267
|
79 |
struct DefaultMapSelector<_Graph, _Item, unsigned short> {
|
deba@980
|
80 |
typedef VectorMap<_Graph, _Item, unsigned short> Map;
|
klao@946
|
81 |
};
|
klao@946
|
82 |
|
klao@946
|
83 |
|
klao@946
|
84 |
// long
|
deba@1267
|
85 |
template <typename _Graph, typename _Item>
|
deba@1267
|
86 |
struct DefaultMapSelector<_Graph, _Item, signed long> {
|
deba@980
|
87 |
typedef VectorMap<_Graph, _Item, signed long> Map;
|
klao@946
|
88 |
};
|
klao@946
|
89 |
|
deba@1267
|
90 |
template <typename _Graph, typename _Item>
|
deba@1267
|
91 |
struct DefaultMapSelector<_Graph, _Item, unsigned long> {
|
deba@980
|
92 |
typedef VectorMap<_Graph, _Item, unsigned long> Map;
|
klao@946
|
93 |
};
|
klao@946
|
94 |
|
klao@946
|
95 |
// \todo handling long long type
|
klao@946
|
96 |
|
klao@946
|
97 |
|
klao@946
|
98 |
// float
|
deba@1267
|
99 |
template <typename _Graph, typename _Item>
|
deba@1267
|
100 |
struct DefaultMapSelector<_Graph, _Item, float> {
|
deba@980
|
101 |
typedef VectorMap<_Graph, _Item, float> Map;
|
klao@946
|
102 |
};
|
klao@946
|
103 |
|
klao@946
|
104 |
|
klao@946
|
105 |
// double
|
deba@1267
|
106 |
template <typename _Graph, typename _Item>
|
deba@1267
|
107 |
struct DefaultMapSelector<_Graph, _Item, double> {
|
deba@980
|
108 |
typedef VectorMap<_Graph, _Item, double> Map;
|
klao@946
|
109 |
};
|
klao@946
|
110 |
|
klao@946
|
111 |
|
klao@946
|
112 |
// long double
|
deba@1267
|
113 |
template <typename _Graph, typename _Item>
|
deba@1267
|
114 |
struct DefaultMapSelector<_Graph, _Item, long double> {
|
deba@980
|
115 |
typedef VectorMap<_Graph, _Item, long double> Map;
|
klao@946
|
116 |
};
|
klao@946
|
117 |
|
klao@946
|
118 |
|
klao@946
|
119 |
// pointer
|
deba@1267
|
120 |
template <typename _Graph, typename _Item, typename _Ptr>
|
deba@1267
|
121 |
struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
|
deba@980
|
122 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map;
|
klao@946
|
123 |
};
|
klao@946
|
124 |
|
deba@1669
|
125 |
/// \e
|
deba@1267
|
126 |
template <
|
deba@1267
|
127 |
typename _Graph,
|
deba@1267
|
128 |
typename _Item,
|
deba@1267
|
129 |
typename _Value>
|
deba@1267
|
130 |
class DefaultMap
|
deba@1267
|
131 |
: public DefaultMapSelector<_Graph, _Item, _Value>::Map {
|
klao@946
|
132 |
public:
|
deba@1267
|
133 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
|
deba@1267
|
134 |
typedef DefaultMap<_Graph, _Item, _Value> Map;
|
klao@946
|
135 |
|
klao@946
|
136 |
typedef typename Parent::Graph Graph;
|
alpar@987
|
137 |
typedef typename Parent::Value Value;
|
klao@946
|
138 |
|
deba@980
|
139 |
DefaultMap(const Graph& _g) : Parent(_g) {}
|
alpar@987
|
140 |
DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
|
deba@1669
|
141 |
|
klao@946
|
142 |
};
|
klao@946
|
143 |
|
klao@946
|
144 |
|
deba@1669
|
145 |
/// \e
|
klao@946
|
146 |
template <typename _Base>
|
deba@1669
|
147 |
class MappableGraphExtender : public _Base {
|
klao@946
|
148 |
public:
|
klao@946
|
149 |
|
deba@1669
|
150 |
typedef MappableGraphExtender<_Base> Graph;
|
klao@946
|
151 |
typedef _Base Parent;
|
klao@946
|
152 |
|
klao@946
|
153 |
typedef typename Parent::Node Node;
|
klao@946
|
154 |
typedef typename Parent::NodeIt NodeIt;
|
klao@946
|
155 |
|
klao@946
|
156 |
typedef typename Parent::Edge Edge;
|
klao@946
|
157 |
typedef typename Parent::EdgeIt EdgeIt;
|
klao@946
|
158 |
|
klao@946
|
159 |
|
klao@946
|
160 |
template <typename _Value>
|
deba@1267
|
161 |
class NodeMap
|
deba@1267
|
162 |
: public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
|
klao@946
|
163 |
public:
|
deba@1669
|
164 |
typedef MappableGraphExtender Graph;
|
deba@1267
|
165 |
typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
klao@946
|
166 |
|
deba@980
|
167 |
NodeMap(const Graph& _g)
|
deba@980
|
168 |
: Parent(_g) {}
|
klao@1022
|
169 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@980
|
170 |
: Parent(_g, _v) {}
|
deba@1669
|
171 |
|
deba@1672
|
172 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1672
|
173 |
return operator=<NodeMap>(cmap);
|
deba@1672
|
174 |
}
|
deba@1672
|
175 |
|
deba@1672
|
176 |
|
deba@1669
|
177 |
/// \brief Template assign operator.
|
deba@1669
|
178 |
///
|
deba@1669
|
179 |
/// The given parameter should be conform to the ReadMap
|
deba@1669
|
180 |
/// concecpt and could be indiced by the current item set of
|
deba@1669
|
181 |
/// the NodeMap. In this case the value for each item
|
deba@1669
|
182 |
/// is assigned by the value of the given ReadMap.
|
deba@1669
|
183 |
template <typename CMap>
|
deba@1669
|
184 |
NodeMap& operator=(const CMap& cmap) {
|
deba@1669
|
185 |
checkConcept<concept::ReadMap<Node, _Value>, CMap>();
|
deba@1669
|
186 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1669
|
187 |
Node it;
|
deba@1669
|
188 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1669
|
189 |
Parent::set(it, cmap[it]);
|
deba@1669
|
190 |
}
|
deba@1669
|
191 |
return *this;
|
deba@1669
|
192 |
}
|
deba@1669
|
193 |
|
klao@946
|
194 |
};
|
klao@946
|
195 |
|
klao@946
|
196 |
template <typename _Value>
|
deba@1267
|
197 |
class EdgeMap
|
deba@1267
|
198 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
klao@946
|
199 |
public:
|
deba@1669
|
200 |
typedef MappableGraphExtender Graph;
|
deba@1267
|
201 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
klao@946
|
202 |
|
deba@980
|
203 |
EdgeMap(const Graph& _g)
|
deba@980
|
204 |
: Parent(_g) {}
|
klao@1022
|
205 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@980
|
206 |
: Parent(_g, _v) {}
|
deba@1669
|
207 |
|
deba@1672
|
208 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1672
|
209 |
return operator=<EdgeMap>(cmap);
|
deba@1672
|
210 |
}
|
deba@1672
|
211 |
|
deba@1669
|
212 |
template <typename CMap>
|
deba@1669
|
213 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1669
|
214 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1669
|
215 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1669
|
216 |
Edge it;
|
deba@1669
|
217 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1669
|
218 |
Parent::set(it, cmap[it]);
|
deba@1669
|
219 |
}
|
deba@1669
|
220 |
return *this;
|
deba@1669
|
221 |
}
|
klao@946
|
222 |
};
|
klao@946
|
223 |
|
klao@946
|
224 |
};
|
klao@946
|
225 |
|
deba@1669
|
226 |
/// \e
|
klao@1022
|
227 |
template <typename _Base>
|
deba@1842
|
228 |
class MappableEdgeSetExtender : public _Base {
|
deba@1842
|
229 |
public:
|
deba@1842
|
230 |
|
deba@1842
|
231 |
typedef MappableEdgeSetExtender<_Base> Graph;
|
deba@1842
|
232 |
typedef _Base Parent;
|
deba@1842
|
233 |
|
deba@1842
|
234 |
typedef typename Parent::Edge Edge;
|
deba@1842
|
235 |
typedef typename Parent::EdgeIt EdgeIt;
|
deba@1842
|
236 |
|
deba@1842
|
237 |
template <typename _Value>
|
deba@1842
|
238 |
class EdgeMap
|
deba@1842
|
239 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1842
|
240 |
public:
|
deba@1842
|
241 |
typedef MappableEdgeSetExtender Graph;
|
deba@1842
|
242 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1842
|
243 |
|
deba@1842
|
244 |
EdgeMap(const Graph& _g)
|
deba@1842
|
245 |
: Parent(_g) {}
|
deba@1842
|
246 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@1842
|
247 |
: Parent(_g, _v) {}
|
deba@1842
|
248 |
|
deba@1842
|
249 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1842
|
250 |
return operator=<EdgeMap>(cmap);
|
deba@1842
|
251 |
}
|
deba@1842
|
252 |
|
deba@1842
|
253 |
template <typename CMap>
|
deba@1842
|
254 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1842
|
255 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1842
|
256 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1842
|
257 |
Edge it;
|
deba@1842
|
258 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1842
|
259 |
Parent::set(it, cmap[it]);
|
deba@1842
|
260 |
}
|
deba@1842
|
261 |
return *this;
|
deba@1842
|
262 |
}
|
deba@1842
|
263 |
};
|
deba@1842
|
264 |
|
deba@1842
|
265 |
};
|
deba@1842
|
266 |
|
deba@1842
|
267 |
/// \e
|
deba@1842
|
268 |
template <typename _Base>
|
klao@1909
|
269 |
class MappableUGraphExtender :
|
deba@1669
|
270 |
public MappableGraphExtender<_Base> {
|
klao@1022
|
271 |
public:
|
klao@1022
|
272 |
|
klao@1909
|
273 |
typedef MappableUGraphExtender Graph;
|
deba@1669
|
274 |
typedef MappableGraphExtender<_Base> Parent;
|
klao@1022
|
275 |
|
klao@1909
|
276 |
typedef typename Parent::UEdge UEdge;
|
klao@1022
|
277 |
|
klao@1022
|
278 |
template <typename _Value>
|
klao@1909
|
279 |
class UEdgeMap
|
klao@1909
|
280 |
: public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
klao@1022
|
281 |
public:
|
klao@1909
|
282 |
typedef MappableUGraphExtender Graph;
|
deba@1267
|
283 |
typedef IterableMapExtender<
|
klao@1909
|
284 |
DefaultMap<Graph, UEdge, _Value> > Parent;
|
klao@1022
|
285 |
|
klao@1909
|
286 |
UEdgeMap(const Graph& _g)
|
klao@1022
|
287 |
: Parent(_g) {}
|
klao@1909
|
288 |
UEdgeMap(const Graph& _g, const _Value& _v)
|
klao@1022
|
289 |
: Parent(_g, _v) {}
|
deba@1669
|
290 |
|
klao@1909
|
291 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
klao@1909
|
292 |
return operator=<UEdgeMap>(cmap);
|
deba@1672
|
293 |
}
|
deba@1672
|
294 |
|
deba@1669
|
295 |
template <typename CMap>
|
klao@1909
|
296 |
UEdgeMap& operator=(const CMap& cmap) {
|
klao@1909
|
297 |
checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
|
deba@1669
|
298 |
const typename Parent::Graph* graph = Parent::getGraph();
|
klao@1909
|
299 |
UEdge it;
|
deba@1669
|
300 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1669
|
301 |
Parent::set(it, cmap[it]);
|
deba@1669
|
302 |
}
|
deba@1669
|
303 |
return *this;
|
deba@1669
|
304 |
}
|
klao@1022
|
305 |
};
|
klao@1022
|
306 |
|
klao@1022
|
307 |
|
klao@1022
|
308 |
};
|
deba@822
|
309 |
|
deba@1842
|
310 |
/// \e
|
deba@1842
|
311 |
template <typename _Base>
|
klao@1909
|
312 |
class MappableUEdgeSetExtender :
|
deba@1842
|
313 |
public MappableEdgeSetExtender<_Base> {
|
deba@1842
|
314 |
public:
|
deba@1842
|
315 |
|
klao@1909
|
316 |
typedef MappableUEdgeSetExtender Graph;
|
deba@1842
|
317 |
typedef MappableEdgeSetExtender<_Base> Parent;
|
deba@1842
|
318 |
|
klao@1909
|
319 |
typedef typename Parent::UEdge UEdge;
|
deba@1842
|
320 |
|
deba@1842
|
321 |
template <typename _Value>
|
klao@1909
|
322 |
class UEdgeMap
|
klao@1909
|
323 |
: public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@1842
|
324 |
public:
|
klao@1909
|
325 |
typedef MappableUEdgeSetExtender Graph;
|
deba@1842
|
326 |
typedef IterableMapExtender<
|
klao@1909
|
327 |
DefaultMap<Graph, UEdge, _Value> > Parent;
|
deba@1842
|
328 |
|
klao@1909
|
329 |
UEdgeMap(const Graph& _g)
|
deba@1842
|
330 |
: Parent(_g) {}
|
klao@1909
|
331 |
UEdgeMap(const Graph& _g, const _Value& _v)
|
deba@1842
|
332 |
: Parent(_g, _v) {}
|
deba@1842
|
333 |
|
klao@1909
|
334 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
klao@1909
|
335 |
return operator=<UEdgeMap>(cmap);
|
deba@1842
|
336 |
}
|
deba@1842
|
337 |
|
deba@1842
|
338 |
template <typename CMap>
|
klao@1909
|
339 |
UEdgeMap& operator=(const CMap& cmap) {
|
klao@1909
|
340 |
checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
|
deba@1842
|
341 |
const typename Parent::Graph* graph = Parent::getGraph();
|
klao@1909
|
342 |
UEdge it;
|
deba@1842
|
343 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1842
|
344 |
Parent::set(it, cmap[it]);
|
deba@1842
|
345 |
}
|
deba@1842
|
346 |
return *this;
|
deba@1842
|
347 |
}
|
deba@1842
|
348 |
};
|
deba@1842
|
349 |
|
deba@1842
|
350 |
|
deba@1842
|
351 |
};
|
deba@1842
|
352 |
|
deba@1820
|
353 |
|
deba@1820
|
354 |
template <typename _Base>
|
klao@1909
|
355 |
class MappableUBipartiteGraphExtender : public _Base {
|
deba@1820
|
356 |
public:
|
deba@1820
|
357 |
|
deba@1820
|
358 |
typedef _Base Parent;
|
klao@1909
|
359 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
360 |
|
deba@1820
|
361 |
typedef typename Parent::Node Node;
|
deba@1820
|
362 |
typedef typename Parent::UpperNode UpperNode;
|
deba@1820
|
363 |
typedef typename Parent::LowerNode LowerNode;
|
deba@1820
|
364 |
typedef typename Parent::Edge Edge;
|
klao@1909
|
365 |
typedef typename Parent::UEdge UEdge;
|
deba@1820
|
366 |
|
deba@1820
|
367 |
template <typename _Value>
|
deba@1820
|
368 |
class UpperNodeMap
|
deba@1820
|
369 |
: public IterableMapExtender<DefaultMap<Graph, UpperNode, _Value> > {
|
deba@1820
|
370 |
public:
|
klao@1909
|
371 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
372 |
typedef IterableMapExtender<DefaultMap<Graph, UpperNode, _Value> >
|
deba@1820
|
373 |
Parent;
|
deba@1820
|
374 |
|
deba@1820
|
375 |
UpperNodeMap(const Graph& _g)
|
deba@1820
|
376 |
: Parent(_g) {}
|
deba@1820
|
377 |
UpperNodeMap(const Graph& _g, const _Value& _v)
|
deba@1820
|
378 |
: Parent(_g, _v) {}
|
deba@1820
|
379 |
|
deba@1820
|
380 |
UpperNodeMap& operator=(const UpperNodeMap& cmap) {
|
deba@1820
|
381 |
return operator=<UpperNodeMap>(cmap);
|
deba@1820
|
382 |
}
|
deba@1820
|
383 |
|
deba@1820
|
384 |
|
deba@1820
|
385 |
/// \brief Template assign operator.
|
deba@1820
|
386 |
///
|
deba@1820
|
387 |
/// The given parameter should be conform to the ReadMap
|
deba@1820
|
388 |
/// concept and could be indiced by the current item set of
|
deba@1820
|
389 |
/// the UpperNodeMap. In this case the value for each item
|
deba@1820
|
390 |
/// is assigned by the value of the given ReadMap.
|
deba@1820
|
391 |
template <typename CMap>
|
deba@1820
|
392 |
UpperNodeMap& operator=(const CMap& cmap) {
|
deba@1820
|
393 |
checkConcept<concept::ReadMap<UpperNode, _Value>, CMap>();
|
deba@1820
|
394 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1820
|
395 |
UpperNode it;
|
deba@1820
|
396 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1820
|
397 |
Parent::set(it, cmap[it]);
|
deba@1820
|
398 |
}
|
deba@1820
|
399 |
return *this;
|
deba@1820
|
400 |
}
|
deba@1820
|
401 |
|
deba@1820
|
402 |
};
|
deba@1820
|
403 |
|
deba@1820
|
404 |
template <typename _Value>
|
deba@1820
|
405 |
class LowerNodeMap
|
deba@1820
|
406 |
: public IterableMapExtender<DefaultMap<Graph, LowerNode, _Value> > {
|
deba@1820
|
407 |
public:
|
klao@1909
|
408 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
409 |
typedef IterableMapExtender<DefaultMap<Graph, LowerNode, _Value> >
|
deba@1820
|
410 |
Parent;
|
deba@1820
|
411 |
|
deba@1820
|
412 |
LowerNodeMap(const Graph& _g)
|
deba@1820
|
413 |
: Parent(_g) {}
|
deba@1820
|
414 |
LowerNodeMap(const Graph& _g, const _Value& _v)
|
deba@1820
|
415 |
: Parent(_g, _v) {}
|
deba@1820
|
416 |
|
deba@1820
|
417 |
LowerNodeMap& operator=(const LowerNodeMap& cmap) {
|
deba@1820
|
418 |
return operator=<LowerNodeMap>(cmap);
|
deba@1820
|
419 |
}
|
deba@1820
|
420 |
|
deba@1820
|
421 |
|
deba@1820
|
422 |
/// \brief Template assign operator.
|
deba@1820
|
423 |
///
|
deba@1820
|
424 |
/// The given parameter should be conform to the ReadMap
|
deba@1820
|
425 |
/// concept and could be indiced by the current item set of
|
deba@1820
|
426 |
/// the LowerNodeMap. In this case the value for each item
|
deba@1820
|
427 |
/// is assigned by the value of the given ReadMap.
|
deba@1820
|
428 |
template <typename CMap>
|
deba@1820
|
429 |
LowerNodeMap& operator=(const CMap& cmap) {
|
deba@1820
|
430 |
checkConcept<concept::ReadMap<LowerNode, _Value>, CMap>();
|
deba@1820
|
431 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1820
|
432 |
LowerNode it;
|
deba@1820
|
433 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1820
|
434 |
Parent::set(it, cmap[it]);
|
deba@1820
|
435 |
}
|
deba@1820
|
436 |
return *this;
|
deba@1820
|
437 |
}
|
deba@1820
|
438 |
|
deba@1820
|
439 |
};
|
deba@1820
|
440 |
|
deba@1820
|
441 |
protected:
|
deba@1820
|
442 |
|
deba@1820
|
443 |
template <typename _Value>
|
deba@1820
|
444 |
class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
|
deba@1820
|
445 |
public:
|
klao@1909
|
446 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
447 |
|
deba@1820
|
448 |
typedef Node Key;
|
deba@1820
|
449 |
typedef _Value Value;
|
deba@1820
|
450 |
|
deba@1820
|
451 |
/// The reference type of the map;
|
deba@1820
|
452 |
typedef typename LowerNodeMap<_Value>::Reference Reference;
|
deba@1820
|
453 |
/// The pointer type of the map;
|
deba@1820
|
454 |
typedef typename LowerNodeMap<_Value>::Pointer Pointer;
|
deba@1820
|
455 |
|
deba@1820
|
456 |
/// The const value type of the map.
|
deba@1820
|
457 |
typedef const Value ConstValue;
|
deba@1820
|
458 |
/// The const reference type of the map;
|
deba@1820
|
459 |
typedef typename LowerNodeMap<_Value>::ConstReference ConstReference;
|
deba@1820
|
460 |
/// The pointer type of the map;
|
deba@1820
|
461 |
typedef typename LowerNodeMap<_Value>::ConstPointer ConstPointer;
|
deba@1820
|
462 |
|
deba@1820
|
463 |
typedef True ReferenceMapTag;
|
deba@1820
|
464 |
|
deba@1820
|
465 |
NodeMapBase(const Graph& _g)
|
deba@1820
|
466 |
: graph(&_g), lowerMap(_g), upperMap(_g) {
|
deba@1820
|
467 |
Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
|
deba@1820
|
468 |
}
|
deba@1820
|
469 |
NodeMapBase(const Graph& _g, const _Value& _v)
|
deba@1820
|
470 |
: graph(&_g), lowerMap(_g, _v),
|
deba@1820
|
471 |
upperMap(_g, _v) {
|
deba@1820
|
472 |
Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
|
deba@1820
|
473 |
}
|
deba@1820
|
474 |
|
deba@1820
|
475 |
virtual ~NodeMapBase() {
|
deba@1820
|
476 |
if (Parent::NodeNotifier::ObserverBase::attached()) {
|
deba@1820
|
477 |
Parent::NodeNotifier::ObserverBase::detach();
|
deba@1820
|
478 |
}
|
deba@1820
|
479 |
}
|
deba@1820
|
480 |
|
deba@1820
|
481 |
ConstReference operator[](const Key& node) const {
|
deba@1820
|
482 |
if (Parent::upper(node)) {
|
deba@1820
|
483 |
return upperMap[node];
|
deba@1820
|
484 |
} else {
|
deba@1820
|
485 |
return lowerMap[node];
|
deba@1820
|
486 |
}
|
deba@1820
|
487 |
}
|
deba@1820
|
488 |
|
deba@1820
|
489 |
Reference operator[](const Key& node) {
|
deba@1820
|
490 |
if (Parent::upper(node)) {
|
deba@1820
|
491 |
return upperMap[node];
|
deba@1820
|
492 |
} else {
|
deba@1820
|
493 |
return lowerMap[node];
|
deba@1820
|
494 |
}
|
deba@1820
|
495 |
}
|
deba@1820
|
496 |
|
deba@1820
|
497 |
void set(const Key& node, const Value& value) {
|
deba@1820
|
498 |
if (Parent::upper(node)) {
|
deba@1820
|
499 |
upperMap.set(node, value);
|
deba@1820
|
500 |
} else {
|
deba@1820
|
501 |
lowerMap.set(node, value);
|
deba@1820
|
502 |
}
|
deba@1820
|
503 |
}
|
deba@1820
|
504 |
|
deba@1820
|
505 |
protected:
|
deba@1820
|
506 |
|
deba@1820
|
507 |
virtual void add(const Node&) {}
|
deba@1820
|
508 |
virtual void erase(const Node&) {}
|
deba@1820
|
509 |
virtual void clear() {}
|
deba@1820
|
510 |
virtual void build() {}
|
deba@1820
|
511 |
|
deba@1820
|
512 |
const Graph* getGraph() const { return graph; }
|
deba@1820
|
513 |
|
deba@1820
|
514 |
private:
|
deba@1820
|
515 |
const Graph* graph;
|
deba@1820
|
516 |
LowerNodeMap<_Value> lowerMap;
|
deba@1820
|
517 |
UpperNodeMap<_Value> upperMap;
|
deba@1820
|
518 |
};
|
deba@1820
|
519 |
|
deba@1820
|
520 |
public:
|
deba@1820
|
521 |
|
deba@1820
|
522 |
template <typename _Value>
|
deba@1820
|
523 |
class NodeMap
|
deba@1820
|
524 |
: public IterableMapExtender<NodeMapBase<_Value> > {
|
deba@1820
|
525 |
public:
|
klao@1909
|
526 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
527 |
typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
|
deba@1820
|
528 |
|
deba@1820
|
529 |
NodeMap(const Graph& _g)
|
deba@1820
|
530 |
: Parent(_g) {}
|
deba@1820
|
531 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@1820
|
532 |
: Parent(_g, _v) {}
|
deba@1820
|
533 |
|
deba@1820
|
534 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1820
|
535 |
return operator=<NodeMap>(cmap);
|
deba@1820
|
536 |
}
|
deba@1820
|
537 |
|
deba@1820
|
538 |
|
deba@1820
|
539 |
/// \brief Template assign operator.
|
deba@1820
|
540 |
///
|
deba@1820
|
541 |
/// The given parameter should be conform to the ReadMap
|
deba@1820
|
542 |
/// concept and could be indiced by the current item set of
|
deba@1820
|
543 |
/// the NodeMap. In this case the value for each item
|
deba@1820
|
544 |
/// is assigned by the value of the given ReadMap.
|
deba@1820
|
545 |
template <typename CMap>
|
deba@1820
|
546 |
NodeMap& operator=(const CMap& cmap) {
|
deba@1820
|
547 |
checkConcept<concept::ReadMap<Node, _Value>, CMap>();
|
deba@1820
|
548 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1820
|
549 |
Node it;
|
deba@1820
|
550 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1820
|
551 |
Parent::set(it, cmap[it]);
|
deba@1820
|
552 |
}
|
deba@1820
|
553 |
return *this;
|
deba@1820
|
554 |
}
|
deba@1820
|
555 |
|
deba@1820
|
556 |
};
|
deba@1820
|
557 |
|
deba@1820
|
558 |
|
deba@1820
|
559 |
|
deba@1820
|
560 |
template <typename _Value>
|
deba@1820
|
561 |
class EdgeMap
|
deba@1820
|
562 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1820
|
563 |
public:
|
klao@1909
|
564 |
typedef MappableUBipartiteGraphExtender Graph;
|
deba@1820
|
565 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1820
|
566 |
|
deba@1820
|
567 |
EdgeMap(const Graph& _g)
|
deba@1820
|
568 |
: Parent(_g) {}
|
deba@1820
|
569 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@1820
|
570 |
: Parent(_g, _v) {}
|
deba@1820
|
571 |
|
deba@1820
|
572 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1820
|
573 |
return operator=<EdgeMap>(cmap);
|
deba@1820
|
574 |
}
|
deba@1820
|
575 |
|
deba@1820
|
576 |
template <typename CMap>
|
deba@1820
|
577 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1820
|
578 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1820
|
579 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1820
|
580 |
Edge it;
|
deba@1820
|
581 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1820
|
582 |
Parent::set(it, cmap[it]);
|
deba@1820
|
583 |
}
|
deba@1820
|
584 |
return *this;
|
deba@1820
|
585 |
}
|
deba@1820
|
586 |
};
|
deba@1820
|
587 |
|
deba@1820
|
588 |
template <typename _Value>
|
klao@1909
|
589 |
class UEdgeMap
|
klao@1909
|
590 |
: public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@1820
|
591 |
public:
|
klao@1909
|
592 |
typedef MappableUBipartiteGraphExtender Graph;
|
klao@1909
|
593 |
typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> >
|
deba@1820
|
594 |
Parent;
|
deba@1820
|
595 |
|
klao@1909
|
596 |
UEdgeMap(const Graph& _g)
|
deba@1820
|
597 |
: Parent(_g) {}
|
klao@1909
|
598 |
UEdgeMap(const Graph& _g, const _Value& _v)
|
deba@1820
|
599 |
: Parent(_g, _v) {}
|
deba@1820
|
600 |
|
klao@1909
|
601 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
klao@1909
|
602 |
return operator=<UEdgeMap>(cmap);
|
deba@1820
|
603 |
}
|
deba@1820
|
604 |
|
deba@1820
|
605 |
template <typename CMap>
|
klao@1909
|
606 |
UEdgeMap& operator=(const CMap& cmap) {
|
klao@1909
|
607 |
checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
|
deba@1820
|
608 |
const typename Parent::Graph* graph = Parent::getGraph();
|
klao@1909
|
609 |
UEdge it;
|
deba@1820
|
610 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1820
|
611 |
Parent::set(it, cmap[it]);
|
deba@1820
|
612 |
}
|
deba@1820
|
613 |
return *this;
|
deba@1820
|
614 |
}
|
deba@1820
|
615 |
};
|
deba@1820
|
616 |
|
deba@1820
|
617 |
};
|
deba@1820
|
618 |
|
deba@822
|
619 |
}
|
deba@822
|
620 |
|
deba@822
|
621 |
#endif
|