4#ifndef DUNE_AMG_GRAPH_HH
5#define DUNE_AMG_GRAPH_HH
14#include <dune/istl/istlexception.hh>
15#include <dune/common/propertymap.hh>
65 typedef typename M::block_type
Weight;
125 const typename M::block_type>::type
154 typename M::block_type,
const typename M::block_type>::type
264 typename M::block_type,
const typename M::block_type>::type
440 template<
class G,
class T>
474 : firstEdge_(firstEdge)
479 : firstEdge_(emap.firstEdge_)
482 std::size_t operator[](
const EdgeDescriptor& edge)
const
484 return edge-firstEdge_;
488 EdgeDescriptor firstEdge_;
542 std::ptrdiff_t distanceTo(
const EdgeIterator& other)
const;
551 EdgeDescriptor edge_;
695 std::size_t noVertices_;
708 std::ptrdiff_t* start_;
710 std::ptrdiff_t* end_;
720 template<
class G,
class VP,
class VM=IdentityMap>
797 class VertexIteratorT
798 :
public conditional<is_same<typename remove_const<C>::type,
800 typename Graph::VertexIterator,
801 typename Graph::ConstVertexIterator>::type
803 friend class VertexIteratorT<const typename
remove_const<C>::type>;
804 friend class VertexIteratorT<typename remove_const<C>::type>;
809 typedef typename
conditional<is_same<typename remove_const<C>::type,
811 typename Graph::VertexIterator,
812 typename Graph::ConstVertexIterator>::type
818 typedef typename
conditional<is_same<typename remove_const<C>::type,
820 typename Graph::EdgeIterator,
821 typename Graph::ConstEdgeIterator>::type
829 explicit VertexIteratorT(const Father& iter,
840 explicit VertexIteratorT(const Father& iter);
847 VertexIteratorT(const VertexIteratorT<C1>& other);
852 typename
conditional<is_same<C,typename remove_const<C>::type>::value,
854 const VertexProperties&>::type
881 typedef VertexIteratorT<VertexPropertiesGraph<Graph,
887 typedef VertexIteratorT<const VertexPropertiesGraph<Graph,
968 std::vector<VertexProperties> vertexProperties_;
975 template<
class G,
class VP,
class EP,
class VM=IdentityMap,
class EM=IdentityMap>
1033 :
public conditional<is_same<typename remove_const<C>::type,
1035 typename Graph::EdgeIterator,
1036 typename Graph::ConstEdgeIterator>::type
1039 friend class EdgeIteratorT<const typename
remove_const<C>::type>;
1040 friend class EdgeIteratorT<typename remove_const<C>::type>;
1045 typedef typename
conditional<is_same<typename remove_const<C>::type,
1047 typename Graph::EdgeIterator,
1048 typename Graph::ConstEdgeIterator>::type
1056 explicit EdgeIteratorT(const Father& iter,
1066 explicit EdgeIteratorT(const Father& iter);
1073 EdgeIteratorT(const EdgeIteratorT<C1>& other);
1078 typename
conditional<is_same<C,typename remove_const<C>::type>::value,
1080 const EdgeProperties&>::type
1093 typedef EdgeIteratorT<PropertiesGraph<Graph,
1100 typedef EdgeIteratorT<const PropertiesGraph<Graph,
1134 class VertexIteratorT
1135 :
public conditional<is_same<typename remove_const<C>::type,
1137 typename Graph::VertexIterator,
1138 typename Graph::ConstVertexIterator>::type
1140 friend class VertexIteratorT<const typename
remove_const<C>::type>;
1141 friend class VertexIteratorT<typename remove_const<C>::type>;
1146 typedef typename
conditional<is_same<typename remove_const<C>::type,
1148 typename Graph::VertexIterator,
1149 typename Graph::ConstVertexIterator>::type
1157 explicit VertexIteratorT(const Father& iter,
1168 explicit VertexIteratorT(const Father& iter);
1175 VertexIteratorT(const VertexIteratorT<C1>& other);
1180 typename
conditional<is_same<C,typename remove_const<C>::type>::value,
1182 const VertexProperties&>::type
1190 EdgeIteratorT<C>
begin() const;
1197 EdgeIteratorT<C>
end() const;
1209 typedef VertexIteratorT<PropertiesGraph<Graph,
1216 typedef VertexIteratorT<const PropertiesGraph<Graph,
1265 const VertexDescriptor& target)
1267 return graph_.findEdge(source,target);
1345 std::vector<VertexProperties> vertexProperties_;
1349 std::vector<EdgeProperties> edgeProperties_;
1358 template<
typename G>
1396 return graph_->getVertexProperties(vertex);
1406 template<
typename G>
1421 typedef typename G::EdgeDescriptor
Edge;
1443 return graph_->getEdgeProperties(edge);
1460 template<
class G,
class V>
1470 if(matrix_.N()!=matrix_.M())
1473 start_ =
new EdgeDescriptor[matrix_.N()+1];
1475 typedef typename M::ConstIterator Iterator;
1476 Iterator row = matrix_.begin();
1477 start_[row.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())
1514 return std::numeric_limits<EdgeDescriptor>::max();
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>
1811 inline bool SubGraph<G,T>::EdgeIterator::equals(
const EdgeIterator & other)
const
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>
1895 inline bool SubGraph<G,T>::VertexIterator::equals(
const VertexIterator & other)
const
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 const 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)
1968 return std::numeric_limits<EdgeDescriptor>::max();
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_;
1991 typedef typename Graph::ConstVertexIterator Iterator;
1992 Iterator endVertex=graph.end();
1994 for(Iterator vertex = graph.begin(); vertex != endVertex; ++vertex)
1995 if(excluded_[*vertex])
1996 start_[*vertex]=end_[*vertex]=-1;
1999 endVertex_ = std::max(*vertex, endVertex_);
2001 start_[*vertex] = edge-edges_;
2003 typedef typename Graph::ConstEdgeIterator Iterator;
2004 Iterator endEdge = vertex.end();
2006 for(Iterator iter=vertex.begin(); iter!= endEdge; ++iter)
2007 if(!excluded[iter.target()]) {
2008 *edge = iter.target();
2012 end_[*vertex] = edge - edges_;
2015 std::sort(edges_+start_[*vertex], edge);
2017 noEdges_ = edge-edges_;
2021 template<
class G,
class V,
class VM>
2022 inline std::size_t VertexPropertiesGraph<G,V,VM>::noEdges()
const
2024 return graph_.noEdges();
2027 template<
class G,
class V,
class VM>
2028 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2029 VertexPropertiesGraph<G,V,VM>::beginEdges(
const VertexDescriptor& source)
2031 return graph_.beginEdges(source);
2034 template<
class G,
class V,
class VM>
2035 inline typename VertexPropertiesGraph<G,V,VM>::EdgeIterator
2036 VertexPropertiesGraph<G,V,VM>::endEdges(
const VertexDescriptor& source)
2038 return graph_.endEdges(source);
2041 template<
class G,
class V,
class VM>
2042 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2043 inline VertexPropertiesGraph<G,V,VM>::beginEdges(
const VertexDescriptor& source)
const
2045 return graph_.beginEdges(source);
2048 template<
class G,
class V,
class VM>
2049 typename VertexPropertiesGraph<G,V,VM>::ConstEdgeIterator
2050 VertexPropertiesGraph<G,V,VM>::endEdges(
const VertexDescriptor& source)
const
2052 return graph_.endEdges(source);
2055 template<
class G,
class V,
class VM>
2057 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2058 ::VertexIteratorT(
const Father& iter,
2060 : Father(iter), graph_(graph)
2063 template<
class G,
class V,
class VM>
2065 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2066 ::VertexIteratorT(
const Father& iter)
2070 template<
class G,
class V,
class VM>
2073 VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>
2074 ::VertexIteratorT(
const VertexIteratorT<C1>& other)
2075 : Father(other), graph_(other.graph_)
2078 template<
class G,
class V,
class VM>
2082 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::properties()
const
2084 return graph_->getVertexProperties(Father::operator*());
2087 template<
class G,
class V,
class VM>
2091 typename G::EdgeIterator,
2092 typename G::ConstEdgeIterator>::type
2093 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::begin()
const
2095 return graph_->beginEdges(Father::operator*());
2098 template<
class G,
class V,
class VM>
2102 typename G::EdgeIterator,
2103 typename G::ConstEdgeIterator>::type
2104 inline VertexPropertiesGraph<G,V,VM>::VertexIteratorT<C>::end()
const
2106 return graph_->endEdges(Father::operator*());
2109 template<
class G,
class V,
class VM>
2110 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::begin()
2112 return VertexIterator(graph_.begin(),
this);
2115 template<
class G,
class V,
class VM>
2116 inline typename VertexPropertiesGraph<G,V,VM>::VertexIterator VertexPropertiesGraph<G,V,VM>::end()
2118 return VertexIterator(graph_.end());
2122 template<
class G,
class V,
class VM>
2123 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::begin()
const
2125 return ConstVertexIterator(graph_.begin(),
this);
2128 template<
class G,
class V,
class VM>
2129 inline typename VertexPropertiesGraph<G,V,VM>::ConstVertexIterator VertexPropertiesGraph<G,V,VM>::end()
const
2131 return ConstVertexIterator(graph_.end());
2134 template<
class G,
class V,
class VM>
2135 inline V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(
const VertexDescriptor& vertex)
2137 return vertexProperties_[vmap_[vertex]];
2140 template<
class G,
class V,
class VM>
2141 inline const V& VertexPropertiesGraph<G,V,VM>::getVertexProperties(
const VertexDescriptor& vertex)
const
2143 return vertexProperties_[vmap_[vertex]];
2146 template<
class G,
class V,
class VM>
2147 inline const G& VertexPropertiesGraph<G,V,VM>::graph()
const
2152 template<
class G,
class V,
class VM>
2153 inline std::size_t VertexPropertiesGraph<G,V,VM>::noVertices()
const
2155 return graph_.noVertices();
2159 template<
class G,
class V,
class VM>
2160 inline typename VertexPropertiesGraph<G,V,VM>::VertexDescriptor VertexPropertiesGraph<G,V,VM>::maxVertex()
const
2162 return graph_.maxVertex();
2165 template<
class G,
class V,
class VM>
2166 VertexPropertiesGraph<G,V,VM>::VertexPropertiesGraph(Graph& graph,
const VM vmap)
2167 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V())
2170 template<
class G,
class V,
class E,
class VM,
class EM>
2172 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const Father& iter,
2174 : Father(iter), graph_(graph)
2177 template<
class G,
class V,
class E,
class VM,
class EM>
2179 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const Father& iter)
2183 template<
class G,
class V,
class E,
class VM,
class EM>
2186 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::EdgeIteratorT(
const EdgeIteratorT<C1>& other)
2187 : Father(other), graph_(other.graph_)
2191 template<
class G,
class V,
class E,
class VM,
class EM>
2192 inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noEdges()
const
2194 return graph_.noEdges();
2197 template<
class G,
class V,
class E,
class VM,
class EM>
2200 PropertiesGraph<G,V,E,VM,EM>::EdgeIteratorT<C>::properties()
const
2202 return graph_->getEdgeProperties(Father::operator*());
2205 template<
class G,
class V,
class E,
class VM,
class EM>
2206 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2207 PropertiesGraph<G,V,E,VM,EM>::beginEdges(
const VertexDescriptor& source)
2209 return EdgeIterator(graph_.beginEdges(source),
this);
2212 template<
class G,
class V,
class E,
class VM,
class EM>
2213 inline typename PropertiesGraph<G,V,E,VM,EM>::EdgeIterator
2214 PropertiesGraph<G,V,E,VM,EM>::endEdges(
const VertexDescriptor& source)
2216 return EdgeIterator(graph_.endEdges(source));
2219 template<
class G,
class V,
class E,
class VM,
class EM>
2220 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2221 inline PropertiesGraph<G,V,E,VM,EM>::beginEdges(
const VertexDescriptor& source)
const
2223 return ConstEdgeIterator(graph_.beginEdges(source),
this);
2226 template<
class G,
class V,
class E,
class VM,
class EM>
2227 typename PropertiesGraph<G,V,E,VM,EM>::ConstEdgeIterator
2228 PropertiesGraph<G,V,E,VM,EM>::endEdges(
const VertexDescriptor& source)
const
2230 return ConstEdgeIterator(graph_.endEdges(source));
2233 template<
class G,
class V,
class E,
class VM,
class EM>
2235 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2236 ::VertexIteratorT(
const Father& iter,
2238 : Father(iter), graph_(graph)
2241 template<
class G,
class V,
class E,
class VM,
class EM>
2243 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2244 ::VertexIteratorT(
const Father& iter)
2248 template<
class G,
class V,
class E,
class VM,
class EM>
2251 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>
2252 ::VertexIteratorT(
const VertexIteratorT<C1>& other)
2253 : Father(other), graph_(other.graph_)
2256 template<
class G,
class V,
class E,
class VM,
class EM>
2260 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::properties()
const
2262 return graph_->getVertexProperties(Father::operator*());
2265 template<
class G,
class V,
class E,
class VM,
class EM>
2267 inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2268 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::begin()
const
2270 return graph_->beginEdges(Father::operator*());
2273 template<
class G,
class V,
class E,
class VM,
class EM>
2275 inline typename PropertiesGraph<G,V,E,VM,EM>::template EdgeIteratorT<C>
2276 PropertiesGraph<G,V,E,VM,EM>::VertexIteratorT<C>::end()
const
2278 return graph_->endEdges(Father::operator*());
2281 template<
class G,
class V,
class E,
class VM,
class EM>
2282 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
2284 return VertexIterator(graph_.begin(),
this);
2287 template<
class G,
class V,
class E,
class VM,
class EM>
2288 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
2290 return VertexIterator(graph_.end());
2294 template<
class G,
class V,
class E,
class VM,
class EM>
2295 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::begin()
const
2297 return ConstVertexIterator(graph_.begin(),
this);
2300 template<
class G,
class V,
class E,
class VM,
class EM>
2301 inline typename PropertiesGraph<G,V,E,VM,EM>::ConstVertexIterator PropertiesGraph<G,V,E,VM,EM>::end()
const
2303 return ConstVertexIterator(graph_.end());
2306 template<
class G,
class V,
class E,
class VM,
class EM>
2307 inline V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(
const VertexDescriptor& vertex)
2309 return vertexProperties_[vmap_[vertex]];
2312 template<
class G,
class V,
class E,
class VM,
class EM>
2313 inline const V& PropertiesGraph<G,V,E,VM,EM>::getVertexProperties(
const VertexDescriptor& vertex)
const
2315 return vertexProperties_[vmap_[vertex]];
2318 template<
class G,
class V,
class E,
class VM,
class EM>
2319 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const EdgeDescriptor& edge)
2321 return edgeProperties_[emap_[edge]];
2324 template<
class G,
class V,
class E,
class VM,
class EM>
2325 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const EdgeDescriptor& edge)
const
2327 return edgeProperties_[emap_[edge]];
2330 template<
class G,
class V,
class E,
class VM,
class EM>
2331 inline E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const VertexDescriptor& source,
2332 const VertexDescriptor& target)
2334 return getEdgeProperties(graph_.findEdge(source,target));
2337 template<
class G,
class V,
class E,
class VM,
class EM>
2338 inline const E& PropertiesGraph<G,V,E,VM,EM>::getEdgeProperties(
const VertexDescriptor& source,
2339 const VertexDescriptor& target)
const
2341 return getEdgeProperties(graph_.findEdge(source,target));
2344 template<
class G,
class V,
class E,
class VM,
class EM>
2345 inline const G& PropertiesGraph<G,V,E,VM,EM>::graph()
const
2350 template<
class G,
class V,
class E,
class VM,
class EM>
2351 inline std::size_t PropertiesGraph<G,V,E,VM,EM>::noVertices()
const
2353 return graph_.noVertices();
2357 template<
class G,
class V,
class E,
class VM,
class EM>
2358 inline typename PropertiesGraph<G,V,E,VM,EM>::VertexDescriptor PropertiesGraph<G,V,E,VM,EM>::maxVertex()
const
2360 return graph_.maxVertex();
2363 template<
class G,
class V,
class E,
class VM,
class EM>
2364 PropertiesGraph<G,V,E,VM,EM>::PropertiesGraph(Graph& graph,
const VM& vmap,
const EM& emap)
2365 : graph_(graph), vmap_(vmap), vertexProperties_(vmap_[graph_.maxVertex()+1], V()),
2366 emap_(emap), edgeProperties_(graph_.noEdges(), E())
2369 template<
class G,
class V>
2370 inline int visitNeighbours(
const G& graph,
const typename G::VertexDescriptor& vertex,
2373 typedef typename G::ConstEdgeIterator iterator;
2374 const iterator end = graph.endEdges(vertex);
2376 for(iterator edge = graph.beginEdges(vertex); edge != end; ++edge, ++noNeighbours)
2378 return noNeighbours;
Wrapper to access the internal vertex properties of a graph via operator[]()
Definition: graph.hh:1408
EdgeProperties & operator[](const Edge &edge) const
Get the properties associated to a vertex.
Definition: graph.hh:1441
G::EdgeProperties EdgeProperties
The type of the vertex properties.
Definition: graph.hh:1417
G::EdgeDescriptor Edge
The edge descriptor.
Definition: graph.hh:1421
GraphEdgePropertiesSelector()
Default constructor.
Definition: graph.hh:1433
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1413
GraphEdgePropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1427
Wrapper to access the internal edge properties of a graph via operator[]()
Definition: graph.hh:1360
GraphVertexPropertiesSelector(G &g)
Constructor.
Definition: graph.hh:1379
VertexProperties & operator[](const Vertex &vertex) const
Get the properties associated to a vertex.
Definition: graph.hh:1394
G Graph
The type of the graph with internal properties.
Definition: graph.hh:1365
G::VertexProperties VertexProperties
The type of the vertex properties.
Definition: graph.hh:1369
GraphVertexPropertiesSelector()
Default constructor.
Definition: graph.hh:1385
G::VertexDescriptor Vertex
The vertex descriptor.
Definition: graph.hh:1373
Iterator over all edges starting from a vertex.
Definition: graph.hh:94
EdgeIteratorT(const VertexDescriptor &source, const ColIterator &block, const ColIterator &end, const EdgeDescriptor &edge)
Constructor.
bool operator!=(const EdgeIteratorT< typename remove_const< C >::type > &other) const
Inequality operator.
VertexDescriptor target() const
The index of the target vertex of the current edge.
EdgeIteratorT< C > & operator++()
preincrement operator.
const remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:104
@ isMutable
whether C is mutable.
Definition: graph.hh:111
remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:100
conditional< isMutable &&C::mutableMatrix, typenameM::block_type, consttypenameM::block_type >::type Weight
The matrix block type we use as weights.
Definition: graph.hh:126
EdgeIteratorT(const EdgeIteratorT< C1 > &other)
Copy Constructor.
bool operator==(const EdgeIteratorT< const typename remove_const< C >::type > &other) const
Equality operator.
WeightType & weight() const
Access the edge weight.
VertexDescriptor source() const
The index of the source vertex of the current edge.
EdgeIteratorT(const ColIterator &block)
Constructor for the end iterator.
bool operator!=(const EdgeIteratorT< const typename remove_const< C >::type > &other) const
Inequality operator.
const EdgeDescriptor & operator*() const
Get the edge descriptor.
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:119
const EdgeDescriptor * operator->() const
Get the edge descriptor.
bool operator==(const EdgeIteratorT< typename remove_const< C >::type > &other) const
Equality operator.
The vertex iterator type of the graph.
Definition: graph.hh:208
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.
@ isMutable
whether C is mutable.
Definition: graph.hh:224
VertexIteratorT(C *graph, const VertexDescriptor ¤t)
Constructor.
remove_const< C >::type MutableContainer
The mutable type of the container type.
Definition: graph.hh:213
bool operator!=(const VertexIteratorT< MutableContainer > &other) const
Inequality operator.
bool operator==(const VertexIteratorT< MutableContainer > &other) const
Equality operator.
VertexIteratorT< C > & operator++()
Move to the next vertex.
EdgeIteratorT< C > end() const
Get an iterator over all edges starting at the current vertex.
const remove_const< C >::type ConstContainer
The constant type of the container type.
Definition: graph.hh:217
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:50
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:55
ConstVertexIterator begin() const
Get an iterator over the vertices.
VertexIteratorT< const MatrixGraph< Matrix > > ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:307
~MatrixGraph()
Destructor.
std::ptrdiff_t EdgeDescriptor
The edge descriptor.
Definition: graph.hh:79
ConstEdgeIterator endEdges(const VertexDescriptor &source) const
Get an iterator over the edges starting at a vertex.
remove_const< M >::type MutableMatrix
The mutable type of the matrix we are a graph for.
Definition: graph.hh:60
M::size_type VertexDescriptor
The vertex descriptor.
Definition: graph.hh:72
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:297
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:65
EdgeIteratorT< MatrixGraph< Matrix > > EdgeIterator
The mutable edge iterator type.
Definition: graph.hh:302
VertexIteratorT< MatrixGraph< Matrix > > VertexIterator
The mutable vertex iterator type.
Definition: graph.hh:312
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:977
EdgeIteratorT< PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > EdgeIterator
The type of the mutable edge iterator.
Definition: graph.hh:1095
std::size_t noVertices() const
Get the number of vertices in the graph.
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:992
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:1102
VertexIteratorT< PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > VertexIterator
The type of the mutable Vertex iterator.
Definition: graph.hh:1211
VertexDescriptor maxVertex() const
Get the maximal vertex descriptor.
G Graph
The graph we attach properties to.
Definition: graph.hh:982
EM EdgeMap
The type of the map for converting the EdgeDescriptor to std::size_t.
Definition: graph.hh:1029
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:1010
VertexIteratorT< const PropertiesGraph< Graph, VertexProperties, EdgeProperties, VM, EM > > ConstVertexIterator
The type of the constant Vertex iterator.
Definition: graph.hh:1218
VP VertexProperties
The type of the properties of the vertices.
Definition: graph.hh:997
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:1015
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:987
PropertiesGraph(Graph &graph, const VertexMap &vmap=VertexMap(), const EdgeMap &emap=EdgeMap())
Constructor.
An index map for mapping the edges to indices.
Definition: graph.hh:469
EdgeIndexMap(const EdgeIndexMap &emap)
Protect copy construction.
Definition: graph.hh:478
The edge iterator of the graph.
Definition: graph.hh:504
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:559
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:442
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:453
EdgeIterator ConstEdgeIterator
The constant edge iterator type.
Definition: graph.hh:617
G Graph
The type of the graph we are a sub graph for.
Definition: graph.hh:447
VertexIterator ConstVertexIterator
The constant vertex iterator type.
Definition: graph.hh:622
SubGraph(const Graph &graph, const T &excluded)
Constructor.
ConstVertexIterator begin() const
Get an iterator over the vertices.
const EdgeDescriptor findEdge(const VertexDescriptor &source, const VertexDescriptor &target) const
Find the descriptor of an edge.
Graph::VertexDescriptor VertexDescriptor
The vertex descriptor.
Definition: graph.hh:458
Attaches properties to the vertices of a graph.
Definition: graph.hh:722
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:765
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:888
Graph::EdgeDescriptor EdgeDescriptor
The edge descritor.
Definition: graph.hh:737
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:732
G Graph
The graph we attach properties to.
Definition: graph.hh:727
VM VertexMap
The type of the map for converting the VertexDescriptor to std::size_t.
Definition: graph.hh:755
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:742
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:882
VertexIterator begin()
Get an iterator over the vertices.
Graph::EdgeIterator EdgeIterator
The type of the mutable edge iterator.
Definition: graph.hh:760
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:609
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:142
derive error class from the base class in common
Definition: istlexception.hh:16
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:431
Iterator implementation class
Definition: basearray.hh:80
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
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:231
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:253
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignment.hh:14
Tag for the category of readable property maps.
Definition: propertymap.hh:39
Select a type based on a condition.
Definition: typetraits.hh:419
T1 type
The selected type.
Definition: typetraits.hh:426
Generate a type for a given integral constant.
Definition: typetraits.hh:457
Compile time test for testing whether two types are the same.
Definition: typetraits.hh:360
Removes a const qualifier while preserving others.
Definition: typetraits.hh:176
Traits for type conversions and type information.