40 |
40 |
41 /// \ingroup graph_adaptors |
41 /// \ingroup graph_adaptors |
42 /// |
42 /// |
43 /// \brief Base type for the Graph Adaptors |
43 /// \brief Base type for the Graph Adaptors |
44 /// |
44 /// |
45 /// \warning Graph adaptors are in even more experimental state than the |
|
46 /// other parts of the lib. Use them at you own risk. |
|
47 /// |
|
48 /// This is the base type for most of LEMON graph adaptors. |
45 /// This is the base type for most of LEMON graph adaptors. |
49 /// This class implements a trivial graph adaptor i.e. it only wraps the |
46 /// This class implements a trivial graph adaptor i.e. it only wraps the |
50 /// functions and types of the graph. The purpose of this class is to |
47 /// functions and types of the graph. The purpose of this class is to |
51 /// make easier implementing graph adaptors. E.g. if an adaptor is |
48 /// make easier implementing graph adaptors. E.g. if an adaptor is |
52 /// considered which differs from the wrapped graph only in some of its |
49 /// considered which differs from the wrapped graph only in some of its |
91 void next(UEdge& i) const { graph->next(i); } |
88 void next(UEdge& i) const { graph->next(i); } |
92 void nextIn(Edge& i) const { graph->nextIn(i); } |
89 void nextIn(Edge& i) const { graph->nextIn(i); } |
93 void nextOut(Edge& i) const { graph->nextOut(i); } |
90 void nextOut(Edge& i) const { graph->nextOut(i); } |
94 void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); } |
91 void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); } |
95 |
92 |
96 |
|
97 Node source(const UEdge& e) const { return graph->source(e); } |
93 Node source(const UEdge& e) const { return graph->source(e); } |
98 Node target(const UEdge& e) const { return graph->target(e); } |
94 Node target(const UEdge& e) const { return graph->target(e); } |
99 |
95 |
100 Node source(const Edge& e) const { return graph->source(e); } |
96 Node source(const Edge& e) const { return graph->source(e); } |
101 Node target(const Edge& e) const { return graph->target(e); } |
97 Node target(const Edge& e) const { return graph->target(e); } |
109 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
105 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
110 Edge findEdge(const Node& source, const Node& target, |
106 Edge findEdge(const Node& source, const Node& target, |
111 const Edge& prev = INVALID) { |
107 const Edge& prev = INVALID) { |
112 return graph->findEdge(source, target, prev); |
108 return graph->findEdge(source, target, prev); |
113 } |
109 } |
114 |
|
115 UEdge findUEdge(const Node& source, const Node& target, |
110 UEdge findUEdge(const Node& source, const Node& target, |
116 const UEdge& prev = INVALID) { |
111 const UEdge& prev = INVALID) { |
117 return graph->findUEdge(source, target, prev); |
112 return graph->findUEdge(source, target, prev); |
118 } |
113 } |
119 |
114 |
130 int id(const Node& v) const { return graph->id(v); } |
125 int id(const Node& v) const { return graph->id(v); } |
131 int id(const UEdge& e) const { return graph->id(e); } |
126 int id(const UEdge& e) const { return graph->id(e); } |
132 |
127 |
133 bool direction(const Edge& e) const { return graph->direction(e); } |
128 bool direction(const Edge& e) const { return graph->direction(e); } |
134 Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); } |
129 Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); } |
135 Edge direct(const UEdge& e, const Node& n) const { |
130 |
136 return graph->direct(e, n); |
131 int maxNodeId() const { |
137 } |
132 return graph->maxNodeId(); |
138 |
133 } |
139 Node oppositeNode(const Node& n, const Edge& e) const { |
134 |
140 return graph->oppositeNode(n, e); |
135 int maxEdgeId() const { |
141 } |
136 return graph->maxEdgeId(); |
142 |
137 } |
143 Edge oppositeEdge(const Edge& e) const { |
138 |
144 return graph->oppositeEdge(e); |
139 int maxUEdgeId() const { |
145 } |
140 return graph->maxEdgeId(); |
146 |
141 } |
|
142 |
|
143 typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier; |
|
144 |
|
145 NodeNotifier& getNotifier(Node) const { |
|
146 return graph->getNotifier(Node()); |
|
147 } |
|
148 |
|
149 typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier; |
|
150 |
|
151 EdgeNotifier& getNotifier(Edge) const { |
|
152 return graph->getNotifier(Edge()); |
|
153 } |
|
154 |
|
155 typedef typename ItemSetTraits<Graph, UEdge>::ItemNotifier UEdgeNotifier; |
|
156 |
|
157 UEdgeNotifier& getNotifier(UEdge) const { |
|
158 return graph->getNotifier(UEdge()); |
|
159 } |
147 |
160 |
148 template <typename _Value> |
161 template <typename _Value> |
149 class NodeMap : public Graph::template NodeMap<_Value> { |
162 class NodeMap : public Graph::template NodeMap<_Value> { |
150 public: |
163 public: |
151 typedef typename Graph::template NodeMap<_Value> Parent; |
164 typedef typename Graph::template NodeMap<_Value> Parent; |
377 /// |
390 /// |
378 bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; } |
391 bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; } |
379 |
392 |
380 typedef False NodeNumTag; |
393 typedef False NodeNumTag; |
381 typedef False EdgeNumTag; |
394 typedef False EdgeNumTag; |
|
395 |
|
396 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
|
397 Edge findEdge(const Node& source, const Node& target, |
|
398 const Edge& prev = INVALID) { |
|
399 if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) { |
|
400 return INVALID; |
|
401 } |
|
402 Edge edge = Parent::findEdge(source, target, prev); |
|
403 while (edge != INVALID && !(*uedge_filter_map)[edge]) { |
|
404 edge = Parent::findEdge(source, target, edge); |
|
405 } |
|
406 return edge; |
|
407 } |
|
408 UEdge findUEdge(const Node& source, const Node& target, |
|
409 const UEdge& prev = INVALID) { |
|
410 if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) { |
|
411 return INVALID; |
|
412 } |
|
413 UEdge uedge = Parent::findUEdge(source, target, prev); |
|
414 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
|
415 uedge = Parent::findUEdge(source, target, uedge); |
|
416 } |
|
417 return uedge; |
|
418 } |
382 }; |
419 }; |
383 |
420 |
384 template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap> |
421 template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap> |
385 class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> |
422 class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> |
386 : public UGraphAdaptorBase<_UGraph> { |
423 : public UGraphAdaptorBase<_UGraph> { |
502 /// |
539 /// |
503 bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; } |
540 bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; } |
504 |
541 |
505 typedef False NodeNumTag; |
542 typedef False NodeNumTag; |
506 typedef False EdgeNumTag; |
543 typedef False EdgeNumTag; |
|
544 |
|
545 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
|
546 Edge findEdge(const Node& source, const Node& target, |
|
547 const Edge& prev = INVALID) { |
|
548 Edge edge = Parent::findEdge(source, target, prev); |
|
549 while (edge != INVALID && !(*uedge_filter_map)[edge]) { |
|
550 edge = Parent::findEdge(source, target, edge); |
|
551 } |
|
552 return edge; |
|
553 } |
|
554 UEdge findUEdge(const Node& source, const Node& target, |
|
555 const UEdge& prev = INVALID) { |
|
556 UEdge uedge = Parent::findUEdge(source, target, prev); |
|
557 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
|
558 uedge = Parent::findUEdge(source, target, uedge); |
|
559 } |
|
560 return uedge; |
|
561 } |
507 }; |
562 }; |
508 |
563 |
509 /// \ingroup graph_adaptors |
564 /// \ingroup graph_adaptors |
510 /// |
565 /// |
511 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
566 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
579 |
634 |
580 /// \ingroup graph_adaptors |
635 /// \ingroup graph_adaptors |
581 /// |
636 /// |
582 /// \brief An adaptor for hiding nodes from an undirected graph. |
637 /// \brief An adaptor for hiding nodes from an undirected graph. |
583 /// |
638 /// |
584 /// |
|
585 /// An adaptor for hiding nodes from an undirected graph. |
639 /// An adaptor for hiding nodes from an undirected graph. |
586 /// This adaptor specializes SubUGraphAdaptor in the way that only |
640 /// This adaptor specializes SubUGraphAdaptor in the way that only |
587 /// the node-set |
641 /// the node-set |
588 /// can be filtered. In usual case the checked parameter is true, we get the |
642 /// can be filtered. In usual case the checked parameter is true, we get the |
589 /// induced subgraph. But if the checked parameter is false then we can only |
643 /// induced subgraph. But if the checked parameter is false then we can only |
596 typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, |
650 typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, |
597 ConstMap<typename _UGraph::UEdge, bool> > Parent; |
651 ConstMap<typename _UGraph::UEdge, bool> > Parent; |
598 typedef _UGraph Graph; |
652 typedef _UGraph Graph; |
599 protected: |
653 protected: |
600 ConstMap<typename _UGraph::UEdge, bool> const_true_map; |
654 ConstMap<typename _UGraph::UEdge, bool> const_true_map; |
|
655 |
|
656 NodeSubUGraphAdaptor() : const_true_map(true) { |
|
657 Parent::setUEdgeFilterMap(const_true_map); |
|
658 } |
|
659 |
601 public: |
660 public: |
602 NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : |
661 NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : |
603 Parent(), const_true_map(true) { |
662 Parent(), const_true_map(true) { |
604 Parent::setGraph(_graph); |
663 Parent::setGraph(_graph); |
605 Parent::setNodeFilterMap(_node_filter_map); |
664 Parent::setNodeFilterMap(_node_filter_map); |
637 typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, |
696 typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, |
638 UEdgeFilterMap, false> Parent; |
697 UEdgeFilterMap, false> Parent; |
639 typedef _UGraph Graph; |
698 typedef _UGraph Graph; |
640 protected: |
699 protected: |
641 ConstMap<typename Graph::Node, bool> const_true_map; |
700 ConstMap<typename Graph::Node, bool> const_true_map; |
|
701 |
|
702 EdgeSubUGraphAdaptor() : const_true_map(true) { |
|
703 Parent::setNodeFilterMap(const_true_map); |
|
704 } |
|
705 |
642 public: |
706 public: |
643 EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : |
707 EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : |
644 Parent(), const_true_map(true) { |
708 Parent(), const_true_map(true) { |
645 Parent::setGraph(_graph); |
709 Parent::setGraph(_graph); |
646 Parent::setNodeFilterMap(const_true_map); |
710 Parent::setNodeFilterMap(const_true_map); |
668 typedef _DirectionMap DirectionMap; |
732 typedef _DirectionMap DirectionMap; |
669 |
733 |
670 typedef typename _UGraph::Node Node; |
734 typedef typename _UGraph::Node Node; |
671 typedef typename _UGraph::UEdge Edge; |
735 typedef typename _UGraph::UEdge Edge; |
672 |
736 |
|
737 void reverseEdge(const Edge& edge) { |
|
738 direction->set(edge, !(*direction)[edge]); |
|
739 } |
|
740 |
673 void first(Node& i) const { graph->first(i); } |
741 void first(Node& i) const { graph->first(i); } |
674 void first(Edge& i) const { graph->first(i); } |
742 void first(Edge& i) const { graph->first(i); } |
675 void firstIn(Edge& i, const Node& n) const { |
743 void firstIn(Edge& i, const Node& n) const { |
676 bool d; |
744 bool d; |
677 graph->firstInc(i, d, n); |
745 graph->firstInc(i, d, n); |
744 void clear() const { graph->clear(); } |
812 void clear() const { graph->clear(); } |
745 |
813 |
746 int id(const Node& v) const { return graph->id(v); } |
814 int id(const Node& v) const { return graph->id(v); } |
747 int id(const Edge& e) const { return graph->id(e); } |
815 int id(const Edge& e) const { return graph->id(e); } |
748 |
816 |
749 void reverseEdge(const Edge& edge) { |
817 int maxNodeId() const { |
750 direction->set(edge, !(*direction)[edge]); |
818 return graph->maxNodeId(); |
751 } |
819 } |
|
820 |
|
821 int maxEdgeId() const { |
|
822 return graph->maxEdgeId(); |
|
823 } |
|
824 |
|
825 typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier; |
|
826 |
|
827 NodeNotifier& getNotifier(Node) const { |
|
828 return graph->getNotifier(Node()); |
|
829 } |
|
830 |
|
831 typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier; |
|
832 |
|
833 EdgeNotifier& getNotifier(Edge) const { |
|
834 return graph->getNotifier(Edge()); |
|
835 } |
752 |
836 |
753 template <typename _Value> |
837 template <typename _Value> |
754 class NodeMap : public _UGraph::template NodeMap<_Value> { |
838 class NodeMap : public _UGraph::template NodeMap<_Value> { |
755 public: |
839 public: |
756 typedef typename _UGraph::template NodeMap<_Value> Parent; |
840 typedef typename _UGraph::template NodeMap<_Value> Parent; |
786 |
870 |
787 }; |
871 }; |
788 |
872 |
789 |
873 |
790 /// \ingroup graph_adaptors |
874 /// \ingroup graph_adaptors |
791 /// \brief A directed graph is made from a undirected graph by an adaptor |
875 /// |
|
876 /// \brief A directed graph is made from an undirected graph by an adaptor |
792 /// |
877 /// |
793 /// This adaptor gives a direction for each uedge in the undirected graph. |
878 /// This adaptor gives a direction for each uedge in the undirected graph. |
794 /// The direction of the edges stored in the DirectionMap. This map is |
879 /// The direction of the edges stored in the DirectionMap. This map is |
795 /// a bool map on the undirected edges. If the uedge is mapped to true |
880 /// a bool map on the undirected edges. If the uedge is mapped to true |
796 /// then the direction of the directed edge will be the same as the |
881 /// then the direction of the directed edge will be the same as the |