00001
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
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
00188
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 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<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 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<is_same<typename remove_const<C>::type,
01021 C>::value,
01022 typename Graph::EdgeIterator,
01023 typename Graph::ConstEdgeIterator>::Type
01024 {
01025
01026 friend class EdgeIteratorT<const typename remove_const<C>::type>;
01027 friend class EdgeIteratorT<typename remove_const<C>::type>;
01028 public:
01032 typedef typename SelectType<is_same<typename remove_const<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<is_same<C,typename remove_const<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<is_same<typename remove_const<C>::type,
01123 C>::value,
01124 typename Graph::VertexIterator,
01125 typename Graph::ConstVertexIterator>::Type
01126 {
01127 friend class VertexIteratorT<const typename remove_const<C>::type>;
01128 friend class VertexIteratorT<typename remove_const<C>::type>;
01129 public:
01133 typedef typename SelectType<is_same<typename remove_const<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<is_same<C,typename remove_const<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
01430 template<class G, class V>
01431 int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex,
01432 V& visitor);
01433
01434 template<class M>
01435 MatrixGraph<M>::MatrixGraph(M& matrix)
01436 : matrix_(matrix)
01437 {
01438 if(matrix_.N()!=matrix_.M())
01439 DUNE_THROW(ISTLError, "Matrix has to have as many columns as rows!");
01440
01441 start_ = new EdgeDescriptor[matrix_.N()+1];
01442
01443 typedef typename M::ConstIterator Iterator;
01444 Iterator row = matrix_.begin();
01445 start_[row.index()] = 0;
01446
01447 for(Iterator row=matrix_.begin(); row != matrix_.end(); ++row)
01448 start_[row.index()+1] = start_[row.index()] + row->size();
01449 }
01450
01451 template<class M>
01452 MatrixGraph<M>::~MatrixGraph()
01453 {
01454 delete[] start_;
01455 }
01456
01457 template<class M>
01458 inline int MatrixGraph<M>::noEdges() const
01459 {
01460 return start_[matrix_.N()];
01461 }
01462
01463 template<class M>
01464 inline int MatrixGraph<M>::noVertices() const
01465 {
01466 return matrix_.N();
01467 }
01468
01469 template<class M>
01470 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::maxVertex() const
01471 {
01472 return matrix_.N();
01473 }
01474
01475 template<class M>
01476 typename MatrixGraph<M>::EdgeDescriptor
01477 MatrixGraph<M>::findEdge(const VertexDescriptor& source,
01478 const VertexDescriptor& target) const
01479 {
01480 #ifdef DUNE_ISTL_WITH_CHECKING
01481 if(!matrix_.exists(source,target))
01482 DUNE_THROW(ISTLError, "matrix entry ("<<source<<","<<target<<") does not exist!");
01483
01484
01485 typename M::ConstColIterator found = matrix_[source].find(source);
01486 if(found == matrix_[source].end())
01487 DUNE_THROW(ISTLError, "Every matrix row is assumed to have a diagonal!");
01488 #endif
01489 int offset = matrix_[source].find(target).offset();
01490 if(target>source)
01491 offset--;
01492
01493 assert(offset<noEdges());
01494
01495 return start_[source]+offset;
01496 }
01497
01498
01499 template<class M>
01500 inline M& MatrixGraph<M>::matrix()
01501 {
01502 return matrix_;
01503 }
01504
01505 template<class M>
01506 inline const M& MatrixGraph<M>::matrix() const
01507 {
01508 return matrix_;
01509 }
01510
01511 template<class M>
01512 template<class C>
01513 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
01514 const ColIterator& end, const EdgeDescriptor& edge)
01515 : source_(source), block_(block), blockEnd_(end), edge_(edge)
01516 {
01517 if(block_!=blockEnd_ && block_.index() == source_){
01518
01519 ++block_;
01520 }
01521 }
01522
01523 template<class M>
01524 template<class C>
01525 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const ColIterator& block)
01526 : block_(block)
01527 {}
01528
01529 template<class M>
01530 template<class C>
01531 template<class C1>
01532 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
01533 : source_(other.source_), block_(other.block_), blockEnd_(other.blockEnd_), edge_(other.edge_)
01534 {}
01535
01536
01537 template<class M>
01538 template<class C>
01539 inline typename MatrixGraph<M>::template EdgeIteratorT<C>::WeightType&
01540 MatrixGraph<M>::EdgeIteratorT<C>::weight() const
01541 {
01542 return *block_;
01543 }
01544
01545 template<class M>
01546 template<class C>
01547 inline MatrixGraph<M>::EdgeIteratorT<C>& MatrixGraph<M>::EdgeIteratorT<C>::operator++()
01548 {
01549 ++block_;
01550 ++edge_;
01551
01552 if(block_!=blockEnd_ && block_.index() == source_){
01553
01554 ++block_;
01555 }
01556
01557 return *this;
01558 }
01559
01560 template<class M>
01561 template<class C>
01562 inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<typename remove_const<C>::type>& other) const
01563 {
01564 return block_!=other.block_;
01565 }
01566
01567 template<class M>
01568 template<class C>
01569 inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const MatrixGraph<M>::EdgeIteratorT<const typename remove_const<C>::type>& other) const
01570 {
01571 return block_!=other.block_;
01572 }
01573
01574 template<class M>
01575 template<class C>
01576 inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<typename remove_const<C>::type>& other) const
01577 {
01578 return block_==other.block_;
01579 }
01580
01581 template<class M>
01582 template<class C>
01583 inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const MatrixGraph<M>::EdgeIteratorT<const typename remove_const<C>::type>& other) const
01584 {
01585 return block_==other.block_;
01586 }
01587
01588 template<class M>
01589 template<class C>
01590 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::target() const
01591 {
01592 return block_.index();
01593 }
01594
01595 template<class M>
01596 template<class C>
01597 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::source() const
01598 {
01599 return source_;
01600 }
01601
01602 template<class M>
01603 template<class C>
01604 inline const typename MatrixGraph<M>::EdgeDescriptor& MatrixGraph<M>::EdgeIteratorT<C>::operator*() const
01605 {
01606 return edge_;
01607 }
01608
01609 template<class M>
01610 template<class C>
01611 inline const typename MatrixGraph<M>::EdgeDescriptor* MatrixGraph<M>::EdgeIteratorT<C>::operator->() const
01612 {
01613 return &edge_;
01614 }
01615
01616 template<class M>
01617 template<class C>
01618 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(C* graph,
01619 const VertexDescriptor& current)
01620 : graph_(graph), current_(current)
01621 {}
01622
01623
01624 template<class M>
01625 template<class C>
01626 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexDescriptor& current)
01627 : current_(current)
01628 {}
01629
01630 template<class M>
01631 template<class C>
01632 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexIteratorT<MutableContainer>& other)
01633 : graph_(other.graph_), current_(other.current_)
01634 {}
01635
01636 template<class M>
01637 template<class C>
01638 inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<MutableContainer>& other) const
01639 {
01640 return current_ != other.current_;
01641 }
01642
01643 template<class M>
01644 template<class C>
01645 inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<ConstContainer>& other) const
01646 {
01647 return current_ != other.current_;
01648 }
01649
01650
01651 template<class M>
01652 template<class C>
01653 inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<MutableContainer>& other) const
01654 {
01655 return current_ == other.current_;
01656 }
01657
01658 template<class M>
01659 template<class C>
01660 inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<ConstContainer>& other) const
01661 {
01662 return current_ == other.current_;
01663 }
01664
01665 template<class M>
01666 template<class C>
01667 inline MatrixGraph<M>::VertexIteratorT<C>& MatrixGraph<M>::VertexIteratorT<C>::operator++()
01668 {
01669 ++current_;
01670 return *this;
01671 }
01672
01673 template<class M>
01674 template<class C>
01675 inline typename MatrixGraph<M>::template VertexIteratorT<C>::WeightType&
01676 MatrixGraph<M>::VertexIteratorT<C>::weight() const
01677 {
01678 return graph_->matrix()[current_][current_];
01679 }
01680
01681 template<class M>
01682 template<class C>
01683 inline const typename MatrixGraph<M>::VertexDescriptor&
01684 MatrixGraph<M>::VertexIteratorT<C>::operator*() const
01685 {
01686 return current_;
01687 }
01688
01689 template<class M>
01690 template<class C>
01691 inline MatrixGraph<M>::EdgeIteratorT<C>
01692 MatrixGraph<M>::VertexIteratorT<C>::begin() const
01693 {
01694 return graph_->beginEdges(current_);
01695 }
01696
01697 template<class M>
01698 template<class C>
01699 inline MatrixGraph<M>::EdgeIteratorT<C>
01700 MatrixGraph<M>::VertexIteratorT<C>::end() const
01701 {
01702 return graph_->endEdges(current_);
01703 }
01704
01705 template<class M>
01706 inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01707 MatrixGraph<M>::begin()
01708 {
01709 return VertexIterator(this,0);
01710 }
01711
01712 template<class M>
01713 inline MatrixGraph<M>::VertexIteratorT<MatrixGraph<M> >
01714 MatrixGraph<M>::end()
01715 {
01716 return VertexIterator(matrix_.N());
01717 }
01718
01719
01720 template<class M>
01721 inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01722 MatrixGraph<M>::begin() const
01723 {
01724 return ConstVertexIterator(this, 0);
01725 }
01726
01727 template<class M>
01728 inline MatrixGraph<M>::VertexIteratorT<const MatrixGraph<M> >
01729 MatrixGraph<M>::end() const
01730 {
01731 return ConstVertexIterator(matrix_.N());
01732 }
01733
01734 template<class M>
01735 inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01736 MatrixGraph<M>::beginEdges(const VertexDescriptor& source)
01737 {
01738 return EdgeIterator(source, matrix_.operator[](source).begin(),
01739 matrix_.operator[](source).end(), start_[source]);
01740 }
01741
01742 template<class M>
01743 inline MatrixGraph<M>::EdgeIteratorT<MatrixGraph<M> >
01744 MatrixGraph<M>::endEdges(const VertexDescriptor& source)
01745 {
01746 return EdgeIterator(matrix_.operator[](source).end());
01747 }
01748
01749
01750 template<class M>
01751 inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01752 MatrixGraph<M>::beginEdges(const VertexDescriptor& source) const
01753 {
01754 return ConstEdgeIterator(source, matrix_.operator[](source).begin(),
01755 matrix_.operator[](source).end(), start_[source]);
01756 }
01757
01758 template<class M>
01759 inline MatrixGraph<M>::EdgeIteratorT<const MatrixGraph<M> >
01760 MatrixGraph<M>::endEdges(const VertexDescriptor& source) const
01761 {
01762 return ConstEdgeIterator(matrix_.operator[](source).end());
01763 }
01764
01765
01766 template<class G, class T>
01767 SubGraph<G,T>::EdgeIterator::EdgeIterator(const VertexDescriptor& source,
01768 const EdgeDescriptor& edge)
01769 : source_(source), edge_(edge)
01770 {}
01771
01772
01773 template<class G, class T>
01774 SubGraph<G,T>::EdgeIterator::EdgeIterator(const EdgeDescriptor& edge)
01775 : edge_(edge)
01776 {}
01777
01778 template<class G, class T>
01779 typename SubGraph<G,T>::EdgeIndexMap SubGraph<G,T>::getEdgeIndexMap()
01780 {
01781 return EdgeIndexMap(edges_);
01782 }
01783
01784 template<class G, class T>
01785 inline bool SubGraph<G,T>::EdgeIterator::equals(const EdgeIterator& other) const
01786 {
01787 return other.edge_==edge_;
01788 }
01789
01790 template<class G, class T>
01791 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::increment()
01792 {
01793 ++edge_;
01794 return *this;
01795 }
01796
01797 template<class G, class T>
01798 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::decrement()
01799 {
01800 --edge_;
01801 return *this;
01802 }
01803
01804 template<class G, class T>
01805 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::advance(std::ptrdiff_t n)
01806 {
01807 edge_+=n;
01808 return *this;
01809 }
01810 template<class G, class T>
01811 inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::source() const
01812 {
01813 return source_;
01814 }
01815
01816 template<class G, class T>
01817 inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::target() const
01818 {
01819 return *edge_;
01820 }
01821
01822
01823 template<class G, class T>
01824 inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::EdgeIterator::dereference() const
01825 {
01826 return edge_;
01827 }
01828
01829 template<class G, class T>
01830 inline std::ptrdiff_t SubGraph<G,T>::EdgeIterator::distanceTo(const EdgeIterator& other) const
01831 {
01832 return other.edge_-edge_;
01833 }
01834
01835 template<class G, class T>
01836 SubGraph<G,T>::VertexIterator::VertexIterator(const SubGraph<G,T>* graph,
01837 const VertexDescriptor& current,
01838 const VertexDescriptor& end)
01839 : graph_(graph), current_(current), end_(end)
01840 {
01841
01842 typedef typename T::const_iterator Iterator;
01843
01844 for(Iterator vertex = graph_->excluded_.begin();
01845 current_ != end_ && *vertex;
01846 ++vertex)
01847 ++current_;
01848 assert(current_ == end_ || !graph_->excluded_[current_]);
01849 }
01850
01851 template<class G, class T>
01852 SubGraph<G,T>::VertexIterator::VertexIterator(const VertexDescriptor& current)
01853 : current_(current)
01854 {}
01855
01856 template<class G, class T>
01857 inline typename SubGraph<G,T>::VertexIterator& SubGraph<G,T>::VertexIterator::increment()
01858 {
01859 ++current_;
01860
01861 while(current_ != end_ && graph_->excluded_[current_])
01862 ++current_;
01863
01864 assert(current_ == end_ || !graph_->excluded_[current_]);
01865 return *this;
01866 }
01867
01868 template<class G, class T>
01869 inline bool SubGraph<G,T>::VertexIterator::equals(const VertexIterator& other) const
01870 {
01871 return current_==other.current_;
01872 }
01873
01874 template<class G, class T>
01875 inline const typename G::VertexDescriptor& SubGraph<G,T>::VertexIterator::dereference() const
01876 {
01877 return current_;
01878 }
01879
01880 template<class G, class T>
01881 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::begin() const
01882 {
01883 return graph_->beginEdges(current_);
01884 }
01885
01886 template<class G, class T>
01887 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::end() const
01888 {
01889 return graph_->endEdges(current_);
01890 }
01891
01892 template<class G, class T>
01893 inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::begin() const
01894 {
01895 return VertexIterator(this, 0, endVertex_);
01896 }
01897
01898
01899 template<class G, class T>
01900 inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::end() const
01901 {
01902 return VertexIterator(endVertex_);
01903 }
01904
01905
01906 template<class G, class T>
01907 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::beginEdges(const VertexDescriptor& source) const
01908 {
01909 return EdgeIterator(source, edges_+start_[source]);
01910 }
01911
01912 template<class G, class T>
01913 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::endEdges(const VertexDescriptor& source) const
01914 {
01915 return EdgeIterator(edges_+end_[source]);
01916 }
01917
01918 template<class G, class T>
01919 int SubGraph<G,T>::noVertices() const
01920 {
01921 return noVertices_;
01922 }
01923
01924 template<class G, class T>
01925 inline typename SubGraph<G,T>::VertexDescriptor SubGraph<G,T>::maxVertex() const
01926 {
01927 return maxVertex_;
01928 }
01929
01930 template<class G, class T>
01931 inline int SubGraph<G,T>::noEdges() const
01932 {
01933 return noEdges_;
01934 }
01935
01936 template<class G, class T>
01937 inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::findEdge(const VertexDescriptor& source,
01938 const VertexDescriptor& target) const
01939 {
01940 const EdgeDescriptor& edge = std::lower_bound(edges_+start_[source], edges_+end_[source], target);
01941 #ifdef DUNE_ISTL_WITH_CHECKING
01942 if(edge==edges_+end_[source] || *edge!=target)
01943 DUNE_THROW(ISTLError, "No such edge found!");
01944 #endif
01945
01946 return edge;
01947 }
01948
01949 template<class G, class T>
01950 SubGraph<G,T>::~SubGraph()
01951 {
01952 delete[] edges_;
01953 delete[] end_;
01954 delete[] start_;
01955 }
01956
01957 template<class G, class T>
01958 SubGraph<G,T>::SubGraph(const G& graph, const T& excluded)
01959 : excluded_(excluded), noVertices_(0), endVertex_(0), maxVertex_(graph.maxVertex())
01960 {
01961 start_ = new int[graph.noVertices()];
01962 end_ = new int[graph.noVertices()];
01963 edges_ = new VertexDescriptor[graph.noEdges()];
01964
01965 VertexDescriptor* edge=edges_;
01966
01967 typedef typename Graph::ConstVertexIterator Iterator;
01968 Iterator endVertex=graph.end();
01969
01970 for(Iterator vertex = graph.begin(); vertex != endVertex; ++vertex)
01971 if(excluded_[*vertex])
01972 start_[*vertex]=end_[*vertex]=-1;
01973 else{
01974 ++noVertices_;
01975 endVertex_ = std::max(*vertex, endVertex_);
01976
01977 start_[*vertex] = edge-edges_;
01978
01979 typedef typename Graph::ConstEdgeIterator Iterator;
01980 Iterator endEdge = vertex.end();
01981
01982 for(Iterator iter=vertex.begin(); iter!= endEdge; ++iter)
01983 if(!excluded[iter.target()]){
01984 *edge = iter.target();
01985 ++edge;
01986 }
01987
01988 end_[*vertex] = edge - edges_;
01989
01990
01991 std::sort(edges_+start_[*vertex], edge);
01992 }
01993 noEdges_ = edge-edges_;
01994 ++endVertex_;
01995 }
01996
01997 template<class G, class V, class VM>
01998 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
01999 VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source)
02000 {
02001 return graph_.beginEdges(source);
02002 }
02003
02004 template<class G, class V, class VM>
02005 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
02006 VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source)
02007 {
02008 return graph_.endEdges(source);
02009 }
02010
02011 template<class G, class V, class VM>
02012 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02013 inline VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source) const
02014 {
02015 return graph_.beginEdges(source);
02016 }
02017
02018 template<class G, class V, class VM>
02019 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
02020 VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source) const
02021 {
02022 return graph_.endEdges(source);
02023 }
02024
02025 template<class G, class V, class VM>
02026 template<class C>
02027 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02028 ::VertexIteratorT(const Father& iter,
02029 C* graph)
02030 : Father(iter), graph_(graph)
02031 {}
02032
02033 template<class G, class V, class VM>
02034 template<class C>
02035 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02036 ::VertexIteratorT(const Father& iter)
02037 : Father(iter)
02038 {}
02039
02040 template<class G, class V, class VM>
02041 template<class C>
02042 template<class C1>
02043 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
02044 ::VertexIteratorT(const VertexIteratorT<C1>& other)
02045 : Father(other), graph_(other.graph_)
02046 {}
02047
02048 template<class G, class V, class VM>
02049 template<class C>
02050 typename SelectType<is_same<C,typename remove_const<C>::type>::value,
02051 V&, const V&>::Type
02052 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties() const
02053 {
02054 return graph_->getVertexProperties(Father::operator*());
02055 }
02056
02057 template<class G, class V, class VM>
02058 template<class C>
02059 typename SelectType<is_same<typename remove_const<C>::type,
02060 C>::value,
02061 typename G::EdgeIterator,
02062 typename G::ConstEdgeIterator>::Type
02063 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::begin() const
02064 {
02065 return graph_->beginEdges(Father::operator*());
02066 }
02067
02068 template<class G, class V, class VM>
02069 template<class C>
02070 typename SelectType<is_same<typename remove_const<C>::type,
02071 C>::value,
02072 typename G::EdgeIterator,
02073 typename G::ConstEdgeIterator>::Type
02074 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::end() const
02075 {
02076 return graph_->endEdges(Father::operator*());
02077 }
02078
02079 template<class G, class V, class VM>
02080 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
02081 {
02082 return VertexIterator(graph_.begin(), this);
02083 }
02084
02085 template<class G, class V, class VM>
02086 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
02087 {
02088 return VertexIterator(graph_.end());
02089 }
02090
02091
02092 template<class G, class V, class VM>
02093 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin() const
02094 {
02095 return ConstVertexIterator(graph_.begin(), this);
02096 }
02097
02098 template<class G, class V, class VM>
02099 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end() const
02100 {
02101 return ConstVertexIterator(graph_.end());
02102 }
02103
02104 template<class G, class V, class VM>
02105 inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex)
02106 {
02107 return vertexProperties_[vmap_[vertex]];
02108 }
02109
02110 template<class G, class V, class VM>
02111 inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex) const
02112 {
02113 return vertexProperties_[vmap_[vertex]];
02114 }
02115
02116 template<class G, class V, class VM>
02117 inline const G& VertexPropertiesGraph<G,V,VM>::graph() const
02118 {
02119 return graph_;
02120 }
02121
02122 template<class G, class V, class VM>
02123 inline int VertexPropertiesGraph<G,V,VM>::noVertices() const
02124 {
02125 return graph_.noVertices();
02126 }
02127
02128
02129 template<class G, class V, class VM>
02130 inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex() const
02131 {
02132 return graph_.maxVertex();
02133 }
02134
02135 template<class G, class V, class VM>
02136 VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph, const VM vmap)
02137 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()], V())
02138 {}
02139
02140 template<class G, class V, class E, class VM, class EM>
02141 template<class C>
02142 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter,
02143 C* graph)
02144 : Father(iter), graph_(graph)
02145 {}
02146
02147 template<class G, class V, class E, class VM, class EM>
02148 template<class C>
02149 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter)
02150 : Father(iter)
02151 {}
02152
02153 template<class G, class V, class E, class VM, class EM>
02154 template<class C>
02155 template<class C1>
02156 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
02157 : Father(other), graph_(other.graph_)
02158 {}
02159
02160 template<class G, class V, class E, class VM, class EM>
02161 template<class C>
02162 inline typename SelectType<is_same<C,typename remove_const<C>::type>::value,E&,const E&>::Type
02163 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties() const
02164 {
02165 return graph_->getEdgeProperties(Father::operator*());
02166 }
02167
02168 template<class G, class V, class E, class VM, class EM>
02169 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02170 PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source)
02171 {
02172 return EdgeIterator(graph_.beginEdges(source), this);
02173 }
02174
02175 template<class G, class V, class E, class VM, class EM>
02176 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
02177 PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source)
02178 {
02179 return EdgeIterator(graph_.endEdges(source));
02180 }
02181
02182 template<class G, class V, class E, class VM, class EM>
02183 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02184 inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source) const
02185 {
02186 return ConstEdgeIterator(graph_.beginEdges(source), this);
02187 }
02188
02189 template<class G, class V, class E, class VM, class EM>
02190 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
02191 PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source) const
02192 {
02193 return ConstEdgeIterator(graph_.endEdges(source));
02194 }
02195
02196 template<class G, class V, class E, class VM, class EM>
02197 template<class C>
02198 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02199 ::VertexIteratorT(const Father& iter,
02200 C* graph)
02201 : Father(iter), graph_(graph)
02202 {}
02203
02204 template<class G, class V, class E, class VM, class EM>
02205 template<class C>
02206 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02207 ::VertexIteratorT(const Father& iter)
02208 : Father(iter)
02209 {}
02210
02211 template<class G, class V, class E, class VM, class EM>
02212 template<class C>
02213 template<class C1>
02214 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
02215 ::VertexIteratorT(const VertexIteratorT<C1>& other)
02216 : Father(other), graph_(other.graph_)
02217 {}
02218
02219 template<class G, class V, class E, class VM, class EM>
02220 template<class C>
02221 inline typename SelectType<is_same<C,typename remove_const<C>::type>::value,
02222 V&, const V&>::Type
02223 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties() const
02224 {
02225 return graph_->getVertexProperties(Father::operator*());
02226 }
02227
02228 template<class G, class V, class E, class VM, class EM>
02229 template<class C>
02230 inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02231 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::begin() const
02232 {
02233 return graph_->beginEdges(Father::operator*());
02234 }
02235
02236 template<class G, class V, class E, class VM, class EM>
02237 template<class C>
02238 inline PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>
02239 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::end() const
02240 {
02241 return graph_->endEdges(Father::operator*());
02242 }
02243
02244 template<class G, class V, class E, class VM, class EM>
02245 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
02246 {
02247 return VertexIterator(graph_.begin(), this);
02248 }
02249
02250 template<class G, class V, class E, class VM, class EM>
02251 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
02252 {
02253 return VertexIterator(graph_.end());
02254 }
02255
02256
02257 template<class G, class V, class E, class VM, class EM>
02258 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin() const
02259 {
02260 return ConstVertexIterator(graph_.begin(), this);
02261 }
02262
02263 template<class G, class V, class E, class VM, class EM>
02264 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end() const
02265 {
02266 return ConstVertexIterator(graph_.end());
02267 }
02268
02269 template<class G, class V, class E, class VM, class EM>
02270 inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex)
02271 {
02272 return vertexProperties_[vmap_[vertex]];
02273 }
02274
02275 template<class G, class V, class E, class VM, class EM>
02276 inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex) const
02277 {
02278 return vertexProperties_[vmap_[vertex]];
02279 }
02280
02281 template<class G, class V, class E, class VM, class EM>
02282 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge)
02283 {
02284 return edgeProperties_[emap_[edge]];
02285 }
02286
02287 template<class G, class V, class E, class VM, class EM>
02288 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge) const
02289 {
02290 return edgeProperties_[emap_[edge]];
02291 }
02292
02293 template<class G, class V, class E, class VM, class EM>
02294 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02295 const VertexDescriptor& target)
02296 {
02297 return edgeProperties_[emap_[graph_.findEdge(source,target)]];
02298 }
02299
02300 template<class G, class V, class E, class VM, class EM>
02301 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
02302 const VertexDescriptor& target) const
02303 {
02304 return edgeProperties_[emap_[graph_.findEdge(source,target)]];
02305 }
02306
02307 template<class G, class V, class E, class VM, class EM>
02308 inline const G& PropertiesGraph<G,V,E,VM,EM>::graph() const
02309 {
02310 return graph_;
02311 }
02312
02313 template<class G, class V, class E, class VM, class EM>
02314 inline int PropertiesGraph<G,V,E,VM,EM>::noVertices() const
02315 {
02316 return graph_.noVertices();
02317 }
02318
02319
02320 template<class G, class V, class E, class VM, class EM>
02321 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex() const
02322 {
02323 return graph_.maxVertex();
02324 }
02325
02326 template<class G, class V, class E, class VM, class EM>
02327 PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph, const VM& vmap, const EM& emap)
02328 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()], V()),
02329 emap_(emap), edgeProperties_(graph_.noEdges(), E())
02330 {}
02331
02332 template<class G, class V>
02333 inline int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex,
02334 V& visitor)
02335 {
02336 typedef typename G::ConstEdgeIterator iterator;
02337 const iterator end = graph.endEdges(vertex);
02338 int noNeighbours=0;
02339 for(iterator edge = graph.beginEdges(vertex); edge != end; ++edge, ++noNeighbours)
02340 visitor(edge);
02341 return noNeighbours;
02342 }
02343
02344
02346 }
02347 }
02348 #endif