private void Build() { a = new Alphabet(); allInstances = new HashSet <MInstance>(); instanceTypes = new Dictionary <MInstance, MType>(); idMap = new KpIdMap(kp); growthPerType = new int[kp.Types.Count]; foreach (MType mtype in kp.Types) { foreach (MInstance instance in mtype.Instances) { registerSymbols(instance.Multiset); allInstances.Add(instance); instanceTypes.Add(instance, mtype); } ExecutionStrategy ex = mtype.ExecutionStrategy; while (ex != null) { foreach (Rule r in ex.Rules) { if (r is ConsumerRule) { registerSymbols((r as ConsumerRule).Lhs); if (r.Type == RuleType.MULTISET_REWRITING) { registerSymbols((r as RewritingRule).Rhs); } else if (r.Type == RuleType.REWRITE_COMMUNICATION) { RewriteCommunicationRule rcr = r as RewriteCommunicationRule; registerSymbols(rcr.Rhs); foreach (TargetedMultiset tm in rcr.TargetRhs.Values) { registerSymbols(tm.Multiset); } HasCommunication = true; } else if (r.Type == RuleType.LINK_CREATION) { HasLinkCreation = true; } else if (r.Type == RuleType.LINK_DESTRUCTION) { HasLinkDestruction = true; } else if (r.Type == RuleType.MEMBRANE_DIVISION) { HasDivision = true; foreach (InstanceBlueprint ib in (r as DivisionRule).Rhs) { registerSymbols(ib.Multiset); growthPerType[ib.Type.Id]++; } } else if (r.Type == RuleType.MEMBRANE_DISSOLUTION) { HasDissolution = true; } if (r.IsGuarded) { registerSymbols(r.Guard); } } } ex = ex.Next; } } }
static int Main(string[] args) { if (args == null || args.Length == 0 || String.Compare(args[0], "usage", true) == 0 || args[0] == "?" || String.Compare(args[0], "help", true) == 0 || String.Compare(args[0], "info", true) == 0) { PrintUsage(); return(1); } int argIndex = 0; if (!args[argIndex].StartsWith("-") || args[argIndex] == "-s") { //simulation KpSimulationParams ksp = KpSimulationParams.Default(); PropertyInfo[] kspProperties = typeof(KpSimulationParams).GetProperties(); if (args[argIndex] == "-s") { ++argIndex; } string srcFileName = args[argIndex]; FileInfo fi = new FileInfo(srcFileName); if (!fi.Exists) { Console.WriteLine("File '{0}' does not exist. Please specify a valid input file.", srcFileName); return(1); } string outFileName = null; KpModel kpModel = null; try { kpModel = KP.FromKpl(srcFileName); } catch (Exception ex) { Console.WriteLine("Parsing failed. Source: {0}", srcFileName); Console.WriteLine(ex.Message); return(1); } for (int i = ++argIndex; i < args.Length; i++) { if (args[i] == "-o") { if (++i < args.Length) { outFileName = args[i]; } } else { string arg = args[i]; int eqIndex = arg.IndexOf('='); if (eqIndex > 0) { string prop = arg.Substring(0, eqIndex); string val = arg.Substring(eqIndex + 1); bool propertyRecognized = false; foreach (PropertyInfo kspProp in kspProperties) { if (kspProp.Name == prop) { try { if (kspProp.PropertyType == typeof(Int32)) { kspProp.SetValue(ksp, Int32.Parse(val)); } else if (kspProp.PropertyType == typeof(bool)) { kspProp.SetValue(ksp, bool.Parse(val)); } else { kspProp.SetValue(ksp, val); } } catch { Console.WriteLine("*** Warning. Invalid format for property {0}: value must be of type {1}", kspProp.Name, kspProp.PropertyType.ToString()); } propertyRecognized = true; break; } } if (!propertyRecognized) { Console.WriteLine("*** Warning. Property {0} not recognized.", prop); } } } } KpIdMap idMap = new KpIdMap(kpModel.KPsystem); KpSimulator simulator = new KpSimulator(ksp); //make sure newly created instances are accounted for in the idMap //for simulators, this must always be the first handler registered since it will assign //a valid Id to the instance, and id which is referred to in the Simulation interpreter simulator.RegisterNewInstance = idMap.RegisterNewInstance; TextWriter writer = outFileName == null ? Console.Out : new StreamWriter(outFileName); SimulationTextWriter textWriter = new SimulationTextWriter(writer); textWriter.BindToSimulator(simulator); simulator.Run(kpModel.KPsystem); return(0); } if (args[argIndex] == "-spin") { try { //PerformPromelaTranslation(args); PerformImprovedPromelaTranslation(args); } catch (Exception exception) { Console.WriteLine(exception.Message); } } if (args[argIndex] == "-smv") { try { PerformNuSmvTransation(args); } catch (Exception exception) { Console.WriteLine(exception.Message); } } if (args[argIndex] == "-flame") { try { PerformFlameTransation(args); } catch (Exception exception) { Console.WriteLine(exception.Message); } } return(0); }