private VariabilityModel extractFeatureModelFromExpression(String expression) { VariabilityModel varModel = new VariabilityModel("TEMP"); string[] parts = expression.Split(new char[] { '+', '*', '[', ']' }); double value = 0.0; for (int i = 0; i < parts.Length; i++) { string part = parts[i].Trim(); if (part.Length > 0) { if (!Double.TryParse(part, out value)) { if (varModel.getNumericOption(part) == null) { NumericOption option = new NumericOption(varModel, part); varModel.addConfigurationOption(option); } } } } return(varModel); }
public VariabilityModel createVarModel() { VariabilityModel varMod = new VariabilityModel("testModel_1"); // -------------------- BINARY OPTIONS ---------------- BinaryOption binOp1 = new BinaryOption(varMod, "binOpt1"); binOp1.Optional = false; binOp1.Prefix = "--"; varMod.addConfigurationOption(binOp1); BinaryOption binOp2 = new BinaryOption(varMod, "binOpt2"); binOp2.Optional = true; binOp2.Prefix = "-?"; binOp2.Postfix = "kg"; binOp2.Parent = binOp1; binOp2.OutputString = "binOpt2"; varMod.addConfigurationOption(binOp2); BinaryOption binOp3 = new BinaryOption(varMod, "binOpt3"); binOp3.Optional = true; binOp3.Prefix = ""; binOp3.Postfix = ""; binOp3.Parent = binOp1; List<List<ConfigurationOption>> exclude = new List<List<ConfigurationOption>>(); List<ConfigurationOption> subExclude = new List<ConfigurationOption>(); subExclude.Add(binOp2); exclude.Add(subExclude); binOp3.Excluded_Options = exclude; varMod.addConfigurationOption(binOp3); BinaryOption binOp4 = new BinaryOption(varMod, "binOpt4"); binOp4.Optional = true; binOp4.Prefix = "4_"; binOp4.Postfix = "_4"; binOp4.Parent = binOp1; List<List<ConfigurationOption>> implied = new List<List<ConfigurationOption>>(); List<ConfigurationOption> subimplied = new List<ConfigurationOption>(); subimplied.Add(binOp2); implied.Add(subimplied); binOp4.Implied_Options = implied; varMod.addConfigurationOption(binOp4); // -------------------- NUMERIC OPTIONS ---------------- NumericOption numOpt1 = new NumericOption(varMod, "numOpt1"); numOpt1.DefaultValue = 0.0; numOpt1.Prefix = "num1-"; numOpt1.Postfix = "--"; numOpt1.Min_value = 0; numOpt1.Max_value = 10; numOpt1.StepFunction = new InfluenceFunction("n + 2"); varMod.addConfigurationOption(numOpt1); NumericOption numOpt2 = new NumericOption(varMod, "numOpt2"); numOpt2.DefaultValue = 0.8; numOpt2.Prefix = ""; numOpt2.Postfix = ""; numOpt2.Min_value = 0.1; numOpt2.Max_value = 5; numOpt2.StepFunction = new InfluenceFunction("n * 2"); varMod.addConfigurationOption(numOpt2); return varMod; }
/// <summary> /// Produce a reduced version of the variability model, containing only binary options /// and at least the considered options. Is a considered option, all parent option will be inlcuded. /// Constraints between options(alternative groups, implication etc), will be included if enough options /// are present to (e.g. both options for implications or at least 2 options in alternative groups). /// </summary> /// <param name="consideredOptions">The options that will be in the reduced model.</param> /// <returns>A reduced version of the model containing the considered options.</returns> public VariabilityModel reduce(List <BinaryOption> consideredOptions) { VariabilityModel reduced = new VariabilityModel(this.name); foreach (BinaryOption binOpt in consideredOptions) { BinaryOption child = new BinaryOption(reduced, binOpt.Name); replicateOption(binOpt, child); reduced.addConfigurationOption(child); BinaryOption parent = (BinaryOption)binOpt.Parent; bool parentExists = false; while ((parent != null && parent != this.root) && !parentExists) { BinaryOption newParent = reduced.getBinaryOption(parent.Name); if (newParent == null) { newParent = new BinaryOption(reduced, parent.Name); replicateOption(parent, newParent); reduced.addConfigurationOption(newParent); } else { parentExists = true; } child.Parent = newParent; child = newParent; parent = (BinaryOption)parent.Parent; } if (child.Parent == null) { child.Parent = reduced.root; } } foreach (BinaryOption opt in consideredOptions) { List <List <ConfigurationOption> > impliedOptionsRepl = new List <List <ConfigurationOption> >(); foreach (List <ConfigurationOption> implied in opt.Implied_Options) { List <ConfigurationOption> implRepl = new List <ConfigurationOption>(); foreach (ConfigurationOption impliedOption in implied) { if (reduced.getOption(impliedOption.Name) != null) { implRepl.Add(reduced.getOption(impliedOption.Name)); } } impliedOptionsRepl.Add(implRepl); } reduced.getBinaryOption(opt.Name).Implied_Options = impliedOptionsRepl; List <List <ConfigurationOption> > excludedOptionsRepl = new List <List <ConfigurationOption> >(); foreach (List <ConfigurationOption> excluded in opt.Excluded_Options) { List <ConfigurationOption> exclRepl = new List <ConfigurationOption>(); foreach (ConfigurationOption excludedOption in excluded) { if (reduced.getOption(excludedOption.Name) != null) { exclRepl.Add(reduced.getOption(excludedOption.Name)); } } excludedOptionsRepl.Add(exclRepl); } reduced.getBinaryOption(opt.Name).Excluded_Options = excludedOptionsRepl; } return(reduced); }
private VariabilityModel extractFeatureModelFromExpression(String expression) { VariabilityModel varModel = new VariabilityModel("TEMP"); string[] parts = expression.Split(new char[] { '+', '*', '[', ']' }); double value = 0.0; for (int i = 0; i < parts.Length;i++) { string part = parts[i].Trim(); if (part.Length > 0) { if (!Double.TryParse(part, out value)) { if (varModel.getNumericOption(part) == null) { NumericOption option = new NumericOption(varModel, part); varModel.addConfigurationOption(option); } } } } return varModel; }