graph.hh

Go to the documentation of this file.
00001 // $Id: graph.hh 1139 2009-12-04 15:44:26Z mblatt $
00002 #ifndef DUNE_AMG_GRAPH_HH
00003 #define DUNE_AMG_GRAPH_HH
00004 
00005 #include<cstddef>
00006 #include<algorithm>
00007 #include<vector>
00008 #include<cassert>
00009 #include<dune/common/typetraits.hh>
00010 #include<dune/common/iteratorfacades.hh>
00011 #include<dune/istl/istlexception.hh>
00012 #include<dune/common/propertymap.hh>
00013 
00014 namespace Dune
00015 {
00016   namespace Amg
00017   {
00045     template<class M>
00046     class MatrixGraph
00047     {
00048     public:     
00052       typedef M Matrix;
00053       
00057       typedef typename M::block_type Weight;
00058 
00064       typedef typename M::size_type VertexDescriptor;
00065          
00071       typedef std::ptrdiff_t EdgeDescriptor;
00072 
00073       enum{
00074         /*
00075          * @brief Whether Matrix is mutable.
00076          */
00077         mutableMatrix = is_same<M, typename remove_const<M>::type>::value
00078       };
00079       
00080       
00084       template<class C>
00085       class EdgeIteratorT
00086       {
00087                         
00088       public:
00092         typedef typename remove_const<C>::type MutableContainer;
00096         typedef const typename remove_const<C>::type ConstContainer;
00097         
00098         friend class EdgeIteratorT<MutableContainer>;
00099         friend class EdgeIteratorT<ConstContainer>;
00100 
00101         enum{ 
00103           isMutable = is_same<C, MutableContainer>::value
00104             };
00105         
00109         typedef typename SelectType<isMutable && C::mutableMatrix,typename Matrix::row_type::Iterator,
00110                            typename Matrix::row_type::ConstIterator>::Type
00111         ColIterator;
00112 
00116         typedef typename SelectType<isMutable && C::mutableMatrix,typename M::block_type,
00117                                     const typename M::block_type>::Type
00118         Weight;
00119 
00127         EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
00128                           const ColIterator& end, const EdgeDescriptor& edge);
00129         
00136         EdgeIteratorT(const ColIterator& block);
00137 
00142         template<class C1>
00143         EdgeIteratorT(const EdgeIteratorT<C1>& other);
00144         
00145         typedef typename SelectType<is_same<C, typename remove_const<C>::type>::value && C::mutableMatrix,
00146                                typename M::block_type, const typename M::block_type>::Type
00147         WeightType;
00148         
00152         WeightType& weight() const;
00153 
00155         EdgeIteratorT<C>& operator++();
00156 
00158         bool operator!=(const EdgeIteratorT<typename remove_const<C>::type>& other) const;
00159         
00161         bool operator!=(const EdgeIteratorT<const typename remove_const<C>::type>& other) const;
00162         
00164         bool operator==(const EdgeIteratorT<typename remove_const<C>::type>& other) const;
00165         
00167         bool operator==(const EdgeIteratorT<const typename remove_const<C>::type>& other) const;
00168 
00170         VertexDescriptor target() const;
00171 
00173         VertexDescriptor source() const;
00174         
00176         const EdgeDescriptor& operator*() const;
00177         
00179         const EdgeDescriptor* operator->() const;
00180         
00181       private:
00183         VertexDescriptor source_;
00185         ColIterator block_;
00186         /***
00187          * @brief The column iterator positioned at the end of the row 
00188          * of vertex source_ 
00189          */
00190         ColIterator blockEnd_;
00192         EdgeDescriptor edge_;
00193       };
00194 
00198       template<class C>
00199       class VertexIteratorT
00200       {
00201       public:
00205         typedef typename remove_const<C>::type MutableContainer;
00209         typedef const typename remove_const<C>::type ConstContainer;
00210         
00211         friend class VertexIteratorT<MutableContainer>;
00212         friend class VertexIteratorT<ConstContainer>;
00213 
00214         enum{ 
00216           isMutable = is_same<C, MutableContainer>::value
00217             };
00218 
00224         explicit VertexIteratorT(C* graph, const VertexDescriptor& current);
00225 
00233         explicit VertexIteratorT(const VertexDescriptor& current);
00234         
00235         VertexIteratorT(const VertexIteratorT<MutableContainer>& other);
00236         
00241         VertexIteratorT<C>& operator++();
00242         
00244         bool operator!=(const VertexIteratorT<ConstContainer>& other) const;
00245         
00247         bool operator==(const VertexIteratorT<ConstContainer>& other) const;
00248         
00250         bool operator!=(const VertexIteratorT<MutableContainer>& other) const;
00251         
00253         bool operator==(const VertexIteratorT<MutableContainer>& other) const;
00254         
00255         typedef typename SelectType<is_same<C, typename remove_const<C>::type>::value && C::mutableMatrix,
00256                                typename M::block_type, const typename M::block_type>::Type
00257         WeightType;
00259         WeightType& weight() const;
00260         
00265         const VertexDescriptor& operator*() const;
00266         
00272         EdgeIteratorT<C> begin() const;
00273         
00279         EdgeIteratorT<C> end() const;
00280          
00281       private:
00282         C* graph_;
00283         VertexDescriptor current_;
00284       };
00285       
00289       typedef EdgeIteratorT<const MatrixGraph<Matrix> > ConstEdgeIterator;
00290       
00294       typedef EdgeIteratorT<MatrixGraph<Matrix> > EdgeIterator;
00295       
00299       typedef VertexIteratorT<const MatrixGraph<Matrix> > ConstVertexIterator;
00300       
00304       typedef VertexIteratorT<MatrixGraph<Matrix> > VertexIterator;
00305 
00310       MatrixGraph(Matrix& matrix);
00311       
00315       ~MatrixGraph();
00316       
00321       VertexIterator begin();
00322 
00327       VertexIterator end();
00328       
00333       ConstVertexIterator begin() const;
00334       
00339       ConstVertexIterator end() const;
00340       
00347       EdgeIterator beginEdges(const VertexDescriptor& source);
00348       
00355       EdgeIterator endEdges(const VertexDescriptor& source);
00356 
00357       
00364       ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
00365       
00372       ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
00373 
00378       Matrix& matrix();
00379       
00384       const Matrix& matrix() const;
00385       
00389       std::size_t noVertices() const;
00390 
00397       VertexDescriptor maxVertex() const;
00398       
00402       std::size_t noEdges() const;
00403 
00410       EdgeDescriptor findEdge(const VertexDescriptor& source,
00411                               const VertexDescriptor& target) const;
00412       
00413     private:
00415       Matrix& matrix_;
00417       EdgeDescriptor* start_;
00419       MatrixGraph(const MatrixGraph&);
00420       
00421     };
00422 
00432     template<class G, class T>
00433     class SubGraph
00434     {
00435     public:
00439       typedef G Graph;
00440       
00445       typedef T Excluded;
00446       
00450       typedef typename Graph::VertexDescriptor VertexDescriptor;
00451 
00452       typedef VertexDescriptor* EdgeDescriptor;
00453       
00460       class EdgeIndexMap
00461       {
00462       public:
00463         typedef ReadablePropertyMapTag Category;
00464         
00465         EdgeIndexMap(const EdgeDescriptor& firstEdge)
00466           : firstEdge_(firstEdge)
00467         {}
00468         
00470         EdgeIndexMap(const EdgeIndexMap& emap)
00471           : firstEdge_(emap.firstEdge_)
00472         {}
00473 
00474         std::size_t operator[](const EdgeDescriptor& edge) const
00475         {
00476           return edge-firstEdge_;
00477         }
00478       private:
00480         EdgeDescriptor firstEdge_;
00482         EdgeIndexMap()
00483         {}
00484       };
00485       
00490       EdgeIndexMap getEdgeIndexMap();
00491       
00495       class EdgeIterator : public RandomAccessIteratorFacade<EdgeIterator,const EdgeDescriptor>
00496       {
00497       public:   
00503         explicit EdgeIterator(const VertexDescriptor& source, const EdgeDescriptor& edge);
00504                 
00512         explicit EdgeIterator(const EdgeDescriptor& edge);
00513         
00515         bool equals(const EdgeIterator& other) const;
00516                 
00518         EdgeIterator& increment();
00519         
00521         EdgeIterator& decrement();
00522 
00523         EdgeIterator& advance(std::ptrdiff_t n);
00524 
00526         const EdgeDescriptor& dereference() const;
00527 
00529         const VertexDescriptor& target() const;
00530 
00532         const VertexDescriptor& source() const;
00533 
00534         std::ptrdiff_t distanceTo(const EdgeIterator& other) const;
00535         
00536       private:
00538         VertexDescriptor source_;
00543         EdgeDescriptor edge_;   
00544       };
00545       
00549       class VertexIterator 
00550         : public ForwardIteratorFacade<VertexIterator,const VertexDescriptor>
00551       {
00552       public:
00559         explicit VertexIterator(const SubGraph<G,T>* graph, const VertexDescriptor& current,
00560                        const VertexDescriptor& end);
00561         
00562         
00569         explicit VertexIterator(const VertexDescriptor& current);
00570 
00572         VertexIterator& increment();
00573         
00575         bool equals(const VertexIterator& other) const;
00576                 
00581         const VertexDescriptor& dereference() const;
00582 
00588         EdgeIterator begin() const;
00589         
00595         EdgeIterator end() const;
00596         
00597       private:
00599         const SubGraph<Graph,T>* graph_;
00601         VertexDescriptor current_;
00603         VertexDescriptor end_;
00604       };
00605       
00609       typedef EdgeIterator ConstEdgeIterator;
00610       
00614       typedef VertexIterator ConstVertexIterator;
00615       
00620       ConstVertexIterator begin() const;
00621       
00626       ConstVertexIterator end() const;
00627       
00634       ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
00635       
00642       ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
00643       
00647       std::size_t noVertices() const;
00648       
00655       VertexDescriptor maxVertex() const;
00656 
00660       std::size_t noEdges() const;
00667       const EdgeDescriptor findEdge(const VertexDescriptor& source,
00668                                      const VertexDescriptor& target) const;
00676       SubGraph(const Graph& graph, const T& excluded);
00677       
00681       ~SubGraph();
00682       
00683     private:
00685       const T& excluded_;
00687       std::size_t noVertices_;
00689       VertexDescriptor endVertex_;
00691       int noEdges_;
00696       VertexDescriptor maxVertex_;
00698       VertexDescriptor* edges_;
00700       std::ptrdiff_t* start_;
00702       std::ptrdiff_t* end_;
00704       SubGraph(const SubGraph&)
00705       {}
00706     };
00707 
00708 
00712     template<class G, class VP, class VM=IdentityMap>
00713     class VertexPropertiesGraph
00714     {
00715     public:
00719       typedef G Graph;
00720 
00724       typedef typename Graph::VertexDescriptor VertexDescriptor;
00725 
00729       typedef typename Graph::EdgeDescriptor EdgeDescriptor;
00730       
00734       typedef VP VertexProperties;
00735 
00747       typedef VM VertexMap;
00748       
00752       typedef typename Graph::EdgeIterator EdgeIterator;
00753       
00757       typedef typename Graph::ConstEdgeIterator ConstEdgeIterator;
00758       
00764       EdgeIterator beginEdges(const VertexDescriptor& source);
00765       
00771       EdgeIterator endEdges(const VertexDescriptor& source);
00772 
00778       ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
00779       
00785       ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
00786 
00787       
00788       template<class C>
00789       class VertexIteratorT 
00790         : public SelectType<is_same<typename remove_const<C>::type,
00791                                      C>::value,
00792                             typename Graph::VertexIterator,
00793                             typename Graph::ConstVertexIterator>::Type
00794       {
00795         friend class VertexIteratorT<const typename remove_const<C>::type>;
00796         friend class VertexIteratorT<typename remove_const<C>::type>;
00797       public:
00801         typedef typename SelectType<is_same<typename remove_const<C>::type,
00802                                      C>::value,
00803                                     typename Graph::VertexIterator,
00804                                     typename Graph::ConstVertexIterator>::Type
00805         Father;
00806 
00810         typedef typename SelectType<is_same<typename remove_const<C>::type,
00811                                      C>::value,
00812                                     typename Graph::EdgeIterator,
00813                                     typename Graph::ConstEdgeIterator>::Type
00814         EdgeIterator;
00815         
00821         explicit VertexIteratorT(const Father& iter,
00822                         C* graph);
00823         
00824         
00832         explicit VertexIteratorT(const Father& iter);
00833 
00838         template<class C1>
00839         VertexIteratorT(const VertexIteratorT<C1>& other);
00840         
00844         typename SelectType<is_same<C,typename remove_const<C>::type>::value,
00845                             VertexProperties&,
00846                             const VertexProperties&>::Type 
00847         properties() const;
00848 
00854         EdgeIterator begin() const;
00855         
00861         EdgeIterator end() const;
00862 
00863       private:
00867         C* graph_;
00868       };
00869       
00873       typedef VertexIteratorT<VertexPropertiesGraph<Graph,
00874                                               VertexProperties,VM> > VertexIterator;
00875       
00879       typedef VertexIteratorT<const VertexPropertiesGraph<Graph,
00880                                                     VertexProperties,VM> > ConstVertexIterator;
00881      
00886       VertexIterator begin();
00887 
00892       VertexIterator end();
00893       
00898       ConstVertexIterator begin() const;
00899       
00904       ConstVertexIterator end() const;
00905       
00911       VertexProperties& getVertexProperties(const VertexDescriptor& vertex);
00912       
00918       const VertexProperties& getVertexProperties(const VertexDescriptor& vertex) const;
00919       
00924       const Graph& graph() const;
00925 
00929       std::size_t noVertices() const;
00930       
00934       std::size_t noEdges() const;
00935 
00942       VertexDescriptor maxVertex() const;
00943       
00949       VertexPropertiesGraph(Graph& graph, const VertexMap vmap=VertexMap());
00950       
00951     private:
00952       VertexPropertiesGraph(const VertexPropertiesGraph&)
00953       {}
00954       
00956       Graph& graph_;
00958       VertexMap vmap_;
00960       std::vector<VertexProperties> vertexProperties_;
00961       
00962     };
00963 
00967     template<class G, class VP, class EP, class VM=IdentityMap, class EM=IdentityMap>
00968     class PropertiesGraph
00969     {
00970     public:
00974       typedef G Graph;
00975 
00979       typedef typename Graph::VertexDescriptor VertexDescriptor;
00980 
00984       typedef typename Graph::EdgeDescriptor EdgeDescriptor;
00985       
00989       typedef VP VertexProperties;
00990       
01002       typedef VM VertexMap;
01003 
01007       typedef EP EdgeProperties;
01008      
01009       
01021       typedef EM EdgeMap;
01022 
01023       template<class C>
01024       class EdgeIteratorT 
01025         :  public SelectType<is_same<typename remove_const<C>::type,
01026                                       C>::value,
01027                              typename Graph::EdgeIterator,
01028                              typename Graph::ConstEdgeIterator>::Type
01029       {
01030         
01031         friend class EdgeIteratorT<const typename remove_const<C>::type>;
01032         friend class EdgeIteratorT<typename remove_const<C>::type>;
01033       public:
01037         typedef typename SelectType<is_same<typename remove_const<C>::type,
01038                                       C>::value,
01039                                     typename Graph::EdgeIterator,
01040                                     typename Graph::ConstEdgeIterator>::Type
01041         Father;
01042         
01048         explicit EdgeIteratorT(const Father& iter,
01049                         C* graph);
01050         
01058         explicit EdgeIteratorT(const Father& iter);
01059 
01064         template<class C1>
01065         EdgeIteratorT(const EdgeIteratorT<C1>& other);
01066         
01070         typename SelectType<is_same<C,typename remove_const<C>::type>::value,
01071                             EdgeProperties&,
01072                             const EdgeProperties&>::Type 
01073         properties() const;
01074         
01075       private:
01079         C* graph_;
01080       };
01081       
01085       typedef EdgeIteratorT<PropertiesGraph<Graph,
01086                                             VertexProperties,
01087                                             EdgeProperties,VM,EM> > EdgeIterator;
01088       
01092       typedef EdgeIteratorT<const PropertiesGraph<Graph,
01093                                                   VertexProperties,
01094                                                   EdgeProperties,VM,EM> > ConstEdgeIterator;
01095       
01101       EdgeIterator beginEdges(const VertexDescriptor& source);
01102       
01108       EdgeIterator endEdges(const VertexDescriptor& source);
01109 
01115       ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
01116       
01122       ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
01123 
01124       
01125       template<class C>
01126       class VertexIteratorT 
01127         : public SelectType<is_same<typename remove_const<C>::type,
01128                                      C>::value,
01129                             typename Graph::VertexIterator,
01130                             typename Graph::ConstVertexIterator>::Type
01131       {
01132         friend class VertexIteratorT<const typename remove_const<C>::type>;
01133         friend class VertexIteratorT<typename remove_const<C>::type>;
01134       public:
01138         typedef typename SelectType<is_same<typename remove_const<C>::type,
01139                                      C>::value,
01140                                     typename Graph::VertexIterator,
01141                                     typename Graph::ConstVertexIterator>::Type
01142         Father;
01143 
01149         explicit VertexIteratorT(const Father& iter,
01150                         C* graph);
01151         
01152         
01160         explicit VertexIteratorT(const Father& iter);
01161 
01166         template<class C1>
01167         VertexIteratorT(const VertexIteratorT<C1>& other);
01168         
01172         typename SelectType<is_same<C,typename remove_const<C>::type>::value,
01173                             VertexProperties&,
01174                             const VertexProperties&>::Type 
01175         properties() const;
01176 
01182         EdgeIteratorT<C> begin() const;
01183         
01189         EdgeIteratorT<C> end() const;
01190 
01191       private:
01195         C* graph_;
01196       };
01197       
01201       typedef VertexIteratorT<PropertiesGraph<Graph,
01202                                               VertexProperties,
01203                                               EdgeProperties,VM,EM> > VertexIterator;
01204       
01208       typedef VertexIteratorT<const PropertiesGraph<Graph,
01209                                                     VertexProperties,
01210                                                     EdgeProperties,VM,EM> > ConstVertexIterator;
01211      
01216       VertexIterator begin();
01217 
01222       VertexIterator end();
01223       
01228       ConstVertexIterator begin() const;
01229       
01234       ConstVertexIterator end() const;
01235       
01241       VertexProperties& getVertexProperties(const VertexDescriptor& vertex);
01242       
01248       const VertexProperties& getVertexProperties(const VertexDescriptor& vertex) const;
01249 
01255       EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge);
01256       
01257       
01263       const EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge) const;
01264       
01271       EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
01272                                     const VertexDescriptor& target);
01273       
01280       const EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
01281                                     const VertexDescriptor& target) const;
01282       
01287       const Graph& graph() const;
01288 
01292       std::size_t noVertices() const;
01293 
01297       std::size_t noEdges() const;
01298 
01305       VertexDescriptor maxVertex() const;
01306       
01313       PropertiesGraph(Graph& graph, const VertexMap& vmap=VertexMap(),
01314                       const EdgeMap& emap=EdgeMap());
01315       
01316     private:
01317       PropertiesGraph(const PropertiesGraph&)
01318       {}
01319       
01321       Graph& graph_;
01324       VertexMap vmap_;
01325       std::vector<VertexProperties> vertexProperties_;
01327       EdgeMap emap_;
01329       std::vector<EdgeProperties> edgeProperties_;
01330       
01331     };
01332 
01333     
01338     template<typename G>
01339     class GraphVertexPropertiesSelector
01340     {
01341     public:
01345       typedef G Graph;
01349       typedef typename G::VertexProperties VertexProperties;
01353       typedef typename G::VertexDescriptor Vertex;
01354       
01359       GraphVertexPropertiesSelector(G& g)
01360         : graph_(g)
01361       {}
01365       GraphVertexPropertiesSelector()
01366         :graph_(0)
01367       {}
01368       
01369 
01374       VertexProperties& operator[](const Vertex& vertex) const
01375       {
01376         return graph_->getVertexProperties(vertex);
01377       }
01378     private:
01379       Graph* graph_;
01380     };
01381     
01386     template<typename G>
01387     class GraphEdgePropertiesSelector
01388     {
01389     public:
01393       typedef G Graph;
01397       typedef typename G::EdgeProperties EdgeProperties;
01401       typedef typename G::EdgeDescriptor Edge;
01402       
01407       GraphEdgePropertiesSelector(G& g)
01408         : graph_(g)
01409       {}
01413       GraphEdgePropertiesSelector()
01414         :graph_(0)
01415       {}
01416 
01421       EdgeProperties& operator[](const Edge& edge) const
01422       {
01423         return graph_->getEdgeProperties(edge);
01424       }
01425     private:
01426       Graph* graph_;
01427     };
01428     
01429 
01440     template<class G, class V>
01441     int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex, 
01442                          V& visitor);
01443 
01444 #ifndef DOXYGEN
01445     
01446     template<class M>
01447     MatrixGraph<M>::MatrixGraph(M& matrix)
01448       : matrix_(matrix)
01449     {
01450       if(matrix_.N()!=matrix_.M())
01451         DUNE_THROW(ISTLError, "Matrix has to have as many columns as rows!");
01452 
01453       start_ = new EdgeDescriptor[matrix_.N()+1];
01454       
01455       typedef typename M::ConstIterator Iterator;
01456       Iterator row = matrix_.begin();
01457       start_[row.index()] = 0;
01458       
01459       for(Iterator row=matrix_.begin(); row != matrix_.end(); ++row)
01460         start_[row.index()+1] = start_[row.index()] + row->size();
01461     }
01462 
01463     template<class M>
01464     MatrixGraph<M>::~MatrixGraph()
01465     {
01466       delete[] start_;
01467     }
01468     
01469     template<class M>
01470     inline std::size_t MatrixGraph<M>::noEdges() const
01471     {
01472       return start_[matrix_.N()];
01473     }
01474     
01475     template<class M>
01476     inline std::size_t MatrixGraph<M>::noVertices() const
01477     {
01478       return matrix_.N();
01479     }
01480 
01481     template<class M>
01482     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::maxVertex() const
01483     {
01484       return matrix_.N()-1;
01485     }
01486 
01487     template<class M>
01488     typename MatrixGraph<M>::EdgeDescriptor
01489     MatrixGraph<M>::findEdge(const VertexDescriptor& source,
01490                              const VertexDescriptor& target) const
01491     {
01492 #ifdef DUNE_ISTL_WITH_CHECKING
01493       if(!matrix_.exists(source,target))
01494          DUNE_THROW(ISTLError, "matrix entry ("<<source<<","<<target<<") does not exist!");
01495       // diagonal is assumed to exist, so search for it
01496       // If not present this should throw an exception
01497       typename M::ConstColIterator found = matrix_[source].find(source);
01498       if(found == matrix_[source].end())
01499         DUNE_THROW(ISTLError, "Every matrix row is assumed to have a diagonal!");
01500 #endif
01501       std::size_t offset = matrix_[source].find(target).offset();
01502       if(target>source)
01503         offset--;
01504       
01505       assert(offset<noEdges());
01506       
01507       return start_[source]+offset;
01508     }
01509     
01510         
01511     template<class M>
01512     inline M& MatrixGraph<M>::matrix()
01513     {
01514       return matrix_;
01515     }
01516 
01517     template<class M>
01518     inline const M& MatrixGraph<M>::matrix() const
01519     {
01520       return matrix_;
01521     }   
01522     
01523     template<class M>
01524     template<class C>
01525     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
01526                           const ColIterator& end, const EdgeDescriptor& edge)
01527       : source_(source), block_(block), blockEnd_(end), edge_(edge)
01528     {
01529       if(block_!=blockEnd_ && block_.index() == source_){
01530         // This is the edge from the diagonal to the diagonal. Skip it.
01531         ++block_;
01532       }
01533     }
01534    
01535     template<class M>
01536     template<class C>
01537     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const ColIterator& block)
01538       : block_(block)
01539     {}
01540     
01541     template<class M>
01542     template<class C>
01543     template<class C1>
01544     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
01545       : source_(other.source_), block_(other.block_), blockEnd_(other.blockEnd_), edge_(other.edge_)
01546     {}
01547 
01548     
01549     template<class M>
01550     template<class C>
01551     inline typename MatrixGraph<M>::template EdgeIteratorT<C>::WeightType& 
01552     MatrixGraph<M>::EdgeIteratorT<C>::weight() const
01553     {
01554       return *block_;
01555     }
01556 
01557     template<class M>
01558     template<class C>
01559     inline MatrixGraph<M>::EdgeIteratorT<C>& MatrixGraph<M>::EdgeIteratorT<C>::operator++()
01560     {      
01561       ++block_;
01562       ++edge_;
01563       
01564       if(block_!=blockEnd_ && block_.index() == source_){
01565         // This is the edge from the diagonal to the diagonal. Skip it.
01566         ++block_;
01567       }
01568       
01569       return *this;
01570     }
01571     
01572     template<class M>
01573     template<class C>
01574     inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<typename remove_const<C>::type>& other) const
01575     {
01576       return block_!=other.block_;
01577     }
01578 
01579     template<class M>
01580     template<class C>
01581     inline  bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<const typename remove_const<C>::type>& other) const
01582     {
01583       return block_!=other.block_;
01584     }
01585     
01586     template<class M>
01587     template<class C>
01588     inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<typename remove_const<C>::type>& other) const
01589     {
01590       return block_==other.block_;
01591     }
01592 
01593     template<class M>
01594     template<class C>
01595     inline  bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<const typename remove_const<C>::type>& other) const
01596     {
01597       return block_==other.block_;
01598     }
01599     
01600     template<class M>
01601     template<class C>
01602     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::target() const
01603     {
01604       return block_.index();
01605     }
01606     
01607     template<class M>
01608     template<class C>
01609     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::source() const
01610     {
01611       return source_;
01612     }
01613 
01614     template<class M>
01615     template<class C>
01616     inline const typename MatrixGraph<M>::EdgeDescriptor& MatrixGraph<M>::EdgeIteratorT<C>::operator*() const
01617     {
01618       return edge_;
01619     }
01620   
01621     template<class M>
01622     template<class C>
01623     inline const typename MatrixGraph<M>::EdgeDescriptor* MatrixGraph<M>::EdgeIteratorT<C>::operator->() const
01624     {
01625       return &edge_;
01626     }
01627 
01628     template<class M>
01629     template<class C>
01630     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(C* graph,
01631                                                       const VertexDescriptor& current)
01632       : graph_(graph), current_(current)
01633     {}
01634     
01635     
01636     template<class M>
01637     template<class C>
01638     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexDescriptor& current)
01639       : current_(current)
01640     {}
01641 
01642     template<class M>
01643     template<class C>
01644     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexIteratorT<MutableContainer>& other)
01645       : graph_(other.graph_), current_(other.current_)
01646     {}
01647     
01648     template<class M>
01649     template<class C>
01650     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<MutableContainer>& other) const
01651     {
01652       return current_ != other.current_;
01653     }
01654     
01655     template<class M>
01656     template<class C>
01657     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<ConstContainer>& other) const
01658     {
01659       return current_ != other.current_;
01660     }
01661     
01662     
01663     template<class M>
01664     template<class C>
01665     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<MutableContainer>& other) const
01666     {
01667       return current_ == other.current_;
01668     }
01669     
01670     template<class M>
01671     template<class C>
01672     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<ConstContainer>& other) const
01673     {
01674       return current_ == other.current_;
01675     }
01676 
01677     template<class M>
01678     template<class C>
01679     inline MatrixGraph<M>::VertexIteratorT<C>& MatrixGraph<M>::VertexIteratorT<C>::operator++()
01680     {
01681       ++current_;
01682       return *this;
01683     }
01684     
01685     template<class M>
01686     template<class C>
01687     inline typename MatrixGraph<M>::template VertexIteratorT<C>::WeightType&
01688     MatrixGraph<M>::VertexIteratorT<C>::weight() const
01689     {
01690       return graph_->matrix()[current_][current_];
01691     }
01692 
01693     template<class M>
01694     template<class C>
01695     inline const typename MatrixGraph<M>::VertexDescriptor& 
01696     MatrixGraph<M>::VertexIteratorT<C>::operator*() const
01697     {
01698       return current_;
01699     }
01700     
01701     template<class M>
01702     template<class C>
01703     inline MatrixGraph<M>::EdgeIteratorT<C>
01704     MatrixGraph<M>::VertexIteratorT<C>::begin() const
01705     {
01706       return graph_->beginEdges(current_);
01707     }
01708     
01709     template<class M>
01710     template<class C>
01711     inline MatrixGraph<M>::EdgeIteratorT<C>
01712     MatrixGraph<M>::VertexIteratorT<C>::end() const
01713     {
01714       return graph_->endEdges(current_);
01715     }
01716     
01717     template<class M>
01718     inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01719     MatrixGraph<M>::begin()
01720     {
01721       return VertexIterator(this,0);
01722     }
01723     
01724     template<class M>
01725     inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01726     MatrixGraph<M>::end()
01727     {
01728       return VertexIterator(matrix_.N());
01729     }
01730 
01731     
01732     template<class M>
01733     inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01734     MatrixGraph<M>::begin() const
01735     {
01736       return ConstVertexIterator(this, 0);
01737     }
01738     
01739     template<class M>
01740     inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01741     MatrixGraph<M>::end() const
01742     {
01743       return ConstVertexIterator(matrix_.N());
01744     }
01745 
01746     template<class M>
01747     inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01748     MatrixGraph<M>::beginEdges(const VertexDescriptor& source)
01749     {
01750       return EdgeIterator(source, matrix_.operator[](source).begin(),
01751                           matrix_.operator[](source).end(), start_[source]);
01752     }
01753      
01754     template<class M>
01755     inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01756     MatrixGraph<M>::endEdges(const VertexDescriptor& source)
01757     {
01758       return EdgeIterator(matrix_.operator[](source).end());
01759     }
01760 
01761     
01762     template<class M>
01763     inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01764     MatrixGraph<M>::beginEdges(const VertexDescriptor& source) const
01765     {
01766       return ConstEdgeIterator(source, matrix_.operator[](source).begin(),
01767                                matrix_.operator[](source).end(), start_[source]);
01768     }
01769      
01770     template<class M>
01771     inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01772     MatrixGraph<M>::endEdges(const VertexDescriptor& source) const
01773     {
01774       return ConstEdgeIterator(matrix_.operator[](source).end());
01775     }
01776     
01777 
01778     template<class G, class T>
01779     SubGraph<G,T>::EdgeIterator::EdgeIterator(const VertexDescriptor& source,
01780                                             const EdgeDescriptor& edge)
01781       : source_(source), edge_(edge)
01782     {}
01783 
01784     
01785     template<class G, class T>
01786     SubGraph<G,T>::EdgeIterator::EdgeIterator(const EdgeDescriptor& edge)
01787       : edge_(edge)
01788     {}
01789 
01790     template<class G, class T>
01791     typename SubGraph<G,T>::EdgeIndexMap SubGraph<G,T>::getEdgeIndexMap()
01792     {
01793       return EdgeIndexMap(edges_);
01794     }
01795     
01796     template<class G, class T>
01797     inline bool SubGraph<G,T>::EdgeIterator::equals(const EdgeIterator& other) const
01798     {
01799       return other.edge_==edge_;
01800     }
01801 
01802     template<class G, class T>
01803     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::increment()
01804     {
01805       ++edge_;
01806       return *this;
01807     }
01808     
01809     template<class G, class T>
01810     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::decrement()
01811     {
01812       --edge_;
01813       return *this;
01814     }
01815 
01816     template<class G, class T>
01817     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::advance(std::ptrdiff_t n)
01818     {
01819       edge_+=n;
01820       return *this;
01821     }
01822     template<class G, class T>
01823     inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::source() const
01824     {
01825       return source_;
01826     }
01827     
01828     template<class G, class T>
01829     inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::target() const
01830     {
01831       return *edge_;
01832     }
01833 
01834     
01835     template<class G, class T>
01836     inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::EdgeIterator::dereference() const
01837     {
01838       return edge_;
01839     }
01840 
01841     template<class G, class T>
01842     inline std::ptrdiff_t SubGraph<G,T>::EdgeIterator::distanceTo(const EdgeIterator& other) const
01843     {
01844       return other.edge_-edge_;
01845     }
01846     
01847     template<class G, class T>
01848     SubGraph<G,T>::VertexIterator::VertexIterator(const SubGraph<G,T>* graph,
01849                                                 const VertexDescriptor& current,
01850                                                 const VertexDescriptor& end)
01851       : graph_(graph), current_(current), end_(end)
01852     {
01853       // Skip excluded vertices
01854       typedef typename T::const_iterator Iterator;
01855 
01856       for(Iterator vertex = graph_->excluded_.begin(); 
01857           current_ != end_ && *vertex; 
01858           ++vertex)
01859         ++current_;
01860       assert(current_ == end_ || !graph_->excluded_[current_]);
01861     }
01862     
01863     template<class G, class T>
01864     SubGraph<G,T>::VertexIterator::VertexIterator(const VertexDescriptor& current)
01865       : current_(current)
01866     {}
01867 
01868     template<class G, class T>
01869     inline typename SubGraph<G,T>::VertexIterator& SubGraph<G,T>::VertexIterator::increment()
01870     {
01871       ++current_;
01872       //Skip excluded vertices
01873       while(current_ != end_ && graph_->excluded_[current_])
01874         ++current_;
01875       
01876       assert(current_ == end_ || !graph_->excluded_[current_]);
01877       return *this;
01878     }
01879     
01880     template<class G, class T>
01881     inline bool SubGraph<G,T>::VertexIterator::equals(const VertexIterator& other) const
01882     {
01883       return current_==other.current_;
01884     }
01885     
01886     template<class G, class T>
01887     inline const typename G::VertexDescriptor& SubGraph<G,T>::VertexIterator::dereference() const
01888     {
01889       return current_;
01890     }
01891     
01892     template<class G, class T>
01893     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::begin() const
01894     {
01895       return graph_->beginEdges(current_);
01896     }
01897     
01898     template<class G, class T>
01899     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::end() const
01900     {
01901       return graph_->endEdges(current_);
01902     }
01903 
01904     template<class G, class T>
01905     inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::begin() const
01906     {
01907       return VertexIterator(this, 0, endVertex_);
01908     }
01909     
01910     
01911     template<class G, class T>
01912     inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::end() const
01913     {
01914       return VertexIterator(endVertex_);
01915     }
01916     
01917 
01918     template<class G, class T>
01919     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::beginEdges(const VertexDescriptor& source) const
01920     {
01921       return EdgeIterator(source, edges_+start_[source]);
01922     }
01923 
01924     template<class G, class T>
01925     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::endEdges(const VertexDescriptor& source) const
01926     {
01927       return EdgeIterator(edges_+end_[source]);
01928     }
01929 
01930     template<class G, class T>
01931     std::size_t SubGraph<G,T>::noVertices() const
01932     {
01933       return noVertices_;
01934     }
01935 
01936     template<class G, class T>
01937     inline typename SubGraph<G,T>::VertexDescriptor SubGraph<G,T>::maxVertex() const
01938     {
01939       return maxVertex_;
01940     }
01941 
01942     template<class G, class T>
01943     inline std::size_t SubGraph<G,T>::noEdges() const
01944     {
01945       return noEdges_;
01946     }
01947 
01948     template<class G, class T>
01949     inline const typename SubGraph<G,T>::EdgeDescriptor SubGraph<G,T>::findEdge(const VertexDescriptor& source,
01950                                                                       const VertexDescriptor& target) const
01951     {
01952       const EdgeDescriptor edge = std::lower_bound(edges_+start_[source], edges_+end_[source], target);
01953 #ifdef DUNE_ISTL_WITH_CHECKING
01954       if(edge==edges_+end_[source] || *edge!=target)
01955         DUNE_THROW(ISTLError, "No such edge found!");
01956 #endif
01957 
01958       return edge;
01959     }
01960       
01961     template<class G, class T>
01962     SubGraph<G,T>::~SubGraph()
01963     {
01964       delete[] edges_;
01965       delete[] end_;
01966       delete[] start_;
01967     }
01968     
01969     template<class G, class T>
01970     SubGraph<G,T>::SubGraph(const G& graph, const T& excluded)
01971       : excluded_(excluded), noVertices_(0), endVertex_(0), maxVertex_(graph.maxVertex())
01972     {
01973       start_ = new std::ptrdiff_t[graph.noVertices()];
01974       end_ = new std::ptrdiff_t[graph.noVertices()];
01975       edges_ = new VertexDescriptor[graph.noEdges()];
01976       
01977       VertexDescriptor* edge=edges_;
01978       
01979       typedef typename Graph::ConstVertexIterator Iterator;
01980       Iterator endVertex=graph.end();
01981       
01982       for(Iterator vertex = graph.begin(); vertex != endVertex; ++vertex)
01983         if(excluded_[*vertex])
01984           start_[*vertex]=end_[*vertex]=-1;
01985         else{
01986           ++noVertices_;
01987           endVertex_ = std::max(*vertex, endVertex_);
01988           
01989           start_[*vertex] = edge-edges_;
01990 
01991           typedef typename Graph::ConstEdgeIterator Iterator;
01992           Iterator endEdge = vertex.end();
01993           
01994           for(Iterator iter=vertex.begin(); iter!= endEdge; ++iter)
01995             if(!excluded[iter.target()]){
01996               *edge = iter.target();
01997               ++edge;
01998             }
01999 
02000           end_[*vertex] = edge - edges_;
02001 
02002           // Sort the edges
02003           std::sort(edges_+start_[*vertex], edge);
02004         }
02005       noEdges_ = edge-edges_;
02006       ++endVertex_;
02007     }
02008 
02009     template<class G, class V, class VM>
02010     inline std::size_t VertexPropertiesGraph<G,V,VM>::noEdges() const
02011     {
02012       return graph_.noEdges();
02013     }
02014 
02015     template<class G, class V, class VM>
02016     inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
02017     VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source)
02018     {
02019       return graph_.beginEdges(source);
02020     }
02021     
02022     template<class G, class V, class VM>
02023     inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
02024     VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source)
02025     {
02026       return graph_.endEdges(source);
02027     }
02028 
02029     template<class G, class V, class VM>
02030     typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02031     inline VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source) const
02032     {
02033       return graph_.beginEdges(source);
02034     }
02035     
02036     template<class G, class V, class VM>
02037     typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02038     VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source) const
02039     {
02040       return graph_.endEdges(source);
02041     }
02042 
02043     template<class G, class V, class VM>
02044     template<class C>
02045     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02046     ::VertexIteratorT(const Father& iter,
02047                       C* graph)
02048       : Father(iter), graph_(graph)
02049     {}
02050 
02051     template<class G, class V, class VM>
02052     template<class C>
02053     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02054     ::VertexIteratorT(const Father& iter)
02055       : Father(iter)
02056     {}
02057 
02058     template<class G, class V, class VM>
02059     template<class C>
02060     template<class C1>
02061     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02062     ::VertexIteratorT(const VertexIteratorT<C1>& other)
02063       : Father(other), graph_(other.graph_)
02064     {}
02065 
02066     template<class G, class V, class VM>
02067     template<class C>
02068     typename SelectType<is_same<C,typename remove_const<C>::type>::value,
02069                         V&, const V&>::Type
02070     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties() const
02071     {
02072       return graph_->getVertexProperties(Father::operator*());
02073     }
02074     
02075     template<class G, class V, class VM>
02076     template<class C>
02077     typename SelectType<is_same<typename remove_const<C>::type,
02078                                  C>::value,
02079                         typename G::EdgeIterator,
02080                         typename G::ConstEdgeIterator>::Type
02081     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::begin() const
02082     {
02083       return graph_->beginEdges(Father::operator*());
02084     }
02085 
02086     template<class G, class V, class VM>
02087     template<class C>
02088     typename SelectType<is_same<typename remove_const<C>::type,
02089                                  C>::value,
02090                         typename G::EdgeIterator,
02091                         typename G::ConstEdgeIterator>::Type
02092     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::end() const
02093     {
02094       return graph_->endEdges(Father::operator*());
02095     }
02096 
02097     template<class G, class V, class VM>
02098     inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
02099     {
02100       return VertexIterator(graph_.begin(), this);
02101     }
02102     
02103     template<class G, class V, class VM>
02104     inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
02105     {
02106       return VertexIterator(graph_.end());
02107     }
02108 
02109     
02110     template<class G, class V, class VM>
02111     inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin() const
02112     {
02113       return ConstVertexIterator(graph_.begin(), this);
02114     }
02115     
02116     template<class G, class V, class VM>
02117     inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end() const
02118     {
02119       return ConstVertexIterator(graph_.end());
02120     }
02121 
02122     template<class G, class V, class VM>
02123     inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex)
02124     {
02125       return vertexProperties_[vmap_[vertex]];
02126     }
02127     
02128     template<class G, class V, class VM>
02129     inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex) const
02130     {
02131       return vertexProperties_[vmap_[vertex]];
02132     }
02133 
02134     template<class G, class V, class VM>
02135     inline const G& VertexPropertiesGraph<G,V,VM>::graph() const
02136     {
02137       return graph_;
02138     }
02139 
02140     template<class G, class V, class VM>
02141     inline std::size_t VertexPropertiesGraph<G,V,VM>::noVertices() const
02142     {
02143       return graph_.noVertices();
02144     }
02145     
02146     
02147     template<class G, class V, class VM>
02148     inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex() const
02149     {
02150       return graph_.maxVertex();
02151     }
02152 
02153     template<class G, class V, class VM>
02154     VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph, const VM vmap)
02155       : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V())
02156     {}
02157 
02158     template<class G, class V, class E, class VM, class EM>
02159     template<class C>
02160     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter,
02161                                                     C* graph)
02162       : Father(iter), graph_(graph)
02163     {}
02164     
02165     template<class G, class V, class E, class VM, class EM>
02166     template<class C>
02167     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter)
02168       : Father(iter)
02169     {}
02170 
02171     template<class G, class V, class E, class VM, class EM>
02172     template<class C>
02173     template<class C1>
02174     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
02175       : Father(other), graph_(other.graph_)
02176     {}
02177 
02178 
02179     template<class G, class V, class E, class VM, class EM>
02180     inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noEdges() const
02181     {
02182       return graph_.noEdges();
02183     }
02184 
02185     template<class G, class V, class E, class VM, class EM>
02186     template<class C>
02187     inline typename SelectType<is_same<C,typename remove_const<C>::type>::value,E&,const E&>::Type
02188     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties() const
02189     {
02190       return graph_->getEdgeProperties(Father::operator*());
02191     }
02192     
02193     template<class G, class V, class E, class VM, class EM>
02194     inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02195     PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source)
02196     {
02197       return EdgeIterator(graph_.beginEdges(source), this);
02198     }
02199     
02200     template<class G, class V, class E, class VM, class EM>
02201     inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02202     PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source)
02203     {
02204       return EdgeIterator(graph_.endEdges(source));
02205     }
02206 
02207     template<class G, class V, class E, class VM, class EM>
02208     typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02209     inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source) const
02210     {
02211       return ConstEdgeIterator(graph_.beginEdges(source), this);
02212     }
02213     
02214     template<class G, class V, class E, class VM, class EM>
02215     typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02216     PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source) const
02217     {
02218       return ConstEdgeIterator(graph_.endEdges(source));
02219     }
02220 
02221     template<class G, class V, class E, class VM, class EM>
02222     template<class C>
02223     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02224     ::VertexIteratorT(const Father& iter,
02225                       C* graph)
02226       : Father(iter), graph_(graph)
02227     {}
02228 
02229     template<class G, class V, class E, class VM, class EM>
02230     template<class C>
02231     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02232     ::VertexIteratorT(const Father& iter)
02233       : Father(iter)
02234     {}
02235 
02236     template<class G, class V, class E, class VM, class EM>
02237     template<class C>
02238     template<class C1>
02239     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02240     ::VertexIteratorT(const VertexIteratorT<C1>& other)
02241       : Father(other), graph_(other.graph_)
02242     {}
02243 
02244     template<class G, class V, class E, class VM, class EM>
02245     template<class C>
02246     inline typename SelectType<is_same<C,typename remove_const<C>::type>::value,
02247                         V&, const V&>::Type
02248     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties() const
02249     {
02250       return graph_->getVertexProperties(Father::operator*());
02251     }
02252     
02253     template<class G, class V, class E, class VM, class EM>
02254     template<class C>
02255     inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02256     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::begin() const
02257     {
02258       return graph_->beginEdges(Father::operator*());
02259     }
02260 
02261     template<class G, class V, class E, class VM, class EM>
02262     template<class C>
02263     inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02264     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::end() const
02265     {
02266       return graph_->endEdges(Father::operator*());
02267     }
02268 
02269     template<class G, class V, class E, class VM, class EM>
02270     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
02271     {
02272       return VertexIterator(graph_.begin(), this);
02273     }
02274     
02275     template<class G, class V, class E, class VM, class EM>
02276     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
02277     {
02278       return VertexIterator(graph_.end());
02279     }
02280 
02281     
02282     template<class G, class V, class E, class VM, class EM>
02283     inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin() const
02284     {
02285       return ConstVertexIterator(graph_.begin(), this);
02286     }
02287     
02288     template<class G, class V, class E, class VM, class EM>
02289     inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end() const
02290     {
02291       return ConstVertexIterator(graph_.end());
02292     }
02293 
02294     template<class G, class V, class E, class VM, class EM>
02295     inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex)
02296     {
02297       return vertexProperties_[vmap_[vertex]];
02298     }
02299     
02300     template<class G, class V, class E, class VM, class EM>
02301     inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex) const
02302     {
02303       return vertexProperties_[vmap_[vertex]];
02304     }
02305     
02306     template<class G, class V, class E, class VM, class EM>
02307     inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge)
02308     {
02309       return edgeProperties_[emap_[edge]];
02310     }
02311 
02312     template<class G, class V, class E, class VM, class EM>
02313     inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge) const
02314     {
02315       return edgeProperties_[emap_[edge]];
02316     }
02317 
02318     template<class G, class V, class E, class VM, class EM>
02319     inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02320                                                const VertexDescriptor& target)
02321     {
02322       return getEdgeProperties(graph_.findEdge(source,target));
02323     }
02324 
02325     template<class G, class V, class E, class VM, class EM>
02326     inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02327                                                const VertexDescriptor& target) const
02328     {
02329       return getEdgeProperties(graph_.findEdge(source,target));
02330     }
02331 
02332     template<class G, class V, class E, class VM, class EM>
02333     inline const G& PropertiesGraph<G,V,E,VM,EM>::graph() const
02334     {
02335       return graph_;
02336     }
02337 
02338     template<class G, class V, class E, class VM, class EM>
02339     inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noVertices() const
02340     {
02341       return graph_.noVertices();
02342     }
02343     
02344     
02345     template<class G, class V, class E, class VM, class EM>
02346     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex() const
02347     {
02348       return graph_.maxVertex();
02349     }
02350 
02351     template<class G, class V, class E, class VM, class EM>
02352     PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph, const VM& vmap, const EM& emap)
02353       : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V()),
02354         emap_(emap), edgeProperties_(graph_.noEdges(), E())
02355     {}
02356 
02357     template<class G, class V>
02358     inline int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex, 
02359                          V& visitor)
02360     {      
02361       typedef typename G::ConstEdgeIterator iterator;
02362       const iterator end = graph.endEdges(vertex);
02363       int noNeighbours=0;
02364       for(iterator edge = graph.beginEdges(vertex); edge != end; ++edge, ++noNeighbours)
02365         visitor(edge);
02366       return noNeighbours;
02367     }
02368 
02369 #endif // DOXYGEN
02370       
02372   }
02373 }
02374 #endif
Generated on Sat Apr 24 11:13:45 2010 for dune-istl by  doxygen 1.6.3