gsl_anneal Class Template Reference

Multidimensional minimization by simulated annealing (GSL). More...

#include <gsl_anneal.h>

Inheritance diagram for gsl_anneal:

sim_anneal multi_min

Detailed Description

template<class param_t, class func_t = multi_funct<param_t>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc, class rng_t = gsl_rnga>
class gsl_anneal< param_t, func_t, vec_t, alloc_vec_t, alloc_t, rng_t >

Multidimensional minimization by simulated annealing (GSL).

This class is a modification of simulated annealing as implemented in GSL in the function gsl_siman_solve(). It acts as a generic multidimensional minimizer for any function given a generic temperature schedule specified by the user.

The simulated annealing algorithm proposes a displacement of one coordinate of the previous point by

\[ x_{i,\mathrm{new}} = \mathrm{step\_size}_i (2 u_i - 1) + x_{i,\mathrm{old}} \]

where the $u_i$ are random numbers between 0 and 1. The displacement is accepted or rejected based on the Metropolis method. The random number generator is set in the parent, sim_anneal.

There are a large variety of strategies for choosing the temperature evolution. To offer the user the largest possible flexibility, the temperature evolution is controlled by a the virtual functions start() and next() which can be freely changed by creating descendant.

The default behavior is as follows: Initially, the step sizes are chosen to be 10 and the temperature to be 1. Each iteration decreases the temperature by a factor of 1.5 for each step, and the minimizer is finished when the next decrease would bring the temperature below multi_min::tolx. If none of the multi_min::ntrial steps in a particular iteration changes the value of the minimum, and the step sizes are greater than 100 times multi_min::tolx, then the step sizes are decreased by a factor of 1.5 for the next iteration.

If multi_min::verbose is greater than zero, then mmin() will print out information and/or request a keypress after the function iterations for each temperature.

An example demonstrating the usage of this class is given in examples/ex_anneal.cpp and in the Simulated annealing example .

See also a multi-threaded version of this class in anneal_mt.

Idea for future:
There's x0, old_x, new_x, best_x, and x? There's probably some duplication here which could be avoided.
Idea for future:
  • Implement a more general simulated annealing routine which would allow the solution of discrete problems like the Traveling Salesman problem.

Definition at line 116 of file gsl_anneal.h.


Public Member Functions

virtual int mmin (size_t nvar, vec_t &x0, double &fmin, param_t &pa, func_t &func)
 Calculate the minimum fmin of func w.r.t the array x0 of size nvar.
virtual const char * type ()
 Return string denoting type ("gsl_anneal").
template<class vec2_t >
int set_step (size_t nv, vec2_t &stepv)
 Set the step sizes.

Data Fields

double boltz
 Boltzmann factor (default 1.0).

Protected Member Functions

virtual int next (size_t nvar, vec_t &x_old, double min_old, vec_t &x_new, double min_new, double &T, size_t n_moves, bool &finished)
 Determine how to change the minimization for the next iteration.
virtual int start (size_t nvar, double &T)
 Setup initial temperature and stepsize.
virtual int allocate (size_t n, double boltz_factor=1.0)
 Allocate memory for a minimizer over n dimensions with stepsize step and Boltzmann factor boltz_factor.
virtual int free ()
 Free allocated memory.
virtual int step (vec_t &sx, int nvar)
 Make a step to a new attempted minimum.

Protected Attributes

alloc_t ao
 Allocation object.
ovector step_vec
 Vector of step sizes.
Storage for present, next, and best vectors
alloc_vec_t x
alloc_vec_t new_x
alloc_vec_t best_x
alloc_vec_t old_x

The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page