private List <AgentArchetype> ReadAgentArchetypes() { SkipUntilConfiguration("AgentArchetypeAttributes"); var archetypeName = new InputVar <string>("ArchetypeName"); var archetypePrefix = new InputVar <string>("ArchetypePrefix"); var dataSetOriented = new InputVar <bool>("DataSetOriented"); var goalImportanceAdjusting = new InputVar <bool>("GoalImportanceAdjusting"); var agentArchetypes = new List <AgentArchetype>(); while (!CurrentName.Equals("AgentArchetypeVariables")) { var currentLine = new StringReader(CurrentLine); var agentArchetype = new AgentArchetype(); ReadValue(archetypeName, currentLine); agentArchetype.ArchetypeName = archetypeName.Value; ReadValue(archetypePrefix, currentLine); agentArchetype.ArchetypePrefix = archetypePrefix.Value; ReadValue(dataSetOriented, currentLine); agentArchetype.DataSetOriented = dataSetOriented.Value; ReadValue(goalImportanceAdjusting, currentLine); agentArchetype.GoalImportanceAdjusting = goalImportanceAdjusting.Value; agentArchetypes.Add(agentArchetype); GetNextLine(); } return(agentArchetypes); }
/// <summary> /// Creates agent instance based on agent archetype and agent configuration. /// </summary> /// <param name="agentConfiguration"></param> /// <param name="archetype"></param> /// <returns></returns> public static SosielHarvestAgent Create( AgentStateConfiguration agentConfiguration, AgentArchetype archetype, string name) { var agent = new SosielHarvestAgent(); agent.Id = name; agent.Archetype = archetype; agent.privateVariables = new Dictionary <string, dynamic>(agentConfiguration.PrivateVariables); agent.AssignedDecisionOptions = archetype.DecisionOptions.Where( r => agentConfiguration.AssignedDecisionOptions.Contains(r.Name)).ToList(); agent.AssignedGoals = archetype.Goals.Where( g => agentConfiguration.AssignedGoals.Contains(g.Name)).ToList(); agent.AssignedDecisionOptions.ForEach( decisionOption => agent.DecisionOptionActivationFreshness.Add(decisionOption, 1)); // Generates goal importance. agentConfiguration.GoalStates.ForEach(kvp => { var goalName = kvp.Key; var config = kvp.Value; var goal = agent.AssignedGoals.FirstOrDefault(g => g.Name == goalName); if (goal != null) { var goalState = new GoalState(goal, agent, config.Value, config.FocalValue, config.Importance, config.MinValue, config.MaxValue, config.MinValueReference, config.MaxValueReference); agent.InitialGoalStates.Add(goal, goalState); } }); // Initializes initial anticipated influence for each kh and goal assigned to the agent agent.AssignedDecisionOptions.ForEach(decisionOption => { Dictionary <string, double> source; if (decisionOption.AutoGenerated && agent.Archetype.DoNothingAnticipatedInfluence != null) { source = agent.Archetype.DoNothingAnticipatedInfluence; } else { agentConfiguration.AnticipatedInfluenceState.TryGetValue(decisionOption.Name, out source); } var inner = new Dictionary <Goal, double>(); agent.AssignedGoals.ForEach(g => { inner.Add(g, source != null && source.ContainsKey(g.Name) ? source[g.Name] : 0); }); agent.AnticipationInfluence.Add(decisionOption, inner); }); InitializeDynamicVariables(agent); agent.AgentStateConfiguration = agentConfiguration; return(agent); }
/// <inheritdoc /> protected override void InitializeAgents() { var agents = new List <IAgent>(); Dictionary <string, AgentArchetype> agentArchetypes = _configuration.AgentConfiguration; if (agentArchetypes.Count == 0) { throw new SosielAlgorithmException("Agent archetypes were not defined. See configuration file"); } InitialStateConfiguration initialState = _configuration.InitialState; var networks = new Dictionary <string, List <SOSIEL.Entities.Agent> >(); //create agents, groupby is used for saving agents numeration, e.g. FE1, HM1. HM2 etc initialState.AgentsState.GroupBy(state => state.ArchetypeOfAgent).ForEach((agentStateGroup) => { AgentArchetype archetype = agentArchetypes[agentStateGroup.Key]; var mentalProto = archetype.MentalProto; int index = 1; agentStateGroup.ForEach((agentState) => { for (int i = 0; i < agentState.NumberOfAgents; i++) { SOSIEL.Entities.Agent agent = Agent.CreateAgent(agentState, archetype); agent.SetId(index); agents.Add(agent); networks.AddToDictionary((string)agent[AlgorithmVariables.Household], agent); networks.AddToDictionary((string)agent[AlgorithmVariables.NuclearFamily], agent); if (agent.ContainsVariable(AlgorithmVariables.ExternalRelations)) { var externals = (string)agent[AlgorithmVariables.ExternalRelations]; foreach (var en in externals.Split(';')) { networks.AddToDictionary(en, agent); } } //household and extended family are the same at the beginning agent[AlgorithmVariables.ExtendedFamily] = new List <string>() { (string)agent[AlgorithmVariables.Household] }; index++; } }); }); //convert temp networks to list of connetcted agents networks.ForEach(kvp => { var connectedAgents = kvp.Value; connectedAgents.ForEach(agent => { agent.ConnectedAgents.AddRange(connectedAgents.Where(a => a != agent).Except(agent.ConnectedAgents)); }); }); agentList = new AgentList(agents, agentArchetypes.Select(kvp => kvp.Value).ToList()); }