/// <summary> /// Load a simulation from a given .dll file and a classname, create /// a new simulation run, initialize it and update the start configuration. /// </summary> /// <param name="path"></param> /// <param name="className"></param> private bool Load(string path, string className) { try { _model.Sim?.Unload(); _model.Sim = new Simulation(path, className); // -- Create run from simulation var run = new SimRun(_model.Sim.Spawn()) { RenderHeight = _model.RenderHeight, RenderWidth = _model.RenderWidth, IsWriteLogToFile = _model.WriteLogToFile, SimDelay = _model.SimDelay }; run.OnUpdate += (sender, args) => { Application.Invoke((s, a) => AfterUpdate()); }; run.OnLog += (sender, args) => { Application.Invoke((s, a) => _logOutput.Log(args.Message)); }; run.Init(run.Instance.GetConfig()); _model.ActiveRun.Set(run); return(true); } catch (ArgumentException e) { ShowMessageDialog(e.Message); _model.Sim = null; LoadDefault(); return(false); } }
private Widget CreateScheduleArea() { var result = new VBox(false, 5); var title = new Label("Schedule") { Halign = Align.Start }; var scheduleEntry = new Entry("200 x 50") { WidthChars = 8, HasFrame = false, Alignment = 0.5f }; var scheduleBtn = new Button("S") { TooltipText = "Schedule i iterations times n runs e.g. '100 x 20'" }; scheduleBtn.Clicked += (sender, args) => { if (_model.ActiveRun == null) { Logger.Say("No simulation loaded."); return; } var values = scheduleEntry.Text.Split('x'); if (values.Length == 2 && int.TryParse(values[0], out var iterations) && int.TryParse(values[1], out var runs)) { var totalIterations = iterations * runs; var task = new HBox(false, 5); var taskTitle = new Label( $"- {iterations} x {runs}, 0% from {totalIterations} in total"); // var deleteTaskBtn = new Button("x") { Name = "textBtn"}; // deleteTaskBtn.Clicked += (o, a) => // { // result.Remove(task); // }; task.PackStart(taskTitle, false, false, 0); // task.PackEnd(deleteTaskBtn, false, false, 0); task.ShowAll(); result.Add(task); var run = new SimRun(_model.Sim.Spawn()) { RenderHeight = _model.RenderHeight, RenderWidth = _model.RenderWidth, IsWriteLogToFile = _model.WriteLogToFile, SimDelay = _model.SimDelay }; run.OnEnd += (o, a) => result.Remove(task); run.OnUpdate += (o, a) => { // var percentage = taskTitle.Text = $"- {iterations} x {runs}, {0}% from {totalIterations} in total"; }; _model.ScheduledRuns.Add(run); } else { ShowMessageDialog("Please enter a iterations " + "x runs e.g. '100 x 20'"); } }; var scheduleBox = new HBox(false, 0) { Name = "runSteps" }; scheduleBox.PackStart(scheduleEntry, true, true, 0); scheduleBox.PackStart(scheduleBtn, false, false, 0); var startStopScheduleBtn = new Button("Start"); startStopScheduleBtn.Clicked += (sender, args) => { if (_model.ScheduledRuns.Count == 0) { return; } var activeRun = _model.ScheduledRuns[0]; activeRun.OnEnd += (o, a) => { // _model.ScheduledRuns }; }; var clearScheduleBtn = new Button("Clear"); var scheduleControls = new HBox(false, 10); scheduleControls.PackStart(scheduleBox, true, true, 0); scheduleControls.PackEnd(clearScheduleBtn, false, false, 0); scheduleControls.PackEnd(startStopScheduleBtn, false, false, 0); result.PackStart(title, false, false, 0); result.PackStart(scheduleControls, false, false, 5); return(result); }
public static void Run(string[] args) { if (args[0] == "--help" || args[0] == "-h") { Logger.Say("Commands:"); Logger.Say("--help --> Print help information"); Logger.Say("--get (config|descr|meta) --> Get information about " + "the simulation"); Logger.Say("--run <simulation> <iterations> <runs> <out-dir> " + "--> Run a simulation for a number of runs, each " + "for a certain number of iterations. The results are " + "stored in ~/.charlie/<out-dir>"); } else if (args[0] == "--get") { var sim = new Simulation(args[1]); var instance = sim.Spawn(); if (args[2] == "config") { Logger.Say(instance.GetConfig()); } else if (args[2] == "descr") { Logger.Say(instance.GetDescr()); } else if (args[2] == "meta") { Logger.Say(instance.GetMeta()); } } else if (args[0] == "--run") { if (args.Length < 4) { Logger.Warn("Invalid number of parameters to run a simulation."); Logger.Warn("See --help for more information."); return; } if (!int.TryParse(args[2], out var iterations)) { Logger.Warn($"'{args[2]}' is not a number."); } if (!int.TryParse(args[3], out var runs)) { Logger.Warn($"'{args[3]}' is not a number."); } Simulation sim; try { sim = new Simulation(args[1]); } catch (Exception e) { Logger.Warn(e.ToString()); return; } var run = new SimRun(sim.Spawn()) { IsWriteLogToFile = true, RenderHeight = 800, RenderWidth = 800 }; var config = run.Instance.GetConfig(); // -- Parse simulation start configuration if (args.Length > 4) { var configFile = args[4]; if (!Path.IsPathRooted(configFile)) { configFile = Path.Combine(Environment.CurrentDirectory, configFile); } if (!File.Exists(configFile)) { Logger.Warn("Provide start configuration " + $"file does not exist: '{configFile}'"); return; } config = File.ReadAllText(configFile); } // -- Parse simulation data sub directory if (args.Length > 5) { run.LogSubDirectory = args[5]; } // -- Run simulation Logger.Say($"Running Simulation {sim.ClassName} {iterations}x{runs}"); for (var i = 0; i < runs; i++) { run.Init(config); run.UpdateSync(iterations); run.SaveImage(); run.End(); var percentage = (double)(i + 1) / runs * 100; Logger.Say($"{percentage}% done, {run.Initializations} runs"); } sim.Unload(); } else { Logger.Say($"Unknown command '{args[0]}', use --help"); } }