示例#1
0
        public static List <string> CreateSimulationJobs(ApsimFile _F, string[] SimsToRun, ref List <JobScheduler.Job> ApsimJobs, ProgressNotifier Notifier)
        {
            List <string> SimFiles = new List <string>();

            foreach (string FullSimulationPath in SimsToRun)
            {
                Notifier(0, "Opening " + FullSimulationPath);
                FactorBuilder builder       = new FactorBuilder();
                List <string> allFactorials = new List <string>();
                int           totalCount    = 0;
                foreach (FactorItem item in builder.BuildFactorItems(_F.FactorComponent, FullSimulationPath))
                {
                    totalCount += item.CalcCount();
                    var scratch = new SortedDictionary <string, string>();
                    item.CalcFactorialList(allFactorials, "", scratch);
                }


                string FullSimulationPathName = _F.Find(FullSimulationPath).Name;
                int    sequenceNumber         = 0;
                foreach (string str in allFactorials)
                {
                    SimFiles.Add(FullSimulationPath + "@factorial=" + str);
                    Notifier((int)(100 * ((double)sequenceNumber / totalCount)), "Found factorial " + sequenceNumber.ToString());
                    sequenceNumber++;
                }
            }
            return(SimFiles);
        }
示例#2
0
        public static List <string> CalcFactorialList(ApsimFile _F, string SimulationPath)
        {
            FactorBuilder builder       = new FactorBuilder();
            List <string> allFactorials = new List <string>();

            foreach (FactorItem item in builder.BuildFactorItems(_F.FactorComponent, SimulationPath))
            {
                var scratch = new SortedDictionary <string, string>();
                item.CalcFactorialList(allFactorials, "", scratch);
            }
            return(allFactorials);
        }
示例#3
0
        public static List <string> CreateSimFiles(ApsimFile _F, string[] SimsToRun, string destFolder = "")
        {
            List <string> SimFiles = new List <string>();

            foreach (string FullSimulationPath in SimsToRun)
            {
                string[] simPathParts          = FullSimulationPath.Split(new string[] { "@factorial=" }, StringSplitOptions.None);
                string   simXmlPath            = simPathParts[0];
                string   simPathFactorInstance = "";
                if (simPathParts.Count() > 1)
                {
                    simPathFactorInstance = simPathParts[1].Trim(new char[] { '\'', ' ' });
                }

                FactorBuilder builder       = new FactorBuilder();
                List <string> allFactorials = new List <string>();
                foreach (FactorItem item in builder.BuildFactorItems(_F.FactorComponent, simXmlPath))
                {
                    var scratch = new SortedDictionary <string, string>();
                    item.CalcFactorialList(allFactorials, "", scratch);
                }

                if (simPathFactorInstance != "")
                {
                    var myFactors      = new SortedDictionary <string, string>(simPathFactorInstance.Split(';').Select(s => s.Split('=')).ToDictionary(a => a[0].Trim(), a => a[1].Trim()));
                    var sequenceNumber = 1 + allFactorials.FindIndex(x => x == simPathFactorInstance);
                    if (sequenceNumber < 1)
                    {
                        throw new Exception("factor level '" + simPathFactorInstance + "' not found");
                    }
                    //work on a copy of the file - names will change during the processing of the factorial nodes
                    SimFiles.Add(Factor.ProcessSingleSimulation(CreateCopy(_F), simXmlPath, myFactors, sequenceNumber, destFolder));
                }
                else
                {
                    foreach (string str in allFactorials)
                    {
                        var myFactors      = new SortedDictionary <string, string>(str.Split(';').Select(s => s.Split('=')).ToDictionary(a => a[0].Trim(), a => a[1].Trim()));
                        var sequenceNumber = 1 + allFactorials.FindIndex(x => x == str);
                        SimFiles.Add(Factor.ProcessSingleSimulation(CreateCopy(_F), simXmlPath, myFactors, sequenceNumber, destFolder));
                    }
                }
            }
            return(SimFiles);
        }
示例#4
0
        private static string ProcessSingleSimulation(ApsimFile copiedFile, string SimulationPath, SortedDictionary <string, string> factorInstance, int uniqueId, string destFolder = "")
        {
            if (copiedFile == null)
            {
                throw new Exception("copiedFile is null in ProcessSingleSimulation");
            }
            if (factorInstance == null)
            {
                throw new Exception("factorInstance is null in ProcessSingleSimulation");
            }

            Component Simulation = copiedFile.Find(SimulationPath);

            if (Simulation == null)
            {
                throw new Exception("Simulation is null in ProcessSingleSimulation");
            }

            string rootName   = Simulation.Name;
            int    totalCount = 0;

            try
            {
                FactorBuilder     builder = new FactorBuilder();
                List <FactorItem> items   = builder.BuildFactorItems(copiedFile.FactorComponent, SimulationPath);

                foreach (FactorItem item in items)
                {
                    totalCount += item.CalcCount();
                    item.Process(Simulation, "", factorInstance);
                }

                Simulation.Name = simulationName(builder.SaveExtraInfoInFilename, rootName, factorInstance, uniqueId, totalCount);
                return(CreateJobFromSimulation(Simulation, factorInstance, builder.TitleIsSingleLine, destFolder));
            }
            catch (Exception ex)
            {
                throw new Exception("Error encountered creating Factorials. \r\n" +
                                    "SimulationPath: " + SimulationPath + "\r\n" +
                                    "Total count: " + totalCount +
                                    "Exception: " + ex.ToString());
            }
        }