[Lemon-commits] Alpar Juttner: Merge
Lemon HG
hg at lemon.cs.elte.hu
Sun Jan 11 16:18:27 CET 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/5a1e9fdcfd3a
changeset: 478:5a1e9fdcfd3a
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Sun Jan 11 15:09:53 2009 +0000
description:
Merge
diffstat:
3 files changed, 1008 insertions(+), 750 deletions(-)
doc/groups.dox | 49 -
lemon/adaptors.h | 1705 ++++++++++++++++++++---------------
lemon/bits/graph_adaptor_extender.h | 4
diffs (truncated from 2676 to 300 lines):
diff --git a/doc/groups.dox b/doc/groups.dox
--- a/doc/groups.dox
+++ b/doc/groups.dox
@@ -62,18 +62,20 @@
*/
/**
- at defgroup graph_adaptors Adaptor Classes for graphs
+ at defgroup graph_adaptors Adaptor Classes for Graphs
@ingroup graphs
-\brief This group contains several adaptor classes for digraphs and graphs
+\brief Adaptor classes for digraphs and graphs
+
+This group contains several useful adaptor classes for digraphs and graphs.
The main parts of LEMON are the different graph structures, generic
-graph algorithms, graph concepts which couple these, and graph
+graph algorithms, graph concepts, which couple them, and graph
adaptors. While the previous notions are more or less clear, the
latter one needs further explanation. Graph adaptors are graph classes
which serve for considering graph structures in different ways.
A short example makes this much clearer. Suppose that we have an
-instance \c g of a directed graph type say ListDigraph and an algorithm
+instance \c g of a directed graph type, say ListDigraph and an algorithm
\code
template <typename Digraph>
int algorithm(const Digraph&);
@@ -81,13 +83,13 @@
is needed to run on the reverse oriented graph. It may be expensive
(in time or in memory usage) to copy \c g with the reversed
arcs. In this case, an adaptor class is used, which (according
-to LEMON digraph concepts) works as a digraph. The adaptor uses the
-original digraph structure and digraph operations when methods of the
-reversed oriented graph are called. This means that the adaptor have
-minor memory usage, and do not perform sophisticated algorithmic
+to LEMON \ref concepts::Digraph "digraph concepts") works as a digraph.
+The adaptor uses the original digraph structure and digraph operations when
+methods of the reversed oriented graph are called. This means that the adaptor
+have minor memory usage, and do not perform sophisticated algorithmic
actions. The purpose of it is to give a tool for the cases when a
graph have to be used in a specific alteration. If this alteration is
-obtained by a usual construction like filtering the arc-set or
+obtained by a usual construction like filtering the node or the arc set or
considering a new orientation, then an adaptor is worthwhile to use.
To come back to the reverse oriented graph, in this situation
\code
@@ -96,39 +98,40 @@
template class can be used. The code looks as follows
\code
ListDigraph g;
-ReverseDigraph<ListGraph> rg(g);
+ReverseDigraph<ListDigraph> rg(g);
int result = algorithm(rg);
\endcode
-After running the algorithm, the original graph \c g is untouched.
-This techniques gives rise to an elegant code, and based on stable
+During running the algorithm, the original digraph \c g is untouched.
+This techniques give rise to an elegant code, and based on stable
graph adaptors, complex algorithms can be implemented easily.
-In flow, circulation and bipartite matching problems, the residual
+In flow, circulation and matching problems, the residual
graph is of particular importance. Combining an adaptor implementing
-this, shortest path algorithms and minimum mean cycle algorithms,
+this with shortest path algorithms or minimum mean cycle algorithms,
a range of weighted and cardinality optimization algorithms can be
obtained. For other examples, the interested user is referred to the
detailed documentation of particular adaptors.
The behavior of graph adaptors can be very different. Some of them keep
capabilities of the original graph while in other cases this would be
-meaningless. This means that the concepts that they are models of depend
-on the graph adaptor, and the wrapped graph(s).
-If an arc of \c rg is deleted, this is carried out by deleting the
-corresponding arc of \c g, thus the adaptor modifies the original graph.
+meaningless. This means that the concepts that they meet depend
+on the graph adaptor, and the wrapped graph.
+For example, if an arc of a reversed digraph is deleted, this is carried
+out by deleting the corresponding arc of the original digraph, thus the
+adaptor modifies the original digraph.
+However in case of a residual digraph, this operation has no sense.
-But for a residual graph, this operation has no sense.
Let us stand one more example here to simplify your work.
-RevGraphAdaptor has constructor
+ReverseDigraph has constructor
\code
ReverseDigraph(Digraph& digraph);
\endcode
-This means that in a situation, when a <tt>const ListDigraph&</tt>
+This means that in a situation, when a <tt>const %ListDigraph&</tt>
reference to a graph is given, then it have to be instantiated with
-<tt>Digraph=const ListDigraph</tt>.
+<tt>Digraph=const %ListDigraph</tt>.
\code
int algorithm1(const ListDigraph& g) {
- RevGraphAdaptor<const ListDigraph> rg(g);
+ ReverseDigraph<const ListDigraph> rg(g);
return algorithm2(rg);
}
\endcode
diff --git a/lemon/adaptors.h b/lemon/adaptors.h
--- a/lemon/adaptors.h
+++ b/lemon/adaptors.h
@@ -21,7 +21,7 @@
/// \ingroup graph_adaptors
/// \file
-/// \brief Several graph adaptors
+/// \brief Adaptor classes for digraphs and graphs
///
/// This file contains several useful adaptors for digraphs and graphs.
@@ -70,21 +70,21 @@
typedef NodeNumTagIndicator<Digraph> NodeNumTag;
int nodeNum() const { return _digraph->nodeNum(); }
- typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
+ typedef ArcNumTagIndicator<Digraph> ArcNumTag;
int arcNum() const { return _digraph->arcNum(); }
- typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
- Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
+ typedef FindArcTagIndicator<Digraph> FindArcTag;
+ Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) const {
return _digraph->findArc(u, v, prev);
}
Node addNode() { return _digraph->addNode(); }
Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
- void erase(const Node& n) const { _digraph->erase(n); }
- void erase(const Arc& a) const { _digraph->erase(a); }
+ void erase(const Node& n) { _digraph->erase(n); }
+ void erase(const Arc& a) { _digraph->erase(a); }
- void clear() const { _digraph->clear(); }
+ void clear() { _digraph->clear(); }
int id(const Node& n) const { return _digraph->id(n); }
int id(const Arc& a) const { return _digraph->id(a); }
@@ -198,15 +198,21 @@
typedef NodeNumTagIndicator<Graph> NodeNumTag;
int nodeNum() const { return _graph->nodeNum(); }
+ typedef ArcNumTagIndicator<Graph> ArcNumTag;
+ int arcNum() const { return _graph->arcNum(); }
+
typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
- int arcNum() const { return _graph->arcNum(); }
int edgeNum() const { return _graph->edgeNum(); }
- typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
- Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
+ typedef FindArcTagIndicator<Graph> FindArcTag;
+ Arc findArc(const Node& u, const Node& v,
+ const Arc& prev = INVALID) const {
return _graph->findArc(u, v, prev);
}
- Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
+
+ typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
+ Edge findEdge(const Node& u, const Node& v,
+ const Edge& prev = INVALID) const {
return _graph->findEdge(u, v, prev);
}
@@ -330,9 +336,9 @@
Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
- typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
+ typedef FindArcTagIndicator<Digraph> FindArcTag;
Arc findArc(const Node& u, const Node& v,
- const Arc& prev = INVALID) {
+ const Arc& prev = INVALID) const {
return Parent::findArc(v, u, prev);
}
@@ -340,41 +346,56 @@
/// \ingroup graph_adaptors
///
- /// \brief A digraph adaptor which reverses the orientation of the arcs.
+ /// \brief Adaptor class for reversing the orientation of the arcs in
+ /// a digraph.
///
- /// ReverseDigraph reverses the arcs in the adapted digraph. The
- /// SubDigraph is conform to the \ref concepts::Digraph
- /// "Digraph concept".
+ /// ReverseDigraph can be used for reversing the arcs in a digraph.
+ /// It conforms to the \ref concepts::Digraph "Digraph" concept.
///
- /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
- /// "Digraph concept". The type can be specified to be const.
- template<typename _Digraph>
+ /// The adapted digraph can also be modified through this adaptor
+ /// by adding or removing nodes or arcs, unless the \c GR template
+ /// parameter is set to be \c const.
+ ///
+ /// \tparam GR The type of the adapted digraph.
+ /// It must conform to the \ref concepts::Digraph "Digraph" concept.
+ /// It can also be specified to be \c const.
+ ///
+ /// \note The \c Node and \c Arc types of this adaptor and the adapted
+ /// digraph are convertible to each other.
+ template<typename GR>
+#ifdef DOXYGEN
+ class ReverseDigraph {
+#else
class ReverseDigraph :
- public DigraphAdaptorExtender<ReverseDigraphBase<_Digraph> > {
+ public DigraphAdaptorExtender<ReverseDigraphBase<GR> > {
+#endif
public:
- typedef _Digraph Digraph;
- typedef DigraphAdaptorExtender<
- ReverseDigraphBase<_Digraph> > Parent;
+ /// The type of the adapted digraph.
+ typedef GR Digraph;
+ typedef DigraphAdaptorExtender<ReverseDigraphBase<GR> > Parent;
protected:
ReverseDigraph() { }
public:
/// \brief Constructor
///
- /// Creates a reverse digraph adaptor for the given digraph
+ /// Creates a reverse digraph adaptor for the given digraph.
explicit ReverseDigraph(Digraph& digraph) {
Parent::setDigraph(digraph);
}
};
- /// \brief Just gives back a reverse digraph adaptor
+ /// \brief Returns a read-only ReverseDigraph adaptor
///
- /// Just gives back a reverse digraph adaptor
- template<typename Digraph>
- ReverseDigraph<const Digraph> reverseDigraph(const Digraph& digraph) {
- return ReverseDigraph<const Digraph>(digraph);
+ /// This function just returns a read-only \ref ReverseDigraph adaptor.
+ /// \ingroup graph_adaptors
+ /// \relates ReverseDigraph
+ template<typename GR>
+ ReverseDigraph<const GR> reverseDigraph(const GR& digraph) {
+ return ReverseDigraph<const GR>(digraph);
}
+
template <typename _Digraph, typename _NodeFilterMap,
typename _ArcFilterMap, bool _checked = true>
class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
@@ -457,21 +478,18 @@
Parent::nextOut(i);
}
- void hide(const Node& n) const { _node_filter->set(n, false); }
- void hide(const Arc& a) const { _arc_filter->set(a, false); }
+ void status(const Node& n, bool v) const { _node_filter->set(n, v); }
+ void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
- void unHide(const Node& n) const { _node_filter->set(n, true); }
- void unHide(const Arc& a) const { _arc_filter->set(a, true); }
-
- bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
- bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
+ bool status(const Node& n) const { return (*_node_filter)[n]; }
+ bool status(const Arc& a) const { return (*_arc_filter)[a]; }
typedef False NodeNumTag;
- typedef False EdgeNumTag;
+ typedef False ArcNumTag;
- typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
+ typedef FindArcTagIndicator<Digraph> FindArcTag;
Arc findArc(const Node& source, const Node& target,
- const Arc& prev = INVALID) {
+ const Arc& prev = INVALID) const {
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
return INVALID;
}
@@ -600,21 +618,18 @@
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
}
- void hide(const Node& n) const { _node_filter->set(n, false); }
- void hide(const Arc& e) const { _arc_filter->set(e, false); }
+ void status(const Node& n, bool v) const { _node_filter->set(n, v); }
+ void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
- void unHide(const Node& n) const { _node_filter->set(n, true); }
- void unHide(const Arc& e) const { _arc_filter->set(e, true); }
-
- bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
- bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
+ bool status(const Node& n) const { return (*_node_filter)[n]; }
+ bool status(const Arc& a) const { return (*_arc_filter)[a]; }
More information about the Lemon-commits
mailing list