예제 #1
0
    private void StartNewGeneration()
    {
        curGeneration++;

        finishedBotCount = 0;

        generationText.text = "Generation " + curGeneration.ToString();

        GeneScore        baseGene            = null;
        List <GeneScore> crossoverCandidates = new List <GeneScore>();

        if (geneScores.Count > 0)
        {
            List <GeneScore> orderedGenes = geneScores.OrderByDescending(x => x.score).ToList();
            UpdateLeaderBoard(orderedGenes);

            baseGene = new GeneScore(orderedGenes.First().CreateForceGeneCopy());
            List <GeneScore> mostFitting = GetMostFitting(orderedGenes.Skip(1).ToList());
            foreach (GeneScore gs in mostFitting)
            {
                crossoverCandidates.Add(new GeneScore(gs.CreateForceGeneCopy()));
            }

            geneScores = new List <GeneScore>(orderedGenes);
            CleanGeneList();
        }

        for (int i = 0; i < generationTotal; i++)
        {
            CreateNewBot(i, new Vector3(startPos.x + (i * 4), startPos.y, startPos.z), baseGene, crossoverCandidates);
        }
    }
예제 #2
0
    private List <ForceGene> GetCrossoverAndMutatedGene(GeneScore baseGene, List <GeneScore> crossoverCandidates)
    {
        GeneScore        newGene       = new GeneScore(baseGene.CreateForceGeneCopy());
        GeneScore        crossoverGene = new GeneScore(newGene.CrossOver(crossoverCandidates));
        List <ForceGene> mutatedGene   = new GeneScore(crossoverGene.Mutate()).CreateForceGeneCopy();

        return(mutatedGene);
    }
예제 #3
0
    public void RegisterGene(GeneScore geneScore)
    {
        finishedBotCount++;

        geneScores.Add(geneScore);

        if (finishedBotCount == generationTotal)
        {
            StartNewGeneration();
        }
    }
예제 #4
0
        private void HandleGenerationComplete(object sender, GenerationCompleteEventArgs args)
        {
            // Update best if necessary
            if (_bestResult == null || args.Scores[0] > _bestResult)
            {
                _bestResult = args.Scores[0];
            }

            var iterationsPerSecond = _iterationNumber / (DateTime.Now - _startDateTime).TotalSeconds;

            Strategy.Print(Strategy.Instrument.FullName + ": completed generation " + (args.GenerationNumber + 1) + "/" +
                           __lastParameters.MaximumGenerations + ", iterations per second: " +
                           iterationsPerSecond.ToString("N1") + ", max fitness this gen: " +
                           args.Scores[0].Fitness.ToString("N2"));

            _parameterWriter.Flush();
        }
예제 #5
0
    private void CreateNewBot(int curBotId, Vector3 botPos, GeneScore baseGene, List <GeneScore> crossoverCandidates)
    {
        GameObject        curBot            = Instantiate(ragdoll, botPos, Quaternion.identity) as GameObject;
        RagdollController ragdollController = curBot.GetComponent <RagdollController>();

        ragdollController.Initialize(this, "G" + curGeneration.ToString() + "B" + curBotId.ToString());

        if (baseGene == null)
        {
            ragdollController.StartMoving(GetNewGene(ragdollController.GetNumOfJoints()));
        }
        else
        {
            if (curBotId == 0)
            {
                ragdollController.StartMoving(baseGene.CreateForceGeneCopy());
            }
            else
            {
                ragdollController.StartMoving(GetCrossoverAndMutatedGene(baseGene, crossoverCandidates));
            }
        }
    }
예제 #6
0
 public IterationCompleteEventArgs(GeneScore score, int iterationNumber, int iterationsRemaining)
 {
     _score = score;
     _iterationNumber = iterationNumber;
     _iterationsRemaining = iterationsRemaining;
 }
예제 #7
0
파일: MoGoNT.cs 프로젝트: redrhino/MoGo
        private void HandleGenerationComplete(object sender, GenerationCompleteEventArgs args)
        {
            // Update best if necessary
            if (_bestResult == null || args.Scores[0] > _bestResult)
            {
                _bestResult = args.Scores[0];
            }

            var iterationsPerSecond = _iterationNumber / (DateTime.Now - _startDateTime).TotalSeconds;

            Strategy.Print(Strategy.Instrument.FullName + ": completed generation " + (args.GenerationNumber + 1) + "/" +
                           __lastParameters.MaximumGenerations + ", iterations per second: " +
                           iterationsPerSecond.ToString("N1") + ", max fitness this gen: " +
                           args.Scores[0].Fitness.ToString("N2"));

            _parameterWriter.Flush();
        }
예제 #8
0
파일: Optimiser.cs 프로젝트: redrhino/MoGo
        private bool OnIterationComplete(GeneScore score, int iterationCount, int iterationsRemaining)
        {
            if (IterationComplete != null)
            {
                var args = new IterationCompleteEventArgs(score, iterationCount, iterationsRemaining);
                IterationComplete(this, args);

                return args.Stop;
            }

            return false;
        }