Exemplo n.º 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 = new PrimitiveApplication(PrimitiveApplication.LESS, 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),
                                                                                       new PrimitiveApplication(PrimitiveApplication.PLUS,
                                                                                                                new PrimitiveApplication(PrimitiveApplication.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, new PrimitiveApplication(PrimitiveApplication.PLUS,
                                                                                                                          new Variable(countChannelVariable), new IntConstant(1))));
            //Update top position: top_a = (top_a + 1) %L
            updateOfChannel = new Sequence(updateOfChannel, new Assignment(topChannelVariable, new PrimitiveApplication(PrimitiveApplication.MOD,
                                                                                                                        new PrimitiveApplication(PrimitiveApplication.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
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return Valuation in Configuration of given BDD configuration in the column form
        /// [ REFS: '', DEREFS: '']
        /// </summary>
        /// <param name="currentStateDD">current BDD configuration</param>
        /// <param name="initialValuation">based on Initial Valuation to get the global variables</param>
        /// <returns>Corresponding Valuation of the BDD configuration</returns>
        public Valuation GetValuationFromBDD(CUDDNode currentStateDD, Valuation initialValuation)
        {
            Valuation currentValuation = initialValuation.GetClone();

            if (currentValuation.Variables != null && currentValuation.Variables.Count > 0)
            {
                foreach (StringDictionaryEntryWithKey <ExpressionValue> pair in currentValuation.Variables._entries)
                {
                    if (pair != null)
                    {
                        if (pair.Value is RecordValue)
                        {
                            RecordValue       array      = pair.Value as RecordValue;
                            ExpressionValue[] arrayValue = new ExpressionValue[array.Associations.Length];

                            for (int i = 0; i < array.Associations.Length; i++)
                            {
                                string variableName = pair.Key + Model.NAME_SEPERATOR + i.ToString();
                                int    value        = model.GetColVarValue(currentStateDD, variableName);
                                arrayValue[i] = new IntConstant(value);
                            }
                            pair.Value = new RecordValue(arrayValue);
                        }
                        else if (pair.Value is BoolConstant)
                        {
                            string variableName = pair.Key;
                            int    value        = model.GetColVarValue(currentStateDD, variableName);
                            pair.Value = new BoolConstant(value == 1);
                        }
                        else
                        {
                            string variableName = pair.Key;
                            int    value        = model.GetColVarValue(currentStateDD, variableName);
                            pair.Value = new IntConstant(value);
                        }
                    }
                }
            }

            if (currentValuation.Channels != null && currentValuation.Channels.Count > 0)
            {
                List <string> channelNames = new List <string>(currentValuation.Channels.Keys);


                foreach (string channelName in channelNames)
                {
                    int count = model.GetColVarValue(currentStateDD, Model.GetCountVarChannel(channelName));
                    int top   = model.GetColVarValue(currentStateDD, Model.GetTopVarChannel(channelName));

                    ChannelQueue currentQueue = new ChannelQueue(count);

                    int firstElement = 0;
                    if (top >= count)
                    {
                        firstElement = top - count;
                    }
                    else
                    {
                        firstElement = top - count + model.mapChannelToSize[channelName];
                    }

                    for (int i = 0; i < count; i++)
                    {
                        int elementSize = model.GetColVarValue(currentStateDD, Model.GetArrayOfSizeElementChannel(channelName) + Model.NAME_SEPERATOR + firstElement);
                        ExpressionValue[] elementValues = new ExpressionValue[elementSize];
                        //Find values in the message
                        for (int j = 0; j < elementSize; j++)
                        {
                            int subElementIndex = firstElement * Model.MAX_MESSAGE_LENGTH + j;
                            int value           = model.GetColVarValue(currentStateDD, channelName + Model.NAME_SEPERATOR + subElementIndex.ToString());
                            elementValues[j] = new IntConstant(value);
                        }

                        //Add element to queue
                        currentQueue.Enqueue(elementValues);

                        //update to the next element
                        firstElement = (firstElement + 1) % model.mapChannelToSize[channelName];
                    }

                    currentValuation.Channels[channelName] = currentQueue;
                }
            }

            return(currentValuation);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return guard, update of channel input
        /// guard: not empty and same size (buffer and received) and guard and expected value in buffer
        /// update: received = buffer and length of buffer - 1
        /// Does not include the update of Event
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="guard"></param>
        /// <param name="exps"></param>
        /// <param name="assignmentExp">null if does not exist</param>
        /// <param name="model"></param>
        /// <returns></returns>
        private static List <Expression> GetGuardUpdateOfChannelInput(string channelName, Expression guard, List <Expression> exps, Expression assignmentExp, Model model)
        {
            string topChannelVariable   = Model.GetTopVarChannel(channelName);
            string countChannelVariable = Model.GetCountVarChannel(channelName);
            string sizeElementArray     = Model.GetArrayOfSizeElementChannel(channelName);

            Expression guardOfChannel, updateOfChannel = null;

            //Not empty channel buffer: count_a > 0
            Expression notEmptyChannel = new PrimitiveApplication(PrimitiveApplication.GREATER, new Variable(countChannelVariable), new IntConstant(0));

            //The poped element size must have the same size of exps: size_a[top_a - count_a %L] == exps.count
            //(top_a - count_a) % L
            Expression popedElementPosition = new PrimitiveApplication(PrimitiveApplication.NON_NEGATIVE_MOD,
                                                                       new PrimitiveApplication(PrimitiveApplication.MINUS, new Variable(topChannelVariable), new Variable(countChannelVariable)),
                                                                       new IntConstant(model.mapChannelToSize[channelName]));

            Expression sameSize = new PrimitiveApplication(PrimitiveApplication.EQUAL,
                                                           new PrimitiveApplication(PrimitiveApplication.ARRAY, new Variable(sizeElementArray), popedElementPosition),
                                                           new IntConstant(exps.Count));

            guardOfChannel = new PrimitiveApplication(PrimitiveApplication.AND, notEmptyChannel, sameSize);
            guardOfChannel = new PrimitiveApplication(PrimitiveApplication.AND, guardOfChannel, guard);

            //Assign data from buffer to exps
            //exps[i] = a[top_a - count_a % L][i]
            for (int i = 0; i < exps.Count; i++)
            {
                //Expect value in the channel
                if (exps[i] is IntConstant)
                {
                    //a[top_a - count_a % L][i] == exps[i]
                    guardOfChannel = new PrimitiveApplication(PrimitiveApplication.AND, guardOfChannel, new PrimitiveApplication(PrimitiveApplication.EQUAL,
                                                                                                                                 new PrimitiveApplication(PrimitiveApplication.ARRAY, new Variable(channelName), new PrimitiveApplication(PrimitiveApplication.PLUS,
                                                                                                                                                                                                                                          new PrimitiveApplication(PrimitiveApplication.TIMES, popedElementPosition, new IntConstant(Model.MAX_MESSAGE_LENGTH)),
                                                                                                                                                                                                                                          new IntConstant(i))),
                                                                                                                                 exps[i]));
                }
                else
                {
                    //receive value from buffer
                    updateOfChannel = Expression.CombineProgramBlock(updateOfChannel, new Assignment(exps[i].expressionID,
                                                                                                     new PrimitiveApplication(PrimitiveApplication.ARRAY, new Variable(channelName),
                                                                                                                              new PrimitiveApplication(PrimitiveApplication.PLUS,
                                                                                                                                                       new PrimitiveApplication(
                                                                                                                                                           PrimitiveApplication.TIMES,
                                                                                                                                                           popedElementPosition,
                                                                                                                                                           new IntConstant(
                                                                                                                                                               Model.MAX_MESSAGE_LENGTH)),
                                                                                                                                                       new IntConstant(i)))));
                }
            }

            //Update size: count_a = count_a - 1
            updateOfChannel = Expression.CombineProgramBlock(updateOfChannel,
                                                             new Assignment(countChannelVariable,
                                                                            new PrimitiveApplication(PrimitiveApplication.MINUS, new Variable(countChannelVariable), new IntConstant(1))));
            updateOfChannel = Expression.CombineProgramBlock(updateOfChannel, assignmentExp);

            return(new List <Expression>()
            {
                guardOfChannel, updateOfChannel
            });
        }