Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <returns></returns>
        public List <CUDDNode> EncodeSyncChannelInTransition(BDDEncoder encoder, string processVariableName, List <int> localVars)
        {
            Expression guard = Expression.EQ(
                new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guard = Expression.CombineGuard(guard, GuardCondition);

            List <Expression> parameters = encoder.GetParaExpInEvent(this.Event);
            int channelEventIndex        = encoder.GetEventIndex(this.Event.BaseName, parameters.Count);

            guard = Expression.AND(guard, new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));
            guard = Expression.AND(guard, new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID])));

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

            List <CUDDNode> transitions = guard.TranslateBoolExpToBDD(encoder.model).GuardDDs;

            return(encoder.model.AddVarUnchangedConstraint(transitions, localVars));
        }
Exemple #2
0
        private void EncodeSimulationRel(BDDEncoder encoder, AutomataBDD processBDD, string stateVar)
        {
            int      stateVarIndex = encoder.model.GetVarIndex(stateVar);
            CUDDVars rowStateVars  = encoder.model.GetRowVars(stateVarIndex);
            CUDDVars colStateVars  = encoder.model.GetColVars(stateVarIndex);


            CUDDNode result = CUDD.Constant(0);

            foreach (var pair in mapOldLoc2NewStates)
            {
                List <State> statesInLoc = pair.Value;

                for (int i = 0; i < statesInLoc.Count; i++)
                {
                    for (int j = 0; j < statesInLoc.Count; j++)
                    {
                        if (ClockValuation.IsLUSimulated(mapNewState2Valuation[statesInLoc[i].ID], mapNewState2Valuation[statesInLoc[j].ID], pair.Key))
                        {
                            CUDDNode simulated  = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), rowStateVars, encoder.stateIndexOfCurrentProcess[statesInLoc[i].ID], 1);
                            CUDDNode simulating = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), colStateVars, encoder.stateIndexOfCurrentProcess[statesInLoc[j].ID], 1);

                            result = CUDD.Function.Or(result, CUDD.Function.And(simulated, simulating));
                        }
                    }
                }
            }

            processBDD.SimulationRel = result;
        }
Exemple #3
0
 private void EncodeTransitions(BDDEncoder encoder, AutomataBDD processAutomataBDD, string processVariableName)
 {
     foreach (Transition transition in this.Transitions)
     {
         //Depend on what kind of transition to add the encoded transition to AutomataBDD
         if (transition.Event is ChannelInputEvent)
         {
             List <CUDDNode> transitionBDDs = transition.Encode(encoder, processVariableName, processAutomataBDD.variableIndex, true);
             if (transition.FromState.HavePriority)
             {
                 processAutomataBDD.prioritychannelIns.AddRange(transitionBDDs);
             }
             else
             {
                 processAutomataBDD.channelInTransitionBDD.AddRange(transitionBDDs);
             }
         }
         else if (transition.Event is ChannelOutputEvent)
         {
             List <CUDDNode> transitionBDDs = transition.Encode(encoder, processVariableName, processAutomataBDD.variableIndex, true);
             if (transition.FromState.HavePriority)
             {
                 processAutomataBDD.prioritychannelOuts.AddRange(transitionBDDs);
             }
             else
             {
                 processAutomataBDD.channelOutTransitionBDD.AddRange(transitionBDDs);
             }
         }
         else if (transition.Event is BDDEncoder.EventChannelInfo && (transition.Event as BDDEncoder.EventChannelInfo).type == BDDEncoder.EventChannelInfo.EventType.SYNC_CHANNEL_INPUT)
         {
             List <CUDDNode> transitionBDDs = transition.EncodeSyncChannelInTransition(encoder, processVariableName, processAutomataBDD.variableIndex);
             processAutomataBDD.channelInTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.Event is BDDEncoder.EventChannelInfo && (transition.Event as BDDEncoder.EventChannelInfo).type == BDDEncoder.EventChannelInfo.EventType.SYNC_CHANNEL_OUTPUT)
         {
             List <CUDDNode> transitionBDDs = transition.EncodeSyncChannelOutTransition(encoder, processVariableName, processAutomataBDD.variableIndex);
             processAutomataBDD.channelOutTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.IsTick())
         {
             List <CUDDNode> transitionBDDs = transition.Encode(encoder, processVariableName, processAutomataBDD.variableIndex, false);
             processAutomataBDD.Ticks.AddRange(transitionBDDs);
         }
         else
         {
             List <CUDDNode> transitionBDDs = transition.Encode(encoder, processVariableName, processAutomataBDD.variableIndex, false);
             if (transition.FromState.HavePriority)
             {
                 processAutomataBDD.priorityTransitionsBDD.AddRange(transitionBDDs);
             }
             else
             {
                 processAutomataBDD.transitionBDD.AddRange(transitionBDDs);
             }
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Add local variable including state, and parameters
        /// Return the variable name encoding states
        /// </summary>
        /// <param name="encoder"></param>
        public string AddLocalVariables(BDDEncoder encoder)
        {
            RenameLocalVars();

            for (int i = 0; i < this.Parameters.Count; i++)
            {
                string parameter = this.Parameters[i];

                int min = 0;
                int max = 0;

                if (ParameterUpperBound.ContainsKey(parameter) && ParameterLowerBound.ContainsKey(parameter))
                {
                    min = ParameterLowerBound[parameter];
                    max = ParameterUpperBound[parameter];
                }
                else
                {
                    if(this.Arguments[i] is IntConstant)
                    {
                        IntConstant tempExp = (IntConstant) this.Arguments[i];

                        min = tempExp.Value;
                        max = tempExp.Value;
                    }
                    else
                    {
                        throw new Exception("Symbolic Model Checking only support constant parameters!");
                    }
                }

                //In its old transition encoding, we don't make sure this variable must be unchanged.
                //We also need to add this variable to VaribleIndex of the AutomataBDD because previous process does not know this variable
                //if global then later processes will set this variable as unchange.
                encoder.model.AddLocalVar(parameter, min, max);

            }

            const string STATE = "state";
            //
            string processVariableName = Name + Model.NAME_SEPERATOR + STATE + Model.GetNewTempVarName();
            encoder.model.AddLocalVar(processVariableName, 0, this.States.Count - 1);

            //
            encoder.stateIndexOfCurrentProcess = new Dictionary<string, int>();
            //collect the state index
            foreach (State state in this.States)
            {
                encoder.stateIndexOfCurrentProcess.Add(state.ID, encoder.stateIndexOfCurrentProcess.Count);
            }

            return processVariableName;
        }
Exemple #5
0
        /// <summary>
        /// Add local variable including state, and parameters
        /// Return the variable name encoding states
        /// </summary>
        /// <param name="encoder"></param>
        public string AddLocalVariables(BDDEncoder encoder)
        {
            RenameLocalVars();

            for (int i = 0; i < this.Parameters.Count; i++)
            {
                string parameter = this.Parameters[i];

                int min = 0;
                int max = 0;

                if (ParameterUpperBound.ContainsKey(parameter) && ParameterLowerBound.ContainsKey(parameter))
                {
                    min = ParameterLowerBound[parameter];
                    max = ParameterUpperBound[parameter];
                }
                else
                {
                    if (this.Arguments[i] is IntConstant)
                    {
                        IntConstant tempExp = (IntConstant)this.Arguments[i];

                        min = tempExp.Value;
                        max = tempExp.Value;
                    }
                    else
                    {
                        throw new Exception("Symbolic Model Checking only support constant parameters!");
                    }
                }

                //In its old transition encoding, we don't make sure this variable must be unchanged.
                //We also need to add this variable to VaribleIndex of the AutomataBDD because previous process does not know this variable
                //if global then later processes will set this variable as unchange.
                encoder.model.AddLocalVar(parameter, min, max);
            }

            const string STATE = "state";
            //
            string processVariableName = Name + Model.NAME_SEPERATOR + STATE + Model.GetNewTempVarName();

            encoder.model.AddLocalVar(processVariableName, 0, this.States.Count - 1);

            //
            encoder.stateIndexOfCurrentProcess = new Dictionary <string, int>();
            //collect the state index
            foreach (State state in this.States)
            {
                encoder.stateIndexOfCurrentProcess.Add(state.ID, encoder.stateIndexOfCurrentProcess.Count);
            }

            return(processVariableName);
        }
Exemple #6
0
        /// <summary>
        /// Generate the counter example for LTL model checking, including 2 parts: prefix, and period.
        /// [ REFS: '', DEREFS: automataBDD.transitionBDD, this.prefix, this.period ]
        /// </summary>
        /// <param name="automataBDD"></param>
        /// <param name="encoder"></param>
        /// <returns></returns>
        public void GetMCResult(AutomataBDD automataBDD, BDDEncoder encoder)
        {
            VerificationOutput.CounterExampleTrace.Add(InitialStep);

            if (VerificationOutput.VerificationResult == VerificationResultType.INVALID && VerificationOutput.GenerateCounterExample)
            {
                VerificationOutput.LoopIndex = this.prefix.Count + 1;

                List<CUDDNode> traces = new List<CUDDNode>();
                ExpressionBDDEncoding initEncoding = automataBDD.initExpression.TranslateBoolExpToBDD(encoder.model);
                traces.Add(CUDD.Function.Or(initEncoding.GuardDDs));
                traces.AddRange(this.prefix);
                traces.AddRange(this.period);

                Valuation currentValuation = this.InitialStep.GlobalEnv;
                Valuation lastValuation;
                for (int i = 1; i < traces.Count; i++)
                {
                    //Get event information

                    CUDD.Ref(traces[i], traces[i - 1]);
                    CUDDNode transitionTemp = CUDD.Function.And(traces[i - 1], encoder.model.SwapRowColVars(traces[i]));

                    CUDD.Ref(automataBDD.transitionBDD);
                    CUDDNode transWithEventInfo = CUDD.Function.And(transitionTemp, automataBDD.transitionBDD);

                    transWithEventInfo = CUDD.Abstract.ThereExists(transWithEventInfo, encoder.model.AllRowVarsExceptSingleCopy);
                    transWithEventInfo = CUDD.RestrictToFirst(transWithEventInfo, encoder.model.AllColVars);

                    lastValuation = currentValuation;
                    currentValuation = encoder.GetValuationFromBDD(transWithEventInfo, this.InitialStep.GlobalEnv);

                    string eventName = encoder.GetEventChannelName(lastValuation, currentValuation, transWithEventInfo);

                    VerificationOutput.CounterExampleTrace.Add(new ConfigurationBDD(eventName, currentValuation));

                    //
                    CUDD.Deref(transWithEventInfo);
                }

                //
                CUDD.Deref(traces);
            }

            CUDD.Deref(automataBDD.transitionBDD);

            VerificationOutput.ActualMemoryUsage = CUDD.ReadMemoryInUse();
            VerificationOutput.numberOfBoolVars = encoder.model.NumberOfBoolVars;

            encoder.model.Close();
        }
Exemple #7
0
        /// <summary>
        /// Encode the graph
        /// make sure that the local variables' names are unique.
        /// </summary>
        /// <param name="encoder"></param>
        /// <returns></returns>
        public AutomataBDD Encode(BDDEncoder encoder)
        {
            AutomataBDD processAutomataBDD = new AutomataBDD();

            string processVariableName = this.AddLocalVariables(encoder);

            //Set local variables and initial condition
            SetLocalVarsAndInit(encoder, processAutomataBDD, processVariableName);

            //Encode transitions
            EncodeTransitions(encoder, processAutomataBDD, processVariableName);

            return(processAutomataBDD);
        }
Exemple #8
0
        /// <summary>
        /// Add local variable including state, and parameters
        /// Return the variable name encoding states
        /// </summary>
        /// <param name="encoder"></param>
        public string AddLocalVariables(BDDEncoder encoder)
        {
            RenameLocalVars();

            for (int i = 0; i < this.Parameters.Count; i++)
            {
                string parameter = this.Parameters[i];

                int min = Model.BDD_INT_UPPER_BOUND;
                int max = Model.BDD_INT_LOWER_BOUND;

                if (ParameterUpperBound.ContainsKey(parameter) && ParameterLowerBound.ContainsKey(parameter))
                {
                    min = ParameterLowerBound[parameter];
                    max = ParameterUpperBound[parameter];
                }
                else
                {
                    ExpressionBDDEncoding argumentBDD = this.Arguments[i].TranslateIntExpToBDD(encoder.model);
                    foreach (CUDDNode argExp in argumentBDD.ExpressionDDs)
                    {
                        min = Math.Min(min, (int)CUDD.FindMinThreshold(argExp, Model.BDD_INT_LOWER_BOUND));
                        max = Math.Max(max, (int)CUDD.FindMaxThreshold(argExp, Model.BDD_INT_UPPER_BOUND));
                    }
                }

                //In its old transition encoding, we don't make sure this variable must be unchanged.
                //We also need to add this variable to VaribleIndex of the AutomataBDD because previous process does not know this variable
                //if global then later processes will set this variable as unchange.
                encoder.model.AddLocalVar(parameter, min, max);
            }

            const string STATE = "state";
            //
            string processVariableName = Name + Model.NAME_SEPERATOR + STATE + Model.GetNewTempVarName();

            encoder.model.AddLocalVar(processVariableName, 0, this.States.Count - 1);

            //
            encoder.stateIndexOfCurrentProcess = new Dictionary <string, int>();
            //collect the state index
            foreach (State state in this.States)
            {
                encoder.stateIndexOfCurrentProcess.Add(state.Name, encoder.stateIndexOfCurrentProcess.Count);
            }

            return(processVariableName);
        }
Exemple #9
0
        public void SetLocalVarsAndInit(BDDEncoder encoder, AutomataBDD processAutomataBDD, string processVariableName)
        {
            processAutomataBDD.variableIndex.Add(encoder.model.GetVarIndex(processVariableName));
            //
            foreach (string parameter in this.Parameters)
            {
                processAutomataBDD.variableIndex.Add(encoder.model.GetVarIndex(parameter));
            }

            //Set initial expression
            processAutomataBDD.initExpression = new PrimitiveApplication(PrimitiveApplication.EQUAL, new Variable(processVariableName),
                                                                         new IntConstant(encoder.stateIndexOfCurrentProcess[this.InitialState.Name]));
            for (int i = 0; i < this.Arguments.Count; i++)
            {
                processAutomataBDD.initExpression = new PrimitiveApplication(PrimitiveApplication.AND, processAutomataBDD.initExpression,
                                                                             new PrimitiveApplication(PrimitiveApplication.EQUAL, new Variable(this.Parameters[i]), this.Arguments[i]));
            }
        }
Exemple #10
0
        public void SetLocalVarsAndInit(BDDEncoder encoder, AutomataBDD processBDD, string stateVar)
        {
            processBDD.variableIndex.Add(encoder.model.GetVarIndex(stateVar));
            //
            foreach (string parameter in this.Parameters)
            {
                processBDD.variableIndex.Add(encoder.model.GetVarIndex(parameter));
            }

            //Set initial expression
            processBDD.initExpression = Expression.EQ(new Variable(stateVar),
                                                      new IntConstant(encoder.stateIndexOfCurrentProcess[this.InitialState.ID]));
            for (int i = 0; i < this.Arguments.Count; i++)
            {
                processBDD.initExpression = Expression.AND(processBDD.initExpression,
                                                           Expression.EQ(new Variable(this.Parameters[i]), this.Arguments[i]));
            }
        }
Exemple #11
0
        /// <summary>
        /// Encode sync channel out transition as event!a.b.c
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <returns></returns>
        public List <CUDDNode> EncodeSyncChannelOutTransition(BDDEncoder encoder, string processVariableName, List <int> localVars)
        {
            Expression guard = Expression.EQ(
                new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guard = Expression.CombineGuard(guard, GuardCondition);

            List <Expression> parameters = encoder.GetParaExpInEvent(this.Event);
            int channelEventIndex        = encoder.GetEventIndex(this.Event.BaseName, parameters.Count);

            guard = Expression.AND(guard, new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));
            for (int i = 0; i < parameters.Count; i++)
            {
                //assign event parameter to the values in the event expression
                guard = Expression.AND(guard, new Assignment(encoder.model.eventParameterVariables[i], parameters[i]));
            }

            guard = Expression.AND(guard, new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID])));

            List <CUDDNode> transitions = guard.TranslateBoolExpToBDD(encoder.model).GuardDDs;

            return(encoder.model.AddVarUnchangedConstraint(transitions, localVars));
        }
Exemple #12
0
        /// <summary>
        /// Encode transition, if it is synchronized, then we don't add constraint of unchanged global variables
        /// Parallel process only synchorinize event which does not change global variable or each transition changes same to global variables
        /// 3 kinds of transition: normal event, async channel input and async channel output
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <param name="isSynchronized"></param>
        /// <returns></returns>
        public List <CUDDNode> Encode(BDDEncoder encoder, string processVariableName, List <int> localVars, bool isSynchronized)
        {
            Expression guardExpressions = Expression.EQ(
                new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guardExpressions = Expression.CombineGuard(guardExpressions, GuardCondition);


            Expression eventUpdateExpression;

            if (this.Event is BDDEncoder.EventChannelInfo)
            {
                int channelIndex = encoder.GetChannelIndex(this.Event.BaseName, (this.Event as BDDEncoder.EventChannelInfo).type);
                eventUpdateExpression = new Assignment(Model.EVENT_NAME, new IntConstant(channelIndex));
            }
            else
            {
                eventUpdateExpression = encoder.GetEventExpression(this.Event);
            }

            Assignment stateUpdateExpression = new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID]));
            Sequence   updateExpressions     = new Sequence(eventUpdateExpression, stateUpdateExpression);

            if (this.ProgramBlock != null)
            {
                updateExpressions = new Sequence(updateExpressions, this.ProgramBlock);
            }

            List <int> unchangedVars = new List <int>(localVars);

            if (!isSynchronized)
            {
                unchangedVars.AddRange(encoder.model.GlobalVarIndex);
            }

            return(encoder.model.EncodeTransition(guardExpressions, updateExpressions, unchangedVars));
        }
Exemple #13
0
        /// <summary>
        /// Encode transition, if it is synchronized, then we don't add constraint of unchanged global variables
        /// Parallel process only synchorinize event which does not change global variable or each transition changes same to global variables
        /// 3 kinds of transition: normal event, async channel input and async channel output
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <param name="isSynchronized"></param>
        /// <returns></returns>
        public List<CUDDNode> Encode(BDDEncoder encoder, string processVariableName, List<int> localVars, bool isSynchronized)
        {
            Expression guardExpressions = Expression.EQ(
                                                        new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guardExpressions = Expression.CombineGuard(guardExpressions, GuardCondition);

            Expression eventUpdateExpression;
            if (this.Event is BDDEncoder.EventChannelInfo)
            {
                int channelIndex = encoder.GetChannelIndex(this.Event.BaseName, (this.Event as BDDEncoder.EventChannelInfo).type);
                eventUpdateExpression = new Assignment(Model.EVENT_NAME, new IntConstant(channelIndex));
            }
            else
            {
                eventUpdateExpression = encoder.GetEventExpression(this.Event);
            }

            Assignment stateUpdateExpression = new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID]));
            Sequence updateExpressions = new Sequence(eventUpdateExpression, stateUpdateExpression);

            if (this.ProgramBlock != null)
            {
                updateExpressions = new Sequence(updateExpressions, this.ProgramBlock);
            }

            List<int> unchangedVars = new List<int>(localVars);
            if (!isSynchronized)
            {
                unchangedVars.AddRange(encoder.model.GlobalVarIndex);
            }

            return encoder.model.EncodeTransition(guardExpressions, updateExpressions, unchangedVars);
        }
Exemple #14
0
        /// <summary>
        /// Encode sync channel out transition as event!a.b.c
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <returns></returns>
        public List<CUDDNode> EncodeSyncChannelOutTransition(BDDEncoder encoder, string processVariableName, List<int> localVars)
        {
            Expression guard = Expression.EQ(
                                                       new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guard = Expression.CombineGuard(guard, GuardCondition);

            List<Expression> parameters = encoder.GetParaExpInEvent(this.Event);
            int channelEventIndex = encoder.GetEventIndex(this.Event.BaseName, parameters.Count);

            guard = Expression.AND(guard, new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));
            for (int i = 0; i < parameters.Count; i++)
            {
                //assign event parameter to the values in the event expression
                guard = Expression.AND(guard, new Assignment(encoder.model.eventParameterVariables[i], parameters[i]));
            }

            guard = Expression.AND(guard, new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID])));

            List<CUDDNode> transitions = guard.TranslateBoolExpToBDD(encoder.model).GuardDDs;
            return encoder.model.AddVarUnchangedConstraint(transitions, localVars);
        }
Exemple #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="processVariableName"></param>
        /// <param name="localVars">Local of the current SymbolicLTS is unchanged</param>
        /// <returns></returns>
        public List<CUDDNode> EncodeSyncChannelInTransition(BDDEncoder encoder, string processVariableName, List<int> localVars)
        {
            Expression guard = Expression.EQ(
                                                        new Variable(processVariableName), new IntConstant(encoder.stateIndexOfCurrentProcess[this.FromState.ID]));

            guard = Expression.CombineGuard(guard, GuardCondition);

            List<Expression> parameters = encoder.GetParaExpInEvent(this.Event);
            int channelEventIndex = encoder.GetEventIndex(this.Event.BaseName, parameters.Count);

            guard = Expression.AND(guard, new Assignment(Model.EVENT_NAME, new IntConstant(channelEventIndex)));
            guard = Expression.AND(guard, new Assignment(processVariableName, new IntConstant(encoder.stateIndexOfCurrentProcess[this.ToState.ID])));

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

                }
            }

            List<CUDDNode> transitions = guard.TranslateBoolExpToBDD(encoder.model).GuardDDs;
            return encoder.model.AddVarUnchangedConstraint(transitions, localVars);
        }
Exemple #16
0
 private void EncodeTransitions(BDDEncoder encoder, AutomataBDD processBDD, string stateVar)
 {
     foreach (Transition transition in this.Transitions)
     {
         //Depend on what kind of transition to add the encoded transition to AutomataBDD
         if (transition.Event is ChannelInputEvent)
         {
             List<CUDDNode> transitionBDDs = transition.Encode(encoder, stateVar, processBDD.variableIndex, true);
             processBDD.channelInTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.Event is ChannelOutputEvent)
         {
             List<CUDDNode> transitionBDDs = transition.Encode(encoder, stateVar, processBDD.variableIndex, true);
             processBDD.channelOutTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.Event is BDDEncoder.EventChannelInfo && (transition.Event as BDDEncoder.EventChannelInfo).type == BDDEncoder.EventChannelInfo.EventType.SYNC_CHANNEL_INPUT)
         {
             List<CUDDNode> transitionBDDs = transition.EncodeSyncChannelInTransition(encoder, stateVar, processBDD.variableIndex);
             processBDD.channelInTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.Event is BDDEncoder.EventChannelInfo && (transition.Event as BDDEncoder.EventChannelInfo).type == BDDEncoder.EventChannelInfo.EventType.SYNC_CHANNEL_OUTPUT)
         {
             List<CUDDNode> transitionBDDs = transition.EncodeSyncChannelOutTransition(encoder, stateVar, processBDD.variableIndex);
             processBDD.channelOutTransitionBDD.AddRange(transitionBDDs);
         }
         else if (transition.IsTick())
         {
             List<CUDDNode> transitionBDDs = transition.Encode(encoder, stateVar, processBDD.variableIndex, false);
             processBDD.Ticks.AddRange(transitionBDDs);
         }
         else
         {
             List<CUDDNode> transitionBDDs = transition.Encode(encoder, stateVar, processBDD.variableIndex, false);
             processBDD.transitionBDD.AddRange(transitionBDDs);
         }
     }
 }
Exemple #17
0
        private void EncodeSimulationRel(BDDEncoder encoder, AutomataBDD processBDD, string stateVar)
        {
            int stateVarIndex = encoder.model.GetVarIndex(stateVar);
            CUDDVars rowStateVars = encoder.model.GetRowVars(stateVarIndex);
            CUDDVars colStateVars = encoder.model.GetColVars(stateVarIndex);

            CUDDNode result = CUDD.Constant(0);

            foreach (var pair in mapOldLoc2NewStates)
            {
                List<State> statesInLoc = pair.Value;

                for(int i = 0; i < statesInLoc.Count; i++)
                {
                    for(int j = 0; j < statesInLoc.Count; j++)
                    {
                        if(ClockValuation.IsLUSimulated(mapNewState2Valuation[statesInLoc[i].ID], mapNewState2Valuation[statesInLoc[j].ID], pair.Key))
                        {
                            CUDDNode simulated = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), rowStateVars, encoder.stateIndexOfCurrentProcess[statesInLoc[i].ID], 1);
                            CUDDNode simulating = CUDD.Matrix.SetVectorElement(CUDD.Constant(0), colStateVars, encoder.stateIndexOfCurrentProcess[statesInLoc[j].ID], 1);

                            result = CUDD.Function.Or(result, CUDD.Function.And(simulated, simulating));
                        }
                    }
                }
            }

            processBDD.SimulationRel = result;
        }
Exemple #18
0
        public void SetLocalVarsAndInit(BDDEncoder encoder, AutomataBDD processBDD, string stateVar)
        {
            processBDD.variableIndex.Add(encoder.model.GetVarIndex(stateVar));
            //
            foreach (string parameter in this.Parameters)
            {
                processBDD.variableIndex.Add(encoder.model.GetVarIndex(parameter));
            }

            //Set initial expression
            processBDD.initExpression = Expression.EQ(new Variable(stateVar),
                                                                         new IntConstant(encoder.stateIndexOfCurrentProcess[this.InitialState.ID]));
            for (int i = 0; i < this.Arguments.Count; i++)
            {
                processBDD.initExpression = Expression.AND(processBDD.initExpression,
                                                                             Expression.EQ(new Variable(this.Parameters[i]), this.Arguments[i]));
            }
        }
Exemple #19
0
        /// <summary>
        /// Encode the graph
        /// make sure that the local variables' names are unique.
        /// </summary>
        /// <param name="encoder"></param>
        /// <param name="isUsingSimulation">true to use LU simulation in TA module</param>
        /// <returns></returns>
        public AutomataBDD Encode(BDDEncoder encoder, bool isUsingSimulation)
        {
            AutomataBDD processAutomataBDD = new AutomataBDD();

            string processVariableName = this.AddLocalVariables(encoder);

            //Set local variables and initial condition
            SetLocalVarsAndInit(encoder, processAutomataBDD, processVariableName);

            //Encode transitions
            EncodeTransitions(encoder, processAutomataBDD, processVariableName);

            if (isUsingSimulation)
            {
                EncodeSimulationRel(encoder, processAutomataBDD, processVariableName);
            }

            return processAutomataBDD;
        }