Commit b3dd46c3 authored by Tiago Peixoto's avatar Tiago Peixoto

Modify GraphWrap semantics

Now, whenever GraphWrap is being used, the property maps are always
in "checked" mode.
parent b50fc2fc
......@@ -78,15 +78,15 @@ void deaugment_graph(Graph& g, AugmentedMap augmented)
template <class Type, class Index>
checked_vector_property_map<Type, Index>
get_checked(unchecked_vector_property_map<Type, Index> prop)
unchecked_vector_property_map<Type, Index>
get_unchecked(checked_vector_property_map<Type, Index> prop)
{
return prop.get_checked();
return prop.get_unchecked();
}
template <class Prop>
Prop
get_checked(Prop prop)
get_unchecked(Prop prop)
{
return prop;
}
......
......@@ -41,12 +41,12 @@ struct get_edmonds_karp_max_flow
augmented(edge_index, max_e);
unchecked_vector_property_map<edge_t,EdgeIndex>
reverse_map(edge_index, max_e);
augment_graph(g, augmented.get_checked(), get_checked(cm),
reverse_map.get_checked(), res.get_checked());
augment_graph(g, augmented.get_checked(), cm, reverse_map.get_checked(),
res);
boost::edmonds_karp_max_flow(g._g, vertex(src, g), vertex(sink, g),
capacity_map(cm).
capacity_map(get_unchecked(cm)).
reverse_edge_map(reverse_map).
residual_capacity_map(res));
residual_capacity_map(res.get_unchecked()));
deaugment_graph(g, augmented.get_checked());
}
};
......
......@@ -71,9 +71,10 @@ struct get_kolmogorov_max_flow
unchecked_vector_property_map<size_t,VertexIndex>
dist_map(vertex_index, num_vertices(g));
augment_graph(g, augmented.get_checked(), get_checked(cm),
reverse_map.get_checked(), res.get_checked());
boost::kolmogorov_max_flow(g._g, cm, res, reverse_map, pred_map,
augment_graph(g, augmented.get_checked(), cm,
reverse_map.get_checked(), res);
boost::kolmogorov_max_flow(g._g, get_unchecked(cm),
res.get_unchecked(), reverse_map, pred_map,
color_map, dist_map, vertex_index,
vertex(src, g), vertex(sink, g));
deaugment_graph(g, augmented.get_checked());
......
......@@ -65,12 +65,12 @@ struct get_push_relabel_max_flow
augmented(edge_index, max_e);
unchecked_vector_property_map<edge_t,EdgeIndex>
reverse_map(edge_index, max_e);
augment_graph(g, augmented.get_checked(), get_checked(cm),
reverse_map.get_checked(), res.get_checked());
augment_graph(g, augmented.get_checked(), cm,
reverse_map.get_checked(), res);
boost::push_relabel_max_flow(g._g, vertex(src, g), vertex(sink, g),
capacity_map(cm).
capacity_map(get_unchecked(cm)).
reverse_edge_map(reverse_map).
residual_capacity_map(res));
residual_capacity_map(res.get_unchecked()));
deaugment_graph(g, augmented.get_checked());
}
};
......
......@@ -54,8 +54,7 @@ struct property_union
UnionProp uprop, boost::any aprop) const
{
Graph& g = *gp;
typename UnionProp::checked_t prop =
any_cast<typename UnionProp::checked_t>(aprop);
UnionProp prop = any_cast<UnionProp>(aprop);
dispatch(ug, g, vmap, emap, uprop, prop,
is_same<typename property_traits<UnionProp>::key_type,
typename graph_traits<Graph>::vertex_descriptor>());
......
......@@ -53,7 +53,7 @@ void edge_property_union(GraphInterface& ugi, GraphInterface& gi,
vprop_t vprop = any_cast<vprop_t>(p_vprop);
eprop_t eprop = any_cast<eprop_t>(p_eprop);
run_action<graph_tool::detail::always_directed,mpl::true_>()
run_action<graph_tool::detail::always_directed>()
(ugi, bind<void>(graph_tool::property_union(),
_1, _2, vprop, eprop, _3, prop),
get_pointers::apply<graph_tool::detail::always_directed>::type(),
......
......@@ -52,7 +52,7 @@ void vertex_property_union(GraphInterface& ugi, GraphInterface& gi,
vprop_t vprop = any_cast<vprop_t>(p_vprop);
eprop_t eprop = any_cast<eprop_t>(p_eprop);
run_action<graph_tool::detail::always_directed,mpl::true_>()
run_action<graph_tool::detail::always_directed>()
(ugi, bind<void>(graph_tool::property_union(),
_1, _2, vprop, eprop, _3, prop),
get_pointers::apply<graph_tool::detail::always_directed>::type(),
......
......@@ -307,11 +307,11 @@ string get_graph_type(GraphInterface& g)
bool openmp_enabled()
{
#ifdef USING_OPENMP
#ifdef USING_OPENMP
return true;
#else
#else
return false;
#endif
#endif
}
void ungroup_vector_property(GraphInterface& g, boost::any vector_prop,
......
......@@ -509,33 +509,48 @@ struct action_wrap
: _a(a), _g(g), _max_v(max_v), _max_e(max_e) {}
template <class Type>
typename checked_vector_property_map
<Type,GraphInterface::vertex_index_map_t>::unchecked_t
checked_vector_property_map<Type,GraphInterface::vertex_index_map_t>
uncheck(checked_vector_property_map
<Type,GraphInterface::vertex_index_map_t> a) const
<Type,GraphInterface::vertex_index_map_t> a, mpl::true_) const
{
return a;
}
template <class Type>
unchecked_vector_property_map<Type,GraphInterface::vertex_index_map_t>
uncheck(checked_vector_property_map
<Type,GraphInterface::vertex_index_map_t> a, mpl::false_) const
{
return a.get_unchecked(_max_v);
}
template <class Type>
typename checked_vector_property_map
<Type,GraphInterface::edge_index_map_t>::unchecked_t
checked_vector_property_map<Type,GraphInterface::edge_index_map_t>
uncheck(checked_vector_property_map
<Type,GraphInterface::edge_index_map_t> a) const
<Type,GraphInterface::edge_index_map_t> a, mpl::true_) const
{
return a;
}
template <class Type>
unchecked_vector_property_map<Type,GraphInterface::edge_index_map_t>
uncheck(checked_vector_property_map
<Type,GraphInterface::edge_index_map_t> a, mpl::false_) const
{
return a.get_unchecked(_max_e);
}
template <class Type>
scalarS<typename Type::unchecked_t>
uncheck(scalarS<Type> a) const
uncheck(scalarS<Type> a, mpl::false_) const
{
return scalarS<typename Type::unchecked_t>(uncheck(a._pmap));
return scalarS<typename Type::unchecked_t>(uncheck(a._pmap,
mpl::false_()));
}
//no op
template <class Type>
Type uncheck(Type a) const { return a; }
template <class Type, class DoWrap>
Type uncheck(Type a, DoWrap) const { return a; }
template <class Graph>
GraphWrap<Graph> wrap(Graph* g, mpl::true_) const
......@@ -550,21 +565,24 @@ struct action_wrap
}
void operator()() const {};
template <class T1> void operator()(const T1& a1) const { _a(wrap(a1, Wrap())); }
template <class T1> void operator()(const T1& a1) const
{ _a(wrap(a1, Wrap())); }
template <class T1, class T2>
void operator()(const T1& a1, const T2& a2) const
{ _a(wrap(a1,Wrap()), uncheck(a2)); }
{ _a(wrap(a1,Wrap()), uncheck(a2, Wrap())); }
template <class T1, class T2, class T3>
void operator()(const T1& a1, const T2& a2, const T3& a3) const
{ _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3));}
{ _a(wrap(a1,Wrap()), uncheck(a2, Wrap()), uncheck(a3, Wrap()));}
template <class T1, class T2, class T3, class T4>
void operator()(const T1& a1, const T2& a2, const T3& a3, const T4& a4)
const
{ _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3), uncheck(a4)); }
{ _a(wrap(a1,Wrap()), uncheck(a2, Wrap()), uncheck(a3, Wrap()),
uncheck(a4, Wrap())); }
template <class T1, class T2, class T3, class T4, class T5>
void operator()(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
const T5& a5) const
{ _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3), uncheck(a4), uncheck(a5)); }
{ _a(wrap(a1,Wrap()), uncheck(a2, Wrap()), uncheck(a3, Wrap()),
uncheck(a4, Wrap()), uncheck(a5), Wrap()); }
Action _a;
reference_wrapper<GraphInterface> _g;
......
......@@ -60,6 +60,17 @@ template <class Graph>
struct graph_traits<const GraphWrap<Graph> >:
public graph_traits<const Graph> {};
template <class Graph, class Tag>
struct property_map<GraphWrap<Graph>, Tag>:
public property_map<Graph, Tag> {};
template <class Graph, class Tag>
typename property_map<Graph, Tag>::type
get(Tag t, const GraphWrap<Graph>& g)
{
return get(t, g._g);
}
template <class Graph>
inline typename graph_traits<GraphWrap<Graph> >::vertex_descriptor
source(typename graph_traits<GraphWrap<Graph> >::edge_descriptor e,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment