Esempio n. 1
0
        private static void buildDissolutionVariables(KPsystem kpSystem, KpCore.MType type, NuSMV.Module module, int strategyIndex, KpCore.Rule rule)
        {
            //Preserve variable value and update status value.
            DissolutionRule dissolutionRule = (DissolutionRule)rule;

            foreach (var leftHRule in dissolutionRule.Lhs)
            {
                Variable variable = new Variable(leftHRule.Key);
                if (!module.Variables.Contains(variable))
                {
                    variable.Type      = new BoundInt(0, setMax(kpSystem, type, module, variable));
                    variable.Behaviour = VariableBehaviour.REWRITING;
                    variable.Init      = setOrUpdateInit(module, variable);
                    module.Variables.Add(variable);
                }
                else
                {
                    //if variable exists then update the upperbound value.
                    variable = (Variable)module.Variables.First(item => item.Name.Equals(leftHRule.Key));
                }
                //add result of rule to caseline
                BRulesStandardVar.addCaseLineToStandardVariable(variable, rule, module, strategyIndex);
            }
            // add rule to status variable
            BRulesCustomVar.addRuleToStatusVariable(rule, module, strategyIndex);
        }
Esempio n. 2
0
        private static void buildDivisionVariables(NuSMV.Module module, KPsystem kpSystem, KpCore.MType type, int strategyIndex, KpCore.Rule rule)
        {
            DivisionRule divisionRule = (DivisionRule)rule;

            foreach (var leftHRule in divisionRule.Lhs)
            {
                Variable variable = new Variable(leftHRule.Key);
                if (!module.Variables.Contains(variable))
                {
                    variable.Type      = new BoundInt(0, setMax(kpSystem, type, module, variable));
                    variable.Behaviour = VariableBehaviour.REWRITING;
                    variable.Init      = setOrUpdateInit(module, variable);
                    module.Variables.Add(variable);
                }
                else
                {
                    //if variable exists then update the upperbound value.
                    variable = (Variable)module.Variables.First(item => item.Name.Equals(leftHRule.Key));
                }
                //add result of rule to caseline
                BRulesStandardVar.addCaseLineToStandardVariable(variable, rule, module, strategyIndex);
            }

            foreach (InstanceBlueprint compartment in divisionRule.Rhs)
            {
                MType compType = compartment.Type;
                if (type.Name.Equals(compType.Name))
                {
                    Multiset ms = compartment.Multiset;
                    foreach (var obj in ms.Objects)
                    {
                        Variable variable = new Variable(obj);
                        if (!module.Variables.Contains(variable))
                        {
                            variable.Type      = new BoundInt(0, setMax(kpSystem, compType, module, variable));
                            variable.Behaviour = VariableBehaviour.DIVISION;
                            variable.Init      = setOrUpdateInit(module, variable);
                            module.Variables.Add(variable);
                        }
                        else
                        {
                            variable           = (Variable)module.Variables.First(item => item.Name.Equals(obj));
                            variable.Behaviour = VariableBehaviour.DIVISION;
                        }
                    }
                }
            }
            // add rule to status variable
            BRulesCustomVar.addRuleToStatusVariable(rule, module, strategyIndex);
        }
Esempio n. 3
0
        private static void buildReWritingVariable(KPsystem kpSystem, KpCore.MType kpType, NuSMV.Module module, int strategyIndex, KpCore.Rule kpRule, string newVarName, VariableOrigin origin, bool isLeft)
        {
            Variable newVar = null;

            //if variable does not exist then create it,
            if (!module.isVariableExist(newVarName))
            {
                if (origin == VariableOrigin.Original)
                {
                    newVar = new Variable(newVarName);
                    setBoundIntType(kpSystem, kpType, module, newVar);
                    newVar.Behaviour = VariableBehaviour.REWRITING;
                    newVar.Init      = setOrUpdateInit(module, newVar);
                    newVar.Origin    = VariableOrigin.Original;
                    if (isLeft)
                    {
                        //if it is on left then add it, but do not add rules to first not-copy variable on right.
                        BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex);
                    }
                }
                else if (origin == VariableOrigin.Copy)
                {
                    newVar = new Variable(newVarName);
                    Variable orginalVariable = (Variable)module.getVariable(newVarName.Replace(SMVPreFix.COPY, ""));
                    newVar.Type      = orginalVariable.Type;
                    newVar.Behaviour = VariableBehaviour.REWRITING;
                    newVar.Init      = "0";
                    newVar.Origin    = VariableOrigin.Copy;
                    //add result of rule to caseline
                    BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex);
                }
                if (newVar != null)
                {
                    module.Variables.Add(newVar);
                }
                else
                {
                    throw new Exception("Cannot create variable : " + newVarName);
                }
            }
            else
            {
                //bring variable to add new rules.
                newVar = (Variable)module.Variables.First(item => item.Name.Equals(newVarName));
                BRulesStandardVar.addCaseLineToStandardVariable(newVar, kpRule, module, strategyIndex);
            }
        }