graph.hh

Go to the documentation of this file.
00001 // $Id: graph.hh 764 2007-05-03 12:39:19Z 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 = SameType<M, typename RemoveConst<M>::Type>::value
00078       };
00079       
00080       
00084       template<class C>
00085       class EdgeIteratorT
00086       {
00087                         
00088       public:
00092         typedef typename RemoveConst<C>::Type MutableContainer;
00096         typedef const typename RemoveConst<C>::Type ConstContainer;
00097         
00098         friend class EdgeIteratorT<MutableContainer>;
00099         friend class EdgeIteratorT<ConstContainer>;
00100 
00101         enum{ 
00103           isMutable = SameType<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<SameType<C, typename RemoveConst<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 RemoveConst<C>::Type>& other) const;
00159         
00161         bool operator!=(const EdgeIteratorT<const typename RemoveConst<C>::Type>& other) const;
00162         
00164         bool operator==(const EdgeIteratorT<typename RemoveConst<C>::Type>& other) const;
00165         
00167         bool operator==(const EdgeIteratorT<const typename RemoveConst<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 RemoveConst<C>::Type MutableContainer;
00209         typedef const typename RemoveConst<C>::Type ConstContainer;
00210         
00211         friend class VertexIteratorT<MutableContainer>;
00212         friend class VertexIteratorT<ConstContainer>;
00213 
00214         enum{ 
00216           isMutable = SameType<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<SameType<C, typename RemoveConst<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       int noVertices() const;
00390 
00397       VertexDescriptor maxVertex() const;
00398       
00402       int 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       int noVertices() const;
00648       
00655       VertexDescriptor maxVertex() const;
00656 
00660       int 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       int noVertices_;
00689       VertexDescriptor endVertex_;
00691       int noEdges_;
00696       VertexDescriptor maxVertex_;
00698       VertexDescriptor* edges_;
00700       int* start_;
00702       int* 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<SameType<typename RemoveConst<C>::Type,
00791                                      C>::value,
00792                             typename Graph::VertexIterator,
00793                             typename Graph::ConstVertexIterator>::Type
00794       {
00795         friend class VertexIteratorT<const typename RemoveConst<C>::Type>;
00796         friend class VertexIteratorT<typename RemoveConst<C>::Type>;
00797       public:
00801         typedef typename SelectType<SameType<typename RemoveConst<C>::Type,
00802                                      C>::value,
00803                                     typename Graph::VertexIterator,
00804                                     typename Graph::ConstVertexIterator>::Type
00805         Father;
00806 
00810         typedef typename SelectType<SameType<typename RemoveConst<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<SameType<C,typename RemoveConst<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       int noVertices() const;
00930       
00937       VertexDescriptor maxVertex() const;
00938       
00944       VertexPropertiesGraph(Graph& graph, const VertexMap vmap=VertexMap());
00945       
00946     private:
00947       VertexPropertiesGraph(const VertexPropertiesGraph&)
00948       {}
00949       
00951       Graph& graph_;
00953       VertexMap vmap_;
00955       std::vector<VertexProperties> vertexProperties_;
00956       
00957     };
00958 
00962     template<class G, class VP, class EP, class VM=IdentityMap, class EM=IdentityMap>
00963     class PropertiesGraph
00964     {
00965     public:
00969       typedef G Graph;
00970 
00974       typedef typename Graph::VertexDescriptor VertexDescriptor;
00975 
00979       typedef typename Graph::EdgeDescriptor EdgeDescriptor;
00980       
00984       typedef VP VertexProperties;
00985       
00997       typedef VM VertexMap;
00998 
01002       typedef EP EdgeProperties;
01003      
01004       
01016       typedef EM EdgeMap;
01017 
01018       template<class C>
01019       class EdgeIteratorT 
01020         :  public SelectType<SameType<typename RemoveConst<C>::Type,
01021                                       C>::value,
01022                              typename Graph::EdgeIterator,
01023                              typename Graph::ConstEdgeIterator>::Type
01024       {
01025         
01026         friend class EdgeIteratorT<const typename RemoveConst<C>::Type>;
01027         friend class EdgeIteratorT<typename RemoveConst<C>::Type>;
01028       public:
01032         typedef typename SelectType<SameType<typename RemoveConst<C>::Type,
01033                                       C>::value,
01034                                     typename Graph::EdgeIterator,
01035                                     typename Graph::ConstEdgeIterator>::Type
01036         Father;
01037         
01043         explicit EdgeIteratorT(const Father& iter,
01044                         C* graph);
01045         
01053         explicit EdgeIteratorT(const Father& iter);
01054 
01059         template<class C1>
01060         EdgeIteratorT(const EdgeIteratorT<C1>& other);
01061         
01065         typename SelectType<SameType<C,typename RemoveConst<C>::Type>::value,
01066                             EdgeProperties&,
01067                             const EdgeProperties&>::Type 
01068         properties() const;
01069         
01070       private:
01074         C* graph_;
01075       };
01076       
01080       typedef EdgeIteratorT<PropertiesGraph<Graph,
01081                                             VertexProperties,
01082                                             EdgeProperties,VM,EM> > EdgeIterator;
01083       
01087       typedef EdgeIteratorT<const PropertiesGraph<Graph,
01088                                                   VertexProperties,
01089                                                   EdgeProperties,VM,EM> > ConstEdgeIterator;
01090       
01096       EdgeIterator beginEdges(const VertexDescriptor& source);
01097       
01103       EdgeIterator endEdges(const VertexDescriptor& source);
01104 
01110       ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
01111       
01117       ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
01118 
01119       
01120       template<class C>
01121       class VertexIteratorT 
01122         : public SelectType<SameType<typename RemoveConst<C>::Type,
01123                                      C>::value,
01124                             typename Graph::VertexIterator,
01125                             typename Graph::ConstVertexIterator>::Type
01126       {
01127         friend class VertexIteratorT<const typename RemoveConst<C>::Type>;
01128         friend class VertexIteratorT<typename RemoveConst<C>::Type>;
01129       public:
01133         typedef typename SelectType<SameType<typename RemoveConst<C>::Type,
01134                                      C>::value,
01135                                     typename Graph::VertexIterator,
01136                                     typename Graph::ConstVertexIterator>::Type
01137         Father;
01138 
01144         explicit VertexIteratorT(const Father& iter,
01145                         C* graph);
01146         
01147         
01155         explicit VertexIteratorT(const Father& iter);
01156 
01161         template<class C1>
01162         VertexIteratorT(const VertexIteratorT<C1>& other);
01163         
01167         typename SelectType<SameType<C,typename RemoveConst<C>::Type>::value,
01168                             VertexProperties&,
01169                             const VertexProperties&>::Type 
01170         properties() const;
01171 
01177         EdgeIteratorT<C> begin() const;
01178         
01184         EdgeIteratorT<C> end() const;
01185 
01186       private:
01190         C* graph_;
01191       };
01192       
01196       typedef VertexIteratorT<PropertiesGraph<Graph,
01197                                               VertexProperties,
01198                                               EdgeProperties,VM,EM> > VertexIterator;
01199       
01203       typedef VertexIteratorT<const PropertiesGraph<Graph,
01204                                                     VertexProperties,
01205                                                     EdgeProperties,VM,EM> > ConstVertexIterator;
01206      
01211       VertexIterator begin();
01212 
01217       VertexIterator end();
01218       
01223       ConstVertexIterator begin() const;
01224       
01229       ConstVertexIterator end() const;
01230       
01236       VertexProperties& getVertexProperties(const VertexDescriptor& vertex);
01237       
01243       const VertexProperties& getVertexProperties(const VertexDescriptor& vertex) const;
01244 
01250       EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge);
01251       
01252       
01258       const EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge) const;
01259       
01266       EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
01267                                     const VertexDescriptor& target);
01268       
01275       const EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
01276                                     const VertexDescriptor& target) const;
01277       
01282       const Graph& graph() const;
01283 
01287       int noVertices() const;
01288       
01295       VertexDescriptor maxVertex() const;
01296       
01303       PropertiesGraph(Graph& graph, const VertexMap& vmap=VertexMap(),
01304                       const EdgeMap& emap=EdgeMap());
01305       
01306     private:
01307       PropertiesGraph(const PropertiesGraph&)
01308       {}
01309       
01311       Graph& graph_;
01314       VertexMap vmap_;
01315       std::vector<VertexProperties> vertexProperties_;
01317       EdgeMap emap_;
01319       std::vector<EdgeProperties> edgeProperties_;
01320       
01321     };
01322 
01323     
01328     template<typename G>
01329     class GraphVertexPropertiesSelector
01330     {
01331     public:
01335       typedef G Graph;
01339       typedef typename G::VertexProperties VertexProperties;
01343       typedef typename G::VertexDescriptor Vertex;
01344       
01349       GraphVertexPropertiesSelector(G& g)
01350         : graph_(g)
01351       {}
01355       GraphVertexPropertiesSelector()
01356         :graph_(0)
01357       {}
01358       
01359 
01364       VertexProperties& operator[](const Vertex& vertex) const
01365       {
01366         return graph_->getVertexProperties(vertex);
01367       }
01368     private:
01369       Graph* graph_;
01370     };
01371     
01376     template<typename G>
01377     class GraphEdgePropertiesSelector
01378     {
01379     public:
01383       typedef G Graph;
01387       typedef typename G::EdgeProperties EdgeProperties;
01391       typedef typename G::EdgeDescriptor Edge;
01392       
01397       GraphEdgePropertiesSelector(G& g)
01398         : graph_(g)
01399       {}
01403       GraphEdgePropertiesSelector()
01404         :graph_(0)
01405       {}
01406 
01411       EdgeProperties& operator[](const Edge& edge) const
01412       {
01413         return graph_->getEdgeProperties(edge);
01414       }
01415     private:
01416       Graph* graph_;
01417     };
01418     
01419 
01429     template<class G, class V>
01430     void visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex, 
01431                          V& visitor);
01432     
01433     template<class M>
01434     MatrixGraph<M>::MatrixGraph(M& matrix)
01435       : matrix_(matrix)
01436     {
01437       if(matrix_.N()!=matrix_.M())
01438         DUNE_THROW(ISTLError, "Matrix has to have as many columns as rows!");
01439 
01440       start_ = new EdgeDescriptor[matrix_.N()+1];
01441       
01442       typedef typename M::ConstIterator Iterator;
01443       Iterator row = matrix_.begin();
01444       start_[row.index()] = 0;
01445       
01446       for(Iterator row=matrix_.begin(); row != matrix_.end(); ++row)
01447         start_[row.index()+1] = start_[row.index()] + row->size();
01448     }
01449 
01450     template<class M>
01451     MatrixGraph<M>::~MatrixGraph()
01452     {
01453       delete[] start_;
01454     }
01455     
01456     template<class M>
01457     inline int MatrixGraph<M>::noEdges() const
01458     {
01459       return start_[matrix_.N()];
01460     }
01461     
01462     template<class M>
01463     inline int MatrixGraph<M>::noVertices() const
01464     {
01465       return matrix_.N();
01466     }
01467 
01468     template<class M>
01469     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::maxVertex() const
01470     {
01471       return matrix_.N();
01472     }
01473 
01474     template<class M>
01475     typename MatrixGraph<M>::EdgeDescriptor
01476     MatrixGraph<M>::findEdge(const VertexDescriptor& source,
01477                              const VertexDescriptor& target) const
01478     {
01479 #ifdef DUNE_ISTL_WITH_CHECKING
01480       if(!matrix_.exists(source,target))
01481          DUNE_THROW(ISTLError, "matrix entry ("<<source<<","<<target<<") does not exist!");
01482       // diagonal is assumed to exist, so search for it
01483       // If not present this should throw an exception
01484       typename M::ConstColIterator found = matrix_[source].find(source);
01485       if(found == matrix_[source].end())
01486         DUNE_THROW(ISTLError, "Every matrix row is assumed to have a diagonal!");
01487 #endif
01488       int offset = matrix_[source].find(target).offset();
01489       if(target>source)
01490         offset--;
01491       
01492       assert(offset<noEdges());
01493       
01494       return start_[source]+offset;
01495     }
01496     
01497         
01498     template<class M>
01499     inline M& MatrixGraph<M>::matrix()
01500     {
01501       return matrix_;
01502     }
01503 
01504     template<class M>
01505     inline const M& MatrixGraph<M>::matrix() const
01506     {
01507       return matrix_;
01508     }   
01509     
01510     template<class M>
01511     template<class C>
01512     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
01513                           const ColIterator& end, const EdgeDescriptor& edge)
01514       : source_(source), block_(block), blockEnd_(end), edge_(edge)
01515     {
01516       if(block_!=blockEnd_ && block_.index() == source_){
01517         // This is the edge from the diagonal to the diagonal. Skip it.
01518         ++block_;
01519       }
01520     }
01521    
01522     template<class M>
01523     template<class C>
01524     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const ColIterator& block)
01525       : block_(block)
01526     {}
01527     
01528     template<class M>
01529     template<class C>
01530     template<class C1>
01531     MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
01532       : source_(other.source_), block_(other.block_), blockEnd_(other.blockEnd_), edge_(other.edge_)
01533     {}
01534 
01535     
01536     template<class M>
01537     template<class C>
01538     inline typename MatrixGraph<M>::template EdgeIteratorT<C>::WeightType& 
01539     MatrixGraph<M>::EdgeIteratorT<C>::weight() const
01540     {
01541       return *block_;
01542     }
01543 
01544     template<class M>
01545     template<class C>
01546     inline MatrixGraph<M>::EdgeIteratorT<C>& MatrixGraph<M>::EdgeIteratorT<C>::operator++()
01547     {      
01548       ++block_;
01549       ++edge_;
01550       
01551       if(block_!=blockEnd_ && block_.index() == source_){
01552         // This is the edge from the diagonal to the diagonal. Skip it.
01553         ++block_;
01554       }
01555       
01556       return *this;
01557     }
01558     
01559     template<class M>
01560     template<class C>
01561     inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<typename RemoveConst<C>::Type>& other) const
01562     {
01563       return block_!=other.block_;
01564     }
01565 
01566     template<class M>
01567     template<class C>
01568     inline  bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<const typename RemoveConst<C>::Type>& other) const
01569     {
01570       return block_!=other.block_;
01571     }
01572     
01573     template<class M>
01574     template<class C>
01575     inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<typename RemoveConst<C>::Type>& other) const
01576     {
01577       return block_==other.block_;
01578     }
01579 
01580     template<class M>
01581     template<class C>
01582     inline  bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<const typename RemoveConst<C>::Type>& other) const
01583     {
01584       return block_==other.block_;
01585     }
01586     
01587     template<class M>
01588     template<class C>
01589     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::target() const
01590     {
01591       return block_.index();
01592     }
01593     
01594     template<class M>
01595     template<class C>
01596     inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::source() const
01597     {
01598       return source_;
01599     }
01600 
01601     template<class M>
01602     template<class C>
01603     inline const typename MatrixGraph<M>::EdgeDescriptor& MatrixGraph<M>::EdgeIteratorT<C>::operator*() const
01604     {
01605       return edge_;
01606     }
01607   
01608     template<class M>
01609     template<class C>
01610     inline const typename MatrixGraph<M>::EdgeDescriptor* MatrixGraph<M>::EdgeIteratorT<C>::operator->() const
01611     {
01612       return &edge_;
01613     }
01614 
01615     template<class M>
01616     template<class C>
01617     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(C* graph,
01618                                                       const VertexDescriptor& current)
01619       : graph_(graph), current_(current)
01620     {}
01621     
01622     
01623     template<class M>
01624     template<class C>
01625     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexDescriptor& current)
01626       : current_(current)
01627     {}
01628 
01629     template<class M>
01630     template<class C>
01631     MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexIteratorT<MutableContainer>& other)
01632       : graph_(other.graph_), current_(other.current_)
01633     {}
01634     
01635     template<class M>
01636     template<class C>
01637     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<MutableContainer>& other) const
01638     {
01639       return current_ != other.current_;
01640     }
01641     
01642     template<class M>
01643     template<class C>
01644     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<ConstContainer>& other) const
01645     {
01646       return current_ != other.current_;
01647     }
01648     
01649     
01650     template<class M>
01651     template<class C>
01652     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<MutableContainer>& other) const
01653     {
01654       return current_ == other.current_;
01655     }
01656     
01657     template<class M>
01658     template<class C>
01659     inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<ConstContainer>& other) const
01660     {
01661       return current_ == other.current_;
01662     }
01663 
01664     template<class M>
01665     template<class C>
01666     inline MatrixGraph<M>::VertexIteratorT<C>& MatrixGraph<M>::VertexIteratorT<C>::operator++()
01667     {
01668       ++current_;
01669       return *this;
01670     }
01671     
01672     template<class M>
01673     template<class C>
01674     inline typename MatrixGraph<M>::template VertexIteratorT<C>::WeightType&
01675     MatrixGraph<M>::VertexIteratorT<C>::weight() const
01676     {
01677       return graph_->matrix()[current_][current_];
01678     }
01679 
01680     template<class M>
01681     template<class C>
01682     inline const typename MatrixGraph<M>::VertexDescriptor& 
01683     MatrixGraph<M>::VertexIteratorT<C>::operator*() const
01684     {
01685       return current_;
01686     }
01687     
01688     template<class M>
01689     template<class C>
01690     inline MatrixGraph<M>::EdgeIteratorT<C>
01691     MatrixGraph<M>::VertexIteratorT<C>::begin() const
01692     {
01693       return graph_->beginEdges(current_);
01694     }
01695     
01696     template<class M>
01697     template<class C>
01698     inline MatrixGraph<M>::EdgeIteratorT<C>
01699     MatrixGraph<M>::VertexIteratorT<C>::end() const
01700     {
01701       return graph_->endEdges(current_);
01702     }
01703     
01704     template<class M>
01705     inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01706     MatrixGraph<M>::begin()
01707     {
01708       return VertexIterator(this,0);
01709     }
01710     
01711     template<class M>
01712     inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01713     MatrixGraph<M>::end()
01714     {
01715       return VertexIterator(matrix_.N());
01716     }
01717 
01718     
01719     template<class M>
01720     inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01721     MatrixGraph<M>::begin() const
01722     {
01723       return ConstVertexIterator(this, 0);
01724     }
01725     
01726     template<class M>
01727     inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01728     MatrixGraph<M>::end() const
01729     {
01730       return ConstVertexIterator(matrix_.N());
01731     }
01732 
01733     template<class M>
01734     inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01735     MatrixGraph<M>::beginEdges(const VertexDescriptor& source)
01736     {
01737       return EdgeIterator(source, matrix_.operator[](source).begin(),
01738                           matrix_.operator[](source).end(), start_[source]);
01739     }
01740      
01741     template<class M>
01742     inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01743     MatrixGraph<M>::endEdges(const VertexDescriptor& source)
01744     {
01745       return EdgeIterator(matrix_.operator[](source).end());
01746     }
01747 
01748     
01749     template<class M>
01750     inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01751     MatrixGraph<M>::beginEdges(const VertexDescriptor& source) const
01752     {
01753       return ConstEdgeIterator(source, matrix_.operator[](source).begin(),
01754                                matrix_.operator[](source).end(), start_[source]);
01755     }
01756      
01757     template<class M>
01758     inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01759     MatrixGraph<M>::endEdges(const VertexDescriptor& source) const
01760     {
01761       return ConstEdgeIterator(matrix_.operator[](source).end());
01762     }
01763     
01764 
01765     template<class G, class T>
01766     SubGraph<G,T>::EdgeIterator::EdgeIterator(const VertexDescriptor& source,
01767                                             const EdgeDescriptor& edge)
01768       : source_(source), edge_(edge)
01769     {}
01770 
01771     
01772     template<class G, class T>
01773     SubGraph<G,T>::EdgeIterator::EdgeIterator(const EdgeDescriptor& edge)
01774       : edge_(edge)
01775     {}
01776 
01777     template<class G, class T>
01778     typename SubGraph<G,T>::EdgeIndexMap SubGraph<G,T>::getEdgeIndexMap()
01779     {
01780       return EdgeIndexMap(edges_);
01781     }
01782     
01783     template<class G, class T>
01784     inline bool SubGraph<G,T>::EdgeIterator::equals(const EdgeIterator& other) const
01785     {
01786       return other.edge_==edge_;
01787     }
01788 
01789     template<class G, class T>
01790     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::increment()
01791     {
01792       ++edge_;
01793       return *this;
01794     }
01795     
01796     template<class G, class T>
01797     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::decrement()
01798     {
01799       --edge_;
01800       return *this;
01801     }
01802 
01803     template<class G, class T>
01804     inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::advance(std::ptrdiff_t n)
01805     {
01806       edge_+=n;
01807       return *this;
01808     }
01809     template<class G, class T>
01810     inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::source() const
01811     {
01812       return source_;
01813     }
01814     
01815     template<class G, class T>
01816     inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::target() const
01817     {
01818       return *edge_;
01819     }
01820 
01821     
01822     template<class G, class T>
01823     inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::EdgeIterator::dereference() const
01824     {
01825       return edge_;
01826     }
01827 
01828     template<class G, class T>
01829     inline std::ptrdiff_t SubGraph<G,T>::EdgeIterator::distanceTo(const EdgeIterator& other) const
01830     {
01831       return other.edge_-edge_;
01832     }
01833     
01834     template<class G, class T>
01835     SubGraph<G,T>::VertexIterator::VertexIterator(const SubGraph<G,T>* graph,
01836                                                 const VertexDescriptor& current,
01837                                                 const VertexDescriptor& end)
01838       : graph_(graph), current_(current), end_(end)
01839     {
01840       // Skip excluded vertices
01841       typedef typename T::const_iterator Iterator;
01842 
01843       for(Iterator vertex = graph_->excluded_.begin(); 
01844           current_ != end_ && *vertex; 
01845           ++vertex)
01846         ++current_;
01847       assert(current_ == end_ || !graph_->excluded_[current_]);
01848     }
01849     
01850     template<class G, class T>
01851     SubGraph<G,T>::VertexIterator::VertexIterator(const VertexDescriptor& current)
01852       : current_(current)
01853     {}
01854 
01855     template<class G, class T>
01856     inline typename SubGraph<G,T>::VertexIterator& SubGraph<G,T>::VertexIterator::increment()
01857     {
01858       ++current_;
01859       //Skip excluded vertices
01860       while(current_ != end_ && graph_->excluded_[current_])
01861         ++current_;
01862       
01863       assert(current_ == end_ || !graph_->excluded_[current_]);
01864       return *this;
01865     }
01866     
01867     template<class G, class T>
01868     inline bool SubGraph<G,T>::VertexIterator::equals(const VertexIterator& other) const
01869     {
01870       return current_==other.current_;
01871     }
01872     
01873     template<class G, class T>
01874     inline const typename G::VertexDescriptor& SubGraph<G,T>::VertexIterator::dereference() const
01875     {
01876       return current_;
01877     }
01878     
01879     template<class G, class T>
01880     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::begin() const
01881     {
01882       return graph_->beginEdges(current_);
01883     }
01884     
01885     template<class G, class T>
01886     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::end() const
01887     {
01888       return graph_->endEdges(current_);
01889     }
01890 
01891     template<class G, class T>
01892     inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::begin() const
01893     {
01894       return VertexIterator(this, 0, endVertex_);
01895     }
01896     
01897     
01898     template<class G, class T>
01899     inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::end() const
01900     {
01901       return VertexIterator(endVertex_);
01902     }
01903     
01904 
01905     template<class G, class T>
01906     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::beginEdges(const VertexDescriptor& source) const
01907     {
01908       return EdgeIterator(source, edges_+start_[source]);
01909     }
01910 
01911     template<class G, class T>
01912     inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::endEdges(const VertexDescriptor& source) const
01913     {
01914       return EdgeIterator(edges_+end_[source]);
01915     }
01916 
01917     template<class G, class T>
01918     int SubGraph<G,T>::noVertices() const
01919     {
01920       return noVertices_;
01921     }
01922 
01923     template<class G, class T>
01924     inline typename SubGraph<G,T>::VertexDescriptor SubGraph<G,T>::maxVertex() const
01925     {
01926       return maxVertex_;
01927     }
01928 
01929     template<class G, class T>
01930     inline int SubGraph<G,T>::noEdges() const
01931     {
01932       return noEdges_;
01933     }
01934 
01935     template<class G, class T>
01936     inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::findEdge(const VertexDescriptor& source,
01937                                                                       const VertexDescriptor& target) const
01938     {
01939       const EdgeDescriptor& edge = std::lower_bound(edges_+start_[source], edges_+end_[source], target);
01940 #ifdef DUNE_ISTL_WITH_CHECKING
01941       if(edge==edges_+end_[source] || *edge!=target)
01942         DUNE_THROW(ISTLError, "No such edge found!");
01943 #endif
01944 
01945       return edge;
01946     }
01947       
01948     template<class G, class T>
01949     SubGraph<G,T>::~SubGraph()
01950     {
01951       delete[] edges_;
01952       delete[] end_;
01953       delete[] start_;
01954     }
01955     
01956     template<class G, class T>
01957     SubGraph<G,T>::SubGraph(const G& graph, const T& excluded)
01958       : excluded_(excluded), noVertices_(0), endVertex_(0), maxVertex_(graph.maxVertex())
01959     {
01960       start_ = new int[graph.noVertices()];
01961       end_ = new int[graph.noVertices()];
01962       edges_ = new VertexDescriptor[graph.noEdges()];
01963       
01964       VertexDescriptor* edge=edges_;
01965       
01966       typedef typename Graph::ConstVertexIterator Iterator;
01967       Iterator endVertex=graph.end();
01968       
01969       for(Iterator vertex = graph.begin(); vertex != endVertex; ++vertex)
01970         if(excluded_[*vertex])
01971           start_[*vertex]=end_[*vertex]=-1;
01972         else{
01973           ++noVertices_;
01974           endVertex_ = std::max(*vertex, endVertex_);
01975           
01976           start_[*vertex] = edge-edges_;
01977 
01978           typedef typename Graph::ConstEdgeIterator Iterator;
01979           Iterator endEdge = vertex.end();
01980           
01981           for(Iterator iter=vertex.begin(); iter!= endEdge; ++iter)
01982             if(!excluded[iter.target()]){
01983               *edge = iter.target();
01984               ++edge;
01985             }
01986 
01987           end_[*vertex] = edge - edges_;
01988 
01989           // Sort the edges
01990           std::sort(edges_+start_[*vertex], edge);
01991         }
01992       noEdges_ = edge-edges_;
01993       ++endVertex_;
01994     }
01995 
01996     template<class G, class V, class VM>
01997     inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
01998     VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source)
01999     {
02000       return graph_.beginEdges(source);
02001     }
02002     
02003     template<class G, class V, class VM>
02004     inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
02005     VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source)
02006     {
02007       return graph_.endEdges(source);
02008     }
02009 
02010     template<class G, class V, class VM>
02011     typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02012     inline VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source) const
02013     {
02014       return graph_.beginEdges(source);
02015     }
02016     
02017     template<class G, class V, class VM>
02018     typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02019     VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source) const
02020     {
02021       return graph_.endEdges(source);
02022     }
02023 
02024     template<class G, class V, class VM>
02025     template<class C>
02026     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02027     ::VertexIteratorT(const Father& iter,
02028                       C* graph)
02029       : Father(iter), graph_(graph)
02030     {}
02031 
02032     template<class G, class V, class VM>
02033     template<class C>
02034     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02035     ::VertexIteratorT(const Father& iter)
02036       : Father(iter)
02037     {}
02038 
02039     template<class G, class V, class VM>
02040     template<class C>
02041     template<class C1>
02042     VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02043     ::VertexIteratorT(const VertexIteratorT<C1>& other)
02044       : Father(other), graph_(other.graph_)
02045     {}
02046 
02047     template<class G, class V, class VM>
02048     template<class C>
02049     typename SelectType<SameType<C,typename RemoveConst<C>::Type>::value,
02050                         V&, const V&>::Type
02051     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties() const
02052     {
02053       return graph_->getVertexProperties(Father::operator*());
02054     }
02055     
02056     template<class G, class V, class VM>
02057     template<class C>
02058     typename SelectType<SameType<typename RemoveConst<C>::Type,
02059                                  C>::value,
02060                         typename G::EdgeIterator,
02061                         typename G::ConstEdgeIterator>::Type
02062     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::begin() const
02063     {
02064       return graph_->beginEdges(Father::operator*());
02065     }
02066 
02067     template<class G, class V, class VM>
02068     template<class C>
02069     typename SelectType<SameType<typename RemoveConst<C>::Type,
02070                                  C>::value,
02071                         typename G::EdgeIterator,
02072                         typename G::ConstEdgeIterator>::Type
02073     inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::end() const
02074     {
02075       return graph_->endEdges(Father::operator*());
02076     }
02077 
02078     template<class G, class V, class VM>
02079     inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
02080     {
02081       return VertexIterator(graph_.begin(), this);
02082     }
02083     
02084     template<class G, class V, class VM>
02085     inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
02086     {
02087       return VertexIterator(graph_.end());
02088     }
02089 
02090     
02091     template<class G, class V, class VM>
02092     inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin() const
02093     {
02094       return ConstVertexIterator(graph_.begin(), this);
02095     }
02096     
02097     template<class G, class V, class VM>
02098     inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end() const
02099     {
02100       return ConstVertexIterator(graph_.end());
02101     }
02102 
02103     template<class G, class V, class VM>
02104     inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex)
02105     {
02106       return vertexProperties_[vmap_[vertex]];
02107     }
02108     
02109     template<class G, class V, class VM>
02110     inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex) const
02111     {
02112       return vertexProperties_[vmap_[vertex]];
02113     }
02114 
02115     template<class G, class V, class VM>
02116     inline const G& VertexPropertiesGraph<G,V,VM>::graph() const
02117     {
02118       return graph_;
02119     }
02120 
02121     template<class G, class V, class VM>
02122     inline int VertexPropertiesGraph<G,V,VM>::noVertices() const
02123     {
02124       return graph_.noVertices();
02125     }
02126     
02127     
02128     template<class G, class V, class VM>
02129     inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex() const
02130     {
02131       return graph_.maxVertex();
02132     }
02133 
02134     template<class G, class V, class VM>
02135     VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph, const VM vmap)
02136       : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()], V())
02137     {}
02138 
02139     template<class G, class V, class E, class VM, class EM>
02140     template<class C>
02141     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter,
02142                                                     C* graph)
02143       : Father(iter), graph_(graph)
02144     {}
02145     
02146     template<class G, class V, class E, class VM, class EM>
02147     template<class C>
02148     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter)
02149       : Father(iter)
02150     {}
02151 
02152     template<class G, class V, class E, class VM, class EM>
02153     template<class C>
02154     template<class C1>
02155     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
02156       : Father(other), graph_(other.graph_)
02157     {}
02158 
02159     template<class G, class V, class E, class VM, class EM>
02160     template<class C>
02161     inline typename SelectType<SameType<C,typename RemoveConst<C>::Type>::value,E&,const E&>::Type
02162     PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties() const
02163     {
02164       return graph_->getEdgeProperties(Father::operator*());
02165     }
02166     
02167     template<class G, class V, class E, class VM, class EM>
02168     inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02169     PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source)
02170     {
02171       return EdgeIterator(graph_.beginEdges(source), this);
02172     }
02173     
02174     template<class G, class V, class E, class VM, class EM>
02175     inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02176     PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source)
02177     {
02178       return EdgeIterator(graph_.endEdges(source));
02179     }
02180 
02181     template<class G, class V, class E, class VM, class EM>
02182     typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02183     inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source) const
02184     {
02185       return ConstEdgeIterator(graph_.beginEdges(source), this);
02186     }
02187     
02188     template<class G, class V, class E, class VM, class EM>
02189     typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02190     PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source) const
02191     {
02192       return ConstEdgeIterator(graph_.endEdges(source));
02193     }
02194 
02195     template<class G, class V, class E, class VM, class EM>
02196     template<class C>
02197     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02198     ::VertexIteratorT(const Father& iter,
02199                       C* graph)
02200       : Father(iter), graph_(graph)
02201     {}
02202 
02203     template<class G, class V, class E, class VM, class EM>
02204     template<class C>
02205     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02206     ::VertexIteratorT(const Father& iter)
02207       : Father(iter)
02208     {}
02209 
02210     template<class G, class V, class E, class VM, class EM>
02211     template<class C>
02212     template<class C1>
02213     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02214     ::VertexIteratorT(const VertexIteratorT<C1>& other)
02215       : Father(other), graph_(other.graph_)
02216     {}
02217 
02218     template<class G, class V, class E, class VM, class EM>
02219     template<class C>
02220     inline typename SelectType<SameType<C,typename RemoveConst<C>::Type>::value,
02221                         V&, const V&>::Type
02222     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties() const
02223     {
02224       return graph_->getVertexProperties(Father::operator*());
02225     }
02226     
02227     template<class G, class V, class E, class VM, class EM>
02228     template<class C>
02229     inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02230     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::begin() const
02231     {
02232       return graph_->beginEdges(Father::operator*());
02233     }
02234 
02235     template<class G, class V, class E, class VM, class EM>
02236     template<class C>
02237     inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02238     PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::end() const
02239     {
02240       return graph_->endEdges(Father::operator*());
02241     }
02242 
02243     template<class G, class V, class E, class VM, class EM>
02244     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
02245     {
02246       return VertexIterator(graph_.begin(), this);
02247     }
02248     
02249     template<class G, class V, class E, class VM, class EM>
02250     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
02251     {
02252       return VertexIterator(graph_.end());
02253     }
02254 
02255     
02256     template<class G, class V, class E, class VM, class EM>
02257     inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin() const
02258     {
02259       return ConstVertexIterator(graph_.begin(), this);
02260     }
02261     
02262     template<class G, class V, class E, class VM, class EM>
02263     inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end() const
02264     {
02265       return ConstVertexIterator(graph_.end());
02266     }
02267 
02268     template<class G, class V, class E, class VM, class EM>
02269     inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex)
02270     {
02271       return vertexProperties_[vmap_[vertex]];
02272     }
02273     
02274     template<class G, class V, class E, class VM, class EM>
02275     inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex) const
02276     {
02277       return vertexProperties_[vmap_[vertex]];
02278     }
02279     
02280     template<class G, class V, class E, class VM, class EM>
02281     inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge)
02282     {
02283       return edgeProperties_[emap_[edge]];
02284     }
02285 
02286     template<class G, class V, class E, class VM, class EM>
02287     inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge) const
02288     {
02289       return edgeProperties_[emap_[edge]];
02290     }
02291 
02292     template<class G, class V, class E, class VM, class EM>
02293     inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02294                                                const VertexDescriptor& target)
02295     {
02296       return edgeProperties_[emap_[graph_.findEdge(source,target)]];
02297     }
02298 
02299     template<class G, class V, class E, class VM, class EM>
02300     inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02301                                                const VertexDescriptor& target) const
02302     {
02303       return edgeProperties_[emap_[graph_.findEdge(source,target)]];
02304     }
02305 
02306     template<class G, class V, class E, class VM, class EM>
02307     inline const G& PropertiesGraph<G,V,E,VM,EM>::graph() const
02308     {
02309       return graph_;
02310     }
02311 
02312     template<class G, class V, class E, class VM, class EM>
02313     inline int PropertiesGraph<G,V,E,VM,EM>::noVertices() const
02314     {
02315       return graph_.noVertices();
02316     }
02317     
02318     
02319     template<class G, class V, class E, class VM, class EM>
02320     inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex() const
02321     {
02322       return graph_.maxVertex();
02323     }
02324 
02325     template<class G, class V, class E, class VM, class EM>
02326     PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph, const VM& vmap, const EM& emap)
02327       : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()], V()),
02328         emap_(emap), edgeProperties_(graph_.noEdges(), E())
02329     {}
02330 
02331     template<class G, class V>
02332     inline void visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex, 
02333                          V& visitor)
02334     {      
02335       typedef typename G::ConstEdgeIterator iterator;
02336       const iterator end = graph.endEdges(vertex);
02337       for(iterator edge = graph.beginEdges(vertex); edge != end; ++edge)
02338         visitor(edge);
02339     }
02340     
02341       
02343   }
02344 }
02345 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)