| ... | ... |
@@ -3102,211 +3102,211 @@ |
| 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. |
0 comments (0 inline)