[galib] Trying to implement ex26 into pvmind.

Moon Sup Choi totaljj at gmail.com
Fri Dec 8 06:15:54 EST 2006

I put below 2 functions to genome.c from ex26.

GenomeInitializer(GAGenome& g) {
GAListGenome<int> &child=(GAListGenome<int> &)g;
  while(child.head()) child.destroy(); // destroy any pre-existing list

  int i,town;
  static int visit[MAX_TOWNS];

  memset(visit, 0, MAX_TOWNS*sizeof(int));
  child.insert(town,GAListBASE::HEAD); // the head node

  for( i=1; i<ntowns; i++) {
    do {
    } while (visit[town]);
  }        // each subsequent node

GenomeEvaluator(GAGenome& g) {
  GAListGenome<int> & genome = (GAListGenome<int> &)g;
  float dist = 0;
  if(genome.head()) {
    for(int i=0; i<ntowns; i++) {
      int xx = *genome.current();
      int yy = *genome.next();
      dist += DISTANCE[xx][yy];
  return dist;

I also added below into genome.c and declared in genome.h.

#define MAX_TOWNS 50
#define TSP_FILE "tsp_rect_20.txt"

double x[MAX_TOWNS],y[MAX_TOWNS];
int ntowns = 0;

int   Mutator(GAGenome&, float);
float Comparator(const GAGenome&, const GAGenome&);
int   ERXover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*);
int   PMXover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*);
void  ERXOneChild(const GAGenome&, const GAGenome&, GAGenome*);

But aimk returns

g++ master.o -o master -L../. -L../../../ga -L/usr/msc501/pvm3/lib/LINUX
-lpvm3 -lga -lm
master.o(.text+0x5fc): In function `main':
../master.C:161: undefined reference to `GenomeEvaluator(GAGenome&)'
master.o(.text+0x61b): In function `main':
../../../ga/GAGenome.h:243: undefined reference to
master.o(.text+0x625):../../../ga/GAGenome.h:247: undefined reference to
`Mutator(GAGenome&, float)'master.o(.text+0x62f):../../../ga/GAGenome.h:251:
undefined reference to `Comparator(GAGenome const&, GAGenome const&)'
master.o(.text+0x639):../../../ga/GAGenome.h:253: undefined reference to
`ERXover(GAGenome const&, GAGenome const&, GAGenome*, GAGenome*)'
collect2: ld returned 1 exit status
make: *** [master] Error 1

Global variables and functions declared in genome.h should be accessible by
master and slave as they include genome.h. Shouldn't it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/galib/attachments/20061208/0cabde14/attachment.htm

More information about the galib mailing list