/// <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; }
/// <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); }
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); } } }
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; }
/// <summary> /// Extract condition from KP Rule, add condition to the next of variable. Rule behaviour are writing rules. /// </summary> /// <param name="variable"></param> /// <param name="kpRule"></param> /// <param name="module"></param> /// <param name="strategyIndex"></param> internal static void addCaseLineToStandardVariable(Variable variable, KpCore.Rule kpRule, Module module, int strategyIndex) { //for each variable generate a case line CaseLine caseLine = new CaseLine(); caseLine.Result = getResultOfRuleFromKPRule(module, kpRule, variable); caseLine.Rule = extractStandardRuleFromKPRule(kpRule, module, strategyIndex); caseLine.Rule.ID = kpRule.Id; //if result is division or dissolution it will be null if (caseLine.Result != null) { caseLine.Rule.AddBoolExpression(getBoundCondition(variable, caseLine.Result), BinaryOperator.AND); } else { throw new Exception("BRulesStandarVar, line 176"); // caseLine.Result = new Expression(variable.Name); } ICondition statusCondition = getTurnCondition(module, strategyIndex); ICondition sequenceCondition = getSequenceCondition(module, strategyIndex, kpRule.Id); CompoundBoolExpression statusAndTurn = new CompoundBoolExpression(statusCondition, BinaryOperator.AND, sequenceCondition); caseLine.Rule.AddBoolExpression(statusAndTurn, BinaryOperator.AND); if (variable.Next != null) { if (!BRulesComVar.ruleExist(variable.Next, caseLine)) { variable.Next.addCaseLine(caseLine); } } }
private static Case buildSynchNext(SMVModel nuSMV) { Case newCase = new Case(); CaseLine caseLine = new CaseLine(); foreach (var module in nuSMV.Modules) { string next = SMVKeys.NEXT + "(" + module.Instance.Name + "." + CustomVariables.TURN + ")"; string ready = TurnStates.READY; caseLine.Rule.AppendBoolExpression(new BoolExp(next, NuSMV.RelationalOperator.EQUAL, ready), BinaryOperator.AND); if (module.HasDivisionRule) { foreach (var childIntstance in module.ChildInstances) { next = SMVKeys.NEXT + "(" + childIntstance.Name + "." + CustomVariables.TURN + ")"; ready = TurnStates.READY; caseLine.Rule.AppendBoolExpression(new BoolExp(next, NuSMV.RelationalOperator.EQUAL, ready), BinaryOperator.AND); } } } caseLine.Result = new Expression(SynchStates.EXCHANGE); newCase.CaseLines.Add(caseLine); newCase.CaseLines.Add(BRulesStandardVar.trueCaseLine(SynchStates.BUSY)); return(newCase); }
/// <summary> /// return the last caseline which is TRUE : result /// </summary> /// <param name="result"></param> /// <returns></returns> public static CaseLine trueCaseLine(string result) { CaseLine caseLine = new CaseLine(); NuSMV.Rule rule = new NuSMV.Rule(); rule.Condition = new TruthValue(Truth.TRUE); Expression exp = new Expression(result); caseLine.Rule = rule; caseLine.Result = exp; return(caseLine); }
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); }
public static bool ruleExist(Next next, CaseLine caseLine) { bool exist = false; string caseline1 = caseLine.ToString(); foreach (var line in next.CaseStatement.CaseLines) { string caseline2 = line.ToString(); if (caseline1 == caseline2) { exist = true; break; } } return(exist); }
private static void assignStatusAndSyncToAVariable(Module module, IVar variable) { if (variable is Variable) { CaseLine caseLine = new CaseLine(); Variable var = (Variable)variable; String exchangeState = SynchStates.EXCHANGE; //For Copy variables inside module if (var.Origin == VariableOrigin.Copy || var.Origin == VariableOrigin.CopyOfCommVar) { Expression result = new Expression("0"); caseLine.Rule.Condition = getStatusAndSynchCondition(module, exchangeState); caseLine.Result = result; var.Next.CaseStatement.CaseLines.Add(caseLine); } //For Original variables inside module else if (var.Origin == VariableOrigin.Original && var.Behaviour != VariableBehaviour.COMMUNICATION) { //if it has copy var, then add var + var_cp if (module.isVariableExist(SMVPreFix.getCopyName(var))) { OperExp result = new OperExp(); result.Exp = variable.Name; result.Oper.Value = MathOper.ADD; //if variable is a division variable, then it has go to main part, like comm vars, so it will be instanced. if (var.Behaviour == VariableBehaviour.DIVISION) { result.Result = new InstancedExp(variable.Name + SMVPreFix.COPY); } else { result.Result = new Expression(variable.Name + SMVPreFix.COPY); } ICondition boundCondition = getBoundCondition(var, result); caseLine.Rule.Condition = new CompoundBoolExpression(getStatusAndSynchCondition(module, exchangeState), BinaryOperator.AND, boundCondition); caseLine.Result = result; var.Next.CaseStatement.CaseLines.Add(caseLine); } } //for communication variables, goes into main module. else if (var.Origin == VariableOrigin.OriginalCommVar && var.Behaviour == VariableBehaviour.COMMUNICATION) { CaseLine commCaseLine = assignStatusAndSyncToACommVariable(module, var); var.Next.CaseStatement.CaseLines.Add(commCaseLine); } } }
private static void assingTRUECaseToStandardVariables(Module module) { //add status variable if (module.Status != null) { Variable status = module.Status; status.Next.CaseStatement.CaseLines.Add(trueCaseLine(status)); } //add standard variables foreach (var variable in module.Variables) { if (variable is Variable) { Variable newVar = (Variable)variable; CaseLine caseLine = trueCaseLine(variable); newVar.Next.CaseStatement.CaseLines.Add(caseLine); } } }
/// <summary> /// ((_status = _DISSOLVED) | (_status = _DIVIDED)) /// </summary> /// <param name="module"></param> /// <returns></returns> private static ICondition getDissolvedOrDivided(Module module) { CaseLine caseLine = new CaseLine(); ICondition dissolved = null; ICondition divided = null; ICondition dissolvedOrDivided = null; if (module.HasDissolutionRule) { dissolved = getStatusCondition(module, StatusStates.DISSOLVED); } if (module.HasDivisionRule) { divided = getStatusCondition(module, StatusStates.DIVIDED); } dissolvedOrDivided = new CompoundBoolExpression(dissolved, BinaryOperator.OR, divided); return(dissolvedOrDivided); }
private static CaseLine assignStatusAndSyncToACommVariable(Module module, Variable variable) { CaseLine commCaseLine = new CaseLine(); OperExp result = new OperExp(); result.Exp = new InstancedExp(module.Instance.Name, variable.Name).ToString(); result.Oper.Value = MathOper.ADD; //if it has copy var, then add var + var_cp string res = ""; if (module.isVariableExist(SMVPreFix.getCopyName(variable))) { res += new InstancedExp(module.Instance.Name, SMVPreFix.getCopyName(variable)); } foreach (var connectedInstance in module.Instance.ConnectedTo) { if (connectedInstance.Module.isVariableExist(SMVPreFix.getConnectedCopyCommVarName(variable, module))) { if (!string.IsNullOrWhiteSpace(res)) { res += " + "; } res += new InstancedExp(connectedInstance.Name, SMVPreFix.getConnectedCopyCommVarName(variable, module)); } } result.Result = new Expression(res); //(c1.status = _ACTIVE) CompoundBoolExpression statusAndSync = getInstancedStatusAndSyncCondition(module); ICondition boundCondition = getBoundCondition(variable, result); ICondition compound = new CompoundBoolExpression(statusAndSync, BinaryOperator.AND, boundCondition); CommunicationRule rule = new CommunicationRule(); rule.Condition = compound; //commCaseLine.Rule.Condition = compound; commCaseLine.Rule = rule; commCaseLine.Result = result; return(commCaseLine); }
private static CaseLine trueCaseLine(IVar variable) { CaseLine caseLine = new CaseLine(); NuSMV.Rule rule = new NuSMV.Rule(); rule.Condition = new TruthValue(Truth.TRUE); IExp exp = null; if (variable.Behaviour == VariableBehaviour.COMMUNICATION || variable.Behaviour == VariableBehaviour.DIVISION) { exp = new InstancedExp(variable.Name); } else { exp = new Expression(variable.Name); } caseLine.Rule = rule; caseLine.Result = exp; return(caseLine); }
/// <summary> /// if dissolved, then variable is zero status = dissolved : 0; /// </summary> /// <param name="module"></param> private static void assignDissolvesAndDivides(Module module) { //add standard variables foreach (var iVar in module.Variables) { if (iVar is Variable) { Variable variable = (Variable)iVar; Expression result = new Expression("0"); CaseLine caseLine1 = new CaseLine(); //(((_status = _willDISSOLVE) | (_status = _willDIVIDE)) & (_sync = _EXCH)) : 0; caseLine1.Rule.Condition = getWillDissolveOrWillDivideAndSync(module); caseLine1.Result = result; variable.Next.CaseStatement.CaseLines.Add(caseLine1); CaseLine caseLine2 = new CaseLine(); //((_status = _DISSOLVED) | (_status = _DIVIDED)) : 0; caseLine2.Rule.Condition = getDissolvedOrDivided(module); caseLine2.Result = result; variable.Next.CaseStatement.CaseLines.Add(caseLine2); } } }
/// <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); }
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); } }