00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using GEP.Core.Common; 00006 00007 namespace GEP.Core.Float 00008 { 00017 [Serializable] 00018 public class Population : Common.Population 00019 { 00029 internal float[] _linearStructureValues; 00034 internal ConstantsSetMutation _constantsSetMutation; 00035 00063 public Population(int n_Genes, int headLength, int n_generations, Common.Alphabet functionsSet, Common.Alphabet variablesSet, 00064 Common.Alphabet constantsSet, double[] symbolSetsProbabilityDistribution, Common.Symbol genesLinkingFunction, 00065 OperatorsSet operators, ConstantsSetMutation constantsSetMutation) 00066 : base(n_Genes, headLength, n_generations, functionsSet, variablesSet, 00067 constantsSet, symbolSetsProbabilityDistribution, genesLinkingFunction, operators) 00068 { 00069 _constantsSetMutation = constantsSetMutation; 00070 if (constantsSetMutation != null && constantsSetMutation._mutationSequence != null) 00071 { 00072 constantsSetMutation.GenerateMutationSequence(); 00073 } 00074 } 00075 00076 public override void Initialize(int populationSize) 00077 { 00078 _generation = 0; 00079 _genotypes = new Genotype[populationSize]; 00080 Random random = new Random(); 00081 _linearStructureValues = new float[_headLength + _tailLength]; 00082 _functionStack = new int[(_headLength + 2) * 2]; 00083 for (int i = 0; i < populationSize; i++) 00084 { 00085 _genotypes[i] = new Genotype(this); 00086 _genotypes[i].Initialize(random, _functionsSet, _variablesSet, _constantsSet, 00087 _symbolSetsProbabilityDistribution); 00088 } 00089 _fittest = _genotypes[0]; 00090 } 00091 00092 protected override void MutateConstants() 00093 { 00094 if (_constantsSetMutation == null) 00095 return; 00096 if (!_constantsSetMutation.HasMore()) 00097 _constantsSetMutation.GenerateMutationSequence(); 00098 _constantsSetMutation.Next(); 00099 } 00100 } 00101 }