private static void WriteNext(Module module) { string op = ""; //write turn op += TVariables.VariableNext(module.Turn); //if there is arb, seq or max strategy if (module.HasArbitraryStrategy || module.HasSequenceStrategy || module.HasMaxStrategy) { op += TVariables.VariableNext(module.Count); } //execution strategy variables, e.g. choice foreach (var strategy in module.ExecutionStrategies) { foreach (var variable in strategy.CustomVars) { op += TVariables.VariableNext(variable); } } // model variables foreach (var variable in module.Variables) { if (variable.Behaviour == VariableBehaviour.REWRITING) { op += TVariables.VariableNext(variable); } } Writer.WriteLine(op); }
private static void WriteStatusAndCommuncationNext(SMVModel nuSMV) { string op = ""; //write instances foreach (var module in nuSMV.Modules) { Instance instance = module.Instance; //write parent instances... if (instance is ParentInstance) { op += TVariables.WriteStatusNextWithInstance(module, instance); op += TVariables.WriteParentDivisionVariableNext(module, instance as ParentInstance); } else if (instance is ChildInstance) { //Print status rules of each child instance op += TVariables.WriteChildStatusNext(module, instance as ChildInstance); op += TVariables.WriteChildDivisionVariablesNext(instance as ChildInstance); } foreach (var variable in module.Variables) { if (variable.Behaviour == VariableBehaviour.COMMUNICATION) { op += TVariables.CommunicationVariableNext(module, instance, variable); } } } Writer.WriteLine(op); }
private static void WriteInit(Module module) { string op = SMVKeys.ASSIGN + "\n"; if (module.HasDivisionRule || module.HasDissolutionRule) { op += TVariables.InitVariable(module.Status); } op += TVariables.InitVariable(module.Turn); if (module.HasArbitraryStrategy || module.HasSequenceStrategy || module.HasMaxStrategy) { op += TVariables.InitVariable(module.Count); } //execution strategy variables, e.g. choice int strategyIndex = 0; foreach (var strategy in module.ExecutionStrategies) { foreach (var variable in strategy.CustomVars) { op += TVariables.InitVariable(variable); } strategyIndex++; } // model variables foreach (var variable in module.Variables) { op += TVariables.InitVariable(variable); } Writer.WriteLine(op); }
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); }
internal static string WriteStatusNextWithInstance(NuSMV.Module module, Instance instance) { string op = ""; Variable status = module.Status; op = "next (" + instance.Name + "." + module.Status.Name + ") := case\n"; foreach (var caseLine in status.Next.CaseStatement.CaseLines) { // CaseLine newcaseLine = new CaseLine(); if (!(caseLine.Rule is CommunicationRule)) { string temp = ""; temp += TVariables.insertInstanceName(caseLine.Rule.Condition, instance); temp += " : "; // for last true case if (caseLine.Rule.Condition is TruthValue) { temp += instance.Name + "." + caseLine.Result; } else { temp += caseLine.Result; } temp += ";\n"; op += temp; } } op += "esac;\n"; return(op); }
private static void WriteStatusNext(Module module) { string op = ""; if (!module.HasDivisionRule) { op += TVariables.VariableNext(module.Status); } Writer.WriteLine(op); }
/// <summary> /// Print status rules of each child instance /// </summary> internal static string WriteChildStatusNext(NuSMV.Module module, ChildInstance childInstance) { string op = ""; Variable status = childInstance.DivisionStatus; op = "next (" + childInstance.Name + "." + status.Name + ") := case\n"; bool firstRule = true;// first rule related with parent, so, its rule shouldn't be named with child instances foreach (var caseLine in status.Next.CaseStatement.CaseLines) { string temp = ""; if (!firstRule) { // add child name as prefix temp += TVariables.insertInstanceName(caseLine.Rule.Condition, childInstance); } else { temp += caseLine.Rule.Condition; firstRule = false; } temp += " : "; // for last true case if (caseLine.Rule.Condition is TruthValue) { temp += childInstance.Name + "." + caseLine.Result; } else { temp += caseLine.Result; } temp += ";\n"; op += temp; } op += "esac;\n"; return(op); }
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); }
private static void WriteMain(SMVModel nuSMV) { TUtil.AddDashedComment("MAIN"); string op = SMVKeys.MODULE + " " + SMVKeys.MAIN + "\n"; op += SMVKeys.VAR + "\n"; //write synch,and PStep vars at first. op += TVariables.VariableDefinition(nuSMV.MainModule.Synch); op += TVariables.VariableDefinition(nuSMV.MainModule.PStep); //write instances foreach (var module in nuSMV.Modules) { //parent instance op += TVariables.Instances(module.Instance); //if exists, then child instances if (module.HasDivisionRule) { foreach (var childInstance in module.ChildInstances) { op += TVariables.Instances(childInstance); } } } op += SMVKeys.ASSIGN + "\n"; //write init of synch and PStep vars op += TVariables.InitVariable(nuSMV.MainModule.Synch); op += TVariables.InitVariable(nuSMV.MainModule.PStep); //write next of synch and PStep vars op += TVariables.VariableNext(nuSMV.MainModule.Synch); op += TVariables.VariableNext(nuSMV.MainModule.PStep); Writer.WriteLine(op); }