public GEPIndividual(int headLen, FunctionSet functionSet, double minVal, double maxVal, int optimizeGenerationCount) { this.functionSet = functionSet; this.optimizeGenerationCount = optimizeGenerationCount; // 计算尾部长度 int tailLen = headLen * (functionSet.MaxParamCount - 1) + 1; // 随机生成头部 gene.Add(functionSet.RandomNonterminator()); for (int i = 1; i < headLen; ++i) { gene.Add(functionSet.RandomFunction()); } // 随机生成尾部 for (int i = 0; i < tailLen; ++i) { gene.Add(functionSet.RandomTerminator()); } // 随机生成系数 for (int i = 0; i < tailLen; ++i) { coeff.Add(RandomUtil.U(minVal, maxVal)); } }
public void Mutate() { double p = 0.1; int headLen = (gene.Count - 1) / functionSet.MaxParamCount; for (int i = 0; i < headLen; ++i) { if (RandomUtil.Test(p)) { gene[i] = functionSet.RandomFunction(); } } for (int i = headLen; i < gene.Count; ++i) { if (RandomUtil.Test(p)) { gene[i] = functionSet.RandomTerminator(); } } }