public static void Translate(KpCore.KpModel kpModel, Experiment kpx, string outFileName)
        {
            KPsystem    kpSystem    = kpModel.KPsystem;
            KpMetaModel kpMetaModel = new KpMetaModel(kpSystem);

            try
            {
                //Translate KP model to SMV model
                SMVModel nuSMV = BNuSMV.buildModel(kpSystem);

                //SMVModels are loaded, in first run write variable to XML files, in 2nd run these values can be read.
                foreach (var module in nuSMV.Modules)
                {
                    BVariables.writeBounds2XML(module);
                }

                //Generate SMV file
                if (nuSMV != null)
                {
                    PrintNuSMV(nuSMV, kpMetaModel, kpx, outFileName);
                }
                else
                {
                    throw new Exception("NuSMV translation failed.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred during NuSMV translation.");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }
示例#2
0
 private static void buildModule(MType kpType, MInstance kpInstance)
 {
     if (kpType != null)
     {
         Module module = nuSMV.getModule(kpType, kpInstance);
         BStrategy.buildExecutionStrategies(module, kpType);
         //Extract variables and add next rules
         BVariables.buildVariables(kpSystem, nuSMV, module, kpType);
     }
 }
示例#3
0
        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);
        }