示例#1
0
        /// <summary>
        /// Return guard, update of channel output
        /// guard: buffer not full
        /// update: buffer = sender and update size of message and update length of buffer and update top of buffer
        /// Does not include update Model.Event_Name
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="exps"></param>
        /// <param name="assignmentExp">null if not exist</param>
        /// <param name="model"></param>
        /// <returns></returns>
        private static List<Expression> GetGuardUpdateOfChannelOutput(string channelName, List<Expression> exps, Expression assignmentExp, Model model)
        {
            string topChannelVariable = Model.GetTopVarChannel(channelName);
            string countChannelVariable = Model.GetCountVarChannel(channelName);
            string sizeElementArray = Model.GetArrayOfSizeElementChannel(channelName);

            //count_a  < L
            Expression guardOfChannel = Expression.LT(new Variable(countChannelVariable), new IntConstant(model.mapChannelToSize[channelName]));

            Expression updateOfChannel = new BoolConstant(true);

            //Update buffer channel
            //a[top_a] [ i] = exps[i]
            for (int i = 0; i < exps.Count; i++)
            {
                updateOfChannel = new Sequence(updateOfChannel, new PropertyAssignment(new Variable(channelName),
                            Expression.PLUS(
                                Expression.TIMES(new Variable(topChannelVariable), new IntConstant(Model.MAX_MESSAGE_LENGTH)),
                                new IntConstant(i)),
                            exps[i]));
            }

            //Set size of the new element
            //size_a[top_a] = exps.count
            updateOfChannel = new Sequence(updateOfChannel, new PropertyAssignment(new Variable(sizeElementArray), new Variable(topChannelVariable), new IntConstant(exps.Count)));

            //Update size: count_a = count_a + 1
            updateOfChannel = new Sequence(updateOfChannel, new Assignment(countChannelVariable, Expression.PLUS(
                                                                            new Variable(countChannelVariable), new IntConstant(1))));
            //Update top position: top_a = (top_a + 1) %L
            updateOfChannel = new Sequence(updateOfChannel, new Assignment(topChannelVariable, Expression.MOD(
                            Expression.PLUS(new Variable(topChannelVariable), new IntConstant(1)), new IntConstant(model.mapChannelToSize[channelName]))));

            if(assignmentExp != null)
            {
                updateOfChannel = new Sequence(updateOfChannel, assignmentExp);
            }

            return new List<Expression>() { guardOfChannel, updateOfChannel };
        }
示例#2
0
        public Expression InitializeGlobalVariables(Valuation valuation)
        {
            Expression initialVariables = new BoolConstant(true);
            //continue build inital state
            //default value of global variables
            if (valuation.Variables != null)
            {
                foreach (StringDictionaryEntryWithKey<ExpressionValue> pair in valuation.Variables._entries)
                {
                    if (pair != null)
                    {
                        if (!(pair.Value is WildConstant))
                        {
                            if (pair.Value is RecordValue)
                            {
                                RecordValue array = pair.Value as RecordValue;
                                for (int i = 0; i < array.Associations.Length; i++)
                                {
                                    if (!(array.Associations[i] is WildConstant))
                                    {
                                        Expression initialVariable = Expression.EQ(
                                            new Variable(pair.Key + Model.NAME_SEPERATOR + i),
                                            new IntConstant(int.Parse(array.Associations[i].ExpressionID)));

                                        initialVariables = Expression.AND(initialVariables, initialVariable);
                                    }
                                    else
                                    {
                                        string variableName = pair.Key + Model.NAME_SEPERATOR + i;
                                        Expression lowerBound = Expression.GE(new Variable(variableName),
                                                                                                                             new IntConstant(model.GetVarLowerBound(variableName)));
                                        Expression upperBound = Expression.LE(new Variable(variableName),
                                                                                                                             new IntConstant(model.GetVarUpperBound(variableName)));

                                        initialVariables = Expression.AND(initialVariables, lowerBound);
                                        initialVariables = Expression.AND(initialVariables, upperBound);
                                    }
                                }
                            }
                            else if (pair.Value is BoolConstant)
                            {
                                int value = (pair.Value as BoolConstant).Value ? 1 : 0;
                                Expression initialVariable = Expression.EQ(new Variable(pair.Key), new IntConstant(value));
                                initialVariables = Expression.AND(initialVariables, initialVariable);
                            }
                            else
                            {
                                Expression initialVariable = Expression.EQ(new Variable(pair.Key),
                                                                                    new IntConstant(int.Parse(pair.Value.ExpressionID)));
                                initialVariables = Expression.AND(initialVariables, initialVariable);
                            }
                        }
                        else
                        {
                            Expression lowerBound = Expression.GE(new Variable(pair.Key), new IntConstant(model.GetVarLowerBound(pair.Key)));
                            Expression upperBound = Expression.LE(new Variable(pair.Key), new IntConstant(model.GetVarUpperBound(pair.Key)));

                            initialVariables = Expression.AND(initialVariables, lowerBound);
                            initialVariables = Expression.AND(initialVariables, upperBound);
                        }
                    }
                }
            }

            if (valuation.Channels != null)
            {
                foreach (KeyValuePair<string, ChannelQueue> pair in valuation.Channels)
                {
                    //initialize the top index of channel is 0
                    Expression initialVariable = Expression.EQ(new Variable(Model.GetTopVarChannel(pair.Key)), new IntConstant(0));
                    initialVariables = Expression.AND(initialVariables, initialVariable);

                    //initialize the cound of channel buffer is 0
                    initialVariable = Expression.EQ(new Variable(Model.GetCountVarChannel(pair.Key)), new IntConstant(0));
                    initialVariables = Expression.AND(initialVariables, initialVariable);
                }
            }

            return initialVariables;
        }
示例#3
0
        /// <summary>
        /// Return the CUDDNode of the alphabet
        /// </summary>
        /// <param name="alphabets"></param>
        /// <returns></returns>
        public CUDDNode GetAlphabetInBDD(HashSet<string> alphabets)
        {
            Expression result = new BoolConstant(false);
            foreach (var alphabet in alphabets)
            {
                result = Expression.OR(result, GetEventExpression(alphabet));
            }

            return CUDD.Function.Or(result.TranslateBoolExpToBDD(model).GuardDDs);
        }