📄 gaincga.h
字号:
// $Header$/* ---------------------------------------------------------------------------- gainc.h mbwall 28jul94 Copyright (c) 1995 Massachusetts Institute of Technology all rights reserved Header file for the incremental genetic algorithm class.replacement The replacement strategy defines how the new children will be stuck into thepopulation. If you want the new child to replace one of its parents, usethe Parent strategy. If you want the child to replace a random populationmember, use the Random strategy. If you want the child to replace the worstpopulation member, use the Worst strategy. These are meaningful only foroverlapping populations. To do DeJong-style speciation (crowding), use theCrowding strategy. You must also specify a crowding function as the replacement function if you choose this strategy. If you use Custom as thereplacement strategy you must also specify a replacement function. Note that not every replacement scheme can be used with every type ofgenetic algorithm. If a GA supports replacement schemes, it will specifywhich schemes are valid and which are not. The replacement function is required for crowding and custom replacementstrategies. This function is used to pick which genome will be replaced. The first argument passed to the replacement function is theindividual that is supposed to go into the population. The second argumentis the population into which the individual is supposed to go.The replacement function should return a reference to the genome that theindividual should replace. If no replacement should take place, thereplacement function should return a reference to the individual.---------------------------------------------------------------------------- */#ifndef _ga_gainc_h_#define _ga_gainc_h_#include "GABaseGA.h"class GAIncrementalGA : public GAGeneticAlgorithm {public: GADefineIdentity("GAIncrementalGA", GAID::IncrementalGA); typedef GAGenome & (*ReplacementFunction)(GAGenome&, GAPopulation&); enum ReplacementScheme { RANDOM = GAPopulation::RANDOM, BEST = GAPopulation::BEST, WORST = GAPopulation::WORST, CUSTOM = -30, CROWDING = -30, PARENT = -10 }; static GAParameterList& registerDefaultParameters(GAParameterList&);public: GAIncrementalGA(const GAGenome&); GAIncrementalGA(const GAPopulation&); GAIncrementalGA(const GAIncrementalGA&); GAIncrementalGA& operator=(const GAIncrementalGA&); virtual ~GAIncrementalGA(); virtual void copy(const GAGeneticAlgorithm &); virtual void initialize(unsigned int seed=0); virtual void step(); GAIncrementalGA & operator++() { step(); return *this; } virtual int setptr(const char* name, const void* value); virtual int get(const char* name, void* value) const; virtual void objectiveFunction(GAGenome::Evaluator f); virtual void objectiveData(const GAEvalData& v); int nOffspring() const {return noffspr;} int nOffspring(unsigned int); ReplacementScheme replacement() const {return rs;} ReplacementScheme replacement(ReplacementScheme, ReplacementFunction f=0);protected: GAGenome *child1, *child2; // children that will be generated each gen ReplacementScheme rs; // replacement strategy ReplacementFunction rf; // (optional) replacement function unsigned int noffspr; // number of children to generate in crossover};#ifdef GALIB_USE_STREAMSinline STD_OSTREAM & operator<< (STD_OSTREAM & os, GAIncrementalGA & arg){ arg.write(os); return(os); }inline STD_ISTREAM & operator>> (STD_ISTREAM & is, GAIncrementalGA & arg){ arg.read(is); return(is); }#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -