/// <summary> /// This method returns a list of binary options that comply to the given configuration value. /// </summary> /// <param name="binaryValue">The configuration value ((DE-)Selected).</param> /// <returns>The list of binary options according to the given value.</returns> public List <BinaryOption> getBinaryOptions(BinaryOption.BinaryValue binaryValue) { List <BinaryOption> result = new List <BinaryOption>(); foreach (KeyValuePair <BinaryOption, BinaryOption.BinaryValue> bin in this.binaryOptions) { if (bin.Value.Equals(binaryValue)) { result.Add(bin.Key); } } return(result); }
/// <summary> /// Generates all valid combinations of all configuration options in the given model. /// </summary> /// <param name="vm">the variability model containing the binary options and their constraints</param> /// <param name="optionsToConsider">the options that should be considered. All other options are ignored</param> /// <returns>Returns a list of <see cref="Configuration"/></returns> public List <Configuration> GenerateAllVariants(VariabilityModel vm, List <ConfigurationOption> optionsToConsider) { List <Configuration> allConfigurations = new List <Configuration>(); Dictionary <CspTerm, bool> variables; Dictionary <ConfigurationOption, CspTerm> optionToTerm; Dictionary <CspTerm, ConfigurationOption> termToOption; ConstraintSystem S = CSPsolver.GetGeneralConstraintSystem(out variables, out optionToTerm, out termToOption, vm); ConstraintSolverSolution soln = S.Solve(); while (soln.HasFoundSolution) { Dictionary <BinaryOption, BinaryOption.BinaryValue> binOpts = new Dictionary <BinaryOption, BinaryOption.BinaryValue>(); Dictionary <NumericOption, double> numOpts = new Dictionary <NumericOption, double>(); foreach (CspTerm ct in variables.Keys) { // Ignore all options that should not be considered. if (!optionsToConsider.Contains(termToOption[ct])) { continue; } // If it is a binary option if (variables[ct]) { BinaryOption.BinaryValue isSelected = soln.GetIntegerValue(ct) == 1 ? BinaryOption.BinaryValue.Selected : BinaryOption.BinaryValue.Deselected; if (isSelected == BinaryOption.BinaryValue.Selected) { binOpts.Add((BinaryOption)termToOption[ct], isSelected); } } else { numOpts.Add((NumericOption)termToOption[ct], soln.GetIntegerValue(ct)); } } Configuration c = new Configuration(binOpts, numOpts); // Check if the non-boolean constraints are satisfied if (vm.configurationIsValid(c) && !IsInConfigurationFile(c, allConfigurations) && FulfillsMixedConstraints(c, vm)) { allConfigurations.Add(c); } soln.GetNext(); } return(allConfigurations); }