0
2
0
| ... | ... |
@@ -175,24 +175,25 @@ |
| 175 | 175 |
int _id; |
| 176 | 176 |
Node(int id) : _id(id) {}
|
| 177 | 177 |
public: |
| 178 | 178 |
Node() {}
|
| 179 | 179 |
Node (Invalid) : _id(-1) {}
|
| 180 | 180 |
bool operator==(const Node node) const {return _id == node._id;}
|
| 181 | 181 |
bool operator!=(const Node node) const {return _id != node._id;}
|
| 182 | 182 |
bool operator<(const Node node) const {return _id < node._id;}
|
| 183 | 183 |
}; |
| 184 | 184 |
|
| 185 | 185 |
class Edge {
|
| 186 | 186 |
friend class GridGraphBase; |
| 187 |
friend class Arc; |
|
| 187 | 188 |
|
| 188 | 189 |
protected: |
| 189 | 190 |
int _id; |
| 190 | 191 |
|
| 191 | 192 |
Edge(int id) : _id(id) {}
|
| 192 | 193 |
|
| 193 | 194 |
public: |
| 194 | 195 |
Edge() {}
|
| 195 | 196 |
Edge (Invalid) : _id(-1) {}
|
| 196 | 197 |
bool operator==(const Edge edge) const {return _id == edge._id;}
|
| 197 | 198 |
bool operator!=(const Edge edge) const {return _id != edge._id;}
|
| 198 | 199 |
bool operator<(const Edge edge) const {return _id < edge._id;}
|
| ... | ... |
@@ -463,49 +464,49 @@ |
| 463 | 464 |
|
| 464 | 465 |
typedef GraphExtender<GridGraphBase> ExtendedGridGraphBase; |
| 465 | 466 |
|
| 466 | 467 |
/// \ingroup graphs |
| 467 | 468 |
/// |
| 468 | 469 |
/// \brief Grid graph class |
| 469 | 470 |
/// |
| 470 | 471 |
/// This class implements a special graph type. The nodes of the |
| 471 | 472 |
/// graph can be indexed by two integer \c (i,j) value where \c i is |
| 472 | 473 |
/// in the \c [0..width()-1] range and j is in the \c |
| 473 | 474 |
/// [0..height()-1] range. Two nodes are connected in the graph if |
| 474 | 475 |
/// the indexes differ exactly on one position and exactly one is |
| 475 |
/// the difference. The nodes of the graph be indexed by position |
|
| 476 |
/// with \c operator()() function. The positions of the nodes can be |
|
| 476 |
/// the difference. The nodes of the graph can be indexed by position |
|
| 477 |
/// with the \c operator()() function. The positions of the nodes can be |
|
| 477 | 478 |
/// get with \c pos(), \c col() and \c row() members. The outgoing |
| 478 | 479 |
/// arcs can be retrieved with the \c right(), \c up(), \c left() |
| 479 | 480 |
/// and \c down() functions, where the bottom-left corner is the |
| 480 | 481 |
/// origin. |
| 481 | 482 |
/// |
| 482 | 483 |
/// \image html grid_graph.png |
| 483 |
/// \image latex grid_graph.eps "Grid |
|
| 484 |
/// \image latex grid_graph.eps "Grid graph" row_num=\textrow_num |
|
| 484 | 485 |
/// |
| 485 | 486 |
/// A short example about the basic usage: |
| 486 | 487 |
///\code |
| 487 | 488 |
/// GridGraph graph(rows, cols); |
| 488 | 489 |
/// GridGraph::NodeMap<int> val(graph); |
| 489 | 490 |
/// for (int i = 0; i < graph.width(); ++i) {
|
| 490 | 491 |
/// for (int j = 0; j < graph.height(); ++j) {
|
| 491 | 492 |
/// val[graph(i, j)] = i + j; |
| 492 | 493 |
/// } |
| 493 | 494 |
/// } |
| 494 | 495 |
///\endcode |
| 495 | 496 |
/// |
| 496 |
/// |
|
| 497 |
/// This graph type is fully conform to the \ref concepts::Graph |
|
| 497 | 498 |
/// "Graph" concept, and it also has an important extra feature |
| 498 |
/// that its maps are real \ref concepts::ReferenceMap "reference |
|
| 499 |
/// map"s. |
|
| 499 |
/// that its maps are real \ref concepts::ReferenceMap |
|
| 500 |
/// "reference map"s. |
|
| 500 | 501 |
class GridGraph : public ExtendedGridGraphBase {
|
| 501 | 502 |
public: |
| 502 | 503 |
|
| 503 | 504 |
typedef ExtendedGridGraphBase Parent; |
| 504 | 505 |
|
| 505 | 506 |
/// \brief Map to get the indices of the nodes as dim2::Point<int>. |
| 506 | 507 |
/// |
| 507 | 508 |
/// Map to get the indices of the nodes as dim2::Point<int>. |
| 508 | 509 |
class IndexMap {
|
| 509 | 510 |
public: |
| 510 | 511 |
/// \brief The key type of the map |
| 511 | 512 |
typedef GridGraph::Node Key; |
| ... | ... |
@@ -183,26 +183,26 @@ |
| 183 | 183 |
check(g.valid(e2), "Wrong validity check"); |
| 184 | 184 |
|
| 185 | 185 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
| 186 | 186 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
| 187 | 187 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
| 188 | 188 |
} |
| 189 | 189 |
|
| 190 | 190 |
void checkGridGraph(int width, int height) {
|
| 191 | 191 |
typedef GridGraph Graph; |
| 192 | 192 |
GRAPH_TYPEDEFS(Graph); |
| 193 | 193 |
Graph G(width, height); |
| 194 | 194 |
|
| 195 |
check(G.width() == width, "Wrong row number"); |
|
| 196 |
check(G.height() == height, "Wrong column number"); |
|
| 195 |
check(G.width() == width, "Wrong column number"); |
|
| 196 |
check(G.height() == height, "Wrong row number"); |
|
| 197 | 197 |
|
| 198 | 198 |
for (int i = 0; i < width; ++i) {
|
| 199 | 199 |
for (int j = 0; j < height; ++j) {
|
| 200 | 200 |
check(G.col(G(i, j)) == i, "Wrong column"); |
| 201 | 201 |
check(G.row(G(i, j)) == j, "Wrong row"); |
| 202 | 202 |
check(G.pos(G(i, j)).x == i, "Wrong column"); |
| 203 | 203 |
check(G.pos(G(i, j)).y == j, "Wrong row"); |
| 204 | 204 |
} |
| 205 | 205 |
} |
| 206 | 206 |
|
| 207 | 207 |
for (int j = 0; j < height; ++j) {
|
| 208 | 208 |
for (int i = 0; i < width - 1; ++i) {
|
0 comments (0 inline)