Esempio n. 1
0
        internal static string WriteParentDivisionVariableNext(NuSMV.Module module, ParentInstance parentInstance)
        {
            string op = "";

            foreach (var variable in module.Variables)
            {
                if (variable.Behaviour == VariableBehaviour.DIVISION)
                {
                    op += "next (" + parentInstance.Name + "." + variable.Name + ") := case\n";
                    foreach (var caseLine in (variable as Variable).Next.CaseStatement.CaseLines)
                    {
                        string temp = "\t";
                        temp += TVariables.insertInstanceName(caseLine.Rule.Condition, parentInstance);
                        temp += " : ";
                        temp += insertInstanceName2Expression(caseLine.Result, parentInstance);
                        //if (caseLine.Result is InstancedExp)
                        //    temp += parentInstance.Name + "." + caseLine.Result;
                        //else if (caseLine.Result is Expression)
                        //    temp += caseLine.Result;

                        temp += ";\n";
                        op   += temp;
                    }
                    op += "esac;\n";
                }
            }
            return(op);
        }
Esempio n. 2
0
        private static void getRulePermutation(ParentInstance parentInstance, List <KpCore.Rule> divisionRules, int ruleCount, List <InstanceBlueprint> result)
        {
            if (ruleCount == divisionRules.Count)
            {
                formDivisionInstance(parentInstance, divisionRules, result);
                return;
            }
            DivisionRule divisionRule = (DivisionRule)divisionRules.ElementAt(ruleCount);
            int          compartCount = divisionRule.Rhs.Count;

            ruleCount++;
            for (int j = 0; j < compartCount; j++)
            {
                InstanceBlueprint compartment = divisionRule.Rhs.ElementAt(j);
                int index = ruleCount - 1;
                if (result.Count < ruleCount)
                {
                    result.Insert(index, compartment);
                }
                else
                {
                    result.RemoveAt(index);
                    result.Insert(index, compartment);
                }
                getRulePermutation(parentInstance, divisionRules, ruleCount, result);
            }
        }
Esempio n. 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;
        }
Esempio n. 4
0
        public static void generateDivisionRules(MType type, Module paramModule)
        {
            if (paramModule != null)
            {
                module = paramModule;
            }
            //get all division rules
            List <KpCore.Rule> divisionRules = new List <KpCore.Rule>();
            ExecutionStrategy  eS            = type.ExecutionStrategy;

            while (eS != null)
            {
                foreach (var rule in eS.Rules)
                {
                    if (rule.Type == RuleType.MEMBRANE_DIVISION)
                    {
                        divisionRules.Add(rule);
                    }
                }
                eS = eS.Next;
            }
            if (divisionRules.Count > 0)
            {
                //or each parent instance, generate a permutation of rules.
                ParentInstance parentInstance = null;
                Instance       smvInstance    = module.Instance;
                if (smvInstance.DivisionType == DIVISIONTYPE.PARENT)
                {
                    parentInstance = (ParentInstance)smvInstance;
                    generateDivisionInstances(parentInstance, divisionRules);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// For each MInstance (KP instance) generate a SMV instance.
        /// </summary>
        /// <param name="nuSMV"></param>
        /// <param name="module"></param>
        /// <param name="type"></param>
        /// <param name="kpInstance"></param>
        public static void generateSMVInstances(SMVModel nuSMV, Module module, MType type, MInstance kpInstance)
        {
            Instance smvInstance = null;

            //If module has division rule then being child or parent becomes matter, otherwise they are default SMV instances
            if (module.HasDivisionRule)
            {
                //Define module behaviour based on whether the instance is a parent or a child
                //Status parameter, parents start in ACTIVE; child instances start in NONEXIST state
                ParameterVar statusParam = new ParameterVar();

                //A Child instance
                if (kpInstance is KPChildInstance)
                {
                    // generate SMV Child Instance
                    smvInstance = new ChildInstance();
                    smvInstance.DivisionType = DIVISIONTYPE.CHILD;

                    //Start Status parameter in NONEXISTS state
                    statusParam.Name      = CustomVariables.STATUS;
                    statusParam.Behaviour = VariableBehaviour.CUSTOM;
                    statusParam.Init      = StatusStates.NONEXIST;
                    smvInstance.Parameters.Add(statusParam);
                    //add this instance to its parent children
                    crossReferChild2ParentInstance(nuSMV, type, kpInstance, smvInstance as ChildInstance);
                }
                // A Parent instance
                else
                {
                    // generate SMV Parent Instance
                    smvInstance = new ParentInstance();
                    smvInstance.DivisionType = DIVISIONTYPE.PARENT;

                    //Start Status parameter in Active state
                    statusParam.Name      = CustomVariables.STATUS;
                    statusParam.Behaviour = VariableBehaviour.CUSTOM;
                    statusParam.Init      = StatusStates.ACTIVE;
                    smvInstance.Parameters.Add(statusParam);
                }
                //set parameter to module as well.
                module.Parameters.Add(statusParam);
            }
            //Default instance
            else
            {
                smvInstance = new Instance();
                smvInstance.DivisionType = DIVISIONTYPE.NODIVISION;
            }
            smvInstance.Name = kpInstance.Name;
            //join custom parameters, e.g., status, with model parameters
            smvInstance.Parameters.UnionWith(getInstanceParameters(module, type, kpInstance));
            //cross reference module and its instance
            smvInstance.Module = module;
            module.Instance    = smvInstance;
        }
Esempio n. 6
0
        private static void formDivisionInstance(ParentInstance parentInstance, List <KpCore.Rule> divisionRules, List <InstanceBlueprint> result)
        {
            MType         type             = result.ElementAt(0).Type;
            MInstance     instance         = new MInstance();
            ChildInstance childSmvInstance = new ChildInstance();

            addChildInstance2Module(type, instance, parentInstance, childSmvInstance);

            foreach (var variable in childSmvInstance.DivisionVariables)
            {
                int totalValue = getTotalAmountOfDivisionVar(variable, divisionRules, result);
                addRuleChildDivisionVariables(childSmvInstance, variable, totalValue);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Cross reference child instance to its parent, and vice versa
        /// </summary>
        /// <param name="type"></param>
        /// <param name="kpInstance"></param>
        private static void crossReferChild2ParentInstance(SMVModel nuSMV, MType type, MInstance kpInstance, ChildInstance childSMVInstance)
        {
            //Access its parent KP instance
            MInstance      parentKPInstance  = (kpInstance as KPChildInstance).ParentKPInstance;
            ParentInstance parentSMVInstance = getSMVInstance(nuSMV, parentKPInstance);

            if (childSMVInstance.ParentInstance == null)
            {
                childSMVInstance.ParentInstance = parentSMVInstance;
            }
            else
            {
                throw new Exception("Error: Cross reference error with child and parent SMV instance...");
            }
            if (!parentSMVInstance.ChildInstances.Contains(childSMVInstance))
            {
                parentSMVInstance.ChildInstances.Add(childSMVInstance);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Return SMV counterpart of given KP instance
        /// </summary>
        /// <param name="nuSMV"></param>
        /// <param name="parentKPInstance"></param>
        /// <returns></returns>
        private static ParentInstance getSMVInstance(SMVModel nuSMV, MInstance parentKPInstance)
        {
            ParentInstance parentSMVInstance = null;

            foreach (Module module in nuSMV.Modules)
            {
                if (module.Instance.Name.Equals(parentKPInstance.Name))
                {
                    if (module.Instance is ParentInstance)
                    {
                        parentSMVInstance = (ParentInstance)module.Instance;
                        break;
                    }
                }
            }
            if (parentSMVInstance == null)
            {
                throw new Exception("Error: KPInstance counterpart not found in any SMV modules!");
            }
            return(parentSMVInstance);
        }
Esempio n. 9
0
        private static void addChildInstance2Module(MType type, MInstance newInstance, ParentInstance parentInstance, ChildInstance childSmvInstance)
        {
            childSmvInstance.ParentInstance = parentInstance;
            parentInstance.ChildInstances.Add(childSmvInstance);

            addChildSMVInstance(module, parentInstance, childSmvInstance);

            addDivisionVariableToChildInstance(childSmvInstance);

            addStatusToChildInstance(parentInstance, childSmvInstance);
        }
Esempio n. 10
0
        private static void generateDivisionInstances(ParentInstance parentInstance, List <KpCore.Rule> divisionRules)
        {
            List <InstanceBlueprint> result = new List <InstanceBlueprint>();

            getRulePermutation(parentInstance, divisionRules, 0, result);
        }