Changes in / [154:f4e4dbc1d467:153:976a014b3797] in lemon-main
- Files:
-
- 6 added
- 6 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r154 r153 37 37 ^test/[a-z_]*$ 38 38 ^demo/.*_demo$ 39 ^build/.*40 CMakeFiles41 DartTestfile.txt42 cmake_install.cmake43 CMakeCache.txt -
Makefile.am
r146 r70 8 8 m4/lx_check_cplex.m4 \ 9 9 m4/lx_check_glpk.m4 \ 10 m4/lx_check_soplex.m4 \ 11 CMakeLists.txt 10 m4/lx_check_soplex.m4 12 11 13 12 pkgconfigdir = $(libdir)/pkgconfig … … 46 45 build-aux/ltmain.sh \ 47 46 build-aux/missing \ 48 doc/doxygen.log 47 doc/Makefile.in \ 48 doc/doxygen.log \ 49 Makefile.in \ 50 lemon/Makefile.in \ 51 test/Makefile.in \ 52 benchmark/Makefile.in \ 53 demo/Makefile.in 49 54 50 55 mrproper: -
benchmark/Makefile.am
r146 r1 1 EXTRA_DIST += \ 2 benchmark/Makefile 3 1 4 if WANT_BENCHMARK 2 5 -
demo/Makefile.am
r146 r135 1 1 EXTRA_DIST += \ 2 demo/ CMakeLists.txt2 demo/Makefile 3 3 4 4 if WANT_DEMO … … 14 14 demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc 15 15 demo_lgf_demo_SOURCES = demo/lgf_demo.cc 16 -
demo/lgf_demo.cc
r143 r127 38 38 int main(int argc, const char *argv[]) { 39 39 const int n = argc > 1 ? std::atoi(argv[1]) : 20; 40 const int e = argc > 2 ? std::atoi(argv[2]) : static_cast<int>(n * std::log(double(n)));40 const int e = argc > 2 ? std::atoi(argv[2]) : static_cast<int>(n * log(n)); 41 41 const int m = argc > 3 ? std::atoi(argv[3]) : 100; 42 42 -
doc/Makefile.am
r154 r153 1 1 EXTRA_DIST += \ 2 doc/Makefile \ 2 3 doc/Doxyfile.in \ 3 4 doc/coding_style.dox \ -
lemon/Makefile.am
r146 r135 1 1 EXTRA_DIST += \ 2 lemon/ lemon.pc.in\3 lemon/ CMakeLists.txt2 lemon/Makefile \ 3 lemon/lemon.pc.in 4 4 5 5 pkgconfig_DATA += lemon/lemon.pc -
lemon/assert.h
r142 r118 104 104 105 105 #ifndef LEMON_FUNCTION_NAME 106 # if defined __GNUC__ 107 # define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__) 108 # elif defined _MSC_VER 109 # define LEMON_FUNCTION_NAME (__FUNCSIG__) 110 # else 111 # define LEMON_FUNCTION_NAME (__func__) 112 # endif 106 # define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__) 113 107 #endif 114 108 -
lemon/bits/traits.h
r139 r107 217 217 218 218 template <typename Graph, typename Enable = void> 219 struct EdgeNumTagIndicator {220 static const bool value = false; 221 }; 222 223 template <typename Graph> 224 struct EdgeNumTagIndicator<225 Graph, 226 typename enable_if<typename Graph:: EdgeNumTag, void>::type227 > { 228 static const bool value = true; 229 }; 230 231 template <typename Graph, typename Enable = void> 232 struct Find EdgeTagIndicator {233 static const bool value = false; 234 }; 235 236 template <typename Graph> 237 struct Find EdgeTagIndicator<238 Graph, 239 typename enable_if<typename Graph::Find EdgeTag, void>::type219 struct ArcNumTagIndicator { 220 static const bool value = false; 221 }; 222 223 template <typename Graph> 224 struct ArcNumTagIndicator< 225 Graph, 226 typename enable_if<typename Graph::ArcNumTag, void>::type 227 > { 228 static const bool value = true; 229 }; 230 231 template <typename Graph, typename Enable = void> 232 struct FindArcTagIndicator { 233 static const bool value = false; 234 }; 235 236 template <typename Graph> 237 struct FindArcTagIndicator< 238 Graph, 239 typename enable_if<typename Graph::FindArcTag, void>::type 240 240 > { 241 241 static const bool value = true; -
lemon/graph_to_eps.h
r143 r134 30 30 #include<ctime> 31 31 #else 32 #define WIN32_LEAN_AND_MEAN33 #define NOMINMAX34 32 #include<windows.h> 35 33 #endif -
lemon/graph_utils.h
r148 r100 36 36 ///\ingroup gutils 37 37 ///\file 38 ///\brief Graph utilities.38 ///\brief Digraph utilities. 39 39 40 40 namespace lemon { … … 47 47 ///This \c \#define creates convenience typedefs for the following types 48 48 ///of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, 49 ///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, 50 ///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. 51 /// 52 ///\note If the graph type is a dependent type, ie. the graph type depend 53 ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() 54 ///macro. 55 #define DIGRAPH_TYPEDEFS(Digraph) \ 56 typedef Digraph::Node Node; \ 57 typedef Digraph::NodeIt NodeIt; \ 58 typedef Digraph::Arc Arc; \ 59 typedef Digraph::ArcIt ArcIt; \ 60 typedef Digraph::InArcIt InArcIt; \ 61 typedef Digraph::OutArcIt OutArcIt; \ 62 typedef Digraph::NodeMap<bool> BoolNodeMap; \ 63 typedef Digraph::NodeMap<int> IntNodeMap; \ 64 typedef Digraph::NodeMap<double> DoubleNodeMap; \ 65 typedef Digraph::ArcMap<bool> BoolArcMap; \ 66 typedef Digraph::ArcMap<int> IntArcMap; \ 67 typedef Digraph::ArcMap<double> DoubleArcMap 68 69 ///Creates convenience typedefs for the digraph types and iterators 70 71 ///\see DIGRAPH_TYPEDEFS 72 /// 73 ///\note Use this macro, if the graph type is a dependent type, 74 ///ie. the graph type depend on a template parameter. 75 #define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph) \ 76 typedef typename Digraph::Node Node; \ 77 typedef typename Digraph::NodeIt NodeIt; \ 78 typedef typename Digraph::Arc Arc; \ 79 typedef typename Digraph::ArcIt ArcIt; \ 80 typedef typename Digraph::InArcIt InArcIt; \ 81 typedef typename Digraph::OutArcIt OutArcIt; \ 82 typedef typename Digraph::template NodeMap<bool> BoolNodeMap; \ 83 typedef typename Digraph::template NodeMap<int> IntNodeMap; \ 84 typedef typename Digraph::template NodeMap<double> DoubleNodeMap; \ 85 typedef typename Digraph::template ArcMap<bool> BoolArcMap; \ 86 typedef typename Digraph::template ArcMap<int> IntArcMap; \ 87 typedef typename Digraph::template ArcMap<double> DoubleArcMap 88 49 ///\c OutArcIt 50 ///\note If \c G it a template parameter, it should be used in this way. 51 ///\code 52 /// GRAPH_TYPEDEFS(typename G); 53 ///\endcode 54 /// 55 ///\warning There are no typedefs for the digraph maps because of the lack of 56 ///template typedefs in C++. 57 #define GRAPH_TYPEDEFS(Digraph) \ 58 typedef Digraph:: Node Node; \ 59 typedef Digraph:: NodeIt NodeIt; \ 60 typedef Digraph:: Arc Arc; \ 61 typedef Digraph:: ArcIt ArcIt; \ 62 typedef Digraph:: InArcIt InArcIt; \ 63 typedef Digraph::OutArcIt OutArcIt 64 89 65 ///Creates convenience typedefs for the graph types and iterators 90 66 91 ///This \c \#define creates the same convenience typedefs as defined 92 ///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates 93 ///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap, 94 ///\c DoubleEdgeMap. 95 /// 96 ///\note If the graph type is a dependent type, ie. the graph type depend 97 ///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() 98 ///macro. 99 #define GRAPH_TYPEDEFS(Graph) \ 100 DIGRAPH_TYPEDEFS(Graph); \ 101 typedef Graph::Edge Edge; \ 102 typedef Graph::EdgeIt EdgeIt; \ 103 typedef Graph::IncEdgeIt IncEdgeIt; \ 104 typedef Graph::EdgeMap<bool> BoolEdgeMap; \ 105 typedef Graph::EdgeMap<int> IntEdgeMap; \ 106 typedef Graph::EdgeMap<double> DoubleEdgeMap 107 108 ///Creates convenience typedefs for the graph types and iterators 109 110 ///\see GRAPH_TYPEDEFS 111 /// 112 ///\note Use this macro, if the graph type is a dependent type, 113 ///ie. the graph type depend on a template parameter. 114 #define TEMPLATE_GRAPH_TYPEDEFS(Graph) \ 115 TEMPLATE_DIGRAPH_TYPEDEFS(Graph); \ 116 typedef typename Graph::Edge Edge; \ 117 typedef typename Graph::EdgeIt EdgeIt; \ 118 typedef typename Graph::IncEdgeIt IncEdgeIt; \ 119 typedef typename Graph::template EdgeMap<bool> BoolEdgeMap; \ 120 typedef typename Graph::template EdgeMap<int> IntEdgeMap; \ 121 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 122 123 /// \brief Function to count the items in the graph. 124 /// 125 /// This function counts the items (nodes, arcs etc) in the graph. 67 ///This \c \#define creates the same convenience typedefs as defined by 68 ///\ref GRAPH_TYPEDEFS(Digraph) and three more, namely it creates 69 ///\c Edge, \c EdgeIt, \c IncArcIt, 70 /// 71 ///\note If \c G it a template parameter, it should be used in this way. 72 ///\code 73 /// UGRAPH_TYPEDEFS(typename G); 74 ///\endcode 75 /// 76 ///\warning There are no typedefs for the digraph maps because of the lack of 77 ///template typedefs in C++. 78 #define UGRAPH_TYPEDEFS(Digraph) \ 79 GRAPH_TYPEDEFS(Digraph); \ 80 typedef Digraph:: Edge Edge; \ 81 typedef Digraph:: EdgeIt EdgeIt; \ 82 typedef Digraph:: IncArcIt IncArcIt 83 84 ///\brief Creates convenience typedefs for the bipartite digraph 85 ///types and iterators 86 87 ///This \c \#define creates the same convenience typedefs as defined by 88 ///\ref UGRAPH_TYPEDEFS(Digraph) and two more, namely it creates 89 ///\c RedIt, \c BlueIt, 90 /// 91 ///\note If \c G it a template parameter, it should be used in this way. 92 ///\code 93 /// BPUGRAPH_TYPEDEFS(typename G); 94 ///\endcode 95 /// 96 ///\warning There are no typedefs for the digraph maps because of the lack of 97 ///template typedefs in C++. 98 #define BPUGRAPH_TYPEDEFS(Digraph) \ 99 UGRAPH_TYPEDEFS(Digraph); \ 100 typedef Digraph::Red Red; \ 101 typedef Digraph::Blue Blue; \ 102 typedef Digraph::RedIt RedIt; \ 103 typedef Digraph::BlueIt BlueIt 104 105 /// \brief Function to count the items in the digraph. 106 /// 107 /// This function counts the items (nodes, arcs etc) in the digraph. 126 108 /// The complexity of the function is O(n) because 127 109 /// it iterates on all of the items. 128 template <typename Graph, typename Item> 129 inline int countItems(const Graph& g) { 130 typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt; 110 111 template <typename Digraph, typename Item> 112 inline int countItems(const Digraph& g) { 113 typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt; 131 114 int num = 0; 132 115 for (ItemIt it(g); it != INVALID; ++it) { … … 138 121 // Node counting: 139 122 140 namespace _ graph_utils_bits {141 142 template <typename Graph, typename Enable = void>123 namespace _digraph_utils_bits { 124 125 template <typename Digraph, typename Enable = void> 143 126 struct CountNodesSelector { 144 static int count(const Graph &g) {145 return countItems< Graph, typename Graph::Node>(g);127 static int count(const Digraph &g) { 128 return countItems<Digraph, typename Digraph::Node>(g); 146 129 } 147 130 }; 148 131 149 template <typename Graph>132 template <typename Digraph> 150 133 struct CountNodesSelector< 151 Graph, typename152 enable_if<typename Graph::NodeNumTag, void>::type>134 Digraph, typename 135 enable_if<typename Digraph::NodeNumTag, void>::type> 153 136 { 154 static int count(const Graph &g) {137 static int count(const Digraph &g) { 155 138 return g.nodeNum(); 156 139 } … … 158 141 } 159 142 160 /// \brief Function to count the nodes in the graph.161 /// 162 /// This function counts the nodes in the graph.143 /// \brief Function to count the nodes in the digraph. 144 /// 145 /// This function counts the nodes in the digraph. 163 146 /// The complexity of the function is O(n) but for some 164 /// graph structures it is specialized to run in O(1).165 /// 166 /// If the graph contains a \e nodeNum() member function and a147 /// digraph structures it is specialized to run in O(1). 148 /// 149 /// If the digraph contains a \e nodeNum() member function and a 167 150 /// \e NodeNumTag tag then this function calls directly the member 168 151 /// function to query the cardinality of the node set. 169 template <typename Graph>170 inline int countNodes(const Graph& g) {171 return _ graph_utils_bits::CountNodesSelector<Graph>::count(g);152 template <typename Digraph> 153 inline int countNodes(const Digraph& g) { 154 return _digraph_utils_bits::CountNodesSelector<Digraph>::count(g); 172 155 } 173 156 174 // Arc counting: 175 176 namespace _graph_utils_bits { 177 178 template <typename Graph, typename Enable = void> 179 struct CountArcsSelector { 180 static int count(const Graph &g) { 181 return countItems<Graph, typename Graph::Arc>(g); 157 namespace _digraph_utils_bits { 158 159 template <typename Digraph, typename Enable = void> 160 struct CountRedsSelector { 161 static int count(const Digraph &g) { 162 return countItems<Digraph, typename Digraph::Red>(g); 182 163 } 183 164 }; 184 165 185 template <typename Graph>186 struct Count ArcsSelector<187 Graph,188 typename enable_if<typename Graph::ArcNumTag, void>::type>166 template <typename Digraph> 167 struct CountRedsSelector< 168 Digraph, typename 169 enable_if<typename Digraph::NodeNumTag, void>::type> 189 170 { 190 static int count(const Graph &g) {191 return g. arcNum();171 static int count(const Digraph &g) { 172 return g.redNum(); 192 173 } 193 174 }; 194 175 } 195 176 196 /// \brief Function to count the arcs in thegraph.197 /// 198 /// This function counts the arcs in thegraph.199 /// The complexity of the function is O( e) but for some200 /// graph structures it is specialized to run in O(1).201 /// 202 /// If the graph contains a \e arcNum() member function and a203 /// \e EdgeNumTag tag then this function calls directly the member204 /// function to query the cardinality of the arcset.205 template <typename Graph>206 inline int count Arcs(const Graph& g) {207 return _ graph_utils_bits::CountArcsSelector<Graph>::count(g);177 /// \brief Function to count the reds in the digraph. 178 /// 179 /// This function counts the reds in the digraph. 180 /// The complexity of the function is O(an) but for some 181 /// digraph structures it is specialized to run in O(1). 182 /// 183 /// If the digraph contains an \e redNum() member function and a 184 /// \e NodeNumTag tag then this function calls directly the member 185 /// function to query the cardinality of the A-node set. 186 template <typename Digraph> 187 inline int countReds(const Digraph& g) { 188 return _digraph_utils_bits::CountRedsSelector<Digraph>::count(g); 208 189 } 209 190 210 // Edge counting: 211 namespace _graph_utils_bits { 212 213 template <typename Graph, typename Enable = void> 214 struct CountEdgesSelector { 215 static int count(const Graph &g) { 216 return countItems<Graph, typename Graph::Edge>(g); 191 namespace _digraph_utils_bits { 192 193 template <typename Digraph, typename Enable = void> 194 struct CountBluesSelector { 195 static int count(const Digraph &g) { 196 return countItems<Digraph, typename Digraph::Blue>(g); 217 197 } 218 198 }; 219 199 220 template <typename Graph>221 struct Count EdgesSelector<222 Graph,223 typename enable_if<typename Graph::EdgeNumTag, void>::type>200 template <typename Digraph> 201 struct CountBluesSelector< 202 Digraph, typename 203 enable_if<typename Digraph::NodeNumTag, void>::type> 224 204 { 225 static int count(const Graph &g) {226 return g. edgeNum();205 static int count(const Digraph &g) { 206 return g.blueNum(); 227 207 } 228 208 }; 229 209 } 230 210 231 /// \brief Function to count the edges in the graph. 232 /// 233 /// This function counts the edges in the graph. 234 /// The complexity of the function is O(m) but for some 235 /// graph structures it is specialized to run in O(1). 236 /// 237 /// If the graph contains a \e edgeNum() member function and a 238 /// \e EdgeNumTag tag then this function calls directly the member 211 /// \brief Function to count the blues in the digraph. 212 /// 213 /// This function counts the blues in the digraph. 214 /// The complexity of the function is O(bn) but for some 215 /// digraph structures it is specialized to run in O(1). 216 /// 217 /// If the digraph contains a \e blueNum() member function and a 218 /// \e NodeNumTag tag then this function calls directly the member 219 /// function to query the cardinality of the B-node set. 220 template <typename Digraph> 221 inline int countBlues(const Digraph& g) { 222 return _digraph_utils_bits::CountBluesSelector<Digraph>::count(g); 223 } 224 225 226 // Arc counting: 227 228 namespace _digraph_utils_bits { 229 230 template <typename Digraph, typename Enable = void> 231 struct CountArcsSelector { 232 static int count(const Digraph &g) { 233 return countItems<Digraph, typename Digraph::Arc>(g); 234 } 235 }; 236 237 template <typename Digraph> 238 struct CountArcsSelector< 239 Digraph, 240 typename enable_if<typename Digraph::ArcNumTag, void>::type> 241 { 242 static int count(const Digraph &g) { 243 return g.arcNum(); 244 } 245 }; 246 } 247 248 /// \brief Function to count the arcs in the digraph. 249 /// 250 /// This function counts the arcs in the digraph. 251 /// The complexity of the function is O(e) but for some 252 /// digraph structures it is specialized to run in O(1). 253 /// 254 /// If the digraph contains a \e arcNum() member function and a 255 /// \e ArcNumTag tag then this function calls directly the member 256 /// function to query the cardinality of the arc set. 257 template <typename Digraph> 258 inline int countArcs(const Digraph& g) { 259 return _digraph_utils_bits::CountArcsSelector<Digraph>::count(g); 260 } 261 262 // Undirected arc counting: 263 namespace _digraph_utils_bits { 264 265 template <typename Digraph, typename Enable = void> 266 struct CountEdgesSelector { 267 static int count(const Digraph &g) { 268 return countItems<Digraph, typename Digraph::Edge>(g); 269 } 270 }; 271 272 template <typename Digraph> 273 struct CountEdgesSelector< 274 Digraph, 275 typename enable_if<typename Digraph::ArcNumTag, void>::type> 276 { 277 static int count(const Digraph &g) { 278 return g.edgeNum(); 279 } 280 }; 281 } 282 283 /// \brief Function to count the edges in the digraph. 284 /// 285 /// This function counts the edges in the digraph. 286 /// The complexity of the function is O(e) but for some 287 /// digraph structures it is specialized to run in O(1). 288 /// 289 /// If the digraph contains a \e edgeNum() member function and a 290 /// \e ArcNumTag tag then this function calls directly the member 239 291 /// function to query the cardinality of the edge set. 240 template <typename Graph>241 inline int countEdges(const Graph& g) {242 return _ graph_utils_bits::CountEdgesSelector<Graph>::count(g);292 template <typename Digraph> 293 inline int countEdges(const Digraph& g) { 294 return _digraph_utils_bits::CountEdgesSelector<Digraph>::count(g); 243 295 244 296 } 245 297 246 298 247 template <typename Graph, typename DegIt>248 inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) {299 template <typename Digraph, typename DegIt> 300 inline int countNodeDegree(const Digraph& _g, const typename Digraph::Node& _n) { 249 301 int num = 0; 250 302 for (DegIt it(_g, _n); it != INVALID; ++it) { … … 257 309 /// 258 310 /// This function counts the number of the out-arcs from node \c n 259 /// in the graph.260 template <typename Graph>261 inline int countOutArcs(const Graph& _g, const typename Graph::Node& _n) {262 return countNodeDegree< Graph, typename Graph::OutArcIt>(_g, _n);311 /// in the digraph. 312 template <typename Digraph> 313 inline int countOutArcs(const Digraph& _g, const typename Digraph::Node& _n) { 314 return countNodeDegree<Digraph, typename Digraph::OutArcIt>(_g, _n); 263 315 } 264 316 … … 266 318 /// 267 319 /// This function counts the number of the in-arcs to node \c n 268 /// in the graph.269 template <typename Graph>270 inline int countInArcs(const Graph& _g, const typename Graph::Node& _n) {271 return countNodeDegree< Graph, typename Graph::InArcIt>(_g, _n);320 /// in the digraph. 321 template <typename Digraph> 322 inline int countInArcs(const Digraph& _g, const typename Digraph::Node& _n) { 323 return countNodeDegree<Digraph, typename Digraph::InArcIt>(_g, _n); 272 324 } 273 325 274 /// \brief Function to count the number of the inc- edges to node \c n.275 /// 276 /// This function counts the number of the inc- edges to node \c n277 /// in the graph.278 template <typename Graph>279 inline int countInc Edges(const Graph& _g, const typename Graph::Node& _n) {280 return countNodeDegree< Graph, typename Graph::IncEdgeIt>(_g, _n);326 /// \brief Function to count the number of the inc-arcs to node \c n. 327 /// 328 /// This function counts the number of the inc-arcs to node \c n 329 /// in the digraph. 330 template <typename Digraph> 331 inline int countIncArcs(const Digraph& _g, const typename Digraph::Node& _n) { 332 return countNodeDegree<Digraph, typename Digraph::IncArcIt>(_g, _n); 281 333 } 282 334 283 namespace _ graph_utils_bits {284 285 template <typename Graph, typename Enable = void>335 namespace _digraph_utils_bits { 336 337 template <typename Digraph, typename Enable = void> 286 338 struct FindArcSelector { 287 typedef typename Graph::Node Node;288 typedef typename Graph::Arc Arc;289 static Arc find(const Graph &g, Node u, Node v, Arc e) {339 typedef typename Digraph::Node Node; 340 typedef typename Digraph::Arc Arc; 341 static Arc find(const Digraph &g, Node u, Node v, Arc e) { 290 342 if (e == INVALID) { 291 343 g.firstOut(e, u); … … 300 352 }; 301 353 302 template <typename Graph>354 template <typename Digraph> 303 355 struct FindArcSelector< 304 Graph,305 typename enable_if<typename Graph::FindEdgeTag, void>::type>356 Digraph, 357 typename enable_if<typename Digraph::FindArcTag, void>::type> 306 358 { 307 typedef typename Graph::Node Node;308 typedef typename Graph::Arc Arc;309 static Arc find(const Graph &g, Node u, Node v, Arc prev) {359 typedef typename Digraph::Node Node; 360 typedef typename Digraph::Arc Arc; 361 static Arc find(const Digraph &g, Node u, Node v, Arc prev) { 310 362 return g.findArc(u, v, prev); 311 363 } … … 313 365 } 314 366 315 /// \brief Finds an arc between two nodes of a graph.316 /// 317 /// Finds an arc from node \c u to node \c v in graph \c g.367 /// \brief Finds an arc between two nodes of a digraph. 368 /// 369 /// Finds an arc from node \c u to node \c v in digraph \c g. 318 370 /// 319 371 /// If \c prev is \ref INVALID (this is the default value), then … … 333 385 ///\sa DynArcLookUp 334 386 ///\sa ConArcIt 335 template <typename Graph>336 inline typename Graph::Arc337 findArc(const Graph &g, typename Graph::Node u, typename Graph::Node v,338 typename Graph::Arc prev = INVALID) {339 return _ graph_utils_bits::FindArcSelector<Graph>::find(g, u, v, prev);387 template <typename Digraph> 388 inline typename Digraph::Arc 389 findArc(const Digraph &g, typename Digraph::Node u, typename Digraph::Node v, 390 typename Digraph::Arc prev = INVALID) { 391 return _digraph_utils_bits::FindArcSelector<Digraph>::find(g, u, v, prev); 340 392 } 341 393 … … 346 398 /// use it the following way: 347 399 ///\code 348 /// for (ConArcIt< Graph> it(g, src, trg); it != INVALID; ++it) {400 /// for (ConArcIt<Digraph> it(g, src, trg); it != INVALID; ++it) { 349 401 /// ... 350 402 /// } … … 357 409 /// 358 410 /// \author Balazs Dezso 359 template <typename _ Graph>360 class ConArcIt : public _ Graph::Arc {411 template <typename _Digraph> 412 class ConArcIt : public _Digraph::Arc { 361 413 public: 362 414 363 typedef _ Graph Graph;364 typedef typename Graph::Arc Parent;365 366 typedef typename Graph::Arc Arc;367 typedef typename Graph::Node Node;415 typedef _Digraph Digraph; 416 typedef typename Digraph::Arc Parent; 417 418 typedef typename Digraph::Arc Arc; 419 typedef typename Digraph::Node Node; 368 420 369 421 /// \brief Constructor. … … 371 423 /// Construct a new ConArcIt iterating on the arcs which 372 424 /// connects the \c u and \c v node. 373 ConArcIt(const Graph& g, Node u, Node v) : _graph(g) {374 Parent::operator=(findArc( _graph, u, v));425 ConArcIt(const Digraph& g, Node u, Node v) : digraph(g) { 426 Parent::operator=(findArc(digraph, u, v)); 375 427 } 376 428 … … 379 431 /// Construct a new ConArcIt which continues the iterating from 380 432 /// the \c e arc. 381 ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {}433 ConArcIt(const Digraph& g, Arc e) : Parent(e), digraph(g) {} 382 434 383 435 /// \brief Increment operator. … … 385 437 /// It increments the iterator and gives back the next arc. 386 438 ConArcIt& operator++() { 387 Parent::operator=(findArc( _graph, _graph.source(*this),388 _graph.target(*this), *this));439 Parent::operator=(findArc(digraph, digraph.source(*this), 440 digraph.target(*this), *this)); 389 441 return *this; 390 442 } 391 443 private: 392 const Graph& _graph;444 const Digraph& digraph; 393 445 }; 394 446 395 namespace _ graph_utils_bits {396 397 template <typename Graph, typename Enable = void>447 namespace _digraph_utils_bits { 448 449 template <typename Digraph, typename Enable = void> 398 450 struct FindEdgeSelector { 399 typedef typename Graph::Node Node;400 typedef typename Graph::Edge Edge;401 static Edge find(const Graph &g, Node u, Node v, Edge e) {451 typedef typename Digraph::Node Node; 452 typedef typename Digraph::Edge Edge; 453 static Edge find(const Digraph &g, Node u, Node v, Edge e) { 402 454 bool b; 403 455 if (u != v) { … … 426 478 }; 427 479 428 template <typename Graph>480 template <typename Digraph> 429 481 struct FindEdgeSelector< 430 Graph,431 typename enable_if<typename Graph::FindEdgeTag, void>::type>482 Digraph, 483 typename enable_if<typename Digraph::FindArcTag, void>::type> 432 484 { 433 typedef typename Graph::Node Node;434 typedef typename Graph::Edge Edge;435 static Edge find(const Graph &g, Node u, Node v, Edge prev) {485 typedef typename Digraph::Node Node; 486 typedef typename Digraph::Edge Edge; 487 static Edge find(const Digraph &g, Node u, Node v, Edge prev) { 436 488 return g.findEdge(u, v, prev); 437 489 } … … 439 491 } 440 492 441 /// \brief Finds an edge between two nodes of a graph.442 /// 443 /// Finds an edge from node \c u to node \c v in graph \c g.444 /// If the node \c u and node \c v is equal then each loop edge445 /// will be enumerated once.493 /// \brief Finds an edge between two nodes of a digraph. 494 /// 495 /// Finds an edge from node \c u to node \c v in digraph \c g. 496 /// If the node \c u and node \c v is equal then each loop arc 497 /// will be enumerated. 446 498 /// 447 499 /// If \c prev is \ref INVALID (this is the default value), then … … 460 512 ///\sa ConArcIt 461 513 462 template <typename Graph>463 inline typename Graph::Edge464 findEdge(const Graph &g, typename Graph::Node u, typename Graph::Node v,465 typename Graph::Edge p = INVALID) {466 return _ graph_utils_bits::FindEdgeSelector<Graph>::find(g, u, v, p);514 template <typename Digraph> 515 inline typename Digraph::Edge 516 findEdge(const Digraph &g, typename Digraph::Node u, typename Digraph::Node v, 517 typename Digraph::Edge p = INVALID) { 518 return _digraph_utils_bits::FindEdgeSelector<Digraph>::find(g, u, v, p); 467 519 } 468 520 … … 473 525 /// use it the following way: 474 526 ///\code 475 /// for (ConEdgeIt< Graph> it(g, src, trg); it != INVALID; ++it) {527 /// for (ConEdgeIt<Digraph> it(g, src, trg); it != INVALID; ++it) { 476 528 /// ... 477 529 /// } … … 481 533 /// 482 534 /// \author Balazs Dezso 483 template <typename _ Graph>484 class ConEdgeIt : public _ Graph::Edge {535 template <typename _Digraph> 536 class ConEdgeIt : public _Digraph::Edge { 485 537 public: 486 538 487 typedef _ Graph Graph;488 typedef typename Graph::Edge Parent;489 490 typedef typename Graph::Edge Edge;491 typedef typename Graph::Node Node;539 typedef _Digraph Digraph; 540 typedef typename Digraph::Edge Parent; 541 542 typedef typename Digraph::Edge Edge; 543 typedef typename Digraph::Node Node; 492 544 493 545 /// \brief Constructor. 494 546 /// 495 /// Construct a new ConEdgeIt iterating on the edges which547 /// Construct a new ConEdgeIt iterating on the arcs which 496 548 /// connects the \c u and \c v node. 497 ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g) {498 Parent::operator=(findEdge( _graph, u, v));549 ConEdgeIt(const Digraph& g, Node u, Node v) : digraph(g) { 550 Parent::operator=(findEdge(digraph, u, v)); 499 551 } 500 552 … … 502 554 /// 503 555 /// Construct a new ConEdgeIt which continues the iterating from 504 /// the \c e edge.505 ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {}556 /// the \c e arc. 557 ConEdgeIt(const Digraph& g, Edge e) : Parent(e), digraph(g) {} 506 558 507 559 /// \brief Increment operator. 508 560 /// 509 /// It increments the iterator and gives back the next edge.561 /// It increments the iterator and gives back the next arc. 510 562 ConEdgeIt& operator++() { 511 Parent::operator=(findEdge( _graph, _graph.source(*this),512 _graph.target(*this), *this));563 Parent::operator=(findEdge(digraph, digraph.source(*this), 564 digraph.target(*this), *this)); 513 565 return *this; 514 566 } 515 567 private: 516 const Graph& _graph;568 const Digraph& digraph; 517 569 }; 518 570 519 namespace _graph_utils_bits { 571 /// \brief Copy a map. 572 /// 573 /// This function copies the \c from map to the \c to map. It uses the 574 /// given iterator to iterate on the data structure and it uses the \c ref 575 /// mapping to convert the from's keys to the to's keys. 576 template <typename To, typename From, 577 typename ItemIt, typename Ref> 578 void copyMap(To& to, const From& from, 579 ItemIt it, const Ref& ref) { 580 for (; it != INVALID; ++it) { 581 to[ref[it]] = from[it]; 582 } 583 } 584 585 /// \brief Copy the from map to the to map. 586 /// 587 /// Copy the \c from map to the \c to map. It uses the given iterator 588 /// to iterate on the data structure. 589 template <typename To, typename From, typename ItemIt> 590 void copyMap(To& to, const From& from, ItemIt it) { 591 for (; it != INVALID; ++it) { 592 to[it] = from[it]; 593 } 594 } 595 596 namespace _digraph_utils_bits { 520 597 521 598 template <typename Digraph, typename Item, typename RefMap> … … 651 728 }; 652 729 730 template <typename BpGraph, typename Enable = void> 731 struct BpGraphCopySelector { 732 template <typename From, typename RedRefMap, 733 typename BlueRefMap, typename EdgeRefMap> 734 static void copy(BpGraph &to, const From& from, 735 RedRefMap& redRefMap, BlueRefMap& blueRefMap, 736 EdgeRefMap& edgeRefMap) { 737 for (typename From::RedIt it(from); it != INVALID; ++it) { 738 redRefMap[it] = to.addRed(); 739 } 740 for (typename From::BlueIt it(from); it != INVALID; ++it) { 741 blueRefMap[it] = to.addBlue(); 742 } 743 for (typename From::EdgeIt it(from); it != INVALID; ++it) { 744 edgeRefMap[it] = to.addArc(redRefMap[from.red(it)], 745 blueRefMap[from.blue(it)]); 746 } 747 } 748 }; 749 750 template <typename BpGraph> 751 struct BpGraphCopySelector< 752 BpGraph, 753 typename enable_if<typename BpGraph::BuildTag, void>::type> 754 { 755 template <typename From, typename RedRefMap, 756 typename BlueRefMap, typename EdgeRefMap> 757 static void copy(BpGraph &to, const From& from, 758 RedRefMap& redRefMap, BlueRefMap& blueRefMap, 759 EdgeRefMap& edgeRefMap) { 760 to.build(from, redRefMap, blueRefMap, edgeRefMap); 761 } 762 }; 763 764 653 765 } 654 766 … … 657 769 /// Class to copy a digraph to another digraph (duplicate a digraph). The 658 770 /// simplest way of using it is through the \c copyDigraph() function. 659 ///660 /// This class not just make a copy of a graph, but it can create661 /// references and cross references between the nodes and arcs of662 /// the two graphs, it can copy maps for use with the newly created663 /// graph and copy nodes and arcs.664 ///665 /// To make a copy from a graph, first an instance of DigraphCopy666 /// should be created, then the data belongs to the graph should667 /// assigned to copy. In the end, the \c run() member should be668 /// called.669 ///670 /// The next code copies a graph with several data:671 ///\code672 /// DigraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph);673 /// // create a reference for the nodes674 /// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph);675 /// dc.nodeRef(nr);676 /// // create a cross reference (inverse) for the arcs677 /// NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph);678 /// dc.arcCrossRef(acr);679 /// // copy an arc map680 /// OrigGraph::ArcMap<double> oamap(orig_graph);681 /// NewGraph::ArcMap<double> namap(new_graph);682 /// dc.arcMap(namap, oamap);683 /// // copy a node684 /// OrigGraph::Node on;685 /// NewGraph::Node nn;686 /// dc.node(nn, on);687 /// // Executions of copy688 /// dc.run();689 ///\endcode690 771 template <typename To, typename From> 691 772 class DigraphCopy { … … 711 792 /// It copies the content of the \c _from digraph into the 712 793 /// \c _to digraph. 713 DigraphCopy(To& to, const From&from)714 : _from(from), _to(to) {}794 DigraphCopy(To& _to, const From& _from) 795 : from(_from), to(_to) {} 715 796 716 797 /// \brief Destructor of the DigraphCopy … … 718 799 /// Destructor of the DigraphCopy 719 800 ~DigraphCopy() { 720 for (int i = 0; i < int( _node_maps.size()); ++i) {721 delete _node_maps[i];722 } 723 for (int i = 0; i < int( _arc_maps.size()); ++i) {724 delete _arc_maps[i];801 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 802 delete nodeMapCopies[i]; 803 } 804 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 805 delete arcMapCopies[i]; 725 806 } 726 807 … … 729 810 /// \brief Copies the node references into the given map. 730 811 /// 731 /// Copies the node references into the given map. The parameter 732 /// should be a map, which key type is the Node type of the source 733 /// graph, while the value type is the Node type of the 734 /// destination graph. 812 /// Copies the node references into the given map. 735 813 template <typename NodeRef> 736 814 DigraphCopy& nodeRef(NodeRef& map) { 737 _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node,738 815 nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 816 NodeRefMap, NodeRef>(map)); 739 817 return *this; 740 818 } … … 743 821 /// 744 822 /// Copies the node cross references (reverse references) into 745 /// the given map. The parameter should be a map, which key type 746 /// is the Node type of the destination graph, while the value type is 747 /// the Node type of the source graph. 823 /// the given map. 748 824 template <typename NodeCrossRef> 749 825 DigraphCopy& nodeCrossRef(NodeCrossRef& map) { 750 _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,751 826 nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node, 827 NodeRefMap, NodeCrossRef>(map)); 752 828 return *this; 753 829 } … … 755 831 /// \brief Make copy of the given map. 756 832 /// 757 /// Makes copy of the given map for the newly created digraph. 758 /// The new map's key type is the destination graph's node type, 759 /// and the copied map's key type is the source graph's node type. 833 /// Makes copy of the given map for the newly created digraph. 834 /// The new map's key type is the to digraph's node type, 835 /// and the copied map's key type is the from digraph's node 836 /// type. 760 837 template <typename ToMap, typename FromMap> 761 838 DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 762 _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node,763 839 nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 840 NodeRefMap, ToMap, FromMap>(tmap, map)); 764 841 return *this; 765 842 } … … 769 846 /// Make a copy of the given node. 770 847 DigraphCopy& node(TNode& tnode, const Node& snode) { 771 _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node,772 848 nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 849 NodeRefMap, TNode>(tnode, snode)); 773 850 return *this; 774 851 } … … 779 856 template <typename ArcRef> 780 857 DigraphCopy& arcRef(ArcRef& map) { 781 _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc,782 858 arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 859 ArcRefMap, ArcRef>(map)); 783 860 return *this; 784 861 } … … 790 867 template <typename ArcCrossRef> 791 868 DigraphCopy& arcCrossRef(ArcCrossRef& map) { 792 _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc,793 869 arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc, 870 ArcRefMap, ArcCrossRef>(map)); 794 871 return *this; 795 872 } … … 803 880 template <typename ToMap, typename FromMap> 804 881 DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 805 _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc,806 882 arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 883 ArcRefMap, ToMap, FromMap>(tmap, map)); 807 884 return *this; 808 885 } … … 812 889 /// Make a copy of the given arc. 813 890 DigraphCopy& arc(TArc& tarc, const Arc& sarc) { 814 _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc,815 891 arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 892 ArcRefMap, TArc>(tarc, sarc)); 816 893 return *this; 817 894 } … … 821 898 /// Executes the copies. 822 899 void run() { 823 NodeRefMap nodeRefMap( _from);824 ArcRefMap arcRefMap( _from);825 _ graph_utils_bits::DigraphCopySelector<To>::826 copy( _to, _from, nodeRefMap, arcRefMap);827 for (int i = 0; i < int( _node_maps.size()); ++i) {828 _node_maps[i]->copy(_from, nodeRefMap);829 } 830 for (int i = 0; i < int( _arc_maps.size()); ++i) {831 _arc_maps[i]->copy(_from, arcRefMap);900 NodeRefMap nodeRefMap(from); 901 ArcRefMap arcRefMap(from); 902 _digraph_utils_bits::DigraphCopySelector<To>:: 903 copy(to, from, nodeRefMap, arcRefMap); 904 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 905 nodeMapCopies[i]->copy(from, nodeRefMap); 906 } 907 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 908 arcMapCopies[i]->copy(from, arcRefMap); 832 909 } 833 910 } … … 836 913 837 914 838 const From& _from;839 To& _to;840 841 std::vector<_ graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* >842 _node_maps;843 844 std::vector<_ graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* >845 _arc_maps;915 const From& from; 916 To& to; 917 918 std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 919 nodeMapCopies; 920 921 std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 922 arcMapCopies; 846 923 847 924 }; … … 849 926 /// \brief Copy a digraph to another digraph. 850 927 /// 851 /// Copy a digraph to another digraph. The complete usage of the852 /// function is detailed in the DigraphCopy class, but a short853 /// example shows a basic work:928 /// Copy a digraph to another digraph. 929 /// The usage of the function: 930 /// 854 931 ///\code 855 932 /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); … … 867 944 } 868 945 869 /// \brief Class to copy a graph. 870 /// 871 /// Class to copy a graph to another graph (duplicate a graph). The 872 /// simplest way of using it is through the \c copyGraph() function. 873 /// 874 /// This class not just make a copy of a graph, but it can create 875 /// references and cross references between the nodes, edges and arcs of 876 /// the two graphs, it can copy maps for use with the newly created 877 /// graph and copy nodes, edges and arcs. 878 /// 879 /// To make a copy from a graph, first an instance of GraphCopy 880 /// should be created, then the data belongs to the graph should 881 /// assigned to copy. In the end, the \c run() member should be 882 /// called. 883 /// 884 /// The next code copies a graph with several data: 885 ///\code 886 /// GraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph); 887 /// // create a reference for the nodes 888 /// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); 889 /// dc.nodeRef(nr); 890 /// // create a cross reference (inverse) for the edges 891 /// NewGraph::EdgeMap<OrigGraph::Arc> ecr(new_graph); 892 /// dc.edgeCrossRef(ecr); 893 /// // copy an arc map 894 /// OrigGraph::ArcMap<double> oamap(orig_graph); 895 /// NewGraph::ArcMap<double> namap(new_graph); 896 /// dc.arcMap(namap, oamap); 897 /// // copy a node 898 /// OrigGraph::Node on; 899 /// NewGraph::Node nn; 900 /// dc.node(nn, on); 901 /// // Executions of copy 902 /// dc.run(); 903 ///\endcode 946 /// \brief Class to copy an graph. 947 /// 948 /// Class to copy an graph to another digraph (duplicate a digraph). 949 /// The simplest way of using it is through the \c copyGraph() function. 904 950 template <typename To, typename From> 905 951 class GraphCopy { … … 921 967 922 968 struct ArcRefMap { 923 ArcRefMap(const To& to, const From&from,924 const EdgeRefMap& edge_ref, const NodeRefMap&node_ref)925 : _to(to), _from(from),926 _edge_ref(edge_ref), _node_ref(node_ref) {}969 ArcRefMap(const To& _to, const From& _from, 970 const EdgeRefMap& _edge_ref, const NodeRefMap& _node_ref) 971 : to(_to), from(_from), 972 edge_ref(_edge_ref), node_ref(_node_ref) {} 927 973 928 974 typedef typename From::Arc Key; … … 931 977 Value operator[](const Key& key) const { 932 978 bool forward = 933 (_from.direction(key) == 934 (_node_ref[_from.source(key)] == _to.source(_edge_ref[key]))); 935 return _to.direct(_edge_ref[key], forward); 979 (from.direction(key) == 980 (node_ref[from.source(static_cast<const Edge&>(key))] == 981 to.source(edge_ref[static_cast<const Edge&>(key)]))); 982 return to.direct(edge_ref[key], forward); 936 983 } 937 984 938 const To& _to;939 const From& _from;940 const EdgeRefMap& _edge_ref;941 const NodeRefMap& _node_ref;985 const To& to; 986 const From& from; 987 const EdgeRefMap& edge_ref; 988 const NodeRefMap& node_ref; 942 989 }; 943 990 … … 946 993 947 994 948 /// \brief Constructor for the GraphCopy.949 /// 950 /// It copies the content of the \c _from graph into the951 /// \c _to graph.952 GraphCopy(To& to, const From&from)953 : _from(from), _to(to) {}954 955 /// \brief Destructor of the GraphCopy956 /// 957 /// Destructor of the GraphCopy995 /// \brief Constructor for the DigraphCopy. 996 /// 997 /// It copies the content of the \c _from digraph into the 998 /// \c _to digraph. 999 GraphCopy(To& _to, const From& _from) 1000 : from(_from), to(_to) {} 1001 1002 /// \brief Destructor of the DigraphCopy 1003 /// 1004 /// Destructor of the DigraphCopy 958 1005 ~GraphCopy() { 959 for (int i = 0; i < int( _node_maps.size()); ++i) {960 delete _node_maps[i];961 } 962 for (int i = 0; i < int( _arc_maps.size()); ++i) {963 delete _arc_maps[i];964 } 965 for (int i = 0; i < int( _edge_maps.size()); ++i) {966 delete _edge_maps[i];1006 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 1007 delete nodeMapCopies[i]; 1008 } 1009 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 1010 delete arcMapCopies[i]; 1011 } 1012 for (int i = 0; i < int(edgeMapCopies.size()); ++i) { 1013 delete edgeMapCopies[i]; 967 1014 } 968 1015 … … 974 1021 template <typename NodeRef> 975 1022 GraphCopy& nodeRef(NodeRef& map) { 976 _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node,977 1023 nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 1024 NodeRefMap, NodeRef>(map)); 978 1025 return *this; 979 1026 } … … 985 1032 template <typename NodeCrossRef> 986 1033 GraphCopy& nodeCrossRef(NodeCrossRef& map) { 987 _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,988 1034 nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node, 1035 NodeRefMap, NodeCrossRef>(map)); 989 1036 return *this; 990 1037 } … … 992 1039 /// \brief Make copy of the given map. 993 1040 /// 994 /// Makes copy of the given map for the newly created graph.995 /// The new map's key type is the to graph's node type,996 /// and the copied map's key type is the from graph's node1041 /// Makes copy of the given map for the newly created digraph. 1042 /// The new map's key type is the to digraph's node type, 1043 /// and the copied map's key type is the from digraph's node 997 1044 /// type. 998 1045 template <typename ToMap, typename FromMap> 999 1046 GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 1000 _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node,1001 1047 nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 1048 NodeRefMap, ToMap, FromMap>(tmap, map)); 1002 1049 return *this; 1003 1050 } … … 1007 1054 /// Make a copy of the given node. 1008 1055 GraphCopy& node(TNode& tnode, const Node& snode) { 1009 _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node,1010 1056 nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 1057 NodeRefMap, TNode>(tnode, snode)); 1011 1058 return *this; 1012 1059 } … … 1017 1064 template <typename ArcRef> 1018 1065 GraphCopy& arcRef(ArcRef& map) { 1019 _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc,1020 1066 arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 1067 ArcRefMap, ArcRef>(map)); 1021 1068 return *this; 1022 1069 } … … 1028 1075 template <typename ArcCrossRef> 1029 1076 GraphCopy& arcCrossRef(ArcCrossRef& map) { 1030 _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc,1031 1077 arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc, 1078 ArcRefMap, ArcCrossRef>(map)); 1032 1079 return *this; 1033 1080 } … … 1035 1082 /// \brief Make copy of the given map. 1036 1083 /// 1037 /// Makes copy of the given map for the newly created graph.1038 /// The new map's key type is the to graph's arc type,1039 /// and the copied map's key type is the from graph's arc1084 /// Makes copy of the given map for the newly created digraph. 1085 /// The new map's key type is the to digraph's arc type, 1086 /// and the copied map's key type is the from digraph's arc 1040 1087 /// type. 1041 1088 template <typename ToMap, typename FromMap> 1042 1089 GraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 1043 _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc,1044 1090 arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 1091 ArcRefMap, ToMap, FromMap>(tmap, map)); 1045 1092 return *this; 1046 1093 } … … 1050 1097 /// Make a copy of the given arc. 1051 1098 GraphCopy& arc(TArc& tarc, const Arc& sarc) { 1052 _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc,1053 1099 arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 1100 ArcRefMap, TArc>(tarc, sarc)); 1054 1101 return *this; 1055 1102 } … … 1060 1107 template <typename EdgeRef> 1061 1108 GraphCopy& edgeRef(EdgeRef& map) { 1062 _edge_maps.push_back(new _graph_utils_bits::RefCopy<From, Edge,1063 1109 edgeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Edge, 1110 EdgeRefMap, EdgeRef>(map)); 1064 1111 return *this; 1065 1112 } … … 1071 1118 template <typename EdgeCrossRef> 1072 1119 GraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1073 _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy<From,1074 1120 edgeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 1121 Edge, EdgeRefMap, EdgeCrossRef>(map)); 1075 1122 return *this; 1076 1123 } … … 1078 1125 /// \brief Make copy of the given map. 1079 1126 /// 1080 /// Makes copy of the given map for the newly created graph.1081 /// The new map's key type is the to graph's edge type,1082 /// and the copied map's key type is the from graph's edge1127 /// Makes copy of the given map for the newly created digraph. 1128 /// The new map's key type is the to digraph's edge type, 1129 /// and the copied map's key type is the from digraph's edge 1083 1130 /// type. 1084 1131 template <typename ToMap, typename FromMap> 1085 1132 GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) { 1086 _edge_maps.push_back(new _graph_utils_bits::MapCopy<From, Edge,1087 1133 edgeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Edge, 1134 EdgeRefMap, ToMap, FromMap>(tmap, map)); 1088 1135 return *this; 1089 1136 } … … 1093 1140 /// Make a copy of the given edge. 1094 1141 GraphCopy& edge(TEdge& tedge, const Edge& sedge) { 1095 _edge_maps.push_back(new _graph_utils_bits::ItemCopy<From, Edge,1096 1142 edgeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Edge, 1143 EdgeRefMap, TEdge>(tedge, sedge)); 1097 1144 return *this; 1098 1145 } … … 1102 1149 /// Executes the copies. 1103 1150 void run() { 1104 NodeRefMap nodeRefMap( _from);1105 EdgeRefMap edgeRefMap( _from);1106 ArcRefMap arcRefMap( _to, _from, edgeRefMap, nodeRefMap);1107 _ graph_utils_bits::GraphCopySelector<To>::1108 copy( _to, _from, nodeRefMap, edgeRefMap);1109 for (int i = 0; i < int( _node_maps.size()); ++i) {1110 _node_maps[i]->copy(_from, nodeRefMap);1111 } 1112 for (int i = 0; i < int( _edge_maps.size()); ++i) {1113 _edge_maps[i]->copy(_from, edgeRefMap);1114 } 1115 for (int i = 0; i < int( _arc_maps.size()); ++i) {1116 _arc_maps[i]->copy(_from, arcRefMap);1151 NodeRefMap nodeRefMap(from); 1152 EdgeRefMap edgeRefMap(from); 1153 ArcRefMap arcRefMap(to, from, edgeRefMap, nodeRefMap); 1154 _digraph_utils_bits::GraphCopySelector<To>:: 1155 copy(to, from, nodeRefMap, edgeRefMap); 1156 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 1157 nodeMapCopies[i]->copy(from, nodeRefMap); 1158 } 1159 for (int i = 0; i < int(edgeMapCopies.size()); ++i) { 1160 edgeMapCopies[i]->copy(from, edgeRefMap); 1161 } 1162 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 1163 arcMapCopies[i]->copy(from, arcRefMap); 1117 1164 } 1118 1165 } … … 1120 1167 private: 1121 1168 1122 const From& _from;1123 To& _to;1124 1125 std::vector<_ graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* >1126 _node_maps;1127 1128 std::vector<_ graph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* >1129 _arc_maps;1130 1131 std::vector<_ graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* >1132 _edge_maps;1169 const From& from; 1170 To& to; 1171 1172 std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 1173 nodeMapCopies; 1174 1175 std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 1176 arcMapCopies; 1177 1178 std::vector<_digraph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 1179 edgeMapCopies; 1133 1180 1134 1181 }; 1135 1182 1136 /// \brief Copy a graph to anothergraph.1137 /// 1138 /// Copy a graph to another graph. The complete usage of the1139 /// function is detailed in the GraphCopy class, but a short1140 /// example shows a basic work:1183 /// \brief Copy an graph to another digraph. 1184 /// 1185 /// Copy an graph to another digraph. 1186 /// The usage of the function: 1187 /// 1141 1188 ///\code 1142 1189 /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); … … 1144 1191 /// 1145 1192 /// After the copy the \c nr map will contain the mapping from the 1146 /// nodes of the \c from graph to the nodes of the \c tograph and1147 /// \c ecr will contain the mapping from the arcs of the \c to graph1148 /// to the arcs of the \c from graph.1193 /// nodes of the \c from digraph to the nodes of the \c to digraph and 1194 /// \c ecr will contain the mapping from the arcs of the \c to digraph 1195 /// to the arcs of the \c from digraph. 1149 1196 /// 1150 1197 /// \see GraphCopy … … 1155 1202 } 1156 1203 1204 /// \brief Class to copy a bipartite digraph. 1205 /// 1206 /// Class to copy a bipartite digraph to another digraph 1207 /// (duplicate a digraph). The simplest way of using it is through 1208 /// the \c copyBpGraph() function. 1209 template <typename To, typename From> 1210 class BpGraphCopy { 1211 private: 1212 1213 typedef typename From::Node Node; 1214 typedef typename From::Red Red; 1215 typedef typename From::Blue Blue; 1216 typedef typename From::NodeIt NodeIt; 1217 typedef typename From::Arc Arc; 1218 typedef typename From::ArcIt ArcIt; 1219 typedef typename From::Edge Edge; 1220 typedef typename From::EdgeIt EdgeIt; 1221 1222 typedef typename To::Node TNode; 1223 typedef typename To::Arc TArc; 1224 typedef typename To::Edge TEdge; 1225 1226 typedef typename From::template RedMap<TNode> RedRefMap; 1227 typedef typename From::template BlueMap<TNode> BlueRefMap; 1228 typedef typename From::template EdgeMap<TEdge> EdgeRefMap; 1229 1230 struct NodeRefMap { 1231 NodeRefMap(const From& _from, const RedRefMap& _red_ref, 1232 const BlueRefMap& _blue_ref) 1233 : from(_from), red_ref(_red_ref), blue_ref(_blue_ref) {} 1234 1235 typedef typename From::Node Key; 1236 typedef typename To::Node Value; 1237 1238 Value operator[](const Key& key) const { 1239 return from.red(key) ? red_ref[key] : blue_ref[key]; 1240 } 1241 1242 const From& from; 1243 const RedRefMap& red_ref; 1244 const BlueRefMap& blue_ref; 1245 }; 1246 1247 struct ArcRefMap { 1248 ArcRefMap(const To& _to, const From& _from, 1249 const EdgeRefMap& _edge_ref, const NodeRefMap& _node_ref) 1250 : to(_to), from(_from), 1251 edge_ref(_edge_ref), node_ref(_node_ref) {} 1252 1253 typedef typename From::Arc Key; 1254 typedef typename To::Arc Value; 1255 1256 Value operator[](const Key& key) const { 1257 bool forward = 1258 (from.direction(key) == 1259 (node_ref[from.source(static_cast<const Edge&>(key))] == 1260 to.source(edge_ref[static_cast<const Edge&>(key)]))); 1261 return to.direct(edge_ref[key], forward); 1262 } 1263 1264 const To& to; 1265 const From& from; 1266 const EdgeRefMap& edge_ref; 1267 const NodeRefMap& node_ref; 1268 }; 1269 1270 public: 1271 1272 1273 /// \brief Constructor for the DigraphCopy. 1274 /// 1275 /// It copies the content of the \c _from digraph into the 1276 /// \c _to digraph. 1277 BpGraphCopy(To& _to, const From& _from) 1278 : from(_from), to(_to) {} 1279 1280 /// \brief Destructor of the DigraphCopy 1281 /// 1282 /// Destructor of the DigraphCopy 1283 ~BpGraphCopy() { 1284 for (int i = 0; i < int(redMapCopies.size()); ++i) { 1285 delete redMapCopies[i]; 1286 } 1287 for (int i = 0; i < int(blueMapCopies.size()); ++i) { 1288 delete blueMapCopies[i]; 1289 } 1290 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 1291 delete nodeMapCopies[i]; 1292 } 1293 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 1294 delete arcMapCopies[i]; 1295 } 1296 for (int i = 0; i < int(edgeMapCopies.size()); ++i) { 1297 delete edgeMapCopies[i]; 1298 } 1299 1300 } 1301 1302 /// \brief Copies the A-node references into the given map. 1303 /// 1304 /// Copies the A-node references into the given map. 1305 template <typename RedRef> 1306 BpGraphCopy& redRef(RedRef& map) { 1307 redMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Red, 1308 RedRefMap, RedRef>(map)); 1309 return *this; 1310 } 1311 1312 /// \brief Copies the A-node cross references into the given map. 1313 /// 1314 /// Copies the A-node cross references (reverse references) into 1315 /// the given map. 1316 template <typename RedCrossRef> 1317 BpGraphCopy& redCrossRef(RedCrossRef& map) { 1318 redMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 1319 Red, RedRefMap, RedCrossRef>(map)); 1320 return *this; 1321 } 1322 1323 /// \brief Make copy of the given A-node map. 1324 /// 1325 /// Makes copy of the given map for the newly created digraph. 1326 /// The new map's key type is the to digraph's node type, 1327 /// and the copied map's key type is the from digraph's node 1328 /// type. 1329 template <typename ToMap, typename FromMap> 1330 BpGraphCopy& redMap(ToMap& tmap, const FromMap& map) { 1331 redMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Red, 1332 RedRefMap, ToMap, FromMap>(tmap, map)); 1333 return *this; 1334 } 1335 1336 /// \brief Copies the B-node references into the given map. 1337 /// 1338 /// Copies the B-node references into the given map. 1339 template <typename BlueRef> 1340 BpGraphCopy& blueRef(BlueRef& map) { 1341 blueMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Blue, 1342 BlueRefMap, BlueRef>(map)); 1343 return *this; 1344 } 1345 1346 /// \brief Copies the B-node cross references into the given map. 1347 /// 1348 /// Copies the B-node cross references (reverse references) into 1349 /// the given map. 1350 template <typename BlueCrossRef> 1351 BpGraphCopy& blueCrossRef(BlueCrossRef& map) { 1352 blueMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 1353 Blue, BlueRefMap, BlueCrossRef>(map)); 1354 return *this; 1355 } 1356 1357 /// \brief Make copy of the given B-node map. 1358 /// 1359 /// Makes copy of the given map for the newly created digraph. 1360 /// The new map's key type is the to digraph's node type, 1361 /// and the copied map's key type is the from digraph's node 1362 /// type. 1363 template <typename ToMap, typename FromMap> 1364 BpGraphCopy& blueMap(ToMap& tmap, const FromMap& map) { 1365 blueMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Blue, 1366 BlueRefMap, ToMap, FromMap>(tmap, map)); 1367 return *this; 1368 } 1369 /// \brief Copies the node references into the given map. 1370 /// 1371 /// Copies the node references into the given map. 1372 template <typename NodeRef> 1373 BpGraphCopy& nodeRef(NodeRef& map) { 1374 nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node, 1375 NodeRefMap, NodeRef>(map)); 1376 return *this; 1377 } 1378 1379 /// \brief Copies the node cross references into the given map. 1380 /// 1381 /// Copies the node cross references (reverse references) into 1382 /// the given map. 1383 template <typename NodeCrossRef> 1384 BpGraphCopy& nodeCrossRef(NodeCrossRef& map) { 1385 nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node, 1386 NodeRefMap, NodeCrossRef>(map)); 1387 return *this; 1388 } 1389 1390 /// \brief Make copy of the given map. 1391 /// 1392 /// Makes copy of the given map for the newly created digraph. 1393 /// The new map's key type is the to digraph's node type, 1394 /// and the copied map's key type is the from digraph's node 1395 /// type. 1396 template <typename ToMap, typename FromMap> 1397 BpGraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 1398 nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node, 1399 NodeRefMap, ToMap, FromMap>(tmap, map)); 1400 return *this; 1401 } 1402 1403 /// \brief Make a copy of the given node. 1404 /// 1405 /// Make a copy of the given node. 1406 BpGraphCopy& node(TNode& tnode, const Node& snode) { 1407 nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node, 1408 NodeRefMap, TNode>(tnode, snode)); 1409 return *this; 1410 } 1411 1412 /// \brief Copies the arc references into the given map. 1413 /// 1414 /// Copies the arc references into the given map. 1415 template <typename ArcRef> 1416 BpGraphCopy& arcRef(ArcRef& map) { 1417 arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc, 1418 ArcRefMap, ArcRef>(map)); 1419 return *this; 1420 } 1421 1422 /// \brief Copies the arc cross references into the given map. 1423 /// 1424 /// Copies the arc cross references (reverse references) into 1425 /// the given map. 1426 template <typename ArcCrossRef> 1427 BpGraphCopy& arcCrossRef(ArcCrossRef& map) { 1428 arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc, 1429 ArcRefMap, ArcCrossRef>(map)); 1430 return *this; 1431 } 1432 1433 /// \brief Make copy of the given map. 1434 /// 1435 /// Makes copy of the given map for the newly created digraph. 1436 /// The new map's key type is the to digraph's arc type, 1437 /// and the copied map's key type is the from digraph's arc 1438 /// type. 1439 template <typename ToMap, typename FromMap> 1440 BpGraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 1441 arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc, 1442 ArcRefMap, ToMap, FromMap>(tmap, map)); 1443 return *this; 1444 } 1445 1446 /// \brief Make a copy of the given arc. 1447 /// 1448 /// Make a copy of the given arc. 1449 BpGraphCopy& arc(TArc& tarc, const Arc& sarc) { 1450 arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc, 1451 ArcRefMap, TArc>(tarc, sarc)); 1452 return *this; 1453 } 1454 1455 /// \brief Copies the edge references into the given map. 1456 /// 1457 /// Copies the edge references into the given map. 1458 template <typename EdgeRef> 1459 BpGraphCopy& edgeRef(EdgeRef& map) { 1460 edgeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Edge, 1461 EdgeRefMap, EdgeRef>(map)); 1462 return *this; 1463 } 1464 1465 /// \brief Copies the edge cross references into the given map. 1466 /// 1467 /// Copies the edge cross references (reverse 1468 /// references) into the given map. 1469 template <typename EdgeCrossRef> 1470 BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1471 edgeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, 1472 Edge, EdgeRefMap, EdgeCrossRef>(map)); 1473 return *this; 1474 } 1475 1476 /// \brief Make copy of the given map. 1477 /// 1478 /// Makes copy of the given map for the newly created digraph. 1479 /// The new map's key type is the to digraph's edge type, 1480 /// and the copied map's key type is the from digraph's edge 1481 /// type. 1482 template <typename ToMap, typename FromMap> 1483 BpGraphCopy& edgeMap(ToMap& tmap, const FromMap& map) { 1484 edgeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Edge, 1485 EdgeRefMap, ToMap, FromMap>(tmap, map)); 1486 return *this; 1487 } 1488 1489 /// \brief Make a copy of the given edge. 1490 /// 1491 /// Make a copy of the given edge. 1492 BpGraphCopy& edge(TEdge& tedge, const Edge& sedge) { 1493 edgeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Edge, 1494 EdgeRefMap, TEdge>(tedge, sedge)); 1495 return *this; 1496 } 1497 1498 /// \brief Executes the copies. 1499 /// 1500 /// Executes the copies. 1501 void run() { 1502 RedRefMap redRefMap(from); 1503 BlueRefMap blueRefMap(from); 1504 NodeRefMap nodeRefMap(from, redRefMap, blueRefMap); 1505 EdgeRefMap edgeRefMap(from); 1506 ArcRefMap arcRefMap(to, from, edgeRefMap, nodeRefMap); 1507 _digraph_utils_bits::BpGraphCopySelector<To>:: 1508 copy(to, from, redRefMap, blueRefMap, edgeRefMap); 1509 for (int i = 0; i < int(redMapCopies.size()); ++i) { 1510 redMapCopies[i]->copy(from, redRefMap); 1511 } 1512 for (int i = 0; i < int(blueMapCopies.size()); ++i) { 1513 blueMapCopies[i]->copy(from, blueRefMap); 1514 } 1515 for (int i = 0; i < int(nodeMapCopies.size()); ++i) { 1516 nodeMapCopies[i]->copy(from, nodeRefMap); 1517 } 1518 for (int i = 0; i < int(edgeMapCopies.size()); ++i) { 1519 edgeMapCopies[i]->copy(from, edgeRefMap); 1520 } 1521 for (int i = 0; i < int(arcMapCopies.size()); ++i) { 1522 arcMapCopies[i]->copy(from, arcRefMap); 1523 } 1524 } 1525 1526 private: 1527 1528 const From& from; 1529 To& to; 1530 1531 std::vector<_digraph_utils_bits::MapCopyBase<From, Red, RedRefMap>* > 1532 redMapCopies; 1533 1534 std::vector<_digraph_utils_bits::MapCopyBase<From, Blue, BlueRefMap>* > 1535 blueMapCopies; 1536 1537 std::vector<_digraph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 1538 nodeMapCopies; 1539 1540 std::vector<_digraph_utils_bits::MapCopyBase<From, Arc, ArcRefMap>* > 1541 arcMapCopies; 1542 1543 std::vector<_digraph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 1544 edgeMapCopies; 1545 1546 }; 1547 1548 /// \brief Copy a bipartite digraph to another digraph. 1549 /// 1550 /// Copy a bipartite digraph to another digraph. 1551 /// The usage of the function: 1552 /// 1553 ///\code 1554 /// copyBpGraph(trg, src).redRef(anr).arcCrossRef(ecr).run(); 1555 ///\endcode 1556 /// 1557 /// After the copy the \c nr map will contain the mapping from the 1558 /// nodes of the \c from digraph to the nodes of the \c to digraph and 1559 /// \c ecr will contain the mapping from the arcs of the \c to digraph 1560 /// to the arcs of the \c from digraph. 1561 /// 1562 /// \see BpGraphCopy 1563 template <typename To, typename From> 1564 BpGraphCopy<To, From> 1565 copyBpGraph(To& to, const From& from) { 1566 return BpGraphCopy<To, From>(to, from); 1567 } 1568 1569 1157 1570 /// @} 1158 1571 1159 /// \addtogroup graph_maps1572 /// \addtogroup digraph_maps 1160 1573 /// @{ 1161 1574 1162 /// Provides an immutable and unique id for each item in the graph.1575 /// Provides an immutable and unique id for each item in the digraph. 1163 1576 1164 1577 /// The IdMap class provides a unique and immutable id for each item of the 1165 /// same type (e.g. node) in the graph. This id is <ul><li>\b unique:1578 /// same type (e.g. node) in the digraph. This id is <ul><li>\b unique: 1166 1579 /// different items (nodes) get different ids <li>\b immutable: the id of an 1167 1580 /// item (node) does not change (even if you delete other nodes). </ul> 1168 1581 /// Through this map you get access (i.e. can read) the inner id values of 1169 /// the items stored in the graph. This map can be inverted with its member1170 /// class \c InverseMap or with the \c operator() member.1171 /// 1172 template <typename _ Graph, typename _Item>1582 /// the items stored in the digraph. This map can be inverted with its member 1583 /// class \c InverseMap. 1584 /// 1585 template <typename _Digraph, typename _Item> 1173 1586 class IdMap { 1174 1587 public: 1175 typedef _ Graph Graph;1588 typedef _Digraph Digraph; 1176 1589 typedef int Value; 1177 1590 typedef _Item Item; … … 1181 1594 /// 1182 1595 /// Constructor of the map. 1183 explicit IdMap(const Graph& graph) : _graph(&graph) {}1596 explicit IdMap(const Digraph& _digraph) : digraph(&_digraph) {} 1184 1597 1185 1598 /// \brief Gives back the \e id of the item. 1186 1599 /// 1187 1600 /// Gives back the immutable and unique \e id of the item. 1188 int operator[](const Item& item) const { return _graph->id(item);}1601 int operator[](const Item& item) const { return digraph->id(item);} 1189 1602 1190 1603 /// \brief Gives back the item by its id. 1191 1604 /// 1192 1605 /// Gives back the item by its id. 1193 Item operator()(int id) { return _graph->fromId(id, Item()); }1606 Item operator()(int id) { return digraph->fromId(id, Item()); } 1194 1607 1195 1608 private: 1196 const Graph* _graph;1609 const Digraph* digraph; 1197 1610 1198 1611 public: … … 1208 1621 /// 1209 1622 /// Constructor for creating an id-to-item map. 1210 explicit InverseMap(const Graph& graph) : _graph(&graph) {}1623 explicit InverseMap(const Digraph& _digraph) : digraph(&_digraph) {} 1211 1624 1212 1625 /// \brief Constructor. 1213 1626 /// 1214 1627 /// Constructor for creating an id-to-item map. 1215 explicit InverseMap(const IdMap& map) : _graph(map._graph) {}1628 explicit InverseMap(const IdMap& idMap) : digraph(idMap.digraph) {} 1216 1629 1217 1630 /// \brief Gives back the given item from its id. … … 1219 1632 /// Gives back the given item from its id. 1220 1633 /// 1221 Item operator[](int id) const { return _graph->fromId(id, Item());}1634 Item operator[](int id) const { return digraph->fromId(id, Item());} 1222 1635 1223 1636 private: 1224 const Graph* _graph;1637 const Digraph* digraph; 1225 1638 }; 1226 1639 … … 1228 1641 /// 1229 1642 /// Gives back the inverse of the IdMap. 1230 InverseMap inverse() const { return InverseMap(* _graph);}1643 InverseMap inverse() const { return InverseMap(*digraph);} 1231 1644 1232 1645 }; 1233 1646 1234 1647 1235 /// \brief General invertable graph-map type.1236 1237 /// This type provides simple invertable graph-maps.1648 /// \brief General invertable digraph-map type. 1649 1650 /// This type provides simple invertable digraph-maps. 1238 1651 /// The InvertableMap wraps an arbitrary ReadWriteMap 1239 1652 /// and if a key is set to a new value then store it … … 1243 1656 /// with stl compatible forward iterator. 1244 1657 /// 1245 /// \param _ Graph Thegraph type.1246 /// \param _Item The item type of the graph.1658 /// \param _Digraph The digraph type. 1659 /// \param _Item The item type of the digraph. 1247 1660 /// \param _Value The value type of the map. 1248 1661 /// 1249 1662 /// \see IterableValueMap 1250 template <typename _ Graph, typename _Item, typename _Value>1251 class InvertableMap : protected DefaultMap<_ Graph, _Item, _Value> {1663 template <typename _Digraph, typename _Item, typename _Value> 1664 class InvertableMap : protected DefaultMap<_Digraph, _Item, _Value> { 1252 1665 private: 1253 1666 1254 typedef DefaultMap<_ Graph, _Item, _Value> Map;1255 typedef _ Graph Graph;1667 typedef DefaultMap<_Digraph, _Item, _Value> Map; 1668 typedef _Digraph Digraph; 1256 1669 1257 1670 typedef std::map<_Value, _Item> Container; 1258 Container _inv_map;1671 Container invMap; 1259 1672 1260 1673 public: … … 1269 1682 /// \brief Constructor. 1270 1683 /// 1271 /// Construct a new InvertableMap for the graph.1272 /// 1273 explicit InvertableMap(const Graph& graph) : Map(graph) {}1684 /// Construct a new InvertableMap for the digraph. 1685 /// 1686 explicit InvertableMap(const Digraph& digraph) : Map(digraph) {} 1274 1687 1275 1688 /// \brief Forward iterator for values. … … 1313 1726 /// range. 1314 1727 ValueIterator beginValue() const { 1315 return ValueIterator( _inv_map.begin());1728 return ValueIterator(invMap.begin()); 1316 1729 } 1317 1730 … … 1323 1736 /// range. 1324 1737 ValueIterator endValue() const { 1325 return ValueIterator( _inv_map.end());1738 return ValueIterator(invMap.end()); 1326 1739 } 1327 1740 … … 1331 1744 void set(const Key& key, const Value& val) { 1332 1745 Value oldval = Map::operator[](key); 1333 typename Container::iterator it = _inv_map.find(oldval);1334 if (it != _inv_map.end() && it->second == key) {1335 _inv_map.erase(it);1746 typename Container::iterator it = invMap.find(oldval); 1747 if (it != invMap.end() && it->second == key) { 1748 invMap.erase(it); 1336 1749 } 1337 _inv_map.insert(make_pair(val, key));1750 invMap.insert(make_pair(val, key)); 1338 1751 Map::set(key, val); 1339 1752 } … … 1351 1764 /// Gives back the item by its value. 1352 1765 Key operator()(const Value& key) const { 1353 typename Container::const_iterator it = _inv_map.find(key);1354 return it != _inv_map.end() ? it->second : INVALID;1766 typename Container::const_iterator it = invMap.find(key); 1767 return it != invMap.end() ? it->second : INVALID; 1355 1768 } 1356 1769 … … 1363 1776 virtual void erase(const Key& key) { 1364 1777 Value val = Map::operator[](key); 1365 typename Container::iterator it = _inv_map.find(val);1366 if (it != _inv_map.end() && it->second == key) {1367 _inv_map.erase(it);1778 typename Container::iterator it = invMap.find(val); 1779 if (it != invMap.end() && it->second == key) { 1780 invMap.erase(it); 1368 1781 } 1369 1782 Map::erase(key); … … 1377 1790 for (int i = 0; i < int(keys.size()); ++i) { 1378 1791 Value val = Map::operator[](keys[i]); 1379 typename Container::iterator it = _inv_map.find(val);1380 if (it != _inv_map.end() && it->second == keys[i]) {1381 _inv_map.erase(it);1792 typename Container::iterator it = invMap.find(val); 1793 if (it != invMap.end() && it->second == keys[i]) { 1794 invMap.erase(it); 1382 1795 } 1383 1796 } … … 1390 1803 /// \c AlterationNotifier. 1391 1804 virtual void clear() { 1392 _inv_map.clear();1805 invMap.clear(); 1393 1806 Map::clear(); 1394 1807 } … … 1405 1818 /// 1406 1819 /// Constructor of the InverseMap. 1407 explicit InverseMap(const InvertableMap& inverted)1408 : _inverted(inverted) {}1820 explicit InverseMap(const InvertableMap& _inverted) 1821 : inverted(_inverted) {} 1409 1822 1410 1823 /// The value type of the InverseMap. … … 1418 1831 /// what was last assigned to the value. 1419 1832 Value operator[](const Key& key) const { 1420 return _inverted(key);1833 return inverted(key); 1421 1834 } 1422 1835 1423 1836 private: 1424 const InvertableMap& _inverted;1837 const InvertableMap& inverted; 1425 1838 }; 1426 1839 … … 1437 1850 1438 1851 /// \brief Provides a mutable, continuous and unique descriptor for each 1439 /// item in the graph.1852 /// item in the digraph. 1440 1853 /// 1441 1854 /// The DescriptorMap class provides a unique and continuous (but mutable) 1442 1855 /// descriptor (id) for each item of the same type (e.g. node) in the 1443 /// graph. This id is <ul><li>\b unique: different items (nodes) get1856 /// digraph. This id is <ul><li>\b unique: different items (nodes) get 1444 1857 /// different ids <li>\b continuous: the range of the ids is the set of 1445 1858 /// integers between 0 and \c n-1, where \c n is the number of the items of 1446 1859 /// this type (e.g. nodes) (so the id of a node can change if you delete an 1447 1860 /// other node, i.e. this id is mutable). </ul> This map can be inverted 1448 /// with its member class \c InverseMap , or with the \c operator() member.1449 /// 1450 /// \param _ Graph Thegraph class the \c DescriptorMap belongs to.1861 /// with its member class \c InverseMap. 1862 /// 1863 /// \param _Digraph The digraph class the \c DescriptorMap belongs to. 1451 1864 /// \param _Item The Item is the Key of the Map. It may be Node, Arc or 1452 1865 /// Edge. 1453 template <typename _ Graph, typename _Item>1454 class DescriptorMap : protected DefaultMap<_ Graph, _Item, int> {1866 template <typename _Digraph, typename _Item> 1867 class DescriptorMap : protected DefaultMap<_Digraph, _Item, int> { 1455 1868 1456 1869 typedef _Item Item; 1457 typedef DefaultMap<_ Graph, _Item, int> Map;1870 typedef DefaultMap<_Digraph, _Item, int> Map; 1458 1871 1459 1872 public: 1460 /// The graph class of DescriptorMap.1461 typedef _ Graph Graph;1873 /// The digraph class of DescriptorMap. 1874 typedef _Digraph Digraph; 1462 1875 1463 1876 /// The key type of DescriptorMap (Node, Arc, Edge). … … 1469 1882 /// 1470 1883 /// Constructor for descriptor map. 1471 explicit DescriptorMap(const Graph& _graph) : Map(_graph) {1884 explicit DescriptorMap(const Digraph& _digraph) : Map(_digraph) { 1472 1885 Item it; 1473 1886 const typename Map::Notifier* nf = Map::notifier(); 1474 1887 for (nf->first(it); it != INVALID; nf->next(it)) { 1475 Map::set(it, _inv_map.size());1476 _inv_map.push_back(it);1888 Map::set(it, invMap.size()); 1889 invMap.push_back(it); 1477 1890 } 1478 1891 } … … 1486 1899 virtual void add(const Item& item) { 1487 1900 Map::add(item); 1488 Map::set(item, _inv_map.size());1489 _inv_map.push_back(item);1901 Map::set(item, invMap.size()); 1902 invMap.push_back(item); 1490 1903 } 1491 1904 … … 1497 1910 Map::add(items); 1498 1911 for (int i = 0; i < int(items.size()); ++i) { 1499 Map::set(items[i], _inv_map.size());1500 _inv_map.push_back(items[i]);1912 Map::set(items[i], invMap.size()); 1913 invMap.push_back(items[i]); 1501 1914 } 1502 1915 } … … 1507 1920 /// \c AlterationNotifier. 1508 1921 virtual void erase(const Item& item) { 1509 Map::set( _inv_map.back(), Map::operator[](item));1510 _inv_map[Map::operator[](item)] = _inv_map.back();1511 _inv_map.pop_back();1922 Map::set(invMap.back(), Map::operator[](item)); 1923 invMap[Map::operator[](item)] = invMap.back(); 1924 invMap.pop_back(); 1512 1925 Map::erase(item); 1513 1926 } … … 1519 1932 virtual void erase(const std::vector<Item>& items) { 1520 1933 for (int i = 0; i < int(items.size()); ++i) { 1521 Map::set( _inv_map.back(), Map::operator[](items[i]));1522 _inv_map[Map::operator[](items[i])] = _inv_map.back();1523 _inv_map.pop_back();1934 Map::set(invMap.back(), Map::operator[](items[i])); 1935 invMap[Map::operator[](items[i])] = invMap.back(); 1936 invMap.pop_back(); 1524 1937 } 1525 1938 Map::erase(items); … … 1535 1948 const typename Map::Notifier* nf = Map::notifier(); 1536 1949 for (nf->first(it); it != INVALID; nf->next(it)) { 1537 Map::set(it, _inv_map.size());1538 _inv_map.push_back(it);1950 Map::set(it, invMap.size()); 1951 invMap.push_back(it); 1539 1952 } 1540 1953 } … … 1545 1958 /// \c AlterationNotifier. 1546 1959 virtual void clear() { 1547 _inv_map.clear();1960 invMap.clear(); 1548 1961 Map::clear(); 1549 1962 } … … 1555 1968 /// Returns the maximal value plus one in the map. 1556 1969 unsigned int size() const { 1557 return _inv_map.size();1970 return invMap.size(); 1558 1971 } 1559 1972 … … 1565 1978 int qi = Map::operator[](q); 1566 1979 Map::set(p, qi); 1567 _inv_map[qi] = p;1980 invMap[qi] = p; 1568 1981 Map::set(q, pi); 1569 _inv_map[pi] = q;1982 invMap[pi] = q; 1570 1983 } 1571 1984 … … 1581 1994 /// Gives back th item by its descriptor. 1582 1995 Item operator()(int id) const { 1583 return _inv_map[id];1996 return invMap[id]; 1584 1997 } 1585 1998 … … 1587 2000 1588 2001 typedef std::vector<Item> Container; 1589 Container _inv_map;2002 Container invMap; 1590 2003 1591 2004 public: … … 1598 2011 /// 1599 2012 /// Constructor of the InverseMap. 1600 explicit InverseMap(const DescriptorMap& inverted)1601 : _inverted(inverted) {}2013 explicit InverseMap(const DescriptorMap& _inverted) 2014 : inverted(_inverted) {} 1602 2015 1603 2016 … … 1612 2025 /// that the descriptor belongs to currently. 1613 2026 Value operator[](const Key& key) const { 1614 return _inverted(key);2027 return inverted(key); 1615 2028 } 1616 2029 … … 1619 2032 /// Returns the size of the map. 1620 2033 unsigned int size() const { 1621 return _inverted.size();2034 return inverted.size(); 1622 2035 } 1623 2036 1624 2037 private: 1625 const DescriptorMap& _inverted;2038 const DescriptorMap& inverted; 1626 2039 }; 1627 2040 … … 1650 2063 /// Constructor 1651 2064 /// \param _digraph The digraph that the map belongs to. 1652 explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {}2065 explicit SourceMap(const Digraph& _digraph) : digraph(_digraph) {} 1653 2066 1654 2067 /// \brief The subscript operator. … … 1658 2071 /// \return The source of the arc 1659 2072 Value operator[](const Key& arc) const { 1660 return _digraph.source(arc);2073 return digraph.source(arc); 1661 2074 } 1662 2075 1663 2076 private: 1664 const Digraph& _digraph;2077 const Digraph& digraph; 1665 2078 }; 1666 2079 … … 1690 2103 /// Constructor 1691 2104 /// \param _digraph The digraph that the map belongs to. 1692 explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {}2105 explicit TargetMap(const Digraph& _digraph) : digraph(_digraph) {} 1693 2106 1694 2107 /// \brief The subscript operator. … … 1698 2111 /// \return The target of the arc 1699 2112 Value operator[](const Key& e) const { 1700 return _digraph.target(e);2113 return digraph.target(e); 1701 2114 } 1702 2115 1703 2116 private: 1704 const Digraph& _digraph;2117 const Digraph& digraph; 1705 2118 }; 1706 2119 … … 1719 2132 /// \see BackwardMap 1720 2133 /// \author Balazs Dezso 1721 template <typename Graph>2134 template <typename Digraph> 1722 2135 class ForwardMap { 1723 2136 public: 1724 2137 1725 typedef typename Graph::Arc Value;1726 typedef typename Graph::Edge Key;2138 typedef typename Digraph::Arc Value; 2139 typedef typename Digraph::Edge Key; 1727 2140 1728 2141 /// \brief Constructor 1729 2142 /// 1730 2143 /// Constructor 1731 /// \param _ graph Thegraph that the map belongs to.1732 explicit ForwardMap(const Graph& graph) : _graph(graph) {}2144 /// \param _digraph The digraph that the map belongs to. 2145 explicit ForwardMap(const Digraph& _digraph) : digraph(_digraph) {} 1733 2146 1734 2147 /// \brief The subscript operator. … … 1738 2151 /// \return The "forward" directed arc view of edge 1739 2152 Value operator[](const Key& key) const { 1740 return _graph.direct(key, true);2153 return digraph.direct(key, true); 1741 2154 } 1742 2155 1743 2156 private: 1744 const Graph& _graph;2157 const Digraph& digraph; 1745 2158 }; 1746 2159 … … 1749 2162 /// This function just returns an \ref ForwardMap class. 1750 2163 /// \relates ForwardMap 1751 template <typename Graph>1752 inline ForwardMap< Graph> forwardMap(const Graph&graph) {1753 return ForwardMap< Graph>(graph);2164 template <typename Digraph> 2165 inline ForwardMap<Digraph> forwardMap(const Digraph& digraph) { 2166 return ForwardMap<Digraph>(digraph); 1754 2167 } 1755 2168 … … 1759 2172 /// \see ForwardMap 1760 2173 /// \author Balazs Dezso 1761 template <typename Graph>2174 template <typename Digraph> 1762 2175 class BackwardMap { 1763 2176 public: 1764 2177 1765 typedef typename Graph::Arc Value;1766 typedef typename Graph::Edge Key;2178 typedef typename Digraph::Arc Value; 2179 typedef typename Digraph::Edge Key; 1767 2180 1768 2181 /// \brief Constructor 1769 2182 /// 1770 2183 /// Constructor 1771 /// \param _ graph Thegraph that the map belongs to.1772 explicit BackwardMap(const Graph& graph) : _graph(graph) {}2184 /// \param _digraph The digraph that the map belongs to. 2185 explicit BackwardMap(const Digraph& _digraph) : digraph(_digraph) {} 1773 2186 1774 2187 /// \brief The subscript operator. … … 1778 2191 /// \return The "backward" directed arc view of edge 1779 2192 Value operator[](const Key& key) const { 1780 return _graph.direct(key, false);2193 return digraph.direct(key, false); 1781 2194 } 1782 2195 1783 2196 private: 1784 const Graph& _graph;2197 const Digraph& digraph; 1785 2198 }; 1786 2199 … … 1789 2202 /// This function just returns a \ref BackwardMap class. 1790 2203 /// \relates BackwardMap 1791 template <typename Graph>1792 inline BackwardMap< Graph> backwardMap(const Graph&graph) {1793 return BackwardMap< Graph>(graph);2204 template <typename Digraph> 2205 inline BackwardMap<Digraph> backwardMap(const Digraph& digraph) { 2206 return BackwardMap<Digraph>(digraph); 1794 2207 } 1795 2208 … … 1808 2221 /// 1809 2222 /// Contructor of the map 1810 explicit PotentialDifferenceMap(const Digraph& digraph,1811 const NodeMap& potential)1812 : _digraph(digraph), _potential(potential) {}2223 explicit PotentialDifferenceMap(const Digraph& _digraph, 2224 const NodeMap& _potential) 2225 : digraph(_digraph), potential(_potential) {} 1813 2226 1814 2227 /// \brief Const subscription operator … … 1816 2229 /// Const subscription operator 1817 2230 Value operator[](const Key& arc) const { 1818 return _potential[_digraph.target(arc)] - 1819 _potential[_digraph.source(arc)]; 2231 return potential[digraph.target(arc)] - potential[digraph.source(arc)]; 1820 2232 } 1821 2233 1822 2234 private: 1823 const Digraph& _digraph;1824 const NodeMap& _potential;2235 const Digraph& digraph; 2236 const NodeMap& potential; 1825 2237 }; 1826 2238 … … 1863 2275 typedef typename Digraph::Node Key; 1864 2276 1865 typedef typename ItemSetTraits< Digraph, typenameDigraph::Arc>2277 typedef typename ItemSetTraits<_Digraph, typename _Digraph::Arc> 1866 2278 ::ItemNotifier::ObserverBase Parent; 1867 2279 1868 2280 private: 1869 2281 1870 class AutoNodeMap : public DefaultMap< Digraph, Key, int> {2282 class AutoNodeMap : public DefaultMap<_Digraph, Key, int> { 1871 2283 public: 1872 2284 1873 typedef DefaultMap<Digraph, Key, int> Parent; 2285 typedef DefaultMap<_Digraph, Key, int> Parent; 2286 typedef typename Parent::Digraph Digraph; 1874 2287 1875 2288 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} … … 1902 2315 /// 1903 2316 /// Constructor for creating in-degree map. 1904 explicit InDegMap(const Digraph& digraph) 1905 : _digraph(digraph), _deg(digraph) { 1906 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2317 explicit InDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) { 2318 Parent::attach(digraph.notifier(typename _Digraph::Arc())); 1907 2319 1908 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {1909 _deg[it] = countInArcs(_digraph, it);2320 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2321 deg[it] = countInArcs(digraph, it); 1910 2322 } 1911 2323 } … … 1913 2325 /// Gives back the in-degree of a Node. 1914 2326 int operator[](const Key& key) const { 1915 return _deg[key];2327 return deg[key]; 1916 2328 } 1917 2329 … … 1921 2333 1922 2334 virtual void add(const Arc& arc) { 1923 ++ _deg[_digraph.target(arc)];2335 ++deg[digraph.target(arc)]; 1924 2336 } 1925 2337 1926 2338 virtual void add(const std::vector<Arc>& arcs) { 1927 2339 for (int i = 0; i < int(arcs.size()); ++i) { 1928 ++ _deg[_digraph.target(arcs[i])];2340 ++deg[digraph.target(arcs[i])]; 1929 2341 } 1930 2342 } 1931 2343 1932 2344 virtual void erase(const Arc& arc) { 1933 -- _deg[_digraph.target(arc)];2345 --deg[digraph.target(arc)]; 1934 2346 } 1935 2347 1936 2348 virtual void erase(const std::vector<Arc>& arcs) { 1937 2349 for (int i = 0; i < int(arcs.size()); ++i) { 1938 -- _deg[_digraph.target(arcs[i])];2350 --deg[digraph.target(arcs[i])]; 1939 2351 } 1940 2352 } 1941 2353 1942 2354 virtual void build() { 1943 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {1944 _deg[it] = countInArcs(_digraph, it);2355 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2356 deg[it] = countInArcs(digraph, it); 1945 2357 } 1946 2358 } 1947 2359 1948 2360 virtual void clear() { 1949 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {1950 _deg[it] = 0;2361 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2362 deg[it] = 0; 1951 2363 } 1952 2364 } 1953 2365 private: 1954 2366 1955 const Digraph& _digraph;1956 AutoNodeMap _deg;2367 const _Digraph& digraph; 2368 AutoNodeMap deg; 1957 2369 }; 1958 2370 … … 1980 2392 1981 2393 public: 2394 2395 typedef typename ItemSetTraits<_Digraph, typename _Digraph::Arc> 2396 ::ItemNotifier::ObserverBase Parent; 1982 2397 1983 2398 typedef _Digraph Digraph; … … 1985 2400 typedef typename Digraph::Node Key; 1986 2401 1987 typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>1988 ::ItemNotifier::ObserverBase Parent;1989 1990 2402 private: 1991 2403 1992 class AutoNodeMap : public DefaultMap< Digraph, Key, int> {2404 class AutoNodeMap : public DefaultMap<_Digraph, Key, int> { 1993 2405 public: 1994 2406 1995 typedef DefaultMap<Digraph, Key, int> Parent; 2407 typedef DefaultMap<_Digraph, Key, int> Parent; 2408 typedef typename Parent::Digraph Digraph; 1996 2409 1997 2410 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} … … 2022 2435 /// 2023 2436 /// Constructor for creating out-degree map. 2024 explicit OutDegMap(const Digraph& digraph) 2025 : _digraph(digraph), _deg(digraph) { 2026 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2437 explicit OutDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) { 2438 Parent::attach(digraph.notifier(typename _Digraph::Arc())); 2027 2439 2028 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {2029 _deg[it] = countOutArcs(_digraph, it);2440 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2441 deg[it] = countOutArcs(digraph, it); 2030 2442 } 2031 2443 } … … 2033 2445 /// Gives back the out-degree of a Node. 2034 2446 int operator[](const Key& key) const { 2035 return _deg[key];2447 return deg[key]; 2036 2448 } 2037 2449 … … 2041 2453 2042 2454 virtual void add(const Arc& arc) { 2043 ++ _deg[_digraph.source(arc)];2455 ++deg[digraph.source(arc)]; 2044 2456 } 2045 2457 2046 2458 virtual void add(const std::vector<Arc>& arcs) { 2047 2459 for (int i = 0; i < int(arcs.size()); ++i) { 2048 ++ _deg[_digraph.source(arcs[i])];2460 ++deg[digraph.source(arcs[i])]; 2049 2461 } 2050 2462 } 2051 2463 2052 2464 virtual void erase(const Arc& arc) { 2053 -- _deg[_digraph.source(arc)];2465 --deg[digraph.source(arc)]; 2054 2466 } 2055 2467 2056 2468 virtual void erase(const std::vector<Arc>& arcs) { 2057 2469 for (int i = 0; i < int(arcs.size()); ++i) { 2058 -- _deg[_digraph.source(arcs[i])];2470 --deg[digraph.source(arcs[i])]; 2059 2471 } 2060 2472 } 2061 2473 2062 2474 virtual void build() { 2063 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {2064 _deg[it] = countOutArcs(_digraph, it);2475 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2476 deg[it] = countOutArcs(digraph, it); 2065 2477 } 2066 2478 } 2067 2479 2068 2480 virtual void clear() { 2069 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {2070 _deg[it] = 0;2481 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) { 2482 deg[it] = 0; 2071 2483 } 2072 2484 } 2073 2485 private: 2074 2486 2075 const Digraph& _digraph;2076 AutoNodeMap _deg;2487 const _Digraph& digraph; 2488 AutoNodeMap deg; 2077 2489 }; 2078 2490 … … 2089 2501 /// 2090 2502 ///See the \ref ArcLookUp and \ref AllArcLookUp classes if your 2091 ///digraph isnot changed so frequently.2503 ///digraph do not changed so frequently. 2092 2504 /// 2093 2505 ///This class uses a self-adjusting binary search tree, Sleator's … … 2109 2521 ::ItemNotifier::ObserverBase Parent; 2110 2522 2111 TEMPLATE_DIGRAPH_TYPEDEFS(G);2523 GRAPH_TYPEDEFS(typename G); 2112 2524 typedef G Digraph; 2113 2525 … … 2424 2836 Arc operator()(Node s, Node t) const 2425 2837 { 2426 Arc a= _head[s];2838 Arc e = _head[s]; 2427 2839 while (true) { 2428 if (_g.target( a) == t) {2429 const_cast<DynArcLookUp&>(*this).splay( a);2430 return a;2431 } else if (t < _g.target( a)) {2432 if (_left[ a] == INVALID) {2433 const_cast<DynArcLookUp&>(*this).splay( a);2840 if (_g.target(e) == t) { 2841 const_cast<DynArcLookUp&>(*this).splay(e); 2842 return e; 2843 } else if (t < _g.target(e)) { 2844 if (_left[e] == INVALID) { 2845 const_cast<DynArcLookUp&>(*this).splay(e); 2434 2846 return INVALID; 2435 2847 } else { 2436 a = _left[a];2848 e = _left[e]; 2437 2849 } 2438 2850 } else { 2439 if (_right[ a] == INVALID) {2440 const_cast<DynArcLookUp&>(*this).splay( a);2851 if (_right[e] == INVALID) { 2852 const_cast<DynArcLookUp&>(*this).splay(e); 2441 2853 return INVALID; 2442 2854 } else { 2443 a = _right[a];2855 e = _right[e]; 2444 2856 } 2445 2857 } … … 2458 2870 Arc findFirst(Node s, Node t) const 2459 2871 { 2460 Arc a= _head[s];2872 Arc e = _head[s]; 2461 2873 Arc r = INVALID; 2462 2874 while (true) { 2463 if (_g.target( a) < t) {2464 if (_right[ a] == INVALID) {2465 const_cast<DynArcLookUp&>(*this).splay( a);2875 if (_g.target(e) < t) { 2876 if (_right[e] == INVALID) { 2877 const_cast<DynArcLookUp&>(*this).splay(e); 2466 2878 return r; 2467 2879 } else { 2468 a = _right[a];2880 e = _right[e]; 2469 2881 } 2470 2882 } else { 2471 if (_g.target( a) == t) {2472 r = a;2883 if (_g.target(e) == t) { 2884 r = e; 2473 2885 } 2474 if (_left[ a] == INVALID) {2475 const_cast<DynArcLookUp&>(*this).splay( a);2886 if (_left[e] == INVALID) { 2887 const_cast<DynArcLookUp&>(*this).splay(e); 2476 2888 return r; 2477 2889 } else { 2478 a = _left[a];2890 e = _left[e]; 2479 2891 } 2480 2892 } … … 2495 2907 ///operation then the amorized time bound can not be guaranteed. 2496 2908 #ifdef DOXYGEN 2497 Arc findNext(Node s, Node t, Arc a) const2909 Arc findNext(Node s, Node t, Arc e) const 2498 2910 #else 2499 Arc findNext(Node, Node t, Arc a) const2911 Arc findNext(Node, Node t, Arc e) const 2500 2912 #endif 2501 2913 { 2502 if (_right[ a] != INVALID) {2503 a = _right[a];2504 while (_left[ a] != INVALID) {2505 a = _left[a];2914 if (_right[e] != INVALID) { 2915 e = _right[e]; 2916 while (_left[e] != INVALID) { 2917 e = _left[e]; 2506 2918 } 2507 const_cast<DynArcLookUp&>(*this).splay( a);2919 const_cast<DynArcLookUp&>(*this).splay(e); 2508 2920 } else { 2509 while (_parent[ a] != INVALID && _right[_parent[a]] == a) {2510 a = _parent[a];2921 while (_parent[e] != INVALID && _right[_parent[e]] == e) { 2922 e = _parent[e]; 2511 2923 } 2512 if (_parent[ a] == INVALID) {2924 if (_parent[e] == INVALID) { 2513 2925 return INVALID; 2514 2926 } else { 2515 a = _parent[a];2516 const_cast<DynArcLookUp&>(*this).splay( a);2927 e = _parent[e]; 2928 const_cast<DynArcLookUp&>(*this).splay(e); 2517 2929 } 2518 2930 } 2519 if (_g.target( a) == t) return a;2931 if (_g.target(e) == t) return e; 2520 2932 else return INVALID; 2521 2933 } … … 2546 2958 { 2547 2959 public: 2548 TEMPLATE_DIGRAPH_TYPEDEFS(G);2960 GRAPH_TYPEDEFS(typename G); 2549 2961 typedef G Digraph; 2550 2962 … … 2663 3075 using ArcLookUp<G>::_head; 2664 3076 2665 TEMPLATE_DIGRAPH_TYPEDEFS(G);3077 GRAPH_TYPEDEFS(typename G); 2666 3078 typedef G Digraph; 2667 3079 -
lemon/lgf_reader.h
r148 r127 303 303 304 304 typedef _Digraph Digraph; 305 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);305 GRAPH_TYPEDEFS(typename Digraph); 306 306 307 307 private: -
lemon/lgf_writer.h
r148 r127 238 238 239 239 typedef _Digraph Digraph; 240 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);240 GRAPH_TYPEDEFS(typename Digraph); 241 241 242 242 private: -
lemon/list_graph.h
r149 r73 153 153 static Arc arcFromId(int id) { return Arc(id);} 154 154 155 bool valid(Node n) const {156 return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&157 nodes[n.id].prev != -2;158 }159 160 bool valid(Arc a) const {161 return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&162 arcs[a.id].prev_in != -2;163 }164 165 155 Node addNode() { 166 156 int n; … … 230 220 nodes[n].next = first_free_node; 231 221 first_free_node = n; 232 nodes[n].prev = -2;233 222 234 223 } … … 259 248 260 249 arcs[n].next_in = first_free_arc; 261 first_free_arc = n; 262 arcs[n].prev_in = -2; 250 first_free_arc = n; 251 263 252 } 264 253 … … 361 350 return Parent::addArc(s, t); 362 351 } 363 364 /// Node validity check365 366 /// This function gives back true if the given node is valid,367 /// ie. it is a real node of the graph.368 ///369 /// \warning A Node pointing to a removed item370 /// could become valid again later if new nodes are371 /// added to the graph.372 bool valid(Node n) const { return Parent::valid(n); }373 374 /// Arc validity check375 376 /// This function gives back true if the given arc is valid,377 /// ie. it is a real arc of the graph.378 ///379 /// \warning An Arc pointing to a removed item380 /// could become valid again later if new nodes are381 /// added to the graph.382 bool valid(Arc a) const { return Parent::valid(a); }383 352 384 353 /// Change the target of \c e to \c n … … 977 946 static Edge edgeFromId(int id) { return Edge(id);} 978 947 979 bool valid(Node n) const {980 return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&981 nodes[n.id].prev != -2;982 }983 984 bool valid(Arc a) const {985 return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&986 arcs[a.id].prev_out != -2;987 }988 989 bool valid(Edge e) const {990 return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) &&991 arcs[2 * e.id].prev_out != -2;992 }993 994 948 Node addNode() { 995 949 int n; … … 1060 1014 nodes[n].next = first_free_node; 1061 1015 first_free_node = n; 1062 nodes[n].prev = -2; 1016 1063 1017 } 1064 1018 … … 1088 1042 arcs[n].next_out = first_free_arc; 1089 1043 first_free_arc = n; 1090 arcs[n].prev_out = -2;1091 arcs[n | 1].prev_out = -2;1092 1044 1093 1045 } … … 1206 1158 return Parent::addEdge(s, t); 1207 1159 } 1208 /// Node validity check1209 1210 /// This function gives back true if the given node is valid,1211 /// ie. it is a real node of the graph.1212 ///1213 /// \warning A Node pointing to a removed item1214 /// could become valid again later if new nodes are1215 /// added to the graph.1216 bool valid(Node n) const { return Parent::valid(n); }1217 /// Arc validity check1218 1219 /// This function gives back true if the given arc is valid,1220 /// ie. it is a real arc of the graph.1221 ///1222 /// \warning An Arc pointing to a removed item1223 /// could become valid again later if new edges are1224 /// added to the graph.1225 bool valid(Arc a) const { return Parent::valid(a); }1226 /// Edge validity check1227 1228 /// This function gives back true if the given edge is valid,1229 /// ie. it is a real arc of the graph.1230 ///1231 /// \warning A Edge pointing to a removed item1232 /// could become valid again later if new edges are1233 /// added to the graph.1234 bool valid(Edge e) const { return Parent::valid(e); }1235 1160 /// \brief Change the source of \c e to \c n 1236 1161 /// -
lemon/path.h
r144 r100 904 904 905 905 template <typename Path, typename Enable = void> 906 struct Rev PathTagIndicator {906 struct RevTagIndicator { 907 907 static const bool value = false; 908 908 }; 909 909 910 template <typename Path> 911 struct RevPathTagIndicator< 912 Path, 913 typename enable_if<typename Path::RevPathTag, void>::type 914 > { 915 static const bool value = true; 916 }; 917 918 template <typename Path, typename Enable = void> 919 struct BuildTagIndicator { 920 static const bool value = false; 921 }; 922 923 template <typename Path> 924 struct BuildTagIndicator< 925 Path, 926 typename enable_if<typename Path::BuildTag, void>::type 910 template <typename Digraph> 911 struct RevTagIndicator< 912 Digraph, 913 typename enable_if<typename Digraph::RevTag, void>::type 927 914 > { 928 915 static const bool value = true; … … 930 917 931 918 template <typename Target, typename Source, 932 bool buildEnable = BuildTagIndicator<Target>::value, 933 bool revEnable = RevPathTagIndicator<Source>::value> 919 typename BuildEnable = void, typename RevEnable = void> 934 920 struct PathCopySelector { 935 921 static void copy(Target& target, const Source& source) { … … 941 927 }; 942 928 943 template <typename Target, typename Source> 944 struct PathCopySelector<Target, Source, false, true> { 929 template <typename Target, typename Source, typename BuildEnable> 930 struct PathCopySelector< 931 Target, Source, BuildEnable, 932 typename enable_if<typename Source::RevPathTag, void>::type> { 945 933 static void copy(Target& target, const Source& source) { 946 934 target.clear(); … … 951 939 }; 952 940 953 template <typename Target, typename Source> 954 struct PathCopySelector<Target, Source, true, false> { 941 template <typename Target, typename Source, typename RevEnable> 942 struct PathCopySelector< 943 Target, Source, 944 typename enable_if<typename Target::BuildTag, void>::type, RevEnable> { 955 945 static void copy(Target& target, const Source& source) { 956 946 target.clear(); … … 960 950 961 951 template <typename Target, typename Source> 962 struct PathCopySelector<Target, Source, true, true> { 952 struct PathCopySelector< 953 Target, Source, 954 typename enable_if<typename Target::BuildTag, void>::type, 955 typename enable_if<typename Source::RevPathTag, void>::type> { 963 956 static void copy(Target& target, const Source& source) { 964 957 target.clear(); -
lemon/smart_graph.h
r149 r125 74 74 75 75 typedef True NodeNumTag; 76 typedef True EdgeNumTag;76 typedef True ArcNumTag; 77 77 78 78 int nodeNum() const { return nodes.size(); } … … 115 115 static Node nodeFromId(int id) { return Node(id);} 116 116 static Arc arcFromId(int id) { return Arc(id);} 117 118 bool valid(Node n) const {119 return n._id >= 0 && n._id < static_cast<int>(nodes.size());120 }121 bool valid(Arc a) const {122 return a._id >= 0 && a._id < static_cast<int>(arcs.size());123 }124 117 125 118 class Node { … … 268 261 /// \sa reserveNode 269 262 void reserveArc(int m) { arcs.reserve(m); }; 270 271 /// \brief Node validity check272 ///273 /// This function gives back true if the given node is valid,274 /// ie. it is a real node of the graph.275 ///276 /// \warning A removed node (using Snapshot) could become valid again277 /// when new nodes are added to the graph.278 bool valid(Node n) const { return Parent::valid(n); }279 280 /// \brief Arc validity check281 ///282 /// This function gives back true if the given arc is valid,283 /// ie. it is a real arc of the graph.284 ///285 /// \warning A removed arc (using Snapshot) could become valid again286 /// when new arcs are added to the graph.287 bool valid(Arc a) const { return Parent::valid(a); }288 263 289 264 ///Clear the digraph. … … 576 551 static Edge edgeFromId(int id) { return Edge(id);} 577 552 578 bool valid(Node n) const {579 return n._id >= 0 && n._id < static_cast<int>(nodes.size());580 }581 bool valid(Arc a) const {582 return a._id >= 0 && a._id < static_cast<int>(arcs.size());583 }584 bool valid(Edge e) const {585 return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size());586 }587 588 553 Node addNode() { 589 554 int n = nodes.size(); … … 594 559 } 595 560 596 Edge add Edge(Node u, Node v) {561 Edge addArc(Node u, Node v) { 597 562 int n = arcs.size(); 598 563 arcs.push_back(ArcT()); … … 675 640 ///\return the new edge. 676 641 Edge addEdge(const Node& s, const Node& t) { 677 return Parent::addEdge(s, t); 678 } 679 680 /// \brief Node validity check 681 /// 682 /// This function gives back true if the given node is valid, 683 /// ie. it is a real node of the graph. 684 /// 685 /// \warning A removed node (using Snapshot) could become valid again 686 /// when new nodes are added to the graph. 687 bool valid(Node n) const { return Parent::valid(n); } 688 689 /// \brief Arc validity check 690 /// 691 /// This function gives back true if the given arc is valid, 692 /// ie. it is a real arc of the graph. 693 /// 694 /// \warning A removed arc (using Snapshot) could become valid again 695 /// when new edges are added to the graph. 696 bool valid(Arc a) const { return Parent::valid(a); } 697 698 /// \brief Edge validity check 699 /// 700 /// This function gives back true if the given edge is valid, 701 /// ie. it is a real edge of the graph. 702 /// 703 /// \warning A removed edge (using Snapshot) could become valid again 704 /// when new edges are added to the graph. 705 bool valid(Edge e) const { return Parent::valid(e); } 642 return Parent::addArc(s, t); 643 } 706 644 707 645 ///Clear the graph. -
lemon/time_measure.h
r143 r126 25 25 26 26 #ifdef WIN32 27 #define WIN32_LEAN_AND_MEAN28 #define NOMINMAX29 27 #include <windows.h> 30 28 #include <cmath> … … 34 32 #endif 35 33 36 #include <string>37 34 #include <fstream> 38 35 #include <iostream> -
test/Makefile.am
r146 r119 1 1 EXTRA_DIST += \ 2 test/ CMakeLists.txt2 test/Makefile 3 3 4 4 noinst_HEADERS += \ 5 5 test/digraph_test.h \ 6 test/graph_utils_test.h \7 6 test/heap_test.h \ 8 7 test/map_test.h \ … … 17 16 test/error_test \ 18 17 test/graph_test \ 19 test/graph_utils_test \20 18 test/kruskal_test \ 21 19 test/maps_test \ … … 37 35 test_error_test_SOURCES = test/error_test.cc 38 36 test_graph_test_SOURCES = test/graph_test.cc 39 test_graph_utils_test_SOURCES = test/graph_utils_test.cc40 37 # test_heap_test_SOURCES = test/heap_test.cc 41 38 test_kruskal_test_SOURCES = test/kruskal_test.cc -
test/graph_test.cc
r149 r109 23 23 // #include <lemon/grid_graph.h> 24 24 25 #include <lemon/graph_utils.h>25 //#include <lemon/graph_utils.h> 26 26 27 27 #include "test_tools.h" … … 83 83 84 84 template <typename Graph> 85 void check_graph_counts() { 86 87 TEMPLATE_GRAPH_TYPEDEFS(Graph); 85 void print_items(Graph &g) { 86 87 typedef typename Graph::NodeIt NodeIt; 88 typedef typename Graph::EdgeIt EdgeIt; 89 typedef typename Graph::ArcIt ArcIt; 90 91 std::cout << "Nodes" << std::endl; 92 int i=0; 93 for(NodeIt it(g); it!=INVALID; ++it, ++i) { 94 std::cout << " " << i << ": " << g.id(it) << std::endl; 95 } 96 97 std::cout << "Edge" << std::endl; 98 i=0; 99 for(EdgeIt it(g); it!=INVALID; ++it, ++i) { 100 std::cout << " " << i << ": " << g.id(it) 101 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 102 << ")" << std::endl; 103 } 104 105 std::cout << "Arc" << std::endl; 106 i=0; 107 for(ArcIt it(g); it!=INVALID; ++it, ++i) { 108 std::cout << " " << i << ": " << g.id(it) 109 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 110 << ")" << std::endl; 111 } 112 113 } 114 115 template <typename Graph> 116 void check_graph() { 117 118 typedef typename Graph::Node Node; 119 typedef typename Graph::Edge Edge; 120 typedef typename Graph::Arc Arc; 121 typedef typename Graph::NodeIt NodeIt; 122 typedef typename Graph::EdgeIt EdgeIt; 123 typedef typename Graph::ArcIt ArcIt; 124 88 125 Graph g; 89 126 … … 99 136 e2 = g.addEdge(n2, n3); 100 137 138 // print_items(g); 139 101 140 check_item_counts(g,3,2); 102 141 } 103 104 template <typename Graph>105 void check_graph_validity() {106 107 TEMPLATE_GRAPH_TYPEDEFS(Graph);108 Graph g;109 110 check_item_counts(g,0,0);111 112 Node113 n1 = g.addNode(),114 n2 = g.addNode(),115 n3 = g.addNode();116 117 Edge118 e1 = g.addEdge(n1, n2),119 e2 = g.addEdge(n2, n3);120 121 check(g.valid(n1), "Validity check");122 check(g.valid(e1), "Validity check");123 check(g.valid(g.direct(e1, true)), "Validity check");124 125 check(!g.valid(g.nodeFromId(-1)), "Validity check");126 check(!g.valid(g.edgeFromId(-1)), "Validity check");127 check(!g.valid(g.arcFromId(-1)), "Validity check");128 129 }130 131 template <typename Graph>132 void check_graph_validity_erase() {133 134 TEMPLATE_GRAPH_TYPEDEFS(Graph);135 Graph g;136 137 check_item_counts(g,0,0);138 139 Node140 n1 = g.addNode(),141 n2 = g.addNode(),142 n3 = g.addNode();143 144 Edge145 e1 = g.addEdge(n1, n2),146 e2 = g.addEdge(n2, n3);147 148 check(g.valid(n1), "Validity check");149 check(g.valid(e1), "Validity check");150 check(g.valid(g.direct(e1, true)), "Validity check");151 152 g.erase(n1);153 154 check(!g.valid(n1), "Validity check");155 check(g.valid(n2), "Validity check");156 check(g.valid(n3), "Validity check");157 check(!g.valid(e1), "Validity check");158 check(g.valid(e2), "Validity check");159 160 check(!g.valid(g.nodeFromId(-1)), "Validity check");161 check(!g.valid(g.edgeFromId(-1)), "Validity check");162 check(!g.valid(g.arcFromId(-1)), "Validity check");163 164 }165 166 167 142 168 143 // void checkGridGraph(const GridGraph& g, int w, int h) { … … 213 188 check_concepts(); 214 189 215 check_graph_counts<ListGraph>(); 216 check_graph_counts<SmartGraph>(); 217 218 check_graph_validity_erase<ListGraph>(); 219 check_graph_validity<SmartGraph>(); 190 check_graph<ListGraph>(); 191 check_graph<SmartGraph>(); 220 192 221 193 // { -
tools/Makefile.am
r146 r1 1 EXTRA_DIST += \ 2 tools/Makefile 3 1 4 if WANT_TOOLS 2 5
Note: See TracChangeset
for help on using the changeset viewer.