Beispiel #1
0
        /// <summary>
        /// Evaluates the reachable state space of a transition system given a initial state.
        /// </summary>
        /// <param name="I">The Bdd representing the initial state of the system.</param>
        /// <param name="T">The Bdd representing all possible transition in the system.</param>
        /// <param name="bpl">A list of variable pairs that represent pre- and post-states.</param>
        /// <returns>The Bdd representing the reachable state space.</returns>
        public static Bdd ReachableStates(Bdd I, Bdd T, BddPairList bpl)
        {
            Bdd Rp;
            Bdd R = new Bdd(false);

            do
            {
                Rp = R;
                R  = I | ExecuteTransition(R, T, bpl);
            }while (!R.Equals(Rp));
            return(R);
        }
Beispiel #2
0
        private static bool IsOnTrace(Bdd I, Bdd E, Bdd T, BddPairList bpl, int tracelength)
        {
            int count = 0;
            Bdd R     = I;

            while (count < tracelength)
            {
                R = ExecuteTransition(R, T, bpl);
                count++;
            }
            Bdd test = E >= R;

            return(test.U == Kernel.bddtrue);
        }
Beispiel #3
0
        /// <summary>
        /// Evaluates the number of transitions it takes to reach a state from a given initial
        /// state in a transition system.
        /// </summary>
        /// <param name="I">The Bdd representing the initial state of the system.</param>
        /// <param name="E">The state that what to be reached.</param>
        /// <param name="T">The Bdd representing all possible transition in the system.</param>
        /// <param name="bpl">A list of variable pairs that represent pre- and post-states.</param>
        /// <returns>Number of transitions needed. -1 if no trace exists.</returns>
        public static int Tracelength(Bdd I, Bdd E, Bdd T, BddPairList bpl)
        {
            int tracelength = 0;
            Bdd Rp, test;
            Bdd R = I;

            do
            {
                Rp   = R;
                R    = I | ExecuteTransition(R, T, bpl);
                test = E >= R;
                if (R.Equals(Rp) & test.U != Kernel.bddtrue)
                {
                    return(-1);
                }
                tracelength++;
            }while (test.U != Kernel.bddtrue);
            return(tracelength);
        }
Beispiel #4
0
        private static int VarListQuantification(ref BddPairList varList, int u, Op op)
        {
            if (quantiHash.ContainsKey(u))
            {
                return(quantiHash[u]);
            }
            int low, high;

            if (!IsTerminal(Low(u)))
            {
                low = VarListQuantification(ref varList, Low(u), op);
            }
            else
            {
                low = Low(u);
            }

            if (!IsTerminal(High(u)))
            {
                high = VarListQuantification(ref varList, High(u), op);
            }
            else
            {
                high = High(u);
            }

            int newU;

            if (varList.QuantificationContainsKey(Var(u)))
            {
                newU = Apply(op, low, high);
            }
            else
            {
                newU = Mk(Var(u), low, high);
            }

            quantiHash.Add(u, newU);
            return(newU);
        }
Beispiel #5
0
        private static int AppEx(Op op, int u1, int u2, ref BddPairList varList)
        {
            int u;

            if (GAppEx.ContainsKey(u1, u2, op))
            {
                return(GAppEx[u1, u2, op]);
            }

            if (IsTerminal(u1) && IsTerminal(u2))
            {
                return(Lookup[(int)(byte)op, u1 * 2 + u2]);
            }
            else
            {
                switch (Var(u1).CompareTo(Var(u2)))
                {
                case 0:         //equals
                    u = Mk(Var(u1), AppEx(op, Low(u1), Low(u2), ref varList), AppEx(op, High(u1), High(u2), ref varList));
                    break;

                case -1:        //less than
                    u = Mk(Var(u1), AppEx(op, Low(u1), u2, ref varList), AppEx(op, High(u1), u2, ref varList));
                    break;

                default:        //greater than
                    u = Mk(Var(u2), AppEx(op, u1, Low(u2), ref varList), AppEx(op, u1, High(u2), ref varList));
                    break;
                }
            }
            if (varList.QuantificationContainsKey(Var(u)))
            {
                u = Apply(Op.DIS, Low(u), High(u));
            }
            GAppEx.Add(u1, u2, op, u);
            return(u);
        }
Beispiel #6
0
        private static int VarListCompose(ref BddPairList bpl, int u)
        {
            if (u == 0 || u == 1)
            {
                return(u);
            }
            if (composeHash.ContainsKey(u))
            {
                return(composeHash[u]);
            }
            int newU = u;

            if (bpl.ComposeContainsKey(Var(u)))
            {
                newU = Mk(bpl[Var(u)], VarListCompose(ref bpl, Low(u)), VarListCompose(ref bpl, High(u)));
            }
            else
            {
                newU = Mk(Var(u), VarListCompose(ref bpl, Low(u)), VarListCompose(ref bpl, High(u)));
            }

            composeHash.Add(u, newU);
            return(newU);
        }
Beispiel #7
0
//#######################################################################################



        /// <summary>
        /// Universal quantification on a list of variables.
        /// </summary>
        /// <param name="varList">List of variables</param>
        /// <param name="root">bdd</param>
        /// <returns>Resulting Bdd</returns>
        public static Bdd VarListForAll(BddPairList varList, Bdd root)
        {
            int u = VarListQuantification(ref varList, root.U, Op.CON);

            return(Bdd.CreateBdd(u));
        }
Beispiel #8
0
//###########################################################################################

        /// <summary>
        /// Boolean operation and existential quantification on a list of variables.
        /// The same operation as first using Apply() and then VarListExists().
        /// </summary>
        /// <param name="operatoR">Boolean operator</param>
        /// <param name="root1">bdd</param>
        /// <param name="root2">bdd</param>
        /// <param name="varList">List of variables</param>
        /// <returns>Resulting Bdd</returns>
        public static Bdd ApplyExists(Op operatoR, Bdd root1, Bdd root2, BddPairList varList)
        {
            int u = AppEx(operatoR, root1.U, root2.U, ref varList);

            return(Bdd.CreateBdd(u));
        }
Beispiel #9
0
//################################################################################################



        /// <summary>
        /// Existential quantification on a list of variables.
        /// </summary>
        /// <param name="varList">List of variables</param>
        /// <param name="root">bdd</param>
        /// <returns>Resulting Bdd</returns>
        public static Bdd VarListExists(BddPairList varList, Bdd root)
        {
            int u = VarListQuantification(ref varList, root.U, Op.DIS);

            return(Bdd.CreateBdd(u));
        }
Beispiel #10
0
        /// <summary>
        /// Substitution of a list of variablepairs in a Bdd.
        /// </summary>
        /// <param name="bpl">Variablepairlist</param>
        /// <param name="root">bdd</param>
        /// <returns>Resulting Bdd</returns>
        public static Bdd VarListCompose(BddPairList bpl, Bdd root)
        {
            int u = VarListCompose(ref bpl, root.U);

            return(Bdd.CreateBdd(u));
        }
Beispiel #11
0
        /// <summary>
        /// List a possible sequence of transitions to reach a state from a given initial
        /// state in a transition system.
        /// </summary>
        /// <param name="I">The Bdd representing the initial state of the system.</param>
        /// <param name="E">The state that what to be reached.</param>
        /// <param name="T">The Bdd representing all possible transition in the system.</param>
        /// <param name="transitionlist">A collection of all possible transition in the
        /// transition system and a string that describes each transition.</param>
        /// <param name="bpl">A list of variable pairs that represent pre- and post-states.</param>
        /// <param name="tracelength">The number of transitions it takes to reach a state from a given initial
        /// state.</param>
        /// <returns>A string representing a possible sequence of transitions. "No trace to state" if no trace exists.</returns>
        public static string FindTrace(Bdd I, Bdd E, Bdd T, Dictionary <Bdd, string> transitionlist, BddPairList bpl, int tracelength)
        {
            Bdd R;

            if (tracelength == 0)
            {
                return("[]");
            }
            else if (tracelength > 0)
            {
                foreach (KeyValuePair <Bdd, string> trans in transitionlist)
                {
                    R = ExecuteTransition(I, trans.Key, bpl);
                    if (IsOnTrace(R, E, T, bpl, tracelength - 1))
                    {
                        return(trans.Value + " " + FindTrace(R, E, T, transitionlist, bpl, tracelength - 1));
                    }
                }
            }
            return("No trace to the state.");
        }
Beispiel #12
0
        private static Bdd ExecuteTransition(Bdd R, Bdd T, BddPairList bpl)
        {
            Bdd temp = Kernel.ApplyExists(Op.CON, T, R, bpl);

            return(Kernel.VarListCompose(bpl, temp));
        }