private void OnBreedingUpdate() { // Perform one generation of our GA genericAlgorithm.DoGeneration(); simulation.SetCars(genericAlgorithm.GetPopulation().Cast <ICarController>()); simulation.ResetCars(); // Add the metrics we will use to judge our cars fitness simulation.GetCars().ForEach(car => this.AddFitnessMetrics(car)); // Reset our simulation currentTrackIndex = 0; simulation.SetTrack(currentTrack); simulation.Reset(); // Reset the visualisation if (IsVisualizationEnabled) { // Reset all cars simulationVisualization.InitializeCars(simulation.GetCars()); // Reset all track visuals - not the most efficient but works really clean simulationVisualization.SetTrack(currentTrack); simulationVisualization.Reset(); } trainingState = TrainState.Evaluating; }
public void Initialize(Track track, MLPNeuralNetwork controller) { var carAi = new CarAI(random, controller); // Load the simulation simulation = appService.Kernel.Get <RacingSimulationLogic>(); simulation.SetTrack(track); // Add the 1:1 trained AI to the list of cars var cars = new List <ICarController>() { carAi }; // Spawn 100 mutated versions of our AI for (int i = 0; i < 100; i++) { var car = carAi.Clone(); car.Mutate(); cars.Add((CarAI)car); } // Initialize the simulation simulation.SetCars(cars); simulation.ResetCars(); // If the visualization is turned on, create it, set the track and add the cars. simulationVisualization = appService.Kernel.Get <RacingSimulationVisualization>(); simulationVisualization.SetTrack(track); simulationVisualization.InitializeCars(simulation.GetCars()); }
public SelfTrainingScreen( IApplicationService appService, bool enableVisualization = true) { random = new Random(); List <float> seed = null; var seedFile = "Resources/CarAi/AI_2.mlpnn"; if (File.Exists(seedFile)) { var seedText = File.ReadAllText(seedFile); seed = seedText.Split(',').Select(s => float.Parse(s)).ToList(); } // Create the GA genericAlgorithm = this.CreateGeneticAlgorithm(seed); // Load the tracks used for evaluation tracks = TrackHelper.LoadTrackFiles("Resources/Tracks"); // Spawn the initial population genericAlgorithm.SpawnPopulation(); // Load the simulation simulation = appService.Kernel.Get <RacingSimulationLogic>(); simulation.SetTrack(currentTrack); // Initialize the simulation simulation.SetCars(genericAlgorithm.GetPopulation().Cast <ICarController>()); simulation.ResetCars(); // Add the metrics we will use to judge our cars fitness simulation.GetCars().ForEach(car => this.AddFitnessMetrics(car)); // If the visualization is turned on, create it, set the track and add the cars. if (enableVisualization) { simulationVisualization = appService.Kernel.Get <RacingSimulationVisualization>(); simulationVisualization.SetTrack(currentTrack); simulationVisualization.InitializeCars(simulation.GetCars()); } }