public void updateChildren() { this.children = new List <ConfigurationOption>(); foreach (ConfigurationOption other in vm.getOptions()) { if (other.parent != null && other.parent.Equals(this) && !this.children.Contains(other)) { this.children.Add(other); } } }
/// <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> /// 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; }