[graph-tool-tickets] [graph-tool] Ticket #108: g.reindex_edges() needs to take into account the edges property maps

graph-tool webmaster at skewed.de
Fri Jul 20 09:20:41 UTC 2012

#108: g.reindex_edges() needs to take into account the edges property maps
new enhancement
Reporter: oleguer.sagarra at gmail.com
Owner: Oleguer
Priority: normal
Milestone: (None)
Changes (by tiago peixoto (2)): 

 * Description:
 When reindexing the edges on a graph (for instance, upon deleting
 edges (self loops for instance) the function should also take care
 to preserve the mapping with the edge_property maps. I don't know
 whether this is a bug (unintentional) or an improvement (a flag
 could be passed to the function in order to do so).
 See example below:
 In [66]: g=gt.Graph()
 In [67]: g.add_vertex(2)
 [<Vertex object with index '0' at 0x406c1d0>,
  <Vertex object with index '1' at 0x406c250>]
 In [68]: g.add_edge(g.vertex(0),g.vertex(1))
 Out[68]: <Edge object with source '0' and target '1' at 0x4066dd0>
 In [69]: g.add_edge(g.vertex(1),g.vertex(0))
 Out[69]: <Edge object with source '1' and target '0' at 0x4066f80>
 In [70]: z=g.new_edge_property("int")
 In [71]: z[g.edge(0,1)]=84
 In [72]: z[g.edge(1,0)]=-84
 In [73]: f= lambda x: z[x]==84 # to remove edges afterwards
 In [74]: g.edge_properties["z"]=z
 In [75]: for e in g.edges():
    ....:     print g.edge_properties['z'][e]
 In [77]: g.remove_edge_if(f) # remove edge
 In [78]: for e in g.edges(): # this is ok
     print g.edge_properties["z"][e]
 In [79]: g.reindex_edges() #reindex
 In [80]: for e in g.edges(): # this is NOT ok.
     print g.edge_properties["z"][e]


This is intentional, and is even mentioned in the documentation:


You should only re-index edges when you don't care about property maps. Note that most of the time you should not care about the edge indexes at all.

Modifying the property maps would make this operation much more expensive, and may have unintended consequences which the user does not expect, since the vectors associated with the property maps will be scrambled in unpredictable ways.

Unless you can give a very good reason to change this, I'd rather leave this as it is.
Ticket URL: <URL:http://graph-tool.skewed.de/ticket/108>
graph-tool <URL:http://graph-tool.skewed.de/>
An efficient python module for graph analysis and manipulation.

More information about the graph-tool-tickets mailing list