Ejemplo n.º 1
0
        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 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;
                }
            }
        }