/// <summary> /// This method reads all configurations specified in the .csv file. In this mehtod, we assume that the file has a header. /// </summary> /// <param name="file"></param> /// <param name="model">The variabiliy model for the configurations.</param> /// <returns>A list of all configurations </returns> public static List <Configuration> readConfigurations_Header_CSV(String file, VariabilityModel model) { List <Configuration> configurations = new List <Configuration>(); StreamReader sr = new StreamReader(file); String[] optionOrder = new String[model.getOptions().Count]; String[] nfpOrder = null; bool isHeader = true; while (!sr.EndOfStream) { String[] tokens = sr.ReadLine().Split(';'); if (isHeader) { nfpOrder = new String[tokens.Length - optionOrder.Length]; for (int i = 0; i < tokens.Length; i++) { String token = tokens[i]; if (i < optionOrder.Length) { optionOrder[i] = token; } else { nfpOrder[i - optionOrder.Length] = token; if (!GlobalState.nfProperties.ContainsKey(token)) { GlobalState.nfProperties.Add(token, new NFProperty(token)); } } } isHeader = false; } else { Dictionary <BinaryOption, BinaryOption.BinaryValue> binOptions = new Dictionary <BinaryOption, BinaryOption.BinaryValue>(); Dictionary <NumericOption, double> numOptions = new Dictionary <NumericOption, double>(); Dictionary <NFProperty, double> properties = new Dictionary <NFProperty, double>(); for (int i = 0; i < tokens.Length; i++) { String token = tokens[i]; if (i < optionOrder.Length) { ConfigurationOption option = model.getOption(optionOrder[i]); if (option.GetType() == typeof(BinaryOption)) { if (token.Equals("true") || token.Equals("1")) { binOptions.Add((BinaryOption)option, BinaryOption.BinaryValue.Selected); } } else { double value = Convert.ToDouble(token); numOptions.Add((NumericOption)option, value); } } else { NFProperty nfp = GlobalState.nfProperties[nfpOrder[i - optionOrder.Length]]; double value = Convert.ToDouble(token); properties.Add(nfp, value); double currentMaxMeasuredValue; if (GlobalState.allMeasurements.maxMeasuredValue.TryGetValue(nfp, out currentMaxMeasuredValue)) { if (Math.Abs(value) > Math.Abs(currentMaxMeasuredValue)) { GlobalState.allMeasurements.maxMeasuredValue[nfp] = value; } } else { GlobalState.allMeasurements.maxMeasuredValue.Add(nfp, value); } } } Configuration config = new Configuration(binOptions, numOptions, properties); configurations.Add(config); } } sr.Close(); return(configurations); }
/// <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); }
/// <summary> /// This method reads all configurations specified in the .csv file. In this mehtod, we assume that the file has a header. /// </summary> /// <param name="file"></param> /// <param name="model">The variabiliy model for the configurations.</param> /// <returns>A list of all configurations </returns> public static List<Configuration> readConfigurations_Header_CSV(String file, VariabilityModel model) { List<Configuration> configurations = new List<Configuration>(); StreamReader sr = new StreamReader(file); String[] optionOrder = new String[model.getOptions().Count - 1]; String[] nfpOrder = null; bool isHeader = true; while(!sr.EndOfStream) { String[] tokens = sr.ReadLine().Split(';'); if (isHeader) { nfpOrder = new String[tokens.Length - optionOrder.Length]; for (int i = 0; i < tokens.Length; i++) { String token = tokens[i]; if (i < optionOrder.Length) { optionOrder[i] = token; } else { nfpOrder[i - optionOrder.Length] = token; if (!GlobalState.nfProperties.ContainsKey(token)) { GlobalState.nfProperties.Add(token, new NFProperty(token)); } } } isHeader = false; } else { Dictionary<BinaryOption, BinaryOption.BinaryValue> binOptions = new Dictionary<BinaryOption, BinaryOption.BinaryValue>(); Dictionary<NumericOption, double> numOptions = new Dictionary<NumericOption, double>(); Dictionary<NFProperty, double> properties = new Dictionary<NFProperty, double>(); for (int i = 0; i < tokens.Length; i++) { String token = tokens[i]; if (i < optionOrder.Length) { ConfigurationOption option = model.getOption(optionOrder[i]); if (option.GetType() == typeof(BinaryOption)) { if (token.Equals("true") || token.Equals("1")) binOptions.Add((BinaryOption)option, BinaryOption.BinaryValue.Selected); else binOptions.Add((BinaryOption)option, BinaryOption.BinaryValue.Deselected); } else { double value = Convert.ToDouble(token); numOptions.Add((NumericOption)option, value); } } else { NFProperty nfp = GlobalState.nfProperties[nfpOrder[i - optionOrder.Length]]; double value = Convert.ToDouble(token); properties.Add(nfp, value); double currentMaxMeasuredValue; if (GlobalState.allMeasurements.maxMeasuredValue.TryGetValue(nfp, out currentMaxMeasuredValue)) { if (Math.Abs(value) > Math.Abs(currentMaxMeasuredValue)) { GlobalState.allMeasurements.maxMeasuredValue[nfp] = value; } } else { GlobalState.allMeasurements.maxMeasuredValue.Add(nfp, value); } } } Configuration config = new Configuration(binOptions, numOptions, properties); configurations.Add(config); } } sr.Close(); return configurations; }
/// <summary> /// Checks if the specified expression is compatible with the specified model. /// </summary> /// <param name="exp">Specified expression. Must not be null.</param> /// <param name="model">Specified variability model. Must not be null.</param> /// <returns>Returns true if expression and model are compatible else false</returns> private bool checkExpressionCompatibility(string exp, VariabilityModel model) { if (exp == null) throw new ArgumentNullException("Parameter exp must not be null!"); if (model == null) throw new ArgumentNullException("Parameter model must not be null!"); foreach (string prt in exp.Split(' ')) { double d; if (!isOperator(prt) && prt != "log10(" && prt != ")" && !double.TryParse(prt, out d) && model.getOption(prt) == null) { return false; } } return true; }