Hi Dan,
Thanks for your reply. I understand your point about the desirability
of using generators. The NetworkX function nx.simple_cycles(G) is a good example
of when this is very useful as it allows the user to iterate through all cycles
in a simple graph.
When I asked my question, I was thinking more about
heuristic optimisation algorithms where we are interested in finding the best
solution among many different options. In these cases, a generator seems to be
less useful because the user will only really be interested in the best
solution that the algorithm found (and not the inferior solutions that it
looked at along the way). Allowing the user to state some sort of computational
limit on a heuristic optimisation algorithm up front also allows values for any internal control parameters to be determined by the algorithm.
As a guide, I've been looking at the simulated annealing algorithm for the travelling salesman problem in the NetworkX library. This is more like the sort of thing I have in mind.
In this example, lengths of runs are specified using several user-defined parameters (things like temp, max_iterations, N_inner and alpha). While this only gives the user indirect control over how long the algorithm will run for, it does mean that runs with the same input always produce the same output.
Unless advised otherwise, I think, then, that I will use
the above simulated annealing example a guide in my implementations. I will run
the optimisation process for a fixed number of iterations (defined by the user)
and will make a note of the computation complexity of each iteration in the documentation.
Thanks
Rhyd
Hi Dan,
Thanks for your reply. I understand your point about the desirability of using generators. The NetworkX function nx.simple_cycles(G) is a good example of when this is very useful as it allows the user to iterate through all cycles in a simple graph.
When I asked my question, I was thinking more about heuristic optimisation algorithms where we are interested in finding the best solution among many different options. In these cases, a generator seems to be less useful because the user will only really be interested in the best solution that the algorithm found (and not the inferior solutions that it looked at along the way). Allowing the user to state some sort of computational limit on a heuristic optimisation algorithm up front also allows values for any internal control parameters to be determined by the algorithm.
As a guide, I've been looking at the simulated annealing algorithm for the travelling salesman problem in the NetworkX library. This is more like the sort of thing I have in mind.
In this example, lengths of runs are specified using several user-defined parameters (things like temp, max_iterations, N_inner and alpha). While this only gives the user indirect control over how long the algorithm will run for, it does mean that runs with the same input always produce the same output.