# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1225561910 -3600
# Node ID a598f74ea87ec18aec51a5352114625a961bcaa7
# Parent 37557a46e29874bd50b7c0e54c5595dc6bde36a2
Improvements related to full graphs (#57)
diff --git a/lemon/full_graph.h b/lemon/full_graph.h
|
a
|
b
|
|
| 19 | 19 | #ifndef LEMON_FULL_GRAPH_H |
| 20 | 20 | #define LEMON_FULL_GRAPH_H |
| 21 | 21 | |
| 22 | | #include <lemon/math.h> |
| 23 | | |
| 24 | 22 | #include <lemon/core.h> |
| 25 | 23 | #include <lemon/bits/graph_extender.h> |
| 26 | 24 | |
| 27 | 25 | ///\ingroup graphs |
| 28 | 26 | ///\file |
| 29 | | ///\brief FullDigraph and FullGraph classes. |
| | 27 | ///\brief FullGraph and FullDigraph classes. |
| | 28 | |
| 30 | 29 | namespace lemon { |
| 31 | 30 | |
| 32 | 31 | class FullDigraphBase { |
| … |
… |
|
| 67 | 66 | Node source(Arc arc) const { return arc._id / _node_num; } |
| 68 | 67 | Node target(Arc arc) const { return arc._id % _node_num; } |
| 69 | 68 | |
| 70 | | |
| 71 | 69 | static int id(Node node) { return node._id; } |
| 72 | 70 | static int id(Arc arc) { return arc._id; } |
| 73 | 71 | |
| 74 | 72 | static Node nodeFromId(int id) { return Node(id);} |
| 75 | | |
| 76 | 73 | static Arc arcFromId(int id) { return Arc(id);} |
| 77 | 74 | |
| 78 | 75 | typedef True FindArcTag; |
| … |
… |
|
| 80 | 77 | Arc findArc(Node s, Node t, Arc prev = INVALID) const { |
| 81 | 78 | return prev != INVALID ? arc(s, t) : INVALID; |
| 82 | 79 | } |
| 83 | | |
| 84 | 80 | |
| 85 | 81 | class Node { |
| 86 | 82 | friend class FullDigraphBase; |
| … |
… |
|
| 157 | 153 | /// This is a simple and fast directed full graph implementation. |
| 158 | 154 | /// From each node go arcs to each node (including the source node), |
| 159 | 155 | /// therefore the number of the arcs in the digraph is the square of |
| 160 | | /// the node number. The digraph is completely static, so you can |
| 161 | | /// neither add nor delete either arcs or nodes, and it needs just |
| | 156 | /// the node number. This digraph type is completely static, so you |
| | 157 | /// can neither add nor delete either arcs or nodes, and it needs just |
| 162 | 158 | /// constant space in memory. |
| 163 | 159 | /// |
| 164 | | /// Thus it conforms to the \ref concepts::Digraph "Digraph" concept |
| | 160 | /// This class conforms to the \ref concepts::Digraph "Digraph" concept |
| 165 | 161 | /// and it also has an important extra feature that its maps are |
| 166 | 162 | /// real \ref concepts::ReferenceMap "reference map"s. |
| 167 | | /// \sa concepts::Digraph. |
| 168 | 163 | /// |
| 169 | 164 | /// \sa FullGraph |
| 170 | 165 | class FullDigraph : public ExtendedFullDigraphBase { |
| … |
… |
|
| 177 | 172 | |
| 178 | 173 | /// \brief Constructor |
| 179 | 174 | /// |
| | 175 | /// Constructor. |
| 180 | 176 | /// \param n The number of the nodes. |
| 181 | 177 | FullDigraph(int n) { construct(n); } |
| 182 | 178 | |
| 183 | | /// \brief Resize the digraph |
| | 179 | /// \brief Resizes the digraph |
| 184 | 180 | /// |
| 185 | | /// Resize the digraph. The function will fully destroy and |
| 186 | | /// rebuild the digraph. This cause that the maps of the digraph |
| 187 | | /// will reallocated automatically and the previous values will be |
| 188 | | /// lost. |
| | 181 | /// Resizes the digraph. The function will fully destroy and |
| | 182 | /// rebuild the digraph. This cause that the maps of the digraph will |
| | 183 | /// reallocated automatically and the previous values will be lost. |
| 189 | 184 | void resize(int n) { |
| 190 | 185 | Parent::notifier(Arc()).clear(); |
| 191 | 186 | Parent::notifier(Node()).clear(); |
| … |
… |
|
| 196 | 191 | |
| 197 | 192 | /// \brief Returns the node with the given index. |
| 198 | 193 | /// |
| 199 | | /// Returns the node with the given index. Because it is a |
| 200 | | /// static size digraph the node's of the digraph can be indexed |
| 201 | | /// in the range <tt>[0..nodeNum()-1]</tt> and the index of |
| 202 | | /// the node can accessed by the \e index() member. |
| | 194 | /// Returns the node with the given index. Since it is a static |
| | 195 | /// digraph its nodes can be indexed with integers from the range |
| | 196 | /// <tt>[0..nodeNum()-1]</tt>. |
| | 197 | /// \sa index() |
| 203 | 198 | Node operator()(int ix) const { return Parent::operator()(ix); } |
| 204 | 199 | |
| 205 | | /// \brief Returns the index of the node. |
| | 200 | /// \brief Returns the index of the given node. |
| 206 | 201 | /// |
| 207 | | /// Returns the index of the node. Because it is a |
| 208 | | /// static size digraph the node's of the digraph can be indexed |
| 209 | | /// in the range <tt>[0..nodeNum()-1]</tt> and the index of |
| 210 | | /// the node can accessed by the \e index() member. |
| | 202 | /// Returns the index of the given node. Since it is a static |
| | 203 | /// digraph its nodes can be indexed with integers from the range |
| | 204 | /// <tt>[0..nodeNum()-1]</tt>. |
| | 205 | /// \sa operator() |
| 211 | 206 | int index(const Node& node) const { return Parent::index(node); } |
| 212 | 207 | |
| 213 | | /// \brief Returns the arc connects the given nodes. |
| | 208 | /// \brief Returns the arc connecting the given nodes. |
| 214 | 209 | /// |
| 215 | | /// Returns the arc connects the given nodes. |
| | 210 | /// Returns the arc connecting the given nodes. |
| 216 | 211 | Arc arc(const Node& u, const Node& v) const { |
| 217 | 212 | return Parent::arc(u, v); |
| 218 | 213 | } |
| … |
… |
|
| 279 | 274 | } |
| 280 | 275 | |
| 281 | 276 | public: |
| 282 | | |
| 283 | 277 | |
| 284 | 278 | Node operator()(int ix) const { return Node(ix); } |
| 285 | 279 | int index(const Node& node) const { return node._id; } |
| … |
… |
|
| 367 | 361 | |
| 368 | 362 | class Edge { |
| 369 | 363 | friend class FullGraphBase; |
| | 364 | friend class Arc; |
| 370 | 365 | |
| 371 | 366 | protected: |
| 372 | 367 | int _id; |
| … |
… |
|
| 518 | 513 | /// |
| 519 | 514 | /// This is a simple and fast undirected full graph |
| 520 | 515 | /// implementation. From each node go edge to each other node, |
| 521 | | /// therefore the number of edges in the graph is |
| 522 | | /// <tt>n(n-1)/2</tt>. It is completely static, so you can neither |
| | 516 | /// therefore the number of edges in the graph is <tt>n(n-1)/2</tt>, |
| | 517 | /// \f$n(n-1)/2\f$, \f$\frec{n(n-1)}{2}\f$. |
| | 518 | /// This graph type is completely static, so you can neither |
| 523 | 519 | /// add nor delete either edges or nodes, and it needs just constant |
| 524 | 520 | /// space in memory. |
| 525 | 521 | /// |
| 526 | | /// The \e FullDigraph and \e FullGraph classes are very similar, |
| 527 | | /// but there are two differences. While the \e FullDigraph class is |
| 528 | | /// conform just to the \ref concepts::Digraph "Digraph" concept, |
| 529 | | /// this class is conform to the \ref concepts::Graph "Graph" |
| 530 | | /// concept. In addition, the \e FullGraph class does not contain a |
| | 522 | /// The \e FullGraph and \e FullDigraph classes are very similar, |
| | 523 | /// but there are two differences. While the \e FullDigraph class |
| | 524 | /// conforms only to the \ref concepts::Digraph "Digraph" concept, |
| | 525 | /// this class conforms to the \ref concepts::Graph "Graph" |
| | 526 | /// concept. In addition, the \e FullGraph class does not contain the |
| 531 | 527 | /// loop arc from each node as the \e FullDigraph does. |
| 532 | 528 | /// |
| 533 | 529 | /// It also has an important extra feature that its maps are real |
| … |
… |
|
| 544 | 540 | |
| 545 | 541 | /// \brief Constructor |
| 546 | 542 | /// |
| | 543 | /// Constructor. |
| 547 | 544 | /// \param n The number of the nodes. |
| 548 | 545 | FullGraph(int n) { construct(n); } |
| 549 | 546 | |
| 550 | | /// \brief Resize the graph |
| | 547 | /// \brief Resizes the graph |
| 551 | 548 | /// |
| 552 | | /// Resize the graph. The function will fully destroy and rebuild |
| 553 | | /// the graph. This cause that the maps of the graph will |
| 554 | | /// reallocated automatically and the previous values will be |
| 555 | | /// lost. |
| | 549 | /// Resizes the graph. The function will fully destroy and |
| | 550 | /// rebuild the graph. This cause that the maps of the graph will |
| | 551 | /// reallocated automatically and the previous values will be lost. |
| 556 | 552 | void resize(int n) { |
| 557 | 553 | Parent::notifier(Arc()).clear(); |
| 558 | 554 | Parent::notifier(Edge()).clear(); |
| … |
… |
|
| 565 | 561 | |
| 566 | 562 | /// \brief Returns the node with the given index. |
| 567 | 563 | /// |
| 568 | | /// Returns the node with the given index. Because it is a static |
| 569 | | /// size graph the node's of the graph can be indexed in the range |
| 570 | | /// <tt>[0..nodeNum()-1]</tt> and the index of the node can |
| 571 | | /// accessed by the \e index() member. |
| | 564 | /// Returns the node with the given index. Since it is a static |
| | 565 | /// graph its nodes can be indexed with integers from the range |
| | 566 | /// <tt>[0..nodeNum()-1]</tt>. |
| | 567 | /// \sa index() |
| 572 | 568 | Node operator()(int ix) const { return Parent::operator()(ix); } |
| 573 | 569 | |
| 574 | | /// \brief Returns the index of the node. |
| | 570 | /// \brief Returns the index of the given node. |
| 575 | 571 | /// |
| 576 | | /// Returns the index of the node. Because it is a static size |
| 577 | | /// graph the node's of the graph can be indexed in the range |
| 578 | | /// <tt>[0..nodeNum()-1]</tt> and the index of the node can |
| 579 | | /// accessed by the \e index() member. |
| | 572 | /// Returns the index of the given node. Since it is a static |
| | 573 | /// graph its nodes can be indexed with integers from the range |
| | 574 | /// <tt>[0..nodeNum()-1]</tt>. |
| | 575 | /// \sa operator() |
| 580 | 576 | int index(const Node& node) const { return Parent::index(node); } |
| 581 | 577 | |
| 582 | | /// \brief Number of nodes. |
| 583 | | int nodeNum() const { return Parent::nodeNum(); } |
| 584 | | /// \brief Number of arcs. |
| 585 | | int arcNum() const { return Parent::arcNum(); } |
| 586 | | /// \brief Number of edges. |
| 587 | | int edgeNum() const { return Parent::edgeNum(); } |
| 588 | | |
| 589 | | /// \brief Returns the arc connects the given nodes. |
| | 578 | /// \brief Returns the arc connecting the given nodes. |
| 590 | 579 | /// |
| 591 | | /// Returns the arc connects the given nodes. |
| | 580 | /// Returns the arc connecting the given nodes. |
| 592 | 581 | Arc arc(const Node& s, const Node& t) const { |
| 593 | 582 | return Parent::arc(s, t); |
| 594 | 583 | } |
| … |
… |
|
| 599 | 588 | Edge edge(const Node& u, const Node& v) const { |
| 600 | 589 | return Parent::edge(u, v); |
| 601 | 590 | } |
| | 591 | |
| | 592 | /// \brief Number of nodes. |
| | 593 | int nodeNum() const { return Parent::nodeNum(); } |
| | 594 | /// \brief Number of arcs. |
| | 595 | int arcNum() const { return Parent::arcNum(); } |
| | 596 | /// \brief Number of edges. |
| | 597 | int edgeNum() const { return Parent::edgeNum(); } |
| | 598 | |
| 602 | 599 | }; |
| 603 | 600 | |
| 604 | 601 | |
diff --git a/test/digraph_test.cc b/test/digraph_test.cc
|
a
|
b
|
|
| 142 | 142 | checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
| 143 | 143 | checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
| 144 | 144 | } |
| 145 | | // { // Checking FullDigraph |
| 146 | | // checkConcept<Digraph, FullDigraph>(); |
| 147 | | // } |
| | 145 | { // Checking FullDigraph |
| | 146 | checkConcept<Digraph, FullDigraph>(); |
| | 147 | } |
| 148 | 148 | // { // Checking HyperCubeDigraph |
| 149 | 149 | // checkConcept<Digraph, HyperCubeDigraph>(); |
| 150 | 150 | // } |