示例#1
0
    void Start()
    {
        // create our neural networks for the genomes
        species       = new GeneticController(numGenomes, mutationRate);
        cars          = new GameObject[numSimulate];
        carController = new AICarController[numSimulate];
        bestCar       = carController[0];

        CarCheckPoint checkpoint = carFab.GetComponent <CarCheckPoint>();

        checkpoint.track = track;

        // Instantiate the number of cars we are going to simulate
        // Add assign them an AI Controller

        for (int i = 0; i < numSimulate; i++)
        {
            cars[i]                  = Instantiate(carFab, startingPos, carFab.transform.rotation);
            carController[i]         = cars[i].GetComponent <AICarController>();
            carController[i].network = species.population[i];
        }

        currentGenome = numSimulate;
        batchSimulate = numSimulate;

        Network_GUI = Instantiate(Network_GUI);
        UI_Genetics genetics = Network_GUI.GetComponentInChildren <UI_Genetics>();

        genetics.academy = this;
        networkUI        = Network_GUI.GetComponentInChildren <UI_Network>();
        networkUI.Display(carController[0].network);
    }
示例#2
0
 void Start()
 {
     gController = new GeneticController(genomes, 60, brainStructure, outputs);
     agents      = new GameObject[genomes];
     fitness     = new double[genomes];
     gController.createGeneration();
     setEnvironment(49, 49);
     Debug.Log("Generation: " + gController.getGeneration());
 }
示例#3
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
    void Awake()
    {
        geneticController = new GeneticController <ChromosomeSalesman> ();

        // Setting basic info to Chromosome

        /*ChromosomeSalesman.cities = new List<SalesmanCity>();
         * ChromosomeSalesman.cities.Add (new SalesmanCity (0));
         * ChromosomeSalesman.cities.Add (new SalesmanCity (1));
         * ChromosomeSalesman.cities.Add (new SalesmanCity (2));
         *
         * ChromosomeSalesman solution = geneticController.Calculate ();
         * Debug.Log ( solution.toString() );*/
    }
示例#5
0
 public GeneticBrain(int inputSize, int hiddenLayerSize, int outputSize, int minRandom, int maxRandom, GeneticController control)
 {
     this.inputSize       = inputSize;
     this.hiddenLayerSize = hiddenLayerSize;
     this.outputSize      = outputSize;
     ihWeights            = new Matrix(hiddenLayerSize, inputSize);
     hoWeights            = new Matrix(outputSize, hiddenLayerSize);
     ihWeights.Randomize(minRandom, maxRandom);
     hoWeights.Randomize(minRandom, maxRandom);
     hBias = new Matrix(hiddenLayerSize, 1);
     oBias = new Matrix(outputSize, 1);
     hBias.Randomize(minRandom, maxRandom);
     oBias.Randomize(minRandom, maxRandom);
     this.fitness = 0;
     this.control = control;
 }
示例#6
0
        static void Main(string[] args)
        {
            Console.Title = "Genetic Algorithm + Neural Network ~ Testing";

            // Testing Genetic Algorithm combined with Neural Network of 200 neurons
            GeneticController GController = new GeneticController(12, 3, new int[] { 80, 120 }, 1);

            // Learning process for 100 generations
            for (int i = 0; i < 100; i++)
            {
                GController.createGeneration();
                printResultsAndSetFitness(GController);
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("\nPress a key to exit...");
            Console.ReadLine();
        }
示例#7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ColumnHeader logHeader = new ColumnHeader();

            geneticController = new GeneticController(this);
            bestInds          = new List <BitIndividual>();
            averageInds       = new List <BitIndividual>();
            worstInds         = new List <BitIndividual>();
            bestIndsBackup    = new List <BitIndividual>();
            averageIndsBackup = new List <BitIndividual>();
            worstIndsBackup   = new List <BitIndividual>();
            LogListView.Columns.Add(logHeader);
            LogListView.Scrollable  = true;
            LogListView.HeaderStyle = ColumnHeaderStyle.None;
            LogListView.View        = View.Details;
            LogListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            geneticChart.ChartAreas[0].AxisX.ScaleView.Zoom(0, 50);
            geneticChart.ChartAreas[0].CursorX.IsUserEnabled              = true;
            geneticChart.ChartAreas[0].CursorX.IsUserSelectionEnabled     = true;
            geneticChart.ChartAreas[0].AxisX.ScaleView.Zoomable           = true;
            geneticChart.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
        }
示例#8
0
        static void printResultsAndSetFitness(GeneticController g_ctrl)
        {
            Console.Clear();
            double[][] result  = g_ctrl.executeGeneration(new double[] { 0, 1, -.5 });
            double[]   fitness = new double[result.Length];
            int        index   = 0;

            foreach (double[] r in result)
            {
                if (r[0] <= .4)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                else if (r[0] >= .6)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                Console.WriteLine(r[0]);

                if (r[0] > .4 && r[0] < .6)
                {
                    fitness[index] = 1 - (10 * Math.Abs(.5 - r[0])); // Funzione di fitness
                }
                else
                {
                    fitness[index] = 0;
                }

                index++;
            }
            g_ctrl.setFitness(fitness);
            Console.WriteLine();
        }
示例#9
0
 private void MakeGenetic()
 {
     geneticController = Instantiate(geneticControllerPrefab);
     Attach(geneticController.gameObject);
 }