0
11
0
| ... | ... |
@@ -315,96 +315,99 @@ |
| 315 | 315 |
return *this; |
| 316 | 316 |
} |
| 317 | 317 |
}; |
| 318 | 318 |
|
| 319 | 319 |
}; |
| 320 | 320 |
|
| 321 | 321 |
template <typename DGR> |
| 322 | 322 |
class ReverseDigraphBase : public DigraphAdaptorBase<DGR> {
|
| 323 | 323 |
typedef DigraphAdaptorBase<DGR> Parent; |
| 324 | 324 |
public: |
| 325 | 325 |
typedef DGR Digraph; |
| 326 | 326 |
protected: |
| 327 | 327 |
ReverseDigraphBase() : Parent() { }
|
| 328 | 328 |
public: |
| 329 | 329 |
typedef typename Parent::Node Node; |
| 330 | 330 |
typedef typename Parent::Arc Arc; |
| 331 | 331 |
|
| 332 | 332 |
void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
|
| 333 | 333 |
void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
|
| 334 | 334 |
|
| 335 | 335 |
void nextIn(Arc& a) const { Parent::nextOut(a); }
|
| 336 | 336 |
void nextOut(Arc& a) const { Parent::nextIn(a); }
|
| 337 | 337 |
|
| 338 | 338 |
Node source(const Arc& a) const { return Parent::target(a); }
|
| 339 | 339 |
Node target(const Arc& a) const { return Parent::source(a); }
|
| 340 | 340 |
|
| 341 | 341 |
Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
|
| 342 | 342 |
|
| 343 | 343 |
typedef FindArcTagIndicator<DGR> FindArcTag; |
| 344 | 344 |
Arc findArc(const Node& u, const Node& v, |
| 345 | 345 |
const Arc& prev = INVALID) const {
|
| 346 | 346 |
return Parent::findArc(v, u, prev); |
| 347 | 347 |
} |
| 348 | 348 |
|
| 349 | 349 |
}; |
| 350 | 350 |
|
| 351 | 351 |
/// \ingroup graph_adaptors |
| 352 | 352 |
/// |
| 353 | 353 |
/// \brief Adaptor class for reversing the orientation of the arcs in |
| 354 | 354 |
/// a digraph. |
| 355 | 355 |
/// |
| 356 | 356 |
/// ReverseDigraph can be used for reversing the arcs in a digraph. |
| 357 | 357 |
/// It conforms to the \ref concepts::Digraph "Digraph" concept. |
| 358 | 358 |
/// |
| 359 | 359 |
/// The adapted digraph can also be modified through this adaptor |
| 360 | 360 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 361 | 361 |
/// parameter is set to be \c const. |
| 362 | 362 |
/// |
| 363 |
/// This class provides item counting in the same time as the adapted |
|
| 364 |
/// digraph structure. |
|
| 365 |
/// |
|
| 363 | 366 |
/// \tparam DGR The type of the adapted digraph. |
| 364 | 367 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 365 | 368 |
/// It can also be specified to be \c const. |
| 366 | 369 |
/// |
| 367 | 370 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
| 368 | 371 |
/// digraph are convertible to each other. |
| 369 | 372 |
template<typename DGR> |
| 370 | 373 |
#ifdef DOXYGEN |
| 371 | 374 |
class ReverseDigraph {
|
| 372 | 375 |
#else |
| 373 | 376 |
class ReverseDigraph : |
| 374 | 377 |
public DigraphAdaptorExtender<ReverseDigraphBase<DGR> > {
|
| 375 | 378 |
#endif |
| 376 | 379 |
typedef DigraphAdaptorExtender<ReverseDigraphBase<DGR> > Parent; |
| 377 | 380 |
public: |
| 378 | 381 |
/// The type of the adapted digraph. |
| 379 | 382 |
typedef DGR Digraph; |
| 380 | 383 |
protected: |
| 381 | 384 |
ReverseDigraph() { }
|
| 382 | 385 |
public: |
| 383 | 386 |
|
| 384 | 387 |
/// \brief Constructor |
| 385 | 388 |
/// |
| 386 | 389 |
/// Creates a reverse digraph adaptor for the given digraph. |
| 387 | 390 |
explicit ReverseDigraph(DGR& digraph) {
|
| 388 | 391 |
Parent::initialize(digraph); |
| 389 | 392 |
} |
| 390 | 393 |
}; |
| 391 | 394 |
|
| 392 | 395 |
/// \brief Returns a read-only ReverseDigraph adaptor |
| 393 | 396 |
/// |
| 394 | 397 |
/// This function just returns a read-only \ref ReverseDigraph adaptor. |
| 395 | 398 |
/// \ingroup graph_adaptors |
| 396 | 399 |
/// \relates ReverseDigraph |
| 397 | 400 |
template<typename DGR> |
| 398 | 401 |
ReverseDigraph<const DGR> reverseDigraph(const DGR& digraph) {
|
| 399 | 402 |
return ReverseDigraph<const DGR>(digraph); |
| 400 | 403 |
} |
| 401 | 404 |
|
| 402 | 405 |
|
| 403 | 406 |
template <typename DGR, typename NF, typename AF, bool ch = true> |
| 404 | 407 |
class SubDigraphBase : public DigraphAdaptorBase<DGR> {
|
| 405 | 408 |
typedef DigraphAdaptorBase<DGR> Parent; |
| 406 | 409 |
public: |
| 407 | 410 |
typedef DGR Digraph; |
| 408 | 411 |
typedef NF NodeFilterMap; |
| 409 | 412 |
typedef AF ArcFilterMap; |
| 410 | 413 |
|
| ... | ... |
@@ -674,96 +677,98 @@ |
| 674 | 677 |
} |
| 675 | 678 |
}; |
| 676 | 679 |
|
| 677 | 680 |
template <typename V> |
| 678 | 681 |
class ArcMap |
| 679 | 682 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
| 680 | 683 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
|
| 681 | 684 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, |
| 682 | 685 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent; |
| 683 | 686 |
|
| 684 | 687 |
public: |
| 685 | 688 |
typedef V Value; |
| 686 | 689 |
|
| 687 | 690 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor) |
| 688 | 691 |
: Parent(adaptor) {}
|
| 689 | 692 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value) |
| 690 | 693 |
: Parent(adaptor, value) {}
|
| 691 | 694 |
|
| 692 | 695 |
private: |
| 693 | 696 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 694 | 697 |
return operator=<ArcMap>(cmap); |
| 695 | 698 |
} |
| 696 | 699 |
|
| 697 | 700 |
template <typename CMap> |
| 698 | 701 |
ArcMap& operator=(const CMap& cmap) {
|
| 699 | 702 |
Parent::operator=(cmap); |
| 700 | 703 |
return *this; |
| 701 | 704 |
} |
| 702 | 705 |
}; |
| 703 | 706 |
|
| 704 | 707 |
}; |
| 705 | 708 |
|
| 706 | 709 |
/// \ingroup graph_adaptors |
| 707 | 710 |
/// |
| 708 | 711 |
/// \brief Adaptor class for hiding nodes and arcs in a digraph |
| 709 | 712 |
/// |
| 710 | 713 |
/// SubDigraph can be used for hiding nodes and arcs in a digraph. |
| 711 | 714 |
/// A \c bool node map and a \c bool arc map must be specified, which |
| 712 | 715 |
/// define the filters for nodes and arcs. |
| 713 | 716 |
/// Only the nodes and arcs with \c true filter value are |
| 714 | 717 |
/// shown in the subdigraph. The arcs that are incident to hidden |
| 715 | 718 |
/// nodes are also filtered out. |
| 716 | 719 |
/// This adaptor conforms to the \ref concepts::Digraph "Digraph" concept. |
| 717 | 720 |
/// |
| 718 | 721 |
/// The adapted digraph can also be modified through this adaptor |
| 719 | 722 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 720 | 723 |
/// parameter is set to be \c const. |
| 721 | 724 |
/// |
| 725 |
/// This class provides only linear time counting for nodes and arcs. |
|
| 726 |
/// |
|
| 722 | 727 |
/// \tparam DGR The type of the adapted digraph. |
| 723 | 728 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 724 | 729 |
/// It can also be specified to be \c const. |
| 725 | 730 |
/// \tparam NF The type of the node filter map. |
| 726 | 731 |
/// It must be a \c bool (or convertible) node map of the |
| 727 | 732 |
/// adapted digraph. The default type is |
| 728 | 733 |
/// \ref concepts::Digraph::NodeMap "DGR::NodeMap<bool>". |
| 729 | 734 |
/// \tparam AF The type of the arc filter map. |
| 730 | 735 |
/// It must be \c bool (or convertible) arc map of the |
| 731 | 736 |
/// adapted digraph. The default type is |
| 732 | 737 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>". |
| 733 | 738 |
/// |
| 734 | 739 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
| 735 | 740 |
/// digraph are convertible to each other. |
| 736 | 741 |
/// |
| 737 | 742 |
/// \see FilterNodes |
| 738 | 743 |
/// \see FilterArcs |
| 739 | 744 |
#ifdef DOXYGEN |
| 740 | 745 |
template<typename DGR, typename NF, typename AF> |
| 741 | 746 |
class SubDigraph {
|
| 742 | 747 |
#else |
| 743 | 748 |
template<typename DGR, |
| 744 | 749 |
typename NF = typename DGR::template NodeMap<bool>, |
| 745 | 750 |
typename AF = typename DGR::template ArcMap<bool> > |
| 746 | 751 |
class SubDigraph : |
| 747 | 752 |
public DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > {
|
| 748 | 753 |
#endif |
| 749 | 754 |
public: |
| 750 | 755 |
/// The type of the adapted digraph. |
| 751 | 756 |
typedef DGR Digraph; |
| 752 | 757 |
/// The type of the node filter map. |
| 753 | 758 |
typedef NF NodeFilterMap; |
| 754 | 759 |
/// The type of the arc filter map. |
| 755 | 760 |
typedef AF ArcFilterMap; |
| 756 | 761 |
|
| 757 | 762 |
typedef DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > |
| 758 | 763 |
Parent; |
| 759 | 764 |
|
| 760 | 765 |
typedef typename Parent::Node Node; |
| 761 | 766 |
typedef typename Parent::Arc Arc; |
| 762 | 767 |
|
| 763 | 768 |
protected: |
| 764 | 769 |
SubDigraph() { }
|
| 765 | 770 |
public: |
| 766 | 771 |
|
| 767 | 772 |
/// \brief Constructor |
| 768 | 773 |
/// |
| 769 | 774 |
/// Creates a subdigraph for the given digraph with the |
| ... | ... |
@@ -1269,96 +1274,98 @@ |
| 1269 | 1274 |
|
| 1270 | 1275 |
template <typename V> |
| 1271 | 1276 |
class EdgeMap |
| 1272 | 1277 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
| 1273 | 1278 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
|
| 1274 | 1279 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, |
| 1275 | 1280 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent; |
| 1276 | 1281 |
|
| 1277 | 1282 |
public: |
| 1278 | 1283 |
typedef V Value; |
| 1279 | 1284 |
|
| 1280 | 1285 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor) |
| 1281 | 1286 |
: Parent(adaptor) {}
|
| 1282 | 1287 |
|
| 1283 | 1288 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value) |
| 1284 | 1289 |
: Parent(adaptor, value) {}
|
| 1285 | 1290 |
|
| 1286 | 1291 |
private: |
| 1287 | 1292 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 1288 | 1293 |
return operator=<EdgeMap>(cmap); |
| 1289 | 1294 |
} |
| 1290 | 1295 |
|
| 1291 | 1296 |
template <typename CMap> |
| 1292 | 1297 |
EdgeMap& operator=(const CMap& cmap) {
|
| 1293 | 1298 |
Parent::operator=(cmap); |
| 1294 | 1299 |
return *this; |
| 1295 | 1300 |
} |
| 1296 | 1301 |
}; |
| 1297 | 1302 |
|
| 1298 | 1303 |
}; |
| 1299 | 1304 |
|
| 1300 | 1305 |
/// \ingroup graph_adaptors |
| 1301 | 1306 |
/// |
| 1302 | 1307 |
/// \brief Adaptor class for hiding nodes and edges in an undirected |
| 1303 | 1308 |
/// graph. |
| 1304 | 1309 |
/// |
| 1305 | 1310 |
/// SubGraph can be used for hiding nodes and edges in a graph. |
| 1306 | 1311 |
/// A \c bool node map and a \c bool edge map must be specified, which |
| 1307 | 1312 |
/// define the filters for nodes and edges. |
| 1308 | 1313 |
/// Only the nodes and edges with \c true filter value are |
| 1309 | 1314 |
/// shown in the subgraph. The edges that are incident to hidden |
| 1310 | 1315 |
/// nodes are also filtered out. |
| 1311 | 1316 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept. |
| 1312 | 1317 |
/// |
| 1313 | 1318 |
/// The adapted graph can also be modified through this adaptor |
| 1314 | 1319 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 1315 | 1320 |
/// parameter is set to be \c const. |
| 1316 | 1321 |
/// |
| 1322 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
| 1323 |
/// |
|
| 1317 | 1324 |
/// \tparam GR The type of the adapted graph. |
| 1318 | 1325 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 1319 | 1326 |
/// It can also be specified to be \c const. |
| 1320 | 1327 |
/// \tparam NF The type of the node filter map. |
| 1321 | 1328 |
/// It must be a \c bool (or convertible) node map of the |
| 1322 | 1329 |
/// adapted graph. The default type is |
| 1323 | 1330 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>". |
| 1324 | 1331 |
/// \tparam EF The type of the edge filter map. |
| 1325 | 1332 |
/// It must be a \c bool (or convertible) edge map of the |
| 1326 | 1333 |
/// adapted graph. The default type is |
| 1327 | 1334 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
| 1328 | 1335 |
/// |
| 1329 | 1336 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the |
| 1330 | 1337 |
/// adapted graph are convertible to each other. |
| 1331 | 1338 |
/// |
| 1332 | 1339 |
/// \see FilterNodes |
| 1333 | 1340 |
/// \see FilterEdges |
| 1334 | 1341 |
#ifdef DOXYGEN |
| 1335 | 1342 |
template<typename GR, typename NF, typename EF> |
| 1336 | 1343 |
class SubGraph {
|
| 1337 | 1344 |
#else |
| 1338 | 1345 |
template<typename GR, |
| 1339 | 1346 |
typename NF = typename GR::template NodeMap<bool>, |
| 1340 | 1347 |
typename EF = typename GR::template EdgeMap<bool> > |
| 1341 | 1348 |
class SubGraph : |
| 1342 | 1349 |
public GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > {
|
| 1343 | 1350 |
#endif |
| 1344 | 1351 |
public: |
| 1345 | 1352 |
/// The type of the adapted graph. |
| 1346 | 1353 |
typedef GR Graph; |
| 1347 | 1354 |
/// The type of the node filter map. |
| 1348 | 1355 |
typedef NF NodeFilterMap; |
| 1349 | 1356 |
/// The type of the edge filter map. |
| 1350 | 1357 |
typedef EF EdgeFilterMap; |
| 1351 | 1358 |
|
| 1352 | 1359 |
typedef GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > |
| 1353 | 1360 |
Parent; |
| 1354 | 1361 |
|
| 1355 | 1362 |
typedef typename Parent::Node Node; |
| 1356 | 1363 |
typedef typename Parent::Edge Edge; |
| 1357 | 1364 |
|
| 1358 | 1365 |
protected: |
| 1359 | 1366 |
SubGraph() { }
|
| 1360 | 1367 |
public: |
| 1361 | 1368 |
|
| 1362 | 1369 |
/// \brief Constructor |
| 1363 | 1370 |
/// |
| 1364 | 1371 |
/// Creates a subgraph for the given graph with the given node |
| ... | ... |
@@ -1426,96 +1433,98 @@ |
| 1426 | 1433 |
/// This function just returns a read-only \ref SubGraph adaptor. |
| 1427 | 1434 |
/// \ingroup graph_adaptors |
| 1428 | 1435 |
/// \relates SubGraph |
| 1429 | 1436 |
template<typename GR, typename NF, typename EF> |
| 1430 | 1437 |
SubGraph<const GR, NF, EF> |
| 1431 | 1438 |
subGraph(const GR& graph, NF& node_filter, EF& edge_filter) {
|
| 1432 | 1439 |
return SubGraph<const GR, NF, EF> |
| 1433 | 1440 |
(graph, node_filter, edge_filter); |
| 1434 | 1441 |
} |
| 1435 | 1442 |
|
| 1436 | 1443 |
template<typename GR, typename NF, typename EF> |
| 1437 | 1444 |
SubGraph<const GR, const NF, EF> |
| 1438 | 1445 |
subGraph(const GR& graph, const NF& node_filter, EF& edge_filter) {
|
| 1439 | 1446 |
return SubGraph<const GR, const NF, EF> |
| 1440 | 1447 |
(graph, node_filter, edge_filter); |
| 1441 | 1448 |
} |
| 1442 | 1449 |
|
| 1443 | 1450 |
template<typename GR, typename NF, typename EF> |
| 1444 | 1451 |
SubGraph<const GR, NF, const EF> |
| 1445 | 1452 |
subGraph(const GR& graph, NF& node_filter, const EF& edge_filter) {
|
| 1446 | 1453 |
return SubGraph<const GR, NF, const EF> |
| 1447 | 1454 |
(graph, node_filter, edge_filter); |
| 1448 | 1455 |
} |
| 1449 | 1456 |
|
| 1450 | 1457 |
template<typename GR, typename NF, typename EF> |
| 1451 | 1458 |
SubGraph<const GR, const NF, const EF> |
| 1452 | 1459 |
subGraph(const GR& graph, const NF& node_filter, const EF& edge_filter) {
|
| 1453 | 1460 |
return SubGraph<const GR, const NF, const EF> |
| 1454 | 1461 |
(graph, node_filter, edge_filter); |
| 1455 | 1462 |
} |
| 1456 | 1463 |
|
| 1457 | 1464 |
|
| 1458 | 1465 |
/// \ingroup graph_adaptors |
| 1459 | 1466 |
/// |
| 1460 | 1467 |
/// \brief Adaptor class for hiding nodes in a digraph or a graph. |
| 1461 | 1468 |
/// |
| 1462 | 1469 |
/// FilterNodes adaptor can be used for hiding nodes in a digraph or a |
| 1463 | 1470 |
/// graph. A \c bool node map must be specified, which defines the filter |
| 1464 | 1471 |
/// for the nodes. Only the nodes with \c true filter value and the |
| 1465 | 1472 |
/// arcs/edges incident to nodes both with \c true filter value are shown |
| 1466 | 1473 |
/// in the subgraph. This adaptor conforms to the \ref concepts::Digraph |
| 1467 | 1474 |
/// "Digraph" concept or the \ref concepts::Graph "Graph" concept |
| 1468 | 1475 |
/// depending on the \c GR template parameter. |
| 1469 | 1476 |
/// |
| 1470 | 1477 |
/// The adapted (di)graph can also be modified through this adaptor |
| 1471 | 1478 |
/// by adding or removing nodes or arcs/edges, unless the \c GR template |
| 1472 | 1479 |
/// parameter is set to be \c const. |
| 1473 | 1480 |
/// |
| 1481 |
/// This class provides only linear time item counting. |
|
| 1482 |
/// |
|
| 1474 | 1483 |
/// \tparam GR The type of the adapted digraph or graph. |
| 1475 | 1484 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept |
| 1476 | 1485 |
/// or the \ref concepts::Graph "Graph" concept. |
| 1477 | 1486 |
/// It can also be specified to be \c const. |
| 1478 | 1487 |
/// \tparam NF The type of the node filter map. |
| 1479 | 1488 |
/// It must be a \c bool (or convertible) node map of the |
| 1480 | 1489 |
/// adapted (di)graph. The default type is |
| 1481 | 1490 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>". |
| 1482 | 1491 |
/// |
| 1483 | 1492 |
/// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the |
| 1484 | 1493 |
/// adapted (di)graph are convertible to each other. |
| 1485 | 1494 |
#ifdef DOXYGEN |
| 1486 | 1495 |
template<typename GR, typename NF> |
| 1487 | 1496 |
class FilterNodes {
|
| 1488 | 1497 |
#else |
| 1489 | 1498 |
template<typename GR, |
| 1490 | 1499 |
typename NF = typename GR::template NodeMap<bool>, |
| 1491 | 1500 |
typename Enable = void> |
| 1492 | 1501 |
class FilterNodes : |
| 1493 | 1502 |
public DigraphAdaptorExtender< |
| 1494 | 1503 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
| 1495 | 1504 |
true> > {
|
| 1496 | 1505 |
#endif |
| 1497 | 1506 |
typedef DigraphAdaptorExtender< |
| 1498 | 1507 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, |
| 1499 | 1508 |
true> > Parent; |
| 1500 | 1509 |
|
| 1501 | 1510 |
public: |
| 1502 | 1511 |
|
| 1503 | 1512 |
typedef GR Digraph; |
| 1504 | 1513 |
typedef NF NodeFilterMap; |
| 1505 | 1514 |
|
| 1506 | 1515 |
typedef typename Parent::Node Node; |
| 1507 | 1516 |
|
| 1508 | 1517 |
protected: |
| 1509 | 1518 |
ConstMap<typename Digraph::Arc, Const<bool, true> > const_true_map; |
| 1510 | 1519 |
|
| 1511 | 1520 |
FilterNodes() : const_true_map() {}
|
| 1512 | 1521 |
|
| 1513 | 1522 |
public: |
| 1514 | 1523 |
|
| 1515 | 1524 |
/// \brief Constructor |
| 1516 | 1525 |
/// |
| 1517 | 1526 |
/// Creates a subgraph for the given digraph or graph with the |
| 1518 | 1527 |
/// given node filter map. |
| 1519 | 1528 |
FilterNodes(GR& graph, NF& node_filter) |
| 1520 | 1529 |
: Parent(), const_true_map() |
| 1521 | 1530 |
{
|
| ... | ... |
@@ -1574,96 +1583,98 @@ |
| 1574 | 1583 |
FilterNodes() : const_true_map() {}
|
| 1575 | 1584 |
|
| 1576 | 1585 |
public: |
| 1577 | 1586 |
|
| 1578 | 1587 |
FilterNodes(GR& graph, NodeFilterMap& node_filter) : |
| 1579 | 1588 |
Parent(), const_true_map() {
|
| 1580 | 1589 |
Parent::initialize(graph, node_filter, const_true_map); |
| 1581 | 1590 |
} |
| 1582 | 1591 |
|
| 1583 | 1592 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
| 1584 | 1593 |
bool status(const Node& n) const { return Parent::status(n); }
|
| 1585 | 1594 |
void disable(const Node& n) const { Parent::status(n, false); }
|
| 1586 | 1595 |
void enable(const Node& n) const { Parent::status(n, true); }
|
| 1587 | 1596 |
|
| 1588 | 1597 |
}; |
| 1589 | 1598 |
|
| 1590 | 1599 |
|
| 1591 | 1600 |
/// \brief Returns a read-only FilterNodes adaptor |
| 1592 | 1601 |
/// |
| 1593 | 1602 |
/// This function just returns a read-only \ref FilterNodes adaptor. |
| 1594 | 1603 |
/// \ingroup graph_adaptors |
| 1595 | 1604 |
/// \relates FilterNodes |
| 1596 | 1605 |
template<typename GR, typename NF> |
| 1597 | 1606 |
FilterNodes<const GR, NF> |
| 1598 | 1607 |
filterNodes(const GR& graph, NF& node_filter) {
|
| 1599 | 1608 |
return FilterNodes<const GR, NF>(graph, node_filter); |
| 1600 | 1609 |
} |
| 1601 | 1610 |
|
| 1602 | 1611 |
template<typename GR, typename NF> |
| 1603 | 1612 |
FilterNodes<const GR, const NF> |
| 1604 | 1613 |
filterNodes(const GR& graph, const NF& node_filter) {
|
| 1605 | 1614 |
return FilterNodes<const GR, const NF>(graph, node_filter); |
| 1606 | 1615 |
} |
| 1607 | 1616 |
|
| 1608 | 1617 |
/// \ingroup graph_adaptors |
| 1609 | 1618 |
/// |
| 1610 | 1619 |
/// \brief Adaptor class for hiding arcs in a digraph. |
| 1611 | 1620 |
/// |
| 1612 | 1621 |
/// FilterArcs adaptor can be used for hiding arcs in a digraph. |
| 1613 | 1622 |
/// A \c bool arc map must be specified, which defines the filter for |
| 1614 | 1623 |
/// the arcs. Only the arcs with \c true filter value are shown in the |
| 1615 | 1624 |
/// subdigraph. This adaptor conforms to the \ref concepts::Digraph |
| 1616 | 1625 |
/// "Digraph" concept. |
| 1617 | 1626 |
/// |
| 1618 | 1627 |
/// The adapted digraph can also be modified through this adaptor |
| 1619 | 1628 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 1620 | 1629 |
/// parameter is set to be \c const. |
| 1621 | 1630 |
/// |
| 1631 |
/// This class provides only linear time counting for nodes and arcs. |
|
| 1632 |
/// |
|
| 1622 | 1633 |
/// \tparam DGR The type of the adapted digraph. |
| 1623 | 1634 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 1624 | 1635 |
/// It can also be specified to be \c const. |
| 1625 | 1636 |
/// \tparam AF The type of the arc filter map. |
| 1626 | 1637 |
/// It must be a \c bool (or convertible) arc map of the |
| 1627 | 1638 |
/// adapted digraph. The default type is |
| 1628 | 1639 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>". |
| 1629 | 1640 |
/// |
| 1630 | 1641 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted |
| 1631 | 1642 |
/// digraph are convertible to each other. |
| 1632 | 1643 |
#ifdef DOXYGEN |
| 1633 | 1644 |
template<typename DGR, |
| 1634 | 1645 |
typename AF> |
| 1635 | 1646 |
class FilterArcs {
|
| 1636 | 1647 |
#else |
| 1637 | 1648 |
template<typename DGR, |
| 1638 | 1649 |
typename AF = typename DGR::template ArcMap<bool> > |
| 1639 | 1650 |
class FilterArcs : |
| 1640 | 1651 |
public DigraphAdaptorExtender< |
| 1641 | 1652 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
| 1642 | 1653 |
AF, false> > {
|
| 1643 | 1654 |
#endif |
| 1644 | 1655 |
typedef DigraphAdaptorExtender< |
| 1645 | 1656 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, |
| 1646 | 1657 |
AF, false> > Parent; |
| 1647 | 1658 |
|
| 1648 | 1659 |
public: |
| 1649 | 1660 |
|
| 1650 | 1661 |
/// The type of the adapted digraph. |
| 1651 | 1662 |
typedef DGR Digraph; |
| 1652 | 1663 |
/// The type of the arc filter map. |
| 1653 | 1664 |
typedef AF ArcFilterMap; |
| 1654 | 1665 |
|
| 1655 | 1666 |
typedef typename Parent::Arc Arc; |
| 1656 | 1667 |
|
| 1657 | 1668 |
protected: |
| 1658 | 1669 |
ConstMap<typename DGR::Node, Const<bool, true> > const_true_map; |
| 1659 | 1670 |
|
| 1660 | 1671 |
FilterArcs() : const_true_map() {}
|
| 1661 | 1672 |
|
| 1662 | 1673 |
public: |
| 1663 | 1674 |
|
| 1664 | 1675 |
/// \brief Constructor |
| 1665 | 1676 |
/// |
| 1666 | 1677 |
/// Creates a subdigraph for the given digraph with the given arc |
| 1667 | 1678 |
/// filter map. |
| 1668 | 1679 |
FilterArcs(DGR& digraph, ArcFilterMap& arc_filter) |
| 1669 | 1680 |
: Parent(), const_true_map() {
|
| ... | ... |
@@ -1684,96 +1695,98 @@ |
| 1684 | 1695 |
bool status(const Arc& a) const { return Parent::status(a); }
|
| 1685 | 1696 |
|
| 1686 | 1697 |
/// \brief Disables the given arc |
| 1687 | 1698 |
/// |
| 1688 | 1699 |
/// This function disables the given arc in the subdigraph, |
| 1689 | 1700 |
/// so the iteration jumps over it. |
| 1690 | 1701 |
/// It is the same as \ref status() "status(a, false)". |
| 1691 | 1702 |
void disable(const Arc& a) const { Parent::status(a, false); }
|
| 1692 | 1703 |
|
| 1693 | 1704 |
/// \brief Enables the given arc |
| 1694 | 1705 |
/// |
| 1695 | 1706 |
/// This function enables the given arc in the subdigraph. |
| 1696 | 1707 |
/// It is the same as \ref status() "status(a, true)". |
| 1697 | 1708 |
void enable(const Arc& a) const { Parent::status(a, true); }
|
| 1698 | 1709 |
|
| 1699 | 1710 |
}; |
| 1700 | 1711 |
|
| 1701 | 1712 |
/// \brief Returns a read-only FilterArcs adaptor |
| 1702 | 1713 |
/// |
| 1703 | 1714 |
/// This function just returns a read-only \ref FilterArcs adaptor. |
| 1704 | 1715 |
/// \ingroup graph_adaptors |
| 1705 | 1716 |
/// \relates FilterArcs |
| 1706 | 1717 |
template<typename DGR, typename AF> |
| 1707 | 1718 |
FilterArcs<const DGR, AF> |
| 1708 | 1719 |
filterArcs(const DGR& digraph, AF& arc_filter) {
|
| 1709 | 1720 |
return FilterArcs<const DGR, AF>(digraph, arc_filter); |
| 1710 | 1721 |
} |
| 1711 | 1722 |
|
| 1712 | 1723 |
template<typename DGR, typename AF> |
| 1713 | 1724 |
FilterArcs<const DGR, const AF> |
| 1714 | 1725 |
filterArcs(const DGR& digraph, const AF& arc_filter) {
|
| 1715 | 1726 |
return FilterArcs<const DGR, const AF>(digraph, arc_filter); |
| 1716 | 1727 |
} |
| 1717 | 1728 |
|
| 1718 | 1729 |
/// \ingroup graph_adaptors |
| 1719 | 1730 |
/// |
| 1720 | 1731 |
/// \brief Adaptor class for hiding edges in a graph. |
| 1721 | 1732 |
/// |
| 1722 | 1733 |
/// FilterEdges adaptor can be used for hiding edges in a graph. |
| 1723 | 1734 |
/// A \c bool edge map must be specified, which defines the filter for |
| 1724 | 1735 |
/// the edges. Only the edges with \c true filter value are shown in the |
| 1725 | 1736 |
/// subgraph. This adaptor conforms to the \ref concepts::Graph |
| 1726 | 1737 |
/// "Graph" concept. |
| 1727 | 1738 |
/// |
| 1728 | 1739 |
/// The adapted graph can also be modified through this adaptor |
| 1729 | 1740 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 1730 | 1741 |
/// parameter is set to be \c const. |
| 1731 | 1742 |
/// |
| 1743 |
/// This class provides only linear time counting for nodes, edges and arcs. |
|
| 1744 |
/// |
|
| 1732 | 1745 |
/// \tparam GR The type of the adapted graph. |
| 1733 | 1746 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 1734 | 1747 |
/// It can also be specified to be \c const. |
| 1735 | 1748 |
/// \tparam EF The type of the edge filter map. |
| 1736 | 1749 |
/// It must be a \c bool (or convertible) edge map of the |
| 1737 | 1750 |
/// adapted graph. The default type is |
| 1738 | 1751 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
| 1739 | 1752 |
/// |
| 1740 | 1753 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the |
| 1741 | 1754 |
/// adapted graph are convertible to each other. |
| 1742 | 1755 |
#ifdef DOXYGEN |
| 1743 | 1756 |
template<typename GR, |
| 1744 | 1757 |
typename EF> |
| 1745 | 1758 |
class FilterEdges {
|
| 1746 | 1759 |
#else |
| 1747 | 1760 |
template<typename GR, |
| 1748 | 1761 |
typename EF = typename GR::template EdgeMap<bool> > |
| 1749 | 1762 |
class FilterEdges : |
| 1750 | 1763 |
public GraphAdaptorExtender< |
| 1751 | 1764 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, |
| 1752 | 1765 |
EF, false> > {
|
| 1753 | 1766 |
#endif |
| 1754 | 1767 |
typedef GraphAdaptorExtender< |
| 1755 | 1768 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, |
| 1756 | 1769 |
EF, false> > Parent; |
| 1757 | 1770 |
|
| 1758 | 1771 |
public: |
| 1759 | 1772 |
|
| 1760 | 1773 |
/// The type of the adapted graph. |
| 1761 | 1774 |
typedef GR Graph; |
| 1762 | 1775 |
/// The type of the edge filter map. |
| 1763 | 1776 |
typedef EF EdgeFilterMap; |
| 1764 | 1777 |
|
| 1765 | 1778 |
typedef typename Parent::Edge Edge; |
| 1766 | 1779 |
|
| 1767 | 1780 |
protected: |
| 1768 | 1781 |
ConstMap<typename GR::Node, Const<bool, true> > const_true_map; |
| 1769 | 1782 |
|
| 1770 | 1783 |
FilterEdges() : const_true_map(true) {
|
| 1771 | 1784 |
Parent::setNodeFilterMap(const_true_map); |
| 1772 | 1785 |
} |
| 1773 | 1786 |
|
| 1774 | 1787 |
public: |
| 1775 | 1788 |
|
| 1776 | 1789 |
/// \brief Constructor |
| 1777 | 1790 |
/// |
| 1778 | 1791 |
/// Creates a subgraph for the given graph with the given edge |
| 1779 | 1792 |
/// filter map. |
| ... | ... |
@@ -2187,96 +2200,99 @@ |
| 2187 | 2200 |
|
| 2188 | 2201 |
private: |
| 2189 | 2202 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 2190 | 2203 |
return operator=<EdgeMap>(cmap); |
| 2191 | 2204 |
} |
| 2192 | 2205 |
|
| 2193 | 2206 |
template <typename CMap> |
| 2194 | 2207 |
EdgeMap& operator=(const CMap& cmap) {
|
| 2195 | 2208 |
Parent::operator=(cmap); |
| 2196 | 2209 |
return *this; |
| 2197 | 2210 |
} |
| 2198 | 2211 |
|
| 2199 | 2212 |
}; |
| 2200 | 2213 |
|
| 2201 | 2214 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier; |
| 2202 | 2215 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
| 2203 | 2216 |
|
| 2204 | 2217 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier; |
| 2205 | 2218 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
|
| 2206 | 2219 |
|
| 2207 | 2220 |
typedef EdgeNotifier ArcNotifier; |
| 2208 | 2221 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
|
| 2209 | 2222 |
|
| 2210 | 2223 |
protected: |
| 2211 | 2224 |
|
| 2212 | 2225 |
UndirectorBase() : _digraph(0) {}
|
| 2213 | 2226 |
|
| 2214 | 2227 |
DGR* _digraph; |
| 2215 | 2228 |
|
| 2216 | 2229 |
void initialize(DGR& digraph) {
|
| 2217 | 2230 |
_digraph = &digraph; |
| 2218 | 2231 |
} |
| 2219 | 2232 |
|
| 2220 | 2233 |
}; |
| 2221 | 2234 |
|
| 2222 | 2235 |
/// \ingroup graph_adaptors |
| 2223 | 2236 |
/// |
| 2224 | 2237 |
/// \brief Adaptor class for viewing a digraph as an undirected graph. |
| 2225 | 2238 |
/// |
| 2226 | 2239 |
/// Undirector adaptor can be used for viewing a digraph as an undirected |
| 2227 | 2240 |
/// graph. All arcs of the underlying digraph are showed in the |
| 2228 | 2241 |
/// adaptor as an edge (and also as a pair of arcs, of course). |
| 2229 | 2242 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept. |
| 2230 | 2243 |
/// |
| 2231 | 2244 |
/// The adapted digraph can also be modified through this adaptor |
| 2232 | 2245 |
/// by adding or removing nodes or edges, unless the \c GR template |
| 2233 | 2246 |
/// parameter is set to be \c const. |
| 2234 | 2247 |
/// |
| 2248 |
/// This class provides item counting in the same time as the adapted |
|
| 2249 |
/// digraph structure. |
|
| 2250 |
/// |
|
| 2235 | 2251 |
/// \tparam DGR The type of the adapted digraph. |
| 2236 | 2252 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2237 | 2253 |
/// It can also be specified to be \c const. |
| 2238 | 2254 |
/// |
| 2239 | 2255 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
| 2240 | 2256 |
/// convertible to each other, moreover the \c Edge type of the adaptor |
| 2241 | 2257 |
/// and the \c Arc type of the adapted digraph are also convertible to |
| 2242 | 2258 |
/// each other. |
| 2243 | 2259 |
/// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type |
| 2244 | 2260 |
/// of the adapted digraph.) |
| 2245 | 2261 |
template<typename DGR> |
| 2246 | 2262 |
#ifdef DOXYGEN |
| 2247 | 2263 |
class Undirector {
|
| 2248 | 2264 |
#else |
| 2249 | 2265 |
class Undirector : |
| 2250 | 2266 |
public GraphAdaptorExtender<UndirectorBase<DGR> > {
|
| 2251 | 2267 |
#endif |
| 2252 | 2268 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent; |
| 2253 | 2269 |
public: |
| 2254 | 2270 |
/// The type of the adapted digraph. |
| 2255 | 2271 |
typedef DGR Digraph; |
| 2256 | 2272 |
protected: |
| 2257 | 2273 |
Undirector() { }
|
| 2258 | 2274 |
public: |
| 2259 | 2275 |
|
| 2260 | 2276 |
/// \brief Constructor |
| 2261 | 2277 |
/// |
| 2262 | 2278 |
/// Creates an undirected graph from the given digraph. |
| 2263 | 2279 |
Undirector(DGR& digraph) {
|
| 2264 | 2280 |
initialize(digraph); |
| 2265 | 2281 |
} |
| 2266 | 2282 |
|
| 2267 | 2283 |
/// \brief Arc map combined from two original arc maps |
| 2268 | 2284 |
/// |
| 2269 | 2285 |
/// This map adaptor class adapts two arc maps of the underlying |
| 2270 | 2286 |
/// digraph to get an arc map of the undirected graph. |
| 2271 | 2287 |
/// Its value type is inherited from the first arc map type (\c FW). |
| 2272 | 2288 |
/// \tparam FW The type of the "foward" arc map. |
| 2273 | 2289 |
/// \tparam BK The type of the "backward" arc map. |
| 2274 | 2290 |
template <typename FW, typename BK> |
| 2275 | 2291 |
class CombinedArcMap {
|
| 2276 | 2292 |
public: |
| 2277 | 2293 |
|
| 2278 | 2294 |
/// The key type of the map |
| 2279 | 2295 |
typedef typename Parent::Arc Key; |
| 2280 | 2296 |
/// The value type of the map |
| 2281 | 2297 |
typedef typename FW::Value Value; |
| 2282 | 2298 |
|
| ... | ... |
@@ -2490,96 +2506,99 @@ |
| 2490 | 2506 |
public: |
| 2491 | 2507 |
|
| 2492 | 2508 |
explicit ArcMap(const OrienterBase<GR, DM>& adapter) |
| 2493 | 2509 |
: Parent(*adapter._graph) { }
|
| 2494 | 2510 |
|
| 2495 | 2511 |
ArcMap(const OrienterBase<GR, DM>& adapter, const V& value) |
| 2496 | 2512 |
: Parent(*adapter._graph, value) { }
|
| 2497 | 2513 |
|
| 2498 | 2514 |
private: |
| 2499 | 2515 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 2500 | 2516 |
return operator=<ArcMap>(cmap); |
| 2501 | 2517 |
} |
| 2502 | 2518 |
|
| 2503 | 2519 |
template <typename CMap> |
| 2504 | 2520 |
ArcMap& operator=(const CMap& cmap) {
|
| 2505 | 2521 |
Parent::operator=(cmap); |
| 2506 | 2522 |
return *this; |
| 2507 | 2523 |
} |
| 2508 | 2524 |
}; |
| 2509 | 2525 |
|
| 2510 | 2526 |
|
| 2511 | 2527 |
|
| 2512 | 2528 |
protected: |
| 2513 | 2529 |
Graph* _graph; |
| 2514 | 2530 |
DM* _direction; |
| 2515 | 2531 |
|
| 2516 | 2532 |
void initialize(GR& graph, DM& direction) {
|
| 2517 | 2533 |
_graph = &graph; |
| 2518 | 2534 |
_direction = &direction; |
| 2519 | 2535 |
} |
| 2520 | 2536 |
|
| 2521 | 2537 |
}; |
| 2522 | 2538 |
|
| 2523 | 2539 |
/// \ingroup graph_adaptors |
| 2524 | 2540 |
/// |
| 2525 | 2541 |
/// \brief Adaptor class for orienting the edges of a graph to get a digraph |
| 2526 | 2542 |
/// |
| 2527 | 2543 |
/// Orienter adaptor can be used for orienting the edges of a graph to |
| 2528 | 2544 |
/// get a digraph. A \c bool edge map of the underlying graph must be |
| 2529 | 2545 |
/// specified, which define the direction of the arcs in the adaptor. |
| 2530 | 2546 |
/// The arcs can be easily reversed by the \c reverseArc() member function |
| 2531 | 2547 |
/// of the adaptor. |
| 2532 | 2548 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
| 2533 | 2549 |
/// |
| 2534 | 2550 |
/// The adapted graph can also be modified through this adaptor |
| 2535 | 2551 |
/// by adding or removing nodes or arcs, unless the \c GR template |
| 2536 | 2552 |
/// parameter is set to be \c const. |
| 2537 | 2553 |
/// |
| 2554 |
/// This class provides item counting in the same time as the adapted |
|
| 2555 |
/// graph structure. |
|
| 2556 |
/// |
|
| 2538 | 2557 |
/// \tparam GR The type of the adapted graph. |
| 2539 | 2558 |
/// It must conform to the \ref concepts::Graph "Graph" concept. |
| 2540 | 2559 |
/// It can also be specified to be \c const. |
| 2541 | 2560 |
/// \tparam DM The type of the direction map. |
| 2542 | 2561 |
/// It must be a \c bool (or convertible) edge map of the |
| 2543 | 2562 |
/// adapted graph. The default type is |
| 2544 | 2563 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>". |
| 2545 | 2564 |
/// |
| 2546 | 2565 |
/// \note The \c Node type of this adaptor and the adapted graph are |
| 2547 | 2566 |
/// convertible to each other, moreover the \c Arc type of the adaptor |
| 2548 | 2567 |
/// and the \c Edge type of the adapted graph are also convertible to |
| 2549 | 2568 |
/// each other. |
| 2550 | 2569 |
#ifdef DOXYGEN |
| 2551 | 2570 |
template<typename GR, |
| 2552 | 2571 |
typename DM> |
| 2553 | 2572 |
class Orienter {
|
| 2554 | 2573 |
#else |
| 2555 | 2574 |
template<typename GR, |
| 2556 | 2575 |
typename DM = typename GR::template EdgeMap<bool> > |
| 2557 | 2576 |
class Orienter : |
| 2558 | 2577 |
public DigraphAdaptorExtender<OrienterBase<GR, DM> > {
|
| 2559 | 2578 |
#endif |
| 2560 | 2579 |
typedef DigraphAdaptorExtender<OrienterBase<GR, DM> > Parent; |
| 2561 | 2580 |
public: |
| 2562 | 2581 |
|
| 2563 | 2582 |
/// The type of the adapted graph. |
| 2564 | 2583 |
typedef GR Graph; |
| 2565 | 2584 |
/// The type of the direction edge map. |
| 2566 | 2585 |
typedef DM DirectionMap; |
| 2567 | 2586 |
|
| 2568 | 2587 |
typedef typename Parent::Arc Arc; |
| 2569 | 2588 |
|
| 2570 | 2589 |
protected: |
| 2571 | 2590 |
Orienter() { }
|
| 2572 | 2591 |
|
| 2573 | 2592 |
public: |
| 2574 | 2593 |
|
| 2575 | 2594 |
/// \brief Constructor |
| 2576 | 2595 |
/// |
| 2577 | 2596 |
/// Constructor of the adaptor. |
| 2578 | 2597 |
Orienter(GR& graph, DM& direction) {
|
| 2579 | 2598 |
Parent::initialize(graph, direction); |
| 2580 | 2599 |
} |
| 2581 | 2600 |
|
| 2582 | 2601 |
/// \brief Reverses the given arc |
| 2583 | 2602 |
/// |
| 2584 | 2603 |
/// This function reverses the given arc. |
| 2585 | 2604 |
/// It is done by simply negate the assigned value of \c a |
| ... | ... |
@@ -2633,96 +2652,98 @@ |
| 2633 | 2652 |
}; |
| 2634 | 2653 |
|
| 2635 | 2654 |
template<typename DGR,typename CM, typename FM, typename TL> |
| 2636 | 2655 |
class ResBackwardFilter {
|
| 2637 | 2656 |
public: |
| 2638 | 2657 |
|
| 2639 | 2658 |
typedef typename DGR::Arc Key; |
| 2640 | 2659 |
typedef bool Value; |
| 2641 | 2660 |
|
| 2642 | 2661 |
private: |
| 2643 | 2662 |
|
| 2644 | 2663 |
const CM* _capacity; |
| 2645 | 2664 |
const FM* _flow; |
| 2646 | 2665 |
TL _tolerance; |
| 2647 | 2666 |
|
| 2648 | 2667 |
public: |
| 2649 | 2668 |
|
| 2650 | 2669 |
ResBackwardFilter(const CM& capacity, const FM& flow, |
| 2651 | 2670 |
const TL& tolerance = TL()) |
| 2652 | 2671 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
| 2653 | 2672 |
|
| 2654 | 2673 |
bool operator[](const typename DGR::Arc& a) const {
|
| 2655 | 2674 |
return _tolerance.positive((*_flow)[a]); |
| 2656 | 2675 |
} |
| 2657 | 2676 |
}; |
| 2658 | 2677 |
|
| 2659 | 2678 |
} |
| 2660 | 2679 |
|
| 2661 | 2680 |
/// \ingroup graph_adaptors |
| 2662 | 2681 |
/// |
| 2663 | 2682 |
/// \brief Adaptor class for composing the residual digraph for directed |
| 2664 | 2683 |
/// flow and circulation problems. |
| 2665 | 2684 |
/// |
| 2666 | 2685 |
/// ResidualDigraph can be used for composing the \e residual digraph |
| 2667 | 2686 |
/// for directed flow and circulation problems. Let \f$ G=(V, A) \f$ |
| 2668 | 2687 |
/// be a directed graph and let \f$ F \f$ be a number type. |
| 2669 | 2688 |
/// Let \f$ flow, cap: A\to F \f$ be functions on the arcs. |
| 2670 | 2689 |
/// This adaptor implements a digraph structure with node set \f$ V \f$ |
| 2671 | 2690 |
/// and arc set \f$ A_{forward}\cup A_{backward} \f$,
|
| 2672 | 2691 |
/// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and
|
| 2673 | 2692 |
/// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so
|
| 2674 | 2693 |
/// called residual digraph. |
| 2675 | 2694 |
/// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken,
|
| 2676 | 2695 |
/// multiplicities are counted, i.e. the adaptor has exactly |
| 2677 | 2696 |
/// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel
|
| 2678 | 2697 |
/// arcs). |
| 2679 | 2698 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
| 2680 | 2699 |
/// |
| 2700 |
/// This class provides only linear time counting for nodes and arcs. |
|
| 2701 |
/// |
|
| 2681 | 2702 |
/// \tparam DGR The type of the adapted digraph. |
| 2682 | 2703 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2683 | 2704 |
/// It is implicitly \c const. |
| 2684 | 2705 |
/// \tparam CM The type of the capacity map. |
| 2685 | 2706 |
/// It must be an arc map of some numerical type, which defines |
| 2686 | 2707 |
/// the capacities in the flow problem. It is implicitly \c const. |
| 2687 | 2708 |
/// The default type is |
| 2688 | 2709 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 2689 | 2710 |
/// \tparam FM The type of the flow map. |
| 2690 | 2711 |
/// It must be an arc map of some numerical type, which defines |
| 2691 | 2712 |
/// the flow values in the flow problem. The default type is \c CM. |
| 2692 | 2713 |
/// \tparam TL The tolerance type for handling inexact computation. |
| 2693 | 2714 |
/// The default tolerance type depends on the value type of the |
| 2694 | 2715 |
/// capacity map. |
| 2695 | 2716 |
/// |
| 2696 | 2717 |
/// \note This adaptor is implemented using Undirector and FilterArcs |
| 2697 | 2718 |
/// adaptors. |
| 2698 | 2719 |
/// |
| 2699 | 2720 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
| 2700 | 2721 |
/// convertible to each other, moreover the \c Arc type of the adaptor |
| 2701 | 2722 |
/// is convertible to the \c Arc type of the adapted digraph. |
| 2702 | 2723 |
#ifdef DOXYGEN |
| 2703 | 2724 |
template<typename DGR, typename CM, typename FM, typename TL> |
| 2704 | 2725 |
class ResidualDigraph |
| 2705 | 2726 |
#else |
| 2706 | 2727 |
template<typename DGR, |
| 2707 | 2728 |
typename CM = typename DGR::template ArcMap<int>, |
| 2708 | 2729 |
typename FM = CM, |
| 2709 | 2730 |
typename TL = Tolerance<typename CM::Value> > |
| 2710 | 2731 |
class ResidualDigraph |
| 2711 | 2732 |
: public SubDigraph< |
| 2712 | 2733 |
Undirector<const DGR>, |
| 2713 | 2734 |
ConstMap<typename DGR::Node, Const<bool, true> >, |
| 2714 | 2735 |
typename Undirector<const DGR>::template CombinedArcMap< |
| 2715 | 2736 |
_adaptor_bits::ResForwardFilter<const DGR, CM, FM, TL>, |
| 2716 | 2737 |
_adaptor_bits::ResBackwardFilter<const DGR, CM, FM, TL> > > |
| 2717 | 2738 |
#endif |
| 2718 | 2739 |
{
|
| 2719 | 2740 |
public: |
| 2720 | 2741 |
|
| 2721 | 2742 |
/// The type of the underlying digraph. |
| 2722 | 2743 |
typedef DGR Digraph; |
| 2723 | 2744 |
/// The type of the capacity map. |
| 2724 | 2745 |
typedef CM CapacityMap; |
| 2725 | 2746 |
/// The type of the flow map. |
| 2726 | 2747 |
typedef FM FlowMap; |
| 2727 | 2748 |
/// The tolerance type. |
| 2728 | 2749 |
typedef TL Tolerance; |
| ... | ... |
@@ -3280,96 +3301,99 @@ |
| 3280 | 3301 |
ArcMap(const SplitNodesBase<DGR>& adaptor, const V& value) |
| 3281 | 3302 |
: Parent(adaptor, value) {}
|
| 3282 | 3303 |
|
| 3283 | 3304 |
private: |
| 3284 | 3305 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 3285 | 3306 |
return operator=<ArcMap>(cmap); |
| 3286 | 3307 |
} |
| 3287 | 3308 |
|
| 3288 | 3309 |
template <typename CMap> |
| 3289 | 3310 |
ArcMap& operator=(const CMap& cmap) {
|
| 3290 | 3311 |
Parent::operator=(cmap); |
| 3291 | 3312 |
return *this; |
| 3292 | 3313 |
} |
| 3293 | 3314 |
}; |
| 3294 | 3315 |
|
| 3295 | 3316 |
protected: |
| 3296 | 3317 |
|
| 3297 | 3318 |
SplitNodesBase() : _digraph(0) {}
|
| 3298 | 3319 |
|
| 3299 | 3320 |
DGR* _digraph; |
| 3300 | 3321 |
|
| 3301 | 3322 |
void initialize(Digraph& digraph) {
|
| 3302 | 3323 |
_digraph = &digraph; |
| 3303 | 3324 |
} |
| 3304 | 3325 |
|
| 3305 | 3326 |
}; |
| 3306 | 3327 |
|
| 3307 | 3328 |
/// \ingroup graph_adaptors |
| 3308 | 3329 |
/// |
| 3309 | 3330 |
/// \brief Adaptor class for splitting the nodes of a digraph. |
| 3310 | 3331 |
/// |
| 3311 | 3332 |
/// SplitNodes adaptor can be used for splitting each node into an |
| 3312 | 3333 |
/// \e in-node and an \e out-node in a digraph. Formaly, the adaptor |
| 3313 | 3334 |
/// replaces each node \f$ u \f$ in the digraph with two nodes, |
| 3314 | 3335 |
/// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$.
|
| 3315 | 3336 |
/// If there is a \f$ (v, u) \f$ arc in the original digraph, then the |
| 3316 | 3337 |
/// new target of the arc will be \f$ u_{in} \f$ and similarly the
|
| 3317 | 3338 |
/// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$.
|
| 3318 | 3339 |
/// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$
|
| 3319 | 3340 |
/// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph.
|
| 3320 | 3341 |
/// |
| 3321 | 3342 |
/// The aim of this class is running an algorithm with respect to node |
| 3322 | 3343 |
/// costs or capacities if the algorithm considers only arc costs or |
| 3323 | 3344 |
/// capacities directly. |
| 3324 | 3345 |
/// In this case you can use \c SplitNodes adaptor, and set the node |
| 3325 | 3346 |
/// costs/capacities of the original digraph to the \e bind \e arcs |
| 3326 | 3347 |
/// in the adaptor. |
| 3327 | 3348 |
/// |
| 3349 |
/// This class provides item counting in the same time as the adapted |
|
| 3350 |
/// digraph structure. |
|
| 3351 |
/// |
|
| 3328 | 3352 |
/// \tparam DGR The type of the adapted digraph. |
| 3329 | 3353 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 3330 | 3354 |
/// It is implicitly \c const. |
| 3331 | 3355 |
/// |
| 3332 | 3356 |
/// \note The \c Node type of this adaptor is converible to the \c Node |
| 3333 | 3357 |
/// type of the adapted digraph. |
| 3334 | 3358 |
template <typename DGR> |
| 3335 | 3359 |
#ifdef DOXYGEN |
| 3336 | 3360 |
class SplitNodes {
|
| 3337 | 3361 |
#else |
| 3338 | 3362 |
class SplitNodes |
| 3339 | 3363 |
: public DigraphAdaptorExtender<SplitNodesBase<const DGR> > {
|
| 3340 | 3364 |
#endif |
| 3341 | 3365 |
typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent; |
| 3342 | 3366 |
|
| 3343 | 3367 |
public: |
| 3344 | 3368 |
typedef DGR Digraph; |
| 3345 | 3369 |
|
| 3346 | 3370 |
typedef typename DGR::Node DigraphNode; |
| 3347 | 3371 |
typedef typename DGR::Arc DigraphArc; |
| 3348 | 3372 |
|
| 3349 | 3373 |
typedef typename Parent::Node Node; |
| 3350 | 3374 |
typedef typename Parent::Arc Arc; |
| 3351 | 3375 |
|
| 3352 | 3376 |
/// \brief Constructor |
| 3353 | 3377 |
/// |
| 3354 | 3378 |
/// Constructor of the adaptor. |
| 3355 | 3379 |
SplitNodes(const DGR& g) {
|
| 3356 | 3380 |
Parent::initialize(g); |
| 3357 | 3381 |
} |
| 3358 | 3382 |
|
| 3359 | 3383 |
/// \brief Returns \c true if the given node is an in-node. |
| 3360 | 3384 |
/// |
| 3361 | 3385 |
/// Returns \c true if the given node is an in-node. |
| 3362 | 3386 |
static bool inNode(const Node& n) {
|
| 3363 | 3387 |
return Parent::inNode(n); |
| 3364 | 3388 |
} |
| 3365 | 3389 |
|
| 3366 | 3390 |
/// \brief Returns \c true if the given node is an out-node. |
| 3367 | 3391 |
/// |
| 3368 | 3392 |
/// Returns \c true if the given node is an out-node. |
| 3369 | 3393 |
static bool outNode(const Node& n) {
|
| 3370 | 3394 |
return Parent::outNode(n); |
| 3371 | 3395 |
} |
| 3372 | 3396 |
|
| 3373 | 3397 |
/// \brief Returns \c true if the given arc is an original arc. |
| 3374 | 3398 |
/// |
| 3375 | 3399 |
/// Returns \c true if the given arc is one of the arcs in the |
| ... | ... |
@@ -656,102 +656,98 @@ |
| 656 | 656 |
return rnode; |
| 657 | 657 |
} |
| 658 | 658 |
|
| 659 | 659 |
///Runs the algorithm from the given source node. |
| 660 | 660 |
|
| 661 | 661 |
///This method runs the %BFS algorithm from node \c s |
| 662 | 662 |
///in order to compute the shortest path to each node. |
| 663 | 663 |
/// |
| 664 | 664 |
///The algorithm computes |
| 665 | 665 |
///- the shortest path tree, |
| 666 | 666 |
///- the distance of each node from the root. |
| 667 | 667 |
/// |
| 668 | 668 |
///\note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 669 | 669 |
///\code |
| 670 | 670 |
/// b.init(); |
| 671 | 671 |
/// b.addSource(s); |
| 672 | 672 |
/// b.start(); |
| 673 | 673 |
///\endcode |
| 674 | 674 |
void run(Node s) {
|
| 675 | 675 |
init(); |
| 676 | 676 |
addSource(s); |
| 677 | 677 |
start(); |
| 678 | 678 |
} |
| 679 | 679 |
|
| 680 | 680 |
///Finds the shortest path between \c s and \c t. |
| 681 | 681 |
|
| 682 | 682 |
///This method runs the %BFS algorithm from node \c s |
| 683 | 683 |
///in order to compute the shortest path to node \c t |
| 684 | 684 |
///(it stops searching when \c t is processed). |
| 685 | 685 |
/// |
| 686 | 686 |
///\return \c true if \c t is reachable form \c s. |
| 687 | 687 |
/// |
| 688 | 688 |
///\note Apart from the return value, <tt>b.run(s,t)</tt> is just a |
| 689 | 689 |
///shortcut of the following code. |
| 690 | 690 |
///\code |
| 691 | 691 |
/// b.init(); |
| 692 | 692 |
/// b.addSource(s); |
| 693 | 693 |
/// b.start(t); |
| 694 | 694 |
///\endcode |
| 695 | 695 |
bool run(Node s,Node t) {
|
| 696 | 696 |
init(); |
| 697 | 697 |
addSource(s); |
| 698 | 698 |
start(t); |
| 699 | 699 |
return reached(t); |
| 700 | 700 |
} |
| 701 | 701 |
|
| 702 | 702 |
///Runs the algorithm to visit all nodes in the digraph. |
| 703 | 703 |
|
| 704 |
///This method runs the %BFS algorithm in order to |
|
| 705 |
///compute the shortest path to each node. |
|
| 706 |
/// |
|
| 707 |
///The algorithm computes |
|
| 708 |
///- the shortest path tree (forest), |
|
| 709 |
///- the distance of each node from the root(s). |
|
| 704 |
///This method runs the %BFS algorithm in order to visit all nodes |
|
| 705 |
///in the digraph. |
|
| 710 | 706 |
/// |
| 711 | 707 |
///\note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 712 | 708 |
///\code |
| 713 | 709 |
/// b.init(); |
| 714 | 710 |
/// for (NodeIt n(gr); n != INVALID; ++n) {
|
| 715 | 711 |
/// if (!b.reached(n)) {
|
| 716 | 712 |
/// b.addSource(n); |
| 717 | 713 |
/// b.start(); |
| 718 | 714 |
/// } |
| 719 | 715 |
/// } |
| 720 | 716 |
///\endcode |
| 721 | 717 |
void run() {
|
| 722 | 718 |
init(); |
| 723 | 719 |
for (NodeIt n(*G); n != INVALID; ++n) {
|
| 724 | 720 |
if (!reached(n)) {
|
| 725 | 721 |
addSource(n); |
| 726 | 722 |
start(); |
| 727 | 723 |
} |
| 728 | 724 |
} |
| 729 | 725 |
} |
| 730 | 726 |
|
| 731 | 727 |
///@} |
| 732 | 728 |
|
| 733 | 729 |
///\name Query Functions |
| 734 | 730 |
///The results of the BFS algorithm can be obtained using these |
| 735 | 731 |
///functions.\n |
| 736 | 732 |
///Either \ref run(Node) "run()" or \ref start() should be called |
| 737 | 733 |
///before using them. |
| 738 | 734 |
|
| 739 | 735 |
///@{
|
| 740 | 736 |
|
| 741 | 737 |
///The shortest path to the given node. |
| 742 | 738 |
|
| 743 | 739 |
///Returns the shortest path to the given node from the root(s). |
| 744 | 740 |
/// |
| 745 | 741 |
///\warning \c t should be reached from the root(s). |
| 746 | 742 |
/// |
| 747 | 743 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 748 | 744 |
///must be called before using this function. |
| 749 | 745 |
Path path(Node t) const { return Path(*G, *_pred, t); }
|
| 750 | 746 |
|
| 751 | 747 |
///The distance of the given node from the root(s). |
| 752 | 748 |
|
| 753 | 749 |
///Returns the distance of the given node from the root(s). |
| 754 | 750 |
/// |
| 755 | 751 |
///\warning If node \c v is not reached from the root(s), then |
| 756 | 752 |
///the return value of this function is undefined. |
| 757 | 753 |
/// |
| ... | ... |
@@ -1001,98 +997,98 @@ |
| 1001 | 997 |
|
| 1002 | 998 |
///This method runs BFS algorithm from node \c s |
| 1003 | 999 |
///in order to compute the shortest path to each node. |
| 1004 | 1000 |
void run(Node s) |
| 1005 | 1001 |
{
|
| 1006 | 1002 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
| 1007 | 1003 |
if (Base::_pred) |
| 1008 | 1004 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
| 1009 | 1005 |
if (Base::_dist) |
| 1010 | 1006 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
| 1011 | 1007 |
if (Base::_reached) |
| 1012 | 1008 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
| 1013 | 1009 |
if (Base::_processed) |
| 1014 | 1010 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
| 1015 | 1011 |
if (s!=INVALID) |
| 1016 | 1012 |
alg.run(s); |
| 1017 | 1013 |
else |
| 1018 | 1014 |
alg.run(); |
| 1019 | 1015 |
} |
| 1020 | 1016 |
|
| 1021 | 1017 |
///Finds the shortest path between \c s and \c t. |
| 1022 | 1018 |
|
| 1023 | 1019 |
///This method runs BFS algorithm from node \c s |
| 1024 | 1020 |
///in order to compute the shortest path to node \c t |
| 1025 | 1021 |
///(it stops searching when \c t is processed). |
| 1026 | 1022 |
/// |
| 1027 | 1023 |
///\return \c true if \c t is reachable form \c s. |
| 1028 | 1024 |
bool run(Node s, Node t) |
| 1029 | 1025 |
{
|
| 1030 | 1026 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
| 1031 | 1027 |
if (Base::_pred) |
| 1032 | 1028 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
| 1033 | 1029 |
if (Base::_dist) |
| 1034 | 1030 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
| 1035 | 1031 |
if (Base::_reached) |
| 1036 | 1032 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
| 1037 | 1033 |
if (Base::_processed) |
| 1038 | 1034 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
| 1039 | 1035 |
alg.run(s,t); |
| 1040 | 1036 |
if (Base::_path) |
| 1041 | 1037 |
*reinterpret_cast<Path*>(Base::_path) = alg.path(t); |
| 1042 | 1038 |
if (Base::_di) |
| 1043 | 1039 |
*Base::_di = alg.dist(t); |
| 1044 | 1040 |
return alg.reached(t); |
| 1045 | 1041 |
} |
| 1046 | 1042 |
|
| 1047 | 1043 |
///Runs BFS algorithm to visit all nodes in the digraph. |
| 1048 | 1044 |
|
| 1049 |
///This method runs BFS algorithm in order to compute |
|
| 1050 |
///the shortest path to each node. |
|
| 1045 |
///This method runs BFS algorithm in order to visit all nodes |
|
| 1046 |
///in the digraph. |
|
| 1051 | 1047 |
void run() |
| 1052 | 1048 |
{
|
| 1053 | 1049 |
run(INVALID); |
| 1054 | 1050 |
} |
| 1055 | 1051 |
|
| 1056 | 1052 |
template<class T> |
| 1057 | 1053 |
struct SetPredMapBase : public Base {
|
| 1058 | 1054 |
typedef T PredMap; |
| 1059 | 1055 |
static PredMap *createPredMap(const Digraph &) { return 0; };
|
| 1060 | 1056 |
SetPredMapBase(const TR &b) : TR(b) {}
|
| 1061 | 1057 |
}; |
| 1062 | 1058 |
|
| 1063 | 1059 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 1064 | 1060 |
///the predecessor map. |
| 1065 | 1061 |
/// |
| 1066 | 1062 |
///\ref named-templ-param "Named parameter" function for setting |
| 1067 | 1063 |
///the map that stores the predecessor arcs of the nodes. |
| 1068 | 1064 |
template<class T> |
| 1069 | 1065 |
BfsWizard<SetPredMapBase<T> > predMap(const T &t) |
| 1070 | 1066 |
{
|
| 1071 | 1067 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
| 1072 | 1068 |
return BfsWizard<SetPredMapBase<T> >(*this); |
| 1073 | 1069 |
} |
| 1074 | 1070 |
|
| 1075 | 1071 |
template<class T> |
| 1076 | 1072 |
struct SetReachedMapBase : public Base {
|
| 1077 | 1073 |
typedef T ReachedMap; |
| 1078 | 1074 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; };
|
| 1079 | 1075 |
SetReachedMapBase(const TR &b) : TR(b) {}
|
| 1080 | 1076 |
}; |
| 1081 | 1077 |
|
| 1082 | 1078 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 1083 | 1079 |
///the reached map. |
| 1084 | 1080 |
/// |
| 1085 | 1081 |
///\ref named-templ-param "Named parameter" function for setting |
| 1086 | 1082 |
///the map that indicates which nodes are reached. |
| 1087 | 1083 |
template<class T> |
| 1088 | 1084 |
BfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) |
| 1089 | 1085 |
{
|
| 1090 | 1086 |
Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t)); |
| 1091 | 1087 |
return BfsWizard<SetReachedMapBase<T> >(*this); |
| 1092 | 1088 |
} |
| 1093 | 1089 |
|
| 1094 | 1090 |
template<class T> |
| 1095 | 1091 |
struct SetDistMapBase : public Base {
|
| 1096 | 1092 |
typedef T DistMap; |
| 1097 | 1093 |
static DistMap *createDistMap(const Digraph &) { return 0; };
|
| 1098 | 1094 |
SetDistMapBase(const TR &b) : TR(b) {}
|
| ... | ... |
@@ -1650,100 +1646,96 @@ |
| 1650 | 1646 |
return rnode; |
| 1651 | 1647 |
} |
| 1652 | 1648 |
|
| 1653 | 1649 |
/// \brief Runs the algorithm from the given source node. |
| 1654 | 1650 |
/// |
| 1655 | 1651 |
/// This method runs the %BFS algorithm from node \c s |
| 1656 | 1652 |
/// in order to compute the shortest path to each node. |
| 1657 | 1653 |
/// |
| 1658 | 1654 |
/// The algorithm computes |
| 1659 | 1655 |
/// - the shortest path tree, |
| 1660 | 1656 |
/// - the distance of each node from the root. |
| 1661 | 1657 |
/// |
| 1662 | 1658 |
/// \note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 1663 | 1659 |
///\code |
| 1664 | 1660 |
/// b.init(); |
| 1665 | 1661 |
/// b.addSource(s); |
| 1666 | 1662 |
/// b.start(); |
| 1667 | 1663 |
///\endcode |
| 1668 | 1664 |
void run(Node s) {
|
| 1669 | 1665 |
init(); |
| 1670 | 1666 |
addSource(s); |
| 1671 | 1667 |
start(); |
| 1672 | 1668 |
} |
| 1673 | 1669 |
|
| 1674 | 1670 |
/// \brief Finds the shortest path between \c s and \c t. |
| 1675 | 1671 |
/// |
| 1676 | 1672 |
/// This method runs the %BFS algorithm from node \c s |
| 1677 | 1673 |
/// in order to compute the shortest path to node \c t |
| 1678 | 1674 |
/// (it stops searching when \c t is processed). |
| 1679 | 1675 |
/// |
| 1680 | 1676 |
/// \return \c true if \c t is reachable form \c s. |
| 1681 | 1677 |
/// |
| 1682 | 1678 |
/// \note Apart from the return value, <tt>b.run(s,t)</tt> is just a |
| 1683 | 1679 |
/// shortcut of the following code. |
| 1684 | 1680 |
///\code |
| 1685 | 1681 |
/// b.init(); |
| 1686 | 1682 |
/// b.addSource(s); |
| 1687 | 1683 |
/// b.start(t); |
| 1688 | 1684 |
///\endcode |
| 1689 | 1685 |
bool run(Node s,Node t) {
|
| 1690 | 1686 |
init(); |
| 1691 | 1687 |
addSource(s); |
| 1692 | 1688 |
start(t); |
| 1693 | 1689 |
return reached(t); |
| 1694 | 1690 |
} |
| 1695 | 1691 |
|
| 1696 | 1692 |
/// \brief Runs the algorithm to visit all nodes in the digraph. |
| 1697 | 1693 |
/// |
| 1698 |
/// This method runs the %BFS algorithm in order to |
|
| 1699 |
/// compute the shortest path to each node. |
|
| 1700 |
/// |
|
| 1701 |
/// The algorithm computes |
|
| 1702 |
/// - the shortest path tree (forest), |
|
| 1703 |
/// - the distance of each node from the root(s). |
|
| 1694 |
/// This method runs the %BFS algorithm in order to visit all nodes |
|
| 1695 |
/// in the digraph. |
|
| 1704 | 1696 |
/// |
| 1705 | 1697 |
/// \note <tt>b.run(s)</tt> is just a shortcut of the following code. |
| 1706 | 1698 |
///\code |
| 1707 | 1699 |
/// b.init(); |
| 1708 | 1700 |
/// for (NodeIt n(gr); n != INVALID; ++n) {
|
| 1709 | 1701 |
/// if (!b.reached(n)) {
|
| 1710 | 1702 |
/// b.addSource(n); |
| 1711 | 1703 |
/// b.start(); |
| 1712 | 1704 |
/// } |
| 1713 | 1705 |
/// } |
| 1714 | 1706 |
///\endcode |
| 1715 | 1707 |
void run() {
|
| 1716 | 1708 |
init(); |
| 1717 | 1709 |
for (NodeIt it(*_digraph); it != INVALID; ++it) {
|
| 1718 | 1710 |
if (!reached(it)) {
|
| 1719 | 1711 |
addSource(it); |
| 1720 | 1712 |
start(); |
| 1721 | 1713 |
} |
| 1722 | 1714 |
} |
| 1723 | 1715 |
} |
| 1724 | 1716 |
|
| 1725 | 1717 |
///@} |
| 1726 | 1718 |
|
| 1727 | 1719 |
/// \name Query Functions |
| 1728 | 1720 |
/// The results of the BFS algorithm can be obtained using these |
| 1729 | 1721 |
/// functions.\n |
| 1730 | 1722 |
/// Either \ref run(Node) "run()" or \ref start() should be called |
| 1731 | 1723 |
/// before using them. |
| 1732 | 1724 |
|
| 1733 | 1725 |
///@{
|
| 1734 | 1726 |
|
| 1735 | 1727 |
/// \brief Checks if the given node is reached from the root(s). |
| 1736 | 1728 |
/// |
| 1737 | 1729 |
/// Returns \c true if \c v is reached from the root(s). |
| 1738 | 1730 |
/// |
| 1739 | 1731 |
/// \pre Either \ref run(Node) "run()" or \ref init() |
| 1740 | 1732 |
/// must be called before using this function. |
| 1741 | 1733 |
bool reached(Node v) const { return (*_reached)[v]; }
|
| 1742 | 1734 |
|
| 1743 | 1735 |
///@} |
| 1744 | 1736 |
|
| 1745 | 1737 |
}; |
| 1746 | 1738 |
|
| 1747 | 1739 |
} //END OF NAMESPACE LEMON |
| 1748 | 1740 |
|
| 1749 | 1741 |
#endif |
| ... | ... |
@@ -588,102 +588,98 @@ |
| 588 | 588 |
return emptyQueue() ? INVALID : _stack[_stack_head]; |
| 589 | 589 |
} |
| 590 | 590 |
|
| 591 | 591 |
///Runs the algorithm from the given source node. |
| 592 | 592 |
|
| 593 | 593 |
///This method runs the %DFS algorithm from node \c s |
| 594 | 594 |
///in order to compute the DFS path to each node. |
| 595 | 595 |
/// |
| 596 | 596 |
///The algorithm computes |
| 597 | 597 |
///- the %DFS tree, |
| 598 | 598 |
///- the distance of each node from the root in the %DFS tree. |
| 599 | 599 |
/// |
| 600 | 600 |
///\note <tt>d.run(s)</tt> is just a shortcut of the following code. |
| 601 | 601 |
///\code |
| 602 | 602 |
/// d.init(); |
| 603 | 603 |
/// d.addSource(s); |
| 604 | 604 |
/// d.start(); |
| 605 | 605 |
///\endcode |
| 606 | 606 |
void run(Node s) {
|
| 607 | 607 |
init(); |
| 608 | 608 |
addSource(s); |
| 609 | 609 |
start(); |
| 610 | 610 |
} |
| 611 | 611 |
|
| 612 | 612 |
///Finds the %DFS path between \c s and \c t. |
| 613 | 613 |
|
| 614 | 614 |
///This method runs the %DFS algorithm from node \c s |
| 615 | 615 |
///in order to compute the DFS path to node \c t |
| 616 | 616 |
///(it stops searching when \c t is processed) |
| 617 | 617 |
/// |
| 618 | 618 |
///\return \c true if \c t is reachable form \c s. |
| 619 | 619 |
/// |
| 620 | 620 |
///\note Apart from the return value, <tt>d.run(s,t)</tt> is |
| 621 | 621 |
///just a shortcut of the following code. |
| 622 | 622 |
///\code |
| 623 | 623 |
/// d.init(); |
| 624 | 624 |
/// d.addSource(s); |
| 625 | 625 |
/// d.start(t); |
| 626 | 626 |
///\endcode |
| 627 | 627 |
bool run(Node s,Node t) {
|
| 628 | 628 |
init(); |
| 629 | 629 |
addSource(s); |
| 630 | 630 |
start(t); |
| 631 | 631 |
return reached(t); |
| 632 | 632 |
} |
| 633 | 633 |
|
| 634 | 634 |
///Runs the algorithm to visit all nodes in the digraph. |
| 635 | 635 |
|
| 636 |
///This method runs the %DFS algorithm in order to compute the |
|
| 637 |
///%DFS path to each node. |
|
| 638 |
/// |
|
| 639 |
///The algorithm computes |
|
| 640 |
///- the %DFS tree (forest), |
|
| 641 |
///- the distance of each node from the root(s) in the %DFS tree. |
|
| 636 |
///This method runs the %DFS algorithm in order to visit all nodes |
|
| 637 |
///in the digraph. |
|
| 642 | 638 |
/// |
| 643 | 639 |
///\note <tt>d.run()</tt> is just a shortcut of the following code. |
| 644 | 640 |
///\code |
| 645 | 641 |
/// d.init(); |
| 646 | 642 |
/// for (NodeIt n(digraph); n != INVALID; ++n) {
|
| 647 | 643 |
/// if (!d.reached(n)) {
|
| 648 | 644 |
/// d.addSource(n); |
| 649 | 645 |
/// d.start(); |
| 650 | 646 |
/// } |
| 651 | 647 |
/// } |
| 652 | 648 |
///\endcode |
| 653 | 649 |
void run() {
|
| 654 | 650 |
init(); |
| 655 | 651 |
for (NodeIt it(*G); it != INVALID; ++it) {
|
| 656 | 652 |
if (!reached(it)) {
|
| 657 | 653 |
addSource(it); |
| 658 | 654 |
start(); |
| 659 | 655 |
} |
| 660 | 656 |
} |
| 661 | 657 |
} |
| 662 | 658 |
|
| 663 | 659 |
///@} |
| 664 | 660 |
|
| 665 | 661 |
///\name Query Functions |
| 666 | 662 |
///The results of the DFS algorithm can be obtained using these |
| 667 | 663 |
///functions.\n |
| 668 | 664 |
///Either \ref run(Node) "run()" or \ref start() should be called |
| 669 | 665 |
///before using them. |
| 670 | 666 |
|
| 671 | 667 |
///@{
|
| 672 | 668 |
|
| 673 | 669 |
///The DFS path to the given node. |
| 674 | 670 |
|
| 675 | 671 |
///Returns the DFS path to the given node from the root(s). |
| 676 | 672 |
/// |
| 677 | 673 |
///\warning \c t should be reached from the root(s). |
| 678 | 674 |
/// |
| 679 | 675 |
///\pre Either \ref run(Node) "run()" or \ref init() |
| 680 | 676 |
///must be called before using this function. |
| 681 | 677 |
Path path(Node t) const { return Path(*G, *_pred, t); }
|
| 682 | 678 |
|
| 683 | 679 |
///The distance of the given node from the root(s). |
| 684 | 680 |
|
| 685 | 681 |
///Returns the distance of the given node from the root(s). |
| 686 | 682 |
/// |
| 687 | 683 |
///\warning If node \c v is not reached from the root(s), then |
| 688 | 684 |
///the return value of this function is undefined. |
| 689 | 685 |
/// |
| ... | ... |
@@ -931,98 +927,98 @@ |
| 931 | 927 |
|
| 932 | 928 |
///This method runs DFS algorithm from node \c s |
| 933 | 929 |
///in order to compute the DFS path to each node. |
| 934 | 930 |
void run(Node s) |
| 935 | 931 |
{
|
| 936 | 932 |
Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
| 937 | 933 |
if (Base::_pred) |
| 938 | 934 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
| 939 | 935 |
if (Base::_dist) |
| 940 | 936 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
| 941 | 937 |
if (Base::_reached) |
| 942 | 938 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
| 943 | 939 |
if (Base::_processed) |
| 944 | 940 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
| 945 | 941 |
if (s!=INVALID) |
| 946 | 942 |
alg.run(s); |
| 947 | 943 |
else |
| 948 | 944 |
alg.run(); |
| 949 | 945 |
} |
| 950 | 946 |
|
| 951 | 947 |
///Finds the DFS path between \c s and \c t. |
| 952 | 948 |
|
| 953 | 949 |
///This method runs DFS algorithm from node \c s |
| 954 | 950 |
///in order to compute the DFS path to node \c t |
| 955 | 951 |
///(it stops searching when \c t is processed). |
| 956 | 952 |
/// |
| 957 | 953 |
///\return \c true if \c t is reachable form \c s. |
| 958 | 954 |
bool run(Node s, Node t) |
| 959 | 955 |
{
|
| 960 | 956 |
Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
| 961 | 957 |
if (Base::_pred) |
| 962 | 958 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
| 963 | 959 |
if (Base::_dist) |
| 964 | 960 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
| 965 | 961 |
if (Base::_reached) |
| 966 | 962 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
| 967 | 963 |
if (Base::_processed) |
| 968 | 964 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
| 969 | 965 |
alg.run(s,t); |
| 970 | 966 |
if (Base::_path) |
| 971 | 967 |
*reinterpret_cast<Path*>(Base::_path) = alg.path(t); |
| 972 | 968 |
if (Base::_di) |
| 973 | 969 |
*Base::_di = alg.dist(t); |
| 974 | 970 |
return alg.reached(t); |
| 975 | 971 |
} |
| 976 | 972 |
|
| 977 | 973 |
///Runs DFS algorithm to visit all nodes in the digraph. |
| 978 | 974 |
|
| 979 |
///This method runs DFS algorithm in order to compute |
|
| 980 |
///the DFS path to each node. |
|
| 975 |
///This method runs DFS algorithm in order to visit all nodes |
|
| 976 |
///in the digraph. |
|
| 981 | 977 |
void run() |
| 982 | 978 |
{
|
| 983 | 979 |
run(INVALID); |
| 984 | 980 |
} |
| 985 | 981 |
|
| 986 | 982 |
template<class T> |
| 987 | 983 |
struct SetPredMapBase : public Base {
|
| 988 | 984 |
typedef T PredMap; |
| 989 | 985 |
static PredMap *createPredMap(const Digraph &) { return 0; };
|
| 990 | 986 |
SetPredMapBase(const TR &b) : TR(b) {}
|
| 991 | 987 |
}; |
| 992 | 988 |
|
| 993 | 989 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 994 | 990 |
///the predecessor map. |
| 995 | 991 |
/// |
| 996 | 992 |
///\ref named-templ-param "Named parameter" function for setting |
| 997 | 993 |
///the map that stores the predecessor arcs of the nodes. |
| 998 | 994 |
template<class T> |
| 999 | 995 |
DfsWizard<SetPredMapBase<T> > predMap(const T &t) |
| 1000 | 996 |
{
|
| 1001 | 997 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
| 1002 | 998 |
return DfsWizard<SetPredMapBase<T> >(*this); |
| 1003 | 999 |
} |
| 1004 | 1000 |
|
| 1005 | 1001 |
template<class T> |
| 1006 | 1002 |
struct SetReachedMapBase : public Base {
|
| 1007 | 1003 |
typedef T ReachedMap; |
| 1008 | 1004 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; };
|
| 1009 | 1005 |
SetReachedMapBase(const TR &b) : TR(b) {}
|
| 1010 | 1006 |
}; |
| 1011 | 1007 |
|
| 1012 | 1008 |
///\brief \ref named-templ-param "Named parameter" for setting |
| 1013 | 1009 |
///the reached map. |
| 1014 | 1010 |
/// |
| 1015 | 1011 |
///\ref named-templ-param "Named parameter" function for setting |
| 1016 | 1012 |
///the map that indicates which nodes are reached. |
| 1017 | 1013 |
template<class T> |
| 1018 | 1014 |
DfsWizard<SetReachedMapBase<T> > reachedMap(const T &t) |
| 1019 | 1015 |
{
|
| 1020 | 1016 |
Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t)); |
| 1021 | 1017 |
return DfsWizard<SetReachedMapBase<T> >(*this); |
| 1022 | 1018 |
} |
| 1023 | 1019 |
|
| 1024 | 1020 |
template<class T> |
| 1025 | 1021 |
struct SetDistMapBase : public Base {
|
| 1026 | 1022 |
typedef T DistMap; |
| 1027 | 1023 |
static DistMap *createDistMap(const Digraph &) { return 0; };
|
| 1028 | 1024 |
SetDistMapBase(const TR &b) : TR(b) {}
|
| ... | ... |
@@ -1533,100 +1529,96 @@ |
| 1533 | 1529 |
return emptyQueue() ? INVALID : _stack[_stack_head]; |
| 1534 | 1530 |
} |
| 1535 | 1531 |
|
| 1536 | 1532 |
/// \brief Runs the algorithm from the given source node. |
| 1537 | 1533 |
/// |
| 1538 | 1534 |
/// This method runs the %DFS algorithm from node \c s. |
| 1539 | 1535 |
/// in order to compute the DFS path to each node. |
| 1540 | 1536 |
/// |
| 1541 | 1537 |
/// The algorithm computes |
| 1542 | 1538 |
/// - the %DFS tree, |
| 1543 | 1539 |
/// - the distance of each node from the root in the %DFS tree. |
| 1544 | 1540 |
/// |
| 1545 | 1541 |
/// \note <tt>d.run(s)</tt> is just a shortcut of the following code. |
| 1546 | 1542 |
///\code |
| 1547 | 1543 |
/// d.init(); |
| 1548 | 1544 |
/// d.addSource(s); |
| 1549 | 1545 |
/// d.start(); |
| 1550 | 1546 |
///\endcode |
| 1551 | 1547 |
void run(Node s) {
|
| 1552 | 1548 |
init(); |
| 1553 | 1549 |
addSource(s); |
| 1554 | 1550 |
start(); |
| 1555 | 1551 |
} |
| 1556 | 1552 |
|
| 1557 | 1553 |
/// \brief Finds the %DFS path between \c s and \c t. |
| 1558 | 1554 |
|
| 1559 | 1555 |
/// This method runs the %DFS algorithm from node \c s |
| 1560 | 1556 |
/// in order to compute the DFS path to node \c t |
| 1561 | 1557 |
/// (it stops searching when \c t is processed). |
| 1562 | 1558 |
/// |
| 1563 | 1559 |
/// \return \c true if \c t is reachable form \c s. |
| 1564 | 1560 |
/// |
| 1565 | 1561 |
/// \note Apart from the return value, <tt>d.run(s,t)</tt> is |
| 1566 | 1562 |
/// just a shortcut of the following code. |
| 1567 | 1563 |
///\code |
| 1568 | 1564 |
/// d.init(); |
| 1569 | 1565 |
/// d.addSource(s); |
| 1570 | 1566 |
/// d.start(t); |
| 1571 | 1567 |
///\endcode |
| 1572 | 1568 |
bool run(Node s,Node t) {
|
| 1573 | 1569 |
init(); |
| 1574 | 1570 |
addSource(s); |
| 1575 | 1571 |
start(t); |
| 1576 | 1572 |
return reached(t); |
| 1577 | 1573 |
} |
| 1578 | 1574 |
|
| 1579 | 1575 |
/// \brief Runs the algorithm to visit all nodes in the digraph. |
| 1580 | 1576 |
|
| 1581 |
/// This method runs the %DFS algorithm in order to |
|
| 1582 |
/// compute the %DFS path to each node. |
|
| 1583 |
/// |
|
| 1584 |
/// The algorithm computes |
|
| 1585 |
/// - the %DFS tree (forest), |
|
| 1586 |
/// - the distance of each node from the root(s) in the %DFS tree. |
|
| 1577 |
/// This method runs the %DFS algorithm in order to visit all nodes |
|
| 1578 |
/// in the digraph. |
|
| 1587 | 1579 |
/// |
| 1588 | 1580 |
/// \note <tt>d.run()</tt> is just a shortcut of the following code. |
| 1589 | 1581 |
///\code |
| 1590 | 1582 |
/// d.init(); |
| 1591 | 1583 |
/// for (NodeIt n(digraph); n != INVALID; ++n) {
|
| 1592 | 1584 |
/// if (!d.reached(n)) {
|
| 1593 | 1585 |
/// d.addSource(n); |
| 1594 | 1586 |
/// d.start(); |
| 1595 | 1587 |
/// } |
| 1596 | 1588 |
/// } |
| 1597 | 1589 |
///\endcode |
| 1598 | 1590 |
void run() {
|
| 1599 | 1591 |
init(); |
| 1600 | 1592 |
for (NodeIt it(*_digraph); it != INVALID; ++it) {
|
| 1601 | 1593 |
if (!reached(it)) {
|
| 1602 | 1594 |
addSource(it); |
| 1603 | 1595 |
start(); |
| 1604 | 1596 |
} |
| 1605 | 1597 |
} |
| 1606 | 1598 |
} |
| 1607 | 1599 |
|
| 1608 | 1600 |
///@} |
| 1609 | 1601 |
|
| 1610 | 1602 |
/// \name Query Functions |
| 1611 | 1603 |
/// The results of the DFS algorithm can be obtained using these |
| 1612 | 1604 |
/// functions.\n |
| 1613 | 1605 |
/// Either \ref run(Node) "run()" or \ref start() should be called |
| 1614 | 1606 |
/// before using them. |
| 1615 | 1607 |
|
| 1616 | 1608 |
///@{
|
| 1617 | 1609 |
|
| 1618 | 1610 |
/// \brief Checks if the given node is reached from the root(s). |
| 1619 | 1611 |
/// |
| 1620 | 1612 |
/// Returns \c true if \c v is reached from the root(s). |
| 1621 | 1613 |
/// |
| 1622 | 1614 |
/// \pre Either \ref run(Node) "run()" or \ref init() |
| 1623 | 1615 |
/// must be called before using this function. |
| 1624 | 1616 |
bool reached(Node v) const { return (*_reached)[v]; }
|
| 1625 | 1617 |
|
| 1626 | 1618 |
///@} |
| 1627 | 1619 |
|
| 1628 | 1620 |
}; |
| 1629 | 1621 |
|
| 1630 | 1622 |
} //END OF NAMESPACE LEMON |
| 1631 | 1623 |
|
| 1632 | 1624 |
#endif |
| ... | ... |
@@ -161,97 +161,97 @@ |
| 161 | 161 |
static DistMap *createDistMap(const Digraph &g) |
| 162 | 162 |
{
|
| 163 | 163 |
return new DistMap(g); |
| 164 | 164 |
} |
| 165 | 165 |
}; |
| 166 | 166 |
|
| 167 | 167 |
///%Dijkstra algorithm class. |
| 168 | 168 |
|
| 169 | 169 |
/// \ingroup shortest_path |
| 170 | 170 |
///This class provides an efficient implementation of the %Dijkstra algorithm. |
| 171 | 171 |
/// |
| 172 | 172 |
///The %Dijkstra algorithm solves the single-source shortest path problem |
| 173 | 173 |
///when all arc lengths are non-negative. If there are negative lengths, |
| 174 | 174 |
///the BellmanFord algorithm should be used instead. |
| 175 | 175 |
/// |
| 176 | 176 |
///The arc lengths are passed to the algorithm using a |
| 177 | 177 |
///\ref concepts::ReadMap "ReadMap", |
| 178 | 178 |
///so it is easy to change it to any kind of length. |
| 179 | 179 |
///The type of the length is determined by the |
| 180 | 180 |
///\ref concepts::ReadMap::Value "Value" of the length map. |
| 181 | 181 |
///It is also possible to change the underlying priority heap. |
| 182 | 182 |
/// |
| 183 | 183 |
///There is also a \ref dijkstra() "function-type interface" for the |
| 184 | 184 |
///%Dijkstra algorithm, which is convenient in the simplier cases and |
| 185 | 185 |
///it can be used easier. |
| 186 | 186 |
/// |
| 187 | 187 |
///\tparam GR The type of the digraph the algorithm runs on. |
| 188 | 188 |
///The default type is \ref ListDigraph. |
| 189 | 189 |
///\tparam LEN A \ref concepts::ReadMap "readable" arc map that specifies |
| 190 | 190 |
///the lengths of the arcs. |
| 191 | 191 |
///It is read once for each arc, so the map may involve in |
| 192 | 192 |
///relatively time consuming process to compute the arc lengths if |
| 193 | 193 |
///it is necessary. The default map type is \ref |
| 194 | 194 |
///concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 195 | 195 |
#ifdef DOXYGEN |
| 196 | 196 |
template <typename GR, typename LEN, typename TR> |
| 197 | 197 |
#else |
| 198 | 198 |
template <typename GR=ListDigraph, |
| 199 | 199 |
typename LEN=typename GR::template ArcMap<int>, |
| 200 | 200 |
typename TR=DijkstraDefaultTraits<GR,LEN> > |
| 201 | 201 |
#endif |
| 202 | 202 |
class Dijkstra {
|
| 203 | 203 |
public: |
| 204 | 204 |
|
| 205 | 205 |
///The type of the digraph the algorithm runs on. |
| 206 | 206 |
typedef typename TR::Digraph Digraph; |
| 207 | 207 |
|
| 208 | 208 |
///The type of the arc lengths. |
| 209 |
typedef typename TR:: |
|
| 209 |
typedef typename TR::Value Value; |
|
| 210 | 210 |
///The type of the map that stores the arc lengths. |
| 211 | 211 |
typedef typename TR::LengthMap LengthMap; |
| 212 | 212 |
///\brief The type of the map that stores the predecessor arcs of the |
| 213 | 213 |
///shortest paths. |
| 214 | 214 |
typedef typename TR::PredMap PredMap; |
| 215 | 215 |
///The type of the map that stores the distances of the nodes. |
| 216 | 216 |
typedef typename TR::DistMap DistMap; |
| 217 | 217 |
///The type of the map that indicates which nodes are processed. |
| 218 | 218 |
typedef typename TR::ProcessedMap ProcessedMap; |
| 219 | 219 |
///The type of the paths. |
| 220 | 220 |
typedef PredMapPath<Digraph, PredMap> Path; |
| 221 | 221 |
///The cross reference type used for the current heap. |
| 222 | 222 |
typedef typename TR::HeapCrossRef HeapCrossRef; |
| 223 | 223 |
///The heap type used by the algorithm. |
| 224 | 224 |
typedef typename TR::Heap Heap; |
| 225 | 225 |
///\brief The \ref DijkstraDefaultOperationTraits "operation traits class" |
| 226 | 226 |
///of the algorithm. |
| 227 | 227 |
typedef typename TR::OperationTraits OperationTraits; |
| 228 | 228 |
|
| 229 | 229 |
///The \ref DijkstraDefaultTraits "traits class" of the algorithm. |
| 230 | 230 |
typedef TR Traits; |
| 231 | 231 |
|
| 232 | 232 |
private: |
| 233 | 233 |
|
| 234 | 234 |
typedef typename Digraph::Node Node; |
| 235 | 235 |
typedef typename Digraph::NodeIt NodeIt; |
| 236 | 236 |
typedef typename Digraph::Arc Arc; |
| 237 | 237 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 238 | 238 |
|
| 239 | 239 |
//Pointer to the underlying digraph. |
| 240 | 240 |
const Digraph *G; |
| 241 | 241 |
//Pointer to the length map. |
| 242 | 242 |
const LengthMap *_length; |
| 243 | 243 |
//Pointer to the map of predecessors arcs. |
| 244 | 244 |
PredMap *_pred; |
| 245 | 245 |
//Indicates if _pred is locally allocated (true) or not. |
| 246 | 246 |
bool local_pred; |
| 247 | 247 |
//Pointer to the map of distances. |
| 248 | 248 |
DistMap *_dist; |
| 249 | 249 |
//Indicates if _dist is locally allocated (true) or not. |
| 250 | 250 |
bool local_dist; |
| 251 | 251 |
//Pointer to the map of processed status of the nodes. |
| 252 | 252 |
ProcessedMap *_processed; |
| 253 | 253 |
//Indicates if _processed is locally allocated (true) or not. |
| 254 | 254 |
bool local_processed; |
| 255 | 255 |
//Pointer to the heap cross references. |
| 256 | 256 |
HeapCrossRef *_heap_cross_ref; |
| 257 | 257 |
//Indicates if _heap_cross_ref is locally allocated (true) or not. |
| ... | ... |
@@ -210,103 +210,104 @@ |
| 210 | 210 |
NodeNotifier& notifier(Node) const {
|
| 211 | 211 |
return _graph->notifier(Node()); |
| 212 | 212 |
} |
| 213 | 213 |
|
| 214 | 214 |
template <typename V> |
| 215 | 215 |
class NodeMap : public GR::template NodeMap<V> {
|
| 216 | 216 |
typedef typename GR::template NodeMap<V> Parent; |
| 217 | 217 |
|
| 218 | 218 |
public: |
| 219 | 219 |
|
| 220 | 220 |
explicit NodeMap(const ListArcSetBase<GR>& arcset) |
| 221 | 221 |
: Parent(*arcset._graph) {}
|
| 222 | 222 |
|
| 223 | 223 |
NodeMap(const ListArcSetBase<GR>& arcset, const V& value) |
| 224 | 224 |
: Parent(*arcset._graph, value) {}
|
| 225 | 225 |
|
| 226 | 226 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 227 | 227 |
return operator=<NodeMap>(cmap); |
| 228 | 228 |
} |
| 229 | 229 |
|
| 230 | 230 |
template <typename CMap> |
| 231 | 231 |
NodeMap& operator=(const CMap& cmap) {
|
| 232 | 232 |
Parent::operator=(cmap); |
| 233 | 233 |
return *this; |
| 234 | 234 |
} |
| 235 | 235 |
}; |
| 236 | 236 |
|
| 237 | 237 |
}; |
| 238 | 238 |
|
| 239 | 239 |
/// \ingroup graphs |
| 240 | 240 |
/// |
| 241 | 241 |
/// \brief Digraph using a node set of another digraph or graph and |
| 242 | 242 |
/// an own arc set. |
| 243 | 243 |
/// |
| 244 | 244 |
/// This structure can be used to establish another directed graph |
| 245 | 245 |
/// over a node set of an existing one. This class uses the same |
| 246 | 246 |
/// Node type as the underlying graph, and each valid node of the |
| 247 | 247 |
/// original graph is valid in this arc set, therefore the node |
| 248 | 248 |
/// objects of the original graph can be used directly with this |
| 249 | 249 |
/// class. The node handling functions (id handling, observing, and |
| 250 | 250 |
/// iterators) works equivalently as in the original graph. |
| 251 | 251 |
/// |
| 252 | 252 |
/// This implementation is based on doubly-linked lists, from each |
| 253 | 253 |
/// node the outgoing and the incoming arcs make up lists, therefore |
| 254 | 254 |
/// one arc can be erased in constant time. It also makes possible, |
| 255 | 255 |
/// that node can be removed from the underlying graph, in this case |
| 256 | 256 |
/// all arcs incident to the given node is erased from the arc set. |
| 257 | 257 |
/// |
| 258 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 259 |
/// "Digraph" concept. |
|
| 260 |
/// It provides only linear time counting for nodes and arcs. |
|
| 261 |
/// |
|
| 258 | 262 |
/// \param GR The type of the graph which shares its node set with |
| 259 | 263 |
/// this class. Its interface must conform to the |
| 260 | 264 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 261 | 265 |
/// concept. |
| 262 |
/// |
|
| 263 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 264 |
/// "Digraph" concept. |
|
| 265 | 266 |
template <typename GR> |
| 266 | 267 |
class ListArcSet : public ArcSetExtender<ListArcSetBase<GR> > {
|
| 267 | 268 |
typedef ArcSetExtender<ListArcSetBase<GR> > Parent; |
| 268 | 269 |
|
| 269 | 270 |
public: |
| 270 | 271 |
|
| 271 | 272 |
typedef typename Parent::Node Node; |
| 272 | 273 |
typedef typename Parent::Arc Arc; |
| 273 | 274 |
|
| 274 | 275 |
typedef typename Parent::NodesImplBase NodesImplBase; |
| 275 | 276 |
|
| 276 | 277 |
void eraseNode(const Node& node) {
|
| 277 | 278 |
Arc arc; |
| 278 | 279 |
Parent::firstOut(arc, node); |
| 279 | 280 |
while (arc != INVALID ) {
|
| 280 | 281 |
erase(arc); |
| 281 | 282 |
Parent::firstOut(arc, node); |
| 282 | 283 |
} |
| 283 | 284 |
|
| 284 | 285 |
Parent::firstIn(arc, node); |
| 285 | 286 |
while (arc != INVALID ) {
|
| 286 | 287 |
erase(arc); |
| 287 | 288 |
Parent::firstIn(arc, node); |
| 288 | 289 |
} |
| 289 | 290 |
} |
| 290 | 291 |
|
| 291 | 292 |
void clearNodes() {
|
| 292 | 293 |
Parent::clear(); |
| 293 | 294 |
} |
| 294 | 295 |
|
| 295 | 296 |
class NodesImpl : public NodesImplBase {
|
| 296 | 297 |
typedef NodesImplBase Parent; |
| 297 | 298 |
|
| 298 | 299 |
public: |
| 299 | 300 |
NodesImpl(const GR& graph, ListArcSet& arcset) |
| 300 | 301 |
: Parent(graph), _arcset(arcset) {}
|
| 301 | 302 |
|
| 302 | 303 |
virtual ~NodesImpl() {}
|
| 303 | 304 |
|
| 304 | 305 |
protected: |
| 305 | 306 |
|
| 306 | 307 |
virtual void erase(const Node& node) {
|
| 307 | 308 |
_arcset.eraseNode(node); |
| 308 | 309 |
Parent::erase(node); |
| 309 | 310 |
} |
| 310 | 311 |
virtual void erase(const std::vector<Node>& nodes) {
|
| 311 | 312 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 312 | 313 |
_arcset.eraseNode(nodes[i]); |
| ... | ... |
@@ -640,103 +641,104 @@ |
| 640 | 641 |
NodeNotifier& notifier(Node) const {
|
| 641 | 642 |
return _graph->notifier(Node()); |
| 642 | 643 |
} |
| 643 | 644 |
|
| 644 | 645 |
template <typename V> |
| 645 | 646 |
class NodeMap : public GR::template NodeMap<V> {
|
| 646 | 647 |
typedef typename GR::template NodeMap<V> Parent; |
| 647 | 648 |
|
| 648 | 649 |
public: |
| 649 | 650 |
|
| 650 | 651 |
explicit NodeMap(const ListEdgeSetBase<GR>& arcset) |
| 651 | 652 |
: Parent(*arcset._graph) {}
|
| 652 | 653 |
|
| 653 | 654 |
NodeMap(const ListEdgeSetBase<GR>& arcset, const V& value) |
| 654 | 655 |
: Parent(*arcset._graph, value) {}
|
| 655 | 656 |
|
| 656 | 657 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 657 | 658 |
return operator=<NodeMap>(cmap); |
| 658 | 659 |
} |
| 659 | 660 |
|
| 660 | 661 |
template <typename CMap> |
| 661 | 662 |
NodeMap& operator=(const CMap& cmap) {
|
| 662 | 663 |
Parent::operator=(cmap); |
| 663 | 664 |
return *this; |
| 664 | 665 |
} |
| 665 | 666 |
}; |
| 666 | 667 |
|
| 667 | 668 |
}; |
| 668 | 669 |
|
| 669 | 670 |
/// \ingroup graphs |
| 670 | 671 |
/// |
| 671 | 672 |
/// \brief Graph using a node set of another digraph or graph and an |
| 672 | 673 |
/// own edge set. |
| 673 | 674 |
/// |
| 674 | 675 |
/// This structure can be used to establish another graph over a |
| 675 | 676 |
/// node set of an existing one. This class uses the same Node type |
| 676 | 677 |
/// as the underlying graph, and each valid node of the original |
| 677 | 678 |
/// graph is valid in this arc set, therefore the node objects of |
| 678 | 679 |
/// the original graph can be used directly with this class. The |
| 679 | 680 |
/// node handling functions (id handling, observing, and iterators) |
| 680 | 681 |
/// works equivalently as in the original graph. |
| 681 | 682 |
/// |
| 682 | 683 |
/// This implementation is based on doubly-linked lists, from each |
| 683 | 684 |
/// node the incident edges make up lists, therefore one edge can be |
| 684 | 685 |
/// erased in constant time. It also makes possible, that node can |
| 685 | 686 |
/// be removed from the underlying graph, in this case all edges |
| 686 | 687 |
/// incident to the given node is erased from the arc set. |
| 687 | 688 |
/// |
| 689 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
| 690 |
/// concept. |
|
| 691 |
/// It provides only linear time counting for nodes, edges and arcs. |
|
| 692 |
/// |
|
| 688 | 693 |
/// \param GR The type of the graph which shares its node set |
| 689 | 694 |
/// with this class. Its interface must conform to the |
| 690 | 695 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 691 | 696 |
/// concept. |
| 692 |
/// |
|
| 693 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
| 694 |
/// concept. |
|
| 695 | 697 |
template <typename GR> |
| 696 | 698 |
class ListEdgeSet : public EdgeSetExtender<ListEdgeSetBase<GR> > {
|
| 697 | 699 |
typedef EdgeSetExtender<ListEdgeSetBase<GR> > Parent; |
| 698 | 700 |
|
| 699 | 701 |
public: |
| 700 | 702 |
|
| 701 | 703 |
typedef typename Parent::Node Node; |
| 702 | 704 |
typedef typename Parent::Arc Arc; |
| 703 | 705 |
typedef typename Parent::Edge Edge; |
| 704 | 706 |
|
| 705 | 707 |
typedef typename Parent::NodesImplBase NodesImplBase; |
| 706 | 708 |
|
| 707 | 709 |
void eraseNode(const Node& node) {
|
| 708 | 710 |
Arc arc; |
| 709 | 711 |
Parent::firstOut(arc, node); |
| 710 | 712 |
while (arc != INVALID ) {
|
| 711 | 713 |
erase(arc); |
| 712 | 714 |
Parent::firstOut(arc, node); |
| 713 | 715 |
} |
| 714 | 716 |
|
| 715 | 717 |
} |
| 716 | 718 |
|
| 717 | 719 |
void clearNodes() {
|
| 718 | 720 |
Parent::clear(); |
| 719 | 721 |
} |
| 720 | 722 |
|
| 721 | 723 |
class NodesImpl : public NodesImplBase {
|
| 722 | 724 |
typedef NodesImplBase Parent; |
| 723 | 725 |
|
| 724 | 726 |
public: |
| 725 | 727 |
NodesImpl(const GR& graph, ListEdgeSet& arcset) |
| 726 | 728 |
: Parent(graph), _arcset(arcset) {}
|
| 727 | 729 |
|
| 728 | 730 |
virtual ~NodesImpl() {}
|
| 729 | 731 |
|
| 730 | 732 |
protected: |
| 731 | 733 |
|
| 732 | 734 |
virtual void erase(const Node& node) {
|
| 733 | 735 |
_arcset.eraseNode(node); |
| 734 | 736 |
Parent::erase(node); |
| 735 | 737 |
} |
| 736 | 738 |
virtual void erase(const std::vector<Node>& nodes) {
|
| 737 | 739 |
for (int i = 0; i < int(nodes.size()); ++i) {
|
| 738 | 740 |
_arcset.eraseNode(nodes[i]); |
| 739 | 741 |
} |
| 740 | 742 |
Parent::erase(nodes); |
| 741 | 743 |
} |
| 742 | 744 |
virtual void clear() {
|
| ... | ... |
@@ -909,103 +911,104 @@ |
| 909 | 911 |
class NodeMap : public GR::template NodeMap<V> {
|
| 910 | 912 |
typedef typename GR::template NodeMap<V> Parent; |
| 911 | 913 |
|
| 912 | 914 |
public: |
| 913 | 915 |
|
| 914 | 916 |
explicit NodeMap(const SmartArcSetBase<GR>& arcset) |
| 915 | 917 |
: Parent(*arcset._graph) { }
|
| 916 | 918 |
|
| 917 | 919 |
NodeMap(const SmartArcSetBase<GR>& arcset, const V& value) |
| 918 | 920 |
: Parent(*arcset._graph, value) { }
|
| 919 | 921 |
|
| 920 | 922 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 921 | 923 |
return operator=<NodeMap>(cmap); |
| 922 | 924 |
} |
| 923 | 925 |
|
| 924 | 926 |
template <typename CMap> |
| 925 | 927 |
NodeMap& operator=(const CMap& cmap) {
|
| 926 | 928 |
Parent::operator=(cmap); |
| 927 | 929 |
return *this; |
| 928 | 930 |
} |
| 929 | 931 |
}; |
| 930 | 932 |
|
| 931 | 933 |
}; |
| 932 | 934 |
|
| 933 | 935 |
|
| 934 | 936 |
/// \ingroup graphs |
| 935 | 937 |
/// |
| 936 | 938 |
/// \brief Digraph using a node set of another digraph or graph and |
| 937 | 939 |
/// an own arc set. |
| 938 | 940 |
/// |
| 939 | 941 |
/// This structure can be used to establish another directed graph |
| 940 | 942 |
/// over a node set of an existing one. This class uses the same |
| 941 | 943 |
/// Node type as the underlying graph, and each valid node of the |
| 942 | 944 |
/// original graph is valid in this arc set, therefore the node |
| 943 | 945 |
/// objects of the original graph can be used directly with this |
| 944 | 946 |
/// class. The node handling functions (id handling, observing, and |
| 945 | 947 |
/// iterators) works equivalently as in the original graph. |
| 946 | 948 |
/// |
| 947 | 949 |
/// \param GR The type of the graph which shares its node set with |
| 948 | 950 |
/// this class. Its interface must conform to the |
| 949 | 951 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 950 | 952 |
/// concept. |
| 951 | 953 |
/// |
| 952 | 954 |
/// This implementation is slightly faster than the \c ListArcSet, |
| 953 | 955 |
/// because it uses continuous storage for arcs and it uses just |
| 954 | 956 |
/// single-linked lists for enumerate outgoing and incoming |
| 955 | 957 |
/// arcs. Therefore the arcs cannot be erased from the arc sets. |
| 956 | 958 |
/// |
| 959 |
/// This class fully conforms to the \ref concepts::Digraph "Digraph" |
|
| 960 |
/// concept. |
|
| 961 |
/// It provides only linear time counting for nodes and arcs. |
|
| 962 |
/// |
|
| 957 | 963 |
/// \warning If a node is erased from the underlying graph and this |
| 958 | 964 |
/// node is the source or target of one arc in the arc set, then |
| 959 | 965 |
/// the arc set is invalidated, and it cannot be used anymore. The |
| 960 | 966 |
/// validity can be checked with the \c valid() member function. |
| 961 |
/// |
|
| 962 |
/// This class fully conforms to the \ref concepts::Digraph |
|
| 963 |
/// "Digraph" concept. |
|
| 964 | 967 |
template <typename GR> |
| 965 | 968 |
class SmartArcSet : public ArcSetExtender<SmartArcSetBase<GR> > {
|
| 966 | 969 |
typedef ArcSetExtender<SmartArcSetBase<GR> > Parent; |
| 967 | 970 |
|
| 968 | 971 |
public: |
| 969 | 972 |
|
| 970 | 973 |
typedef typename Parent::Node Node; |
| 971 | 974 |
typedef typename Parent::Arc Arc; |
| 972 | 975 |
|
| 973 | 976 |
protected: |
| 974 | 977 |
|
| 975 | 978 |
typedef typename Parent::NodesImplBase NodesImplBase; |
| 976 | 979 |
|
| 977 | 980 |
void eraseNode(const Node& node) {
|
| 978 | 981 |
if (typename Parent::InArcIt(*this, node) == INVALID && |
| 979 | 982 |
typename Parent::OutArcIt(*this, node) == INVALID) {
|
| 980 | 983 |
return; |
| 981 | 984 |
} |
| 982 | 985 |
throw typename NodesImplBase::Notifier::ImmediateDetach(); |
| 983 | 986 |
} |
| 984 | 987 |
|
| 985 | 988 |
void clearNodes() {
|
| 986 | 989 |
Parent::clear(); |
| 987 | 990 |
} |
| 988 | 991 |
|
| 989 | 992 |
class NodesImpl : public NodesImplBase {
|
| 990 | 993 |
typedef NodesImplBase Parent; |
| 991 | 994 |
|
| 992 | 995 |
public: |
| 993 | 996 |
NodesImpl(const GR& graph, SmartArcSet& arcset) |
| 994 | 997 |
: Parent(graph), _arcset(arcset) {}
|
| 995 | 998 |
|
| 996 | 999 |
virtual ~NodesImpl() {}
|
| 997 | 1000 |
|
| 998 | 1001 |
bool attached() const {
|
| 999 | 1002 |
return Parent::attached(); |
| 1000 | 1003 |
} |
| 1001 | 1004 |
|
| 1002 | 1005 |
protected: |
| 1003 | 1006 |
|
| 1004 | 1007 |
virtual void erase(const Node& node) {
|
| 1005 | 1008 |
try {
|
| 1006 | 1009 |
_arcset.eraseNode(node); |
| 1007 | 1010 |
Parent::erase(node); |
| 1008 | 1011 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) {
|
| 1009 | 1012 |
Parent::clear(); |
| 1010 | 1013 |
throw; |
| 1011 | 1014 |
} |
| ... | ... |
@@ -1259,103 +1262,104 @@ |
| 1259 | 1262 |
template <typename V> |
| 1260 | 1263 |
class NodeMap : public GR::template NodeMap<V> {
|
| 1261 | 1264 |
typedef typename GR::template NodeMap<V> Parent; |
| 1262 | 1265 |
|
| 1263 | 1266 |
public: |
| 1264 | 1267 |
|
| 1265 | 1268 |
explicit NodeMap(const SmartEdgeSetBase<GR>& arcset) |
| 1266 | 1269 |
: Parent(*arcset._graph) { }
|
| 1267 | 1270 |
|
| 1268 | 1271 |
NodeMap(const SmartEdgeSetBase<GR>& arcset, const V& value) |
| 1269 | 1272 |
: Parent(*arcset._graph, value) { }
|
| 1270 | 1273 |
|
| 1271 | 1274 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 1272 | 1275 |
return operator=<NodeMap>(cmap); |
| 1273 | 1276 |
} |
| 1274 | 1277 |
|
| 1275 | 1278 |
template <typename CMap> |
| 1276 | 1279 |
NodeMap& operator=(const CMap& cmap) {
|
| 1277 | 1280 |
Parent::operator=(cmap); |
| 1278 | 1281 |
return *this; |
| 1279 | 1282 |
} |
| 1280 | 1283 |
}; |
| 1281 | 1284 |
|
| 1282 | 1285 |
}; |
| 1283 | 1286 |
|
| 1284 | 1287 |
/// \ingroup graphs |
| 1285 | 1288 |
/// |
| 1286 | 1289 |
/// \brief Graph using a node set of another digraph or graph and an |
| 1287 | 1290 |
/// own edge set. |
| 1288 | 1291 |
/// |
| 1289 | 1292 |
/// This structure can be used to establish another graph over a |
| 1290 | 1293 |
/// node set of an existing one. This class uses the same Node type |
| 1291 | 1294 |
/// as the underlying graph, and each valid node of the original |
| 1292 | 1295 |
/// graph is valid in this arc set, therefore the node objects of |
| 1293 | 1296 |
/// the original graph can be used directly with this class. The |
| 1294 | 1297 |
/// node handling functions (id handling, observing, and iterators) |
| 1295 | 1298 |
/// works equivalently as in the original graph. |
| 1296 | 1299 |
/// |
| 1297 | 1300 |
/// \param GR The type of the graph which shares its node set |
| 1298 | 1301 |
/// with this class. Its interface must conform to the |
| 1299 | 1302 |
/// \ref concepts::Digraph "Digraph" or \ref concepts::Graph "Graph" |
| 1300 | 1303 |
/// concept. |
| 1301 | 1304 |
/// |
| 1302 | 1305 |
/// This implementation is slightly faster than the \c ListEdgeSet, |
| 1303 | 1306 |
/// because it uses continuous storage for edges and it uses just |
| 1304 | 1307 |
/// single-linked lists for enumerate incident edges. Therefore the |
| 1305 | 1308 |
/// edges cannot be erased from the edge sets. |
| 1306 | 1309 |
/// |
| 1310 |
/// This class fully conforms to the \ref concepts::Graph "Graph" |
|
| 1311 |
/// concept. |
|
| 1312 |
/// It provides only linear time counting for nodes, edges and arcs. |
|
| 1313 |
/// |
|
| 1307 | 1314 |
/// \warning If a node is erased from the underlying graph and this |
| 1308 | 1315 |
/// node is incident to one edge in the edge set, then the edge set |
| 1309 | 1316 |
/// is invalidated, and it cannot be used anymore. The validity can |
| 1310 | 1317 |
/// be checked with the \c valid() member function. |
| 1311 |
/// |
|
| 1312 |
/// This class fully conforms to the \ref concepts::Graph |
|
| 1313 |
/// "Graph" concept. |
|
| 1314 | 1318 |
template <typename GR> |
| 1315 | 1319 |
class SmartEdgeSet : public EdgeSetExtender<SmartEdgeSetBase<GR> > {
|
| 1316 | 1320 |
typedef EdgeSetExtender<SmartEdgeSetBase<GR> > Parent; |
| 1317 | 1321 |
|
| 1318 | 1322 |
public: |
| 1319 | 1323 |
|
| 1320 | 1324 |
typedef typename Parent::Node Node; |
| 1321 | 1325 |
typedef typename Parent::Arc Arc; |
| 1322 | 1326 |
typedef typename Parent::Edge Edge; |
| 1323 | 1327 |
|
| 1324 | 1328 |
protected: |
| 1325 | 1329 |
|
| 1326 | 1330 |
typedef typename Parent::NodesImplBase NodesImplBase; |
| 1327 | 1331 |
|
| 1328 | 1332 |
void eraseNode(const Node& node) {
|
| 1329 | 1333 |
if (typename Parent::IncEdgeIt(*this, node) == INVALID) {
|
| 1330 | 1334 |
return; |
| 1331 | 1335 |
} |
| 1332 | 1336 |
throw typename NodesImplBase::Notifier::ImmediateDetach(); |
| 1333 | 1337 |
} |
| 1334 | 1338 |
|
| 1335 | 1339 |
void clearNodes() {
|
| 1336 | 1340 |
Parent::clear(); |
| 1337 | 1341 |
} |
| 1338 | 1342 |
|
| 1339 | 1343 |
class NodesImpl : public NodesImplBase {
|
| 1340 | 1344 |
typedef NodesImplBase Parent; |
| 1341 | 1345 |
|
| 1342 | 1346 |
public: |
| 1343 | 1347 |
NodesImpl(const GR& graph, SmartEdgeSet& arcset) |
| 1344 | 1348 |
: Parent(graph), _arcset(arcset) {}
|
| 1345 | 1349 |
|
| 1346 | 1350 |
virtual ~NodesImpl() {}
|
| 1347 | 1351 |
|
| 1348 | 1352 |
bool attached() const {
|
| 1349 | 1353 |
return Parent::attached(); |
| 1350 | 1354 |
} |
| 1351 | 1355 |
|
| 1352 | 1356 |
protected: |
| 1353 | 1357 |
|
| 1354 | 1358 |
virtual void erase(const Node& node) {
|
| 1355 | 1359 |
try {
|
| 1356 | 1360 |
_arcset.eraseNode(node); |
| 1357 | 1361 |
Parent::erase(node); |
| 1358 | 1362 |
} catch (const typename NodesImplBase::Notifier::ImmediateDetach&) {
|
| 1359 | 1363 |
Parent::clear(); |
| 1360 | 1364 |
throw; |
| 1361 | 1365 |
} |
| ... | ... |
@@ -117,146 +117,150 @@ |
| 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 directed full graph class. |
| 152 | 152 |
/// |
| 153 | 153 |
/// FullDigraph is a simple and fast implmenetation of directed full |
| 154 | 154 |
/// (complete) graphs. It contains an arc from each node to each node |
| 155 | 155 |
/// (including a loop for each node), therefore the number of arcs |
| 156 | 156 |
/// is the square of the number of nodes. |
| 157 | 157 |
/// This class is completely static and it needs constant memory space. |
| 158 | 158 |
/// Thus you can neither add nor delete nodes or arcs, however |
| 159 | 159 |
/// the structure can be resized using resize(). |
| 160 | 160 |
/// |
| 161 | 161 |
/// This type fully conforms to the \ref concepts::Digraph "Digraph concept". |
| 162 | 162 |
/// Most of its member functions and nested classes are documented |
| 163 | 163 |
/// only in the concept class. |
| 164 | 164 |
/// |
| 165 |
/// This class provides constant time counting for nodes and arcs. |
|
| 166 |
/// |
|
| 165 | 167 |
/// \note FullDigraph and FullGraph classes are very similar, |
| 166 | 168 |
/// but there are two differences. While this class conforms only |
| 167 | 169 |
/// to the \ref concepts::Digraph "Digraph" concept, FullGraph |
| 168 | 170 |
/// conforms to the \ref concepts::Graph "Graph" concept, |
| 169 | 171 |
/// moreover FullGraph does not contain a loop for each |
| 170 | 172 |
/// node as this class does. |
| 171 | 173 |
/// |
| 172 | 174 |
/// \sa FullGraph |
| 173 | 175 |
class FullDigraph : public ExtendedFullDigraphBase {
|
| 174 | 176 |
typedef ExtendedFullDigraphBase Parent; |
| 175 | 177 |
|
| 176 | 178 |
public: |
| 177 | 179 |
|
| 178 | 180 |
/// \brief Default constructor. |
| 179 | 181 |
/// |
| 180 | 182 |
/// Default constructor. The number of nodes and arcs will be zero. |
| 181 | 183 |
FullDigraph() { construct(0); }
|
| 182 | 184 |
|
| 183 | 185 |
/// \brief Constructor |
| 184 | 186 |
/// |
| 185 | 187 |
/// Constructor. |
| 186 | 188 |
/// \param n The number of the nodes. |
| 187 | 189 |
FullDigraph(int n) { construct(n); }
|
| 188 | 190 |
|
| 189 | 191 |
/// \brief Resizes the digraph |
| 190 | 192 |
/// |
| 191 | 193 |
/// This function resizes the digraph. It fully destroys and |
| 192 | 194 |
/// rebuilds the structure, therefore the maps of the digraph will be |
| 193 | 195 |
/// reallocated automatically and the previous values will be lost. |
| 194 | 196 |
void resize(int n) {
|
| 195 | 197 |
Parent::notifier(Arc()).clear(); |
| 196 | 198 |
Parent::notifier(Node()).clear(); |
| 197 | 199 |
construct(n); |
| 198 | 200 |
Parent::notifier(Node()).build(); |
| 199 | 201 |
Parent::notifier(Arc()).build(); |
| 200 | 202 |
} |
| 201 | 203 |
|
| 202 | 204 |
/// \brief Returns the node with the given index. |
| 203 | 205 |
/// |
| 204 | 206 |
/// Returns the node with the given index. Since this structure is |
| 205 | 207 |
/// completely static, the nodes can be indexed with integers from |
| 206 | 208 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
| 209 |
/// The index of a node is the same as its ID. |
|
| 207 | 210 |
/// \sa index() |
| 208 | 211 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 209 | 212 |
|
| 210 | 213 |
/// \brief Returns the index of the given node. |
| 211 | 214 |
/// |
| 212 | 215 |
/// Returns the index of the given node. Since this structure is |
| 213 | 216 |
/// completely static, the nodes can be indexed with integers from |
| 214 | 217 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
| 218 |
/// The index of a node is the same as its ID. |
|
| 215 | 219 |
/// \sa operator()() |
| 216 | 220 |
static int index(const Node& node) { return Parent::index(node); }
|
| 217 | 221 |
|
| 218 | 222 |
/// \brief Returns the arc connecting the given nodes. |
| 219 | 223 |
/// |
| 220 | 224 |
/// Returns the arc connecting the given nodes. |
| 221 | 225 |
Arc arc(Node u, Node v) const {
|
| 222 | 226 |
return Parent::arc(u, v); |
| 223 | 227 |
} |
| 224 | 228 |
|
| 225 | 229 |
/// \brief Number of nodes. |
| 226 | 230 |
int nodeNum() const { return Parent::nodeNum(); }
|
| 227 | 231 |
/// \brief Number of arcs. |
| 228 | 232 |
int arcNum() const { return Parent::arcNum(); }
|
| 229 | 233 |
}; |
| 230 | 234 |
|
| 231 | 235 |
|
| 232 | 236 |
class FullGraphBase {
|
| 233 | 237 |
public: |
| 234 | 238 |
|
| 235 | 239 |
typedef FullGraphBase Graph; |
| 236 | 240 |
|
| 237 | 241 |
class Node; |
| 238 | 242 |
class Arc; |
| 239 | 243 |
class Edge; |
| 240 | 244 |
|
| 241 | 245 |
protected: |
| 242 | 246 |
|
| 243 | 247 |
int _node_num; |
| 244 | 248 |
int _edge_num; |
| 245 | 249 |
|
| 246 | 250 |
FullGraphBase() {}
|
| 247 | 251 |
|
| 248 | 252 |
void construct(int n) { _node_num = n; _edge_num = n * (n - 1) / 2; }
|
| 249 | 253 |
|
| 250 | 254 |
int _uid(int e) const {
|
| 251 | 255 |
int u = e / _node_num; |
| 252 | 256 |
int v = e % _node_num; |
| 253 | 257 |
return u < v ? u : _node_num - 2 - u; |
| 254 | 258 |
} |
| 255 | 259 |
|
| 256 | 260 |
int _vid(int e) const {
|
| 257 | 261 |
int u = e / _node_num; |
| 258 | 262 |
int v = e % _node_num; |
| 259 | 263 |
return u < v ? v : _node_num - 1 - v; |
| 260 | 264 |
} |
| 261 | 265 |
|
| 262 | 266 |
void _uvid(int e, int& u, int& v) const {
|
| ... | ... |
@@ -490,131 +494,135 @@ |
| 490 | 494 |
if (u < v) {
|
| 491 | 495 |
edge._id = _eid(u, v); |
| 492 | 496 |
dir = true; |
| 493 | 497 |
} else {
|
| 494 | 498 |
--v; |
| 495 | 499 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 496 | 500 |
dir = false; |
| 497 | 501 |
} |
| 498 | 502 |
} |
| 499 | 503 |
|
| 500 | 504 |
void nextInc(Edge& edge, bool& dir) const {
|
| 501 | 505 |
int u, v; |
| 502 | 506 |
if (dir) {
|
| 503 | 507 |
_uvid(edge._id, u, v); |
| 504 | 508 |
--v; |
| 505 | 509 |
if (u < v) {
|
| 506 | 510 |
edge._id = _eid(u, v); |
| 507 | 511 |
} else {
|
| 508 | 512 |
--v; |
| 509 | 513 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 510 | 514 |
dir = false; |
| 511 | 515 |
} |
| 512 | 516 |
} else {
|
| 513 | 517 |
_uvid(edge._id, v, u); |
| 514 | 518 |
--v; |
| 515 | 519 |
edge._id = (v != -1 ? _eid(v, u) : -1); |
| 516 | 520 |
} |
| 517 | 521 |
} |
| 518 | 522 |
|
| 519 | 523 |
}; |
| 520 | 524 |
|
| 521 | 525 |
typedef GraphExtender<FullGraphBase> ExtendedFullGraphBase; |
| 522 | 526 |
|
| 523 | 527 |
/// \ingroup graphs |
| 524 | 528 |
/// |
| 525 | 529 |
/// \brief An undirected full graph class. |
| 526 | 530 |
/// |
| 527 | 531 |
/// FullGraph is a simple and fast implmenetation of undirected full |
| 528 | 532 |
/// (complete) graphs. It contains an edge between every distinct pair |
| 529 | 533 |
/// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>. |
| 530 | 534 |
/// This class is completely static and it needs constant memory space. |
| 531 | 535 |
/// Thus you can neither add nor delete nodes or edges, however |
| 532 | 536 |
/// the structure can be resized using resize(). |
| 533 | 537 |
/// |
| 534 | 538 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
| 535 | 539 |
/// Most of its member functions and nested classes are documented |
| 536 | 540 |
/// only in the concept class. |
| 537 | 541 |
/// |
| 542 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
| 543 |
/// |
|
| 538 | 544 |
/// \note FullDigraph and FullGraph classes are very similar, |
| 539 | 545 |
/// but there are two differences. While FullDigraph |
| 540 | 546 |
/// conforms only to the \ref concepts::Digraph "Digraph" concept, |
| 541 | 547 |
/// this class conforms to the \ref concepts::Graph "Graph" concept, |
| 542 | 548 |
/// moreover this class does not contain a loop for each |
| 543 | 549 |
/// node as FullDigraph does. |
| 544 | 550 |
/// |
| 545 | 551 |
/// \sa FullDigraph |
| 546 | 552 |
class FullGraph : public ExtendedFullGraphBase {
|
| 547 | 553 |
typedef ExtendedFullGraphBase Parent; |
| 548 | 554 |
|
| 549 | 555 |
public: |
| 550 | 556 |
|
| 551 | 557 |
/// \brief Default constructor. |
| 552 | 558 |
/// |
| 553 | 559 |
/// Default constructor. The number of nodes and edges will be zero. |
| 554 | 560 |
FullGraph() { construct(0); }
|
| 555 | 561 |
|
| 556 | 562 |
/// \brief Constructor |
| 557 | 563 |
/// |
| 558 | 564 |
/// Constructor. |
| 559 | 565 |
/// \param n The number of the nodes. |
| 560 | 566 |
FullGraph(int n) { construct(n); }
|
| 561 | 567 |
|
| 562 | 568 |
/// \brief Resizes the graph |
| 563 | 569 |
/// |
| 564 | 570 |
/// This function resizes the graph. It fully destroys and |
| 565 | 571 |
/// rebuilds the structure, therefore the maps of the graph will be |
| 566 | 572 |
/// reallocated automatically and the previous values will be lost. |
| 567 | 573 |
void resize(int n) {
|
| 568 | 574 |
Parent::notifier(Arc()).clear(); |
| 569 | 575 |
Parent::notifier(Edge()).clear(); |
| 570 | 576 |
Parent::notifier(Node()).clear(); |
| 571 | 577 |
construct(n); |
| 572 | 578 |
Parent::notifier(Node()).build(); |
| 573 | 579 |
Parent::notifier(Edge()).build(); |
| 574 | 580 |
Parent::notifier(Arc()).build(); |
| 575 | 581 |
} |
| 576 | 582 |
|
| 577 | 583 |
/// \brief Returns the node with the given index. |
| 578 | 584 |
/// |
| 579 | 585 |
/// Returns the node with the given index. Since this structure is |
| 580 | 586 |
/// completely static, the nodes can be indexed with integers from |
| 581 | 587 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
| 588 |
/// The index of a node is the same as its ID. |
|
| 582 | 589 |
/// \sa index() |
| 583 | 590 |
Node operator()(int ix) const { return Parent::operator()(ix); }
|
| 584 | 591 |
|
| 585 | 592 |
/// \brief Returns the index of the given node. |
| 586 | 593 |
/// |
| 587 | 594 |
/// Returns the index of the given node. Since this structure is |
| 588 | 595 |
/// completely static, the nodes can be indexed with integers from |
| 589 | 596 |
/// the range <tt>[0..nodeNum()-1]</tt>. |
| 597 |
/// The index of a node is the same as its ID. |
|
| 590 | 598 |
/// \sa operator()() |
| 591 | 599 |
static int index(const Node& node) { return Parent::index(node); }
|
| 592 | 600 |
|
| 593 | 601 |
/// \brief Returns the arc connecting the given nodes. |
| 594 | 602 |
/// |
| 595 | 603 |
/// Returns the arc connecting the given nodes. |
| 596 | 604 |
Arc arc(Node s, Node t) const {
|
| 597 | 605 |
return Parent::arc(s, t); |
| 598 | 606 |
} |
| 599 | 607 |
|
| 600 | 608 |
/// \brief Returns the edge connecting the given nodes. |
| 601 | 609 |
/// |
| 602 | 610 |
/// Returns the edge connecting the given nodes. |
| 603 | 611 |
Edge edge(Node u, Node v) const {
|
| 604 | 612 |
return Parent::edge(u, v); |
| 605 | 613 |
} |
| 606 | 614 |
|
| 607 | 615 |
/// \brief Number of nodes. |
| 608 | 616 |
int nodeNum() const { return Parent::nodeNum(); }
|
| 609 | 617 |
/// \brief Number of arcs. |
| 610 | 618 |
int arcNum() const { return Parent::arcNum(); }
|
| 611 | 619 |
/// \brief Number of edges. |
| 612 | 620 |
int edgeNum() const { return Parent::edgeNum(); }
|
| 613 | 621 |
|
| 614 | 622 |
}; |
| 615 | 623 |
|
| 616 | 624 |
|
| 617 | 625 |
} //namespace lemon |
| 618 | 626 |
|
| 619 | 627 |
|
| 620 | 628 |
#endif //LEMON_FULL_GRAPH_H |
| ... | ... |
@@ -458,96 +458,98 @@ |
| 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 |
/// GridGraph implements a special graph type. The nodes of the |
| 474 | 474 |
/// graph can be indexed by two integer values \c (i,j) where \c i is |
| 475 | 475 |
/// in the range <tt>[0..width()-1]</tt> and j is in the range |
| 476 | 476 |
/// <tt>[0..height()-1]</tt>. Two nodes are connected in the graph if |
| 477 | 477 |
/// the indices differ exactly on one position and the difference is |
| 478 | 478 |
/// also exactly one. The nodes of the graph can be obtained by position |
| 479 | 479 |
/// using the \c operator()() function and the indices of the nodes can |
| 480 | 480 |
/// be obtained using \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 |
/// This class is completely static and it needs constant memory space. |
| 486 | 486 |
/// Thus you can neither add nor delete nodes or edges, however |
| 487 | 487 |
/// the structure can be resized using resize(). |
| 488 | 488 |
/// |
| 489 | 489 |
/// \image html grid_graph.png |
| 490 | 490 |
/// \image latex grid_graph.eps "Grid graph" width=\textwidth |
| 491 | 491 |
/// |
| 492 | 492 |
/// A short example about the basic usage: |
| 493 | 493 |
///\code |
| 494 | 494 |
/// GridGraph graph(rows, cols); |
| 495 | 495 |
/// GridGraph::NodeMap<int> val(graph); |
| 496 | 496 |
/// for (int i = 0; i < graph.width(); ++i) {
|
| 497 | 497 |
/// for (int j = 0; j < graph.height(); ++j) {
|
| 498 | 498 |
/// val[graph(i, j)] = i + j; |
| 499 | 499 |
/// } |
| 500 | 500 |
/// } |
| 501 | 501 |
///\endcode |
| 502 | 502 |
/// |
| 503 | 503 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
| 504 | 504 |
/// Most of its member functions and nested classes are documented |
| 505 | 505 |
/// only in the concept class. |
| 506 |
/// |
|
| 507 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
| 506 | 508 |
class GridGraph : public ExtendedGridGraphBase {
|
| 507 | 509 |
typedef ExtendedGridGraphBase Parent; |
| 508 | 510 |
|
| 509 | 511 |
public: |
| 510 | 512 |
|
| 511 | 513 |
/// \brief Map to get the indices of the nodes as \ref dim2::Point |
| 512 | 514 |
/// "dim2::Point<int>". |
| 513 | 515 |
/// |
| 514 | 516 |
/// Map to get the indices of the nodes as \ref dim2::Point |
| 515 | 517 |
/// "dim2::Point<int>". |
| 516 | 518 |
class IndexMap {
|
| 517 | 519 |
public: |
| 518 | 520 |
/// \brief The key type of the map |
| 519 | 521 |
typedef GridGraph::Node Key; |
| 520 | 522 |
/// \brief The value type of the map |
| 521 | 523 |
typedef dim2::Point<int> Value; |
| 522 | 524 |
|
| 523 | 525 |
/// \brief Constructor |
| 524 | 526 |
IndexMap(const GridGraph& graph) : _graph(graph) {}
|
| 525 | 527 |
|
| 526 | 528 |
/// \brief The subscript operator |
| 527 | 529 |
Value operator[](Key key) const {
|
| 528 | 530 |
return _graph.pos(key); |
| 529 | 531 |
} |
| 530 | 532 |
|
| 531 | 533 |
private: |
| 532 | 534 |
const GridGraph& _graph; |
| 533 | 535 |
}; |
| 534 | 536 |
|
| 535 | 537 |
/// \brief Map to get the column of the nodes. |
| 536 | 538 |
/// |
| 537 | 539 |
/// Map to get the column of the nodes. |
| 538 | 540 |
class ColMap {
|
| 539 | 541 |
public: |
| 540 | 542 |
/// \brief The key type of the map |
| 541 | 543 |
typedef GridGraph::Node Key; |
| 542 | 544 |
/// \brief The value type of the map |
| 543 | 545 |
typedef int Value; |
| 544 | 546 |
|
| 545 | 547 |
/// \brief Constructor |
| 546 | 548 |
ColMap(const GridGraph& graph) : _graph(graph) {}
|
| 547 | 549 |
|
| 548 | 550 |
/// \brief The subscript operator |
| 549 | 551 |
Value operator[](Key key) const {
|
| 550 | 552 |
return _graph.col(key); |
| 551 | 553 |
} |
| 552 | 554 |
|
| 553 | 555 |
private: |
| ... | ... |
@@ -249,96 +249,98 @@ |
| 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 |
static int index(Node node) {
|
| 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 |
/// 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 | 290 |
/// Thus you can neither add nor delete nodes or edges, however |
| 291 | 291 |
/// the structure can be resized using resize(). |
| 292 | 292 |
/// |
| 293 | 293 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept". |
| 294 | 294 |
/// Most of its member functions and nested classes are documented |
| 295 | 295 |
/// only in the concept class. |
| 296 | 296 |
/// |
| 297 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
| 298 |
/// |
|
| 297 | 299 |
/// \note The type of the indices is chosen to \c int for efficiency |
| 298 | 300 |
/// reasons. Thus the maximum dimension of this implementation is 26 |
| 299 | 301 |
/// (assuming that the size of \c int is 32 bit). |
| 300 | 302 |
class HypercubeGraph : public ExtendedHypercubeGraphBase {
|
| 301 | 303 |
typedef ExtendedHypercubeGraphBase Parent; |
| 302 | 304 |
|
| 303 | 305 |
public: |
| 304 | 306 |
|
| 305 | 307 |
/// \brief Constructs a hypercube graph with \c dim dimensions. |
| 306 | 308 |
/// |
| 307 | 309 |
/// Constructs a hypercube graph with \c dim dimensions. |
| 308 | 310 |
HypercubeGraph(int dim) { construct(dim); }
|
| 309 | 311 |
|
| 310 | 312 |
/// \brief Resizes the graph |
| 311 | 313 |
/// |
| 312 | 314 |
/// This function resizes the graph. It fully destroys and |
| 313 | 315 |
/// rebuilds the structure, therefore the maps of the graph will be |
| 314 | 316 |
/// reallocated automatically and the previous values will be lost. |
| 315 | 317 |
void resize(int dim) {
|
| 316 | 318 |
Parent::notifier(Arc()).clear(); |
| 317 | 319 |
Parent::notifier(Edge()).clear(); |
| 318 | 320 |
Parent::notifier(Node()).clear(); |
| 319 | 321 |
construct(dim); |
| 320 | 322 |
Parent::notifier(Node()).build(); |
| 321 | 323 |
Parent::notifier(Edge()).build(); |
| 322 | 324 |
Parent::notifier(Arc()).build(); |
| 323 | 325 |
} |
| 324 | 326 |
|
| 325 | 327 |
/// \brief The number of dimensions. |
| 326 | 328 |
/// |
| 327 | 329 |
/// Gives back the number of dimensions. |
| 328 | 330 |
int dimension() const {
|
| 329 | 331 |
return Parent::dimension(); |
| 330 | 332 |
} |
| 331 | 333 |
|
| 332 | 334 |
/// \brief Returns \c true if the n'th bit of the node is one. |
| 333 | 335 |
/// |
| 334 | 336 |
/// Returns \c true if the n'th bit of the node is one. |
| 335 | 337 |
bool projection(Node node, int n) const {
|
| 336 | 338 |
return Parent::projection(node, n); |
| 337 | 339 |
} |
| 338 | 340 |
|
| 339 | 341 |
/// \brief The dimension id of an edge. |
| 340 | 342 |
/// |
| 341 | 343 |
/// Gives back the dimension id of the given edge. |
| 342 | 344 |
/// It is in the range <tt>[0..dim-1]</tt>. |
| 343 | 345 |
int dimension(Edge edge) const {
|
| 344 | 346 |
return Parent::dimension(edge); |
| ... | ... |
@@ -279,138 +279,147 @@ |
| 279 | 279 |
{
|
| 280 | 280 |
if(arcs[e.id].next_in != -1) |
| 281 | 281 |
arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in; |
| 282 | 282 |
if(arcs[e.id].prev_in != -1) |
| 283 | 283 |
arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in; |
| 284 | 284 |
else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in; |
| 285 | 285 |
if (nodes[n.id].first_in != -1) {
|
| 286 | 286 |
arcs[nodes[n.id].first_in].prev_in = e.id; |
| 287 | 287 |
} |
| 288 | 288 |
arcs[e.id].target = n.id; |
| 289 | 289 |
arcs[e.id].prev_in = -1; |
| 290 | 290 |
arcs[e.id].next_in = nodes[n.id].first_in; |
| 291 | 291 |
nodes[n.id].first_in = e.id; |
| 292 | 292 |
} |
| 293 | 293 |
void changeSource(Arc e, Node n) |
| 294 | 294 |
{
|
| 295 | 295 |
if(arcs[e.id].next_out != -1) |
| 296 | 296 |
arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out; |
| 297 | 297 |
if(arcs[e.id].prev_out != -1) |
| 298 | 298 |
arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out; |
| 299 | 299 |
else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out; |
| 300 | 300 |
if (nodes[n.id].first_out != -1) {
|
| 301 | 301 |
arcs[nodes[n.id].first_out].prev_out = e.id; |
| 302 | 302 |
} |
| 303 | 303 |
arcs[e.id].source = n.id; |
| 304 | 304 |
arcs[e.id].prev_out = -1; |
| 305 | 305 |
arcs[e.id].next_out = nodes[n.id].first_out; |
| 306 | 306 |
nodes[n.id].first_out = e.id; |
| 307 | 307 |
} |
| 308 | 308 |
|
| 309 | 309 |
}; |
| 310 | 310 |
|
| 311 | 311 |
typedef DigraphExtender<ListDigraphBase> ExtendedListDigraphBase; |
| 312 | 312 |
|
| 313 | 313 |
/// \addtogroup graphs |
| 314 | 314 |
/// @{
|
| 315 | 315 |
|
| 316 | 316 |
///A general directed graph structure. |
| 317 | 317 |
|
| 318 | 318 |
///\ref ListDigraph is a versatile and fast directed graph |
| 319 | 319 |
///implementation based on linked lists that are stored in |
| 320 | 320 |
///\c std::vector structures. |
| 321 | 321 |
/// |
| 322 | 322 |
///This type fully conforms to the \ref concepts::Digraph "Digraph concept" |
| 323 | 323 |
///and it also provides several useful additional functionalities. |
| 324 | 324 |
///Most of its member functions and nested classes are documented |
| 325 | 325 |
///only in the concept class. |
| 326 | 326 |
/// |
| 327 |
///This class provides only linear time counting for nodes and arcs. |
|
| 328 |
/// |
|
| 327 | 329 |
///\sa concepts::Digraph |
| 328 | 330 |
///\sa ListGraph |
| 329 | 331 |
class ListDigraph : public ExtendedListDigraphBase {
|
| 330 | 332 |
typedef ExtendedListDigraphBase Parent; |
| 331 | 333 |
|
| 332 | 334 |
private: |
| 333 | 335 |
/// Digraphs are \e not copy constructible. Use DigraphCopy instead. |
| 334 | 336 |
ListDigraph(const ListDigraph &) :ExtendedListDigraphBase() {};
|
| 335 | 337 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
| 336 | 338 |
/// Use DigraphCopy instead. |
| 337 | 339 |
void operator=(const ListDigraph &) {}
|
| 338 | 340 |
public: |
| 339 | 341 |
|
| 340 | 342 |
/// Constructor |
| 341 | 343 |
|
| 342 | 344 |
/// Constructor. |
| 343 | 345 |
/// |
| 344 | 346 |
ListDigraph() {}
|
| 345 | 347 |
|
| 346 | 348 |
///Add a new node to the digraph. |
| 347 | 349 |
|
| 348 | 350 |
///This function adds a new node to the digraph. |
| 349 | 351 |
///\return The new node. |
| 350 | 352 |
Node addNode() { return Parent::addNode(); }
|
| 351 | 353 |
|
| 352 | 354 |
///Add a new arc to the digraph. |
| 353 | 355 |
|
| 354 | 356 |
///This function adds a new arc to the digraph with source node \c s |
| 355 | 357 |
///and target node \c t. |
| 356 | 358 |
///\return The new arc. |
| 357 | 359 |
Arc addArc(Node s, Node t) {
|
| 358 | 360 |
return Parent::addArc(s, t); |
| 359 | 361 |
} |
| 360 | 362 |
|
| 361 | 363 |
///\brief Erase a node from the digraph. |
| 362 | 364 |
/// |
| 363 |
///This function erases the given node |
|
| 365 |
///This function erases the given node along with its outgoing and |
|
| 366 |
///incoming arcs from the digraph. |
|
| 367 |
/// |
|
| 368 |
///\note All iterators referencing the removed node or the connected |
|
| 369 |
///arcs are invalidated, of course. |
|
| 364 | 370 |
void erase(Node n) { Parent::erase(n); }
|
| 365 | 371 |
|
| 366 | 372 |
///\brief Erase an arc from the digraph. |
| 367 | 373 |
/// |
| 368 | 374 |
///This function erases the given arc from the digraph. |
| 375 |
/// |
|
| 376 |
///\note All iterators referencing the removed arc are invalidated, |
|
| 377 |
///of course. |
|
| 369 | 378 |
void erase(Arc a) { Parent::erase(a); }
|
| 370 | 379 |
|
| 371 | 380 |
/// Node validity check |
| 372 | 381 |
|
| 373 | 382 |
/// This function gives back \c true if the given node is valid, |
| 374 | 383 |
/// i.e. it is a real node of the digraph. |
| 375 | 384 |
/// |
| 376 | 385 |
/// \warning A removed node could become valid again if new nodes are |
| 377 | 386 |
/// added to the digraph. |
| 378 | 387 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 379 | 388 |
|
| 380 | 389 |
/// Arc validity check |
| 381 | 390 |
|
| 382 | 391 |
/// This function gives back \c true if the given arc is valid, |
| 383 | 392 |
/// i.e. it is a real arc of the digraph. |
| 384 | 393 |
/// |
| 385 | 394 |
/// \warning A removed arc could become valid again if new arcs are |
| 386 | 395 |
/// added to the digraph. |
| 387 | 396 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 388 | 397 |
|
| 389 | 398 |
/// Change the target node of an arc |
| 390 | 399 |
|
| 391 | 400 |
/// This function changes the target node of the given arc \c a to \c n. |
| 392 | 401 |
/// |
| 393 | 402 |
///\note \c ArcIt and \c OutArcIt iterators referencing the changed |
| 394 | 403 |
///arc remain valid, however \c InArcIt iterators are invalidated. |
| 395 | 404 |
/// |
| 396 | 405 |
///\warning This functionality cannot be used together with the Snapshot |
| 397 | 406 |
///feature. |
| 398 | 407 |
void changeTarget(Arc a, Node n) {
|
| 399 | 408 |
Parent::changeTarget(a,n); |
| 400 | 409 |
} |
| 401 | 410 |
/// Change the source node of an arc |
| 402 | 411 |
|
| 403 | 412 |
/// This function changes the source node of the given arc \c a to \c n. |
| 404 | 413 |
/// |
| 405 | 414 |
///\note \c InArcIt iterators referencing the changed arc remain |
| 406 | 415 |
///valid, however \c ArcIt and \c OutArcIt iterators are invalidated. |
| 407 | 416 |
/// |
| 408 | 417 |
///\warning This functionality cannot be used together with the Snapshot |
| 409 | 418 |
///feature. |
| 410 | 419 |
void changeSource(Arc a, Node n) {
|
| 411 | 420 |
Parent::changeSource(a,n); |
| 412 | 421 |
} |
| 413 | 422 |
|
| 414 | 423 |
/// Reverse the direction of an arc. |
| 415 | 424 |
|
| 416 | 425 |
/// This function reverses the direction of the given arc. |
| ... | ... |
@@ -465,96 +474,97 @@ |
| 465 | 474 |
|
| 466 | 475 |
///This function splits the given node. First, a new node is added |
| 467 | 476 |
///to the digraph, then the source of each outgoing arc of node \c n |
| 468 | 477 |
///is moved to this new node. |
| 469 | 478 |
///If the second parameter \c connect is \c true (this is the default |
| 470 | 479 |
///value), then a new arc from node \c n to the newly created node |
| 471 | 480 |
///is also added. |
| 472 | 481 |
///\return The newly created node. |
| 473 | 482 |
/// |
| 474 | 483 |
///\note All iterators remain valid. |
| 475 | 484 |
/// |
| 476 | 485 |
///\warning This functionality cannot be used together with the |
| 477 | 486 |
///Snapshot feature. |
| 478 | 487 |
Node split(Node n, bool connect = true) {
|
| 479 | 488 |
Node b = addNode(); |
| 480 | 489 |
nodes[b.id].first_out=nodes[n.id].first_out; |
| 481 | 490 |
nodes[n.id].first_out=-1; |
| 482 | 491 |
for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
|
| 483 | 492 |
arcs[i].source=b.id; |
| 484 | 493 |
} |
| 485 | 494 |
if (connect) addArc(n,b); |
| 486 | 495 |
return b; |
| 487 | 496 |
} |
| 488 | 497 |
|
| 489 | 498 |
///Split an arc. |
| 490 | 499 |
|
| 491 | 500 |
///This function splits the given arc. First, a new node \c v is |
| 492 | 501 |
///added to the digraph, then the target node of the original arc |
| 493 | 502 |
///is set to \c v. Finally, an arc from \c v to the original target |
| 494 | 503 |
///is added. |
| 495 | 504 |
///\return The newly created node. |
| 496 | 505 |
/// |
| 497 | 506 |
///\note \c InArcIt iterators referencing the original arc are |
| 498 | 507 |
///invalidated. Other iterators remain valid. |
| 499 | 508 |
/// |
| 500 | 509 |
///\warning This functionality cannot be used together with the |
| 501 | 510 |
///Snapshot feature. |
| 502 | 511 |
Node split(Arc a) {
|
| 503 | 512 |
Node v = addNode(); |
| 504 | 513 |
addArc(v,target(a)); |
| 505 | 514 |
changeTarget(a,v); |
| 506 | 515 |
return v; |
| 507 | 516 |
} |
| 508 | 517 |
|
| 509 | 518 |
///Clear the digraph. |
| 510 | 519 |
|
| 511 | 520 |
///This function erases all nodes and arcs from the digraph. |
| 512 | 521 |
/// |
| 522 |
///\note All iterators of the digraph are invalidated, of course. |
|
| 513 | 523 |
void clear() {
|
| 514 | 524 |
Parent::clear(); |
| 515 | 525 |
} |
| 516 | 526 |
|
| 517 | 527 |
/// Reserve memory for nodes. |
| 518 | 528 |
|
| 519 | 529 |
/// Using this function, it is possible to avoid superfluous memory |
| 520 | 530 |
/// allocation: if you know that the digraph you want to build will |
| 521 | 531 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
| 522 | 532 |
/// then it is worth reserving space for this amount before starting |
| 523 | 533 |
/// to build the digraph. |
| 524 | 534 |
/// \sa reserveArc() |
| 525 | 535 |
void reserveNode(int n) { nodes.reserve(n); };
|
| 526 | 536 |
|
| 527 | 537 |
/// Reserve memory for arcs. |
| 528 | 538 |
|
| 529 | 539 |
/// Using this function, it is possible to avoid superfluous memory |
| 530 | 540 |
/// allocation: if you know that the digraph you want to build will |
| 531 | 541 |
/// be large (e.g. it will contain millions of nodes and/or arcs), |
| 532 | 542 |
/// then it is worth reserving space for this amount before starting |
| 533 | 543 |
/// to build the digraph. |
| 534 | 544 |
/// \sa reserveNode() |
| 535 | 545 |
void reserveArc(int m) { arcs.reserve(m); };
|
| 536 | 546 |
|
| 537 | 547 |
/// \brief Class to make a snapshot of the digraph and restore |
| 538 | 548 |
/// it later. |
| 539 | 549 |
/// |
| 540 | 550 |
/// Class to make a snapshot of the digraph and restore it later. |
| 541 | 551 |
/// |
| 542 | 552 |
/// The newly added nodes and arcs can be removed using the |
| 543 | 553 |
/// restore() function. |
| 544 | 554 |
/// |
| 545 | 555 |
/// \note After a state is restored, you cannot restore a later state, |
| 546 | 556 |
/// i.e. you cannot add the removed nodes and arcs again using |
| 547 | 557 |
/// another Snapshot instance. |
| 548 | 558 |
/// |
| 549 | 559 |
/// \warning Node and arc deletions and other modifications (e.g. |
| 550 | 560 |
/// reversing, contracting, splitting arcs or nodes) cannot be |
| 551 | 561 |
/// restored. These events invalidate the snapshot. |
| 552 | 562 |
/// However the arcs and nodes that were added to the digraph after |
| 553 | 563 |
/// making the current snapshot can be removed without invalidating it. |
| 554 | 564 |
class Snapshot {
|
| 555 | 565 |
protected: |
| 556 | 566 |
|
| 557 | 567 |
typedef Parent::NodeNotifier NodeNotifier; |
| 558 | 568 |
|
| 559 | 569 |
class NodeObserverProxy : public NodeNotifier::ObserverBase {
|
| 560 | 570 |
public: |
| ... | ... |
@@ -1134,229 +1144,239 @@ |
| 1134 | 1144 |
} |
| 1135 | 1145 |
arcs[(2 * e.id) | 1].target = n.id; |
| 1136 | 1146 |
arcs[2 * e.id].prev_out = -1; |
| 1137 | 1147 |
arcs[2 * e.id].next_out = nodes[n.id].first_out; |
| 1138 | 1148 |
nodes[n.id].first_out = 2 * e.id; |
| 1139 | 1149 |
} |
| 1140 | 1150 |
|
| 1141 | 1151 |
void changeU(Edge e, Node n) {
|
| 1142 | 1152 |
if(arcs[(2 * e.id) | 1].next_out != -1) {
|
| 1143 | 1153 |
arcs[arcs[(2 * e.id) | 1].next_out].prev_out = |
| 1144 | 1154 |
arcs[(2 * e.id) | 1].prev_out; |
| 1145 | 1155 |
} |
| 1146 | 1156 |
if(arcs[(2 * e.id) | 1].prev_out != -1) {
|
| 1147 | 1157 |
arcs[arcs[(2 * e.id) | 1].prev_out].next_out = |
| 1148 | 1158 |
arcs[(2 * e.id) | 1].next_out; |
| 1149 | 1159 |
} else {
|
| 1150 | 1160 |
nodes[arcs[2 * e.id].target].first_out = |
| 1151 | 1161 |
arcs[(2 * e.id) | 1].next_out; |
| 1152 | 1162 |
} |
| 1153 | 1163 |
|
| 1154 | 1164 |
if (nodes[n.id].first_out != -1) {
|
| 1155 | 1165 |
arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1); |
| 1156 | 1166 |
} |
| 1157 | 1167 |
arcs[2 * e.id].target = n.id; |
| 1158 | 1168 |
arcs[(2 * e.id) | 1].prev_out = -1; |
| 1159 | 1169 |
arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out; |
| 1160 | 1170 |
nodes[n.id].first_out = ((2 * e.id) | 1); |
| 1161 | 1171 |
} |
| 1162 | 1172 |
|
| 1163 | 1173 |
}; |
| 1164 | 1174 |
|
| 1165 | 1175 |
typedef GraphExtender<ListGraphBase> ExtendedListGraphBase; |
| 1166 | 1176 |
|
| 1167 | 1177 |
|
| 1168 | 1178 |
/// \addtogroup graphs |
| 1169 | 1179 |
/// @{
|
| 1170 | 1180 |
|
| 1171 | 1181 |
///A general undirected graph structure. |
| 1172 | 1182 |
|
| 1173 | 1183 |
///\ref ListGraph is a versatile and fast undirected graph |
| 1174 | 1184 |
///implementation based on linked lists that are stored in |
| 1175 | 1185 |
///\c std::vector structures. |
| 1176 | 1186 |
/// |
| 1177 | 1187 |
///This type fully conforms to the \ref concepts::Graph "Graph concept" |
| 1178 | 1188 |
///and it also provides several useful additional functionalities. |
| 1179 | 1189 |
///Most of its member functions and nested classes are documented |
| 1180 | 1190 |
///only in the concept class. |
| 1181 | 1191 |
/// |
| 1192 |
///This class provides only linear time counting for nodes, edges and arcs. |
|
| 1193 |
/// |
|
| 1182 | 1194 |
///\sa concepts::Graph |
| 1183 | 1195 |
///\sa ListDigraph |
| 1184 | 1196 |
class ListGraph : public ExtendedListGraphBase {
|
| 1185 | 1197 |
typedef ExtendedListGraphBase Parent; |
| 1186 | 1198 |
|
| 1187 | 1199 |
private: |
| 1188 | 1200 |
/// Graphs are \e not copy constructible. Use GraphCopy instead. |
| 1189 | 1201 |
ListGraph(const ListGraph &) :ExtendedListGraphBase() {};
|
| 1190 | 1202 |
/// \brief Assignment of a graph to another one is \e not allowed. |
| 1191 | 1203 |
/// Use GraphCopy instead. |
| 1192 | 1204 |
void operator=(const ListGraph &) {}
|
| 1193 | 1205 |
public: |
| 1194 | 1206 |
/// Constructor |
| 1195 | 1207 |
|
| 1196 | 1208 |
/// Constructor. |
| 1197 | 1209 |
/// |
| 1198 | 1210 |
ListGraph() {}
|
| 1199 | 1211 |
|
| 1200 | 1212 |
typedef Parent::OutArcIt IncEdgeIt; |
| 1201 | 1213 |
|
| 1202 | 1214 |
/// \brief Add a new node to the graph. |
| 1203 | 1215 |
/// |
| 1204 | 1216 |
/// This function adds a new node to the graph. |
| 1205 | 1217 |
/// \return The new node. |
| 1206 | 1218 |
Node addNode() { return Parent::addNode(); }
|
| 1207 | 1219 |
|
| 1208 | 1220 |
/// \brief Add a new edge to the graph. |
| 1209 | 1221 |
/// |
| 1210 | 1222 |
/// This function adds a new edge to the graph between nodes |
| 1211 | 1223 |
/// \c u and \c v with inherent orientation from node \c u to |
| 1212 | 1224 |
/// node \c v. |
| 1213 | 1225 |
/// \return The new edge. |
| 1214 | 1226 |
Edge addEdge(Node u, Node v) {
|
| 1215 | 1227 |
return Parent::addEdge(u, v); |
| 1216 | 1228 |
} |
| 1217 | 1229 |
|
| 1218 | 1230 |
///\brief Erase a node from the graph. |
| 1219 | 1231 |
/// |
| 1220 |
/// This function erases the given node |
|
| 1232 |
/// This function erases the given node along with its incident arcs |
|
| 1233 |
/// from the graph. |
|
| 1234 |
/// |
|
| 1235 |
/// \note All iterators referencing the removed node or the incident |
|
| 1236 |
/// edges are invalidated, of course. |
|
| 1221 | 1237 |
void erase(Node n) { Parent::erase(n); }
|
| 1222 | 1238 |
|
| 1223 | 1239 |
///\brief Erase an edge from the graph. |
| 1224 | 1240 |
/// |
| 1225 | 1241 |
/// This function erases the given edge from the graph. |
| 1242 |
/// |
|
| 1243 |
/// \note All iterators referencing the removed edge are invalidated, |
|
| 1244 |
/// of course. |
|
| 1226 | 1245 |
void erase(Edge e) { Parent::erase(e); }
|
| 1227 | 1246 |
/// Node validity check |
| 1228 | 1247 |
|
| 1229 | 1248 |
/// This function gives back \c true if the given node is valid, |
| 1230 | 1249 |
/// i.e. it is a real node of the graph. |
| 1231 | 1250 |
/// |
| 1232 | 1251 |
/// \warning A removed node could become valid again if new nodes are |
| 1233 | 1252 |
/// added to the graph. |
| 1234 | 1253 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 1235 | 1254 |
/// Edge validity check |
| 1236 | 1255 |
|
| 1237 | 1256 |
/// This function gives back \c true if the given edge is valid, |
| 1238 | 1257 |
/// i.e. it is a real edge of the graph. |
| 1239 | 1258 |
/// |
| 1240 | 1259 |
/// \warning A removed edge could become valid again if new edges are |
| 1241 | 1260 |
/// added to the graph. |
| 1242 | 1261 |
bool valid(Edge e) const { return Parent::valid(e); }
|
| 1243 | 1262 |
/// Arc validity check |
| 1244 | 1263 |
|
| 1245 | 1264 |
/// This function gives back \c true if the given arc is valid, |
| 1246 | 1265 |
/// i.e. it is a real arc of the graph. |
| 1247 | 1266 |
/// |
| 1248 | 1267 |
/// \warning A removed arc could become valid again if new edges are |
| 1249 | 1268 |
/// added to the graph. |
| 1250 | 1269 |
bool valid(Arc a) const { return Parent::valid(a); }
|
| 1251 | 1270 |
|
| 1252 | 1271 |
/// \brief Change the first node of an edge. |
| 1253 | 1272 |
/// |
| 1254 | 1273 |
/// This function changes the first node of the given edge \c e to \c n. |
| 1255 | 1274 |
/// |
| 1256 | 1275 |
///\note \c EdgeIt and \c ArcIt iterators referencing the |
| 1257 | 1276 |
///changed edge are invalidated and all other iterators whose |
| 1258 | 1277 |
///base node is the changed node are also invalidated. |
| 1259 | 1278 |
/// |
| 1260 | 1279 |
///\warning This functionality cannot be used together with the |
| 1261 | 1280 |
///Snapshot feature. |
| 1262 | 1281 |
void changeU(Edge e, Node n) {
|
| 1263 | 1282 |
Parent::changeU(e,n); |
| 1264 | 1283 |
} |
| 1265 | 1284 |
/// \brief Change the second node of an edge. |
| 1266 | 1285 |
/// |
| 1267 | 1286 |
/// This function changes the second node of the given edge \c e to \c n. |
| 1268 | 1287 |
/// |
| 1269 | 1288 |
///\note \c EdgeIt iterators referencing the changed edge remain |
| 1270 | 1289 |
///valid, however \c ArcIt iterators referencing the changed edge and |
| 1271 | 1290 |
///all other iterators whose base node is the changed node are also |
| 1272 | 1291 |
///invalidated. |
| 1273 | 1292 |
/// |
| 1274 | 1293 |
///\warning This functionality cannot be used together with the |
| 1275 | 1294 |
///Snapshot feature. |
| 1276 | 1295 |
void changeV(Edge e, Node n) {
|
| 1277 | 1296 |
Parent::changeV(e,n); |
| 1278 | 1297 |
} |
| 1279 | 1298 |
|
| 1280 | 1299 |
/// \brief Contract two nodes. |
| 1281 | 1300 |
/// |
| 1282 | 1301 |
/// This function contracts the given two nodes. |
| 1283 | 1302 |
/// Node \c b is removed, but instead of deleting |
| 1284 | 1303 |
/// its incident edges, they are joined to node \c a. |
| 1285 | 1304 |
/// If the last parameter \c r is \c true (this is the default value), |
| 1286 | 1305 |
/// then the newly created loops are removed. |
| 1287 | 1306 |
/// |
| 1288 | 1307 |
/// \note The moved edges are joined to node \c a using changeU() |
| 1289 | 1308 |
/// or changeV(), thus all edge and arc iterators whose base node is |
| 1290 | 1309 |
/// \c b are invalidated. |
| 1291 | 1310 |
/// Moreover all iterators referencing node \c b or the removed |
| 1292 | 1311 |
/// loops are also invalidated. Other iterators remain valid. |
| 1293 | 1312 |
/// |
| 1294 | 1313 |
///\warning This functionality cannot be used together with the |
| 1295 | 1314 |
///Snapshot feature. |
| 1296 | 1315 |
void contract(Node a, Node b, bool r = true) {
|
| 1297 | 1316 |
for(IncEdgeIt e(*this, b); e!=INVALID;) {
|
| 1298 | 1317 |
IncEdgeIt f = e; ++f; |
| 1299 | 1318 |
if (r && runningNode(e) == a) {
|
| 1300 | 1319 |
erase(e); |
| 1301 | 1320 |
} else if (u(e) == b) {
|
| 1302 | 1321 |
changeU(e, a); |
| 1303 | 1322 |
} else {
|
| 1304 | 1323 |
changeV(e, a); |
| 1305 | 1324 |
} |
| 1306 | 1325 |
e = f; |
| 1307 | 1326 |
} |
| 1308 | 1327 |
erase(b); |
| 1309 | 1328 |
} |
| 1310 | 1329 |
|
| 1311 | 1330 |
///Clear the graph. |
| 1312 | 1331 |
|
| 1313 | 1332 |
///This function erases all nodes and arcs from the graph. |
| 1314 | 1333 |
/// |
| 1334 |
///\note All iterators of the graph are invalidated, of course. |
|
| 1315 | 1335 |
void clear() {
|
| 1316 | 1336 |
Parent::clear(); |
| 1317 | 1337 |
} |
| 1318 | 1338 |
|
| 1319 | 1339 |
/// Reserve memory for nodes. |
| 1320 | 1340 |
|
| 1321 | 1341 |
/// Using this function, it is possible to avoid superfluous memory |
| 1322 | 1342 |
/// allocation: if you know that the graph you want to build will |
| 1323 | 1343 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
| 1324 | 1344 |
/// then it is worth reserving space for this amount before starting |
| 1325 | 1345 |
/// to build the graph. |
| 1326 | 1346 |
/// \sa reserveEdge() |
| 1327 | 1347 |
void reserveNode(int n) { nodes.reserve(n); };
|
| 1328 | 1348 |
|
| 1329 | 1349 |
/// Reserve memory for edges. |
| 1330 | 1350 |
|
| 1331 | 1351 |
/// Using this function, it is possible to avoid superfluous memory |
| 1332 | 1352 |
/// allocation: if you know that the graph you want to build will |
| 1333 | 1353 |
/// be large (e.g. it will contain millions of nodes and/or edges), |
| 1334 | 1354 |
/// then it is worth reserving space for this amount before starting |
| 1335 | 1355 |
/// to build the graph. |
| 1336 | 1356 |
/// \sa reserveNode() |
| 1337 | 1357 |
void reserveEdge(int m) { arcs.reserve(2 * m); };
|
| 1338 | 1358 |
|
| 1339 | 1359 |
/// \brief Class to make a snapshot of the graph and restore |
| 1340 | 1360 |
/// it later. |
| 1341 | 1361 |
/// |
| 1342 | 1362 |
/// Class to make a snapshot of the graph and restore it later. |
| 1343 | 1363 |
/// |
| 1344 | 1364 |
/// The newly added nodes and edges can be removed |
| 1345 | 1365 |
/// using the restore() function. |
| 1346 | 1366 |
/// |
| 1347 | 1367 |
/// \note After a state is restored, you cannot restore a later state, |
| 1348 | 1368 |
/// i.e. you cannot add the removed nodes and edges again using |
| 1349 | 1369 |
/// another Snapshot instance. |
| 1350 | 1370 |
/// |
| 1351 | 1371 |
/// \warning Node and edge deletions and other modifications |
| 1352 | 1372 |
/// (e.g. changing the end-nodes of edges or contracting nodes) |
| 1353 | 1373 |
/// cannot be restored. These events invalidate the snapshot. |
| 1354 | 1374 |
/// However the edges and nodes that were added to the graph after |
| 1355 | 1375 |
/// making the current snapshot can be removed without invalidating it. |
| 1356 | 1376 |
class Snapshot {
|
| 1357 | 1377 |
protected: |
| 1358 | 1378 |
|
| 1359 | 1379 |
typedef Parent::NodeNotifier NodeNotifier; |
| 1360 | 1380 |
|
| 1361 | 1381 |
class NodeObserverProxy : public NodeNotifier::ObserverBase {
|
| 1362 | 1382 |
public: |
| ... | ... |
@@ -149,96 +149,98 @@ |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 | 151 |
static void next(Node& node) {
|
| 152 | 152 |
--node._id; |
| 153 | 153 |
} |
| 154 | 154 |
|
| 155 | 155 |
void first(Arc& arc) const {
|
| 156 | 156 |
arc._id = arcs.size() - 1; |
| 157 | 157 |
} |
| 158 | 158 |
|
| 159 | 159 |
static void next(Arc& arc) {
|
| 160 | 160 |
--arc._id; |
| 161 | 161 |
} |
| 162 | 162 |
|
| 163 | 163 |
void firstOut(Arc& arc, const Node& node) const {
|
| 164 | 164 |
arc._id = nodes[node._id].first_out; |
| 165 | 165 |
} |
| 166 | 166 |
|
| 167 | 167 |
void nextOut(Arc& arc) const {
|
| 168 | 168 |
arc._id = arcs[arc._id].next_out; |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
void firstIn(Arc& arc, const Node& node) const {
|
| 172 | 172 |
arc._id = nodes[node._id].first_in; |
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 | 175 |
void nextIn(Arc& arc) const {
|
| 176 | 176 |
arc._id = arcs[arc._id].next_in; |
| 177 | 177 |
} |
| 178 | 178 |
|
| 179 | 179 |
}; |
| 180 | 180 |
|
| 181 | 181 |
typedef DigraphExtender<SmartDigraphBase> ExtendedSmartDigraphBase; |
| 182 | 182 |
|
| 183 | 183 |
///\ingroup graphs |
| 184 | 184 |
/// |
| 185 | 185 |
///\brief A smart directed graph class. |
| 186 | 186 |
/// |
| 187 | 187 |
///\ref SmartDigraph is a simple and fast digraph implementation. |
| 188 | 188 |
///It is also quite memory efficient but at the price |
| 189 | 189 |
///that it does not support node and arc deletion |
| 190 | 190 |
///(except for the Snapshot feature). |
| 191 | 191 |
/// |
| 192 | 192 |
///This type fully conforms to the \ref concepts::Digraph "Digraph concept" |
| 193 | 193 |
///and it also provides some additional functionalities. |
| 194 | 194 |
///Most of its member functions and nested classes are documented |
| 195 | 195 |
///only in the concept class. |
| 196 | 196 |
/// |
| 197 |
///This class provides constant time counting for nodes and arcs. |
|
| 198 |
/// |
|
| 197 | 199 |
///\sa concepts::Digraph |
| 198 | 200 |
///\sa SmartGraph |
| 199 | 201 |
class SmartDigraph : public ExtendedSmartDigraphBase {
|
| 200 | 202 |
typedef ExtendedSmartDigraphBase Parent; |
| 201 | 203 |
|
| 202 | 204 |
private: |
| 203 | 205 |
/// Digraphs are \e not copy constructible. Use DigraphCopy instead. |
| 204 | 206 |
SmartDigraph(const SmartDigraph &) : ExtendedSmartDigraphBase() {};
|
| 205 | 207 |
/// \brief Assignment of a digraph to another one is \e not allowed. |
| 206 | 208 |
/// Use DigraphCopy instead. |
| 207 | 209 |
void operator=(const SmartDigraph &) {}
|
| 208 | 210 |
|
| 209 | 211 |
public: |
| 210 | 212 |
|
| 211 | 213 |
/// Constructor |
| 212 | 214 |
|
| 213 | 215 |
/// Constructor. |
| 214 | 216 |
/// |
| 215 | 217 |
SmartDigraph() {};
|
| 216 | 218 |
|
| 217 | 219 |
///Add a new node to the digraph. |
| 218 | 220 |
|
| 219 | 221 |
///This function adds a new node to the digraph. |
| 220 | 222 |
///\return The new node. |
| 221 | 223 |
Node addNode() { return Parent::addNode(); }
|
| 222 | 224 |
|
| 223 | 225 |
///Add a new arc to the digraph. |
| 224 | 226 |
|
| 225 | 227 |
///This function adds a new arc to the digraph with source node \c s |
| 226 | 228 |
///and target node \c t. |
| 227 | 229 |
///\return The new arc. |
| 228 | 230 |
Arc addArc(Node s, Node t) {
|
| 229 | 231 |
return Parent::addArc(s, t); |
| 230 | 232 |
} |
| 231 | 233 |
|
| 232 | 234 |
/// \brief Node validity check |
| 233 | 235 |
/// |
| 234 | 236 |
/// This function gives back \c true if the given node is valid, |
| 235 | 237 |
/// i.e. it is a real node of the digraph. |
| 236 | 238 |
/// |
| 237 | 239 |
/// \warning A removed node (using Snapshot) could become valid again |
| 238 | 240 |
/// if new nodes are added to the digraph. |
| 239 | 241 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 240 | 242 |
|
| 241 | 243 |
/// \brief Arc validity check |
| 242 | 244 |
/// |
| 243 | 245 |
/// This function gives back \c true if the given arc is valid, |
| 244 | 246 |
/// i.e. it is a real arc of the digraph. |
| ... | ... |
@@ -575,96 +577,98 @@ |
| 575 | 577 |
Node addNode() {
|
| 576 | 578 |
int n = nodes.size(); |
| 577 | 579 |
nodes.push_back(NodeT()); |
| 578 | 580 |
nodes[n].first_out = -1; |
| 579 | 581 |
|
| 580 | 582 |
return Node(n); |
| 581 | 583 |
} |
| 582 | 584 |
|
| 583 | 585 |
Edge addEdge(Node u, Node v) {
|
| 584 | 586 |
int n = arcs.size(); |
| 585 | 587 |
arcs.push_back(ArcT()); |
| 586 | 588 |
arcs.push_back(ArcT()); |
| 587 | 589 |
|
| 588 | 590 |
arcs[n].target = u._id; |
| 589 | 591 |
arcs[n | 1].target = v._id; |
| 590 | 592 |
|
| 591 | 593 |
arcs[n].next_out = nodes[v._id].first_out; |
| 592 | 594 |
nodes[v._id].first_out = n; |
| 593 | 595 |
|
| 594 | 596 |
arcs[n | 1].next_out = nodes[u._id].first_out; |
| 595 | 597 |
nodes[u._id].first_out = (n | 1); |
| 596 | 598 |
|
| 597 | 599 |
return Edge(n / 2); |
| 598 | 600 |
} |
| 599 | 601 |
|
| 600 | 602 |
void clear() {
|
| 601 | 603 |
arcs.clear(); |
| 602 | 604 |
nodes.clear(); |
| 603 | 605 |
} |
| 604 | 606 |
|
| 605 | 607 |
}; |
| 606 | 608 |
|
| 607 | 609 |
typedef GraphExtender<SmartGraphBase> ExtendedSmartGraphBase; |
| 608 | 610 |
|
| 609 | 611 |
/// \ingroup graphs |
| 610 | 612 |
/// |
| 611 | 613 |
/// \brief A smart undirected graph class. |
| 612 | 614 |
/// |
| 613 | 615 |
/// \ref SmartGraph is a simple and fast graph implementation. |
| 614 | 616 |
/// It is also quite memory efficient but at the price |
| 615 | 617 |
/// that it does not support node and edge deletion |
| 616 | 618 |
/// (except for the Snapshot feature). |
| 617 | 619 |
/// |
| 618 | 620 |
/// This type fully conforms to the \ref concepts::Graph "Graph concept" |
| 619 | 621 |
/// and it also provides some additional functionalities. |
| 620 | 622 |
/// Most of its member functions and nested classes are documented |
| 621 | 623 |
/// only in the concept class. |
| 622 | 624 |
/// |
| 625 |
/// This class provides constant time counting for nodes, edges and arcs. |
|
| 626 |
/// |
|
| 623 | 627 |
/// \sa concepts::Graph |
| 624 | 628 |
/// \sa SmartDigraph |
| 625 | 629 |
class SmartGraph : public ExtendedSmartGraphBase {
|
| 626 | 630 |
typedef ExtendedSmartGraphBase Parent; |
| 627 | 631 |
|
| 628 | 632 |
private: |
| 629 | 633 |
/// Graphs are \e not copy constructible. Use GraphCopy instead. |
| 630 | 634 |
SmartGraph(const SmartGraph &) : ExtendedSmartGraphBase() {};
|
| 631 | 635 |
/// \brief Assignment of a graph to another one is \e not allowed. |
| 632 | 636 |
/// Use GraphCopy instead. |
| 633 | 637 |
void operator=(const SmartGraph &) {}
|
| 634 | 638 |
|
| 635 | 639 |
public: |
| 636 | 640 |
|
| 637 | 641 |
/// Constructor |
| 638 | 642 |
|
| 639 | 643 |
/// Constructor. |
| 640 | 644 |
/// |
| 641 | 645 |
SmartGraph() {}
|
| 642 | 646 |
|
| 643 | 647 |
/// \brief Add a new node to the graph. |
| 644 | 648 |
/// |
| 645 | 649 |
/// This function adds a new node to the graph. |
| 646 | 650 |
/// \return The new node. |
| 647 | 651 |
Node addNode() { return Parent::addNode(); }
|
| 648 | 652 |
|
| 649 | 653 |
/// \brief Add a new edge to the graph. |
| 650 | 654 |
/// |
| 651 | 655 |
/// This function adds a new edge to the graph between nodes |
| 652 | 656 |
/// \c u and \c v with inherent orientation from node \c u to |
| 653 | 657 |
/// node \c v. |
| 654 | 658 |
/// \return The new edge. |
| 655 | 659 |
Edge addEdge(Node u, Node v) {
|
| 656 | 660 |
return Parent::addEdge(u, v); |
| 657 | 661 |
} |
| 658 | 662 |
|
| 659 | 663 |
/// \brief Node validity check |
| 660 | 664 |
/// |
| 661 | 665 |
/// This function gives back \c true if the given node is valid, |
| 662 | 666 |
/// i.e. it is a real node of the graph. |
| 663 | 667 |
/// |
| 664 | 668 |
/// \warning A removed node (using Snapshot) could become valid again |
| 665 | 669 |
/// if new nodes are added to the graph. |
| 666 | 670 |
bool valid(Node n) const { return Parent::valid(n); }
|
| 667 | 671 |
|
| 668 | 672 |
/// \brief Edge validity check |
| 669 | 673 |
/// |
| 670 | 674 |
/// This function gives back \c true if the given edge is valid, |
| ... | ... |
@@ -247,96 +247,98 @@ |
| 247 | 247 |
|
| 248 | 248 |
static void fastNextOut(Arc& e) {
|
| 249 | 249 |
++e.id; |
| 250 | 250 |
} |
| 251 | 251 |
void fastLastOut(Arc& e, const Node& n) const {
|
| 252 | 252 |
e.id = node_first_out[n.id + 1]; |
| 253 | 253 |
} |
| 254 | 254 |
|
| 255 | 255 |
protected: |
| 256 | 256 |
bool built; |
| 257 | 257 |
int node_num; |
| 258 | 258 |
int arc_num; |
| 259 | 259 |
int *node_first_out; |
| 260 | 260 |
int *node_first_in; |
| 261 | 261 |
int *arc_source; |
| 262 | 262 |
int *arc_target; |
| 263 | 263 |
int *arc_next_in; |
| 264 | 264 |
int *arc_next_out; |
| 265 | 265 |
}; |
| 266 | 266 |
|
| 267 | 267 |
typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase; |
| 268 | 268 |
|
| 269 | 269 |
|
| 270 | 270 |
/// \ingroup graphs |
| 271 | 271 |
/// |
| 272 | 272 |
/// \brief A static directed graph class. |
| 273 | 273 |
/// |
| 274 | 274 |
/// \ref StaticDigraph is a highly efficient digraph implementation, |
| 275 | 275 |
/// but it is fully static. |
| 276 | 276 |
/// It stores only two \c int values for each node and only four \c int |
| 277 | 277 |
/// values for each arc. Moreover it provides faster item iteration than |
| 278 | 278 |
/// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt |
| 279 | 279 |
/// iterators, since its arcs are stored in an appropriate order. |
| 280 | 280 |
/// However it only provides build() and clear() functions and does not |
| 281 | 281 |
/// support any other modification of the digraph. |
| 282 | 282 |
/// |
| 283 | 283 |
/// Since this digraph structure is completely static, its nodes and arcs |
| 284 | 284 |
/// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt> |
| 285 | 285 |
/// and <tt>[0..arcNum()-1]</tt>, respectively. |
| 286 | 286 |
/// The index of an item is the same as its ID, it can be obtained |
| 287 | 287 |
/// using the corresponding \ref index() or \ref concepts::Digraph::id() |
| 288 | 288 |
/// "id()" function. A node or arc with a certain index can be obtained |
| 289 | 289 |
/// using node() or arc(). |
| 290 | 290 |
/// |
| 291 | 291 |
/// This type fully conforms to the \ref concepts::Digraph "Digraph concept". |
| 292 | 292 |
/// Most of its member functions and nested classes are documented |
| 293 | 293 |
/// only in the concept class. |
| 294 | 294 |
/// |
| 295 |
/// This class provides constant time counting for nodes and arcs. |
|
| 296 |
/// |
|
| 295 | 297 |
/// \sa concepts::Digraph |
| 296 | 298 |
class StaticDigraph : public ExtendedStaticDigraphBase {
|
| 297 | 299 |
public: |
| 298 | 300 |
|
| 299 | 301 |
typedef ExtendedStaticDigraphBase Parent; |
| 300 | 302 |
|
| 301 | 303 |
public: |
| 302 | 304 |
|
| 303 | 305 |
/// \brief Constructor |
| 304 | 306 |
/// |
| 305 | 307 |
/// Default constructor. |
| 306 | 308 |
StaticDigraph() : Parent() {}
|
| 307 | 309 |
|
| 308 | 310 |
/// \brief The node with the given index. |
| 309 | 311 |
/// |
| 310 | 312 |
/// This function returns the node with the given index. |
| 311 | 313 |
/// \sa index() |
| 312 | 314 |
static Node node(int ix) { return Parent::nodeFromId(ix); }
|
| 313 | 315 |
|
| 314 | 316 |
/// \brief The arc with the given index. |
| 315 | 317 |
/// |
| 316 | 318 |
/// This function returns the arc with the given index. |
| 317 | 319 |
/// \sa index() |
| 318 | 320 |
static Arc arc(int ix) { return Parent::arcFromId(ix); }
|
| 319 | 321 |
|
| 320 | 322 |
/// \brief The index of the given node. |
| 321 | 323 |
/// |
| 322 | 324 |
/// This function returns the index of the the given node. |
| 323 | 325 |
/// \sa node() |
| 324 | 326 |
static int index(Node node) { return Parent::id(node); }
|
| 325 | 327 |
|
| 326 | 328 |
/// \brief The index of the given arc. |
| 327 | 329 |
/// |
| 328 | 330 |
/// This function returns the index of the the given arc. |
| 329 | 331 |
/// \sa arc() |
| 330 | 332 |
static int index(Arc arc) { return Parent::id(arc); }
|
| 331 | 333 |
|
| 332 | 334 |
/// \brief Number of nodes. |
| 333 | 335 |
/// |
| 334 | 336 |
/// This function returns the number of nodes. |
| 335 | 337 |
int nodeNum() const { return node_num; }
|
| 336 | 338 |
|
| 337 | 339 |
/// \brief Number of arcs. |
| 338 | 340 |
/// |
| 339 | 341 |
/// This function returns the number of arcs. |
| 340 | 342 |
int arcNum() const { return arc_num; }
|
| 341 | 343 |
|
| 342 | 344 |
/// \brief Build the digraph copying another digraph. |
0 comments (0 inline)