예제 #1
0
        /// <summary>
        /// Adds guards for the rules of NonDeter and INVAR of ARB and MAX strategies.
        /// </summary>
        /// <param name="kpRule"></param>
        /// <param name="module"></param>
        /// <param name="strategyIndex"></param>
        /// <returns></returns>
        public static NuSMV.Rule extractStandardRuleWithGuard4ARBandMAX(KpCore.Rule kpRule)
        {
            NuSMV.Rule smvRule = new NuSMV.Rule();
            smvRule.Type = SMVRuleType.REWRITING;
            if (kpRule is ConsumerRule)
            {
                ConsumerRule consumerRule = (ConsumerRule)kpRule;
                // it adds guards to _arb0 and _max0
                if (kpRule.IsGuarded)
                {
                    ICondition guardCondition = extractGuardConditionFromKPRule(kpRule);
                    smvRule.Condition = guardCondition;
                }
                foreach (var multiset in consumerRule.Lhs)
                {
                    BoolExp ruleConditions = new BoolExp();

                    ruleConditions.Left = new Expression(multiset.Key);
                    ruleConditions.RelationalOperator.Operator = NuSMV.RelationalOperator.GEQ;
                    ruleConditions.Right = new Expression(multiset.Value.ToString());
                    if (smvRule.Condition == null)
                    {
                        smvRule.Condition = ruleConditions;
                    }
                    else
                    {
                        smvRule.AppendBoolExpression(ruleConditions, BinaryOperator.AND);
                    }
                }
            }
            return(smvRule);
        }
예제 #2
0
        /// <summary> Insert the caseline at the beginning of child status' next, If parent divides then child will activate
        /// case (parent._status = willDivide) & (next( parent._status) = DIVIDED) : _ACTIVE; </summary> <param
        /// name="childSMVInstance"></param>
        private static void updateChildModuleStatus(ChildInstance childSMVInstance)
        {
            //copy status variable and add custom activation case.
            Variable status = module.Status;

            status.Behaviour = VariableBehaviour.DIVISION;

            // add custom case (parent._status = willDivide) & (next( parent._status) = DIVIDED)
            CaseLine   newCase      = new CaseLine();
            string     parentStatus = childSMVInstance.ParentInstance.Name + "." + status.Name;
            Expression left         = new Expression();

            left.Exp = parentStatus;
            Expression right      = new Expression(StatusStates.WILLDIVIDE);
            BoolExp    condition1 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            left     = new Expression();
            left.Exp = SMVKeys.NEXT + "( " + parentStatus + ")";
            right    = new Expression(StatusStates.DIVIDED);
            BoolExp condition2 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);
            CompoundBoolExpression compound = new CompoundBoolExpression(condition1, BinaryOperator.AND, condition2);
            Expression             result   = new Expression(StatusStates.ACTIVE);

            newCase.Rule.Condition = compound;
            newCase.Result         = result;
            //insert at the beginning
            status.Next.CaseStatement.CaseLines.Insert(0, newCase);

            childSMVInstance.DivisionStatus = status;
        }
예제 #3
0
        private static void addStatusToChildInstance(ParentInstance parentInstance, ChildInstance childSmvInstance)
        {
            //copy status variable and add custom activation case.
            Variable status      = module.Status;
            Variable childStatus = new Variable(status.Name);

            childStatus.Behaviour = VariableBehaviour.DIVISION;
            childStatus.Type      = status.Type;
            foreach (var caseLine in status.Next.CaseStatement.CaseLines)
            {
                childStatus.Next.CaseStatement.CaseLines.Add(caseLine);
            }
            // add custom case (parent._status = willDivide) & (next( parent._status) = DIVIDED)
            CaseLine   newCase      = new CaseLine();
            string     parentStatus = parentInstance.Name + "." + status.Name;
            Expression left         = new Expression();

            left.Exp = parentStatus;
            Expression right      = new Expression(StatusStates.WILLDIVIDE);//I changed here for willDivide
            BoolExp    condition1 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            left     = new Expression();
            left.Exp = SMVKeys.NEXT + "( " + parentStatus + ")";
            right    = new Expression(StatusStates.DIVIDED);
            BoolExp condition2 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);
            CompoundBoolExpression compound = new CompoundBoolExpression(condition1, NuSMV.BinaryOperator.AND, condition2);
            Expression             result   = new Expression(StatusStates.ACTIVE);

            newCase.Rule.Condition = compound;
            newCase.Result         = result;
            //insert at the beginning
            childStatus.Next.CaseStatement.CaseLines.Insert(0, newCase);

            childSmvInstance.DivisionStatus = childStatus;
        }
예제 #4
0
        internal static void addCaseLineToCurrentCopyCommVar(Variable orjVariable, Variable copyCommVar, KpCore.Rule rule, Module module, Module targetModule, int strategyIndex)
        {
            //for each variable generate a case line
            CaseLine caseLine            = new CaseLine();
            OperExp  result              = new OperExp();
            int      resultValue         = 0;
            RewriteCommunicationRule rcr = (RewriteCommunicationRule)rule;

            foreach (var target in rcr.TargetRhs.Values)
            {
                TargetedMultiset   targetMultiSet = (TargetedMultiset)target;
                InstanceIdentifier targetType     = (InstanceIdentifier)targetMultiSet.Target;
                if (targetModule.Type == targetType.Value)
                {
                    Multiset ms = targetMultiSet.Multiset;
                    foreach (var obj in ms.Objects)
                    {
                        if (obj.Equals(orjVariable.Name))
                        {
                            resultValue += ms[obj];
                        }
                    }
                }
            }
            result.Exp = copyCommVar.Name;
            if (resultValue != 0)
            {
                result.Oper.Value = MathOper.ADD;
                result.Result     = new Expression(resultValue.ToString());
            }

            caseLine.Result = result;
            caseLine.Rule   = BRulesStandardVar.extractStandardRuleFromKPRule(rule, module, strategyIndex);

            ICondition             sequenceCondition = BRulesStandardVar.getSequenceCondition(module, strategyIndex, rule.Id);
            ICondition             targetBounds      = getBoundCondition(copyCommVar, caseLine.Result);
            CompoundBoolExpression sequenceAndBound  = new CompoundBoolExpression(sequenceCondition, BinaryOperator.AND, targetBounds);

            ICondition statusCondition = BRulesStandardVar.getTurnCondition(module, strategyIndex);

            CompoundBoolExpression statusAndSequence = new CompoundBoolExpression(statusCondition, BinaryOperator.AND, sequenceAndBound);

            // _conn = to_c2
            if (module.connectionToModuleExist(targetModule))
            {
                BoolExp connEqInstance = new BoolExp(module.getConnectionToModule(targetModule).Name, NuSMV.RelationalOperator.EQUAL, SMVPreFix.getConnectedTo(targetModule.Instance));
                caseLine.Rule.AddBoolExpression(connEqInstance, BinaryOperator.AND);
            }
            caseLine.Rule.AddBoolExpression(statusAndSequence, BinaryOperator.AND);
            caseLine.Rule.ID = rule.Id;

            if (copyCommVar.Next != null)
            {
                //if the case line has not added yet
                if (!ruleExist(copyCommVar.Next, caseLine))
                {
                    copyCommVar.Next.addCaseLine(caseLine);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Add the rule which defines the values of division variables. Remained rules will be added later in
        /// BRulesStandardVar.assignLastCasesToDivisionVars
        /// </summary>
        /// <param name="childSmvInstance"></param>
        /// <param name="variable"></param>
        /// <param name="totalValue"></param>
        private static void addRuleChildDivisionVariables(ChildInstance childSmvInstance, Variable variable, int totalValue)
        {
            CaseLine newCase = new CaseLine();

            string     childActivation = childSmvInstance.Name + "." + childSmvInstance.DivisionStatus.Name;
            Expression left            = new Expression();

            left.Exp = childActivation;
            Expression right      = new Expression(StatusStates.NONEXIST);
            BoolExp    condition1 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            //next(child.status)=ACTIVE
            left     = new Expression();
            left.Exp = SMVKeys.NEXT + "(" + childActivation + ")";
            right    = new Expression(StatusStates.ACTIVE);
            BoolExp condition2 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            CompoundBoolExpression compound = new CompoundBoolExpression(condition1, NuSMV.BinaryOperator.AND, condition2);

            newCase.Rule.Condition = compound;

            Expression result = new Expression();

            result.Exp = totalValue.ToString();

            newCase.Result = result;
            variable.Next.CaseStatement.CaseLines.Insert(0, newCase);
        }
예제 #6
0
        /// <summary>
        /// NEXT(_turn)=turnState;
        /// </summary>
        /// <param name="turnState"></param>
        /// <returns></returns>
        public static BoolExp getNextTurnCondition(string turnState)
        {
            BoolExp turnIsSequence = new BoolExp();
            string  nextTurn       = SMVKeys.NEXT + "(" + CustomVariables.TURN + ")";

            turnIsSequence.Left = new Expression(nextTurn);
            turnIsSequence.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            turnIsSequence.Right = new Expression(turnState);
            return(turnIsSequence);
        }
예제 #7
0
        /// <summary>
        /// Return turn RELATIONALOP state, eg. turn !=Ready
        /// </summary>
        /// <param name="turnState"></param>
        /// <param name="relationalOperator">eg. NuSMV.RelationalOperator.NOT_EQUAL</param>
        /// <returns></returns>
        public static ICondition getTurnCondition(string turnState, String relationalOperator)
        {
            //turn = sequence1
            BoolExp turnExp = new BoolExp();

            turnExp.Left = new Expression(CustomVariables.TURN);
            turnExp.RelationalOperator.Operator = relationalOperator;
            turnExp.Right = new Expression(turnState);
            return(turnExp);
        }
예제 #8
0
        /// <summary>
        /// Status = StatusState
        /// </summary>
        /// <param name="module"></param>
        /// <param name="statusState"></param>
        /// <returns></returns>
        public static ICondition getStatusCondition(Module module, string statusState)
        {
            BoolExp statusCondition = null;

            if (module.HasDissolutionRule || module.HasDivisionRule)
            {
                statusCondition = new BoolExp();
                statusCondition = new BoolExp(module.Status.Name, NuSMV.RelationalOperator.EQUAL, statusState);
            }
            return(statusCondition);
        }
예제 #9
0
        public static ICondition getTurnCondition(Module module, int strategyIndex)
        {
            Strategy ex        = module.ExecutionStrategies.ElementAt(strategyIndex);
            string   turnState = ex.Name;
            //turn = sequence1
            BoolExp turnEQState = new BoolExp();

            turnEQState.Left = new Expression(CustomVariables.TURN);
            turnEQState.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            turnEQState.Right = new Expression(turnState + strategyIndex);
            return(turnEQState);
        }
예제 #10
0
        /// <summary> (((_status = _willDISSOLVE) | (_status = _willDIVIDE)) & (_sync = _EXCH)) </summary> <param
        /// name="module"></param> <returns></returns>
        private static ICondition getWillDissolveOrWillDivideAndSync(Module module)
        {
            ICondition statusWillDissolveOrWillDivide = getStatusWillDissolveOrWillDivide(module);
            BoolExp    synchIsExch = new BoolExp();

            synchIsExch.Left = new Expression(CustomVariables.SYNCH);
            synchIsExch.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            synchIsExch.Right = new Expression(SynchStates.EXCHANGE);
            CompoundBoolExpression willDisDivAndSync = new CompoundBoolExpression(statusWillDissolveOrWillDivide, BinaryOperator.AND, synchIsExch);

            return(willDisDivAndSync);
        }
예제 #11
0
        /// <summary>
        /// this is instanced status e.g. c1.STATUS =ACTIVE
        /// </summary>
        /// <param name="module"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        internal static BoolExp getInstancedStatus(Module module, string statusStates)
        {
            BoolExp statusCondition = null;

            if (module.HasDissolutionRule || module.HasDivisionRule)
            {
                statusCondition      = new BoolExp();
                statusCondition.Left = new InstancedExp(module.Instance.Name, module.Status.Name);
                statusCondition.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                statusCondition.Right = new Expression(statusStates);
            }
            return(statusCondition);
        }
예제 #12
0
        private static Case buildPStepNext(SMVModel nuSMV)
        {
            Case     newCase  = new Case();
            CaseLine caseLine = new CaseLine();
            //_sync = _EXCH
            ICondition synchIsExch = new BoolExp(CustomVariables.SYNCH, NuSMV.RelationalOperator.EQUAL, SynchStates.EXCHANGE);

            caseLine.Rule.Condition = synchIsExch;
            caseLine.Result         = new Expression(Truth.TRUE);
            newCase.CaseLines.Add(caseLine);
            newCase.CaseLines.Add(BRulesStandardVar.trueCaseLine(Truth.FALSE));
            return(newCase);
        }
예제 #13
0
        /// <summary>
        /// if module has either dissolution or division rule, then (_status = _ACTIVE)
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public static ICondition getStatusCondition(Module module)
        {
            BoolExp status = null;

            if (module.HasDissolutionRule || module.HasDivisionRule)
            {
                status      = new BoolExp();
                status.Left = new Expression(module.Status.Name);
                status.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                status.Right = new Expression(StatusStates.ACTIVE);
            }
            return(status);
        }
예제 #14
0
        /// <summary>
        /// Extracts boolean expression from a KP guard. In addition it adds module name as an identifier.
        /// </summary>
        /// <param name="sourceModule">module of guard</param>
        /// <param name="basicGuard"></param>
        /// <returns></returns>
        public static ICondition getBoolExpression(BasicGuard basicGuard)
        {
            Multiset ms = basicGuard.Multiset;

            NuSMV.RelationalOperator oper = SMVUtil.getRelationalOperator(basicGuard.Operator);
            BoolExp booleanExpression     = new BoolExp();

            foreach (var obj in ms.Objects)
            {
                booleanExpression.Left = new Expression(obj);
                booleanExpression.RelationalOperator = oper;
                booleanExpression.Right = new Expression(ms[obj].ToString());
            }
            return(booleanExpression);
        }
예제 #15
0
        /// <summary> ((_status = _NONEXIST) & (next(_status) = _ACTIVE))) </summary> <param name="module"></param>
        /// <returns></returns>
        internal static CompoundBoolExpression getStatusNonExistNEXTActive(Module module)
        {
            CompoundBoolExpression statusNonExistNEXTActive = null;

            if (module.HasDivisionRule)
            {
                ICondition statusNONEXIST = BRulesStandardVar.getStatusCondition(module, StatusStates.NONEXIST);

                //next(child.status)=ACTIVE
                Expression left = new Expression();
                left.Exp = SMVKeys.NEXT + "(" + module.Status.Name + ")";
                Expression right            = new Expression(StatusStates.ACTIVE);
                BoolExp    nextStatusACTIVE = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);
                statusNonExistNEXTActive = new CompoundBoolExpression(statusNONEXIST, NuSMV.BinaryOperator.AND, nextStatusACTIVE);
            }
            return(statusNonExistNEXTActive);
        }
예제 #16
0
        /// <summary> (((_status = _ACTIVE) | ((_status = _willDISSOLVE) | (_status = _willDIVIDE))) & (_sync = _EXCH)) : 0;
        /// </summary> <param name="module">NuSMV module</param> <param name="synchState">synchState = _EXCH</param>
        /// <returns>((_status = _ACTIVE | status = willDissolve) & (_synch = _EXCH))</returns>
        public static CompoundBoolExpression getStatusAndSynchCondition(Module module, string synchState)
        {
            ICondition status = null;

            if (module.HasDissolutionRule | module.HasDivisionRule)
            {
                status = getStatusCondition(module);
            }
            BoolExp synchIsExch = new BoolExp();

            synchIsExch.Left = new Expression(CustomVariables.SYNCH);
            synchIsExch.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            synchIsExch.Right = new Expression(synchState);
            CompoundBoolExpression statusAndTurn = new CompoundBoolExpression(status, BinaryOperator.AND, synchIsExch);

            return(statusAndTurn);
        }
예제 #17
0
        private static CompoundBoolExpression getInstancedStatusAndSyncCondition(Module module)
        {
            ICondition status = null;

            if (module.HasDissolutionRule || module.HasDivisionRule)
            {
                status = BRulesComVar.getInstancedStatus(module, StatusStates.ACTIVE);
            }
            // this is non-instanced _sync = _EXCH
            BoolExp synchIsExch = new BoolExp();

            synchIsExch.Left = new Expression(CustomVariables.SYNCH);
            synchIsExch.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            synchIsExch.Right = new Expression(SynchStates.EXCHANGE);

            //(_sync = _EXCH)
            CompoundBoolExpression statusAndSync = new CompoundBoolExpression(status, BinaryOperator.AND, synchIsExch);

            return(statusAndSync);
        }
예제 #18
0
        /// <summary>
        /// Extracts boolean expression from a KP guard. In addition it adds module name as an identifier.
        /// </summary>
        /// <param name="sourceModule">module of guard</param>
        /// <param name="basicGuard"></param>
        /// <returns></returns>
        private static ICondition getBoolExpression(Module sourceModule, BasicGuard basicGuard)
        {
            Multiset ms = basicGuard.Multiset;

            NuSMV.RelationalOperator oper = SMVUtil.getRelationalOperator(basicGuard.Operator);
            BoolExp booleanExpression     = new BoolExp();

            foreach (var obj in ms.Objects)
            {
                if (sourceModule != null)
                {
                    booleanExpression.Left = new InstancedExp(sourceModule.Type, obj);
                }
                else
                {
                    booleanExpression.Left = new InstancedExp(obj);
                }
                booleanExpression.RelationalOperator = oper;
                booleanExpression.Right = new Expression(ms[obj].ToString());
            }
            return(booleanExpression);
        }
예제 #19
0
        /// <summary>
        /// Translates KPRule to NUSMV rule, it ignores guards for ARB and MAX strategies, because the guards are
        /// represented by _arb0 and _max0 custom variables.
        /// </summary>
        /// <param name="kpRule"></param>
        /// <returns></returns>
        public static NuSMV.Rule extractStandardRuleFromKPRule(KpCore.Rule kpRule, Module module, int strategyIndex)
        {
            NuSMV.Rule smvRule = new NuSMV.Rule();
            smvRule.Type = SMVRuleType.REWRITING;
            Strategy ex = module.ExecutionStrategies.ElementAt(strategyIndex);

            if (kpRule is ConsumerRule)
            {
                ConsumerRule consumerRule = (ConsumerRule)kpRule;
                // If strategy is ARB or MAX then ignore guards for regular rules
                if (!(ex.Type == StrategyTypes.ARBITRARY || ex.Type == StrategyTypes.MAX))
                {
                    if (kpRule.IsGuarded)
                    {
                        ICondition guardCondition = extractGuardConditionFromKPRule(kpRule);
                        smvRule.Condition = guardCondition;
                    }
                }


                foreach (var multiset in consumerRule.Lhs)
                {
                    BoolExp ruleConditions = new BoolExp();

                    ruleConditions.Left = new Expression(multiset.Key);
                    ruleConditions.RelationalOperator.Operator = NuSMV.RelationalOperator.GEQ;
                    ruleConditions.Right = new Expression(multiset.Value.ToString());
                    if (smvRule.Condition == null)
                    {
                        smvRule.Condition = ruleConditions;
                    }
                    else
                    {
                        smvRule.AppendBoolExpression(ruleConditions, BinaryOperator.AND);
                    }
                }
            }
            return(smvRule);
        }
예제 #20
0
        /// <summary> Returns condition for lower and upper bound of a variable, to be added in rules. eg. ((step +
        /// 1)>=0)&((step + 1)<=9) </summary> <param name="sequence">variable</param> <param name="result">result of a rule
        /// e.g.(step + 1)</param> <returns>((step + 1)>=0)&((step + 1)<=9)</returns>
        internal static ICondition getBoundCondition(Variable variable, IExp result)
        {
            //ex. ((step + 1)>=0)
            BoolExp lowerCondition = new BoolExp();

            lowerCondition.Left = result;
            lowerCondition.RelationalOperator.Operator = NuSMV.RelationalOperator.GEQ;
            lowerCondition.Right = new Expression(((variable.Type) as BoundInt).LowerBound.ToString());
            //ex. ((step + 1)<=9)
            BoolExp upperCondition = new BoolExp();

            upperCondition.Left = result;
            upperCondition.RelationalOperator.Operator = NuSMV.RelationalOperator.LEQ;
            upperCondition.Right = new Expression(((variable.Type) as BoundInt).UpperBound.ToString());

            CompoundBoolExpression boundCondition = new CompoundBoolExpression();

            boundCondition.LeftCondition           = lowerCondition;
            boundCondition.BinaryOperator.Operator = BinaryOperator.AND;
            boundCondition.RightCondition          = upperCondition;

            return(boundCondition);
        }
예제 #21
0
        /// <summary>
        /// Adds sequence of execution strategy, such as, choice
        /// </summary>
        /// <param name="module"></param>
        /// <param name="strategyIndex"></param>
        /// <returns></returns>
        internal static ICondition getSequenceCondition(Module module, int strategyIndex, int ruleID)
        {
            BoolExp boolExpression = new BoolExp();

            Strategy ex = module.ExecutionStrategies.ElementAt(strategyIndex);

            if (ex.Type == StrategyTypes.CHOICE)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.CHOICE + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.SEQUENCE)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.SEQUENCE + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.ARBITRARY)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.ARBITRARY + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            else if (ex.Type == StrategyTypes.MAX)
            {
                IVar sequence = ex.CustomVars.Find(variable => variable.Name == (CustomVariables.MAX + strategyIndex));
                boolExpression.Left = new Expression(sequence.Name);
                boolExpression.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
                boolExpression.Right = new Expression(ruleID.ToString());
            }
            return(boolExpression);
        }
예제 #22
0
        /// <summary>
        /// Add the rule which defines the values of division variables. Remained rules will be added later in
        /// BRulesStandardVar.assignLastCasesToDivisionVars
        /// </summary>
        /// <param name="childSmvInstance"></param>
        /// <param name="variable"></param>
        /// <param name="totalValue"></param>
        private static void addRuleChildDivisionVariables(ChildInstance childSmvInstance, Variable variable, int totalValue)
        {
            CaseLine newCase = new CaseLine();

            string     childActivation = childSmvInstance.Name + "." + childSmvInstance.DivisionStatus.Name;
            Expression left            = new Expression();

            left.Exp = childActivation;
            Expression right      = new Expression(StatusStates.NONEXIST);
            BoolExp    condition1 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            //next(child.status)=ACTIVE
            left     = new Expression();
            left.Exp = SMVKeys.NEXT + "(" + childActivation + ")";
            right    = new Expression(StatusStates.ACTIVE);
            BoolExp condition2 = new BoolExp(left, NuSMV.RelationalOperator.EQUAL, right);

            CompoundBoolExpression compound = new CompoundBoolExpression(condition1, NuSMV.BinaryOperator.AND, condition2);

            newCase.Rule.Condition = compound;

            Expression result = new Expression();

            //inherit the parent's remained multiset objects
            //result.Exp = SMVKeys.NEXT + "(" + childSmvInstance.ParentInstance.Name + "." + variable.Name + ") + " + totalValue.ToString();
            //newCase.Rule.AppendBoolExpression(BRulesStandardVar.getBoundCondition(variable, result), BinaryOperator.AND);
            result.Exp = totalValue.ToString();

            newCase.Result = result;
            variable.Next.CaseStatement.CaseLines.Insert(0, newCase);

            ////((((_status = _willDISSOLVE) | (_status = _willDIVIDE))) & (_sync = _EXCH)) : 0;
            //CaseLine caseLine2 = new CaseLine();
            //ICondition willDissolve = null;
            //ICondition willDivide = null;
            //ICondition willDissolveOrDivide = null;

            //if (module.HasDissolutionRule)
            //{
            //    willDissolve = BRulesComVar.getInstancedStatus(module, StatusStates.WILLDISSOLVE);
            //}
            //if (module.HasDivisionRule)
            //{
            //    willDivide = BRulesComVar.getInstancedStatus(module, StatusStates.WILLDIVIDE);
            //}
            //willDissolveOrDivide = new CompoundBoolExpression(willDissolve, BinaryOperator.OR, willDivide);
            //// this is non-instanced _sync = _EXCH
            //BoolExp synchIsExch = new BoolExp();
            //synchIsExch.Left = new Expression(CustomVariables.SYNCH);
            //synchIsExch.RelationalOperator.Operator = NuSMV.RelationalOperator.EQUAL;
            //synchIsExch.Right = new Expression(SynchStates.EXCHANGE);

            //CompoundBoolExpression statusAndSync = new CompoundBoolExpression(willDissolveOrDivide, BinaryOperator.AND, synchIsExch);
            //caseLine2.Rule.Condition = statusAndSync;
            //caseLine2.Result = new Expression("0");
            //variable.Next.CaseStatement.CaseLines.Insert(1, caseLine2);

            ////((_status = _DISSOLVED) | (_status = _DIVIDED)) : 0;
            //CaseLine caseLine3 = new CaseLine();
            //ICondition dissolved = null;
            //ICondition divided = null;
            //ICondition dissolvedOrDivided= null;

            //if (module.HasDissolutionRule)
            //{
            //    dissolved = BRulesComVar.getInstancedStatus(module, StatusStates.DISSOLVED);
            //}
            //if (module.HasDivisionRule)
            //{
            //    divided = BRulesComVar.getInstancedStatus(module, StatusStates.DIVIDED);
            //}
            //dissolvedOrDivided = new CompoundBoolExpression(dissolved, BinaryOperator.OR, divided);
            //caseLine3.Rule.Condition = dissolvedOrDivided;
            //caseLine3.Result = new Expression("0");
            //variable.Next.CaseStatement.CaseLines.Insert(2, caseLine3);
        }
예제 #23
0
        public static ICondition insertInstanceName(ICondition left, Instance instance)
        {
            // ICondition condition = null;
            if (left is BoolExp)
            {
                BoolExp condition = new BoolExp();
                BoolExp boolExp   = (BoolExp)left;
                if (boolExp.Left.Exp.Contains(SMVKeys.SELF))
                {
                    if (boolExp.Left is OperExp)
                    {
                        OperExp tempOper = new OperExp();
                        tempOper.Exp        = (boolExp.Left as OperExp).Exp;
                        tempOper.Oper.Value = (boolExp.Left as OperExp).Oper.Value;
                        tempOper.Result     = (boolExp.Left as OperExp).Result;
                        condition.Left      = new Expression();
                        condition.Left.Exp  = tempOper.ToString().Replace(SMVKeys.SELF, instance.Name);
                    }
                    else
                    {
                        condition.Left     = new Expression();
                        condition.Left.Exp = condition.ToString().Replace(SMVKeys.SELF, instance.Name);
                    }
                    condition.RelationalOperator = boolExp.RelationalOperator;
                    condition.Right     = new Expression();
                    condition.Right.Exp = boolExp.Right.Exp;
                }
                else if (!boolExp.Left.Exp.Contains(instance.Name))
                {
                    // if it is a shared variable (such as main's synch variable), then don't call with compartment name
                    if (boolExp.Left.Exp == CustomVariables.SYNCH)
                    {
                        // actually do nothing.
                        condition.Left     = new Expression();
                        condition.Left.Exp = boolExp.Left.Exp;
                    }
                    else if (boolExp.Left is OperExp)
                    {
                        condition.Left     = new Expression();
                        condition.Left.Exp = insertInstanceName2Expression(boolExp.Left, instance);
                    }
                    else
                    {
                        condition.Left     = new Expression();
                        condition.Left.Exp = instance.Name + "." + boolExp.Left.Exp;
                    }
                    condition.RelationalOperator = boolExp.RelationalOperator;
                    condition.Right     = new Expression();
                    condition.Right.Exp = boolExp.Right.Exp;
                }
                else
                {
                    condition = boolExp;
                }
                return(condition);
            }
            else if (left is BoolVariable)
            {
                BoolVariable boolGuard = (BoolVariable)left;
                BoolVariable condition = new BoolVariable();
                if (boolGuard.BoolGuard.Exp == SMVKeys.SELF)
                {
                    (condition as BoolVariable).BoolGuard.Exp = boolGuard.BoolGuard.Exp.Replace(SMVKeys.SELF, instance.Name);
                }
                else
                {
                    (condition as BoolVariable).BoolGuard.Exp = instance.Name + "." + boolGuard.BoolGuard.Exp;
                }
                return(condition);;
            }
            else if (left is NegatedBoolExpression)
            {
                NegatedBoolExpression negated   = (NegatedBoolExpression)left;
                NegatedBoolExpression condition = new NegatedBoolExpression();

                BoolExp boolExp = (BoolExp)negated.BoolExpression;
                if (boolExp.Left.Exp == SMVKeys.SELF)
                {
                    ((condition as NegatedBoolExpression).BoolExpression as BoolExp).Left.Exp = boolExp.Left.Exp.Replace(SMVKeys.SELF, instance.Name);
                }
                else
                {
                    ((condition as NegatedBoolExpression).BoolExpression as BoolExp).Left.Exp = instance.Name + "." + boolExp.Left.Exp;
                }
                return(condition);
            }
            else if (left is TruthValue)
            {
                return(left);
            }
            else
            {
                if (left != null)
                {
                    CompoundBoolExpression comp             = (CompoundBoolExpression)left;
                    CompoundBoolExpression compoundBoolExpr = new CompoundBoolExpression();
                    compoundBoolExpr.LeftCondition  = insertInstanceName(comp.LeftCondition, instance);
                    compoundBoolExpr.BinaryOperator = comp.BinaryOperator;
                    compoundBoolExpr.RightCondition = insertInstanceName(comp.RightCondition, instance);
                    // condition = compoundBoolExpr;
                    return(compoundBoolExpr);
                }
                else
                {
                    return(null);
                }
            }
        }
        internal static void addRuleToStatusVariable(KpCore.Rule rule, NuSMV.Module module, int strategyIndex)
        {
            // ((main._status = _willDIVIDE) & (_sync = _BUSY)) : _willDIVIDE; ((main._status = _willDIVIDE) & (_sync =
            // _EXCH)) : _DIVIDED;
            if (module.HasDivisionRule)
            {
                CaseLine willDivideCaseLine = new CaseLine();
                //((main._status = _willDIVIDE) & (_sync = _BUSY)) : _willDIVIDE;
                ICondition willDivide = BRulesStandardVar.getStatusCondition(module, StatusStates.WILLDIVIDE);
                ICondition syncBusy   = new BoolExp(CustomVariables.SYNCH, NuSMV.RelationalOperator.EQUAL, SynchStates.BUSY);
                willDivideCaseLine.Rule.Condition = new CompoundBoolExpression(willDivide, BinaryOperator.AND, syncBusy);
                willDivideCaseLine.Result         = new Expression(StatusStates.WILLDIVIDE);
                if (!BRulesComVar.ruleExist(module.Status.Next, willDivideCaseLine))
                {
                    module.Status.Next.addCaseLine(willDivideCaseLine);
                }
                // ((main._status = _willDIVIDE) & (_sync = _EXCH)) : _DIVIDED;
                CaseLine   dividedCaseLine = new CaseLine();
                ICondition syncExch        = new BoolExp(CustomVariables.SYNCH, NuSMV.RelationalOperator.EQUAL, SynchStates.EXCHANGE);
                dividedCaseLine.Rule.Condition = new CompoundBoolExpression(willDivide, BinaryOperator.AND, syncExch);
                dividedCaseLine.Result         = new Expression(StatusStates.DIVIDED);
                if (!BRulesComVar.ruleExist(module.Status.Next, dividedCaseLine))
                {
                    module.Status.Next.addCaseLine(dividedCaseLine);
                }
            }
            // ((main._status = _willDISSOLVE) & (_sync = _BUSY)) : _willDISSOLVE; ((main._status = _willDISSOLVE) & (_sync =
            // _EXCH)) : _DISSOLVED;
            if (module.HasDissolutionRule)
            {
                CaseLine caseLine2 = new CaseLine();
                //status = willDissolve & (_sync = _BUSY) : willDissolve;
                ICondition willSolve = BRulesStandardVar.getStatusCondition(module, StatusStates.WILLDISSOLVE);
                ICondition syncBusy  = new BoolExp(CustomVariables.SYNCH, NuSMV.RelationalOperator.EQUAL, SynchStates.BUSY);
                caseLine2.Rule.Condition = new CompoundBoolExpression(willSolve, BinaryOperator.AND, syncBusy);
                caseLine2.Result         = new Expression(StatusStates.WILLDISSOLVE);
                if (!BRulesComVar.ruleExist(module.Status.Next, caseLine2))
                {
                    module.Status.Next.addCaseLine(caseLine2);
                }
                //((c1._status = _willDISSOLVE) & (_sync = _EXCH)) : _DISSOLVED;
                CaseLine   caseLine3 = new CaseLine();
                ICondition syncExch  = new BoolExp(CustomVariables.SYNCH, NuSMV.RelationalOperator.EQUAL, SynchStates.EXCHANGE);
                caseLine3.Rule.Condition = new CompoundBoolExpression(willSolve, BinaryOperator.AND, syncExch);
                caseLine3.Result         = new Expression(StatusStates.DISSOLVED);
                if (!BRulesComVar.ruleExist(module.Status.Next, caseLine3))
                {
                    module.Status.Next.addCaseLine(caseLine3);
                }
            }

            CaseLine caseLine = new CaseLine();

            caseLine.Result  = getResultOfStatusRuleFromKPRule(module, rule);
            caseLine.Rule    = BRulesStandardVar.extractStandardRuleFromKPRule(rule, module, strategyIndex);
            caseLine.Rule.ID = rule.Id;
            //if module has division rule then, dissolve process happens inside instances.
            // ICondition statusCondition = BRulesStandardVar.getStatusCondition(module); No need status=Active condition anymore
            ICondition sequence = BRulesStandardVar.getSequenceCondition(module, strategyIndex, rule.Id);

            //CompoundBoolExpression compound = new CompoundBoolExpression(statusCondition, BinaryOperator.AND, sequence);
            caseLine.Rule.AddBoolExpression(sequence, BinaryOperator.AND);
            //if the case line has not added yet
            if (!BRulesComVar.ruleExist(module.Status.Next, caseLine))
            {
                module.Status.Next.addCaseLine(caseLine);
            }
        }