Exemplo n.º 1
0
        public void RegisterAgent(IAgent agent)//エージェントの内部状態を見るもの
        {
            //******すでに登録されていて、違うエージェントだったら既存のイベントを削除******
            if (registeredAgent != null && registeredAgent != agent)
            {
                removeEvents(registeredAgent);
            }

            //******引数がnullだったら 表示を空っぽにして終了******
            if (agent == null)
            {
                //nullが渡されたなら,nullを登録
                registeredAgent = null;

                //候補をクリア
                Candidates_CB.DataSource = null;
                Candidates_CB.Items.Add(new object());
                Candidates_CB.Items.Clear();


                //表示を更新
                Invoke(new Action(() =>
                {
                    IDLabel.Text                  = "ID";
                    AlgorithmLabel.Text           = "Algorithm";
                    TargetAwarenessRateLabel.Text = "h_trg";
                }));


                //再描画
                Invalidate();
                return;
            }

            //******型が合ってるかチェック***
            IAATBasedAgent aat = null;

            if (agent is IAATBasedAgent && agent is AgentAlgorithm)
            {
                aat = agent as IAATBasedAgent;
            }
            else
            {
                Console.WriteLine("このパネルでは,AATベースのエージェントアルゴリズムしか監視できません.");
                return;
            }


            //****** ここまで来たら,晴れて合格.AATベースのエージェントを登録 ******


            //新たなエージェントを追加

            registeredAgent = aat;

            //イベントを監視開始
            addEvents(registeredAgent);

            //ネットワークの指標を計算
            INode bodyAsINode = ((aat as AgentAlgorithm).Body as INode);

            double cluster = NetworkIndexes.cluster(bodyAsINode, bodyAsINode.Network);


            //表示を変更する
            Invoke(new Action(() => {
                //ちょっと複雑・・・
                IDLabel.Text                  = "ID" + (aat as AgentAlgorithm).ID;//結局Body=AgentIOを参照してる
                AlgorithmLabel.Text           = aat.GetType().Name;
                TargetAwarenessRateLabel.Text = aat.TargetAwarenessRate.ToString();
                PrepareCandidatesCB(aat);

                otherStates.Text = "cluster = " + cluster + "\r\n" +
                                   "friend = " + bodyAsINode.Neighbours.Count;
            }));

            Invalidate();

            #region SHOW
            Console.WriteLine("registered :" + registeredAgent);


            if (registeredAgent.CandidateSelector != null && registeredAgent.CandidateSelector.Candidates != null)
            {
                var candidates_greater = registeredAgent.CandidateSelector.Candidates.OrderBy((c) => c.ImportanceLevel);

                int i = 0;
                foreach (var candidate in candidates_greater)
                {
                    Console.Write("[0] l: {1} r: {2} t: {3} h: {4}",
                                  i++,
                                  candidate.JumpNumLeft,
                                  candidate.JumpNumRight,
                                  candidate.ImportanceLevel,
                                  candidate.AwarenessRate);

                    if (candidate == registeredAgent.CandidateSelector.CurrentCandidate)
                    {
                        Console.Write("<==== this one!");
                    }

                    Console.WriteLine();
                }
            }

            #endregion
        }