public KPsystemXMLWriter(KPsystem kp) { kPsystem = kp; model = new Model(); agentsInitial = new AgentsInitialConfiguration(); objectsId = new ObjectsId(); typeId = new Dictionary <string, int>(); membraneId = new MembraneId(); membranes = new Membranes(objectsId); FlameRulesGenerator flameRulesGenerator = new FlameRulesGenerator(objectsId, membraneId); FlameCodeRulesGenerator flameCodeRulesGenerator = new FlameCodeRulesGenerator(objectsId, membraneId); foreach (MType mType in kPsystem.Types) { typeId.Add(mType.Name, typeId.Count); membranes.AddMembraneType(mType); model.AddAgent(new Agent(mType, typeId[mType.Name], flameCodeRulesGenerator)); Console.WriteLine(mType.Name); } foreach (MType mType in kPsystem.Types) { AgentMembrane agentMembrane = new AgentMembrane(); agentMembrane.Name = mType.Name; agentMembrane.Id = membraneId[mType.Name].ToString(); List <int> list = flameCodeRulesGenerator.Rules(mType.ExecutionStrategy); foreach (MInstance mInstance in mType.Instances) { agentMembrane.AddInstance(flameRulesGenerator.Multiset(mInstance.Multiset), mInstance, membranes, membraneId); } agentsInitial.AddMembrane(agentMembrane); } }
public FlameCodeRulesGenerator(ObjectsId objectsId, MembraneId membraneId) { this.objectsId = objectsId; this.membraneId = membraneId; }
public void AddInstance(string multiset, MInstance mInstance, Membranes membranes, MembraneId membraneId) { List <InstanceIds> connections = new List <InstanceIds>(); Dictionary <int, InstanceIds> connectionsMap = new Dictionary <int, InstanceIds>(); foreach (MInstance m in mInstance.Connections) { KeyValuePair <string, int> key = membranes[m]; int id = membraneId[key.Key]; if (connectionsMap.ContainsKey(id)) { connectionsMap[id].Add(key.Value); } else { connections.Add(new InstanceIds(id)); connectionsMap.Add(id, connections[connections.Count - 1]); connectionsMap[id].Add(key.Value); } } instances.Add(new Instance(this, membranes[mInstance].Value, multiset, connections)); }