Suresh Pillai wrote:
I am performing simulations on networks (graphs). I have a question on
speed of execution (assuming very ample memory for now). I simplify the
details of my simulation below, as the question I ask applies more
generally than my specific case. I would greatly appreciate general
feedback in terms of computing and of course considerations specific to
implementation in Python.
The nodes in my network may be ON or OFF. The network starts off with
all nodes in the OFF state. I loop through the nodes. For each node
that is OFF, I consider some probability of it turning ON based on the
states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING
WHICH ONES TO TURN ON.
If the nodes do not have to be processed in any particular order, then
you could keep them either in a dict, with the value being either On or
Off (True,False)(plus connection data) or a pair of sets, one for On and
one for Off. The advantage of the dict is that the items would be fixed
and only their values would change, but you needlessly scan through On
items. The advantage of the set pair is that you only scan through Off
items but have to move some from Off to On. I will not guess which
would be faster over a complete run, or how this will compare with using
lists.
tjr
--
http://mail.python.org/mailman/listinfo/python-list