diff -r 96244ea562a3 -r 12a3101cf3ab lemon/full_graph.h --- a/lemon/full_graph.h Mon Jul 18 15:07:28 2005 +0000 +++ b/lemon/full_graph.h Mon Jul 18 15:08:18 2005 +0000 @@ -24,6 +24,8 @@ #include #include +#include + #include #include @@ -36,8 +38,8 @@ namespace lemon { class FullGraphBase { - int NodeNum; - int EdgeNum; + int _nodeNum; + int _edgeNum; public: typedef FullGraphBase Graph; @@ -51,32 +53,32 @@ ///Creates a full graph with \c n nodes. - void construct(int n) { NodeNum = n; EdgeNum = n * n; } + void construct(int n) { _nodeNum = n; _edgeNum = n * n; } /// // FullGraphBase(const FullGraphBase &_g) - // : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { } + // : _nodeNum(_g.nodeNum()), _edgeNum(_nodeNum*_nodeNum) { } typedef True NodeNumTag; typedef True EdgeNumTag; ///Number of nodes. - int nodeNum() const { return NodeNum; } + int nodeNum() const { return _nodeNum; } ///Number of edges. - int edgeNum() const { return EdgeNum; } + int edgeNum() const { return _edgeNum; } /// Maximum node ID. /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return NodeNum-1; } + int maxId(Node = INVALID) const { return _nodeNum-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return EdgeNum-1; } + int maxId(Edge = INVALID) const { return _edgeNum-1; } - Node source(Edge e) const { return e.id % NodeNum; } - Node target(Edge e) const { return e.id / NodeNum; } + Node source(Edge e) const { return e.id % _nodeNum; } + Node target(Edge e) const { return e.id / _nodeNum; } /// Node ID. @@ -103,6 +105,8 @@ static Edge fromId(int id, Edge) { return Edge(id);} + typedef True FindEdgeTag; + /// Finds an edge between two nodes. /// Finds an edge from node \c u to node \c v. @@ -111,8 +115,7 @@ /// 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) - { + Edge findEdge(Node u,Node v, Edge prev = INVALID) const { return prev.id == -1 ? Edge(*this, u.id, v.id) : INVALID; } @@ -137,12 +140,12 @@ friend class FullGraphBase; protected: - int id; // NodeNum * target + source; + int id; // _nodeNum * target + source; Edge(int _id) : id(_id) {} Edge(const FullGraphBase& _graph, int source, int target) - : id(_graph.NodeNum * target+source) {} + : id(_graph._nodeNum * target+source) {} public: Edge() { } Edge (Invalid) { id = -1; } @@ -152,7 +155,7 @@ }; void first(Node& node) const { - node.id = NodeNum-1; + node.id = _nodeNum-1; } static void next(Node& node) { @@ -160,7 +163,7 @@ } void first(Edge& edge) const { - edge.id = EdgeNum-1; + edge.id = _edgeNum-1; } static void next(Edge& edge) { @@ -168,43 +171,45 @@ } void firstOut(Edge& edge, const Node& node) const { - edge.id = EdgeNum + node.id - NodeNum; + edge.id = _edgeNum + node.id - _nodeNum; } void nextOut(Edge& edge) const { - edge.id -= NodeNum; + edge.id -= _nodeNum; if (edge.id < 0) edge.id = -1; } void firstIn(Edge& edge, const Node& node) const { - edge.id = node.id * NodeNum; + edge.id = node.id * _nodeNum; } void nextIn(Edge& edge) const { ++edge.id; - if (edge.id % NodeNum == 0) edge.id = -1; + if (edge.id % _nodeNum == 0) edge.id = -1; } }; - typedef AlterableGraphExtender AlterableFullGraphBase; - typedef IterableGraphExtender IterableFullGraphBase; - typedef DefaultMappableGraphExtender MappableFullGraphBase; + typedef AlterableGraphExtender + AlterableFullGraphBase; + typedef IterableGraphExtender + IterableFullGraphBase; + typedef DefaultMappableGraphExtender + MappableFullGraphBase; - /// \addtogroup graphs - /// @{ - - ///A full graph class. - - ///This is a simple and fast directed full graph implementation. - ///It is completely static, so you can neither add nor delete either - ///edges or nodes. - ///Thus it conforms to - ///the \ref concept::StaticGraph "StaticGraph" concept - ///\sa concept::StaticGraph. + /// \ingroup graphs /// - ///\author Alpar Juttner + /// \brief A full graph class. + /// + /// This is a simple and fast directed full graph implementation. + /// It is completely static, so you can neither add nor delete either + /// edges or nodes. + /// Thus it conforms to + /// the \ref concept::StaticGraph "StaticGraph" concept + /// \sa concept::StaticGraph. + /// + /// \author Alpar Juttner class FullGraph : public MappableFullGraphBase { public: @@ -213,10 +218,9 @@ ///@} - // Base graph class for UndirFullGraph. class UndirFullGraphBase { - int NodeNum; - int EdgeNum; + int _nodeNum; + int _edgeNum; public: typedef UndirFullGraphBase Graph; @@ -230,29 +234,29 @@ ///Creates a full graph with \c n nodes. - void construct(int n) { NodeNum = n; EdgeNum = n * (n - 1) / 2; } + void construct(int n) { _nodeNum = n; _edgeNum = n * (n - 1) / 2; } /// // FullGraphBase(const FullGraphBase &_g) - // : NodeNum(_g.nodeNum()), EdgeNum(NodeNum*NodeNum) { } + // : _nodeNum(_g.nodeNum()), _edgeNum(_nodeNum*_nodeNum) { } typedef True NodeNumTag; typedef True EdgeNumTag; ///Number of nodes. - int nodeNum() const { return NodeNum; } + int nodeNum() const { return _nodeNum; } ///Number of edges. - int edgeNum() const { return EdgeNum; } + int edgeNum() const { return _edgeNum; } /// Maximum node ID. /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return NodeNum-1; } + int maxId(Node = INVALID) const { return _nodeNum-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return EdgeNum-1; } + int maxId(Edge = INVALID) const { return _edgeNum-1; } Node source(Edge e) const { /// \todo we may do it faster @@ -319,12 +323,12 @@ friend class UndirFullGraphBase; protected: - int id; // NodeNum * target + source; + int id; // _nodeNum * target + source; Edge(int _id) : id(_id) {} Edge(const UndirFullGraphBase& _graph, int source, int target) - : id(_graph.NodeNum * target+source) {} + : id(_graph._nodeNum * target+source) {} public: Edge() { } Edge (Invalid) { id = -1; } @@ -334,7 +338,7 @@ }; void first(Node& node) const { - node.id = NodeNum-1; + node.id = _nodeNum-1; } static void next(Node& node) { @@ -342,7 +346,7 @@ } void first(Edge& edge) const { - edge.id = EdgeNum-1; + edge.id = _edgeNum-1; } static void next(Edge& edge) { @@ -369,19 +373,39 @@ int source = ((int)sqrt((double)(1 + 8 * e.id)) + 1) / 2;; int target = e.id - (source) * (source - 1) / 2; ++target; ++source; - e.id = source < NodeNum ? source * (source - 1) / 2 + target : -1; + e.id = source < _nodeNum ? source * (source - 1) / 2 + target : -1; } }; - /// \addtogroup graphs - /// @{ + typedef UndirGraphExtender + UndirUndirFullGraphBase; + typedef AlterableUndirGraphExtender + AlterableUndirFullGraphBase; + typedef IterableUndirGraphExtender + IterableUndirFullGraphBase; + typedef MappableUndirGraphExtender + MappableUndirFullGraphBase; - - /// \todo UndirFullGraph from the UndirFullGraphBase - - - /// @} + /// \ingroup graphs + /// + /// \brief An undirected full graph class. + /// + /// This is a simple and fast directed full graph implementation. + /// It is completely static, so you can neither add nor delete either + /// edges or nodes. + /// + /// The main difference beetween the \e FullGraph and \e UndirFullGraph class + /// is that this class conforms to the undirected graph concept and + /// it does not contain the hook edges. + /// + /// \sa FullGraph + /// + /// \author Balazs Dezso + class UndirFullGraph : public MappableUndirFullGraphBase { + public: + UndirFullGraph(int n) { construct(n); } + }; } //namespace lemon