[galib] ga initialisation
#SAWHNEY ADITI#
aditi at pmail.ntu.edu.sg
Mon Aug 1 00:34:25 EDT 2005
hi,
i need a bit of help. I have written a program hwich incorporates a GA over an ant colony algorithm(bvasically a kind of algorithm). Now when i run my progrm after abt 4-5 populations teh program gives a fatal error saying its referencing some illegal loctaion. Below is my intialisation of teh GA and the genome using allele sets. can soemone please just check n tell me if i have made a mistake in the ga initialistaion part? my ant algorithm works perfetcly independntly thast hwy i thought it might be a mistake in the GA
-----------------------------------------------------------------------------------------
#include <GASStateGA.h>
//#include <std_stream.h>
//#define cout STD_COUT
//#define endl STD_ENDL
//#define INSTANTIATE_REAL_GENOME
#include <GARealGenome.h>
#include <GAAllele.h>
#include <string.h>
#include <stdlib.h>
//#include <stdio.h>
#include <utility>
#include <math.h>
#include <iomanip>
//#include <iostream>
#include <fstream>
#include "General.hpp"
#include "AntColonyVRP.hpp"
#define INSTANTIATE_REAL_GENOME
vector<VehInfo> vehArray;
void createVehicles(char *fileName, vector<VehInfo> &vehArray);
float Objective(GAGenome &);
int
main(int argc, char **argv)
{
// Declare variables for the GA parameters and set them to some default values.
int popsize = 10;
int ngen = 40;
float pmut = 0.02;
float pcross = 0.9;
GARealAlleleSetArray alleles;
alleles.add(0,15);
alleles.add(0,1);
alleles.add(0,1);
GARealGenome genome(alleles, Objective);
genome.mutator(GA1DArrayAlleleGenome<float>::FlipMutator);
genome.crossover(GA1DArrayAlleleGenome<float>::OnePointCrossover);
genome.initializer(GA1DArrayAlleleGenome<float>::UniformInitializer);
GAParameterList params;
//fill it with default values
GASteadyStateGA::registerDefaultParameters(params);
params.set(gaNminimaxi, GASteadyStateGA::MINIMIZE);
params.set(gaNpopulationSize, popsize); // number of individuals in population
params.set(gaNpCrossover, pcross); // likelihood of doing crossover
params.set(gaNpMutation, pmut); // probability of mutation
params.set(gaNnGenerations, ngen); // number of generations
params.set(gaNscoreFrequency, 1); // how often to record scores
params.set(gaNflushFrequency, 1); // how often to flush scores to file
params.set(gaNscoreFilename, "bog.dat");
GASteadyStateGA ga(genome);
ga.parameters(params); //register GA settings
GATournamentSelector selector;
ga.selector(selector);
ga.terminator(GAGeneticAlgorithm::TerminateUponGeneration);
ga.evolve();
genome = ga.statistics().bestIndividual();
float x1 = (float) genome.gene(0);
float x2 = (float) genome.gene(1);
float x3 = (float) genome.gene(2);
// Now we print out the best genome that the GA found.
//cout << "The GA found:\n" << ga.statistics().bestIndividual() << "\n";
printf("The GA found :%f,%f,%f,%f",x1,x2,x3 );
genome = ga.statistics().bestIndividual();
printf("%f", genome.score() );
// That's it!
return 0;
}
More information about the galib
mailing list