Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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));
        }