Beispiel #1
0
        public void TestWS1S_SuccDef_GetAutomaton()
        {
            var solver      = new CharSetSolver(BitWidth.BV7);
            var x           = new Variable("x", true);
            var y           = new Variable("y", true);
            var z           = new Variable("z", true);
            var xLTy        = new MSOLt <BDD>(x, y);
            var xLTzLTy     = new MSOAnd <BDD>(new MSOLt <BDD>(x, z), new MSOLt <BDD>(z, y));
            var Ez          = new MSOExists <BDD>(z, xLTzLTy);
            var notEz       = new MSONot <BDD>(Ez);
            var xSyDef      = new MSOAnd <BDD>(xLTy, notEz);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var aut_xSyDef  = xSyDef.GetAutomaton(ca);
            var aut_xLTzLTy = xLTzLTy.GetAutomaton(ca);
            var aut_Ez      = Ez.GetAutomaton(ca);
            var aut_notEz   = notEz.GetAutomaton(ca);
            var aut_xLTy    = xLTy.GetAutomaton(ca);

            //aut_xSyDef.ShowGraph("aut_xSyDEf");
            //aut_xLTzLTy.ShowGraph("aut_xLTzLTy");
            //aut_Ez.ShowGraph("aut_Ez");
            //aut_notEz.ShowGraph("aut_notEz");

            var xSyPrim     = new MSOSuccN <BDD>(x, y, 1);
            var aut_xSyPrim = xSyPrim.GetAutomaton(ca);
            var equiv       = aut_xSyPrim.IsEquivalentWith(aut_xSyDef);

            Assert.IsTrue(equiv);
        }
Beispiel #2
0
        public void TestIntZ3()
        {
            var solver = new Z3Provider();
            var isNeg  = solver.MkLt(solver.MkVar(0, solver.IntSort), solver.MkInt(0));
            var isPos  = solver.MkLt(solver.MkInt(0), solver.MkVar(0, solver.IntSort));

            var sort = solver.CharacterSort;
            //if x has a negative label then x has successor y with a nonnegative label
            var x   = new Variable("x", true);
            var y   = new Variable("y", true);
            var psi = new MSOImplies <Expr>(
                new MSOPredicate <Expr>(isNeg, x),
                new MSOExists <Expr>(y,
                                     new MSOAnd <Expr>(
                                         new MSOSuccN <Expr>(x, y, 1),
                                         new MSOPredicate <Expr>(isPos, y)
                                         )
                                     )
                );
            //all negative labels are immediately followed by a positive label
            MSOFormula <Expr> phi = new MSOForall <Expr>(x, psi);
            var ca      = new CartesianAlgebraBDD <Expr>(solver);
            var aut_psi = psi.GetAutomaton(ca).Determinize().Minimize();
            var aut_phi = phi.GetAutomaton(solver).Determinize().Minimize();

            Assert.IsFalse(aut_phi.IsEmpty);
            //aut_phi.ShowGraph("aut_phi");
            //aut_psi.ShowGraph("aut_psi");
        }
Beispiel #3
0
        public void TestWS1S_GetAutomatonBDD_eq_GetAutomaton()
        {
            var solver = new CharSetSolver(BitWidth.BV7);
            //var nrOfLabelBits = (int)BitWidth.BV7;
            var isDigit  = solver.MkCharSetFromRegexCharClass(@"\d");
            var isLetter = solver.MkCharSetFromRegexCharClass(@"(c|C)");
            var x        = new Variable("x", false);
            var y        = new Variable("y", false);
            var z        = new Variable("z", false);
            var X        = new Variable("X", false);
            //there are at least two distinct positions x and y
            var xy = new MSOAnd <BDD>(new MSONot <BDD>(new MSOEq <BDD>(x, y)), new MSOAnd <BDD>(new MSOIsSingleton <BDD>(x), new MSOIsSingleton <BDD>(y)));
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var x_sub_X    = new MSOSubset <BDD>(x, X);
            var y_sub_X    = new MSOSubset <BDD>(y, X);
            var z_sub_X    = new MSOSubset <BDD>(z, X);
            var isletter_z = new MSOPredicate <BDD>(isLetter, z);
            var psi        = new MSOExists <BDD>(X, (x_sub_X & y_sub_X & ~(new MSOExists <BDD>(z, ~((~((new MSOIsSingleton <BDD>(z)) & z_sub_X)) | isletter_z)))));

            var atLeast2w   = xy & psi;
            var atLeast2wEE = new MSOExists <BDD>(x, (new MSOExists <BDD>(y, atLeast2w)));
            var autBDD      = atLeast2w.GetAutomaton(solver);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var autPROD     = atLeast2w.GetAutomaton(ca);
            //autBDD.ShowGraph("autBDD");
            //autPROD.ShowGraph("autPROD");
            var aut_atLeast2wEE1 = BasicAutomata.Restrict(atLeast2wEE.GetAutomaton(ca));
            var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver);

            //aut_atLeast2wEE1.ShowGraph("aut_atLeast2wEE1");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            Assert.IsTrue(aut_atLeast2wEE1.IsEquivalentWith(aut_atLeast2wEE2));
        }
Beispiel #4
0
        public void TestWS1S_NotLt()
        {
            var solver = new CharSetSolver(BitWidth.BV7);
            var ca     = new CartesianAlgebraBDD <BDD>(solver);
            var x      = new Variable("x", true);
            var y      = new Variable("y", true);
            var fo     = new WS1SSingleton <BDD>(x) & new WS1SSingleton <BDD>(y);
            var aut_fo = fo.GetAutomaton(ca, x, y);
            WS1SFormula <BDD> not_xLTy = new WS1SNot <BDD>(new WS1SLt <BDD>(x, y));

            not_xLTy = new WS1SAnd <BDD>(not_xLTy, fo); //*
            WS1SFormula <BDD> xEQy = new WS1SEq <BDD>(x, y);

            xEQy = new WS1SAnd <BDD>(xEQy, fo); //*
            var yGTx         = new WS1SLt <BDD>(y, x);
            var xEQy_or_yGTx = new WS1SAnd <BDD>(new WS1SOr <BDD>(xEQy, yGTx), fo);
            var aut_not_xLTy = not_xLTy.GetAutomaton(ca, x, y);
            var B            = xEQy_or_yGTx.GetAutomaton(ca, x, y);
            var c_aut_xLTy   = (new WS1SLt <BDD>(x, y)).GetAutomaton(ca, x, y).Complement(ca).Determinize(ca).Minimize(ca);
            //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //*
            //aut_not_xLTy.ShowGraph("aut_not_xLTy");
            //B.ShowGraph("x_geq_y");
            //c_aut_xLTy.ShowGraph("c_aut_xLTy");
            var equiv1 = aut_not_xLTy.IsEquivalentWith(B, ca);

            //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca);
            Assert.IsTrue(equiv1);
            //Assert.IsTrue(equiv2);
        }
Beispiel #5
0
        //Run the test on each phi in phis and store result in infFile
        static void RunTest(System.IO.StreamWriter outFile, List <Pair <MSOFormula <BDD>, CharSetSolver> > phis, int stop1At = 100, int stop2At = 100, int stop3At = 100)
        {
            var sw = new Stopwatch();

            using (System.IO.StreamWriter file = outFile)
            {
                file.WriteLine("k, old, cartesian-bdd, cartesian-product");
                int to = 2;
                foreach (var p in phis)
                {
                    // T1
                    var t1 = timeout;
                    if (to < stop1At)
                    {
                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            p.First.GetAutomaton(p.Second);
                        }
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }

                    //T2
                    var t2 = timeout;
                    if (to < stop1At)
                    {
                        var cartesianBDD = new CartesianAlgebraBDD <BDD>(p.Second);

                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            p.First.GetAutomaton(cartesianBDD);
                        }
                        sw.Stop();
                        t2 = sw.ElapsedMilliseconds;
                    }

                    // T3
                    var t3 = timeout;
                    if (to < stop3At)
                    {
                        BDDAlgebra <BDD> cartesianProduct = new BDDAlgebra <BDD>(p.Second);

                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            p.First.GetAutomaton(cartesianProduct, false);
                        }
                        sw.Stop();

                        t3 = sw.ElapsedMilliseconds;
                    }

                    file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    to++;
                }
            }
        }
Beispiel #6
0
        public void TestWS1S_GetAutomatonBDD_eq_GetAutomaton()
        {
            var solver        = new CharSetSolver(BitWidth.BV7);
            var nrOfLabelBits = (int)BitWidth.BV7;
            var isDigit       = solver.MkCharSetFromRegexCharClass(@"\d");
            var isLetter      = solver.MkCharSetFromRegexCharClass(@"(c|C)");
            var x             = new WS1SVariable <BDD>("x");
            var y             = new WS1SVariable <BDD>("y");
            var z             = new WS1SVariable <BDD>("z");
            var X             = new WS1SVariable <BDD>("X");
            //there are at least two distinct positions x and y
            var xy = (x != y) & !x & !y;
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var psi = X ^ ((x <= X) & (y <= X) & ~(z ^ ~(~(!z & z <= X) | isLetter % z)));

            var atLeast2w   = xy & psi;
            var atLeast2wEE = x ^ (y ^ atLeast2w);
            var autBDD      = atLeast2w.GetAutomatonBDD(solver, nrOfLabelBits, x, y);
            var ca          = new CartesianAlgebraBDD <BDD>(solver);
            var autPROD     = atLeast2w.GetAutomaton(ca, x, y);
            //autBDD.ShowGraph("autBDD");
            //autPROD.ShowGraph("autPROD");
            var aut_atLeast2wEE1 = BasicAutomata.Restrict(atLeast2wEE.GetAutomaton(ca));
            var aut_atLeast2wEE2 = atLeast2wEE.GetAutomatonBDD(solver, nrOfLabelBits);

            //aut_atLeast2wEE1.ShowGraph("aut_atLeast2wEE1");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            Assert.IsTrue(aut_atLeast2wEE1.IsEquivalentWith(aut_atLeast2wEE2, solver));
        }
Beispiel #7
0
        /// <summary>
        ///  Constructs the automaton assuming the given list fvs of free variables.
        /// </summary>
        /// <param name="alg">label algebra</param>
        /// <param name="nrOfLabelBits">nr of labels bits, only relevant if alg is not CharSetSolver but is BDDAlgebra</param>
        /// <param name="singletonSetSemantics">if true uses singleton-set-semantics for f-o variables else uses min-nonempty-set-semantics</param>
        /// <param name="fvs">free variables, if null uses this.FreeVariables</param>
        /// <returns></returns>
        public Automaton <T> GetAutomaton(IBooleanAlgebra <T> alg, int nrOfLabelBits = 0, bool singletonSetSemantics = false, Variable[] fvs = null)
        {
            if (fvs == null)
            {
                fvs = this.FreeVariables;
            }
            Automaton <T> res;
            var           A = alg as CharSetSolver;

            if (A != null)
            {
                res = this.GetAutomatonBDD1(fvs, A, (int)A.Encoding, singletonSetSemantics) as Automaton <T>;
            }
            else
            {
                var B = alg as BDDAlgebra;
                if (B != null)
                {
                    if (nrOfLabelBits == 0 && this.ExistsSubformula(f => f.Kind == MSOFormulaKind.Predicate))
                    {
                        throw new ArgumentException("BDD predicates are not allowed without any reserved label bits");
                    }
                    res = this.GetAutomatonBDD1(fvs, B, nrOfLabelBits, singletonSetSemantics) as Automaton <T>;
                }
                else
                {
                    //create temporary cartesian product algebra
                    var C = new CartesianAlgebraBDD <T>(alg);
                    //keep only the original algebra
                    res = Automaton <T> .ProjectSecond <BDD>(this.GetAutomatonX1(fvs, C, singletonSetSemantics)).Determinize().Minimize();
                }
            }
            return(res);
        }
Beispiel #8
0
        //LTL over finite traces
        private static void AutomatarkMsoFormulasTest(string inputDir, string outFile)
        {
            Console.WriteLine("fileName , generic-bdd, product");
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(outFile))
            {
                var files = new List <string>(Directory.EnumerateFiles(inputDir, "*.mona", SearchOption.AllDirectories));
                files.Sort((s1, s2) => cmp(s1, s2));
                foreach (string fileName in files)
                {
                    string      contents = File.ReadAllText(fileName);
                    MonaProgram pgm1     = MonaParser.Parse(contents);
                    phi = pgm1.ToMSO();

                    var bv7 = new CharSetSolver(BitWidth.BV7);
                    bddSolver = new BDDAlgebra <BDD>(bv7);
                    var sw = new Stopwatch();
                    sw.Restart();
                    Thread t = new Thread(BDDSolver);
                    t.Start();
                    long t1 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t1 = 5000;
                    }
                    else
                    {
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }

                    bv7        = new CharSetSolver(BitWidth.BV7);
                    cartSolver = new CartesianAlgebraBDD <BDD>(bv7);

                    sw.Restart();
                    t = new Thread(CartesianSolver);
                    t.Start();
                    long t2 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t2 = 5000;
                    }
                    else
                    {
                        sw.Stop();
                        t2 = sw.ElapsedMilliseconds;
                    }

                    //if (t2 > 5000)
                    //    t2 = 5000;

                    file.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                    Console.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                }
            }
        }
Beispiel #9
0
 public void TestWS1S_Label()
 {
     var solver  = new CharSetSolver(BitWidth.BV7);
     var x       = new WS1SVariable <BDD>("x");
     var pred    = new WS1SPred <BDD>(solver.MkCharConstraint('c'), x);
     var ca      = new CartesianAlgebraBDD <BDD>(solver);
     var lab     = pred & !x;
     var lab_aut = lab.GetAutomaton(ca, x);
     //lab_aut.ShowGraph("lab_aut");
 }
Beispiel #10
0
 public void TestWS1S_Label()
 {
     var solver  = new CharSetSolver(BitWidth.BV7);
     var x       = new Variable("X", false);
     var pred    = new MSOPredicate <BDD>(solver.MkCharConstraint('c'), x);
     var ca      = new CartesianAlgebraBDD <BDD>(solver);
     var lab     = pred & new MSOIsSingleton <BDD>(x);
     var lab_aut = lab.GetAutomaton(ca);
     //lab_aut.ShowGraph("lab_aut");
 }
Beispiel #11
0
 public void TestWS1S_Member()
 {
     var solver            = new CharSetSolver(BitWidth.BV7);
     var ca                = new CartesianAlgebraBDD <BDD>(solver);
     var x                 = new WS1SVariable <BDD>("x");
     var y                 = new WS1SVariable <BDD>("y");
     var fo_x              = !x;
     WS1SFormula <BDD> xSy = new WS1SSubset <BDD>(x, y);
     var mem               = new WS1SAnd <BDD>(xSy, fo_x);
     var aut_mem           = mem.GetAutomaton(ca, x, y);
     //aut_mem.ShowGraph("aut_mem");
 }
Beispiel #12
0
 public void TestMSO_Member()
 {
     var solver           = new CharSetSolver(BitWidth.BV7);
     var ca               = new CartesianAlgebraBDD <BDD>(solver);
     var x                = new Variable("x", false);
     var y                = new Variable("y", false);
     var fo_x             = new MSOIsSingleton <BDD>(x);
     MSOFormula <BDD> xSy = new MSOSubset <BDD>(x, y);
     var mem              = new MSOAnd <BDD>(xSy, fo_x);
     var aut_mem          = mem.GetAutomaton(ca);
     //aut_mem.ShowGraph("aut_mem");
 }
Beispiel #13
0
 public void TestMSO_Equal()
 {
     var solver = new CharSetSolver(BitWidth.BV7);
     var ca = new CartesianAlgebraBDD<BDD>(solver);
     var x = new Variable("x", false);
     var y = new Variable("y", false);
     var fo_x = new MSOIsSingleton<BDD>(x) ;
     var fo_y = new MSOIsSingleton<BDD>(y);
     MSOFormula<BDD> fo = new MSOAnd<BDD>(fo_x, fo_y);
     MSOFormula<BDD> xSy = new MSOSubset<BDD>(x, y);
     MSOFormula<BDD> ySx = new MSOSubset<BDD>(y, x);
     MSOFormula<BDD> yEQx = new MSOAnd<BDD>(xSy, ySx);
     yEQx = new MSOAnd<BDD>(yEQx, fo);
     var aut_yEQx = yEQx.GetAutomaton(ca);
     //aut_yEQx.ShowGraph("aut_yEQx");
 }
Beispiel #14
0
        public void TestWS1S_Equal()
        {
            var solver             = new CharSetSolver(BitWidth.BV7);
            var ca                 = new CartesianAlgebraBDD <BDD>(solver);
            var x                  = new Variable("x", false);
            var y                  = new Variable("y", false);
            var fo_x               = new WS1SSingleton <BDD>(x);
            var fo_y               = new WS1SSingleton <BDD>(y);
            WS1SFormula <BDD> fo   = fo_x & fo_y;
            WS1SFormula <BDD> xSy  = new WS1SSubset <BDD>(x, y);
            WS1SFormula <BDD> ySx  = new WS1SSubset <BDD>(y, x);
            WS1SFormula <BDD> yEQx = xSy & ySx;

            yEQx = yEQx & fo;
            var aut_yEQx = yEQx.GetAutomaton(ca, x, y);
            //aut_yEQx.ShowGraph("aut_yEQx");
        }
Beispiel #15
0
        //Automaton<T> Restrict<T>(Automaton<IMonadicPredicate<BDD, T>> autom)
        //{
        //    List<Move<T>> moves = new List<Move<T>>();
        //    foreach (var move in autom.GetMoves())
        //        moves.Add(new Move<T>(move.SourceState, move.TargetState, move.Label.ProjectSecond()));
        //    var res = Automaton<T>.Create(autom.InitialState, autom.GetFinalStates(), moves);
        //    return res;
        //}

        public void TestWS1S_UseOfCharRangePreds <T>(IBooleanAlgebra <T> solver, T isDigit, T isWordLetter, IRegexConverter <T> regexConverter)
        {
            var ca = new CartesianAlgebraBDD <T>(solver);
            var x  = new Variable("x", false);
            var y  = new Variable("y", false);
            var z  = new Variable("z", false);
            var X  = new Variable("X", false);
            //there are at least two distinct positions x and y
            var xy = new MSOAnd <T>(new MSOAnd <T>(new MSONot <T>(new MSOEq <T>(x, y)), new MSOIsSingleton <T>(x)), new MSOIsSingleton <T>(y));
            //there is a set X containing x and y and all positions z in X have characters that satisfy isWordLetter
            var phi = new MSOExists <T>(X, new MSOAnd <T>(
                                            new MSOAnd <T>(new MSOSubset <T>(x, X), new MSOSubset <T>(y, X)),
                                            new MSONot <T>(new MSOExists <T>(z, new MSONot <T>(
                                                                                 new MSOOr <T>(new MSONot <T>(new MSOAnd <T>(new MSOIsSingleton <T>(z), new MSOSubset <T>(z, X))),
                                                                                               new MSOPredicate <T>(isWordLetter, z)))))));

            var psi2        = new MSOAnd <T>(xy, phi);
            var atLeast2wEE = new MSOExists <T>(x, new MSOExists <T>(y, psi2));
            var psi1        = new MSOAnd <T>(new MSOIsSingleton <T>(x), new MSOPredicate <T>(isDigit, x));
            var aut_psi1    = psi1.GetAutomaton(ca);
            //aut_psi1.ShowGraph("SFA(psi1)");
            var atLeast1d = new MSOExists <T>(x, psi1);
            var psi       = new MSOAnd <T>(atLeast2wEE, atLeast1d);
            var aut1      = psi.GetAutomaton(ca);
            //var aut_atLeast1d = atLeast1d.GetAutomaton(solver);

            var aut2 = regexConverter.Convert(@"\w.*\w", System.Text.RegularExpressions.RegexOptions.Singleline).Intersect(regexConverter.Convert(@"\d"));

            //aut1.ShowGraph("aut1");
            //aut2.ShowGraph("aut2");

            bool equiv = aut2.IsEquivalentWith(BasicAutomata.Restrict(aut1));

            Assert.IsTrue(equiv);

            //solver.ShowGraph(aut_atLeast1d, "aut_atLeast1d");

            var aut_psi2 = psi2.GetAutomaton(ca);
            // var aut_atLeast2wEE = atLeast2wEE.GetAutomaton(ca, "x", "y");
            // var aut_atLeast2wEE2 = atLeast2wEE.GetAutomaton(solver);
            //aut_psi2.ShowGraph("SFA(psi2)");
            //aut_atLeast2wEE.ShowGraph("aut_atLeast2wEE");
            //aut_atLeast2wEE2.ShowGraph("aut_atLeast2wEE2");
            //solver.ShowGraph(aut_atLeast2wEE2, "aut_atLeast2wEE2");
        }
Beispiel #16
0
 public void TestWS1S_NotLabel()
 {
     var solver = new CharSetSolver(BitWidth.BV7);
     //var x1 = new Variable("x1", false);
     var x    = new Variable("x", false);
     var pred = new MSOPredicate <BDD>(solver.MkCharConstraint('c'), x);
     var fo_x = new MSOIsSingleton <BDD>(x);
     var ca   = new CartesianAlgebraBDD <BDD>(solver);
     var lab  = new MSOAnd <BDD>(pred, fo_x);
     MSOFormula <BDD> not_lab = new MSONot <BDD>(lab);
     var not_lab_actual       = new MSOAnd <BDD>(not_lab, fo_x);
     var aut_not_lab          = not_lab_actual.GetAutomaton(ca);
     var aut_not_lab_prelim   = not_lab.GetAutomaton(ca);
     var c_aut_lab            = lab.GetAutomaton(ca).Complement().Minimize();
     //c_aut_lab.ShowGraph("c_aut_lab");
     //aut_not_lab.ShowGraph("aut_not_lab");
     //aut_not_lab_prelim.ShowGraph("aut_not_lab_prelim");
     //TBD: equivalence
 }
Beispiel #17
0
 public void TestMSO_NotLt()
 {
     var solver = new CharSetSolver(BitWidth.BV7);
     var ca = new CartesianAlgebraBDD<BDD>(solver);
     var x = new Variable("x", true);
     var y = new Variable("y", true);
     MSOFormula<BDD> not_xLTy = new MSONot<BDD>(new MSOLt<BDD>(x,y));
     MSOFormula<BDD> xEQy = new MSOEq<BDD>(x, y);
     var xGTy = new MSOLt<BDD>(y, x);
     var xGEy = new MSOOr<BDD>(xEQy, xGTy);
     var aut_not_xLTy = not_xLTy.GetAutomaton(ca);
     var aut_xGEy = xGEy.GetAutomaton(ca);
     var c_aut_xLTy = (new MSOLt<BDD>(x,y)).GetAutomaton(ca).Complement().Determinize().Minimize();
     //c_aut_xLTy = c_aut_xLTy.Intersect(aut_fo, ca).Determinize(ca).Minimize(ca); //*
     //aut_not_xLTy.ShowGraph("aut_not_xLTy");
     //aut_xGEy.ShowGraph("aut_xGEy");
     //c_aut_xLTy.ShowGraph("c_aut_xLTy");
     var equiv1 = aut_not_xLTy.IsEquivalentWith(aut_xGEy);
     //var equiv2 = aut_not_xLTy.IsEquivalentWith(c_aut_xLTy, ca);
     Assert.IsTrue(equiv1);
     //Assert.IsTrue(equiv2);
 }
Beispiel #18
0
        public void TestMSO_Pred()
        {
            var solver = new CharSetSolver(BitWidth.BV16);
            var x = new Variable("x", true);
            var pred = new MSOPredicate<BDD>(solver.MkCharConstraint( 'c'), x);
            MSOFormula<BDD> phi = new MSOExists<BDD>(x, pred);

            var ca = new CartesianAlgebraBDD<BDD>(solver);
            var pred_aut = pred.GetAutomaton(ca);
            //pred_aut.ShowGraph("pred_aut");

            var aut = phi.GetAutomaton(solver);
            for (int i = 0; i < 10; i++)
            {
                var s = solver.GenerateMember(aut);
                Assert.IsTrue(System.Text.RegularExpressions.Regex.IsMatch(s, "c"), "regex mismatch");
            }
            var aut2 = solver.RegexConverter.Convert("c", System.Text.RegularExpressions.RegexOptions.Singleline);
            //aut2.ShowGraph("aut2");
            //aut.ShowGraph("aut");
            Assert.IsTrue(aut2.IsEquivalentWith(aut), "automata not equialent");
        }
Beispiel #19
0
        public static void Run()
        {
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"randomMSOInt.csv", false))
            {
                Console.WriteLine("num-predicates, num-minterms, minterm-time, generic-bdd, product ");
                file.WriteLine("num-predicates, num-minterms, minterm-time, generic-bdd, product ");
            }
            random = new Random(0);

            currSeed = 0;


            for (int maxConst = 3; maxConst < 4; maxConst++)
            {
                for (int phisize = 5; phisize < 8; phisize += 1)
                {
                    //Console.WriteLine(maxConst + "," + phisize);


                    for (int i = 0; i < howMany; i++)
                    {
                        c    = new Context();
                        z3   = new Z3BoolAlg(c, c.IntSort, timeout);
                        size = phisize;
                        try
                        {
                            var pair = GenerateMSOZ3Formula();

                            if (maxConst == 4 && phisize > 5)
                            {
                                break;
                            }



                            formula    = pair.First;
                            predicates = pair.Second;
                            if (predicates.Count > 2)
                            {
                                var bddsolver = new BDDAlgebra <BoolExpr>(z3);
                                var sw        = new Stopwatch();
                                sw.Restart();

                                long tbdd = timeout;

                                try
                                {
                                    formula.GetAutomaton(bddsolver, false);
                                    sw.Stop();
                                    tbdd = sw.ElapsedMilliseconds;
                                    if (tbdd > timeout)
                                    {
                                        tbdd = timeout;
                                    }
                                }
                                catch (Z3Exception e)
                                {
                                    tbdd = timeout;
                                }
                                catch (AutomataException e)
                                {
                                    tbdd = timeout;
                                }



                                if (tbdd != timeout)
                                {
                                    long tcart = timeout;
                                    try
                                    {
                                        var bdd = new BDDAlgebra();
                                        solver = new CartesianAlgebraBDD <BoolExpr>(bdd, z3);
                                        sw.Restart();
                                        formula.GetAutomaton(solver);
                                        sw.Stop();
                                        tcart = sw.ElapsedMilliseconds;
                                        if (tcart > timeout)
                                        {
                                            tcart = timeout;
                                        }
                                    }
                                    catch (Z3Exception e)
                                    {
                                        tcart = timeout;
                                    }
                                    catch (AutomataException e)
                                    {
                                        tcart = timeout;
                                    }

                                    sw.Restart();
                                    long tminterm = timeout;
                                    List <Pair <bool[], BoolExpr> > mint = new List <Pair <bool[], BoolExpr> >();
                                    try
                                    {
                                        mint = z3.GenerateMinterms(predicates.ToArray()).ToList();
                                        sw.Stop();
                                        tminterm = sw.ElapsedMilliseconds;
                                        if (tminterm > timeout)
                                        {
                                            tminterm = timeout;
                                        }
                                    }
                                    catch (Z3Exception e)
                                    {
                                        tminterm = timeout;
                                    }
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"randomMSOInt.csv", true))
                                    {
                                        Console.WriteLine(predicates.Count + ", " + (tminterm == timeout ? (int)Math.Pow(2, predicates.Count) : mint.Count) + ",  " + (double)tminterm + ", " + (double)tbdd + ", " + (double)tcart);
                                        file.WriteLine(predicates.Count + ", " + (tminterm == timeout ? (int)Math.Pow(2, predicates.Count) : mint.Count) + ", " + (double)tminterm + ", " + (double)tbdd + ", " + (double)tcart);
                                    }
                                }
                                else
                                {
                                    //Console.WriteLine("moving to next one");
                                }
                            }
                            else
                            {
                                // Console.WriteLine("moving to next one");
                            }
                        }
                        catch (Z3Exception e)
                        {
                            Console.WriteLine("Z3 out of memory");
                            return;
                        }
                        catch (OutOfMemoryException e)
                        {
                            Console.WriteLine("Out of memory");
                            return;
                        }
                    }
                }
            }
        }
Beispiel #20
0
        public static void Run()
        {
            using (System.IO.StreamWriter file =
               new System.IO.StreamWriter(@"randomMSOInt.csv", false))
            {
                Console.WriteLine("num-predicates, num-minterms, minterm-time, generic-bdd, product ");
                file.WriteLine("num-predicates, num-minterms, minterm-time, generic-bdd, product ");
            }
            random = new Random(0);

            currSeed = 0;

            for (int maxConst = 3; maxConst < 4; maxConst++)
                for (int phisize = 5; phisize < 8; phisize += 1)
                {
                    //Console.WriteLine(maxConst + "," + phisize);

                    for (int i = 0; i < howMany; i++)
                    {
                        c = new Context();
                        z3 = new Z3BoolAlg(c, c.IntSort, timeout);
                        size = phisize;
                        try
                        {
                            var pair = GenerateMSOZ3Formula();

                        if (maxConst == 4 && phisize > 5)
                            break;

                            formula = pair.First;
                            predicates = pair.Second;
                            if (predicates.Count > 2)
                            {
                                var bddsolver = new BDDAlgebra<BoolExpr>(z3);
                                var sw = new Stopwatch();
                                sw.Restart();

                                long tbdd = timeout;

                                try
                                {
                                    formula.GetAutomaton(bddsolver, false);
                                    sw.Stop();
                                    tbdd = sw.ElapsedMilliseconds;
                                    if (tbdd > timeout)
                                        tbdd = timeout;
                                }
                                catch (Z3Exception e)
                                {
                                    tbdd = timeout;
                                }
                                catch (AutomataException e)
                                {
                                    tbdd = timeout;
                                }

                                if (tbdd != timeout)
                                {
                                    long tcart = timeout;
                                    try
                                    {
                                        var bdd = new BDDAlgebra();
                                        solver = new CartesianAlgebraBDD<BoolExpr>(bdd, z3);
                                        sw.Restart();
                                        formula.GetAutomaton(solver);
                                        sw.Stop();
                                        tcart = sw.ElapsedMilliseconds;
                                        if (tcart > timeout)
                                            tcart = timeout;
                                    }
                                    catch (Z3Exception e)
                                    {
                                        tcart = timeout;
                                    }
                                    catch (AutomataException e)
                                    {
                                        tcart = timeout;
                                    }

                                    sw.Restart();
                                    long tminterm = timeout;
                                    List<Pair<bool[], BoolExpr>> mint = new List<Pair<bool[], BoolExpr>>();
                                    try
                                    {
                                        mint = z3.GenerateMinterms(predicates.ToArray()).ToList();
                                        sw.Stop();
                                        tminterm = sw.ElapsedMilliseconds;
                                        if (tminterm > timeout)
                                            tminterm = timeout;
                                    }
                                    catch (Z3Exception e)
                                    {

                                        tminterm = timeout;

                                    }
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"randomMSOInt.csv", true))
                                    {
                                        Console.WriteLine(predicates.Count + ", " + (tminterm == timeout ? (int)Math.Pow(2, predicates.Count) : mint.Count) + ",  " + (double)tminterm + ", " + (double)tbdd + ", " + (double)tcart);
                                        file.WriteLine(predicates.Count + ", " + (tminterm == timeout ? (int)Math.Pow(2, predicates.Count) : mint.Count) + ", " + (double)tminterm + ", " + (double)tbdd + ", " + (double)tcart);
                                    }
                                }
                                else {
                                    //Console.WriteLine("moving to next one");

                                }
                            }
                            else
                            {
                               // Console.WriteLine("moving to next one");

                            }
                        }
                        catch (Z3Exception e)
                        {
                            Console.WriteLine("Z3 out of memory");
                            return;

                        }
                        catch (OutOfMemoryException e)
                        {
                            Console.WriteLine("Out of memory");
                            return;

                        }
                    }
                }
        }
Beispiel #21
0
        //Run the test on each phi in phis and store result in infFile
        static void RunTest(System.IO.StreamWriter outFile, List <Tuple <MSOFormula <BDD>, CharSetSolver> > phis, int stop1At = 100, int stop2At = 100, int stop3At = 100)
        {
            var sw = new Stopwatch();

            using (System.IO.StreamWriter file = outFile)
            {
                Console.WriteLine("k, old, cartesian, generic-bdd");
                file.WriteLine("k, old, cartesian, generic-bdd");
                int to = 2;
                foreach (var p in phis)
                {
                    // T1
                    var t1 = timeout;
                    if (to < stop1At)
                    {
                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.Item1.GetAutomaton(p.Item2);
                            }
                            sw.Stop();
                            t1 = sw.ElapsedMilliseconds;
                        }
                        catch (OutOfMemoryException)
                        {
                            t1 = timeout * numTests;
                        }
                    }

                    //T2
                    var t2 = timeout;
                    if (to < stop1At)
                    {
                        var cartesianBDD = new CartesianAlgebraBDD <BDD>(p.Item2);

                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.Item1.GetAutomaton(cartesianBDD);
                            }
                            sw.Stop();
                            t2 = sw.ElapsedMilliseconds;
                        }
                        catch (OutOfMemoryException)
                        {
                            t2 = timeout * numTests;
                        }
                    }

                    // T3
                    var t3 = timeout;
                    if (to < stop3At)
                    {
                        BDDAlgebra <BDD> cartesianProduct = new BDDAlgebra <BDD>(p.Item2);

                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.Item1.GetAutomaton(cartesianProduct, false);
                            }
                            sw.Stop();

                            t3 = sw.ElapsedMilliseconds;
                        }
                        catch (OutOfMemoryException)
                        {
                            t3 = timeout * numTests;
                        }
                    }

                    file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    to++;
                }
            }
        }
Beispiel #22
0
        public static void MintermTest()
        {
            var sw = new Stopwatch();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msomintermp1s1.txt"))
            {
                for (int size = 2; size < kminterm; size++)
                {
                    // Tsolve no force
                    var s1     = new CharSetSolver(BitWidth.BV64);
                    var solver = new CartesianAlgebraBDD <BDD>(s1);

                    WS1SFormula <BDD> phi = new WS1STrue <BDD>();

                    for (int k = 1; k < size; k++)
                    {
                        var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, leq);
                    }
                    for (int k = 0; k < size; k++)
                    {
                        var axk = new WS1SPred <BDD>(s1.MkBitTrue(k), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = size - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    sw.Restart();
                    for (int t = 0; t < numTests; t++)
                    {
                        phi.GetAutomaton(solver);
                    }
                    sw.Stop();

                    var t1 = sw.ElapsedMilliseconds;

                    file.WriteLine((double)t1 / numTests);
                    Console.WriteLine((double)t1 / numTests);
                }
            }
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msomintermp2s1.txt"))
            {
                for (int size = 2; size < kminterm; size++)
                {
                    // Tsolve force
                    var s1     = new CharSetSolver(BitWidth.BV64);
                    var solver = new CartesianAlgebraBDD <BDD>(s1);

                    WS1SFormula <BDD> phi = new WS1STrue <BDD>();

                    for (int k = 0; k < size; k++)
                    {
                        var axk = new WS1SPred <BDD>(s1.MkBitTrue(k), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = size - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    var t1 = 60000L;
                    if (size <= maxmint)
                    {
                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            phi.GetAutomaton(solver);
                        }
                        sw.Stop();

                        t1 = sw.ElapsedMilliseconds;
                    }
                    file.WriteLine((double)t1 / numTests);
                    Console.WriteLine((double)t1 / numTests);
                }
            }
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msomintermp1s2.txt"))
            {
                for (int size = 2; size < kminterm; size++)
                {
                    // Tsolve solver 2
                    var solver = new CharSetSolver(BitWidth.BV64);
                    var alg    = new BDDAlgebra <BDD>(solver);

                    WS1SFormula <BDD> phi = new WS1STrue <BDD>();

                    for (int k = 1; k < size; k++)
                    {
                        var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, leq);
                    }
                    for (int k = 0; k < size; k++)
                    {
                        var axk = new WS1SPred <BDD>(solver.MkBitTrue(k), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = size - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    var t1 = 60000L;


                    sw.Restart();
                    for (int t = 0; t < numTests; t++)
                    {
                        phi.GetAutomaton(alg);
                    }
                    sw.Stop();

                    t1 = sw.ElapsedMilliseconds;

                    file.WriteLine((double)t1 / numTests);
                    Console.WriteLine((double)t1 / numTests);
                }
            }
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msomintermp2s2.txt"))
            {
                for (int size = 2; size < kminterm; size++)
                {
                    var solver = new CharSetSolver(BitWidth.BV64);
                    var alg    = new BDDAlgebra <BDD>(solver);
                    //Tforce sol 2


                    WS1SFormula <BDD> phi = new WS1STrue <BDD>();

                    for (int k = 0; k < size; k++)
                    {
                        var axk = new WS1SPred <BDD>(solver.MkBitTrue(k), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = size - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    var t1 = 60000L;
                    if (size <= maxmint)
                    {
                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            phi.GetAutomaton(alg);
                        }
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }
                    file.WriteLine((double)t1 / numTests);
                    Console.WriteLine((double)t1 / numTests);
                }
            }
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msominterm.txt"))
            {
                for (int size = 2; size < kminterm; size++)
                {
                    //Tminterm
                    var   solver     = new CharSetSolver(BitWidth.BV64);
                    BDD[] predicates = new BDD[size];
                    solver.GenerateMinterms();
                    for (int k = 0; k < size; k++)
                    {
                        predicates[k] = solver.MkBitTrue(k);
                    }

                    var t1 = 60000L * numTests;
                    if (size <= maxmint)
                    {
                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            var mint = solver.GenerateMinterms(predicates).ToList();
                        }
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }

                    file.WriteLine((double)t1 / numTests);
                    Console.WriteLine((double)t1 / numTests);
                }
            }
        }
Beispiel #23
0
        public static void POPLTestsNew()
        {
            var sw = new Stopwatch();

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"..\msobdd.txt"))
            {
                for (int to = 2; to < kpopl; to++)
                {
                    // T1
                    var s1     = new CharSetSolver(BitWidth.BV64);
                    var solver = new CartesianAlgebraBDD <BDD>(s1);

                    WS1SFormula <BDD> phi = new WS1STrue <BDD>();

                    for (int k = 1; k < to; k++)
                    {
                        var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, leq);
                    }
                    for (int k = to - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    sw.Restart();
                    for (int t = 0; t < numTests; t++)
                    {
                        phi.GetAutomaton(solver);
                    }
                    sw.Stop();

                    var t1 = sw.ElapsedMilliseconds;

                    //T2
                    s1     = new CharSetSolver(BitWidth.BV64);
                    solver = new CartesianAlgebraBDD <BDD>(s1);
                    phi    = new WS1STrue <BDD>();

                    for (int k = 1; k < to; k++)
                    {
                        var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, leq);
                    }
                    for (int k = 0; k < to; k++)
                    {
                        var axk = new WS1SPred <BDD>(
                            s1.MkCharConstraint('a', false), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = to - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    sw.Restart();
                    for (int t = 0; t < numTests; t++)
                    {
                        phi.GetAutomaton(solver);
                    }
                    sw.Stop();

                    var t2 = sw.ElapsedMilliseconds;

                    // T3
                    s1     = new CharSetSolver(BitWidth.BV64);
                    solver = new CartesianAlgebraBDD <BDD>(s1);
                    phi    = new WS1STrue <BDD>();

                    for (int k = 1; k < to; k++)
                    {
                        var leq = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, leq);
                    }
                    for (int k = 0; k < to; k++)
                    {
                        var axk = new WS1SPred <BDD>(s1.MkCharConstraint('a', false), new Variable <BDD>("x" + k));
                        phi = new WS1SAnd <BDD>(phi, axk);
                    }
                    for (int k = to - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    var exycy = new WS1SExists <BDD>(new Variable <BDD>("y"), new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("y")));
                    phi = new WS1SAnd <BDD>(phi, exycy);

                    sw.Restart();
                    for (int t = 0; t < numTests; t++)
                    {
                        phi.GetAutomaton(solver);
                    }
                    sw.Stop();

                    var t3 = sw.ElapsedMilliseconds;

                    //T4
                    s1     = new CharSetSolver(BitWidth.BV64);
                    solver = new CartesianAlgebraBDD <BDD>(s1);
                    phi    = new WS1STrue <BDD>();

                    for (int k = 1; k < to; k++)
                    {
                        var leq   = new WS1SLt <BDD>(new Variable <BDD>("x" + (k - 1)), new Variable <BDD>("x" + k));
                        var axk   = new WS1SPred <BDD>(s1.MkCharConstraint('a', false), new Variable <BDD>("x" + (k - 1)));
                        var cxk   = new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("x" + (k - 1)));
                        var inter = new WS1SOr <BDD>(new WS1SAnd <BDD>(leq, axk), cxk);
                        phi = new WS1SAnd <BDD>(phi, inter);
                    }
                    for (int k = to - 1; k >= 0; k--)
                    {
                        phi = new WS1SExists <BDD>(new Variable <BDD>("x" + k), phi);
                    }

                    exycy = new WS1SExists <BDD>(new Variable <BDD>("y"), new WS1SPred <BDD>(s1.MkCharConstraint('c', false), new Variable <BDD>("y")));
                    phi   = new WS1SAnd <BDD>(phi, exycy);

                    var t4 = 60000L * numTests;
                    if (to <= maxmphipop)
                    {
                        sw.Restart();
                        for (int t = 0; t < numTests; t++)
                        {
                            phi.GetAutomaton(solver);
                        }
                        sw.Stop();
                        t4 = sw.ElapsedMilliseconds;
                    }

                    file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests);
                    Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests + "," + (double)t4 / numTests);
                }
            }
        }
Beispiel #24
0
        //LTL over finite traces
        private static void AutomatarkMsoFormulasTest(string inputDir, string outFile)
        {
            Console.WriteLine("fileName , generic-bdd, product");
            using (System.IO.StreamWriter file =
               new System.IO.StreamWriter(outFile))
            {
                var files = new List<string>(Directory.EnumerateFiles(inputDir, "*.mona", SearchOption.AllDirectories));
                files.Sort((s1, s2) => cmp(s1, s2));
                foreach (string fileName in files)
                {
                    string contents = File.ReadAllText(fileName);
                    MonaProgram pgm1 = MonaParser.Parse(contents);
                    phi = pgm1.ToMSO();

                    var bv7 = new CharSetSolver(BitWidth.BV7);
                    bddSolver = new BDDAlgebra<BDD>(bv7);
                    var sw = new Stopwatch();
                    sw.Restart();
                    Thread t = new Thread(BDDSolver);
                    t.Start();
                    long t1 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t1 = 5000;
                    }
                    else {
                        sw.Stop();
                        t1 = sw.ElapsedMilliseconds;
                    }

                    bv7 = new CharSetSolver(BitWidth.BV7);
                    cartSolver = new CartesianAlgebraBDD<BDD>(bv7);

                    sw.Restart();
                    t = new Thread(CartesianSolver);
                    t.Start();
                    long t2 = 5000;
                    if (!t.Join(TimeSpan.FromSeconds(5)))
                    {
                        t.Abort();
                        t2 = 5000;
                    }
                    else {
                        sw.Stop();
                        t2 = sw.ElapsedMilliseconds;
                    }

                    //if (t2 > 5000)
                    //    t2 = 5000;

                    file.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                    Console.WriteLine(fileName + "," + (double)t1 / numTests + "," + (double)t2 / numTests);
                }
            }
        }
Beispiel #25
0
        //Run the test on each phi in phis and store result in infFile
        static void RunTest(System.IO.StreamWriter outFile, List<Pair<MSOFormula<BDD>, CharSetSolver>> phis, int stop1At = 100, int stop2At = 100, int stop3At = 100)
        {
            var sw = new Stopwatch();

            using (System.IO.StreamWriter file = outFile)
            {
                Console.WriteLine("k, old, cartesian, generic-bdd");
                file.WriteLine("k, old, cartesian, generic-bdd");
                int to = 2;
                foreach (var p in phis)
                {
                    // T1
                    var t1 = timeout;
                    if (to < stop1At)
                    {
                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.First.GetAutomaton(p.Second);
                            }
                            sw.Stop();
                            t1 = sw.ElapsedMilliseconds;
                        }
                        catch (OutOfMemoryException)
                        {
                            t1 = timeout * numTests;
                        }
                    }

                    //T2
                    var t2 = timeout;
                    if (to < stop1At)
                    {
                        var cartesianBDD = new CartesianAlgebraBDD<BDD>(p.Second);

                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.First.GetAutomaton(cartesianBDD);
                            }
                            sw.Stop();
                            t2 = sw.ElapsedMilliseconds;

                        }
                        catch (OutOfMemoryException)
                        {
                            t2 = timeout * numTests;
                        }
                    }

                    // T3
                    var t3 = timeout;
                    if (to < stop3At)
                    {
                        BDDAlgebra<BDD> cartesianProduct = new BDDAlgebra<BDD>(p.Second);

                        try
                        {
                            sw.Restart();
                            for (int t = 0; t < numTests; t++)
                            {
                                p.First.GetAutomaton(cartesianProduct, false);
                            }
                            sw.Stop();

                            t3 = sw.ElapsedMilliseconds;
                        }
                        catch (OutOfMemoryException)
                        {
                            t3 = timeout * numTests;
                        }
                    }

                    file.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    Console.WriteLine(to + "," + (double)t1 / numTests + "," + (double)t2 / numTests + "," + (double)t3 / numTests);
                    to++;
                }
            }
        }