public void PerformCrossover(ref IGenoType genoTypeLeft, ref IGenoType genoTypeRight) { if ((new PhenoTypeTree(genoTypeLeft.GenoTypeNodes)).ToString().Equals((new PhenoTypeTree(genoTypeRight.GenoTypeNodes)).ToString())) { return; } // var left1 = new PhenoTypeTree(genoTypeLeft.GenoTypeNodes).ToString(); // var right1 = new PhenoTypeTree(genoTypeRight.GenoTypeNodes).ToString(); if (!(UniformRandomGenerator.GetContinousRandomNumber(0, 1.0) <= EaGeneExpressionParameters.CrossoverProbability)) { return; } if (UniformRandomGenerator.GetContinousRandomNumber(0, 1.0) < 0.5) { var numberOfNodes = PhenoTypeTree.GetNumberOfNodes(genoTypeLeft.GenoTypeNodes); var crossOverPosition1 = UniformRandomGenerator.GetIntegerRandomNumber(0, numberOfNodes - 1); if (UniformRandomGenerator.GetContinousRandomNumber(0, 1.0) < 0.1) { for (var index = crossOverPosition1; index < genoTypeLeft.GenoTypeNodes.Count; index++) { Swap(genoTypeLeft.GenoTypeNodes, genoTypeRight.GenoTypeNodes, index); } } else { for (var index = 0; index <= crossOverPosition1; index++) { Swap(genoTypeLeft.GenoTypeNodes, genoTypeRight.GenoTypeNodes, index); } } } else { var crossOverPosition1 = UniformRandomGenerator.GetIntegerRandomNumber(1, genoTypeLeft.GenoTypeNodes.Count - 2); var crossOverPosition2 = UniformRandomGenerator.GetIntegerRandomNumber(crossOverPosition1, genoTypeLeft.GenoTypeNodes.Count - 2); for (var index = crossOverPosition1; index < crossOverPosition2; index++) { Swap(genoTypeLeft.GenoTypeNodes, genoTypeRight.GenoTypeNodes, index); } } // var left2 = new PhenoTypeTree(genoTypeLeft.GenoTypeNodes).ToString(); // var right2 = new PhenoTypeTree(genoTypeRight.GenoTypeNodes).ToString(); }
public void PerformMutation(ref IGenoType genoType) { if (!(UniformRandomGenerator.GetContinousRandomNumber(0, 1.0) <= EaGeneExpressionParameters.MutationProbability)) { return; } var randomNumber = UniformRandomGenerator.GetContinousRandomNumber(0, 1.0); if (randomNumber <= 0.3) { genoType = GenoTypeFactory.GetGenoType(); } else { //var index = UniformRandomGenerator.GetIntegerRandomNumber(0, genoType.GenoTypeNodes.Count - 1); var numberOfNodes = PhenoTypeTree.GetNumberOfNodes(genoType.GenoTypeNodes); var index = UniformRandomGenerator.GetIntegerRandomNumber(0, numberOfNodes - 1); if (randomNumber <= 0.6) { var node = genoType.GenoTypeNodes[index]; genoType.GenoTypeNodes.RemoveAt(index); index = UniformRandomGenerator.GetIntegerRandomNumber(0, genoType.GenoTypeNodes.Count - 1); genoType.GenoTypeNodes.Insert(index, node); } else { if (genoType.GenoTypeNodes[index].GetType() == typeof(ParameterTerminal)) { ((ParameterTerminal)genoType.GenoTypeNodes[index]).Value = ((ParameterTerminal)genoType.GenoTypeNodes[index]).Value + UniformRandomGenerator.GetContinousRandomNumber(-3.0, 3.0); } else { if (index < EaGeneExpressionParameters.MaximumNumberOfHeadNodes) { genoType.GenoTypeNodes[index] = GenoTypeFactory.GetFunctionOrTerminalNode(); } else { genoType.GenoTypeNodes[index] = GenoTypeFactory.GetTerminalNode(); } } } } }
public Individual(IGenoType genoType) { Guid = Guid.NewGuid(); GenoType = genoType; }