Exemplo n.º 1
0
 /// <summary>
 /// What to do when the run benchmarks button is pressed.
 /// </summary>
 public void OnRunBenchmarks()
 {
     PauseRun();
     // Start benchmark.
     BenchData = new List <BenchData>();
     CurrentBenchmarkBeingRan = CurrentBench.Fitness1;
     RunBenchmarks(true);
 }
Exemplo n.º 2
0
    /// <summary>
    /// What to do when initialise button is pressed.
    /// </summary>
    public void InitialiseButton()
    {
        Func <int, float> fitnessFunc = null;

        CurrentBenchmarkBeingRan = CurrentBench.DONT_RUN;
        // Get Fitness function.
        switch (FitnessDropdown.value)
        {
        case 0:
            fitnessFunc = FitnessFunction;
            break;

        case 1:
            fitnessFunc = FitnessFunction2NoFlip;
            break;
        }


        // Get size reward
        switch (SizeRewardDropdown.value)
        {
        case 0:
            CurrentlyRewardingSize = SizeReward.DontReward;
            break;

        case 1:
            CurrentlyRewardingSize = SizeReward.RewardBig;
            break;

        case 2:
            CurrentlyRewardingSize = SizeReward.RewardSmall;
            break;
        }

        // Finally initialise
        PauseRun();
        Initialise(fitnessFunc);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Initialise all the variables (get references etc.), generate an initial scene.
    /// </summary>
    void Start()
    {
        // Verfiy that prefabs are set.
        Assert.IsNotNull(DefaultCarPrefab, "Car prefab not set!");
        Assert.IsNotNull(TerrainPrefab, "Terrain prefab not set!");
        Assert.IsNotNull(RootGameObjectToAttachTerrainTo, "RootGameObjectToAttachTerrainTo not set!");

        // Get text components.
        GenerationText  = GameObject.Find("Generation Text").GetComponent <TextMeshProUGUI>();
        FitnessText     = GameObject.Find("Fitness Text").GetComponent <TextMeshProUGUI>();
        BenchText       = GameObject.Find("Bench Text").GetComponent <TextMeshProUGUI>();
        RunText         = GameObject.Find("Run Text").GetComponent <TextMeshProUGUI>();
        TimeScaleSlider = GameObject.Find("Time Scale Slider").GetComponent <Slider>();

        Assert.IsNotNull(TimeScaleSlider, "Not found time scale slider by game object name!");

        FitnessDropdown    = GameObject.Find("Fitness Dropdown").GetComponent <TMP_Dropdown>();
        SizeRewardDropdown = GameObject.Find("Size Reward Dropdown").GetComponent <TMP_Dropdown>();

        CurrentBenchmarkBeingRan = CurrentBench.DONT_RUN;
        CurrentlyRewardingSize   = SizeReward.DontReward;
        Initialise(FitnessFunction);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Benchmarking function.
    /// </summary>
    /// <param name="firstRun">Whether this is the first time the benchmark is being ran.</param>
    private void RunBenchmarks(bool firstRun = false)
    {
        if (HasAnyCarReachedGoal || firstRun)
        {
            if (!firstRun)
            {
                Run++;
            }

            RunText.text = "Run: " + Run + "/" + RunsPerBench;

            PauseRun();

            if (!firstRun && Run >= RunsPerBench)
            {
                SaveToSpreadsheet();
            }

            switch (CurrentBenchmarkBeingRan)
            {
            case CurrentBench.Fitness1:
                BenchText.text = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                if (!firstRun && Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.Fitness2;
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                    BenchData    = new List <BenchData>();
                    goto case CurrentBench.Fitness2;     // The system works one behind, so if its not the first run chances its already been initailised.
                }
                CurrentlyRewardingSize = SizeReward.DontReward;
                Initialise(FitnessFunction);
                break;

            case CurrentBench.Fitness2:
                BenchText.text         = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                CurrentlyRewardingSize = SizeReward.DontReward;
                Initialise(FitnessFunction2NoFlip);
                if (Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.Fitness1SmallSizeReward;
                    BenchData    = new List <BenchData>();
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                }
                break;

            case CurrentBench.Fitness1SmallSizeReward:
                BenchText.text         = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                CurrentlyRewardingSize = SizeReward.RewardSmall;
                Initialise(FitnessFunction);
                if (Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.Fitness2SmallSizeReward;
                    BenchData    = new List <BenchData>();
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                }
                break;

            case CurrentBench.Fitness2SmallSizeReward:
                BenchText.text         = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                CurrentlyRewardingSize = SizeReward.RewardSmall;
                Initialise(FitnessFunction2NoFlip);
                if (Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.Fitness1BigSizeReward;
                    BenchData    = new List <BenchData>();
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                }
                break;

            case CurrentBench.Fitness1BigSizeReward:
                BenchText.text         = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                CurrentlyRewardingSize = SizeReward.RewardBig;
                Initialise(FitnessFunction);
                if (Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.Fitness2BigSizeReward;
                    BenchData    = new List <BenchData>();
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                }
                break;

            case CurrentBench.Fitness2BigSizeReward:
                BenchText.text         = "Bench: " + CurrentBenchmarkBeingRan.ToString();
                CurrentlyRewardingSize = SizeReward.RewardBig;
                Initialise(FitnessFunction2NoFlip);
                if (Run >= RunsPerBench)
                {
                    CurrentBenchmarkBeingRan = CurrentBench.BencFinished;
                    BenchData    = new List <BenchData>();
                    Run          = 0;
                    RunText.text = "Run: " + Run + "/" + RunsPerBench;
                }
                break;
            }

            if (CurrentBenchmarkBeingRan == CurrentBench.BencFinished)
            {
                CurrentBenchmarkBeingRan = CurrentBench.DONT_RUN;
                PauseRun();
                return;
            }

            HasAnyCarReachedGoal = false;
            StartRunning();
        }
    }