private static InitialStateConfiguration MakeInitialStateConfiguration( SheParameters sheParameters, SosielParameters sosielParameters) { var sameKeys = sosielParameters.AgentGoalAttributes.Select(ga => ga.Agent).Intersect( sosielParameters.AgentDecisionOptions.Select(d => d.Agent)).ToList(); if (sosielParameters.AgentGoalAttributes.Count != sosielParameters.AgentDecisionOptions.Count || sosielParameters.AgentGoalAttributes.Count != sameKeys.Count) { throw new ConfigurationException("AgentGoalAttributes is not suitable for AgentDecisionOptions"); } var initialState = sosielParameters.AgentGoalAttributes .Join(sosielParameters.AgentDecisionOptions, ga => ga.Agent, d => d.Agent, (goal, decision) => new { GoalAttribute = goal, DecisionAttribute = decision }) .ToList(); var parsedStates = new List <AgentStateConfiguration>(); foreach (var state in initialState) { var agentState = ParseAgentState(sheParameters, state.GoalAttribute, state.DecisionAttribute); var variablesCollection = sosielParameters.AgentVariables.Cast <IVariable>().ToList(); agentState.PrivateVariables = ParseAgentVariables(variablesCollection, state.GoalAttribute.Agent); parsedStates.Add(agentState); } return(new InitialStateConfiguration { AgentStates = parsedStates.ToArray() }); }
public static ConfigurationModel MakeConfiguration(SheParameters sheParameters, SosielParameters sosielParameters) { return(new ConfigurationModel { AlgorithmConfiguration = MakeAlgorithmConfiguration( sosielParameters.CognitiveLevel, sosielParameters.Demographic, sosielParameters.Probabilities), AgentArchetypeConfiguration = MakeAgentArchetypeConfiguration(sosielParameters), InitialState = MakeInitialStateConfiguration(sheParameters, sosielParameters) }); }
private static AgentStateConfiguration ParseAgentState( SheParameters sheParameters, AgentGoalAttribute goalAttribute, AgentDecisionOptions decisionAttribute) { var agentState = new AgentStateConfiguration(); agentState.Name = goalAttribute.Agent; agentState.NumberOfAgents = 1; agentState.Archetype = goalAttribute.Archetype; agentState.AssignedGoals = goalAttribute.Goals.Split('|').ToArray(); var parsedDecisionOptions = ParseAgentDecisionOptions(decisionAttribute.DecisionOptions); agentState.AnticipatedInfluenceState = parsedDecisionOptions; agentState.AssignedDecisionOptions = parsedDecisionOptions.Keys.ToArray(); agentState.GoalStates = ParseAgentGoalAttributes(goalAttribute); var agentToManagementArea = sheParameters.AgentToManagementAreaList.Where(a => a.Agent == agentState.Name).FirstOrDefault(); if (agentToManagementArea != null) { agentState.Mode = agentToManagementArea.AgentMode; if (!SheParameters.ValidateModeNumber(agentState.Mode)) { throw new Exception($"Invalid simulation mode {agentState.Mode} for the agent '{agentState.Name}'"); } } else if (sheParameters.Modes.Count == 1) { agentState.Mode = sheParameters.Modes[0]; } else { throw new Exception($"Cannot determine simulation mode for the agent '{agentState.Name}'"); } return(agentState); }