/// <summary> /// It combines module instances with other, this should be done at the end, since all modules' instances should had /// been created /// </summary> /// <param name="kpType"></param> private static void buildInstanceConnections(MType kpType, MInstance kpInstance) { if (kpType != null) { Module module = nuSMV.getModule(kpType, kpInstance); module.Instance.ConnectedTo = BInstances.getInstanceConnections(nuSMV, kpSystem, kpInstance); } }
/// <summary> /// Get list of all connected instances to @param kpInstance as the list of SMV instances. /// </summary> /// <param name="nuSMV"></param> /// <param name="kPsystem"></param> /// <param name="kpInstance"></param> /// <returns></returns> public static List <Instance> getInstanceConnections(SMVModel nuSMV, KPsystem kPsystem, MInstance kpInstance) { List <Instance> smvInstances = new List <Instance>(); foreach (var connected in kpInstance.Connections) { MType targetType = findTargetTypeOfInstance(kPsystem, connected); Module targetModule = nuSMV.getModule(targetType, connected); Instance smvInstance = targetModule.Instance; if (smvInstance != null) { // if connection is not exist then add it if (!smvInstances.Exists(item => item.Name == smvInstance.Name)) { smvInstances.Add(smvInstance); } } else { throw new Exception("Corresponding SMV instance of " + connected.Name + " not found!"); } } return(smvInstances); }
public static SMVModel buildModel(KPsystem param_kpSystem) { kpSystem = param_kpSystem; if (kpSystem != null) { //set an id to each rules prepareKpSystem(kpSystem); nuSMV = new SMVModel(); try { //If there are division rules, generate child instances as kPInstance foreach (var kpType in kpSystem.Types) { if (kpTypeHasDivisionRule(kpType)) { List <KPChildInstance> kpChildInstances = BDivisionInstances.generateKPChildInstances(kpType); if (kpChildInstances != null) { kpType.Instances.AddRange(kpChildInstances); } } } //Generate a module for each kPInstance, including child instances(if division rule exist) foreach (var kpType in kpSystem.Types) { foreach (MInstance kpInstance in kpType.Instances) { Module module = new Module(); prepareSMVModule(module, kpType, kpInstance); nuSMV.Modules.Add(module); } } foreach (var kpType in kpSystem.Types) { foreach (MInstance kpInstance in kpType.Instances) { buildInstanceConnections(kpType, kpInstance); } } foreach (var kpType in kpSystem.Types) { foreach (MInstance kpInstance in kpType.Instances) { Module module = nuSMV.getModule(kpType, kpInstance); BVariables.generateCustomVariables(kpSystem, kpType, module); } } foreach (var kpType in kpSystem.Types) { foreach (MInstance kpInstance in kpType.Instances) { buildModule(kpType, kpInstance); } } if (nuSMV != null) { foreach (var kpType in kpSystem.Types) { foreach (MInstance kpInstance in kpType.Instances) { Module module = nuSMV.getModule(kpType, kpInstance); if (module.HasDivisionRule) { BDivisionInstances.generateDivisionRules(kpType, kpInstance, module); } } } } //assign cases for synch variable of main module. buildMain(nuSMV); //finalize model, add caseLast caselines, do modifications, sorting etc. assignLastCasesToNext(nuSMV); } catch (Exception ex) { throw ex; } } return(nuSMV); }