/// <summary> /// Runs simulation for a given number of steps. Simulation will be left in PAUSED state after /// this function returns, allowing to inspect content of memory blocks and then perhaps /// resume the simulation by calling this function again. /// </summary> /// <param name="stepCount">Number of steps to perform</param> /// <param name="reportInterval">Step count between printing out simulation info (e.g. speed)</param> public void RunAndPause(uint stepCount, uint reportInterval = 100) { if (stepCount == 0) throw new ArgumentException("Zero step count not allowed.", "stepCount"); // would run forever // TODO(Premek): Add a check that that simulation is not finished if (SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED) { if (SimulationHandler.UpdateMemoryModel()) { MyLog.ERROR.WriteLine("Simulation cannot be started! Memory model did not converge."); return; } MyValidator validator = new MyValidator(); validator.Simulation = SimulationHandler.Simulation; validator.ClearValidation(); Project.World.ValidateWorld(validator); Project.Network.Validate(validator); validator.Simulation = null; if (!validator.ValidationSucessfull) { MyLog.ERROR.WriteLine("Simulation cannot be started! Validation failed."); return; } } try { SimulationHandler.ReportIntervalSteps = reportInterval; SimulationHandler.StartSimulation(stepCount); SimulationHandler.WaitUntilStepsPerformed(); } catch (Exception e) { MyLog.ERROR.WriteLine("Simulation cannot be started! Exception occured: " + e.Message); throw; } }