Example #1
0
        public void TestMethod1()
        {
            var agentIO = new AgentIO();

            IAATBasedAgent algo = new AAT();

            algo.TargetAwarenessRate = 0.9;

            agentIO.Algorithm = (algo as AgentAlgorithm);
        }
Example #2
0
        public void TestMethod1()
        {
            var agentIO = new AgentIO();

            IAATBasedAgent algo = new AAT();

            algo.TargetAwarenessRate = 0.9;

            agentIO.Algorithm = (algo as AgentAlgorithm);
        }
Example #3
0
        void FigurePanel_Click(object sender, EventArgs e)
        {
            Point p = this.PointToClient(Control.MousePosition);


            foreach (var pair in agentViews)
            {
                if (pair.Value.includes(p.X, p.Y))
                {
                    AgentIO io = pair.Key;

                    if ((e as MouseEventArgs).Button == MouseButtons.Left)
                    {
                        AgentStatePanel.RegisterAgent(io.Algorithm as IAATBasedAgent);
                    }
                    else if ((e as MouseEventArgs).Button == MouseButtons.Right)
                    {
                        //なにかエージェントが選択中ならば
                        if (AgentStatePanel.Agent != null)
                        {
                            var selected = (AgentStatePanel.Agent as AgentAlgorithm).Body;
                            var net      = selected.Network;

                            if (io != selected)
                            {
                                var link = new Link(io, selected);

                                if (io.Neighbours.Contains(selected))
                                {
                                    net.DisconnectNode(link);
                                }
                                else
                                {
                                    net.ConnectNode(link);
                                }
                            }
                        }
                    }

                    this.Invalidate();
                    return;
                }
            }

            AgentStatePanel.RegisterAgent(null);
            this.Invalidate();
        }
Example #4
0
        private void PrepareSensor(int sensorNum)
        {
            //センサー
            Sensors = new List <Sensor>();

            //センサーをもつエージェントを決める
            var selectedIndexes = RandomPool.Get("envset").getRandomIndexes(this.Network.Nodes.Count(), sensorNum);

            foreach (var i in selectedIndexes)
            {
                //センサーを生成
                Sensor s = new Sensor(TheFact);

                //センサーにエージェントをセット(内部でAgentのhavesensorをtrueにしてる.微妙に密結合)
                AgentIO agent = this.Network.Nodes.ElementAt(i) as AgentIO;
                s.SetAgent(agent);
                agent.SetSensor(s);
                this.Sensors.Add(s);
            }
        }
Example #5
0
 public void SendWhite(AgentIO to)
 {
     SendOpinion(BlackWhiteSubject.White, to);
 }
Example #6
0
 public void SendBlack(AgentIO to)
 {
     SendOpinion(BlackWhiteSubject.Black, to);
 }
Example #7
0
        private void FigurePanel_Paint(object sender, PaintEventArgs e)
        {
            if (agentViews == null)
            {
                return;
            }

            //***************************基本的な設定***************************
            var g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            int ActualWidth  = this.ClientSize.Width;
            int ActualHeight = this.ClientSize.Height;


            //***************************ブラシなどの準備***************************

            //色の基本
            float hue     = 200;  //色相 青系:200
            float vOffset = 0.3f; //Vのオフセット  高いほど明るくなる

            //色
            Color OpWhiteColor   = Util.StaticColor.ConvertHSBtoARGB(hue, 1f - 1f, 1f);
            Color OpBlackColor   = Util.StaticColor.ConvertHSBtoARGB(hue, 1f - 0f, vOffset);
            Color OpUndeterColor = Util.StaticColor.ConvertHSBtoARGB(hue, 1f - 0.5f, (1f - vOffset) * 0.5f + vOffset);
            Color OrangeColor    = Util.StaticColor.ConvertHSBtoARGB(40F, 0.9F, 0.9F);
            Color GreenColor     = Util.StaticColor.ConvertHSBtoARGB(91F, 0.62F, 0.80F);
            Color PriorColor     = Util.StaticColor.ConvertHSBtoARGB(hue, 0.5f, 0f);

            //ペン
            Pen blackPen     = new Pen(Color.Black);
            Pen blackThinPen = new Pen(Color.Black);

            blackThinPen.Width = 1;

            Pen grayPen = new Pen(Color.Gray);

            grayPen.Width    = 2;
            grayPen.StartCap = grayPen.EndCap = LineCap.Round;
            Pen priorBeliefPen = new Pen(PriorColor);

            priorBeliefPen.StartCap = priorBeliefPen.EndCap = LineCap.Round;
            priorBeliefPen.Width    = 1;
            Pen linkPen = new Pen(GreenColor);

            linkPen.Width = 1.5f;
            Pen selectedLinkPen = new Pen(new SolidBrush(Color.Red));

            selectedLinkPen.Width = 3f;
            Pen sensorPen = new Pen(OrangeColor);

            sensorPen.Width = 10;
            Pen sensorNetworkPen = new Pen(OrangeColor);

            sensorNetworkPen.Width = 10;
            Pen redPen = new Pen(Color.Red);

            redPen.Width = 3;
            Pen meterPen = new Pen(Util.StaticColor.ConvertHSBtoARGB(hue, 1f - 0f, vOffset));

            meterPen.Width    = 2;
            meterPen.StartCap = meterPen.EndCap = LineCap.Round;

            //ブラシ
            SolidBrush redBrush       = new SolidBrush(Color.Red);
            SolidBrush grayBrush      = new SolidBrush(Color.Gray);
            SolidBrush lightGrayBrush = new SolidBrush(Color.LightGray);
            SolidBrush beliefBrush    = new SolidBrush(Util.StaticColor.ConvertHSBtoARGB(100F, 0.9F, 0.8F));
            SolidBrush opinionBrush   = new SolidBrush(Util.StaticColor.ConvertHSBtoARGB(0F, 0F, 1F));



            //四隅をためしに描画
            g.FillRectangle(beliefBrush, 0, 0, 10, 10);
            g.FillRectangle(beliefBrush, ActualWidth - 10, 0, 10, 10);
            g.FillRectangle(beliefBrush, ActualWidth - 10, ActualHeight - 10, 10, 10);
            g.FillRectangle(beliefBrush, 0, ActualHeight - 10, 10, 10);


            //***************************縮尺を変更***************************
            Matrix scaleMat = new Matrix();

            scaleMat.Scale(scale, scale);
            g.Transform = scaleMat;

            //AgentPanelに監視されてるエージェント
            IAATBasedAgent selected = AgentStatePanel.Agent;

            //リンクを描く 緑の線
            if (DrawLinks)
            {
                foreach (Link li in Environment.Network.Links)
                {
                    AgentIO agent1 = li.Node1 as AgentIO;
                    AgentIO agent2 = li.Node2 as AgentIO;

                    Point p1 = new Point((int)agentViews[agent1].X, (int)agentViews[agent1].Y);
                    Point p2 = new Point((int)agentViews[agent2].X, (int)agentViews[agent2].Y);


                    //センサーネットワークを表示する場合表示
                    if (showSensorNetworkCB.Checked)
                    {
                        if (agent1.HasSensor || agent2.HasSensor)
                        {
                            g.DrawLine(sensorNetworkPen, p1, p2);
                        }
                        else if (showOnlySensorNetworkCB.Checked)
                        {
                            continue;
                        }
                    }


                    //選択中のものならばそう表示
                    if (selected != null && (agent1.Algorithm == selected || agent2.Algorithm == selected))
                    {
                        g.DrawLine(selectedLinkPen, p1, p2);
                    }


                    else
                    {
                        g.DrawLine(linkPen, p1, p2);
                    }
                }
            }



            //絶対行列を記録
            Matrix absoluteMatrix = g.Transform;

            //エージェントを描く
            foreach (AgentIO agentIO in Environment.Network.Nodes)
            {
                //******************各種サイズ**************************
                float r  = agentViews[agentIO].R;
                float r2 = r * 2;
                float r3 = r * 3;
                float r4 = r * 4;

                float r_outer = r3;



                { //エージェントの位置に移動
                    //絶対行列に戻す
                    g.Transform = absoluteMatrix;

                    //エージェントの位置に移動
                    Matrix agentMatrix = g.Transform;
                    agentMatrix.Translate(agentViews[agentIO].X, agentViews[agentIO].Y);
                    g.Transform = agentMatrix;
                }


                //センサーネットワークだけを表示する設定になっている場合
                if (showSensorNetworkCB.Checked && showOnlySensorNetworkCB.Checked)
                {
                    //センサーネットワークに入っているか否か
                    bool inNetwork = false;

                    //センサーエージェントならば入っている
                    if (agentIO.HasSensor)
                    {
                        inNetwork = true;
                    }
                    //それ以外でも,友達がセンサーネットワークならばOK
                    else
                    {
                        //友達を調べる
                        foreach (var neighbour in agentIO.Neighbours)
                        {
                            if ((neighbour as AgentIO).HasSensor)
                            {
                                inNetwork = true;
                            }
                        }
                    }

                    //ネットワークに入っているならば処理を続ける.
                    if (inNetwork == true)
                    {
                        //ok
                    }
                    //ネットワーに入っていないならば処理を中断する.
                    else
                    {
                        continue;
                    }
                }

                //エージェントが描けない場合は丸書いて終わり
                if (!agentIO.Drawable)
                {
                    g.FillEllipse(grayBrush, -r_outer / 2, -r_outer / 2, r_outer, r_outer);

                    continue;//break;にすべきかも
                }

                IAATBasedAgent aat = agentIO.Algorithm as IAATBasedAgent;


                //エージェントの内部状態
                float agentBelief = (float)(aat.Belief);
                float priorBelief = (float)(aat.PriorBelief);
                float sigmaRight  = (float)(aat.Sigma);
                float sigmaLeft   = 1 - sigmaRight;


                //ペンの太さを設定
                priorBeliefPen.Width = agentViews[agentIO].PenWidth;
                sensorPen.Width      = priorBeliefPen.Width;



                //意見によってブラシの色を変更
                if (agentIO.Opinion == BlackWhiteSubject.White)
                {
                    opinionBrush.Color = OpWhiteColor;
                }

                else if (agentIO.Opinion == BlackWhiteSubject.Black)
                {
                    opinionBrush.Color = OpBlackColor;
                }

                else
                {
                    opinionBrush.Color = OpUndeterColor;
                }

                //信念によってブラシの色を変更
                //beliefBrush.Color = Util.StaticColor.ConvertHSBtoARGB(240 - (240 * agentBelief), 1f, 1f);
                beliefBrush.Color = Util.StaticColor.ConvertHSBtoARGB(hue, 1f - agentBelief, (1 - vOffset) * agentBelief + vOffset);

                //初期値は今は使ってない
                priorBeliefPen.Color = Util.StaticColor.ConvertHSBtoARGB(hue, 1f - priorBelief, (1 - vOffset) * priorBelief + vOffset);



                //panelによって注目しているエージェントを描画
                if (agentIO == selected)//|| i.ChangedOpinion)
                {
                    g.DrawEllipse(redPen, -r2, -r2, r2 * 2, r2 * 2);
                }

                //意見の円
                g.FillEllipse(opinionBrush, -r_outer / 2, -r_outer / 2, r_outer, r_outer);

                //扇型を表示
                {
                    float zeroDeg       = 180f;
                    float sigmaLeftDeg  = (sigmaLeft * 180f + zeroDeg);
                    float sigmaRightDeg = (sigmaRight * 180f + zeroDeg);
                    float sigmaSweepDeg = (sigmaRight - sigmaLeft) * 180f;


                    g.FillPie(lightGrayBrush, -r_outer / 2, -r_outer / 2, r_outer, r_outer, zeroDeg, 180);
                    g.FillPie(grayBrush, -r_outer / 2, -r_outer / 2, r_outer, r_outer, sigmaLeftDeg, sigmaSweepDeg);
                }

                //髪の毛を生成.しかし,毎回つくるのはしゃくだな・・・
                var beliefList = calcBeliefList(aat.PriorBelief, aat.Sigma, aat.CandidateSelector.BeliefUpdater);

                /* 将来なるであろうBelief */
                foreach (double futureBelief in beliefList)
                {
                    g.DrawLine(blackThinPen,
                               0,
                               0,
                               r_outer / 2 * (float)Math.Cos(Math.PI * futureBelief + Math.PI),
                               r_outer / 2 * (float)Math.Sin(Math.PI * futureBelief + Math.PI));
                }

                //priorBelief
                g.DrawLine(blackThinPen, 0, 0,
                           r_outer / 2 * (float)Math.Cos(Math.PI * priorBelief + Math.PI),
                           r_outer / 2 * (float)Math.Sin(Math.PI * priorBelief + Math.PI));
                //*/


                //外枠の円
                g.DrawEllipse(priorBeliefPen, -r_outer / 2, -r_outer / 2, r_outer, r_outer);

                //信念のmeter
                g.DrawLine(meterPen, 0, 0,
                           r3 * (float)Math.Cos(Math.PI * agentBelief + Math.PI),
                           r3 * (float)Math.Sin(Math.PI * agentBelief + Math.PI));

                //信念の円
                g.FillEllipse(beliefBrush, -r / 2, -r / 2, r2 / 2, r2 / 2);
            }

            g.Transform = absoluteMatrix;

            //センサーを描く
            foreach (var s in Environment.Sensors)
            {
                var   view = agentViews[s.Agent as AgentIO];
                float r2   = view.R * 2;

                g.DrawRectangle(sensorPen, view.X - r2, view.Y - r2, r2 * 2, r2 * 2);
            }
        }