Problems compiling the examples

Petrakos P. Kyriakos petrakos at ceid.upatras.gr
Thu May 24 07:38:54 EDT 2001


Kyle, 
	Thank you for your help...it was quit useful.I have followed your
instructions and managed to reduce the number of errors.But I still have
some problems. For instance, during the compilation of ex1.C file, which
is included in galib\examples direcotry, I receive the following strange
error: 

--------------------------------------------------------------------------------------------
Compiling...
ex1.C
c:\windows\desktop\ex1.c(70) : error C2679: binary '<<' : no operator
defined which takes a right-hand operand of type 'const class GAGenome'
(or there is no acceptable conversion)
Error executing cl.exe.
--------------------------------------------------------------------------------------------

In contrast with ex1.C file, I face no problems with the compilation of
the ex2.C file in the same directory. But when trying to link the .obj
file, I receive the following error messages: 

--------------------------------------------------------------------------------------------
Linking...
ex2.obj : error LNK2001: unresolved external symbol "public: virtual
__thiscall GASimpleGA::~GASimpleGA(void)" (??1GASimpleGA@@UAE at XZ)
ex2.obj : error LNK2001: unresolved external symbol "public: class
GAGenome const & __thiscall GAStatistics::bestIndividual(unsigned
int)const " (?bestIndividual at GAStatistics@@QBEABVGAGenome@@I at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: float
__thiscall GABin2DecGenome::phenotype(unsigned int)const
" (?phenotype at GABin2DecGenome@@QBEMI at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual int
__thiscall GASimpleGA::populationSize(unsigned
int)" (?populationSize at GASimpleGA@@UAEHI at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: __thiscall
GASimpleGA::GASimpleGA(class GAGenome const
&)" (??0GASimpleGA@@QAE at ABVGAGenome@@@Z)
ex2.obj : error LNK2001: unresolved external symbol "public: void
__thiscall GABin2DecPhenotype::add(unsigned
int,float,float)" (?add at GABin2DecPhenotype@@QAEXIMM at Z)
ex2.obj : error LNK2001: unresolved external symbol "void __cdecl
GARandomSeed(unsigned int)" (?GARandomSeed@@YAXI at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: void
__thiscall
GAStatistics::flushScores(void)" (?flushScores at GAStatistics@@QAEXXZ)
ex2.obj : error LNK2001: unresolved external symbol "public: int
__thiscall GAParameterList::set(char const *,void const
*)" (?set at GAParameterList@@QAEHPBDPBX at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: int
__thiscall GAParameterList::set(char const
*,double)" (?set at GAParameterList@@QAEHPBDN at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: int
__thiscall GAStatistics::flushFrequency(unsigned
int)" (?flushFrequency at GAStatistics@@QAEHI at Z)
ex2.obj : error LNK2001: unresolved external symbol "float __cdecl
ran2(void)" (?ran2@@YAMXZ)
ex2.obj : error LNK2001: unresolved external symbol "public: __thiscall
GABin2DecPhenotypeCore::GABin2DecPhenotypeCore(void)" (??0GABin2DecPhenotypeCore@@QAE at XZ)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual int
__thiscall GABin2DecGenome::notequal(class GAGenome const &)const
" (?notequal at GABin2DecGenome@@UBEHABVGAGenome@@@Z)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual int
__thiscall GABin2DecGenome::equal(class GAGenome const &)const
" (?equal at GABin2DecGenome@@UBEHABVGAGenome@@@Z)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual void
__thiscall GABin2DecGenome::copy(class GAGenome const
&)" (?copy at GABin2DecGenome@@UAEXABVGAGenome@@@Z)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual class
GAGenome * __thiscall GABin2DecGenome::clone(enum
GAGenome::CloneMethod)const
" (?clone at GABin2DecGenome@@UBEPAVGAGenome@@W4CloneMethod at 2@@Z)
ex2.obj : error LNK2001: unresolved external symbol "public: virtual
__thiscall
GA1DBinaryStringGenome::~GA1DBinaryStringGenome(void)" (??1GA1DBinaryStringGenome@@UAE at XZ)
ex2.obj : error LNK2001: unresolved external symbol "int __cdecl
GABinaryDecode(float &,unsigned char const *,unsigned
int,float,float)" (?GABinaryDecode@@YAHAAMPBEIMM at Z)
ex2.obj : error LNK2001: unresolved external symbol "int __cdecl
GABinaryEncode(float &,unsigned char *,unsigned
int,float,float)" (?GABinaryEncode@@YAHAAMPAEIMM at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: static float
__cdecl GA1DBinaryStringGenome::BitComparator(class GAGenome const &,class
GAGenome const
&)" (?BitComparator at GA1DBinaryStringGenome@@SAMABVGAGenome@@0 at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: __thiscall
GA1DBinaryStringGenome::GA1DBinaryStringGenome(unsigned int,float
(__cdecl*)(class GAGenome &),void
*)" (??0GA1DBinaryStringGenome@@QAE at IP6AMAAVGAGenome@@@ZPAX at Z)
ex2.obj : error LNK2001: unresolved external symbol "public: __thiscall
GABin2DecPhenotypeCore::GABin2DecPhenotypeCore(class
GABin2DecPhenotypeCore const &)" (??0GABin2DecPhenotypeCore@@QAE at ABV0@@Z)
Debug/ex2.exe : fatal error LNK1120: 23 unresolved externals
Error executing link.exe.

ex2.exe - 24 error(s), 0 warning(s)
--------------------------------------------------------------------------------------------

The result is that the .exe file cannot be created. Is anyone aware of
what is going wrong? For the sake of conception, I also attach the two
files mentioned abobe (it ) ...
Your help would be extremely useful, as I am constantly engaging with
evolutionary computing this period, and I am obliged to implement some
classes by myself, as I cannot use Galib.

       Thank you in advance.




  |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=|
  |                    Petrakos Kyriakos                    | 
  |       Computer Engineering and Informatics Dept.        |
  |             University of Patras - Greece               |
  |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=|
  |"What we cannot speak about we must pass over in silence"| 
  |                     L. Wittgenstein                     |
  |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=|
-------------- next part --------------
/* ----------------------------------------------------------------------------
  ex1.C
  mbwall 28jul94
  Copyright (c) 1995-1996  Massachusetts Institute of Technology

 DESCRIPTION:
   Example program for the SimpleGA class and 2DBinaryStringGenome class.
This program tries to fill the 2Dgenome with alternating 1s and 0s. 
  This example uses the default crossover (single point), default mutator
(uniform random bit flip), and default initializer (uniform random) for the
2D genome.
  Notice that one-point crossover is not necessarily the best kind of crossover
to use if you want to generate a 'good' genome with this kind of objective 
function.  But it does work.
---------------------------------------------------------------------------- */
#include <stdio.h>
#include <iostream.h>

#include <ga/GASimpleGA.h>	// we're going to use the simple GA
#include <ga/GA2DBinStrGenome.h> // and the 2D binary string genome

float Objective(GAGenome &);	// This is the declaration of our obj function.
				// The definition comes later in the file.

int
main(int argc, char **argv)
{
  cout << "Example 1\n\n";
  cout << "This program tries to fill a 2DBinaryStringGenome with\n";
  cout << "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();

// See if we've been given a seed to use (for testing purposes).  When you
// specify a random seed, the evolution will be exactly the same each time
// you use that seed number.

  for(int ii=1; ii<argc; ii++) {
    if(strcmp(argv[ii++],"seed") == 0) {
      GARandomSeed((unsigned int)atoi(argv[ii]));
    }
  }

// Declare variables for the GA parameters and set them to some default values.

  int width    = 10;
  int height   = 5;
  int popsize  = 30;
  int ngen     = 400;
  float pmut   = 0.001;
  float pcross = 0.9;

// Now create the GA and run it.  First we create a genome of the type that
// we want to use in the GA.  The ga doesn't operate on this genome in the
// optimization - it just uses it to clone a population of genomes.

  GA2DBinaryStringGenome genome(width, height, Objective);

// Now that we have the genome, we create the genetic algorithm and set
// its parameters - number of generations, mutation probability, and crossover
// probability.  And finally we tell it to evolve itself.

  GASimpleGA ga(genome);
  ga.populationSize(popsize);
  ga.nGenerations(ngen);
  ga.pMutation(pmut);
  ga.pCrossover(pcross);
  ga.evolve();

// Now we print out the best genome that the GA found.

  cout << "The GA found:\n" << ga.statistics().bestIndividual() << "\n";

// That's it!
  return 0;
}
 



// This is the objective function.  All it does is check for alternating 0s and
// 1s.  If the gene is odd and contains a 1, the fitness is incremented by 1.
// If the gene is even and contains a 0, the fitness is incremented by 1.  No
// penalties are assigned. 
//   We have to do the cast because a plain, generic GAGenome doesn't have 
// the members that a GA2DBinaryStringGenome has.  And it's ok to cast it
// because we know that we will only get GA2DBinaryStringGenomes and
// nothing else.

float
Objective(GAGenome& g) {
  GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g;
  float score=0.0;
  int count=0;
  for(int i=0; i<genome.width(); i++){
    for(int j=0; j<genome.height(); j++){
      if(genome.gene(i,j) == 0 && count%2 == 0)
	score += 1.0;
      if(genome.gene(i,j) == 1 && count%2 != 0)
	score += 1.0;
      count++;
    }
  }
  return score;
}
-------------- next part --------------
/* ----------------------------------------------------------------------------
  ex2.C
  mbwall 28jul94
  Copyright (c) 1995-1996  Massachusetts Institute of Technology

 DESCRIPTION:
   Example program for the SimpleGA class and Bin2DecGenome class.  This
program generates randomly a series of numbers then tries to match those
values in a binary-to-decimal genome.  We use a simple GA (with linear
scaled fitness selection and non-steady-state population generation) and
binary-to-decimal, 1D genomes.  We also use the userData argument to the
objective function.
---------------------------------------------------------------------------- */
#include <stdio.h>
#include <iostream.h>
#include <fstream.h>
#include <math.h>

#include <ga/GASimpleGA.h>
#include <ga/GABin2DecGenome.h>

float Objective(GAGenome &);

int
main(int argc, char **argv)
{
  cout << "Example 2\n\n";
  cout << "This program generates a sequence of random numbers then uses\n";
  cout << "a simple GA and binary-to-decimal genome to match the\n";
  cout << "sequence.\n\n";

// See if we've been given a seed to use (for testing purposes).  When you
// specify a random seed, the evolution will be exactly the same each time
// you use that seed number.

  unsigned int seed = 0;
  for(int ii=1; ii<argc; ii++) {
    if(strcmp(argv[ii++],"seed") == 0) {
      seed = atoi(argv[ii]);
    }
  }

// Declare variables for the GA parameters and set them to some default values.

  int popsize  = 25;
  int ngen     = 100;
  float pmut   = 0.01;
  float pcross = 0.6;

// Generate a sequence of random numbers using the values in the min and max
// arrays.  We also set one of them to integer value to show how you can get
// explicit integer representations by choosing your number of bits
// appropriately.

  GARandomSeed(seed);
  unsigned int n=7;
  float *target = new float[n];
  float min[] = {0, 0,   3, -5, 100,    0.001, 0};
  float max[] = {1, 100, 3, -2, 100000, 0.010, 7};
  unsigned int i;
  for(i=0; i<n; i++)
    target[i] = GARandomFloat(min[i], max[i]);
  target[6] = GARandomInt((int)min[6], (int)max[6]);

// Print out the sequence to see what we got.

  cout << "input sequence:\n";
  for(i=0; i<n; i++){
    cout.width(10);
    cout << target[i] << " ";
  }
  cout << "\n"; cout.flush();

// Create a phenotype then fill it with the phenotypes we will need to map to
// the values we read from the file.  The arguments to the add() method of a
// Bin2Dec phenotype are (1) number of bits, (2) min value, and (3) max value.
// The phenotype maps a floating-point number onto the number of bits that
// you designate.  Here we just make everything use 8 bits and use the max and
// min that were used to generate the target values.  You can experiment with
// the number of bits and max/min values in order to make the GA work better
// or worse.

  GABin2DecPhenotype map;
  for(i=0; i<n; i++)
    map.add(8, min[i], max[i]);

// Create the template genome using the phenotype map we just made.  The
// GA will use this genome to clone the population that it uses to do the
// evolution.  We pass the objective function to create the genome.  We 
// also use the user data function in the genome to keep track of our
// target values.

  GABin2DecGenome genome(map, Objective, (void *)target);

// Now create the GA using the genome, set the parameters, and run it.

  GASimpleGA ga(genome);
  ga.populationSize(popsize);
  ga.nGenerations(ngen);
  ga.pMutation(pmut);
  ga.pCrossover(pcross);
  ga.scoreFilename("bog.dat");
  ga.flushFrequency(50);	// dump scores to disk every 50th generation
  ga.evolve(seed);

// Dump the results of the GA to the screen.  We print out first what a random
// genome looks like (so we get a bit of a feel for how hard it is for the
// GA to find the right values) then we print out the best genome that the
// GA was able to find.

  genome.initialize();
  cout << "random values in the genome:\n";;
  for(i=0; i<map.nPhenotypes(); i++){
    cout.width(10); cout << genome.phenotype(i) << " ";
  }
  cout << "\n";

  genome = ga.statistics().bestIndividual();
  cout << "the ga generated:\n";
  for(i=0; i<map.nPhenotypes(); i++){
    cout.width(10); cout << genome.phenotype(i) << " ";
  }
  cout << "\n\n"; cout.flush();

// We could print out the genome directly, like this:
// cout << genome << "\n";

  cout << "best of generation data are in 'bog.dat'\n";

// Clean up by freeing the memory we allocated.

  delete [] target;
  return 0;
}
 

// For this objective function we try to match the values in the array of float
// that is passed to us as userData.  If the values in the genome map to 
// values that are close, we return a better score.  We are limited to positive
// values for the objective value (because we're using linear scaling - the
// default scaling method for SimpleGA), so we take the reciprocal of the 
// absolute value of the difference between the value from the phenotype and 
// the value in the sequence.
float
Objective(GAGenome& g)
{
  GABin2DecGenome & genome = (GABin2DecGenome &)g;
  float *sequence = (float *)g.userData();

  float value=genome.nPhenotypes();
  for(int i=0; i<genome.nPhenotypes(); i++)
    value += 1.0 / (1.0 + fabs(genome.phenotype(i) - sequence[i]));
  return value;
}


More information about the galib mailing list