I'm sorry if this has been asked before, but I'm not really sure what I'm looking for and I lack the domain knowledge to correctly frame the question which make answers rather hard to find!
Anyway, I am trying to implement in Python a simulated annealing algorithm from a paper (IBM J. Res. Dev., 2001; 45(3/4); 545). The author gives a clear outline of the algorithm which he has implemented in C++, however at the end of his definition he states the follwing
"To avoid repeated and potentially expensive memory allocation S and S* are implemented as a single object that is able to revert to its initial state after an unfavourable mutation."
(S and S* represent the original and step changed state of whatever is being optimised).
In a previous more naive version I have used two lists to hold each state, but his comment seems to suggest that such an approach is memory inefficient. Thus, my questions are:
- Is his comment C++ specific and in Python I can continue to use lists and not worry about it?
- If I do need to worry about it, what Python data structure should I use? Simply define a class with original and mutated attributes and a method to do the mutation or is there something else I'm missing?
- I still need the two states, so does wrapping that in a class change the way the memory is allocated to make the class representation more compact?