IEnumerator Gestation() { gestating = true; yield return(new WaitForSeconds(2f)); Color[] cs = new Color[2]; for (int i = 0; i < colors.Length; i++) { float r = Mutate() ? Random.Range(0f, 1f) : partner != null ? (Random.Range(0, 2) == 0 ? partner.colors[i].r : colors[i].r) : colors[i].r; float g = Mutate() ? Random.Range(0f, 1f) : partner != null ? (Random.Range(0, 2) == 0 ? partner.colors[i].g : colors[i].g) : colors[i].g; float b = Mutate() ? Random.Range(0f, 1f) : partner != null ? (Random.Range(0, 2) == 0 ? partner.colors[i].b : colors[i].b) : colors[i].b; cs[i] = new Color(r, g, b, 1f); } if (!neat) { NeuralNet newNet = net.MutateAndReproduce(2, partner == null ? null : partner.net, true); SimulationStarter.SpawnCreature(transform.position, newNet, cs); } else { if (neatNet != null && partner != null && gameObject != null && partner.neatNet != null) { SimulationStarter.SpawnCreature(transform.position, new NEATNetwork(NEATGenome.Reproduce(neatNet.genome, partner == null ? neatNet.genome : partner.neatNet.genome)), cs); } } vitality /= 2f; gestating = false; partner = null; }
public void Test(FCM fcm, int generations, string[] args) { var startTime = DateTime.Now; for (int generation = 0; generation < generations; generation++) { Console.WriteLine("\nTest generation: {0} of {1}", generation, generations); LoggerFactory.SetLogLevel(LogLevel.Warning); LoggerFactory.DeactivateConsoleLogging(); SimulationStarter task = SimulationStarter.Start(this.modelDescription, args); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); SimulationWorkflowState loopResults = task.Run(); if (loopResults.IsFinished) { stopWatch.Stop(); // Console.WriteLine($"Simulation execution finished in {stopWatch.ElapsedMilliseconds / 1000:N2} seconds"); stopWatch.Restart(); fcm.Run(false); stopWatch.Stop(); // Console.WriteLine($"FCM finished in {stopWatch.ElapsedMilliseconds / 100:N2} seconds"); GC.Collect(); } } }
public SimulationOptionsDialog(SimulationStarter simulationStarter) { InitializeComponent(); SimulationStart += simulationStarter; MessageGenerateChance.Text = AllConstants.MessageGenerateChance.ToString("N"); TableUpdatePeriod.Text = AllConstants.UpdateTablePeriod.ToString(); GeneratedMessagesSizes.Text = AllConstants.DefaultMessageSize.ToString(); _exceptionCatcher = new ExceptionCatcher(); }
private static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = new CultureInfo("EN-US"); LoggerFactory.SetLogLevel(LogLevel.Off); var description = new ModelDescription(); description.AddLayer <CarLayer>(); description.AddLayer <CarParkingLayer>(); description.AddLayer <TrafficLightLayer>(); description.AddLayer <TravelerLayer>(); description.AddAgent <Traveler, TravelerLayer>(); description.AddEntity <Car>(); ISimulationContainer application; if (args != null && args.Any()) { application = SimulationStarter.BuildApplication(description, args); } else { var config = CreateDefaultConfig(); application = SimulationStarter.BuildApplication(description, config); } var simulation = application.Resolve <ISimulation>(); var watch = Stopwatch.StartNew(); var state = simulation.StartSimulation(); var layers = state.Model.Layers; foreach (var layer in layers) { if (layer.Value is TravelerLayer travelerLayer) { TripsOutputAdapter.PrintTripResult(travelerLayer.Travelers.Values); } } watch.Stop(); Console.WriteLine($"Executed iterations {state.Iterations} lasted {watch.Elapsed}"); application.Dispose(); }
public void Train(FCM fcm, int generations, float targetFitness, Boolean saveGenomes, string[] args) { var startTime = DateTime.Now; for (int generation = 0; generation < generations; generation++) { Console.WriteLine("\nGeneration: {0} of {1}", generation, generations); LoggerFactory.SetLogLevel(LogLevel.Warning); LoggerFactory.DeactivateConsoleLogging(); SimulationStarter task = SimulationStarter.Start(this.modelDescription, args); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); SimulationWorkflowState loopResults = task.Run(); if (loopResults.IsFinished) { stopWatch.Stop(); Console.WriteLine($"Simulation execution finished in {stopWatch.ElapsedMilliseconds / 1000:N2} seconds"); stopWatch.Restart(); fcm.Run(true, targetFitness, saveGenomes); stopWatch.Stop(); Console.WriteLine($"FCM finished in {stopWatch.ElapsedMilliseconds / 100:N2} seconds"); GC.Collect(); } } string filename = FileUtils.CreateTimestampedFilename("Genomes", DateTime.Now, ".csv"); fcm.WriteGenomes(filename); fcm.WriteGenomes("genomes.csv"); }
private void Start() { instance = this; InitSimulation(); }