Exemplo n.º 1
0
        private static void Benchmark(List <MuFormula> list)
        {
            Log("Formula; LTS Size; Algorithm; Time");

            double[,] results = new double[list.Count * 2, 13];
            bool lastResult = false;

            foreach (var formula in list)
            {
                int num_runs = 4;
                for (int i = 2; i <= 13; i++)
                {
                    if (i >= 11)
                    {
                        num_runs = 1;
                    }
                    var sw  = Stopwatch.StartNew();
                    var lts = LTS.Parse("../demanding/demanding_" + i.ToString(CultureInfo.InvariantCulture) + ".aut");
                    Log("Read input set in {0}ms", sw.ElapsedMilliseconds);

                    sw.Reset(); sw.Start();
                    for (int j = 0; j < num_runs; j++)
                    {
                        lastResult = NaiveSolver.Solve(formula, lts, new Environment()).Contains(lts.InitialState);
                    }
                    results[list.IndexOf(formula) * 2 + 0, i - 2] = (double)sw.ElapsedMilliseconds / num_runs;
                    Log("{0}\t{1}\t{2}\t{3}\t{4}", list.IndexOf(formula) + 1, i, "Naive      ", (double)sw.ElapsedMilliseconds / (double)num_runs, lastResult);

                    sw.Reset(); sw.Start();
                    for (int j = 0; j < num_runs; j++)
                    {
                        lastResult = EmersonLei.Solve(formula, lts, new Environment()).Contains(lts.InitialState);
                    }
                    results[list.IndexOf(formula) * 2 + 1, i - 2] = (double)sw.ElapsedMilliseconds / num_runs;
                    Log("{0}\t{1}\t{2}\t{3}\t{4}", list.IndexOf(formula) + 1, i, "Emerson-Lei", (double)sw.ElapsedMilliseconds / (double)num_runs, lastResult);

                    logWriter.Flush();
                    lts = null;
                }
            }

            Log("");
            Log("");
            Log("Results table:");
            Log("lts size\tformula1 naive\tformula1 emers\tformula2 naive\tformula2 emers\tformula3 naive\tformula3 emers\tformula4 naive\tformula4 emers");
            for (int j = 0; j < results.GetLength(1); j++)
            {
                var sb = new StringBuilder();
                sb.Append((j + 2).ToString());
                for (int i = 0; i < results.GetLength(0); i++)
                {
                    sb.AppendFormat("\t{0}", results[i, j]);
                }
                Log(sb.ToString());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var p = new MuCalculusParser();

            p.Setup();
            bool b = p.Parse(new StringReader("nu X.((mu Y . [b]Y) && nu Z.((<b> X) && (<a>(Z && <a> X))))\r\n"));

            string ltsPath      = args[0];
            string formulasPath = args[1];

            Log("LTS: {0}", ltsPath);
            var parser = new MuCalculusParser();

            parser.Setup();
            var  fileStream  = new FileStream(formulasPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            bool parseResult = parser.Parse(new StreamReader(fileStream, Encoding.Default));

            fileStream.Close();
            if (!parseResult)
            {
                Log("Failed to parse!");
            }

            LTS lts = LTS.Parse(ltsPath);

            foreach (MuFormula f in parser.formulas)
            {
                Log("----------------------------------");
                OutputResult(f, lts);
            }
            Log();
            Log();
            logWriter.Flush();

            logWriter.Close();
            Console.ReadKey();
        }