0
2
0
| ... | ... |
@@ -2645,145 +2645,145 @@ |
| 2645 | 2645 |
private: |
| 2646 | 2646 |
|
| 2647 | 2647 |
const CapacityMap* _capacity; |
| 2648 | 2648 |
const FlowMap* _flow; |
| 2649 | 2649 |
Tolerance _tolerance; |
| 2650 | 2650 |
|
| 2651 | 2651 |
public: |
| 2652 | 2652 |
|
| 2653 | 2653 |
ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow, |
| 2654 | 2654 |
const Tolerance& tolerance = Tolerance()) |
| 2655 | 2655 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
| 2656 | 2656 |
|
| 2657 | 2657 |
bool operator[](const typename Digraph::Arc& a) const {
|
| 2658 | 2658 |
return _tolerance.positive((*_flow)[a]); |
| 2659 | 2659 |
} |
| 2660 | 2660 |
}; |
| 2661 | 2661 |
|
| 2662 | 2662 |
} |
| 2663 | 2663 |
|
| 2664 | 2664 |
/// \ingroup graph_adaptors |
| 2665 | 2665 |
/// |
| 2666 | 2666 |
/// \brief Adaptor class for composing the residual digraph for directed |
| 2667 | 2667 |
/// flow and circulation problems. |
| 2668 | 2668 |
/// |
| 2669 |
/// Residual can be used for composing the \e residual digraph for directed |
|
| 2670 |
/// flow and circulation problems. Let \f$ G=(V, A) \f$ be a directed graph |
|
| 2671 |
/// and let \f$ F \f$ be a number type. Let \f$ flow, cap: A\to F \f$ be |
|
| 2672 |
/// functions on the arcs. |
|
| 2669 |
/// ResidualDigraph can be used for composing the \e residual digraph |
|
| 2670 |
/// for directed flow and circulation problems. Let \f$ G=(V, A) \f$ |
|
| 2671 |
/// be a directed graph and let \f$ F \f$ be a number type. |
|
| 2672 |
/// Let \f$ flow, cap: A\to F \f$ be functions on the arcs. |
|
| 2673 | 2673 |
/// This adaptor implements a digraph structure with node set \f$ V \f$ |
| 2674 | 2674 |
/// and arc set \f$ A_{forward}\cup A_{backward} \f$,
|
| 2675 | 2675 |
/// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and
|
| 2676 | 2676 |
/// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so
|
| 2677 | 2677 |
/// called residual digraph. |
| 2678 | 2678 |
/// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken,
|
| 2679 | 2679 |
/// multiplicities are counted, i.e. the adaptor has exactly |
| 2680 | 2680 |
/// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel
|
| 2681 | 2681 |
/// arcs). |
| 2682 | 2682 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept. |
| 2683 | 2683 |
/// |
| 2684 | 2684 |
/// \tparam GR The type of the adapted digraph. |
| 2685 | 2685 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 2686 | 2686 |
/// It is implicitly \c const. |
| 2687 | 2687 |
/// \tparam CM The type of the capacity map. |
| 2688 | 2688 |
/// It must be an arc map of some numerical type, which defines |
| 2689 | 2689 |
/// the capacities in the flow problem. It is implicitly \c const. |
| 2690 | 2690 |
/// The default type is |
| 2691 | 2691 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>". |
| 2692 | 2692 |
/// \tparam FM The type of the flow map. |
| 2693 | 2693 |
/// It must be an arc map of some numerical type, which defines |
| 2694 | 2694 |
/// the flow values in the flow problem. The default type is \c CM. |
| 2695 | 2695 |
/// \tparam TL The tolerance type for handling inexact computation. |
| 2696 | 2696 |
/// The default tolerance type depends on the value type of the |
| 2697 | 2697 |
/// capacity map. |
| 2698 | 2698 |
/// |
| 2699 | 2699 |
/// \note This adaptor is implemented using Undirector and FilterArcs |
| 2700 | 2700 |
/// adaptors. |
| 2701 | 2701 |
/// |
| 2702 | 2702 |
/// \note The \c Node type of this adaptor and the adapted digraph are |
| 2703 | 2703 |
/// convertible to each other, moreover the \c Arc type of the adaptor |
| 2704 | 2704 |
/// is convertible to the \c Arc type of the adapted digraph. |
| 2705 | 2705 |
#ifdef DOXYGEN |
| 2706 | 2706 |
template<typename GR, typename CM, typename FM, typename TL> |
| 2707 |
class |
|
| 2707 |
class ResidualDigraph |
|
| 2708 | 2708 |
#else |
| 2709 | 2709 |
template<typename GR, |
| 2710 | 2710 |
typename CM = typename GR::template ArcMap<int>, |
| 2711 | 2711 |
typename FM = CM, |
| 2712 | 2712 |
typename TL = Tolerance<typename CM::Value> > |
| 2713 |
class |
|
| 2713 |
class ResidualDigraph : |
|
| 2714 | 2714 |
public FilterArcs< |
| 2715 | 2715 |
Undirector<const GR>, |
| 2716 | 2716 |
typename Undirector<const GR>::template CombinedArcMap< |
| 2717 | 2717 |
_adaptor_bits::ResForwardFilter<const GR, CM, FM, TL>, |
| 2718 | 2718 |
_adaptor_bits::ResBackwardFilter<const GR, CM, FM, TL> > > |
| 2719 | 2719 |
#endif |
| 2720 | 2720 |
{
|
| 2721 | 2721 |
public: |
| 2722 | 2722 |
|
| 2723 | 2723 |
/// The type of the underlying digraph. |
| 2724 | 2724 |
typedef GR Digraph; |
| 2725 | 2725 |
/// The type of the capacity map. |
| 2726 | 2726 |
typedef CM CapacityMap; |
| 2727 | 2727 |
/// The type of the flow map. |
| 2728 | 2728 |
typedef FM FlowMap; |
| 2729 | 2729 |
/// The tolerance type. |
| 2730 | 2730 |
typedef TL Tolerance; |
| 2731 | 2731 |
|
| 2732 | 2732 |
typedef typename CapacityMap::Value Value; |
| 2733 |
typedef |
|
| 2733 |
typedef ResidualDigraph Adaptor; |
|
| 2734 | 2734 |
|
| 2735 | 2735 |
protected: |
| 2736 | 2736 |
|
| 2737 | 2737 |
typedef Undirector<const Digraph> Undirected; |
| 2738 | 2738 |
|
| 2739 | 2739 |
typedef _adaptor_bits::ResForwardFilter<const Digraph, CapacityMap, |
| 2740 | 2740 |
FlowMap, Tolerance> ForwardFilter; |
| 2741 | 2741 |
|
| 2742 | 2742 |
typedef _adaptor_bits::ResBackwardFilter<const Digraph, CapacityMap, |
| 2743 | 2743 |
FlowMap, Tolerance> BackwardFilter; |
| 2744 | 2744 |
|
| 2745 | 2745 |
typedef typename Undirected:: |
| 2746 | 2746 |
template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter; |
| 2747 | 2747 |
|
| 2748 | 2748 |
typedef FilterArcs<Undirected, ArcFilter> Parent; |
| 2749 | 2749 |
|
| 2750 | 2750 |
const CapacityMap* _capacity; |
| 2751 | 2751 |
FlowMap* _flow; |
| 2752 | 2752 |
|
| 2753 | 2753 |
Undirected _graph; |
| 2754 | 2754 |
ForwardFilter _forward_filter; |
| 2755 | 2755 |
BackwardFilter _backward_filter; |
| 2756 | 2756 |
ArcFilter _arc_filter; |
| 2757 | 2757 |
|
| 2758 | 2758 |
public: |
| 2759 | 2759 |
|
| 2760 | 2760 |
/// \brief Constructor |
| 2761 | 2761 |
/// |
| 2762 | 2762 |
/// Constructor of the residual digraph adaptor. The parameters are the |
| 2763 | 2763 |
/// digraph, the capacity map, the flow map, and a tolerance object. |
| 2764 |
Residual(const Digraph& digraph, const CapacityMap& capacity, |
|
| 2765 |
FlowMap& flow, const Tolerance& tolerance = Tolerance()) |
|
| 2764 |
ResidualDigraph(const Digraph& digraph, const CapacityMap& capacity, |
|
| 2765 |
FlowMap& flow, const Tolerance& tolerance = Tolerance()) |
|
| 2766 | 2766 |
: Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph), |
| 2767 | 2767 |
_forward_filter(capacity, flow, tolerance), |
| 2768 | 2768 |
_backward_filter(capacity, flow, tolerance), |
| 2769 | 2769 |
_arc_filter(_forward_filter, _backward_filter) |
| 2770 | 2770 |
{
|
| 2771 | 2771 |
Parent::setDigraph(_graph); |
| 2772 | 2772 |
Parent::setArcFilterMap(_arc_filter); |
| 2773 | 2773 |
} |
| 2774 | 2774 |
|
| 2775 | 2775 |
typedef typename Parent::Arc Arc; |
| 2776 | 2776 |
|
| 2777 | 2777 |
/// \brief Returns the residual capacity of the given arc. |
| 2778 | 2778 |
/// |
| 2779 | 2779 |
/// Returns the residual capacity of the given arc. |
| 2780 | 2780 |
Value residualCapacity(const Arc& a) const {
|
| 2781 | 2781 |
if (Undirected::direction(a)) {
|
| 2782 | 2782 |
return (*_capacity)[a] - (*_flow)[a]; |
| 2783 | 2783 |
} else {
|
| 2784 | 2784 |
return (*_flow)[a]; |
| 2785 | 2785 |
} |
| 2786 | 2786 |
} |
| 2787 | 2787 |
|
| 2788 | 2788 |
/// \brief Augments on the given arc in the residual digraph. |
| 2789 | 2789 |
/// |
| ... | ... |
@@ -2848,52 +2848,51 @@ |
| 2848 | 2848 |
ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
|
| 2849 | 2849 |
|
| 2850 | 2850 |
/// Returns the value associated with the given residual arc |
| 2851 | 2851 |
Value operator[](const Arc& a) const {
|
| 2852 | 2852 |
return _adaptor->residualCapacity(a); |
| 2853 | 2853 |
} |
| 2854 | 2854 |
|
| 2855 | 2855 |
}; |
| 2856 | 2856 |
|
| 2857 | 2857 |
/// \brief Returns a residual capacity map |
| 2858 | 2858 |
/// |
| 2859 | 2859 |
/// This function just returns a residual capacity map. |
| 2860 | 2860 |
ResidualCapacity residualCapacity() const {
|
| 2861 | 2861 |
return ResidualCapacity(*this); |
| 2862 | 2862 |
} |
| 2863 | 2863 |
|
| 2864 | 2864 |
}; |
| 2865 | 2865 |
|
| 2866 | 2866 |
/// \brief Returns a (read-only) Residual adaptor |
| 2867 | 2867 |
/// |
| 2868 | 2868 |
/// This function just returns a (read-only) \ref Residual adaptor. |
| 2869 | 2869 |
/// \ingroup graph_adaptors |
| 2870 | 2870 |
/// \relates Residual |
| 2871 | 2871 |
template<typename GR, typename CM, typename FM> |
| 2872 |
Residual<GR, CM, FM> residual(const GR& digraph, |
|
| 2873 |
const CM& capacity_map, |
|
| 2874 |
FM& flow_map) {
|
|
| 2875 |
return Residual<GR, CM, FM> (digraph, capacity_map, flow_map); |
|
| 2872 |
ResidualDigraph<GR, CM, FM> |
|
| 2873 |
residualDigraph(const GR& digraph, const CM& capacity_map, FM& flow_map) {
|
|
| 2874 |
return ResidualDigraph<GR, CM, FM> (digraph, capacity_map, flow_map); |
|
| 2876 | 2875 |
} |
| 2877 | 2876 |
|
| 2878 | 2877 |
|
| 2879 | 2878 |
template <typename _Digraph> |
| 2880 | 2879 |
class SplitNodesBase {
|
| 2881 | 2880 |
public: |
| 2882 | 2881 |
|
| 2883 | 2882 |
typedef _Digraph Digraph; |
| 2884 | 2883 |
typedef DigraphAdaptorBase<const _Digraph> Parent; |
| 2885 | 2884 |
typedef SplitNodesBase Adaptor; |
| 2886 | 2885 |
|
| 2887 | 2886 |
typedef typename Digraph::Node DigraphNode; |
| 2888 | 2887 |
typedef typename Digraph::Arc DigraphArc; |
| 2889 | 2888 |
|
| 2890 | 2889 |
class Node; |
| 2891 | 2890 |
class Arc; |
| 2892 | 2891 |
|
| 2893 | 2892 |
private: |
| 2894 | 2893 |
|
| 2895 | 2894 |
template <typename T> class NodeMapBase; |
| 2896 | 2895 |
template <typename T> class ArcMapBase; |
| 2897 | 2896 |
|
| 2898 | 2897 |
public: |
| 2899 | 2898 |
| ... | ... |
@@ -560,57 +560,57 @@ |
| 560 | 560 |
bk_map[a] = -digraph.id(a); |
| 561 | 561 |
} |
| 562 | 562 |
|
| 563 | 563 |
Adaptor::CombinedArcMap<Digraph::ArcMap<int>, Digraph::ArcMap<int> > |
| 564 | 564 |
comb_map(fw_map, bk_map); |
| 565 | 565 |
for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
|
| 566 | 566 |
if (adaptor.source(a) == digraph.source(a)) {
|
| 567 | 567 |
check(comb_map[a] == fw_map[a], "Wrong combined map"); |
| 568 | 568 |
} else {
|
| 569 | 569 |
check(comb_map[a] == bk_map[a], "Wrong combined map"); |
| 570 | 570 |
} |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 | 573 |
// Check the conversion of nodes and arcs/edges |
| 574 | 574 |
Digraph::Node nd = n3; |
| 575 | 575 |
nd = n3; |
| 576 | 576 |
Adaptor::Node na = n1; |
| 577 | 577 |
na = n2; |
| 578 | 578 |
Digraph::Arc ad = e3; |
| 579 | 579 |
ad = e3; |
| 580 | 580 |
Adaptor::Edge ea = a1; |
| 581 | 581 |
ea = a2; |
| 582 | 582 |
} |
| 583 | 583 |
|
| 584 |
void |
|
| 584 |
void checkResidualDigraph() {
|
|
| 585 | 585 |
// Check concepts |
| 586 |
checkConcept<concepts::Digraph, Residual<concepts::Digraph> >(); |
|
| 587 |
checkConcept<concepts::Digraph, Residual<ListDigraph> >(); |
|
| 586 |
checkConcept<concepts::Digraph, ResidualDigraph<concepts::Digraph> >(); |
|
| 587 |
checkConcept<concepts::Digraph, ResidualDigraph<ListDigraph> >(); |
|
| 588 | 588 |
|
| 589 | 589 |
// Create a digraph and an adaptor |
| 590 | 590 |
typedef ListDigraph Digraph; |
| 591 | 591 |
typedef Digraph::ArcMap<int> IntArcMap; |
| 592 |
typedef |
|
| 592 |
typedef ResidualDigraph<Digraph, IntArcMap> Adaptor; |
|
| 593 | 593 |
|
| 594 | 594 |
Digraph digraph; |
| 595 | 595 |
IntArcMap capacity(digraph), flow(digraph); |
| 596 | 596 |
Adaptor adaptor(digraph, capacity, flow); |
| 597 | 597 |
|
| 598 | 598 |
Digraph::Node n1 = digraph.addNode(); |
| 599 | 599 |
Digraph::Node n2 = digraph.addNode(); |
| 600 | 600 |
Digraph::Node n3 = digraph.addNode(); |
| 601 | 601 |
Digraph::Node n4 = digraph.addNode(); |
| 602 | 602 |
|
| 603 | 603 |
Digraph::Arc a1 = digraph.addArc(n1, n2); |
| 604 | 604 |
Digraph::Arc a2 = digraph.addArc(n1, n3); |
| 605 | 605 |
Digraph::Arc a3 = digraph.addArc(n1, n4); |
| 606 | 606 |
Digraph::Arc a4 = digraph.addArc(n2, n3); |
| 607 | 607 |
Digraph::Arc a5 = digraph.addArc(n2, n4); |
| 608 | 608 |
Digraph::Arc a6 = digraph.addArc(n3, n4); |
| 609 | 609 |
|
| 610 | 610 |
capacity[a1] = 8; |
| 611 | 611 |
capacity[a2] = 6; |
| 612 | 612 |
capacity[a3] = 4; |
| 613 | 613 |
capacity[a4] = 4; |
| 614 | 614 |
capacity[a5] = 6; |
| 615 | 615 |
capacity[a6] = 10; |
| 616 | 616 |
|
| ... | ... |
@@ -1449,38 +1449,38 @@ |
| 1449 | 1449 |
|
| 1450 | 1450 |
// Check uuadaptor |
| 1451 | 1451 |
checkGraphNodeList(uuadaptor, 8); |
| 1452 | 1452 |
checkGraphEdgeList(uuadaptor, 16); |
| 1453 | 1453 |
checkGraphArcList(uuadaptor, 32); |
| 1454 | 1454 |
checkGraphConEdgeList(uuadaptor, 16); |
| 1455 | 1455 |
checkGraphConArcList(uuadaptor, 32); |
| 1456 | 1456 |
|
| 1457 | 1457 |
checkNodeIds(uuadaptor); |
| 1458 | 1458 |
checkEdgeIds(uuadaptor); |
| 1459 | 1459 |
checkArcIds(uuadaptor); |
| 1460 | 1460 |
|
| 1461 | 1461 |
checkGraphNodeMap(uuadaptor); |
| 1462 | 1462 |
checkGraphEdgeMap(uuadaptor); |
| 1463 | 1463 |
checkGraphArcMap(uuadaptor); |
| 1464 | 1464 |
} |
| 1465 | 1465 |
|
| 1466 | 1466 |
int main(int, const char **) {
|
| 1467 | 1467 |
// Check the digraph adaptors (using ListDigraph) |
| 1468 | 1468 |
checkReverseDigraph(); |
| 1469 | 1469 |
checkSubDigraph(); |
| 1470 | 1470 |
checkFilterNodes1(); |
| 1471 | 1471 |
checkFilterArcs(); |
| 1472 | 1472 |
checkUndirector(); |
| 1473 |
|
|
| 1473 |
checkResidualDigraph(); |
|
| 1474 | 1474 |
checkSplitNodes(); |
| 1475 | 1475 |
|
| 1476 | 1476 |
// Check the graph adaptors (using ListGraph) |
| 1477 | 1477 |
checkSubGraph(); |
| 1478 | 1478 |
checkFilterNodes2(); |
| 1479 | 1479 |
checkFilterEdges(); |
| 1480 | 1480 |
checkOrienter(); |
| 1481 | 1481 |
|
| 1482 | 1482 |
// Combine adaptors (using GridGraph) |
| 1483 | 1483 |
checkCombiningAdaptors(); |
| 1484 | 1484 |
|
| 1485 | 1485 |
return 0; |
| 1486 | 1486 |
} |
0 comments (0 inline)