Changes in / [153:976a014b3797:154:f4e4dbc1d467] in lemon-main
- Files:
-
- 6 added
- 6 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r153 r154 37 37 ^test/[a-z_]*$ 38 38 ^demo/.*_demo$ 39 ^build/.* 40 CMakeFiles 41 DartTestfile.txt 42 cmake_install.cmake 43 CMakeCache.txt -
Makefile.am
r70 r146 8 8 m4/lx_check_cplex.m4 \ 9 9 m4/lx_check_glpk.m4 \ 10 m4/lx_check_soplex.m4 10 m4/lx_check_soplex.m4 \ 11 CMakeLists.txt 11 12 12 13 pkgconfigdir = $(libdir)/pkgconfig … … 45 46 build-aux/ltmain.sh \ 46 47 build-aux/missing \ 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 48 doc/doxygen.log 54 49 55 50 mrproper: -
benchmark/Makefile.am
r1 r146 1 EXTRA_DIST += \2 benchmark/Makefile3 4 1 if WANT_BENCHMARK 5 2 -
demo/Makefile.am
r135 r146 1 1 EXTRA_DIST += \ 2 demo/ Makefile2 demo/CMakeLists.txt 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
r127 r143 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 * log(n));40 const int e = argc > 2 ? std::atoi(argv[2]) : static_cast<int>(n * std::log(double(n))); 41 41 const int m = argc > 3 ? std::atoi(argv[3]) : 100; 42 42 -
doc/Makefile.am
r153 r154 1 1 EXTRA_DIST += \ 2 doc/Makefile \3 2 doc/Doxyfile.in \ 4 3 doc/coding_style.dox \ -
lemon/Makefile.am
r135 r146 1 1 EXTRA_DIST += \ 2 lemon/ Makefile\3 lemon/ lemon.pc.in2 lemon/lemon.pc.in \ 3 lemon/CMakeLists.txt 4 4 5 5 pkgconfig_DATA += lemon/lemon.pc -
lemon/assert.h
r118 r142 104 104 105 105 #ifndef LEMON_FUNCTION_NAME 106 # define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__) 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 107 113 #endif 108 114 -
lemon/bits/traits.h
r107 r139 217 217 218 218 template <typename Graph, typename Enable = void> 219 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>::type227 > { 228 static const bool value = true; 229 }; 230 231 template <typename Graph, typename Enable = void> 232 struct Find ArcTagIndicator {233 static const bool value = false; 234 }; 235 236 template <typename Graph> 237 struct Find ArcTagIndicator<238 Graph, 239 typename enable_if<typename Graph::Find ArcTag, void>::type219 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>::type 227 > { 228 static const bool value = true; 229 }; 230 231 template <typename Graph, typename Enable = void> 232 struct FindEdgeTagIndicator { 233 static const bool value = false; 234 }; 235 236 template <typename Graph> 237 struct FindEdgeTagIndicator< 238 Graph, 239 typename enable_if<typename Graph::FindEdgeTag, void>::type 240 240 > { 241 241 static const bool value = true; -
lemon/graph_to_eps.h
r134 r143 30 30 #include<ctime> 31 31 #else 32 #define WIN32_LEAN_AND_MEAN 33 #define NOMINMAX 32 34 #include<windows.h> 33 35 #endif -
lemon/graph_utils.h
r100 r148 36 36 ///\ingroup gutils 37 37 ///\file 38 ///\brief Digraph utilities.38 ///\brief Graph 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 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 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 65 89 ///Creates convenience typedefs for the graph types and iterators 66 90 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. 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. 108 126 /// The complexity of the function is O(n) because 109 127 /// it iterates on all of the items. 110 111 template <typename Digraph, typename Item> 112 inline int countItems(const Digraph& g) { 113 typedef typename ItemSetTraits<Digraph, Item>::ItemIt ItemIt; 128 template <typename Graph, typename Item> 129 inline int countItems(const Graph& g) { 130 typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt; 114 131 int num = 0; 115 132 for (ItemIt it(g); it != INVALID; ++it) { … … 121 138 // Node counting: 122 139 123 namespace _ digraph_utils_bits {124 125 template <typename Digraph, typename Enable = void>140 namespace _graph_utils_bits { 141 142 template <typename Graph, typename Enable = void> 126 143 struct CountNodesSelector { 127 static int count(const Digraph &g) {128 return countItems< Digraph, typename Digraph::Node>(g);144 static int count(const Graph &g) { 145 return countItems<Graph, typename Graph::Node>(g); 129 146 } 130 147 }; 131 148 132 template <typename Digraph>149 template <typename Graph> 133 150 struct CountNodesSelector< 134 Digraph, typename135 enable_if<typename Digraph::NodeNumTag, void>::type>151 Graph, typename 152 enable_if<typename Graph::NodeNumTag, void>::type> 136 153 { 137 static int count(const Digraph &g) {154 static int count(const Graph &g) { 138 155 return g.nodeNum(); 139 156 } … … 141 158 } 142 159 143 /// \brief Function to count the nodes in the digraph.144 /// 145 /// This function counts the nodes in the digraph.160 /// \brief Function to count the nodes in the graph. 161 /// 162 /// This function counts the nodes in the graph. 146 163 /// The complexity of the function is O(n) but for some 147 /// digraph structures it is specialized to run in O(1).148 /// 149 /// If the digraph contains a \e nodeNum() member function and a164 /// graph structures it is specialized to run in O(1). 165 /// 166 /// If the graph contains a \e nodeNum() member function and a 150 167 /// \e NodeNumTag tag then this function calls directly the member 151 168 /// function to query the cardinality of the node set. 152 template <typename Digraph>153 inline int countNodes(const Digraph& g) {154 return _ digraph_utils_bits::CountNodesSelector<Digraph>::count(g);169 template <typename Graph> 170 inline int countNodes(const Graph& g) { 171 return _graph_utils_bits::CountNodesSelector<Graph>::count(g); 155 172 } 156 173 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); 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); 163 182 } 164 183 }; 165 184 166 template <typename Digraph>167 struct Count RedsSelector<168 Digraph, typename169 enable_if<typename Digraph::NodeNumTag, void>::type>185 template <typename Graph> 186 struct CountArcsSelector< 187 Graph, 188 typename enable_if<typename Graph::ArcNumTag, void>::type> 170 189 { 171 static int count(const Digraph &g) {172 return g. redNum();190 static int count(const Graph &g) { 191 return g.arcNum(); 173 192 } 174 193 }; 175 194 } 176 195 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 some181 /// digraph structures it is specialized to run in O(1).182 /// 183 /// If the digraph contains an \e redNum() member function and a184 /// \e NodeNumTag tag then this function calls directly the member185 /// function to query the cardinality of the A-nodeset.186 template <typename Digraph>187 inline int count Reds(const Digraph& g) {188 return _ digraph_utils_bits::CountRedsSelector<Digraph>::count(g);196 /// \brief Function to count the arcs in the graph. 197 /// 198 /// This function counts the arcs in the graph. 199 /// The complexity of the function is O(e) but for some 200 /// graph structures it is specialized to run in O(1). 201 /// 202 /// If the graph contains a \e arcNum() member function and a 203 /// \e EdgeNumTag tag then this function calls directly the member 204 /// function to query the cardinality of the arc set. 205 template <typename Graph> 206 inline int countArcs(const Graph& g) { 207 return _graph_utils_bits::CountArcsSelector<Graph>::count(g); 189 208 } 190 209 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); 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); 197 217 } 198 218 }; 199 219 200 template <typename Digraph>201 struct Count BluesSelector<202 Digraph, typename203 enable_if<typename Digraph::NodeNumTag, void>::type>220 template <typename Graph> 221 struct CountEdgesSelector< 222 Graph, 223 typename enable_if<typename Graph::EdgeNumTag, void>::type> 204 224 { 205 static int count(const Digraph &g) {206 return g. blueNum();225 static int count(const Graph &g) { 226 return g.edgeNum(); 207 227 } 208 228 }; 209 229 } 210 230 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); 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 239 /// 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); 243 223 244 } 224 245 225 246 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 291 /// function to query the cardinality of the edge set. 292 template <typename Digraph> 293 inline int countEdges(const Digraph& g) { 294 return _digraph_utils_bits::CountEdgesSelector<Digraph>::count(g); 295 296 } 297 298 299 template <typename Digraph, typename DegIt> 300 inline int countNodeDegree(const Digraph& _g, const typename Digraph::Node& _n) { 247 template <typename Graph, typename DegIt> 248 inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) { 301 249 int num = 0; 302 250 for (DegIt it(_g, _n); it != INVALID; ++it) { … … 309 257 /// 310 258 /// This function counts the number of the out-arcs from node \c 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);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); 315 263 } 316 264 … … 318 266 /// 319 267 /// This function counts the number of the in-arcs to node \c 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);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); 324 272 } 325 273 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 n329 /// in the digraph.330 template <typename Digraph>331 inline int countInc Arcs(const Digraph& _g, const typename Digraph::Node& _n) {332 return countNodeDegree< Digraph, typename Digraph::IncArcIt>(_g, _n);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 n 277 /// in the graph. 278 template <typename Graph> 279 inline int countIncEdges(const Graph& _g, const typename Graph::Node& _n) { 280 return countNodeDegree<Graph, typename Graph::IncEdgeIt>(_g, _n); 333 281 } 334 282 335 namespace _ digraph_utils_bits {336 337 template <typename Digraph, typename Enable = void>283 namespace _graph_utils_bits { 284 285 template <typename Graph, typename Enable = void> 338 286 struct FindArcSelector { 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) {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) { 342 290 if (e == INVALID) { 343 291 g.firstOut(e, u); … … 352 300 }; 353 301 354 template <typename Digraph>302 template <typename Graph> 355 303 struct FindArcSelector< 356 Digraph,357 typename enable_if<typename Digraph::FindArcTag, void>::type>304 Graph, 305 typename enable_if<typename Graph::FindEdgeTag, void>::type> 358 306 { 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) {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) { 362 310 return g.findArc(u, v, prev); 363 311 } … … 365 313 } 366 314 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.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. 370 318 /// 371 319 /// If \c prev is \ref INVALID (this is the default value), then … … 385 333 ///\sa DynArcLookUp 386 334 ///\sa ConArcIt 387 template <typename Digraph>388 inline typename Digraph::Arc389 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);335 template <typename Graph> 336 inline typename Graph::Arc 337 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); 392 340 } 393 341 … … 398 346 /// use it the following way: 399 347 ///\code 400 /// for (ConArcIt< Digraph> it(g, src, trg); it != INVALID; ++it) {348 /// for (ConArcIt<Graph> it(g, src, trg); it != INVALID; ++it) { 401 349 /// ... 402 350 /// } … … 409 357 /// 410 358 /// \author Balazs Dezso 411 template <typename _ Digraph>412 class ConArcIt : public _ Digraph::Arc {359 template <typename _Graph> 360 class ConArcIt : public _Graph::Arc { 413 361 public: 414 362 415 typedef _ Digraph Digraph;416 typedef typename Digraph::Arc Parent;417 418 typedef typename Digraph::Arc Arc;419 typedef typename Digraph::Node Node;363 typedef _Graph Graph; 364 typedef typename Graph::Arc Parent; 365 366 typedef typename Graph::Arc Arc; 367 typedef typename Graph::Node Node; 420 368 421 369 /// \brief Constructor. … … 423 371 /// Construct a new ConArcIt iterating on the arcs which 424 372 /// connects the \c u and \c v node. 425 ConArcIt(const Digraph& g, Node u, Node v) : digraph(g) {426 Parent::operator=(findArc( digraph, u, v));373 ConArcIt(const Graph& g, Node u, Node v) : _graph(g) { 374 Parent::operator=(findArc(_graph, u, v)); 427 375 } 428 376 … … 431 379 /// Construct a new ConArcIt which continues the iterating from 432 380 /// the \c e arc. 433 ConArcIt(const Digraph& g, Arc e) : Parent(e), digraph(g) {}381 ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {} 434 382 435 383 /// \brief Increment operator. … … 437 385 /// It increments the iterator and gives back the next arc. 438 386 ConArcIt& operator++() { 439 Parent::operator=(findArc( digraph, digraph.source(*this),440 digraph.target(*this), *this));387 Parent::operator=(findArc(_graph, _graph.source(*this), 388 _graph.target(*this), *this)); 441 389 return *this; 442 390 } 443 391 private: 444 const Digraph& digraph;392 const Graph& _graph; 445 393 }; 446 394 447 namespace _ digraph_utils_bits {448 449 template <typename Digraph, typename Enable = void>395 namespace _graph_utils_bits { 396 397 template <typename Graph, typename Enable = void> 450 398 struct FindEdgeSelector { 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) {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) { 454 402 bool b; 455 403 if (u != v) { … … 478 426 }; 479 427 480 template <typename Digraph>428 template <typename Graph> 481 429 struct FindEdgeSelector< 482 Digraph,483 typename enable_if<typename Digraph::FindArcTag, void>::type>430 Graph, 431 typename enable_if<typename Graph::FindEdgeTag, void>::type> 484 432 { 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) {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) { 488 436 return g.findEdge(u, v, prev); 489 437 } … … 491 439 } 492 440 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 arc497 /// will be enumerated .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 edge 445 /// will be enumerated once. 498 446 /// 499 447 /// If \c prev is \ref INVALID (this is the default value), then … … 512 460 ///\sa ConArcIt 513 461 514 template <typename Digraph>515 inline typename Digraph::Edge516 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);462 template <typename Graph> 463 inline typename Graph::Edge 464 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); 519 467 } 520 468 … … 525 473 /// use it the following way: 526 474 ///\code 527 /// for (ConEdgeIt< Digraph> it(g, src, trg); it != INVALID; ++it) {475 /// for (ConEdgeIt<Graph> it(g, src, trg); it != INVALID; ++it) { 528 476 /// ... 529 477 /// } … … 533 481 /// 534 482 /// \author Balazs Dezso 535 template <typename _ Digraph>536 class ConEdgeIt : public _ Digraph::Edge {483 template <typename _Graph> 484 class ConEdgeIt : public _Graph::Edge { 537 485 public: 538 486 539 typedef _ Digraph Digraph;540 typedef typename Digraph::Edge Parent;541 542 typedef typename Digraph::Edge Edge;543 typedef typename Digraph::Node Node;487 typedef _Graph Graph; 488 typedef typename Graph::Edge Parent; 489 490 typedef typename Graph::Edge Edge; 491 typedef typename Graph::Node Node; 544 492 545 493 /// \brief Constructor. 546 494 /// 547 /// Construct a new ConEdgeIt iterating on the arcs which495 /// Construct a new ConEdgeIt iterating on the edges which 548 496 /// connects the \c u and \c v node. 549 ConEdgeIt(const Digraph& g, Node u, Node v) : digraph(g) {550 Parent::operator=(findEdge( digraph, u, v));497 ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g) { 498 Parent::operator=(findEdge(_graph, u, v)); 551 499 } 552 500 … … 554 502 /// 555 503 /// Construct a new ConEdgeIt which continues the iterating from 556 /// the \c e arc.557 ConEdgeIt(const Digraph& g, Edge e) : Parent(e), digraph(g) {}504 /// the \c e edge. 505 ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {} 558 506 559 507 /// \brief Increment operator. 560 508 /// 561 /// It increments the iterator and gives back the next arc.509 /// It increments the iterator and gives back the next edge. 562 510 ConEdgeIt& operator++() { 563 Parent::operator=(findEdge( digraph, digraph.source(*this),564 digraph.target(*this), *this));511 Parent::operator=(findEdge(_graph, _graph.source(*this), 512 _graph.target(*this), *this)); 565 513 return *this; 566 514 } 567 515 private: 568 const Digraph& digraph;516 const Graph& _graph; 569 517 }; 570 518 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 { 519 namespace _graph_utils_bits { 597 520 598 521 template <typename Digraph, typename Item, typename RefMap> … … 728 651 }; 729 652 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 765 653 } 766 654 … … 769 657 /// Class to copy a digraph to another digraph (duplicate a digraph). The 770 658 /// 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 create 661 /// references and cross references between the nodes and arcs of 662 /// the two graphs, it can copy maps for use with the newly created 663 /// graph and copy nodes and arcs. 664 /// 665 /// To make a copy from a graph, first an instance of DigraphCopy 666 /// should be created, then the data belongs to the graph should 667 /// assigned to copy. In the end, the \c run() member should be 668 /// called. 669 /// 670 /// The next code copies a graph with several data: 671 ///\code 672 /// DigraphCopy<NewGraph, OrigGraph> dc(new_graph, orig_graph); 673 /// // create a reference for the nodes 674 /// OrigGraph::NodeMap<NewGraph::Node> nr(orig_graph); 675 /// dc.nodeRef(nr); 676 /// // create a cross reference (inverse) for the arcs 677 /// NewGraph::ArcMap<OrigGraph::Arc> acr(new_graph); 678 /// dc.arcCrossRef(acr); 679 /// // copy an arc map 680 /// OrigGraph::ArcMap<double> oamap(orig_graph); 681 /// NewGraph::ArcMap<double> namap(new_graph); 682 /// dc.arcMap(namap, oamap); 683 /// // copy a node 684 /// OrigGraph::Node on; 685 /// NewGraph::Node nn; 686 /// dc.node(nn, on); 687 /// // Executions of copy 688 /// dc.run(); 689 ///\endcode 771 690 template <typename To, typename From> 772 691 class DigraphCopy { … … 792 711 /// It copies the content of the \c _from digraph into the 793 712 /// \c _to digraph. 794 DigraphCopy(To& _to, const From& _from)795 : from(_from), to(_to) {}713 DigraphCopy(To& to, const From& from) 714 : _from(from), _to(to) {} 796 715 797 716 /// \brief Destructor of the DigraphCopy … … 799 718 /// Destructor of the DigraphCopy 800 719 ~DigraphCopy() { 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];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]; 806 725 } 807 726 … … 810 729 /// \brief Copies the node references into the given map. 811 730 /// 812 /// Copies the node references into the given map. 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. 813 735 template <typename NodeRef> 814 736 DigraphCopy& nodeRef(NodeRef& map) { 815 nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node,816 737 _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node, 738 NodeRefMap, NodeRef>(map)); 817 739 return *this; 818 740 } … … 821 743 /// 822 744 /// Copies the node cross references (reverse references) into 823 /// the given map. 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. 824 748 template <typename NodeCrossRef> 825 749 DigraphCopy& nodeCrossRef(NodeCrossRef& map) { 826 nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node,827 750 _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node, 751 NodeRefMap, NodeCrossRef>(map)); 828 752 return *this; 829 753 } … … 831 755 /// \brief Make copy of the given map. 832 756 /// 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. 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. 837 760 template <typename ToMap, typename FromMap> 838 761 DigraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 839 nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node,840 762 _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node, 763 NodeRefMap, ToMap, FromMap>(tmap, map)); 841 764 return *this; 842 765 } … … 846 769 /// Make a copy of the given node. 847 770 DigraphCopy& node(TNode& tnode, const Node& snode) { 848 nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node,849 771 _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node, 772 NodeRefMap, TNode>(tnode, snode)); 850 773 return *this; 851 774 } … … 856 779 template <typename ArcRef> 857 780 DigraphCopy& arcRef(ArcRef& map) { 858 arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc,859 781 _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc, 782 ArcRefMap, ArcRef>(map)); 860 783 return *this; 861 784 } … … 867 790 template <typename ArcCrossRef> 868 791 DigraphCopy& arcCrossRef(ArcCrossRef& map) { 869 arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc,870 792 _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc, 793 ArcRefMap, ArcCrossRef>(map)); 871 794 return *this; 872 795 } … … 880 803 template <typename ToMap, typename FromMap> 881 804 DigraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 882 arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc,883 805 _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc, 806 ArcRefMap, ToMap, FromMap>(tmap, map)); 884 807 return *this; 885 808 } … … 889 812 /// Make a copy of the given arc. 890 813 DigraphCopy& arc(TArc& tarc, const Arc& sarc) { 891 arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc,892 814 _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc, 815 ArcRefMap, TArc>(tarc, sarc)); 893 816 return *this; 894 817 } … … 898 821 /// Executes the copies. 899 822 void run() { 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);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); 909 832 } 910 833 } … … 913 836 914 837 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;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; 923 846 924 847 }; … … 926 849 /// \brief Copy a digraph to another digraph. 927 850 /// 928 /// Copy a digraph to another digraph. 929 /// The usage of the function:930 /// 851 /// Copy a digraph to another digraph. The complete usage of the 852 /// function is detailed in the DigraphCopy class, but a short 853 /// example shows a basic work: 931 854 ///\code 932 855 /// copyDigraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); … … 944 867 } 945 868 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. 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 950 904 template <typename To, typename From> 951 905 class GraphCopy { … … 967 921 968 922 struct ArcRefMap { 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) {}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) {} 973 927 974 928 typedef typename From::Arc Key; … … 977 931 Value operator[](const Key& key) const { 978 932 bool 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); 933 (_from.direction(key) == 934 (_node_ref[_from.source(key)] == _to.source(_edge_ref[key]))); 935 return _to.direct(_edge_ref[key], forward); 983 936 } 984 937 985 const To& to;986 const From& from;987 const EdgeRefMap& edge_ref;988 const NodeRefMap& node_ref;938 const To& _to; 939 const From& _from; 940 const EdgeRefMap& _edge_ref; 941 const NodeRefMap& _node_ref; 989 942 }; 990 943 … … 993 946 994 947 995 /// \brief Constructor for the DigraphCopy.996 /// 997 /// It copies the content of the \c _from digraph into the998 /// \c _to digraph.999 GraphCopy(To& _to, const From& _from)1000 : from(_from), to(_to) {}1001 1002 /// \brief Destructor of the DigraphCopy1003 /// 1004 /// Destructor of the DigraphCopy948 /// \brief Constructor for the GraphCopy. 949 /// 950 /// It copies the content of the \c _from graph into the 951 /// \c _to graph. 952 GraphCopy(To& to, const From& from) 953 : _from(from), _to(to) {} 954 955 /// \brief Destructor of the GraphCopy 956 /// 957 /// Destructor of the GraphCopy 1005 958 ~GraphCopy() { 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];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]; 1014 967 } 1015 968 … … 1021 974 template <typename NodeRef> 1022 975 GraphCopy& nodeRef(NodeRef& map) { 1023 nodeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Node,1024 976 _node_maps.push_back(new _graph_utils_bits::RefCopy<From, Node, 977 NodeRefMap, NodeRef>(map)); 1025 978 return *this; 1026 979 } … … 1032 985 template <typename NodeCrossRef> 1033 986 GraphCopy& nodeCrossRef(NodeCrossRef& map) { 1034 nodeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Node,1035 987 _node_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Node, 988 NodeRefMap, NodeCrossRef>(map)); 1036 989 return *this; 1037 990 } … … 1039 992 /// \brief Make copy of the given map. 1040 993 /// 1041 /// 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 node994 /// 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 node 1044 997 /// type. 1045 998 template <typename ToMap, typename FromMap> 1046 999 GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) { 1047 nodeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Node,1048 1000 _node_maps.push_back(new _graph_utils_bits::MapCopy<From, Node, 1001 NodeRefMap, ToMap, FromMap>(tmap, map)); 1049 1002 return *this; 1050 1003 } … … 1054 1007 /// Make a copy of the given node. 1055 1008 GraphCopy& node(TNode& tnode, const Node& snode) { 1056 nodeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Node,1057 1009 _node_maps.push_back(new _graph_utils_bits::ItemCopy<From, Node, 1010 NodeRefMap, TNode>(tnode, snode)); 1058 1011 return *this; 1059 1012 } … … 1064 1017 template <typename ArcRef> 1065 1018 GraphCopy& arcRef(ArcRef& map) { 1066 arcMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Arc,1067 1019 _arc_maps.push_back(new _graph_utils_bits::RefCopy<From, Arc, 1020 ArcRefMap, ArcRef>(map)); 1068 1021 return *this; 1069 1022 } … … 1075 1028 template <typename ArcCrossRef> 1076 1029 GraphCopy& arcCrossRef(ArcCrossRef& map) { 1077 arcMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From, Arc,1078 1030 _arc_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, Arc, 1031 ArcRefMap, ArcCrossRef>(map)); 1079 1032 return *this; 1080 1033 } … … 1082 1035 /// \brief Make copy of the given map. 1083 1036 /// 1084 /// 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 arc1037 /// 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 arc 1087 1040 /// type. 1088 1041 template <typename ToMap, typename FromMap> 1089 1042 GraphCopy& arcMap(ToMap& tmap, const FromMap& map) { 1090 arcMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Arc,1091 1043 _arc_maps.push_back(new _graph_utils_bits::MapCopy<From, Arc, 1044 ArcRefMap, ToMap, FromMap>(tmap, map)); 1092 1045 return *this; 1093 1046 } … … 1097 1050 /// Make a copy of the given arc. 1098 1051 GraphCopy& arc(TArc& tarc, const Arc& sarc) { 1099 arcMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Arc,1100 1052 _arc_maps.push_back(new _graph_utils_bits::ItemCopy<From, Arc, 1053 ArcRefMap, TArc>(tarc, sarc)); 1101 1054 return *this; 1102 1055 } … … 1107 1060 template <typename EdgeRef> 1108 1061 GraphCopy& edgeRef(EdgeRef& map) { 1109 edgeMapCopies.push_back(new _digraph_utils_bits::RefCopy<From, Edge,1110 1062 _edge_maps.push_back(new _graph_utils_bits::RefCopy<From, Edge, 1063 EdgeRefMap, EdgeRef>(map)); 1111 1064 return *this; 1112 1065 } … … 1118 1071 template <typename EdgeCrossRef> 1119 1072 GraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1120 edgeMapCopies.push_back(new _digraph_utils_bits::CrossRefCopy<From,1121 1073 _edge_maps.push_back(new _graph_utils_bits::CrossRefCopy<From, 1074 Edge, EdgeRefMap, EdgeCrossRef>(map)); 1122 1075 return *this; 1123 1076 } … … 1125 1078 /// \brief Make copy of the given map. 1126 1079 /// 1127 /// 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 edge1080 /// 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 edge 1130 1083 /// type. 1131 1084 template <typename ToMap, typename FromMap> 1132 1085 GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) { 1133 edgeMapCopies.push_back(new _digraph_utils_bits::MapCopy<From, Edge,1134 1086 _edge_maps.push_back(new _graph_utils_bits::MapCopy<From, Edge, 1087 EdgeRefMap, ToMap, FromMap>(tmap, map)); 1135 1088 return *this; 1136 1089 } … … 1140 1093 /// Make a copy of the given edge. 1141 1094 GraphCopy& edge(TEdge& tedge, const Edge& sedge) { 1142 edgeMapCopies.push_back(new _digraph_utils_bits::ItemCopy<From, Edge,1143 1095 _edge_maps.push_back(new _graph_utils_bits::ItemCopy<From, Edge, 1096 EdgeRefMap, TEdge>(tedge, sedge)); 1144 1097 return *this; 1145 1098 } … … 1149 1102 /// Executes the copies. 1150 1103 void run() { 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);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); 1164 1117 } 1165 1118 } … … 1167 1120 private: 1168 1121 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;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; 1180 1133 1181 1134 }; 1182 1135 1183 /// \brief Copy a n graph to another digraph.1184 /// 1185 /// Copy a n graph to another digraph.1186 /// The usage of the function:1187 /// 1136 /// \brief Copy a graph to another graph. 1137 /// 1138 /// Copy a graph to another graph. The complete usage of the 1139 /// function is detailed in the GraphCopy class, but a short 1140 /// example shows a basic work: 1188 1141 ///\code 1189 1142 /// copyGraph(trg, src).nodeRef(nr).arcCrossRef(ecr).run(); … … 1191 1144 /// 1192 1145 /// After the copy the \c nr map will contain the mapping from the 1193 /// nodes of the \c from digraph to the nodes of the \c to digraph and1194 /// \c ecr will contain the mapping from the arcs of the \c to digraph1195 /// to the arcs of the \c from digraph.1146 /// nodes of the \c from graph to the nodes of the \c to graph and 1147 /// \c ecr will contain the mapping from the arcs of the \c to graph 1148 /// to the arcs of the \c from graph. 1196 1149 /// 1197 1150 /// \see GraphCopy … … 1202 1155 } 1203 1156 1204 /// \brief Class to copy a bipartite digraph.1205 ///1206 /// Class to copy a bipartite digraph to another digraph1207 /// (duplicate a digraph). The simplest way of using it is through1208 /// 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 the1276 /// \c _to digraph.1277 BpGraphCopy(To& _to, const From& _from)1278 : from(_from), to(_to) {}1279 1280 /// \brief Destructor of the DigraphCopy1281 ///1282 /// Destructor of the DigraphCopy1283 ~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) into1315 /// 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 node1328 /// 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) into1349 /// 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 node1362 /// 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) into1382 /// 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 node1395 /// 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) into1425 /// 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 arc1438 /// 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 (reverse1468 /// 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 edge1481 /// 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 ///\code1554 /// copyBpGraph(trg, src).redRef(anr).arcCrossRef(ecr).run();1555 ///\endcode1556 ///1557 /// After the copy the \c nr map will contain the mapping from the1558 /// nodes of the \c from digraph to the nodes of the \c to digraph and1559 /// \c ecr will contain the mapping from the arcs of the \c to digraph1560 /// to the arcs of the \c from digraph.1561 ///1562 /// \see BpGraphCopy1563 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 1570 1157 /// @} 1571 1158 1572 /// \addtogroup digraph_maps1159 /// \addtogroup graph_maps 1573 1160 /// @{ 1574 1161 1575 /// Provides an immutable and unique id for each item in the digraph.1162 /// Provides an immutable and unique id for each item in the graph. 1576 1163 1577 1164 /// The IdMap class provides a unique and immutable id for each item of the 1578 /// same type (e.g. node) in the digraph. This id is <ul><li>\b unique:1165 /// same type (e.g. node) in the graph. This id is <ul><li>\b unique: 1579 1166 /// different items (nodes) get different ids <li>\b immutable: the id of an 1580 1167 /// item (node) does not change (even if you delete other nodes). </ul> 1581 1168 /// Through this map you get access (i.e. can read) the inner id values of 1582 /// the items stored in the digraph. This map can be inverted with its member1583 /// class \c InverseMap .1584 /// 1585 template <typename _ Digraph, typename _Item>1169 /// the items stored in the graph. This map can be inverted with its member 1170 /// class \c InverseMap or with the \c operator() member. 1171 /// 1172 template <typename _Graph, typename _Item> 1586 1173 class IdMap { 1587 1174 public: 1588 typedef _ Digraph Digraph;1175 typedef _Graph Graph; 1589 1176 typedef int Value; 1590 1177 typedef _Item Item; … … 1594 1181 /// 1595 1182 /// Constructor of the map. 1596 explicit IdMap(const Digraph& _digraph) : digraph(&_digraph) {}1183 explicit IdMap(const Graph& graph) : _graph(&graph) {} 1597 1184 1598 1185 /// \brief Gives back the \e id of the item. 1599 1186 /// 1600 1187 /// Gives back the immutable and unique \e id of the item. 1601 int operator[](const Item& item) const { return digraph->id(item);}1188 int operator[](const Item& item) const { return _graph->id(item);} 1602 1189 1603 1190 /// \brief Gives back the item by its id. 1604 1191 /// 1605 1192 /// Gives back the item by its id. 1606 Item operator()(int id) { return digraph->fromId(id, Item()); }1193 Item operator()(int id) { return _graph->fromId(id, Item()); } 1607 1194 1608 1195 private: 1609 const Digraph* digraph;1196 const Graph* _graph; 1610 1197 1611 1198 public: … … 1621 1208 /// 1622 1209 /// Constructor for creating an id-to-item map. 1623 explicit InverseMap(const Digraph& _digraph) : digraph(&_digraph) {}1210 explicit InverseMap(const Graph& graph) : _graph(&graph) {} 1624 1211 1625 1212 /// \brief Constructor. 1626 1213 /// 1627 1214 /// Constructor for creating an id-to-item map. 1628 explicit InverseMap(const IdMap& idMap) : digraph(idMap.digraph) {}1215 explicit InverseMap(const IdMap& map) : _graph(map._graph) {} 1629 1216 1630 1217 /// \brief Gives back the given item from its id. … … 1632 1219 /// Gives back the given item from its id. 1633 1220 /// 1634 Item operator[](int id) const { return digraph->fromId(id, Item());}1221 Item operator[](int id) const { return _graph->fromId(id, Item());} 1635 1222 1636 1223 private: 1637 const Digraph* digraph;1224 const Graph* _graph; 1638 1225 }; 1639 1226 … … 1641 1228 /// 1642 1229 /// Gives back the inverse of the IdMap. 1643 InverseMap inverse() const { return InverseMap(* digraph);}1230 InverseMap inverse() const { return InverseMap(*_graph);} 1644 1231 1645 1232 }; 1646 1233 1647 1234 1648 /// \brief General invertable digraph-map type.1649 1650 /// This type provides simple invertable digraph-maps.1235 /// \brief General invertable graph-map type. 1236 1237 /// This type provides simple invertable graph-maps. 1651 1238 /// The InvertableMap wraps an arbitrary ReadWriteMap 1652 1239 /// and if a key is set to a new value then store it … … 1656 1243 /// with stl compatible forward iterator. 1657 1244 /// 1658 /// \param _ Digraph The digraph type.1659 /// \param _Item The item type of the digraph.1245 /// \param _Graph The graph type. 1246 /// \param _Item The item type of the graph. 1660 1247 /// \param _Value The value type of the map. 1661 1248 /// 1662 1249 /// \see IterableValueMap 1663 template <typename _ Digraph, typename _Item, typename _Value>1664 class InvertableMap : protected DefaultMap<_ Digraph, _Item, _Value> {1250 template <typename _Graph, typename _Item, typename _Value> 1251 class InvertableMap : protected DefaultMap<_Graph, _Item, _Value> { 1665 1252 private: 1666 1253 1667 typedef DefaultMap<_ Digraph, _Item, _Value> Map;1668 typedef _ Digraph Digraph;1254 typedef DefaultMap<_Graph, _Item, _Value> Map; 1255 typedef _Graph Graph; 1669 1256 1670 1257 typedef std::map<_Value, _Item> Container; 1671 Container invMap;1258 Container _inv_map; 1672 1259 1673 1260 public: … … 1682 1269 /// \brief Constructor. 1683 1270 /// 1684 /// Construct a new InvertableMap for the digraph.1685 /// 1686 explicit InvertableMap(const Digraph& digraph) : Map(digraph) {}1271 /// Construct a new InvertableMap for the graph. 1272 /// 1273 explicit InvertableMap(const Graph& graph) : Map(graph) {} 1687 1274 1688 1275 /// \brief Forward iterator for values. … … 1726 1313 /// range. 1727 1314 ValueIterator beginValue() const { 1728 return ValueIterator( invMap.begin());1315 return ValueIterator(_inv_map.begin()); 1729 1316 } 1730 1317 … … 1736 1323 /// range. 1737 1324 ValueIterator endValue() const { 1738 return ValueIterator( invMap.end());1325 return ValueIterator(_inv_map.end()); 1739 1326 } 1740 1327 … … 1744 1331 void set(const Key& key, const Value& val) { 1745 1332 Value oldval = Map::operator[](key); 1746 typename Container::iterator it = invMap.find(oldval);1747 if (it != invMap.end() && it->second == key) {1748 invMap.erase(it);1333 typename Container::iterator it = _inv_map.find(oldval); 1334 if (it != _inv_map.end() && it->second == key) { 1335 _inv_map.erase(it); 1749 1336 } 1750 invMap.insert(make_pair(val, key));1337 _inv_map.insert(make_pair(val, key)); 1751 1338 Map::set(key, val); 1752 1339 } … … 1764 1351 /// Gives back the item by its value. 1765 1352 Key operator()(const Value& key) const { 1766 typename Container::const_iterator it = invMap.find(key);1767 return it != invMap.end() ? it->second : INVALID;1353 typename Container::const_iterator it = _inv_map.find(key); 1354 return it != _inv_map.end() ? it->second : INVALID; 1768 1355 } 1769 1356 … … 1776 1363 virtual void erase(const Key& key) { 1777 1364 Value val = Map::operator[](key); 1778 typename Container::iterator it = invMap.find(val);1779 if (it != invMap.end() && it->second == key) {1780 invMap.erase(it);1365 typename Container::iterator it = _inv_map.find(val); 1366 if (it != _inv_map.end() && it->second == key) { 1367 _inv_map.erase(it); 1781 1368 } 1782 1369 Map::erase(key); … … 1790 1377 for (int i = 0; i < int(keys.size()); ++i) { 1791 1378 Value val = Map::operator[](keys[i]); 1792 typename Container::iterator it = invMap.find(val);1793 if (it != invMap.end() && it->second == keys[i]) {1794 invMap.erase(it);1379 typename Container::iterator it = _inv_map.find(val); 1380 if (it != _inv_map.end() && it->second == keys[i]) { 1381 _inv_map.erase(it); 1795 1382 } 1796 1383 } … … 1803 1390 /// \c AlterationNotifier. 1804 1391 virtual void clear() { 1805 invMap.clear();1392 _inv_map.clear(); 1806 1393 Map::clear(); 1807 1394 } … … 1818 1405 /// 1819 1406 /// Constructor of the InverseMap. 1820 explicit InverseMap(const InvertableMap& _inverted)1821 : inverted(_inverted) {}1407 explicit InverseMap(const InvertableMap& inverted) 1408 : _inverted(inverted) {} 1822 1409 1823 1410 /// The value type of the InverseMap. … … 1831 1418 /// what was last assigned to the value. 1832 1419 Value operator[](const Key& key) const { 1833 return inverted(key);1420 return _inverted(key); 1834 1421 } 1835 1422 1836 1423 private: 1837 const InvertableMap& inverted;1424 const InvertableMap& _inverted; 1838 1425 }; 1839 1426 … … 1850 1437 1851 1438 /// \brief Provides a mutable, continuous and unique descriptor for each 1852 /// item in the digraph.1439 /// item in the graph. 1853 1440 /// 1854 1441 /// The DescriptorMap class provides a unique and continuous (but mutable) 1855 1442 /// descriptor (id) for each item of the same type (e.g. node) in the 1856 /// digraph. This id is <ul><li>\b unique: different items (nodes) get1443 /// graph. This id is <ul><li>\b unique: different items (nodes) get 1857 1444 /// different ids <li>\b continuous: the range of the ids is the set of 1858 1445 /// integers between 0 and \c n-1, where \c n is the number of the items of 1859 1446 /// this type (e.g. nodes) (so the id of a node can change if you delete an 1860 1447 /// other node, i.e. this id is mutable). </ul> This map can be inverted 1861 /// with its member class \c InverseMap .1862 /// 1863 /// \param _ Digraph The digraph class the \c DescriptorMap belongs to.1448 /// with its member class \c InverseMap, or with the \c operator() member. 1449 /// 1450 /// \param _Graph The graph class the \c DescriptorMap belongs to. 1864 1451 /// \param _Item The Item is the Key of the Map. It may be Node, Arc or 1865 1452 /// Edge. 1866 template <typename _ Digraph, typename _Item>1867 class DescriptorMap : protected DefaultMap<_ Digraph, _Item, int> {1453 template <typename _Graph, typename _Item> 1454 class DescriptorMap : protected DefaultMap<_Graph, _Item, int> { 1868 1455 1869 1456 typedef _Item Item; 1870 typedef DefaultMap<_ Digraph, _Item, int> Map;1457 typedef DefaultMap<_Graph, _Item, int> Map; 1871 1458 1872 1459 public: 1873 /// The digraph class of DescriptorMap.1874 typedef _ Digraph Digraph;1460 /// The graph class of DescriptorMap. 1461 typedef _Graph Graph; 1875 1462 1876 1463 /// The key type of DescriptorMap (Node, Arc, Edge). … … 1882 1469 /// 1883 1470 /// Constructor for descriptor map. 1884 explicit DescriptorMap(const Digraph& _digraph) : Map(_digraph) {1471 explicit DescriptorMap(const Graph& _graph) : Map(_graph) { 1885 1472 Item it; 1886 1473 const typename Map::Notifier* nf = Map::notifier(); 1887 1474 for (nf->first(it); it != INVALID; nf->next(it)) { 1888 Map::set(it, invMap.size());1889 invMap.push_back(it);1475 Map::set(it, _inv_map.size()); 1476 _inv_map.push_back(it); 1890 1477 } 1891 1478 } … … 1899 1486 virtual void add(const Item& item) { 1900 1487 Map::add(item); 1901 Map::set(item, invMap.size());1902 invMap.push_back(item);1488 Map::set(item, _inv_map.size()); 1489 _inv_map.push_back(item); 1903 1490 } 1904 1491 … … 1910 1497 Map::add(items); 1911 1498 for (int i = 0; i < int(items.size()); ++i) { 1912 Map::set(items[i], invMap.size());1913 invMap.push_back(items[i]);1499 Map::set(items[i], _inv_map.size()); 1500 _inv_map.push_back(items[i]); 1914 1501 } 1915 1502 } … … 1920 1507 /// \c AlterationNotifier. 1921 1508 virtual void erase(const Item& item) { 1922 Map::set( invMap.back(), Map::operator[](item));1923 invMap[Map::operator[](item)] = invMap.back();1924 invMap.pop_back();1509 Map::set(_inv_map.back(), Map::operator[](item)); 1510 _inv_map[Map::operator[](item)] = _inv_map.back(); 1511 _inv_map.pop_back(); 1925 1512 Map::erase(item); 1926 1513 } … … 1932 1519 virtual void erase(const std::vector<Item>& items) { 1933 1520 for (int i = 0; i < int(items.size()); ++i) { 1934 Map::set( invMap.back(), Map::operator[](items[i]));1935 invMap[Map::operator[](items[i])] = invMap.back();1936 invMap.pop_back();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(); 1937 1524 } 1938 1525 Map::erase(items); … … 1948 1535 const typename Map::Notifier* nf = Map::notifier(); 1949 1536 for (nf->first(it); it != INVALID; nf->next(it)) { 1950 Map::set(it, invMap.size());1951 invMap.push_back(it);1537 Map::set(it, _inv_map.size()); 1538 _inv_map.push_back(it); 1952 1539 } 1953 1540 } … … 1958 1545 /// \c AlterationNotifier. 1959 1546 virtual void clear() { 1960 invMap.clear();1547 _inv_map.clear(); 1961 1548 Map::clear(); 1962 1549 } … … 1968 1555 /// Returns the maximal value plus one in the map. 1969 1556 unsigned int size() const { 1970 return invMap.size();1557 return _inv_map.size(); 1971 1558 } 1972 1559 … … 1978 1565 int qi = Map::operator[](q); 1979 1566 Map::set(p, qi); 1980 invMap[qi] = p;1567 _inv_map[qi] = p; 1981 1568 Map::set(q, pi); 1982 invMap[pi] = q;1569 _inv_map[pi] = q; 1983 1570 } 1984 1571 … … 1994 1581 /// Gives back th item by its descriptor. 1995 1582 Item operator()(int id) const { 1996 return invMap[id];1583 return _inv_map[id]; 1997 1584 } 1998 1585 … … 2000 1587 2001 1588 typedef std::vector<Item> Container; 2002 Container invMap;1589 Container _inv_map; 2003 1590 2004 1591 public: … … 2011 1598 /// 2012 1599 /// Constructor of the InverseMap. 2013 explicit InverseMap(const DescriptorMap& _inverted)2014 : inverted(_inverted) {}1600 explicit InverseMap(const DescriptorMap& inverted) 1601 : _inverted(inverted) {} 2015 1602 2016 1603 … … 2025 1612 /// that the descriptor belongs to currently. 2026 1613 Value operator[](const Key& key) const { 2027 return inverted(key);1614 return _inverted(key); 2028 1615 } 2029 1616 … … 2032 1619 /// Returns the size of the map. 2033 1620 unsigned int size() const { 2034 return inverted.size();1621 return _inverted.size(); 2035 1622 } 2036 1623 2037 1624 private: 2038 const DescriptorMap& inverted;1625 const DescriptorMap& _inverted; 2039 1626 }; 2040 1627 … … 2063 1650 /// Constructor 2064 1651 /// \param _digraph The digraph that the map belongs to. 2065 explicit SourceMap(const Digraph& _digraph) : digraph(_digraph) {}1652 explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {} 2066 1653 2067 1654 /// \brief The subscript operator. … … 2071 1658 /// \return The source of the arc 2072 1659 Value operator[](const Key& arc) const { 2073 return digraph.source(arc);1660 return _digraph.source(arc); 2074 1661 } 2075 1662 2076 1663 private: 2077 const Digraph& digraph;1664 const Digraph& _digraph; 2078 1665 }; 2079 1666 … … 2103 1690 /// Constructor 2104 1691 /// \param _digraph The digraph that the map belongs to. 2105 explicit TargetMap(const Digraph& _digraph) : digraph(_digraph) {}1692 explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {} 2106 1693 2107 1694 /// \brief The subscript operator. … … 2111 1698 /// \return The target of the arc 2112 1699 Value operator[](const Key& e) const { 2113 return digraph.target(e);1700 return _digraph.target(e); 2114 1701 } 2115 1702 2116 1703 private: 2117 const Digraph& digraph;1704 const Digraph& _digraph; 2118 1705 }; 2119 1706 … … 2132 1719 /// \see BackwardMap 2133 1720 /// \author Balazs Dezso 2134 template <typename Digraph>1721 template <typename Graph> 2135 1722 class ForwardMap { 2136 1723 public: 2137 1724 2138 typedef typename Digraph::Arc Value;2139 typedef typename Digraph::Edge Key;1725 typedef typename Graph::Arc Value; 1726 typedef typename Graph::Edge Key; 2140 1727 2141 1728 /// \brief Constructor 2142 1729 /// 2143 1730 /// Constructor 2144 /// \param _ digraph The digraph that the map belongs to.2145 explicit ForwardMap(const Digraph& _digraph) : digraph(_digraph) {}1731 /// \param _graph The graph that the map belongs to. 1732 explicit ForwardMap(const Graph& graph) : _graph(graph) {} 2146 1733 2147 1734 /// \brief The subscript operator. … … 2151 1738 /// \return The "forward" directed arc view of edge 2152 1739 Value operator[](const Key& key) const { 2153 return digraph.direct(key, true);1740 return _graph.direct(key, true); 2154 1741 } 2155 1742 2156 1743 private: 2157 const Digraph& digraph;1744 const Graph& _graph; 2158 1745 }; 2159 1746 … … 2162 1749 /// This function just returns an \ref ForwardMap class. 2163 1750 /// \relates ForwardMap 2164 template <typename Digraph>2165 inline ForwardMap< Digraph> forwardMap(const Digraph& digraph) {2166 return ForwardMap< Digraph>(digraph);1751 template <typename Graph> 1752 inline ForwardMap<Graph> forwardMap(const Graph& graph) { 1753 return ForwardMap<Graph>(graph); 2167 1754 } 2168 1755 … … 2172 1759 /// \see ForwardMap 2173 1760 /// \author Balazs Dezso 2174 template <typename Digraph>1761 template <typename Graph> 2175 1762 class BackwardMap { 2176 1763 public: 2177 1764 2178 typedef typename Digraph::Arc Value;2179 typedef typename Digraph::Edge Key;1765 typedef typename Graph::Arc Value; 1766 typedef typename Graph::Edge Key; 2180 1767 2181 1768 /// \brief Constructor 2182 1769 /// 2183 1770 /// Constructor 2184 /// \param _ digraph The digraph that the map belongs to.2185 explicit BackwardMap(const Digraph& _digraph) : digraph(_digraph) {}1771 /// \param _graph The graph that the map belongs to. 1772 explicit BackwardMap(const Graph& graph) : _graph(graph) {} 2186 1773 2187 1774 /// \brief The subscript operator. … … 2191 1778 /// \return The "backward" directed arc view of edge 2192 1779 Value operator[](const Key& key) const { 2193 return digraph.direct(key, false);1780 return _graph.direct(key, false); 2194 1781 } 2195 1782 2196 1783 private: 2197 const Digraph& digraph;1784 const Graph& _graph; 2198 1785 }; 2199 1786 … … 2202 1789 /// This function just returns a \ref BackwardMap class. 2203 1790 /// \relates BackwardMap 2204 template <typename Digraph>2205 inline BackwardMap< Digraph> backwardMap(const Digraph& digraph) {2206 return BackwardMap< Digraph>(digraph);1791 template <typename Graph> 1792 inline BackwardMap<Graph> backwardMap(const Graph& graph) { 1793 return BackwardMap<Graph>(graph); 2207 1794 } 2208 1795 … … 2221 1808 /// 2222 1809 /// Contructor of the map 2223 explicit PotentialDifferenceMap(const Digraph& _digraph,2224 const NodeMap& _potential)2225 : digraph(_digraph), potential(_potential) {}1810 explicit PotentialDifferenceMap(const Digraph& digraph, 1811 const NodeMap& potential) 1812 : _digraph(digraph), _potential(potential) {} 2226 1813 2227 1814 /// \brief Const subscription operator … … 2229 1816 /// Const subscription operator 2230 1817 Value operator[](const Key& arc) const { 2231 return potential[digraph.target(arc)] - potential[digraph.source(arc)]; 1818 return _potential[_digraph.target(arc)] - 1819 _potential[_digraph.source(arc)]; 2232 1820 } 2233 1821 2234 1822 private: 2235 const Digraph& digraph;2236 const NodeMap& potential;1823 const Digraph& _digraph; 1824 const NodeMap& _potential; 2237 1825 }; 2238 1826 … … 2275 1863 typedef typename Digraph::Node Key; 2276 1864 2277 typedef typename ItemSetTraits< _Digraph, typename _Digraph::Arc>1865 typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> 2278 1866 ::ItemNotifier::ObserverBase Parent; 2279 1867 2280 1868 private: 2281 1869 2282 class AutoNodeMap : public DefaultMap< _Digraph, Key, int> {1870 class AutoNodeMap : public DefaultMap<Digraph, Key, int> { 2283 1871 public: 2284 1872 2285 typedef DefaultMap<_Digraph, Key, int> Parent; 2286 typedef typename Parent::Digraph Digraph; 1873 typedef DefaultMap<Digraph, Key, int> Parent; 2287 1874 2288 1875 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} … … 2315 1902 /// 2316 1903 /// Constructor for creating in-degree map. 2317 explicit InDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) { 2318 Parent::attach(digraph.notifier(typename _Digraph::Arc())); 1904 explicit InDegMap(const Digraph& digraph) 1905 : _digraph(digraph), _deg(digraph) { 1906 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2319 1907 2320 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2321 deg[it] = countInArcs(digraph, it);1908 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 1909 _deg[it] = countInArcs(_digraph, it); 2322 1910 } 2323 1911 } … … 2325 1913 /// Gives back the in-degree of a Node. 2326 1914 int operator[](const Key& key) const { 2327 return deg[key];1915 return _deg[key]; 2328 1916 } 2329 1917 … … 2333 1921 2334 1922 virtual void add(const Arc& arc) { 2335 ++ deg[digraph.target(arc)];1923 ++_deg[_digraph.target(arc)]; 2336 1924 } 2337 1925 2338 1926 virtual void add(const std::vector<Arc>& arcs) { 2339 1927 for (int i = 0; i < int(arcs.size()); ++i) { 2340 ++ deg[digraph.target(arcs[i])];1928 ++_deg[_digraph.target(arcs[i])]; 2341 1929 } 2342 1930 } 2343 1931 2344 1932 virtual void erase(const Arc& arc) { 2345 -- deg[digraph.target(arc)];1933 --_deg[_digraph.target(arc)]; 2346 1934 } 2347 1935 2348 1936 virtual void erase(const std::vector<Arc>& arcs) { 2349 1937 for (int i = 0; i < int(arcs.size()); ++i) { 2350 -- deg[digraph.target(arcs[i])];1938 --_deg[_digraph.target(arcs[i])]; 2351 1939 } 2352 1940 } 2353 1941 2354 1942 virtual void build() { 2355 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2356 deg[it] = countInArcs(digraph, it);1943 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 1944 _deg[it] = countInArcs(_digraph, it); 2357 1945 } 2358 1946 } 2359 1947 2360 1948 virtual void clear() { 2361 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2362 deg[it] = 0;1949 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 1950 _deg[it] = 0; 2363 1951 } 2364 1952 } 2365 1953 private: 2366 1954 2367 const _Digraph&digraph;2368 AutoNodeMap deg;1955 const Digraph& _digraph; 1956 AutoNodeMap _deg; 2369 1957 }; 2370 1958 … … 2392 1980 2393 1981 public: 2394 2395 typedef typename ItemSetTraits<_Digraph, typename _Digraph::Arc>2396 ::ItemNotifier::ObserverBase Parent;2397 1982 2398 1983 typedef _Digraph Digraph; … … 2400 1985 typedef typename Digraph::Node Key; 2401 1986 1987 typedef typename ItemSetTraits<Digraph, typename Digraph::Arc> 1988 ::ItemNotifier::ObserverBase Parent; 1989 2402 1990 private: 2403 1991 2404 class AutoNodeMap : public DefaultMap< _Digraph, Key, int> {1992 class AutoNodeMap : public DefaultMap<Digraph, Key, int> { 2405 1993 public: 2406 1994 2407 typedef DefaultMap<_Digraph, Key, int> Parent; 2408 typedef typename Parent::Digraph Digraph; 1995 typedef DefaultMap<Digraph, Key, int> Parent; 2409 1996 2410 1997 AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {} … … 2435 2022 /// 2436 2023 /// Constructor for creating out-degree map. 2437 explicit OutDegMap(const Digraph& _digraph) : digraph(_digraph), deg(_digraph) { 2438 Parent::attach(digraph.notifier(typename _Digraph::Arc())); 2024 explicit OutDegMap(const Digraph& digraph) 2025 : _digraph(digraph), _deg(digraph) { 2026 Parent::attach(_digraph.notifier(typename Digraph::Arc())); 2439 2027 2440 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2441 deg[it] = countOutArcs(digraph, it);2028 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2029 _deg[it] = countOutArcs(_digraph, it); 2442 2030 } 2443 2031 } … … 2445 2033 /// Gives back the out-degree of a Node. 2446 2034 int operator[](const Key& key) const { 2447 return deg[key];2035 return _deg[key]; 2448 2036 } 2449 2037 … … 2453 2041 2454 2042 virtual void add(const Arc& arc) { 2455 ++ deg[digraph.source(arc)];2043 ++_deg[_digraph.source(arc)]; 2456 2044 } 2457 2045 2458 2046 virtual void add(const std::vector<Arc>& arcs) { 2459 2047 for (int i = 0; i < int(arcs.size()); ++i) { 2460 ++ deg[digraph.source(arcs[i])];2048 ++_deg[_digraph.source(arcs[i])]; 2461 2049 } 2462 2050 } 2463 2051 2464 2052 virtual void erase(const Arc& arc) { 2465 -- deg[digraph.source(arc)];2053 --_deg[_digraph.source(arc)]; 2466 2054 } 2467 2055 2468 2056 virtual void erase(const std::vector<Arc>& arcs) { 2469 2057 for (int i = 0; i < int(arcs.size()); ++i) { 2470 -- deg[digraph.source(arcs[i])];2058 --_deg[_digraph.source(arcs[i])]; 2471 2059 } 2472 2060 } 2473 2061 2474 2062 virtual void build() { 2475 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2476 deg[it] = countOutArcs(digraph, it);2063 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2064 _deg[it] = countOutArcs(_digraph, it); 2477 2065 } 2478 2066 } 2479 2067 2480 2068 virtual void clear() { 2481 for(typename _Digraph::NodeIt it(digraph); it != INVALID; ++it) {2482 deg[it] = 0;2069 for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) { 2070 _deg[it] = 0; 2483 2071 } 2484 2072 } 2485 2073 private: 2486 2074 2487 const _Digraph&digraph;2488 AutoNodeMap deg;2075 const Digraph& _digraph; 2076 AutoNodeMap _deg; 2489 2077 }; 2490 2078 … … 2501 2089 /// 2502 2090 ///See the \ref ArcLookUp and \ref AllArcLookUp classes if your 2503 ///digraph donot changed so frequently.2091 ///digraph is not changed so frequently. 2504 2092 /// 2505 2093 ///This class uses a self-adjusting binary search tree, Sleator's … … 2521 2109 ::ItemNotifier::ObserverBase Parent; 2522 2110 2523 GRAPH_TYPEDEFS(typenameG);2111 TEMPLATE_DIGRAPH_TYPEDEFS(G); 2524 2112 typedef G Digraph; 2525 2113 … … 2836 2424 Arc operator()(Node s, Node t) const 2837 2425 { 2838 Arc e= _head[s];2426 Arc a = _head[s]; 2839 2427 while (true) { 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);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); 2846 2434 return INVALID; 2847 2435 } else { 2848 e = _left[e];2436 a = _left[a]; 2849 2437 } 2850 2438 } else { 2851 if (_right[ e] == INVALID) {2852 const_cast<DynArcLookUp&>(*this).splay( e);2439 if (_right[a] == INVALID) { 2440 const_cast<DynArcLookUp&>(*this).splay(a); 2853 2441 return INVALID; 2854 2442 } else { 2855 e = _right[e];2443 a = _right[a]; 2856 2444 } 2857 2445 } … … 2870 2458 Arc findFirst(Node s, Node t) const 2871 2459 { 2872 Arc e= _head[s];2460 Arc a = _head[s]; 2873 2461 Arc r = INVALID; 2874 2462 while (true) { 2875 if (_g.target( e) < t) {2876 if (_right[ e] == INVALID) {2877 const_cast<DynArcLookUp&>(*this).splay( e);2463 if (_g.target(a) < t) { 2464 if (_right[a] == INVALID) { 2465 const_cast<DynArcLookUp&>(*this).splay(a); 2878 2466 return r; 2879 2467 } else { 2880 e = _right[e];2468 a = _right[a]; 2881 2469 } 2882 2470 } else { 2883 if (_g.target( e) == t) {2884 r = e;2471 if (_g.target(a) == t) { 2472 r = a; 2885 2473 } 2886 if (_left[ e] == INVALID) {2887 const_cast<DynArcLookUp&>(*this).splay( e);2474 if (_left[a] == INVALID) { 2475 const_cast<DynArcLookUp&>(*this).splay(a); 2888 2476 return r; 2889 2477 } else { 2890 e = _left[e];2478 a = _left[a]; 2891 2479 } 2892 2480 } … … 2907 2495 ///operation then the amorized time bound can not be guaranteed. 2908 2496 #ifdef DOXYGEN 2909 Arc findNext(Node s, Node t, Arc e) const2497 Arc findNext(Node s, Node t, Arc a) const 2910 2498 #else 2911 Arc findNext(Node, Node t, Arc e) const2499 Arc findNext(Node, Node t, Arc a) const 2912 2500 #endif 2913 2501 { 2914 if (_right[ e] != INVALID) {2915 e = _right[e];2916 while (_left[ e] != INVALID) {2917 e = _left[e];2502 if (_right[a] != INVALID) { 2503 a = _right[a]; 2504 while (_left[a] != INVALID) { 2505 a = _left[a]; 2918 2506 } 2919 const_cast<DynArcLookUp&>(*this).splay( e);2507 const_cast<DynArcLookUp&>(*this).splay(a); 2920 2508 } else { 2921 while (_parent[ e] != INVALID && _right[_parent[e]] == e) {2922 e = _parent[e];2509 while (_parent[a] != INVALID && _right[_parent[a]] == a) { 2510 a = _parent[a]; 2923 2511 } 2924 if (_parent[ e] == INVALID) {2512 if (_parent[a] == INVALID) { 2925 2513 return INVALID; 2926 2514 } else { 2927 e = _parent[e];2928 const_cast<DynArcLookUp&>(*this).splay( e);2515 a = _parent[a]; 2516 const_cast<DynArcLookUp&>(*this).splay(a); 2929 2517 } 2930 2518 } 2931 if (_g.target( e) == t) return e;2519 if (_g.target(a) == t) return a; 2932 2520 else return INVALID; 2933 2521 } … … 2958 2546 { 2959 2547 public: 2960 GRAPH_TYPEDEFS(typenameG);2548 TEMPLATE_DIGRAPH_TYPEDEFS(G); 2961 2549 typedef G Digraph; 2962 2550 … … 3075 2663 using ArcLookUp<G>::_head; 3076 2664 3077 GRAPH_TYPEDEFS(typenameG);2665 TEMPLATE_DIGRAPH_TYPEDEFS(G); 3078 2666 typedef G Digraph; 3079 2667 -
lemon/lgf_reader.h
r127 r148 303 303 304 304 typedef _Digraph Digraph; 305 GRAPH_TYPEDEFS(typenameDigraph);305 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 306 306 307 307 private: -
lemon/lgf_writer.h
r127 r148 238 238 239 239 typedef _Digraph Digraph; 240 GRAPH_TYPEDEFS(typenameDigraph);240 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); 241 241 242 242 private: -
lemon/list_graph.h
r73 r149 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 155 165 Node addNode() { 156 166 int n; … … 220 230 nodes[n].next = first_free_node; 221 231 first_free_node = n; 232 nodes[n].prev = -2; 222 233 223 234 } … … 248 259 249 260 arcs[n].next_in = first_free_arc; 250 first_free_arc = n; 251 261 first_free_arc = n; 262 arcs[n].prev_in = -2; 252 263 } 253 264 … … 350 361 return Parent::addArc(s, t); 351 362 } 363 364 /// Node validity check 365 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 item 370 /// could become valid again later if new nodes are 371 /// added to the graph. 372 bool valid(Node n) const { return Parent::valid(n); } 373 374 /// Arc validity check 375 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 item 380 /// could become valid again later if new nodes are 381 /// added to the graph. 382 bool valid(Arc a) const { return Parent::valid(a); } 352 383 353 384 /// Change the target of \c e to \c n … … 946 977 static Edge edgeFromId(int id) { return Edge(id);} 947 978 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 948 994 Node addNode() { 949 995 int n; … … 1014 1060 nodes[n].next = first_free_node; 1015 1061 first_free_node = n; 1016 1062 nodes[n].prev = -2; 1017 1063 } 1018 1064 … … 1042 1088 arcs[n].next_out = first_free_arc; 1043 1089 first_free_arc = n; 1090 arcs[n].prev_out = -2; 1091 arcs[n | 1].prev_out = -2; 1044 1092 1045 1093 } … … 1158 1206 return Parent::addEdge(s, t); 1159 1207 } 1208 /// Node validity check 1209 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 item 1214 /// could become valid again later if new nodes are 1215 /// added to the graph. 1216 bool valid(Node n) const { return Parent::valid(n); } 1217 /// Arc validity check 1218 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 item 1223 /// could become valid again later if new edges are 1224 /// added to the graph. 1225 bool valid(Arc a) const { return Parent::valid(a); } 1226 /// Edge validity check 1227 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 item 1232 /// could become valid again later if new edges are 1233 /// added to the graph. 1234 bool valid(Edge e) const { return Parent::valid(e); } 1160 1235 /// \brief Change the source of \c e to \c n 1161 1236 /// -
lemon/path.h
r100 r144 904 904 905 905 template <typename Path, typename Enable = void> 906 struct Rev TagIndicator {906 struct RevPathTagIndicator { 907 907 static const bool value = false; 908 908 }; 909 909 910 template <typename Digraph> 911 struct RevTagIndicator< 912 Digraph, 913 typename enable_if<typename Digraph::RevTag, void>::type 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 914 927 > { 915 928 static const bool value = true; … … 917 930 918 931 template <typename Target, typename Source, 919 typename BuildEnable = void, typename RevEnable = void> 932 bool buildEnable = BuildTagIndicator<Target>::value, 933 bool revEnable = RevPathTagIndicator<Source>::value> 920 934 struct PathCopySelector { 921 935 static void copy(Target& target, const Source& source) { … … 927 941 }; 928 942 929 template <typename Target, typename Source, typename BuildEnable> 930 struct PathCopySelector< 931 Target, Source, BuildEnable, 932 typename enable_if<typename Source::RevPathTag, void>::type> { 943 template <typename Target, typename Source> 944 struct PathCopySelector<Target, Source, false, true> { 933 945 static void copy(Target& target, const Source& source) { 934 946 target.clear(); … … 939 951 }; 940 952 941 template <typename Target, typename Source, typename RevEnable> 942 struct PathCopySelector< 943 Target, Source, 944 typename enable_if<typename Target::BuildTag, void>::type, RevEnable> { 953 template <typename Target, typename Source> 954 struct PathCopySelector<Target, Source, true, false> { 945 955 static void copy(Target& target, const Source& source) { 946 956 target.clear(); … … 950 960 951 961 template <typename Target, typename Source> 952 struct PathCopySelector< 953 Target, Source, 954 typename enable_if<typename Target::BuildTag, void>::type, 955 typename enable_if<typename Source::RevPathTag, void>::type> { 962 struct PathCopySelector<Target, Source, true, true> { 956 963 static void copy(Target& target, const Source& source) { 957 964 target.clear(); -
lemon/smart_graph.h
r125 r149 74 74 75 75 typedef True NodeNumTag; 76 typedef True ArcNumTag;76 typedef True EdgeNumTag; 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 } 117 124 118 125 class Node { … … 261 268 /// \sa reserveNode 262 269 void reserveArc(int m) { arcs.reserve(m); }; 270 271 /// \brief Node validity check 272 /// 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 again 277 /// when new nodes are added to the graph. 278 bool valid(Node n) const { return Parent::valid(n); } 279 280 /// \brief Arc validity check 281 /// 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 again 286 /// when new arcs are added to the graph. 287 bool valid(Arc a) const { return Parent::valid(a); } 263 288 264 289 ///Clear the digraph. … … 551 576 static Edge edgeFromId(int id) { return Edge(id);} 552 577 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 553 588 Node addNode() { 554 589 int n = nodes.size(); … … 559 594 } 560 595 561 Edge add Arc(Node u, Node v) {596 Edge addEdge(Node u, Node v) { 562 597 int n = arcs.size(); 563 598 arcs.push_back(ArcT()); … … 640 675 ///\return the new edge. 641 676 Edge addEdge(const Node& s, const Node& t) { 642 return Parent::addArc(s, t); 643 } 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); } 644 706 645 707 ///Clear the graph. -
lemon/time_measure.h
r126 r143 25 25 26 26 #ifdef WIN32 27 #define WIN32_LEAN_AND_MEAN 28 #define NOMINMAX 27 29 #include <windows.h> 28 30 #include <cmath> … … 32 34 #endif 33 35 36 #include <string> 34 37 #include <fstream> 35 38 #include <iostream> -
test/Makefile.am
r119 r146 1 1 EXTRA_DIST += \ 2 test/ Makefile2 test/CMakeLists.txt 3 3 4 4 noinst_HEADERS += \ 5 5 test/digraph_test.h \ 6 test/graph_utils_test.h \ 6 7 test/heap_test.h \ 7 8 test/map_test.h \ … … 16 17 test/error_test \ 17 18 test/graph_test \ 19 test/graph_utils_test \ 18 20 test/kruskal_test \ 19 21 test/maps_test \ … … 35 37 test_error_test_SOURCES = test/error_test.cc 36 38 test_graph_test_SOURCES = test/graph_test.cc 39 test_graph_utils_test_SOURCES = test/graph_utils_test.cc 37 40 # test_heap_test_SOURCES = test/heap_test.cc 38 41 test_kruskal_test_SOURCES = test/kruskal_test.cc -
test/graph_test.cc
r109 r149 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 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 85 void check_graph_counts() { 86 87 TEMPLATE_GRAPH_TYPEDEFS(Graph); 125 88 Graph g; 126 89 … … 136 99 e2 = g.addEdge(n2, n3); 137 100 138 // print_items(g);139 140 101 check_item_counts(g,3,2); 141 102 } 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 Node 113 n1 = g.addNode(), 114 n2 = g.addNode(), 115 n3 = g.addNode(); 116 117 Edge 118 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 Node 140 n1 = g.addNode(), 141 n2 = g.addNode(), 142 n3 = g.addNode(); 143 144 Edge 145 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 142 167 143 168 // void checkGridGraph(const GridGraph& g, int w, int h) { … … 188 213 check_concepts(); 189 214 190 check_graph<ListGraph>(); 191 check_graph<SmartGraph>(); 215 check_graph_counts<ListGraph>(); 216 check_graph_counts<SmartGraph>(); 217 218 check_graph_validity_erase<ListGraph>(); 219 check_graph_validity<SmartGraph>(); 192 220 193 221 // { -
tools/Makefile.am
r1 r146 1 EXTRA_DIST += \2 tools/Makefile3 4 1 if WANT_TOOLS 5 2
Note: See TracChangeset
for help on using the changeset viewer.