示例#1
0
        public static void UpdateClockBounds(Expression expression, Dictionary <string, Expression> constantDB, int oldCeiling, int oldFloor, out int ceiling, out int floor)
        {
            try
            {
                if (constantDB.Count > 0)
                {
                    expression = expression.ClearConstant(constantDB);
                }

                if (!expression.HasVar)
                {
                    ExpressionValue rhv = EvaluatorDenotational.Evaluate(expression, null);

                    if (rhv is IntConstant)
                    {
                        IntConstant v = rhv as IntConstant;
                        ceiling = Math.Max(v.Value, oldCeiling);
                        floor   = Math.Min(v.Value, oldFloor);

                        return;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            ceiling = oldCeiling;
            floor   = oldFloor;
        }
示例#2
0
        public override PetriNet ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression[] newArgs = new Expression[Args.Length];

            for (int i = 0; i < Args.Length; i++)
            {
                Expression arg = Args[i].ClearConstant(constMapping);

                if (!arg.HasVar)
                {
                    newArgs[i] = EvaluatorDenotational.Evaluate(arg, null);
                }
                else
                {
                    newArgs[i] = arg;
                }
            }

            DefinitionRef newRef = new DefinitionRef(Name, newArgs);

            //this is a special cases happened in the middle of parsing, where the current Def is not initialized in the parser.
            //so need to put the newRef into the def list to initialize the Def once the parsing is done.
            if (Def == null)
            {
            }
            else
            {
                newRef.Def = Def;
            }

            return(newRef);
        }
示例#3
0
        public static IntConstant EvaluateIntExpression(Expression exp, IToken token, Dictionary <string, Expression> constantDB)
        {
            try
            {
                if (constantDB.Count > 0)
                {
                    exp = exp.ClearConstant(constantDB);
                }

                if (exp.HasVar)
                {
                    List <string> vars = exp.GetVars();
                    throw new ParsingException(string.Format(Resources.Variables___0___can_not_be_used_in_this_expression_, Classes.Ultility.Ultility.PPStringList(vars)) + exp, token);
                }

                ExpressionValue rhv = EvaluatorDenotational.Evaluate(exp, null);

                if (rhv is IntConstant)
                {
                    return(rhv as IntConstant);
                }
                else
                {
                    throw new ParsingException(Resources.The_expression_should_return_an_integer_value_, token);
                }
            }
            catch (Exception ex)
            {
                throw new ParsingException(ex.Message, token);
            }
        }
示例#4
0
        public override void SyncOutput(Valuation GlobalEnv, List <ConfigurationWithChannelData> list)
        {
            //List<ConfigurationWithChannelData> list = new List<ConfigurationWithChannelData>(1);

            if (Specification.SyncrhonousChannelNames.Contains(ChannelName))
            {
                string eventName = ChannelName;
                string eventID   = ChannelName;

                Expression[] newExpressionList = new Expression[ExpressionList.Length];

                for (int i = 0; i < ExpressionList.Length; i++)
                {
                    newExpressionList[i] = EvaluatorDenotational.Evaluate(ExpressionList[i], GlobalEnv);
                    eventName           += "." + newExpressionList[i];
                    eventID += "." + newExpressionList[i].ExpressionID;
                }

                if (eventID != eventName)
                {
                    list.Add(new ConfigurationWithChannelData(Process, eventID, eventName, GlobalEnv, false, ChannelName, newExpressionList));
                }
                else
                {
                    list.Add(new ConfigurationWithChannelData(Process, eventID, null, GlobalEnv, false, ChannelName, newExpressionList));
                }
            }

            //return list;
        }
        public override Process Rename(Dictionary <string, Expression> constMapping, Dictionary <string, string> newDefNames, Dictionary <string, Definition> renamedProcesses)
        {
            Expression[] newExpression = new Expression[ExpressionList.Length];
            for (int i = 0; i < ExpressionList.Length; i++)
            {
                if (ExpressionList[i] is ExpressionValue)
                {
                    newExpression[i] = ExpressionList[i];
                }
                else
                {
                    newExpression[i] = ExpressionList[i].ClearConstant(constMapping);
                    //evaluate the value after the clearance, to make sure there only single variable or single value for each expression
                    if (!newExpression[i].HasVar)
                    {
                        newExpression[i] = EvaluatorDenotational.Evaluate(newExpression[i], null);
                    }
                }
            }

            Process result = new ChannelInputGuardedDataOperation(ChannelName, ChannelIndex != null ? ChannelIndex.ClearConstant(constMapping) : ChannelIndex, newExpression, Process.Rename(constMapping, newDefNames, renamedProcesses), GuardExpression.ClearConstant(constMapping), AssignmentExpr.ClearConstant(constMapping), HasLocalVar);

            result.IsBDDEncodableProp = this.IsBDDEncodableProp;
            return(result);
        }
示例#6
0
        public override void SyncInput(ConfigurationWithChannelData eStep, List <Configuration> list)
        {
            string channelName = this.ChannelName;

            if (ChannelIndex != null)
            {
                int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, eStep.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 + "]";
            }

            //List<Configuration> list = new List<Configuration>(1);
            if (eStep.ChannelName == channelName && eStep.Expressions.Length == ExpressionList.Length)
            {
                Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(eStep.Expressions.Length);

                for (int i = 0; i < ExpressionList.Length; i++)
                {
                    Expression v = eStep.Expressions[i];

                    if (ExpressionList[i] is Variable)
                    {
                        mapping.Add(ExpressionList[i].ExpressionID, v);
                    }
                    else
                    {
                        if (v.ExpressionID != ExpressionList[i].ExpressionID)
                        {
                            return;
                        }
                    }
                }

                Expression      guard = GuardExpression.ClearConstant(mapping);
                ExpressionValue value = EvaluatorDenotational.Evaluate(guard, eStep.GlobalEnv);

                if ((value as BoolConstant).Value)
                {
                    Configuration vm;
                    if (mapping.Count > 0)
                    {
                        vm = new Configuration(Process.ClearConstant(mapping), null, null, eStep.GlobalEnv, false);
                    }
                    else
                    {
                        vm = new Configuration(Process, null, null, eStep.GlobalEnv, false);
                    }

                    list.Add(vm);
                }
            }

            //return list;
        }
示例#7
0
        //Assumption: the expression list of event can only contain process parameters, which mean after constant clearance, the expression must be a constant.
        public virtual Event ClearConstant(Dictionary <string, Expression> constMapping)
        {
            if (EventID == null)
            {
                string            newID             = BaseName;
                string            newName           = BaseName;
                int               size              = (ExpressionList == null) ? 0 : ExpressionList.Length;
                List <Expression> newExpressionList = new List <Expression>(size);
                bool              hasVar            = false;

                for (int i = 0; i < size; i++)
                {
                    Expression tempExp = ExpressionList[i].ClearConstant(constMapping);

                    //if there is no variables inside tempExp, then evaluate expression
                    if (!tempExp.HasVar)
                    {
                        ExpressionValue v = EvaluatorDenotational.Evaluate(tempExp, null);
                        if (v != null)
                        {
                            newID   += "." + v.ExpressionID;
                            newName += "." + v.ToString();
                            newExpressionList.Add(v);
                        }
                        else
                        {
                            throw new RuntimeException("Expression " + tempExp + " has no value! Please make sure it has a value when used in event!");
                        }
                    }
                    //otherwise simplely display the variable names.
                    else
                    {
                        hasVar = true;
                        newExpressionList.Add(tempExp);
                    }
                }

                if (hasVar)
                {
                    Event newEvt = new Event(BaseName);
                    newEvt.ExpressionList = newExpressionList.ToArray();
                    return(newEvt);
                }
                else
                {
                    Event newEvt = new Event(BaseName);
                    //no need to set since it is null anyway
                    //newEvt.ExpressionList = null;
                    newEvt.EventID   = newID;
                    newEvt.EventName = newName;
                    return(newEvt);
                }
            }
            //if full name is not null, then there is nothing to be changed, so we can safely return the event itself.

            return(this);
        }
示例#8
0
        public override void SyncInput(ConfigurationWithChannelData eStep, List <Configuration> list)
        {
            ExpressionValue v = EvaluatorDenotational.Evaluate(Condition, eStep.GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                Process.SyncInput(eStep, list);
            }

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

            ExpressionValue v = EvaluatorDenotational.Evaluate(ConditionalExpression, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                list.Add(new Configuration(FirstProcess, Constants.TAU, "[ifb(" + ConditionalExpression + ")]", GlobalEnv, false));
            }
        }
示例#10
0
        public override void SyncOutput(Valuation GlobalEnv, List <ConfigurationWithChannelData> list)
        {
            ExpressionValue v = EvaluatorDenotational.Evaluate(Condition, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                Process.SyncOutput(GlobalEnv, list);
            }

            //return new List<ConfigurationWithChannelData>(0);
        }
示例#11
0
        /*getsingleTrail() with the assumptions:
         * 1.DTMC model without any no-deterministic choices
         * 2.Bounded steps
         */
        public bool getsingleTrial()
        {
            currentStep = 0;
            ExpressionValue v = EvaluatorDenotational.Evaluate(ReachableStateCondition, intialConfiguration.GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                return(true);
            }

            return(sampleNextStateWithEvaluation(intialConfiguration));
        }
示例#12
0
 public override string GetEventID(Valuation global)
 {
     if (ExpressionList.Length > 0)
     {
         ExpressionValue v = EvaluatorDenotational.Evaluate(ExpressionList[0], global);
         return(BaseName + "[" + v.ExpressionID + "]");
     }
     else
     {
         return(BaseName);
     }
 }
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            ExpressionValue v = EvaluatorDenotational.Evaluate(ConditionalExpression, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                FirstProcess.MoveOneStep(GlobalEnv, list);
            }
            else
            {
                SecondProcess.MoveOneStep(GlobalEnv, list);
            }
        }
示例#14
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            ExpressionValue v = EvaluatorDenotational.Evaluate(Condition, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                Process.MoveOneStep(GlobalEnv, list);
            }

            //return new List<Configuration>(0);
        }
示例#15
0
        /*SampleNextStateWithEvaluation(...) does the following tasks:
         * 1. sample next MDPconfiguration if it is a pcase
         * 2. if not, it will directly return nex MDPconfiguration
         * 3. Evaluation on the next MDPconfiguration will also be done
         */
        //assume there is no no-deterministic choice
        //as we assume there is only deterministic choices, including probabilistic choices. Hence, if the list.length=1, corresponding to a normal step, if not, then, it should be a probability distribution, hence, a simple sampling process will be taken to evaluate the next step. Here, we assume there is no loop. and the whole precess is bounded.
        public bool sampleNextStateWithEvaluation(MDPConfiguration currentConfiguration)
        {
            numberOfTotalVisitedStates++;
            bool evaluationResult;

            currentStep++;
            if (currentConfiguration.IsDeadLock || currentStep > boundedStep)
            {
                return(false);
            }
            MDPConfiguration[] list = currentConfiguration.MakeOneMoveLocal().ToArray();
            if (list.Length == 0)
            {
                return(false);
            }

            if (list.Length == 1)
            {
                MDPConfiguration step = list[0];
                ExpressionValue  v    = EvaluatorDenotational.Evaluate(ReachableStateCondition, step.GlobalEnv);
                evaluationResult = (v as BoolConstant).Value;
                return(evaluationResult || sampleNextStateWithEvaluation(step));
            }


            double value = random.NextDouble();

            double sum = 0;

            foreach (MDPConfiguration configuration in list)
            {
                sum += configuration.Probability;
            }

            double accumulation = 0;

            foreach (MDPConfiguration configuration in list)
            {
                double preaccumulation = accumulation;
                accumulation += (configuration.Probability / sum);
                if (value > preaccumulation && value <= accumulation)
                {
                    ExpressionValue v = EvaluatorDenotational.Evaluate(ReachableStateCondition, configuration.GlobalEnv);
                    evaluationResult = (v as BoolConstant).Value;
                    return(evaluationResult || sampleNextStateWithEvaluation(configuration));
                }
            }
            // the folllowing codes will never happen. -----Should be.
            return(false);
        }
示例#16
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            Valuation    globalEnv = GlobalEnv;
            ChannelQueue Buffer    = null;

            if (globalEnv.Channels.TryGetValue(this.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;

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

            // return list;
        }
        public override void SyncOutput(Valuation GlobalEnv, List <ConfigurationWithChannelData> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            ExpressionValue v = EvaluatorDenotational.Evaluate(ConditionalExpression, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                FirstProcess.SyncOutput(GlobalEnv, list);
            }
            else
            {
                SecondProcess.SyncOutput(GlobalEnv, list);
            }
        }
示例#18
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            ExpressionValue v = EvaluatorDenotational.Evaluate(ConditionalExpression, GlobalEnv);

            if ((v as BoolConstant).Value)
            {
                list.Add(new Configuration(new Stop(), Constants.TERMINATION, null, GlobalEnv, false));
            }
            else
            {
                throw new RuntimeException("Assertion at line " + LineNumber + " failed: " + ConditionalExpression.ToString());
            }
        }
示例#19
0
        public static Bitmap MapConfigurationToImage(ConfigurationBase <P, V> config, SpecificationBase <P, V> Spec, int imageSize)
        {
            string ExampleName = Spec.SpecificationName;

            try
            {
                ExpressionValue value;
                switch (ExampleName)
                {
                case "Sliding Game":
                    value = config.GlobalEnv.Variables["board"];
                    return(DrawSlidingBoard(EvaluatorDenotational.GetValueFromExpression(value) as int[], imageSize));

                case "Shunting Game":
                    value = config.GlobalEnv.Variables["board"];
                    int c = (config.GlobalEnv.Variables["c"] as IntConstant).Value;
                    int r = (config.GlobalEnv.Variables["r"] as IntConstant).Value;

                    //row
                    int N = (Spec.GlobalConstantDatabase["N"] as IntConstant).Value;
                    //col
                    int M = (Spec.GlobalConstantDatabase["M"] as IntConstant).Value;

                    Point shunter = new Point(c, r);

                    //DrawShunterBoard
                    //return DrawShunterBoard(EvaluatorDenotational.GetValueFromExpression(value) as int[], imageSize);
                    Point[] crossPos = { new Point(2, 2), new Point(2, 3), new Point(3, 2), new Point(3, 3) };
                    return(DrawShunterBoard(EvaluatorDenotational.GetValueFromExpression(value) as int[], shunter, crossPos, M, N, imageSize, imageSize));
                    //case "Dining Philosopher":
                    //    int numberOfPhilosophers = 5;
                    //    PhilosopherStatus[] philosopherStatuses = new PhilosopherStatus[numberOfPhilosophers];
                    //    philosopherStatuses[0] = PhilosopherStatus.Thinking;
                    //    philosopherStatuses[1] = PhilosopherStatus.Eating;
                    //    philosopherStatuses[2] = PhilosopherStatus.Thinking;
                    //    philosopherStatuses[3] = PhilosopherStatus.Thinking;
                    //    philosopherStatuses[4] = PhilosopherStatus.HaveLeftFork;

                    //    return DrawDiningPhilosopher(imageSize, philosopherStatuses);
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
示例#20
0
        public override void SyncInput(ConfigurationWithChannelData eStep, List <Configuration> list)
        {
            //List<Configuration> list = new List<Configuration>(1);
            if (eStep.ChannelName == ChannelName && eStep.Expressions.Length == ExpressionList.Length)
            {
                Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(eStep.Expressions.Length);

                for (int i = 0; i < ExpressionList.Length; i++)
                {
                    Expression v = eStep.Expressions[i];

                    if (ExpressionList[i] is Variable)
                    {
                        mapping.Add(ExpressionList[i].ExpressionID, v);
                    }
                    else
                    {
                        if (v.ExpressionID != ExpressionList[i].ExpressionID)
                        {
                            return;
                        }
                    }
                }

                Expression      guard = GuardExpression.ClearConstant(mapping);
                ExpressionValue value = EvaluatorDenotational.Evaluate(guard, eStep.GlobalEnv);

                if ((value as BoolConstant).Value)
                {
                    Configuration vm;
                    if (mapping.Count > 0)
                    {
                        vm = new Configuration(Process.ClearConstant(mapping), null, null, eStep.GlobalEnv, false);
                    }
                    else
                    {
                        vm = new Configuration(Process, null, null, eStep.GlobalEnv, false);
                    }

                    list.Add(vm);
                }
            }

            //return list;
        }
示例#21
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            for (int i = 0; i < Processes.Length; i++)
            {
                Expression      con = Conditions[i];
                ExpressionValue v   = EvaluatorDenotational.Evaluate(con, GlobalEnv);

                if ((v as BoolConstant).Value)
                {
                    list.Add(new Configuration(Processes[i], Constants.TAU, "[" + con + "]", GlobalEnv, false));
                    return;
                }
            }

            //if there is no condition is true, return a skip action
            list.Add(new Configuration(new Skip(), Constants.TAU, "[default]", GlobalEnv, false));
        }
示例#22
0
        public override void SyncOutput(Valuation GlobalEnv, List <ConfigurationWithChannelData> list)
        {
            //List<ConfigurationWithChannelData> list = new List<ConfigurationWithChannelData>(1);

            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 (SpecificationBase.SyncrhonousChannelNames.Contains(channelName))
            {
                string eventName = channelName;
                string eventID   = channelName;

                Expression[] newExpressionList = new Expression[ExpressionList.Length];

                for (int i = 0; i < ExpressionList.Length; i++)
                {
                    newExpressionList[i] = EvaluatorDenotational.Evaluate(ExpressionList[i], GlobalEnv);
                    eventName           += "." + newExpressionList[i];
                    eventID += "." + newExpressionList[i].ExpressionID;
                }

                if (eventID != eventName)
                {
                    list.Add(new ConfigurationWithChannelData(Process, eventID, eventName, GlobalEnv, false, channelName, newExpressionList));
                }
                else
                {
                    list.Add(new ConfigurationWithChannelData(Process, eventID, null, GlobalEnv, false, channelName, newExpressionList));
                }
            }

            //return list;
        }
示例#23
0
        public override Process ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression[]  newArgs = new Expression[Args.Length];
            DefinitionRef newRef  = null;

            // Console.WriteLine("clearing constant for " + this.Name +" Def"+Def);
            try {
                for (int i = 0; i < Args.Length; i++)
                {
                    Expression arg = Args[i].ClearConstant(constMapping);

                    if (!arg.HasVar)
                    {
                        newArgs[i] = EvaluatorDenotational.Evaluate(arg, null);
                    }
                    else
                    {
                        newArgs[i] = arg;
                    }
                }

                newRef = new DefinitionRef(Name, newArgs);

                //this is a special cases happened in the middle of parsing, where the current Def is not initialized in the parser.
                //so need to put the newRef into the def list to initialize the Def once the parsing is done.
                if (Def == null)
                {
                    //    EGTreeWalker.dlist.Add(newRef);
                    //    EGTreeWalker.dtokens.Add(null);
                }
                else
                {
                    newRef.Def = Def;
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw e;
            }
            return(newRef);
        }
示例#24
0
        public virtual string GetEventID(Valuation global)
        {
            if (EventID != null)
            {
                return(EventID);
            }

            if (ExpressionList != null && ExpressionList.Length > 0)
            {
                string toReturn = BaseName;

                for (int i = 0; i < ExpressionList.Length; i++)
                {
                    ExpressionValue v = EvaluatorDenotational.Evaluate(ExpressionList[i], global);
                    toReturn += "." + v.ExpressionID;
                }

                return(toReturn);
            }

            return(BaseName);
        }
        public override Process ClearConstant(Dictionary <string, Expression> constMapping)
        {
            Expression[] newExpression = new Expression[ExpressionList.Length];
            for (int i = 0; i < ExpressionList.Length; i++)
            {
                if (ExpressionList[i] is ExpressionValue)
                {
                    newExpression[i] = ExpressionList[i];
                }
                else
                {
                    newExpression[i] = ExpressionList[i].ClearConstant(constMapping);
                    //evaluate the value after the clearance, to make sure there only single variable or single value for each expression
                    if (!newExpression[i].HasVar)
                    {
                        newExpression[i] = EvaluatorDenotational.Evaluate(newExpression[i], null);
                    }
                }
            }

            return(new ChannelInputGuardedDataOperation(ChannelName, ChannelIndex != null ? ChannelIndex.ClearConstant(constMapping) : ChannelIndex, newExpression, Process.ClearConstant(constMapping), GuardExpression.ClearConstant(constMapping), AssignmentExpr.ClearConstant(constMapping), HasLocalVar));
        }
示例#26
0
        public override IEnumerable <ConfigurationBase> MakeOneMove()
        {
            var nextPNConfigurations = new List <PNConfiguration>();

            foreach (var t in Process.Transitions)
            {
                if (t.GuardCondition != null)
                {
                    ExpressionValue v = EvaluatorDenotational.Evaluate(t.GuardCondition, GlobalEnv);
                    if (!(v as BoolConstant).Value)
                    {
                        continue;
                    }

                    //transition can fire --> move one step
                    var newGlobleEnv = GlobalEnv.GetVariableClone();
                    EvaluatorDenotational.Evaluate(t.ProgramBlock, newGlobleEnv);

                    var name = t.Event.GetEventName(GlobalEnv);
                    var id   = t.Event.GetEventID(GlobalEnv);

                    var newConfiguration = new PNConfiguration(Process, id, name, newGlobleEnv, IsDataOperation);
                    nextPNConfigurations.Add(newConfiguration);
                }
                else
                {
                    //SOME THING WRONG HERE:
                    System.Diagnostics.Debug.WriteLine("Transition don't have guardCondition/fired condition.");
                }
            }

            if (nextPNConfigurations.Count == 0)
            {
                IsDeadLock = true;
            }

            return(nextPNConfigurations);
        }
示例#27
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            string name = Event.GetEventName(GlobalEnv);

            Valuation newGlobleEnv = GlobalEnv.GetVariableClone();

            EvaluatorDenotational.Evaluate(AssignmentExpr, newGlobleEnv);

            //if (LocalVariables != null)
            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;
            }

            string ID = Event.GetEventID(GlobalEnv);

            if (ID != name)
            {
                list.Add(new Configuration(Process, ID, name, newGlobleEnv, true));
            }
            else
            {
                list.Add(new Configuration(Process, ID, null, newGlobleEnv, true));
            }
            //return list;
        }
示例#28
0
        public List <int> MakeOneMove(int stateIndex, Valuation env, string evt)
        {
            DA_State   state      = this._index[stateIndex];
            List <int> returnList = new List <int>();

            if (state.hasOnlySelfLoop())
            {
                // get first to-state, as all the to-states are the same
                DA_State to = state.edges().get(new APElement(_ap_set.all_elements_begin()));
                returnList.Add(to.Index);
                return(returnList);
            }

            //Transition[] trans = fromTransitions[state];

            //foreach (Transition tran in trans)
            for (int el_it = _ap_set.all_elements_begin(); el_it != _ap_set.all_elements_end(); ++el_it)
            {
                APElement label          = new APElement(el_it);
                DA_State  to_state       = state.edges().get(label);
                int       to_state_index = to_state.Index;

                //bool toAdd = true;
                //for (int i = 0; i < _ap_set.size(); i++)
                bool toAdd = true;
                for (int i = 0; i < _ap_set.size(); i++)
                {
                    ////If the transition is labelled with Sigma, there should not be any other labels.
                    //if (label.IsSigmal)
                    //{
                    //    //if(!returnList.Contains(tran.ToState))
                    //    {
                    //        returnList.Add(tran.ToState);
                    //    }
                    //    break;
                    //}

                    string labelstring = _ap_set.getAP(i);
                    //If the labed is negated, e.g., !eat0.
                    if (!label.get(i))
                    {
                        if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        {
                            //if the label says that this event can not happen, the event is eat0 and the label is !eat0.
                            if (labelstring == evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            ExpressionValue v = EvaluatorDenotational.Evaluate(DeclarationDatabase[labelstring], env);

                            //liuyang: v must be a boolconstant, 20/04/2009
                            Debug.Assert(v is BoolConstant);
                            //if (v is BoolConstant)
                            //{
                            if ((v as BoolConstant).Value)
                            {
                                toAdd = false;
                                break;
                            }
                            //}
                        }
                    }
                    else //if (!label.Negated)
                    {
                        if (!DeclarationDatabase.ContainsKey(labelstring)) //If the label is an event.
                        {
                            if (labelstring != evt)
                            {
                                toAdd = false;
                                break;
                            }
                        }
                        else //If the label is a proposition.
                        {
                            ExpressionValue v = EvaluatorDenotational.Evaluate(DeclarationDatabase[labelstring], env);

                            //liuyang: v must be a boolconstant, 20/04/2009
                            Debug.Assert(v is BoolConstant);
                            //if (v is BoolConstant)
                            //{
                            if (!(v as BoolConstant).Value)
                            {
                                toAdd = false;
                                break;
                            }
                            //}
                        }
                    }
                }

                if (toAdd && !returnList.Contains(to_state_index))
                {
                    returnList.Add(to_state_index);
                }
            }

            return(returnList);
        }
示例#29
0
        private MDPStat BuildMDP()
        {
            Stack <KeyValuePair <MDPConfiguration, MDPStateStat> > working = new Stack <KeyValuePair <MDPConfiguration, MDPStateStat> >(1024);

            string       initID = InitialStep.GetID();
            MDPStateStat init   = new MDPStateStat(initID);

            working.Push(new KeyValuePair <MDPConfiguration, MDPStateStat>(InitialStep as MDPConfiguration, init));
            MDPStat mdp = new MDPStat(init, Ultility.Ultility.DEFAULT_PRECISION, Ultility.Ultility.MAX_DIFFERENCE);

            do
            {
                if (CancelRequested)
                {
                    VerificationOutput.NoOfStates = mdp.States.Count;
                    return(mdp);
                }

                KeyValuePair <MDPConfiguration, MDPStateStat> current = working.Pop();
                IEnumerable <MDPConfiguration> list = current.Key.MakeOneMoveLocal();
                VerificationOutput.Transitions += list.Count();

                int currentDistriIndex  = -1;
                DistributionStat newDis = new DistributionStat(Constants.TAU);

                //for (int i = 0; i < list.Length; i++)
                foreach (MDPConfiguration step in list)
                {
                    //MDPConfiguration step = list[i];
                    string       stepID = step.GetID();
                    MDPStateStat nextState;

                    if (!mdp.States.TryGetValue(stepID, out nextState))
                    {
                        nextState = new MDPStateStat(stepID);
                        mdp.AddState(nextState);

                        ExpressionValue v = EvaluatorDenotational.Evaluate(ReachableStateCondition, step.GlobalEnv);

                        if ((v as BoolConstant).Value)
                        {
                            mdp.AddTargetStates(nextState);
                        }
                        else
                        {
                            working.Push(new KeyValuePair <MDPConfiguration, MDPStateStat>(step, nextState));
                        }
                    }

                    if (step.DisIndex == -1)
                    {
                        if (currentDistriIndex >= 0)
                        {
                            current.Value.AddDistribution(newDis);
                            newDis = new DistributionStat(Constants.TAU);
                        }

                        var newTrivialDis = new DistributionStat(step.Event);
                        newTrivialDis.AddProbStatePair(1, nextState);
                        current.Value.AddDistribution(newTrivialDis);
                    }
                    else if (currentDistriIndex != -1 && step.DisIndex != currentDistriIndex)
                    {
                        current.Value.AddDistribution(newDis);
                        newDis = new DistributionStat(Constants.TAU);
                        newDis.AddProbStatePair(step.Probability, nextState);
                    }
                    else
                    {
                        newDis.AddProbStatePair(step.Probability, nextState);
                    }

                    currentDistriIndex = step.DisIndex;
                }

                if (currentDistriIndex >= 0)
                {
                    current.Value.AddDistribution(newDis);
                }
            } while (working.Count > 0);

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

            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 > 0)
                {
                    ChannelQueue      newBuffer = Buffer.Clone();
                    ExpressionValue[] values    = newBuffer.Dequeue();

                    if (values.Length == this.ExpressionList.Length)
                    {
                        Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(values.Length);

                        Valuation newChannelEvn = GlobalEnv.GetChannelClone();
                        newChannelEvn.Channels[channelName] = newBuffer;

                        string eventName = channelName + "?";
                        string eventID   = channelName + "?";

                        for (int i = 0; i < ExpressionList.Length; i++)
                        {
                            ExpressionValue v = values[i];
                            if (i == ExpressionList.Length - 1)
                            {
                                eventName += v;
                                eventID   += v.ExpressionID;
                            }
                            else
                            {
                                eventName += v + ".";
                                eventID   += v.ExpressionID + ".";
                            }

                            if (ExpressionList[i] is Variable)
                            {
                                mapping.Add(ExpressionList[i].ExpressionID, v);
                            }
                            else
                            {
                                if (v.ExpressionID != ExpressionList[i].ExpressionID)
                                {
                                    return; //list
                                }
                            }
                        }

                        Expression guard = GuardExpression.ClearConstant(mapping);

                        ExpressionValue value = EvaluatorDenotational.Evaluate(guard, newChannelEvn);

                        if ((value as BoolConstant).Value)
                        {
                            Valuation newGlobleEnv = newChannelEvn.GetVariableClone();

                            EvaluatorDenotational.Evaluate(AssignmentExpr.ClearConstant(mapping), newGlobleEnv);

                            if (HasLocalVar)
                            {
                                Valuation tempEnv = newChannelEvn.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;
                            }

                            Process newProcess = mapping.Count > 0 ? Process.ClearConstant(mapping) : Process;

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

            //return list;
        }