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 Agent(MType membraneType, int typeId, FlameCodeRulesGenerator rulesGenerator) { this.membraneType = membraneType; this.TypeId = typeId; Name = membraneType.Name; Description = Name; RulesNumber = 0; functions = new List <Function>(); Strategy(membraneType.ExecutionStrategy, rulesGenerator); }
private void Strategy(ExecutionStrategy executionStrategy, FlameCodeRulesGenerator rulesGenerator) { Dictionary <StrategyOperator, int> strategyNumber = new Dictionary <StrategyOperator, int>(); StrategyNumberCreate(strategyNumber); Function function = new Function(Name, JoinStrings(Name, "show"), JoinStrings(Name, "show"), JoinStrings(Name, "start")); AddFunction(function); function = new Function(Name, JoinStrings(Name, "initialization"), JoinStrings(Name, "start"), JoinStrings(Name, "initialization")); function.Condition = new Condition("a.structure_rule", Condition.RelationalOperators.EQ, "-1"); AddFunction(function); function = new Function(Name, "idle", JoinStrings(Name, "start"), JoinStrings(Name, "end")); function.Condition = new Condition("a.structure_rule", Condition.RelationalOperators.NEQ, "-1"); AddFunction(function); int ruleNumber = 0; string previousState = JoinStrings(Name, "initialization"); string functionName = ""; string currentState = ""; string nextState = ""; bool b = false; ExecutionStrategy strategy = membraneType.ExecutionStrategy; while (strategy != null) { RulesNumber += strategy.Rules.Count; strategyNumber[strategy.Operator]++; functionName = Name; currentState = previousState; StrategyFunction strategyFunction = new StrategyFunction(Name, Name, currentState, nextState, strategyNumber[strategy.Operator]); strategyFunction.StrategyType = strategy.Operator; strategyFunction.Rules = rulesGenerator.Rules(strategy); strategyFunction.Guards = rulesGenerator.Guards(strategy); if (strategy.Next != null) { nextState = strategyFunction.Name; strategyFunction.NextState = nextState; } else { nextState = JoinStrings(Name, "execution_completed"); strategyFunction.NextState = nextState; } strategyFunction.Add(ruleNumber, strategy.Rules.Count); ruleNumber += strategy.Rules.Count; strategyFunction.Outputs = new Outputs(); strategyFunction.Outputs.AddMessage("msgSendObject"); if (b) { strategyFunction.Condition = new Condition("a.stop", Condition.RelationalOperators.EQ, "0"); AddFunction(strategyFunction); function = new Function(Name, "idle", currentState, JoinStrings(Name, "execution_completed")); function.Condition = new Condition("a.stop", Condition.RelationalOperators.NEQ, "0"); AddFunction(function); } else { AddFunction(strategyFunction); } previousState = nextState; b = true; strategy = strategy.Next; } function = new Function(Name, JoinStrings(Name, "PrepareTheNewMembrane"), JoinStrings(Name, "execution_completed"), JoinStrings(Name, "prepare_the_new_membrane")); function.Condition = new Condition("a.rule_type_selected", Condition.RelationalOperators.EQ, "2"); function.Outputs = new Outputs(); function.Outputs.AddMessage("msgRequestId"); AddFunction(function); function = new Function(Name, JoinStrings(Name, "CreateNewMembrane"), JoinStrings(Name, "prepare_the_new_membrane"), JoinStrings(Name, "remove_membrane")); function.Inputs = new Inputs(); function.Inputs.AddMessage("msgReceiveId"); function.Inputs.Messages[0].AddCondition(new Condition(Condition.LogicOperators.AND, TypeId.ToString(), Condition.RelationalOperators.EQ, "m.type_id")); function.Inputs.Messages[0].AddCondition(new Condition("a.instanceId", Condition.RelationalOperators.EQ, "m.instance_id")); AddFunction(function); function = new Function(Name, JoinStrings(Name, "removeMembrane"), JoinStrings(Name, "remove_membrane"), JoinStrings(Name, "applyChanges")); AddFunction(function); function = new Function(Name, "idle", JoinStrings(Name, "execution_completed"), JoinStrings(Name, "remove_membrane")); function.Condition = new Condition("a.rule_type_selected", Condition.RelationalOperators.EQ, "3"); AddFunction(function); function = new Function(Name, "idle", JoinStrings(Name, "execution_completed"), JoinStrings(Name, "applyChanges")); function.Condition = new Condition("a.rule_type_selected", Condition.RelationalOperators.LEQ, "1"); AddFunction(function); function = new Function(Name, JoinStrings(Name, "applyChanges"), JoinStrings(Name, "applyChanges"), JoinStrings(Name, "receive")); AddFunction(function); function = new Function(Name, JoinStrings(Name, "receive"), JoinStrings(Name, "receive"), JoinStrings(Name, "end")); function.Inputs = new Inputs(); function.Inputs.AddMessage("msgSendObject"); function.Inputs.Messages[0].AddCondition(new Condition(Condition.LogicOperators.AND, "a.id", Condition.RelationalOperators.EQ, "m.idTo")); function.Inputs.Messages[0].AddCondition(new Condition("a.instanceId", Condition.RelationalOperators.EQ, "m.instanceIdTo")); AddFunction(function); }