5#ifndef DUNE_AMG_GRAPH_HH
6#define DUNE_AMG_GRAPH_HH
15#include <dune/istl/istlexception.hh>
16#include <dune/common/propertymap.hh>
66 typedef typename M::block_type
Weight;
86 mutableMatrix = std::is_same<M, typename std::remove_const<M>::type>::value
112 isMutable = std::is_same<C, MutableContainer>::value
118 typedef typename std::conditional<
isMutable && C::mutableMatrix,
typename Matrix::row_type::Iterator,
119 typename Matrix::row_type::ConstIterator>::type
125 typedef typename std::conditional<
isMutable && C::mutableMatrix,
typename M::block_type,
126 const typename M::block_type>::type
154 typedef typename std::conditional<std::is_same<C, typename std::remove_const<C>::type>::value && C::mutableMatrix,
155 typename M::block_type,
const typename M::block_type>::type
225 isMutable = std::is_same<C, MutableContainer>::value
264 typedef typename std::conditional<std::is_same<C, typename std::remove_const<C>::type>::value && C::mutableMatrix,
265 typename M::block_type,
const typename M::block_type>::type
441 template<
class G,
class T>
475 : firstEdge_(firstEdge)
480 : firstEdge_(emap.firstEdge_)
483 std::size_t operator[](
const EdgeDescriptor& edge)
const
485 return edge-firstEdge_;
489 EdgeDescriptor firstEdge_;
543 std::ptrdiff_t distanceTo(
const EdgeIterator& other)
const;
552 EdgeDescriptor edge_;
696 std::size_t noVertices_;
709 std::ptrdiff_t* start_;
711 std::ptrdiff_t* end_;
721 template<
class G,
class VP,
class VM=IdentityMap>
798 class VertexIteratorT
799 :
public std::conditional<std::is_same<typename std::remove_const<C>::type,
801 typename Graph::VertexIterator,
802 typename Graph::ConstVertexIterator>::type
804 friend class VertexIteratorT<const typename
std::remove_const<C>::type>;
805 friend class VertexIteratorT<typename std::remove_const<C>::type>;
810 typedef typename std::conditional<std::is_same<typename std::remove_const<C>::type,
812 typename Graph::VertexIterator,
813 typename Graph::ConstVertexIterator>::type
819 typedef typename std::conditional<std::is_same<typename std::remove_const<C>::type,
821 typename Graph::EdgeIterator,
822 typename Graph::ConstEdgeIterator>::type
830 explicit VertexIteratorT(const Father& iter,
841 explicit VertexIteratorT(const Father& iter);
848 VertexIteratorT(const VertexIteratorT<C1>& other);
853 typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,
855 const VertexProperties&>::type
882 typedef VertexIteratorT<VertexPropertiesGraph<Graph,
888 typedef VertexIteratorT<const VertexPropertiesGraph<Graph,
969 std::vector<VertexProperties> vertexProperties_;
976 template<
class G,
class VP,
class EP,
class VM=IdentityMap,
class EM=IdentityMap>
1034 :
public std::conditional<std::is_same<typename std::remove_const<C>::type,
1036 typename Graph::EdgeIterator,
1037 typename Graph::ConstEdgeIterator>::type
1040 friend class EdgeIteratorT<const typename
std::remove_const<C>::type>;
1041 friend class EdgeIteratorT<typename std::remove_const<C>::type>;
1046 typedef typename std::conditional<std::is_same<typename std::remove_const<C>::type,
1048 typename Graph::EdgeIterator,
1049 typename Graph::ConstEdgeIterator>::type
1057 explicit EdgeIteratorT(const Father& iter,
1067 explicit EdgeIteratorT(const Father& iter);
1074 EdgeIteratorT(const EdgeIteratorT<C1>& other);
1079 typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,
1081 const EdgeProperties&>::type
1094 typedef EdgeIteratorT<PropertiesGraph<Graph,
1101 typedef EdgeIteratorT<const PropertiesGraph<Graph,
1135 class VertexIteratorT
1136 :
public std::conditional<std::is_same<typename std::remove_const<C>::type,
1138 typename Graph::VertexIterator,
1139 typename Graph::ConstVertexIterator>::type
1141 friend class VertexIteratorT<const typename
std::remove_const<C>::type>;
1142 friend class VertexIteratorT<typename std::remove_const<C>::type>;
1147 typedef typename std::conditional<std::is_same<typename std::remove_const<C>::type,
1149 typename Graph::VertexIterator,
1150 typename Graph::ConstVertexIterator>::type
1158 explicit VertexIteratorT(const Father& iter,
1169 explicit VertexIteratorT(const Father& iter);
1176 VertexIteratorT(const VertexIteratorT<C1>& other);
1181 typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,
1183 const VertexProperties&>::type
1191 EdgeIteratorT<C>
begin() const;
1198 EdgeIteratorT<C>
end() const;
1210 typedef VertexIteratorT<PropertiesGraph<Graph,
1217 typedef VertexIteratorT<const PropertiesGraph<Graph,
1266 const VertexDescriptor& target)
1268 return graph_.findEdge(source,target);
1346 std::vector<VertexProperties> vertexProperties_;
1350 std::vector<EdgeProperties> edgeProperties_;
1359 template<
typename G>
1397 return graph_->getVertexProperties(
vertex);
1407 template<
typename G>
1422 typedef typename G::EdgeDescriptor
Edge;
1444 return graph_->getEdgeProperties(edge);
1461 template<
class G,
class V>
1471 if(matrix_.N()!=matrix_.M())
1474 start_ =
new EdgeDescriptor[matrix_.N()+1];
1476 typedef typename M::ConstIterator Iterator;
1477 start_[matrix_.begin().index()] = 0;
1479 for(Iterator row=matrix_.begin(); row != matrix_.end(); ++row)
1480 start_[row.index()+1] = start_[row.index()] + row->size();
1484 MatrixGraph<M>::~MatrixGraph()
1490 inline std::size_t MatrixGraph<M>::noEdges()
const
1492 return start_[matrix_.N()];
1496 inline std::size_t MatrixGraph<M>::noVertices()
const
1502 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::maxVertex()
const
1504 return matrix_.N()-1;
1508 typename MatrixGraph<M>::EdgeDescriptor
1509 MatrixGraph<M>::findEdge(
const VertexDescriptor& source,
1510 const VertexDescriptor& target)
const
1512 typename M::ConstColIterator found =matrix_[source].find(target);
1513 if(found == matrix_[source].end())
1515 std::size_t offset = found.offset();
1519 assert(offset<noEdges());
1521 return start_[source]+offset;
1526 inline M& MatrixGraph<M>::matrix()
1532 inline const M& MatrixGraph<M>::matrix()
const
1539 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(
const VertexDescriptor& source,
const ColIterator& block,
1540 const ColIterator& end,
const EdgeDescriptor& edge)
1541 : source_(source), block_(block), blockEnd_(end), edge_(edge)
1543 if(block_!=blockEnd_ && block_.index() == source_) {
1551 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(
const ColIterator& block)
1558 MatrixGraph<M>::EdgeIteratorT<C>::EdgeIteratorT(
const EdgeIteratorT<C1>& other)
1559 : source_(other.source_), block_(other.block_), blockEnd_(other.blockEnd_), edge_(other.edge_)
1565 inline typename MatrixGraph<M>::template EdgeIteratorT<C>::WeightType&
1566 MatrixGraph<M>::EdgeIteratorT<C>::weight()
const
1573 inline typename MatrixGraph<M>::template EdgeIteratorT<C>& MatrixGraph<M>::EdgeIteratorT<C>::operator++()
1578 if(block_!=blockEnd_ && block_.index() == source_) {
1590 return block_!=other.block_;
1597 return block_!=other.block_;
1604 return block_==other.block_;
1611 return block_==other.block_;
1616 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::target()
const
1618 return block_.index();
1623 inline typename MatrixGraph<M>::VertexDescriptor MatrixGraph<M>::EdgeIteratorT<C>::source()
const
1630 inline const typename MatrixGraph<M>::EdgeDescriptor& MatrixGraph<M>::EdgeIteratorT<C>::operator*()
const
1637 inline const typename MatrixGraph<M>::EdgeDescriptor* MatrixGraph<M>::EdgeIteratorT<C>::operator->()
const
1644 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(C* graph,
1645 const VertexDescriptor& current)
1646 : graph_(graph), current_(current)
1652 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(
const VertexDescriptor& current)
1658 MatrixGraph<M>::VertexIteratorT<C>::VertexIteratorT(
const VertexIteratorT<MutableContainer>& other)
1659 : graph_(other.graph_), current_(other.current_)
1666 return current_ != other.current_;
1673 return current_ != other.current_;
1681 return current_ == other.current_;
1688 return current_ == other.current_;
1693 inline typename MatrixGraph<M>::template VertexIteratorT<C>& MatrixGraph<M>::VertexIteratorT<C>::operator++()
1701 inline typename MatrixGraph<M>::template VertexIteratorT<C>::WeightType&
1702 MatrixGraph<M>::VertexIteratorT<C>::weight()
const
1704 return graph_->matrix()[current_][current_];
1709 inline const typename MatrixGraph<M>::VertexDescriptor&
1710 MatrixGraph<M>::VertexIteratorT<C>::operator*()
const
1717 inline typename MatrixGraph<M>::template EdgeIteratorT<C>
1718 MatrixGraph<M>::VertexIteratorT<C>::begin()
const
1720 return graph_->beginEdges(current_);
1725 inline typename MatrixGraph<M>::template EdgeIteratorT<C>
1726 MatrixGraph<M>::VertexIteratorT<C>::end()
const
1728 return graph_->endEdges(current_);
1732 inline typename MatrixGraph<M>::template VertexIteratorT<MatrixGraph<M> >
1733 MatrixGraph<M>::begin()
1735 return VertexIterator(
this,0);
1739 inline typename MatrixGraph<M>::template VertexIteratorT<MatrixGraph<M> >
1740 MatrixGraph<M>::end()
1742 return VertexIterator(matrix_.N());
1747 inline typename MatrixGraph<M>::template VertexIteratorT<const MatrixGraph<M> >
1748 MatrixGraph<M>::begin()
const
1750 return ConstVertexIterator(
this, 0);
1754 inline typename MatrixGraph<M>::template VertexIteratorT<const MatrixGraph<M> >
1755 MatrixGraph<M>::end()
const
1757 return ConstVertexIterator(matrix_.N());
1761 inline typename MatrixGraph<M>::template EdgeIteratorT<MatrixGraph<M> >
1762 MatrixGraph<M>::beginEdges(
const VertexDescriptor& source)
1764 return EdgeIterator(source, matrix_.operator[](source).begin(),
1765 matrix_.operator[](source).end(), start_[source]);
1769 inline typename MatrixGraph<M>::template EdgeIteratorT<MatrixGraph<M> >
1770 MatrixGraph<M>::endEdges(
const VertexDescriptor& source)
1772 return EdgeIterator(matrix_.operator[](source).end());
1777 inline typename MatrixGraph<M>::template EdgeIteratorT<const MatrixGraph<M> >
1778 MatrixGraph<M>::beginEdges(
const VertexDescriptor& source)
const
1780 return ConstEdgeIterator(source, matrix_.operator[](source).begin(),
1781 matrix_.operator[](source).end(), start_[source]);
1785 inline typename MatrixGraph<M>::template EdgeIteratorT<const MatrixGraph<M> >
1786 MatrixGraph<M>::endEdges(
const VertexDescriptor& source)
const
1788 return ConstEdgeIterator(matrix_.operator[](source).end());
1792 template<
class G,
class T>
1793 SubGraph<G,T>::EdgeIterator::EdgeIterator(
const VertexDescriptor& source,
1794 const EdgeDescriptor& edge)
1795 : source_(source), edge_(edge)
1799 template<
class G,
class T>
1800 SubGraph<G,T>::EdgeIterator::EdgeIterator(
const EdgeDescriptor& edge)
1804 template<
class G,
class T>
1805 typename SubGraph<G,T>::EdgeIndexMap SubGraph<G,T>::getEdgeIndexMap()
1807 return EdgeIndexMap(edges_);
1810 template<
class G,
class T>
1813 return other.edge_==edge_;
1816 template<
class G,
class T>
1817 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::increment()
1823 template<
class G,
class T>
1824 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::decrement()
1830 template<
class G,
class T>
1831 inline typename SubGraph<G,T>::EdgeIterator& SubGraph<G,T>::EdgeIterator::advance(std::ptrdiff_t n)
1836 template<
class G,
class T>
1837 inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::source()
const
1842 template<
class G,
class T>
1843 inline const typename G::VertexDescriptor& SubGraph<G,T>::EdgeIterator::target()
const
1849 template<
class G,
class T>
1850 inline const typename SubGraph<G,T>::EdgeDescriptor& SubGraph<G,T>::EdgeIterator::dereference()
const
1855 template<
class G,
class T>
1856 inline std::ptrdiff_t SubGraph<G,T>::EdgeIterator::distanceTo(
const EdgeIterator & other)
const
1858 return other.edge_-edge_;
1861 template<
class G,
class T>
1862 SubGraph<G,T>::VertexIterator::VertexIterator(
const SubGraph<G,T>* graph,
1863 const VertexDescriptor& current,
1864 const VertexDescriptor& end)
1865 : graph_(graph), current_(current), end_(end)
1868 typedef typename T::const_iterator Iterator;
1870 for(Iterator
vertex = graph_->excluded_.begin();
1871 current_ != end_ && *
vertex;
1874 assert(current_ == end_ || !graph_->excluded_[current_]);
1877 template<
class G,
class T>
1878 SubGraph<G,T>::VertexIterator::VertexIterator(
const VertexDescriptor& current)
1882 template<
class G,
class T>
1883 inline typename SubGraph<G,T>::VertexIterator& SubGraph<G,T>::VertexIterator::increment()
1887 while(current_ != end_ && graph_->excluded_[current_])
1890 assert(current_ == end_ || !graph_->excluded_[current_]);
1894 template<
class G,
class T>
1897 return current_==other.current_;
1900 template<
class G,
class T>
1901 inline const typename G::VertexDescriptor& SubGraph<G,T>::VertexIterator::dereference()
const
1906 template<
class G,
class T>
1907 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::begin()
const
1909 return graph_->beginEdges(current_);
1912 template<
class G,
class T>
1913 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::VertexIterator::end()
const
1915 return graph_->endEdges(current_);
1918 template<
class G,
class T>
1919 inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::begin()
const
1921 return VertexIterator(
this, 0, endVertex_);
1925 template<
class G,
class T>
1926 inline typename SubGraph<G,T>::VertexIterator SubGraph<G,T>::end()
const
1928 return VertexIterator(endVertex_);
1932 template<
class G,
class T>
1933 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::beginEdges(
const VertexDescriptor& source)
const
1935 return EdgeIterator(source, edges_+start_[source]);
1938 template<
class G,
class T>
1939 inline typename SubGraph<G,T>::EdgeIterator SubGraph<G,T>::endEdges(
const VertexDescriptor& source)
const
1941 return EdgeIterator(edges_+end_[source]);
1944 template<
class G,
class T>
1945 std::size_t SubGraph<G,T>::noVertices()
const
1950 template<
class G,
class T>
1951 inline typename SubGraph<G,T>::VertexDescriptor SubGraph<G,T>::maxVertex()
const
1956 template<
class G,
class T>
1957 inline std::size_t SubGraph<G,T>::noEdges()
const
1962 template<
class G,
class T>
1963 inline typename SubGraph<G,T>::EdgeDescriptor SubGraph<G,T>::findEdge(
const VertexDescriptor& source,
1964 const VertexDescriptor& target)
const
1966 const EdgeDescriptor edge = std::lower_bound(edges_+start_[source], edges_+end_[source], target);
1967 if(edge==edges_+end_[source] || *edge!=target)
1973 template<
class G,
class T>
1974 SubGraph<G,T>::~SubGraph()
1981 template<
class G,
class T>
1982 SubGraph<G,T>::SubGraph(
const G& graph,
const T& excluded)
1983 : excluded_(excluded), noVertices_(0), endVertex_(0), maxVertex_(graph.maxVertex())
1985 start_ =
new std::ptrdiff_t[graph.noVertices()];
1986 end_ =
new std::ptrdiff_t[graph.noVertices()];
1987 edges_ =
new VertexDescriptor[graph.noEdges()];
1989 VertexDescriptor* edge=edges_;
1993 if ( graph.noVertices() == 0)
1996 typedef typename Graph::ConstVertexIterator Iterator;
1997 Iterator endVertex=graph.end();
2004 endVertex_ = std::max(*
vertex, endVertex_);
2006 start_[*
vertex] = edge-edges_;
2008 auto endEdge =
vertex.end();
2010 for(
auto iter=
vertex.begin(); iter!= endEdge; ++iter)
2011 if(!excluded[iter.target()]) {
2012 *edge = iter.target();
2016 end_[*
vertex] = edge - edges_;
2019 std::sort(edges_+start_[*
vertex], edge);
2021 noEdges_ = edge-edges_;
2025 template<
class G,
class V,
class VM>
2026 inline std::size_t VertexPropertiesGraph<G,V,VM>::noEdges()
const
2028 return graph_.noEdges();
2031 template<
class G,
class V,
class VM>
2032 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2033 VertexPropertiesGraph<G,V,VM>::beginEdges(
const VertexDescriptor& source)
2035 return graph_.beginEdges(source);
2038 template<
class G,
class V,
class VM>
2039 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2040 VertexPropertiesGraph<G,V,VM>::endEdges(
const VertexDescriptor& source)
2042 return graph_.endEdges(source);
2045 template<
class G,
class V,
class VM>
2046 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2047 inline VertexPropertiesGraph<G,V,VM>::beginEdges(
const VertexDescriptor& source)
const
2049 return graph_.beginEdges(source);
2052 template<
class G,
class V,
class VM>
2053 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2054 VertexPropertiesGraph<G,V,VM>::endEdges(
const VertexDescriptor& source)
const
2056 return graph_.endEdges(source);
2059 template<
class G,
class V,
class VM>
2061 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2062 ::VertexIteratorT(
const Father& iter,
2064 : Father(iter), graph_(graph)
2067 template<
class G,
class V,
class VM>
2069 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2070 ::VertexIteratorT(
const Father& iter)
2074 template<
class G,
class V,
class VM>
2077 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2078 ::VertexIteratorT(
const VertexIteratorT<C1>& other)
2079 : Father(other), graph_(other.graph_)
2082 template<
class G,
class V,
class VM>
2084 typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,
2086 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties()
const
2088 return graph_->getVertexProperties(Father::operator*());
2091 template<
class G,
class V,
class VM>
2093 typename std::conditional<std::is_same<typename std::remove_const<C>::type,
2095 typename G::EdgeIterator,
2096 typename G::ConstEdgeIterator>::type
2097 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::begin()
const
2099 return graph_->beginEdges(Father::operator*());
2102 template<
class G,
class V,
class VM>
2104 typename std::conditional<std::is_same<typename std::remove_const<C>::type,
2106 typename G::EdgeIterator,
2107 typename G::ConstEdgeIterator>::type
2108 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::end()
const
2110 return graph_->endEdges(Father::operator*());
2113 template<
class G,
class V,
class VM>
2114 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
2116 return VertexIterator(graph_.begin(),
this);
2119 template<
class G,
class V,
class VM>
2120 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
2122 return VertexIterator(graph_.end());
2126 template<
class G,
class V,
class VM>
2127 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin()
const
2129 return ConstVertexIterator(graph_.begin(),
this);
2132 template<
class G,
class V,
class VM>
2133 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end()
const
2135 return ConstVertexIterator(graph_.end());
2138 template<
class G,
class V,
class VM>
2139 inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(
const VertexDescriptor&
vertex)
2141 return vertexProperties_[vmap_[
vertex]];
2144 template<
class G,
class V,
class VM>
2145 inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(
const VertexDescriptor&
vertex)
const
2147 return vertexProperties_[vmap_[
vertex]];
2150 template<
class G,
class V,
class VM>
2151 inline const G& VertexPropertiesGraph<G,V,VM>::graph()
const
2156 template<
class G,
class V,
class VM>
2157 inline std::size_t VertexPropertiesGraph<G,V,VM>::noVertices()
const
2159 return graph_.noVertices();
2163 template<
class G,
class V,
class VM>
2164 inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex()
const
2166 return graph_.maxVertex();
2169 template<
class G,
class V,
class VM>
2170 VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph,
const VM vmap)
2171 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V())
2174 template<
class G,
class V,
class E,
class VM,
class EM>
2176 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const Father& iter,
2178 : Father(iter), graph_(graph)
2181 template<
class G,
class V,
class E,
class VM,
class EM>
2183 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const Father& iter)
2187 template<
class G,
class V,
class E,
class VM,
class EM>
2190 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const EdgeIteratorT<C1>& other)
2191 : Father(other), graph_(other.graph_)
2195 template<
class G,
class V,
class E,
class VM,
class EM>
2196 inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noEdges()
const
2198 return graph_.noEdges();
2201 template<
class G,
class V,
class E,
class VM,
class EM>
2203 inline typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,E&,
const E&>::type
2204 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties()
const
2206 return graph_->getEdgeProperties(Father::operator*());
2209 template<
class G,
class V,
class E,
class VM,
class EM>
2210 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2211 PropertiesGraph<G,V,E,VM,EM>::beginEdges(
const VertexDescriptor& source)
2213 return EdgeIterator(graph_.beginEdges(source),
this);
2216 template<
class G,
class V,
class E,
class VM,
class EM>
2217 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2218 PropertiesGraph<G,V,E,VM,EM>::endEdges(
const VertexDescriptor& source)
2220 return EdgeIterator(graph_.endEdges(source));
2223 template<
class G,
class V,
class E,
class VM,
class EM>
2224 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2225 inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(
const VertexDescriptor& source)
const
2227 return ConstEdgeIterator(graph_.beginEdges(source),
this);
2230 template<
class G,
class V,
class E,
class VM,
class EM>
2231 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2232 PropertiesGraph<G,V,E,VM,EM>::endEdges(
const VertexDescriptor& source)
const
2234 return ConstEdgeIterator(graph_.endEdges(source));
2237 template<
class G,
class V,
class E,
class VM,
class EM>
2239 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2240 ::VertexIteratorT(
const Father& iter,
2242 : Father(iter), graph_(graph)
2245 template<
class G,
class V,
class E,
class VM,
class EM>
2247 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2248 ::VertexIteratorT(
const Father& iter)
2252 template<
class G,
class V,
class E,
class VM,
class EM>
2255 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2256 ::VertexIteratorT(
const VertexIteratorT<C1>& other)
2257 : Father(other), graph_(other.graph_)
2260 template<
class G,
class V,
class E,
class VM,
class EM>
2262 inline typename std::conditional<std::is_same<C,typename std::remove_const<C>::type>::value,
2264 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties()
const
2266 return graph_->getVertexProperties(Father::operator*());
2269 template<
class G,
class V,
class E,
class VM,
class EM>
2271 inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2272 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::begin()
const
2274 return graph_->beginEdges(Father::operator*());
2277 template<
class G,
class V,
class E,
class VM,
class EM>
2279 inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2280 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::end()
const
2282 return graph_->endEdges(Father::operator*());
2285 template<
class G,
class V,
class E,
class VM,
class EM>
2286 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
2288 return VertexIterator(graph_.begin(),
this);
2291 template<
class G,
class V,
class E,
class VM,
class EM>
2292 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
2294 return VertexIterator(graph_.end());
2298 template<
class G,
class V,
class E,
class VM,
class EM>
2299 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
const
2301 return ConstVertexIterator(graph_.begin(),
this);
2304 template<
class G,
class V,
class E,
class VM,
class EM>
2305 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
const
2307 return ConstVertexIterator(graph_.end());
2310 template<
class G,
class V,
class E,
class VM,
class EM>
2311 inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(
const VertexDescriptor&
vertex)
2313 return vertexProperties_[vmap_[
vertex]];
2316 template<
class G,
class V,
class E,
class VM,
class EM>
2317 inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(
const VertexDescriptor&
vertex)
const
2319 return vertexProperties_[vmap_[
vertex]];
2322 template<
class G,
class V,
class E,
class VM,
class EM>
2323 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const EdgeDescriptor& edge)
2325 return edgeProperties_[emap_[edge]];
2328 template<
class G,
class V,
class E,
class VM,
class EM>
2329 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const EdgeDescriptor& edge)
const
2331 return edgeProperties_[emap_[edge]];
2334 template<
class G,
class V,
class E,
class VM,
class EM>
2335 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const VertexDescriptor& source,
2336 const VertexDescriptor& target)
2338 return getEdgeProperties(graph_.findEdge(source,target));
2341 template<
class G,
class V,
class E,
class VM,
class EM>
2342 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const VertexDescriptor& source,
2343 const VertexDescriptor& target)
const
2345 return getEdgeProperties(graph_.findEdge(source,target));
2348 template<
class G,
class V,
class E,
class VM,
class EM>
2349 inline const G& PropertiesGraph<G,V,E,VM,EM>::graph()
const
2354 template<
class G,
class V,
class E,
class VM,
class EM>
2355 inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noVertices()
const
2357 return graph_.noVertices();
2361 template<
class G,
class V,
class E,
class VM,
class EM>
2362 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex()
const
2364 return graph_.maxVertex();
2367 template<
class G,
class V,
class E,
class VM,
class EM>
2368 PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph,
const VM& vmap,
const EM& emap)
2369 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V()),
2370 emap_(emap), edgeProperties_(graph_.noEdges(), E())
2373 template<
class G,
class V>
2377 typedef typename G::ConstEdgeIterator iterator;
2378 const iterator end = graph.endEdges(
vertex);
2380 for(iterator edge = graph.beginEdges(
vertex); edge != end; ++edge, ++noNeighbours)
2382 return noNeighbours;
Wrapper to access the internal vertex properties of a graph via operator[]()
Definition: graph.hh:1409
EdgeProperties & operator[](const Edge &edge) const
Get the properties associated to a vertex.
Definition: graph.hh:1442
G::EdgeProperties EdgeProperties
The type of the vertex properties.
Definition: graph.hh:1418
G::EdgeDescriptor Edge
The edge descriptor.
Definition: graph.hh:1422
GraphEdgePropertiesSelector()
Default constructor.
Definition: graph.hh:1434
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1414
GraphEdgePropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1428
Wrapper to access the internal edge properties of a graph via operator[]()
Definition: graph.hh:1361
GraphVertexPropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1380
VertexProperties & operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: graph.hh:1395
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1366
G::VertexProperties VertexProperties
The type of the vertex properties.
Definition: graph.hh:1370
GraphVertexPropertiesSelector()
Default constructor.
Definition: graph.hh:1386
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: graph.hh:1374
Iterator over all edges starting from a vertex.
Definition: graph.hh:95
EdgeIteratorT(const VertexDescriptor &source, const ColIterator &block, const ColIterator &end, const EdgeDescriptor &edge)
Constructor.
@ isMutable
whether C is mutable.
Definition: graph.hh:112
VertexDescriptor target() const
The index of the target vertex of the current edge.
EdgeIteratorT< C > & operator++()
preincrement operator.
bool operator!=(const EdgeIteratorT< const typename std::remove_const< C >::type > &other) const
Inequality operator.
bool operator==(const EdgeIteratorT< const typename std::remove_const< C >::type > &other) const
Equality operator.
EdgeIteratorT(const EdgeIteratorT< C1 > &other)
Copy Constructor.
bool operator!=(const EdgeIteratorT< typename std::remove_const< C >::type > &other) const
Inequality operator.
WeightType & weight() const
Access the edge weight.
VertexDescriptor source() const
The index of the source vertex of the current edge.
std::conditional< isMutable &&C::mutableMatrix, typenameMatrix::row_type::Iterator, typenameMatrix::row_type::ConstIterator >::type ColIterator
The column iterator of the matrix we use.
Definition: graph.hh:120
const std::remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:105
bool operator==(const EdgeIteratorT< typename std::remove_const< C >::type > &other) const
Equality operator.
EdgeIteratorT(const ColIterator &block)
Constructor for the end iterator.
std::conditional< isMutable &&C::mutableMatrix, typenameM::block_type, consttypenameM::block_type >::type Weight
The matrix block type we use as weights.
Definition: graph.hh:127
const EdgeDescriptor & operator*() const
Get the edge descriptor.
const EdgeDescriptor * operator->() const
Get the edge descriptor.
std::remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:101
The vertex iterator type of the graph.
Definition: graph.hh:209
EdgeIteratorT< C > begin() const
Get an iterator over all edges starting at the current vertex.
const VertexDescriptor & operator*() const
Get the descriptor of the current vertex.
WeightType & weight() const
Access the weight of the vertex.
VertexIteratorT(C *graph, const VertexDescriptor ¤t)
Constructor.
std::remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:214
@ isMutable
whether C is mutable.
Definition: graph.hh:225
bool operator!=(const VertexIteratorT< MutableContainer > &other) const
Inequality operator.
bool operator==(const VertexIteratorT< MutableContainer > &other) const
Equality operator.
const std::remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:218
VertexIteratorT< C > & operator++()
Move to the next vertex.
EdgeIteratorT< C > end() const
Get an iterator over all edges starting at the current vertex.
bool operator==(const VertexIteratorT< ConstContainer > &other) const
Equality operator.
bool operator!=(const VertexIteratorT< ConstContainer > &other) const
Inequality operator.
VertexIteratorT(const VertexDescriptor ¤t)
Constructor for the end iterator.
The (undirected) graph of a matrix.
Definition: graph.hh:51
MatrixGraph(Matrix &matrix)
Constructor.
VertexIterator end()
Get an iterator over the vertices.
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
M Matrix
The type of the matrix we are a graph for.
Definition: graph.hh:56
ConstVertexIterator begin() const
Get an iterator over the vertices.
VertexIteratorT< const MatrixGraph< Matrix > > ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:308
~MatrixGraph()
Destructor.
std::ptrdiff_t EdgeDescriptor
The edge descriptor.
Definition: graph.hh:80
ConstEdgeIterator endEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:73
const Matrix & matrix() const
Get the underlying matrix.
ConstEdgeIterator beginEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
ConstVertexIterator end() const
Get an iterator over the vertices.
EdgeIteratorT< const MatrixGraph< Matrix > > ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:298
EdgeIterator beginEdges(const VertexDescriptor &source)
Get an iterator over the edges starting at a vertex.
std::size_t noVertices() const
Get the number of vertices in the graph.
EdgeDescriptor findEdge(const VertexDescriptor &source, const VertexDescriptor &target) const
Find the descriptor of an edge.
M::block_type Weight
The type of the weights.
Definition: graph.hh:66
std::remove_const< M >::type MutableMatrix
The mutable type of the matrix we are a graph for.
Definition: graph.hh:61
EdgeIteratorT< MatrixGraph< Matrix > > EdgeIterator
The mutable edge iterator type.
Definition: graph.hh:303
VertexIteratorT< MatrixGraph< Matrix > > VertexIterator
The mutable vertex iterator type.
Definition: graph.hh:313
EdgeIterator endEdges(const VertexDescriptor &source)
Get an iterator over the edges starting at a vertex.
std::size_t noEdges() const
Get the number of edges in the graph.
Matrix & matrix()
Get the underlying matrix.
VertexIterator begin()
Get an iterator over the vertices.
Attaches properties to the edges and vertices of a graph.
Definition: graph.hh:978
EdgeIteratorT< PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > EdgeIterator
The type of the mutable edge iterator.
Definition: graph.hh:1096
std::size_t noVertices() const
Get the number of vertices in the graph.
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:993
const EdgeProperties & getEdgeProperties(const VertexDescriptor &source, const VertexDescriptor &target) const
Get the properties associated with a edge.
const EdgeProperties & getEdgeProperties(const EdgeDescriptor &edge) const
Get the properties associated with a edge.
const Graph & graph() const
Get the graph the properties are attached to.
EdgeIteratorT< const PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > ConstEdgeIterator
The type of the constant edge iterator.
Definition: graph.hh:1103
VertexIteratorT< PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > VertexIterator
The type of the mutable Vertex iterator.
Definition: graph.hh:1212
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
G Graph
The graph we attach properties to.
Definition: graph.hh:983
EM EdgeMap
The type of the map for converting the EdgeDescriptor to std::size_t.
Definition: graph.hh:1030
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:1011
VertexIteratorT< const PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > ConstVertexIterator
The type of the constant Vertex iterator.
Definition: graph.hh:1219
VP VertexProperties
The type of the properties of the vertices.
Definition: graph.hh:998
std::size_t noEdges() const
Get the number of edges in the graph.
EP EdgeProperties
The type of the properties of the edges;.
Definition: graph.hh:1016
EdgeProperties & getEdgeProperties(const VertexDescriptor &source, const VertexDescriptor &target)
Get the properties associated with a edge.
EdgeProperties & getEdgeProperties(const EdgeDescriptor &edge)
Get the properties associated with a edge.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:988
PropertiesGraph(Graph &graph, const VertexMap &vmap=VertexMap(), const EdgeMap &emap=EdgeMap())
Constructor.
An index map for mapping the edges to indices.
Definition: graph.hh:470
EdgeIndexMap(const EdgeIndexMap &emap)
Protect copy construction.
Definition: graph.hh:479
The edge iterator of the graph.
Definition: graph.hh:505
const EdgeDescriptor & dereference() const
The descriptor of the current edge.
EdgeIterator(const EdgeDescriptor &edge)
Constructor for the end iterator.
bool equals(const EdgeIterator &other) const
Equality operator.
EdgeIterator & increment()
Preincrement operator.
const VertexDescriptor & target() const
The index of the target vertex of the current edge.
const VertexDescriptor & source() const
The index of the source vertex of the current edge.
EdgeIterator & decrement()
Preincrement operator.
EdgeIterator(const VertexDescriptor &source, const EdgeDescriptor &edge)
Constructor.
The vertex iterator of the graph.
Definition: graph.hh:560
VertexIterator(const VertexDescriptor ¤t)
Constructor for end iterator.
VertexIterator & increment()
Preincrement operator.
EdgeIterator begin() const
Get an iterator over all edges starting at the current vertex.
bool equals(const VertexIterator &other) const
Equality iterator.
VertexIterator(const SubGraph< G, T > *graph, const VertexDescriptor ¤t, const VertexDescriptor &end)
Constructor.
EdgeIterator end() const
Get an iterator over all edges starting at the current vertex.
const VertexDescriptor & dereference() const
Get the descriptor of the current vertex.
A subgraph of a graph.
Definition: graph.hh:443
EdgeDescriptor findEdge(const VertexDescriptor &source, const VertexDescriptor &target) const
Find the descriptor of an edge.
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
EdgeIndexMap getEdgeIndexMap()
Get an edge index map for the graph.
std::size_t noEdges() const
Get the number of edges in the graph.
ConstEdgeIterator endEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
ConstVertexIterator end() const
Get an iterator over the vertices.
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.
T Excluded
Random access container providing information about which vertices are excluded.
Definition: graph.hh:454
EdgeIterator ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:618
G Graph
The type of the graph we are a sub graph for.
Definition: graph.hh:448
VertexIterator ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:623
SubGraph(const Graph &graph, const T &excluded)
Constructor.
ConstVertexIterator begin() const
Get an iterator over the vertices.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:459
Attaches properties to the vertices of a graph.
Definition: graph.hh:723
VertexIterator end()
Get an iterator over the vertices.
const Graph & graph() const
Get the graph the properties are attached to.
Graph::ConstEdgeIterator ConstEdgeIterator
The type of the constant edge iterator.
Definition: graph.hh:766
VertexProperties & getVertexProperties(const VertexDescriptor &vertex)
Get the properties associated with a vertex.
std::size_t noEdges() const
Get the number of edges in the graph.
VertexIteratorT< const VertexPropertiesGraph< Graph, VertexProperties, VM > > ConstVertexIterator
The type of the constant Vertex iterator.
Definition: graph.hh:889
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:738
ConstEdgeIterator endEdges(const VertexDescriptor &source) const
Get the mutable edge iterator over edges starting at a vertex.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:733
G Graph
The graph we attach properties to.
Definition: graph.hh:728
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:756
EdgeIterator endEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
EdgeIterator beginEdges(const VertexDescriptor &source)
Get the mutable edge iterator over edges starting at a vertex.
VP VertexProperties
The type of the properties of the vertices.
Definition: graph.hh:743
std::size_t noVertices() const
Get the number of vertices in the graph.
ConstEdgeIterator beginEdges(const VertexDescriptor &source) const
Get the mutable edge iterator over edges starting at a vertex.
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
VertexIteratorT< VertexPropertiesGraph< Graph, VertexProperties, VM > > VertexIterator
The type of the mutable Vertex iterator.
Definition: graph.hh:883
VertexIterator begin()
Get an iterator over the vertices.
Graph::EdgeIterator EdgeIterator
The type of the mutable edge iterator.
Definition: graph.hh:761
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:142
derive error class from the base class in common
Definition: istlexception.hh:19
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:435
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
int visitNeighbours(const G &graph, const typename G::VertexDescriptor &vertex, V &visitor)
Visit all neighbour vertices of a vertex in a graph.
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:13
Tag for the category of readable property maps.
Definition: propertymap.hh:38
Traits for type conversions and type information.