/*************************************************************************** main.cpp - description ------------------- begin : Thu Oct 3 11:44:13 CEST 2002 copyright : (C) 2002 by Rolland Balzon Philippe email : prolland@free.fr ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include // the header for the GA we'll use #include // and the header for the genome we need #include #define pow2i(x) ((x)<0 ? 0 : (1<<(x))) float objective(GAGenome &); int genome_bin2dec (GAGenome & ,int ); int main(int argc, char *argv[]) { cout << "Example \n\n"; cout << "This program reads in a data file a ascii \n"; cout << "graph file then runs a simple GA whose \n"; cout << "objective function tries to color the graph\n"; cout << "By option option: f path_of_your_file_graph.txt you can load your graph.\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. for(int ii=1; ii= argc){ cerr << argv[0] << ": the file option needs a filename.\n"; exit(1); } else{ sprintf(filename, argv[i]); continue; } } else if(strcmp("seed", argv[i]) == 0){ if(++i < argc) continue; continue; } else { cerr << argv[0] << ": unrecognized arguement: " << argv[i] << "\n\n"; cerr << "valid arguments include standard GAlib arguments plus:\n"; cerr << " f\tfilename from which to read (" << filename << ")\n"; cerr << "\n"; exit(1); } } ManyGraphBin aGraphSet(filename); //aGraphSet.display_all_graphBin(); printf("\n _nb_graph=%d\n", aGraphSet._nb_graph); //printf("\n _nb_graph=%d\n", aGraphSet._nb_graph); // for(int g=0;g < aGraphSet._nb_graph;g++){ for(int g=0;g < 1;g++){ OneGraphBin * aGraphBin = new OneGraphBin(); aGraphBin = aGraphSet.selectOneGraphBin(g); short **target=aGraphBin->_mat; int width=aGraphBin->_n; int height=width; GA2DBinaryStringGenome genome(width, height, objective, (void *)target); GASimpleGA ga(genome); GASigmaTruncationScaling scaling; ga.parameters(params); ga.populationSize(popsize); ga.nGenerations(ngen); ga.pMutation(pmut); ga.pCrossover(pcross); ga.scaling(scaling); ga.evolve(); //cout << "best of generation data are in '" << ga.scoreFilename() << "'\n"; genome = ga.statistics().bestIndividual(); aGraphBin->coloration (genome) ; aGraphBin->nb_color(genome.nb_color); //printf("\n genome.nb_color %d",genome.nb_color); //cout << "the ga generated:\n"; //aGraphSet.display_target (aGraphSet.selectOneGraphBin(g)); //exit(0); } aGraphSet.display_all_graphBin(); return 0; } int genome_bin2dec (GAGenome & c,int k) { GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)c; int temp =0; for (int i=0; itab[j+1]){tmp= tab[j+1];tab[j+1]=tab[j];tab[j]=tmp;} } } genome.nb_color=0; //printf("\n\n"); for(int i=0;i