Ejemplo n.º 1
0
        public List <List <BinaryOption> > getSample(Dictionary <string, string> parameter)
        {
            int numberConfigs;

            int optionWeight = 1;

            string numConfigsValue = null;

            if (parameter.ContainsKey(NUMBER_SAMPLES))
            {
                numConfigsValue = parameter[NUMBER_SAMPLES];
            }
            else
            {
                numConfigsValue = "asOW";
            }

            if (numConfigsValue.Contains("asOW"))
            {
                FeatureWise fw = new FeatureWise();
                numberConfigs = fw.generateFeatureWiseConfigsCSP(vm).Count;
            }
            else if (numConfigsValue.Contains("asTW"))
            {
                numConfigsValue.Replace("asTW", "");
                numberConfigs = Int32.Parse(numConfigsValue);
                TWise tw = new TWise();
                numberConfigs = tw.generateT_WiseVariants_new(vm, numberConfigs).Count;
            }
            else
            {
                numberConfigs = Int32.Parse(numConfigsValue);
            }

            if (parameter.ContainsKey(OPTION_WEIGHT))
            {
                optionWeight = Int32.Parse(parameter[OPTION_WEIGHT]);
            }

            List <BinaryOption> minimalConfiguration = ConfigurationBuilder.vg.MinimizeConfig(new List <BinaryOption>(), vm, true, null);

            return(ConfigurationBuilder.vg.DistanceMaximization(vm, minimalConfiguration, numberConfigs, optionWeight));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a set of random binary partial configurations.
        /// </summary>
        /// <param name="parameters">Parameters for this random sampling. The following paramters are supported:
        /// seed = the seed for the random generator (int required)
        /// numConfigs = the number of configurations that have to be selected.
        ///              To be able ot select a number of configurations equal to the number selected by the OW heuristic or
        ///              the TWise heuristics, two special values can be given for this paramter. To select a number equal to
        ///              the OW heuristics use "asOW" as value and to select a number equal to a TWise heuristics with a t of X
        ///              use "asTWX".
        /// </param>
        /// <returns>A list of random binary partial configuartions.</returns>
        public List <List <BinaryOption> > getRandomConfigs(Dictionary <String, String> parameters)
        {
            configurations.Clear();

            int seed       = 0;
            int numConfigs = varModel.BinaryOptions.Count;

            // parse parameters
            if (parameters.ContainsKey("numConfigs"))
            {
                String numConfigsValue = parameters["numConfigs"];
                if (!int.TryParse(numConfigsValue, out numConfigs))
                {
                    // special constants as parameter (numConfigs = asOW or asTWX
                    if (numConfigsValue.Contains("asOW"))
                    {
                        FeatureWise fw = new FeatureWise();
                        numConfigs = fw.generateFeatureWiseConfigsCSP(varModel).Count;
                    }
                    else if (numConfigsValue.Contains("asTW"))
                    {
                        numConfigsValue = numConfigsValue.Replace("asTW", "").Trim();
                        int.TryParse(numConfigsValue, out numConfigs);
                        TWise tw = new TWise();
                        numConfigs = tw.generateT_WiseVariants_new(varModel, numConfigs).Count;
                    }
                }
            }
            if (parameters.ContainsKey("seed"))
            {
                int.TryParse(parameters["seed"], out seed);
            }

            // build set of all valid binary partial configurations
            VariantGenerator            vg         = new VariantGenerator();
            List <List <BinaryOption> > allConfigs = vg.generateAllVariantsFast(varModel);

            //repair wrong parameters
            if (numConfigs >= allConfigs.Count)
            {
                if (numConfigs > allConfigs.Count)
                {
                    GlobalState.logError.logLine("Random Sampling: numConfigs to large for variability model. num set to " + allConfigs.Count);
                }
                configurations = allConfigs;
                return(allConfigs);
            }

            // select random configurations
            Random r = new Random(seed);

            for (int i = 0; i < numConfigs; i++)
            {
                List <BinaryOption> selectedConfig = allConfigs[r.Next(allConfigs.Count + 1)];

                if (configurations.Contains(selectedConfig))
                {
                    i -= 1;
                }
                else
                {
                    configurations.Add(selectedConfig);
                }
            }
            return(configurations);
        }