| ... | ... |
@@ -2814,781 +2814,781 @@ |
| 2814 | 2814 |
/// arc of the underlying digraph. |
| 2815 | 2815 |
static Arc backward(const typename Digraph::Arc& a) {
|
| 2816 | 2816 |
return Undirected::direct(a, false); |
| 2817 | 2817 |
} |
| 2818 | 2818 |
|
| 2819 | 2819 |
/// \brief Residual capacity map. |
| 2820 | 2820 |
/// |
| 2821 | 2821 |
/// This map adaptor class can be used for obtaining the residual |
| 2822 | 2822 |
/// capacities as an arc map of the residual digraph. |
| 2823 | 2823 |
/// Its value type is inherited from the capacity map. |
| 2824 | 2824 |
class ResidualCapacity {
|
| 2825 | 2825 |
protected: |
| 2826 | 2826 |
const Adaptor* _adaptor; |
| 2827 | 2827 |
public: |
| 2828 | 2828 |
/// The key type of the map |
| 2829 | 2829 |
typedef Arc Key; |
| 2830 | 2830 |
/// The value type of the map |
| 2831 | 2831 |
typedef typename CapacityMap::Value Value; |
| 2832 | 2832 |
|
| 2833 | 2833 |
/// Constructor |
| 2834 | 2834 |
ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) |
| 2835 | 2835 |
: _adaptor(&adaptor) {}
|
| 2836 | 2836 |
|
| 2837 | 2837 |
/// Returns the value associated with the given residual arc |
| 2838 | 2838 |
Value operator[](const Arc& a) const {
|
| 2839 | 2839 |
return _adaptor->residualCapacity(a); |
| 2840 | 2840 |
} |
| 2841 | 2841 |
|
| 2842 | 2842 |
}; |
| 2843 | 2843 |
|
| 2844 | 2844 |
/// \brief Returns a residual capacity map |
| 2845 | 2845 |
/// |
| 2846 | 2846 |
/// This function just returns a residual capacity map. |
| 2847 | 2847 |
ResidualCapacity residualCapacity() const {
|
| 2848 | 2848 |
return ResidualCapacity(*this); |
| 2849 | 2849 |
} |
| 2850 | 2850 |
|
| 2851 | 2851 |
}; |
| 2852 | 2852 |
|
| 2853 | 2853 |
/// \brief Returns a (read-only) Residual adaptor |
| 2854 | 2854 |
/// |
| 2855 | 2855 |
/// This function just returns a (read-only) \ref ResidualDigraph adaptor. |
| 2856 | 2856 |
/// \ingroup graph_adaptors |
| 2857 | 2857 |
/// \relates ResidualDigraph |
| 2858 | 2858 |
template<typename DGR, typename CM, typename FM> |
| 2859 | 2859 |
ResidualDigraph<DGR, CM, FM> |
| 2860 | 2860 |
residualDigraph(const DGR& digraph, const CM& capacity_map, FM& flow_map) {
|
| 2861 | 2861 |
return ResidualDigraph<DGR, CM, FM> (digraph, capacity_map, flow_map); |
| 2862 | 2862 |
} |
| 2863 | 2863 |
|
| 2864 | 2864 |
|
| 2865 | 2865 |
template <typename DGR> |
| 2866 | 2866 |
class SplitNodesBase {
|
| 2867 | 2867 |
public: |
| 2868 | 2868 |
|
| 2869 | 2869 |
typedef DGR Digraph; |
| 2870 | 2870 |
typedef DigraphAdaptorBase<const DGR> Parent; |
| 2871 | 2871 |
typedef SplitNodesBase Adaptor; |
| 2872 | 2872 |
|
| 2873 | 2873 |
typedef typename DGR::Node DigraphNode; |
| 2874 | 2874 |
typedef typename DGR::Arc DigraphArc; |
| 2875 | 2875 |
|
| 2876 | 2876 |
class Node; |
| 2877 | 2877 |
class Arc; |
| 2878 | 2878 |
|
| 2879 | 2879 |
private: |
| 2880 | 2880 |
|
| 2881 | 2881 |
template <typename T> class NodeMapBase; |
| 2882 | 2882 |
template <typename T> class ArcMapBase; |
| 2883 | 2883 |
|
| 2884 | 2884 |
public: |
| 2885 | 2885 |
|
| 2886 | 2886 |
class Node : public DigraphNode {
|
| 2887 | 2887 |
friend class SplitNodesBase; |
| 2888 | 2888 |
template <typename T> friend class NodeMapBase; |
| 2889 | 2889 |
private: |
| 2890 | 2890 |
|
| 2891 | 2891 |
bool _in; |
| 2892 | 2892 |
Node(DigraphNode node, bool in) |
| 2893 | 2893 |
: DigraphNode(node), _in(in) {}
|
| 2894 | 2894 |
|
| 2895 | 2895 |
public: |
| 2896 | 2896 |
|
| 2897 | 2897 |
Node() {}
|
| 2898 | 2898 |
Node(Invalid) : DigraphNode(INVALID), _in(true) {}
|
| 2899 | 2899 |
|
| 2900 | 2900 |
bool operator==(const Node& node) const {
|
| 2901 | 2901 |
return DigraphNode::operator==(node) && _in == node._in; |
| 2902 | 2902 |
} |
| 2903 | 2903 |
|
| 2904 | 2904 |
bool operator!=(const Node& node) const {
|
| 2905 | 2905 |
return !(*this == node); |
| 2906 | 2906 |
} |
| 2907 | 2907 |
|
| 2908 | 2908 |
bool operator<(const Node& node) const {
|
| 2909 | 2909 |
return DigraphNode::operator<(node) || |
| 2910 | 2910 |
(DigraphNode::operator==(node) && _in < node._in); |
| 2911 | 2911 |
} |
| 2912 | 2912 |
}; |
| 2913 | 2913 |
|
| 2914 | 2914 |
class Arc {
|
| 2915 | 2915 |
friend class SplitNodesBase; |
| 2916 | 2916 |
template <typename T> friend class ArcMapBase; |
| 2917 | 2917 |
private: |
| 2918 | 2918 |
typedef BiVariant<DigraphArc, DigraphNode> ArcImpl; |
| 2919 | 2919 |
|
| 2920 | 2920 |
explicit Arc(const DigraphArc& arc) : _item(arc) {}
|
| 2921 | 2921 |
explicit Arc(const DigraphNode& node) : _item(node) {}
|
| 2922 | 2922 |
|
| 2923 | 2923 |
ArcImpl _item; |
| 2924 | 2924 |
|
| 2925 | 2925 |
public: |
| 2926 | 2926 |
Arc() {}
|
| 2927 | 2927 |
Arc(Invalid) : _item(DigraphArc(INVALID)) {}
|
| 2928 | 2928 |
|
| 2929 | 2929 |
bool operator==(const Arc& arc) const {
|
| 2930 | 2930 |
if (_item.firstState()) {
|
| 2931 | 2931 |
if (arc._item.firstState()) {
|
| 2932 | 2932 |
return _item.first() == arc._item.first(); |
| 2933 | 2933 |
} |
| 2934 | 2934 |
} else {
|
| 2935 | 2935 |
if (arc._item.secondState()) {
|
| 2936 | 2936 |
return _item.second() == arc._item.second(); |
| 2937 | 2937 |
} |
| 2938 | 2938 |
} |
| 2939 | 2939 |
return false; |
| 2940 | 2940 |
} |
| 2941 | 2941 |
|
| 2942 | 2942 |
bool operator!=(const Arc& arc) const {
|
| 2943 | 2943 |
return !(*this == arc); |
| 2944 | 2944 |
} |
| 2945 | 2945 |
|
| 2946 | 2946 |
bool operator<(const Arc& arc) const {
|
| 2947 | 2947 |
if (_item.firstState()) {
|
| 2948 | 2948 |
if (arc._item.firstState()) {
|
| 2949 | 2949 |
return _item.first() < arc._item.first(); |
| 2950 | 2950 |
} |
| 2951 | 2951 |
return false; |
| 2952 | 2952 |
} else {
|
| 2953 | 2953 |
if (arc._item.secondState()) {
|
| 2954 | 2954 |
return _item.second() < arc._item.second(); |
| 2955 | 2955 |
} |
| 2956 | 2956 |
return true; |
| 2957 | 2957 |
} |
| 2958 | 2958 |
} |
| 2959 | 2959 |
|
| 2960 | 2960 |
operator DigraphArc() const { return _item.first(); }
|
| 2961 | 2961 |
operator DigraphNode() const { return _item.second(); }
|
| 2962 | 2962 |
|
| 2963 | 2963 |
}; |
| 2964 | 2964 |
|
| 2965 | 2965 |
void first(Node& n) const {
|
| 2966 | 2966 |
_digraph->first(n); |
| 2967 | 2967 |
n._in = true; |
| 2968 | 2968 |
} |
| 2969 | 2969 |
|
| 2970 | 2970 |
void next(Node& n) const {
|
| 2971 | 2971 |
if (n._in) {
|
| 2972 | 2972 |
n._in = false; |
| 2973 | 2973 |
} else {
|
| 2974 | 2974 |
n._in = true; |
| 2975 | 2975 |
_digraph->next(n); |
| 2976 | 2976 |
} |
| 2977 | 2977 |
} |
| 2978 | 2978 |
|
| 2979 | 2979 |
void first(Arc& e) const {
|
| 2980 | 2980 |
e._item.setSecond(); |
| 2981 | 2981 |
_digraph->first(e._item.second()); |
| 2982 | 2982 |
if (e._item.second() == INVALID) {
|
| 2983 | 2983 |
e._item.setFirst(); |
| 2984 | 2984 |
_digraph->first(e._item.first()); |
| 2985 | 2985 |
} |
| 2986 | 2986 |
} |
| 2987 | 2987 |
|
| 2988 | 2988 |
void next(Arc& e) const {
|
| 2989 | 2989 |
if (e._item.secondState()) {
|
| 2990 | 2990 |
_digraph->next(e._item.second()); |
| 2991 | 2991 |
if (e._item.second() == INVALID) {
|
| 2992 | 2992 |
e._item.setFirst(); |
| 2993 | 2993 |
_digraph->first(e._item.first()); |
| 2994 | 2994 |
} |
| 2995 | 2995 |
} else {
|
| 2996 | 2996 |
_digraph->next(e._item.first()); |
| 2997 | 2997 |
} |
| 2998 | 2998 |
} |
| 2999 | 2999 |
|
| 3000 | 3000 |
void firstOut(Arc& e, const Node& n) const {
|
| 3001 | 3001 |
if (n._in) {
|
| 3002 | 3002 |
e._item.setSecond(n); |
| 3003 | 3003 |
} else {
|
| 3004 | 3004 |
e._item.setFirst(); |
| 3005 | 3005 |
_digraph->firstOut(e._item.first(), n); |
| 3006 | 3006 |
} |
| 3007 | 3007 |
} |
| 3008 | 3008 |
|
| 3009 | 3009 |
void nextOut(Arc& e) const {
|
| 3010 | 3010 |
if (!e._item.firstState()) {
|
| 3011 | 3011 |
e._item.setFirst(INVALID); |
| 3012 | 3012 |
} else {
|
| 3013 | 3013 |
_digraph->nextOut(e._item.first()); |
| 3014 | 3014 |
} |
| 3015 | 3015 |
} |
| 3016 | 3016 |
|
| 3017 | 3017 |
void firstIn(Arc& e, const Node& n) const {
|
| 3018 | 3018 |
if (!n._in) {
|
| 3019 | 3019 |
e._item.setSecond(n); |
| 3020 | 3020 |
} else {
|
| 3021 | 3021 |
e._item.setFirst(); |
| 3022 | 3022 |
_digraph->firstIn(e._item.first(), n); |
| 3023 | 3023 |
} |
| 3024 | 3024 |
} |
| 3025 | 3025 |
|
| 3026 | 3026 |
void nextIn(Arc& e) const {
|
| 3027 | 3027 |
if (!e._item.firstState()) {
|
| 3028 | 3028 |
e._item.setFirst(INVALID); |
| 3029 | 3029 |
} else {
|
| 3030 | 3030 |
_digraph->nextIn(e._item.first()); |
| 3031 | 3031 |
} |
| 3032 | 3032 |
} |
| 3033 | 3033 |
|
| 3034 | 3034 |
Node source(const Arc& e) const {
|
| 3035 | 3035 |
if (e._item.firstState()) {
|
| 3036 | 3036 |
return Node(_digraph->source(e._item.first()), false); |
| 3037 | 3037 |
} else {
|
| 3038 | 3038 |
return Node(e._item.second(), true); |
| 3039 | 3039 |
} |
| 3040 | 3040 |
} |
| 3041 | 3041 |
|
| 3042 | 3042 |
Node target(const Arc& e) const {
|
| 3043 | 3043 |
if (e._item.firstState()) {
|
| 3044 | 3044 |
return Node(_digraph->target(e._item.first()), true); |
| 3045 | 3045 |
} else {
|
| 3046 | 3046 |
return Node(e._item.second(), false); |
| 3047 | 3047 |
} |
| 3048 | 3048 |
} |
| 3049 | 3049 |
|
| 3050 | 3050 |
int id(const Node& n) const {
|
| 3051 | 3051 |
return (_digraph->id(n) << 1) | (n._in ? 0 : 1); |
| 3052 | 3052 |
} |
| 3053 | 3053 |
Node nodeFromId(int ix) const {
|
| 3054 | 3054 |
return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0); |
| 3055 | 3055 |
} |
| 3056 | 3056 |
int maxNodeId() const {
|
| 3057 | 3057 |
return 2 * _digraph->maxNodeId() + 1; |
| 3058 | 3058 |
} |
| 3059 | 3059 |
|
| 3060 | 3060 |
int id(const Arc& e) const {
|
| 3061 | 3061 |
if (e._item.firstState()) {
|
| 3062 | 3062 |
return _digraph->id(e._item.first()) << 1; |
| 3063 | 3063 |
} else {
|
| 3064 | 3064 |
return (_digraph->id(e._item.second()) << 1) | 1; |
| 3065 | 3065 |
} |
| 3066 | 3066 |
} |
| 3067 | 3067 |
Arc arcFromId(int ix) const {
|
| 3068 | 3068 |
if ((ix & 1) == 0) {
|
| 3069 | 3069 |
return Arc(_digraph->arcFromId(ix >> 1)); |
| 3070 | 3070 |
} else {
|
| 3071 | 3071 |
return Arc(_digraph->nodeFromId(ix >> 1)); |
| 3072 | 3072 |
} |
| 3073 | 3073 |
} |
| 3074 | 3074 |
int maxArcId() const {
|
| 3075 | 3075 |
return std::max(_digraph->maxNodeId() << 1, |
| 3076 | 3076 |
(_digraph->maxArcId() << 1) | 1); |
| 3077 | 3077 |
} |
| 3078 | 3078 |
|
| 3079 | 3079 |
static bool inNode(const Node& n) {
|
| 3080 | 3080 |
return n._in; |
| 3081 | 3081 |
} |
| 3082 | 3082 |
|
| 3083 | 3083 |
static bool outNode(const Node& n) {
|
| 3084 | 3084 |
return !n._in; |
| 3085 | 3085 |
} |
| 3086 | 3086 |
|
| 3087 | 3087 |
static bool origArc(const Arc& e) {
|
| 3088 | 3088 |
return e._item.firstState(); |
| 3089 | 3089 |
} |
| 3090 | 3090 |
|
| 3091 | 3091 |
static bool bindArc(const Arc& e) {
|
| 3092 | 3092 |
return e._item.secondState(); |
| 3093 | 3093 |
} |
| 3094 | 3094 |
|
| 3095 | 3095 |
static Node inNode(const DigraphNode& n) {
|
| 3096 | 3096 |
return Node(n, true); |
| 3097 | 3097 |
} |
| 3098 | 3098 |
|
| 3099 | 3099 |
static Node outNode(const DigraphNode& n) {
|
| 3100 | 3100 |
return Node(n, false); |
| 3101 | 3101 |
} |
| 3102 | 3102 |
|
| 3103 | 3103 |
static Arc arc(const DigraphNode& n) {
|
| 3104 | 3104 |
return Arc(n); |
| 3105 | 3105 |
} |
| 3106 | 3106 |
|
| 3107 | 3107 |
static Arc arc(const DigraphArc& e) {
|
| 3108 | 3108 |
return Arc(e); |
| 3109 | 3109 |
} |
| 3110 | 3110 |
|
| 3111 | 3111 |
typedef True NodeNumTag; |
| 3112 | 3112 |
int nodeNum() const {
|
| 3113 | 3113 |
return 2 * countNodes(*_digraph); |
| 3114 | 3114 |
} |
| 3115 | 3115 |
|
| 3116 | 3116 |
typedef True ArcNumTag; |
| 3117 | 3117 |
int arcNum() const {
|
| 3118 | 3118 |
return countArcs(*_digraph) + countNodes(*_digraph); |
| 3119 | 3119 |
} |
| 3120 | 3120 |
|
| 3121 | 3121 |
typedef True FindArcTag; |
| 3122 | 3122 |
Arc findArc(const Node& u, const Node& v, |
| 3123 | 3123 |
const Arc& prev = INVALID) const {
|
| 3124 | 3124 |
if (inNode(u) && outNode(v)) {
|
| 3125 | 3125 |
if (static_cast<const DigraphNode&>(u) == |
| 3126 | 3126 |
static_cast<const DigraphNode&>(v) && prev == INVALID) {
|
| 3127 | 3127 |
return Arc(u); |
| 3128 | 3128 |
} |
| 3129 | 3129 |
} |
| 3130 | 3130 |
else if (outNode(u) && inNode(v)) {
|
| 3131 | 3131 |
return Arc(::lemon::findArc(*_digraph, u, v, prev)); |
| 3132 | 3132 |
} |
| 3133 | 3133 |
return INVALID; |
| 3134 | 3134 |
} |
| 3135 | 3135 |
|
| 3136 | 3136 |
private: |
| 3137 | 3137 |
|
| 3138 | 3138 |
template <typename V> |
| 3139 | 3139 |
class NodeMapBase |
| 3140 | 3140 |
: public MapTraits<typename Parent::template NodeMap<V> > {
|
| 3141 | 3141 |
typedef typename Parent::template NodeMap<V> NodeImpl; |
| 3142 | 3142 |
public: |
| 3143 | 3143 |
typedef Node Key; |
| 3144 | 3144 |
typedef V Value; |
| 3145 | 3145 |
typedef typename MapTraits<NodeImpl>::ReferenceMapTag ReferenceMapTag; |
| 3146 | 3146 |
typedef typename MapTraits<NodeImpl>::ReturnValue ReturnValue; |
| 3147 | 3147 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReturnValue; |
| 3148 | 3148 |
typedef typename MapTraits<NodeImpl>::ReturnValue Reference; |
| 3149 | 3149 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReference; |
| 3150 | 3150 |
|
| 3151 | 3151 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor) |
| 3152 | 3152 |
: _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
|
| 3153 | 3153 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor, const V& value) |
| 3154 | 3154 |
: _in_map(*adaptor._digraph, value), |
| 3155 | 3155 |
_out_map(*adaptor._digraph, value) {}
|
| 3156 | 3156 |
|
| 3157 | 3157 |
void set(const Node& key, const V& val) {
|
| 3158 | 3158 |
if (SplitNodesBase<DGR>::inNode(key)) { _in_map.set(key, val); }
|
| 3159 | 3159 |
else {_out_map.set(key, val); }
|
| 3160 | 3160 |
} |
| 3161 | 3161 |
|
| 3162 | 3162 |
ReturnValue operator[](const Node& key) {
|
| 3163 | 3163 |
if (SplitNodesBase<DGR>::inNode(key)) { return _in_map[key]; }
|
| 3164 | 3164 |
else { return _out_map[key]; }
|
| 3165 | 3165 |
} |
| 3166 | 3166 |
|
| 3167 | 3167 |
ConstReturnValue operator[](const Node& key) const {
|
| 3168 | 3168 |
if (Adaptor::inNode(key)) { return _in_map[key]; }
|
| 3169 | 3169 |
else { return _out_map[key]; }
|
| 3170 | 3170 |
} |
| 3171 | 3171 |
|
| 3172 | 3172 |
private: |
| 3173 | 3173 |
NodeImpl _in_map, _out_map; |
| 3174 | 3174 |
}; |
| 3175 | 3175 |
|
| 3176 | 3176 |
template <typename V> |
| 3177 | 3177 |
class ArcMapBase |
| 3178 | 3178 |
: public MapTraits<typename Parent::template ArcMap<V> > {
|
| 3179 | 3179 |
typedef typename Parent::template ArcMap<V> ArcImpl; |
| 3180 | 3180 |
typedef typename Parent::template NodeMap<V> NodeImpl; |
| 3181 | 3181 |
public: |
| 3182 | 3182 |
typedef Arc Key; |
| 3183 | 3183 |
typedef V Value; |
| 3184 | 3184 |
typedef typename MapTraits<ArcImpl>::ReferenceMapTag ReferenceMapTag; |
| 3185 | 3185 |
typedef typename MapTraits<ArcImpl>::ReturnValue ReturnValue; |
| 3186 | 3186 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReturnValue; |
| 3187 | 3187 |
typedef typename MapTraits<ArcImpl>::ReturnValue Reference; |
| 3188 | 3188 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReference; |
| 3189 | 3189 |
|
| 3190 | 3190 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor) |
| 3191 | 3191 |
: _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
|
| 3192 | 3192 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor, const V& value) |
| 3193 | 3193 |
: _arc_map(*adaptor._digraph, value), |
| 3194 | 3194 |
_node_map(*adaptor._digraph, value) {}
|
| 3195 | 3195 |
|
| 3196 | 3196 |
void set(const Arc& key, const V& val) {
|
| 3197 | 3197 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3198 |
_arc_map.set( |
|
| 3198 |
_arc_map.set(static_cast<const DigraphArc&>(key), val); |
|
| 3199 | 3199 |
} else {
|
| 3200 |
_node_map.set( |
|
| 3200 |
_node_map.set(static_cast<const DigraphNode&>(key), val); |
|
| 3201 | 3201 |
} |
| 3202 | 3202 |
} |
| 3203 | 3203 |
|
| 3204 | 3204 |
ReturnValue operator[](const Arc& key) {
|
| 3205 | 3205 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3206 |
return _arc_map[ |
|
| 3206 |
return _arc_map[static_cast<const DigraphArc&>(key)]; |
|
| 3207 | 3207 |
} else {
|
| 3208 |
return _node_map[ |
|
| 3208 |
return _node_map[static_cast<const DigraphNode&>(key)]; |
|
| 3209 | 3209 |
} |
| 3210 | 3210 |
} |
| 3211 | 3211 |
|
| 3212 | 3212 |
ConstReturnValue operator[](const Arc& key) const {
|
| 3213 | 3213 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
| 3214 |
return _arc_map[ |
|
| 3214 |
return _arc_map[static_cast<const DigraphArc&>(key)]; |
|
| 3215 | 3215 |
} else {
|
| 3216 |
return _node_map[ |
|
| 3216 |
return _node_map[static_cast<const DigraphNode&>(key)]; |
|
| 3217 | 3217 |
} |
| 3218 | 3218 |
} |
| 3219 | 3219 |
|
| 3220 | 3220 |
private: |
| 3221 | 3221 |
ArcImpl _arc_map; |
| 3222 | 3222 |
NodeImpl _node_map; |
| 3223 | 3223 |
}; |
| 3224 | 3224 |
|
| 3225 | 3225 |
public: |
| 3226 | 3226 |
|
| 3227 | 3227 |
template <typename V> |
| 3228 | 3228 |
class NodeMap |
| 3229 | 3229 |
: public SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> > |
| 3230 | 3230 |
{
|
| 3231 | 3231 |
public: |
| 3232 | 3232 |
typedef V Value; |
| 3233 | 3233 |
typedef SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<Value> > Parent; |
| 3234 | 3234 |
|
| 3235 | 3235 |
NodeMap(const SplitNodesBase<DGR>& adaptor) |
| 3236 | 3236 |
: Parent(adaptor) {}
|
| 3237 | 3237 |
|
| 3238 | 3238 |
NodeMap(const SplitNodesBase<DGR>& adaptor, const V& value) |
| 3239 | 3239 |
: Parent(adaptor, value) {}
|
| 3240 | 3240 |
|
| 3241 | 3241 |
private: |
| 3242 | 3242 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 3243 | 3243 |
return operator=<NodeMap>(cmap); |
| 3244 | 3244 |
} |
| 3245 | 3245 |
|
| 3246 | 3246 |
template <typename CMap> |
| 3247 | 3247 |
NodeMap& operator=(const CMap& cmap) {
|
| 3248 | 3248 |
Parent::operator=(cmap); |
| 3249 | 3249 |
return *this; |
| 3250 | 3250 |
} |
| 3251 | 3251 |
}; |
| 3252 | 3252 |
|
| 3253 | 3253 |
template <typename V> |
| 3254 | 3254 |
class ArcMap |
| 3255 | 3255 |
: public SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> > |
| 3256 | 3256 |
{
|
| 3257 | 3257 |
public: |
| 3258 | 3258 |
typedef V Value; |
| 3259 | 3259 |
typedef SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<Value> > Parent; |
| 3260 | 3260 |
|
| 3261 | 3261 |
ArcMap(const SplitNodesBase<DGR>& adaptor) |
| 3262 | 3262 |
: Parent(adaptor) {}
|
| 3263 | 3263 |
|
| 3264 | 3264 |
ArcMap(const SplitNodesBase<DGR>& adaptor, const V& value) |
| 3265 | 3265 |
: Parent(adaptor, value) {}
|
| 3266 | 3266 |
|
| 3267 | 3267 |
private: |
| 3268 | 3268 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 3269 | 3269 |
return operator=<ArcMap>(cmap); |
| 3270 | 3270 |
} |
| 3271 | 3271 |
|
| 3272 | 3272 |
template <typename CMap> |
| 3273 | 3273 |
ArcMap& operator=(const CMap& cmap) {
|
| 3274 | 3274 |
Parent::operator=(cmap); |
| 3275 | 3275 |
return *this; |
| 3276 | 3276 |
} |
| 3277 | 3277 |
}; |
| 3278 | 3278 |
|
| 3279 | 3279 |
protected: |
| 3280 | 3280 |
|
| 3281 | 3281 |
SplitNodesBase() : _digraph(0) {}
|
| 3282 | 3282 |
|
| 3283 | 3283 |
DGR* _digraph; |
| 3284 | 3284 |
|
| 3285 | 3285 |
void initialize(Digraph& digraph) {
|
| 3286 | 3286 |
_digraph = &digraph; |
| 3287 | 3287 |
} |
| 3288 | 3288 |
|
| 3289 | 3289 |
}; |
| 3290 | 3290 |
|
| 3291 | 3291 |
/// \ingroup graph_adaptors |
| 3292 | 3292 |
/// |
| 3293 | 3293 |
/// \brief Adaptor class for splitting the nodes of a digraph. |
| 3294 | 3294 |
/// |
| 3295 | 3295 |
/// SplitNodes adaptor can be used for splitting each node into an |
| 3296 | 3296 |
/// \e in-node and an \e out-node in a digraph. Formaly, the adaptor |
| 3297 | 3297 |
/// replaces each node \f$ u \f$ in the digraph with two nodes, |
| 3298 | 3298 |
/// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$.
|
| 3299 | 3299 |
/// If there is a \f$ (v, u) \f$ arc in the original digraph, then the |
| 3300 | 3300 |
/// new target of the arc will be \f$ u_{in} \f$ and similarly the
|
| 3301 | 3301 |
/// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$.
|
| 3302 | 3302 |
/// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$
|
| 3303 | 3303 |
/// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph.
|
| 3304 | 3304 |
/// |
| 3305 | 3305 |
/// The aim of this class is running an algorithm with respect to node |
| 3306 | 3306 |
/// costs or capacities if the algorithm considers only arc costs or |
| 3307 | 3307 |
/// capacities directly. |
| 3308 | 3308 |
/// In this case you can use \c SplitNodes adaptor, and set the node |
| 3309 | 3309 |
/// costs/capacities of the original digraph to the \e bind \e arcs |
| 3310 | 3310 |
/// in the adaptor. |
| 3311 | 3311 |
/// |
| 3312 | 3312 |
/// \tparam DGR The type of the adapted digraph. |
| 3313 | 3313 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept. |
| 3314 | 3314 |
/// It is implicitly \c const. |
| 3315 | 3315 |
/// |
| 3316 | 3316 |
/// \note The \c Node type of this adaptor is converible to the \c Node |
| 3317 | 3317 |
/// type of the adapted digraph. |
| 3318 | 3318 |
template <typename DGR> |
| 3319 | 3319 |
#ifdef DOXYGEN |
| 3320 | 3320 |
class SplitNodes {
|
| 3321 | 3321 |
#else |
| 3322 | 3322 |
class SplitNodes |
| 3323 | 3323 |
: public DigraphAdaptorExtender<SplitNodesBase<const DGR> > {
|
| 3324 | 3324 |
#endif |
| 3325 | 3325 |
public: |
| 3326 | 3326 |
typedef DGR Digraph; |
| 3327 | 3327 |
typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent; |
| 3328 | 3328 |
|
| 3329 | 3329 |
typedef typename DGR::Node DigraphNode; |
| 3330 | 3330 |
typedef typename DGR::Arc DigraphArc; |
| 3331 | 3331 |
|
| 3332 | 3332 |
typedef typename Parent::Node Node; |
| 3333 | 3333 |
typedef typename Parent::Arc Arc; |
| 3334 | 3334 |
|
| 3335 | 3335 |
/// \brief Constructor |
| 3336 | 3336 |
/// |
| 3337 | 3337 |
/// Constructor of the adaptor. |
| 3338 | 3338 |
SplitNodes(const DGR& g) {
|
| 3339 | 3339 |
Parent::initialize(g); |
| 3340 | 3340 |
} |
| 3341 | 3341 |
|
| 3342 | 3342 |
/// \brief Returns \c true if the given node is an in-node. |
| 3343 | 3343 |
/// |
| 3344 | 3344 |
/// Returns \c true if the given node is an in-node. |
| 3345 | 3345 |
static bool inNode(const Node& n) {
|
| 3346 | 3346 |
return Parent::inNode(n); |
| 3347 | 3347 |
} |
| 3348 | 3348 |
|
| 3349 | 3349 |
/// \brief Returns \c true if the given node is an out-node. |
| 3350 | 3350 |
/// |
| 3351 | 3351 |
/// Returns \c true if the given node is an out-node. |
| 3352 | 3352 |
static bool outNode(const Node& n) {
|
| 3353 | 3353 |
return Parent::outNode(n); |
| 3354 | 3354 |
} |
| 3355 | 3355 |
|
| 3356 | 3356 |
/// \brief Returns \c true if the given arc is an original arc. |
| 3357 | 3357 |
/// |
| 3358 | 3358 |
/// Returns \c true if the given arc is one of the arcs in the |
| 3359 | 3359 |
/// original digraph. |
| 3360 | 3360 |
static bool origArc(const Arc& a) {
|
| 3361 | 3361 |
return Parent::origArc(a); |
| 3362 | 3362 |
} |
| 3363 | 3363 |
|
| 3364 | 3364 |
/// \brief Returns \c true if the given arc is a bind arc. |
| 3365 | 3365 |
/// |
| 3366 | 3366 |
/// Returns \c true if the given arc is a bind arc, i.e. it connects |
| 3367 | 3367 |
/// an in-node and an out-node. |
| 3368 | 3368 |
static bool bindArc(const Arc& a) {
|
| 3369 | 3369 |
return Parent::bindArc(a); |
| 3370 | 3370 |
} |
| 3371 | 3371 |
|
| 3372 | 3372 |
/// \brief Returns the in-node created from the given original node. |
| 3373 | 3373 |
/// |
| 3374 | 3374 |
/// Returns the in-node created from the given original node. |
| 3375 | 3375 |
static Node inNode(const DigraphNode& n) {
|
| 3376 | 3376 |
return Parent::inNode(n); |
| 3377 | 3377 |
} |
| 3378 | 3378 |
|
| 3379 | 3379 |
/// \brief Returns the out-node created from the given original node. |
| 3380 | 3380 |
/// |
| 3381 | 3381 |
/// Returns the out-node created from the given original node. |
| 3382 | 3382 |
static Node outNode(const DigraphNode& n) {
|
| 3383 | 3383 |
return Parent::outNode(n); |
| 3384 | 3384 |
} |
| 3385 | 3385 |
|
| 3386 | 3386 |
/// \brief Returns the bind arc that corresponds to the given |
| 3387 | 3387 |
/// original node. |
| 3388 | 3388 |
/// |
| 3389 | 3389 |
/// Returns the bind arc in the adaptor that corresponds to the given |
| 3390 | 3390 |
/// original node, i.e. the arc connecting the in-node and out-node |
| 3391 | 3391 |
/// of \c n. |
| 3392 | 3392 |
static Arc arc(const DigraphNode& n) {
|
| 3393 | 3393 |
return Parent::arc(n); |
| 3394 | 3394 |
} |
| 3395 | 3395 |
|
| 3396 | 3396 |
/// \brief Returns the arc that corresponds to the given original arc. |
| 3397 | 3397 |
/// |
| 3398 | 3398 |
/// Returns the arc in the adaptor that corresponds to the given |
| 3399 | 3399 |
/// original arc. |
| 3400 | 3400 |
static Arc arc(const DigraphArc& a) {
|
| 3401 | 3401 |
return Parent::arc(a); |
| 3402 | 3402 |
} |
| 3403 | 3403 |
|
| 3404 | 3404 |
/// \brief Node map combined from two original node maps |
| 3405 | 3405 |
/// |
| 3406 | 3406 |
/// This map adaptor class adapts two node maps of the original digraph |
| 3407 | 3407 |
/// to get a node map of the split digraph. |
| 3408 | 3408 |
/// Its value type is inherited from the first node map type |
| 3409 | 3409 |
/// (\c InNodeMap). |
| 3410 | 3410 |
template <typename InNodeMap, typename OutNodeMap> |
| 3411 | 3411 |
class CombinedNodeMap {
|
| 3412 | 3412 |
public: |
| 3413 | 3413 |
|
| 3414 | 3414 |
/// The key type of the map |
| 3415 | 3415 |
typedef Node Key; |
| 3416 | 3416 |
/// The value type of the map |
| 3417 | 3417 |
typedef typename InNodeMap::Value Value; |
| 3418 | 3418 |
|
| 3419 | 3419 |
typedef typename MapTraits<InNodeMap>::ReferenceMapTag ReferenceMapTag; |
| 3420 | 3420 |
typedef typename MapTraits<InNodeMap>::ReturnValue ReturnValue; |
| 3421 | 3421 |
typedef typename MapTraits<InNodeMap>::ConstReturnValue ConstReturnValue; |
| 3422 | 3422 |
typedef typename MapTraits<InNodeMap>::ReturnValue Reference; |
| 3423 | 3423 |
typedef typename MapTraits<InNodeMap>::ConstReturnValue ConstReference; |
| 3424 | 3424 |
|
| 3425 | 3425 |
/// Constructor |
| 3426 | 3426 |
CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) |
| 3427 | 3427 |
: _in_map(in_map), _out_map(out_map) {}
|
| 3428 | 3428 |
|
| 3429 | 3429 |
/// Returns the value associated with the given key. |
| 3430 | 3430 |
Value operator[](const Key& key) const {
|
| 3431 | 3431 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3432 | 3432 |
return _in_map[key]; |
| 3433 | 3433 |
} else {
|
| 3434 | 3434 |
return _out_map[key]; |
| 3435 | 3435 |
} |
| 3436 | 3436 |
} |
| 3437 | 3437 |
|
| 3438 | 3438 |
/// Returns a reference to the value associated with the given key. |
| 3439 | 3439 |
Value& operator[](const Key& key) {
|
| 3440 | 3440 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3441 | 3441 |
return _in_map[key]; |
| 3442 | 3442 |
} else {
|
| 3443 | 3443 |
return _out_map[key]; |
| 3444 | 3444 |
} |
| 3445 | 3445 |
} |
| 3446 | 3446 |
|
| 3447 | 3447 |
/// Sets the value associated with the given key. |
| 3448 | 3448 |
void set(const Key& key, const Value& value) {
|
| 3449 | 3449 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
| 3450 | 3450 |
_in_map.set(key, value); |
| 3451 | 3451 |
} else {
|
| 3452 | 3452 |
_out_map.set(key, value); |
| 3453 | 3453 |
} |
| 3454 | 3454 |
} |
| 3455 | 3455 |
|
| 3456 | 3456 |
private: |
| 3457 | 3457 |
|
| 3458 | 3458 |
InNodeMap& _in_map; |
| 3459 | 3459 |
OutNodeMap& _out_map; |
| 3460 | 3460 |
|
| 3461 | 3461 |
}; |
| 3462 | 3462 |
|
| 3463 | 3463 |
|
| 3464 | 3464 |
/// \brief Returns a combined node map |
| 3465 | 3465 |
/// |
| 3466 | 3466 |
/// This function just returns a combined node map. |
| 3467 | 3467 |
template <typename InNodeMap, typename OutNodeMap> |
| 3468 | 3468 |
static CombinedNodeMap<InNodeMap, OutNodeMap> |
| 3469 | 3469 |
combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
|
| 3470 | 3470 |
return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map); |
| 3471 | 3471 |
} |
| 3472 | 3472 |
|
| 3473 | 3473 |
template <typename InNodeMap, typename OutNodeMap> |
| 3474 | 3474 |
static CombinedNodeMap<const InNodeMap, OutNodeMap> |
| 3475 | 3475 |
combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
|
| 3476 | 3476 |
return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map); |
| 3477 | 3477 |
} |
| 3478 | 3478 |
|
| 3479 | 3479 |
template <typename InNodeMap, typename OutNodeMap> |
| 3480 | 3480 |
static CombinedNodeMap<InNodeMap, const OutNodeMap> |
| 3481 | 3481 |
combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
|
| 3482 | 3482 |
return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map); |
| 3483 | 3483 |
} |
| 3484 | 3484 |
|
| 3485 | 3485 |
template <typename InNodeMap, typename OutNodeMap> |
| 3486 | 3486 |
static CombinedNodeMap<const InNodeMap, const OutNodeMap> |
| 3487 | 3487 |
combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
|
| 3488 | 3488 |
return CombinedNodeMap<const InNodeMap, |
| 3489 | 3489 |
const OutNodeMap>(in_map, out_map); |
| 3490 | 3490 |
} |
| 3491 | 3491 |
|
| 3492 | 3492 |
/// \brief Arc map combined from an arc map and a node map of the |
| 3493 | 3493 |
/// original digraph. |
| 3494 | 3494 |
/// |
| 3495 | 3495 |
/// This map adaptor class adapts an arc map and a node map of the |
| 3496 | 3496 |
/// original digraph to get an arc map of the split digraph. |
| 3497 | 3497 |
/// Its value type is inherited from the original arc map type |
| 3498 | 3498 |
/// (\c ArcMap). |
| 3499 | 3499 |
template <typename ArcMap, typename NodeMap> |
| 3500 | 3500 |
class CombinedArcMap {
|
| 3501 | 3501 |
public: |
| 3502 | 3502 |
|
| 3503 | 3503 |
/// The key type of the map |
| 3504 | 3504 |
typedef Arc Key; |
| 3505 | 3505 |
/// The value type of the map |
| 3506 | 3506 |
typedef typename ArcMap::Value Value; |
| 3507 | 3507 |
|
| 3508 | 3508 |
typedef typename MapTraits<ArcMap>::ReferenceMapTag ReferenceMapTag; |
| 3509 | 3509 |
typedef typename MapTraits<ArcMap>::ReturnValue ReturnValue; |
| 3510 | 3510 |
typedef typename MapTraits<ArcMap>::ConstReturnValue ConstReturnValue; |
| 3511 | 3511 |
typedef typename MapTraits<ArcMap>::ReturnValue Reference; |
| 3512 | 3512 |
typedef typename MapTraits<ArcMap>::ConstReturnValue ConstReference; |
| 3513 | 3513 |
|
| 3514 | 3514 |
/// Constructor |
| 3515 | 3515 |
CombinedArcMap(ArcMap& arc_map, NodeMap& node_map) |
| 3516 | 3516 |
: _arc_map(arc_map), _node_map(node_map) {}
|
| 3517 | 3517 |
|
| 3518 | 3518 |
/// Returns the value associated with the given key. |
| 3519 | 3519 |
Value operator[](const Key& arc) const {
|
| 3520 | 3520 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3521 | 3521 |
return _arc_map[arc]; |
| 3522 | 3522 |
} else {
|
| 3523 | 3523 |
return _node_map[arc]; |
| 3524 | 3524 |
} |
| 3525 | 3525 |
} |
| 3526 | 3526 |
|
| 3527 | 3527 |
/// Returns a reference to the value associated with the given key. |
| 3528 | 3528 |
Value& operator[](const Key& arc) {
|
| 3529 | 3529 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3530 | 3530 |
return _arc_map[arc]; |
| 3531 | 3531 |
} else {
|
| 3532 | 3532 |
return _node_map[arc]; |
| 3533 | 3533 |
} |
| 3534 | 3534 |
} |
| 3535 | 3535 |
|
| 3536 | 3536 |
/// Sets the value associated with the given key. |
| 3537 | 3537 |
void set(const Arc& arc, const Value& val) {
|
| 3538 | 3538 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
| 3539 | 3539 |
_arc_map.set(arc, val); |
| 3540 | 3540 |
} else {
|
| 3541 | 3541 |
_node_map.set(arc, val); |
| 3542 | 3542 |
} |
| 3543 | 3543 |
} |
| 3544 | 3544 |
|
| 3545 | 3545 |
private: |
| 3546 | 3546 |
ArcMap& _arc_map; |
| 3547 | 3547 |
NodeMap& _node_map; |
| 3548 | 3548 |
}; |
| 3549 | 3549 |
|
| 3550 | 3550 |
/// \brief Returns a combined arc map |
| 3551 | 3551 |
/// |
| 3552 | 3552 |
/// This function just returns a combined arc map. |
| 3553 | 3553 |
template <typename ArcMap, typename NodeMap> |
| 3554 | 3554 |
static CombinedArcMap<ArcMap, NodeMap> |
| 3555 | 3555 |
combinedArcMap(ArcMap& arc_map, NodeMap& node_map) {
|
| 3556 | 3556 |
return CombinedArcMap<ArcMap, NodeMap>(arc_map, node_map); |
| 3557 | 3557 |
} |
| 3558 | 3558 |
|
| 3559 | 3559 |
template <typename ArcMap, typename NodeMap> |
| 3560 | 3560 |
static CombinedArcMap<const ArcMap, NodeMap> |
| 3561 | 3561 |
combinedArcMap(const ArcMap& arc_map, NodeMap& node_map) {
|
| 3562 | 3562 |
return CombinedArcMap<const ArcMap, NodeMap>(arc_map, node_map); |
| 3563 | 3563 |
} |
| 3564 | 3564 |
|
| 3565 | 3565 |
template <typename ArcMap, typename NodeMap> |
| 3566 | 3566 |
static CombinedArcMap<ArcMap, const NodeMap> |
| 3567 | 3567 |
combinedArcMap(ArcMap& arc_map, const NodeMap& node_map) {
|
| 3568 | 3568 |
return CombinedArcMap<ArcMap, const NodeMap>(arc_map, node_map); |
| 3569 | 3569 |
} |
| 3570 | 3570 |
|
| 3571 | 3571 |
template <typename ArcMap, typename NodeMap> |
| 3572 | 3572 |
static CombinedArcMap<const ArcMap, const NodeMap> |
| 3573 | 3573 |
combinedArcMap(const ArcMap& arc_map, const NodeMap& node_map) {
|
| 3574 | 3574 |
return CombinedArcMap<const ArcMap, const NodeMap>(arc_map, node_map); |
| 3575 | 3575 |
} |
| 3576 | 3576 |
|
| 3577 | 3577 |
}; |
| 3578 | 3578 |
|
| 3579 | 3579 |
/// \brief Returns a (read-only) SplitNodes adaptor |
| 3580 | 3580 |
/// |
| 3581 | 3581 |
/// This function just returns a (read-only) \ref SplitNodes adaptor. |
| 3582 | 3582 |
/// \ingroup graph_adaptors |
| 3583 | 3583 |
/// \relates SplitNodes |
| 3584 | 3584 |
template<typename DGR> |
| 3585 | 3585 |
SplitNodes<DGR> |
| 3586 | 3586 |
splitNodes(const DGR& digraph) {
|
| 3587 | 3587 |
return SplitNodes<DGR>(digraph); |
| 3588 | 3588 |
} |
| 3589 | 3589 |
|
| 3590 | 3590 |
#undef LEMON_SCOPE_FIX |
| 3591 | 3591 |
|
| 3592 | 3592 |
} //namespace lemon |
| 3593 | 3593 |
|
| 3594 | 3594 |
#endif //LEMON_ADAPTORS_H |
0 comments (0 inline)