コード例 #1
0
        public void TestParseVariable_Parameter()
        {
            StringReader  tr     = new StringReader("<parameter name='N' type='index' comment='number of processes in the system' />");
            XmlTextReader reader = new XmlTextReader(tr);

            reader.Read(); // read into block
            Variable actual   = ParseHyXML.ParseVariableParameter(reader);
            Variable expected = new VariableParameter("N", Variable.VarType.index, Variable.VarUpdateType.constant, "");

            Assert.AreEqual(expected, actual);

            tr     = new StringReader("<parameter name='abcd' type='real' comment='' />");
            reader = new XmlTextReader(tr);
            reader.Read(); // read into block
            actual   = ParseHyXML.ParseVariableParameter(reader);
            expected = new VariableParameter("abcd", Variable.VarType.real, Variable.VarUpdateType.constant, "");
            Assert.AreEqual(expected, actual);

            tr     = new StringReader("<parameter name='r1234' type='integer' comment='' />");
            reader = new XmlTextReader(tr);
            reader.Read(); // read into block
            actual   = ParseHyXML.ParseVariableParameter(reader);
            expected = new VariableParameter("r1234", Variable.VarType.integer, Variable.VarUpdateType.constant, "");
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void ToConcreteTest()
        {
            uint N;
            uint TN;

            N  = 0;
            TN = 0;
            List <SymmetricType> types = new List <SymmetricType>();

            types.Add(new SymmetricType(TN, Controller.Instance.Z3.MkTrue()));
            SymmetricState target   = new SymmetricState(N, types.ToArray());
            Expr           expected = null;
            Expr           actual;

            actual = target.ToConcrete();
            //Assert.AreEqual(expected, actual);

            N     = 1;
            TN    = 1;
            types = new List <SymmetricType>();


            Holism sys = new Holism();
            ConcreteHybridAutomaton h = new ConcreteHybridAutomaton(sys, "test");
            ConcreteLocation        aloc;
            ConcreteLocation        bloc;

            StringReader  tr;
            XmlTextReader reader;

            tr     = new StringReader("<holism><mode id='0' name='aloc' initial='True'></mode><mode id='0' name='bloc' initial='False'></mode></holism>");
            reader = new XmlTextReader(tr);
            reader.Read();
            reader.Read();
            aloc = ParseHyXML.ParseLocation(reader, h);
            reader.Read();
            ParseHyXML.ParseLocationEnd(reader, h, aloc);
            reader.Read();
            bloc = ParseHyXML.ParseLocation(reader, h);
            reader.Read();
            ParseHyXML.ParseLocationEnd(reader, h, bloc);

            expected = LogicalExpression.CreateTerm("q[1] == aloc");
            types.Add(new SymmetricType(TN, LogicalExpression.CreateTerm("q[i] == aloc")));
            target = new SymmetricState(N, types.ToArray());
            actual = target.ToConcrete();
            //expected = expected.Substitute(Controller.Instance.Indices["i"], Controller.Instance.Z3.MkInt(1));
            //Assert.AreEqual(expected, actual);
            Assert.IsTrue(Controller.Instance.Z3.ProveEqual(actual, expected));

            expected = LogicalExpression.CreateTerm("q[1] == aloc and q[2] == aloc");
            types    = new List <SymmetricType>();
            types.Add(new SymmetricType(2, LogicalExpression.CreateTerm("q[i] == aloc")));
            target = new SymmetricState(2, types.ToArray());
            actual = target.ToConcrete();
            Assert.IsTrue(Controller.Instance.Z3.ProveEqual(actual, expected));

            expected = LogicalExpression.CreateTerm("q[1] == aloc and q[2] == aloc and q[3] == aloc");
            types    = new List <SymmetricType>();
            types.Add(new SymmetricType(3, LogicalExpression.CreateTerm("q[i] == aloc")));
            target = new SymmetricState(3, types.ToArray());
            actual = target.ToConcrete();
            Assert.IsTrue(Controller.Instance.Z3.ProveEqual(actual, expected));


            //target.visit(0, 3);


            List <uint> ids = new List <uint>();

            ids.Add(1);
            ids.Add(2);
            ids.Add(3);
            ids.Add(4);

            var perms = SymHelp.Permutations(ids);

            //ids.Add(5);
            //ids.Add(6);

            /*
             * IEnumerable<uint> t1 = SymmetricState.Combinations(ids, 1);
             * String s = "";
             * foreach (var v in t1)
             * {
             *  s += v + ", ";
             * }
             * IEnumerable<uint> t2 = SymmetricState.Combinations(ids, 2);
             * foreach (var v in t2)
             * {
             *  s += v + ", ";
             * }
             * IEnumerable<uint> t3 = SymmetricState.Combinations(ids, 3);
             * foreach (var v in t3)
             * {
             *  s += v + ", ";
             * }
             * IEnumerable<uint> t4 = SymmetricState.Combinations(ids, 4);
             * foreach (var v in t4)
             * {
             *  s += v + ", ";
             * }*/

            /*
             * uint T1 = 2;
             * uint T2 = 2;
             * uint T3 = (uint)(ids.Count - (T1 + T2));
             * var ids_t1 = SymHelp.Combinations(ids, (int)T1);
             * //s = "";
             * string s = "";
             * foreach (var v in ids_t1)
             * {
             *  List<uint> vt = new List<uint>(v);
             *  var ids_t2 = SymHelp.Combinations(ids.FindAll(id => !vt.Contains(id)), (int)T2);
             *
             *
             *  //foreach (var stmp in v)
             *  //{
             * //      s += stmp;
             * //  }
             * //  s += ", ";
             *
             *  foreach (var v2 in ids_t2)
             *  {
             *      List<uint> vt2 = new List<uint>(v2);
             *      var ids_t3 = SymHelp.Combinations(ids.FindAll(id => !vt.Contains(id) && !vt2.Contains(id)), (int)T3);
             *
             *      foreach (var v3 in ids_t3)
             *      {
             *          List<uint> idset = new List<uint>(v);
             *          idset.AddRange(v2);
             *          idset.AddRange(v3);
             *
             *          foreach (var stmp in idset)
             *          {
             *              s += stmp;
             *          }
             *          s += ", ";
             *      }
             *  }
             * }*/
            //IEnumerable<uint> combinations = ;


            expected = LogicalExpression.CreateTerm("(q[1] == aloc and q[2] == bloc) or (q[1] == bloc and q[2] == aloc)");
            types    = new List <SymmetricType>();
            types.Add(new SymmetricType(1, LogicalExpression.CreateTerm("q[i] == aloc")));
            types.Add(new SymmetricType(1, LogicalExpression.CreateTerm("q[i] == bloc")));
            target = new SymmetricState(2, types.ToArray());
            actual = target.ToConcrete();
            Assert.IsTrue(Controller.Instance.Z3.ProveEqual(actual, expected));
        }