⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pop.h

📁 Genetic Algorithm (GA) based solver for the Traveling Salesman Problem
💻 H
字号:
// pop.h// Declaration of class Pop// Thomas Pederson, 950505#ifndef POP#define POP#include "global.h"#include "chromo.h"#include <iostream.h>class Pop{public:   Pop(int _popSize, unsigned int _chromoLength, Gene *_genePool[]);   ~Pop();      // Population initialization.   void init();   // Calculates (if necessary) fitness for each chromosome in the   // population and returns the sum of the fitness values.   eval_long_t fitness(fitness_t fitnessType, eval_t fitnessParam);   // Creates a new population using this population as a parent pool   // and returns a pointer to the new population.   // If deletionType == deleteAll, the user of this class has to   // delete this population (the new one is really a _new_ one).   // If deletionType == steadyDelete, the old population is altered   // and thus, requires no further action by the user.   Pop *newPop(fitness_t fitnessType, eval_t fitnessParam,	       float crossover, cross_t crossoverType, float mutation,	       delete_t deletionType, int elitismValue);   // Returns the fitness of the best cromosome in the population.   eval_t bestFitness() {return myChromoPool[0]->getEval();}   // Returns the modified fitness of the best cromosome in the population.   eval_t bestFitnessMod() {return myChromoPool[0]->getModEval();}   // Returns the average chromosome fitness of the population.   eval_t fitnessAverage();   // Returns the average modified chromosome fitness of the population.   eval_t fitnessAverageMod() {return (eval / popSize);}   // Returns the best chromosome in the population.   Chromo& bestChromo() {return *myChromoPool[0];}      Chromo **myChromoPool; // Chromosome vector   // (has to be public for some reason I can't remember at the time beeing)   // Prints population information to stream.   friend ostream& operator<<(ostream& outStr, Pop& pop);   private:   Gene **genePool; // pointer to original gene pool vector   unsigned int chromoLength; // length of chromosomes in the population   eval_long_t eval; // sum of all chromosome evaluation values   int popSize; // number of chromosomes in the population   // Returns a suitable parent using Roulette Wheel Selection.   Chromo& getParent();   // Sorts chromosome pool in fitness order.   void quickSort(int start, int finish);};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -