Example #1
0
        private static ICondition extractGuardConditionFromKpGuard(IGuard guard)
        {
            ICondition condition = null;

            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                condition = getBoolExpression(basicGuard);
            }
            else if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                Console.Error.WriteLine("KP NegatedGuard to SMV translation has not been implemented yet!");
            }
            else if (guard is CompoundGuard)
            {
                CompoundGuard          compoundGuard    = (CompoundGuard)guard;
                CompoundBoolExpression compoundBoolExpr = new CompoundBoolExpression();
                compoundBoolExpr.LeftCondition  = extractGuardConditionFromKpGuard(compoundGuard.Lhs);
                compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator);
                compoundBoolExpr.RightCondition = extractGuardConditionFromKpGuard(compoundGuard.Rhs);
                condition = compoundBoolExpr;
            }
            return(condition);
        }
        private static ICondition extractConditionFromKpGuard(Module sourceModule, IGuard guard)
        {
            ICondition condition = null;

            if (guard is BasicGuard)
            {
                BasicGuard basicGuard = (BasicGuard)guard;
                condition = getBoolExpression(sourceModule, basicGuard);
            }
            else if (guard is NegatedGuard)
            {
                NegatedGuard negatedGuard = (NegatedGuard)guard;
                Console.Error.WriteLine("NegatedGuard is not applicable.");
                // ICondition negatedBooleanExpression = getNegatedGuard(negatedGuard);
            }
            else if (guard is CompoundGuard)
            {
                CompoundGuard          compoundGuard    = (CompoundGuard)guard;
                CompoundBoolExpression compoundBoolExpr = null;
                compoundBoolExpr.LeftCondition  = extractConditionFromKpGuard(sourceModule, compoundGuard.Lhs);
                compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator);
                compoundBoolExpr.RightCondition = extractConditionFromKpGuard(sourceModule, compoundGuard.Rhs);
                condition = compoundBoolExpr;
            }
            return(condition);
        }
Example #3
0
        private static void extractVarFromBasicGuards(KPsystem kpSystem, MType kpType, Module module, BasicGuard basicGuard)
        {
            Multiset ms = basicGuard.Multiset;

            NuSMV.RelationalOperator oper = SMVUtil.getRelationalOperator(basicGuard.Operator);
            Variable variable             = null;

            foreach (var varName in ms.Objects)
            {
                if (!module.isVariableExist(varName))
                {
                    variable = new Variable(varName);
                    int upperBound = ms[varName];
                    //if the guard requires a number greater, or greaterEqual, then it upperbound should be at least one number greater then,
                    //the condition
                    if (oper.Operator == NuSMV.RelationalOperator.GEQ || oper.Operator == NuSMV.RelationalOperator.GT)
                    {
                        upperBound = upperBound + 1;
                    }
                    variable.Type = new BoundInt(0, upperBound);
                    setBoundIntType(kpSystem, kpType, module, variable);
                    variable.Behaviour = VariableBehaviour.REWRITING;
                    variable.Init      = setOrUpdateInit(module, variable);
                    module.Variables.Add(variable);
                }
            }
        }
Example #4
0
 private static void addChildSMVInstance(Module module, Instance parentSMVInstance, ChildInstance childSmvInstance)
 {
     childSmvInstance.ConnectedTo = parentSMVInstance.ConnectedTo;
     //build cross relation
     foreach (var target in parentSMVInstance.ConnectedTo)
     {
         //if it is not added already, then add
         if (!target.ConnectedTo.Contains(childSmvInstance))
         {
             target.ConnectedTo.Add(childSmvInstance);
         }
     }
     childSmvInstance.DivisionType = DIVISIONTYPE.CHILD;
     childSmvInstance.Module       = parentSMVInstance.Module;
     childSmvInstance.Name         = SMVUtil.generateAnInstanceName(childSmvInstance);
     foreach (var parameter in parentSMVInstance.Parameters)
     {
         if (parameter is ParameterVar)
         {
             ParameterVar childParam  = new ParameterVar();
             ParameterVar parentParam = (ParameterVar)parameter;
             // if status variable, set NONEXIST
             if (parentParam.Behaviour == VariableBehaviour.CUSTOM)
             {
                 if (parentParam.Name == CustomVariables.STATUS)
                 {
                     childParam.Behaviour = parentParam.Behaviour;
                     childParam.Name      = parentParam.Name;
                     childParam.Init      = StatusStates.NONEXIST;
                 }
                 else if (parentParam.Name == CustomVariables.TURN)
                 {
                     childParam.Behaviour = parentParam.Behaviour;
                     childParam.Name      = parentParam.Name;
                     childParam.Init      = TurnStates.READY;
                 }
                 else if (parameter.Name == CustomVariables.SYNCH)
                 {
                     childParam = parentParam;
                 }
             }
             else
             //set remained parameters as zero
             {
                 childParam.Behaviour = parentParam.Behaviour;
                 childParam.Name      = parentParam.Name;
                 childParam.Init      = "0";
             }
             childSmvInstance.Parameters.Add(childParam);
         }
         else
         {
             //if there is something else just take as it is.
             childSmvInstance.Parameters.Add(parameter);
         }
     }
     module.ChildInstances.Add(childSmvInstance);
 }
Example #5
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);
        }
        /// <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);
        }
        private static void WriteVariables(Module module)
        {
            string op = SMVKeys.VAR + "\n";

            //define custom variables
            //status variable for all types
            op += TVariables.VariableDefinition(module.Status);
            op += TVariables.VariableDefinition(module.Turn);
            //if module has arb, seq or max strategies
            if (module.HasArbitraryStrategy || module.HasSequenceStrategy || module.HasMaxStrategy)
            {
                op += TVariables.VariableDefinition(module.Count);
            }
            if (module.HasConnection)
            {
                foreach (var connection in module.Connections)
                {
                    op += TVariables.VariableDefinition(connection);
                }
            }
            //execution strategy variables, e.g. choice
            foreach (var strategy in module.ExecutionStrategies)
            {
                foreach (var variable in strategy.CustomVars)
                {
                    op += TVariables.VariableDefinition(variable);
                }
            }
            // model variables
            //sort variables, then print
            module.Variables = SMVUtil.sortVariable(module.Variables);
            foreach (var variable in module.Variables)
            {
                op += "\t" + TVariables.VariableDefinition(variable);
            }
            Writer.WriteLine(op);
        }