509 /// \ingroup graph_adaptors |
509 /// \ingroup graph_adaptors |
510 /// |
510 /// |
511 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
511 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
512 /// graph. |
512 /// graph. |
513 /// |
513 /// |
514 /// \warning Graph adaptors are in even more experimental state than the |
|
515 /// other parts of the lib. Use them at you own risk. |
|
516 /// |
|
517 /// SubUGraphAdaptor shows the undirected graph with filtered node-set and |
514 /// SubUGraphAdaptor shows the undirected graph with filtered node-set and |
518 /// edge-set. If the \c checked parameter is true then it filters the edgeset |
515 /// edge-set. If the \c checked parameter is true then it filters the edgeset |
519 /// to do not get invalid edges without source or target. |
516 /// to do not get invalid edges without source or target. |
520 /// |
517 /// |
521 /// If the \c checked template parameter is false then we have to note that |
518 /// If the \c checked template parameter is false then we have to note that |
526 /// node-filter. |
523 /// node-filter. |
527 /// |
524 /// |
528 /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to |
525 /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to |
529 /// \c Graph::Node that is why \c g.id(n) can be applied. |
526 /// \c Graph::Node that is why \c g.id(n) can be applied. |
530 /// |
527 /// |
531 /// For examples see also the documentation of NodeSubUGraphAdaptor and |
|
532 /// EdgeSubUGraphAdaptor. |
|
533 /// |
|
534 /// \author Marton Makai |
|
535 |
|
536 template<typename _UGraph, typename NodeFilterMap, |
528 template<typename _UGraph, typename NodeFilterMap, |
537 typename UEdgeFilterMap, bool checked = true> |
529 typename UEdgeFilterMap, bool checked = true> |
538 class SubUGraphAdaptor : |
530 class SubUGraphAdaptor : |
539 public UGraphAdaptorExtender< |
531 public UGraphAdaptorExtender< |
540 SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > { |
532 SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > { |
551 setNodeFilterMap(_node_filter_map); |
543 setNodeFilterMap(_node_filter_map); |
552 setUEdgeFilterMap(_uedge_filter_map); |
544 setUEdgeFilterMap(_uedge_filter_map); |
553 } |
545 } |
554 }; |
546 }; |
555 |
547 |
|
548 template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap> |
|
549 SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap> |
|
550 subUGraphAdaptor(const UGraph& graph, |
|
551 NodeFilterMap& nfm, EdgeFilterMap& efm) { |
|
552 return SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap> |
|
553 (graph, nfm, efm); |
|
554 } |
|
555 |
|
556 template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap> |
|
557 SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap> |
|
558 subUGraphAdaptor(const UGraph& graph, |
|
559 NodeFilterMap& nfm, EdgeFilterMap& efm) { |
|
560 return SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap> |
|
561 (graph, nfm, efm); |
|
562 } |
|
563 |
|
564 template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap> |
|
565 SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap> |
|
566 subUGraphAdaptor(const UGraph& graph, |
|
567 NodeFilterMap& nfm, EdgeFilterMap& efm) { |
|
568 return SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap> |
|
569 (graph, nfm, efm); |
|
570 } |
|
571 |
|
572 template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap> |
|
573 SubUGraphAdaptor<const UGraph, const NodeFilterMap, const EdgeFilterMap> |
|
574 subUGraphAdaptor(const UGraph& graph, |
|
575 NodeFilterMap& nfm, EdgeFilterMap& efm) { |
|
576 return SubUGraphAdaptor<const UGraph, const NodeFilterMap, |
|
577 const EdgeFilterMap>(graph, nfm, efm); |
|
578 } |
|
579 |
556 /// \ingroup graph_adaptors |
580 /// \ingroup graph_adaptors |
557 /// |
581 /// |
558 /// \brief An adaptor for hiding nodes from an undorected graph. |
582 /// \brief An adaptor for hiding nodes from an undirected graph. |
559 /// |
583 /// |
560 /// \warning Graph adaptors are in even more experimental state |
|
561 /// than the other |
|
562 /// parts of the lib. Use them at you own risk. |
|
563 /// |
584 /// |
564 /// An adaptor for hiding nodes from an undirected graph. |
585 /// An adaptor for hiding nodes from an undirected graph. |
565 /// This adaptor specializes SubUGraphAdaptor in the way that only |
586 /// This adaptor specializes SubUGraphAdaptor in the way that only |
566 /// the node-set |
587 /// the node-set |
567 /// can be filtered. In usual case the checked parameter is true, we get the |
588 /// can be filtered. In usual case the checked parameter is true, we get the |
568 /// induced subgraph. But if the checked parameter is false then we can only |
589 /// induced subgraph. But if the checked parameter is false then we can only |
569 /// filter only isolated nodes. |
590 /// filter only isolated nodes. |
570 /// \author Marton Makai |
|
571 template<typename _UGraph, typename NodeFilterMap, bool checked = true> |
591 template<typename _UGraph, typename NodeFilterMap, bool checked = true> |
572 class NodeSubUGraphAdaptor : |
592 class NodeSubUGraphAdaptor : |
573 public SubUGraphAdaptor<_UGraph, NodeFilterMap, |
593 public SubUGraphAdaptor<_UGraph, NodeFilterMap, |
574 ConstMap<typename _UGraph::UEdge, bool>, checked> { |
594 ConstMap<typename _UGraph::UEdge, bool>, checked> { |
575 public: |
595 public: |
607 /// |
627 /// |
608 /// An adaptor for hiding undirected edges from an undirected graph. |
628 /// An adaptor for hiding undirected edges from an undirected graph. |
609 /// This adaptor specializes SubUGraphAdaptor in the way that |
629 /// This adaptor specializes SubUGraphAdaptor in the way that |
610 /// only the edge-set |
630 /// only the edge-set |
611 /// can be filtered. |
631 /// can be filtered. |
612 /// |
|
613 ///\author Marton Makai |
|
614 template<typename _UGraph, typename UEdgeFilterMap> |
632 template<typename _UGraph, typename UEdgeFilterMap> |
615 class EdgeSubUGraphAdaptor : |
633 class EdgeSubUGraphAdaptor : |
616 public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, |
634 public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, |
617 UEdgeFilterMap, false> { |
635 UEdgeFilterMap, false> { |
618 public: |
636 public: |
641 edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) { |
659 edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) { |
642 return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm); |
660 return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm); |
643 } |
661 } |
644 |
662 |
645 template <typename _UGraph, typename _DirectionMap> |
663 template <typename _UGraph, typename _DirectionMap> |
646 class DirectUGraphAdaptorBase { |
664 class DirUGraphAdaptorBase { |
647 public: |
665 public: |
648 |
666 |
649 typedef _UGraph Graph; |
667 typedef _UGraph Graph; |
650 typedef _DirectionMap DirectionMap; |
668 typedef _DirectionMap DirectionMap; |
651 |
669 |
734 |
752 |
735 template <typename _Value> |
753 template <typename _Value> |
736 class NodeMap : public _UGraph::template NodeMap<_Value> { |
754 class NodeMap : public _UGraph::template NodeMap<_Value> { |
737 public: |
755 public: |
738 typedef typename _UGraph::template NodeMap<_Value> Parent; |
756 typedef typename _UGraph::template NodeMap<_Value> Parent; |
739 explicit NodeMap(const DirectUGraphAdaptorBase& ga) |
757 explicit NodeMap(const DirUGraphAdaptorBase& ga) |
740 : Parent(*ga.graph) { } |
758 : Parent(*ga.graph) { } |
741 NodeMap(const DirectUGraphAdaptorBase& ga, const _Value& value) |
759 NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
742 : Parent(*ga.graph, value) { } |
760 : Parent(*ga.graph, value) { } |
743 }; |
761 }; |
744 |
762 |
745 template <typename _Value> |
763 template <typename _Value> |
746 class EdgeMap : public _UGraph::template UEdgeMap<_Value> { |
764 class EdgeMap : public _UGraph::template UEdgeMap<_Value> { |
747 public: |
765 public: |
748 typedef typename _UGraph::template EdgeMap<_Value> Parent; |
766 typedef typename _UGraph::template UEdgeMap<_Value> Parent; |
749 explicit EdgeMap(const DirectUGraphAdaptorBase& ga) |
767 explicit EdgeMap(const DirUGraphAdaptorBase& ga) |
750 : Parent(*ga.graph) { } |
768 : Parent(*ga.graph) { } |
751 EdgeMap(const DirectUGraphAdaptorBase& ga, const _Value& value) |
769 EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
752 : Parent(*ga.graph, value) { } |
770 : Parent(*ga.graph, value) { } |
753 }; |
771 }; |
754 |
772 |
755 |
773 |
756 |
774 |
767 } |
785 } |
768 |
786 |
769 }; |
787 }; |
770 |
788 |
771 |
789 |
772 template<typename _Graph, typename DirectionMap> |
790 /// \ingroup graph_adaptors |
773 class DirectUGraphAdaptor : |
791 /// \brief A directed graph is made from a undirected graph by an adaptor |
|
792 /// |
|
793 /// 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 |
|
795 /// 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 |
|
797 /// default direction of the uedge. The edges can be easily reverted |
|
798 /// by the reverseEdge member in the adaptor. |
|
799 template<typename _Graph, |
|
800 typename DirectionMap = typename _Graph::template UEdgeMap<bool> > |
|
801 class DirUGraphAdaptor : |
774 public GraphAdaptorExtender< |
802 public GraphAdaptorExtender< |
775 DirectUGraphAdaptorBase<_Graph, DirectionMap> > { |
803 DirUGraphAdaptorBase<_Graph, DirectionMap> > { |
776 public: |
804 public: |
777 typedef _Graph Graph; |
805 typedef _Graph Graph; |
778 typedef GraphAdaptorExtender< |
806 typedef GraphAdaptorExtender< |
779 DirectUGraphAdaptorBase<_Graph, DirectionMap> > Parent; |
807 DirUGraphAdaptorBase<_Graph, DirectionMap> > Parent; |
780 protected: |
808 protected: |
781 DirectUGraphAdaptor() { } |
809 DirUGraphAdaptor() { } |
782 public: |
810 public: |
783 DirectUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { |
811 DirUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { |
784 setGraph(_graph); |
812 setGraph(_graph); |
785 setDirectionMap(_direction_map); |
813 setDirectionMap(_direction_map); |
786 } |
814 } |
787 }; |
815 }; |
788 |
816 |
789 template<typename UGraph, typename DirectionMap> |
817 template<typename UGraph, typename DirectionMap> |
790 DirectUGraphAdaptor<const UGraph, DirectionMap> |
818 DirUGraphAdaptor<const UGraph, DirectionMap> |
791 directUGraphAdaptor(const UGraph& graph, DirectionMap& dm) { |
819 dirUGraphAdaptor(const UGraph& graph, DirectionMap& dm) { |
792 return DirectUGraphAdaptor<const UGraph, DirectionMap>(graph, dm); |
820 return DirUGraphAdaptor<const UGraph, DirectionMap>(graph, dm); |
793 } |
821 } |
794 |
822 |
795 template<typename UGraph, typename DirectionMap> |
823 template<typename UGraph, typename DirectionMap> |
796 DirectUGraphAdaptor<const UGraph, const DirectionMap> |
824 DirUGraphAdaptor<const UGraph, const DirectionMap> |
797 directUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) { |
825 dirUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) { |
798 return DirectUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm); |
826 return DirUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm); |
799 } |
827 } |
800 |
828 |
801 } |
829 } |
802 |
830 |
803 #endif |
831 #endif |