0
3
0
... | ... |
@@ -278,43 +278,59 @@ |
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 |
/// HypercubeGraph implements a special graph type. The nodes of the |
286 | 286 |
/// graph are indexed with integers having 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 |
/// This class is completely static and it needs constant memory space. |
290 |
/// Thus you can neither add nor delete nodes or edges |
|
290 |
/// Thus you can neither add nor delete nodes or edges, however |
|
291 |
/// the structure can be resized using resize(). |
|
291 | 292 |
/// |
292 | 293 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
293 | 294 |
/// Most of its member functions and nested classes are documented |
294 | 295 |
/// only in the concept class. |
295 | 296 |
/// |
296 | 297 |
/// \note The type of the indices is chosen to \c int for efficiency |
297 | 298 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
298 | 299 |
/// (assuming that the size of \c int is 32 bit). |
299 | 300 |
class HypercubeGraph : public ExtendedHypercubeGraphBase { |
300 | 301 |
typedef ExtendedHypercubeGraphBase Parent; |
301 | 302 |
|
302 | 303 |
public: |
303 | 304 |
|
304 | 305 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
305 | 306 |
/// |
306 | 307 |
/// Constructs a hypercube graph with \c dim dimensions. |
307 | 308 |
HypercubeGraph(int dim) { construct(dim); } |
308 | 309 |
|
310 |
/// \brief Resizes the graph |
|
311 |
/// |
|
312 |
/// This function resizes the graph. It fully destroys and |
|
313 |
/// rebuilds the structure, therefore the maps of the graph will be |
|
314 |
/// reallocated automatically and the previous values will be lost. |
|
315 |
void resize(int dim) { |
|
316 |
Parent::notifier(Arc()).clear(); |
|
317 |
Parent::notifier(Edge()).clear(); |
|
318 |
Parent::notifier(Node()).clear(); |
|
319 |
construct(dim); |
|
320 |
Parent::notifier(Node()).build(); |
|
321 |
Parent::notifier(Edge()).build(); |
|
322 |
Parent::notifier(Arc()).build(); |
|
323 |
} |
|
324 |
|
|
309 | 325 |
/// \brief The number of dimensions. |
310 | 326 |
/// |
311 | 327 |
/// Gives back the number of dimensions. |
312 | 328 |
int dimension() const { |
313 | 329 |
return Parent::dimension(); |
314 | 330 |
} |
315 | 331 |
|
316 | 332 |
/// \brief Returns \c true if the n'th bit of the node is one. |
317 | 333 |
/// |
318 | 334 |
/// Returns \c true if the n'th bit of the node is one. |
319 | 335 |
bool projection(Node node, int n) const { |
320 | 336 |
return Parent::projection(node, n); |
... | ... |
@@ -369,25 +369,30 @@ |
369 | 369 |
check(g.valid(n2), "Wrong validity check"); |
370 | 370 |
check(g.valid(n3), "Wrong validity check"); |
371 | 371 |
check(!g.valid(e1), "Wrong validity check"); |
372 | 372 |
check(g.valid(e2), "Wrong validity check"); |
373 | 373 |
|
374 | 374 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
375 | 375 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
376 | 376 |
} |
377 | 377 |
|
378 | 378 |
void checkFullDigraph(int num) { |
379 | 379 |
typedef FullDigraph Digraph; |
380 | 380 |
DIGRAPH_TYPEDEFS(Digraph); |
381 |
|
|
381 | 382 |
Digraph G(num); |
383 |
check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size"); |
|
384 |
|
|
385 |
G.resize(num); |
|
386 |
check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size"); |
|
382 | 387 |
|
383 | 388 |
checkGraphNodeList(G, num); |
384 | 389 |
checkGraphArcList(G, num * num); |
385 | 390 |
|
386 | 391 |
for (NodeIt n(G); n != INVALID; ++n) { |
387 | 392 |
checkGraphOutArcList(G, n, num); |
388 | 393 |
checkGraphInArcList(G, n, num); |
389 | 394 |
} |
390 | 395 |
|
391 | 396 |
checkGraphConArcList(G, num * num); |
392 | 397 |
|
393 | 398 |
checkNodeIds(G); |
... | ... |
@@ -261,24 +261,31 @@ |
261 | 261 |
snapshot.restore(); |
262 | 262 |
|
263 | 263 |
checkGraphNodeList(G, 4); |
264 | 264 |
checkGraphEdgeList(G, 3); |
265 | 265 |
checkGraphArcList(G, 6); |
266 | 266 |
} |
267 | 267 |
|
268 | 268 |
void checkFullGraph(int num) { |
269 | 269 |
typedef FullGraph Graph; |
270 | 270 |
GRAPH_TYPEDEFS(Graph); |
271 | 271 |
|
272 | 272 |
Graph G(num); |
273 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2, |
|
274 |
"Wrong size"); |
|
275 |
|
|
276 |
G.resize(num); |
|
277 |
check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2, |
|
278 |
"Wrong size"); |
|
279 |
|
|
273 | 280 |
checkGraphNodeList(G, num); |
274 | 281 |
checkGraphEdgeList(G, num * (num - 1) / 2); |
275 | 282 |
|
276 | 283 |
for (NodeIt n(G); n != INVALID; ++n) { |
277 | 284 |
checkGraphOutArcList(G, n, num - 1); |
278 | 285 |
checkGraphInArcList(G, n, num - 1); |
279 | 286 |
checkGraphIncEdgeList(G, n, num - 1); |
280 | 287 |
} |
281 | 288 |
|
282 | 289 |
checkGraphConArcList(G, num * (num - 1)); |
283 | 290 |
checkGraphConEdgeList(G, num * (num - 1) / 2); |
284 | 291 |
|
... | ... |
@@ -405,24 +412,28 @@ |
405 | 412 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
406 | 413 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
407 | 414 |
} |
408 | 415 |
|
409 | 416 |
void checkGridGraph(int width, int height) { |
410 | 417 |
typedef GridGraph Graph; |
411 | 418 |
GRAPH_TYPEDEFS(Graph); |
412 | 419 |
Graph G(width, height); |
413 | 420 |
|
414 | 421 |
check(G.width() == width, "Wrong column number"); |
415 | 422 |
check(G.height() == height, "Wrong row number"); |
416 | 423 |
|
424 |
G.resize(width, height); |
|
425 |
check(G.width() == width, "Wrong column number"); |
|
426 |
check(G.height() == height, "Wrong row number"); |
|
427 |
|
|
417 | 428 |
for (int i = 0; i < width; ++i) { |
418 | 429 |
for (int j = 0; j < height; ++j) { |
419 | 430 |
check(G.col(G(i, j)) == i, "Wrong column"); |
420 | 431 |
check(G.row(G(i, j)) == j, "Wrong row"); |
421 | 432 |
check(G.pos(G(i, j)).x == i, "Wrong column"); |
422 | 433 |
check(G.pos(G(i, j)).y == j, "Wrong row"); |
423 | 434 |
} |
424 | 435 |
} |
425 | 436 |
|
426 | 437 |
for (int j = 0; j < height; ++j) { |
427 | 438 |
for (int i = 0; i < width - 1; ++i) { |
428 | 439 |
check(G.source(G.right(G(i, j))) == G(i, j), "Wrong right"); |
... | ... |
@@ -480,24 +491,29 @@ |
480 | 491 |
checkArcIds(G); |
481 | 492 |
checkEdgeIds(G); |
482 | 493 |
checkGraphNodeMap(G); |
483 | 494 |
checkGraphArcMap(G); |
484 | 495 |
checkGraphEdgeMap(G); |
485 | 496 |
|
486 | 497 |
} |
487 | 498 |
|
488 | 499 |
void checkHypercubeGraph(int dim) { |
489 | 500 |
GRAPH_TYPEDEFS(HypercubeGraph); |
490 | 501 |
|
491 | 502 |
HypercubeGraph G(dim); |
503 |
check(G.dimension() == dim, "Wrong dimension"); |
|
504 |
|
|
505 |
G.resize(dim); |
|
506 |
check(G.dimension() == dim, "Wrong dimension"); |
|
507 |
|
|
492 | 508 |
checkGraphNodeList(G, 1 << dim); |
493 | 509 |
checkGraphEdgeList(G, dim * (1 << (dim-1))); |
494 | 510 |
checkGraphArcList(G, dim * (1 << dim)); |
495 | 511 |
|
496 | 512 |
Node n = G.nodeFromId(dim); |
497 | 513 |
|
498 | 514 |
for (NodeIt n(G); n != INVALID; ++n) { |
499 | 515 |
checkGraphIncEdgeList(G, n, dim); |
500 | 516 |
for (IncEdgeIt e(G, n); e != INVALID; ++e) { |
501 | 517 |
check( (G.u(e) == n && |
502 | 518 |
G.id(G.v(e)) == (G.id(n) ^ (1 << G.dimension(e)))) || |
503 | 519 |
(G.v(e) == n && |
0 comments (0 inline)