help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Problem using simulated annealing


From: Carl Boettiger
Subject: Re: [Help-gsl] Problem using simulated annealing
Date: Tue, 2 Feb 2010 12:30:56 -0800

Hi Francisco,

I think you're missing some necessary header files  Include the header
files listed in the example in the documentation should work:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_siman.h>

See: 
http://www.gnu.org/software/gsl/manual/gsl-ref.html#Examples-with-Simulated-Annealing

With that I could compile and run your program fine.  Not sure about
all the c++ headers you're including, but perhaps you're missing the
links to them?  If it is still not working let us know how you are
compiling.

-Carl

On Tue, Feb 2, 2010 at 6:43 AM, Francisco Marcelo Rocha
<address@hidden> wrote:
> Dear help-gsl,
>
> I have included the header of the simple example of simulated annealing
> result in the following libraries: the following libraries iostream, fstream
> and cstdio. When compiled the example occurred the following error:
> segmentation fault. How can I fix the program?
> and how can I write the result of the program in a file using fstream? The
> example used is
>
> # include<cstdio>
> # include<iostream>
> # include<cmath>
> # include<cstdlib>
> # include<cstring>
> # include<fstream>
> #include <gsl/gsl_errno.h>
> # include<gsl/gsl_siman.h>
> /* 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 1.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
>
> using namespace std;
>
> gsl_siman_params_t params   = {N_TRIES, ITERS_FIXED_T, STEP_SIZE,
>     K, T_INITIAL, MU_T, T_MIN};
> /* now some functions to test in one dimension */
> double E1(void *xp)
> {
>  double x = * ((double *) xp);
>  return exp(-pow((x-1.0),2.0))*sin(8*x);
> }
>
> double M1(void *xp, void *yp)
> {
>  double x = *((double *) xp);
>  double y = *((double *) yp);
>  return fabs(x - y);
> }
>
> void S1(const gsl_rng * r, void *xp, double step_size)
> {
>  double old_x = *((double *) xp);
>  double new_x;
>  double u = gsl_rng_uniform(r);
>  new_x = u * 2 * step_size - step_size + old_x;
>  memcpy(xp, &new_x, sizeof(new_x));
> }
>
> void P1(void *xp)// ostream & simuanel
> {
> //  printf ("%12g", *((double *) xp));
> //   cout <<  *((double *) xp) << endl;
>  // simuanel << *((double *) xp) << endl;
> }
>
>
> int main(int argc, char *argv[])
> {
>  const gsl_rng_type * T;
>  gsl_rng * r;
>  double x_initial = 15.5;
>  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;
> }
>
> Sincerely
>
>
>
> --
> Francisco Marcelo Monteiro da Rocha
> E-mail: address@hidden
> tel: 11 6397-4748
> _______________________________________________
> Help-gsl mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-gsl
>



-- 
Carl Boettiger
Population Biology, UC Davis
http://two.ucdavis.edu/~cboettig




reply via email to

[Prev in Thread] Current Thread [Next in Thread]