Exemple #1
0
        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);
        }
Exemple #2
0
    public Genome CreateOffspring(float ignoreRatio)
    {
        Subject parent1 = GetProportionalRandomParent(ignoreRatio);
        Subject parent2 = GetProportionalRandomParent(ignoreRatio);

        return(CrossoverAlgorithm.Crossover(parent1.Genome, parent2.Genome));
    }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
    // 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);
    }
Exemple #5
0
 public static void SetCrossover(CrossoverAlgorithm newCrossoverAlgorithm)
 {
     crossoverAlgorithm = newCrossoverAlgorithm;
 }
Exemple #6
0
 private void CreateChild_OnClick()
 {
     Parent1Genome.AdjustedFitness = 2;
     Parent2Genome.AdjustedFitness = 1;
     ChildGV.VisualizeGenome(CrossoverAlgorithm.Crossover(Parent1Genome, Parent2Genome), false, true);
 }