0
16
0
1
1
5
5
1
1
21
26
5
5
1
1
| ... | ... |
@@ -5,49 +5,49 @@ |
| 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 |
/// \ingroup demos |
| 20 | 20 |
/// \file |
| 21 | 21 |
/// \brief Demo of the graph drawing function \ref graphToEps() |
| 22 | 22 |
/// |
| 23 | 23 |
/// This demo program shows examples how to use the function \ref |
| 24 | 24 |
/// graphToEps(). It takes no input but simply creates seven |
| 25 | 25 |
/// <tt>.eps</tt> files demonstrating the capability of \ref |
| 26 | 26 |
/// graphToEps(), and showing how to draw directed graphs, |
| 27 | 27 |
/// how to handle parallel egdes, how to change the properties (like |
| 28 | 28 |
/// color, shape, size, title etc.) of nodes and arcs individually |
| 29 |
/// using appropriate |
|
| 29 |
/// using appropriate graph maps. |
|
| 30 | 30 |
/// |
| 31 | 31 |
/// \include graph_to_eps_demo.cc |
| 32 | 32 |
|
| 33 | 33 |
#include<lemon/list_graph.h> |
| 34 | 34 |
#include<lemon/graph_to_eps.h> |
| 35 | 35 |
#include<lemon/math.h> |
| 36 | 36 |
|
| 37 | 37 |
using namespace std; |
| 38 | 38 |
using namespace lemon; |
| 39 | 39 |
|
| 40 | 40 |
int main() |
| 41 | 41 |
{
|
| 42 | 42 |
Palette palette; |
| 43 | 43 |
Palette paletteW(true); |
| 44 | 44 |
|
| 45 | 45 |
// Create a small digraph |
| 46 | 46 |
ListDigraph g; |
| 47 | 47 |
typedef ListDigraph::Node Node; |
| 48 | 48 |
typedef ListDigraph::NodeIt NodeIt; |
| 49 | 49 |
typedef ListDigraph::Arc Arc; |
| 50 | 50 |
typedef dim2::Point<int> Point; |
| 51 | 51 |
|
| 52 | 52 |
Node n1=g.addNode(); |
| 53 | 53 |
Node n2=g.addNode(); |
| ... | ... |
@@ -57,49 +57,49 @@ |
| 57 | 57 |
|
| 58 | 58 |
\code |
| 59 | 59 |
@nodes |
| 60 | 60 |
label coordinates size title |
| 61 | 61 |
1 (10,20) 10 "First node" |
| 62 | 62 |
2 (80,80) 8 "Second node" |
| 63 | 63 |
3 (40,10) 10 "Third node" |
| 64 | 64 |
\endcode |
| 65 | 65 |
|
| 66 | 66 |
The \c \@arcs section is very similar to the \c \@nodes section, |
| 67 | 67 |
it again starts with a header line describing the names of the maps, |
| 68 | 68 |
but the \c "label" map is not obligatory here. The following lines |
| 69 | 69 |
describe the arcs. The first two tokens of each line are |
| 70 | 70 |
the source and the target node of the arc, respectively, then come the map |
| 71 | 71 |
values. The source and target tokens must be node labels. |
| 72 | 72 |
|
| 73 | 73 |
\code |
| 74 | 74 |
@arcs |
| 75 | 75 |
capacity |
| 76 | 76 |
1 2 16 |
| 77 | 77 |
1 3 12 |
| 78 | 78 |
2 3 18 |
| 79 | 79 |
\endcode |
| 80 | 80 |
|
| 81 |
The \c \@edges is just a synonym of \c \@arcs. The @arcs section can |
|
| 81 |
The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can |
|
| 82 | 82 |
also store the edge set of an undirected graph. In such case there is |
| 83 | 83 |
a conventional method for store arc maps in the file, if two columns |
| 84 | 84 |
has the same caption with \c '+' and \c '-' prefix, then these columns |
| 85 | 85 |
can be regarded as the values of an arc map. |
| 86 | 86 |
|
| 87 | 87 |
The \c \@attributes section contains key-value pairs, each line |
| 88 | 88 |
consists of two tokens, an attribute name, and then an attribute |
| 89 | 89 |
value. The value of the attribute could be also a label value of a |
| 90 | 90 |
node or an edge, or even an edge label prefixed with \c '+' or \c '-', |
| 91 | 91 |
which regards to the forward or backward directed arc of the |
| 92 | 92 |
corresponding edge. |
| 93 | 93 |
|
| 94 | 94 |
\code |
| 95 | 95 |
@attributes |
| 96 | 96 |
source 1 |
| 97 | 97 |
target 3 |
| 98 | 98 |
caption "LEMON test digraph" |
| 99 | 99 |
\endcode |
| 100 | 100 |
|
| 101 | 101 |
The \e LGF can contain extra sections, but there is no restriction on |
| 102 | 102 |
the format of such sections. |
| 103 | 103 |
|
| 104 | 104 |
*/ |
| 105 | 105 |
} |
| ... | ... |
@@ -58,50 +58,49 @@ |
| 58 | 58 |
/// about each alteration in the container. The alterations have four type |
| 59 | 59 |
/// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and |
| 60 | 60 |
/// \e erase() signals that only one or few items added or erased to or |
| 61 | 61 |
/// from the graph. If all items are erased from the graph or from an empty |
| 62 | 62 |
/// graph a new graph is builded then it can be signaled with the |
| 63 | 63 |
/// clear() and build() members. Important rule that if we erase items |
| 64 | 64 |
/// from graph we should first signal the alteration and after that erase |
| 65 | 65 |
/// them from the container, on the other way on item addition we should |
| 66 | 66 |
/// first extend the container and just after that signal the alteration. |
| 67 | 67 |
/// |
| 68 | 68 |
/// The alteration can be observed with a class inherited from the |
| 69 | 69 |
/// \e ObserverBase nested class. The signals can be handled with |
| 70 | 70 |
/// overriding the virtual functions defined in the base class. The |
| 71 | 71 |
/// observer base can be attached to the notifier with the |
| 72 | 72 |
/// \e attach() member and can be detached with detach() function. The |
| 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 |
/// exception. Actullay, it can be throw only |
|
| 83 |
/// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
|
| 82 |
/// exception. Actullay, it can be throw only \ref ImmediateDetach |
|
| 84 | 83 |
/// exception which detach the observer from the notifier. |
| 85 | 84 |
/// |
| 86 | 85 |
/// There are some place when the alteration observing is not completly |
| 87 | 86 |
/// reliable. If we want to carry out the node degree in the graph |
| 88 | 87 |
/// as in the \ref InDegMap and we use the reverseEdge that cause |
| 89 | 88 |
/// unreliable functionality. Because the alteration observing signals |
| 90 | 89 |
/// only erasing and adding but not the reversing it will stores bad |
| 91 | 90 |
/// degrees. The sub graph adaptors cannot signal the alterations because |
| 92 | 91 |
/// just a setting in the filter map can modify the graph and this cannot |
| 93 | 92 |
/// be watched in any way. |
| 94 | 93 |
/// |
| 95 | 94 |
/// \param _Container The container which is observed. |
| 96 | 95 |
/// \param _Item The item type which is obserbved. |
| 97 | 96 |
|
| 98 | 97 |
template <typename _Container, typename _Item> |
| 99 | 98 |
class AlterationNotifier {
|
| 100 | 99 |
public: |
| 101 | 100 |
|
| 102 | 101 |
typedef True Notifier; |
| 103 | 102 |
|
| 104 | 103 |
typedef _Container Container; |
| 105 | 104 |
typedef _Item Item; |
| 106 | 105 |
|
| 107 | 106 |
/// \brief Exception which can be called from \e clear() and |
| ... | ... |
@@ -128,49 +128,49 @@ |
| 128 | 128 |
|
| 129 | 129 |
|
| 130 | 130 |
// long double |
| 131 | 131 |
template <typename _Graph, typename _Item> |
| 132 | 132 |
struct DefaultMapSelector<_Graph, _Item, long double> {
|
| 133 | 133 |
typedef VectorMap<_Graph, _Item, long double> Map; |
| 134 | 134 |
}; |
| 135 | 135 |
|
| 136 | 136 |
|
| 137 | 137 |
// pointer |
| 138 | 138 |
template <typename _Graph, typename _Item, typename _Ptr> |
| 139 | 139 |
struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
|
| 140 | 140 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map; |
| 141 | 141 |
}; |
| 142 | 142 |
|
| 143 | 143 |
// #else |
| 144 | 144 |
|
| 145 | 145 |
// template <typename _Graph, typename _Item, typename _Value> |
| 146 | 146 |
// struct DefaultMapSelector {
|
| 147 | 147 |
// typedef DebugMap<_Graph, _Item, _Value> Map; |
| 148 | 148 |
// }; |
| 149 | 149 |
|
| 150 | 150 |
// #endif |
| 151 | 151 |
|
| 152 |
/// |
|
| 152 |
/// DefaultMap class |
|
| 153 | 153 |
template <typename _Graph, typename _Item, typename _Value> |
| 154 | 154 |
class DefaultMap |
| 155 | 155 |
: public DefaultMapSelector<_Graph, _Item, _Value>::Map {
|
| 156 | 156 |
public: |
| 157 | 157 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; |
| 158 | 158 |
typedef DefaultMap<_Graph, _Item, _Value> Map; |
| 159 | 159 |
|
| 160 | 160 |
typedef typename Parent::Graph Graph; |
| 161 | 161 |
typedef typename Parent::Value Value; |
| 162 | 162 |
|
| 163 | 163 |
explicit DefaultMap(const Graph& graph) : Parent(graph) {}
|
| 164 | 164 |
DefaultMap(const Graph& graph, const Value& value) |
| 165 | 165 |
: Parent(graph, value) {}
|
| 166 | 166 |
|
| 167 | 167 |
DefaultMap& operator=(const DefaultMap& cmap) {
|
| 168 | 168 |
return operator=<DefaultMap>(cmap); |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
template <typename CMap> |
| 172 | 172 |
DefaultMap& operator=(const CMap& cmap) {
|
| 173 | 173 |
Parent::operator=(cmap); |
| 174 | 174 |
return *this; |
| 175 | 175 |
} |
| 176 | 176 |
| ... | ... |
@@ -71,49 +71,49 @@ |
| 71 | 71 |
extern const Color GREEN; |
| 72 | 72 |
/// Blue color constant |
| 73 | 73 |
extern const Color BLUE; |
| 74 | 74 |
/// Yellow color constant |
| 75 | 75 |
extern const Color YELLOW; |
| 76 | 76 |
/// Magenta color constant |
| 77 | 77 |
extern const Color MAGENTA; |
| 78 | 78 |
/// Cyan color constant |
| 79 | 79 |
extern const Color CYAN; |
| 80 | 80 |
/// Grey color constant |
| 81 | 81 |
extern const Color GREY; |
| 82 | 82 |
/// Dark red color constant |
| 83 | 83 |
extern const Color DARK_RED; |
| 84 | 84 |
/// Dark green color constant |
| 85 | 85 |
extern const Color DARK_GREEN; |
| 86 | 86 |
/// Drak blue color constant |
| 87 | 87 |
extern const Color DARK_BLUE; |
| 88 | 88 |
/// Dark yellow color constant |
| 89 | 89 |
extern const Color DARK_YELLOW; |
| 90 | 90 |
/// Dark magenta color constant |
| 91 | 91 |
extern const Color DARK_MAGENTA; |
| 92 | 92 |
/// Dark cyan color constant |
| 93 | 93 |
extern const Color DARK_CYAN; |
| 94 | 94 |
|
| 95 |
///Map <tt>int</tt>s to different |
|
| 95 |
///Map <tt>int</tt>s to different <tt>Color</tt>s |
|
| 96 | 96 |
|
| 97 | 97 |
///This map assigns one of the predefined \ref Color "Color"s to |
| 98 | 98 |
///each <tt>int</tt>. It is possible to change the colors as well as |
| 99 | 99 |
///their number. The integer range is cyclically mapped to the |
| 100 | 100 |
///provided set of colors. |
| 101 | 101 |
/// |
| 102 | 102 |
///This is a true \ref concepts::ReferenceMap "reference map", so |
| 103 | 103 |
///you can also change the actual colors. |
| 104 | 104 |
|
| 105 | 105 |
class Palette : public MapBase<int,Color> |
| 106 | 106 |
{
|
| 107 | 107 |
std::vector<Color> colors; |
| 108 | 108 |
public: |
| 109 | 109 |
///Constructor |
| 110 | 110 |
|
| 111 | 111 |
///Constructor. |
| 112 | 112 |
///\param have_white Indicates whether white is among the |
| 113 | 113 |
///provided initial colors (\c true) or not (\c false). If it is true, |
| 114 | 114 |
///white will be assigned to \c 0. |
| 115 | 115 |
///\param num The number of the allocated colors. If it is \c -1, |
| 116 | 116 |
///the default color configuration is set up (26 color plus optionaly the |
| 117 | 117 |
///white). If \c num is less then 26/27 then the default color |
| 118 | 118 |
///list is cut. Otherwise the color list is filled repeatedly with |
| 119 | 119 |
///the default color list. (The colors can be changed later on.) |
| ... | ... |
@@ -961,49 +961,49 @@ |
| 961 | 961 |
/// |
| 962 | 962 |
/// Gives back the arc alteration notifier. |
| 963 | 963 |
EdgeNotifier& notifier(Edge) const {
|
| 964 | 964 |
return EdgeNotifier(); |
| 965 | 965 |
} |
| 966 | 966 |
|
| 967 | 967 |
template <typename _Graph> |
| 968 | 968 |
struct Constraints {
|
| 969 | 969 |
void constraints() {
|
| 970 | 970 |
checkConcept<AlterableGraphComponent<Base>, _Graph>(); |
| 971 | 971 |
typename _Graph::EdgeNotifier& uen |
| 972 | 972 |
= graph.notifier(typename _Graph::Edge()); |
| 973 | 973 |
ignore_unused_variable_warning(uen); |
| 974 | 974 |
} |
| 975 | 975 |
|
| 976 | 976 |
const _Graph& graph; |
| 977 | 977 |
|
| 978 | 978 |
}; |
| 979 | 979 |
|
| 980 | 980 |
}; |
| 981 | 981 |
|
| 982 | 982 |
/// \brief Class describing the concept of graph maps |
| 983 | 983 |
/// |
| 984 | 984 |
/// This class describes the common interface of the graph maps |
| 985 |
/// (NodeMap, ArcMap), that is |
|
| 985 |
/// (NodeMap, ArcMap), that is maps that can be used to |
|
| 986 | 986 |
/// associate data to graph descriptors (nodes or arcs). |
| 987 | 987 |
template <typename _Graph, typename _Item, typename _Value> |
| 988 | 988 |
class GraphMap : public ReadWriteMap<_Item, _Value> {
|
| 989 | 989 |
public: |
| 990 | 990 |
|
| 991 | 991 |
typedef ReadWriteMap<_Item, _Value> Parent; |
| 992 | 992 |
|
| 993 | 993 |
/// The graph type of the map. |
| 994 | 994 |
typedef _Graph Graph; |
| 995 | 995 |
/// The key type of the map. |
| 996 | 996 |
typedef _Item Key; |
| 997 | 997 |
/// The value type of the map. |
| 998 | 998 |
typedef _Value Value; |
| 999 | 999 |
|
| 1000 | 1000 |
/// \brief Construct a new map. |
| 1001 | 1001 |
/// |
| 1002 | 1002 |
/// Construct a new map for the graph. |
| 1003 | 1003 |
explicit GraphMap(const Graph&) {}
|
| 1004 | 1004 |
/// \brief Construct a new map with default value. |
| 1005 | 1005 |
/// |
| 1006 | 1006 |
/// Construct a new map for the graph and initalise the values. |
| 1007 | 1007 |
GraphMap(const Graph&, const Value&) {}
|
| 1008 | 1008 |
|
| 1009 | 1009 |
private: |
| ... | ... |
@@ -1533,49 +1533,49 @@ |
| 1533 | 1533 |
///\param s The source node. |
| 1534 | 1534 |
///\param t The target node. |
| 1535 | 1535 |
///\param p The previous arc between \c s and \c t. It it is INVALID or |
| 1536 | 1536 |
///not given, the operator finds the first appropriate arc. |
| 1537 | 1537 |
///\return An arc from \c s to \c t after \c p or |
| 1538 | 1538 |
///\ref INVALID if there is no more. |
| 1539 | 1539 |
/// |
| 1540 | 1540 |
///For example, you can count the number of arcs from \c u to \c v in the |
| 1541 | 1541 |
///following way. |
| 1542 | 1542 |
///\code |
| 1543 | 1543 |
///DynArcLookUp<ListDigraph> ae(g); |
| 1544 | 1544 |
///... |
| 1545 | 1545 |
///int n = 0; |
| 1546 | 1546 |
///for(Arc a = ae(u,v); a != INVALID; a = ae(u,v,a)) n++; |
| 1547 | 1547 |
///\endcode |
| 1548 | 1548 |
/// |
| 1549 | 1549 |
///Finding the arcs take at most <em>O</em>(log<em>d</em>) |
| 1550 | 1550 |
///amortized time, specifically, the time complexity of the lookups |
| 1551 | 1551 |
///is equal to the optimal search tree implementation for the |
| 1552 | 1552 |
///current query distribution in a constant factor. |
| 1553 | 1553 |
/// |
| 1554 | 1554 |
///\note This is a dynamic data structure, therefore the data |
| 1555 | 1555 |
///structure is updated after each graph alteration. Thus although |
| 1556 | 1556 |
///this data structure is theoretically faster than \ref ArcLookUp |
| 1557 |
///and \ref |
|
| 1557 |
///and \ref AllArcLookUp, it often provides worse performance than |
|
| 1558 | 1558 |
///them. |
| 1559 | 1559 |
Arc operator()(Node s, Node t, Arc p = INVALID) const {
|
| 1560 | 1560 |
if (p == INVALID) {
|
| 1561 | 1561 |
Arc a = _head[s]; |
| 1562 | 1562 |
if (a == INVALID) return INVALID; |
| 1563 | 1563 |
Arc r = INVALID; |
| 1564 | 1564 |
while (true) {
|
| 1565 | 1565 |
if (_g.target(a) < t) {
|
| 1566 | 1566 |
if (_right[a] == INVALID) {
|
| 1567 | 1567 |
const_cast<DynArcLookUp&>(*this).splay(a); |
| 1568 | 1568 |
return r; |
| 1569 | 1569 |
} else {
|
| 1570 | 1570 |
a = _right[a]; |
| 1571 | 1571 |
} |
| 1572 | 1572 |
} else {
|
| 1573 | 1573 |
if (_g.target(a) == t) {
|
| 1574 | 1574 |
r = a; |
| 1575 | 1575 |
} |
| 1576 | 1576 |
if (_left[a] == INVALID) {
|
| 1577 | 1577 |
const_cast<DynArcLookUp&>(*this).splay(a); |
| 1578 | 1578 |
return r; |
| 1579 | 1579 |
} else {
|
| 1580 | 1580 |
a = _left[a]; |
| 1581 | 1581 |
} |
| ... | ... |
@@ -1678,50 +1678,50 @@ |
| 1678 | 1678 |
{
|
| 1679 | 1679 |
std::vector<Arc> v; |
| 1680 | 1680 |
for(OutArcIt e(_g,n);e!=INVALID;++e) v.push_back(e); |
| 1681 | 1681 |
if(v.size()) {
|
| 1682 | 1682 |
std::sort(v.begin(),v.end(),ArcLess(_g)); |
| 1683 | 1683 |
_head[n]=refreshRec(v,0,v.size()-1); |
| 1684 | 1684 |
} |
| 1685 | 1685 |
else _head[n]=INVALID; |
| 1686 | 1686 |
} |
| 1687 | 1687 |
///Refresh the full data structure. |
| 1688 | 1688 |
|
| 1689 | 1689 |
///Build up the full search database. In fact, it simply calls |
| 1690 | 1690 |
///\ref refresh(Node) "refresh(n)" for each node \c n. |
| 1691 | 1691 |
/// |
| 1692 | 1692 |
///It runs in time <em>O</em>(<em>m</em> log<em>D</em>), where <em>m</em> is |
| 1693 | 1693 |
///the number of the arcs in the digraph and <em>D</em> is the maximum |
| 1694 | 1694 |
///out-degree of the digraph. |
| 1695 | 1695 |
void refresh() |
| 1696 | 1696 |
{
|
| 1697 | 1697 |
for(NodeIt n(_g);n!=INVALID;++n) refresh(n); |
| 1698 | 1698 |
} |
| 1699 | 1699 |
|
| 1700 | 1700 |
///Find an arc between two nodes. |
| 1701 | 1701 |
|
| 1702 |
///Find an arc between two nodes in time <em>O</em>(log<em>d</em>), where |
|
| 1703 |
///<em>d</em> is the number of outgoing arcs of \c s. |
|
| 1702 |
///Find an arc between two nodes in time <em>O</em>(log<em>d</em>), |
|
| 1703 |
///where <em>d</em> is the number of outgoing arcs of \c s. |
|
| 1704 | 1704 |
///\param s The source node. |
| 1705 | 1705 |
///\param t The target node. |
| 1706 | 1706 |
///\return An arc from \c s to \c t if there exists, |
| 1707 | 1707 |
///\ref INVALID otherwise. |
| 1708 | 1708 |
/// |
| 1709 | 1709 |
///\warning If you change the digraph, refresh() must be called before using |
| 1710 | 1710 |
///this operator. If you change the outgoing arcs of |
| 1711 | 1711 |
///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. |
| 1712 | 1712 |
Arc operator()(Node s, Node t) const |
| 1713 | 1713 |
{
|
| 1714 | 1714 |
Arc e; |
| 1715 | 1715 |
for(e=_head[s]; |
| 1716 | 1716 |
e!=INVALID&&_g.target(e)!=t; |
| 1717 | 1717 |
e = t < _g.target(e)?_left[e]:_right[e]) ; |
| 1718 | 1718 |
return e; |
| 1719 | 1719 |
} |
| 1720 | 1720 |
|
| 1721 | 1721 |
}; |
| 1722 | 1722 |
|
| 1723 | 1723 |
///Fast look-up of all arcs between given endpoints. |
| 1724 | 1724 |
|
| 1725 | 1725 |
///This class is the same as \ref ArcLookUp, with the addition |
| 1726 | 1726 |
///that it makes it possible to find all parallel arcs between given |
| 1727 | 1727 |
///endpoints. |
| ... | ... |
@@ -1796,49 +1796,49 @@ |
| 1796 | 1796 |
void refresh() |
| 1797 | 1797 |
{
|
| 1798 | 1798 |
for(NodeIt n(_g);n!=INVALID;++n) refresh(_head[n]); |
| 1799 | 1799 |
} |
| 1800 | 1800 |
|
| 1801 | 1801 |
///Find an arc between two nodes. |
| 1802 | 1802 |
|
| 1803 | 1803 |
///Find an arc between two nodes. |
| 1804 | 1804 |
///\param s The source node. |
| 1805 | 1805 |
///\param t The target node. |
| 1806 | 1806 |
///\param prev The previous arc between \c s and \c t. It it is INVALID or |
| 1807 | 1807 |
///not given, the operator finds the first appropriate arc. |
| 1808 | 1808 |
///\return An arc from \c s to \c t after \c prev or |
| 1809 | 1809 |
///\ref INVALID if there is no more. |
| 1810 | 1810 |
/// |
| 1811 | 1811 |
///For example, you can count the number of arcs from \c u to \c v in the |
| 1812 | 1812 |
///following way. |
| 1813 | 1813 |
///\code |
| 1814 | 1814 |
///AllArcLookUp<ListDigraph> ae(g); |
| 1815 | 1815 |
///... |
| 1816 | 1816 |
///int n = 0; |
| 1817 | 1817 |
///for(Arc a = ae(u,v); a != INVALID; a=ae(u,v,a)) n++; |
| 1818 | 1818 |
///\endcode |
| 1819 | 1819 |
/// |
| 1820 |
///Finding the first arc take <em>O</em>(log<em>d</em>) time, where |
|
| 1821 |
///<em>d</em> is the number of outgoing arcs of \c s. Then, the |
|
| 1820 |
///Finding the first arc take <em>O</em>(log<em>d</em>) time, |
|
| 1821 |
///where <em>d</em> is the number of outgoing arcs of \c s. Then the |
|
| 1822 | 1822 |
///consecutive arcs are found in constant time. |
| 1823 | 1823 |
/// |
| 1824 | 1824 |
///\warning If you change the digraph, refresh() must be called before using |
| 1825 | 1825 |
///this operator. If you change the outgoing arcs of |
| 1826 | 1826 |
///a single node \c n, then \ref refresh(Node) "refresh(n)" is enough. |
| 1827 | 1827 |
/// |
| 1828 | 1828 |
#ifdef DOXYGEN |
| 1829 | 1829 |
Arc operator()(Node s, Node t, Arc prev=INVALID) const {}
|
| 1830 | 1830 |
#else |
| 1831 | 1831 |
using ArcLookUp<G>::operator() ; |
| 1832 | 1832 |
Arc operator()(Node s, Node t, Arc prev) const |
| 1833 | 1833 |
{
|
| 1834 | 1834 |
return prev==INVALID?(*this)(s,t):_next[prev]; |
| 1835 | 1835 |
} |
| 1836 | 1836 |
#endif |
| 1837 | 1837 |
|
| 1838 | 1838 |
}; |
| 1839 | 1839 |
|
| 1840 | 1840 |
/// @} |
| 1841 | 1841 |
|
| 1842 | 1842 |
} //namespace lemon |
| 1843 | 1843 |
|
| 1844 | 1844 |
#endif |
| ... | ... |
@@ -814,49 +814,49 @@ |
| 814 | 814 |
} |
| 815 | 815 |
|
| 816 | 816 |
///The type of the map that stores the distances of the nodes. |
| 817 | 817 |
|
| 818 | 818 |
///The type of the map that stores the distances of the nodes. |
| 819 | 819 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 820 | 820 |
typedef typename Digraph::template NodeMap<int> DistMap; |
| 821 | 821 |
///Instantiates a DistMap. |
| 822 | 822 |
|
| 823 | 823 |
///This function instantiates a DistMap. |
| 824 | 824 |
///\param g is the digraph, to which we would like to define |
| 825 | 825 |
///the DistMap |
| 826 | 826 |
static DistMap *createDistMap(const Digraph &g) |
| 827 | 827 |
{
|
| 828 | 828 |
return new DistMap(g); |
| 829 | 829 |
} |
| 830 | 830 |
|
| 831 | 831 |
///The type of the DFS paths. |
| 832 | 832 |
|
| 833 | 833 |
///The type of the DFS paths. |
| 834 | 834 |
///It must meet the \ref concepts::Path "Path" concept. |
| 835 | 835 |
typedef lemon::Path<Digraph> Path; |
| 836 | 836 |
}; |
| 837 | 837 |
|
| 838 |
/// Default traits class used by |
|
| 838 |
/// Default traits class used by DfsWizard |
|
| 839 | 839 |
|
| 840 | 840 |
/// To make it easier to use Dfs algorithm |
| 841 | 841 |
/// we have created a wizard class. |
| 842 | 842 |
/// This \ref DfsWizard class needs default traits, |
| 843 | 843 |
/// as well as the \ref Dfs class. |
| 844 | 844 |
/// The \ref DfsWizardBase is a class to be the default traits of the |
| 845 | 845 |
/// \ref DfsWizard class. |
| 846 | 846 |
template<class GR> |
| 847 | 847 |
class DfsWizardBase : public DfsWizardDefaultTraits<GR> |
| 848 | 848 |
{
|
| 849 | 849 |
|
| 850 | 850 |
typedef DfsWizardDefaultTraits<GR> Base; |
| 851 | 851 |
protected: |
| 852 | 852 |
//The type of the nodes in the digraph. |
| 853 | 853 |
typedef typename Base::Digraph::Node Node; |
| 854 | 854 |
|
| 855 | 855 |
//Pointer to the digraph the algorithm runs on. |
| 856 | 856 |
void *_g; |
| 857 | 857 |
//Pointer to the map of reached nodes. |
| 858 | 858 |
void *_reached; |
| 859 | 859 |
//Pointer to the map of processed nodes. |
| 860 | 860 |
void *_processed; |
| 861 | 861 |
//Pointer to the map of predecessors arcs. |
| 862 | 862 |
void *_pred; |
| ... | ... |
@@ -432,49 +432,49 @@ |
| 432 | 432 |
{
|
| 433 | 433 |
return new Heap(R); |
| 434 | 434 |
} |
| 435 | 435 |
}; |
| 436 | 436 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 437 | 437 |
///heap and cross reference type with automatic allocation |
| 438 | 438 |
/// |
| 439 | 439 |
///\ref named-templ-param "Named parameter" for setting heap and cross |
| 440 | 440 |
///reference type. It can allocate the heap and the cross reference |
| 441 | 441 |
///object if the cross reference's constructor waits for the digraph as |
| 442 | 442 |
///parameter and the heap's constructor waits for the cross reference. |
| 443 | 443 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
| 444 | 444 |
struct SetStandardHeap |
| 445 | 445 |
: public Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> > {
|
| 446 | 446 |
typedef Dijkstra< Digraph, LengthMap, SetStandardHeapTraits<H, CR> > |
| 447 | 447 |
Create; |
| 448 | 448 |
}; |
| 449 | 449 |
|
| 450 | 450 |
template <class T> |
| 451 | 451 |
struct SetOperationTraitsTraits : public Traits {
|
| 452 | 452 |
typedef T OperationTraits; |
| 453 | 453 |
}; |
| 454 | 454 |
|
| 455 | 455 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 456 |
///\ |
|
| 456 |
///\c OperationTraits type |
|
| 457 | 457 |
/// |
| 458 | 458 |
///\ref named-templ-param "Named parameter" for setting |
| 459 | 459 |
///\ref OperationTraits type. |
| 460 | 460 |
template <class T> |
| 461 | 461 |
struct SetOperationTraits |
| 462 | 462 |
: public Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > {
|
| 463 | 463 |
typedef Dijkstra<Digraph, LengthMap, SetOperationTraitsTraits<T> > |
| 464 | 464 |
Create; |
| 465 | 465 |
}; |
| 466 | 466 |
|
| 467 | 467 |
///@} |
| 468 | 468 |
|
| 469 | 469 |
protected: |
| 470 | 470 |
|
| 471 | 471 |
Dijkstra() {}
|
| 472 | 472 |
|
| 473 | 473 |
public: |
| 474 | 474 |
|
| 475 | 475 |
///Constructor. |
| 476 | 476 |
|
| 477 | 477 |
///Constructor. |
| 478 | 478 |
///\param _g The digraph the algorithm runs on. |
| 479 | 479 |
///\param _length The length map used by the algorithm. |
| 480 | 480 |
Dijkstra(const Digraph& _g, const LengthMap& _length) : |
| ... | ... |
@@ -1017,49 +1017,49 @@ |
| 1017 | 1017 |
} |
| 1018 | 1018 |
|
| 1019 | 1019 |
///The type of the map that stores the distances of the nodes. |
| 1020 | 1020 |
|
| 1021 | 1021 |
///The type of the map that stores the distances of the nodes. |
| 1022 | 1022 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
| 1023 | 1023 |
typedef typename Digraph::template NodeMap<typename LM::Value> DistMap; |
| 1024 | 1024 |
///Instantiates a DistMap. |
| 1025 | 1025 |
|
| 1026 | 1026 |
///This function instantiates a DistMap. |
| 1027 | 1027 |
///\param g is the digraph, to which we would like to define |
| 1028 | 1028 |
///the DistMap |
| 1029 | 1029 |
static DistMap *createDistMap(const Digraph &g) |
| 1030 | 1030 |
{
|
| 1031 | 1031 |
return new DistMap(g); |
| 1032 | 1032 |
} |
| 1033 | 1033 |
|
| 1034 | 1034 |
///The type of the shortest paths. |
| 1035 | 1035 |
|
| 1036 | 1036 |
///The type of the shortest paths. |
| 1037 | 1037 |
///It must meet the \ref concepts::Path "Path" concept. |
| 1038 | 1038 |
typedef lemon::Path<Digraph> Path; |
| 1039 | 1039 |
}; |
| 1040 | 1040 |
|
| 1041 |
/// Default traits class used by |
|
| 1041 |
/// Default traits class used by DijkstraWizard |
|
| 1042 | 1042 |
|
| 1043 | 1043 |
/// To make it easier to use Dijkstra algorithm |
| 1044 | 1044 |
/// we have created a wizard class. |
| 1045 | 1045 |
/// This \ref DijkstraWizard class needs default traits, |
| 1046 | 1046 |
/// as well as the \ref Dijkstra class. |
| 1047 | 1047 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
| 1048 | 1048 |
/// \ref DijkstraWizard class. |
| 1049 | 1049 |
template<class GR,class LM> |
| 1050 | 1050 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM> |
| 1051 | 1051 |
{
|
| 1052 | 1052 |
typedef DijkstraWizardDefaultTraits<GR,LM> Base; |
| 1053 | 1053 |
protected: |
| 1054 | 1054 |
//The type of the nodes in the digraph. |
| 1055 | 1055 |
typedef typename Base::Digraph::Node Node; |
| 1056 | 1056 |
|
| 1057 | 1057 |
//Pointer to the digraph the algorithm runs on. |
| 1058 | 1058 |
void *_g; |
| 1059 | 1059 |
//Pointer to the length map. |
| 1060 | 1060 |
void *_length; |
| 1061 | 1061 |
//Pointer to the map of processed nodes. |
| 1062 | 1062 |
void *_processed; |
| 1063 | 1063 |
//Pointer to the map of predecessors arcs. |
| 1064 | 1064 |
void *_pred; |
| 1065 | 1065 |
//Pointer to the map of distances. |
| ... | ... |
@@ -238,52 +238,52 @@ |
| 238 | 238 |
///Rotate by 180 degrees |
| 239 | 239 |
|
| 240 | 240 |
///Returns the parameter rotated by 180 degrees. |
| 241 | 241 |
///\relates Point |
| 242 | 242 |
/// |
| 243 | 243 |
template<typename T> |
| 244 | 244 |
inline Point<T> rot180(const Point<T> &z) |
| 245 | 245 |
{
|
| 246 | 246 |
return Point<T>(-z.x,-z.y); |
| 247 | 247 |
} |
| 248 | 248 |
|
| 249 | 249 |
///Rotate by 270 degrees |
| 250 | 250 |
|
| 251 | 251 |
///Returns the parameter rotated by 90 degrees in negative direction. |
| 252 | 252 |
///\relates Point |
| 253 | 253 |
/// |
| 254 | 254 |
template<typename T> |
| 255 | 255 |
inline Point<T> rot270(const Point<T> &z) |
| 256 | 256 |
{
|
| 257 | 257 |
return Point<T>(z.y,-z.x); |
| 258 | 258 |
} |
| 259 | 259 |
|
| 260 | 260 |
|
| 261 | 261 |
|
| 262 |
/// Bounding box of plain vectors ( |
|
| 262 |
/// Bounding box of plain vectors (points). |
|
| 263 | 263 |
|
| 264 | 264 |
/// A class to calculate or store the bounding box of plain vectors |
| 265 |
/// (\ref Point points). |
|
| 265 |
/// (\ref Point "points"). |
|
| 266 | 266 |
template<typename T> |
| 267 | 267 |
class Box {
|
| 268 | 268 |
Point<T> _bottom_left, _top_right; |
| 269 | 269 |
bool _empty; |
| 270 | 270 |
public: |
| 271 | 271 |
|
| 272 | 272 |
///Default constructor: creates an empty box |
| 273 | 273 |
Box() { _empty = true; }
|
| 274 | 274 |
|
| 275 | 275 |
///Construct a box from one point |
| 276 | 276 |
Box(Point<T> a) {
|
| 277 | 277 |
_bottom_left = _top_right = a; |
| 278 | 278 |
_empty = false; |
| 279 | 279 |
} |
| 280 | 280 |
|
| 281 | 281 |
///Construct a box from two points |
| 282 | 282 |
|
| 283 | 283 |
///Construct a box from two points. |
| 284 | 284 |
///\param a The bottom left corner. |
| 285 | 285 |
///\param b The top right corner. |
| 286 | 286 |
///\warning The coordinates of the bottom left corner must be no more |
| 287 | 287 |
///than those of the top right one. |
| 288 | 288 |
Box(Point<T> a,Point<T> b) |
| 289 | 289 |
{
|
| ... | ... |
@@ -552,197 +552,192 @@ |
| 552 | 552 |
} else {
|
| 553 | 553 |
is.clear(); |
| 554 | 554 |
} |
| 555 | 555 |
if (!(is >> p)) return is; |
| 556 | 556 |
b.topRight(p); |
| 557 | 557 |
if (is >> c) {
|
| 558 | 558 |
if (c != ')') is.putback(c); |
| 559 | 559 |
} else {
|
| 560 | 560 |
is.clear(); |
| 561 | 561 |
} |
| 562 | 562 |
return is; |
| 563 | 563 |
} |
| 564 | 564 |
|
| 565 | 565 |
///Write a box to a stream |
| 566 | 566 |
|
| 567 | 567 |
///Write a box to a stream. |
| 568 | 568 |
///\relates Box |
| 569 | 569 |
template<typename T> |
| 570 | 570 |
inline std::ostream& operator<<(std::ostream &os, const Box<T>& b) |
| 571 | 571 |
{
|
| 572 | 572 |
os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
|
| 573 | 573 |
return os; |
| 574 | 574 |
} |
| 575 | 575 |
|
| 576 |
///Map of x-coordinates of a |
|
| 576 |
///Map of x-coordinates of a <tt>Point</tt>-map |
|
| 577 | 577 |
|
| 578 |
///Map of x-coordinates of a \ref Point "Point"-map. |
|
| 578 | 579 |
///\ingroup maps |
| 579 |
///Map of x-coordinates of a \ref Point "Point"-map. |
|
| 580 |
/// |
|
| 581 | 580 |
template<class M> |
| 582 | 581 |
class XMap |
| 583 | 582 |
{
|
| 584 | 583 |
M& _map; |
| 585 | 584 |
public: |
| 586 | 585 |
|
| 587 | 586 |
typedef typename M::Value::Value Value; |
| 588 | 587 |
typedef typename M::Key Key; |
| 589 | 588 |
///\e |
| 590 | 589 |
XMap(M& map) : _map(map) {}
|
| 591 | 590 |
Value operator[](Key k) const {return _map[k].x;}
|
| 592 | 591 |
void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
|
| 593 | 592 |
}; |
| 594 | 593 |
|
| 595 |
///Returns an |
|
| 594 |
///Returns an XMap class |
|
| 596 | 595 |
|
| 597 |
///This function just returns an |
|
| 596 |
///This function just returns an XMap class. |
|
| 598 | 597 |
/// |
| 599 | 598 |
///\ingroup maps |
| 600 | 599 |
///\relates XMap |
| 601 | 600 |
template<class M> |
| 602 | 601 |
inline XMap<M> xMap(M &m) |
| 603 | 602 |
{
|
| 604 | 603 |
return XMap<M>(m); |
| 605 | 604 |
} |
| 606 | 605 |
|
| 607 | 606 |
template<class M> |
| 608 | 607 |
inline XMap<M> xMap(const M &m) |
| 609 | 608 |
{
|
| 610 | 609 |
return XMap<M>(m); |
| 611 | 610 |
} |
| 612 | 611 |
|
| 613 |
///Constant (read only) version of |
|
| 612 |
///Constant (read only) version of XMap |
|
| 614 | 613 |
|
| 614 |
///Constant (read only) version of XMap. |
|
| 615 | 615 |
///\ingroup maps |
| 616 |
///Constant (read only) version of \ref XMap |
|
| 617 |
/// |
|
| 618 | 616 |
template<class M> |
| 619 | 617 |
class ConstXMap |
| 620 | 618 |
{
|
| 621 | 619 |
const M& _map; |
| 622 | 620 |
public: |
| 623 | 621 |
|
| 624 | 622 |
typedef typename M::Value::Value Value; |
| 625 | 623 |
typedef typename M::Key Key; |
| 626 | 624 |
///\e |
| 627 | 625 |
ConstXMap(const M &map) : _map(map) {}
|
| 628 | 626 |
Value operator[](Key k) const {return _map[k].x;}
|
| 629 | 627 |
}; |
| 630 | 628 |
|
| 631 |
///Returns a |
|
| 629 |
///Returns a ConstXMap class |
|
| 632 | 630 |
|
| 633 |
///This function just returns a |
|
| 631 |
///This function just returns a ConstXMap class. |
|
| 634 | 632 |
/// |
| 635 | 633 |
///\ingroup maps |
| 636 | 634 |
///\relates ConstXMap |
| 637 | 635 |
template<class M> |
| 638 | 636 |
inline ConstXMap<M> xMap(const M &m) |
| 639 | 637 |
{
|
| 640 | 638 |
return ConstXMap<M>(m); |
| 641 | 639 |
} |
| 642 | 640 |
|
| 643 |
///Map of y-coordinates of a |
|
| 641 |
///Map of y-coordinates of a <tt>Point</tt>-map |
|
| 644 | 642 |
|
| 643 |
///Map of y-coordinates of a \ref Point "Point"-map. |
|
| 645 | 644 |
///\ingroup maps |
| 646 |
///Map of y-coordinates of a \ref Point "Point"-map. |
|
| 647 |
/// |
|
| 648 | 645 |
template<class M> |
| 649 | 646 |
class YMap |
| 650 | 647 |
{
|
| 651 | 648 |
M& _map; |
| 652 | 649 |
public: |
| 653 | 650 |
|
| 654 | 651 |
typedef typename M::Value::Value Value; |
| 655 | 652 |
typedef typename M::Key Key; |
| 656 | 653 |
///\e |
| 657 | 654 |
YMap(M& map) : _map(map) {}
|
| 658 | 655 |
Value operator[](Key k) const {return _map[k].y;}
|
| 659 | 656 |
void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
|
| 660 | 657 |
}; |
| 661 | 658 |
|
| 662 |
///Returns a |
|
| 659 |
///Returns a YMap class |
|
| 663 | 660 |
|
| 664 |
///This function just returns a |
|
| 661 |
///This function just returns a YMap class. |
|
| 665 | 662 |
/// |
| 666 | 663 |
///\ingroup maps |
| 667 | 664 |
///\relates YMap |
| 668 | 665 |
template<class M> |
| 669 | 666 |
inline YMap<M> yMap(M &m) |
| 670 | 667 |
{
|
| 671 | 668 |
return YMap<M>(m); |
| 672 | 669 |
} |
| 673 | 670 |
|
| 674 | 671 |
template<class M> |
| 675 | 672 |
inline YMap<M> yMap(const M &m) |
| 676 | 673 |
{
|
| 677 | 674 |
return YMap<M>(m); |
| 678 | 675 |
} |
| 679 | 676 |
|
| 680 |
///Constant (read only) version of |
|
| 677 |
///Constant (read only) version of YMap |
|
| 681 | 678 |
|
| 679 |
///Constant (read only) version of YMap. |
|
| 682 | 680 |
///\ingroup maps |
| 683 |
///Constant (read only) version of \ref YMap |
|
| 684 |
/// |
|
| 685 | 681 |
template<class M> |
| 686 | 682 |
class ConstYMap |
| 687 | 683 |
{
|
| 688 | 684 |
const M& _map; |
| 689 | 685 |
public: |
| 690 | 686 |
|
| 691 | 687 |
typedef typename M::Value::Value Value; |
| 692 | 688 |
typedef typename M::Key Key; |
| 693 | 689 |
///\e |
| 694 | 690 |
ConstYMap(const M &map) : _map(map) {}
|
| 695 | 691 |
Value operator[](Key k) const {return _map[k].y;}
|
| 696 | 692 |
}; |
| 697 | 693 |
|
| 698 |
///Returns a |
|
| 694 |
///Returns a ConstYMap class |
|
| 699 | 695 |
|
| 700 |
///This function just returns a |
|
| 696 |
///This function just returns a ConstYMap class. |
|
| 701 | 697 |
/// |
| 702 | 698 |
///\ingroup maps |
| 703 | 699 |
///\relates ConstYMap |
| 704 | 700 |
template<class M> |
| 705 | 701 |
inline ConstYMap<M> yMap(const M &m) |
| 706 | 702 |
{
|
| 707 | 703 |
return ConstYMap<M>(m); |
| 708 | 704 |
} |
| 709 | 705 |
|
| 710 | 706 |
|
| 711 |
///\brief Map of the \ref Point::normSquare() "normSquare()" |
|
| 712 |
///of a \ref Point "Point"-map |
|
| 707 |
///\brief Map of the normSquare() of a <tt>Point</tt>-map |
|
| 713 | 708 |
/// |
| 714 | 709 |
///Map of the \ref Point::normSquare() "normSquare()" |
| 715 | 710 |
///of a \ref Point "Point"-map. |
| 716 | 711 |
///\ingroup maps |
| 717 | 712 |
template<class M> |
| 718 | 713 |
class NormSquareMap |
| 719 | 714 |
{
|
| 720 | 715 |
const M& _map; |
| 721 | 716 |
public: |
| 722 | 717 |
|
| 723 | 718 |
typedef typename M::Value::Value Value; |
| 724 | 719 |
typedef typename M::Key Key; |
| 725 | 720 |
///\e |
| 726 | 721 |
NormSquareMap(const M &map) : _map(map) {}
|
| 727 | 722 |
Value operator[](Key k) const {return _map[k].normSquare();}
|
| 728 | 723 |
}; |
| 729 | 724 |
|
| 730 |
///Returns a |
|
| 725 |
///Returns a NormSquareMap class |
|
| 731 | 726 |
|
| 732 |
///This function just returns a |
|
| 727 |
///This function just returns a NormSquareMap class. |
|
| 733 | 728 |
/// |
| 734 | 729 |
///\ingroup maps |
| 735 | 730 |
///\relates NormSquareMap |
| 736 | 731 |
template<class M> |
| 737 | 732 |
inline NormSquareMap<M> normSquareMap(const M &m) |
| 738 | 733 |
{
|
| 739 | 734 |
return NormSquareMap<M>(m); |
| 740 | 735 |
} |
| 741 | 736 |
|
| 742 | 737 |
/// @} |
| 743 | 738 |
|
| 744 | 739 |
} //namespce dim2 |
| 745 | 740 |
|
| 746 | 741 |
} //namespace lemon |
| 747 | 742 |
|
| 748 | 743 |
#endif //LEMON_DIM2_H |
| ... | ... |
@@ -41,49 +41,49 @@ |
| 41 | 41 |
#include<lemon/color.h> |
| 42 | 42 |
#include<lemon/bits/bezier.h> |
| 43 | 43 |
#include<lemon/error.h> |
| 44 | 44 |
|
| 45 | 45 |
|
| 46 | 46 |
///\ingroup eps_io |
| 47 | 47 |
///\file |
| 48 | 48 |
///\brief A well configurable tool for visualizing graphs |
| 49 | 49 |
|
| 50 | 50 |
namespace lemon {
|
| 51 | 51 |
|
| 52 | 52 |
namespace _graph_to_eps_bits {
|
| 53 | 53 |
template<class MT> |
| 54 | 54 |
class _NegY {
|
| 55 | 55 |
public: |
| 56 | 56 |
typedef typename MT::Key Key; |
| 57 | 57 |
typedef typename MT::Value Value; |
| 58 | 58 |
const MT ↦ |
| 59 | 59 |
int yscale; |
| 60 | 60 |
_NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
|
| 61 | 61 |
Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
|
| 62 | 62 |
}; |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 |
///Default traits class of |
|
| 65 |
///Default traits class of GraphToEps |
|
| 66 | 66 |
|
| 67 | 67 |
///Default traits class of \ref GraphToEps. |
| 68 | 68 |
/// |
| 69 | 69 |
///\c G is the type of the underlying graph. |
| 70 | 70 |
template<class G> |
| 71 | 71 |
struct DefaultGraphToEpsTraits |
| 72 | 72 |
{
|
| 73 | 73 |
typedef G Graph; |
| 74 | 74 |
typedef typename Graph::Node Node; |
| 75 | 75 |
typedef typename Graph::NodeIt NodeIt; |
| 76 | 76 |
typedef typename Graph::Arc Arc; |
| 77 | 77 |
typedef typename Graph::ArcIt ArcIt; |
| 78 | 78 |
typedef typename Graph::InArcIt InArcIt; |
| 79 | 79 |
typedef typename Graph::OutArcIt OutArcIt; |
| 80 | 80 |
|
| 81 | 81 |
|
| 82 | 82 |
const Graph &g; |
| 83 | 83 |
|
| 84 | 84 |
std::ostream& os; |
| 85 | 85 |
|
| 86 | 86 |
typedef ConstMap<typename Graph::Node,dim2::Point<double> > CoordsMapType; |
| 87 | 87 |
CoordsMapType _coords; |
| 88 | 88 |
ConstMap<typename Graph::Node,double > _nodeSizes; |
| 89 | 89 |
ConstMap<typename Graph::Node,int > _nodeShapes; |
| ... | ... |
@@ -392,49 +392,49 @@ |
| 392 | 392 |
/// |
| 393 | 393 |
/// \warning An Arc pointing to a removed item |
| 394 | 394 |
/// could become valid again later if new nodes are |
| 395 | 395 |
/// added to the graph. |
| 396 | 396 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 397 | 397 |
|
| 398 | 398 |
/// Change the target of \c a to \c n |
| 399 | 399 |
|
| 400 | 400 |
/// Change the target of \c a to \c n |
| 401 | 401 |
/// |
| 402 | 402 |
///\note The <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s referencing |
| 403 | 403 |
///the changed arc remain valid. However <tt>InArcIt</tt>s are |
| 404 | 404 |
///invalidated. |
| 405 | 405 |
/// |
| 406 | 406 |
///\warning This functionality cannot be used together with the Snapshot |
| 407 | 407 |
///feature. |
| 408 | 408 |
void changeTarget(Arc a, Node n) {
|
| 409 | 409 |
Parent::changeTarget(a,n); |
| 410 | 410 |
} |
| 411 | 411 |
/// Change the source of \c a to \c n |
| 412 | 412 |
|
| 413 | 413 |
/// Change the source of \c a to \c n |
| 414 | 414 |
/// |
| 415 | 415 |
///\note The <tt>InArcIt</tt>s referencing the changed arc remain |
| 416 |
///valid. However the <tt>ArcIt<tt>s and <tt>OutArcIt</tt>s are |
|
| 416 |
///valid. However the <tt>ArcIt</tt>s and <tt>OutArcIt</tt>s are |
|
| 417 | 417 |
///invalidated. |
| 418 | 418 |
/// |
| 419 | 419 |
///\warning This functionality cannot be used together with the Snapshot |
| 420 | 420 |
///feature. |
| 421 | 421 |
void changeSource(Arc a, Node n) {
|
| 422 | 422 |
Parent::changeSource(a,n); |
| 423 | 423 |
} |
| 424 | 424 |
|
| 425 | 425 |
/// Invert the direction of an arc. |
| 426 | 426 |
|
| 427 | 427 |
///\note The <tt>ArcIt</tt>s referencing the changed arc remain |
| 428 | 428 |
///valid. However <tt>OutArcIt</tt>s and <tt>InArcIt</tt>s are |
| 429 | 429 |
///invalidated. |
| 430 | 430 |
/// |
| 431 | 431 |
///\warning This functionality cannot be used together with the Snapshot |
| 432 | 432 |
///feature. |
| 433 | 433 |
void reverseArc(Arc e) {
|
| 434 | 434 |
Node t=target(e); |
| 435 | 435 |
changeTarget(e,source(e)); |
| 436 | 436 |
changeSource(e,t); |
| 437 | 437 |
} |
| 438 | 438 |
|
| 439 | 439 |
/// Reserve memory for nodes. |
| 440 | 440 |
| ... | ... |
@@ -22,49 +22,49 @@ |
| 22 | 22 |
#include <iterator> |
| 23 | 23 |
#include <functional> |
| 24 | 24 |
#include <vector> |
| 25 | 25 |
|
| 26 | 26 |
#include <lemon/core.h> |
| 27 | 27 |
|
| 28 | 28 |
///\file |
| 29 | 29 |
///\ingroup maps |
| 30 | 30 |
///\brief Miscellaneous property maps |
| 31 | 31 |
|
| 32 | 32 |
#include <map> |
| 33 | 33 |
|
| 34 | 34 |
namespace lemon {
|
| 35 | 35 |
|
| 36 | 36 |
/// \addtogroup maps |
| 37 | 37 |
/// @{
|
| 38 | 38 |
|
| 39 | 39 |
/// Base class of maps. |
| 40 | 40 |
|
| 41 | 41 |
/// Base class of maps. It provides the necessary type definitions |
| 42 | 42 |
/// required by the map %concepts. |
| 43 | 43 |
template<typename K, typename V> |
| 44 | 44 |
class MapBase {
|
| 45 | 45 |
public: |
| 46 |
/// \ |
|
| 46 |
/// \brief The key type of the map. |
|
| 47 | 47 |
typedef K Key; |
| 48 | 48 |
/// \brief The value type of the map. |
| 49 | 49 |
/// (The type of objects associated with the keys). |
| 50 | 50 |
typedef V Value; |
| 51 | 51 |
}; |
| 52 | 52 |
|
| 53 | 53 |
|
| 54 | 54 |
/// Null map. (a.k.a. DoNothingMap) |
| 55 | 55 |
|
| 56 | 56 |
/// This map can be used if you have to provide a map only for |
| 57 | 57 |
/// its type definitions, or if you have to provide a writable map, |
| 58 | 58 |
/// but data written to it is not required (i.e. it will be sent to |
| 59 | 59 |
/// <tt>/dev/null</tt>). |
| 60 | 60 |
/// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
| 61 | 61 |
/// |
| 62 | 62 |
/// \sa ConstMap |
| 63 | 63 |
template<typename K, typename V> |
| 64 | 64 |
class NullMap : public MapBase<K, V> {
|
| 65 | 65 |
public: |
| 66 | 66 |
typedef MapBase<K, V> Parent; |
| 67 | 67 |
typedef typename Parent::Key Key; |
| 68 | 68 |
typedef typename Parent::Value Value; |
| 69 | 69 |
|
| 70 | 70 |
/// Gives back a default constructed element. |
| ... | ... |
@@ -2245,166 +2245,166 @@ |
| 2245 | 2245 |
}; |
| 2246 | 2246 |
|
| 2247 | 2247 |
/// \brief Gives back the inverse of the map. |
| 2248 | 2248 |
/// |
| 2249 | 2249 |
/// Gives back the inverse of the map. |
| 2250 | 2250 |
const InverseMap inverse() const {
|
| 2251 | 2251 |
return InverseMap(*this); |
| 2252 | 2252 |
} |
| 2253 | 2253 |
}; |
| 2254 | 2254 |
|
| 2255 | 2255 |
/// \brief Returns the source of the given arc. |
| 2256 | 2256 |
/// |
| 2257 | 2257 |
/// The SourceMap gives back the source Node of the given arc. |
| 2258 | 2258 |
/// \see TargetMap |
| 2259 | 2259 |
template <typename Digraph> |
| 2260 | 2260 |
class SourceMap {
|
| 2261 | 2261 |
public: |
| 2262 | 2262 |
|
| 2263 | 2263 |
typedef typename Digraph::Node Value; |
| 2264 | 2264 |
typedef typename Digraph::Arc Key; |
| 2265 | 2265 |
|
| 2266 | 2266 |
/// \brief Constructor |
| 2267 | 2267 |
/// |
| 2268 | 2268 |
/// Constructor |
| 2269 |
/// \param |
|
| 2269 |
/// \param digraph The digraph that the map belongs to. |
|
| 2270 | 2270 |
explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {}
|
| 2271 | 2271 |
|
| 2272 | 2272 |
/// \brief The subscript operator. |
| 2273 | 2273 |
/// |
| 2274 | 2274 |
/// The subscript operator. |
| 2275 | 2275 |
/// \param arc The arc |
| 2276 | 2276 |
/// \return The source of the arc |
| 2277 | 2277 |
Value operator[](const Key& arc) const {
|
| 2278 | 2278 |
return _digraph.source(arc); |
| 2279 | 2279 |
} |
| 2280 | 2280 |
|
| 2281 | 2281 |
private: |
| 2282 | 2282 |
const Digraph& _digraph; |
| 2283 | 2283 |
}; |
| 2284 | 2284 |
|
| 2285 | 2285 |
/// \brief Returns a \c SourceMap class. |
| 2286 | 2286 |
/// |
| 2287 | 2287 |
/// This function just returns an \c SourceMap class. |
| 2288 | 2288 |
/// \relates SourceMap |
| 2289 | 2289 |
template <typename Digraph> |
| 2290 | 2290 |
inline SourceMap<Digraph> sourceMap(const Digraph& digraph) {
|
| 2291 | 2291 |
return SourceMap<Digraph>(digraph); |
| 2292 | 2292 |
} |
| 2293 | 2293 |
|
| 2294 | 2294 |
/// \brief Returns the target of the given arc. |
| 2295 | 2295 |
/// |
| 2296 | 2296 |
/// The TargetMap gives back the target Node of the given arc. |
| 2297 | 2297 |
/// \see SourceMap |
| 2298 | 2298 |
template <typename Digraph> |
| 2299 | 2299 |
class TargetMap {
|
| 2300 | 2300 |
public: |
| 2301 | 2301 |
|
| 2302 | 2302 |
typedef typename Digraph::Node Value; |
| 2303 | 2303 |
typedef typename Digraph::Arc Key; |
| 2304 | 2304 |
|
| 2305 | 2305 |
/// \brief Constructor |
| 2306 | 2306 |
/// |
| 2307 | 2307 |
/// Constructor |
| 2308 |
/// \param |
|
| 2308 |
/// \param digraph The digraph that the map belongs to. |
|
| 2309 | 2309 |
explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {}
|
| 2310 | 2310 |
|
| 2311 | 2311 |
/// \brief The subscript operator. |
| 2312 | 2312 |
/// |
| 2313 | 2313 |
/// The subscript operator. |
| 2314 | 2314 |
/// \param e The arc |
| 2315 | 2315 |
/// \return The target of the arc |
| 2316 | 2316 |
Value operator[](const Key& e) const {
|
| 2317 | 2317 |
return _digraph.target(e); |
| 2318 | 2318 |
} |
| 2319 | 2319 |
|
| 2320 | 2320 |
private: |
| 2321 | 2321 |
const Digraph& _digraph; |
| 2322 | 2322 |
}; |
| 2323 | 2323 |
|
| 2324 | 2324 |
/// \brief Returns a \c TargetMap class. |
| 2325 | 2325 |
/// |
| 2326 | 2326 |
/// This function just returns a \c TargetMap class. |
| 2327 | 2327 |
/// \relates TargetMap |
| 2328 | 2328 |
template <typename Digraph> |
| 2329 | 2329 |
inline TargetMap<Digraph> targetMap(const Digraph& digraph) {
|
| 2330 | 2330 |
return TargetMap<Digraph>(digraph); |
| 2331 | 2331 |
} |
| 2332 | 2332 |
|
| 2333 | 2333 |
/// \brief Returns the "forward" directed arc view of an edge. |
| 2334 | 2334 |
/// |
| 2335 | 2335 |
/// Returns the "forward" directed arc view of an edge. |
| 2336 | 2336 |
/// \see BackwardMap |
| 2337 | 2337 |
template <typename Graph> |
| 2338 | 2338 |
class ForwardMap {
|
| 2339 | 2339 |
public: |
| 2340 | 2340 |
|
| 2341 | 2341 |
typedef typename Graph::Arc Value; |
| 2342 | 2342 |
typedef typename Graph::Edge Key; |
| 2343 | 2343 |
|
| 2344 | 2344 |
/// \brief Constructor |
| 2345 | 2345 |
/// |
| 2346 | 2346 |
/// Constructor |
| 2347 |
/// \param |
|
| 2347 |
/// \param graph The graph that the map belongs to. |
|
| 2348 | 2348 |
explicit ForwardMap(const Graph& graph) : _graph(graph) {}
|
| 2349 | 2349 |
|
| 2350 | 2350 |
/// \brief The subscript operator. |
| 2351 | 2351 |
/// |
| 2352 | 2352 |
/// The subscript operator. |
| 2353 | 2353 |
/// \param key An edge |
| 2354 | 2354 |
/// \return The "forward" directed arc view of edge |
| 2355 | 2355 |
Value operator[](const Key& key) const {
|
| 2356 | 2356 |
return _graph.direct(key, true); |
| 2357 | 2357 |
} |
| 2358 | 2358 |
|
| 2359 | 2359 |
private: |
| 2360 | 2360 |
const Graph& _graph; |
| 2361 | 2361 |
}; |
| 2362 | 2362 |
|
| 2363 | 2363 |
/// \brief Returns a \c ForwardMap class. |
| 2364 | 2364 |
/// |
| 2365 | 2365 |
/// This function just returns an \c ForwardMap class. |
| 2366 | 2366 |
/// \relates ForwardMap |
| 2367 | 2367 |
template <typename Graph> |
| 2368 | 2368 |
inline ForwardMap<Graph> forwardMap(const Graph& graph) {
|
| 2369 | 2369 |
return ForwardMap<Graph>(graph); |
| 2370 | 2370 |
} |
| 2371 | 2371 |
|
| 2372 | 2372 |
/// \brief Returns the "backward" directed arc view of an edge. |
| 2373 | 2373 |
/// |
| 2374 | 2374 |
/// Returns the "backward" directed arc view of an edge. |
| 2375 | 2375 |
/// \see ForwardMap |
| 2376 | 2376 |
template <typename Graph> |
| 2377 | 2377 |
class BackwardMap {
|
| 2378 | 2378 |
public: |
| 2379 | 2379 |
|
| 2380 | 2380 |
typedef typename Graph::Arc Value; |
| 2381 | 2381 |
typedef typename Graph::Edge Key; |
| 2382 | 2382 |
|
| 2383 | 2383 |
/// \brief Constructor |
| 2384 | 2384 |
/// |
| 2385 | 2385 |
/// Constructor |
| 2386 |
/// \param |
|
| 2386 |
/// \param graph The graph that the map belongs to. |
|
| 2387 | 2387 |
explicit BackwardMap(const Graph& graph) : _graph(graph) {}
|
| 2388 | 2388 |
|
| 2389 | 2389 |
/// \brief The subscript operator. |
| 2390 | 2390 |
/// |
| 2391 | 2391 |
/// The subscript operator. |
| 2392 | 2392 |
/// \param key An edge |
| 2393 | 2393 |
/// \return The "backward" directed arc view of edge |
| 2394 | 2394 |
Value operator[](const Key& key) const {
|
| 2395 | 2395 |
return _graph.direct(key, false); |
| 2396 | 2396 |
} |
| 2397 | 2397 |
|
| 2398 | 2398 |
private: |
| 2399 | 2399 |
const Graph& _graph; |
| 2400 | 2400 |
}; |
| 2401 | 2401 |
|
| 2402 | 2402 |
/// \brief Returns a \c BackwardMap class |
| 2403 | 2403 |
|
| 2404 | 2404 |
/// This function just returns a \c BackwardMap class. |
| 2405 | 2405 |
/// \relates BackwardMap |
| 2406 | 2406 |
template <typename Graph> |
| 2407 | 2407 |
inline BackwardMap<Graph> backwardMap(const Graph& graph) {
|
| 2408 | 2408 |
return BackwardMap<Graph>(graph); |
| 2409 | 2409 |
} |
| 2410 | 2410 |
| ... | ... |
@@ -828,49 +828,49 @@ |
| 828 | 828 |
|
| 829 | 829 |
private: |
| 830 | 830 |
const StaticPath *path; |
| 831 | 831 |
int idx; |
| 832 | 832 |
}; |
| 833 | 833 |
|
| 834 | 834 |
/// \brief The nth arc. |
| 835 | 835 |
/// |
| 836 | 836 |
/// \pre n is in the [0..length() - 1] range |
| 837 | 837 |
const Arc& nth(int n) const {
|
| 838 | 838 |
return arcs[n]; |
| 839 | 839 |
} |
| 840 | 840 |
|
| 841 | 841 |
/// \brief The arc iterator pointing to the nth arc. |
| 842 | 842 |
ArcIt nthIt(int n) const {
|
| 843 | 843 |
return ArcIt(*this, n); |
| 844 | 844 |
} |
| 845 | 845 |
|
| 846 | 846 |
/// \brief The length of the path. |
| 847 | 847 |
int length() const { return len; }
|
| 848 | 848 |
|
| 849 | 849 |
/// \brief Return true when the path is empty. |
| 850 | 850 |
int empty() const { return len == 0; }
|
| 851 | 851 |
|
| 852 |
/// \ |
|
| 852 |
/// \brief Erase all arcs in the digraph. |
|
| 853 | 853 |
void clear() {
|
| 854 | 854 |
len = 0; |
| 855 | 855 |
if (arcs) delete[] arcs; |
| 856 | 856 |
arcs = 0; |
| 857 | 857 |
} |
| 858 | 858 |
|
| 859 | 859 |
/// \brief The first arc of the path. |
| 860 | 860 |
const Arc& front() const {
|
| 861 | 861 |
return arcs[0]; |
| 862 | 862 |
} |
| 863 | 863 |
|
| 864 | 864 |
/// \brief The last arc of the path. |
| 865 | 865 |
const Arc& back() const {
|
| 866 | 866 |
return arcs[len - 1]; |
| 867 | 867 |
} |
| 868 | 868 |
|
| 869 | 869 |
|
| 870 | 870 |
typedef True BuildTag; |
| 871 | 871 |
|
| 872 | 872 |
template <typename CPath> |
| 873 | 873 |
void build(const CPath& path) {
|
| 874 | 874 |
len = path.length(); |
| 875 | 875 |
arcs = new Arc[len]; |
| 876 | 876 |
int index = 0; |
| ... | ... |
@@ -344,61 +344,61 @@ |
| 344 | 344 |
///a later state, in other word you cannot add again the arcs deleted |
| 345 | 345 |
///by restore() using another one Snapshot instance. |
| 346 | 346 |
/// |
| 347 | 347 |
///\warning If you do not use correctly the snapshot that can cause |
| 348 | 348 |
///either broken program, invalid state of the digraph, valid but |
| 349 | 349 |
///not the restored digraph or no change. Because the runtime performance |
| 350 | 350 |
///the validity of the snapshot is not stored. |
| 351 | 351 |
class Snapshot |
| 352 | 352 |
{
|
| 353 | 353 |
SmartDigraph *_graph; |
| 354 | 354 |
protected: |
| 355 | 355 |
friend class SmartDigraph; |
| 356 | 356 |
unsigned int node_num; |
| 357 | 357 |
unsigned int arc_num; |
| 358 | 358 |
public: |
| 359 | 359 |
///Default constructor. |
| 360 | 360 |
|
| 361 | 361 |
///Default constructor. |
| 362 | 362 |
///To actually make a snapshot you must call save(). |
| 363 | 363 |
/// |
| 364 | 364 |
Snapshot() : _graph(0) {}
|
| 365 | 365 |
///Constructor that immediately makes a snapshot |
| 366 | 366 |
|
| 367 | 367 |
///This constructor immediately makes a snapshot of the digraph. |
| 368 |
///\param |
|
| 368 |
///\param graph The digraph we make a snapshot of. |
|
| 369 | 369 |
Snapshot(SmartDigraph &graph) : _graph(&graph) {
|
| 370 | 370 |
node_num=_graph->nodes.size(); |
| 371 | 371 |
arc_num=_graph->arcs.size(); |
| 372 | 372 |
} |
| 373 | 373 |
|
| 374 | 374 |
///Make a snapshot. |
| 375 | 375 |
|
| 376 | 376 |
///Make a snapshot of the digraph. |
| 377 | 377 |
/// |
| 378 | 378 |
///This function can be called more than once. In case of a repeated |
| 379 | 379 |
///call, the previous snapshot gets lost. |
| 380 |
///\param |
|
| 380 |
///\param graph The digraph we make the snapshot of. |
|
| 381 | 381 |
void save(SmartDigraph &graph) |
| 382 | 382 |
{
|
| 383 | 383 |
_graph=&graph; |
| 384 | 384 |
node_num=_graph->nodes.size(); |
| 385 | 385 |
arc_num=_graph->arcs.size(); |
| 386 | 386 |
} |
| 387 | 387 |
|
| 388 | 388 |
///Undo the changes until a snapshot. |
| 389 | 389 |
|
| 390 | 390 |
///Undo the changes until a snapshot created by save(). |
| 391 | 391 |
/// |
| 392 | 392 |
///\note After you restored a state, you cannot restore |
| 393 | 393 |
///a later state, in other word you cannot add again the arcs deleted |
| 394 | 394 |
///by restore(). |
| 395 | 395 |
void restore() |
| 396 | 396 |
{
|
| 397 | 397 |
_graph->restoreSnapshot(*this); |
| 398 | 398 |
} |
| 399 | 399 |
}; |
| 400 | 400 |
}; |
| 401 | 401 |
|
| 402 | 402 |
|
| 403 | 403 |
class SmartGraphBase {
|
| 404 | 404 |
|
| ... | ... |
@@ -754,59 +754,59 @@ |
| 754 | 754 |
///a later state, in other word you cannot add again the arcs deleted |
| 755 | 755 |
///by restore() using another one Snapshot instance. |
| 756 | 756 |
/// |
| 757 | 757 |
///\warning If you do not use correctly the snapshot that can cause |
| 758 | 758 |
///either broken program, invalid state of the digraph, valid but |
| 759 | 759 |
///not the restored digraph or no change. Because the runtime performance |
| 760 | 760 |
///the validity of the snapshot is not stored. |
| 761 | 761 |
class Snapshot |
| 762 | 762 |
{
|
| 763 | 763 |
SmartGraph *_graph; |
| 764 | 764 |
protected: |
| 765 | 765 |
friend class SmartGraph; |
| 766 | 766 |
unsigned int node_num; |
| 767 | 767 |
unsigned int arc_num; |
| 768 | 768 |
public: |
| 769 | 769 |
///Default constructor. |
| 770 | 770 |
|
| 771 | 771 |
///Default constructor. |
| 772 | 772 |
///To actually make a snapshot you must call save(). |
| 773 | 773 |
/// |
| 774 | 774 |
Snapshot() : _graph(0) {}
|
| 775 | 775 |
///Constructor that immediately makes a snapshot |
| 776 | 776 |
|
| 777 | 777 |
///This constructor immediately makes a snapshot of the digraph. |
| 778 |
///\param |
|
| 778 |
///\param graph The digraph we make a snapshot of. |
|
| 779 | 779 |
Snapshot(SmartGraph &graph) {
|
| 780 | 780 |
graph.saveSnapshot(*this); |
| 781 | 781 |
} |
| 782 | 782 |
|
| 783 | 783 |
///Make a snapshot. |
| 784 | 784 |
|
| 785 | 785 |
///Make a snapshot of the graph. |
| 786 | 786 |
/// |
| 787 | 787 |
///This function can be called more than once. In case of a repeated |
| 788 | 788 |
///call, the previous snapshot gets lost. |
| 789 |
///\param |
|
| 789 |
///\param graph The digraph we make the snapshot of. |
|
| 790 | 790 |
void save(SmartGraph &graph) |
| 791 | 791 |
{
|
| 792 | 792 |
graph.saveSnapshot(*this); |
| 793 | 793 |
} |
| 794 | 794 |
|
| 795 | 795 |
///Undo the changes until a snapshot. |
| 796 | 796 |
|
| 797 | 797 |
///Undo the changes until a snapshot created by save(). |
| 798 | 798 |
/// |
| 799 | 799 |
///\note After you restored a state, you cannot restore |
| 800 | 800 |
///a later state, in other word you cannot add again the arcs deleted |
| 801 | 801 |
///by restore(). |
| 802 | 802 |
void restore() |
| 803 | 803 |
{
|
| 804 | 804 |
_graph->restoreSnapshot(*this); |
| 805 | 805 |
} |
| 806 | 806 |
}; |
| 807 | 807 |
}; |
| 808 | 808 |
|
| 809 | 809 |
} //namespace lemon |
| 810 | 810 |
|
| 811 | 811 |
|
| 812 | 812 |
#endif //LEMON_SMART_GRAPH_H |
| ... | ... |
@@ -290,54 +290,53 @@ |
| 290 | 290 |
///distorted results. |
| 291 | 291 |
/// |
| 292 | 292 |
///\note If you want to measure the running time of the execution of a certain |
| 293 | 293 |
///function, consider the usage of \ref TimeReport instead. |
| 294 | 294 |
/// |
| 295 | 295 |
///\sa TimeReport |
| 296 | 296 |
class Timer |
| 297 | 297 |
{
|
| 298 | 298 |
int _running; //Timer is running iff _running>0; (_running>=0 always holds) |
| 299 | 299 |
TimeStamp start_time; //This is the relativ start-time if the timer |
| 300 | 300 |
//is _running, the collected _running time otherwise. |
| 301 | 301 |
|
| 302 | 302 |
void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
|
| 303 | 303 |
|
| 304 | 304 |
public: |
| 305 | 305 |
///Constructor. |
| 306 | 306 |
|
| 307 | 307 |
///\param run indicates whether or not the timer starts immediately. |
| 308 | 308 |
/// |
| 309 | 309 |
Timer(bool run=true) :_running(run) {_reset();}
|
| 310 | 310 |
|
| 311 | 311 |
///\name Control the state of the timer |
| 312 | 312 |
///Basically a Timer can be either running or stopped, |
| 313 | 313 |
///but it provides a bit finer control on the execution. |
| 314 |
///The \ref Timer also counts the number of \ref start() |
|
| 315 |
///executions, and is stops only after the same amount (or more) |
|
| 316 |
///\ref stop() "stop()"s. This can be useful e.g. to compute |
|
| 317 |
///the running time |
|
| 314 |
///The \ref lemon::Timer "Timer" also counts the number of |
|
| 315 |
///\ref lemon::Timer::start() "start()" executions, and it stops |
|
| 316 |
///only after the same amount (or more) \ref lemon::Timer::stop() |
|
| 317 |
///"stop()"s. This can be useful e.g. to compute the running time |
|
| 318 | 318 |
///of recursive functions. |
| 319 |
/// |
|
| 320 | 319 |
|
| 321 | 320 |
///@{
|
| 322 | 321 |
|
| 323 | 322 |
///Reset and stop the time counters |
| 324 | 323 |
|
| 325 | 324 |
///This function resets and stops the time counters |
| 326 | 325 |
///\sa restart() |
| 327 | 326 |
void reset() |
| 328 | 327 |
{
|
| 329 | 328 |
_running=0; |
| 330 | 329 |
_reset(); |
| 331 | 330 |
} |
| 332 | 331 |
|
| 333 | 332 |
///Start the time counters |
| 334 | 333 |
|
| 335 | 334 |
///This function starts the time counters. |
| 336 | 335 |
/// |
| 337 | 336 |
///If the timer is started more than ones, it will remain running |
| 338 | 337 |
///until the same amount of \ref stop() is called. |
| 339 | 338 |
///\sa stop() |
| 340 | 339 |
void start() |
| 341 | 340 |
{
|
| 342 | 341 |
if(_running) _running++; |
| 343 | 342 |
else {
|
| ... | ... |
@@ -451,83 +450,83 @@ |
| 451 | 450 |
double realTime() const |
| 452 | 451 |
{
|
| 453 | 452 |
return operator TimeStamp().realTime(); |
| 454 | 453 |
} |
| 455 | 454 |
///Computes the ellapsed time |
| 456 | 455 |
|
| 457 | 456 |
///This conversion computes the ellapsed time, therefore you can print |
| 458 | 457 |
///the ellapsed time like this. |
| 459 | 458 |
///\code |
| 460 | 459 |
/// Timer t; |
| 461 | 460 |
/// doSomething(); |
| 462 | 461 |
/// std::cout << t << '\n'; |
| 463 | 462 |
///\endcode |
| 464 | 463 |
operator TimeStamp () const |
| 465 | 464 |
{
|
| 466 | 465 |
TimeStamp t; |
| 467 | 466 |
t.stamp(); |
| 468 | 467 |
return _running?t-start_time:start_time; |
| 469 | 468 |
} |
| 470 | 469 |
|
| 471 | 470 |
|
| 472 | 471 |
///@} |
| 473 | 472 |
}; |
| 474 | 473 |
|
| 475 |
///Same as |
|
| 474 |
///Same as Timer but prints a report on destruction. |
|
| 476 | 475 |
|
| 477 | 476 |
///Same as \ref Timer but prints a report on destruction. |
| 478 | 477 |
///This example shows its usage. |
| 479 | 478 |
///\code |
| 480 | 479 |
/// void myAlg(ListGraph &g,int n) |
| 481 | 480 |
/// {
|
| 482 | 481 |
/// TimeReport tr("Running time of myAlg: ");
|
| 483 | 482 |
/// ... //Here comes the algorithm |
| 484 | 483 |
/// } |
| 485 | 484 |
///\endcode |
| 486 | 485 |
/// |
| 487 | 486 |
///\sa Timer |
| 488 | 487 |
///\sa NoTimeReport |
| 489 | 488 |
class TimeReport : public Timer |
| 490 | 489 |
{
|
| 491 | 490 |
std::string _title; |
| 492 | 491 |
std::ostream &_os; |
| 493 | 492 |
public: |
| 494 |
/// |
|
| 493 |
///Constructor |
|
| 495 | 494 |
|
| 495 |
///Constructor. |
|
| 496 | 496 |
///\param title This text will be printed before the ellapsed time. |
| 497 | 497 |
///\param os The stream to print the report to. |
| 498 | 498 |
///\param run Sets whether the timer should start immediately. |
| 499 |
|
|
| 500 | 499 |
TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) |
| 501 | 500 |
: Timer(run), _title(title), _os(os){}
|
| 502 |
/// |
|
| 501 |
///Destructor that prints the ellapsed time |
|
| 503 | 502 |
~TimeReport() |
| 504 | 503 |
{
|
| 505 | 504 |
_os << _title << *this << std::endl; |
| 506 | 505 |
} |
| 507 | 506 |
}; |
| 508 | 507 |
|
| 509 |
///'Do nothing' version of |
|
| 508 |
///'Do nothing' version of TimeReport |
|
| 510 | 509 |
|
| 511 | 510 |
///\sa TimeReport |
| 512 | 511 |
/// |
| 513 | 512 |
class NoTimeReport |
| 514 | 513 |
{
|
| 515 | 514 |
public: |
| 516 | 515 |
///\e |
| 517 | 516 |
NoTimeReport(std::string,std::ostream &,bool) {}
|
| 518 | 517 |
///\e |
| 519 | 518 |
NoTimeReport(std::string,std::ostream &) {}
|
| 520 | 519 |
///\e |
| 521 | 520 |
NoTimeReport(std::string) {}
|
| 522 | 521 |
///\e Do nothing. |
| 523 | 522 |
~NoTimeReport() {}
|
| 524 | 523 |
|
| 525 | 524 |
operator TimeStamp () const { return TimeStamp(); }
|
| 526 | 525 |
void reset() {}
|
| 527 | 526 |
void start() {}
|
| 528 | 527 |
void stop() {}
|
| 529 | 528 |
void halt() {}
|
| 530 | 529 |
int running() { return 0; }
|
| 531 | 530 |
void restart() {}
|
| 532 | 531 |
double userTime() const { return 0; }
|
| 533 | 532 |
double systemTime() const { return 0; }
|
0 comments (0 inline)