/// <summary> /// Initialise the experiment ready for creating simulations. /// </summary> private void Initialise(bool fullFactorial = false) { parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations; allCombinations = fullFactorial ? AllCombinations() : EnabledCombinations(); Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation; serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream; }
private void OnBeginRun(IEnumerable <string> knownSimulationNames = null, IEnumerable <string> simulationNamesBeingRun = null) { allCombinations = AllCombinations(); parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations; Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation; serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream; }
/// <summary> /// Initialise the experiment ready for creating simulations. /// </summary> private void Initialise() { parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations; Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation; serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream; allCombinations.Clear(); CalculateFactors(); }
/// <summary>Gets the next job to run</summary> public Simulation NextSimulationToRun() { if (allCombinations == null || allCombinations.Count == 0) { return(null); } if (serialisedBase == null) { allCombinations = AllCombinations(); parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations; Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation; serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream; } var combination = allCombinations[0]; allCombinations.RemoveAt(0); string newSimulationName = Name; foreach (FactorValue value in combination) { newSimulationName += value.Name; } Simulation newSimulation = Apsim.DeserialiseFromStream(serialisedBase) as Simulation; newSimulation.Name = newSimulationName; newSimulation.Parent = null; newSimulation.FileName = parentSimulations.FileName; Apsim.ParentAllChildren(newSimulation); // Make substitutions. parentSimulations.MakeSubstitutions(newSimulation); // Call OnLoaded in all models. Events events = new Events(newSimulation); LoadedEventArgs loadedArgs = new LoadedEventArgs(); events.Publish("Loaded", new object[] { newSimulation, loadedArgs }); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } PushFactorsToReportModels(newSimulation, combination); StoreFactorsInDataStore(newSimulation, combination); return(newSimulation); }
/// <summary>Called to start the job.</summary> /// <param name="jobManager">The job manager running this job.</param> /// <param name="workerThread">The thread this job is running on.</param> public void Run(JobManager jobManager, BackgroundWorker workerThread) { List <List <FactorValue> > allCombinations = AllCombinations(); Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation; Simulations parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations; Stream serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream; List <Simulation> simulations = new List <Simulation>(); foreach (List <FactorValue> combination in allCombinations) { string newSimulationName = Name; foreach (FactorValue value in combination) { newSimulationName += value.Name; } Simulation newSimulation = Apsim.DeserialiseFromStream(serialisedBase) as Simulation; newSimulation.Name = newSimulationName; newSimulation.Parent = null; newSimulation.FileName = parentSimulations.FileName; Apsim.ParentAllChildren(newSimulation); // Make substitutions. Simulations.MakeSubstitutions(parentSimulations, new List <Simulation> { newSimulation }); // Call OnLoaded in all models. Events events = new Events(); events.AddModelEvents(newSimulation); events.CallEventHandler(newSimulation, "Loaded", null); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } PushFactorsToReportModels(newSimulation, combination); StoreFactorsInDataStore(newSimulation, combination); jobManager.AddChildJob(this, newSimulation); } }