Ejemplo n.º 1
0
        public List <List <BinaryOption> > generateFeatureWiseUntilSeconds(VariabilityModel vm, int seconds)
        {
            var cts  = new CancellationTokenSource();
            var task = Task.Factory.StartNew(() =>
            {
                #region task
                configurations.Clear();
                List <BinaryOption> optionalFirstLevelElements = new List <BinaryOption>();
                List <BinaryOption> binOptions = vm.BinaryOptions;

                //First: Add options that are present in all configurations
                List <BinaryOption> firstLevelMandatoryFeatures = new List <BinaryOption>();
                foreach (BinaryOption binOpt in binOptions)
                {
                    if (binOpt.Parent == null || binOpt.Parent == vm.Root)
                    {
                        if (!binOpt.Optional)
                        {
                            if (!binOpt.hasAlternatives())
                            {
                                firstLevelMandatoryFeatures.Add(binOpt);
                                //Todo: Recursive down search

                                /*List<BinaryOption> tmpList = (List<BinaryOption>)vm.getMandatoryChildsRecursive(binOpt);
                                 * if (tmpList != null && tmpList.Count > 0)
                                 *  firstLevelMandatoryFeatures.AddRange(tmpList);*/
                            }
                        }
                        else
                        {
                            optionalFirstLevelElements.Add(binOpt);
                        }
                    }
                }
                //Solver.CheckConfigSAT checkSAT = new Solver.CheckConfigSAT(AppDomain.CurrentDomain.BaseDirectory);
                //Solver.VariantGenerator generator = new Solver.VariantGenerator(AppDomain.CurrentDomain.BaseDirectory);
                Solver.VariantGenerator generator = new Solver.VariantGenerator(null);
                Solver.CheckConfigSAT checkSAT    = new Solver.CheckConfigSAT(null);
                //Generating new configurations: one per option
                if (checkSAT.checkConfigurationSAT(firstLevelMandatoryFeatures, vm, true))
                {
                    this.configurations.Add(firstLevelMandatoryFeatures);
                }
                foreach (BinaryOption e in binOptions)
                {
                    if (cts.IsCancellationRequested)
                    {
                        return(configurations);
                    }


                    BinaryOption[] temp = new BinaryOption[firstLevelMandatoryFeatures.Count];
                    firstLevelMandatoryFeatures.CopyTo(temp);
                    List <BinaryOption> tme = temp.ToList <BinaryOption>();
                    if (!tme.Contains(e))
                    {
                        tme.Add(e);
                        if (checkSAT.checkConfigurationSAT(tme, vm, true))
                        {
                            if (!this.configurations.Contains(tme))
                            {
                                this.configurations.Add(tme);
                            }
                        }
                        else
                        {
                            tme = generator.minimizeConfig(tme, vm, true, null);
                            if (tme != null && Configuration.containsBinaryConfiguration(this.configurations, tme) == false)
                            {
                                this.configurations.Add(tme);
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                Console.WriteLine("Found " + configurations.Count);
                return(this.configurations);

                #endregion
            }, cts.Token);

            if (Task.WaitAny(new[] { task }, TimeSpan.FromMilliseconds(seconds * 1000)) < 0)
            {
                cts.Cancel();
            }
            return(configurations);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates configurations based on the feature-wise heuristic: The method utilizes the structure of the variability model by first determining the set of options that are always selected.
        /// In each iteration, it starts from this set of options (partial configuration) and adds a single option to this partial configurations.
        /// It then checks whether configuration is valid and if not calls a CSP solver to make this configuration valid with as few selected options as possible.
        /// </summary>
        /// <param name="vm">The variability model for which the feature-wise configurations should be generated.</param>
        /// <returns>A list of configurations, in which each configuration is a list of binary options that represent the SELECTED options.</returns>
        public List <List <BinaryOption> > generateFeatureWiseConfigurations(VariabilityModel vm)
        {
            configurations.Clear();
            List <BinaryOption> optionalFirstLevelElements = new List <BinaryOption>();
            List <BinaryOption> binOptions = vm.WithAbstractBinaryOptions;

            //First: Add options that are present in all configurations
            List <BinaryOption> firstLevelMandatoryFeatures = new List <BinaryOption>();

            foreach (BinaryOption binOpt in binOptions)
            {
                if (binOpt.Parent == null || binOpt.Parent == vm.Root)
                {
                    if (!binOpt.Optional)
                    {
                        if (!binOpt.hasAlternatives())
                        {
                            firstLevelMandatoryFeatures.Add(binOpt);
                        }
                    }
                    else
                    {
                        optionalFirstLevelElements.Add(binOpt);
                    }
                }
            }
            Solver.CheckConfigSAT checkSAT = new Solver.CheckConfigSAT();
            //Generating new configurations: one per option
            if (checkSAT.checkConfigurationSAT(firstLevelMandatoryFeatures, vm, false))
            {
                this.configurations.Add(firstLevelMandatoryFeatures);
            }
            foreach (BinaryOption e in binOptions)
            {
                BinaryOption[] temp = new BinaryOption[firstLevelMandatoryFeatures.Count];
                firstLevelMandatoryFeatures.CopyTo(temp);
                List <BinaryOption> tme = temp.ToList <BinaryOption>();
                if (!tme.Contains(e))
                {
                    tme.Add(e);
                    if (checkSAT.checkConfigurationSAT(tme, vm, false))
                    {
                        if (!this.configurations.Contains(tme))
                        {
                            this.configurations.Add(tme);
                        }
                    }
                    else
                    {
                        tme = ConfigurationBuilder.vg.MinimizeConfig(tme, vm, true, null);
                        if (tme != null && Configuration.containsBinaryConfiguration(this.configurations, tme) == false)
                        {
                            this.configurations.Add(tme);
                        }
                    }
                }
                else
                {
                    continue;
                }
            }

            return(this.configurations);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates configurations based on the feature-wise heuristic: The method utilizes the structure of the variability model by first determining the set of options that are always selected.
        /// In each iteration, it starts from this set of options (partial configuration) and adds a single option to this partial configurations.
        /// It then checks whether configuration is valid and if not calls a CSP solver to make this configuration valid with as few selected options as possible.
        /// </summary>
        /// <param name="vm">The variability model for which the feature-wise configurations should be generated.</param>
        /// <returns>A list of configurations, in which each configuration is a list of binary options that represent the SELECTED options.</returns>
        public List <List <BinaryOption> > generateFeatureWiseConfigurations(VariabilityModel vm)
        {
            configurations.Clear();
            List <BinaryOption> optionalFirstLevelElements = new List <BinaryOption>();
            List <BinaryOption> binOptions = vm.BinaryOptions;

            //First: Add options that are present in all configurations
            List <BinaryOption> firstLevelMandatoryFeatures = new List <BinaryOption>();

            foreach (BinaryOption binOpt in binOptions)
            {
                if (binOpt.Parent == null || binOpt.Parent == vm.Root)
                {
                    if (!binOpt.Optional)
                    {
                        if (!binOpt.hasAlternatives())
                        {
                            firstLevelMandatoryFeatures.Add(binOpt);
                            //Todo: Recursive down search

                            /*List<BinaryOption> tmpList = (List<BinaryOption>)vm.getMandatoryChildsRecursive(binOpt);
                             * if (tmpList != null && tmpList.Count > 0)
                             *  firstLevelMandatoryFeatures.AddRange(tmpList);*/
                        }
                    }
                    else
                    {
                        optionalFirstLevelElements.Add(binOpt);
                    }
                }
            }
            Solver.CheckConfigSAT   checkSAT  = new Solver.CheckConfigSAT(null);
            Solver.VariantGenerator generator = new Solver.VariantGenerator(null);
            //Generating new configurations: one per option
            if (checkSAT.checkConfigurationSAT(firstLevelMandatoryFeatures, vm, true))
            {
                this.configurations.Add(firstLevelMandatoryFeatures);
            }
            foreach (BinaryOption e in binOptions)
            {
                BinaryOption[] temp = new BinaryOption[firstLevelMandatoryFeatures.Count];
                firstLevelMandatoryFeatures.CopyTo(temp);
                List <BinaryOption> tme = temp.ToList <BinaryOption>();
                if (!tme.Contains(e))
                {
                    tme.Add(e);
                    if (checkSAT.checkConfigurationSAT(tme, vm, true))
                    {
                        if (!this.configurations.Contains(tme))
                        {
                            this.configurations.Add(tme);
                        }
                    }
                    else
                    {
                        tme = generator.minimizeConfig(tme, vm, true, null);
                        if (tme != null && Configuration.containsBinaryConfiguration(this.configurations, tme) == false)
                        {
                            this.configurations.Add(tme);
                        }
                    }
                }
                else
                {
                    continue;
                }
            }

            return(this.configurations);
        }
        /// <summary>
        /// Generates configurations based on the feature-wise heuristic: The method utilizes the structure of the variability model by first determining the set of options that are always selected.
        /// In each iteration, it starts from this set of options (partial configuration) and adds a single option to this partial configurations. 
        /// It then checks whether configuration is valid and if not calls a CSP solver to make this configuration valid with as few selected options as possible.
        /// </summary>
        /// <param name="vm">The variability model for which the feature-wise configurations should be generated.</param>
        /// <returns>A list of configurations, in which each configuration is a list of binary options that represent the SELECTED options.</returns>
        public List<List<BinaryOption>> generateFeatureWiseConfigurations(VariabilityModel vm)
        {
            configurations.Clear();
            List<BinaryOption> optionalFirstLevelElements = new List<BinaryOption>();
            List<BinaryOption> binOptions = vm.BinaryOptions;

            //First: Add options that are present in all configurations
            List<BinaryOption> firstLevelMandatoryFeatures = new List<BinaryOption>();
            foreach (BinaryOption binOpt in binOptions)
            {
                if (binOpt.Parent == null || binOpt.Parent == vm.Root)
                {
                    if (!binOpt.Optional)
                    {
                        if (!binOpt.hasAlternatives())
                        {
                            firstLevelMandatoryFeatures.Add(binOpt);
                            //Todo: Recursive down search
                            /*List<BinaryOption> tmpList = (List<BinaryOption>)vm.getMandatoryChildsRecursive(binOpt);
                            if (tmpList != null && tmpList.Count > 0)
                                firstLevelMandatoryFeatures.AddRange(tmpList);*/
                        }
                    }
                    else
                        optionalFirstLevelElements.Add(binOpt);
                }
            }
            Solver.CheckConfigSAT checkSAT = new Solver.CheckConfigSAT(null);
            Solver.VariantGenerator generator = new Solver.VariantGenerator(null);
            //Generating new configurations: one per option
            if (checkSAT.checkConfigurationSAT(firstLevelMandatoryFeatures, vm, false))
                this.configurations.Add(firstLevelMandatoryFeatures);
            foreach (BinaryOption e in binOptions)
            {
                BinaryOption[] temp = new BinaryOption[firstLevelMandatoryFeatures.Count];
                firstLevelMandatoryFeatures.CopyTo(temp);
                List<BinaryOption> tme = temp.ToList<BinaryOption>();
                if (!tme.Contains(e))
                {
                    tme.Add(e);
                    if (checkSAT.checkConfigurationSAT(tme, vm, false))
                    {
                        if (!this.configurations.Contains(tme))
                            this.configurations.Add(tme);
                    }
                    else
                    {
                        tme = generator.minimizeConfig(tme, vm, true, null);
                        if (tme != null && Configuration.containsBinaryConfiguration(this.configurations, tme) == false)
                            this.configurations.Add(tme);
                    }
                }
                else
                    continue;
            }

            return this.configurations;
        }