dune-istl  2.4
graph.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_AMG_GRAPH_HH
4 #define DUNE_AMG_GRAPH_HH
5 
6 #include <cstddef>
7 #include <algorithm>
8 #include <vector>
9 #include <cassert>
10 #include <limits>
11 #include <dune/common/typetraits.hh>
12 #include <dune/common/iteratorfacades.hh>
14 #include <dune/common/propertymap.hh>
15 
16 namespace Dune
17 {
18  namespace Amg
19  {
47  template<class M>
49  {
50  public:
54  typedef M Matrix;
55 
59  typedef typename remove_const<M>::type MutableMatrix;
60 
64  typedef typename M::block_type Weight;
65 
71  typedef typename M::size_type VertexDescriptor;
72 
78  typedef std::ptrdiff_t EdgeDescriptor;
79 
80  enum {
81  /*
82  * @brief Whether Matrix is mutable.
83  */
84  mutableMatrix = is_same<M, typename remove_const<M>::type>::value
85  };
86 
87 
91  template<class C>
93  {
94 
95  public:
99  typedef typename remove_const<C>::type MutableContainer;
103  typedef const typename remove_const<C>::type ConstContainer;
104 
105  friend class EdgeIteratorT<MutableContainer>;
106  friend class EdgeIteratorT<ConstContainer>;
107 
108  enum {
110  isMutable = is_same<C, MutableContainer>::value
111  };
112 
116  typedef typename conditional<isMutable && C::mutableMatrix,typename Matrix::row_type::Iterator,
117  typename Matrix::row_type::ConstIterator>::type
119 
123  typedef typename conditional<isMutable && C::mutableMatrix,typename M::block_type,
124  const typename M::block_type>::type
126 
134  EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
135  const ColIterator& end, const EdgeDescriptor& edge);
136 
143  EdgeIteratorT(const ColIterator& block);
144 
149  template<class C1>
150  EdgeIteratorT(const EdgeIteratorT<C1>& other);
151 
152  typedef typename conditional<is_same<C, typename remove_const<C>::type>::value && C::mutableMatrix,
153  typename M::block_type, const typename M::block_type>::type
155 
159  WeightType& weight() const;
160 
163 
165  bool operator!=(const EdgeIteratorT<typename remove_const<C>::type>& other) const;
166 
168  bool operator!=(const EdgeIteratorT<const typename remove_const<C>::type>& other) const;
169 
171  bool operator==(const EdgeIteratorT<typename remove_const<C>::type>& other) const;
172 
174  bool operator==(const EdgeIteratorT<const typename remove_const<C>::type>& other) const;
175 
177  VertexDescriptor target() const;
178 
180  VertexDescriptor source() const;
181 
183  const EdgeDescriptor& operator*() const;
184 
186  const EdgeDescriptor* operator->() const;
187 
188  private:
190  VertexDescriptor source_;
192  ColIterator block_;
193  /***
194  * @brief The column iterator positioned at the end of the row
195  * of vertex source_
196  */
197  ColIterator blockEnd_;
199  EdgeDescriptor edge_;
200  };
201 
205  template<class C>
207  {
208  public:
212  typedef typename remove_const<C>::type MutableContainer;
216  typedef const typename remove_const<C>::type ConstContainer;
217 
218  friend class VertexIteratorT<MutableContainer>;
219  friend class VertexIteratorT<ConstContainer>;
220 
221  enum {
223  isMutable = is_same<C, MutableContainer>::value
224  };
225 
231  explicit VertexIteratorT(C* graph, const VertexDescriptor& current);
232 
240  explicit VertexIteratorT(const VertexDescriptor& current);
241 
243 
249 
251  bool operator!=(const VertexIteratorT<ConstContainer>& other) const;
252 
254  bool operator==(const VertexIteratorT<ConstContainer>& other) const;
255 
257  bool operator!=(const VertexIteratorT<MutableContainer>& other) const;
258 
260  bool operator==(const VertexIteratorT<MutableContainer>& other) const;
261 
262  typedef typename conditional<is_same<C, typename remove_const<C>::type>::value && C::mutableMatrix,
263  typename M::block_type, const typename M::block_type>::type
266  WeightType& weight() const;
267 
272  const VertexDescriptor& operator*() const;
273 
279  EdgeIteratorT<C> begin() const;
280 
286  EdgeIteratorT<C> end() const;
287 
288  private:
289  C* graph_;
290  VertexDescriptor current_;
291  };
292 
296  typedef EdgeIteratorT<const MatrixGraph<Matrix> > ConstEdgeIterator;
297 
301  typedef EdgeIteratorT<MatrixGraph<Matrix> > EdgeIterator;
302 
306  typedef VertexIteratorT<const MatrixGraph<Matrix> > ConstVertexIterator;
307 
311  typedef VertexIteratorT<MatrixGraph<Matrix> > VertexIterator;
312 
317  MatrixGraph(Matrix& matrix);
318 
322  ~MatrixGraph();
323 
328  VertexIterator begin();
329 
334  VertexIterator end();
335 
340  ConstVertexIterator begin() const;
341 
346  ConstVertexIterator end() const;
347 
354  EdgeIterator beginEdges(const VertexDescriptor& source);
355 
362  EdgeIterator endEdges(const VertexDescriptor& source);
363 
364 
371  ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
372 
379  ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
380 
385  Matrix& matrix();
386 
391  const Matrix& matrix() const;
392 
396  std::size_t noVertices() const;
397 
404  VertexDescriptor maxVertex() const;
405 
409  std::size_t noEdges() const;
410 
417  EdgeDescriptor findEdge(const VertexDescriptor& source,
418  const VertexDescriptor& target) const;
419 
420  private:
422  Matrix& matrix_;
424  EdgeDescriptor* start_;
426  MatrixGraph(const MatrixGraph&);
427 
428  };
429 
439  template<class G, class T>
440  class SubGraph
441  {
442  public:
446  typedef G Graph;
447 
452  typedef T Excluded;
453 
457  typedef typename Graph::VertexDescriptor VertexDescriptor;
458 
459  typedef VertexDescriptor* EdgeDescriptor;
460 
468  {
469  public:
470  typedef ReadablePropertyMapTag Category;
471 
472  EdgeIndexMap(const EdgeDescriptor& firstEdge)
473  : firstEdge_(firstEdge)
474  {}
475 
478  : firstEdge_(emap.firstEdge_)
479  {}
480 
481  std::size_t operator[](const EdgeDescriptor& edge) const
482  {
483  return edge-firstEdge_;
484  }
485  private:
487  EdgeDescriptor firstEdge_;
489  EdgeIndexMap()
490  {}
491  };
492 
497  EdgeIndexMap getEdgeIndexMap();
498 
502  class EdgeIterator : public RandomAccessIteratorFacade<EdgeIterator,const EdgeDescriptor>
503  {
504  public:
510  explicit EdgeIterator(const VertexDescriptor& source, const EdgeDescriptor& edge);
511 
519  explicit EdgeIterator(const EdgeDescriptor& edge);
520 
522  bool equals(const EdgeIterator& other) const;
523 
526 
529 
530  EdgeIterator& advance(std::ptrdiff_t n);
531 
533  const EdgeDescriptor& dereference() const;
534 
536  const VertexDescriptor& target() const;
537 
539  const VertexDescriptor& source() const;
540 
541  std::ptrdiff_t distanceTo(const EdgeIterator& other) const;
542 
543  private:
545  VertexDescriptor source_;
550  EdgeDescriptor edge_;
551  };
552 
557  : public ForwardIteratorFacade<VertexIterator,const VertexDescriptor>
558  {
559  public:
566  explicit VertexIterator(const SubGraph<G,T>* graph, const VertexDescriptor& current,
567  const VertexDescriptor& end);
568 
569 
576  explicit VertexIterator(const VertexDescriptor& current);
577 
580 
582  bool equals(const VertexIterator& other) const;
583 
588  const VertexDescriptor& dereference() const;
589 
595  EdgeIterator begin() const;
596 
602  EdgeIterator end() const;
603 
604  private:
606  const SubGraph<Graph,T>* graph_;
608  VertexDescriptor current_;
610  VertexDescriptor end_;
611  };
612 
616  typedef EdgeIterator ConstEdgeIterator;
617 
621  typedef VertexIterator ConstVertexIterator;
622 
627  ConstVertexIterator begin() const;
628 
633  ConstVertexIterator end() const;
634 
641  ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
642 
649  ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
650 
654  std::size_t noVertices() const;
655 
662  VertexDescriptor maxVertex() const;
663 
667  std::size_t noEdges() const;
674  EdgeDescriptor findEdge(const VertexDescriptor& source,
675  const VertexDescriptor& target) const;
683  SubGraph(const Graph& graph, const T& excluded);
684 
688  ~SubGraph();
689 
690  private:
692  const T& excluded_;
694  std::size_t noVertices_;
696  VertexDescriptor endVertex_;
698  int noEdges_;
703  VertexDescriptor maxVertex_;
705  VertexDescriptor* edges_;
707  std::ptrdiff_t* start_;
709  std::ptrdiff_t* end_;
711  SubGraph(const SubGraph&)
712  {}
713  };
714 
715 
719  template<class G, class VP, class VM=IdentityMap>
721  {
722  public:
726  typedef G Graph;
727 
731  typedef typename Graph::VertexDescriptor VertexDescriptor;
732 
736  typedef typename Graph::EdgeDescriptor EdgeDescriptor;
737 
741  typedef VP VertexProperties;
742 
754  typedef VM VertexMap;
755 
759  typedef typename Graph::EdgeIterator EdgeIterator;
760 
764  typedef typename Graph::ConstEdgeIterator ConstEdgeIterator;
765 
771  EdgeIterator beginEdges(const VertexDescriptor& source);
772 
778  EdgeIterator endEdges(const VertexDescriptor& source);
779 
785  ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
786 
792  ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
793 
794 
795  template<class C>
797  : public conditional<is_same<typename remove_const<C>::type,
798  C>::value,
799  typename Graph::VertexIterator,
800  typename Graph::ConstVertexIterator>::type
801  {
802  friend class VertexIteratorT<const typename remove_const<C>::type>;
803  friend class VertexIteratorT<typename remove_const<C>::type>;
804  public:
808  typedef typename conditional<is_same<typename remove_const<C>::type,
809  C>::value,
810  typename Graph::VertexIterator,
811  typename Graph::ConstVertexIterator>::type
813 
817  typedef typename conditional<is_same<typename remove_const<C>::type,
818  C>::value,
819  typename Graph::EdgeIterator,
820  typename Graph::ConstEdgeIterator>::type
821  EdgeIterator;
822 
828  explicit VertexIteratorT(const Father& iter,
829  C* graph);
830 
831 
839  explicit VertexIteratorT(const Father& iter);
840 
845  template<class C1>
846  VertexIteratorT(const VertexIteratorT<C1>& other);
847 
851  typename conditional<is_same<C,typename remove_const<C>::type>::value,
852  VertexProperties&,
853  const VertexProperties&>::type
854  properties() const;
855 
861  EdgeIterator begin() const;
862 
868  EdgeIterator end() const;
869 
870  private:
874  C* graph_;
875  };
876 
880  typedef VertexIteratorT<VertexPropertiesGraph<Graph,
881  VertexProperties,VM> > VertexIterator;
882 
886  typedef VertexIteratorT<const VertexPropertiesGraph<Graph,
887  VertexProperties,VM> > ConstVertexIterator;
888 
894 
900 
905  ConstVertexIterator begin() const;
906 
911  ConstVertexIterator end() const;
912 
918  VertexProperties& getVertexProperties(const VertexDescriptor& vertex);
919 
925  const VertexProperties& getVertexProperties(const VertexDescriptor& vertex) const;
926 
931  const Graph& graph() const;
932 
936  std::size_t noVertices() const;
937 
941  std::size_t noEdges() const;
942 
949  VertexDescriptor maxVertex() const;
950 
956  VertexPropertiesGraph(Graph& graph, const VertexMap vmap=VertexMap());
957 
958  private:
959  VertexPropertiesGraph(const VertexPropertiesGraph&)
960  {}
961 
963  Graph& graph_;
965  VertexMap vmap_;
967  std::vector<VertexProperties> vertexProperties_;
968 
969  };
970 
974  template<class G, class VP, class EP, class VM=IdentityMap, class EM=IdentityMap>
976  {
977  public:
981  typedef G Graph;
982 
986  typedef typename Graph::VertexDescriptor VertexDescriptor;
987 
991  typedef typename Graph::EdgeDescriptor EdgeDescriptor;
992 
996  typedef VP VertexProperties;
997 
1009  typedef VM VertexMap;
1010 
1014  typedef EP EdgeProperties;
1015 
1016 
1028  typedef EM EdgeMap;
1029 
1030  template<class C>
1032  : public conditional<is_same<typename remove_const<C>::type,
1033  C>::value,
1034  typename Graph::EdgeIterator,
1035  typename Graph::ConstEdgeIterator>::type
1036  {
1037 
1038  friend class EdgeIteratorT<const typename remove_const<C>::type>;
1039  friend class EdgeIteratorT<typename remove_const<C>::type>;
1040  public:
1044  typedef typename conditional<is_same<typename remove_const<C>::type,
1045  C>::value,
1046  typename Graph::EdgeIterator,
1047  typename Graph::ConstEdgeIterator>::type
1049 
1055  explicit EdgeIteratorT(const Father& iter,
1056  C* graph);
1057 
1065  explicit EdgeIteratorT(const Father& iter);
1066 
1071  template<class C1>
1072  EdgeIteratorT(const EdgeIteratorT<C1>& other);
1073 
1077  typename conditional<is_same<C,typename remove_const<C>::type>::value,
1078  EdgeProperties&,
1079  const EdgeProperties&>::type
1080  properties() const;
1081 
1082  private:
1086  C* graph_;
1087  };
1088 
1092  typedef EdgeIteratorT<PropertiesGraph<Graph,
1093  VertexProperties,
1094  EdgeProperties,VM,EM> > EdgeIterator;
1095 
1099  typedef EdgeIteratorT<const PropertiesGraph<Graph,
1100  VertexProperties,
1101  EdgeProperties,VM,EM> > ConstEdgeIterator;
1102 
1108  EdgeIterator beginEdges(const VertexDescriptor& source);
1109 
1115  EdgeIterator endEdges(const VertexDescriptor& source);
1116 
1122  ConstEdgeIterator beginEdges(const VertexDescriptor& source) const;
1123 
1129  ConstEdgeIterator endEdges(const VertexDescriptor& source) const;
1130 
1131 
1132  template<class C>
1134  : public conditional<is_same<typename remove_const<C>::type,
1135  C>::value,
1136  typename Graph::VertexIterator,
1137  typename Graph::ConstVertexIterator>::type
1138  {
1139  friend class VertexIteratorT<const typename remove_const<C>::type>;
1140  friend class VertexIteratorT<typename remove_const<C>::type>;
1141  public:
1145  typedef typename conditional<is_same<typename remove_const<C>::type,
1146  C>::value,
1147  typename Graph::VertexIterator,
1148  typename Graph::ConstVertexIterator>::type
1150 
1156  explicit VertexIteratorT(const Father& iter,
1157  C* graph);
1158 
1159 
1167  explicit VertexIteratorT(const Father& iter);
1168 
1173  template<class C1>
1174  VertexIteratorT(const VertexIteratorT<C1>& other);
1175 
1179  typename conditional<is_same<C,typename remove_const<C>::type>::value,
1180  VertexProperties&,
1181  const VertexProperties&>::type
1182  properties() const;
1183 
1189  EdgeIteratorT<C> begin() const;
1190 
1196  EdgeIteratorT<C> end() const;
1197 
1198  private:
1202  C* graph_;
1203  };
1204 
1208  typedef VertexIteratorT<PropertiesGraph<Graph,
1209  VertexProperties,
1210  EdgeProperties,VM,EM> > VertexIterator;
1211 
1215  typedef VertexIteratorT<const PropertiesGraph<Graph,
1216  VertexProperties,
1217  EdgeProperties,VM,EM> > ConstVertexIterator;
1218 
1224 
1229  VertexIterator end();
1230 
1235  ConstVertexIterator begin() const;
1236 
1241  ConstVertexIterator end() const;
1242 
1248  VertexProperties& getVertexProperties(const VertexDescriptor& vertex);
1249 
1255  const VertexProperties& getVertexProperties(const VertexDescriptor& vertex) const;
1256 
1263  EdgeDescriptor findEdge(const VertexDescriptor& source,
1264  const VertexDescriptor& target)
1265  {
1266  return graph_.findEdge(source,target);
1267  }
1268 
1274  EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge);
1275 
1276 
1282  const EdgeProperties& getEdgeProperties(const EdgeDescriptor& edge) const;
1283 
1290  EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
1291  const VertexDescriptor& target);
1292 
1299  const EdgeProperties& getEdgeProperties(const VertexDescriptor& source,
1300  const VertexDescriptor& target) const;
1301 
1306  const Graph& graph() const;
1307 
1311  std::size_t noVertices() const;
1312 
1316  std::size_t noEdges() const;
1317 
1324  VertexDescriptor maxVertex() const;
1325 
1332  PropertiesGraph(Graph& graph, const VertexMap& vmap=VertexMap(),
1333  const EdgeMap& emap=EdgeMap());
1334 
1335  private:
1337  {}
1338 
1340  Graph& graph_;
1343  VertexMap vmap_;
1344  std::vector<VertexProperties> vertexProperties_;
1346  EdgeMap emap_;
1348  std::vector<EdgeProperties> edgeProperties_;
1349 
1350  };
1351 
1352 
1357  template<typename G>
1359  {
1360  public:
1364  typedef G Graph;
1368  typedef typename G::VertexProperties VertexProperties;
1372  typedef typename G::VertexDescriptor Vertex;
1373 
1379  : graph_(g)
1380  {}
1385  : graph_(0)
1386  {}
1387 
1388 
1393  VertexProperties& operator[](const Vertex& vertex) const
1394  {
1395  return graph_->getVertexProperties(vertex);
1396  }
1397  private:
1398  Graph* graph_;
1399  };
1400 
1405  template<typename G>
1407  {
1408  public:
1412  typedef G Graph;
1416  typedef typename G::EdgeProperties EdgeProperties;
1420  typedef typename G::EdgeDescriptor Edge;
1421 
1427  : graph_(g)
1428  {}
1433  : graph_(0)
1434  {}
1435 
1440  EdgeProperties& operator[](const Edge& edge) const
1441  {
1442  return graph_->getEdgeProperties(edge);
1443  }
1444  private:
1445  Graph* graph_;
1446  };
1447 
1448 
1459  template<class G, class V>
1460  int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex,
1461  V& visitor);
1462 
1463 #ifndef DOXYGEN
1464 
1465  template<class M>
1466  MatrixGraph<M>::MatrixGraph(M& matrix)
1467  : matrix_(matrix)
1468  {
1469  if(matrix_.N()!=matrix_.M())
1470  DUNE_THROW(ISTLError, "Matrix has to have as many columns as rows!");
1471 
1472  start_ = new EdgeDescriptor[matrix_.N()+1];
1473 
1474  typedef typename M::ConstIterator Iterator;
1475  Iterator row = matrix_.begin();
1476  start_[row.index()] = 0;
1477 
1478  for(Iterator row=matrix_.begin(); row != matrix_.end(); ++row)
1479  start_[row.index()+1] = start_[row.index()] + row->size();
1480  }
1481 
1482  template<class M>
1484  {
1485  delete[] start_;
1486  }
1487 
1488  template<class M>
1489  inline std::size_t MatrixGraph<M>::noEdges() const
1490  {
1491  return start_[matrix_.N()];
1492  }
1493 
1494  template<class M>
1495  inline std::size_t MatrixGraph<M>::noVertices() const
1496  {
1497  return matrix_.N();
1498  }
1499 
1500  template<class M>
1501  inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::maxVertex() const
1502  {
1503  return matrix_.N()-1;
1504  }
1505 
1506  template<class M>
1507  typename MatrixGraph<M>::EdgeDescriptor
1508  MatrixGraph<M>::findEdge(const VertexDescriptor& source,
1509  const VertexDescriptor& target) const
1510  {
1511  typename M::ConstColIterator found =matrix_[source].find(target);
1512  if(found == matrix_[source].end())
1513  return std::numeric_limits<EdgeDescriptor>::max();
1514  std::size_t offset = found.offset();
1515  if(target>source)
1516  offset--;
1517 
1518  assert(offset<noEdges());
1519 
1520  return start_[source]+offset;
1521  }
1522 
1523 
1524  template<class M>
1525  inline M& MatrixGraph<M>::matrix()
1526  {
1527  return matrix_;
1528  }
1529 
1530  template<class M>
1531  inline const M& MatrixGraph<M>::matrix() const
1532  {
1533  return matrix_;
1534  }
1535 
1536  template<class M>
1537  template<class C>
1538  MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const VertexDescriptor& source, const ColIterator& block,
1539  const ColIterator& end, const EdgeDescriptor& edge)
1540  : source_(source), block_(block), blockEnd_(end), edge_(edge)
1541  {
1542  if(block_!=blockEnd_ && block_.index() == source_) {
1543  // This is the edge from the diagonal to the diagonal. Skip it.
1544  ++block_;
1545  }
1546  }
1547 
1548  template<class M>
1549  template<class C>
1550  MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const ColIterator& block)
1551  : block_(block)
1552  {}
1553 
1554  template<class M>
1555  template<class C>
1556  template<class C1>
1557  MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
1558  : source_(other.source_), block_(other.block_), blockEnd_(other.blockEnd_), edge_(other.edge_)
1559  {}
1560 
1561 
1562  template<class M>
1563  template<class C>
1564  inline typename MatrixGraph<M>::template EdgeIteratorT<C>::WeightType&
1565  MatrixGraph<M>::EdgeIteratorT<C>::weight() const
1566  {
1567  return *block_;
1568  }
1569 
1570  template<class M>
1571  template<class C>
1572  inline typename MatrixGraph<M>::template EdgeIteratorT<C>& MatrixGraph<M>::EdgeIteratorT<C>::operator++()
1573  {
1574  ++block_;
1575  ++edge_;
1576 
1577  if(block_!=blockEnd_ && block_.index() == source_) {
1578  // This is the edge from the diagonal to the diagonal. Skip it.
1579  ++block_;
1580  }
1581 
1582  return *this;
1583  }
1584 
1585  template<class M>
1586  template<class C>
1587  inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const typename MatrixGraph<M>::template EdgeIteratorT<typename remove_const<C>::type>& other) const
1588  {
1589  return block_!=other.block_;
1590  }
1591 
1592  template<class M>
1593  template<class C>
1594  inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator!=(const typename MatrixGraph<M>::template EdgeIteratorT<const typename remove_const<C>::type>& other) const
1595  {
1596  return block_!=other.block_;
1597  }
1598 
1599  template<class M>
1600  template<class C>
1601  inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const typename MatrixGraph<M>::template EdgeIteratorT<typename remove_const<C>::type>& other) const
1602  {
1603  return block_==other.block_;
1604  }
1605 
1606  template<class M>
1607  template<class C>
1608  inline bool MatrixGraph<M>::EdgeIteratorT<C>::operator==(const typename MatrixGraph<M>::template EdgeIteratorT<const typename remove_const<C>::type>& other) const
1609  {
1610  return block_==other.block_;
1611  }
1612 
1613  template<class M>
1614  template<class C>
1615  inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::target() const
1616  {
1617  return block_.index();
1618  }
1619 
1620  template<class M>
1621  template<class C>
1622  inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::source() const
1623  {
1624  return source_;
1625  }
1626 
1627  template<class M>
1628  template<class C>
1629  inline const typename MatrixGraph<M>::EdgeDescriptor& MatrixGraph<M>::EdgeIteratorT<C>::operator*() const
1630  {
1631  return edge_;
1632  }
1633 
1634  template<class M>
1635  template<class C>
1636  inline const typename MatrixGraph<M>::EdgeDescriptor* MatrixGraph<M>::EdgeIteratorT<C>::operator->() const
1637  {
1638  return &edge_;
1639  }
1640 
1641  template<class M>
1642  template<class C>
1643  MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(C* graph,
1644  const VertexDescriptor& current)
1645  : graph_(graph), current_(current)
1646  {}
1647 
1648 
1649  template<class M>
1650  template<class C>
1651  MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexDescriptor& current)
1652  : current_(current)
1653  {}
1654 
1655  template<class M>
1656  template<class C>
1657  MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(const VertexIteratorT<MutableContainer>& other)
1658  : graph_(other.graph_), current_(other.current_)
1659  {}
1660 
1661  template<class M>
1662  template<class C>
1663  inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<MutableContainer>& other) const
1664  {
1665  return current_ != other.current_;
1666  }
1667 
1668  template<class M>
1669  template<class C>
1670  inline bool MatrixGraph<M>::VertexIteratorT<C>::operator!=(const VertexIteratorT<ConstContainer>& other) const
1671  {
1672  return current_ != other.current_;
1673  }
1674 
1675 
1676  template<class M>
1677  template<class C>
1678  inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<MutableContainer>& other) const
1679  {
1680  return current_ == other.current_;
1681  }
1682 
1683  template<class M>
1684  template<class C>
1685  inline bool MatrixGraph<M>::VertexIteratorT<C>::operator==(const VertexIteratorT<ConstContainer>& other) const
1686  {
1687  return current_ == other.current_;
1688  }
1689 
1690  template<class M>
1691  template<class C>
1692  inline typename MatrixGraph<M>::template VertexIteratorT<C>& MatrixGraph<M>::VertexIteratorT<C>::operator++()
1693  {
1694  ++current_;
1695  return *this;
1696  }
1697 
1698  template<class M>
1699  template<class C>
1700  inline typename MatrixGraph<M>::template VertexIteratorT<C>::WeightType&
1701  MatrixGraph<M>::VertexIteratorT<C>::weight() const
1702  {
1703  return graph_->matrix()[current_][current_];
1704  }
1705 
1706  template<class M>
1707  template<class C>
1708  inline const typename MatrixGraph<M>::VertexDescriptor&
1709  MatrixGraph<M>::VertexIteratorT<C>::operator*() const
1710  {
1711  return current_;
1712  }
1713 
1714  template<class M>
1715  template<class C>
1716  inline typename MatrixGraph<M>::template EdgeIteratorT<C>
1718  {
1719  return graph_->beginEdges(current_);
1720  }
1721 
1722  template<class M>
1723  template<class C>
1724  inline typename MatrixGraph<M>::template EdgeIteratorT<C>
1726  {
1727  return graph_->endEdges(current_);
1728  }
1729 
1730  template<class M>
1731  inline typename MatrixGraph<M>::template VertexIteratorT<MatrixGraph<M> >
1733  {
1734  return VertexIterator(this,0);
1735  }
1736 
1737  template<class M>
1738  inline typename MatrixGraph<M>::template VertexIteratorT<MatrixGraph<M> >
1740  {
1741  return VertexIterator(matrix_.N());
1742  }
1743 
1744 
1745  template<class M>
1746  inline typename MatrixGraph<M>::template VertexIteratorT<const MatrixGraph<M> >
1747  MatrixGraph<M>::begin() const
1748  {
1749  return ConstVertexIterator(this, 0);
1750  }
1751 
1752  template<class M>
1753  inline typename MatrixGraph<M>::template VertexIteratorT<const MatrixGraph<M> >
1754  MatrixGraph<M>::end() const
1755  {
1756  return ConstVertexIterator(matrix_.N());
1757  }
1758 
1759  template<class M>
1760  inline typename MatrixGraph<M>::template EdgeIteratorT<MatrixGraph<M> >
1761  MatrixGraph<M>::beginEdges(const VertexDescriptor& source)
1762  {
1763  return EdgeIterator(source, matrix_.operator[](source).begin(),
1764  matrix_.operator[](source).end(), start_[source]);
1765  }
1766 
1767  template<class M>
1768  inline typename MatrixGraph<M>::template EdgeIteratorT<MatrixGraph<M> >
1769  MatrixGraph<M>::endEdges(const VertexDescriptor& source)
1770  {
1771  return EdgeIterator(matrix_.operator[](source).end());
1772  }
1773 
1774 
1775  template<class M>
1776  inline typename MatrixGraph<M>::template EdgeIteratorT<const MatrixGraph<M> >
1777  MatrixGraph<M>::beginEdges(const VertexDescriptor& source) const
1778  {
1779  return ConstEdgeIterator(source, matrix_.operator[](source).begin(),
1780  matrix_.operator[](source).end(), start_[source]);
1781  }
1782 
1783  template<class M>
1784  inline typename MatrixGraph<M>::template EdgeIteratorT<const MatrixGraph<M> >
1785  MatrixGraph<M>::endEdges(const VertexDescriptor& source) const
1786  {
1787  return ConstEdgeIterator(matrix_.operator[](source).end());
1788  }
1789 
1790 
1791  template<class G, class T>
1792  SubGraph<G,T>::EdgeIterator::EdgeIterator(const VertexDescriptor& source,
1793  const EdgeDescriptor& edge)
1794  : source_(source), edge_(edge)
1795  {}
1796 
1797 
1798  template<class G, class T>
1799  SubGraph<G,T>::EdgeIterator::EdgeIterator(const EdgeDescriptor& edge)
1800  : edge_(edge)
1801  {}
1802 
1803  template<class G, class T>
1804  typename SubGraph<G,T>::EdgeIndexMap SubGraph<G,T>::getEdgeIndexMap()
1805  {
1806  return EdgeIndexMap(edges_);
1807  }
1808 
1809  template<class G, class T>
1810  inline bool SubGraph<G,T>::EdgeIterator::equals(const EdgeIterator & other) const
1811  {
1812  return other.edge_==edge_;
1813  }
1814 
1815  template<class G, class T>
1816  inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::increment()
1817  {
1818  ++edge_;
1819  return *this;
1820  }
1821 
1822  template<class G, class T>
1823  inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::decrement()
1824  {
1825  --edge_;
1826  return *this;
1827  }
1828 
1829  template<class G, class T>
1830  inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::advance(std::ptrdiff_t n)
1831  {
1832  edge_+=n;
1833  return *this;
1834  }
1835  template<class G, class T>
1836  inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::source() const
1837  {
1838  return source_;
1839  }
1840 
1841  template<class G, class T>
1842  inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::target() const
1843  {
1844  return *edge_;
1845  }
1846 
1847 
1848  template<class G, class T>
1849  inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::EdgeIterator::dereference() const
1850  {
1851  return edge_;
1852  }
1853 
1854  template<class G, class T>
1855  inline std::ptrdiff_t SubGraph<G,T>::EdgeIterator::distanceTo(const EdgeIterator & other) const
1856  {
1857  return other.edge_-edge_;
1858  }
1859 
1860  template<class G, class T>
1861  SubGraph<G,T>::VertexIterator::VertexIterator(const SubGraph<G,T>* graph,
1862  const VertexDescriptor& current,
1863  const VertexDescriptor& end)
1864  : graph_(graph), current_(current), end_(end)
1865  {
1866  // Skip excluded vertices
1867  typedef typename T::const_iterator Iterator;
1868 
1869  for(Iterator vertex = graph_->excluded_.begin();
1870  current_ != end_ && *vertex;
1871  ++vertex)
1872  ++current_;
1873  assert(current_ == end_ || !graph_->excluded_[current_]);
1874  }
1875 
1876  template<class G, class T>
1877  SubGraph<G,T>::VertexIterator::VertexIterator(const VertexDescriptor& current)
1878  : current_(current)
1879  {}
1880 
1881  template<class G, class T>
1882  inline typename SubGraph<G,T>::VertexIterator& SubGraph<G,T>::VertexIterator::increment()
1883  {
1884  ++current_;
1885  //Skip excluded vertices
1886  while(current_ != end_ && graph_->excluded_[current_])
1887  ++current_;
1888 
1889  assert(current_ == end_ || !graph_->excluded_[current_]);
1890  return *this;
1891  }
1892 
1893  template<class G, class T>
1894  inline bool SubGraph<G,T>::VertexIterator::equals(const VertexIterator & other) const
1895  {
1896  return current_==other.current_;
1897  }
1898 
1899  template<class G, class T>
1900  inline const typename G::VertexDescriptor& SubGraph<G,T>::VertexIterator::dereference() const
1901  {
1902  return current_;
1903  }
1904 
1905  template<class G, class T>
1906  inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::begin() const
1907  {
1908  return graph_->beginEdges(current_);
1909  }
1910 
1911  template<class G, class T>
1912  inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::end() const
1913  {
1914  return graph_->endEdges(current_);
1915  }
1916 
1917  template<class G, class T>
1918  inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::begin() const
1919  {
1920  return VertexIterator(this, 0, endVertex_);
1921  }
1922 
1923 
1924  template<class G, class T>
1925  inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::end() const
1926  {
1927  return VertexIterator(endVertex_);
1928  }
1929 
1930 
1931  template<class G, class T>
1932  inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::beginEdges(const VertexDescriptor& source) const
1933  {
1934  return EdgeIterator(source, edges_+start_[source]);
1935  }
1936 
1937  template<class G, class T>
1938  inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::endEdges(const VertexDescriptor& source) const
1939  {
1940  return EdgeIterator(edges_+end_[source]);
1941  }
1942 
1943  template<class G, class T>
1944  std::size_t SubGraph<G,T>::noVertices() const
1945  {
1946  return noVertices_;
1947  }
1948 
1949  template<class G, class T>
1950  inline typename SubGraph<G,T>::VertexDescriptor SubGraph<G,T>::maxVertex() const
1951  {
1952  return maxVertex_;
1953  }
1954 
1955  template<class G, class T>
1956  inline std::size_t SubGraph<G,T>::noEdges() const
1957  {
1958  return noEdges_;
1959  }
1960 
1961  template<class G, class T>
1962  inline typename SubGraph<G,T>::EdgeDescriptor SubGraph<G,T>::findEdge(const VertexDescriptor& source,
1963  const VertexDescriptor& target) const
1964  {
1965  const EdgeDescriptor edge = std::lower_bound(edges_+start_[source], edges_+end_[source], target);
1966  if(edge==edges_+end_[source] || *edge!=target)
1967  return std::numeric_limits<EdgeDescriptor>::max();
1968 
1969  return edge;
1970  }
1971 
1972  template<class G, class T>
1974  {
1975  delete[] edges_;
1976  delete[] end_;
1977  delete[] start_;
1978  }
1979 
1980  template<class G, class T>
1981  SubGraph<G,T>::SubGraph(const G& graph, const T& excluded)
1982  : excluded_(excluded), noVertices_(0), endVertex_(0), maxVertex_(graph.maxVertex())
1983  {
1984  start_ = new std::ptrdiff_t[graph.noVertices()];
1985  end_ = new std::ptrdiff_t[graph.noVertices()];
1986  edges_ = new VertexDescriptor[graph.noEdges()];
1987 
1988  VertexDescriptor* edge=edges_;
1989 
1990  typedef typename Graph::ConstVertexIterator Iterator;
1991  Iterator endVertex=graph.end();
1992 
1993  for(Iterator vertex = graph.begin(); vertex != endVertex; ++vertex)
1994  if(excluded_[*vertex])
1995  start_[*vertex]=end_[*vertex]=-1;
1996  else{
1997  ++noVertices_;
1998  endVertex_ = std::max(*vertex, endVertex_);
1999 
2000  start_[*vertex] = edge-edges_;
2001 
2002  typedef typename Graph::ConstEdgeIterator Iterator;
2003  Iterator endEdge = vertex.end();
2004 
2005  for(Iterator iter=vertex.begin(); iter!= endEdge; ++iter)
2006  if(!excluded[iter.target()]) {
2007  *edge = iter.target();
2008  ++edge;
2009  }
2010 
2011  end_[*vertex] = edge - edges_;
2012 
2013  // Sort the edges
2014  std::sort(edges_+start_[*vertex], edge);
2015  }
2016  noEdges_ = edge-edges_;
2017  ++endVertex_;
2018  }
2019 
2020  template<class G, class V, class VM>
2021  inline std::size_t VertexPropertiesGraph<G,V,VM>::noEdges() const
2022  {
2023  return graph_.noEdges();
2024  }
2025 
2026  template<class G, class V, class VM>
2027  inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2028  VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source)
2029  {
2030  return graph_.beginEdges(source);
2031  }
2032 
2033  template<class G, class V, class VM>
2034  inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2035  VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source)
2036  {
2037  return graph_.endEdges(source);
2038  }
2039 
2040  template<class G, class V, class VM>
2041  typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2042  inline VertexPropertiesGraph<G,V,VM>::beginEdges(const VertexDescriptor& source) const
2043  {
2044  return graph_.beginEdges(source);
2045  }
2046 
2047  template<class G, class V, class VM>
2048  typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2049  VertexPropertiesGraph<G,V,VM>::endEdges(const VertexDescriptor& source) const
2050  {
2051  return graph_.endEdges(source);
2052  }
2053 
2054  template<class G, class V, class VM>
2055  template<class C>
2056  VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2057  ::VertexIteratorT(const Father& iter,
2058  C* graph)
2059  : Father(iter), graph_(graph)
2060  {}
2061 
2062  template<class G, class V, class VM>
2063  template<class C>
2064  VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2065  ::VertexIteratorT(const Father& iter)
2066  : Father(iter)
2067  {}
2068 
2069  template<class G, class V, class VM>
2070  template<class C>
2071  template<class C1>
2072  VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2073  ::VertexIteratorT(const VertexIteratorT<C1>& other)
2074  : Father(other), graph_(other.graph_)
2075  {}
2076 
2077  template<class G, class V, class VM>
2078  template<class C>
2079  typename conditional<is_same<C,typename remove_const<C>::type>::value,
2080  V&, const V&>::type
2081  inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties() const
2082  {
2083  return graph_->getVertexProperties(Father::operator*());
2084  }
2085 
2086  template<class G, class V, class VM>
2087  template<class C>
2088  typename conditional<is_same<typename remove_const<C>::type,
2089  C>::value,
2090  typename G::EdgeIterator,
2091  typename G::ConstEdgeIterator>::type
2093  {
2094  return graph_->beginEdges(Father::operator*());
2095  }
2096 
2097  template<class G, class V, class VM>
2098  template<class C>
2099  typename conditional<is_same<typename remove_const<C>::type,
2100  C>::value,
2101  typename G::EdgeIterator,
2102  typename G::ConstEdgeIterator>::type
2104  {
2105  return graph_->endEdges(Father::operator*());
2106  }
2107 
2108  template<class G, class V, class VM>
2109  inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
2110  {
2111  return VertexIterator(graph_.begin(), this);
2112  }
2113 
2114  template<class G, class V, class VM>
2115  inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
2116  {
2117  return VertexIterator(graph_.end());
2118  }
2119 
2120 
2121  template<class G, class V, class VM>
2122  inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin() const
2123  {
2124  return ConstVertexIterator(graph_.begin(), this);
2125  }
2126 
2127  template<class G, class V, class VM>
2128  inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end() const
2129  {
2130  return ConstVertexIterator(graph_.end());
2131  }
2132 
2133  template<class G, class V, class VM>
2134  inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex)
2135  {
2136  return vertexProperties_[vmap_[vertex]];
2137  }
2138 
2139  template<class G, class V, class VM>
2140  inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(const VertexDescriptor& vertex) const
2141  {
2142  return vertexProperties_[vmap_[vertex]];
2143  }
2144 
2145  template<class G, class V, class VM>
2146  inline const G& VertexPropertiesGraph<G,V,VM>::graph() const
2147  {
2148  return graph_;
2149  }
2150 
2151  template<class G, class V, class VM>
2152  inline std::size_t VertexPropertiesGraph<G,V,VM>::noVertices() const
2153  {
2154  return graph_.noVertices();
2155  }
2156 
2157 
2158  template<class G, class V, class VM>
2159  inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex() const
2160  {
2161  return graph_.maxVertex();
2162  }
2163 
2164  template<class G, class V, class VM>
2165  VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph, const VM vmap)
2166  : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V())
2167  {}
2168 
2169  template<class G, class V, class E, class VM, class EM>
2170  template<class C>
2171  PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter,
2172  C* graph)
2173  : Father(iter), graph_(graph)
2174  {}
2175 
2176  template<class G, class V, class E, class VM, class EM>
2177  template<class C>
2178  PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const Father& iter)
2179  : Father(iter)
2180  {}
2181 
2182  template<class G, class V, class E, class VM, class EM>
2183  template<class C>
2184  template<class C1>
2185  PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(const EdgeIteratorT<C1>& other)
2186  : Father(other), graph_(other.graph_)
2187  {}
2188 
2189 
2190  template<class G, class V, class E, class VM, class EM>
2191  inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noEdges() const
2192  {
2193  return graph_.noEdges();
2194  }
2195 
2196  template<class G, class V, class E, class VM, class EM>
2197  template<class C>
2198  inline typename conditional<is_same<C,typename remove_const<C>::type>::value,E&,const E&>::type
2199  PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties() const
2200  {
2201  return graph_->getEdgeProperties(Father::operator*());
2202  }
2203 
2204  template<class G, class V, class E, class VM, class EM>
2205  inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2206  PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source)
2207  {
2208  return EdgeIterator(graph_.beginEdges(source), this);
2209  }
2210 
2211  template<class G, class V, class E, class VM, class EM>
2212  inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2213  PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source)
2214  {
2215  return EdgeIterator(graph_.endEdges(source));
2216  }
2217 
2218  template<class G, class V, class E, class VM, class EM>
2219  typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2220  inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(const VertexDescriptor& source) const
2221  {
2222  return ConstEdgeIterator(graph_.beginEdges(source), this);
2223  }
2224 
2225  template<class G, class V, class E, class VM, class EM>
2226  typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2227  PropertiesGraph<G,V,E,VM,EM>::endEdges(const VertexDescriptor& source) const
2228  {
2229  return ConstEdgeIterator(graph_.endEdges(source));
2230  }
2231 
2232  template<class G, class V, class E, class VM, class EM>
2233  template<class C>
2234  PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2235  ::VertexIteratorT(const Father& iter,
2236  C* graph)
2237  : Father(iter), graph_(graph)
2238  {}
2239 
2240  template<class G, class V, class E, class VM, class EM>
2241  template<class C>
2242  PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2243  ::VertexIteratorT(const Father& iter)
2244  : Father(iter)
2245  {}
2246 
2247  template<class G, class V, class E, class VM, class EM>
2248  template<class C>
2249  template<class C1>
2250  PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2251  ::VertexIteratorT(const VertexIteratorT<C1>& other)
2252  : Father(other), graph_(other.graph_)
2253  {}
2254 
2255  template<class G, class V, class E, class VM, class EM>
2256  template<class C>
2257  inline typename conditional<is_same<C,typename remove_const<C>::type>::value,
2258  V&, const V&>::type
2259  PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties() const
2260  {
2261  return graph_->getVertexProperties(Father::operator*());
2262  }
2263 
2264  template<class G, class V, class E, class VM, class EM>
2265  template<class C>
2266  inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2268  {
2269  return graph_->beginEdges(Father::operator*());
2270  }
2271 
2272  template<class G, class V, class E, class VM, class EM>
2273  template<class C>
2274  inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2276  {
2277  return graph_->endEdges(Father::operator*());
2278  }
2279 
2280  template<class G, class V, class E, class VM, class EM>
2281  inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
2282  {
2283  return VertexIterator(graph_.begin(), this);
2284  }
2285 
2286  template<class G, class V, class E, class VM, class EM>
2287  inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
2288  {
2289  return VertexIterator(graph_.end());
2290  }
2291 
2292 
2293  template<class G, class V, class E, class VM, class EM>
2294  inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin() const
2295  {
2296  return ConstVertexIterator(graph_.begin(), this);
2297  }
2298 
2299  template<class G, class V, class E, class VM, class EM>
2300  inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end() const
2301  {
2302  return ConstVertexIterator(graph_.end());
2303  }
2304 
2305  template<class G, class V, class E, class VM, class EM>
2306  inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex)
2307  {
2308  return vertexProperties_[vmap_[vertex]];
2309  }
2310 
2311  template<class G, class V, class E, class VM, class EM>
2312  inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(const VertexDescriptor& vertex) const
2313  {
2314  return vertexProperties_[vmap_[vertex]];
2315  }
2316 
2317  template<class G, class V, class E, class VM, class EM>
2318  inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge)
2319  {
2320  return edgeProperties_[emap_[edge]];
2321  }
2322 
2323  template<class G, class V, class E, class VM, class EM>
2324  inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const EdgeDescriptor& edge) const
2325  {
2326  return edgeProperties_[emap_[edge]];
2327  }
2328 
2329  template<class G, class V, class E, class VM, class EM>
2330  inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
2331  const VertexDescriptor& target)
2332  {
2333  return getEdgeProperties(graph_.findEdge(source,target));
2334  }
2335 
2336  template<class G, class V, class E, class VM, class EM>
2337  inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(const VertexDescriptor& source,
2338  const VertexDescriptor& target) const
2339  {
2340  return getEdgeProperties(graph_.findEdge(source,target));
2341  }
2342 
2343  template<class G, class V, class E, class VM, class EM>
2344  inline const G& PropertiesGraph<G,V,E,VM,EM>::graph() const
2345  {
2346  return graph_;
2347  }
2348 
2349  template<class G, class V, class E, class VM, class EM>
2350  inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noVertices() const
2351  {
2352  return graph_.noVertices();
2353  }
2354 
2355 
2356  template<class G, class V, class E, class VM, class EM>
2357  inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex() const
2358  {
2359  return graph_.maxVertex();
2360  }
2361 
2362  template<class G, class V, class E, class VM, class EM>
2363  PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph, const VM& vmap, const EM& emap)
2364  : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V()),
2365  emap_(emap), edgeProperties_(graph_.noEdges(), E())
2366  {}
2367 
2368  template<class G, class V>
2369  inline int visitNeighbours(const G& graph, const typename G::VertexDescriptor& vertex,
2370  V& visitor)
2371  {
2372  typedef typename G::ConstEdgeIterator iterator;
2373  const iterator end = graph.endEdges(vertex);
2374  int noNeighbours=0;
2375  for(iterator edge = graph.beginEdges(vertex); edge != end; ++edge, ++noNeighbours)
2376  visitor(edge);
2377  return noNeighbours;
2378  }
2379 
2380 #endif // DOXYGEN
2381 
2383  }
2384 }
2385 #endif
VertexIterator begin()
Get an iterator over the vertices.
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
EdgeIterator beginEdges(const VertexDescriptor &source)
Get an iterator over the edges starting at a vertex.
EdgeIteratorT< C > & operator++()
preincrement operator.
const EdgeDescriptor & operator*() const
Get the edge descriptor.
std::ptrdiff_t distanceTo(const EdgeIterator &other) const
conditional< is_same< C, typename remove_const< C >::type >::value &&C::mutableMatrix, typename M::block_type, const typename M::block_type >::type WeightType
Definition: graph.hh:264
VertexIteratorT< MatrixGraph< Matrix > > VertexIterator
The mutable vertex iterator type.
Definition: graph.hh:311
VertexIteratorT(C *graph, const VertexDescriptor &current)
Constructor.
remove_const< M >::type MutableMatrix
The mutable type of the matrix we are a graph for.
Definition: graph.hh:59
bool equals(const EdgeIterator &other) const
Equality operator.
ConstEdgeIterator beginEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
std::size_t noVertices() const
Get the number of vertices in the graph.
conditional< is_same< typename remove_const< C >::type, C >::value, typename Graph::EdgeIterator, typename Graph::ConstEdgeIterator >::type Father
The father class.
Definition: graph.hh:1048
EdgeIteratorT(const VertexDescriptor &source, const ColIterator &block, const ColIterator &end, const EdgeDescriptor &edge)
Constructor.
VertexDescriptor * EdgeDescriptor
Definition: graph.hh:459
EdgeIterator endEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:736
conditional< is_same< C, typename remove_const< C >::type >::value &&C::mutableMatrix, typename M::block_type, const typename M::block_type >::type WeightType
Definition: graph.hh:154
const VertexDescriptor & target() const
The index of the target vertex of the current edge.
Row row
Definition: matrixmatrix.hh:345
remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:99
Definition: basearray.hh:19
const VertexDescriptor & source() const
The index of the source vertex of the current edge.
M::block_type Weight
The type of the weights.
Definition: graph.hh:64
The edge iterator of the graph.
Definition: graph.hh:502
conditional< isMutable &&C::mutableMatrix, typename Matrix::row_type::Iterator, typename Matrix::row_type::ConstIterator >::type ColIterator
The column iterator of the matrix we use.
Definition: graph.hh:118
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:1009
VertexIterator begin()
Get an iterator over the vertices.
VertexIterator ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:621
Matrix & matrix()
Get the underlying matrix.
ReadablePropertyMapTag Category
Definition: graph.hh:470
~SubGraph()
Destructor.
VertexIterator end()
Get an iterator over the vertices.
const Graph & graph() const
Get the graph the properties are attached to.
derive error class from the base class in common
Definition: istlexception.hh:16
std::size_t noVertices() const
Get the number of vertices in the graph.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:731
Attaches properties to the edges and vertices of a graph.
Definition: graph.hh:975
VertexDescriptor target() const
The index of the target vertex of the current edge.
GraphEdgePropertiesSelector()
Default constructor.
Definition: graph.hh:1432
EP EdgeProperties
The type of the properties of the edges;.
Definition: graph.hh:1014
EdgeIterator beginEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
VertexProperties & operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: graph.hh:1393
VertexProperties & getVertexProperties(const VertexDescriptor &vertex)
Get the properties associated with a vertex.
VP VertexProperties
The type of the properties of the vertices.
Definition: graph.hh:741
std::size_t noVertices() const
Get the number of vertices in the graph.
const remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:103
std::size_t noEdges() const
Get the number of edges in the graph.
const Graph & graph() const
Get the graph the properties are attached to.
The (undirected) graph of a matrix.
Definition: graph.hh:48
VertexIterator & increment()
Preincrement operator.
ConstVertexIterator end() const
Get an iterator over the vertices.
EdgeIterator & advance(std::ptrdiff_t n)
EdgeIndexMap(const EdgeDescriptor &firstEdge)
Definition: graph.hh:472
whether C is mutable.
Definition: graph.hh:223
bool equals(const VertexIterator &other) const
Equality iterator.
EdgeIterator beginEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:457
EdgeIterator begin() const
Get an iterator over the edges starting from the current vertex.
T Excluded
Random access container providing information about which vertices are excluded.
Definition: graph.hh:452
GraphVertexPropertiesSelector()
Default constructor.
Definition: graph.hh:1384
EdgeIterator(const VertexDescriptor &source, const EdgeDescriptor &edge)
Constructor.
VertexIterator begin()
Get an iterator over the vertices.
const EdgeDescriptor & dereference() const
The descriptor of the current edge.
conditional< is_same< typename remove_const< C >::type, C >::value, typename Graph::VertexIterator, typename Graph::ConstVertexIterator >::type Father
The father class.
Definition: graph.hh:812
EdgeIteratorT< C > end() const
Get an iterator over all edges starting at the current vertex.
VertexIteratorT< C > & operator++()
Move to the next vertex.
An index map for mapping the edges to indices.
Definition: graph.hh:467
G Graph
The graph we attach properties to.
Definition: graph.hh:726
const remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:216
EdgeIteratorT< const MatrixGraph< Matrix > > ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:296
EdgeIndexMap(const EdgeIndexMap &emap)
Protect copy construction.
Definition: graph.hh:477
const VertexDescriptor & dereference() const
Get the descriptor of the current vertex.
conditional< is_same< C, typename remove_const< C >::type >::value, VertexProperties &, const VertexProperties & >::type properties() const
Get the properties of the current Vertex.
conditional< isMutable &&C::mutableMatrix, typename M::block_type, const typename M::block_type >::type Weight
The matrix block type we use as weights.
Definition: graph.hh:125
EdgeIterator begin() const
Get an iterator over all edges starting at the current vertex.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:986
ConstEdgeIterator endEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
The vertex iterator of the graph.
Definition: graph.hh:556
EdgeProperties & getEdgeProperties(const EdgeDescriptor &edge)
Get the properties associated with a edge.
bool operator!=(const EdgeIteratorT< typename remove_const< C >::type > &other) const
Inequality operator.
VertexPropertiesGraph(Graph &graph, const VertexMap vmap=VertexMap())
Constructor.
WeightType & weight() const
Access the weight of the vertex.
std::size_t noVertices() const
Get the number of vertices in the graph.
std::size_t noEdges() const
Get the number of edges in the graph.
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1364
GraphVertexPropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1378
Graph::EdgeIterator EdgeIterator
The type of the mutable edge iterator.
Definition: graph.hh:759
EdgeIterator end() const
Get an iterator over all edges starting at the current vertex.
const EdgeDescriptor * operator->() const
Get the edge descriptor.
The vertex iterator type of the graph.
Definition: graph.hh:206
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
EdgeIterator ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:616
VertexIterator end()
Get an iterator over the vertices.
G Graph
The type of the graph we are a sub graph for.
Definition: graph.hh:446
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:71
EM EdgeMap
The type of the map for converting the EdgeDescriptor to std::size_t.
Definition: graph.hh:1028
EdgeProperties & operator[](const Edge &edge) const
Get the properties associated to a vertex.
Definition: graph.hh:1440
std::size_t operator[](const EdgeDescriptor &edge) const
Definition: graph.hh:481
Wrapper to access the internal edge properties of a graph via operator[]()
Definition: graph.hh:1358
EdgeIterator & decrement()
Preincrement operator.
EdgeIterator end() const
Get an iterator over the edges starting from the current vertex.
bool operator!=(const VertexIteratorT< ConstContainer > &other) const
Inequality operator.
A subgraph of a graph.
Definition: graph.hh:440
G::EdgeProperties EdgeProperties
The type of the vertex properties.
Definition: graph.hh:1416
std::size_t noEdges() const
Get the number of edges in the graph.
std::size_t noEdges() const
Get the number of edges in the graph.
conditional< is_same< typename remove_const< C >::type, C >::value, typename Graph::VertexIterator, typename Graph::ConstVertexIterator >::type Father
The father class.
Definition: graph.hh:1149
VertexDescriptor source() const
The index of the source vertex of the current edge.
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:754
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
MatrixGraph(Matrix &matrix)
Constructor.
bool operator==(const VertexIteratorT< ConstContainer > &other) const
Equality operator.
EdgeIterator & increment()
Preincrement operator.
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:991
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: graph.hh:1372
~MatrixGraph()
Destructor.
EdgeIndexMap getEdgeIndexMap()
Get an edge index map for the graph.
VertexIterator(const SubGraph< G, T > *graph, const VertexDescriptor &current, const VertexDescriptor &end)
Constructor.
EdgeDescriptor findEdge(const VertexDescriptor &source, const VertexDescriptor &target) const
Find the descriptor of an edge.
EdgeIteratorT< C > begin() const
Get an iterator over all edges starting at the current vertex.
G::VertexProperties VertexProperties
The type of the vertex properties.
Definition: graph.hh:1368
EdgeIteratorT< MatrixGraph< Matrix > > EdgeIterator
The mutable edge iterator type.
Definition: graph.hh:301
int visitNeighbours(const G &graph, const typename G::VertexDescriptor &vertex, V &visitor)
Visit all neighbour vertices of a vertex in a graph.
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1412
bool operator==(const EdgeIteratorT< typename remove_const< C >::type > &other) const
Equality operator.
Graph::ConstEdgeIterator ConstEdgeIterator
The type of the constant edge iterator.
Definition: graph.hh:764
ConstVertexIterator begin() const
Get an iterator over the vertices.
std::ptrdiff_t EdgeDescriptor
The edge descriptor.
Definition: graph.hh:78
EdgeDescriptor findEdge(const VertexDescriptor &source, const VertexDescriptor &target) const
Find the descriptor of an edge.
VertexIteratorT< const MatrixGraph< Matrix > > ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:306
VertexProperties & getVertexProperties(const VertexDescriptor &vertex)
Get the properties associated with a vertex.
VP VertexProperties
The type of the properties of the vertices.
Definition: graph.hh:996
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
G Graph
The graph we attach properties to.
Definition: graph.hh:981
EdgeIterator endEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
VertexIterator end()
Get an iterator over the vertices.
Attaches properties to the vertices of a graph.
Definition: graph.hh:720
Iterator over all edges starting from a vertex.
Definition: graph.hh:92
WeightType & weight() const
Access the edge weight.
EdgeIterator endEdges(const VertexDescriptor &source)
Get an iterator over the edges starting at a vertex.
G::EdgeDescriptor Edge
The edge descriptor.
Definition: graph.hh:1420
const VertexDescriptor & operator*() const
Get the descriptor of the current vertex.
GraphEdgePropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1426
remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:212
M Matrix
The type of the matrix we are a graph for.
Definition: graph.hh:54
PropertiesGraph(Graph &graph, const VertexMap &vmap=VertexMap(), const EdgeMap &emap=EdgeMap())
Constructor.
SubGraph(const Graph &graph, const T &excluded)
Constructor.
whether C is mutable.
Definition: graph.hh:110
Wrapper to access the internal vertex properties of a graph via operator[]()
Definition: graph.hh:1406