alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@906
|
2 |
* src/hugo/sym_map.h - Part of HUGOlib, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@906
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@906
|
5 |
* (Egervary Combinatorial Optimization Research Group, 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 |
|
marci@901
|
17 |
#ifndef HUGO_SYM_MAP_H
|
marci@901
|
18 |
#define HUGO_SYM_MAP_H
|
deba@822
|
19 |
|
deba@822
|
20 |
///\ingroup graphmaps
|
deba@822
|
21 |
///\file
|
deba@822
|
22 |
///\brief Graph maps that construates and destruates
|
deba@822
|
23 |
///their elements dynamically.
|
deba@822
|
24 |
|
deba@822
|
25 |
namespace hugo {
|
deba@822
|
26 |
|
deba@822
|
27 |
/// \addtogroup graphmaps
|
deba@822
|
28 |
/// @{
|
deba@822
|
29 |
|
deba@822
|
30 |
/** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
|
deba@822
|
31 |
* iterate on the symmetric maps when all of the edge - reverse edge pair
|
deba@822
|
32 |
* has different parity.
|
deba@822
|
33 |
*/
|
deba@822
|
34 |
|
deba@844
|
35 |
|
deba@822
|
36 |
template <typename Graph, typename Edge, typename EdgeIt>
|
deba@822
|
37 |
class SymEdgeIt : public EdgeIt {
|
deba@822
|
38 |
public:
|
deba@822
|
39 |
|
deba@822
|
40 |
/** Default constructor.
|
deba@822
|
41 |
*/
|
deba@822
|
42 |
SymEdgeIt()
|
deba@822
|
43 |
: EdgeIt() {}
|
deba@822
|
44 |
|
deba@822
|
45 |
/** Graph initialized constructor.
|
deba@822
|
46 |
*/
|
deba@822
|
47 |
SymEdgeIt(const Graph& graph)
|
deba@822
|
48 |
: EdgeIt(graph) {
|
deba@844
|
49 |
while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
|
deba@822
|
50 |
EdgeIt::operator++();
|
deba@822
|
51 |
}
|
deba@822
|
52 |
}
|
deba@822
|
53 |
|
deba@822
|
54 |
/** Creating invelid SymEdgeIt.
|
deba@822
|
55 |
*/
|
deba@822
|
56 |
SymEdgeIt(Invalid invalid)
|
deba@822
|
57 |
: EdgeIt(invalid) {}
|
deba@822
|
58 |
|
deba@822
|
59 |
/** SymEdgeIt from the given Edge.
|
deba@822
|
60 |
*/
|
deba@822
|
61 |
SymEdgeIt(const Graph& graph, const Edge& edge)
|
deba@822
|
62 |
: EdgeIt(graph, edge) {
|
deba@844
|
63 |
while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
|
deba@822
|
64 |
EdgeIt::operator++();
|
deba@822
|
65 |
}
|
deba@822
|
66 |
}
|
deba@822
|
67 |
|
deba@822
|
68 |
/** Increase operator.
|
deba@822
|
69 |
*/
|
deba@822
|
70 |
SymEdgeIt& operator++() {
|
deba@822
|
71 |
EdgeIt::operator++();
|
deba@844
|
72 |
while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
|
deba@822
|
73 |
EdgeIt::operator++();
|
deba@822
|
74 |
}
|
deba@822
|
75 |
return *this;
|
deba@822
|
76 |
}
|
deba@822
|
77 |
};
|
deba@822
|
78 |
|
deba@822
|
79 |
/** The SymMap template class is graph map structure what
|
deba@822
|
80 |
* wraps an other map structure to use as symmetric map structure.
|
deba@822
|
81 |
*
|
deba@822
|
82 |
* The template parameter is the MapRegistry that the maps
|
deba@822
|
83 |
* will belong to and the ValueType.
|
deba@822
|
84 |
*/
|
deba@822
|
85 |
template <template <typename, typename> class DynMap,
|
deba@822
|
86 |
typename MapRegistry, typename Value>
|
deba@822
|
87 |
class SymMap : public DynMap<MapRegistry, Value>{
|
deba@822
|
88 |
|
deba@822
|
89 |
private:
|
deba@822
|
90 |
|
deba@822
|
91 |
typedef DynMap<MapRegistry, Value> MapImpl;
|
deba@822
|
92 |
|
deba@822
|
93 |
public:
|
deba@822
|
94 |
|
deba@822
|
95 |
/// The graph type of the maps.
|
deba@822
|
96 |
typedef typename MapRegistry::Graph Graph;
|
deba@822
|
97 |
|
deba@822
|
98 |
typedef typename MapImpl::KeyType KeyType;
|
deba@822
|
99 |
|
deba@822
|
100 |
public:
|
deba@822
|
101 |
|
deba@822
|
102 |
|
deba@822
|
103 |
/** Graph and Registry initialized map constructor.
|
deba@822
|
104 |
*/
|
deba@822
|
105 |
SymMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
|
deba@822
|
106 |
|
deba@822
|
107 |
/** Constructor to use default value to initialize the map.
|
deba@822
|
108 |
*/
|
deba@822
|
109 |
SymMap(const Graph& g, MapRegistry& r, const Value& v)
|
deba@822
|
110 |
: MapImpl(g, r, v) {}
|
deba@822
|
111 |
|
deba@822
|
112 |
/** Constructor to copy a map of the same map type.
|
deba@822
|
113 |
*/
|
deba@822
|
114 |
SymMap(const SymMap& copy)
|
deba@822
|
115 |
: MapImpl(static_cast<const MapImpl&>(copy)) {}
|
deba@822
|
116 |
|
deba@822
|
117 |
/** Assign operator to copy a map of the same map type.
|
deba@822
|
118 |
*/
|
deba@822
|
119 |
SymMap& operator=(const SymMap& copy) {
|
deba@822
|
120 |
MapImpl::operator=(static_cast<const MapImpl&>(copy));
|
deba@822
|
121 |
return *this;
|
deba@822
|
122 |
}
|
deba@822
|
123 |
|
deba@822
|
124 |
/** Add a new key to the map. It called by the map registry.
|
deba@822
|
125 |
*/
|
deba@822
|
126 |
void add(const KeyType& key) {
|
deba@822
|
127 |
int id = MapImpl::getGraph()->id(key);
|
deba@822
|
128 |
if (id & 1) return;
|
deba@822
|
129 |
MapImpl::add(key);
|
deba@822
|
130 |
}
|
deba@822
|
131 |
|
deba@822
|
132 |
/** Erase a key from the map. It called by the map registry.
|
deba@822
|
133 |
*/
|
deba@822
|
134 |
void erase(const KeyType& key) {
|
deba@822
|
135 |
int id = MapImpl::getGraph()->id(key);
|
deba@822
|
136 |
if (id & 1) return;
|
deba@822
|
137 |
MapImpl::add(key);
|
deba@822
|
138 |
}
|
deba@822
|
139 |
};
|
deba@822
|
140 |
|
deba@822
|
141 |
/// @}
|
deba@822
|
142 |
}
|
deba@822
|
143 |
|
deba@822
|
144 |
#endif
|