Changed to new-style named parameters for A* code; added named parameters for astar_search_no_init()

[SVN r64024]
This commit is contained in:
Jeremiah Willcock 2010-07-14 22:15:48 +00:00
parent 724773b517
commit c44888396b
3 changed files with 108 additions and 89 deletions

View File

@ -22,7 +22,7 @@
<P> <P>
<PRE> <PRE>
<i>// Named parameter interface</i> <i>// Named parameter interfaces</i>
template &lt;typename VertexListGraph, template &lt;typename VertexListGraph,
typename AStarHeuristic, typename AStarHeuristic,
typename P, typename T, typename R&gt; typename P, typename T, typename R&gt;
@ -32,6 +32,15 @@ astar_search
typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s, typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
<a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params); <a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
template &lt;typename VertexListGraph,
typename AStarHeuristic,
typename P, typename T, typename R&gt;
void
astar_search_no_init
(const VertexListGraph &amp;g,
typename graph_traits&lt;VertexListGraph&gt;::vertex_descriptor s,
<a href="AStarHeuristic.html">AStarHeuristic</a> h, const bgl_named_params&lt;P, T, R&gt;&amp; params);
<i>// Non-named parameter interface</i> <i>// Non-named parameter interface</i>
template &lt;typename VertexListGraph, typename AStarHeuristic, template &lt;typename VertexListGraph, typename AStarHeuristic,
typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap, typename <a href="AStarVisitor.html">AStarVisitor</a>, typename PredecessorMap,
@ -71,7 +80,8 @@ astar_search_no_init
CostInf inf, CostZero zero); CostInf inf, CostZero zero);
<b>Note that the index_map and color parameters are swapped in <b>Note that the index_map and color parameters are swapped in
astar_search_no_init relative to astar_search.</b> astar_search_no_init() relative to astar_search(); the named parameter
interfaces are not affected.</b>
</PRE> </PRE>
<P> <P>
@ -110,7 +120,7 @@ A* is particularly useful for searching <i>implicit</i> graphs.
Implicit graphs are graphs that are not completely known at the Implicit graphs are graphs that are not completely known at the
beginning of the search. Upon visiting a vertex, its neighbors are beginning of the search. Upon visiting a vertex, its neighbors are
"generated" and added to the search. Implicit graphs are particularly "generated" and added to the search. Implicit graphs are particularly
useful for searching large state spaces -- in gameplaying scenarios useful for searching large state spaces -- in game-playing scenarios
(e.g. chess), for example -- in which it may not be possible to store (e.g. chess), for example -- in which it may not be possible to store
the entire graph. Implicit searches can be performed with this the entire graph. Implicit searches can be performed with this
implementation of A* by creating special visitors that generate implementation of A* by creating special visitors that generate
@ -293,7 +303,7 @@ IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
<b>Default:</b> <tt>get(vertex_index, g)</tt>. <b>Default:</b> <tt>get(vertex_index, g)</tt>.
Note: if you use this default, make sure your graph has Note: if you use this default, make sure your graph has
an internal <tt>vertex_index</tt> property. For example, an internal <tt>vertex_index</tt> property. For example,
<tt>adjacenty_list</tt> with <tt>VertexList=listS</tt> does <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
not have an internal <tt>vertex_index</tt> property. not have an internal <tt>vertex_index</tt> property.
</blockquote> </blockquote>
@ -330,8 +340,8 @@ UTIL/OUT: <tt>distance_map(DistanceMap d_map)</tt>
href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html"><tt>StrictWeakOrdering</tt></a> href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html"><tt>StrictWeakOrdering</tt></a>
provided by the <tt>compare</tt> function object.<br> provided by the <tt>compare</tt> function object.<br>
<b>Default:</b> <tt>iterator_property_map</tt> created from a <b>Default:</b> <tt>shared_array_property_map</tt>
<tt>std::vector</tt> with the same value type as the with the same value type as the
<tt>WeightMap</tt>, and of size <tt>num_vertices(g)</tt>, and using <tt>WeightMap</tt>, and of size <tt>num_vertices(g)</tt>, and using
the <tt>i_map</tt> for the index map. the <tt>i_map</tt> for the index map.
</blockquote> </blockquote>
@ -356,9 +366,9 @@ UTIL/OUT: <tt>rank_map(CostMap c_map)</tt>
for this map must be the same as the value type for the distance for this map must be the same as the value type for the distance
map.<br> map.<br>
<b>Default:</b> <tt>iterator_property_map</tt> created from a <b>Default:</b> <tt>shared_array_property_map</tt>
<tt>std::vector</tt> with the same value type as the with the same value type as the
<tt>WeightMap</tt>, and of size <tt>num_vertices(g)</tt>, and using <tt>DistanceMap</tt>, and of size <tt>num_vertices(g)</tt>, and using
the <tt>i_map</tt> for the index map. the <tt>i_map</tt> for the index map.
</blockquote> </blockquote>
@ -378,10 +388,10 @@ UTIL/OUT: <tt>color_map(ColorMap c_map)</tt>
key type of the map, and the value type of the map must be a model key type of the map, and the value type of the map must be a model
of <a href="./ColorValue.html"><tt>Color Value</tt></a>.<br> of <a href="./ColorValue.html"><tt>Color Value</tt></a>.<br>
<b>Default:</b> <tt>iterator_property_map</tt> created from a <b>Default:</b> <tt>shared_array_property_map</tt>
<tt>std::vector</tt> of value type <tt>default_color_type</tt>, with of value type <tt>default_color_type</tt>, with size
size <tt>num_vertices(g)</tt>, and using the <tt>i_map</tt> for the <tt>num_vertices(g)</tt>, and using
index map. the <tt>i_map</tt> for the index map.
</blockquote> </blockquote>
IN: <tt>distance_compare(CompareFunction cmp)</tt> IN: <tt>distance_compare(CompareFunction cmp)</tt>

View File

@ -300,63 +300,7 @@ namespace boost {
} }
// Named parameter interfaces
namespace detail {
template <class VertexListGraph, class AStarHeuristic,
class CostMap, class DistanceMap, class WeightMap,
class IndexMap, class ColorMap, class Params>
inline void
astar_dispatch2
(const VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
AStarHeuristic h, CostMap cost, DistanceMap distance,
WeightMap weight, IndexMap index_map, ColorMap color,
const Params& params)
{
dummy_property_map p_map;
typedef typename property_traits<CostMap>::value_type C;
astar_search
(g, s, h,
choose_param(get_param(params, graph_visitor),
make_astar_visitor(null_visitor())),
choose_param(get_param(params, vertex_predecessor), p_map),
cost, distance, weight, index_map, color,
choose_param(get_param(params, distance_compare_t()),
std::less<C>()),
choose_param(get_param(params, distance_combine_t()),
closed_plus<C>()),
choose_param(get_param(params, distance_inf_t()),
std::numeric_limits<C>::max BOOST_PREVENT_MACRO_SUBSTITUTION ()),
choose_param(get_param(params, distance_zero_t()),
C()));
}
template <class VertexListGraph, class AStarHeuristic,
class CostMap, class DistanceMap, class WeightMap,
class IndexMap, class ColorMap, class Params>
inline void
astar_dispatch1
(const VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
AStarHeuristic h, CostMap cost, DistanceMap distance,
WeightMap weight, IndexMap index_map, ColorMap color,
const Params& params)
{
typedef typename property_traits<WeightMap>::value_type D;
detail::astar_dispatch2
(g, s, h,
choose_param(cost, vector_property_map<D, IndexMap>(index_map)),
choose_param(distance, vector_property_map<D, IndexMap>(index_map)),
weight, index_map,
choose_param(color, vector_property_map<default_color_type, IndexMap>(index_map)),
params);
}
} // namespace detail
// Named parameter interface
template <typename VertexListGraph, template <typename VertexListGraph,
typename AStarHeuristic, typename AStarHeuristic,
typename P, typename T, typename R> typename P, typename T, typename R>
@ -366,16 +310,67 @@ namespace boost {
typename graph_traits<VertexListGraph>::vertex_descriptor s, typename graph_traits<VertexListGraph>::vertex_descriptor s,
AStarHeuristic h, const bgl_named_params<P, T, R>& params) AStarHeuristic h, const bgl_named_params<P, T, R>& params)
{ {
using namespace boost::graph::keywords;
typedef bgl_named_params<P, T, R> params_type;
BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
detail::astar_dispatch1 // Distance type is the value type of the distance map if there is one,
// otherwise the value type of the weight map.
typedef
typename detail::override_const_property_result<
arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
weight_map_type;
typedef typename boost::property_traits<weight_map_type>::value_type W;
typedef
typename detail::map_maker<VertexListGraph, arg_pack_type, tag::distance_map, W>::map_type
distance_map_type;
typedef typename boost::property_traits<distance_map_type>::value_type D;
astar_search
(g, s, h, (g, s, h,
get_param(params, vertex_rank), arg_pack[_visitor | make_astar_visitor(null_visitor())],
get_param(params, vertex_distance), arg_pack[_predecessor_map | dummy_property_map()],
choose_const_pmap(get_param(params, edge_weight), g, edge_weight), detail::make_property_map_from_arg_pack_gen<tag::rank_map, D>(D())(g, arg_pack),
choose_const_pmap(get_param(params, vertex_index), g, vertex_index), detail::make_property_map_from_arg_pack_gen<tag::distance_map, W>(W())(g, arg_pack),
get_param(params, vertex_color), override_const_property(arg_pack, _weight_map, g, edge_weight),
params); override_const_property(arg_pack, _vertex_index_map, g, vertex_index),
detail::make_color_map_from_arg_pack(g, arg_pack),
arg_pack[_distance_compare | std::less<D>()],
arg_pack[_distance_combine | closed_plus<D>()],
arg_pack[_distance_inf | (std::numeric_limits<D>::max)()],
arg_pack[_distance_zero | D()]);
}
template <typename VertexListGraph,
typename AStarHeuristic,
typename P, typename T, typename R>
void
astar_search_no_init
(const VertexListGraph &g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
AStarHeuristic h, const bgl_named_params<P, T, R>& params)
{
using namespace boost::graph::keywords;
typedef bgl_named_params<P, T, R> params_type;
BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
typedef
typename detail::override_const_property_result<
arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
weight_map_type;
typedef typename boost::property_traits<weight_map_type>::value_type D;
astar_search_no_init
(g, s, h,
arg_pack[_visitor | make_astar_visitor(null_visitor())],
arg_pack[_predecessor_map | dummy_property_map()],
detail::make_property_map_from_arg_pack_gen<tag::rank_map, D>(D())(g, arg_pack),
detail::make_property_map_from_arg_pack_gen<tag::distance_map, D>(D())(g, arg_pack),
override_const_property(arg_pack, _weight_map, g, edge_weight),
override_const_property(arg_pack, _vertex_index_map, g, vertex_index),
detail::make_color_map_from_arg_pack(g, arg_pack),
arg_pack[_distance_compare | std::less<D>()],
arg_pack[_distance_combine | closed_plus<D>()],
arg_pack[_distance_inf | (std::numeric_limits<D>::max)()],
arg_pack[_distance_zero | D()]);
} }
} // namespace boost } // namespace boost

View File

@ -393,12 +393,19 @@ BOOST_BGL_DECLARE_NAMED_PARAMS
}; };
template <typename ArgPack, typename Tag, typename Prop, typename Graph> template <typename ArgPack, typename Tag, typename Prop, typename Graph>
typename override_const_property_t< struct override_const_property_result {
typename boost::parameter::value_type<ArgPack, Tag, int>::type, typedef
Prop, typename override_const_property_t<
Graph, typename boost::parameter::value_type<ArgPack, Tag, int>::type,
boost::detail::parameter_exists<ArgPack, Tag>::value Prop,
>::result_type Graph,
boost::detail::parameter_exists<ArgPack, Tag>::value
>::result_type
type;
};
template <typename ArgPack, typename Tag, typename Prop, typename Graph>
typename override_const_property_result<ArgPack, Tag, Prop, Graph>::type
override_const_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop) { override_const_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop) {
return override_const_property_t< return override_const_property_t<
typename boost::parameter::value_type<ArgPack, Tag, int>::type, typename boost::parameter::value_type<ArgPack, Tag, int>::type,
@ -421,12 +428,19 @@ BOOST_BGL_DECLARE_NAMED_PARAMS
}; };
template <typename ArgPack, typename Tag, typename Prop, typename Graph> template <typename ArgPack, typename Tag, typename Prop, typename Graph>
typename override_property_t< struct override_property_result {
typename boost::parameter::value_type<ArgPack, Tag, int>::type, typedef
Prop, typename override_property_t<
Graph, typename boost::parameter::value_type<ArgPack, Tag, int>::type,
boost::detail::parameter_exists<ArgPack, Tag>::value Prop,
>::result_type Graph,
boost::detail::parameter_exists<ArgPack, Tag>::value
>::result_type
type;
};
template <typename ArgPack, typename Tag, typename Prop, typename Graph>
typename override_property_result<ArgPack, Tag, Prop, Graph>::type
override_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop prop) { override_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop prop) {
return override_property_t< return override_property_t<
typename boost::parameter::value_type<ArgPack, Tag, int>::type, typename boost::parameter::value_type<ArgPack, Tag, int>::type,