Exemple #1
0
    private IEnumerator CreatePopulation()
    {
        AICreatesInitialPopulationTurn = false;
        GameObject IndividualCompositionSet = Instantiate(Individual, this.transform.position, this.transform.rotation);

        IndividualCompositionSet.GetComponent <BrainGA>().Init();
        BrainGA b = IndividualCompositionSet.GetComponent <BrainGA>();

        b.MoveComposition();

        counterForPopulation++; // COUNTER

        yield return(new WaitForSeconds(secondToWaitForPopGeneration));

        openCVmanager.CallForOpenCVCalculationUpdates(); // to update the score pixels balance of opencv..
        gameManagerNotOpenCV.CallTOCalculateNOTOpenCVScores();

        //inferenceScoreFeatures.CallTOCalculateFeaturesAllScores();
        //inferenceNNfomDATABASE.CallTOCalculateNNFrontTopcore();
        //inferenceCompositionML.CallTOCalculateMobileNetScore();
        //inferenceFinalOut.CallTOCalculateFinalOutScore();

        barracudaCNNModel.CallTOCalculateBarracudaCNNScore();
        barracudaNNfromDatabase.CallTOCalculateBarracudaNNFrontTopcore();
        barracudaOpenCvFeature.BarracudaCallTOCalculateOpencvFeaturesScore();
        barracudaFinalOut.BarracudaCallTOCalculateFinalOutScore();

        IndividualCompositionSet.GetComponent <BrainGA>().CalculateTotalScore(); /// this is where the score is updated
        population.Add(IndividualCompositionSet);


        if (counterForPopulation < populationSize)
        {
            AICreatesInitialPopulationTurn          = true;
            GenerateNewPopulatoinOffsprings_trigger = false;
        }
        else
        {
            AICreatesInitialPopulationTurn          = false; // STOP FIRST INITIAL POPULATION
            GenerateNewPopulatoinOffsprings_trigger = true;  // START NEW BREEDING to produce offsprings
        }
    }
Exemple #2
0
    private IEnumerator Breed()
    {
        // it can happen that father is equal to mother,,, too bad...
        int InternalIndex_parent1 = Random.Range((int)(sortedList.Count / From1To2), sortedList.Count);
        int InternalIndex_parent2 = Random.Range((int)(sortedList.Count / From1To2), sortedList.Count);

        parent1 = sortedList[InternalIndex_parent1];
        parent2 = sortedList[InternalIndex_parent2];

        GameObject offspring = Instantiate(Individual, this.transform.position, this.transform.rotation);

        BrainGA b = offspring.GetComponent <BrainGA>();

        if (Random.Range(0, OneIn2to10) == 1) //mutate 1 in 5
        {
            b.InitForBreed();
            b.dna.Mutate();
            b.MoveComposition(); // this is where the moved
        }
        else
        {
            b.InitForBreed();
            b.dna.Combine(parent1.GetComponent <BrainGA>().dna, parent2.GetComponent <BrainGA>().dna);
            b.MoveComposition(); // this is where the moved
        }

        yield return(new WaitForSeconds(secondToWaitForPopGeneration));

        openCVmanager.CallForOpenCVCalculationUpdates(); // to update the score pixels balance of opencv..
        gameManagerNotOpenCV.CallTOCalculateNOTOpenCVScores();

        //inferenceScoreFeatures.CallTOCalculateFeaturesAllScores();
        //inferenceNNfomDATABASE.CallTOCalculateNNFrontTopcore();
        //inferenceCompositionML.CallTOCalculateMobileNetScore();
        //inferenceFinalOut.CallTOCalculateFinalOutScore();

        barracudaCNNModel.CallTOCalculateBarracudaCNNScore();
        barracudaNNfromDatabase.CallTOCalculateBarracudaNNFrontTopcore();
        barracudaOpenCvFeature.BarracudaCallTOCalculateOpencvFeaturesScore();
        barracudaFinalOut.BarracudaCallTOCalculateFinalOutScore();

        offspring.GetComponent <BrainGA>().CalculateTotalScore(); // are updated and score

        population.Add(offspring);
        GenerateNewPopulatoinOffsprings_trigger = true;

        CounterOffsprings++;                                           // counter

        if (CounterOffsprings == populationSize)
        {
            DestroyPopulationStack();

            sortNewGeneration = true;
            CounterOffsprings = 0;
            generation++;                                             // counter
        }

        if (generation == NumberOfGeneration)
        {
            GenerateNewPopulatoinOffsprings_trigger = false;
            triggerAI = false;

            AICreatesInitialPopulationTurn = true;


            sortedList = population.OrderBy(o => o.GetComponent <BrainGA>().TotalScore).ToList();
            List <float> genes = new List <float>();
            genes.Clear();
            genes = sortedList[sortedList.Count - 1].GetComponent <BrainGA>().genes;
            sortedList[sortedList.Count - 1].GetComponent <BrainGA>().MoveCompositionOfBestFitAfterAIfinishedIsTurn(genes);

            bestScore = sortedList[sortedList.Count - 1].GetComponent <BrainGA>().TotalScore; // for debugging only

            generation           = 0;
            CounterOffsprings    = 0;
            counterForPopulation = 0;

            DESTROYPopulationOBJECTinSCENE();

            sortNewGeneration = true;

            yield return(new WaitForSeconds(secondToWaitForPopGeneration));

            openCVmanager.CallForOpenCVCalculationUpdates(); // to update the score pixels balance of opencv..
            gameManagerNotOpenCV.CallTOCalculateNOTOpenCVScores();

            //inferenceScoreFeatures.CallTOCalculateFeaturesAllScores();
            //inferenceNNfomDATABASE.CallTOCalculateNNFrontTopcore();
            //inferenceCompositionML.CallTOCalculateMobileNetScore();
            //inferenceFinalOut.CallTOCalculateFinalOutScore();

            barracudaCNNModel.CallTOCalculateBarracudaCNNScore();
            barracudaNNfromDatabase.CallTOCalculateBarracudaNNFrontTopcore();
            barracudaOpenCvFeature.BarracudaCallTOCalculateOpencvFeaturesScore();
            barracudaFinalOut.BarracudaCallTOCalculateFinalOutScore();
        }
    }