private void findAlternatives(Dictionary <string, VariationPoint> varPoints) { foreach (VariationPoint vP in varPoints.Values) { Dictionary <String, DuneFeature> result = ProgramUtil.getAlternativesRecursive(vP.defaultValue); vP.alternatives = result; } }
private static void generateVariants(DuneApplication da, string RESULT_DIR) { int numberOfVariants = 1; // identify all alternatives without ?? String unfilteredMiniFileContent = ProgramUtil.generateMiniFileContent(da); File.WriteAllText(RESULT_DIR + "unfilteredmini.mini", unfilteredMiniFileContent); foreach (KeyValuePair <String, VariationPoint> varP in da.varPoints) { Dictionary <String, DuneFeature> resultsUnfiltered = ProgramUtil.getAlternativesRecursive(varP.Value.defaultValue); Dictionary <String, DuneFeature> filtered = ProgramUtil.filter(resultsUnfiltered); varP.Value.alternatives = filtered; numberOfVariants = numberOfVariants * filtered.Count; } //List<Variant> allVariants = new List<Variant>(); //for(int i = 0; i < numberOfVariants; i++) //{ // allVariants.Add(new Variant()); //} Dictionary <VariationPoint, int> varPo = new Dictionary <VariationPoint, int>(); foreach (KeyValuePair <String, VariationPoint> varP in da.varPoints) { varPo.Add(varP.Value, varP.Value.alternatives.Count); } List <KeyValuePair <VariationPoint, int> > varPList = varPo.ToList(); double[,] allAlternatives = getFullFactorial(varPList, numberOfVariants); for (int i = 0; i < allAlternatives.GetLength(0); i++) { String curr = ""; for (int j = 0; j < allAlternatives.GetLength(1); j++) { curr = curr + allAlternatives.GetValue(new int[] { i, j }) + ";"; } File.AppendAllText(RESULT_DIR + "variants2.txt", curr + Environment.NewLine); } //for (int i = 0; i < allVariants.Count; i++) //{ // int varPIndex = 0; // foreach (KeyValuePair<VariationPoint,int> varP in varPList) // { // int alternative = (int)allAlternatives[i, varPIndex]; // string value = varP.Key.alternatives[alternative]; // allVariants[i].selectedAlternatives.Add(varP.Key, value); // varPIndex++; // } //} //foreach (KeyValuePair<String, VariationPoint> varP in da.varPoints) //{ // int repitions = allVariants.Count / powerTwo; // int currIndex = 0; // for (int i = 0; i < allVariants.Count; i++) // { // for(int repi = 0; repi < repitions; repitions++) // { // Variant variant = allVariants[i + repi]; // variant.selectedAlternatives.Add(varP.Value, varP.Value.alternatives[currIndex]); // //variant.selectedAlternatives.Add(varP.Value, ""+currIndex); // } // currIndex = ((currIndex +1) % varP.Value.alternatives.Count); // } // powerTwo = powerTwo * 2; //} //Console.WriteLine( allVariants.Count); String miniFileContent = ProgramUtil.generateMiniFileContent(da); File.WriteAllText(MINI_FILE_LOCATION, miniFileContent); //writeVariantsToCSV(allVariants, Program.RESULT_DIR); updateCMakeLists(NEW_C_MAKE_LISTS); }
public static void showShell() { bool quit = false; while (!quit) { System.Console.Write("Dune>"); string input = System.Console.ReadLine(); int firstSpace = input.IndexOf(' '); string command; string arguments = ""; if (firstSpace < 0) { command = input; } else { command = input.Substring(0, firstSpace); arguments = input.Substring(firstSpace, input.Length - firstSpace).Trim(); } switch (command.ToLower()) { case "getClassesWithName": case "g": foreach (DuneClass f in XMLParser.getClassesWithName(arguments)) { System.Console.WriteLine(f.getFeatureName()); } break; case "analyze": case "a": arguments = arguments.Replace("<", " <"); arguments = arguments.Replace(">", " >"); List <string> result = ProgramUtil.getAlternativesRecursive(arguments).Keys.ToList(); if (result != null) { foreach (string s in result) { System.Console.WriteLine(s); } System.Console.WriteLine("Found " + result.Count + " possible alternative(s)."); } else { System.Console.WriteLine("The class wasn't found."); } break; case "iniGeneration": case "i": StreamReader inFile = new System.IO.StreamReader(Program.DEBUG_PATH + "IniInput.txt"); int count = 0; List <List <string> > glResult = new List <List <string> >(); Dictionary <String, List <String> > resultsByVariablePoints = new Dictionary <string, List <string> >(); List <string> iniFilePlaceHolder = new List <string>(); // Find the alternatives of those classes while (!inFile.EndOfStream) { String line = inFile.ReadLine().Trim(); if (!line.Equals("")) { String[] tokens = line.Split(Program.SPLIT_SYMBOL); iniFilePlaceHolder.Add(tokens[0].Trim()); List <String> analyzationResult = ProgramUtil.getAlternativesRecursive(tokens[1].Trim()).Keys.ToList(); resultsByVariablePoints.Add(tokens[1].Trim(), new List <string>()); if (analyzationResult != null) { glResult.Add(analyzationResult); } else { glResult.Add(new List <string>()); } foreach (String oneAlternative in analyzationResult) { resultsByVariablePoints[tokens[1].Trim()].Add(oneAlternative); } } } Program.generateVariabilityModel(resultsByVariablePoints); // Use the whole information and generate the output (ini-files) int[] configCount = new int[glResult.Count]; bool stop = false; while (!stop) { // Print the current configuration StreamWriter outp = new System.IO.StreamWriter(Program.DEBUG_PATH + "diffusion_" + String.Format("{0:0000}", count) + ".ini"); count++; for (int j = 0; j < configCount.Length; j++) { outp.WriteLine(iniFilePlaceHolder[j] + " " + Program.SPLIT_SYMBOL + " " + glResult[j][configCount[j]]); } outp.Close(); // Check if there is another configuration bool backwards = true; int i = configCount.Length - 1; while (i >= 0 && i < configCount.Length) { if (backwards) { if (configCount[i] < glResult[i].Count - 1) { configCount[i]++; backwards = false; i++; } else { i--; } } else { configCount[i] = 0; i++; } } if (i == -1 && backwards) { stop = true; } } inFile.Close(); break; case "fileAnalyzation": case "f": StreamReader inputFile = new System.IO.StreamReader(Program.DEBUG_PATH + "classesInDiffusion.txt"); StreamReader compFile = new System.IO.StreamReader(Program.DEBUG_PATH + "minimalSetClasses.txt"); StreamWriter output = new System.IO.StreamWriter(Program.DEBUG_PATH + "analyzation.txt"); StreamWriter positives = new System.IO.StreamWriter(Program.DEBUG_PATH + "positives.txt"); List <List <string> > globalResult = new List <List <string> >(); Dictionary <String, List <String> > resultsByVariabilityPoints = new Dictionary <string, List <string> >(); while (!inputFile.EndOfStream) { String line = inputFile.ReadLine().Trim(); if (!line.Equals("")) { Console.WriteLine("Identify Alternatives for class " + line); List <String> analyzationResult = ProgramUtil.getAlternativesRecursive(line).Keys.ToList(); resultsByVariabilityPoints.Add(line, new List <string>()); if (analyzationResult != null) { globalResult.Add(analyzationResult); } else { globalResult.Add(new List <string>()); } foreach (String oneAlternative in analyzationResult) { resultsByVariabilityPoints[line].Add(oneAlternative); } } } Program.generateVariabilityModel(resultsByVariabilityPoints); int c = 0; int foundMin = 0; int notFound = 0; while (!compFile.EndOfStream) { String l = compFile.ReadLine(); if (!l.Trim().Equals("")) { switch (containsName(l, globalResult.ElementAt(c))) { case 1: foundMin++; break; case 0: foundMin++; output.WriteLine("This classes name was found: " + l); break; case -1: notFound++; output.WriteLine(l); break; } } else { output.WriteLine(foundMin + "; " + notFound + "; " + globalResult.ElementAt(c).Count); foundMin = 0; notFound = 0; c++; } } // Write the whole set of positives in a file foreach (List <string> results in globalResult) { foreach (string localResult in results) { positives.WriteLine(localResult); } positives.WriteLine(); } output.Flush(); output.Close(); inputFile.Close(); compFile.Close(); positives.Flush(); positives.Close(); break; case "help": case "?": printHelp(); break; case "quit": case "q": quit = true; break; } } }
public void run() { bool quit = false; while (!quit) { Console.Write("DuneAnalyzer>"); String input = Console.ReadLine().Trim(); string[] args = input.Split(new char[] { ' ' }); switch (input.ToLowerInvariant()[0]) { case 'q': quit = true; break; case 'p': if (args[1] == "--all" && args.Length == 2) { Console.Write(ProgramUtil.generateMiniFileContent(da)); } else if (args[1] == "--all") { VariationPoint vaPo; if (!tryGetVariationPoint(args[2], da, out vaPo)) { break; } StringBuilder sb = new StringBuilder(); ProgramUtil.generateVariationPointContent(vaPo, vaPo.getIdentifyer(), sb, new StringBuilder()); Console.Write(sb); } else if (args[1] == "--filtered" && args.Length == 2) { foreach (KeyValuePair <string, VariationPoint> vaPo in da.varPoints) { StringBuilder alternatives = new StringBuilder(); ProgramUtil.alternativesToString(ProgramUtil.filter(vaPo.Value.alternatives), vaPo.Value.getIdentifyer(), alternatives, new StringBuilder()); Console.Write(alternatives.ToString()); } } else if (args[1] == "--filtered") { VariationPoint vaPo; if (!tryGetVariationPoint(args[2], da, out vaPo)) { break; } StringBuilder alternatives = new StringBuilder(); ProgramUtil.alternativesToString(ProgramUtil.filter(vaPo.alternatives), vaPo.getIdentifyer(), alternatives, new StringBuilder()); Console.Write(alternatives.ToString()); } break; case 'r': if (args.Length == 4) { VariationPoint vaPo; if (!tryGetVariationPoint(args[1], da, out vaPo)) { break; } string old = args[2]; string newVariableName = args[3]; // Special symbol to delete words if (newVariableName == "_") { newVariableName = ""; } Dictionary <string, DuneFeature> tmp = new Dictionary <string, DuneFeature>(); foreach (KeyValuePair <string, DuneFeature> va in vaPo.alternatives) { if (va.Key.Contains(">")) { String[] split = va.Key.Split(new string[] { "<", ">" }, StringSplitOptions.None); tmp.Add(split[0] + "<" + split[1].Replace("," + old, newVariableName) + ">", va.Value); } else { tmp.Add(va.Key, va.Value); } } vaPo.alternatives = tmp; } break; case 's': if (args[1] == "--all") { File.WriteAllText(miniLocation, ProgramUtil.generateMiniFileContent(da)); } else if (args[1] == "--filtered") { File.WriteAllText(miniLocation, ProgramUtil.generateFilteredMiniFileContent(da)); } break; case 'd': if (args.Length == 3) { VariationPoint vaPo; if (!tryGetVariationPoint(args[1], da, out vaPo)) { break; } vaPo.alternatives.Remove(vaPo.alternatives.ElementAt(int.Parse(args[2])).Key); } break; case 'c': { VariationPoint vaPo; if (!tryGetVariationPoint(args[1], da, out vaPo)) { break; } string newTemplate = parseTemplateArg(args); Dictionary <string, DuneFeature> newAlternatives = ProgramUtil.getAlternativesRecursive(newTemplate); vaPo.defaultValue = newTemplate; vaPo.alternatives = newAlternatives; if (newAlternatives.Count == 0) { writeConsoleWarning("Warning: Given template could not be found."); } } break; case 'a': { VariationPoint vaPo; if (!tryGetVariationPoint(args[1], da, out vaPo)) { break; } string newTemplate = parseTemplateArg(args); Dictionary <string, DuneFeature> newAlternatives = ProgramUtil.getAlternativesRecursive(newTemplate); int oldCount = vaPo.alternatives.Count; vaPo.alternatives = vaPo.alternatives.Union(newAlternatives).ToDictionary(x => x.Key, x => x.Value); int newCount = vaPo.alternatives.Count; if (newAlternatives.Count == 0) { writeConsoleWarning("Warning: Given template could not be found."); } if (oldCount == newCount) { writeConsoleWarning("Warning: No new templates found for this input."); } } break; default: writeConsoleWarning("Warning: Invalid command."); break; } } }