#include #include #include #include /* set up parameters for this simulated annealing run */ /* how many points do we try before stepping */ #define N_TRIES 200 /* how many iterations for each T? */ #define ITERS_FIXED_T 1000 /* max step size in random walk */ #define STEP_SIZE 2.0 /* Boltzmann constant */ #define K 1.0 /* initial temperature */ #define T_INITIAL 0.008 /* damping factor for temperature */ #define MU_T 1.003 #define T_MIN 2.0e-6 /* Globally declare an array */ gsl_siman_params_t params = {N_TRIES, ITERS_FIXED_T, STEP_SIZE, K, T_INITIAL, MU_T, T_MIN}; /* This is the structure definition. If int b is commmented out or placed after double x, everything appears ok.*/ typedef struct { int b; double x; } STR; /* Error Function -- This is the energy landscape */ double E1(void *xp) { double x = ((STR *) xp)->x; return exp(-pow((x-1.0),2.0))*sin(8*x); } /* Distance function */ double M1(void *xp, void *yp) { double x = ((STR *) xp)->x; double y = ((STR *) yp)->x; // return fabs(x - y); return pow( x-y, 2); } void S1(const gsl_rng * r, void *xp, double step_size) { STR old_x = *((STR *) xp); double u = gsl_rng_uniform(r); old_x.x = u * 2 * step_size - step_size + old_x.x; memcpy(xp, &old_x, sizeof(old_x)); } void P1(void *xp) { printf ("%12g", ((STR *) xp)->x); } int main(int argc, char *argv[]) { const gsl_rng_type * T; gsl_rng * r; STR x_initial; x_initial.x = 10; gsl_rng_env_setup(); T = gsl_rng_default; r = gsl_rng_alloc(T); gsl_siman_solve(r, &x_initial, E1, S1, M1, P1, NULL, NULL, NULL, sizeof(double), params); gsl_rng_free (r); return 0; } /* Run using: ./siman_test | awk '!/^#/ {print $1, $4}' | graph -y 1.34 1.4 -W0 -X generation -Y position | plot -Tps > siman-test.eps ./siman_test | awk '!/^#/ {print $1, $5}' | graph -y -0.88 -0.83 -W0 -X generation -Y energy | plot -Tps > siman-energy.eps */