Пример #1
0
        private void CreateLogDetails(Scenario.ScenarioEventArgs args)
        {
            if (Simulation == null)
            {
                return;
            }

            var rootnode = LogsTreeView.Nodes.Add($"Tick at {AbsoluteTime}s");

            rootnode.Tag = $"Simulation {Simulation.GetName()} at time {AbsoluteTime}s\r\n";

            foreach (var agent in Simulation.Agents)
            {
                var agentnode = rootnode.Nodes.Add(agent.GetName());
                if (agent.AgentArchetype == null)
                {
                    agentnode.Tag = "(No archetype set for this agent)";
                    continue;
                }

                var winctx = args.AgentDecisions[agent].WinningContext;

                string decisionLog = (winctx == null) ? "(stalled!)" : $"{winctx.ChosenBehavior.GetName()} [{winctx.ChosenBehavior.Action}]";
                string contextLog  = (winctx == null) ? "(N/A)" : $"{winctx.Target.GetName()}";
                string position    = agent.GetPosition().ToString();
                agentnode.Tag = $"Agent: {agent.GetName()} (running archetype {agent.AgentArchetype.GetName()})\r\nDecision: {decisionLog}\r\nContext: {contextLog}\r\nPosition: {position}\r\n";

                foreach (var behaviorset in agent.AgentArchetype.BehaviorSets)
                {
                    var setnode = agentnode.Nodes.Add(behaviorset.GetName());
                    setnode.Tag = $"Behavior set: {setnode.Text}\r\n";

                    foreach (var behavior in behaviorset.EnabledBehaviors)
                    {
                        var behaviornode = setnode.Nodes.Add(behavior.GetName());
                        behaviornode.Tag = $"Behavior: {behaviornode.Text}\r\n\r\n";

                        foreach (var ctx in args.AgentDecisions[agent].ScoredContexts)
                        {
                            if (ctx.ChosenBehavior != behavior)
                            {
                                continue;
                            }

                            var contextnode = behaviornode.Nodes.Add(ctx.Target.GetName());
                            contextnode.Tag = ctx;

                            if (ctx == winctx)
                            {
                                contextnode.Text = "(*) " + contextnode.Text;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
 private void ScenarioAdvance(object sender, Scenario.ScenarioEventArgs args)
 {
     RefreshAgentTab();
     CreateLogDetails(args);
     AbsoluteTime += args.DeltaTime;
 }