0
5
0
| ... | ... |
@@ -112,99 +112,98 @@ |
| 112 | 112 |
node._id = _node_num - 1; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
static void next(Node& node) {
|
| 116 | 116 |
--node._id; |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
void first(Arc& arc) const {
|
| 120 | 120 |
arc._id = _arc_num - 1; |
| 121 | 121 |
} |
| 122 | 122 |
|
| 123 | 123 |
static void next(Arc& arc) {
|
| 124 | 124 |
--arc._id; |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 | 127 |
void firstOut(Arc& arc, const Node& node) const {
|
| 128 | 128 |
arc._id = (node._id + 1) * _node_num - 1; |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
void nextOut(Arc& arc) const {
|
| 132 | 132 |
if (arc._id % _node_num == 0) arc._id = 0; |
| 133 | 133 |
--arc._id; |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 | 136 |
void firstIn(Arc& arc, const Node& node) const {
|
| 137 | 137 |
arc._id = _arc_num + node._id - _node_num; |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
void nextIn(Arc& arc) const {
|
| 141 | 141 |
arc._id -= _node_num; |
| 142 | 142 |
if (arc._id < 0) arc._id = -1; |
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
}; |
| 146 | 146 |
|
| 147 | 147 |
typedef DigraphExtender<FullDigraphBase> ExtendedFullDigraphBase; |
| 148 | 148 |
|
| 149 | 149 |
/// \ingroup graphs |
| 150 | 150 |
/// |
| 151 | 151 |
/// \brief A full digraph class. |
| 152 | 152 |
/// |
| 153 | 153 |
/// This is a simple and fast directed full graph implementation. |
| 154 | 154 |
/// From each node go arcs to each node (including the source node), |
| 155 | 155 |
/// therefore the number of the arcs in the digraph is the square of |
| 156 | 156 |
/// the node number. This digraph type is completely static, so you |
| 157 | 157 |
/// can neither add nor delete either arcs or nodes, and it needs |
| 158 | 158 |
/// constant space in memory. |
| 159 | 159 |
/// |
| 160 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept |
|
| 161 |
/// and it also has an important extra feature that its maps are |
|
| 162 |
/// |
|
| 160 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 161 |
/// "Digraph concept". |
|
| 163 | 162 |
/// |
| 164 | 163 |
/// The \c FullDigraph and \c FullGraph classes are very similar, |
| 165 | 164 |
/// but there are two differences. While this class conforms only |
| 166 | 165 |
/// to the \ref concepts::Digraph "Digraph" concept, the \c FullGraph |
| 167 | 166 |
/// class conforms to the \ref concepts::Graph "Graph" concept, |
| 168 | 167 |
/// moreover \c FullGraph does not contain a loop arc for each |
| 169 | 168 |
/// node as \c FullDigraph does. |
| 170 | 169 |
/// |
| 171 | 170 |
/// \sa FullGraph |
| 172 | 171 |
class FullDigraph : public ExtendedFullDigraphBase {
|
| 173 | 172 |
public: |
| 174 | 173 |
|
| 175 | 174 |
typedef ExtendedFullDigraphBase Parent; |
| 176 | 175 |
|
| 177 | 176 |
/// \brief Constructor |
| 178 | 177 |
FullDigraph() { construct(0); }
|
| 179 | 178 |
|
| 180 | 179 |
/// \brief Constructor |
| 181 | 180 |
/// |
| 182 | 181 |
/// Constructor. |
| 183 | 182 |
/// \param n The number of the nodes. |
| 184 | 183 |
FullDigraph(int n) { construct(n); }
|
| 185 | 184 |
|
| 186 | 185 |
/// \brief Resizes the digraph |
| 187 | 186 |
/// |
| 188 | 187 |
/// Resizes the digraph. The function will fully destroy and |
| 189 | 188 |
/// rebuild the digraph. This cause that the maps of the digraph will |
| 190 | 189 |
/// reallocated automatically and the previous values will be lost. |
| 191 | 190 |
void resize(int n) {
|
| 192 | 191 |
Parent::notifier(Arc()).clear(); |
| 193 | 192 |
Parent::notifier(Node()).clear(); |
| 194 | 193 |
construct(n); |
| 195 | 194 |
Parent::notifier(Node()).build(); |
| 196 | 195 |
Parent::notifier(Arc()).build(); |
| 197 | 196 |
} |
| 198 | 197 |
|
| 199 | 198 |
/// \brief Returns the node with the given index. |
| 200 | 199 |
/// |
| 201 | 200 |
/// Returns the node with the given index. Since it is a static |
| 202 | 201 |
/// digraph its nodes can be indexed with integers from the range |
| 203 | 202 |
/// <tt>[0..nodeNum()-1]</tt>. |
| 204 | 203 |
/// \sa index() |
| 205 | 204 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 206 | 205 |
|
| 207 | 206 |
/// \brief Returns the index of the given node. |
| 208 | 207 |
/// |
| 209 | 208 |
/// Returns the index of the given node. Since it is a static |
| 210 | 209 |
/// digraph its nodes can be indexed with integers from the range |
| ... | ... |
@@ -482,99 +481,97 @@ |
| 482 | 481 |
} |
| 483 | 482 |
|
| 484 | 483 |
void firstInc(Edge& edge, bool& dir, const Node& node) const {
|
| 485 | 484 |
int u = node._id, v = _node_num - 1; |
| 486 | 485 |
if (u < v) {
|
| 487 | 486 |
edge._id = _eid(u, v); |
| 488 | 487 |
dir = true; |
| 489 | 488 |
} else {
|
| 490 | 489 |
--v; |
| 491 | 490 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 492 | 491 |
dir = false; |
| 493 | 492 |
} |
| 494 | 493 |
} |
| 495 | 494 |
|
| 496 | 495 |
void nextInc(Edge& edge, bool& dir) const {
|
| 497 | 496 |
int u, v; |
| 498 | 497 |
if (dir) {
|
| 499 | 498 |
_uvid(edge._id, u, v); |
| 500 | 499 |
--v; |
| 501 | 500 |
if (u < v) {
|
| 502 | 501 |
edge._id = _eid(u, v); |
| 503 | 502 |
} else {
|
| 504 | 503 |
--v; |
| 505 | 504 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 506 | 505 |
dir = false; |
| 507 | 506 |
} |
| 508 | 507 |
} else {
|
| 509 | 508 |
_uvid(edge._id, v, u); |
| 510 | 509 |
--v; |
| 511 | 510 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 512 | 511 |
} |
| 513 | 512 |
} |
| 514 | 513 |
|
| 515 | 514 |
}; |
| 516 | 515 |
|
| 517 | 516 |
typedef GraphExtender<FullGraphBase> ExtendedFullGraphBase; |
| 518 | 517 |
|
| 519 | 518 |
/// \ingroup graphs |
| 520 | 519 |
/// |
| 521 | 520 |
/// \brief An undirected full graph class. |
| 522 | 521 |
/// |
| 523 | 522 |
/// This is a simple and fast undirected full graph |
| 524 | 523 |
/// implementation. From each node go edge to each other node, |
| 525 | 524 |
/// therefore the number of edges in the graph is \f$n(n-1)/2\f$. |
| 526 | 525 |
/// This graph type is completely static, so you can neither |
| 527 | 526 |
/// add nor delete either edges or nodes, and it needs constant |
| 528 | 527 |
/// space in memory. |
| 529 | 528 |
/// |
| 530 |
/// This class conforms to the \ref concepts::Graph "Graph" concept |
|
| 531 |
/// and it also has an important extra feature that its maps are |
|
| 532 |
/// |
|
| 529 |
/// This class fully conforms to the \ref concepts::Graph "Graph concept". |
|
| 533 | 530 |
/// |
| 534 | 531 |
/// The \c FullGraph and \c FullDigraph classes are very similar, |
| 535 | 532 |
/// but there are two differences. While the \c FullDigraph class |
| 536 | 533 |
/// conforms only to the \ref concepts::Digraph "Digraph" concept, |
| 537 | 534 |
/// this class conforms to the \ref concepts::Graph "Graph" concept, |
| 538 | 535 |
/// moreover \c FullGraph does not contain a loop arc for each |
| 539 | 536 |
/// node as \c FullDigraph does. |
| 540 | 537 |
/// |
| 541 | 538 |
/// \sa FullDigraph |
| 542 | 539 |
class FullGraph : public ExtendedFullGraphBase {
|
| 543 | 540 |
public: |
| 544 | 541 |
|
| 545 | 542 |
typedef ExtendedFullGraphBase Parent; |
| 546 | 543 |
|
| 547 | 544 |
/// \brief Constructor |
| 548 | 545 |
FullGraph() { construct(0); }
|
| 549 | 546 |
|
| 550 | 547 |
/// \brief Constructor |
| 551 | 548 |
/// |
| 552 | 549 |
/// Constructor. |
| 553 | 550 |
/// \param n The number of the nodes. |
| 554 | 551 |
FullGraph(int n) { construct(n); }
|
| 555 | 552 |
|
| 556 | 553 |
/// \brief Resizes the graph |
| 557 | 554 |
/// |
| 558 | 555 |
/// Resizes the graph. The function will fully destroy and |
| 559 | 556 |
/// rebuild the graph. This cause that the maps of the graph will |
| 560 | 557 |
/// reallocated automatically and the previous values will be lost. |
| 561 | 558 |
void resize(int n) {
|
| 562 | 559 |
Parent::notifier(Arc()).clear(); |
| 563 | 560 |
Parent::notifier(Edge()).clear(); |
| 564 | 561 |
Parent::notifier(Node()).clear(); |
| 565 | 562 |
construct(n); |
| 566 | 563 |
Parent::notifier(Node()).build(); |
| 567 | 564 |
Parent::notifier(Edge()).build(); |
| 568 | 565 |
Parent::notifier(Arc()).build(); |
| 569 | 566 |
} |
| 570 | 567 |
|
| 571 | 568 |
/// \brief Returns the node with the given index. |
| 572 | 569 |
/// |
| 573 | 570 |
/// Returns the node with the given index. Since it is a static |
| 574 | 571 |
/// graph its nodes can be indexed with integers from the range |
| 575 | 572 |
/// <tt>[0..nodeNum()-1]</tt>. |
| 576 | 573 |
/// \sa index() |
| 577 | 574 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 578 | 575 |
|
| 579 | 576 |
/// \brief Returns the index of the given node. |
| 580 | 577 |
/// |
| ... | ... |
@@ -452,99 +452,97 @@ |
| 452 | 452 |
Arc down(Node n) const {
|
| 453 | 453 |
if (n._id >= _width) {
|
| 454 | 454 |
return Arc((n._id - _width) << 1); |
| 455 | 455 |
} else {
|
| 456 | 456 |
return INVALID; |
| 457 | 457 |
} |
| 458 | 458 |
} |
| 459 | 459 |
|
| 460 | 460 |
private: |
| 461 | 461 |
int _width, _height; |
| 462 | 462 |
int _node_num, _edge_num; |
| 463 | 463 |
int _edge_limit; |
| 464 | 464 |
}; |
| 465 | 465 |
|
| 466 | 466 |
|
| 467 | 467 |
typedef GraphExtender<GridGraphBase> ExtendedGridGraphBase; |
| 468 | 468 |
|
| 469 | 469 |
/// \ingroup graphs |
| 470 | 470 |
/// |
| 471 | 471 |
/// \brief Grid graph class |
| 472 | 472 |
/// |
| 473 | 473 |
/// This class implements a special graph type. The nodes of the |
| 474 | 474 |
/// graph can be indexed by two integer \c (i,j) value where \c i is |
| 475 | 475 |
/// in the \c [0..width()-1] range and j is in the \c |
| 476 | 476 |
/// [0..height()-1] range. Two nodes are connected in the graph if |
| 477 | 477 |
/// the indexes differ exactly on one position and exactly one is |
| 478 | 478 |
/// the difference. The nodes of the graph can be indexed by position |
| 479 | 479 |
/// with the \c operator()() function. The positions of the nodes can be |
| 480 | 480 |
/// get with \c pos(), \c col() and \c row() members. The outgoing |
| 481 | 481 |
/// arcs can be retrieved with the \c right(), \c up(), \c left() |
| 482 | 482 |
/// and \c down() functions, where the bottom-left corner is the |
| 483 | 483 |
/// origin. |
| 484 | 484 |
/// |
| 485 | 485 |
/// \image html grid_graph.png |
| 486 | 486 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
| 487 | 487 |
/// |
| 488 | 488 |
/// A short example about the basic usage: |
| 489 | 489 |
///\code |
| 490 | 490 |
/// GridGraph graph(rows, cols); |
| 491 | 491 |
/// GridGraph::NodeMap<int> val(graph); |
| 492 | 492 |
/// for (int i = 0; i < graph.width(); ++i) {
|
| 493 | 493 |
/// for (int j = 0; j < graph.height(); ++j) {
|
| 494 | 494 |
/// val[graph(i, j)] = i + j; |
| 495 | 495 |
/// } |
| 496 | 496 |
/// } |
| 497 | 497 |
///\endcode |
| 498 | 498 |
/// |
| 499 | 499 |
/// This graph type fully conforms to the \ref concepts::Graph |
| 500 |
/// "Graph" concept, and it also has an important extra feature |
|
| 501 |
/// that its maps are real \ref concepts::ReferenceMap |
|
| 502 |
/// " |
|
| 500 |
/// "Graph concept". |
|
| 503 | 501 |
class GridGraph : public ExtendedGridGraphBase {
|
| 504 | 502 |
public: |
| 505 | 503 |
|
| 506 | 504 |
typedef ExtendedGridGraphBase Parent; |
| 507 | 505 |
|
| 508 | 506 |
/// \brief Map to get the indices of the nodes as dim2::Point<int>. |
| 509 | 507 |
/// |
| 510 | 508 |
/// Map to get the indices of the nodes as dim2::Point<int>. |
| 511 | 509 |
class IndexMap {
|
| 512 | 510 |
public: |
| 513 | 511 |
/// \brief The key type of the map |
| 514 | 512 |
typedef GridGraph::Node Key; |
| 515 | 513 |
/// \brief The value type of the map |
| 516 | 514 |
typedef dim2::Point<int> Value; |
| 517 | 515 |
|
| 518 | 516 |
/// \brief Constructor |
| 519 | 517 |
/// |
| 520 | 518 |
/// Constructor |
| 521 | 519 |
IndexMap(const GridGraph& graph) : _graph(graph) {}
|
| 522 | 520 |
|
| 523 | 521 |
/// \brief The subscript operator |
| 524 | 522 |
/// |
| 525 | 523 |
/// The subscript operator. |
| 526 | 524 |
Value operator[](Key key) const {
|
| 527 | 525 |
return _graph.pos(key); |
| 528 | 526 |
} |
| 529 | 527 |
|
| 530 | 528 |
private: |
| 531 | 529 |
const GridGraph& _graph; |
| 532 | 530 |
}; |
| 533 | 531 |
|
| 534 | 532 |
/// \brief Map to get the column of the nodes. |
| 535 | 533 |
/// |
| 536 | 534 |
/// Map to get the column of the nodes. |
| 537 | 535 |
class ColMap {
|
| 538 | 536 |
public: |
| 539 | 537 |
/// \brief The key type of the map |
| 540 | 538 |
typedef GridGraph::Node Key; |
| 541 | 539 |
/// \brief The value type of the map |
| 542 | 540 |
typedef int Value; |
| 543 | 541 |
|
| 544 | 542 |
/// \brief Constructor |
| 545 | 543 |
/// |
| 546 | 544 |
/// Constructor |
| 547 | 545 |
ColMap(const GridGraph& graph) : _graph(graph) {}
|
| 548 | 546 |
|
| 549 | 547 |
/// \brief The subscript operator |
| 550 | 548 |
/// |
| ... | ... |
@@ -247,99 +247,97 @@ |
| 247 | 247 |
} |
| 248 | 248 |
|
| 249 | 249 |
int dimension() const {
|
| 250 | 250 |
return _dim; |
| 251 | 251 |
} |
| 252 | 252 |
|
| 253 | 253 |
bool projection(Node node, int n) const {
|
| 254 | 254 |
return static_cast<bool>(node._id & (1 << n)); |
| 255 | 255 |
} |
| 256 | 256 |
|
| 257 | 257 |
int dimension(Edge edge) const {
|
| 258 | 258 |
return edge._id >> (_dim-1); |
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 | 261 |
int dimension(Arc arc) const {
|
| 262 | 262 |
return arc._id >> _dim; |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 | 265 |
int index(Node node) const {
|
| 266 | 266 |
return node._id; |
| 267 | 267 |
} |
| 268 | 268 |
|
| 269 | 269 |
Node operator()(int ix) const {
|
| 270 | 270 |
return Node(ix); |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
private: |
| 274 | 274 |
int _dim; |
| 275 | 275 |
int _node_num, _edge_num; |
| 276 | 276 |
}; |
| 277 | 277 |
|
| 278 | 278 |
|
| 279 | 279 |
typedef GraphExtender<HypercubeGraphBase> ExtendedHypercubeGraphBase; |
| 280 | 280 |
|
| 281 | 281 |
/// \ingroup graphs |
| 282 | 282 |
/// |
| 283 | 283 |
/// \brief Hypercube graph class |
| 284 | 284 |
/// |
| 285 | 285 |
/// This class implements a special graph type. The nodes of the graph |
| 286 | 286 |
/// are indiced with integers with at most \c dim binary digits. |
| 287 | 287 |
/// Two nodes are connected in the graph if and only if their indices |
| 288 | 288 |
/// differ only on one position in the binary form. |
| 289 | 289 |
/// |
| 290 | 290 |
/// \note The type of the indices is chosen to \c int for efficiency |
| 291 | 291 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
| 292 | 292 |
/// (assuming that the size of \c int is 32 bit). |
| 293 | 293 |
/// |
| 294 | 294 |
/// This graph type fully conforms to the \ref concepts::Graph |
| 295 |
/// "Graph" concept, and it also has an important extra feature |
|
| 296 |
/// that its maps are real \ref concepts::ReferenceMap |
|
| 297 |
/// " |
|
| 295 |
/// "Graph concept". |
|
| 298 | 296 |
class HypercubeGraph : public ExtendedHypercubeGraphBase {
|
| 299 | 297 |
public: |
| 300 | 298 |
|
| 301 | 299 |
typedef ExtendedHypercubeGraphBase Parent; |
| 302 | 300 |
|
| 303 | 301 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
| 304 | 302 |
/// |
| 305 | 303 |
/// Constructs a hypercube graph with \c dim dimensions. |
| 306 | 304 |
HypercubeGraph(int dim) { construct(dim); }
|
| 307 | 305 |
|
| 308 | 306 |
/// \brief The number of dimensions. |
| 309 | 307 |
/// |
| 310 | 308 |
/// Gives back the number of dimensions. |
| 311 | 309 |
int dimension() const {
|
| 312 | 310 |
return Parent::dimension(); |
| 313 | 311 |
} |
| 314 | 312 |
|
| 315 | 313 |
/// \brief Returns \c true if the n'th bit of the node is one. |
| 316 | 314 |
/// |
| 317 | 315 |
/// Returns \c true if the n'th bit of the node is one. |
| 318 | 316 |
bool projection(Node node, int n) const {
|
| 319 | 317 |
return Parent::projection(node, n); |
| 320 | 318 |
} |
| 321 | 319 |
|
| 322 | 320 |
/// \brief The dimension id of an edge. |
| 323 | 321 |
/// |
| 324 | 322 |
/// Gives back the dimension id of the given edge. |
| 325 | 323 |
/// It is in the [0..dim-1] range. |
| 326 | 324 |
int dimension(Edge edge) const {
|
| 327 | 325 |
return Parent::dimension(edge); |
| 328 | 326 |
} |
| 329 | 327 |
|
| 330 | 328 |
/// \brief The dimension id of an arc. |
| 331 | 329 |
/// |
| 332 | 330 |
/// Gives back the dimension id of the given arc. |
| 333 | 331 |
/// It is in the [0..dim-1] range. |
| 334 | 332 |
int dimension(Arc arc) const {
|
| 335 | 333 |
return Parent::dimension(arc); |
| 336 | 334 |
} |
| 337 | 335 |
|
| 338 | 336 |
/// \brief The index of a node. |
| 339 | 337 |
/// |
| 340 | 338 |
/// Gives back the index of the given node. |
| 341 | 339 |
/// The lower bits of the integer describes the node. |
| 342 | 340 |
int index(Node node) const {
|
| 343 | 341 |
return Parent::index(node); |
| 344 | 342 |
} |
| 345 | 343 |
| ... | ... |
@@ -275,99 +275,96 @@ |
| 275 | 275 |
{
|
| 276 | 276 |
if(arcs[e.id].next_in != -1) |
| 277 | 277 |
arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; |
| 278 | 278 |
if(arcs[e.id].prev_in != -1) |
| 279 | 279 |
arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; |
| 280 | 280 |
else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in; |
| 281 | 281 |
if (nodes[n.id].first_in != -1) {
|
| 282 | 282 |
arcs[nodes[n.id].first_in].prev_in = e.id; |
| 283 | 283 |
} |
| 284 | 284 |
arcs[e.id].target = n.id; |
| 285 | 285 |
arcs[e.id].prev_in = -1; |
| 286 | 286 |
arcs[e.id].next_in = nodes[n.id].first_in; |
| 287 | 287 |
nodes[n.id].first_in = e.id; |
| 288 | 288 |
} |
| 289 | 289 |
void changeSource(Arc e, Node n) |
| 290 | 290 |
{
|
| 291 | 291 |
if(arcs[e.id].next_out != -1) |
| 292 | 292 |
arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; |
| 293 | 293 |
if(arcs[e.id].prev_out != -1) |
| 294 | 294 |
arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; |
| 295 | 295 |
else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out; |
| 296 | 296 |
if (nodes[n.id].first_out != -1) {
|
| 297 | 297 |
arcs[nodes[n.id].first_out].prev_out = e.id; |
| 298 | 298 |
} |
| 299 | 299 |
arcs[e.id].source = n.id; |
| 300 | 300 |
arcs[e.id].prev_out = -1; |
| 301 | 301 |
arcs[e.id].next_out = nodes[n.id].first_out; |
| 302 | 302 |
nodes[n.id].first_out = e.id; |
| 303 | 303 |
} |
| 304 | 304 |
|
| 305 | 305 |
}; |
| 306 | 306 |
|
| 307 | 307 |
typedef DigraphExtender<ListDigraphBase> ExtendedListDigraphBase; |
| 308 | 308 |
|
| 309 | 309 |
/// \addtogroup graphs |
| 310 | 310 |
/// @{
|
| 311 | 311 |
|
| 312 | 312 |
///A general directed graph structure. |
| 313 | 313 |
|
| 314 | 314 |
///\ref ListDigraph is a simple and fast <em>directed graph</em> |
| 315 | 315 |
///implementation based on static linked lists that are stored in |
| 316 | 316 |
///\c std::vector structures. |
| 317 | 317 |
/// |
| 318 | 318 |
///It conforms to the \ref concepts::Digraph "Digraph concept" and it |
| 319 | 319 |
///also provides several useful additional functionalities. |
| 320 | 320 |
///Most of the member functions and nested classes are documented |
| 321 | 321 |
///only in the concept class. |
| 322 | 322 |
/// |
| 323 |
///An important extra feature of this digraph implementation is that |
|
| 324 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 325 |
/// |
|
| 326 | 323 |
///\sa concepts::Digraph |
| 327 | 324 |
|
| 328 | 325 |
class ListDigraph : public ExtendedListDigraphBase {
|
| 329 | 326 |
private: |
| 330 | 327 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
| 331 | 328 |
|
| 332 | 329 |
///ListDigraph is \e not copy constructible. Use copyDigraph() instead. |
| 333 | 330 |
/// |
| 334 | 331 |
ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
|
| 335 | 332 |
///\brief Assignment of ListDigraph to another one is \e not allowed. |
| 336 | 333 |
///Use copyDigraph() instead. |
| 337 | 334 |
|
| 338 | 335 |
///Assignment of ListDigraph to another one is \e not allowed. |
| 339 | 336 |
///Use copyDigraph() instead. |
| 340 | 337 |
void operator=(const ListDigraph &) {}
|
| 341 | 338 |
public: |
| 342 | 339 |
|
| 343 | 340 |
typedef ExtendedListDigraphBase Parent; |
| 344 | 341 |
|
| 345 | 342 |
/// Constructor |
| 346 | 343 |
|
| 347 | 344 |
/// Constructor. |
| 348 | 345 |
/// |
| 349 | 346 |
ListDigraph() {}
|
| 350 | 347 |
|
| 351 | 348 |
///Add a new node to the digraph. |
| 352 | 349 |
|
| 353 | 350 |
///Add a new node to the digraph. |
| 354 | 351 |
///\return The new node. |
| 355 | 352 |
Node addNode() { return Parent::addNode(); }
|
| 356 | 353 |
|
| 357 | 354 |
///Add a new arc to the digraph. |
| 358 | 355 |
|
| 359 | 356 |
///Add a new arc to the digraph with source node \c s |
| 360 | 357 |
///and target node \c t. |
| 361 | 358 |
///\return The new arc. |
| 362 | 359 |
Arc addArc(const Node& s, const Node& t) {
|
| 363 | 360 |
return Parent::addArc(s, t); |
| 364 | 361 |
} |
| 365 | 362 |
|
| 366 | 363 |
///\brief Erase a node from the digraph. |
| 367 | 364 |
/// |
| 368 | 365 |
///Erase a node from the digraph. |
| 369 | 366 |
/// |
| 370 | 367 |
void erase(const Node& n) { Parent::erase(n); }
|
| 371 | 368 |
|
| 372 | 369 |
///\brief Erase an arc from the digraph. |
| 373 | 370 |
/// |
| ... | ... |
@@ -1131,99 +1128,96 @@ |
| 1131 | 1128 |
} |
| 1132 | 1129 |
arcs[(2 * e.id) | 1].target = n.id; |
| 1133 | 1130 |
arcs[2 * e.id].prev_out = -1; |
| 1134 | 1131 |
arcs[2 * e.id].next_out = nodes[n.id].first_out; |
| 1135 | 1132 |
nodes[n.id].first_out = 2 * e.id; |
| 1136 | 1133 |
} |
| 1137 | 1134 |
|
| 1138 | 1135 |
void changeU(Edge e, Node n) {
|
| 1139 | 1136 |
if(arcs[(2 * e.id) | 1].next_out != -1) {
|
| 1140 | 1137 |
arcs[arcs[(2 * e.id) | 1].next_out].prev_out = |
| 1141 | 1138 |
arcs[(2 * e.id) | 1].prev_out; |
| 1142 | 1139 |
} |
| 1143 | 1140 |
if(arcs[(2 * e.id) | 1].prev_out != -1) {
|
| 1144 | 1141 |
arcs[arcs[(2 * e.id) | 1].prev_out].next_out = |
| 1145 | 1142 |
arcs[(2 * e.id) | 1].next_out; |
| 1146 | 1143 |
} else {
|
| 1147 | 1144 |
nodes[arcs[2 * e.id].target].first_out = |
| 1148 | 1145 |
arcs[(2 * e.id) | 1].next_out; |
| 1149 | 1146 |
} |
| 1150 | 1147 |
|
| 1151 | 1148 |
if (nodes[n.id].first_out != -1) {
|
| 1152 | 1149 |
arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); |
| 1153 | 1150 |
} |
| 1154 | 1151 |
arcs[2 * e.id].target = n.id; |
| 1155 | 1152 |
arcs[(2 * e.id) | 1].prev_out = -1; |
| 1156 | 1153 |
arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out; |
| 1157 | 1154 |
nodes[n.id].first_out = ((2 * e.id) | 1); |
| 1158 | 1155 |
} |
| 1159 | 1156 |
|
| 1160 | 1157 |
}; |
| 1161 | 1158 |
|
| 1162 | 1159 |
typedef GraphExtender<ListGraphBase> ExtendedListGraphBase; |
| 1163 | 1160 |
|
| 1164 | 1161 |
|
| 1165 | 1162 |
/// \addtogroup graphs |
| 1166 | 1163 |
/// @{
|
| 1167 | 1164 |
|
| 1168 | 1165 |
///A general undirected graph structure. |
| 1169 | 1166 |
|
| 1170 | 1167 |
///\ref ListGraph is a simple and fast <em>undirected graph</em> |
| 1171 | 1168 |
///implementation based on static linked lists that are stored in |
| 1172 | 1169 |
///\c std::vector structures. |
| 1173 | 1170 |
/// |
| 1174 | 1171 |
///It conforms to the \ref concepts::Graph "Graph concept" and it |
| 1175 | 1172 |
///also provides several useful additional functionalities. |
| 1176 | 1173 |
///Most of the member functions and nested classes are documented |
| 1177 | 1174 |
///only in the concept class. |
| 1178 | 1175 |
/// |
| 1179 |
///An important extra feature of this graph implementation is that |
|
| 1180 |
///its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 1181 |
/// |
|
| 1182 | 1176 |
///\sa concepts::Graph |
| 1183 | 1177 |
|
| 1184 | 1178 |
class ListGraph : public ExtendedListGraphBase {
|
| 1185 | 1179 |
private: |
| 1186 | 1180 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
| 1187 | 1181 |
|
| 1188 | 1182 |
///ListGraph is \e not copy constructible. Use copyGraph() instead. |
| 1189 | 1183 |
/// |
| 1190 | 1184 |
ListGraph(const ListGraph &) :ExtendedListGraphBase() {};
|
| 1191 | 1185 |
///\brief Assignment of ListGraph to another one is \e not allowed. |
| 1192 | 1186 |
///Use copyGraph() instead. |
| 1193 | 1187 |
|
| 1194 | 1188 |
///Assignment of ListGraph to another one is \e not allowed. |
| 1195 | 1189 |
///Use copyGraph() instead. |
| 1196 | 1190 |
void operator=(const ListGraph &) {}
|
| 1197 | 1191 |
public: |
| 1198 | 1192 |
/// Constructor |
| 1199 | 1193 |
|
| 1200 | 1194 |
/// Constructor. |
| 1201 | 1195 |
/// |
| 1202 | 1196 |
ListGraph() {}
|
| 1203 | 1197 |
|
| 1204 | 1198 |
typedef ExtendedListGraphBase Parent; |
| 1205 | 1199 |
|
| 1206 | 1200 |
typedef Parent::OutArcIt IncEdgeIt; |
| 1207 | 1201 |
|
| 1208 | 1202 |
/// \brief Add a new node to the graph. |
| 1209 | 1203 |
/// |
| 1210 | 1204 |
/// Add a new node to the graph. |
| 1211 | 1205 |
/// \return The new node. |
| 1212 | 1206 |
Node addNode() { return Parent::addNode(); }
|
| 1213 | 1207 |
|
| 1214 | 1208 |
/// \brief Add a new edge to the graph. |
| 1215 | 1209 |
/// |
| 1216 | 1210 |
/// Add a new edge to the graph with source node \c s |
| 1217 | 1211 |
/// and target node \c t. |
| 1218 | 1212 |
/// \return The new edge. |
| 1219 | 1213 |
Edge addEdge(const Node& s, const Node& t) {
|
| 1220 | 1214 |
return Parent::addEdge(s, t); |
| 1221 | 1215 |
} |
| 1222 | 1216 |
|
| 1223 | 1217 |
/// \brief Erase a node from the graph. |
| 1224 | 1218 |
/// |
| 1225 | 1219 |
/// Erase a node from the graph. |
| 1226 | 1220 |
/// |
| 1227 | 1221 |
void erase(const Node& n) { Parent::erase(n); }
|
| 1228 | 1222 |
|
| 1229 | 1223 |
/// \brief Erase an edge from the graph. |
| ... | ... |
@@ -146,99 +146,97 @@ |
| 146 | 146 |
bool operator!=(const Arc i) const {return _id != i._id;}
|
| 147 | 147 |
bool operator<(const Arc i) const {return _id < i._id;}
|
| 148 | 148 |
}; |
| 149 | 149 |
|
| 150 | 150 |
void first(Node& node) const {
|
| 151 | 151 |
node._id = nodes.size() - 1; |
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 | 154 |
static void next(Node& node) {
|
| 155 | 155 |
--node._id; |
| 156 | 156 |
} |
| 157 | 157 |
|
| 158 | 158 |
void first(Arc& arc) const {
|
| 159 | 159 |
arc._id = arcs.size() - 1; |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
static void next(Arc& arc) {
|
| 163 | 163 |
--arc._id; |
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
void firstOut(Arc& arc, const Node& node) const {
|
| 167 | 167 |
arc._id = nodes[node._id].first_out; |
| 168 | 168 |
} |
| 169 | 169 |
|
| 170 | 170 |
void nextOut(Arc& arc) const {
|
| 171 | 171 |
arc._id = arcs[arc._id].next_out; |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 | 174 |
void firstIn(Arc& arc, const Node& node) const {
|
| 175 | 175 |
arc._id = nodes[node._id].first_in; |
| 176 | 176 |
} |
| 177 | 177 |
|
| 178 | 178 |
void nextIn(Arc& arc) const {
|
| 179 | 179 |
arc._id = arcs[arc._id].next_in; |
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 | 182 |
}; |
| 183 | 183 |
|
| 184 | 184 |
typedef DigraphExtender<SmartDigraphBase> ExtendedSmartDigraphBase; |
| 185 | 185 |
|
| 186 | 186 |
///\ingroup graphs |
| 187 | 187 |
/// |
| 188 | 188 |
///\brief A smart directed graph class. |
| 189 | 189 |
/// |
| 190 | 190 |
///This is a simple and fast digraph implementation. |
| 191 | 191 |
///It is also quite memory efficient, but at the price |
| 192 | 192 |
///that <b> it does support only limited (only stack-like) |
| 193 | 193 |
///node and arc deletions</b>. |
| 194 |
///It conforms to the \ref concepts::Digraph "Digraph concept" with |
|
| 195 |
///an important extra feature that its maps are real \ref |
|
| 196 |
///concepts:: |
|
| 194 |
///It fully conforms to the \ref concepts::Digraph "Digraph concept". |
|
| 197 | 195 |
/// |
| 198 | 196 |
///\sa concepts::Digraph. |
| 199 | 197 |
class SmartDigraph : public ExtendedSmartDigraphBase {
|
| 200 | 198 |
public: |
| 201 | 199 |
|
| 202 | 200 |
typedef ExtendedSmartDigraphBase Parent; |
| 203 | 201 |
|
| 204 | 202 |
private: |
| 205 | 203 |
|
| 206 | 204 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 207 | 205 |
|
| 208 | 206 |
///SmartDigraph is \e not copy constructible. Use DigraphCopy() instead. |
| 209 | 207 |
/// |
| 210 | 208 |
SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
|
| 211 | 209 |
///\brief Assignment of SmartDigraph to another one is \e not allowed. |
| 212 | 210 |
///Use DigraphCopy() instead. |
| 213 | 211 |
|
| 214 | 212 |
///Assignment of SmartDigraph to another one is \e not allowed. |
| 215 | 213 |
///Use DigraphCopy() instead. |
| 216 | 214 |
void operator=(const SmartDigraph &) {}
|
| 217 | 215 |
|
| 218 | 216 |
public: |
| 219 | 217 |
|
| 220 | 218 |
/// Constructor |
| 221 | 219 |
|
| 222 | 220 |
/// Constructor. |
| 223 | 221 |
/// |
| 224 | 222 |
SmartDigraph() {};
|
| 225 | 223 |
|
| 226 | 224 |
///Add a new node to the digraph. |
| 227 | 225 |
|
| 228 | 226 |
/// Add a new node to the digraph. |
| 229 | 227 |
/// \return The new node. |
| 230 | 228 |
Node addNode() { return Parent::addNode(); }
|
| 231 | 229 |
|
| 232 | 230 |
///Add a new arc to the digraph. |
| 233 | 231 |
|
| 234 | 232 |
///Add a new arc to the digraph with source node \c s |
| 235 | 233 |
///and target node \c t. |
| 236 | 234 |
///\return The new arc. |
| 237 | 235 |
Arc addArc(const Node& s, const Node& t) {
|
| 238 | 236 |
return Parent::addArc(s, t); |
| 239 | 237 |
} |
| 240 | 238 |
|
| 241 | 239 |
/// \brief Using this it is possible to avoid the superfluous memory |
| 242 | 240 |
/// allocation. |
| 243 | 241 |
|
| 244 | 242 |
/// Using this it is possible to avoid the superfluous memory |
| ... | ... |
@@ -584,105 +582,99 @@ |
| 584 | 582 |
return a._id >= 0 && a._id < static_cast<int>(arcs.size()); |
| 585 | 583 |
} |
| 586 | 584 |
bool valid(Edge e) const {
|
| 587 | 585 |
return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size()); |
| 588 | 586 |
} |
| 589 | 587 |
|
| 590 | 588 |
Node addNode() {
|
| 591 | 589 |
int n = nodes.size(); |
| 592 | 590 |
nodes.push_back(NodeT()); |
| 593 | 591 |
nodes[n].first_out = -1; |
| 594 | 592 |
|
| 595 | 593 |
return Node(n); |
| 596 | 594 |
} |
| 597 | 595 |
|
| 598 | 596 |
Edge addEdge(Node u, Node v) {
|
| 599 | 597 |
int n = arcs.size(); |
| 600 | 598 |
arcs.push_back(ArcT()); |
| 601 | 599 |
arcs.push_back(ArcT()); |
| 602 | 600 |
|
| 603 | 601 |
arcs[n].target = u._id; |
| 604 | 602 |
arcs[n | 1].target = v._id; |
| 605 | 603 |
|
| 606 | 604 |
arcs[n].next_out = nodes[v._id].first_out; |
| 607 | 605 |
nodes[v._id].first_out = n; |
| 608 | 606 |
|
| 609 | 607 |
arcs[n | 1].next_out = nodes[u._id].first_out; |
| 610 | 608 |
nodes[u._id].first_out = (n | 1); |
| 611 | 609 |
|
| 612 | 610 |
return Edge(n / 2); |
| 613 | 611 |
} |
| 614 | 612 |
|
| 615 | 613 |
void clear() {
|
| 616 | 614 |
arcs.clear(); |
| 617 | 615 |
nodes.clear(); |
| 618 | 616 |
} |
| 619 | 617 |
|
| 620 | 618 |
}; |
| 621 | 619 |
|
| 622 | 620 |
typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase; |
| 623 | 621 |
|
| 624 | 622 |
/// \ingroup graphs |
| 625 | 623 |
/// |
| 626 | 624 |
/// \brief A smart undirected graph class. |
| 627 | 625 |
/// |
| 628 | 626 |
/// This is a simple and fast graph implementation. |
| 629 | 627 |
/// It is also quite memory efficient, but at the price |
| 630 | 628 |
/// that <b> it does support only limited (only stack-like) |
| 631 | 629 |
/// node and arc deletions</b>. |
| 632 |
/// Except from this it conforms to |
|
| 633 |
/// the \ref concepts::Graph "Graph concept". |
|
| 634 |
/// |
|
| 635 |
/// It also has an |
|
| 636 |
/// important extra feature that |
|
| 637 |
/// its maps are real \ref concepts::ReferenceMap "reference map"s. |
|
| 630 |
/// It fully conforms to the \ref concepts::Graph "Graph concept". |
|
| 638 | 631 |
/// |
| 639 | 632 |
/// \sa concepts::Graph. |
| 640 |
/// |
|
| 641 | 633 |
class SmartGraph : public ExtendedSmartGraphBase {
|
| 642 | 634 |
private: |
| 643 | 635 |
|
| 644 | 636 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
| 645 | 637 |
|
| 646 | 638 |
///SmartGraph is \e not copy constructible. Use GraphCopy() instead. |
| 647 | 639 |
/// |
| 648 | 640 |
SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
|
| 649 | 641 |
|
| 650 | 642 |
///\brief Assignment of SmartGraph to another one is \e not allowed. |
| 651 | 643 |
///Use GraphCopy() instead. |
| 652 | 644 |
|
| 653 | 645 |
///Assignment of SmartGraph to another one is \e not allowed. |
| 654 | 646 |
///Use GraphCopy() instead. |
| 655 | 647 |
void operator=(const SmartGraph &) {}
|
| 656 | 648 |
|
| 657 | 649 |
public: |
| 658 | 650 |
|
| 659 | 651 |
typedef ExtendedSmartGraphBase Parent; |
| 660 | 652 |
|
| 661 | 653 |
/// Constructor |
| 662 | 654 |
|
| 663 | 655 |
/// Constructor. |
| 664 | 656 |
/// |
| 665 | 657 |
SmartGraph() {}
|
| 666 | 658 |
|
| 667 | 659 |
///Add a new node to the graph. |
| 668 | 660 |
|
| 669 | 661 |
/// Add a new node to the graph. |
| 670 | 662 |
/// \return The new node. |
| 671 | 663 |
Node addNode() { return Parent::addNode(); }
|
| 672 | 664 |
|
| 673 | 665 |
///Add a new edge to the graph. |
| 674 | 666 |
|
| 675 | 667 |
///Add a new edge to the graph with node \c s |
| 676 | 668 |
///and \c t. |
| 677 | 669 |
///\return The new edge. |
| 678 | 670 |
Edge addEdge(const Node& s, const Node& t) {
|
| 679 | 671 |
return Parent::addEdge(s, t); |
| 680 | 672 |
} |
| 681 | 673 |
|
| 682 | 674 |
/// \brief Node validity check |
| 683 | 675 |
/// |
| 684 | 676 |
/// This function gives back true if the given node is valid, |
| 685 | 677 |
/// ie. it is a real node of the graph. |
| 686 | 678 |
/// |
| 687 | 679 |
/// \warning A removed node (using Snapshot) could become valid again |
| 688 | 680 |
/// when new nodes are added to the graph. |
0 comments (0 inline)