Commit 30dee452 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Modify semantics of prop.fa attribute for edge properties

The filtered array returned now also reflects the vertex filtering, so that
it corresponds only to actually visible edges in the graph, not only
those explicitly selected via an edge filter.
parent dba90964
......@@ -336,6 +336,8 @@ void infect_vertex_property(GraphInterface& gi, boost::any prop,
python::object val);
void edge_difference(GraphInterface& gi, boost::any prop,
boost::any eprop);
void mark_edges(GraphInterface& gi, boost::any prop);
void export_python_interface();
BOOST_PYTHON_MODULE(libgraph_tool_core)
......@@ -433,6 +435,7 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
def("ungroup_vector_property", &ungroup_vector_property);
def("infect_vertex_property", &infect_vertex_property);
def("edge_difference", &edge_difference);
def("mark_edges", &mark_edges);
class_<LibInfo>("mod_info")
.add_property("name", &LibInfo::GetName)
......
......@@ -256,3 +256,30 @@ void edge_difference(GraphInterface& gi, boost::any prop,
gi.GetEdgeIndex(), _2, eprop),
vprops_t())(prop);
}
struct do_mark_edges
{
template <class Graph, class EdgePropertyMap>
void operator()(Graph& g, EdgePropertyMap prop) const
{
int i, N = num_vertices(g);
#pragma omp parallel for default(shared) private(i) \
schedule(static) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for (tie(e, e_end) = out_edges(v, g); e != e_end; ++e)
prop[*e] = true;
}
}
};
void mark_edges(GraphInterface& gi, boost::any prop)
{
run_action<graph_tool::detail::always_directed>()(gi, bind<void>(do_mark_edges(), _1, _2),
writable_edge_scalar_properties())(prop);
}
......@@ -536,6 +536,12 @@ class PropertyMap(object):
filt = g.get_vertex_filter()
elif self.__key_type == 'e':
filt = g.get_edge_filter()
if g.get_vertex_filter()[0] is not None:
filt = (g.new_edge_property("bool"), filt[1])
u = GraphView(g, directed=True, skip_properties=True)
libcore.mark_edges(u._Graph__graph, _prop("e", g, filt[0]))
if filt[1]:
filt[0].a = 1 - filt[0].a
if get:
if a is None:
return a
......@@ -580,6 +586,12 @@ class PropertyMap(object):
filt = g.get_vertex_filter()
elif self.__key_type == 'e':
filt = g.get_edge_filter()
if g.get_vertex_filter()[0] is not None:
filt = (g.new_edge_property("bool"), filt[1])
u = GraphView(g, directed=True, skip_properties=True)
libcore.mark_edges(u._Graph__graph, _prop("e", g, filt[0]))
if filt[1]:
filt[0].a = 1 - filt[0].a
if filt[0] is None or a is None:
if get:
return a
......
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