126 ///Returns INVALID if the \c node is not covered by the actual matching. |
129 ///Returns INVALID if the \c node is not covered by the actual matching. |
127 Node mate(Node& node) const { |
130 Node mate(Node& node) const { |
128 return _mate[node]; |
131 return _mate[node]; |
129 } |
132 } |
130 |
133 |
131 ///Reads a matching from a \c Node map of \c Nodes. |
134 ///Reads a matching from a \c Node valued \c Node map. |
132 |
135 |
133 ///Reads a matching from a \c Node map of \c Nodes. This map must be \e |
136 ///Reads a matching from a \c Node valued \c Node map. This map |
134 ///symmetric, i.e. if \c map[u]==v then \c map[v]==u must hold, and |
137 ///must be \e symmetric, i.e. if \c map[u]==v then \c map[v]==u |
135 ///\c uv will be an edge of the matching. |
138 ///must hold, and \c uv will be an edge of the matching. |
136 template<typename NMapN> |
139 template<typename NMapN> |
137 void readNMapNode(NMapN& map) { |
140 void readNMapNode(NMapN& map) { |
138 for(NodeIt v(g); v!=INVALID; ++v) { |
141 for(NodeIt v(g); v!=INVALID; ++v) { |
139 _mate.set(v,map[v]); |
142 _mate.set(v,map[v]); |
140 } |
143 } |
141 } |
144 } |
142 |
145 |
143 ///Writes the stored matching to a \c Node map of \c Nodes. |
146 ///Writes the stored matching to a \c Node valued \c Node map. |
144 |
147 |
145 ///Writes the stored matching to a \c Node map of \c Nodes. The |
148 ///Writes the stored matching to a \c Node valued \c Node map. The |
146 ///resulting map will be \e symmetric, i.e. if \c map[u]==v then \c |
149 ///resulting map will be \e symmetric, i.e. if \c map[u]==v then \c |
147 ///map[v]==u will hold, and now \c uv is an edge of the matching. |
150 ///map[v]==u will hold, and now \c uv is an edge of the matching. |
148 template<typename NMapN> |
151 template<typename NMapN> |
149 void writeNMapNode (NMapN& map) const { |
152 void writeNMapNode (NMapN& map) const { |
150 for(NodeIt v(g); v!=INVALID; ++v) { |
153 for(NodeIt v(g); v!=INVALID; ++v) { |
151 map.set(v,_mate[v]); |
154 map.set(v,_mate[v]); |
152 } |
155 } |
153 } |
156 } |
154 |
157 |
155 ///Reads a matching from a \c Node map of \c Edges. |
158 ///Reads a matching from an \c UndirEdge valued \c Node map. |
156 |
159 |
157 ///Reads a matching from a \c Node map of incident \c Edges. This |
160 ///Reads a matching from an \c UndirEdge valued \c Node map. \c |
158 ///map must have the property that if \c G.target(map[u])==v then \c |
161 ///map[v] must be an \c UndirEdge incident to \c v. This map must |
159 ///G.target(map[v])==u must hold, and now this edge is an edge of |
162 ///have the property that if \c g.oppositeNode(u,map[u])==v then |
160 ///the matching. |
163 ///\c \c g.oppositeNode(v,map[v])==u holds, and now some edge |
|
164 ///joining \c u to \v will be an edge of the matching. |
161 template<typename NMapE> |
165 template<typename NMapE> |
162 void readNMapEdge(NMapE& map) { |
166 void readNMapEdge(NMapE& map) { |
163 for(NodeIt v(g); v!=INVALID; ++v) { |
167 for(NodeIt v(g); v!=INVALID; ++v) { |
164 Edge e=map[v]; |
168 UndirEdge e=map[v]; |
165 if ( g.valid(e) ) |
169 if ( e!=INVALID ) |
166 g.source(e) == v ? _mate.set(v,g.target(e)) : _mate.set(v,g.source(e)); |
170 g.source(e) == v ? _mate.set(v,g.target(e)) : _mate.set(v,g.source(e)); |
167 } |
171 } |
168 } |
172 } |
169 |
173 |
170 ///Writes the matching stored to a \c Node map of \c Edges. |
174 ///Writes the matching stored to an \c UndirEdge valued \c Node map. |
171 |
175 |
172 ///Writes the stored matching to a \c Node map of incident \c |
176 ///Writes the stored matching to an \c UndirEdge valued \c Node |
173 ///Edges. This map will have the property that if \c |
177 ///map. \c map[v] will be an \c UndirEdge incident to \c v. This |
174 ///g.target(map[u])==v then \c g.target(map[v])==u holds, and now this |
178 ///map will have the property that if \c g.oppositeNode(u,map[u]) |
175 ///edge is an edge of the matching. |
179 ///== v then \c map[u]==map[v] holds, and now this edge is an edge |
|
180 ///of the matching. |
176 template<typename NMapE> |
181 template<typename NMapE> |
177 void writeNMapEdge (NMapE& map) const { |
182 void writeNMapEdge (NMapE& map) const { |
178 typename Graph::template NodeMap<bool> todo(g,true); |
183 typename Graph::template NodeMap<bool> todo(g,true); |
179 for(NodeIt v(g); v!=INVALID; ++v) { |
184 for(NodeIt v(g); v!=INVALID; ++v) { |
180 if ( todo[v] && _mate[v]!=INVALID ) { |
185 if ( todo[v] && _mate[v]!=INVALID ) { |
191 } |
196 } |
192 } |
197 } |
193 } |
198 } |
194 |
199 |
195 |
200 |
196 ///Reads a matching from an \c Edge map of \c bools. |
201 ///Reads a matching from a \c bool valued \c Edge map. |
197 |
202 |
198 ///Reads a matching from an \c Edge map of \c bools. This map must |
203 ///Reads a matching from a \c bool valued \c Edge map. This map |
199 ///have the property that there are no two adjacent edges \c e, \c |
204 ///must have the property that there are no two incident edges \c |
200 ///f with \c map[e]==map[f]==true. The edges \c e with \c |
205 ///e, \c f with \c map[e]==map[f]==true. The edges \c e with \c |
201 ///map[e]==true form the matching. |
206 ///map[e]==true form the matching. |
202 template<typename EMapB> |
207 template<typename EMapB> |
203 void readEMapBool(EMapB& map) { |
208 void readEMapBool(EMapB& map) { |
204 for(UndirEdgeIt e(g); e!=INVALID; ++e) { |
209 for(UndirEdgeIt e(g); e!=INVALID; ++e) { |
205 if ( map[e] ) { |
210 if ( map[e] ) { |
210 } |
215 } |
211 } |
216 } |
212 } |
217 } |
213 |
218 |
214 |
219 |
215 ///Writes the matching stored to an \c Edge map of \c bools. |
220 ///Writes the matching stored to a \c bool valued \c Edge map. |
216 |
221 |
217 ///Writes the matching stored to an \c Edge map of \c bools. This |
222 ///Writes the matching stored to a \c bool valued \c Edge |
218 ///map will have the property that there are no two adjacent edges |
223 ///map. This map will have the property that there are no two |
219 ///\c e, \c f with \c map[e]==map[f]==true. The edges \c e with \c |
224 ///incident edges \c e, \c f with \c map[e]==map[f]==true. The |
220 ///map[e]==true form the matching. |
225 ///edges \c e with \c map[e]==true form the matching. |
221 template<typename EMapB> |
226 template<typename EMapB> |
222 void writeEMapBool (EMapB& map) const { |
227 void writeEMapBool (EMapB& map) const { |
223 for(UndirEdgeIt e(g); e!=INVALID; ++e) map.set(e,false); |
228 for(UndirEdgeIt e(g); e!=INVALID; ++e) map.set(e,false); |
224 |
229 |
225 typename Graph::template NodeMap<bool> todo(g,true); |
230 typename Graph::template NodeMap<bool> todo(g,true); |
290 for(NodeIt v(g); v!=INVALID; ++v) |
296 for(NodeIt v(g); v!=INVALID; ++v) |
291 position.set(v,C); |
297 position.set(v,C); |
292 |
298 |
293 typename Graph::template NodeMap<Node> ear(g,INVALID); |
299 typename Graph::template NodeMap<Node> ear(g,INVALID); |
294 //undefined for the base nodes of the blossoms (i.e. for the |
300 //undefined for the base nodes of the blossoms (i.e. for the |
295 //representative elements of UFE blossom) and for the nodes in C |
301 //representative elements of UFE blossom) and for the nodes in C |
296 |
302 |
297 typename UFE::MapType blossom_base(g); |
303 typename UFE::MapType blossom_base(g); |
298 UFE blossom(blossom_base); |
304 UFE blossom(blossom_base); |
299 typename UFE::MapType tree_base(g); |
305 typename UFE::MapType tree_base(g); |
300 UFE tree(tree_base); |
306 UFE tree(tree_base); |
|
307 //If these UFE's would be members of the class then also |
|
308 //blossom_base and tree_base should be a member. |
301 |
309 |
302 for(NodeIt v(g); v!=INVALID; ++v) { |
310 for(NodeIt v(g); v!=INVALID; ++v) { |
303 if ( position[v]==C && _mate[v]==INVALID ) { |
311 if ( position[v]==C && _mate[v]==INVALID ) { |
304 blossom.insert(v); |
312 blossom.insert(v); |
305 tree.insert(v); |
313 tree.insert(v); |