0
2
0
50
48
| ... | ... |
@@ -7,28 +7,28 @@ |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 |
// Modified for use in LEMON. |
|
| 20 |
// We should really consider using Boost... |
|
| 19 |
// This file contains a modified version of the concept checking |
|
| 20 |
// utility from BOOST. |
|
| 21 |
// See the appropriate copyright notice below. |
|
| 21 | 22 |
|
| 22 |
// |
|
| 23 | 23 |
// (C) Copyright Jeremy Siek 2000. |
| 24 | 24 |
// Distributed under the Boost Software License, Version 1.0. (See |
| 25 | 25 |
// accompanying file LICENSE_1_0.txt or copy at |
| 26 | 26 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 27 | 27 |
// |
| 28 | 28 |
// Revision History: |
| 29 | 29 |
// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek) |
| 30 | 30 |
// 02 April 2001: Removed limits header altogether. (Jeremy Siek) |
| 31 | 31 |
// 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock) |
| 32 | 32 |
// |
| 33 | 33 |
|
| 34 | 34 |
// See http://www.boost.org/libs/concept_check for documentation. |
| ... | ... |
@@ -238,25 +238,27 @@ |
| 238 | 238 |
|
| 239 | 239 |
template <typename T1, typename C1 = std::less<T1> > |
| 240 | 240 |
struct rebind {
|
| 241 | 241 |
typedef StdMap<Key, T1, C1> other; |
| 242 | 242 |
}; |
| 243 | 243 |
}; |
| 244 | 244 |
|
| 245 | 245 |
/// \brief Map for storing values for the range \c [0..size-1] range keys |
| 246 | 246 |
/// |
| 247 | 247 |
/// The current map has the \c [0..size-1] keyset and the values |
| 248 | 248 |
/// are stored in a \c std::vector<T> container. It can be used with |
| 249 | 249 |
/// some data structures, for example \c UnionFind, \c BinHeap, when |
| 250 |
/// the used items are small integer numbers. |
|
| 250 |
/// the used items are small integer numbers. |
|
| 251 |
/// |
|
| 252 |
/// \todo Revise its name |
|
| 251 | 253 |
template <typename T> |
| 252 | 254 |
class IntegerMap {
|
| 253 | 255 |
|
| 254 | 256 |
template <typename T1> |
| 255 | 257 |
friend class IntegerMap; |
| 256 | 258 |
|
| 257 | 259 |
public: |
| 258 | 260 |
|
| 259 | 261 |
typedef True ReferenceMapTag; |
| 260 | 262 |
///\e |
| 261 | 263 |
typedef int Key; |
| 262 | 264 |
///\e |
| ... | ... |
@@ -337,87 +339,90 @@ |
| 337 | 339 |
}; |
| 338 | 340 |
|
| 339 | 341 |
///Returns an \c IdentityMap class |
| 340 | 342 |
|
| 341 | 343 |
///This function just returns an \c IdentityMap class. |
| 342 | 344 |
///\relates IdentityMap |
| 343 | 345 |
template<typename T> |
| 344 | 346 |
inline IdentityMap<T> identityMap() {
|
| 345 | 347 |
return IdentityMap<T>(); |
| 346 | 348 |
} |
| 347 | 349 |
|
| 348 | 350 |
|
| 349 |
///Convert the \c Value of a map to another type. |
|
| 350 |
|
|
| 351 |
///\brief Convert the \c Value of a map to another type using |
|
| 352 |
///the default conversion. |
|
| 353 |
/// |
|
| 351 | 354 |
///This \c concepts::ReadMap "read only map" |
| 352 | 355 |
///converts the \c Value of a maps to type \c T. |
| 353 | 356 |
///Its \c Key is inherited from \c M. |
| 354 | 357 |
template <typename M, typename T> |
| 355 | 358 |
class ConvertMap : public MapBase<typename M::Key, T> {
|
| 356 | 359 |
const M& m; |
| 357 | 360 |
public: |
| 358 | 361 |
typedef MapBase<typename M::Key, T> Parent; |
| 359 | 362 |
typedef typename Parent::Key Key; |
| 360 | 363 |
typedef typename Parent::Value Value; |
| 361 | 364 |
|
| 362 | 365 |
///Constructor |
| 363 | 366 |
|
| 364 | 367 |
///Constructor |
| 365 | 368 |
///\param _m is the underlying map |
| 366 | 369 |
ConvertMap(const M &_m) : m(_m) {};
|
| 367 | 370 |
|
| 368 | 371 |
/// \brief The subscript operator. |
| 369 | 372 |
/// |
| 370 | 373 |
/// The subscript operator. |
| 371 |
/// \param k The key |
|
| 372 |
/// \return The target of the arc |
|
| 373 | 374 |
Value operator[](const Key& k) const {return m[k];}
|
| 374 | 375 |
}; |
| 375 | 376 |
|
| 376 | 377 |
///Returns an \c ConvertMap class |
| 377 | 378 |
|
| 378 | 379 |
///This function just returns an \c ConvertMap class. |
| 379 | 380 |
///\relates ConvertMap |
| 380 | 381 |
template<typename T, typename M> |
| 381 | 382 |
inline ConvertMap<M, T> convertMap(const M &m) {
|
| 382 | 383 |
return ConvertMap<M, T>(m); |
| 383 | 384 |
} |
| 384 | 385 |
|
| 385 | 386 |
///Simple wrapping of the map |
| 386 | 387 |
|
| 387 | 388 |
///This \c concepts::ReadMap "read only map" returns the simple |
| 388 | 389 |
///wrapping of the given map. Sometimes the reference maps cannot be |
| 389 | 390 |
///combined with simple read maps. This map adaptor wraps the given |
| 390 | 391 |
///map to simple read map. |
| 392 |
/// |
|
| 393 |
/// \todo Revise the misleading name |
|
| 391 | 394 |
template<typename M> |
| 392 | 395 |
class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
|
| 393 | 396 |
const M& m; |
| 394 | 397 |
|
| 395 | 398 |
public: |
| 396 | 399 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 397 | 400 |
typedef typename Parent::Key Key; |
| 398 | 401 |
typedef typename Parent::Value Value; |
| 399 | 402 |
|
| 400 | 403 |
///Constructor |
| 401 | 404 |
SimpleMap(const M &_m) : m(_m) {};
|
| 402 | 405 |
///\e |
| 403 | 406 |
Value operator[](Key k) const {return m[k];}
|
| 404 | 407 |
}; |
| 405 | 408 |
|
| 406 | 409 |
///Simple writeable wrapping of the map |
| 407 | 410 |
|
| 408 |
///This \c concepts:: |
|
| 411 |
///This \c concepts::WriteMap "write map" returns the simple |
|
| 409 | 412 |
///wrapping of the given map. Sometimes the reference maps cannot be |
| 410 | 413 |
///combined with simple read-write maps. This map adaptor wraps the |
| 411 | 414 |
///given map to simple read-write map. |
| 415 |
/// |
|
| 416 |
/// \todo Revise the misleading name |
|
| 412 | 417 |
template<typename M> |
| 413 | 418 |
class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 414 | 419 |
M& m; |
| 415 | 420 |
|
| 416 | 421 |
public: |
| 417 | 422 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 418 | 423 |
typedef typename Parent::Key Key; |
| 419 | 424 |
typedef typename Parent::Value Value; |
| 420 | 425 |
|
| 421 | 426 |
///Constructor |
| 422 | 427 |
SimpleWriteMap(M &_m) : m(_m) {};
|
| 423 | 428 |
///\e |
| ... | ... |
@@ -484,25 +489,25 @@ |
| 484 | 489 |
typedef typename Parent::Value Value; |
| 485 | 490 |
|
| 486 | 491 |
///Constructor |
| 487 | 492 |
|
| 488 | 493 |
///Constructor |
| 489 | 494 |
///\param _m is the undelying map |
| 490 | 495 |
///\param _v is the shift value |
| 491 | 496 |
ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
|
| 492 | 497 |
///\e |
| 493 | 498 |
Value operator[](Key k) const {return m[k] + v;}
|
| 494 | 499 |
}; |
| 495 | 500 |
|
| 496 |
///Shift a map with a constant. |
|
| 501 |
///Shift a map with a constant. This map is also writable. |
|
| 497 | 502 |
|
| 498 | 503 |
///This \c concepts::ReadWriteMap "read-write map" returns the sum of the |
| 499 | 504 |
///given map and a constant value. It makes also possible to write the map. |
| 500 | 505 |
///Its \c Key and \c Value is inherited from \c M. |
| 501 | 506 |
/// |
| 502 | 507 |
///Actually, |
| 503 | 508 |
///\code |
| 504 | 509 |
/// ShiftMap<X> sh(x,v); |
| 505 | 510 |
///\endcode |
| 506 | 511 |
///is equivalent with |
| 507 | 512 |
///\code |
| 508 | 513 |
/// ConstMap<X::Key, X::Value> c_tmp(v); |
| ... | ... |
@@ -540,25 +545,26 @@ |
| 540 | 545 |
|
| 541 | 546 |
template<typename M, typename C> |
| 542 | 547 |
inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
|
| 543 | 548 |
return ShiftWriteMap<M, C>(m,v); |
| 544 | 549 |
} |
| 545 | 550 |
|
| 546 | 551 |
///Difference of two maps |
| 547 | 552 |
|
| 548 | 553 |
///This \c concepts::ReadMap "read only map" returns the difference |
| 549 | 554 |
///of the values of the two |
| 550 | 555 |
///given maps. Its \c Key and \c Value will be inherited from \c M1. |
| 551 | 556 |
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
| 552 |
|
|
| 557 |
/// |
|
| 558 |
/// \todo Revise the misleading name |
|
| 553 | 559 |
template<typename M1, typename M2> |
| 554 | 560 |
class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 555 | 561 |
const M1& m1; |
| 556 | 562 |
const M2& m2; |
| 557 | 563 |
public: |
| 558 | 564 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 559 | 565 |
typedef typename Parent::Key Key; |
| 560 | 566 |
typedef typename Parent::Value Value; |
| 561 | 567 |
|
| 562 | 568 |
///Constructor |
| 563 | 569 |
SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
|
| 564 | 570 |
/// \e |
| ... | ... |
@@ -632,25 +638,25 @@ |
| 632 | 638 |
typedef typename Parent::Value Value; |
| 633 | 639 |
|
| 634 | 640 |
///Constructor |
| 635 | 641 |
|
| 636 | 642 |
///Constructor |
| 637 | 643 |
///\param _m is the undelying map |
| 638 | 644 |
///\param _v is the scaling value |
| 639 | 645 |
ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
|
| 640 | 646 |
/// \e |
| 641 | 647 |
Value operator[](Key k) const {return v * m[k];}
|
| 642 | 648 |
}; |
| 643 | 649 |
|
| 644 |
///Scales a maps with a constant. |
|
| 650 |
///Scales a maps with a constant (ReadWrite version). |
|
| 645 | 651 |
|
| 646 | 652 |
///This \c concepts::ReadWriteMap "read-write map" returns the value of the |
| 647 | 653 |
///given map multiplied from the left side with a constant value. It can |
| 648 | 654 |
///be used as write map also if the given multiplier is not zero. |
| 649 | 655 |
///Its \c Key and \c Value is inherited from \c M. |
| 650 | 656 |
template<typename M, typename C = typename M::Value> |
| 651 | 657 |
class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 652 | 658 |
M& m; |
| 653 | 659 |
C v; |
| 654 | 660 |
public: |
| 655 | 661 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 656 | 662 |
typedef typename Parent::Key Key; |
| ... | ... |
@@ -849,25 +855,25 @@ |
| 849 | 855 |
const M& m; |
| 850 | 856 |
public: |
| 851 | 857 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 852 | 858 |
typedef typename Parent::Key Key; |
| 853 | 859 |
typedef typename Parent::Value Value; |
| 854 | 860 |
|
| 855 | 861 |
///Constructor |
| 856 | 862 |
NegMap(const M &_m) : m(_m) {};
|
| 857 | 863 |
/// \e |
| 858 | 864 |
Value operator[](Key k) const {return -m[k];}
|
| 859 | 865 |
}; |
| 860 | 866 |
|
| 861 |
///Negative value of a map |
|
| 867 |
///Negative value of a map (ReadWrite version) |
|
| 862 | 868 |
|
| 863 | 869 |
///This \c concepts::ReadWriteMap "read-write map" returns the negative |
| 864 | 870 |
///value of the value returned by the |
| 865 | 871 |
///given map. Its \c Key and \c Value will be inherited from \c M. |
| 866 | 872 |
///The unary \c - operator must be defined for \c Value, of course. |
| 867 | 873 |
|
| 868 | 874 |
template<typename M> |
| 869 | 875 |
class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 870 | 876 |
M& m; |
| 871 | 877 |
public: |
| 872 | 878 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 873 | 879 |
typedef typename Parent::Key Key; |
| ... | ... |
@@ -896,36 +902,24 @@ |
| 896 | 902 |
} |
| 897 | 903 |
|
| 898 | 904 |
///Absolute value of a map |
| 899 | 905 |
|
| 900 | 906 |
///This \c concepts::ReadMap "read only map" returns the absolute value |
| 901 | 907 |
///of the |
| 902 | 908 |
///value returned by the |
| 903 | 909 |
///given map. Its \c Key and \c Value will be inherited |
| 904 | 910 |
///from <tt>M</tt>. <tt>Value</tt> |
| 905 | 911 |
///must be comparable to <tt>0</tt> and the unary <tt>-</tt> |
| 906 | 912 |
///operator must be defined for it, of course. |
| 907 | 913 |
/// |
| 908 |
///\bug We need a unified way to handle the situation below: |
|
| 909 |
///\code |
|
| 910 |
/// struct _UnConvertible {};
|
|
| 911 |
/// template<class A> inline A t_abs(A a) {return _UnConvertible();}
|
|
| 912 |
/// template<> inline int t_abs<>(int n) {return abs(n);}
|
|
| 913 |
/// template<> inline long int t_abs<>(long int n) {return labs(n);}
|
|
| 914 |
/// template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
|
|
| 915 |
/// template<> inline float t_abs<>(float n) {return fabsf(n);}
|
|
| 916 |
/// template<> inline double t_abs<>(double n) {return fabs(n);}
|
|
| 917 |
/// template<> inline long double t_abs<>(long double n) {return fabsl(n);}
|
|
| 918 |
///\endcode |
|
| 919 |
|
|
| 920 | 914 |
|
| 921 | 915 |
template<typename M> |
| 922 | 916 |
class AbsMap : public MapBase<typename M::Key, typename M::Value> {
|
| 923 | 917 |
const M& m; |
| 924 | 918 |
public: |
| 925 | 919 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 926 | 920 |
typedef typename Parent::Key Key; |
| 927 | 921 |
typedef typename Parent::Value Value; |
| 928 | 922 |
|
| 929 | 923 |
///Constructor |
| 930 | 924 |
AbsMap(const M &_m) : m(_m) {};
|
| 931 | 925 |
/// \e |
| ... | ... |
@@ -1032,24 +1026,26 @@ |
| 1032 | 1026 |
inline MapFunctor<M> mapFunctor(const M &m) {
|
| 1033 | 1027 |
return MapFunctor<M>(m); |
| 1034 | 1028 |
} |
| 1035 | 1029 |
|
| 1036 | 1030 |
///Applies all map setting operations to two maps |
| 1037 | 1031 |
|
| 1038 | 1032 |
///This map has two \c concepts::ReadMap "readable map" |
| 1039 | 1033 |
///parameters and each read request will be passed just to the |
| 1040 | 1034 |
///first map. This class is the just readable map type of the ForkWriteMap. |
| 1041 | 1035 |
/// |
| 1042 | 1036 |
///The \c Key and \c Value will be inherited from \c M1. |
| 1043 | 1037 |
///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
| 1038 |
/// |
|
| 1039 |
/// \todo Why is it needed? |
|
| 1044 | 1040 |
template<typename M1, typename M2> |
| 1045 | 1041 |
class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 1046 | 1042 |
const M1& m1; |
| 1047 | 1043 |
const M2& m2; |
| 1048 | 1044 |
public: |
| 1049 | 1045 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 1050 | 1046 |
typedef typename Parent::Key Key; |
| 1051 | 1047 |
typedef typename Parent::Value Value; |
| 1052 | 1048 |
|
| 1053 | 1049 |
///Constructor |
| 1054 | 1050 |
ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
|
| 1055 | 1051 |
/// \e |
| ... | ... |
@@ -1115,25 +1111,25 @@ |
| 1115 | 1111 |
const M& m; |
| 1116 | 1112 |
public: |
| 1117 | 1113 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1118 | 1114 |
typedef typename Parent::Key Key; |
| 1119 | 1115 |
typedef typename Parent::Value Value; |
| 1120 | 1116 |
|
| 1121 | 1117 |
/// Constructor |
| 1122 | 1118 |
NotMap(const M &_m) : m(_m) {};
|
| 1123 | 1119 |
///\e |
| 1124 | 1120 |
Value operator[](Key k) const {return !m[k];}
|
| 1125 | 1121 |
}; |
| 1126 | 1122 |
|
| 1127 |
///Logical 'not' of a map |
|
| 1123 |
///Logical 'not' of a map (ReadWrie version) |
|
| 1128 | 1124 |
|
| 1129 | 1125 |
///This bool \c concepts::ReadWriteMap "read-write map" returns the |
| 1130 | 1126 |
///logical negation of value returned by the given map. When it is set, |
| 1131 | 1127 |
///the opposite value is set to the original map. |
| 1132 | 1128 |
///Its \c Key and will be inherited from \c M, |
| 1133 | 1129 |
///its Value is <tt>bool</tt>. |
| 1134 | 1130 |
template <typename M> |
| 1135 | 1131 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1136 | 1132 |
M& m; |
| 1137 | 1133 |
public: |
| 1138 | 1134 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1139 | 1135 |
typedef typename Parent::Key Key; |
| ... | ... |
@@ -1178,94 +1174,97 @@ |
| 1178 | 1174 |
}; |
| 1179 | 1175 |
|
| 1180 | 1176 |
template <typename _Iterator> |
| 1181 | 1177 |
struct IteratorTraits<_Iterator, |
| 1182 | 1178 |
typename exists<typename _Iterator::container_type>::type> |
| 1183 | 1179 |
{
|
| 1184 | 1180 |
typedef typename _Iterator::container_type::value_type Value; |
| 1185 | 1181 |
}; |
| 1186 | 1182 |
|
| 1187 | 1183 |
} |
| 1188 | 1184 |
|
| 1189 | 1185 |
|
| 1190 |
/// \brief Writable bool map for |
|
| 1186 |
/// \brief Writable bool map for logging each true assigned elements |
|
| 1191 | 1187 |
/// |
| 1192 |
/// Writable bool map |
|
| 1188 |
/// Writable bool map for logging each true assigned elements, i.e it |
|
| 1193 | 1189 |
/// copies all the keys set to true to the given iterator. |
| 1194 | 1190 |
/// |
| 1195 | 1191 |
/// \note The container of the iterator should contain space |
| 1196 | 1192 |
/// for each element. |
| 1197 | 1193 |
/// |
| 1198 |
/// The |
|
| 1194 |
/// The following example shows how you can write the edges found by the Prim |
|
| 1195 |
/// algorithm directly |
|
| 1199 | 1196 |
/// to the standard output. |
| 1200 | 1197 |
///\code |
| 1201 | 1198 |
/// typedef IdMap<Graph, Edge> EdgeIdMap; |
| 1202 | 1199 |
/// EdgeIdMap edgeId(graph); |
| 1203 | 1200 |
/// |
| 1204 | 1201 |
/// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor; |
| 1205 | 1202 |
/// EdgeIdFunctor edgeIdFunctor(edgeId); |
| 1206 | 1203 |
/// |
| 1207 | 1204 |
/// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> |
| 1208 | 1205 |
/// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
| 1209 | 1206 |
/// |
| 1210 | 1207 |
/// prim(graph, cost, writerMap); |
| 1211 | 1208 |
///\endcode |
| 1209 |
/// |
|
| 1210 |
///\todo Revise the name of this class and the relates ones. |
|
| 1212 | 1211 |
template <typename _Iterator, |
| 1213 | 1212 |
typename _Functor = |
| 1214 | 1213 |
_maps_bits::Identity<typename _maps_bits:: |
| 1215 | 1214 |
IteratorTraits<_Iterator>::Value> > |
| 1216 | 1215 |
class StoreBoolMap {
|
| 1217 | 1216 |
public: |
| 1218 | 1217 |
typedef _Iterator Iterator; |
| 1219 | 1218 |
|
| 1220 | 1219 |
typedef typename _Functor::argument_type Key; |
| 1221 | 1220 |
typedef bool Value; |
| 1222 | 1221 |
|
| 1223 | 1222 |
typedef _Functor Functor; |
| 1224 | 1223 |
|
| 1225 | 1224 |
/// Constructor |
| 1226 | 1225 |
StoreBoolMap(Iterator it, const Functor& functor = Functor()) |
| 1227 | 1226 |
: _begin(it), _end(it), _functor(functor) {}
|
| 1228 | 1227 |
|
| 1229 |
/// Gives back the given iterator set for the first |
|
| 1228 |
/// Gives back the given iterator set for the first key |
|
| 1230 | 1229 |
Iterator begin() const {
|
| 1231 | 1230 |
return _begin; |
| 1232 | 1231 |
} |
| 1233 | 1232 |
|
| 1234 |
/// Gives back the |
|
| 1233 |
/// Gives back the the 'after the last' iterator |
|
| 1235 | 1234 |
Iterator end() const {
|
| 1236 | 1235 |
return _end; |
| 1237 | 1236 |
} |
| 1238 | 1237 |
|
| 1239 | 1238 |
/// Setter function of the map |
| 1240 | 1239 |
void set(const Key& key, Value value) const {
|
| 1241 | 1240 |
if (value) {
|
| 1242 | 1241 |
*_end++ = _functor(key); |
| 1243 | 1242 |
} |
| 1244 | 1243 |
} |
| 1245 | 1244 |
|
| 1246 | 1245 |
private: |
| 1247 | 1246 |
Iterator _begin; |
| 1248 | 1247 |
mutable Iterator _end; |
| 1249 | 1248 |
Functor _functor; |
| 1250 | 1249 |
}; |
| 1251 | 1250 |
|
| 1252 |
/// \brief Writable bool map for store each true assigned elements in |
|
| 1253 |
/// a back insertable container. |
|
| 1251 |
/// \brief Writable bool map for logging each true assigned elements in |
|
| 1252 |
/// a back insertable container |
|
| 1254 | 1253 |
/// |
| 1255 |
/// Writable bool map for store each true assigned elements in a back |
|
| 1256 |
/// insertable container. It will push back all the keys set to true into |
|
| 1257 |
/// the container. It can be used to retrieve the items into a standard |
|
| 1258 |
/// container. The next example shows how can you store the undirected |
|
| 1259 |
/// |
|
| 1254 |
/// Writable bool map for logging each true assigned elements by pushing |
|
| 1255 |
/// back them into a back insertable container. |
|
| 1256 |
/// It can be used to retrieve the items into a standard |
|
| 1257 |
/// container. The next example shows how you can store the |
|
| 1258 |
/// edges found by the Prim algorithm in a vector. |
|
| 1260 | 1259 |
/// |
| 1261 | 1260 |
///\code |
| 1262 | 1261 |
/// vector<Edge> span_tree_edges; |
| 1263 | 1262 |
/// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges); |
| 1264 | 1263 |
/// prim(graph, cost, inserter_map); |
| 1265 | 1264 |
///\endcode |
| 1266 | 1265 |
template <typename Container, |
| 1267 | 1266 |
typename Functor = |
| 1268 | 1267 |
_maps_bits::Identity<typename Container::value_type> > |
| 1269 | 1268 |
class BackInserterBoolMap {
|
| 1270 | 1269 |
public: |
| 1271 | 1270 |
typedef typename Container::value_type Key; |
| ... | ... |
@@ -1279,28 +1278,28 @@ |
| 1279 | 1278 |
/// Setter function of the map |
| 1280 | 1279 |
void set(const Key& key, Value value) {
|
| 1281 | 1280 |
if (value) {
|
| 1282 | 1281 |
container.push_back(functor(key)); |
| 1283 | 1282 |
} |
| 1284 | 1283 |
} |
| 1285 | 1284 |
|
| 1286 | 1285 |
private: |
| 1287 | 1286 |
Container& container; |
| 1288 | 1287 |
Functor functor; |
| 1289 | 1288 |
}; |
| 1290 | 1289 |
|
| 1291 |
/// \brief Writable bool map for |
|
| 1290 |
/// \brief Writable bool map for storing each true assignments in |
|
| 1292 | 1291 |
/// a front insertable container. |
| 1293 | 1292 |
/// |
| 1294 |
/// Writable bool map for |
|
| 1293 |
/// Writable bool map for storing each true assignment in a front |
|
| 1295 | 1294 |
/// insertable container. It will push front all the keys set to \c true into |
| 1296 | 1295 |
/// the container. For example see the BackInserterBoolMap. |
| 1297 | 1296 |
template <typename Container, |
| 1298 | 1297 |
typename Functor = |
| 1299 | 1298 |
_maps_bits::Identity<typename Container::value_type> > |
| 1300 | 1299 |
class FrontInserterBoolMap {
|
| 1301 | 1300 |
public: |
| 1302 | 1301 |
typedef typename Container::value_type Key; |
| 1303 | 1302 |
typedef bool Value; |
| 1304 | 1303 |
|
| 1305 | 1304 |
/// Constructor |
| 1306 | 1305 |
FrontInserterBoolMap(Container& _container, |
| ... | ... |
@@ -1310,30 +1309,32 @@ |
| 1310 | 1309 |
/// Setter function of the map |
| 1311 | 1310 |
void set(const Key& key, Value value) {
|
| 1312 | 1311 |
if (value) {
|
| 1313 | 1312 |
container.push_front(key); |
| 1314 | 1313 |
} |
| 1315 | 1314 |
} |
| 1316 | 1315 |
|
| 1317 | 1316 |
private: |
| 1318 | 1317 |
Container& container; |
| 1319 | 1318 |
Functor functor; |
| 1320 | 1319 |
}; |
| 1321 | 1320 |
|
| 1322 |
/// \brief Writable bool map for |
|
| 1321 |
/// \brief Writable bool map for storing each true assigned elements in |
|
| 1323 | 1322 |
/// an insertable container. |
| 1324 | 1323 |
/// |
| 1325 |
/// Writable bool map for |
|
| 1324 |
/// Writable bool map for storing each true assigned elements in an |
|
| 1326 | 1325 |
/// insertable container. It will insert all the keys set to \c true into |
| 1327 |
/// the container. |
|
| 1326 |
/// the container. |
|
| 1327 |
/// |
|
| 1328 |
/// For example, if you want to store the cut arcs of the strongly |
|
| 1328 | 1329 |
/// connected components in a set you can use the next code: |
| 1329 | 1330 |
/// |
| 1330 | 1331 |
///\code |
| 1331 | 1332 |
/// set<Arc> cut_arcs; |
| 1332 | 1333 |
/// InserterBoolMap<set<Arc> > inserter_map(cut_arcs); |
| 1333 | 1334 |
/// stronglyConnectedCutArcs(digraph, cost, inserter_map); |
| 1334 | 1335 |
///\endcode |
| 1335 | 1336 |
template <typename Container, |
| 1336 | 1337 |
typename Functor = |
| 1337 | 1338 |
_maps_bits::Identity<typename Container::value_type> > |
| 1338 | 1339 |
class InserterBoolMap {
|
| 1339 | 1340 |
public: |
| ... | ... |
@@ -1360,25 +1361,25 @@ |
| 1360 | 1361 |
private: |
| 1361 | 1362 |
Container& container; |
| 1362 | 1363 |
typename Container::iterator it; |
| 1363 | 1364 |
Functor functor; |
| 1364 | 1365 |
}; |
| 1365 | 1366 |
|
| 1366 | 1367 |
/// \brief Fill the true set elements with a given value. |
| 1367 | 1368 |
/// |
| 1368 | 1369 |
/// Writable bool map to fill the elements set to \c true with a given value. |
| 1369 | 1370 |
/// The value can set |
| 1370 | 1371 |
/// the container. |
| 1371 | 1372 |
/// |
| 1372 |
/// The |
|
| 1373 |
/// The following code finds the connected components of a graph |
|
| 1373 | 1374 |
/// and stores it in the \c comp map: |
| 1374 | 1375 |
///\code |
| 1375 | 1376 |
/// typedef Graph::NodeMap<int> ComponentMap; |
| 1376 | 1377 |
/// ComponentMap comp(graph); |
| 1377 | 1378 |
/// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap; |
| 1378 | 1379 |
/// ComponentFillerMap filler(comp, 0); |
| 1379 | 1380 |
/// |
| 1380 | 1381 |
/// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph); |
| 1381 | 1382 |
/// dfs.processedMap(filler); |
| 1382 | 1383 |
/// dfs.init(); |
| 1383 | 1384 |
/// for (NodeIt it(graph); it != INVALID; ++it) {
|
| 1384 | 1385 |
/// if (!dfs.reached(it)) {
|
| ... | ... |
@@ -1408,63 +1409,64 @@ |
| 1408 | 1409 |
} |
| 1409 | 1410 |
|
| 1410 | 1411 |
/// Gives back the current fill value |
| 1411 | 1412 |
typename Map::Value& fillValue() {
|
| 1412 | 1413 |
return fill; |
| 1413 | 1414 |
} |
| 1414 | 1415 |
|
| 1415 | 1416 |
/// Sets the current fill value |
| 1416 | 1417 |
void fillValue(const typename Map::Value& _fill) {
|
| 1417 | 1418 |
fill = _fill; |
| 1418 | 1419 |
} |
| 1419 | 1420 |
|
| 1420 |
/// |
|
| 1421 |
/// Set function of the map |
|
| 1421 | 1422 |
void set(const Key& key, Value value) {
|
| 1422 | 1423 |
if (value) {
|
| 1423 | 1424 |
map.set(key, fill); |
| 1424 | 1425 |
} |
| 1425 | 1426 |
} |
| 1426 | 1427 |
|
| 1427 | 1428 |
private: |
| 1428 | 1429 |
Map& map; |
| 1429 | 1430 |
typename Map::Value fill; |
| 1430 | 1431 |
}; |
| 1431 | 1432 |
|
| 1432 | 1433 |
|
| 1433 |
/// \brief Writable bool map which stores for each true assigned elements |
|
| 1434 |
/// the setting order number. |
|
| 1435 |
/// |
|
| 1434 |
/// \brief Writable bool map which stores the sequence number of |
|
| 1435 |
/// true assignments. |
|
| 1436 |
/// |
|
| 1436 | 1437 |
/// Writable bool map which stores for each true assigned elements |
| 1437 |
/// the |
|
| 1438 |
/// the sequence number of this setting. |
|
| 1439 |
/// It makes it easy to calculate the leaving |
|
| 1438 | 1440 |
/// order of the nodes in the \c Dfs algorithm. |
| 1439 | 1441 |
/// |
| 1440 | 1442 |
///\code |
| 1441 | 1443 |
/// typedef Digraph::NodeMap<int> OrderMap; |
| 1442 | 1444 |
/// OrderMap order(digraph); |
| 1443 | 1445 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
| 1444 | 1446 |
/// OrderSetterMap setter(order); |
| 1445 | 1447 |
/// Dfs<Digraph>::DefProcessedMap<OrderSetterMap>::Create dfs(digraph); |
| 1446 | 1448 |
/// dfs.processedMap(setter); |
| 1447 | 1449 |
/// dfs.init(); |
| 1448 | 1450 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
| 1449 | 1451 |
/// if (!dfs.reached(it)) {
|
| 1450 | 1452 |
/// dfs.addSource(it); |
| 1451 | 1453 |
/// dfs.start(); |
| 1452 | 1454 |
/// } |
| 1453 | 1455 |
/// } |
| 1454 | 1456 |
///\endcode |
| 1455 | 1457 |
/// |
| 1456 |
/// The discovering order |
|
| 1458 |
/// The storing of the discovering order is more difficult because the |
|
| 1457 | 1459 |
/// ReachedMap should be readable in the dfs algorithm but the setting |
| 1458 |
/// order map is not readable. |
|
| 1460 |
/// order map is not readable. Thus we must use the fork map: |
|
| 1459 | 1461 |
/// |
| 1460 | 1462 |
///\code |
| 1461 | 1463 |
/// typedef Digraph::NodeMap<int> OrderMap; |
| 1462 | 1464 |
/// OrderMap order(digraph); |
| 1463 | 1465 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
| 1464 | 1466 |
/// OrderSetterMap setter(order); |
| 1465 | 1467 |
/// typedef Digraph::NodeMap<bool> StoreMap; |
| 1466 | 1468 |
/// StoreMap store(digraph); |
| 1467 | 1469 |
/// |
| 1468 | 1470 |
/// typedef ForkWriteMap<StoreMap, OrderSetterMap> ReachedMap; |
| 1469 | 1471 |
/// ReachedMap reached(store, setter); |
| 1470 | 1472 |
/// |
0 comments (0 inline)