ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
gsl::siman< XP > Struct Template Reference

Simulated annealing. More...

#include <siman.hpp>

Collaboration diagram for gsl::siman< XP >:
Collaboration graph

Public Types

typedef double(* Efunc_t) (XP &xp)
 Function returning then energy of a configuration. More...
 
typedef void(* step_t) (rng &r, XP &xp, double step_size)
 Function to modify configuration with random number up to maximum step size. More...
 
typedef double(* metric_t) (XP &xp, XP &yp)
 Function to find distance between two configurations. More...
 
typedef void(* print_t) (XP &xp)
 Function to print a configuration. More...
 
typedef void(* copy_t) (XP &source, XP &dest)
 Function to copy configuration contents from source to dest. More...
 
typedef XP *(* copy_construct_t) (XP &xp)
 Function to construct a configuration. More...
 
typedef void(* destroy_t) (XP *xp)
 Function to destruct a configuration. More...
 
typedef gsl_siman_params_t params_t
 Parameters: same as gsl_siman_params_t. More...
 

Public Member Functions

void solve_many (rng &r, XP &x0_p, Efunc_t Ef, step_t take_step, metric_t distance, print_t print_position, params_t params)
 C++ version of gsl_siman_solve_many(). More...
 

Static Public Member Functions

static void solve (rng &r, XP &x0_p, Efunc_t Ef, step_t take_step, metric_t distance, print_t print_position, copy_t copyfunc, copy_construct_t copy_constructor, destroy_t destructor, params_t &params)
 C++ version of gsl_siman_solve(). More...
 

Detailed Description

template<typename XP>
struct gsl::siman< XP >

Simulated annealing.

Use this class as siman<XP>, where XP is the class whose objects represent configurations.

Ideally these functions would wrap the GSL functions as almost all of ccgsl does. However, gsl_siman_solve() uses as arguments pointers to functions with void pointer arguments. In C++ we want to avoid creating such functions explicitly, currently (2012) I know of no way to create them inside a class in such a way that they can be generically constructed as required. It is not possible to substitute a pointer to a function object for a pointer to a function and, while it is possible to create a lambda function in C++11, it is not legal to pass its address as a function pointer.

The compromise here is to wrap the original code from gsl_siman.c in template functions with suitable template arguments. It has the desired effect but means that if gsl_siman.c is updated, the code for ccgsl/siman.hpp must be updated separately to take advantage of any changes.

Definition at line 50 of file siman.hpp.

Member Typedef Documentation

◆ copy_construct_t

template<typename XP >
typedef XP *(* gsl::siman< XP >::copy_construct_t) (XP &xp)

Function to construct a configuration.

Definition at line 75 of file siman.hpp.

◆ copy_t

template<typename XP >
typedef void(* gsl::siman< XP >::copy_t) (XP &source, XP &dest)

Function to copy configuration contents from source to dest.

Definition at line 71 of file siman.hpp.

◆ destroy_t

template<typename XP >
typedef void(* gsl::siman< XP >::destroy_t) (XP *xp)

Function to destruct a configuration.

Definition at line 79 of file siman.hpp.

◆ Efunc_t

template<typename XP >
typedef double(* gsl::siman< XP >::Efunc_t) (XP &xp)

Function returning then energy of a configuration.

Definition at line 55 of file siman.hpp.

◆ metric_t

template<typename XP >
typedef double(* gsl::siman< XP >::metric_t) (XP &xp, XP &yp)

Function to find distance between two configurations.

Definition at line 63 of file siman.hpp.

◆ params_t

template<typename XP >
typedef gsl_siman_params_t gsl::siman< XP >::params_t

Parameters: same as gsl_siman_params_t.

Definition at line 83 of file siman.hpp.

◆ print_t

template<typename XP >
typedef void(* gsl::siman< XP >::print_t) (XP &xp)

Function to print a configuration.

Definition at line 67 of file siman.hpp.

◆ step_t

template<typename XP >
typedef void(* gsl::siman< XP >::step_t) (rng &r, XP &xp, double step_size)

Function to modify configuration with random number up to maximum step size.

Definition at line 59 of file siman.hpp.

Member Function Documentation

◆ solve()

template<typename XP >
static void gsl::siman< XP >::solve ( rng r,
XP &  x0_p,
Efunc_t  Ef,
step_t  take_step,
metric_t  distance,
print_t  print_position,
copy_t  copyfunc,
copy_construct_t  copy_constructor,
destroy_t  destructor,
params_t params 
)
inlinestatic

C++ version of gsl_siman_solve().

If configurations are C++ objects, typically you should provide copyfunc, copy_construct and destructor as non-null pointers and element_size will not be used. Otherwise, element_size must be the size of an object and the object will be copied directly, which is unwise if a configuration object contains pointers.

Parameters
rA random number generator
x0_pThe initial configuration (also final configuration on return)
EfThe Energy fiunction: gives energy of configuration
take_stepThe step function
distanceThe distance function
print_positionFunction to print position
copyfuncFunction to copy a configuration
copy_constructorFunction to copy-construct a configuration
destructorFunction to delete a configuration
paramsParameters of the Simulated Annealing heuristic

Definition at line 101 of file siman.hpp.

References gsl::math::E, gsl::cpx::exp(), gsl::cheb::size(), and gsl::rng::uniform().

◆ solve_many()

template<typename XP >
void gsl::siman< XP >::solve_many ( rng r,
XP &  x0_p,
Efunc_t  Ef,
step_t  take_step,
metric_t  distance,
print_t  print_position,
params_t  params 
)
inline

C++ version of gsl_siman_solve_many().

Element_size must be the size of an object and the object will be copied directly, which is unwise if a configuration object contains pointers.

Parameters
rA random number generator
x0_pThe initial configuration (also final configuration on return)
EfThe Energy fiunction: gives energy of configuration
take_stepThe step function
distanceThe distance function
print_positionFunction to print position
paramsParameters of the Simulated Annealing heuristic

Definition at line 267 of file siman.hpp.

References gsl::math::E, gsl::cpx::exp(), and gsl::rng::uniform().


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