Loading ...
Sorry, an error occurred while loading the content.

Lilgp-Windows

Expand Messages
  • eiram_elahi
    Dear all lil_gp users, I m stuck writing (what should be simple code) to read 5 values from a data file and assigning them to an array. I m using lil_gp the
    Message 1 of 9 , May 21, 2003
    • 0 Attachment
      Dear all lil_gp users,

      I'm stuck writing (what should be simple code) to read 5 values from
      a data file and assigning them to an array.

      I'm using lil_gp the windows version.. coding in C. Hence
      everything is linked using a dynamic link library.
      I am trying to write this in the app.initialise() method of app.c

      Can anyone please help me optimise the code for the following:

      To read in 5 values (4 are independent variables and 1 dependent)
      from a data file containing 55 lines. All these variables
      (datatype - double) are global variables (g.mr3, g.mr4,g.mr5,pi3 and
      g.y)
      I then need to assign these to an array, (the array used is the one
      from the example in the lil_gp manual - the symbolic regression
      problem;

      The following are declared at the beginning of app.c

      static double *app_fitness_cases [5];
      static fitness_cases =55;

      Thie following code is written in the app.c file in the:
      int EXPORT app_initialize(x,y,z...) method

      app_fitness_cases [0] = (double *)malloc (fitness_cases *sizeof
      (double));
      app_fitness_cases [1] = (double *)malloc (fitness_cases *sizeof
      (double));
      //repeated for [2] and [3]
      app_fitness_cases [4] = (double *)malloc (fitness_cases *sizeof
      (double));

      //Read from file until EOF (need some help here please!)

      act_param = get_parameter("app.trail", param,size);
      if (act_param ==NULL)
      {ERROR}
      in=fopen(act_param,"r");
      if(in == NULL)
      {ERROR}
      fscanf (in, "%d%d%d%d%d",&g.mr3,&g.mr4,&g.mr4,&g.mr5,&g.pi3,&g.y);

      app_fitness_cases [0][i] = g.mr3;
      app_fitness_cases [1][i] = g.mr4;
      app_fitness_cases [2][i] = g.mr5;
      app_fitness_cases [3][i] = g.pi3;
      app_fitness_cases [4][i] = g.y;

      **Please note the above code is written be me here and now, it is
      not copy pasted from the compiled version.. so if you spot any
      syntax errors please ignore as the compiled code does not contain
      these.

      The code I have compiles and is linked to the dll, but when trying
      to open the problem.epg (bound with the dll) in the GPS, it causes
      the GPS to crash, taking up too much virtual memory?? Not sure if
      its the static variables taking up so much memory and space.. Don't
      really know what is going on here..

      Please help, getting tied down by this problem..

      Many thanks in advance

      Eiram
    • Mike Eggleston
      ... The way I have done this is something along the lines of: typedef struct _fit { float val[5]; } FITNESS; { int h, rc, i; FILE *fp; char *fn; int lines;
      Message 2 of 9 , May 21, 2003
      • 0 Attachment
        On Wed, 21 May 2003, eiram_elahi wrote:

        > Dear all lil_gp users,
        >
        > I'm stuck writing (what should be simple code) to read 5 values from
        > a data file and assigning them to an array.
        >
        > I'm using lil_gp the windows version.. coding in C. Hence
        > everything is linked using a dynamic link library.
        > I am trying to write this in the app.initialise() method of app.c
        >
        > Can anyone please help me optimise the code for the following:
        >
        > To read in 5 values (4 are independent variables and 1 dependent)
        > from a data file containing 55 lines. All these variables
        > (datatype - double) are global variables (g.mr3, g.mr4,g.mr5,pi3 and
        > g.y)
        > I then need to assign these to an array, (the array used is the one
        > from the example in the lil_gp manual - the symbolic regression
        > problem;
        >
        > The following are declared at the beginning of app.c
        >
        > static double *app_fitness_cases [5];
        > static fitness_cases =55;
        >
        > Thie following code is written in the app.c file in the:
        > int EXPORT app_initialize(x,y,z...) method
        >
        > app_fitness_cases [0] = (double *)malloc (fitness_cases *sizeof
        > (double));
        > app_fitness_cases [1] = (double *)malloc (fitness_cases *sizeof
        > (double));
        > //repeated for [2] and [3]
        > app_fitness_cases [4] = (double *)malloc (fitness_cases *sizeof
        > (double));
        >
        > //Read from file until EOF (need some help here please!)
        >
        > act_param = get_parameter("app.trail", param,size);
        > if (act_param ==NULL)
        > {ERROR}
        > in=fopen(act_param,"r");
        > if(in == NULL)
        > {ERROR}
        > fscanf (in, "%d%d%d%d%d",&g.mr3,&g.mr4,&g.mr4,&g.mr5,&g.pi3,&g.y);
        >
        > app_fitness_cases [0][i] = g.mr3;
        > app_fitness_cases [1][i] = g.mr4;
        > app_fitness_cases [2][i] = g.mr5;
        > app_fitness_cases [3][i] = g.pi3;
        > app_fitness_cases [4][i] = g.y;
        >
        > **Please note the above code is written be me here and now, it is
        > not copy pasted from the compiled version.. so if you spot any
        > syntax errors please ignore as the compiled code does not contain
        > these.
        >
        > The code I have compiles and is linked to the dll, but when trying
        > to open the problem.epg (bound with the dll) in the GPS, it causes
        > the GPS to crash, taking up too much virtual memory?? Not sure if
        > its the static variables taking up so much memory and space.. Don't
        > really know what is going on here..
        >
        > Please help, getting tied down by this problem..
        >
        > Many thanks in advance
        >
        > Eiram

        The way I have done this is something along the lines of:

        typedef struct _fit {
        float val[5];
        } FITNESS;

        {
        int h, rc, i;
        FILE *fp;
        char *fn;
        int lines;
        char buf[1024];
        FITNESS *app_fitness_cases;

        // how many lines
        if((h = open(fn, O_RDONLY)) == -1) {
        // error
        }
        lines = 0;
        while((rc = read(h, buf, 1)) != 0 && rc != -1) {
        if(*buf == '\n') {
        lines++;
        }
        }
        (void) close(h);

        // allocate the space
        if((app_fitness_cases = (FITNESS*) malloc(lines * sizeof(FITNESS))) == (FITNESS*) NULL) {
        // error
        }

        // read the data
        if((fp = fopen(fn, "r")) == (FILE*) NULL) {
        // error
        }
        for(i = 0; i < lines; i++) {
        (void) fscanf(fp, "%f %f %f %f %f", app_fitness_cases[i]->vals[0]
        app_fitness_cases[i]->vals[1], app_fitness_cases[i]->vals[2],
        app_fitness_cases[i]->vals[3], app_fitness_cases[i]->vals[4]);
        }
        (void) fclose(fp);
        }
      • eiram_elahi
        Dear All Mike, many thanks for your code, it has helped me but I am still receiving GPS errors: GPS= EPG.exe Application error The instruction at 0x10001280
        Message 3 of 9 , May 23, 2003
        • 0 Attachment
          Dear All

          Mike, many thanks for your code, it has helped me but I am still
          receiving GPS errors:

          GPS=
          EPG.exe Application error
          The instruction at 0x10001280 referenced memory at 0x00000
          The memory could not be "read"

          If I debug then this takes me to MS visual C++ with the following
          message:
          Unhandled exception in EPG.exe (REGDLL.DLL):0xC0000005: Acces
          Violation. REGDLL! 10001280C

          The debugging takes me to the app_eval_fitness (ind*) method, Can
          you help me with this or suggest something? I really want to start a
          fresh and need some help with the code. I hope you can help.

          Has anyone else experienced similar error messages if so how were
          they dealt with.
          Many thanks

          Eiram

          --- In genetic_programming@yahoogroups.com, Mike Eggleston
          <mikee@m...> wrote:
          > On Wed, 21 May 2003, eiram_elahi wrote:
          >
          > > Dear all lil_gp users,
          > >
          > > I'm stuck writing (what should be simple code) to read 5 values
          from
          > > a data file and assigning them to an array.
          > >
          > > I'm using lil_gp the windows version.. coding in C. Hence
          > > everything is linked using a dynamic link library.
          > > I am trying to write this in the app.initialise() method of app.c
          > >
          > > Can anyone please help me optimise the code for the following:
          > >
          > > To read in 5 values (4 are independent variables and 1
          dependent)
          > > from a data file containing 55 lines. All these variables
          > > (datatype - double) are global variables (g.mr3, g.mr4,g.mr5,pi3
          and
          > > g.y)
          > > I then need to assign these to an array, (the array used is the
          one
          > > from the example in the lil_gp manual - the symbolic regression
          > > problem;
          > >
          > > The following are declared at the beginning of app.c
          > >
          > > static double *app_fitness_cases [5];
          > > static fitness_cases =55;
          > >
          > > Thie following code is written in the app.c file in the:
          > > int EXPORT app_initialize(x,y,z...) method
          > >
          > > app_fitness_cases [0] = (double *)malloc (fitness_cases *sizeof
          > > (double));
          > > app_fitness_cases [1] = (double *)malloc (fitness_cases *sizeof
          > > (double));
          > > //repeated for [2] and [3]
          > > app_fitness_cases [4] = (double *)malloc (fitness_cases *sizeof
          > > (double));
          > >
          > > //Read from file until EOF (need some help here please!)
          > >
          > > act_param = get_parameter("app.trail", param,size);
          > > if (act_param ==NULL)
          > > {ERROR}
          > > in=fopen(act_param,"r");
          > > if(in == NULL)
          > > {ERROR}
          > > fscanf (in, "%d%d%d%d%
          d",&g.mr3,&g.mr4,&g.mr4,&g.mr5,&g.pi3,&g.y);
          > >
          > > app_fitness_cases [0][i] = g.mr3;
          > > app_fitness_cases [1][i] = g.mr4;
          > > app_fitness_cases [2][i] = g.mr5;
          > > app_fitness_cases [3][i] = g.pi3;
          > > app_fitness_cases [4][i] = g.y;
          > >
          > > **Please note the above code is written be me here and now, it
          is
          > > not copy pasted from the compiled version.. so if you spot any
          > > syntax errors please ignore as the compiled code does not
          contain
          > > these.
          > >
          > > The code I have compiles and is linked to the dll, but when
          trying
          > > to open the problem.epg (bound with the dll) in the GPS, it
          causes
          > > the GPS to crash, taking up too much virtual memory?? Not sure
          if
          > > its the static variables taking up so much memory and space..
          Don't
          > > really know what is going on here..
          > >
          > > Please help, getting tied down by this problem..
          > >
          > > Many thanks in advance
          > >
          > > Eiram
          >
          > The way I have done this is something along the lines of:
          >
          > typedef struct _fit {
          > float val[5];
          > } FITNESS;
          >
          > {
          > int h, rc, i;
          > FILE *fp;
          > char *fn;
          > int lines;
          > char buf[1024];
          > FITNESS *app_fitness_cases;
          >
          > // how many lines
          > if((h = open(fn, O_RDONLY)) == -1) {
          > // error
          > }
          > lines = 0;
          > while((rc = read(h, buf, 1)) != 0 && rc != -1) {
          > if(*buf == '\n') {
          > lines++;
          > }
          > }
          > (void) close(h);
          >
          > // allocate the space
          > if((app_fitness_cases = (FITNESS*) malloc(lines * sizeof
          (FITNESS))) == (FITNESS*) NULL) {
          > // error
          > }
          >
          > // read the data
          > if((fp = fopen(fn, "r")) == (FILE*) NULL) {
          > // error
          > }
          > for(i = 0; i < lines; i++) {
          > (void) fscanf(fp, "%f %f %f %f %f", app_fitness_cases
          [i]->vals[0]
          > app_fitness_cases[i]->vals[1], app_fitness_cases[i]-
          >vals[2],
          > app_fitness_cases[i]->vals[3], app_fitness_cases[i]-
          >vals[4]);
          > }
          > (void) fclose(fp);
          > }
        • Mike Eggleston
          ... This is a null or corrupt pointer. What line in your code does this happen with? Mike
          Message 4 of 9 , May 23, 2003
          • 0 Attachment
            On Fri, 23 May 2003, eiram_elahi wrote:

            > Dear All
            >
            > Mike, many thanks for your code, it has helped me but I am still
            > receiving GPS errors:
            >
            > GPS=
            > EPG.exe Application error
            > The instruction at 0x10001280 referenced memory at 0x00000
            > The memory could not be "read"

            This is a null or corrupt pointer. What line in your code
            does this happen with?

            Mike
          • eiram_elahi
            Hi Mike It happens in the following: for(i=0;i
            Message 5 of 9 , May 23, 2003
            • 0 Attachment
              Hi Mike
              It happens in the following:


              for(i=0;i< fitness_cases; i++);
              g.x = app_fitness_cases[0][i]; //this is the independent variable
              and this is where the code is corrupt...
              v=evaluate_tree (ind ->tr[o].data,0);
              y= app_fitness_cases[1][i]; // this is the known value for the
              dependent variable
              disp = fabs(y-v);
              if (disp->value_cutoff) //set to 1e15 in .epg
              {
              ind->r_fitness +=disp;
              if(disp <= value_cutoff)
              ++ind->hits;
              }
              else
              {
              ind ->r_fitness = fitness_cases += value_cutoff;
              }
              }
              ind->s_fitness = ind->r_fitness;
              ind a_fitness = 1.0/(1.0+ind->s_fitness);
              ind->evald = EVAL_CACHE_VALID;
              }

              Thanks
              e
              --- In genetic_programming@yahoogroups.com, Mike Eggleston
              <mikee@m...> wrote:
              > On Fri, 23 May 2003, eiram_elahi wrote:
              >
              > > Dear All
              > >
              > > Mike, many thanks for your code, it has helped me but I am still
              > > receiving GPS errors:
              > >
              > > GPS=
              > > EPG.exe Application error
              > > The instruction at 0x10001280 referenced memory at 0x00000
              > > The memory could not be "read"
              >
              > This is a null or corrupt pointer. What line in your code
              > does this happen with?
              >
              > Mike
            • Mike Eggleston
              ... In the code I sent you, you would not reference the values as app_fitness_cases[0][i]. You would reference the individual values as
              Message 6 of 9 , May 23, 2003
              • 0 Attachment
                On Fri, 23 May 2003, eiram_elahi wrote:

                > Hi Mike
                > It happens in the following:
                >
                >
                > for(i=0;i< fitness_cases; i++);
                > g.x = app_fitness_cases[0][i]; //this is the independent variable
                > and this is where the code is corrupt...
                > v=evaluate_tree (ind ->tr[o].data,0);
                > y= app_fitness_cases[1][i]; // this is the known value for the
                > dependent variable
                > disp = fabs(y-v);
                > if (disp->value_cutoff) //set to 1e15 in .epg
                > {
                > ind->r_fitness +=disp;
                > if(disp <= value_cutoff)
                > ++ind->hits;
                > }
                > else
                > {
                > ind ->r_fitness = fitness_cases += value_cutoff;
                > }
                > }
                > ind->s_fitness = ind->r_fitness;
                > ind a_fitness = 1.0/(1.0+ind->s_fitness);
                > ind->evald = EVAL_CACHE_VALID;
                > }

                In the code I sent you, you would not reference the values as app_fitness_cases[0][i].
                You would reference the individual values as app_fitness_cases[i]->val[0] for
                the first value and app_fitness_cases[i]->val[3] for the fourth value.

                Mike
              • eiram_elahi
                Hi, yes, but I was having some problems with one bit of your code: app_fitness_cases[i]- val[o], app_fitness_cases[i]- val [1],app_fitness_cases[i]- val[2] and
                Message 7 of 9 , May 23, 2003
                • 0 Attachment
                  Hi,

                  yes, but I was having some problems with one bit of your code:

                  app_fitness_cases[i]->val[o], app_fitness_cases[i]->val
                  [1],app_fitness_cases[i]->val[2] and so on...

                  Confusion between app_fitness_cases[i] and FITNESS app_fitness_cases;
                  if I use app_fitness_cases.val[1], this works fine but for only one
                  of the four vals

                  Thanks



                  --- In genetic_programming@yahoogroups.com, Mike Eggleston
                  <mikee@m...> wrote:
                  > On Fri, 23 May 2003, eiram_elahi wrote:
                  >
                  > > Hi Mike
                  > > It happens in the following:
                  > >
                  > >
                  > > for(i=0;i< fitness_cases; i++);
                  > > g.x = app_fitness_cases[0][i]; //this is the independent
                  variable
                  > > and this is where the code is corrupt...
                  > > v=evaluate_tree (ind ->tr[o].data,0);
                  > > y= app_fitness_cases[1][i]; // this is the known value for the
                  > > dependent variable
                  > > disp = fabs(y-v);
                  > > if (disp->value_cutoff) //set to 1e15 in .epg
                  > > {
                  > > ind->r_fitness +=disp;
                  > > if(disp <= value_cutoff)
                  > > ++ind->hits;
                  > > }
                  > > else
                  > > {
                  > > ind ->r_fitness = fitness_cases += value_cutoff;
                  > > }
                  > > }
                  > > ind->s_fitness = ind->r_fitness;
                  > > ind a_fitness = 1.0/(1.0+ind->s_fitness);
                  > > ind->evald = EVAL_CACHE_VALID;
                  > > }
                  >
                  > In the code I sent you, you would not reference the values as
                  app_fitness_cases[0][i].
                  > You would reference the individual values as app_fitness_cases[i]-
                  >val[0] for
                  > the first value and app_fitness_cases[i]->val[3] for the fourth
                  value.
                  >
                  > Mike
                • Mike Eggleston
                  ... In c code when referring to a field in a structure (typedef) you use the . to connect the typedef variable to the field in that typedef. void localfunc()
                  Message 8 of 9 , May 23, 2003
                  • 0 Attachment
                    On Fri, 23 May 2003, eiram_elahi wrote:

                    > Hi,
                    >
                    > yes, but I was having some problems with one bit of your code:
                    >
                    > app_fitness_cases[i]->val[o], app_fitness_cases[i]->val
                    > [1],app_fitness_cases[i]->val[2] and so on...
                    >
                    > Confusion between app_fitness_cases[i] and FITNESS app_fitness_cases;
                    > if I use app_fitness_cases.val[1], this works fine but for only one
                    > of the four vals

                    In c code when referring to a field in a structure (typedef) you use
                    the '.' to connect the typedef variable to the field in that typedef.

                    void localfunc()
                    {
                    FITNESS app_fitness;
                    app_fitness.val[0] = 1.0; // this is locally allocated
                    }

                    For item allocated (malloc) in program memory (heap) you use the
                    '->' to connect the variable to the field.

                    void pointerfunc()
                    {
                    FITNESS *app_fitness;
                    app_fitness = (FITNESS*) malloc(sizeof(FITNESS));
                    app_fitness->val[0] = 1.0; // this is allocated in program memory (heap)
                    }

                    Does that help?

                    Mike
                  • eiram_elahi
                    Hi, yes, but I was having some problems with one bit of your code: app_fitness_cases[i]- val[o], app_fitness_cases[i]- val [1],app_fitness_cases[i]- val[2] and
                    Message 9 of 9 , May 23, 2003
                    • 0 Attachment
                      Hi,

                      yes, but I was having some problems with one bit of your code:

                      app_fitness_cases[i]->val[o], app_fitness_cases[i]->val
                      [1],app_fitness_cases[i]->val[2] and so on...

                      Confusion between app_fitness_cases[i] and FITNESS app_fitness_cases;
                      if I use app_fitness_cases.val[1], this works fine but for only one
                      of the four vals

                      Thanks



                      --- In genetic_programming@yahoogroups.com, Mike Eggleston
                      <mikee@m...> wrote:
                      > On Fri, 23 May 2003, eiram_elahi wrote:
                      >
                      > > Hi Mike
                      > > It happens in the following:
                      > >
                      > >
                      > > for(i=0;i< fitness_cases; i++);
                      > > g.x = app_fitness_cases[0][i]; //this is the independent
                      variable
                      > > and this is where the code is corrupt...
                      > > v=evaluate_tree (ind ->tr[o].data,0);
                      > > y= app_fitness_cases[1][i]; // this is the known value for the
                      > > dependent variable
                      > > disp = fabs(y-v);
                      > > if (disp->value_cutoff) //set to 1e15 in .epg
                      > > {
                      > > ind->r_fitness +=disp;
                      > > if(disp <= value_cutoff)
                      > > ++ind->hits;
                      > > }
                      > > else
                      > > {
                      > > ind ->r_fitness = fitness_cases += value_cutoff;
                      > > }
                      > > }
                      > > ind->s_fitness = ind->r_fitness;
                      > > ind a_fitness = 1.0/(1.0+ind->s_fitness);
                      > > ind->evald = EVAL_CACHE_VALID;
                      > > }
                      >
                      > In the code I sent you, you would not reference the values as
                      app_fitness_cases[0][i].
                      > You would reference the individual values as app_fitness_cases[i]-
                      >val[0] for
                      > the first value and app_fitness_cases[i]->val[3] for the fourth
                      value.
                      >
                      > Mike
                    Your message has been successfully submitted and would be delivered to recipients shortly.