... |
... |
@@ -14,50 +14,39 @@
|
14 |
14 |
* express or implied, and with no claim as to its suitability for any
|
15 |
15 |
* purpose.
|
16 |
16 |
*
|
17 |
17 |
*/
|
18 |
18 |
|
19 |
19 |
#ifndef LEMON_DIGRAPH_ADAPTOR_H
|
20 |
20 |
#define LEMON_DIGRAPH_ADAPTOR_H
|
21 |
21 |
|
22 |
22 |
///\ingroup graph_adaptors
|
23 |
23 |
///\file
|
24 |
24 |
///\brief Several digraph adaptors.
|
25 |
25 |
///
|
26 |
|
///This file contains several useful digraph adaptor functions.
|
|
26 |
///This file contains several useful digraph adaptor classes.
|
27 |
27 |
|
28 |
28 |
#include <lemon/core.h>
|
29 |
29 |
#include <lemon/maps.h>
|
30 |
30 |
#include <lemon/bits/variant.h>
|
31 |
31 |
|
32 |
32 |
#include <lemon/bits/base_extender.h>
|
33 |
33 |
#include <lemon/bits/graph_adaptor_extender.h>
|
34 |
34 |
#include <lemon/bits/graph_extender.h>
|
35 |
35 |
#include <lemon/tolerance.h>
|
36 |
36 |
|
37 |
37 |
#include <algorithm>
|
38 |
38 |
|
39 |
39 |
namespace lemon {
|
40 |
40 |
|
41 |
|
///\brief Base type for the Digraph Adaptors
|
42 |
|
///
|
43 |
|
///Base type for the Digraph Adaptors
|
44 |
|
///
|
45 |
|
///This is the base type for most of LEMON digraph adaptors. This
|
46 |
|
///class implements a trivial digraph adaptor i.e. it only wraps the
|
47 |
|
///functions and types of the digraph. The purpose of this class is
|
48 |
|
///to make easier implementing digraph adaptors. E.g. if an adaptor
|
49 |
|
///is considered which differs from the wrapped digraph only in some
|
50 |
|
///of its functions or types, then it can be derived from
|
51 |
|
///DigraphAdaptor, and only the differences should be implemented.
|
52 |
41 |
template<typename _Digraph>
|
53 |
42 |
class DigraphAdaptorBase {
|
54 |
43 |
public:
|
55 |
44 |
typedef _Digraph Digraph;
|
56 |
45 |
typedef DigraphAdaptorBase Adaptor;
|
57 |
46 |
typedef Digraph ParentDigraph;
|
58 |
47 |
|
59 |
48 |
protected:
|
60 |
49 |
Digraph* _digraph;
|
61 |
50 |
DigraphAdaptorBase() : _digraph(0) { }
|
62 |
51 |
void setDigraph(Digraph& digraph) { _digraph = &digraph; }
|
63 |
52 |
|
... |
... |
@@ -157,53 +146,24 @@
|
157 |
146 |
}
|
158 |
147 |
|
159 |
148 |
template <typename CMap>
|
160 |
149 |
ArcMap& operator=(const CMap& cmap) {
|
161 |
150 |
Parent::operator=(cmap);
|
162 |
151 |
return *this;
|
163 |
152 |
}
|
164 |
153 |
|
165 |
154 |
};
|
166 |
155 |
|
167 |
156 |
};
|
168 |
157 |
|
169 |
|
///\ingroup graph_adaptors
|
170 |
|
///
|
171 |
|
///\brief Trivial Digraph Adaptor
|
172 |
|
///
|
173 |
|
/// This class is an adaptor which does not change the adapted
|
174 |
|
/// digraph. It can be used only to test the digraph adaptors.
|
175 |
|
template <typename _Digraph>
|
176 |
|
class DigraphAdaptor :
|
177 |
|
public DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > {
|
178 |
|
public:
|
179 |
|
typedef _Digraph Digraph;
|
180 |
|
typedef DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > Parent;
|
181 |
|
protected:
|
182 |
|
DigraphAdaptor() : Parent() { }
|
183 |
|
|
184 |
|
public:
|
185 |
|
explicit DigraphAdaptor(Digraph& digraph) { setDigraph(digraph); }
|
186 |
|
};
|
187 |
|
|
188 |
|
/// \brief Just gives back a digraph adaptor
|
189 |
|
///
|
190 |
|
/// Just gives back a digraph adaptor which
|
191 |
|
/// should be provide original digraph
|
192 |
|
template<typename Digraph>
|
193 |
|
DigraphAdaptor<const Digraph>
|
194 |
|
digraphAdaptor(const Digraph& digraph) {
|
195 |
|
return DigraphAdaptor<const Digraph>(digraph);
|
196 |
|
}
|
197 |
|
|
198 |
158 |
|
199 |
159 |
template <typename _Digraph>
|
200 |
160 |
class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
|
201 |
161 |
public:
|
202 |
162 |
typedef _Digraph Digraph;
|
203 |
163 |
typedef DigraphAdaptorBase<_Digraph> Parent;
|
204 |
164 |
protected:
|
205 |
165 |
RevDigraphAdaptorBase() : Parent() { }
|
206 |
166 |
public:
|
207 |
167 |
typedef typename Parent::Node Node;
|
208 |
168 |
typedef typename Parent::Arc Arc;
|
209 |
169 |
|
... |
... |
@@ -222,45 +182,43 @@
|
222 |
182 |
return Parent::findArc(v, u, prev);
|
223 |
183 |
}
|
224 |
184 |
|
225 |
185 |
};
|
226 |
186 |
|
227 |
187 |
|
228 |
188 |
///\ingroup graph_adaptors
|
229 |
189 |
///
|
230 |
190 |
///\brief A digraph adaptor which reverses the orientation of the arcs.
|
231 |
191 |
///
|
232 |
192 |
/// If \c g is defined as
|
233 |
193 |
///\code
|
234 |
|
/// ListDigraph g;
|
|
194 |
/// ListDigraph dg;
|
235 |
195 |
///\endcode
|
236 |
196 |
/// then
|
237 |
197 |
///\code
|
238 |
|
/// RevDigraphAdaptor<ListDigraph> ga(g);
|
|
198 |
/// RevDigraphAdaptor<ListDigraph> dga(dg);
|
239 |
199 |
///\endcode
|
240 |
|
/// implements the digraph obtained from \c g by
|
|
200 |
/// implements the digraph obtained from \c dg by
|
241 |
201 |
/// reversing the orientation of its arcs.
|
242 |
202 |
///
|
243 |
|
/// A good example of using RevDigraphAdaptor is to decide that the
|
244 |
|
/// directed graph is wheter strongly connected or not. If from one
|
245 |
|
/// node each node is reachable and from each node is reachable this
|
246 |
|
/// node then and just then the digraph is strongly
|
247 |
|
/// connected. Instead of this condition we use a little bit
|
248 |
|
/// different. From one node each node ahould be reachable in the
|
249 |
|
/// digraph and in the reversed digraph. Now this condition can be
|
250 |
|
/// checked with the Dfs algorithm class and the RevDigraphAdaptor
|
251 |
|
/// algorithm class.
|
|
203 |
/// A good example of using RevDigraphAdaptor is to decide whether
|
|
204 |
/// the directed graph is strongly connected or not. The digraph is
|
|
205 |
/// strongly connected iff each node is reachable from one node and
|
|
206 |
/// this node is reachable from the others. Instead of this
|
|
207 |
/// condition we use a slightly different, from one node each node
|
|
208 |
/// is reachable both in the digraph and the reversed digraph. Now
|
|
209 |
/// this condition can be checked with the Dfs algorithm and the
|
|
210 |
/// RevDigraphAdaptor class.
|
252 |
211 |
///
|
253 |
|
/// And look at the code:
|
254 |
|
///
|
|
212 |
/// The implementation:
|
255 |
213 |
///\code
|
256 |
214 |
/// bool stronglyConnected(const Digraph& digraph) {
|
257 |
215 |
/// if (NodeIt(digraph) == INVALID) return true;
|
258 |
216 |
/// Dfs<Digraph> dfs(digraph);
|
259 |
217 |
/// dfs.run(NodeIt(digraph));
|
260 |
218 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
261 |
219 |
/// if (!dfs.reached(it)) {
|
262 |
220 |
/// return false;
|
263 |
221 |
/// }
|
264 |
222 |
/// }
|
265 |
223 |
/// typedef RevDigraphAdaptor<const Digraph> RDigraph;
|
266 |
224 |
/// RDigraph rdigraph(digraph);
|
... |
... |
@@ -275,24 +233,28 @@
|
275 |
233 |
/// }
|
276 |
234 |
///\endcode
|
277 |
235 |
template<typename _Digraph>
|
278 |
236 |
class RevDigraphAdaptor :
|
279 |
237 |
public DigraphAdaptorExtender<RevDigraphAdaptorBase<_Digraph> > {
|
280 |
238 |
public:
|
281 |
239 |
typedef _Digraph Digraph;
|
282 |
240 |
typedef DigraphAdaptorExtender<
|
283 |
241 |
RevDigraphAdaptorBase<_Digraph> > Parent;
|
284 |
242 |
protected:
|
285 |
243 |
RevDigraphAdaptor() { }
|
286 |
244 |
public:
|
|
245 |
|
|
246 |
/// \brief Constructor
|
|
247 |
///
|
|
248 |
/// Creates a reverse graph adaptor for the given digraph
|
287 |
249 |
explicit RevDigraphAdaptor(Digraph& digraph) {
|
288 |
250 |
Parent::setDigraph(digraph);
|
289 |
251 |
}
|
290 |
252 |
};
|
291 |
253 |
|
292 |
254 |
/// \brief Just gives back a reverse digraph adaptor
|
293 |
255 |
///
|
294 |
256 |
/// Just gives back a reverse digraph adaptor
|
295 |
257 |
template<typename Digraph>
|
296 |
258 |
RevDigraphAdaptor<const Digraph>
|
297 |
259 |
revDigraphAdaptor(const Digraph& digraph) {
|
298 |
260 |
return RevDigraphAdaptor<const Digraph>(digraph);
|
... |
... |
@@ -365,62 +327,31 @@
|
365 |
327 |
void nextIn(Arc& i) const {
|
366 |
328 |
Parent::nextIn(i);
|
367 |
329 |
while (i != INVALID && (!(*_arc_filter)[i]
|
368 |
330 |
|| !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i);
|
369 |
331 |
}
|
370 |
332 |
|
371 |
333 |
void nextOut(Arc& i) const {
|
372 |
334 |
Parent::nextOut(i);
|
373 |
335 |
while (i != INVALID && (!(*_arc_filter)[i]
|
374 |
336 |
|| !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i);
|
375 |
337 |
}
|
376 |
338 |
|
377 |
|
///\e
|
378 |
|
|
379 |
|
/// This function hides \c n in the digraph, i.e. the iteration
|
380 |
|
/// jumps over it. This is done by simply setting the value of \c n
|
381 |
|
/// to be false in the corresponding node-map.
|
382 |
339 |
void hide(const Node& n) const { _node_filter->set(n, false); }
|
383 |
|
|
384 |
|
///\e
|
385 |
|
|
386 |
|
/// This function hides \c a in the digraph, i.e. the iteration
|
387 |
|
/// jumps over it. This is done by simply setting the value of \c a
|
388 |
|
/// to be false in the corresponding arc-map.
|
389 |
340 |
void hide(const Arc& a) const { _arc_filter->set(a, false); }
|
390 |
341 |
|
391 |
|
///\e
|
392 |
|
|
393 |
|
/// The value of \c n is set to be true in the node-map which stores
|
394 |
|
/// hide information. If \c n was hidden previuosly, then it is shown
|
395 |
|
/// again
|
396 |
|
void unHide(const Node& n) const { _node_filter->set(n, true); }
|
397 |
|
|
398 |
|
///\e
|
399 |
|
|
400 |
|
/// The value of \c a is set to be true in the arc-map which stores
|
401 |
|
/// hide information. If \c a was hidden previuosly, then it is shown
|
402 |
|
/// again
|
|
342 |
void unHide(const Node& n) const { _node_filter->set(n, true); }
|
403 |
343 |
void unHide(const Arc& a) const { _arc_filter->set(a, true); }
|
404 |
344 |
|
405 |
|
/// Returns true if \c n is hidden.
|
406 |
|
|
407 |
|
///\e
|
408 |
|
///
|
409 |
345 |
bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
|
410 |
|
|
411 |
|
/// Returns true if \c a is hidden.
|
412 |
|
|
413 |
|
///\e
|
414 |
|
///
|
415 |
346 |
bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
|
416 |
347 |
|
417 |
348 |
typedef False NodeNumTag;
|
418 |
349 |
typedef False EdgeNumTag;
|
419 |
350 |
|
420 |
351 |
typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
|
421 |
352 |
Arc findArc(const Node& source, const Node& target,
|
422 |
353 |
const Arc& prev = INVALID) {
|
423 |
354 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
424 |
355 |
return INVALID;
|
425 |
356 |
}
|
426 |
357 |
Arc arc = Parent::findArc(source, target, prev);
|
... |
... |
@@ -539,62 +470,31 @@
|
539 |
470 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
|
540 |
471 |
}
|
541 |
472 |
void nextIn(Arc& i) const {
|
542 |
473 |
Parent::nextIn(i);
|
543 |
474 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
|
544 |
475 |
}
|
545 |
476 |
|
546 |
477 |
void nextOut(Arc& i) const {
|
547 |
478 |
Parent::nextOut(i);
|
548 |
479 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
|
549 |
480 |
}
|
550 |
481 |
|
551 |
|
///\e
|
552 |
|
|
553 |
|
/// This function hides \c n in the digraph, i.e. the iteration
|
554 |
|
/// jumps over it. This is done by simply setting the value of \c n
|
555 |
|
/// to be false in the corresponding node-map.
|
556 |
482 |
void hide(const Node& n) const { _node_filter->set(n, false); }
|
557 |
|
|
558 |
|
///\e
|
559 |
|
|
560 |
|
/// This function hides \c e in the digraph, i.e. the iteration
|
561 |
|
/// jumps over it. This is done by simply setting the value of \c e
|
562 |
|
/// to be false in the corresponding arc-map.
|
563 |
483 |
void hide(const Arc& e) const { _arc_filter->set(e, false); }
|
564 |
484 |
|
565 |
|
///\e
|
566 |
|
|
567 |
|
/// The value of \c n is set to be true in the node-map which stores
|
568 |
|
/// hide information. If \c n was hidden previuosly, then it is shown
|
569 |
|
/// again
|
570 |
|
void unHide(const Node& n) const { _node_filter->set(n, true); }
|
571 |
|
|
572 |
|
///\e
|
573 |
|
|
574 |
|
/// The value of \c e is set to be true in the arc-map which stores
|
575 |
|
/// hide information. If \c e was hidden previuosly, then it is shown
|
576 |
|
/// again
|
|
485 |
void unHide(const Node& n) const { _node_filter->set(n, true); }
|
577 |
486 |
void unHide(const Arc& e) const { _arc_filter->set(e, true); }
|
578 |
487 |
|
579 |
|
/// Returns true if \c n is hidden.
|
580 |
|
|
581 |
|
///\e
|
582 |
|
///
|
583 |
488 |
bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
|
584 |
|
|
585 |
|
/// Returns true if \c n is hidden.
|
586 |
|
|
587 |
|
///\e
|
588 |
|
///
|
589 |
489 |
bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
|
590 |
490 |
|
591 |
491 |
typedef False NodeNumTag;
|
592 |
492 |
typedef False EdgeNumTag;
|
593 |
493 |
|
594 |
494 |
typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
|
595 |
495 |
Arc findArc(const Node& source, const Node& target,
|
596 |
496 |
const Arc& prev = INVALID) {
|
597 |
497 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
598 |
498 |
return INVALID;
|
599 |
499 |
}
|
600 |
500 |
Arc arc = Parent::findArc(source, target, prev);
|
... |
... |
@@ -652,107 +552,140 @@
|
652 |
552 |
MapParent::operator=(cmap);
|
653 |
553 |
return *this;
|
654 |
554 |
}
|
655 |
555 |
};
|
656 |
556 |
|
657 |
557 |
};
|
658 |
558 |
|
659 |
559 |
/// \ingroup graph_adaptors
|
660 |
560 |
///
|
661 |
561 |
/// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
|
662 |
562 |
///
|
663 |
563 |
/// SubDigraphAdaptor shows the digraph with filtered node-set and
|
664 |
|
/// arc-set. If the \c checked parameter is true then it filters the arcset
|
665 |
|
/// to do not get invalid arcs without source or target.
|
666 |
|
/// Let \f$ G=(V, A) \f$ be a directed digraph
|
667 |
|
/// and suppose that the digraph instance \c g of type ListDigraph
|
668 |
|
/// implements \f$ G \f$.
|
669 |
|
/// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
|
670 |
|
/// on the node-set and arc-set.
|
671 |
|
/// SubDigraphAdaptor<...>::NodeIt iterates
|
672 |
|
/// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and
|
673 |
|
/// SubDigraphAdaptor<...>::ArcIt iterates
|
674 |
|
/// on the arc-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly,
|
675 |
|
/// SubDigraphAdaptor<...>::OutArcIt and
|
676 |
|
/// SubDigraphAdaptor<...>::InArcIt iterates
|
677 |
|
/// only on arcs leaving and entering a specific node which have true value.
|
|
564 |
/// arc-set. If the \c checked parameter is true then it filters the arc-set
|
|
565 |
/// respect to the source and target.
|
678 |
566 |
///
|
679 |
|
/// If the \c checked template parameter is false then we have to
|
680 |
|
/// note that the node-iterator cares only the filter on the
|
681 |
|
/// node-set, and the arc-iterator cares only the filter on the
|
682 |
|
/// arc-set. This way the arc-map should filter all arcs which's
|
683 |
|
/// source or target is filtered by the node-filter.
|
|
567 |
/// If the \c checked template parameter is false then the
|
|
568 |
/// node-iterator cares only the filter on the node-set, and the
|
|
569 |
/// arc-iterator cares only the filter on the arc-set. Therefore
|
|
570 |
/// the arc-map have to filter all arcs which's source or target is
|
|
571 |
/// filtered by the node-filter.
|
684 |
572 |
///\code
|
685 |
573 |
/// typedef ListDigraph Digraph;
|
686 |
574 |
/// DIGRAPH_TYPEDEFS(Digraph);
|
687 |
575 |
/// Digraph g;
|
688 |
576 |
/// Node u=g.addNode(); //node of id 0
|
689 |
577 |
/// Node v=g.addNode(); //node of id 1
|
690 |
578 |
/// Arc a=g.addArc(u, v); //arc of id 0
|
691 |
579 |
/// Arc f=g.addArc(v, u); //arc of id 1
|
692 |
580 |
/// BoolNodeMap nm(g, true);
|
693 |
581 |
/// nm.set(u, false);
|
694 |
582 |
/// BoolArcMap am(g, true);
|
695 |
583 |
/// am.set(a, false);
|
696 |
|
/// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubGA;
|
697 |
|
/// SubGA ga(g, nm, am);
|
698 |
|
/// for (SubGA::NodeIt n(ga); n!=INVALID; ++n)
|
|
584 |
/// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA;
|
|
585 |
/// SubDGA ga(g, nm, am);
|
|
586 |
/// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n)
|
699 |
587 |
/// std::cout << g.id(n) << std::endl;
|
700 |
|
/// std::cout << ":-)" << std::endl;
|
701 |
|
/// for (SubGA::ArcIt a(ga); a!=INVALID; ++a)
|
|
588 |
/// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a)
|
702 |
589 |
/// std::cout << g.id(a) << std::endl;
|
703 |
590 |
///\endcode
|
704 |
591 |
/// The output of the above code is the following.
|
705 |
592 |
///\code
|
706 |
593 |
/// 1
|
707 |
|
/// :-)
|
708 |
594 |
/// 1
|
709 |
595 |
///\endcode
|
710 |
|
/// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
|
|
596 |
/// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
|
711 |
597 |
/// \c Digraph::Node that is why \c g.id(n) can be applied.
|
712 |
598 |
///
|
713 |
599 |
/// For other examples see also the documentation of
|
714 |
600 |
/// NodeSubDigraphAdaptor and ArcSubDigraphAdaptor.
|
715 |
601 |
template<typename _Digraph,
|
716 |
602 |
typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
|
717 |
603 |
typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
|
718 |
604 |
bool checked = true>
|
719 |
605 |
class SubDigraphAdaptor :
|
720 |
606 |
public DigraphAdaptorExtender<
|
721 |
607 |
SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, checked> > {
|
722 |
608 |
public:
|
723 |
609 |
typedef _Digraph Digraph;
|
724 |
610 |
typedef _NodeFilterMap NodeFilterMap;
|
725 |
611 |
typedef _ArcFilterMap ArcFilterMap;
|
726 |
612 |
|
727 |
613 |
typedef DigraphAdaptorExtender<
|
728 |
614 |
SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
|
729 |
615 |
Parent;
|
730 |
616 |
|
|
617 |
typedef typename Parent::Node Node;
|
|
618 |
typedef typename Parent::Arc Arc;
|
|
619 |
|
731 |
620 |
protected:
|
732 |
621 |
SubDigraphAdaptor() { }
|
733 |
622 |
public:
|
734 |
623 |
|
|
624 |
/// \brief Constructor
|
|
625 |
///
|
|
626 |
/// Creates a sub-digraph-adaptor for the given digraph with
|
|
627 |
/// given node and arc map filters.
|
735 |
628 |
SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter,
|
736 |
629 |
ArcFilterMap& arc_filter) {
|
737 |
630 |
setDigraph(digraph);
|
738 |
631 |
setNodeFilterMap(node_filter);
|
739 |
632 |
setArcFilterMap(arc_filter);
|
740 |
633 |
}
|
741 |
634 |
|
|
635 |
/// \brief Hides the node of the graph
|
|
636 |
///
|
|
637 |
/// This function hides \c n in the digraph, i.e. the iteration
|
|
638 |
/// jumps over it. This is done by simply setting the value of \c n
|
|
639 |
/// to be false in the corresponding node-map.
|
|
640 |
void hide(const Node& n) const { Parent::hide(n); }
|
|
641 |
|
|
642 |
/// \brief Hides the arc of the graph
|
|
643 |
///
|
|
644 |
/// This function hides \c a in the digraph, i.e. the iteration
|
|
645 |
/// jumps over it. This is done by simply setting the value of \c a
|
|
646 |
/// to be false in the corresponding arc-map.
|
|
647 |
void hide(const Arc& a) const { Parent::hide(a); }
|
|
648 |
|
|
649 |
/// \brief Unhides the node of the graph
|
|
650 |
///
|
|
651 |
/// The value of \c n is set to be true in the node-map which stores
|
|
652 |
/// hide information. If \c n was hidden previuosly, then it is shown
|
|
653 |
/// again
|
|
654 |
void unHide(const Node& n) const { Parent::unHide(n); }
|
|
655 |
|
|
656 |
/// \brief Unhides the arc of the graph
|
|
657 |
///
|
|
658 |
/// The value of \c a is set to be true in the arc-map which stores
|
|
659 |
/// hide information. If \c a was hidden previuosly, then it is shown
|
|
660 |
/// again
|
|
661 |
void unHide(const Arc& a) const { Parent::unHide(a); }
|
|
662 |
|
|
663 |
/// \brief Returns true if \c n is hidden.
|
|
664 |
///
|
|
665 |
/// Returns true if \c n is hidden.
|
|
666 |
///
|
|
667 |
bool hidden(const Node& n) const { return Parent::hidden(n); }
|
|
668 |
|
|
669 |
/// \brief Returns true if \c a is hidden.
|
|
670 |
///
|
|
671 |
/// Returns true if \c a is hidden.
|
|
672 |
///
|
|
673 |
bool hidden(const Arc& a) const { return Parent::hidden(a); }
|
|
674 |
|
742 |
675 |
};
|
743 |
676 |
|
744 |
|
/// \brief Just gives back a sub digraph adaptor
|
|
677 |
/// \brief Just gives back a sub-digraph-adaptor
|
745 |
678 |
///
|
746 |
|
/// Just gives back a sub digraph adaptor
|
|
679 |
/// Just gives back a sub-digraph-adaptor
|
747 |
680 |
template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
|
748 |
681 |
SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
|
749 |
682 |
subDigraphAdaptor(const Digraph& digraph,
|
750 |
683 |
NodeFilterMap& nfm, ArcFilterMap& afm) {
|
751 |
684 |
return SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
|
752 |
685 |
(digraph, nfm, afm);
|
753 |
686 |
}
|
754 |
687 |
|
755 |
688 |
template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
|
756 |
689 |
SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
|
757 |
690 |
subDigraphAdaptor(const Digraph& digraph,
|
758 |
691 |
NodeFilterMap& nfm, ArcFilterMap& afm) {
|
... |
... |
@@ -765,24 +698,25 @@
|
765 |
698 |
subDigraphAdaptor(const Digraph& digraph,
|
766 |
699 |
NodeFilterMap& nfm, ArcFilterMap& afm) {
|
767 |
700 |
return SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
|
768 |
701 |
(digraph, nfm, afm);
|
769 |
702 |
}
|
770 |
703 |
|
771 |
704 |
template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
|
772 |
705 |
SubDigraphAdaptor<const Digraph, const NodeFilterMap, const ArcFilterMap>
|
773 |
706 |
subDigraphAdaptor(const Digraph& digraph,
|
774 |
707 |
NodeFilterMap& nfm, ArcFilterMap& afm) {
|
775 |
708 |
return SubDigraphAdaptor<const Digraph, const NodeFilterMap,
|
776 |
709 |
const ArcFilterMap>(digraph, nfm, afm);
|
|
710 |
|
777 |
711 |
}
|
778 |
712 |
|
779 |
713 |
|
780 |
714 |
|
781 |
715 |
///\ingroup graph_adaptors
|
782 |
716 |
///
|
783 |
717 |
///\brief An adaptor for hiding nodes from a digraph.
|
784 |
718 |
///
|
785 |
719 |
///An adaptor for hiding nodes from a digraph. This adaptor
|
786 |
720 |
///specializes SubDigraphAdaptor in the way that only the node-set
|
787 |
721 |
///can be filtered. In usual case the checked parameter is true, we
|
788 |
722 |
///get the induced subgraph. But if the checked parameter is false
|
... |
... |
@@ -793,91 +727,118 @@
|
793 |
727 |
class NodeSubDigraphAdaptor :
|
794 |
728 |
public SubDigraphAdaptor<_Digraph, _NodeFilterMap,
|
795 |
729 |
ConstMap<typename _Digraph::Arc, bool>, checked> {
|
796 |
730 |
public:
|
797 |
731 |
|
798 |
732 |
typedef _Digraph Digraph;
|
799 |
733 |
typedef _NodeFilterMap NodeFilterMap;
|
800 |
734 |
|
801 |
735 |
typedef SubDigraphAdaptor<Digraph, NodeFilterMap,
|
802 |
736 |
ConstMap<typename Digraph::Arc, bool>, checked>
|
803 |
737 |
Parent;
|
804 |
738 |
|
|
739 |
typedef typename Parent::Node Node;
|
|
740 |
|
805 |
741 |
protected:
|
806 |
742 |
ConstMap<typename Digraph::Arc, bool> const_true_map;
|
807 |
743 |
|
808 |
744 |
NodeSubDigraphAdaptor() : const_true_map(true) {
|
809 |
745 |
Parent::setArcFilterMap(const_true_map);
|
810 |
746 |
}
|
811 |
747 |
|
812 |
748 |
public:
|
813 |
749 |
|
|
750 |
/// \brief Constructor
|
|
751 |
///
|
|
752 |
/// Creates a node-sub-digraph-adaptor for the given digraph with
|
|
753 |
/// given node map filter.
|
814 |
754 |
NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) :
|
815 |
755 |
Parent(), const_true_map(true) {
|
816 |
756 |
Parent::setDigraph(_digraph);
|
817 |
757 |
Parent::setNodeFilterMap(node_filter);
|
818 |
758 |
Parent::setArcFilterMap(const_true_map);
|
819 |
759 |
}
|
820 |
760 |
|
|
761 |
/// \brief Hides the node of the graph
|
|
762 |
///
|
|
763 |
/// This function hides \c n in the digraph, i.e. the iteration
|
|
764 |
/// jumps over it. This is done by simply setting the value of \c n
|
|
765 |
/// to be false in the corresponding node-map.
|
|
766 |
void hide(const Node& n) const { Parent::hide(n); }
|
|
767 |
|
|
768 |
/// \brief Unhides the node of the graph
|
|
769 |
///
|
|
770 |
/// The value of \c n is set to be true in the node-map which stores
|
|
771 |
/// hide information. If \c n was hidden previuosly, then it is shown
|
|
772 |
/// again
|
|
773 |
void unHide(const Node& n) const { Parent::unHide(n); }
|
|
774 |
|
|
775 |
/// \brief Returns true if \c n is hidden.
|
|
776 |
///
|
|
777 |
/// Returns true if \c n is hidden.
|
|
778 |
///
|
|
779 |
bool hidden(const Node& n) const { return Parent::hidden(n); }
|
|
780 |
|
821 |
781 |
};
|
822 |
782 |
|
823 |
783 |
|
824 |
|
/// \brief Just gives back a \c NodeSubDigraphAdaptor
|
|
784 |
/// \brief Just gives back a node-sub-digraph adaptor
|
825 |
785 |
///
|
826 |
|
/// Just gives back a \c NodeSubDigraphAdaptor
|
|
786 |
/// Just gives back a node-sub-digraph adaptor
|
827 |
787 |
template<typename Digraph, typename NodeFilterMap>
|
828 |
788 |
NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>
|
829 |
789 |
nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) {
|
830 |
790 |
return NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>(digraph, nfm);
|
831 |
791 |
}
|
832 |
792 |
|
833 |
793 |
template<typename Digraph, typename NodeFilterMap>
|
834 |
794 |
NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
|
835 |
795 |
nodeSubDigraphAdaptor(const Digraph& digraph, const NodeFilterMap& nfm) {
|
836 |
796 |
return NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
|
837 |
797 |
(digraph, nfm);
|
838 |
798 |
}
|
839 |
799 |
|
840 |
800 |
///\ingroup graph_adaptors
|
841 |
801 |
///
|
842 |
802 |
///\brief An adaptor for hiding arcs from a digraph.
|
843 |
803 |
///
|
844 |
804 |
///An adaptor for hiding arcs from a digraph. This adaptor
|
845 |
805 |
///specializes SubDigraphAdaptor in the way that only the arc-set
|
846 |
806 |
///can be filtered. The usefulness of this adaptor is demonstrated
|
847 |
807 |
///in the problem of searching a maximum number of arc-disjoint
|
848 |
808 |
///shortest paths between two nodes \c s and \c t. Shortest here
|
849 |
|
///means being shortest w.r.t. non-negative arc-lengths. Note that
|
850 |
|
///the comprehension of the presented solution need's some
|
851 |
|
///elementary knowlarc from combinatorial optimization.
|
|
809 |
///means being shortest with respect to non-negative
|
|
810 |
///arc-lengths. Note that the comprehension of the presented
|
|
811 |
///solution need's some elementary knowledge from combinatorial
|
|
812 |
///optimization.
|
852 |
813 |
///
|
853 |
814 |
///If a single shortest path is to be searched between \c s and \c
|
854 |
815 |
///t, then this can be done easily by applying the Dijkstra
|
855 |
816 |
///algorithm. What happens, if a maximum number of arc-disjoint
|
856 |
817 |
///shortest paths is to be computed. It can be proved that an arc
|
857 |
818 |
///can be in a shortest path if and only if it is tight with respect
|
858 |
819 |
///to the potential function computed by Dijkstra. Moreover, any
|
859 |
820 |
///path containing only such arcs is a shortest one. Thus we have
|
860 |
821 |
///to compute a maximum number of arc-disjoint paths between \c s
|
861 |
822 |
///and \c t in the digraph which has arc-set all the tight arcs. The
|
862 |
823 |
///computation will be demonstrated on the following digraph, which
|
863 |
824 |
///is read from the dimacs file \c sub_digraph_adaptor_demo.dim.
|
864 |
825 |
///The full source code is available in \ref
|
865 |
826 |
///sub_digraph_adaptor_demo.cc. If you are interested in more demo
|
866 |
827 |
///programs, you can use \ref dim_to_dot.cc to generate .dot files
|
867 |
828 |
///from dimacs files. The .dot file of the following figure was
|
868 |
829 |
///generated by the demo program \ref dim_to_dot.cc.
|
869 |
830 |
///
|
870 |
831 |
///\dot
|
871 |
|
///didigraph lemon_dot_example {
|
|
832 |
///digraph lemon_dot_example {
|
872 |
833 |
///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
|
873 |
834 |
///n0 [ label="0 (s)" ];
|
874 |
835 |
///n1 [ label="1" ];
|
875 |
836 |
///n2 [ label="2" ];
|
876 |
837 |
///n3 [ label="3" ];
|
877 |
838 |
///n4 [ label="4" ];
|
878 |
839 |
///n5 [ label="5" ];
|
879 |
840 |
///n6 [ label="6 (t)" ];
|
880 |
841 |
///arc [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
|
881 |
842 |
///n5 -> n6 [ label="9, length:4" ];
|
882 |
843 |
///n4 -> n6 [ label="8, length:2" ];
|
883 |
844 |
///n3 -> n5 [ label="7, length:1" ];
|
... |
... |
@@ -965,45 +926,72 @@
|
965 |
926 |
/// 1, 0--2->2
|
966 |
927 |
///\endcode
|
967 |
928 |
template<typename _Digraph, typename _ArcFilterMap>
|
968 |
929 |
class ArcSubDigraphAdaptor :
|
969 |
930 |
public SubDigraphAdaptor<_Digraph, ConstMap<typename _Digraph::Node, bool>,
|
970 |
931 |
_ArcFilterMap, false> {
|
971 |
932 |
public:
|
972 |
933 |
typedef _Digraph Digraph;
|
973 |
934 |
typedef _ArcFilterMap ArcFilterMap;
|
974 |
935 |
|
975 |
936 |
typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>,
|
976 |
937 |
ArcFilterMap, false> Parent;
|
|
938 |
|
|
939 |
typedef typename Parent::Arc Arc;
|
|
940 |
|
977 |
941 |
protected:
|
978 |
942 |
ConstMap<typename Digraph::Node, bool> const_true_map;
|
979 |
943 |
|
980 |
944 |
ArcSubDigraphAdaptor() : const_true_map(true) {
|
981 |
945 |
Parent::setNodeFilterMap(const_true_map);
|
982 |
946 |
}
|
983 |
947 |
|
984 |
948 |
public:
|
985 |
949 |
|
|
950 |
/// \brief Constructor
|
|
951 |
///
|
|
952 |
/// Creates a arc-sub-digraph-adaptor for the given digraph with
|
|
953 |
/// given arc map filter.
|
986 |
954 |
ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter)
|
987 |
955 |
: Parent(), const_true_map(true) {
|
988 |
956 |
Parent::setDigraph(digraph);
|
989 |
957 |
Parent::setNodeFilterMap(const_true_map);
|
990 |
958 |
Parent::setArcFilterMap(arc_filter);
|
991 |
959 |
}
|
992 |
960 |
|
|
961 |
/// \brief Hides the arc of the graph
|
|
962 |
///
|
|
963 |
/// This function hides \c a in the digraph, i.e. the iteration
|
|
964 |
/// jumps over it. This is done by simply setting the value of \c a
|
|
965 |
/// to be false in the corresponding arc-map.
|
|
966 |
void hide(const Arc& a) const { Parent::hide(a); }
|
|
967 |
|
|
968 |
/// \brief Unhides the arc of the graph
|
|
969 |
///
|
|
970 |
/// The value of \c a is set to be true in the arc-map which stores
|
|
971 |
/// hide information. If \c a was hidden previuosly, then it is shown
|
|
972 |
/// again
|
|
973 |
void unHide(const Arc& a) const { Parent::unHide(a); }
|
|
974 |
|
|
975 |
/// \brief Returns true if \c a is hidden.
|
|
976 |
///
|
|
977 |
/// Returns true if \c a is hidden.
|
|
978 |
///
|
|
979 |
bool hidden(const Arc& a) const { return Parent::hidden(a); }
|
|
980 |
|
993 |
981 |
};
|
994 |
982 |
|
995 |
|
/// \brief Just gives back an arc sub digraph adaptor
|
|
983 |
/// \brief Just gives back an arc-sub-digraph adaptor
|
996 |
984 |
///
|
997 |
|
/// Just gives back an arc sub digraph adaptor
|
|
985 |
/// Just gives back an arc-sub-digraph adaptor
|
998 |
986 |
template<typename Digraph, typename ArcFilterMap>
|
999 |
987 |
ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>
|
1000 |
988 |
arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) {
|
1001 |
989 |
return ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>(digraph, afm);
|
1002 |
990 |
}
|
1003 |
991 |
|
1004 |
992 |
template<typename Digraph, typename ArcFilterMap>
|
1005 |
993 |
ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
|
1006 |
994 |
arcSubDigraphAdaptor(const Digraph& digraph, const ArcFilterMap& afm) {
|
1007 |
995 |
return ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
|
1008 |
996 |
(digraph, afm);
|
1009 |
997 |
}
|
... |
... |
@@ -1384,30 +1372,30 @@
|
1384 |
1372 |
UndirDigraphAdaptorBase() : _digraph(0) {}
|
1385 |
1373 |
|
1386 |
1374 |
Digraph* _digraph;
|
1387 |
1375 |
|
1388 |
1376 |
void setDigraph(Digraph& digraph) {
|
1389 |
1377 |
_digraph = &digraph;
|
1390 |
1378 |
}
|
1391 |
1379 |
|
1392 |
1380 |
};
|
1393 |
1381 |
|
1394 |
1382 |
///\ingroup graph_adaptors
|
1395 |
1383 |
///
|
1396 |
|
/// \brief An graph is made from a directed digraph by an adaptor
|
|
1384 |
/// \brief A graph is made from a directed digraph by an adaptor
|
1397 |
1385 |
///
|
1398 |
1386 |
/// This adaptor makes an undirected graph from a directed
|
1399 |
|
/// digraph. All arc of the underlying will be showed in the adaptor
|
1400 |
|
/// as an edge. Let's see an informal example about using
|
1401 |
|
/// this adaptor:
|
|
1387 |
/// graph. All arc of the underlying digraph will be showed in the
|
|
1388 |
/// adaptor as an edge. Let's see an informal example about using
|
|
1389 |
/// this adaptor.
|
1402 |
1390 |
///
|
1403 |
1391 |
/// There is a network of the streets of a town. Of course there are
|
1404 |
1392 |
/// some one-way street in the town hence the network is a directed
|
1405 |
1393 |
/// one. There is a crazy driver who go oppositely in the one-way
|
1406 |
1394 |
/// street without moral sense. Of course he can pass this streets
|
1407 |
1395 |
/// slower than the regular way, in fact his speed is half of the
|
1408 |
1396 |
/// normal speed. How long should he drive to get from a source
|
1409 |
1397 |
/// point to the target? Let see the example code which calculate it:
|
1410 |
1398 |
///
|
1411 |
1399 |
/// \todo BadCode, SimpleMap does no exists
|
1412 |
1400 |
///\code
|
1413 |
1401 |
/// typedef UndirDigraphAdaptor<Digraph> Graph;
|
... |
... |
@@ -1793,30 +1781,24 @@
|
1793 |
1781 |
typedef typename _CapacityMap::Value Value;
|
1794 |
1782 |
|
1795 |
1783 |
ResCap(const Adaptor& adaptor) : _adaptor(&adaptor) {}
|
1796 |
1784 |
|
1797 |
1785 |
Value operator[](const Arc& e) const {
|
1798 |
1786 |
return _adaptor->rescap(e);
|
1799 |
1787 |
}
|
1800 |
1788 |
|
1801 |
1789 |
};
|
1802 |
1790 |
|
1803 |
1791 |
};
|
1804 |
1792 |
|
1805 |
|
/// \brief Base class for split digraph adaptor
|
1806 |
|
///
|
1807 |
|
/// Base class of split digraph adaptor. In most case you do not need to
|
1808 |
|
/// use it directly but the documented member functions of this class can
|
1809 |
|
/// be used with the SplitDigraphAdaptor class.
|
1810 |
|
/// \sa SplitDigraphAdaptor
|
1811 |
1793 |
template <typename _Digraph>
|
1812 |
1794 |
class SplitDigraphAdaptorBase {
|
1813 |
1795 |
public:
|
1814 |
1796 |
|
1815 |
1797 |
typedef _Digraph Digraph;
|
1816 |
1798 |
typedef DigraphAdaptorBase<const _Digraph> Parent;
|
1817 |
1799 |
typedef SplitDigraphAdaptorBase Adaptor;
|
1818 |
1800 |
|
1819 |
1801 |
typedef typename Digraph::Node DigraphNode;
|
1820 |
1802 |
typedef typename Digraph::Arc DigraphArc;
|
1821 |
1803 |
|
1822 |
1804 |
class Node;
|
... |
... |
@@ -2013,76 +1995,52 @@
|
2013 |
1995 |
Arc arcFromId(int ix) const {
|
2014 |
1996 |
if ((ix & 1) == 0) {
|
2015 |
1997 |
return Arc(_digraph->arcFromId(ix >> 1));
|
2016 |
1998 |
} else {
|
2017 |
1999 |
return Arc(_digraph->nodeFromId(ix >> 1));
|
2018 |
2000 |
}
|
2019 |
2001 |
}
|
2020 |
2002 |
int maxArcId() const {
|
2021 |
2003 |
return std::max(_digraph->maxNodeId() << 1,
|
2022 |
2004 |
(_digraph->maxArcId() << 1) | 1);
|
2023 |
2005 |
}
|
2024 |
2006 |
|
2025 |
|
/// \brief Returns true when the node is in-node.
|
2026 |
|
///
|
2027 |
|
/// Returns true when the node is in-node.
|
2028 |
2007 |
static bool inNode(const Node& n) {
|
2029 |
2008 |
return n._in;
|
2030 |
2009 |
}
|
2031 |
2010 |
|
2032 |
|
/// \brief Returns true when the node is out-node.
|
2033 |
|
///
|
2034 |
|
/// Returns true when the node is out-node.
|
2035 |
2011 |
static bool outNode(const Node& n) {
|
2036 |
2012 |
return !n._in;
|
2037 |
2013 |
}
|
2038 |
2014 |
|
2039 |
|
/// \brief Returns true when the arc is arc in the original digraph.
|
2040 |
|
///
|
2041 |
|
/// Returns true when the arc is arc in the original digraph.
|
2042 |
2015 |
static bool origArc(const Arc& e) {
|
2043 |
2016 |
return e._item.firstState();
|
2044 |
2017 |
}
|
2045 |
2018 |
|
2046 |
|
/// \brief Returns true when the arc binds an in-node and an out-node.
|
2047 |
|
///
|
2048 |
|
/// Returns true when the arc binds an in-node and an out-node.
|
2049 |
2019 |
static bool bindArc(const Arc& e) {
|
2050 |
2020 |
return e._item.secondState();
|
2051 |
2021 |
}
|
2052 |
2022 |
|
2053 |
|
/// \brief Gives back the in-node created from the \c node.
|
2054 |
|
///
|
2055 |
|
/// Gives back the in-node created from the \c node.
|
2056 |
2023 |
static Node inNode(const DigraphNode& n) {
|
2057 |
2024 |
return Node(n, true);
|
2058 |
2025 |
}
|
2059 |
2026 |
|
2060 |
|
/// \brief Gives back the out-node created from the \c node.
|
2061 |
|
///
|
2062 |
|
/// Gives back the out-node created from the \c node.
|
2063 |
2027 |
static Node outNode(const DigraphNode& n) {
|
2064 |
2028 |
return Node(n, false);
|
2065 |
2029 |
}
|
2066 |
2030 |
|
2067 |
|
/// \brief Gives back the arc binds the two part of the node.
|
2068 |
|
///
|
2069 |
|
/// Gives back the arc binds the two part of the node.
|
2070 |
2031 |
static Arc arc(const DigraphNode& n) {
|
2071 |
2032 |
return Arc(n);
|
2072 |
2033 |
}
|
2073 |
2034 |
|
2074 |
|
/// \brief Gives back the arc of the original arc.
|
2075 |
|
///
|
2076 |
|
/// Gives back the arc of the original arc.
|
2077 |
2035 |
static Arc arc(const DigraphArc& e) {
|
2078 |
2036 |
return Arc(e);
|
2079 |
2037 |
}
|
2080 |
2038 |
|
2081 |
2039 |
typedef True NodeNumTag;
|
2082 |
2040 |
|
2083 |
2041 |
int nodeNum() const {
|
2084 |
2042 |
return 2 * countNodes(*_digraph);
|
2085 |
2043 |
}
|
2086 |
2044 |
|
2087 |
2045 |
typedef True EdgeNumTag;
|
2088 |
2046 |
int arcNum() const {
|
... |
... |
@@ -2266,25 +2224,25 @@
|
2266 |
2224 |
/// \f$ u_{out} \f$ node. If there is an \f$ (v, u) \f$ arc in the
|
2267 |
2225 |
/// original digraph the new target of the arc will be \f$ u_{in} \f$ and
|
2268 |
2226 |
/// similarly the source of the original \f$ (u, v) \f$ arc will be
|
2269 |
2227 |
/// \f$ u_{out} \f$. The adaptor will add for each node in the
|
2270 |
2228 |
/// original digraph an additional arc which will connect
|
2271 |
2229 |
/// \f$ (u_{in}, u_{out}) \f$.
|
2272 |
2230 |
///
|
2273 |
2231 |
/// The aim of this class is to run algorithm with node costs if the
|
2274 |
2232 |
/// algorithm can use directly just arc costs. In this case we should use
|
2275 |
2233 |
/// a \c SplitDigraphAdaptor and set the node cost of the digraph to the
|
2276 |
2234 |
/// bind arc in the adapted digraph.
|
2277 |
2235 |
///
|
2278 |
|
/// By example a maximum flow algoritm can compute how many arc
|
|
2236 |
/// For example a maximum flow algorithm can compute how many arc
|
2279 |
2237 |
/// disjoint paths are in the digraph. But we would like to know how
|
2280 |
2238 |
/// many node disjoint paths are in the digraph. First we have to
|
2281 |
2239 |
/// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow
|
2282 |
2240 |
/// algorithm on the adapted digraph. The bottleneck of the flow will
|
2283 |
2241 |
/// be the bind arcs which bounds the flow with the count of the
|
2284 |
2242 |
/// node disjoint paths.
|
2285 |
2243 |
///
|
2286 |
2244 |
///\code
|
2287 |
2245 |
///
|
2288 |
2246 |
/// typedef SplitDigraphAdaptor<SmartDigraph> SDigraph;
|
2289 |
2247 |
///
|
2290 |
2248 |
/// SDigraph sdigraph(digraph);
|
... |
... |
@@ -2321,34 +2279,93 @@
|
2321 |
2279 |
/// contains some additional member functions and types. The
|
2322 |
2280 |
/// documentation of some member functions may be found just in the
|
2323 |
2281 |
/// SplitDigraphAdaptorBase class.
|
2324 |
2282 |
///
|
2325 |
2283 |
/// \sa SplitDigraphAdaptorBase
|
2326 |
2284 |
template <typename _Digraph>
|
2327 |
2285 |
class SplitDigraphAdaptor
|
2328 |
2286 |
: public DigraphAdaptorExtender<SplitDigraphAdaptorBase<_Digraph> > {
|
2329 |
2287 |
public:
|
2330 |
2288 |
typedef _Digraph Digraph;
|
2331 |
2289 |
typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent;
|
2332 |
2290 |
|
|
2291 |
typedef typename Digraph::Node DigraphNode;
|
|
2292 |
typedef typename Digraph::Arc DigraphArc;
|
|
2293 |
|
2333 |
2294 |
typedef typename Parent::Node Node;
|
2334 |
2295 |
typedef typename Parent::Arc Arc;
|
2335 |
2296 |
|
2336 |
2297 |
/// \brief Constructor of the adaptor.
|
2337 |
2298 |
///
|
2338 |
2299 |
/// Constructor of the adaptor.
|
2339 |
2300 |
SplitDigraphAdaptor(Digraph& g) {
|
2340 |
2301 |
Parent::setDigraph(g);
|
2341 |
2302 |
}
|
2342 |
2303 |
|
|
2304 |
/// \brief Returns true when the node is in-node.
|
|
2305 |
///
|
|
2306 |
/// Returns true when the node is in-node.
|
|
2307 |
static bool inNode(const Node& n) {
|
|
2308 |
return Parent::inNode(n);
|
|
2309 |
}
|
|
2310 |
|
|
2311 |
/// \brief Returns true when the node is out-node.
|
|
2312 |
///
|
|
2313 |
/// Returns true when the node is out-node.
|
|
2314 |
static bool outNode(const Node& n) {
|
|
2315 |
return Parent::outNode(n);
|
|
2316 |
}
|
|
2317 |
|
|
2318 |
/// \brief Returns true when the arc is arc in the original digraph.
|
|
2319 |
///
|
|
2320 |
/// Returns true when the arc is arc in the original digraph.
|
|
2321 |
static bool origArc(const Arc& a) {
|
|
2322 |
return Parent::origArc(a);
|
|
2323 |
}
|
|
2324 |
|
|
2325 |
/// \brief Returns true when the arc binds an in-node and an out-node.
|
|
2326 |
///
|
|
2327 |
/// Returns true when the arc binds an in-node and an out-node.
|
|
2328 |
static bool bindArc(const Arc& a) {
|
|
2329 |
return Parent::bindArc(a);
|
|
2330 |
}
|
|
2331 |
|
|
2332 |
/// \brief Gives back the in-node created from the \c node.
|
|
2333 |
///
|
|
2334 |
/// Gives back the in-node created from the \c node.
|
|
2335 |
static Node inNode(const DigraphNode& n) {
|
|
2336 |
return Parent::inNode(n);
|
|
2337 |
}
|
|
2338 |
|
|
2339 |
/// \brief Gives back the out-node created from the \c node.
|
|
2340 |
///
|
|
2341 |
/// Gives back the out-node created from the \c node.
|
|
2342 |
static Node outNode(const DigraphNode& n) {
|
|
2343 |
return Parent::outNode(n);
|
|
2344 |
}
|
|
2345 |
|
|
2346 |
/// \brief Gives back the arc binds the two part of the node.
|
|
2347 |
///
|
|
2348 |
/// Gives back the arc binds the two part of the node.
|
|
2349 |
static Arc arc(const DigraphNode& n) {
|
|
2350 |
return Parent::arc(n);
|
|
2351 |
}
|
|
2352 |
|
|
2353 |
/// \brief Gives back the arc of the original arc.
|
|
2354 |
///
|
|
2355 |
/// Gives back the arc of the original arc.
|
|
2356 |
static Arc arc(const DigraphArc& a) {
|
|
2357 |
return Parent::arc(a);
|
|
2358 |
}
|
|
2359 |
|
2343 |
2360 |
/// \brief NodeMap combined from two original NodeMap
|
2344 |
2361 |
///
|
2345 |
2362 |
/// This class adapt two of the original digraph NodeMap to
|
2346 |
2363 |
/// get a node map on the adapted digraph.
|
2347 |
2364 |
template <typename InNodeMap, typename OutNodeMap>
|
2348 |
2365 |
class CombinedNodeMap {
|
2349 |
2366 |
public:
|
2350 |
2367 |
|
2351 |
2368 |
typedef Node Key;
|
2352 |
2369 |
typedef typename InNodeMap::Value Value;
|
2353 |
2370 |
|
2354 |
2371 |
/// \brief Constructor
|