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); }
private static Dictionary <string, GoalStateConfiguration> ParseAgentGoalAttributes( AgentGoalAttribute goalAttribute) { var result = goalAttribute.Goals.Split('|').ToDictionary(k => k, k => new GoalStateConfiguration()); var matchedFocalValues = _matchPattern.Matches(goalAttribute.GoalFocalValues); foreach (Match focalValue in matchedFocalValues) { var goal = focalValue.Groups[1].Value; var goalStateConfiguration = result[goal]; if (focalValue.Groups[4].Value != IgnoredValue) { var focalReference = focalValue.Groups[3].Value; if (!string.IsNullOrEmpty(focalReference)) { goalStateConfiguration.FocalValueReference = focalReference; } var focal = focalValue.Groups[2].Value; if (!string.IsNullOrEmpty(focal)) { goalStateConfiguration.FocalValue = ParseValue <double>(focal); } } } var matchedImportances = _matchPattern.Matches(goalAttribute.GoalImportance); foreach (Match importance in matchedImportances) { var goal = importance.Groups[1].Value; var value = ParseValue <double>(importance.Groups[2].Value); result[goal].Importance = value; } var matchedValueRanges = _matchRangePattern.Matches(goalAttribute.GoalValueRange); foreach (Match range in matchedValueRanges) { var goal = range.Groups[1].Value; if (range.Groups[6].Value != IgnoredValue) { var state = result[goal]; if (!string.IsNullOrEmpty(range.Groups[2].Value)) { var minValue = ParseValue <double>(range.Groups[2].Value); state.MinValue = minValue; } if (!string.IsNullOrEmpty(range.Groups[3].Value)) { state.MinValueReference = range.Groups[3].Value; } if (!string.IsNullOrEmpty(range.Groups[4].Value)) { var maxValue = ParseValue <double>(range.Groups[4].Value); state.MaxValue = maxValue; } if (!string.IsNullOrEmpty(range.Groups[5].Value)) { state.MaxValueReference = range.Groups[5].Value; } } } return(result); }