1 // (c) Copyright Juergen Hunold 2012
2 // Use, modification and distribution is subject to the Boost Software
3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/graph/adjacency_list.hpp>
7 #include <boost/graph/dijkstra_shortest_paths.hpp>
8 #include <boost/graph/filtered_graph.hpp>
18 BOOST_INSTALL_PROPERTY(edge
, info
);
21 template < typename EdgeInfo
, typename Directed
> class Graph
24 typedef boost::property
< boost::edge_info_t
, EdgeInfo
> tEdge_property
;
26 typedef boost::adjacency_list
< boost::setS
, boost::vecS
, Directed
,
27 boost::no_property
, tEdge_property
>
30 typedef typename
boost::graph_traits
< tGraph
>::vertex_descriptor tNode
;
31 typedef typename
boost::graph_traits
< tGraph
>::edge_descriptor tEdge
;
39 class UndirectedGraph
: public Graph
< DataEdge
*, boost::undirectedS
>
42 template < class Evaluator
, class Filter
>
43 void dijkstra(Evaluator
const&, Filter
const&) const;
46 template < typename Graph
, typename Derived
>
47 struct Evaluator
: public boost::put_get_helper
< int, Derived
>
49 typedef int value_type
;
50 typedef typename
Graph::tEdge key_type
;
51 typedef int reference
;
52 typedef boost::readable_property_map_tag category
;
54 explicit Evaluator(Graph
const* pGraph
);
57 template < typename Graph
>
58 struct LengthEvaluator
: public Evaluator
< Graph
, LengthEvaluator
< Graph
> >
60 explicit LengthEvaluator(Graph
const* pGraph
);
62 typedef typename Evaluator
< Graph
, LengthEvaluator
< Graph
> >::reference
64 typedef typename Evaluator
< Graph
, LengthEvaluator
< Graph
> >::key_type
67 virtual reference
operator[](key_type
const& edge
) const;
70 template < class Graph
> struct EdgeFilter
72 typedef typename
Graph::tEdge key_type
;
76 explicit EdgeFilter(Graph
const*);
78 bool operator()(key_type
const&) const;
81 const Graph
* m_pGraph
;
84 template < class Evaluator
, class Filter
>
85 void UndirectedGraph::dijkstra(
86 Evaluator
const& rEvaluator
, Filter
const& rFilter
) const
88 tNode nodeSource
= vertex(0, m_Graph
);
90 std::vector
< tNode
> predecessors(num_vertices(m_Graph
));
92 boost::filtered_graph
< tGraph
, Filter
> filteredGraph(m_Graph
, rFilter
);
94 boost::dijkstra_shortest_paths(filteredGraph
, nodeSource
,
95 boost::predecessor_map(&predecessors
[0]).weight_map(rEvaluator
));
98 // explicit instantiation
99 template void UndirectedGraph::dijkstra(
100 LengthEvaluator
< UndirectedGraph
> const&,
101 EdgeFilter
< UndirectedGraph
> const&) const;
103 int main(int, char**)
106 } // Tests above will fail to compile if anything is broken