/// <inheritdoc /> protected override void PostIterationStatistic(int iteration) { base.PostIterationStatistic(iteration); var lastIteration = iterations.Last.Value; agentList.Agents.ForEach(agent => { AgentState <Site> agentState; lastIteration.TryGetValue(agent, out agentState); var details = new AgentDetailsOutput { Iteration = iteration, AgentId = agent.Id, Age = agent[AlgorithmVariables.Age], IsAlive = agent[AlgorithmVariables.IsActive], Income = agent[AlgorithmVariables.AgentIncome], Expenses = agent[AlgorithmVariables.AgentExpenses], Savings = agent[AlgorithmVariables.HouseholdSavings], NumberOfDO = agent.AssignedDecisionOptions.Count, ChosenDecisionOption = agentState != null ? string.Join("|", agentState.DecisionOptionsHistories[DefaultDataSet].Activated.Select(opt => opt.Id)) : string.Empty }; CSVHelper.AppendTo(_outputFolder + string.Format(AgentDetailsOutput.FileName, agent.Id), details); }); }
/// <summary> /// Executes after PostIterationCalculations. Collects output data. /// </summary> /// <param name="iteration"></param> protected override void PostIterationStatistic(int iteration) { base.PostIterationStatistic(iteration); try { var settings = new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; var data = JsonConvert.SerializeObject(iterations.Last.Value, settings); File.WriteAllText($"output_SOSIEL_Harvest_DUMP_{iteration}.json", data); } catch (Exception) { } // Save statistics for each agent agentList.ActiveAgents.ForEach(agent => { var agentState = iterations.Last.Value[agent]; if (agent.Archetype.NamePrefix == "FM") { foreach (var area in agentState.DecisionOptionHistories.Keys) { // Save activation rule stat var key = HarvestResults.GetKey(_sheMode, agent, area); var activatedDOs = agentState.DecisionOptionHistories[area] .Activated.Distinct().OrderBy(r => r.Name).ToArray(); var matchedDOs = agentState.DecisionOptionHistories[area] .Matched.Distinct().OrderBy(r => r.Name).ToArray(); var activatedDOIds = activatedDOs.Select(r => r.Name).ToArray(); var matchedDOIds = matchedDOs.Select(r => r.Name).ToArray(); var usage = new FMDOUsageOutput() { Iteration = iteration, ManagementArea = area.Name, ActivatedDOValues = activatedDOs.Select( r => string.IsNullOrEmpty(r.Consequent.VariableValue) ? (string)r.Consequent.Value.ToString() : (string)agent[r.Consequent.VariableValue].ToString()).ToArray(), ActivatedDO = activatedDOIds, MatchedDO = matchedDOIds, MostImportantGoal = agentState.RankedGoals.First().Name, TotalNumberOfDO = agent.AssignedDecisionOptions.Count, BiomassHarvested = _algorithmModel.HarvestResults.ManagementAreaHarvested[key], ManageAreaMaturityPercent = _algorithmModel.HarvestResults.ManagementAreaMaturityPercent[key], Biomass = _algorithmModel.HarvestResults.ManagementAreaBiomass[key] }; CSVHelper.AppendTo(string.Format("output_SOSIEL_Harvest_{0}.csv", agent.Id), usage); } } }); }