예제 #1
0
        /// <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;
        }
예제 #2
0
        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;
        }
예제 #3
0
파일: Morris.cs 프로젝트: jcbowden/ApsimX
        /// <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();
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        /// <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);
            }
        }