Example #1
0
        private static List <CUDDNode> IsExistPath(Expression goal1, BDDEncoder encoder,
                                                   List <CUDDNode> path,
                                                   CUDDNode initDD,
                                                   AutomataBDD systemBDD,
                                                   List <string> letters,
                                                   ref bool reach1)
        {
            CUDDNode goal1DD;

            goal1DD = CUDD.Function.Or(goal1.TranslateBoolExpToBDD(encoder.model).GuardDDs);

            path = new List <CUDDNode>();

            reach1 = encoder.model.PathForward(initDD, goal1DD, new List <List <CUDDNode> >()
            {
                systemBDD.transitionBDD
            }, path, false);


            logger.Info("Finish run. Result is " + reach1);

#if DEBUG
            StringBuilder builder = new StringBuilder();
            PrintResult(builder, path, encoder, letters);
            logger.Info(builder.ToString());
#endif

            return(path);
        }
Example #2
0
        ///
        /// <summary>
        /// Use when the boolen constant is used as expression: a = true
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override ExpressionBDDEncoding TranslateIntExpToBDD(Model model)
        {
            string channelName          = Arguments[0].ToString();
            string countChannelVariable = Model.GetCountVarChannel(channelName);
            string topChannelVariable   = Model.GetTopVarChannel(channelName);

            switch (MethodName)
            {
            case Constants.cfull:
                Expression            isFull     = Expression.EQ(new Variable(countChannelVariable), new IntConstant(model.mapChannelToSize[channelName]));
                ExpressionBDDEncoding isFullTemp = isFull.TranslateBoolExpToBDD(model);
                isFullTemp.ExpressionDDs = new List <CUDDNode>(isFullTemp.GuardDDs);
                isFullTemp.GuardDDs      = new List <CUDDNode>()
                {
                    CUDD.Constant(1)
                };
                return(isFullTemp);

            case Constants.cempty:
                Expression            isEmpty     = Expression.EQ(new Variable(countChannelVariable), new IntConstant(0));
                ExpressionBDDEncoding isEmptyTemp = isEmpty.TranslateBoolExpToBDD(model);
                isEmptyTemp.ExpressionDDs = new List <CUDDNode>(isEmptyTemp.GuardDDs);
                isEmptyTemp.GuardDDs      = new List <CUDDNode>()
                {
                    CUDD.Constant(1)
                };
                return(isEmptyTemp);

            case Constants.ccount:
                return(new Variable(countChannelVariable).TranslateIntExpToBDD(model));

            case Constants.csize:
                return(new IntConstant(model.mapChannelToSize[channelName]).TranslateIntExpToBDD(model));

            case Constants.cpeek:
                //(top_a - count_a) % L
                Expression popedElementPosition = new PrimitiveApplication(PrimitiveApplication.MOD,
                                                                           Expression.MINUS(new Variable(topChannelVariable), new Variable(countChannelVariable)),
                                                                           new IntConstant(model.mapChannelToSize[channelName]));

                //a[top_a - count_a % L][i]
                return(new PrimitiveApplication(PrimitiveApplication.ARRAY, new Variable(channelName), Expression.TIMES(
                                                    popedElementPosition,
                                                    new IntConstant(Model.MAX_MESSAGE_LENGTH))
                                                ).TranslateIntExpToBDD(model));
            }

            throw new Exception("Static call can not be encoded in BDD");
        }
Example #3
0
        ///
        /// <summary>
        /// Use when the boolen constant is used as expression: a = true
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override ExpressionBDDEncoding TranslateBoolExpToBDD(Model model)
        {
            string channelName          = Arguments[0].ToString();
            string countChannelVariable = Model.GetCountVarChannel(channelName);

            switch (MethodName)
            {
            case Constants.cfull:
                Expression isFull = Expression.EQ(new Variable(countChannelVariable), new IntConstant(model.mapChannelToSize[channelName]));
                return(isFull.TranslateBoolExpToBDD(model));

            case Constants.cempty:
                Expression isEmpty = Expression.EQ(new Variable(countChannelVariable), new IntConstant(0));
                return(isEmpty.TranslateBoolExpToBDD(model));
            }

            throw new Exception("Static call can not be encoded in BDD");
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="channelEventIndex"></param>
        /// <param name="guard">If no guard, give BoolConstant(true)</param>
        /// <param name="exps">List of expressions of channel in</param>
        /// <param name="P1">Process after channel in</param>
        /// <param name="model"></param>
        /// <param name="result"></param>
        private static void SyncChannelInputEncodeTransition(int channelEventIndex, Expression guard, List<Expression> exps, AutomataBDD P1, Model model, AutomataBDD result)
        {
            //temp = result.processName
            //!temp and guard and event' = channelEventIndex and temp' and Update_Channel and P1.init'

            guard = Expression.AND(guard, Expression.EQ(new Variable(result.newLocalVarName),
                                                                                    new IntConstant(0)));
            guard = Expression.AND(guard, new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));
            guard = Expression.AND(guard, new Assignment(result.newLocalVarName, new IntConstant(1)));

            for (int i = 0; i < exps.Count; i++)
            {
                if (exps[i] is IntConstant)
                {
                    //eventParameterVariables[i]' = exps[i]
                    guard = Expression.AND(guard, new Assignment(model.eventParameterVariables[i], exps[i]));
                }
                else
                {
                    //eventParameterVariables[i]' = exps[i]'
                    guard = Expression.AND(guard,
                                 Expression.EQ(new VariablePrime(model.eventParameterVariables[i]),
                                                          new VariablePrime(exps[i].expressionID)));

                }
            }

            //
            List<CUDDNode> transition = guard.TranslateBoolExpToBDD(model).GuardDDs;

            transition = CUDD.Function.And(transition, P1.GetInitInColumn(model));
            transition = model.AddVarUnchangedConstraint(transition, model.GlobalVarIndex);
            result.channelInTransitionBDD.AddRange(transition);

            //
            CopyTransitionAfterEventChannel(P1, model, result);
        }
Example #5
0
        /// <summary>
        /// Encode buchi automaton for proposition. Proposition is implemented as to be true at the destination state
        /// </summary>
        /// <param name="guardDD"></param>
        /// <param name="proposition"></param>
        /// <returns></returns>
        private List<CUDDNode> EncodeProposition(Expression guardDD, Expression proposition)
        {
            List<CUDDNode> transition = guardDD.TranslateBoolExpToBDD(model).GuardDDs;

            List<CUDDNode> propositionDD = model.SwapRowColVars(proposition.TranslateBoolExpToBDD(model).GuardDDs);
            return CUDD.Function.And(transition, propositionDD);
        }
Example #6
0
        /// <summary>
        /// Check whethere the goal can be reachable from the initial state of automataBDD
        /// [ REFS: traces, DEREFS: ]
        /// </summary>
        /// <param name="automataBDD"></param>
        /// <param name="goal"></param>
        /// <param name="model"></param>
        public void MC(AutomataBDD automataBDD, Expression goal, Model model)
        {
            //Clear the old data
            this.traces.Clear();

            ExpressionBDDEncoding goalBddEncoding = goal.TranslateBoolExpToBDD(model);

            ExpressionBDDEncoding initEncoding = automataBDD.initExpression.TranslateBoolExpToBDD(model);
            if (initEncoding.GuardDDs.Count == 0)
            {
                VerificationOutput.VerificationResult = VerificationResultType.INVALID;
            }
            else
            {
                CUDDNode initDD = CUDD.Function.Or(initEncoding.GuardDDs);
                CUDDNode goalDD = CUDD.Function.Or(goalBddEncoding.GuardDDs);

                CUDD.Ref(automataBDD.transitionBDD);
                List<CUDDNode> noEventTrans = CUDD.Abstract.ThereExists(automataBDD.transitionBDD, model.GetAllEventVars());

                bool reachable = model.Path(initDD, goalDD, noEventTrans, traces, SelectedEngineName, VerificationOutput.GenerateCounterExample);
                CUDD.Deref(noEventTrans);

                //
                CUDD.Deref(initDD, goalDD);

                VerificationOutput.VerificationResult = (reachable) ? VerificationResultType.VALID : VerificationResultType.INVALID;
            }
        }