[galib] Bug in GADemeGA::nPopulations ?

Nuissl, Tobias (ext.) ST/HZA-EWBP nuisstbi at schaeffler.com
Tue Sep 18 06:00:55 EDT 2012


Dear Mr. Wall,

in my work with your Library GALib, I experienced some problem while using GADemeGA:

When using an arbitrary number of populations for deme (for example the default value of 10) in combination with an arbitrary number of individuals per population (which can be set via gaNpopulationSize), the number of populations for deme does (of course) not necessarily match the number of individuals in pop.

In the current version, GADemeGA::nPopulatio with n=npop does not do anything but returning that value (GADemeGA.C - line 252).

So in some cases there could happen an access violation while initializing the GEDeme object due to the copy process pop->individual(i).copy(deme[i]->best()) (GADemeGA.C - line 335) when the number of individuals in pop is smaller then the number of populations in deme.

In my opinion the function int GADemeGA::nPopulations(unsigned int n) (GADemeGA.C - lines 250-299) should be changed according to the red annotations below, to assure the numbers of populations and the individuals per population always fit each other (even when n=npop, where not necessarily npop=pop->size):

     int
     GADemeGA::nPopulations(unsigned int n) {
       if(n < 1 || n == npop) return npop;
       if(n < npop) {
         for(unsigned int i=n; i<npop; i++)
           delete deme[i];
         GAPopulation** ptmp = deme;
         deme = new GAPopulation* [n];
         memcpy(deme, ptmp, n * sizeof(GAPopulation*));
         delete [] ptmp;

         GAStatistics* stmp = pstats;
         pstats = new GAStatistics[n];
         for(unsigned int j=0; j<n; j++)
           pstats[j] = stmp[j];
         delete [] stmp;

         int* rtmp = nrepl;
         nrepl = new int[n];
         memcpy(nrepl, rtmp, n * sizeof(int));
         delete [] rtmp;

         npop = n;
       }
       else if (n > npop) {
         GAPopulation** ptmp = deme;
         deme = new GAPopulation* [n];
         memcpy(deme, ptmp, npop * sizeof(GAPopulation*));
         delete [] ptmp;
         for(unsigned int i=npop; i<n; i++)
           deme[i] = new GAPopulation(*deme[GARandomInt(0,npop-1)]);

         GAStatistics* stmp = pstats;
         pstats = new GAStatistics[n];
         for(unsigned int j=0; j<npop; j++)
           pstats[j] = stmp[j];
         delete [] stmp;

         int* rtmp = nrepl;
         nrepl = new int[n];
         memcpy(nrepl, rtmp, npop * sizeof(int));
         for(unsigned int k=npop; k<n; k++)
           nrepl[k] = nrepl[0];

         npop = n;
       }
       params.set(gaNnPopulations, (unsigned int)n);
       pop->size(npop);
       return npop;
     }

I am looking forward to receiving an answer with your opinion to this situation.

Best regards

Tobias Nuißl
Technische IT · CAE-Werkzeuge · Programmentwicklung (ext.)

Schaeffler Technologies AG & Co. KG
Industriestraße 1-3
91074 Herzogenaurach (Germany)
Tel. +49 9132 82-7575
mailto:nuisstbi at schaeffler.com  ·  http://www.ina.de<http://www.ina.de/>

Sitz: Herzogenaurach
Registergericht: AG Fürth HRA 9349

Persönlich haftende Gesellschafterin: Schaeffler AG
Sitz: Herzogenaurach
Registergericht: AG Fürth HRB 13202

Executive Board:
Dr. Jürgen M. Geißinger (Vors.)*, Wolfgang Dangel*, Prof. Dr. Peter Gutzmer*,
Kurt Mirlach*, Klaus Rosenfeld*, Robert Schullan*, Norbert Indlekofer, Oliver Jung, Prof. Dr. Peter Pleus, Dr. Gerhard Schuff
*Vorstand

Diese Information ist für den Gebrauch durch die Person oder die Firma/Organisation bestimmt, die in der Empfängeradresse benannt ist und unterliegt u. U. dem Betriebsgeheimnis, dem Schutz von Arbeitsergebnissen oder anderweitigem rechtlichen Schutz. Wenn Sie nicht der angegebene Empfänger sind, nehmen Sie bitte zur Kenntnis, dass Weitergabe, Kopieren, Verteilung oder Nutzung des Inhalts dieser E-Mail-Übertragung unzulässig ist. Falls Sie diese E-Mail irrtümlich erhalten haben, benachrichtigen Sie den Absender bitte unverzüglich telefonisch oder durch eine E-Mail und löschen Sie diese Information aus Ihrem EDV-System.

This e-mail message is intended only for the use of the named recipient(s) and contains information which may be confidential or privileged. If you are not the intended recipient, be aware that any distribution, or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify the sender and delete the material from the computer.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/galib/attachments/20120918/65844368/attachment.htm


More information about the galib mailing list