Subsets of property map values - iterating over vertices

Hi everyone,

this might be easily solved, but anyways:

I have been thinking whether there is a fast way of retrieving property map
values of subsets of nodes? I mean the following: let's say I have a
property map A, defined for all vertices of graph G. Now, lets say I have a
vertex iterator V that spans a subset of all nodes of G. Is there now a
fast way, to a) read and b) eventually change the values in A of all nodes
in V, e.g. to do something like A[V] and to get an array back, like in A.a
....

Of course, iterating or map would be obvious options, but take eventually a
lot of time. Another idea I had was, let's say the property map is an
internal property map, to use vertex_filter and then get A.a. But what if
the property map is not internal?

I am happy about your thoughts.
Thanks,
René

attachment.html (976 Bytes)

Hi René,

Hi everyone,

this might be easily solved, but anyways:

I have been thinking whether there is a fast way of retrieving
property map values of subsets of nodes? I mean the following: let's
say I have a property map A, defined for all vertices of graph G. Now,
lets say I have a vertex iterator V that spans a subset of all nodes
of G. Is there now a fast way, to a) read and b) eventually change the
values in A of all nodes in V, e.g. to do something like A[V] and to
get an array back, like in A.a ....

Of course, iterating or map would be obvious options, but take
eventually a lot of time. Another idea I had was, let's say the
property map is an internal property map, to use vertex_filter and
then get A.a. But what if the property map is not internal?

This is easily done with graph filters, as you suggest. It does not
matter whether or not the property maps are internal.

For instance, suppose you want to modify the property of all nodes with
a degree larger than four. You could do:

  g = ... # this is your graph
  prop = ... # this is your property

  mask = g.new_vertex_property("bool")
  mask.a = g.degree_property_map("out").a > 4
  g.set_vertex_filter(mask)

  prop.fa = 42 # this only affects the filtered values

You can also do it using a graph view:

  u = GraphView(g, vfilt=g.degree_property_map("out").a > 4)
  uprop = u.own_property(prop)
  uprop.fa = 42

I prefer the last one, since it is more compact.

(Note the use of A.fa instead of A.a)

Cheers,
Tiago