That's assuming you really need to loop through the edges, and that getting edges from masked graphs won't do. On Jul 19, 2014 12:01 PM, "..." <offonoffoffonoff@gmail.com> wrote:
Well, if you build a list of edge objects before hand, you can get and set properties from maps quickly all day, or until you create or destroy edges is the graph and have to rebuild the list. If building that list takes a long time and you're changing edges often, you could use property map masks to keep track of new and deleted edges and add to and subtract from the list.
Elliot On Jul 19, 2014 2:21 AM, "Flavien Lambert" <petit.lepton@gmail.com> wrote:
Thanks a lot for the explanation! So is there a best way to have access to the properties?
On 18 July 2014 21:39, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 07/16/2014 05:44 PM, Flavien Lambert wrote:
On the same topic, I did not find the function for getting the edge from the edge index. There is one for vertices like vertex(n) but for edges?
There is no such function, and this is related to the speed difference you are seeing. The edges are not stored in one big vector, and thus cannot be addressed simply by its index. Instead, they are stored in different vectors across all nodes (i.e. and adjacency list), and thus one needs to iterate first through the vectors.
Now lets look at your code:
_edges = [_e for _e in _network.edges()] %time for _e in _network.edges() : a = _speeds[_e]
_speedDict = {} for _e in _edges : _speedDict[_network.edge_index[_e]] = _speeds[_e] _indexes = [_network.edge_index[_e] for _e in _network.edges()] %time for _n in _indexes : a = _speedDict[_n]
What makes the second loop slower has little to do with property maps vs dicts, but instead with the loop over the Graph.edges() iterator and the loop ofter the list you created in the second part. Whenever you loop over the edges, not only is the loop slightly slower because it is not a simple list, but a "list of lists", but also (more importantly) because it has to *create* edge descriptor objects at each iteration! In the second loop you created these objects and stored them in a list, and then looped over this list, which does not involve object creation, and is therefore much faster.
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
_______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool