コード例 #1
0
    public override void InitPopulation()
    {
        maxNumberOfEvaluations = Mathf.Min(maxNumberOfEvaluations, populationSize);


        populationRed  = new List <Individual> ();
        populationBlue = new List <Individual>();

        while (populationRed.Count < populationSize)
        {
            HillClimberIndividual new_ind_red  = new HillClimberIndividual(NNTopology, maxNumberOfEvaluations, mutationMethod);
            HillClimberIndividual new_ind_blue = new HillClimberIndividual(NNTopology, maxNumberOfEvaluations, mutationMethod);
            if (seedPopulationFromFile)
            {
                NeuralNetwork nnRed  = getRedIndividualFromFile();
                NeuralNetwork nnBlue = getBlueIndividualFromFile();
                new_ind_red.Initialize(nnRed);
                new_ind_blue.Initialize(nnBlue);
                //only the first individual is an exact copy. the other are going to suffer mutations
                if (populationRed.Count != 0 && populationBlue.Count != 0)
                {
                    new_ind_red.Mutate(mutationProbabilityRedPopulation);
                    new_ind_blue.Mutate(mutationProbabilityBluePopulation);
                }
            }
            else
            {
                new_ind_red.Initialize();
                new_ind_blue.Initialize();
            }

            populationRed.Add(new_ind_red);
            populationBlue.Add(new_ind_blue);
        }
    }
コード例 #2
0
    private void SwapGenes(HillClimberIndividual partner, int num)
    {
        float aux;

        aux = partner.genotype[num];
        partner.genotype[num] = this.genotype[num];
        this.genotype[num]    = aux;
    }
コード例 #3
0
    public override Individual Clone()
    {
        HillClimberIndividual new_ind = new HillClimberIndividual(this.topology);

        genotype.CopyTo(new_ind.genotype, 0);
        new_ind.fitness   = this.Fitness;
        new_ind.evaluated = false;
        return(new_ind);
    }
コード例 #4
0
 public override void InitPopulation()
 {
     population = new List <Individual> ();
     while (population.Count < populationSize)
     {
         HillClimberIndividual new_ind = new HillClimberIndividual(topology);
         new_ind.Initialize();
         population.Add(new_ind);
     }
 }
コード例 #5
0
    public override Individual Clone()
    {
        HillClimberIndividual new_ind = new HillClimberIndividual(this.topology, this.maxNumberOfEvaluations, this.mutation);

        genotype.CopyTo(new_ind.genotype, 0);
        new_ind.fitness              = this.Fitness;
        new_ind.evaluated            = false;
        new_ind.completedEvaluations = 0;
        return(new_ind);
    }
コード例 #6
0
 public override void InitPopulation()
 {
     Debug.Log("Estou a inicializar no HillClimber");
     population = new List <Individual> ();
     // jncor
     while (population.Count < populationSize)
     {
         HillClimberIndividual new_ind = new HillClimberIndividual(topology);
         new_ind.Initialize();
         population.Add(new_ind);
     }
 }
コード例 #7
0
    //The Step function assumes that the fitness values of all the individuals in the population have been calculated.
    public override void Step()
    {
        List <Individual> new_pop = new List <Individual> ();

        updateReport();          //called to get some stats
        // fills the rest with mutations of the best !
        for (int i = 0; i < populationSize; i++)
        {
            HillClimberIndividual tmp = (HillClimberIndividual)overallBest.Clone();
            tmp.Mutate(mutationProbability);
            new_pop.Add(tmp.Clone());
        }

        population = new_pop;

        generation++;
    }
コード例 #8
0
	//The Step function assumes that the fitness values of all the individuals in the population have been calculated.
	public override void Step()
	{
		List<Individual> newPopRed = new List<Individual> ();
        List<Individual> newPopBlue = new List<Individual>();

        updateReport (); //called to get some stats
		// fills the rest with mutations of the best !
		for (int i = 0; i < populationSize ; i++) {
			HillClimberIndividual tmpRed = (HillClimberIndividual) overallBestRed.Clone ();
            HillClimberIndividual tmpBlue = (HillClimberIndividual) overallBestBlue.Clone();
            tmpRed.Mutate (mutationProbabilityRedPopulation);
            tmpBlue.Mutate(mutationProbabilityBluePopulation);
            newPopRed.Add (tmpRed.Clone());
            newPopBlue.Add(tmpBlue.Clone());
        }

		populationRed = newPopRed;
        populationBlue = newPopBlue;

        generation++;
	}