int sa_solve(double temperature, double temperature_min, double energy_limit, double damping_factor, int iters) { mds_data_t *t; printf("%f %f\n",temperature, temperature_min); steps_count=0; S.temperature = temperature; S.minimum_temperature = temperature_min; S.damping_factor = damping_factor; S.energy_limit = energy_limit * lower_triangle2; S.number_of_iterations_at_fixed_temperature = iters; annealing_simple_solve(&S); t = (mds_data_t *) S.best_configuration.data; return steps_count; }
int main (int argc, char ** argv) { annealing_simple_workspace_t S; fitting_data_t D; fitting_step_t max_step = { 1.0, 0.1, 1.0 }; configuration_t configurations[3]; int verbose_mode = 0; { int c; while ((c = getopt(argc, argv, "hv")) != -1) switch (c) { case 'h': fprintf(stderr, "usage: test_fitting [-v] [-h]\n"); goto exit; case 'v': verbose_mode = 1; break; default: fprintf(stderr, "test_fitting error: unknown option %c\n", c); exit(EXIT_FAILURE); } } printf("\n------------------------------------------------------------\n"); printf("test_fitting: exponential parameters fitting with simulated annealing\n"); /* fitting data initialisation */ { D.num = NUM; linspace(D.t, D.num, 0.0, 10.0); make_observations(D.t, D.observations, D.num); } /* annealing workspace initialisation */ { S.number_of_iterations_at_fixed_temperature = 10; S.max_step_value = &max_step; S.temperature = 10.0; S.minimum_temperature = 0.1; S.restart_temperature = 1.0; S.boltzmann_constant = 1.0; S.damping_factor = 1.005; S.energy_function = energy_function; S.step_function = step_function; S.copy_function = copy_function; S.log_function = (verbose_mode)? log_function : NULL; S.cooling_function = NULL; S.numbers_generator = gsl_rng_alloc(gsl_rng_rand); gsl_rng_set(S.numbers_generator, 15); S.current_configuration.data= &(configurations[0]); S.best_configuration.data = &(configurations[1]); S.new_configuration.data = &(configurations[2]); /* start configuration */ configurations[0].A = 6.0; configurations[0].lambda = 3.0; configurations[0].b = 1.0; S.params = &D; } annealing_simple_solve(&S); printf("test_fitting: final best solution: %f, %f, %f; original: %g, %g, %g\n", configurations[1].A, configurations[1].lambda, configurations[1].b, original_params.A, original_params.lambda, original_params.b); printf("------------------------------------------------------------\n\n"); gsl_rng_free(S.numbers_generator); exit: exit(EXIT_SUCCESS); }