public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            Valuation    globalEnv = GlobalEnv;
            ChannelQueue Buffer    = null;

            string channelName = this.ChannelName;

            if (ChannelIndex != null)
            {
                int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value;
                if (size >= Specification.ChannelArrayDatabase[ChannelName])
                {
                    throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString());
                }
                channelName = channelName + "[" + size + "]";
            }

            if (globalEnv.Channels.TryGetValue(channelName, out Buffer))
            {
                if (Buffer.Count < Buffer.Size)
                {
                    ExpressionValue[] values    = new ExpressionValue[ExpressionList.Length];
                    string            eventName = channelName + "!";
                    string            eventID   = channelName + "!";

                    for (int i = 0; i < ExpressionList.Length; i++)
                    {
                        values[i] = EvaluatorDenotational.Evaluate(ExpressionList[i], globalEnv);
                        if (i == ExpressionList.Length - 1)
                        {
                            eventName += values[i].ToString();
                            eventID   += values[i].ExpressionID;
                        }
                        else
                        {
                            eventName += values[i].ToString() + ".";
                            eventID   += values[i].ExpressionID + ".";
                        }
                    }

                    ChannelQueue newBuffer = Buffer.Clone();
                    newBuffer.Enqueue(values);

                    globalEnv = globalEnv.GetChannelClone();
                    globalEnv.Channels[channelName] = newBuffer;

                    //program update
                    Valuation newGlobleEnv = globalEnv.GetVariableClone();

                    EvaluatorDenotational.Evaluate(AssignmentExpr, newGlobleEnv);

                    if (HasLocalVar)
                    {
                        Valuation tempEnv = globalEnv.GetVariableClone();
                        for (int i = 0; i < tempEnv.Variables._entries.Length; i++)
                        {
                            StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i];
                            if (pair != null)
                            {
                                pair.Value = newGlobleEnv.Variables[pair.Key];
                            }
                        }

                        newGlobleEnv = tempEnv;
                    }
                    //program update

                    if (eventID != eventName)
                    {
                        list.Add(new Configuration(Process, eventID, eventName, newGlobleEnv, false));
                    }
                    else
                    {
                        list.Add(new Configuration(Process, eventID, null, newGlobleEnv, false));
                    }
                }
            }

            // return list;
        }
Example #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;
        }