[Lemon-commits] [lemon_svn] alpar: r1267 - in hugo/branches/graph_factory: . src src/demo src/lemon src/lemon/skeletons src/test src/work/klao
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:16 CET 2006
Author: alpar
Date: Tue Oct 5 12:08:19 2004
New Revision: 1267
Added:
hugo/branches/graph_factory/src/demo/Makefile.am
- copied unchanged from r1266, /hugo/trunk/src/demo/Makefile.am
hugo/branches/graph_factory/src/lemon/skeletons/sym_graph.h
- copied unchanged from r1266, /hugo/trunk/src/lemon/skeletons/sym_graph.h
hugo/branches/graph_factory/src/test/sym_graph_test.cc
- copied unchanged from r1266, /hugo/trunk/src/test/sym_graph_test.cc
hugo/branches/graph_factory/src/test/sym_graph_test.h
- copied unchanged from r1266, /hugo/trunk/src/test/sym_graph_test.h
hugo/branches/graph_factory/src/work/klao/cpp_hianyok
- copied unchanged from r1266, /hugo/trunk/src/work/klao/cpp_hianyok
Removed:
hugo/branches/graph_factory/src/lemon/sym_map.h
Modified:
hugo/branches/graph_factory/Makefile.am
hugo/branches/graph_factory/configure.ac
hugo/branches/graph_factory/src/Makefile.am
hugo/branches/graph_factory/src/demo/ (props changed)
hugo/branches/graph_factory/src/lemon/Makefile.am
hugo/branches/graph_factory/src/lemon/default_map.h
hugo/branches/graph_factory/src/lemon/list_graph.h
hugo/branches/graph_factory/src/lemon/map_bits.h
hugo/branches/graph_factory/src/lemon/map_defines.h
hugo/branches/graph_factory/src/lemon/map_registry.h
hugo/branches/graph_factory/src/lemon/smart_graph.h
hugo/branches/graph_factory/src/lemon/vector_map.h
hugo/branches/graph_factory/src/test/Makefile.am
hugo/branches/graph_factory/src/test/graph_test.cc
hugo/branches/graph_factory/src/test/graph_test.h
hugo/branches/graph_factory/src/test/graph_wrapper_test.cc
hugo/branches/graph_factory/src/test/test_tools.h
hugo/branches/graph_factory/src/work/klao/jegyzetek
Log:
branches/graph_factory: ported -r1259:1266 from trunk
Modified: hugo/branches/graph_factory/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/Makefile.am (original)
+++ hugo/branches/graph_factory/Makefile.am Tue Oct 5 12:08:19 2004
@@ -13,16 +13,14 @@
src/Makefile.in \
src/lemon/Makefile.in \
src/test/Makefile.in \
- src/benchmark/Makefile.in
+ src/benchmark/Makefile.in \
+ src/demo/Makefile.in
docs:
- @cd doc \
- && $(MAKE) $(AM_MAKEFLAGS) clean \
- && $(MAKE) $(AM_MAKEFLAGS) html
+ $(MAKE) -C doc $(AM_MAKEFLAGS) clean html
benchmark:
- @cd src/benchmark \
- && $(MAKE) $(AM_MAKEFLAGS)
+ $(MAKE) -C src/benchmark $(AM_MAKEFLAGS)
mrproper:
$(MAKE) $(AM_MAKEFLAGS) maintainer-clean
Modified: hugo/branches/graph_factory/configure.ac
==============================================================================
--- hugo/branches/graph_factory/configure.ac (original)
+++ hugo/branches/graph_factory/configure.ac Tue Oct 5 12:08:19 2004
@@ -27,5 +27,5 @@
AC_HEADER_STDC
AC_CHECK_FUNCS(gettimeofday)
-AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile src/lemon/Makefile src/test/Makefile src/benchmark/Makefile])
+AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile src/lemon/Makefile src/test/Makefile src/benchmark/Makefile src/demo/Makefile])
AC_OUTPUT
Modified: hugo/branches/graph_factory/src/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/src/Makefile.am (original)
+++ hugo/branches/graph_factory/src/Makefile.am Tue Oct 5 12:08:19 2004
@@ -1 +1 @@
-SUBDIRS = lemon benchmark test
+SUBDIRS = lemon benchmark demo test
Modified: hugo/branches/graph_factory/src/lemon/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/src/lemon/Makefile.am (original)
+++ hugo/branches/graph_factory/src/lemon/Makefile.am Tue Oct 5 12:08:19 2004
@@ -18,12 +18,11 @@
map_registry.h \
map_bits.h \
maps.h \
- min_cost_flow.h \
+ min_cost_flow.h \
suurballe.h \
preflow.h \
path.h \
smart_graph.h \
- sym_map.h \
time_measure.h \
unionfind.h \
vector_map.h \
@@ -31,5 +30,6 @@
noinst_HEADERS = \
skeletons/graph.h \
+ skeletons/sym_graph.h \
skeletons/maps.h \
skeletons/path.h
Modified: hugo/branches/graph_factory/src/lemon/default_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/default_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/default_map.h Tue Oct 5 12:08:19 2004
@@ -59,12 +59,9 @@
: Parent(static_cast<const Parent&>(copy)) {} \
template <typename TT> \
DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
- : { \
- Parent::MapBase::operator= \
- (static_cast<const typename Parent::MapBase&>(copy)); \
+ : Parent(*copy.getGraph()) { \
if (Parent::getGraph()) { \
for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
- Parent::add(it); \
Parent::operator[](it) = copy[it]; \
} \
} \
Modified: hugo/branches/graph_factory/src/lemon/list_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/list_graph.h (original)
+++ hugo/branches/graph_factory/src/lemon/list_graph.h Tue Oct 5 12:08:19 2004
@@ -29,8 +29,6 @@
#include <lemon/map_registry.h>
#include <lemon/array_map.h>
-#include <lemon/sym_map.h>
-
#include <lemon/map_defines.h>
@@ -104,6 +102,7 @@
first_free_node(_g.first_free_node), edges(_g.edges),
first_free_edge(_g.first_free_edge) {}
+ /// \bug In the vector can be hole if a node is erased from the graph.
///Number of nodes.
int nodeNum() const { return nodes.size(); }
///Number of edges.
@@ -438,7 +437,7 @@
///
///\todo this date structure need some reconsiderations. Maybe it
///should be implemented independently from ListGraph.
-
+ /*
class SymListGraph : public ListGraph
{
public:
@@ -483,8 +482,402 @@
ListGraph::erase(f);
ListGraph::erase(e);
}
- };
+ };*/
+
+ class SymListGraph : public ListGraph {
+ typedef ListGraph Parent;
+ public:
+
+ typedef SymListGraph Graph;
+
+ typedef ListGraph::Node Node;
+ typedef ListGraph::NodeIt NodeIt;
+
+ class SymEdge;
+ class SymEdgeIt;
+
+ class Edge;
+ class EdgeIt;
+ class OutEdgeIt;
+ class InEdgeIt;
+
+ template <typename Value>
+ class NodeMap : public Parent::NodeMap<Value> {
+ public:
+ NodeMap(const SymListGraph& g)
+ : SymListGraph::Parent::NodeMap<Value>(g) {}
+ NodeMap(const SymListGraph& g, Value v)
+ : SymListGraph::Parent::NodeMap<Value>(g, v) {}
+ template<typename TT>
+ NodeMap(const NodeMap<TT>& copy)
+ : SymListGraph::Parent::NodeMap<Value>(copy) { }
+ };
+
+ template <typename Value>
+ class SymEdgeMap : public Parent::EdgeMap<Value> {
+ public:
+ typedef SymEdge KeyType;
+
+ SymEdgeMap(const SymListGraph& g)
+ : SymListGraph::Parent::EdgeMap<Value>(g) {}
+ SymEdgeMap(const SymListGraph& g, Value v)
+ : SymListGraph::Parent::EdgeMap<Value>(g, v) {}
+ template<typename TT>
+ SymEdgeMap(const SymEdgeMap<TT>& copy)
+ : SymListGraph::Parent::EdgeMap<Value>(copy) { }
+
+ };
+
+ // Create edge map registry.
+ CREATE_EDGE_MAP_REGISTRY;
+ // Create edge maps.
+ CREATE_EDGE_MAP(ArrayMap);
+
+ class Edge {
+ friend class SymListGraph;
+ friend class SymListGraph::EdgeIt;
+ friend class SymListGraph::OutEdgeIt;
+ friend class SymListGraph::InEdgeIt;
+
+ protected:
+ int id;
+
+ Edge(int pid) { id = pid; }
+
+ public:
+ /// An Edge with id \c n.
+
+ Edge() { }
+ Edge (Invalid) { id = -1; }
+
+ operator SymEdge(){ return SymEdge(id >> 1);}
+
+ bool operator==(const Edge i) const {return id == i.id;}
+ bool operator!=(const Edge i) const {return id != i.id;}
+ bool operator<(const Edge i) const {return id < i.id;}
+ // ///Validity check
+ // operator bool() { return n!=-1; }
+ };
+
+ class SymEdge : public ListGraph::Edge {
+ friend class SymListGraph;
+ friend class SymListGraph::Edge;
+ typedef ListGraph::Edge Parent;
+
+ protected:
+ SymEdge(int pid) : Parent(pid) {}
+ public:
+
+ SymEdge() { }
+ SymEdge(const ListGraph::Edge& i) : Parent(i) {}
+ SymEdge (Invalid) : Parent(INVALID) {}
+
+ };
+
+ class OutEdgeIt {
+ Parent::OutEdgeIt out;
+ Parent::InEdgeIt in;
+ public:
+ OutEdgeIt() {}
+ OutEdgeIt(const SymListGraph& g, Edge e) {
+ if ((e.id & 1) == 0) {
+ out = Parent::OutEdgeIt(g, SymEdge(e));
+ in = Parent::InEdgeIt(g, g.tail(e));
+ } else {
+ out = Parent::OutEdgeIt(INVALID);
+ in = Parent::InEdgeIt(g, SymEdge(e));
+ }
+ }
+ OutEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
+
+ OutEdgeIt(const SymListGraph& g, const Node v)
+ : out(g, v), in(g, v) {}
+ OutEdgeIt &operator++() {
+ if (out != INVALID) {
+ ++out;
+ } else {
+ ++in;
+ }
+ return *this;
+ }
+
+ operator Edge() const {
+ if (out == INVALID && in == INVALID) return INVALID;
+ return out != INVALID ? forward(out) : backward(in);
+ }
+
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+ };
+
+ class InEdgeIt {
+ Parent::OutEdgeIt out;
+ Parent::InEdgeIt in;
+ public:
+ InEdgeIt() {}
+ InEdgeIt(const SymListGraph& g, Edge e) {
+ if ((e.id & 1) == 0) {
+ out = Parent::OutEdgeIt(g, SymEdge(e));
+ in = Parent::InEdgeIt(g, g.tail(e));
+ } else {
+ out = Parent::OutEdgeIt(INVALID);
+ in = Parent::InEdgeIt(g, SymEdge(e));
+ }
+ }
+ InEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
+
+ InEdgeIt(const SymListGraph& g, const Node v)
+ : out(g, v), in(g, v) {}
+
+ InEdgeIt &operator++() {
+ if (out != INVALID) {
+ ++out;
+ } else {
+ ++in;
+ }
+ return *this;
+ }
+
+ operator Edge() const {
+ if (out == INVALID && in == INVALID) return INVALID;
+ return out != INVALID ? backward(out) : forward(in);
+ }
+
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+ };
+
+ class SymEdgeIt : public Parent::EdgeIt {
+
+ public:
+ SymEdgeIt() {}
+
+ SymEdgeIt(const SymListGraph& g)
+ : SymListGraph::Parent::EdgeIt(g) {}
+
+ SymEdgeIt(const SymListGraph& g, SymEdge e)
+ : SymListGraph::Parent::EdgeIt(g, e) {}
+
+ SymEdgeIt(Invalid i)
+ : SymListGraph::Parent::EdgeIt(INVALID) {}
+
+ SymEdgeIt& operator++() {
+ SymListGraph::Parent::EdgeIt::operator++();
+ return *this;
+ }
+
+ operator SymEdge() const {
+ return SymEdge
+ (static_cast<const SymListGraph::Parent::EdgeIt&>(*this));
+ }
+ bool operator==(const SymEdge i) const {return SymEdge(*this) == i;}
+ bool operator!=(const SymEdge i) const {return SymEdge(*this) != i;}
+ bool operator<(const SymEdge i) const {return SymEdge(*this) < i;}
+ };
+
+ class EdgeIt {
+ SymEdgeIt it;
+ bool fw;
+ public:
+ EdgeIt(const SymListGraph& g) : it(g), fw(true) {}
+ EdgeIt (Invalid i) : it(i) { }
+ EdgeIt(const SymListGraph& g, Edge e)
+ : it(g, SymEdge(e)), fw(id(e) & 1 == 0) { }
+ EdgeIt() { }
+ EdgeIt& operator++() {
+ fw = !fw;
+ if (fw) ++it;
+ return *this;
+ }
+ operator Edge() const {
+ if (it == INVALID) return INVALID;
+ return fw ? forward(it) : backward(it);
+ }
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+
+ };
+ ///Number of nodes.
+ int nodeNum() const { return Parent::nodeNum(); }
+ ///Number of edges.
+ int edgeNum() const { return 2*Parent::edgeNum(); }
+ ///Number of symmetric edges.
+ int symEdgeNum() const { return Parent::edgeNum(); }
+
+ ///Set the expected maximum number of edges.
+
+ ///With this function, it is possible to set the expected number of edges.
+ ///The use of this fasten the building of the graph and makes
+ ///it possible to avoid the superfluous memory allocation.
+ void reserveSymEdge(int n) { Parent::reserveEdge(n); };
+
+ /// Maximum node ID.
+
+ /// Maximum node ID.
+ ///\sa id(Node)
+ int maxNodeId() const { return Parent::maxNodeId(); }
+ /// Maximum edge ID.
+
+ /// Maximum edge ID.
+ ///\sa id(Edge)
+ int maxEdgeId() const { return 2*Parent::maxEdgeId(); }
+ /// Maximum symmetric edge ID.
+
+ /// Maximum symmetric edge ID.
+ ///\sa id(SymEdge)
+ int maxSymEdgeId() const { return Parent::maxEdgeId(); }
+
+
+ Node tail(Edge e) const {
+ return (e.id & 1) == 0 ?
+ Parent::tail(SymEdge(e)) : Parent::head(SymEdge(e));
+ }
+
+ Node head(Edge e) const {
+ return (e.id & 1) == 0 ?
+ Parent::head(SymEdge(e)) : Parent::tail(SymEdge(e));
+ }
+
+ Node tail(SymEdge e) const {
+ return Parent::tail(e);
+ }
+
+ Node head(SymEdge e) const {
+ return Parent::head(e);
+ }
+
+ NodeIt& first(NodeIt& v) const {
+ v=NodeIt(*this); return v; }
+ EdgeIt& first(EdgeIt& e) const {
+ e=EdgeIt(*this); return e; }
+ SymEdgeIt& first(SymEdgeIt& e) const {
+ e=SymEdgeIt(*this); return e; }
+ OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
+ e=OutEdgeIt(*this,v); return e; }
+ InEdgeIt& first(InEdgeIt& e, const Node v) const {
+ e=InEdgeIt(*this,v); return e; }
+
+ /// Node ID.
+
+ /// The ID of a valid Node is a nonnegative integer not greater than
+ /// \ref maxNodeId(). The range of the ID's is not surely continuous
+ /// and the greatest node ID can be actually less then \ref maxNodeId().
+ ///
+ /// The ID of the \ref INVALID node is -1.
+ ///\return The ID of the node \c v.
+ static int id(Node v) { return Parent::id(v); }
+ /// Edge ID.
+
+ /// The ID of a valid Edge is a nonnegative integer not greater than
+ /// \ref maxEdgeId(). The range of the ID's is not surely continuous
+ /// and the greatest edge ID can be actually less then \ref maxEdgeId().
+ ///
+ /// The ID of the \ref INVALID edge is -1.
+ ///\return The ID of the edge \c e.
+ static int id(Edge e) { return e.id; }
+
+ /// The ID of a valid SymEdge is a nonnegative integer not greater than
+ /// \ref maxSymEdgeId(). The range of the ID's is not surely continuous
+ /// and the greatest edge ID can be actually less then \ref maxSymEdgeId().
+ ///
+ /// The ID of the \ref INVALID symmetric edge is -1.
+ ///\return The ID of the edge \c e.
+ static int id(SymEdge e) { return Parent::id(e); }
+
+ /// Adds a new node to the graph.
+
+ /// \warning It adds the new node to the front of the list.
+ /// (i.e. the lastly added node becomes the first.)
+ Node addNode() {
+ return Parent::addNode();
+ }
+
+ SymEdge addEdge(Node u, Node v) {
+ SymEdge se = Parent::addEdge(u, v);
+ edge_maps.add(forward(se));
+ edge_maps.add(backward(se));
+ return se;
+ }
+
+ /// Finds an edge between two nodes.
+
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u, Node v, Edge prev = INVALID)
+ {
+ if (prev == INVALID || id(prev) & 1 == 0) {
+ SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
+ if (se != INVALID) return forward(se);
+ } else {
+ SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
+ if (se != INVALID) return backward(se);
+ }
+ return INVALID;
+ }
+
+// /// Finds an symmetric edge between two nodes.
+
+// /// Finds an symmetric edge from node \c u to node \c v.
+// ///
+// /// If \c prev is \ref INVALID (this is the default value), then
+// /// It finds the first edge from \c u to \c v. Otherwise it looks for
+// /// the next edge from \c u to \c v after \c prev.
+// /// \return The found edge or INVALID if there is no such an edge.
+
+// SymEdge findEdge(Node u, Node v, SymEdge prev = INVALID)
+// {
+// if (prev == INVALID || id(prev) & 1 == 0) {
+// SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
+// if (se != INVALID) return se;
+// } else {
+// SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
+// if (se != INVALID) return se;
+// }
+// return INVALID;
+// }
+
+ public:
+
+ void erase(Node n) {
+ for (OutEdgeIt it(*this, n); it != INVALID; ++it) {
+ edge_maps.erase(it);
+ edge_maps.erase(opposite(it));
+ }
+ Parent::erase(n);
+ }
+
+ void erase(SymEdge e) {
+ edge_maps.erase(forward(e));
+ edge_maps.erase(backward(e));
+ Parent::erase(e);
+ };
+
+ void clear() {
+ edge_maps.clear();
+ Parent::clear();
+ }
+
+ static Edge opposite(Edge e) {
+ return Edge(id(e) ^ 1);
+ }
+
+ static Edge forward(SymEdge e) {
+ return Edge(id(e) << 1);
+ }
+
+ static Edge backward(SymEdge e) {
+ return Edge((id(e) << 1) | 1);
+ }
+
+ };
///A graph class containing only nodes.
Modified: hugo/branches/graph_factory/src/lemon/map_bits.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/map_bits.h (original)
+++ hugo/branches/graph_factory/src/lemon/map_bits.h Tue Oct 5 12:08:19 2004
@@ -54,10 +54,10 @@
template <typename Graph>
struct KeyInfo<Graph, typename Graph::SymEdgeIt> {
static int maxId(const Graph& graph) {
- return graph.maxEdgeId() >> 1;
+ return graph.maxSymEdgeId();
}
- static int id(const Graph& graph, const typename Graph::Edge& edge) {
- return graph.id(edge) >> 1;
+ static int id(const Graph& graph, const typename Graph::SymEdge& edge) {
+ return graph.id(edge);
}
};
Modified: hugo/branches/graph_factory/src/lemon/map_defines.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/map_defines.h (original)
+++ hugo/branches/graph_factory/src/lemon/map_defines.h Tue Oct 5 12:08:19 2004
@@ -114,8 +114,7 @@
/** This macro creates MapRegistry for Symmetric Edge Maps.
*/
#define CREATE_SYM_EDGE_MAP_REGISTRY \
-typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
-typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
+typedef MapRegistry<Graph, SymEdge, SymEdgeIt> SymEdgeMapRegistry; \
mutable SymEdgeMapRegistry sym_edge_maps;
@@ -127,9 +126,9 @@
*/
#define CREATE_SYM_EDGE_MAP(DynMap) \
template <typename Value> \
-class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
+class SymEdgeMap : public DynMap<SymEdgeMapRegistry, Value> { \
public: \
-typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \
+typedef DynMap<SymEdgeMapRegistry, Value> Parent; \
\
SymEdgeMap(const typename Parent::Graph& g) \
: Parent(g, g.sym_edge_maps) {} \
Modified: hugo/branches/graph_factory/src/lemon/map_registry.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/map_registry.h (original)
+++ hugo/branches/graph_factory/src/lemon/map_registry.h Tue Oct 5 12:08:19 2004
@@ -27,24 +27,35 @@
namespace lemon {
-/// \addtogroup graphmapfactory
-/// @{
+ /// \addtogroup graphmapfactory
+ /// @{
+
+ /// Map registry for graph maps.
+
+ /**
+ * Registry class to register edge or node maps into the graph. The
+ * registry helps you to implement an observer pattern. If you add
+ * or erase an edge or node you must notify all the maps about the
+ * event.
+ *
+ * \param G The graph type to register maps.
+ * \param K The key type of the maps registered into the registry.
+ * \param KIt The key iterator type iterates on the keys.
+ *
+ * \author Balazs Dezso
+ */
-/**
- * Registry class to register edge or node maps into the graph. The
- * registry helps you to implement an observer pattern. If you add
- * or erase an edge or node you must notify all the maps about the
- * event.
-*/
template <typename G, typename K, typename KIt>
class MapRegistry {
public:
typedef G Graph;
typedef K KeyType;
typedef KIt KeyIt;
+
+ /// MapBase is the base class of the dynamic maps.
/**
- * MapBase is the base class of the registered maps.
+ * MapBase is the base class of the dynamic maps.
* It defines the core modification operations on the maps and
* implements some helper functions.
*/
@@ -58,22 +69,30 @@
friend class MapRegistry<G, K, KIt>;
+ /// Default constructor.
+
/**
* Default constructor for MapBase.
*/
MapBase() : graph(0), registry(0) {}
+
+ /// Constructor to register map into a graph registry.
/**
- * Simple constructor to register into a graph registry.
+ * Simple constructor to register dynamic map into a graph registry.
*/
MapBase(const Graph& g, Registry& r) : graph(&g), registry(0) {
r.attach(*this);
}
+ /// Copy constructor.
+
/**
* Copy constructor to register into the registry.
+ * If the copiable map is registered into a registry
+ * the construated map will be registered to the same registry.
*/
MapBase(const MapBase& copy) : graph(copy.graph), registry(0) {
@@ -81,9 +100,13 @@
copy.registry->attach(*this);
}
}
+
+ /// Assign operator.
/**
- * Assign operator.
+ * Assign operator. This member detach first the map
+ * from the current registry and then it attach to the
+ * copiable map's registry if it exists.
*/
const MapBase& operator=(const MapBase& copy) {
if (registry) {
@@ -96,9 +119,11 @@
return *this;
}
+ /// Destructor
/**
- * Destructor.
+ * This member detach the map from the its registry if the
+ * registry exists.
*/
virtual ~MapBase() {
@@ -107,6 +132,8 @@
}
}
+ /// The graph of the map.
+
/*
* Returns the graph that the map belongs to.
*/
@@ -121,9 +148,14 @@
int registry_index;
protected:
+
+ /// Helper function to implement constructors in the subclasses.
/**
- Helper function to implement constructors in the subclasses.
+ * Helper function to implement constructors in the subclasses.
+ * It adds all of the nodes or edges to the map via the
+ * \ref MapRegistry::MapBase::add add
+ * member function.
*/
virtual void init() {
@@ -132,8 +164,14 @@
}
}
+
+ /// Helper function to implement destructors in the subclasses.
+
/**
- Helper function to implement the destructor in the subclasses.
+ * Helper function to implement destructors in the subclasses.
+ * It erases all of the nodes or edges of the map via the
+ * \ref MapRegistry::MapBase::erase erase
+ * member function. It can be used by the clear function also.
*/
virtual void destroy() {
@@ -141,16 +179,22 @@
erase(it);
}
}
+
+ /// The member function to add new node or edge to the map.
/**
The add member function should be overloaded in the subclasses.
- \e Add extends the map with the new node.
+ \e Add extends the map with the new node or edge.
*/
virtual void add(const KeyType&) = 0;
+
+
+ /// The member function to erase a node or edge from the map.
+
/**
The erase member function should be overloaded in the subclasses.
- \e Erase removes the node from the map.
+ \e Erase removes the node or edge from the map.
*/
virtual void erase(const KeyType&) = 0;
@@ -161,9 +205,13 @@
*/
virtual void clear() = 0;
+
+ /// Exception class to throw at unsupported operation.
/**
- Exception class to throw at unsupported operation.
+ * Exception class to throw at unsupported operation.
+ * If the map does not support erasing or adding new
+ * node or key it must be throwed.
*/
class NotSupportedOperationException {};
@@ -172,50 +220,58 @@
protected:
- /**
- * The container type of the maps.
- */
+
typedef std::vector<MapBase*> Container;
- /**
- * The container of the registered maps.
- */
Container container;
public:
+
+ /// Default constructor.
/**
- * Default Constructor of the MapRegistry. It creates an empty registry.
+ * Default constructor of the \e MapRegistry.
+ * It creates an empty registry.
*/
MapRegistry() {}
+
+ /// Copy Constructor of the MapRegistry.
/**
- * Copy Constructor of the MapRegistry. The new registry does not steal
- * the maps from the right value. The new registry will be an empty.
+ * Copy constructor of the \e MapRegistry.
+ * The new registry does not steal
+ * the maps from the copiable registry.
+ * The new registry will be empty.
*/
MapRegistry(const MapRegistry&) {}
+
+ /// Assign operator.
/**
- * Assign operator. The left value does not steal the maps
- * from the right value. The left value will be an empty registry.
+ * Assign operator. This registry does not steal the maps
+ * from the copiable registry. This registry will be an empty registry.
+ * This operator will be called when a graph is assigned.
*/
MapRegistry& operator=(const MapRegistry&) {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
- (*it)->destroy();
+ (*it)->clear();
(*it)->graph = 0;
(*it)->registry = 0;
}
}
+
+ /// Destructor.
/**
- * Destructor of the MapRegistry.
+ * Destructor of the MapRegistry. It makes empty the attached map
+ * first then detachs them.
*/
~MapRegistry() {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
- (*it)->destroy();
+ (*it)->clear();
(*it)->registry = 0;
(*it)->graph = 0;
}
@@ -223,9 +279,11 @@
public:
+
+ /// Attachs a map to the \e MapRegistry.
/**
- * Attach a map into thr registry. If the map has been attached
+ * Attachs a map into thr registry. If the map has been attached
* into an other registry it is detached from that automaticly.
*/
void attach(MapBase& map) {
@@ -236,9 +294,11 @@
map.registry = this;
map.registry_index = container.size()-1;
}
+
+ /// Detachs a map from the \e MapRegistry.
/**
- * Detach the map from the registry.
+ * Detachs a map from the \e MapRegistry.
*/
void detach(MapBase& map) {
container.back()->registry_index = map.registry_index;
@@ -248,29 +308,41 @@
map.graph = 0;
}
+ /// Notify all the registered maps about a Key added.
/**
* Notify all the registered maps about a Key added.
+ * This member should be called whenever a node or edge
+ * is added to the graph.
*/
- void add(KeyType& key) {
+ void add(const KeyType& key) {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
(*it)->add(key);
}
}
+
+ /// Notify all the registered maps about a Key erased.
/**
* Notify all the registered maps about a Key erased.
+ * This member should be called whenever a node or edge
+ * is erased from the graph.
*/
- void erase(KeyType& key) {
+ void erase(const KeyType& key) {
typename Container::iterator it;
for (it = container.begin(); it != container.end(); ++it) {
(*it)->erase(key);
}
}
+
+ /// Notify all the registered maps about all the Keys are erased.
+
/**
* Notify all the registered maps about the map should be cleared.
+ * This member should be called whenever all of the nodes or edges
+ * are erased from the graph.
*/
void clear() {
typename Container::iterator it;
Modified: hugo/branches/graph_factory/src/lemon/smart_graph.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/smart_graph.h (original)
+++ hugo/branches/graph_factory/src/lemon/smart_graph.h Tue Oct 5 12:08:19 2004
@@ -26,8 +26,8 @@
#include <lemon/invalid.h>
+
#include <lemon/array_map.h>
-#include <lemon/sym_map.h>
#include <lemon/map_registry.h>
@@ -298,6 +298,381 @@
};
+
+
+ class SymSmartGraph : public SmartGraph {
+ typedef SmartGraph Parent;
+ public:
+
+ typedef SymSmartGraph Graph;
+
+ typedef SmartGraph::Node Node;
+ typedef SmartGraph::NodeIt NodeIt;
+
+ class SymEdge;
+ class SymEdgeIt;
+
+ class Edge;
+ class EdgeIt;
+ class OutEdgeIt;
+ class InEdgeIt;
+
+ template <typename Value>
+ class NodeMap : public Parent::NodeMap<Value> {
+ public:
+ NodeMap(const SymSmartGraph& g)
+ : SymSmartGraph::Parent::NodeMap<Value>(g) {}
+ NodeMap(const SymSmartGraph& g, Value v)
+ : SymSmartGraph::Parent::NodeMap<Value>(g, v) {}
+ template<typename TT>
+ NodeMap(const NodeMap<TT>& copy)
+ : SymSmartGraph::Parent::NodeMap<Value>(copy) { }
+ };
+
+ template <typename Value>
+ class SymEdgeMap : public Parent::EdgeMap<Value> {
+ public:
+ typedef SymEdge KeyType;
+
+ SymEdgeMap(const SymSmartGraph& g)
+ : SymSmartGraph::Parent::EdgeMap<Value>(g) {}
+ SymEdgeMap(const SymSmartGraph& g, Value v)
+ : SymSmartGraph::Parent::EdgeMap<Value>(g, v) {}
+ template<typename TT>
+ SymEdgeMap(const SymEdgeMap<TT>& copy)
+ : SymSmartGraph::Parent::EdgeMap<Value>(copy) { }
+
+ };
+
+ // Create edge map registry.
+ CREATE_EDGE_MAP_REGISTRY;
+ // Create edge maps.
+ CREATE_EDGE_MAP(ArrayMap);
+
+ class Edge {
+ friend class SymSmartGraph;
+ friend class SymSmartGraph::EdgeIt;
+ friend class SymSmartGraph::OutEdgeIt;
+ friend class SymSmartGraph::InEdgeIt;
+
+ protected:
+ int id;
+
+ Edge(int pid) { id = pid; }
+
+ public:
+ /// An Edge with id \c n.
+
+ Edge() { }
+ Edge (Invalid) { id = -1; }
+
+ operator SymEdge(){ return SymEdge(id >> 1);}
+
+ bool operator==(const Edge i) const {return id == i.id;}
+ bool operator!=(const Edge i) const {return id != i.id;}
+ bool operator<(const Edge i) const {return id < i.id;}
+ // ///Validity check
+ // operator bool() { return n!=-1; }
+ };
+
+ class SymEdge : public SmartGraph::Edge {
+ friend class SymSmartGraph;
+ friend class SymSmartGraph::Edge;
+ typedef SmartGraph::Edge Parent;
+
+ protected:
+ SymEdge(int pid) : Parent(pid) {}
+ public:
+
+ SymEdge() { }
+ SymEdge(const SmartGraph::Edge& i) : Parent(i) {}
+ SymEdge (Invalid) : Parent(INVALID) {}
+
+ };
+
+ class OutEdgeIt {
+ Parent::OutEdgeIt out;
+ Parent::InEdgeIt in;
+ public:
+ OutEdgeIt() {}
+ OutEdgeIt(const SymSmartGraph& g, Edge e) {
+ if ((e.id & 1) == 0) {
+ out = Parent::OutEdgeIt(g, SymEdge(e));
+ in = Parent::InEdgeIt(g, g.tail(e));
+ } else {
+ out = Parent::OutEdgeIt(INVALID);
+ in = Parent::InEdgeIt(g, SymEdge(e));
+ }
+ }
+ OutEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
+
+ OutEdgeIt(const SymSmartGraph& g, const Node v)
+ : out(g, v), in(g, v) {}
+ OutEdgeIt &operator++() {
+ if (out != INVALID) {
+ ++out;
+ } else {
+ ++in;
+ }
+ return *this;
+ }
+
+ operator Edge() const {
+ if (out == INVALID && in == INVALID) return INVALID;
+ return out != INVALID ? forward(out) : backward(in);
+ }
+
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+ };
+
+ class InEdgeIt {
+ Parent::OutEdgeIt out;
+ Parent::InEdgeIt in;
+ public:
+ InEdgeIt() {}
+ InEdgeIt(const SymSmartGraph& g, Edge e) {
+ if ((e.id & 1) == 0) {
+ out = Parent::OutEdgeIt(g, SymEdge(e));
+ in = Parent::InEdgeIt(g, g.tail(e));
+ } else {
+ out = Parent::OutEdgeIt(INVALID);
+ in = Parent::InEdgeIt(g, SymEdge(e));
+ }
+ }
+ InEdgeIt (Invalid i) : out(INVALID), in(INVALID) { }
+
+ InEdgeIt(const SymSmartGraph& g, const Node v)
+ : out(g, v), in(g, v) {}
+
+ InEdgeIt &operator++() {
+ if (out != INVALID) {
+ ++out;
+ } else {
+ ++in;
+ }
+ return *this;
+ }
+
+ operator Edge() const {
+ if (out == INVALID && in == INVALID) return INVALID;
+ return out != INVALID ? backward(out) : forward(in);
+ }
+
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+ };
+
+ class SymEdgeIt : public Parent::EdgeIt {
+
+ public:
+ SymEdgeIt() {}
+
+ SymEdgeIt(const SymSmartGraph& g)
+ : SymSmartGraph::Parent::EdgeIt(g) {}
+
+ SymEdgeIt(const SymSmartGraph& g, SymEdge e)
+ : SymSmartGraph::Parent::EdgeIt(g, e) {}
+
+ SymEdgeIt(Invalid i)
+ : SymSmartGraph::Parent::EdgeIt(INVALID) {}
+
+ SymEdgeIt& operator++() {
+ SymSmartGraph::Parent::EdgeIt::operator++();
+ return *this;
+ }
+
+ operator SymEdge() const {
+ return SymEdge
+ (static_cast<const SymSmartGraph::Parent::EdgeIt&>(*this));
+ }
+ bool operator==(const SymEdge i) const {return SymEdge(*this) == i;}
+ bool operator!=(const SymEdge i) const {return SymEdge(*this) != i;}
+ bool operator<(const SymEdge i) const {return SymEdge(*this) < i;}
+ };
+
+ class EdgeIt {
+ SymEdgeIt it;
+ bool fw;
+ public:
+ EdgeIt(const SymSmartGraph& g) : it(g), fw(true) {}
+ EdgeIt (Invalid i) : it(i) { }
+ EdgeIt(const SymSmartGraph& g, Edge e)
+ : it(g, SymEdge(e)), fw(id(e) & 1 == 0) { }
+ EdgeIt() { }
+ EdgeIt& operator++() {
+ fw = !fw;
+ if (fw) ++it;
+ return *this;
+ }
+ operator Edge() const {
+ if (it == INVALID) return INVALID;
+ return fw ? forward(it) : backward(it);
+ }
+ bool operator==(const Edge i) const {return Edge(*this) == i;}
+ bool operator!=(const Edge i) const {return Edge(*this) != i;}
+ bool operator<(const Edge i) const {return Edge(*this) < i;}
+
+ };
+
+ ///Number of nodes.
+ int nodeNum() const { return Parent::nodeNum(); }
+ ///Number of edges.
+ int edgeNum() const { return 2*Parent::edgeNum(); }
+ ///Number of symmetric edges.
+ int symEdgeNum() const { return Parent::edgeNum(); }
+
+ /// Maximum node ID.
+
+ /// Maximum node ID.
+ ///\sa id(Node)
+ int maxNodeId() const { return Parent::maxNodeId(); }
+ /// Maximum edge ID.
+
+ /// Maximum edge ID.
+ ///\sa id(Edge)
+ int maxEdgeId() const { return 2*Parent::maxEdgeId(); }
+ /// Maximum symmetric edge ID.
+
+ /// Maximum symmetric edge ID.
+ ///\sa id(SymEdge)
+ int maxSymEdgeId() const { return Parent::maxEdgeId(); }
+
+
+ Node tail(Edge e) const {
+ return (e.id & 1) == 0 ?
+ Parent::tail(SymEdge(e)) : Parent::head(SymEdge(e));
+ }
+
+ Node head(Edge e) const {
+ return (e.id & 1) == 0 ?
+ Parent::head(SymEdge(e)) : Parent::tail(SymEdge(e));
+ }
+
+ Node tail(SymEdge e) const {
+ return Parent::tail(e);
+ }
+
+ Node head(SymEdge e) const {
+ return Parent::head(e);
+ }
+
+ NodeIt& first(NodeIt& v) const {
+ v=NodeIt(*this); return v; }
+ EdgeIt& first(EdgeIt& e) const {
+ e=EdgeIt(*this); return e; }
+ SymEdgeIt& first(SymEdgeIt& e) const {
+ e=SymEdgeIt(*this); return e; }
+ OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
+ e=OutEdgeIt(*this,v); return e; }
+ InEdgeIt& first(InEdgeIt& e, const Node v) const {
+ e=InEdgeIt(*this,v); return e; }
+
+ /// Node ID.
+
+ /// The ID of a valid Node is a nonnegative integer not greater than
+ /// \ref maxNodeId(). The range of the ID's is not surely continuous
+ /// and the greatest node ID can be actually less then \ref maxNodeId().
+ ///
+ /// The ID of the \ref INVALID node is -1.
+ ///\return The ID of the node \c v.
+ static int id(Node v) { return Parent::id(v); }
+ /// Edge ID.
+
+ /// The ID of a valid Edge is a nonnegative integer not greater than
+ /// \ref maxEdgeId(). The range of the ID's is not surely continuous
+ /// and the greatest edge ID can be actually less then \ref maxEdgeId().
+ ///
+ /// The ID of the \ref INVALID edge is -1.
+ ///\return The ID of the edge \c e.
+ static int id(Edge e) { return e.id; }
+
+ /// The ID of a valid SymEdge is a nonnegative integer not greater than
+ /// \ref maxSymEdgeId(). The range of the ID's is not surely continuous
+ /// and the greatest edge ID can be actually less then \ref maxSymEdgeId().
+ ///
+ /// The ID of the \ref INVALID symmetric edge is -1.
+ ///\return The ID of the edge \c e.
+ static int id(SymEdge e) { return Parent::id(e); }
+
+ /// Adds a new node to the graph.
+
+ /// \warning It adds the new node to the front of the list.
+ /// (i.e. the lastly added node becomes the first.)
+ Node addNode() {
+ return Parent::addNode();
+ }
+
+ SymEdge addEdge(Node u, Node v) {
+ SymEdge se = Parent::addEdge(u, v);
+ edge_maps.add(forward(se));
+ edge_maps.add(backward(se));
+ return se;
+ }
+
+ /// Finds an edge between two nodes.
+
+ /// Finds an edge from node \c u to node \c v.
+ ///
+ /// If \c prev is \ref INVALID (this is the default value), then
+ /// It finds the first edge from \c u to \c v. Otherwise it looks for
+ /// the next edge from \c u to \c v after \c prev.
+ /// \return The found edge or INVALID if there is no such an edge.
+ Edge findEdge(Node u, Node v, Edge prev = INVALID)
+ {
+ if (prev == INVALID || id(prev) & 1 == 0) {
+ SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
+ if (se != INVALID) return forward(se);
+ } else {
+ SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
+ if (se != INVALID) return backward(se);
+ }
+ return INVALID;
+ }
+
+// /// Finds an symmetric edge between two nodes.
+
+// /// Finds an symmetric edge from node \c u to node \c v.
+// ///
+// /// If \c prev is \ref INVALID (this is the default value), then
+// /// It finds the first edge from \c u to \c v. Otherwise it looks for
+// /// the next edge from \c u to \c v after \c prev.
+// /// \return The found edge or INVALID if there is no such an edge.
+
+// SymEdge findEdge(Node u, Node v, SymEdge prev = INVALID)
+// {
+// if (prev == INVALID || id(prev) & 1 == 0) {
+// SymEdge se = Parent::findEdge(u, v, SymEdge(prev));
+// if (se != INVALID) return se;
+// } else {
+// SymEdge se = Parent::findEdge(v, u, SymEdge(prev));
+// if (se != INVALID) return se;
+// }
+// return INVALID;
+// }
+
+ public:
+
+ void clear() {
+ edge_maps.clear();
+ Parent::clear();
+ }
+
+ static Edge opposite(Edge e) {
+ return Edge(id(e) ^ 1);
+ }
+
+ static Edge forward(SymEdge e) {
+ return Edge(id(e) << 1);
+ }
+
+ static Edge backward(SymEdge e) {
+ return Edge((id(e) << 1) | 1);
+ }
+
+ };
///Graph for bidirectional edges.
///The purpose of this graph structure is to handle graphs
@@ -318,7 +693,7 @@
///it is not possible to delete edges or nodes from the graph.
//\sa SmartGraph.
- class SymSmartGraph : public SmartGraph
+ /* class SymSmartGraph : public SmartGraph
{
public:
typedef SymSmartGraph Graph;
@@ -353,7 +728,7 @@
}
- };
+ };*/
/// @}
} //namespace lemon
Modified: hugo/branches/graph_factory/src/lemon/vector_map.h
==============================================================================
--- hugo/branches/graph_factory/src/lemon/vector_map.h (original)
+++ hugo/branches/graph_factory/src/lemon/vector_map.h Tue Oct 5 12:08:19 2004
@@ -31,18 +31,16 @@
/// \addtogroup graphmaps
/// @{
- /** The ArrayMap template class is graph map structure what
+ /** The VectorMap template class is graph map structure what
* automatically updates the map when a key is added to or erased from
* the map. This map factory uses the allocators to implement
* the container functionality. This map factory
* uses the std::vector to implement the container function.
*
- * The template parameter is the MapRegistry that the maps
- * will belong to and the ValueType.
+ * \param MapRegistry The MapRegistry that the maps will belong to.
+ * \param Value The value type of the map.
*
- * \todo It should use a faster initialization using the maxNodeId() or
- * maxEdgeId() function of the graph instead of iterating through each
- * edge/node.
+ * \author Balazs Dezso
*/
template <typename MapRegistry, typename Value>
@@ -84,17 +82,27 @@
/// The pointer type of the map;
typedef typename Container::const_pointer ConstPointerType;
- /** Graph and Registry initialized map constructor.
+ /// Constructor to attach the new map into a registry.
+
+ /** Constructor to attach the new map into a registry.
+ * It adds all the nodes or edges of the graph to the map.
*/
VectorMap(const Graph& g, MapRegistry& r)
: MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
- /** Constructor to use default value to initialize the map.
+ /// Constructor uses given value to initialize the map.
+
+ /** Constructor uses given value to initialize the map.
+ * It adds all the nodes or edges of the graph to the map.
*/
VectorMap(const Graph& g, MapRegistry& r, const Value& v)
: MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
+ /// Assign operator to copy a map of an other map type.
+
/** Assign operator to copy a map of an other map type.
+ * This map's value type must be assignable by the other
+ * map type's value type.
*/
template <typename TT>
VectorMap(const VectorMap<MapRegistry, TT>& c)
@@ -105,7 +113,11 @@
}
}
+ /// Assign operator to copy a map of an other map type.
+
/** Assign operator to copy a map of an other map type.
+ * This map's value type must be assignable by the other
+ * map type's value type.
*/
template <typename TT>
VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) {
@@ -119,6 +131,9 @@
}
return *this;
}
+
+ /// The subcript operator.
+
/**
* The subscript operator. The map can be subscripted by the
* actual keys of the graph.
@@ -128,6 +143,8 @@
return container[id];
}
+ /// The const subcript operator.
+
/**
* The const subscript operator. The map can be subscripted by the
* actual keys of the graph.
@@ -137,6 +154,8 @@
return container[id];
}
+ ///Setter function of the map.
+
/** Setter function of the map. Equivalent with map[key] = val.
* This is a compatibility feature with the not dereferable maps.
*/
@@ -144,8 +163,11 @@
int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
container[id] = val;
}
+ /// Adds a new key to the map.
- /** Add a new key to the map. It called by the map registry.
+ /** Adds a new key to the map. It called by the map registry
+ * and it overrides the \ref MapRegistry::MapBase MapBase's
+ * add() member function.
*/
void add(const KeyType& key) {
int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
@@ -153,13 +175,22 @@
container.resize(id + 1);
}
}
+
+ /// Erases a key from the map.
- /** Erase a key from the map. It called by the map registry.
+ /** Erase a key from the map. It called by the map registry
+ * and it overrides the \ref MapRegistry::MapBase MapBase's
+ * erase() member function.
*/
void erase(const KeyType& key) {}
- /** Clear the data structure.
+ /// Makes empty the map.
+
+ /** Makes empty the map. It called by the map registry
+ * and it overrides the \ref MapRegistry::MapBase MapBase's
+ * clear() member function.
*/
+
void clear() {
container.clear();
}
Modified: hugo/branches/graph_factory/src/test/Makefile.am
==============================================================================
--- hugo/branches/graph_factory/src/test/Makefile.am (original)
+++ hugo/branches/graph_factory/src/test/Makefile.am Tue Oct 5 12:08:19 2004
@@ -2,13 +2,14 @@
EXTRA_DIST = preflow_graph.dim #input file for preflow_test.cc
-noinst_HEADERS = test_tools.h graph_test.h
+noinst_HEADERS = test_tools.h graph_test.h sym_graph_test.h
check_PROGRAMS = \
bfs_test \
dfs_test \
dijkstra_test \
graph_test \
+ sym_graph_test \
graph_wrapper_test \
kruskal_test \
min_cost_flow_test \
@@ -29,6 +30,7 @@
dfs_test_SOURCES = dfs_test.cc
dijkstra_test_SOURCES = dijkstra_test.cc
graph_test_SOURCES = graph_test.cc
+sym_graph_test_SOURCES = sym_graph_test.cc
graph_wrapper_test_SOURCES = graph_wrapper_test.cc
kruskal_test_SOURCES = kruskal_test.cc
min_cost_flow_test_SOURCES = min_cost_flow_test.cc
Modified: hugo/branches/graph_factory/src/test/graph_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.cc (original)
+++ hugo/branches/graph_factory/src/test/graph_test.cc Tue Oct 5 12:08:19 2004
@@ -63,56 +63,64 @@
for(NodeIt n(G);n!=INVALID;++n) {
checkGraphInEdgeList(G,n,3);
checkGraphOutEdgeList(G,n,3);
- ++n;
}
}
//Compile Graph
-template void lemon::checkCompileStaticGraph<skeleton::StaticGraph>
+template void lemon::skeleton::checkCompileStaticGraph<skeleton::StaticGraph>
(skeleton::StaticGraph &);
-template void lemon::checkCompileGraph<skeleton::ExtendableGraph>
+template
+void lemon::skeleton::checkCompileExtendableGraph<skeleton::ExtendableGraph>
(skeleton::ExtendableGraph &);
-template void lemon::checkCompileErasableGraph<skeleton::ErasableGraph>
+template
+void lemon::skeleton::checkCompileErasableGraph<skeleton::ErasableGraph>
(skeleton::ErasableGraph &);
//Compile SmartGraph
-template void lemon::checkCompileGraph<SmartGraph>(SmartGraph &);
-template void lemon::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
+template
+void lemon::skeleton::checkCompileExtendableGraph<SmartGraph>(SmartGraph &);
+template
+void lemon::skeleton::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);
//Compile SymSmartGraph
-template void lemon::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
-template void lemon::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
+//template void hugo::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
+//template void hugo::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);
//Compile ListGraph
-template void lemon::checkCompileGraph<ListGraph>(ListGraph &);
-template void lemon::checkCompileErasableGraph<ListGraph>(ListGraph &);
-template void lemon::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
+template
+void lemon::skeleton::checkCompileExtendableGraph<ListGraph>(ListGraph &);
+template
+void lemon::skeleton::checkCompileErasableGraph<ListGraph>(ListGraph &);
+template
+void lemon::skeleton::checkCompileGraphFindEdge<ListGraph>(ListGraph &);
//Compile SymListGraph
-template void lemon::checkCompileGraph<SymListGraph>(SymListGraph &);
-template void lemon::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
-template void lemon::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
+//template void hugo::checkCompileGraph<SymListGraph>(SymListGraph &);
+//template void hugo::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
+//template void hugo::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);
//Compile FullGraph
-template void lemon::checkCompileStaticGraph<FullGraph>(FullGraph &);
-template void lemon::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
+template void lemon::skeleton::checkCompileStaticGraph<FullGraph>(FullGraph &);
+template
+void lemon::skeleton::checkCompileGraphFindEdge<FullGraph>(FullGraph &);
//Compile EdgeSet <ListGraph>
-template void lemon::checkCompileGraph<EdgeSet <ListGraph> >
+template void lemon::skeleton::checkCompileExtendableGraph<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);
-template void lemon::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
+template void lemon::skeleton::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);
-template void lemon::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
+template void lemon::skeleton::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);
//Compile EdgeSet <NodeSet>
-template void lemon::checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
-template void lemon::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
+template void lemon::skeleton::checkCompileExtendableGraph<EdgeSet <NodeSet> >
(EdgeSet <NodeSet> &);
-template void lemon::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
+template void lemon::skeleton::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
+(EdgeSet <NodeSet> &);
+template void lemon::skeleton::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
(EdgeSet <NodeSet> &);
@@ -131,14 +139,14 @@
checkPetersen(G);
}
{
- SymSmartGraph G;
- addPetersen(G);
- checkPetersen(G);
+ // SymSmartGraph G;
+ // addPetersen(G);
+ // checkPetersen(G);
}
{
- SymListGraph G;
- addPetersen(G);
- checkPetersen(G);
+ // SymListGraph G;
+ // addPetersen(G);
+ // checkPetersen(G);
}
///\file
Modified: hugo/branches/graph_factory/src/test/graph_test.h
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_test.h (original)
+++ hugo/branches/graph_factory/src/test/graph_test.h Tue Oct 5 12:08:19 2004
@@ -24,251 +24,6 @@
//! \brief Some utility to test graph classes.
namespace lemon {
- struct DummyType {
- int value;
- DummyType() {}
- DummyType(int p) : value(p) {}
- DummyType& operator=(int p) { value = p; return *this;}
- };
-
-
- template<class Graph> void checkCompileStaticGraph(Graph &G)
- {
- typedef typename Graph::Node Node;
- typedef typename Graph::NodeIt NodeIt;
- typedef typename Graph::Edge Edge;
- typedef typename Graph::EdgeIt EdgeIt;
- typedef typename Graph::InEdgeIt InEdgeIt;
- typedef typename Graph::OutEdgeIt OutEdgeIt;
-
- {
- Node i; Node j(i); Node k(INVALID);
- i=j;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- b=(i==j); b=(i!=j); b=(i<j);
- }
- {
- NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
- i=j;
- j=G.first(i);
- j=++i;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- Node n(i);
- n=i;
- b=(i==j); b=(i!=j); b=(i<j);
- //Node ->NodeIt conversion
- NodeIt ni(G,n);
- }
- {
- Edge i; Edge j(i); Edge k(INVALID);
- i=j;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- b=(i==j); b=(i!=j); b=(i<j);
- }
- {
- EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
- i=j;
- j=G.first(i);
- j=++i;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- Edge e(i);
- e=i;
- b=(i==j); b=(i!=j); b=(i<j);
- //Edge ->EdgeIt conversion
- EdgeIt ei(G,e);
- }
- {
- Node n;
- InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
- i=j;
- j=G.first(i,n);
- j=++i;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- Edge e(i);
- e=i;
- b=(i==j); b=(i!=j); b=(i<j);
- //Edge ->InEdgeIt conversion
- InEdgeIt ei(G,e);
- }
- {
- Node n;
- OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
- i=j;
- j=G.first(i,n);
- j=++i;
- bool b; b=true;
- b=(i==INVALID); b=(i!=INVALID);
- Edge e(i);
- e=i;
- b=(i==j); b=(i!=j); b=(i<j);
- //Edge ->OutEdgeIt conversion
- OutEdgeIt ei(G,e);
- }
- {
- Node n,m;
- n=m=INVALID;
- Edge e;
- e=INVALID;
- n=G.tail(e);
- n=G.head(e);
- }
- // id tests
- { Node n; int i=G.id(n); i=i; }
- { Edge e; int i=G.id(e); i=i; }
- //NodeMap tests
- {
- Node k;
- typename Graph::template NodeMap<int> m(G);
- //Const map
- typename Graph::template NodeMap<int> const &cm = m;
- //Inicialize with default value
- typename Graph::template NodeMap<int> mdef(G,12);
- //Copy
- typename Graph::template NodeMap<int> mm(cm);
- //Copy from another type
- typename Graph::template NodeMap<double> dm(cm);
- //Copy to more complex type
- typename Graph::template NodeMap<DummyType> em(cm);
- int v;
- v=m[k]; m[k]=v; m.set(k,v);
- v=cm[k];
-
- m=cm;
- dm=cm; //Copy from another type
- em=cm; //Copy to more complex type
- {
- //Check the typedef's
- typename Graph::template NodeMap<int>::ValueType val;
- val=1;
- typename Graph::template NodeMap<int>::KeyType key;
- key = typename Graph::NodeIt(G);
- }
- }
- { //bool NodeMap
- Node k;
- typename Graph::template NodeMap<bool> m(G);
- typename Graph::template NodeMap<bool> const &cm = m; //Const map
- //Inicialize with default value
- typename Graph::template NodeMap<bool> mdef(G,12);
- typename Graph::template NodeMap<bool> mm(cm); //Copy
- typename Graph::template NodeMap<int> dm(cm); //Copy from another type
- bool v;
- v=m[k]; m[k]=v; m.set(k,v);
- v=cm[k];
-
- m=cm;
- dm=cm; //Copy from another type
- m=dm; //Copy to another type
-
- {
- //Check the typedef's
- typename Graph::template NodeMap<bool>::ValueType val;
- val=true;
- typename Graph::template NodeMap<bool>::KeyType key;
- key= typename Graph::NodeIt(G);
- }
- }
- //EdgeMap tests
- {
- Edge k;
- typename Graph::template EdgeMap<int> m(G);
- typename Graph::template EdgeMap<int> const &cm = m; //Const map
- //Inicialize with default value
- typename Graph::template EdgeMap<int> mdef(G,12);
- typename Graph::template EdgeMap<int> mm(cm); //Copy
- typename Graph::template EdgeMap<double> dm(cm); //Copy from another type
- int v;
- v=m[k]; m[k]=v; m.set(k,v);
- v=cm[k];
-
- m=cm;
- dm=cm; //Copy from another type
- {
- //Check the typedef's
- typename Graph::template EdgeMap<int>::ValueType val;
- val=1;
- typename Graph::template EdgeMap<int>::KeyType key;
- key= typename Graph::EdgeIt(G);
- }
- }
- { //bool EdgeMap
- Edge k;
- typename Graph::template EdgeMap<bool> m(G);
- typename Graph::template EdgeMap<bool> const &cm = m; //Const map
- //Inicialize with default value
- typename Graph::template EdgeMap<bool> mdef(G,12);
- typename Graph::template EdgeMap<bool> mm(cm); //Copy
- typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
- bool v;
- v=m[k]; m[k]=v; m.set(k,v);
- v=cm[k];
-
- m=cm;
- dm=cm; //Copy from another type
- m=dm; //Copy to another type
- {
- //Check the typedef's
- typename Graph::template EdgeMap<bool>::ValueType val;
- val=true;
- typename Graph::template EdgeMap<bool>::KeyType key;
- key= typename Graph::EdgeIt(G);
- }
- }
- }
-
- template<class Graph> void checkCompileGraph(Graph &G)
- {
- checkCompileStaticGraph(G);
-
- typedef typename Graph::Node Node;
- typedef typename Graph::NodeIt NodeIt;
- typedef typename Graph::Edge Edge;
- typedef typename Graph::EdgeIt EdgeIt;
- typedef typename Graph::InEdgeIt InEdgeIt;
- typedef typename Graph::OutEdgeIt OutEdgeIt;
-
- Node n,m;
- n=G.addNode();
- m=G.addNode();
- Edge e;
- e=G.addEdge(n,m);
-
- // G.clear();
- }
-
- template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
- {
- typename Graph::Edge e;
- G.erase(e);
- }
-
- template<class Graph> void checkCompileGraphEraseNode(Graph &G)
- {
- typename Graph::Node n;
- G.erase(n);
- }
-
- template<class Graph> void checkCompileErasableGraph(Graph &G)
- {
- checkCompileGraph(G);
- checkCompileGraphEraseNode(G);
- checkCompileGraphEraseEdge(G);
- }
-
- template<class Graph> void checkCompileGraphFindEdge(Graph &G)
- {
- typedef typename Graph::NodeIt Node;
- typedef typename Graph::NodeIt NodeIt;
-
- G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
- G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
- }
-
template<class Graph> void checkGraphNodeList(Graph &G, int nn)
{
typename Graph::NodeIt n(G);
@@ -298,6 +53,7 @@
typename Graph::OutEdgeIt e(G,n);
for(int i=0;i<nn;i++) {
check(e!=INVALID,"Wrong OutEdge list linking.");
+ check(n==G.tail(e), "Wrong OutEdge list linking.");
++e;
}
check(e==INVALID,"Wrong OutEdge list linking.");
@@ -310,6 +66,7 @@
typename Graph::InEdgeIt e(G,n);
for(int i=0;i<nn;i++) {
check(e!=INVALID,"Wrong InEdge list linking.");
+ check(n==G.head(e), "Wrong InEdge list linking.");
++e;
}
check(e==INVALID,"Wrong InEdge list linking.");
Modified: hugo/branches/graph_factory/src/test/graph_wrapper_test.cc
==============================================================================
--- hugo/branches/graph_factory/src/test/graph_wrapper_test.cc (original)
+++ hugo/branches/graph_factory/src/test/graph_wrapper_test.cc Tue Oct 5 12:08:19 2004
@@ -38,24 +38,24 @@
//Compile GraphWrapper
typedef GraphWrapper<Graph> GW;
-template void checkCompileStaticGraph<GW>(GW &);
+template void lemon::skeleton::checkCompileStaticGraph<GW>(GW &);
//Compile RevGraphWrapper
typedef RevGraphWrapper<Graph> RevGW;
-template void checkCompileStaticGraph<RevGW>(RevGW &);
+template void lemon::skeleton::checkCompileStaticGraph<RevGW>(RevGW &);
//Compile SubGraphWrapper
typedef SubGraphWrapper<Graph, Graph::NodeMap<bool>,
Graph::EdgeMap<bool> > SubGW;
-template void checkCompileStaticGraph<SubGW>(SubGW &);
+template void lemon::skeleton::checkCompileStaticGraph<SubGW>(SubGW &);
//Compile NodeSubGraphWrapper
typedef NodeSubGraphWrapper<Graph, Graph::NodeMap<bool> > NodeSubGW;
-template void checkCompileStaticGraph<NodeSubGW>(NodeSubGW &);
+template void lemon::skeleton::checkCompileStaticGraph<NodeSubGW>(NodeSubGW &);
//Compile EdgeSubGraphWrapper
typedef EdgeSubGraphWrapper<Graph, Graph::EdgeMap<bool> > EdgeSubGW;
-template void checkCompileStaticGraph<EdgeSubGW>(EdgeSubGW &);
+template void lemon::skeleton::checkCompileStaticGraph<EdgeSubGW>(EdgeSubGW &);
//Compile UndirGraphWrapper
/// \bug UndirGraphWrapper cannot pass the StaticGraph test
@@ -69,24 +69,25 @@
//Compile SubBidirGraphWrapper
typedef SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>,
Graph::EdgeMap<bool> > SubBDGW;
-template void checkCompileStaticGraph<SubBDGW>(SubBDGW &);
+template void lemon::skeleton::checkCompileStaticGraph<SubBDGW>(SubBDGW &);
//Compile BidirGraphWrapper
typedef BidirGraphWrapper<Graph> BidirGW;
-template void checkCompileStaticGraph<BidirGW>(BidirGW &);
+template void lemon::skeleton::checkCompileStaticGraph<BidirGW>(BidirGW &);
//Compile BidirGraph
typedef BidirGraph<Graph> BidirG;
-template void checkCompileStaticGraph<BidirG>(BidirG &);
+template void lemon::skeleton::checkCompileStaticGraph<BidirG>(BidirG &);
//Compile ResGraphWrapper
typedef ResGraphWrapper<Graph, int, Graph::EdgeMap<int>,
Graph::EdgeMap<int> > ResGW;
-template void checkCompileStaticGraph<ResGW>(ResGW &);
+template void lemon::skeleton::checkCompileStaticGraph<ResGW>(ResGW &);
//Compile ErasingFirstGraphWrapper
typedef ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > ErasingFirstGW;
-template void checkCompileStaticGraph<ErasingFirstGW>(ErasingFirstGW &);
+template
+void lemon::skeleton::checkCompileStaticGraph<ErasingFirstGW>(ErasingFirstGW &);
int main()
Modified: hugo/branches/graph_factory/src/test/test_tools.h
==============================================================================
--- hugo/branches/graph_factory/src/test/test_tools.h (original)
+++ hugo/branches/graph_factory/src/test/test_tools.h Tue Oct 5 12:08:19 2004
@@ -67,7 +67,7 @@
///Adds a Petersen graph to \c G.
///Adds a Petersen graph to \c G.
-///\return The nodes end edges og the generated graph.
+///\return The nodes and edges of the generated graph.
template<typename Graph>
PetStruct<Graph> addPetersen(Graph &G,int num=5)
@@ -87,6 +87,45 @@
return n;
}
+///Structure returned by \ref addSymPetersen().
+///Structure returned by \ref addSymPetersen().
+///
+template<class Graph> struct SymPetStruct
+{
+ ///Vector containing the outer nodes.
+ std::vector<typename Graph::Node> outer;
+ ///Vector containing the inner nodes.
+ std::vector<typename Graph::Node> inner;
+ ///Vector containing the edges of the inner circle.
+ std::vector<typename Graph::SymEdge> incir;
+ ///Vector containing the edges of the outer circle.
+ std::vector<typename Graph::SymEdge> outcir;
+ ///Vector containing the chord edges.
+ std::vector<typename Graph::SymEdge> chords;
+};
+
+///Adds a Petersen graph to the symmetric \c G.
+
+///Adds a Petersen graph to the symmetric \c G.
+///\return The nodes and edges of the generated graph.
+
+template<typename Graph>
+SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
+{
+ SymPetStruct<Graph> n;
+
+ for(int i=0;i<num;i++) {
+ n.outer.push_back(G.addNode());
+ n.inner.push_back(G.addNode());
+ }
+
+ for(int i=0;i<num;i++) {
+ n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
+ n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
+ n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
+ }
+ return n;
+}
#endif
Modified: hugo/branches/graph_factory/src/work/klao/jegyzetek
==============================================================================
--- hugo/branches/graph_factory/src/work/klao/jegyzetek (original)
+++ hugo/branches/graph_factory/src/work/klao/jegyzetek Tue Oct 5 12:08:19 2004
@@ -8,3 +8,8 @@
Boost: variant. Olyasmi, mint ami nekunk kell.
http://www.boost.org/doc/html/variant.html
+
+
+Boost: egy "barmit" tartalmazni tudo tipus.
+(Kis futasideju overhead, futasideju tipus ellenorzes (?))
+http://www.boost.org/doc/html/class.boost.any.html
More information about the Lemon-commits
mailing list