0
14
0
8
12
8
10
4
4
| ... | ... |
@@ -16,49 +16,49 @@ |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BFS_H |
| 20 | 20 |
#define LEMON_BFS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup search |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Bfs algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/graph_utils.h> |
| 28 | 28 |
#include <lemon/bits/path_dump.h> |
| 29 | 29 |
#include <lemon/bits/invalid.h> |
| 30 | 30 |
#include <lemon/error.h> |
| 31 | 31 |
#include <lemon/maps.h> |
| 32 | 32 |
|
| 33 | 33 |
namespace lemon {
|
| 34 | 34 |
|
| 35 | 35 |
|
| 36 | 36 |
|
| 37 | 37 |
///Default traits class of Bfs class. |
| 38 | 38 |
|
| 39 | 39 |
///Default traits class of Bfs class. |
| 40 |
///\ |
|
| 40 |
///\tparam GR Digraph type. |
|
| 41 | 41 |
template<class GR> |
| 42 | 42 |
struct BfsDefaultTraits |
| 43 | 43 |
{
|
| 44 | 44 |
///The digraph type the algorithm runs on. |
| 45 | 45 |
typedef GR Digraph; |
| 46 | 46 |
///\brief The type of the map that stores the last |
| 47 | 47 |
///arcs of the shortest paths. |
| 48 | 48 |
/// |
| 49 | 49 |
///The type of the map that stores the last |
| 50 | 50 |
///arcs of the shortest paths. |
| 51 | 51 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 52 | 52 |
/// |
| 53 | 53 |
typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; |
| 54 | 54 |
///Instantiates a PredMap. |
| 55 | 55 |
|
| 56 | 56 |
///This function instantiates a \ref PredMap. |
| 57 | 57 |
///\param G is the digraph, to which we would like to define the PredMap. |
| 58 | 58 |
///\todo The digraph alone may be insufficient to initialize |
| 59 | 59 |
static PredMap *createPredMap(const GR &G) |
| 60 | 60 |
{
|
| 61 | 61 |
return new PredMap(G); |
| 62 | 62 |
} |
| 63 | 63 |
///The type of the map that indicates which nodes are processed. |
| 64 | 64 |
|
| ... | ... |
@@ -94,58 +94,56 @@ |
| 94 | 94 |
{
|
| 95 | 95 |
return new ReachedMap(G); |
| 96 | 96 |
} |
| 97 | 97 |
///The type of the map that stores the dists of the nodes. |
| 98 | 98 |
|
| 99 | 99 |
///The type of the map that stores the dists of the nodes. |
| 100 | 100 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 101 | 101 |
/// |
| 102 | 102 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 103 | 103 |
///Instantiates a DistMap. |
| 104 | 104 |
|
| 105 | 105 |
///This function instantiates a \ref DistMap. |
| 106 | 106 |
///\param G is the digraph, to which we would like to define the \ref DistMap |
| 107 | 107 |
static DistMap *createDistMap(const GR &G) |
| 108 | 108 |
{
|
| 109 | 109 |
return new DistMap(G); |
| 110 | 110 |
} |
| 111 | 111 |
}; |
| 112 | 112 |
|
| 113 | 113 |
///%BFS algorithm class. |
| 114 | 114 |
|
| 115 | 115 |
///\ingroup search |
| 116 | 116 |
///This class provides an efficient implementation of the %BFS algorithm. |
| 117 | 117 |
/// |
| 118 |
///\ |
|
| 118 |
///\tparam GR The digraph type the algorithm runs on. The default value is |
|
| 119 | 119 |
///\ref ListDigraph. The value of GR is not used directly by Bfs, it |
| 120 | 120 |
///is only passed to \ref BfsDefaultTraits. |
| 121 |
///\ |
|
| 121 |
///\tparam TR Traits class to set various data types used by the algorithm. |
|
| 122 | 122 |
///The default traits class is |
| 123 | 123 |
///\ref BfsDefaultTraits "BfsDefaultTraits<GR>". |
| 124 | 124 |
///See \ref BfsDefaultTraits for the documentation of |
| 125 | 125 |
///a Bfs traits class. |
| 126 |
/// |
|
| 127 |
///\author Alpar Juttner |
|
| 128 | 126 |
|
| 129 | 127 |
#ifdef DOXYGEN |
| 130 | 128 |
template <typename GR, |
| 131 | 129 |
typename TR> |
| 132 | 130 |
#else |
| 133 | 131 |
template <typename GR=ListDigraph, |
| 134 | 132 |
typename TR=BfsDefaultTraits<GR> > |
| 135 | 133 |
#endif |
| 136 | 134 |
class Bfs {
|
| 137 | 135 |
public: |
| 138 | 136 |
/** |
| 139 | 137 |
* \brief \ref Exception for uninitialized parameters. |
| 140 | 138 |
* |
| 141 | 139 |
* This error represents problems in the initialization |
| 142 | 140 |
* of the parameters of the algorithms. |
| 143 | 141 |
*/ |
| 144 | 142 |
class UninitializedParameter : public lemon::UninitializedParameter {
|
| 145 | 143 |
public: |
| 146 | 144 |
virtual const char* what() const throw() {
|
| 147 | 145 |
return "lemon::Bfs::UninitializedParameter"; |
| 148 | 146 |
} |
| 149 | 147 |
}; |
| 150 | 148 |
|
| 151 | 149 |
typedef TR Traits; |
| ... | ... |
@@ -735,49 +733,49 @@ |
| 735 | 733 |
|
| 736 | 734 |
///Returns a reference to the shortest path tree map. |
| 737 | 735 |
|
| 738 | 736 |
///Returns a reference to the NodeMap of the arcs of the |
| 739 | 737 |
///shortest path tree. |
| 740 | 738 |
///\pre Either \ref run() or \ref init() |
| 741 | 739 |
///must be called before using this function. |
| 742 | 740 |
const PredMap &predMap() const { return *_pred;}
|
| 743 | 741 |
|
| 744 | 742 |
///Checks if a node is reachable from the root. |
| 745 | 743 |
|
| 746 | 744 |
///Returns \c true if \c v is reachable from the root. |
| 747 | 745 |
///\warning The source nodes are indicated as unreached. |
| 748 | 746 |
///\pre Either \ref run() or \ref start() |
| 749 | 747 |
///must be called before using this function. |
| 750 | 748 |
/// |
| 751 | 749 |
bool reached(Node v) { return (*_reached)[v]; }
|
| 752 | 750 |
|
| 753 | 751 |
///@} |
| 754 | 752 |
}; |
| 755 | 753 |
|
| 756 | 754 |
///Default traits class of Bfs function. |
| 757 | 755 |
|
| 758 | 756 |
///Default traits class of Bfs function. |
| 759 |
///\ |
|
| 757 |
///\tparam GR Digraph type. |
|
| 760 | 758 |
template<class GR> |
| 761 | 759 |
struct BfsWizardDefaultTraits |
| 762 | 760 |
{
|
| 763 | 761 |
///The digraph type the algorithm runs on. |
| 764 | 762 |
typedef GR Digraph; |
| 765 | 763 |
///\brief The type of the map that stores the last |
| 766 | 764 |
///arcs of the shortest paths. |
| 767 | 765 |
/// |
| 768 | 766 |
///The type of the map that stores the last |
| 769 | 767 |
///arcs of the shortest paths. |
| 770 | 768 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 771 | 769 |
/// |
| 772 | 770 |
typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap; |
| 773 | 771 |
///Instantiates a PredMap. |
| 774 | 772 |
|
| 775 | 773 |
///This function instantiates a \ref PredMap. |
| 776 | 774 |
///\param g is the digraph, to which we would like to define the PredMap. |
| 777 | 775 |
///\todo The digraph alone may be insufficient to initialize |
| 778 | 776 |
#ifdef DOXYGEN |
| 779 | 777 |
static PredMap *createPredMap(const GR &g) |
| 780 | 778 |
#else |
| 781 | 779 |
static PredMap *createPredMap(const GR &) |
| 782 | 780 |
#endif |
| 783 | 781 |
{
|
| ... | ... |
@@ -1144,98 +1142,96 @@ |
| 1144 | 1142 |
void reach(const Node&) {}
|
| 1145 | 1143 |
void examine(const Arc&) {}
|
| 1146 | 1144 |
void start(const Node&) {}
|
| 1147 | 1145 |
void process(const Node&) {}
|
| 1148 | 1146 |
|
| 1149 | 1147 |
template <typename _Visitor> |
| 1150 | 1148 |
struct Constraints {
|
| 1151 | 1149 |
void constraints() {
|
| 1152 | 1150 |
Arc arc; |
| 1153 | 1151 |
Node node; |
| 1154 | 1152 |
visitor.discover(arc); |
| 1155 | 1153 |
visitor.reach(node); |
| 1156 | 1154 |
visitor.examine(arc); |
| 1157 | 1155 |
visitor.start(node); |
| 1158 | 1156 |
visitor.process(node); |
| 1159 | 1157 |
} |
| 1160 | 1158 |
_Visitor& visitor; |
| 1161 | 1159 |
}; |
| 1162 | 1160 |
}; |
| 1163 | 1161 |
#endif |
| 1164 | 1162 |
|
| 1165 | 1163 |
/// \brief Default traits class of BfsVisit class. |
| 1166 | 1164 |
/// |
| 1167 | 1165 |
/// Default traits class of BfsVisit class. |
| 1168 |
/// \ |
|
| 1166 |
/// \tparam _Digraph Digraph type. |
|
| 1169 | 1167 |
template<class _Digraph> |
| 1170 | 1168 |
struct BfsVisitDefaultTraits {
|
| 1171 | 1169 |
|
| 1172 | 1170 |
/// \brief The digraph type the algorithm runs on. |
| 1173 | 1171 |
typedef _Digraph Digraph; |
| 1174 | 1172 |
|
| 1175 | 1173 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1176 | 1174 |
/// |
| 1177 | 1175 |
/// The type of the map that indicates which nodes are reached. |
| 1178 | 1176 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 1179 | 1177 |
/// \todo named parameter to set this type, function to read and write. |
| 1180 | 1178 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1181 | 1179 |
|
| 1182 | 1180 |
/// \brief Instantiates a ReachedMap. |
| 1183 | 1181 |
/// |
| 1184 | 1182 |
/// This function instantiates a \ref ReachedMap. |
| 1185 | 1183 |
/// \param digraph is the digraph, to which |
| 1186 | 1184 |
/// we would like to define the \ref ReachedMap. |
| 1187 | 1185 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1188 | 1186 |
return new ReachedMap(digraph); |
| 1189 | 1187 |
} |
| 1190 | 1188 |
|
| 1191 | 1189 |
}; |
| 1192 | 1190 |
|
| 1193 | 1191 |
/// \ingroup search |
| 1194 | 1192 |
/// |
| 1195 | 1193 |
/// \brief %BFS Visit algorithm class. |
| 1196 | 1194 |
/// |
| 1197 | 1195 |
/// This class provides an efficient implementation of the %BFS algorithm |
| 1198 | 1196 |
/// with visitor interface. |
| 1199 | 1197 |
/// |
| 1200 | 1198 |
/// The %BfsVisit class provides an alternative interface to the Bfs |
| 1201 | 1199 |
/// class. It works with callback mechanism, the BfsVisit object calls |
| 1202 | 1200 |
/// on every bfs event the \c Visitor class member functions. |
| 1203 | 1201 |
/// |
| 1204 |
/// \ |
|
| 1202 |
/// \tparam _Digraph The digraph type the algorithm runs on. The default value is |
|
| 1205 | 1203 |
/// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it |
| 1206 | 1204 |
/// is only passed to \ref BfsDefaultTraits. |
| 1207 |
/// \ |
|
| 1205 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
|
| 1208 | 1206 |
/// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which |
| 1209 | 1207 |
/// does not observe the Bfs events. If you want to observe the bfs |
| 1210 | 1208 |
/// events you should implement your own Visitor class. |
| 1211 |
/// \ |
|
| 1209 |
/// \tparam _Traits Traits class to set various data types used by the |
|
| 1212 | 1210 |
/// algorithm. The default traits class is |
| 1213 | 1211 |
/// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". |
| 1214 | 1212 |
/// See \ref BfsVisitDefaultTraits for the documentation of |
| 1215 | 1213 |
/// a Bfs visit traits class. |
| 1216 |
/// |
|
| 1217 |
/// \author Jacint Szabo, Alpar Juttner and Balazs Dezso |
|
| 1218 | 1214 |
#ifdef DOXYGEN |
| 1219 | 1215 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
| 1220 | 1216 |
#else |
| 1221 | 1217 |
template <typename _Digraph = ListDigraph, |
| 1222 | 1218 |
typename _Visitor = BfsVisitor<_Digraph>, |
| 1223 | 1219 |
typename _Traits = BfsDefaultTraits<_Digraph> > |
| 1224 | 1220 |
#endif |
| 1225 | 1221 |
class BfsVisit {
|
| 1226 | 1222 |
public: |
| 1227 | 1223 |
|
| 1228 | 1224 |
/// \brief \ref Exception for uninitialized parameters. |
| 1229 | 1225 |
/// |
| 1230 | 1226 |
/// This error represents problems in the initialization |
| 1231 | 1227 |
/// of the parameters of the algorithms. |
| 1232 | 1228 |
class UninitializedParameter : public lemon::UninitializedParameter {
|
| 1233 | 1229 |
public: |
| 1234 | 1230 |
virtual const char* what() const throw() |
| 1235 | 1231 |
{
|
| 1236 | 1232 |
return "lemon::BfsVisit::UninitializedParameter"; |
| 1237 | 1233 |
} |
| 1238 | 1234 |
}; |
| 1239 | 1235 |
|
| 1240 | 1236 |
typedef _Traits Traits; |
| 1241 | 1237 |
| ... | ... |
@@ -18,52 +18,52 @@ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BIN_HEAP_H |
| 20 | 20 |
#define LEMON_BIN_HEAP_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup auxdat |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Binary Heap implementation. |
| 25 | 25 |
|
| 26 | 26 |
#include <vector> |
| 27 | 27 |
#include <utility> |
| 28 | 28 |
#include <functional> |
| 29 | 29 |
|
| 30 | 30 |
namespace lemon {
|
| 31 | 31 |
|
| 32 | 32 |
///\ingroup auxdat |
| 33 | 33 |
/// |
| 34 | 34 |
///\brief A Binary Heap implementation. |
| 35 | 35 |
/// |
| 36 | 36 |
///This class implements the \e binary \e heap data structure. A \e heap |
| 37 | 37 |
///is a data structure for storing items with specified values called \e |
| 38 | 38 |
///priorities in such a way that finding the item with minimum priority is |
| 39 | 39 |
///efficient. \c Compare specifies the ordering of the priorities. In a heap |
| 40 | 40 |
///one can change the priority of an item, add or erase an item, etc. |
| 41 | 41 |
/// |
| 42 |
///\param _Prio Type of the priority of the items. |
|
| 43 |
///\param _ItemIntMap A read and writable Item int map, used internally |
|
| 42 |
///\tparam _Prio Type of the priority of the items. |
|
| 43 |
///\tparam _ItemIntMap A read and writable Item int map, used internally |
|
| 44 | 44 |
///to handle the cross references. |
| 45 |
///\ |
|
| 45 |
///\tparam _Compare A class for the ordering of the priorities. The |
|
| 46 | 46 |
///default is \c std::less<_Prio>. |
| 47 | 47 |
/// |
| 48 | 48 |
///\sa FibHeap |
| 49 | 49 |
///\sa Dijkstra |
| 50 | 50 |
template <typename _Prio, typename _ItemIntMap, |
| 51 | 51 |
typename _Compare = std::less<_Prio> > |
| 52 | 52 |
class BinHeap {
|
| 53 | 53 |
|
| 54 | 54 |
public: |
| 55 | 55 |
///\e |
| 56 | 56 |
typedef _ItemIntMap ItemIntMap; |
| 57 | 57 |
///\e |
| 58 | 58 |
typedef _Prio Prio; |
| 59 | 59 |
///\e |
| 60 | 60 |
typedef typename ItemIntMap::Key Item; |
| 61 | 61 |
///\e |
| 62 | 62 |
typedef std::pair<Item,Prio> Pair; |
| 63 | 63 |
///\e |
| 64 | 64 |
typedef _Compare Compare; |
| 65 | 65 |
|
| 66 | 66 |
/// \brief Type to represent the items states. |
| 67 | 67 |
/// |
| 68 | 68 |
/// Each Item element have a state associated to it. It may be "in heap", |
| 69 | 69 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
| ... | ... |
@@ -73,86 +73,82 @@ |
| 73 | 73 |
/// alteration handlers should not call any function which signals |
| 74 | 74 |
/// an other alteration in the same notifier and should not |
| 75 | 75 |
/// detach any observer from the notifier. |
| 76 | 76 |
/// |
| 77 | 77 |
/// Alteration observers try to be exception safe. If an \e add() or |
| 78 | 78 |
/// a \e clear() function throws an exception then the remaining |
| 79 | 79 |
/// observeres will not be notified and the fulfilled additions will |
| 80 | 80 |
/// be rolled back by calling the \e erase() or \e clear() |
| 81 | 81 |
/// functions. Thence the \e erase() and \e clear() should not throw |
| 82 | 82 |
/// exception. Actullay, it can be throw only |
| 83 | 83 |
/// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
| 84 | 84 |
/// exception which detach the observer from the notifier. |
| 85 | 85 |
/// |
| 86 | 86 |
/// There are some place when the alteration observing is not completly |
| 87 | 87 |
/// reliable. If we want to carry out the node degree in the graph |
| 88 | 88 |
/// as in the \ref InDegMap and we use the reverseEdge that cause |
| 89 | 89 |
/// unreliable functionality. Because the alteration observing signals |
| 90 | 90 |
/// only erasing and adding but not the reversing it will stores bad |
| 91 | 91 |
/// degrees. The sub graph adaptors cannot signal the alterations because |
| 92 | 92 |
/// just a setting in the filter map can modify the graph and this cannot |
| 93 | 93 |
/// be watched in any way. |
| 94 | 94 |
/// |
| 95 | 95 |
/// \param _Container The container which is observed. |
| 96 | 96 |
/// \param _Item The item type which is obserbved. |
| 97 |
/// |
|
| 98 |
/// \author Balazs Dezso |
|
| 99 | 97 |
|
| 100 | 98 |
template <typename _Container, typename _Item> |
| 101 | 99 |
class AlterationNotifier {
|
| 102 | 100 |
public: |
| 103 | 101 |
|
| 104 | 102 |
typedef True Notifier; |
| 105 | 103 |
|
| 106 | 104 |
typedef _Container Container; |
| 107 | 105 |
typedef _Item Item; |
| 108 | 106 |
|
| 109 | 107 |
/// \brief Exception which can be called from \e clear() and |
| 110 | 108 |
/// \e erase(). |
| 111 | 109 |
/// |
| 112 | 110 |
/// From the \e clear() and \e erase() function only this |
| 113 | 111 |
/// exception is allowed to throw. The exception immediatly |
| 114 | 112 |
/// detaches the current observer from the notifier. Because the |
| 115 | 113 |
/// \e clear() and \e erase() should not throw other exceptions |
| 116 | 114 |
/// it can be used to invalidate the observer. |
| 117 | 115 |
struct ImmediateDetach {};
|
| 118 | 116 |
|
| 119 | 117 |
/// \brief ObserverBase is the base class for the observers. |
| 120 | 118 |
/// |
| 121 | 119 |
/// ObserverBase is the abstract base class for the observers. |
| 122 | 120 |
/// It will be notified about an item was inserted into or |
| 123 | 121 |
/// erased from the graph. |
| 124 | 122 |
/// |
| 125 | 123 |
/// The observer interface contains some pure virtual functions |
| 126 | 124 |
/// to override. The add() and erase() functions are |
| 127 | 125 |
/// to notify the oberver when one item is added or |
| 128 | 126 |
/// erased. |
| 129 | 127 |
/// |
| 130 | 128 |
/// The build() and clear() members are to notify the observer |
| 131 | 129 |
/// about the container is built from an empty container or |
| 132 | 130 |
/// is cleared to an empty container. |
| 133 |
/// |
|
| 134 |
/// \author Balazs Dezso |
|
| 135 | 131 |
|
| 136 | 132 |
class ObserverBase {
|
| 137 | 133 |
protected: |
| 138 | 134 |
typedef AlterationNotifier Notifier; |
| 139 | 135 |
|
| 140 | 136 |
friend class AlterationNotifier; |
| 141 | 137 |
|
| 142 | 138 |
/// \brief Default constructor. |
| 143 | 139 |
/// |
| 144 | 140 |
/// Default constructor for ObserverBase. |
| 145 | 141 |
/// |
| 146 | 142 |
ObserverBase() : _notifier(0) {}
|
| 147 | 143 |
|
| 148 | 144 |
/// \brief Constructor which attach the observer into notifier. |
| 149 | 145 |
/// |
| 150 | 146 |
/// Constructor which attach the observer into notifier. |
| 151 | 147 |
ObserverBase(AlterationNotifier& nf) {
|
| 152 | 148 |
attach(nf); |
| 153 | 149 |
} |
| 154 | 150 |
|
| 155 | 151 |
/// \brief Constructor which attach the obserever to the same notifier. |
| 156 | 152 |
/// |
| 157 | 153 |
/// Constructor which attach the obserever to the same notifier as |
| 158 | 154 |
/// the other observer is attached to. |
| ... | ... |
@@ -3,50 +3,48 @@ |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 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 | 19 |
#ifndef LEMON_BEZIER_H |
| 20 | 20 |
#define LEMON_BEZIER_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup misc |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Classes to compute with Bezier curves. |
| 25 | 25 |
/// |
| 26 | 26 |
///Up to now this file is used internally by \ref graph_to_eps.h |
| 27 |
/// |
|
| 28 |
///\author Alpar Juttner |
|
| 29 | 27 |
|
| 30 | 28 |
#include<lemon/dim2.h> |
| 31 | 29 |
|
| 32 | 30 |
namespace lemon {
|
| 33 | 31 |
namespace dim2 {
|
| 34 | 32 |
|
| 35 | 33 |
class BezierBase {
|
| 36 | 34 |
public: |
| 37 | 35 |
typedef Point<double> Point; |
| 38 | 36 |
protected: |
| 39 | 37 |
static Point conv(Point x,Point y,double t) {return (1-t)*x+t*y;}
|
| 40 | 38 |
}; |
| 41 | 39 |
|
| 42 | 40 |
class Bezier1 : public BezierBase |
| 43 | 41 |
{
|
| 44 | 42 |
public: |
| 45 | 43 |
Point p1,p2; |
| 46 | 44 |
|
| 47 | 45 |
Bezier1() {}
|
| 48 | 46 |
Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {}
|
| 49 | 47 |
|
| 50 | 48 |
Point operator()(double t) const |
| 51 | 49 |
{
|
| 52 | 50 |
// return conv(conv(p1,p2,t),conv(p2,p3,t),t); |
| ... | ... |
@@ -23,53 +23,52 @@ |
| 23 | 23 |
#include <algorithm> |
| 24 | 24 |
|
| 25 | 25 |
#include <lemon/bits/traits.h> |
| 26 | 26 |
#include <lemon/bits/utility.h> |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/bits/alteration_notifier.h> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/concept_check.h> |
| 31 | 31 |
#include <lemon/concepts/maps.h> |
| 32 | 32 |
|
| 33 | 33 |
///\ingroup graphbits |
| 34 | 34 |
/// |
| 35 | 35 |
///\file |
| 36 | 36 |
///\brief Vector based graph maps. |
| 37 | 37 |
namespace lemon {
|
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup graphbits |
| 40 | 40 |
/// |
| 41 | 41 |
/// \brief Graph map based on the std::vector storage. |
| 42 | 42 |
/// |
| 43 | 43 |
/// The VectorMap template class is graph map structure what |
| 44 | 44 |
/// automatically updates the map when a key is added to or erased from |
| 45 | 45 |
/// the map. This map type uses the std::vector to store the values. |
| 46 | 46 |
/// |
| 47 |
/// \param Notifier The AlterationNotifier that will notify this map. |
|
| 48 |
/// \param Item The item type of the graph items. |
|
| 49 |
/// \param Value The value type of the map. |
|
| 50 |
/// |
|
| 51 |
/// \ |
|
| 47 |
/// \tparam _Notifier The AlterationNotifier that will notify this map. |
|
| 48 |
/// \tparam _Item The item type of the graph items. |
|
| 49 |
/// \tparam _Value The value type of the map. |
|
| 50 |
/// \todo Fix the doc: there is _Graph parameter instead of _Notifier. |
|
| 52 | 51 |
template <typename _Graph, typename _Item, typename _Value> |
| 53 | 52 |
class VectorMap |
| 54 | 53 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
|
| 55 | 54 |
private: |
| 56 | 55 |
|
| 57 | 56 |
/// The container type of the map. |
| 58 | 57 |
typedef std::vector<_Value> Container; |
| 59 | 58 |
|
| 60 | 59 |
public: |
| 61 | 60 |
|
| 62 | 61 |
/// The graph type of the map. |
| 63 | 62 |
typedef _Graph Graph; |
| 64 | 63 |
/// The item type of the map. |
| 65 | 64 |
typedef _Item Item; |
| 66 | 65 |
/// The reference map tag. |
| 67 | 66 |
typedef True ReferenceMapTag; |
| 68 | 67 |
|
| 69 | 68 |
/// The key type of the map. |
| 70 | 69 |
typedef _Item Key; |
| 71 | 70 |
/// The value type of the map. |
| 72 | 71 |
typedef _Value Value; |
| 73 | 72 |
|
| 74 | 73 |
/// The notifier type. |
| 75 | 74 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
| ... | ... |
@@ -6,50 +6,48 @@ |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 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 | 19 |
#ifndef LEMON_COLOR_H |
| 20 | 20 |
#define LEMON_COLOR_H |
| 21 | 21 |
|
| 22 | 22 |
#include<vector> |
| 23 | 23 |
#include<lemon/math.h> |
| 24 | 24 |
#include<lemon/maps.h> |
| 25 | 25 |
|
| 26 | 26 |
|
| 27 | 27 |
///\ingroup misc |
| 28 | 28 |
///\file |
| 29 | 29 |
///\brief Tools to manage RGB colors. |
| 30 |
/// |
|
| 31 |
///\author Alpar Juttner |
|
| 32 | 30 |
|
| 33 | 31 |
namespace lemon {
|
| 34 | 32 |
|
| 35 | 33 |
|
| 36 | 34 |
/// \addtogroup misc |
| 37 | 35 |
/// @{
|
| 38 | 36 |
|
| 39 | 37 |
///Data structure representing RGB colors. |
| 40 | 38 |
|
| 41 | 39 |
///Data structure representing RGB colors. |
| 42 | 40 |
class Color |
| 43 | 41 |
{
|
| 44 | 42 |
double _r,_g,_b; |
| 45 | 43 |
public: |
| 46 | 44 |
///Default constructor |
| 47 | 45 |
Color() {}
|
| 48 | 46 |
///Constructor |
| 49 | 47 |
Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
|
| 50 | 48 |
///Set the red component |
| 51 | 49 |
double & red() {return _r;}
|
| 52 | 50 |
///Return the red component |
| 53 | 51 |
const double & red() const {return _r;}
|
| 54 | 52 |
///Set the green component |
| 55 | 53 |
double & green() {return _g;}
|
| ... | ... |
@@ -19,49 +19,49 @@ |
| 19 | 19 |
///\ingroup concept |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief Classes for representing paths in digraphs. |
| 22 | 22 |
/// |
| 23 | 23 |
///\todo Iterators have obsolete style |
| 24 | 24 |
|
| 25 | 25 |
#ifndef LEMON_CONCEPT_PATH_H |
| 26 | 26 |
#define LEMON_CONCEPT_PATH_H |
| 27 | 27 |
|
| 28 | 28 |
#include <lemon/bits/invalid.h> |
| 29 | 29 |
#include <lemon/bits/utility.h> |
| 30 | 30 |
#include <lemon/concept_check.h> |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
namespace concepts {
|
| 34 | 34 |
|
| 35 | 35 |
/// \addtogroup concept |
| 36 | 36 |
/// @{
|
| 37 | 37 |
|
| 38 | 38 |
/// \brief A skeleton structure for representing directed paths in |
| 39 | 39 |
/// a digraph. |
| 40 | 40 |
/// |
| 41 | 41 |
/// A skeleton structure for representing directed paths in a |
| 42 | 42 |
/// digraph. |
| 43 |
/// \ |
|
| 43 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 44 | 44 |
/// |
| 45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
| 46 | 46 |
/// lemon path type stores just this list. As a consequence it |
| 47 | 47 |
/// cannot enumerate the nodes in the path and the zero length |
| 48 | 48 |
/// paths cannot store the source. |
| 49 | 49 |
/// |
| 50 | 50 |
template <typename _Digraph> |
| 51 | 51 |
class Path {
|
| 52 | 52 |
public: |
| 53 | 53 |
|
| 54 | 54 |
/// Type of the underlying digraph. |
| 55 | 55 |
typedef _Digraph Digraph; |
| 56 | 56 |
/// Arc type of the underlying digraph. |
| 57 | 57 |
typedef typename Digraph::Arc Arc; |
| 58 | 58 |
|
| 59 | 59 |
class ArcIt; |
| 60 | 60 |
|
| 61 | 61 |
/// \brief Default constructor |
| 62 | 62 |
Path() {}
|
| 63 | 63 |
|
| 64 | 64 |
/// \brief Template constructor |
| 65 | 65 |
template <typename CPath> |
| 66 | 66 |
Path(const CPath& cpath) {}
|
| 67 | 67 |
|
| ... | ... |
@@ -184,49 +184,49 @@ |
| 184 | 184 |
} |
| 185 | 185 |
_Path& p; |
| 186 | 186 |
}; |
| 187 | 187 |
|
| 188 | 188 |
} |
| 189 | 189 |
|
| 190 | 190 |
|
| 191 | 191 |
/// \brief A skeleton structure for path dumpers. |
| 192 | 192 |
/// |
| 193 | 193 |
/// A skeleton structure for path dumpers. The path dumpers are |
| 194 | 194 |
/// the generalization of the paths. The path dumpers can |
| 195 | 195 |
/// enumerate the arcs of the path wheter in forward or in |
| 196 | 196 |
/// backward order. In most time these classes are not used |
| 197 | 197 |
/// directly rather it used to assign a dumped class to a real |
| 198 | 198 |
/// path type. |
| 199 | 199 |
/// |
| 200 | 200 |
/// The main purpose of this concept is that the shortest path |
| 201 | 201 |
/// algorithms can enumerate easily the arcs in reverse order. |
| 202 | 202 |
/// If we would like to give back a real path from these |
| 203 | 203 |
/// algorithms then we should create a temporarly path object. In |
| 204 | 204 |
/// Lemon such algorithms gives back a path dumper what can |
| 205 | 205 |
/// assigned to a real path and the dumpers can be implemented as |
| 206 | 206 |
/// an adaptor class to the predecessor map. |
| 207 | 207 |
|
| 208 |
/// \ |
|
| 208 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 209 | 209 |
/// |
| 210 | 210 |
/// The paths can be constructed from any path type by a |
| 211 | 211 |
/// template constructor or a template assignment operator. |
| 212 | 212 |
/// |
| 213 | 213 |
template <typename _Digraph> |
| 214 | 214 |
class PathDumper {
|
| 215 | 215 |
public: |
| 216 | 216 |
|
| 217 | 217 |
/// Type of the underlying digraph. |
| 218 | 218 |
typedef _Digraph Digraph; |
| 219 | 219 |
/// Arc type of the underlying digraph. |
| 220 | 220 |
typedef typename Digraph::Arc Arc; |
| 221 | 221 |
|
| 222 | 222 |
/// Length of the path ie. the number of arcs in the path. |
| 223 | 223 |
int length() const { return 0;}
|
| 224 | 224 |
|
| 225 | 225 |
/// Returns whether the path is empty. |
| 226 | 226 |
bool empty() const { return true;}
|
| 227 | 227 |
|
| 228 | 228 |
/// \brief Forward or reverse dumping |
| 229 | 229 |
/// |
| 230 | 230 |
/// If the RevPathTag is defined and true then reverse dumping |
| 231 | 231 |
/// is provided in the path dumper. In this case instead of the |
| 232 | 232 |
/// ArcIt the RevArcIt iterator should be implemented in the |
| ... | ... |
@@ -17,49 +17,49 @@ |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_DFS_H |
| 20 | 20 |
#define LEMON_DFS_H |
| 21 | 21 |
|
| 22 | 22 |
///\ingroup search |
| 23 | 23 |
///\file |
| 24 | 24 |
///\brief Dfs algorithm. |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/list_graph.h> |
| 27 | 27 |
#include <lemon/graph_utils.h> |
| 28 | 28 |
#include <lemon/bits/path_dump.h> |
| 29 | 29 |
#include <lemon/bits/invalid.h> |
| 30 | 30 |
#include <lemon/error.h> |
| 31 | 31 |
#include <lemon/maps.h> |
| 32 | 32 |
|
| 33 | 33 |
#include <lemon/concept_check.h> |
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
|
| 38 | 38 |
///Default traits class of Dfs class. |
| 39 | 39 |
|
| 40 | 40 |
///Default traits class of Dfs class. |
| 41 |
///\ |
|
| 41 |
///\tparam GR Digraph type. |
|
| 42 | 42 |
template<class GR> |
| 43 | 43 |
struct DfsDefaultTraits |
| 44 | 44 |
{
|
| 45 | 45 |
///The digraph type the algorithm runs on. |
| 46 | 46 |
typedef GR Digraph; |
| 47 | 47 |
///\brief The type of the map that stores the last |
| 48 | 48 |
///arcs of the %DFS paths. |
| 49 | 49 |
/// |
| 50 | 50 |
///The type of the map that stores the last |
| 51 | 51 |
///arcs of the %DFS paths. |
| 52 | 52 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 53 | 53 |
/// |
| 54 | 54 |
typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; |
| 55 | 55 |
///Instantiates a PredMap. |
| 56 | 56 |
|
| 57 | 57 |
///This function instantiates a \ref PredMap. |
| 58 | 58 |
///\param G is the digraph, to which we would like to define the PredMap. |
| 59 | 59 |
///\todo The digraph alone may be insufficient to initialize |
| 60 | 60 |
static PredMap *createPredMap(const GR &G) |
| 61 | 61 |
{
|
| 62 | 62 |
return new PredMap(G); |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
///The type of the map that indicates which nodes are processed. |
| ... | ... |
@@ -96,58 +96,56 @@ |
| 96 | 96 |
{
|
| 97 | 97 |
return new ReachedMap(G); |
| 98 | 98 |
} |
| 99 | 99 |
///The type of the map that stores the dists of the nodes. |
| 100 | 100 |
|
| 101 | 101 |
///The type of the map that stores the dists of the nodes. |
| 102 | 102 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 103 | 103 |
/// |
| 104 | 104 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 105 | 105 |
///Instantiates a DistMap. |
| 106 | 106 |
|
| 107 | 107 |
///This function instantiates a \ref DistMap. |
| 108 | 108 |
///\param G is the digraph, to which we would like to define the \ref DistMap |
| 109 | 109 |
static DistMap *createDistMap(const GR &G) |
| 110 | 110 |
{
|
| 111 | 111 |
return new DistMap(G); |
| 112 | 112 |
} |
| 113 | 113 |
}; |
| 114 | 114 |
|
| 115 | 115 |
///%DFS algorithm class. |
| 116 | 116 |
|
| 117 | 117 |
///\ingroup search |
| 118 | 118 |
///This class provides an efficient implementation of the %DFS algorithm. |
| 119 | 119 |
/// |
| 120 |
///\ |
|
| 120 |
///\tparam GR The digraph type the algorithm runs on. The default value is |
|
| 121 | 121 |
///\ref ListDigraph. The value of GR is not used directly by Dfs, it |
| 122 | 122 |
///is only passed to \ref DfsDefaultTraits. |
| 123 |
///\ |
|
| 123 |
///\tparam TR Traits class to set various data types used by the algorithm. |
|
| 124 | 124 |
///The default traits class is |
| 125 | 125 |
///\ref DfsDefaultTraits "DfsDefaultTraits<GR>". |
| 126 | 126 |
///See \ref DfsDefaultTraits for the documentation of |
| 127 | 127 |
///a Dfs traits class. |
| 128 |
/// |
|
| 129 |
///\author Jacint Szabo and Alpar Juttner |
|
| 130 | 128 |
#ifdef DOXYGEN |
| 131 | 129 |
template <typename GR, |
| 132 | 130 |
typename TR> |
| 133 | 131 |
#else |
| 134 | 132 |
template <typename GR=ListDigraph, |
| 135 | 133 |
typename TR=DfsDefaultTraits<GR> > |
| 136 | 134 |
#endif |
| 137 | 135 |
class Dfs {
|
| 138 | 136 |
public: |
| 139 | 137 |
/** |
| 140 | 138 |
* \brief \ref Exception for uninitialized parameters. |
| 141 | 139 |
* |
| 142 | 140 |
* This error represents problems in the initialization |
| 143 | 141 |
* of the parameters of the algorithms. |
| 144 | 142 |
*/ |
| 145 | 143 |
class UninitializedParameter : public lemon::UninitializedParameter {
|
| 146 | 144 |
public: |
| 147 | 145 |
virtual const char* what() const throw() {
|
| 148 | 146 |
return "lemon::Dfs::UninitializedParameter"; |
| 149 | 147 |
} |
| 150 | 148 |
}; |
| 151 | 149 |
|
| 152 | 150 |
typedef TR Traits; |
| 153 | 151 |
///The type of the underlying digraph. |
| ... | ... |
@@ -718,49 +716,49 @@ |
| 718 | 716 |
|
| 719 | 717 |
///Returns a reference to the %DFS arc-tree map. |
| 720 | 718 |
|
| 721 | 719 |
///Returns a reference to the NodeMap of the arcs of the |
| 722 | 720 |
///%DFS tree. |
| 723 | 721 |
///\pre Either \ref run() or \ref init() |
| 724 | 722 |
///must be called before using this function. |
| 725 | 723 |
const PredMap &predMap() const { return *_pred;}
|
| 726 | 724 |
|
| 727 | 725 |
///Checks if a node is reachable from the root. |
| 728 | 726 |
|
| 729 | 727 |
///Returns \c true if \c v is reachable from the root(s). |
| 730 | 728 |
///\warning The source nodes are inditated as unreachable. |
| 731 | 729 |
///\pre Either \ref run() or \ref start() |
| 732 | 730 |
///must be called before using this function. |
| 733 | 731 |
/// |
| 734 | 732 |
bool reached(Node v) { return (*_reached)[v]; }
|
| 735 | 733 |
|
| 736 | 734 |
///@} |
| 737 | 735 |
}; |
| 738 | 736 |
|
| 739 | 737 |
///Default traits class of Dfs function. |
| 740 | 738 |
|
| 741 | 739 |
///Default traits class of Dfs function. |
| 742 |
///\ |
|
| 740 |
///\tparam GR Digraph type. |
|
| 743 | 741 |
template<class GR> |
| 744 | 742 |
struct DfsWizardDefaultTraits |
| 745 | 743 |
{
|
| 746 | 744 |
///The digraph type the algorithm runs on. |
| 747 | 745 |
typedef GR Digraph; |
| 748 | 746 |
///\brief The type of the map that stores the last |
| 749 | 747 |
///arcs of the %DFS paths. |
| 750 | 748 |
/// |
| 751 | 749 |
///The type of the map that stores the last |
| 752 | 750 |
///arcs of the %DFS paths. |
| 753 | 751 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 754 | 752 |
/// |
| 755 | 753 |
typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap; |
| 756 | 754 |
///Instantiates a PredMap. |
| 757 | 755 |
|
| 758 | 756 |
///This function instantiates a \ref PredMap. |
| 759 | 757 |
///\param g is the digraph, to which we would like to define the PredMap. |
| 760 | 758 |
///\todo The digraph alone may be insufficient to initialize |
| 761 | 759 |
#ifdef DOXYGEN |
| 762 | 760 |
static PredMap *createPredMap(const GR &g) |
| 763 | 761 |
#else |
| 764 | 762 |
static PredMap *createPredMap(const GR &) |
| 765 | 763 |
#endif |
| 766 | 764 |
{
|
| ... | ... |
@@ -1139,91 +1137,91 @@ |
| 1139 | 1137 |
void start(const Node&) {}
|
| 1140 | 1138 |
void stop(const Node&) {}
|
| 1141 | 1139 |
|
| 1142 | 1140 |
template <typename _Visitor> |
| 1143 | 1141 |
struct Constraints {
|
| 1144 | 1142 |
void constraints() {
|
| 1145 | 1143 |
Arc arc; |
| 1146 | 1144 |
Node node; |
| 1147 | 1145 |
visitor.discover(arc); |
| 1148 | 1146 |
visitor.reach(node); |
| 1149 | 1147 |
visitor.backtrack(arc); |
| 1150 | 1148 |
visitor.leave(node); |
| 1151 | 1149 |
visitor.examine(arc); |
| 1152 | 1150 |
visitor.start(node); |
| 1153 | 1151 |
visitor.stop(arc); |
| 1154 | 1152 |
} |
| 1155 | 1153 |
_Visitor& visitor; |
| 1156 | 1154 |
}; |
| 1157 | 1155 |
}; |
| 1158 | 1156 |
#endif |
| 1159 | 1157 |
|
| 1160 | 1158 |
/// \brief Default traits class of DfsVisit class. |
| 1161 | 1159 |
/// |
| 1162 | 1160 |
/// Default traits class of DfsVisit class. |
| 1163 |
/// \ |
|
| 1161 |
/// \tparam _Digraph Digraph type. |
|
| 1164 | 1162 |
template<class _Digraph> |
| 1165 | 1163 |
struct DfsVisitDefaultTraits {
|
| 1166 | 1164 |
|
| 1167 | 1165 |
/// \brief The digraph type the algorithm runs on. |
| 1168 | 1166 |
typedef _Digraph Digraph; |
| 1169 | 1167 |
|
| 1170 | 1168 |
/// \brief The type of the map that indicates which nodes are reached. |
| 1171 | 1169 |
/// |
| 1172 | 1170 |
/// The type of the map that indicates which nodes are reached. |
| 1173 | 1171 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 1174 | 1172 |
/// \todo named parameter to set this type, function to read and write. |
| 1175 | 1173 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
| 1176 | 1174 |
|
| 1177 | 1175 |
/// \brief Instantiates a ReachedMap. |
| 1178 | 1176 |
/// |
| 1179 | 1177 |
/// This function instantiates a \ref ReachedMap. |
| 1180 | 1178 |
/// \param digraph is the digraph, to which |
| 1181 | 1179 |
/// we would like to define the \ref ReachedMap. |
| 1182 | 1180 |
static ReachedMap *createReachedMap(const Digraph &digraph) {
|
| 1183 | 1181 |
return new ReachedMap(digraph); |
| 1184 | 1182 |
} |
| 1185 | 1183 |
|
| 1186 | 1184 |
}; |
| 1187 | 1185 |
|
| 1188 | 1186 |
/// %DFS Visit algorithm class. |
| 1189 | 1187 |
|
| 1190 | 1188 |
/// \ingroup search |
| 1191 | 1189 |
/// This class provides an efficient implementation of the %DFS algorithm |
| 1192 | 1190 |
/// with visitor interface. |
| 1193 | 1191 |
/// |
| 1194 | 1192 |
/// The %DfsVisit class provides an alternative interface to the Dfs |
| 1195 | 1193 |
/// class. It works with callback mechanism, the DfsVisit object calls |
| 1196 | 1194 |
/// on every dfs event the \c Visitor class member functions. |
| 1197 | 1195 |
/// |
| 1198 |
/// \ |
|
| 1196 |
/// \tparam _Digraph The digraph type the algorithm runs on. The default value is |
|
| 1199 | 1197 |
/// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it |
| 1200 | 1198 |
/// is only passed to \ref DfsDefaultTraits. |
| 1201 |
/// \ |
|
| 1199 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
|
| 1202 | 1200 |
/// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which |
| 1203 | 1201 |
/// does not observe the Dfs events. If you want to observe the dfs |
| 1204 | 1202 |
/// events you should implement your own Visitor class. |
| 1205 |
/// \ |
|
| 1203 |
/// \tparam _Traits Traits class to set various data types used by the |
|
| 1206 | 1204 |
/// algorithm. The default traits class is |
| 1207 | 1205 |
/// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>". |
| 1208 | 1206 |
/// See \ref DfsVisitDefaultTraits for the documentation of |
| 1209 | 1207 |
/// a Dfs visit traits class. |
| 1210 | 1208 |
/// |
| 1211 | 1209 |
/// \author Jacint Szabo, Alpar Juttner and Balazs Dezso |
| 1212 | 1210 |
#ifdef DOXYGEN |
| 1213 | 1211 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
| 1214 | 1212 |
#else |
| 1215 | 1213 |
template <typename _Digraph = ListDigraph, |
| 1216 | 1214 |
typename _Visitor = DfsVisitor<_Digraph>, |
| 1217 | 1215 |
typename _Traits = DfsDefaultTraits<_Digraph> > |
| 1218 | 1216 |
#endif |
| 1219 | 1217 |
class DfsVisit {
|
| 1220 | 1218 |
public: |
| 1221 | 1219 |
|
| 1222 | 1220 |
/// \brief \ref Exception for uninitialized parameters. |
| 1223 | 1221 |
/// |
| 1224 | 1222 |
/// This error represents problems in the initialization |
| 1225 | 1223 |
/// of the parameters of the algorithms. |
| 1226 | 1224 |
class UninitializedParameter : public lemon::UninitializedParameter {
|
| 1227 | 1225 |
public: |
| 1228 | 1226 |
virtual const char* what() const throw() |
| 1229 | 1227 |
{
|
| ... | ... |
@@ -56,50 +56,50 @@ |
| 56 | 56 |
|
| 57 | 57 |
/// \brief Widest path OperationTraits for the Dijkstra algorithm class. |
| 58 | 58 |
/// |
| 59 | 59 |
/// It defines all computational operations and constants which are |
| 60 | 60 |
/// used in the Dijkstra algorithm for widest path computation. |
| 61 | 61 |
template <typename Value> |
| 62 | 62 |
struct DijkstraWidestPathOperationTraits {
|
| 63 | 63 |
/// \brief Gives back the maximum value of the type. |
| 64 | 64 |
static Value zero() {
|
| 65 | 65 |
return std::numeric_limits<Value>::max(); |
| 66 | 66 |
} |
| 67 | 67 |
/// \brief Gives back the minimum of the given two elements. |
| 68 | 68 |
static Value plus(const Value& left, const Value& right) {
|
| 69 | 69 |
return std::min(left, right); |
| 70 | 70 |
} |
| 71 | 71 |
/// \brief Gives back true only if the first value less than the second. |
| 72 | 72 |
static bool less(const Value& left, const Value& right) {
|
| 73 | 73 |
return left < right; |
| 74 | 74 |
} |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 | 77 |
///Default traits class of Dijkstra class. |
| 78 | 78 |
|
| 79 | 79 |
///Default traits class of Dijkstra class. |
| 80 |
///\param GR Digraph type. |
|
| 81 |
///\param LM Type of length map. |
|
| 80 |
///\tparam GR Digraph type. |
|
| 81 |
///\tparam LM Type of length map. |
|
| 82 | 82 |
template<class GR, class LM> |
| 83 | 83 |
struct DijkstraDefaultTraits |
| 84 | 84 |
{
|
| 85 | 85 |
///The digraph type the algorithm runs on. |
| 86 | 86 |
typedef GR Digraph; |
| 87 | 87 |
///The type of the map that stores the arc lengths. |
| 88 | 88 |
|
| 89 | 89 |
///The type of the map that stores the arc lengths. |
| 90 | 90 |
///It must meet the \ref concepts::ReadMap "ReadMap" concept. |
| 91 | 91 |
typedef LM LengthMap; |
| 92 | 92 |
//The type of the length of the arcs. |
| 93 | 93 |
typedef typename LM::Value Value; |
| 94 | 94 |
/// Operation traits for Dijkstra algorithm. |
| 95 | 95 |
|
| 96 | 96 |
/// It defines the used operation by the algorithm. |
| 97 | 97 |
/// \see DijkstraDefaultOperationTraits |
| 98 | 98 |
typedef DijkstraDefaultOperationTraits<Value> OperationTraits; |
| 99 | 99 |
/// The cross reference type used by heap. |
| 100 | 100 |
|
| 101 | 101 |
|
| 102 | 102 |
/// The cross reference type used by heap. |
| 103 | 103 |
/// Usually it is \c Digraph::NodeMap<int>. |
| 104 | 104 |
typedef typename Digraph::template NodeMap<int> HeapCrossRef; |
| 105 | 105 |
///Instantiates a HeapCrossRef. |
| ... | ... |
@@ -173,65 +173,64 @@ |
| 173 | 173 |
typedef typename Digraph::template NodeMap<typename LM::Value> DistMap; |
| 174 | 174 |
///Instantiates a DistMap. |
| 175 | 175 |
|
| 176 | 176 |
///This function instantiates a \ref DistMap. |
| 177 | 177 |
///\param G is the digraph, to which we would like to define the \ref DistMap |
| 178 | 178 |
static DistMap *createDistMap(const GR &G) |
| 179 | 179 |
{
|
| 180 | 180 |
return new DistMap(G); |
| 181 | 181 |
} |
| 182 | 182 |
}; |
| 183 | 183 |
|
| 184 | 184 |
///%Dijkstra algorithm class. |
| 185 | 185 |
|
| 186 | 186 |
/// \ingroup shortest_path |
| 187 | 187 |
///This class provides an efficient implementation of %Dijkstra algorithm. |
| 188 | 188 |
///The arc lengths are passed to the algorithm using a |
| 189 | 189 |
///\ref concepts::ReadMap "ReadMap", |
| 190 | 190 |
///so it is easy to change it to any kind of length. |
| 191 | 191 |
/// |
| 192 | 192 |
///The type of the length is determined by the |
| 193 | 193 |
///\ref concepts::ReadMap::Value "Value" of the length map. |
| 194 | 194 |
/// |
| 195 | 195 |
///It is also possible to change the underlying priority heap. |
| 196 | 196 |
/// |
| 197 |
///\ |
|
| 197 |
///\tparam GR The digraph type the algorithm runs on. The default value |
|
| 198 | 198 |
///is \ref ListDigraph. The value of GR is not used directly by |
| 199 | 199 |
///Dijkstra, it is only passed to \ref DijkstraDefaultTraits. |
| 200 |
///\ |
|
| 200 |
///\tparam LM This read-only ArcMap determines the lengths of the |
|
| 201 | 201 |
///arcs. It is read once for each arc, so the map may involve in |
| 202 | 202 |
///relatively time consuming process to compute the arc length if |
| 203 | 203 |
///it is necessary. The default map type is \ref |
| 204 | 204 |
///concepts::Digraph::ArcMap "Digraph::ArcMap<int>". The value |
| 205 | 205 |
///of LM is not used directly by Dijkstra, it is only passed to \ref |
| 206 |
///DijkstraDefaultTraits. |
|
| 206 |
///DijkstraDefaultTraits. |
|
| 207 |
///\tparam TR Traits class to set |
|
| 207 | 208 |
///various data types used by the algorithm. The default traits |
| 208 | 209 |
///class is \ref DijkstraDefaultTraits |
| 209 | 210 |
///"DijkstraDefaultTraits<GR,LM>". See \ref |
| 210 | 211 |
///DijkstraDefaultTraits for the documentation of a Dijkstra traits |
| 211 | 212 |
///class. |
| 212 |
/// |
|
| 213 |
///\author Jacint Szabo and Alpar Juttner |
|
| 214 | 213 |
|
| 215 | 214 |
#ifdef DOXYGEN |
| 216 | 215 |
template <typename GR, typename LM, typename TR> |
| 217 | 216 |
#else |
| 218 | 217 |
template <typename GR=ListDigraph, |
| 219 | 218 |
typename LM=typename GR::template ArcMap<int>, |
| 220 | 219 |
typename TR=DijkstraDefaultTraits<GR,LM> > |
| 221 | 220 |
#endif |
| 222 | 221 |
class Dijkstra {
|
| 223 | 222 |
public: |
| 224 | 223 |
/** |
| 225 | 224 |
* \brief \ref Exception for uninitialized parameters. |
| 226 | 225 |
* |
| 227 | 226 |
* This error represents problems in the initialization |
| 228 | 227 |
* of the parameters of the algorithms. |
| 229 | 228 |
*/ |
| 230 | 229 |
class UninitializedParameter : public lemon::UninitializedParameter {
|
| 231 | 230 |
public: |
| 232 | 231 |
virtual const char* what() const throw() {
|
| 233 | 232 |
return "lemon::Dijkstra::UninitializedParameter"; |
| 234 | 233 |
} |
| 235 | 234 |
}; |
| 236 | 235 |
|
| 237 | 236 |
typedef TR Traits; |
| ... | ... |
@@ -854,50 +853,50 @@ |
| 854 | 853 |
///Returns \c true if \c v is reachable from the root. |
| 855 | 854 |
///\warning The source nodes are inditated as unreached. |
| 856 | 855 |
///\pre \ref run() must be called before using this function. |
| 857 | 856 |
/// |
| 858 | 857 |
bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
|
| 859 | 858 |
|
| 860 | 859 |
///Checks if a node is processed. |
| 861 | 860 |
|
| 862 | 861 |
///Returns \c true if \c v is processed, i.e. the shortest |
| 863 | 862 |
///path to \c v has already found. |
| 864 | 863 |
///\pre \ref run() must be called before using this function. |
| 865 | 864 |
/// |
| 866 | 865 |
bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
|
| 867 | 866 |
|
| 868 | 867 |
///@} |
| 869 | 868 |
}; |
| 870 | 869 |
|
| 871 | 870 |
|
| 872 | 871 |
|
| 873 | 872 |
|
| 874 | 873 |
|
| 875 | 874 |
///Default traits class of Dijkstra function. |
| 876 | 875 |
|
| 877 | 876 |
///Default traits class of Dijkstra function. |
| 878 |
///\param GR Digraph type. |
|
| 879 |
///\param LM Type of length map. |
|
| 877 |
///\tparam GR Digraph type. |
|
| 878 |
///\tparam LM Type of length map. |
|
| 880 | 879 |
template<class GR, class LM> |
| 881 | 880 |
struct DijkstraWizardDefaultTraits |
| 882 | 881 |
{
|
| 883 | 882 |
///The digraph type the algorithm runs on. |
| 884 | 883 |
typedef GR Digraph; |
| 885 | 884 |
///The type of the map that stores the arc lengths. |
| 886 | 885 |
|
| 887 | 886 |
///The type of the map that stores the arc lengths. |
| 888 | 887 |
///It must meet the \ref concepts::ReadMap "ReadMap" concept. |
| 889 | 888 |
typedef LM LengthMap; |
| 890 | 889 |
//The type of the length of the arcs. |
| 891 | 890 |
typedef typename LM::Value Value; |
| 892 | 891 |
/// Operation traits for Dijkstra algorithm. |
| 893 | 892 |
|
| 894 | 893 |
/// It defines the used operation by the algorithm. |
| 895 | 894 |
/// \see DijkstraDefaultOperationTraits |
| 896 | 895 |
typedef DijkstraDefaultOperationTraits<Value> OperationTraits; |
| 897 | 896 |
///The heap type used by Dijkstra algorithm. |
| 898 | 897 |
|
| 899 | 898 |
/// The cross reference type used by heap. |
| 900 | 899 |
|
| 901 | 900 |
/// The cross reference type used by heap. |
| 902 | 901 |
/// Usually it is \c Digraph::NodeMap<int>. |
| 903 | 902 |
typedef typename Digraph::template NodeMap<int> HeapCrossRef; |
| ... | ... |
@@ -395,97 +395,97 @@ |
| 395 | 395 |
///block to the nodes. |
| 396 | 396 |
///The PS current point will be moved to the centre of the node before |
| 397 | 397 |
///the PostScript block inserted. |
| 398 | 398 |
/// |
| 399 | 399 |
///Before and after the block a newline character is inserted so you |
| 400 | 400 |
///don't have to bother with the separators. |
| 401 | 401 |
/// |
| 402 | 402 |
///\param x must be a node map with type that can be pushed to a standard |
| 403 | 403 |
///ostream. |
| 404 | 404 |
/// |
| 405 | 405 |
///\sa nodePsTextsPreamble() |
| 406 | 406 |
template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x) |
| 407 | 407 |
{
|
| 408 | 408 |
dontPrint=true; |
| 409 | 409 |
_showNodePsText=true; |
| 410 | 410 |
return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x)); |
| 411 | 411 |
} |
| 412 | 412 |
template<class X> struct ArcWidthsTraits : public T {
|
| 413 | 413 |
const X &_arcWidths; |
| 414 | 414 |
ArcWidthsTraits(const T &t,const X &x) : T(t), _arcWidths(x) {}
|
| 415 | 415 |
}; |
| 416 | 416 |
///Sets the map of the arc widths |
| 417 | 417 |
|
| 418 | 418 |
///Sets the map of the arc widths |
| 419 |
///\param x must be |
|
| 419 |
///\param x must be an arc map with \c double (or convertible) values. |
|
| 420 | 420 |
template<class X> GraphToEps<ArcWidthsTraits<X> > arcWidths(const X &x) |
| 421 | 421 |
{
|
| 422 | 422 |
dontPrint=true; |
| 423 | 423 |
return GraphToEps<ArcWidthsTraits<X> >(ArcWidthsTraits<X>(*this,x)); |
| 424 | 424 |
} |
| 425 | 425 |
|
| 426 | 426 |
template<class X> struct NodeColorsTraits : public T {
|
| 427 | 427 |
const X &_nodeColors; |
| 428 | 428 |
NodeColorsTraits(const T &t,const X &x) : T(t), _nodeColors(x) {}
|
| 429 | 429 |
}; |
| 430 | 430 |
///Sets the map of the node colors |
| 431 | 431 |
|
| 432 | 432 |
///Sets the map of the node colors |
| 433 | 433 |
///\param x must be a node map with \ref Color values. |
| 434 | 434 |
/// |
| 435 | 435 |
///\sa Palette |
| 436 | 436 |
template<class X> GraphToEps<NodeColorsTraits<X> > |
| 437 | 437 |
nodeColors(const X &x) |
| 438 | 438 |
{
|
| 439 | 439 |
dontPrint=true; |
| 440 | 440 |
return GraphToEps<NodeColorsTraits<X> >(NodeColorsTraits<X>(*this,x)); |
| 441 | 441 |
} |
| 442 | 442 |
template<class X> struct NodeTextColorsTraits : public T {
|
| 443 | 443 |
const X &_nodeTextColors; |
| 444 | 444 |
NodeTextColorsTraits(const T &t,const X &x) : T(t), _nodeTextColors(x) {}
|
| 445 | 445 |
}; |
| 446 | 446 |
///Sets the map of the node text colors |
| 447 | 447 |
|
| 448 | 448 |
///Sets the map of the node text colors |
| 449 | 449 |
///\param x must be a node map with \ref Color values. |
| 450 | 450 |
/// |
| 451 | 451 |
///\sa Palette |
| 452 | 452 |
template<class X> GraphToEps<NodeTextColorsTraits<X> > |
| 453 | 453 |
nodeTextColors(const X &x) |
| 454 | 454 |
{
|
| 455 | 455 |
dontPrint=true; |
| 456 | 456 |
_nodeTextColorType=CUST_COL; |
| 457 | 457 |
return GraphToEps<NodeTextColorsTraits<X> > |
| 458 | 458 |
(NodeTextColorsTraits<X>(*this,x)); |
| 459 | 459 |
} |
| 460 | 460 |
template<class X> struct ArcColorsTraits : public T {
|
| 461 | 461 |
const X &_arcColors; |
| 462 | 462 |
ArcColorsTraits(const T &t,const X &x) : T(t), _arcColors(x) {}
|
| 463 | 463 |
}; |
| 464 | 464 |
///Sets the map of the arc colors |
| 465 | 465 |
|
| 466 | 466 |
///Sets the map of the arc colors |
| 467 |
///\param x must be |
|
| 467 |
///\param x must be an arc map with \ref Color values. |
|
| 468 | 468 |
/// |
| 469 | 469 |
///\sa Palette |
| 470 | 470 |
template<class X> GraphToEps<ArcColorsTraits<X> > |
| 471 | 471 |
arcColors(const X &x) |
| 472 | 472 |
{
|
| 473 | 473 |
dontPrint=true; |
| 474 | 474 |
return GraphToEps<ArcColorsTraits<X> >(ArcColorsTraits<X>(*this,x)); |
| 475 | 475 |
} |
| 476 | 476 |
///Sets a global scale factor for node sizes |
| 477 | 477 |
|
| 478 | 478 |
///Sets a global scale factor for node sizes. |
| 479 | 479 |
/// |
| 480 | 480 |
/// If nodeSizes() is not given, this function simply sets the node |
| 481 | 481 |
/// sizes to \c d. If nodeSizes() is given, but |
| 482 | 482 |
/// autoNodeScale() is not, then the node size given by |
| 483 | 483 |
/// nodeSizes() will be multiplied by the value \c d. |
| 484 | 484 |
/// If both nodeSizes() and autoNodeScale() are used, then the |
| 485 | 485 |
/// node sizes will be scaled in such a way that the greatest size will be |
| 486 | 486 |
/// equal to \c d. |
| 487 | 487 |
/// \sa nodeSizes() |
| 488 | 488 |
/// \sa autoNodeScale() |
| 489 | 489 |
GraphToEps<T> &nodeScale(double d=.01) {_nodeScale=d;return *this;}
|
| 490 | 490 |
///Turns on/off the automatic node width scaling. |
| 491 | 491 |
| ... | ... |
@@ -333,50 +333,48 @@ |
| 333 | 333 |
///\sa DynArcLookUp |
| 334 | 334 |
///\sa ConArcIt |
| 335 | 335 |
template <typename Graph> |
| 336 | 336 |
inline typename Graph::Arc |
| 337 | 337 |
findArc(const Graph &g, typename Graph::Node u, typename Graph::Node v, |
| 338 | 338 |
typename Graph::Arc prev = INVALID) {
|
| 339 | 339 |
return _graph_utils_bits::FindArcSelector<Graph>::find(g, u, v, prev); |
| 340 | 340 |
} |
| 341 | 341 |
|
| 342 | 342 |
/// \brief Iterator for iterating on arcs connected the same nodes. |
| 343 | 343 |
/// |
| 344 | 344 |
/// Iterator for iterating on arcs connected the same nodes. It is |
| 345 | 345 |
/// higher level interface for the findArc() function. You can |
| 346 | 346 |
/// use it the following way: |
| 347 | 347 |
///\code |
| 348 | 348 |
/// for (ConArcIt<Graph> it(g, src, trg); it != INVALID; ++it) {
|
| 349 | 349 |
/// ... |
| 350 | 350 |
/// } |
| 351 | 351 |
///\endcode |
| 352 | 352 |
/// |
| 353 | 353 |
///\sa findArc() |
| 354 | 354 |
///\sa ArcLookUp |
| 355 | 355 |
///\sa AllArcLookUp |
| 356 | 356 |
///\sa DynArcLookUp |
| 357 |
/// |
|
| 358 |
/// \author Balazs Dezso |
|
| 359 | 357 |
template <typename _Graph> |
| 360 | 358 |
class ConArcIt : public _Graph::Arc {
|
| 361 | 359 |
public: |
| 362 | 360 |
|
| 363 | 361 |
typedef _Graph Graph; |
| 364 | 362 |
typedef typename Graph::Arc Parent; |
| 365 | 363 |
|
| 366 | 364 |
typedef typename Graph::Arc Arc; |
| 367 | 365 |
typedef typename Graph::Node Node; |
| 368 | 366 |
|
| 369 | 367 |
/// \brief Constructor. |
| 370 | 368 |
/// |
| 371 | 369 |
/// Construct a new ConArcIt iterating on the arcs which |
| 372 | 370 |
/// connects the \c u and \c v node. |
| 373 | 371 |
ConArcIt(const Graph& g, Node u, Node v) : _graph(g) {
|
| 374 | 372 |
Parent::operator=(findArc(_graph, u, v)); |
| 375 | 373 |
} |
| 376 | 374 |
|
| 377 | 375 |
/// \brief Constructor. |
| 378 | 376 |
/// |
| 379 | 377 |
/// Construct a new ConArcIt which continues the iterating from |
| 380 | 378 |
/// the \c e arc. |
| 381 | 379 |
ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {}
|
| 382 | 380 |
|
| ... | ... |
@@ -457,50 +455,48 @@ |
| 457 | 455 |
/// } |
| 458 | 456 |
///\endcode |
| 459 | 457 |
/// |
| 460 | 458 |
///\sa ConArcIt |
| 461 | 459 |
|
| 462 | 460 |
template <typename Graph> |
| 463 | 461 |
inline typename Graph::Edge |
| 464 | 462 |
findEdge(const Graph &g, typename Graph::Node u, typename Graph::Node v, |
| 465 | 463 |
typename Graph::Edge p = INVALID) {
|
| 466 | 464 |
return _graph_utils_bits::FindEdgeSelector<Graph>::find(g, u, v, p); |
| 467 | 465 |
} |
| 468 | 466 |
|
| 469 | 467 |
/// \brief Iterator for iterating on edges connected the same nodes. |
| 470 | 468 |
/// |
| 471 | 469 |
/// Iterator for iterating on edges connected the same nodes. It is |
| 472 | 470 |
/// higher level interface for the findEdge() function. You can |
| 473 | 471 |
/// use it the following way: |
| 474 | 472 |
///\code |
| 475 | 473 |
/// for (ConEdgeIt<Graph> it(g, src, trg); it != INVALID; ++it) {
|
| 476 | 474 |
/// ... |
| 477 | 475 |
/// } |
| 478 | 476 |
///\endcode |
| 479 | 477 |
/// |
| 480 | 478 |
///\sa findEdge() |
| 481 |
/// |
|
| 482 |
/// \author Balazs Dezso |
|
| 483 | 479 |
template <typename _Graph> |
| 484 | 480 |
class ConEdgeIt : public _Graph::Edge {
|
| 485 | 481 |
public: |
| 486 | 482 |
|
| 487 | 483 |
typedef _Graph Graph; |
| 488 | 484 |
typedef typename Graph::Edge Parent; |
| 489 | 485 |
|
| 490 | 486 |
typedef typename Graph::Edge Edge; |
| 491 | 487 |
typedef typename Graph::Node Node; |
| 492 | 488 |
|
| 493 | 489 |
/// \brief Constructor. |
| 494 | 490 |
/// |
| 495 | 491 |
/// Construct a new ConEdgeIt iterating on the edges which |
| 496 | 492 |
/// connects the \c u and \c v node. |
| 497 | 493 |
ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g) {
|
| 498 | 494 |
Parent::operator=(findEdge(_graph, u, v)); |
| 499 | 495 |
} |
| 500 | 496 |
|
| 501 | 497 |
/// \brief Constructor. |
| 502 | 498 |
/// |
| 503 | 499 |
/// Construct a new ConEdgeIt which continues the iterating from |
| 504 | 500 |
/// the \c e edge. |
| 505 | 501 |
ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {}
|
| 506 | 502 |
|
| ... | ... |
@@ -1221,51 +1217,51 @@ |
| 1221 | 1217 |
Item operator[](int id) const { return _graph->fromId(id, Item());}
|
| 1222 | 1218 |
|
| 1223 | 1219 |
private: |
| 1224 | 1220 |
const Graph* _graph; |
| 1225 | 1221 |
}; |
| 1226 | 1222 |
|
| 1227 | 1223 |
/// \brief Gives back the inverse of the map. |
| 1228 | 1224 |
/// |
| 1229 | 1225 |
/// Gives back the inverse of the IdMap. |
| 1230 | 1226 |
InverseMap inverse() const { return InverseMap(*_graph);}
|
| 1231 | 1227 |
|
| 1232 | 1228 |
}; |
| 1233 | 1229 |
|
| 1234 | 1230 |
|
| 1235 | 1231 |
/// \brief General invertable graph-map type. |
| 1236 | 1232 |
|
| 1237 | 1233 |
/// This type provides simple invertable graph-maps. |
| 1238 | 1234 |
/// The InvertableMap wraps an arbitrary ReadWriteMap |
| 1239 | 1235 |
/// and if a key is set to a new value then store it |
| 1240 | 1236 |
/// in the inverse map. |
| 1241 | 1237 |
/// |
| 1242 | 1238 |
/// The values of the map can be accessed |
| 1243 | 1239 |
/// with stl compatible forward iterator. |
| 1244 | 1240 |
/// |
| 1245 |
/// \param _Graph The graph type. |
|
| 1246 |
/// \param _Item The item type of the graph. |
|
| 1247 |
/// \ |
|
| 1241 |
/// \tparam _Graph The graph type. |
|
| 1242 |
/// \tparam _Item The item type of the graph. |
|
| 1243 |
/// \tparam _Value The value type of the map. |
|
| 1248 | 1244 |
/// |
| 1249 | 1245 |
/// \see IterableValueMap |
| 1250 | 1246 |
template <typename _Graph, typename _Item, typename _Value> |
| 1251 | 1247 |
class InvertableMap : protected DefaultMap<_Graph, _Item, _Value> {
|
| 1252 | 1248 |
private: |
| 1253 | 1249 |
|
| 1254 | 1250 |
typedef DefaultMap<_Graph, _Item, _Value> Map; |
| 1255 | 1251 |
typedef _Graph Graph; |
| 1256 | 1252 |
|
| 1257 | 1253 |
typedef std::map<_Value, _Item> Container; |
| 1258 | 1254 |
Container _inv_map; |
| 1259 | 1255 |
|
| 1260 | 1256 |
public: |
| 1261 | 1257 |
|
| 1262 | 1258 |
/// The key type of InvertableMap (Node, Arc, Edge). |
| 1263 | 1259 |
typedef typename Map::Key Key; |
| 1264 | 1260 |
/// The value type of the InvertableMap. |
| 1265 | 1261 |
typedef typename Map::Value Value; |
| 1266 | 1262 |
|
| 1267 | 1263 |
|
| 1268 | 1264 |
|
| 1269 | 1265 |
/// \brief Constructor. |
| 1270 | 1266 |
/// |
| 1271 | 1267 |
/// Construct a new InvertableMap for the graph. |
| ... | ... |
@@ -1426,50 +1422,50 @@ |
| 1426 | 1422 |
|
| 1427 | 1423 |
/// \brief It gives back the just readable inverse map. |
| 1428 | 1424 |
/// |
| 1429 | 1425 |
/// It gives back the just readable inverse map. |
| 1430 | 1426 |
InverseMap inverse() const {
|
| 1431 | 1427 |
return InverseMap(*this); |
| 1432 | 1428 |
} |
| 1433 | 1429 |
|
| 1434 | 1430 |
|
| 1435 | 1431 |
|
| 1436 | 1432 |
}; |
| 1437 | 1433 |
|
| 1438 | 1434 |
/// \brief Provides a mutable, continuous and unique descriptor for each |
| 1439 | 1435 |
/// item in the graph. |
| 1440 | 1436 |
/// |
| 1441 | 1437 |
/// The DescriptorMap class provides a unique and continuous (but mutable) |
| 1442 | 1438 |
/// descriptor (id) for each item of the same type (e.g. node) in the |
| 1443 | 1439 |
/// graph. This id is <ul><li>\b unique: different items (nodes) get |
| 1444 | 1440 |
/// different ids <li>\b continuous: the range of the ids is the set of |
| 1445 | 1441 |
/// integers between 0 and \c n-1, where \c n is the number of the items of |
| 1446 | 1442 |
/// this type (e.g. nodes) (so the id of a node can change if you delete an |
| 1447 | 1443 |
/// other node, i.e. this id is mutable). </ul> This map can be inverted |
| 1448 | 1444 |
/// with its member class \c InverseMap, or with the \c operator() member. |
| 1449 | 1445 |
/// |
| 1450 |
/// \param _Graph The graph class the \c DescriptorMap belongs to. |
|
| 1451 |
/// \param _Item The Item is the Key of the Map. It may be Node, Arc or |
|
| 1446 |
/// \tparam _Graph The graph class the \c DescriptorMap belongs to. |
|
| 1447 |
/// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or |
|
| 1452 | 1448 |
/// Edge. |
| 1453 | 1449 |
template <typename _Graph, typename _Item> |
| 1454 | 1450 |
class DescriptorMap : protected DefaultMap<_Graph, _Item, int> {
|
| 1455 | 1451 |
|
| 1456 | 1452 |
typedef _Item Item; |
| 1457 | 1453 |
typedef DefaultMap<_Graph, _Item, int> Map; |
| 1458 | 1454 |
|
| 1459 | 1455 |
public: |
| 1460 | 1456 |
/// The graph class of DescriptorMap. |
| 1461 | 1457 |
typedef _Graph Graph; |
| 1462 | 1458 |
|
| 1463 | 1459 |
/// The key type of DescriptorMap (Node, Arc, Edge). |
| 1464 | 1460 |
typedef typename Map::Key Key; |
| 1465 | 1461 |
/// The value type of DescriptorMap. |
| 1466 | 1462 |
typedef typename Map::Value Value; |
| 1467 | 1463 |
|
| 1468 | 1464 |
/// \brief Constructor. |
| 1469 | 1465 |
/// |
| 1470 | 1466 |
/// Constructor for descriptor map. |
| 1471 | 1467 |
explicit DescriptorMap(const Graph& _graph) : Map(_graph) {
|
| 1472 | 1468 |
Item it; |
| 1473 | 1469 |
const typename Map::Notifier* nf = Map::notifier(); |
| 1474 | 1470 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 1475 | 1471 |
Map::set(it, _inv_map.size()); |
| ... | ... |
@@ -1616,169 +1612,165 @@ |
| 1616 | 1612 |
|
| 1617 | 1613 |
/// \brief Size of the map. |
| 1618 | 1614 |
/// |
| 1619 | 1615 |
/// Returns the size of the map. |
| 1620 | 1616 |
unsigned int size() const {
|
| 1621 | 1617 |
return _inverted.size(); |
| 1622 | 1618 |
} |
| 1623 | 1619 |
|
| 1624 | 1620 |
private: |
| 1625 | 1621 |
const DescriptorMap& _inverted; |
| 1626 | 1622 |
}; |
| 1627 | 1623 |
|
| 1628 | 1624 |
/// \brief Gives back the inverse of the map. |
| 1629 | 1625 |
/// |
| 1630 | 1626 |
/// Gives back the inverse of the map. |
| 1631 | 1627 |
const InverseMap inverse() const {
|
| 1632 | 1628 |
return InverseMap(*this); |
| 1633 | 1629 |
} |
| 1634 | 1630 |
}; |
| 1635 | 1631 |
|
| 1636 | 1632 |
/// \brief Returns the source of the given arc. |
| 1637 | 1633 |
/// |
| 1638 | 1634 |
/// The SourceMap gives back the source Node of the given arc. |
| 1639 | 1635 |
/// \see TargetMap |
| 1640 |
/// \author Balazs Dezso |
|
| 1641 | 1636 |
template <typename Digraph> |
| 1642 | 1637 |
class SourceMap {
|
| 1643 | 1638 |
public: |
| 1644 | 1639 |
|
| 1645 | 1640 |
typedef typename Digraph::Node Value; |
| 1646 | 1641 |
typedef typename Digraph::Arc Key; |
| 1647 | 1642 |
|
| 1648 | 1643 |
/// \brief Constructor |
| 1649 | 1644 |
/// |
| 1650 | 1645 |
/// Constructor |
| 1651 | 1646 |
/// \param _digraph The digraph that the map belongs to. |
| 1652 | 1647 |
explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {}
|
| 1653 | 1648 |
|
| 1654 | 1649 |
/// \brief The subscript operator. |
| 1655 | 1650 |
/// |
| 1656 | 1651 |
/// The subscript operator. |
| 1657 | 1652 |
/// \param arc The arc |
| 1658 | 1653 |
/// \return The source of the arc |
| 1659 | 1654 |
Value operator[](const Key& arc) const {
|
| 1660 | 1655 |
return _digraph.source(arc); |
| 1661 | 1656 |
} |
| 1662 | 1657 |
|
| 1663 | 1658 |
private: |
| 1664 | 1659 |
const Digraph& _digraph; |
| 1665 | 1660 |
}; |
| 1666 | 1661 |
|
| 1667 | 1662 |
/// \brief Returns a \ref SourceMap class. |
| 1668 | 1663 |
/// |
| 1669 | 1664 |
/// This function just returns an \ref SourceMap class. |
| 1670 | 1665 |
/// \relates SourceMap |
| 1671 | 1666 |
template <typename Digraph> |
| 1672 | 1667 |
inline SourceMap<Digraph> sourceMap(const Digraph& digraph) {
|
| 1673 | 1668 |
return SourceMap<Digraph>(digraph); |
| 1674 | 1669 |
} |
| 1675 | 1670 |
|
| 1676 | 1671 |
/// \brief Returns the target of the given arc. |
| 1677 | 1672 |
/// |
| 1678 | 1673 |
/// The TargetMap gives back the target Node of the given arc. |
| 1679 | 1674 |
/// \see SourceMap |
| 1680 |
/// \author Balazs Dezso |
|
| 1681 | 1675 |
template <typename Digraph> |
| 1682 | 1676 |
class TargetMap {
|
| 1683 | 1677 |
public: |
| 1684 | 1678 |
|
| 1685 | 1679 |
typedef typename Digraph::Node Value; |
| 1686 | 1680 |
typedef typename Digraph::Arc Key; |
| 1687 | 1681 |
|
| 1688 | 1682 |
/// \brief Constructor |
| 1689 | 1683 |
/// |
| 1690 | 1684 |
/// Constructor |
| 1691 | 1685 |
/// \param _digraph The digraph that the map belongs to. |
| 1692 | 1686 |
explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {}
|
| 1693 | 1687 |
|
| 1694 | 1688 |
/// \brief The subscript operator. |
| 1695 | 1689 |
/// |
| 1696 | 1690 |
/// The subscript operator. |
| 1697 | 1691 |
/// \param e The arc |
| 1698 | 1692 |
/// \return The target of the arc |
| 1699 | 1693 |
Value operator[](const Key& e) const {
|
| 1700 | 1694 |
return _digraph.target(e); |
| 1701 | 1695 |
} |
| 1702 | 1696 |
|
| 1703 | 1697 |
private: |
| 1704 | 1698 |
const Digraph& _digraph; |
| 1705 | 1699 |
}; |
| 1706 | 1700 |
|
| 1707 | 1701 |
/// \brief Returns a \ref TargetMap class. |
| 1708 | 1702 |
/// |
| 1709 | 1703 |
/// This function just returns a \ref TargetMap class. |
| 1710 | 1704 |
/// \relates TargetMap |
| 1711 | 1705 |
template <typename Digraph> |
| 1712 | 1706 |
inline TargetMap<Digraph> targetMap(const Digraph& digraph) {
|
| 1713 | 1707 |
return TargetMap<Digraph>(digraph); |
| 1714 | 1708 |
} |
| 1715 | 1709 |
|
| 1716 | 1710 |
/// \brief Returns the "forward" directed arc view of an edge. |
| 1717 | 1711 |
/// |
| 1718 | 1712 |
/// Returns the "forward" directed arc view of an edge. |
| 1719 | 1713 |
/// \see BackwardMap |
| 1720 |
/// \author Balazs Dezso |
|
| 1721 | 1714 |
template <typename Graph> |
| 1722 | 1715 |
class ForwardMap {
|
| 1723 | 1716 |
public: |
| 1724 | 1717 |
|
| 1725 | 1718 |
typedef typename Graph::Arc Value; |
| 1726 | 1719 |
typedef typename Graph::Edge Key; |
| 1727 | 1720 |
|
| 1728 | 1721 |
/// \brief Constructor |
| 1729 | 1722 |
/// |
| 1730 | 1723 |
/// Constructor |
| 1731 | 1724 |
/// \param _graph The graph that the map belongs to. |
| 1732 | 1725 |
explicit ForwardMap(const Graph& graph) : _graph(graph) {}
|
| 1733 | 1726 |
|
| 1734 | 1727 |
/// \brief The subscript operator. |
| 1735 | 1728 |
/// |
| 1736 | 1729 |
/// The subscript operator. |
| 1737 | 1730 |
/// \param key An edge |
| 1738 | 1731 |
/// \return The "forward" directed arc view of edge |
| 1739 | 1732 |
Value operator[](const Key& key) const {
|
| 1740 | 1733 |
return _graph.direct(key, true); |
| 1741 | 1734 |
} |
| 1742 | 1735 |
|
| 1743 | 1736 |
private: |
| 1744 | 1737 |
const Graph& _graph; |
| 1745 | 1738 |
}; |
| 1746 | 1739 |
|
| 1747 | 1740 |
/// \brief Returns a \ref ForwardMap class. |
| 1748 | 1741 |
/// |
| 1749 | 1742 |
/// This function just returns an \ref ForwardMap class. |
| 1750 | 1743 |
/// \relates ForwardMap |
| 1751 | 1744 |
template <typename Graph> |
| 1752 | 1745 |
inline ForwardMap<Graph> forwardMap(const Graph& graph) {
|
| 1753 | 1746 |
return ForwardMap<Graph>(graph); |
| 1754 | 1747 |
} |
| 1755 | 1748 |
|
| 1756 | 1749 |
/// \brief Returns the "backward" directed arc view of an edge. |
| 1757 | 1750 |
/// |
| 1758 | 1751 |
/// Returns the "backward" directed arc view of an edge. |
| 1759 | 1752 |
/// \see ForwardMap |
| 1760 |
/// \author Balazs Dezso |
|
| 1761 | 1753 |
template <typename Graph> |
| 1762 | 1754 |
class BackwardMap {
|
| 1763 | 1755 |
public: |
| 1764 | 1756 |
|
| 1765 | 1757 |
typedef typename Graph::Arc Value; |
| 1766 | 1758 |
typedef typename Graph::Edge Key; |
| 1767 | 1759 |
|
| 1768 | 1760 |
/// \brief Constructor |
| 1769 | 1761 |
/// |
| 1770 | 1762 |
/// Constructor |
| 1771 | 1763 |
/// \param _graph The graph that the map belongs to. |
| 1772 | 1764 |
explicit BackwardMap(const Graph& graph) : _graph(graph) {}
|
| 1773 | 1765 |
|
| 1774 | 1766 |
/// \brief The subscript operator. |
| 1775 | 1767 |
/// |
| 1776 | 1768 |
/// The subscript operator. |
| 1777 | 1769 |
/// \param key An edge |
| 1778 | 1770 |
/// \return The "backward" directed arc view of edge |
| 1779 | 1771 |
Value operator[](const Key& key) const {
|
| 1780 | 1772 |
return _graph.direct(key, false); |
| 1781 | 1773 |
} |
| 1782 | 1774 |
|
| 1783 | 1775 |
private: |
| 1784 | 1776 |
const Graph& _graph; |
| ... | ... |
@@ -2075,49 +2067,49 @@ |
| 2075 | 2067 |
const Digraph& _digraph; |
| 2076 | 2068 |
AutoNodeMap _deg; |
| 2077 | 2069 |
}; |
| 2078 | 2070 |
|
| 2079 | 2071 |
|
| 2080 | 2072 |
///Dynamic arc look up between given endpoints. |
| 2081 | 2073 |
|
| 2082 | 2074 |
///\ingroup gutils |
| 2083 | 2075 |
///Using this class, you can find an arc in a digraph from a given |
| 2084 | 2076 |
///source to a given target in amortized time <em>O(log d)</em>, |
| 2085 | 2077 |
///where <em>d</em> is the out-degree of the source node. |
| 2086 | 2078 |
/// |
| 2087 | 2079 |
///It is possible to find \e all parallel arcs between two nodes with |
| 2088 | 2080 |
///the \c findFirst() and \c findNext() members. |
| 2089 | 2081 |
/// |
| 2090 | 2082 |
///See the \ref ArcLookUp and \ref AllArcLookUp classes if your |
| 2091 | 2083 |
///digraph is not changed so frequently. |
| 2092 | 2084 |
/// |
| 2093 | 2085 |
///This class uses a self-adjusting binary search tree, Sleator's |
| 2094 | 2086 |
///and Tarjan's Splay tree for guarantee the logarithmic amortized |
| 2095 | 2087 |
///time bound for arc lookups. This class also guarantees the |
| 2096 | 2088 |
///optimal time bound in a constant factor for any distribution of |
| 2097 | 2089 |
///queries. |
| 2098 | 2090 |
/// |
| 2099 |
///\ |
|
| 2091 |
///\tparam G The type of the underlying digraph. |
|
| 2100 | 2092 |
/// |
| 2101 | 2093 |
///\sa ArcLookUp |
| 2102 | 2094 |
///\sa AllArcLookUp |
| 2103 | 2095 |
template<class G> |
| 2104 | 2096 |
class DynArcLookUp |
| 2105 | 2097 |
: protected ItemSetTraits<G, typename G::Arc>::ItemNotifier::ObserverBase |
| 2106 | 2098 |
{
|
| 2107 | 2099 |
public: |
| 2108 | 2100 |
typedef typename ItemSetTraits<G, typename G::Arc> |
| 2109 | 2101 |
::ItemNotifier::ObserverBase Parent; |
| 2110 | 2102 |
|
| 2111 | 2103 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
| 2112 | 2104 |
typedef G Digraph; |
| 2113 | 2105 |
|
| 2114 | 2106 |
protected: |
| 2115 | 2107 |
|
| 2116 | 2108 |
class AutoNodeMap : public DefaultMap<G, Node, Arc> {
|
| 2117 | 2109 |
public: |
| 2118 | 2110 |
|
| 2119 | 2111 |
typedef DefaultMap<G, Node, Arc> Parent; |
| 2120 | 2112 |
|
| 2121 | 2113 |
AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {}
|
| 2122 | 2114 |
|
| 2123 | 2115 |
virtual void add(const Node& node) {
|
| ... | ... |
@@ -2516,49 +2508,49 @@ |
| 2516 | 2508 |
const_cast<DynArcLookUp&>(*this).splay(a); |
| 2517 | 2509 |
} |
| 2518 | 2510 |
} |
| 2519 | 2511 |
if (_g.target(a) == t) return a; |
| 2520 | 2512 |
else return INVALID; |
| 2521 | 2513 |
} |
| 2522 | 2514 |
|
| 2523 | 2515 |
}; |
| 2524 | 2516 |
|
| 2525 | 2517 |
///Fast arc look up between given endpoints. |
| 2526 | 2518 |
|
| 2527 | 2519 |
///\ingroup gutils |
| 2528 | 2520 |
///Using this class, you can find an arc in a digraph from a given |
| 2529 | 2521 |
///source to a given target in time <em>O(log d)</em>, |
| 2530 | 2522 |
///where <em>d</em> is the out-degree of the source node. |
| 2531 | 2523 |
/// |
| 2532 | 2524 |
///It is not possible to find \e all parallel arcs between two nodes. |
| 2533 | 2525 |
///Use \ref AllArcLookUp for this purpose. |
| 2534 | 2526 |
/// |
| 2535 | 2527 |
///\warning This class is static, so you should refresh() (or at least |
| 2536 | 2528 |
///refresh(Node)) this data structure |
| 2537 | 2529 |
///whenever the digraph changes. This is a time consuming (superlinearly |
| 2538 | 2530 |
///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs). |
| 2539 | 2531 |
/// |
| 2540 |
///\ |
|
| 2532 |
///\tparam G The type of the underlying digraph. |
|
| 2541 | 2533 |
/// |
| 2542 | 2534 |
///\sa DynArcLookUp |
| 2543 | 2535 |
///\sa AllArcLookUp |
| 2544 | 2536 |
template<class G> |
| 2545 | 2537 |
class ArcLookUp |
| 2546 | 2538 |
{
|
| 2547 | 2539 |
public: |
| 2548 | 2540 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
| 2549 | 2541 |
typedef G Digraph; |
| 2550 | 2542 |
|
| 2551 | 2543 |
protected: |
| 2552 | 2544 |
const Digraph &_g; |
| 2553 | 2545 |
typename Digraph::template NodeMap<Arc> _head; |
| 2554 | 2546 |
typename Digraph::template ArcMap<Arc> _left; |
| 2555 | 2547 |
typename Digraph::template ArcMap<Arc> _right; |
| 2556 | 2548 |
|
| 2557 | 2549 |
class ArcLess {
|
| 2558 | 2550 |
const Digraph &g; |
| 2559 | 2551 |
public: |
| 2560 | 2552 |
ArcLess(const Digraph &_g) : g(_g) {}
|
| 2561 | 2553 |
bool operator()(Arc a,Arc b) const |
| 2562 | 2554 |
{
|
| 2563 | 2555 |
return g.target(a)<g.target(b); |
| 2564 | 2556 |
} |
| ... | ... |
@@ -2629,49 +2621,49 @@ |
| 2629 | 2621 |
///\ref refresh(Node) "refresh(n)" is enough. |
| 2630 | 2622 |
/// |
| 2631 | 2623 |
Arc operator()(Node s, Node t) const |
| 2632 | 2624 |
{
|
| 2633 | 2625 |
Arc e; |
| 2634 | 2626 |
for(e=_head[s]; |
| 2635 | 2627 |
e!=INVALID&&_g.target(e)!=t; |
| 2636 | 2628 |
e = t < _g.target(e)?_left[e]:_right[e]) ; |
| 2637 | 2629 |
return e; |
| 2638 | 2630 |
} |
| 2639 | 2631 |
|
| 2640 | 2632 |
}; |
| 2641 | 2633 |
|
| 2642 | 2634 |
///Fast look up of all arcs between given endpoints. |
| 2643 | 2635 |
|
| 2644 | 2636 |
///\ingroup gutils |
| 2645 | 2637 |
///This class is the same as \ref ArcLookUp, with the addition |
| 2646 | 2638 |
///that it makes it possible to find all arcs between given endpoints. |
| 2647 | 2639 |
/// |
| 2648 | 2640 |
///\warning This class is static, so you should refresh() (or at least |
| 2649 | 2641 |
///refresh(Node)) this data structure |
| 2650 | 2642 |
///whenever the digraph changes. This is a time consuming (superlinearly |
| 2651 | 2643 |
///proportional (<em>O(m</em>log<em>m)</em>) to the number of arcs). |
| 2652 | 2644 |
/// |
| 2653 |
///\ |
|
| 2645 |
///\tparam G The type of the underlying digraph. |
|
| 2654 | 2646 |
/// |
| 2655 | 2647 |
///\sa DynArcLookUp |
| 2656 | 2648 |
///\sa ArcLookUp |
| 2657 | 2649 |
template<class G> |
| 2658 | 2650 |
class AllArcLookUp : public ArcLookUp<G> |
| 2659 | 2651 |
{
|
| 2660 | 2652 |
using ArcLookUp<G>::_g; |
| 2661 | 2653 |
using ArcLookUp<G>::_right; |
| 2662 | 2654 |
using ArcLookUp<G>::_left; |
| 2663 | 2655 |
using ArcLookUp<G>::_head; |
| 2664 | 2656 |
|
| 2665 | 2657 |
TEMPLATE_DIGRAPH_TYPEDEFS(G); |
| 2666 | 2658 |
typedef G Digraph; |
| 2667 | 2659 |
|
| 2668 | 2660 |
typename Digraph::template ArcMap<Arc> _next; |
| 2669 | 2661 |
|
| 2670 | 2662 |
Arc refreshNext(Arc head,Arc next=INVALID) |
| 2671 | 2663 |
{
|
| 2672 | 2664 |
if(head==INVALID) return next; |
| 2673 | 2665 |
else {
|
| 2674 | 2666 |
next=refreshNext(_right[head],next); |
| 2675 | 2667 |
// _next[head]=next; |
| 2676 | 2668 |
_next[head]=( next!=INVALID && _g.target(next)==_g.target(head)) |
| 2677 | 2669 |
? next : INVALID; |
| ... | ... |
@@ -19,49 +19,49 @@ |
| 19 | 19 |
///\ingroup paths |
| 20 | 20 |
///\file |
| 21 | 21 |
///\brief Classes for representing paths in digraphs. |
| 22 | 22 |
/// |
| 23 | 23 |
|
| 24 | 24 |
#ifndef LEMON_PATH_H |
| 25 | 25 |
#define LEMON_PATH_H |
| 26 | 26 |
|
| 27 | 27 |
#include <vector> |
| 28 | 28 |
#include <algorithm> |
| 29 | 29 |
|
| 30 | 30 |
#include <lemon/error.h> |
| 31 | 31 |
#include <lemon/bits/invalid.h> |
| 32 | 32 |
#include <lemon/concepts/path.h> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \addtogroup paths |
| 37 | 37 |
/// @{
|
| 38 | 38 |
|
| 39 | 39 |
|
| 40 | 40 |
/// \brief A structure for representing directed paths in a digraph. |
| 41 | 41 |
/// |
| 42 | 42 |
/// A structure for representing directed path in a digraph. |
| 43 |
/// \ |
|
| 43 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 44 | 44 |
/// |
| 45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
| 46 | 46 |
/// lemon path type stores just this list. As a consequence, it |
| 47 | 47 |
/// cannot enumerate the nodes of the path and the source node of |
| 48 | 48 |
/// a zero length path is undefined. |
| 49 | 49 |
/// |
| 50 | 50 |
/// This implementation is a back and front insertable and erasable |
| 51 | 51 |
/// path type. It can be indexed in O(1) time. The front and back |
| 52 | 52 |
/// insertion and erase is done in O(1) (amortized) time. The |
| 53 | 53 |
/// implementation uses two vectors for storing the front and back |
| 54 | 54 |
/// insertions. |
| 55 | 55 |
template <typename _Digraph> |
| 56 | 56 |
class Path {
|
| 57 | 57 |
public: |
| 58 | 58 |
|
| 59 | 59 |
typedef _Digraph Digraph; |
| 60 | 60 |
typedef typename Digraph::Arc Arc; |
| 61 | 61 |
|
| 62 | 62 |
/// \brief Default constructor |
| 63 | 63 |
/// |
| 64 | 64 |
/// Default constructor |
| 65 | 65 |
Path() {}
|
| 66 | 66 |
|
| 67 | 67 |
/// \brief Template copy constructor |
| ... | ... |
@@ -207,49 +207,49 @@ |
| 207 | 207 |
tail.reserve(len); |
| 208 | 208 |
for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
|
| 209 | 209 |
tail.push_back(it); |
| 210 | 210 |
} |
| 211 | 211 |
} |
| 212 | 212 |
|
| 213 | 213 |
template <typename CPath> |
| 214 | 214 |
void buildRev(const CPath& path) {
|
| 215 | 215 |
int len = path.length(); |
| 216 | 216 |
head.reserve(len); |
| 217 | 217 |
for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
|
| 218 | 218 |
head.push_back(it); |
| 219 | 219 |
} |
| 220 | 220 |
} |
| 221 | 221 |
|
| 222 | 222 |
protected: |
| 223 | 223 |
typedef std::vector<Arc> Container; |
| 224 | 224 |
Container head, tail; |
| 225 | 225 |
|
| 226 | 226 |
}; |
| 227 | 227 |
|
| 228 | 228 |
/// \brief A structure for representing directed paths in a digraph. |
| 229 | 229 |
/// |
| 230 | 230 |
/// A structure for representing directed path in a digraph. |
| 231 |
/// \ |
|
| 231 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 232 | 232 |
/// |
| 233 | 233 |
/// In a sense, the path can be treated as a list of arcs. The |
| 234 | 234 |
/// lemon path type stores just this list. As a consequence it |
| 235 | 235 |
/// cannot enumerate the nodes in the path and the zero length paths |
| 236 | 236 |
/// cannot store the source. |
| 237 | 237 |
/// |
| 238 | 238 |
/// This implementation is a just back insertable and erasable path |
| 239 | 239 |
/// type. It can be indexed in O(1) time. The back insertion and |
| 240 | 240 |
/// erasure is amortized O(1) time. This implementation is faster |
| 241 | 241 |
/// then the \c Path type because it use just one vector for the |
| 242 | 242 |
/// arcs. |
| 243 | 243 |
template <typename _Digraph> |
| 244 | 244 |
class SimplePath {
|
| 245 | 245 |
public: |
| 246 | 246 |
|
| 247 | 247 |
typedef _Digraph Digraph; |
| 248 | 248 |
typedef typename Digraph::Arc Arc; |
| 249 | 249 |
|
| 250 | 250 |
/// \brief Default constructor |
| 251 | 251 |
/// |
| 252 | 252 |
/// Default constructor |
| 253 | 253 |
SimplePath() {}
|
| 254 | 254 |
|
| 255 | 255 |
/// \brief Template copy constructor |
| ... | ... |
@@ -371,49 +371,49 @@ |
| 371 | 371 |
++index; |
| 372 | 372 |
} |
| 373 | 373 |
} |
| 374 | 374 |
|
| 375 | 375 |
template <typename CPath> |
| 376 | 376 |
void buildRev(const CPath& path) {
|
| 377 | 377 |
int len = path.length(); |
| 378 | 378 |
data.resize(len); |
| 379 | 379 |
int index = len; |
| 380 | 380 |
for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
|
| 381 | 381 |
--index; |
| 382 | 382 |
data[index] = it;; |
| 383 | 383 |
} |
| 384 | 384 |
} |
| 385 | 385 |
|
| 386 | 386 |
protected: |
| 387 | 387 |
typedef std::vector<Arc> Container; |
| 388 | 388 |
Container data; |
| 389 | 389 |
|
| 390 | 390 |
}; |
| 391 | 391 |
|
| 392 | 392 |
/// \brief A structure for representing directed paths in a digraph. |
| 393 | 393 |
/// |
| 394 | 394 |
/// A structure for representing directed path in a digraph. |
| 395 |
/// \ |
|
| 395 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 396 | 396 |
/// |
| 397 | 397 |
/// In a sense, the path can be treated as a list of arcs. The |
| 398 | 398 |
/// lemon path type stores just this list. As a consequence it |
| 399 | 399 |
/// cannot enumerate the nodes in the path and the zero length paths |
| 400 | 400 |
/// cannot store the source. |
| 401 | 401 |
/// |
| 402 | 402 |
/// This implementation is a back and front insertable and erasable |
| 403 | 403 |
/// path type. It can be indexed in O(k) time, where k is the rank |
| 404 | 404 |
/// of the arc in the path. The length can be computed in O(n) |
| 405 | 405 |
/// time. The front and back insertion and erasure is O(1) time |
| 406 | 406 |
/// and it can be splited and spliced in O(1) time. |
| 407 | 407 |
template <typename _Digraph> |
| 408 | 408 |
class ListPath {
|
| 409 | 409 |
public: |
| 410 | 410 |
|
| 411 | 411 |
typedef _Digraph Digraph; |
| 412 | 412 |
typedef typename Digraph::Arc Arc; |
| 413 | 413 |
|
| 414 | 414 |
protected: |
| 415 | 415 |
|
| 416 | 416 |
// the std::list<> is incompatible |
| 417 | 417 |
// hard to create invalid iterator |
| 418 | 418 |
struct Node {
|
| 419 | 419 |
Arc arc; |
| ... | ... |
@@ -711,49 +711,49 @@ |
| 711 | 711 |
} |
| 712 | 712 |
|
| 713 | 713 |
|
| 714 | 714 |
typedef True BuildTag; |
| 715 | 715 |
|
| 716 | 716 |
template <typename CPath> |
| 717 | 717 |
void build(const CPath& path) {
|
| 718 | 718 |
for (typename CPath::ArcIt it(path); it != INVALID; ++it) {
|
| 719 | 719 |
addBack(it); |
| 720 | 720 |
} |
| 721 | 721 |
} |
| 722 | 722 |
|
| 723 | 723 |
template <typename CPath> |
| 724 | 724 |
void buildRev(const CPath& path) {
|
| 725 | 725 |
for (typename CPath::RevArcIt it(path); it != INVALID; ++it) {
|
| 726 | 726 |
addFront(it); |
| 727 | 727 |
} |
| 728 | 728 |
} |
| 729 | 729 |
|
| 730 | 730 |
}; |
| 731 | 731 |
|
| 732 | 732 |
/// \brief A structure for representing directed paths in a digraph. |
| 733 | 733 |
/// |
| 734 | 734 |
/// A structure for representing directed path in a digraph. |
| 735 |
/// \ |
|
| 735 |
/// \tparam _Digraph The digraph type in which the path is. |
|
| 736 | 736 |
/// |
| 737 | 737 |
/// In a sense, the path can be treated as a list of arcs. The |
| 738 | 738 |
/// lemon path type stores just this list. As a consequence it |
| 739 | 739 |
/// cannot enumerate the nodes in the path and the source node of |
| 740 | 740 |
/// a zero length path is undefined. |
| 741 | 741 |
/// |
| 742 | 742 |
/// This implementation is completly static, i.e. it can be copy constucted |
| 743 | 743 |
/// or copy assigned from another path, but otherwise it cannot be |
| 744 | 744 |
/// modified. |
| 745 | 745 |
/// |
| 746 | 746 |
/// Being the the most memory efficient path type in LEMON, |
| 747 | 747 |
/// it is intented to be |
| 748 | 748 |
/// used when you want to store a large number of paths. |
| 749 | 749 |
template <typename _Digraph> |
| 750 | 750 |
class StaticPath {
|
| 751 | 751 |
public: |
| 752 | 752 |
|
| 753 | 753 |
typedef _Digraph Digraph; |
| 754 | 754 |
typedef typename Digraph::Arc Arc; |
| 755 | 755 |
|
| 756 | 756 |
/// \brief Default constructor |
| 757 | 757 |
/// |
| 758 | 758 |
/// Default constructor |
| 759 | 759 |
StaticPath() : len(0), arcs(0) {}
|
| ... | ... |
@@ -181,50 +181,48 @@ |
| 181 | 181 |
arc._id = nodes[node._id].first_in; |
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
void nextIn(Arc& arc) const {
|
| 185 | 185 |
arc._id = arcs[arc._id].next_in; |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
}; |
| 189 | 189 |
|
| 190 | 190 |
typedef DigraphExtender<SmartDigraphBase> ExtendedSmartDigraphBase; |
| 191 | 191 |
|
| 192 | 192 |
///\ingroup graphs |
| 193 | 193 |
/// |
| 194 | 194 |
///\brief A smart directed graph class. |
| 195 | 195 |
/// |
| 196 | 196 |
///This is a simple and fast digraph implementation. |
| 197 | 197 |
///It is also quite memory efficient, but at the price |
| 198 | 198 |
///that <b> it does support only limited (only stack-like) |
| 199 | 199 |
///node and arc deletions</b>. |
| 200 | 200 |
///It conforms to the \ref concepts::Digraph "Digraph concept" with |
| 201 | 201 |
///an important extra feature that its maps are real \ref |
| 202 | 202 |
///concepts::ReferenceMap "reference map"s. |
| 203 | 203 |
/// |
| 204 | 204 |
///\sa concepts::Digraph. |
| 205 |
/// |
|
| 206 |
///\author Alpar Juttner |
|
| 207 | 205 |
class SmartDigraph : public ExtendedSmartDigraphBase {
|
| 208 | 206 |
public: |
| 209 | 207 |
|
| 210 | 208 |
typedef ExtendedSmartDigraphBase Parent; |
| 211 | 209 |
|
| 212 | 210 |
private: |
| 213 | 211 |
|
| 214 | 212 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 215 | 213 |
|
| 216 | 214 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 217 | 215 |
/// |
| 218 | 216 |
SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
|
| 219 | 217 |
///\brief Assignment of SmartDigraph to another one is \e not allowed. |
| 220 | 218 |
///Use DigraphCopy() instead. |
| 221 | 219 |
|
| 222 | 220 |
///Assignment of SmartDigraph to another one is \e not allowed. |
| 223 | 221 |
///Use DigraphCopy() instead. |
| 224 | 222 |
void operator=(const SmartDigraph &) {}
|
| 225 | 223 |
|
| 226 | 224 |
public: |
| 227 | 225 |
|
| 228 | 226 |
/// Constructor |
| 229 | 227 |
|
| 230 | 228 |
/// Constructor. |
| ... | ... |
@@ -35,50 +35,48 @@ |
| 35 | 35 |
|
| 36 | 36 |
#include <string> |
| 37 | 37 |
#include <fstream> |
| 38 | 38 |
#include <iostream> |
| 39 | 39 |
|
| 40 | 40 |
namespace lemon {
|
| 41 | 41 |
|
| 42 | 42 |
/// \addtogroup timecount |
| 43 | 43 |
/// @{
|
| 44 | 44 |
|
| 45 | 45 |
/// A class to store (cpu)time instances. |
| 46 | 46 |
|
| 47 | 47 |
/// This class stores five time values. |
| 48 | 48 |
/// - a real time |
| 49 | 49 |
/// - a user cpu time |
| 50 | 50 |
/// - a system cpu time |
| 51 | 51 |
/// - a user cpu time of children |
| 52 | 52 |
/// - a system cpu time of children |
| 53 | 53 |
/// |
| 54 | 54 |
/// TimeStamp's can be added to or substracted from each other and |
| 55 | 55 |
/// they can be pushed to a stream. |
| 56 | 56 |
/// |
| 57 | 57 |
/// In most cases, perhaps the \ref Timer or the \ref TimeReport |
| 58 | 58 |
/// class is what you want to use instead. |
| 59 |
/// |
|
| 60 |
///\author Alpar Juttner |
|
| 61 | 59 |
|
| 62 | 60 |
class TimeStamp |
| 63 | 61 |
{
|
| 64 | 62 |
double utime; |
| 65 | 63 |
double stime; |
| 66 | 64 |
double cutime; |
| 67 | 65 |
double cstime; |
| 68 | 66 |
double rtime; |
| 69 | 67 |
|
| 70 | 68 |
void _reset() {
|
| 71 | 69 |
utime = stime = cutime = cstime = rtime = 0; |
| 72 | 70 |
} |
| 73 | 71 |
|
| 74 | 72 |
public: |
| 75 | 73 |
|
| 76 | 74 |
///Read the current time values of the process |
| 77 | 75 |
void stamp() |
| 78 | 76 |
{
|
| 79 | 77 |
#ifndef WIN32 |
| 80 | 78 |
timeval tv; |
| 81 | 79 |
gettimeofday(&tv, 0); |
| 82 | 80 |
rtime=tv.tv_sec+double(tv.tv_usec)/1e6; |
| 83 | 81 |
|
| 84 | 82 |
tms ts; |
| ... | ... |
@@ -275,50 +273,48 @@ |
| 275 | 273 |
/// doSomethingElse(); |
| 276 | 274 |
/// std::cout << t << '\n'; |
| 277 | 275 |
/// |
| 278 | 276 |
/// ... |
| 279 | 277 |
/// |
| 280 | 278 |
/// } |
| 281 | 279 |
///\endcode |
| 282 | 280 |
/// |
| 283 | 281 |
///The \ref Timer can also be \ref stop() "stopped" and |
| 284 | 282 |
///\ref start() "started" again, so it is possible to compute collected |
| 285 | 283 |
///running times. |
| 286 | 284 |
/// |
| 287 | 285 |
///\warning Depending on the operation system and its actual configuration |
| 288 | 286 |
///the time counters have a certain (10ms on a typical Linux system) |
| 289 | 287 |
///granularity. |
| 290 | 288 |
///Therefore this tool is not appropriate to measure very short times. |
| 291 | 289 |
///Also, if you start and stop the timer very frequently, it could lead to |
| 292 | 290 |
///distorted results. |
| 293 | 291 |
/// |
| 294 | 292 |
///\note If you want to measure the running time of the execution of a certain |
| 295 | 293 |
///function, consider the usage of \ref TimeReport instead. |
| 296 | 294 |
/// |
| 297 | 295 |
///\todo This shouldn't be Unix (Linux) specific. |
| 298 | 296 |
///\sa TimeReport |
| 299 |
/// |
|
| 300 |
///\author Alpar Juttner |
|
| 301 | 297 |
class Timer |
| 302 | 298 |
{
|
| 303 | 299 |
int _running; //Timer is running iff _running>0; (_running>=0 always holds) |
| 304 | 300 |
TimeStamp start_time; //This is the relativ start-time if the timer |
| 305 | 301 |
//is _running, the collected _running time otherwise. |
| 306 | 302 |
|
| 307 | 303 |
void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
|
| 308 | 304 |
|
| 309 | 305 |
public: |
| 310 | 306 |
///Constructor. |
| 311 | 307 |
|
| 312 | 308 |
///\param run indicates whether or not the timer starts immediately. |
| 313 | 309 |
/// |
| 314 | 310 |
Timer(bool run=true) :_running(run) {_reset();}
|
| 315 | 311 |
|
| 316 | 312 |
///\name Control the state of the timer |
| 317 | 313 |
///Basically a Timer can be either running or stopped, |
| 318 | 314 |
///but it provides a bit finer control on the execution. |
| 319 | 315 |
///The \ref Timer also counts the number of \ref start() |
| 320 | 316 |
///executions, and is stops only after the same amount (or more) |
| 321 | 317 |
///\ref stop() "stop()"s. This can be useful e.g. to compute the running time |
| 322 | 318 |
///of recursive functions. |
| 323 | 319 |
/// |
| 324 | 320 |
|
0 comments (0 inline)