Beispiel #1
0
        /// <summary>
        /// Generates PCC scripts
        /// </summary>
        private PCC.RootObject GeneratePCCScripts()
        {
            var pccDriverCfgFile = "PCCDriverconfigs.json";
            var PCCDriver = this.pet.Children.PCCDriverCollection.FirstOrDefault();

            var upMethod = PCCDriver.Attributes.PCC_UP_Methods;
            int upMethodNum;

            switch (upMethod)
            {
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Monte_Carlo_Simulation__UP_MCS_:
                    upMethodNum = 1;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Taylor_Series_Approximation__UP_TS_:
                    upMethodNum = 2;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Most_Probable_Point_Method__UP_MPP_:
                    this.Logger.WriteWarning("The output from Most Probable Point Method is not compatible with the project analyzer Dashboard.");
                    upMethodNum = 3;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Full_Factorial_Numerical_Integration__UP_FFNI_:
                    upMethodNum = 4;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Univariate_Dimension_Reduction_Method__UP_UDR_:
                    upMethodNum = 5;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_UP_Methods_enum.Polynomial_Chaos_Expansion__UP_PCE_:
                    this.Logger.WriteWarning("The output from Polynomial Chaos Expansion is not compatible with the project analyzer Dashboard.");
                    this.Logger.WriteWarning("Trying to display such data might require a refresh in order to view other data again.");
                    upMethodNum = 6;
                    break;
                default:
                    upMethodNum = 0;
                    break;
            }

            var saMethod = PCCDriver.Attributes.PCC_SA_Methods;
            int saMethodNum;

            switch (saMethod)
            {
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_SA_Methods_enum.Sobol_method__SA_SOBOL_:
                    saMethodNum = 7;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_SA_Methods_enum.FAST_method__SA_FAST_:
                    saMethodNum = 9;
                    break;
                case CyPhyClasses.PCCDriver.AttributesClass.PCC_SA_Methods_enum.EFAST_method__SA_EFAST_:
                    saMethodNum = 10;
                    break;
                default:
                    saMethodNum = 0;
                    break;
            }

            // Generate input config file for OSU code

            var pccConfig = this.BuildUpPCCConfiguration(driverName, PCCDriver, upMethodNum, saMethodNum);

            List<string> objectives = new List<string>();
            List<string> designVariabels = new List<string>();

            foreach (var item in pccConfig.Configurations.Configuration.PCCInputArguments.PCCMetrics)
            {
                objectives.Add("TestBench." + item.TestBenchMetricName);
            }

            foreach (var item in pccConfig.Configurations.Configuration.PCCInputArguments.StochasticInputs.InputDistributions)
            {
                designVariabels.Add("TestBench." + item.TestBenchParameterNames.FirstOrDefault());
            }

            // Add registry defied inputdistributions for Properties in Components
            var PCCPropertyInputs = TryToObtainDyanmicsProperties();
            foreach (var pccProperty in PCCPropertyInputs)
            {
                this.Logger.WriteDebug("Adding Property Input Distribution, Name : {0}, Distribution : {1}", pccProperty.Name, pccProperty.Distribution);
                // TODO: Can multiple testbench names be handled correctly? For now only use the first.
                var testBenchParameterName = pccProperty.TestBenchParameterNames.FirstOrDefault();
                pccProperty.TestBenchParameterNames.Clear();
                pccProperty.TestBenchParameterNames.Add(testBenchParameterName);
                this.PCCPropertyInputDistributions.Add(pccProperty.Name, testBenchParameterName);
                pccConfig.Configurations.Configuration.PCCInputArguments.StochasticInputs.InputDistributions.Add(pccProperty);
            }

            PETConfig.Driver driver = new PETConfig.Driver()
            {
                type = "PCCDriver",
                details = new Dictionary<string, object>(),
                designVariables = new Dictionary<string, PETConfig.DesignVariable>(),
                objectives = new Dictionary<string, PETConfig.Parameter>(),
            };
            this.config.drivers.Add(PCCDriver.Name, driver);
            driver.details["Configurations"] = pccConfig.Configurations;

            foreach (var designVariable in PCCDriver.Children.PCCParameterCollection)
            {
                var configVariable = new PETConfig.DesignVariable();
                driver.designVariables.Add(designVariable.Name, configVariable);
            }
            foreach (var objective in PCCDriver.Children.PCCOutputCollection)
            {
                var sourcePath = GetSourcePath(null, (MgaFCO)objective.Impl);
                if (sourcePath != null)
                {
                    driver.objectives.Add(objective.Name, new PETConfig.Parameter()
                    {
                        source = sourcePath
                    });
                }
            }

            return pccConfig;
        }
Beispiel #2
0
        private PETConfig.Driver AddConfigurationForMDAODriver(CyPhy.MDAODriver driver)
        {

            var config = new PETConfig.Driver()
            {
                designVariables = new Dictionary<string, PETConfig.DesignVariable>(),
                objectives = new Dictionary<string, PETConfig.Parameter>(),
                constraints = new Dictionary<string, PETConfig.Constraint>(),
                intermediateVariables = new Dictionary<string, PETConfig.Parameter>(),
                details = new Dictionary<string, object>()
            };
            this.config.drivers.Add(driver.Name, config);
            foreach (var designVariable in driver.Children.DesignVariableCollection)
            {
                var configVariable = new PETConfig.DesignVariable();
                config.designVariables.Add(designVariable.Name, configVariable);

                var range = designVariable.Attributes.Range;
                var oneValue = new System.Text.RegularExpressions.Regex(
                    // start with previous match. match number or string
                    "\\G(" +
                    // number:
                    // TODO: scientific notation?
                    // TODO: a la NumberStyles.AllowThousands?
                    "[+-]?(?:\\d*[.])?\\d+" + "|" +
                    // string: match \ escape sequence, or anything but \ or "
                    "\"(?:\\\\(?:\\\\|\"|/|b|f|n|r|t|u\\d{4})|[^\\\\\"])*\"" +
                    // match ends with ; or end of string
                    ")(?:;|$)");
                /*
                Print(oneValue.Matches("12;"));
                Print(oneValue.Matches("12.2;"));
                Print(oneValue.Matches("\"\""));
                Print(oneValue.Matches("\";asdf;asd\""));
                Print(oneValue.Matches("\"\\\"\"")); // \"
                Print(oneValue.Matches("\"\\\\\"")); // \\
                Print(oneValue.Matches("\"\\n\"")); // \n
                Print(oneValue.Matches("\"\\n\";\"\";\"asdf\""));
                Print(oneValue.Matches("\"\\\"")); // \ => false
                Print(oneValue.Matches("\"\"\"")); // " => false
                */
                MatchCollection matches = oneValue.Matches(range);
                if (matches.Count > 0)
                {
                    var items = matches.Cast<Match>().Select(x => x.Groups[1].Value).Select(x =>
                        x[0] == '"' ? (string)JsonConvert.DeserializeObject(x) :
                            (object)Double.Parse(x, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture)
                        ).ToList();
                    // special-case: a single number produces a double range
                    if (matches.Count == 1 && matches[0].Groups[1].Value[0] != '"')
                    {
                        configVariable.RangeMin = (double)items[0];
                        configVariable.RangeMax = (double)items[0];
                    }
                    else
                    {
                        configVariable.items = items;
                        configVariable.type = "enum";
                    }
                }
                else if (designVariable.Attributes.Range.Contains(","))
                {
                    var range_split = designVariable.Attributes.Range.Split(new char[] { ',' });
                    if (range_split.Length == 2)
                    {
                        configVariable.RangeMin = Double.Parse(range_split[0], NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture);
                        configVariable.RangeMax = Double.Parse(range_split[1], NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    throw new ApplicationException(String.Format("Cannot parse Design Variable Range '{0}'. ", designVariable.Attributes.Range) +
                        "Double ranges are specified by an un-quoted value or two un-quoted values separated by commas. " +
                        "Enumerations are specified by one double-quoted value or two or more double-quoted values separated by semicolons. " +
                        "E.g.: '2.0,2.5' or '\"Low\";\"Medium\";\"High\"'"
                        );
                }
            }
            foreach (var objective in driver.Children.ObjectiveCollection)
            {
                var sourcePath = GetSourcePath(null, (MgaFCO)objective.Impl);
                if (sourcePath != null)
                {
                    config.objectives.Add(objective.Name, new PETConfig.Parameter()
                    {
                        source = sourcePath
                    });
                }
            }

            foreach (MgaAttribute attribute in ((MgaFCO)driver.Impl).Attributes)
            {
                config.details.Add(attribute.Meta.Name, attribute.StringValue);
            }

            return config;
        }