Beispiel #1
0
 private void EnviromentGUI_FormClosing(object sender, FormClosingEventArgs e)
 {
     backgroundWorker1.CancelAsync();
     if (env != null)
     {
         env.OnIterationEnd -= OnIterationEnds;
     }
     env = null;
 }
Beispiel #2
0
        private void RestartButton_Click(object sender, EventArgs e)
        {
            backgroundWorker1.CancelAsync();

            panel1.Refresh();
            _source = new List <Point>();
            B       = new List <Barrier>();
            B.Add(new Swarm_Logic.Barrier(0, 0, MaxX, 0));
            B.Add(new Swarm_Logic.Barrier(MaxX, 0, MaxX, MaxY));
            B.Add(new Swarm_Logic.Barrier(MaxX, MaxY, 0, MaxY));
            B.Add(new Swarm_Logic.Barrier(0, MaxY, 0, 0));

            if (env != null)
            {
                env.OnIterationEnd -= OnIterationEnds;
            }
            env = null;
            disableStart();
        }
Beispiel #3
0
        public Form1()
        {
            br = new List <Swarm_Logic.Barrier>(8);
            br.Add(new Swarm_Logic.Barrier(0, 0, MaxX, 0));
            br.Add(new Swarm_Logic.Barrier(MaxX, 0, MaxX, MaxY));
            br.Add(new Swarm_Logic.Barrier(MaxX, MaxY, 0, MaxY));
            br.Add(new Swarm_Logic.Barrier(0, MaxY, 0, 0));

            br.Add(new Swarm_Logic.Barrier(50, 100, 95, 50));
            br.Add(new Swarm_Logic.Barrier(200, 30, 211, 40));
            br.Add(new Swarm_Logic.Barrier(150, 120, 100, 50));
            br.Add(new Swarm_Logic.Barrier(250, 130, 200, 140));

            InitializeComponent();

            rs = new MultipleNoisyGaussianFunctionSources(SourceXs, SourceYs, SourceAs, SourceBs);

            env = new Swarm_Logic.Environment(25, MaxX, MaxY, br, rs);
            env.OnIterationEnd += RefreshMe;
        }
Beispiel #4
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            try
            {
                int agentNum = int.Parse(AgentsNum.Text);
                enableStart();

                if (agentNum <= 0)
                {
                    throw new Exception("Number Of Agents Must be => 1");
                }
                if (_source.Count == 0)
                {
                    throw new Exception("Please Add at least one source");
                }

                List <double> _xpos = new List <double>();
                List <double> _ypos = new List <double>();
                List <double> _A    = new List <double>();
                List <double> _B    = new List <double>();
                foreach (Point p in _source)
                {
                    _xpos.Add(p.X);
                    _ypos.Add(p.Y);
                    _A.Add(1000);
                    _B.Add(1000);
                }

                switch (comboBox1.SelectedIndex)
                {
                default:
                case 0:
                    // Gaussian Function Source
                    R   = new GaussianFunctionSource(_source[0].X, _source[0].Y, 1000);
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;

                case 1:
                    // Multiple Gaussian Function Sources
                    R   = new MultipleGaussianFunctionSources(_xpos.ToArray(), _ypos.ToArray(), _A.ToArray(), _B.ToArray());
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;

                case 2:
                    // Multiple Noise Gaussian Function Sources
                    R   = new MultipleNoisyGaussianFunctionSources(_xpos.ToArray(), _ypos.ToArray(), _A.ToArray(), _B.ToArray());
                    env = new Swarm_Logic.Environment(agentNum, MaxX, MaxY, B, R);
                    env.OnIterationEnd += OnIterationEnds;
                    break;
                }

                RefreshGraphics();
                RestartButton.Enabled = true;
            }

            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
                disableStart();
            }
        }