/// <summary>Gets the next job to run</summary> public Simulation NextSimulationToRun(bool fullFactorial = true) { if (allCombinations.Count == 0) { return(null); } var combination = allCombinations[0]; allCombinations.RemoveAt(0); string newSimulationName = Name; foreach (FactorValue value in combination) { newSimulationName += value.Name + value.Values[0]; } Simulation newSimulation = Apsim.DeserialiseFromStream(serialisedBase) as Simulation; newSimulation.Name = newSimulationName; newSimulation.Parent = null; newSimulation.FileName = parentSimulations.FileName; Apsim.ParentAllChildren(newSimulation); // Make substitutions. parentSimulations.MakeSubsAndLoad(newSimulation); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } return(newSimulation); }
/// <summary>Gets the next job to run</summary> public Simulation NextSimulationToRun(bool fullFactorial = true) { if (allCombinations.Count == 0) { return(null); } var combination = allCombinations[0]; allCombinations.RemoveAt(0); Simulation newSimulation = Apsim.DeserialiseFromStream(serialisedBase) as Simulation; newSimulation.Name = Name + "Simulation" + simulationNumber; newSimulation.Parent = null; newSimulation.FileName = parentSimulations.FileName; Apsim.ParentAllChildren(newSimulation); // Make substitutions. parentSimulations.MakeSubsAndLoad(newSimulation); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } PushFactorsToReportModels(newSimulation, combination); simulationNumber++; return(newSimulation); }
/// <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); } }
/// <summary>Gets the next job to run</summary> public Simulation NextSimulationToRun(bool fullFactorial = true) { if (allCombinations == null || allCombinations.Count == 0) { return(null); } if (serialisedBase == null) { Initialise(fullFactorial); } 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 and issue Loaded event parentSimulations.MakeSubsAndLoad(newSimulation); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } PushFactorsToReportModels(newSimulation, combination); StoreFactorsInDataStore(newSimulation, combination); return(newSimulation); }
/// <summary>Gets the next job to run</summary> public IRunnable NextJobToRun() { if (allCombinations == null || allCombinations.Count == 0) { return(null); } 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); events.Publish("Loaded", null); foreach (FactorValue value in combination) { value.ApplyToSimulation(newSimulation); } PushFactorsToReportModels(newSimulation, combination); StoreFactorsInDataStore(newSimulation, combination); return(new RunSimulation(newSimulation, doClone: false)); }