This is the mail archive of the gsl-discuss@sourceware.org mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Simulated annealing cleanup


Hello. I propose the attached patch to cleanup and optimize the 
simulated annealing algorithm.

Diffstat:

siman.c     |  112 ++++++++++++++++++++++++++++++------------------------------
siman_tsp.c |   11 ++++-
2 files changed, 66 insertions(+), 57 deletions(-)

Here's the description of changes:

siman/siman.c:
- remove useless "done" variable
- optimization: new_E <= best_E is only necessary when new_E < E
- new_E < best_E is the proper comparison, not new_E <= best_E. This
  reduces useless copying of state.
- fix whitespace use
- replace repeated occurence of:
    if (copyfunc) {
      copyfunc(src, dst);
    } else {
      memcpy(dst, src, size);
    }
  with copy_state().
- spelling: boltzman -> boltzmann
- make boltzmann function an inline function -> easier to modularize 
  the transition probability function later
- Use T *= T_factor instead of T /= params.mu_t. Avoids division -> faster.
- malloc() returns void * always, remove useless cast
- Print the best energy so far on progress. In the TSP example it reveals
  that optimization continues long after the optimum point has been found.
  On one test the optimum was reached with just 28% of total iterations.

siman/siman_tsp.c:
- initialize parameters using C99 initialization style. This way params
  structure may change inside and siman_tsp.c need not be updated. It
  is also more clear.

You should attribute the patch to "Heikki Orsila <heikki.orsila@iki.fi>"
if you apply it.

-- 
Heikki Orsila			Barbie's law:
heikki.orsila@iki.fi		"Math is hard, let's go shopping!"
http://www.iki.fi/shd

Attachment: simulated_annealing_cleanup.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]