public IList <IChromosome <T> > Solve <T>(IList <IChromosome <T> > population) { if (population.Count == 0) { return(population); } var currentPopulation = population.Clone(); do { var newPopulation = new List <IChromosome <T> >(); while (newPopulation.Count < _parameters.PopulationSize) { var selected = SelectionMethod.Selection(currentPopulation); var chromozome = CrossoverAlgorithm.RunCrossover(selected.Item1, selected.Item2, _parameters.CrossOverProbability); chromozome = MutationAlgorithm.RunMutation(chromozome, _parameters.MutationProbability); chromozome.FintnessValue = EvaluationMethod.Evaluate(chromozome); newPopulation.Add(chromozome); } currentPopulation = newPopulation; } while (!Convirged()); return(currentPopulation); }
public Genome CreateOffspring(float ignoreRatio) { Subject parent1 = GetProportionalRandomParent(ignoreRatio); Subject parent2 = GetProportionalRandomParent(ignoreRatio); return(CrossoverAlgorithm.Crossover(parent1.Genome, parent2.Genome)); }
internal static Genome[] Crossover( Genome parent1, Genome parent2, CrossoverAlgorithm algorithm, bool gaussian) { switch (algorithm) { case CrossoverAlgorithm.SinglePoint: return(CrossoverNPoint(parent1, parent2, gaussian, 1)); case CrossoverAlgorithm.TwoPoint: return(CrossoverNPoint(parent1, parent2, gaussian, 2)); case CrossoverAlgorithm.ThreePoint: return(CrossoverNPoint(parent1, parent2, gaussian, 3)); case CrossoverAlgorithm.Linear: return(CrossoverLinear(parent1, parent2, gaussian)); case CrossoverAlgorithm.Blend: return(CrossoverBlend(parent1, parent2, gaussian)); case CrossoverAlgorithm.RandomSwap: return(CrossoverRandomSwap(parent1, parent2, gaussian)); case CrossoverAlgorithm.SBC: default: throw new ArgumentOutOfRangeException(nameof(algorithm), algorithm, null); } }
// Use this for initialization void Start() { fc = GetComponent <FitnessCalculation> (); crossover = GetComponent <CrossoverAlgorithm> (); spawnLocations = new Vector3[popSize]; for (int i = 0; i < spawnLocations.Length; i++) { spawnLocations[i].x = Random.Range(-20f, 20f); spawnLocations[i].y = Random.Range(-20f, 20f); spawnLocations[i].z = 0; } // Debug.Log ("Population Script: Loaded"); Initialize(popSize, true); }
public static void SetCrossover(CrossoverAlgorithm newCrossoverAlgorithm) { crossoverAlgorithm = newCrossoverAlgorithm; }
private void CreateChild_OnClick() { Parent1Genome.AdjustedFitness = 2; Parent2Genome.AdjustedFitness = 1; ChildGV.VisualizeGenome(CrossoverAlgorithm.Crossover(Parent1Genome, Parent2Genome), false, true); }