当前位置: 首页>>代码示例>>C#>>正文


C# Calculator.RunCalculations方法代码示例

本文整理汇总了C#中Calculator.RunCalculations方法的典型用法代码示例。如果您正苦于以下问题:C# Calculator.RunCalculations方法的具体用法?C# Calculator.RunCalculations怎么用?C# Calculator.RunCalculations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Calculator的用法示例。


在下文中一共展示了Calculator.RunCalculations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        /// <summary>
        /// Program entry point
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            #region preproceiing parsing the user inputs
            Console.WriteLine("Parsing given parameters...");
            //Using the filename provided as the first argument
            string fileName = args[0];

            //Using the years defined in the second argument
            string years = args[1];
            string[] yearsSplit = years.Split(',');
            List<int> yearsList = new List<int>();
            int temp;
            foreach (string y in yearsSplit)
                if (int.TryParse(y, out temp))
                    yearsList.Add(temp);

            //Using the pathways and mix id provided in the third argument
            string pm = args[2];
            string[] pms = pm.Split(',');
            List<InputResourceReference> inRef = new List<InputResourceReference>();
            foreach (string s in pms)
            {
                if (s[0] == 'p')
                {//this is a pathway reference
                    if (int.TryParse(s.Substring(1, s.Length - 1), out temp))
                    {
                        InputResourceReference pRef = new InputResourceReference(-1, temp, Enumerators.SourceType.Pathway);
                        inRef.Add(pRef);
                    }
                }
                else if (s[0] == 'm')
                {//this is a mix reference
                    if (int.TryParse(s.Substring(1, s.Length - 1), out temp))
                    {
                        InputResourceReference mRef = new InputResourceReference(-1, temp, Enumerators.SourceType.Mix);
                        inRef.Add(mRef);
                    }
                }
            }
            #endregion

            #region loading units file and data file
            Console.WriteLine("Building units context...");
            //Build units context before loading the database
            Units.BuildContext();

            Console.WriteLine("Loading datafile...");
            //Loading the database
            GProject project = new GProject();
            project.Load(fileName);
            #endregion

            #region preprocessing the pathways/mixes we want to record by finding their main output resource
            //Assign main output resource IDs to all the inputsResourceReferences
            foreach (InputResourceReference iref in inRef)
            {
                if (iref.SourceType == Greet.DataStructureV4.Interfaces.Enumerators.SourceType.Pathway)
                {
                    if (project.Dataset.PathwaysData.ContainsKey(iref.SourceMixOrPathwayID))
                        iref.ResourceId = project.Dataset.PathwaysData[iref.SourceMixOrPathwayID].MainOutputResourceID;
                }
                else if (iref.SourceType == Greet.DataStructureV4.Interfaces.Enumerators.SourceType.Mix)
                {
                    if (project.Dataset.MixesData.ContainsKey(iref.SourceMixOrPathwayID))
                        iref.ResourceId = project.Dataset.MixesData[iref.SourceMixOrPathwayID].MainOutputResourceID;
                }
            }
            #endregion

            #region running the calculations for each year and storing the results
            //Creating a new instance of a dictionary used to store results of the simulations
            Dictionary<InputResourceReference, Dictionary<int, Results>> savedResults = new Dictionary<InputResourceReference, Dictionary<int, Results>>();

            //Running simulations for every provided years
            foreach (int simulationYear in yearsList)
            {
                Console.WriteLine("Running calculations for year " + simulationYear);
                //Set the current year for simulations
                BasicParameters.SelectedYear = project.Dataset.ParametersData.CreateUnregisteredParameter(project.Dataset, "", simulationYear);
                Calculator calc = new Calculator();

                //Run the simulations for the loaded project and defined year, we need to wait completion as the RunCalculationMethod is Async
                var manualEvent = new ManualResetEvent(false);
                calc.CalculationDoneEvent += () => manualEvent.Set();
                calc.RunCalculations(project);
                manualEvent.WaitOne();

                //Loop over all the pathways and mixes ID that we wish to save
                foreach (InputResourceReference pathMixToSave in inRef)
                {
                    if (!savedResults.ContainsKey(pathMixToSave))
                        savedResults.Add(pathMixToSave, new Dictionary<int, Results>());
                    if(!savedResults[pathMixToSave].ContainsKey(simulationYear))
                    {
                        //Pull the results and add them to the dictionary used to store results
                        Results results;
//.........这里部分代码省略.........
开发者ID:jckelly,项目名称:GREETAPI,代码行数:101,代码来源:Program.cs


注:本文中的Calculator.RunCalculations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。