/// <summary> /// Translates parameter of MInstances to set of ParameterVars. Adds sync variable as parameter to all instances, /// i.e., modules. /// </summary> /// <param name="module"></param> /// <param name="type"></param> /// <param name="instance"></param> /// <returns></returns> public static HashSet <IVar> getInstanceParameters(Module module, MType type, MInstance instance) { HashSet <IVar> parameters = new HashSet <IVar>(); Multiset ms = instance.Multiset; bool paramExist = ms.Count > 0 || module.HasConnection; if (paramExist) { foreach (var param in ms.Objects) { ParameterVar parameter = new ParameterVar(); parameter.Name = param; parameter.Init = ms[param].ToString(); //get instance parameters parameters.Add(parameter); //set module parameters. module.Parameters.Add(parameter); } } //synch parameter ParameterVar synch = new ParameterVar(); synch.Behaviour = VariableBehaviour.CUSTOM; synch.Name = CustomVariables.SYNCH; synch.Init = CustomVariables.SYNCH; synch.IsParamPrefixed = false; //get instance parameters parameters.Add(synch); //set module parameters. module.Parameters.Add(synch); return(parameters); }
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); }
/// <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; }