Exemple #1
0
        /**
         * Given a concrete hybrid automaton, compute the abstraction
         */
        public AbstractHybridAutomaton(Holism parent, ConcreteHybridAutomaton cha)
            : base(parent)
        {
            this._cha = cha;

            this.makePredicates();                               // generate predicates to be used to generate the abstract state space
            this.makeAbstractStateSpace();                       // build abstract state space
            this.makeAbstractProperties(this.Parent.Properties); // abstract the given properties
            this.makeAbstractStateValuations();                  // build explicit state space (e.g., for PHAVer output)
            this.makeAbstractInitial();                          // find the initial abstract states
            //this.makeAbstractTransitions();         // build explicit transitions (e.g., for PHAVer output)

            // model check each property
            foreach (var p in this.Properties)
            {
                switch (p.Type)
                {
                case Property.PropertyType.invariant:     // safety, bad, unreachable, etc. all equivalent at this point (negated appropriately already)
                case Property.PropertyType.bad:
                case Property.PropertyType.safety:
                case Property.PropertyType.unreachable:
                    this.modelCheckInvariant(this.Initial, p.Formula);
                    break;

                default:
                    break;
                }
            }
        }
        public void ComputeReachTest()
        {
            //ReachSymmetric target = new ReachSymmetric(); // TODO: Initialize to an appropriate value
            Holism sys = null; // TODO: Initialize to an appropriate value
            uint   N   = 0;    // TODO: Initialize to an appropriate value

            ReachSymmetric.ComputeReach(sys, N);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Exemple #3
0
 /**
  * Default constructor
  */
 public AbstractHybridAutomaton(Holism parent)
     : base(parent)
 {
 }
 public ConcreteHybridAutomaton(Holism parent, String name)
     : base(parent, name)
 {
 }
Exemple #5
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));
        }
Exemple #6
0
        public void drawSystem(Holism h)
        {
            Graphics g = this.panelSystem.CreateGraphics();

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            System.Drawing.Pen   p = new System.Drawing.Pen(System.Drawing.Color.Black);
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

            System.Drawing.Brush bDiff = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
            System.Drawing.Brush bInv  = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            System.Drawing.Brush bStop = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            System.Drawing.Brush bGuard  = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            System.Drawing.Brush bUGuard = new System.Drawing.SolidBrush(System.Drawing.Color.Purple);
            System.Drawing.Brush bReset  = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            //g.FillEllipse(b, this.panelSystem.Location.X + 50, this.panelSystem.Location.Y + 50, 100, 100);
            //g.DrawEllipse(p, this.panelSystem.Location.X + 50, this.panelSystem.Location.Y + 50, 100, 100);

            int i       = 0;
            int width   = 250;
            int height  = 150;
            int spacing = (int)((float)width * 1.5);

            Dictionary <string, Point> stateNameToPosition = new Dictionary <string, Point>();

            foreach (ConcreteLocation a in h.HybridAutomata[0].Locations)
            {
                int x = this.panelSystem.Location.X + i * spacing;
                int y = this.panelSystem.Location.Y + 50;

                int xmid = (int)(x + width / 2);
                int ybot = y + height;

                stateNameToPosition.Add(a.Label, new Point(xmid, ybot));

                g.DrawEllipse(p, x, y, width, height);

                g.DrawString(a.Label, new System.Drawing.Font("Arial", 16), b, xmid, y);

                int offset       = 20;
                int offset_count = 1;
                int fontsize     = 12;
                if (a.Invariant != null)
                {
                    g.DrawString(a.Invariant.ToString(), new System.Drawing.Font("Arial", fontsize), bInv, xmid, y + offset * offset_count++);
                }
                if (a.Stop != null)
                {
                    g.DrawString(a.Stop.ToString(), new System.Drawing.Font("Arial", fontsize), bStop, xmid, y + offset * offset_count++);
                }
                if (a.Flows != null && a.Flows.Count > 0)
                {
                    g.DrawString(a.Flows[0].ToString(), new System.Drawing.Font("Arial", fontsize), bDiff, xmid, y + offset * offset_count++);
                }

                i++;
            }

            // separate loop, need stateNameToPosition created
            foreach (ConcreteLocation a in h.HybridAutomata[0].Locations)
            {
                int ct = 1;
                foreach (Transition t in a.Transitions)
                {
                    foreach (ConcreteLocation next in t.NextStates)
                    {
                        List <Point> pts = new List <Point>();

                        Point start    = stateNameToPosition[a.Label];
                        Point end      = stateNameToPosition[next.Label];
                        Point midpoint = new Point(Math.Abs(start.X + end.X) / 2, start.Y + ct * 2 * height);

                        pts.Add(start);
                        pts.Add(midpoint);
                        pts.Add(end);
                        g.DrawCurve(p, pts.ToArray());

                        int offset       = 20;
                        int offset_count = 1;
                        int fontsize     = 12;
                        if (t.Guard != null)
                        {
                            g.DrawString(t.Guard.ToString(), new System.Drawing.Font("Arial", fontsize), bGuard, midpoint.X, midpoint.Y + offset * offset_count++);
                        }
                        if (t.UGuard != null)
                        {
                            g.DrawString(t.UGuard.ToString(), new System.Drawing.Font("Arial", fontsize), bUGuard, midpoint.X, midpoint.Y + offset * offset_count++);
                        }
                        if (t.Reset != null)
                        {
                            g.DrawString(t.Reset.ToString(), new System.Drawing.Font("Arial", fontsize), bReset, midpoint.X, midpoint.Y + offset * offset_count++);
                        }
                        ct++;
                    }
                }
            }
        }