Exemple #1
0
        private void PSO_dynamic_Click(object sender, EventArgs e)
        {
            int Aspeed = Int16.Parse(this.AniSpeed.Text);

            Istep = Int16.Parse(this.AniStep.Text);
            #region drawGraph of function
            double[] xx;
            double[] yy;
            PSO_Function.GraphPane.CurveList.Clear();
            int density = 2000;
            xx = new double[density];
            yy = new double[density];
            for (int i = 0; i < density; i++)
            {
                xx[i] = ((Particle)((ArrayList)AniS[0])[0]).PosMin[0] + i * (((Particle)((ArrayList)AniS[0])[0]).PosMax[0] - ((Particle)((ArrayList)AniS[0])[0]).PosMin[0]) / density;
                yy[i] = Function.Test_Function(fx, xx[i]);
            }
            #endregion
            for (int s = Istep; s < AniS.Count; s++)
            {
                Animation.GraphPane.CurveList.Clear();
                DrawGraph.CreateXYCurve(Animation, xx, yy, "F(x)", "Function", Color.Blue);
                Step_Animate(pColor, s);
                Step_Animate_Swarm(pColor, s);
                System.Threading.Thread.Sleep(Aspeed);
            }
        }
Exemple #2
0
        private void Run_Click(object sender, EventArgs e)
        {
            double ObjectiveValue;

            double[] index;
            double[] Avg;
            double[] PSOparas = new double[9];
            fx          = Convert.ToInt32(this.fxindex.Value); //choose objective function to be minimized
            PSOparas[0] = Convert.ToDouble(this.PSOiter.Value);
            PSOparas[1] = Convert.ToDouble(this.PSOnumParticles.Value);
            PSOparas[2] = Convert.ToDouble(this.PSOwmin.Text);
            PSOparas[3] = Convert.ToDouble(this.PSOwmax.Text);
            PSOparas[4] = Convert.ToDouble(this.PSOnb.Value);
            PSOparas[5] = Convert.ToDouble(this.PSOcp.Text);
            PSOparas[6] = Convert.ToDouble(this.PSOcg.Text);
            PSOparas[7] = Convert.ToDouble(this.PSOcl.Text);
            PSOparas[8] = Convert.ToDouble(this.PSOcn.Text);
            DateTime start = DateTime.Now;

            AniS = new ArrayList();
            //call PSO algorithm to minimize f(x)
            MainClass.PSO(fx, PSOparas, out ObjectiveValue, out Avg, out index, out Ani, out AniS, out GBest);

            TimeSpan finish = DateTime.Now - start;

            PSOGraph.GraphPane.CurveList.Clear();
            DrawGraph.CreateXY(PSOGraph, index, Avg);
            int density = 2000; //number of points used to construct the outline of a function within the pre-defined range

            #region drawGraph_function_outline
            double[] xx;
            double[] yy;
            PSO_Function.GraphPane.CurveList.Clear();
            xx    = new double[1];
            yy    = new double[1];
            xx[0] = GBest.BestP[0];
            yy[0] = GBest.ObjectiveP;
            DrawGraph.CreateXYScatter(PSO_Function, xx, yy, "F(x)", "Best Solution", Color.Red, 10f, ZedGraph.SymbolType.Triangle);
            xx = new double[density];
            yy = new double[density];
            for (int i = 0; i < density; i++)
            {
                xx[i] = ((Particle)((ArrayList)AniS[0])[0]).PosMin[0] + i * (((Particle)((ArrayList)AniS[0])[0]).PosMax[0] - ((Particle)((ArrayList)AniS[0])[0]).PosMin[0]) / density;
                yy[i] = Function.Test_Function(fx, xx[i]);
            }
            DrawGraph.CreateXYCurve(PSO_Function, xx, yy, "F(x)", "Function", Color.Blue);
            #endregion
            ObjVal.Text = finish.ToString();
            // Enable animation
            this.AniStep.Enabled     = true;
            this.AniStepRun.Enabled  = true;
            this.PSO_dynamic.Enabled = true;
            this.AniSpeed.Enabled    = true;
        }
Exemple #3
0
        private void Back_Click(object sender, EventArgs e)
        {
            Istep--;
            if (Istep < 0)
            {
                MessageBox.Show("This is first step");
                Istep++;
                return;
            }
            Animation.GraphPane.CurveList.Clear();
            #region drawGraph
            double[] xx;
            double[] yy;
            PSO_Function.GraphPane.CurveList.Clear();
            int density = 2000;
            xx = new double[density];
            yy = new double[density];
            for (int i = 0; i < density; i++)
            {
                xx[i] = ((Particle)((ArrayList)AniS[0])[0]).PosMin[0] + i * (((Particle)((ArrayList)AniS[0])[0]).PosMax[0] - ((Particle)((ArrayList)AniS[0])[0]).PosMin[0]) / density;
                yy[i] = Function.Test_Function(fx, xx[i]);
            }

            #endregion
            DrawGraph.CreateXYCurve(Animation, xx, yy, "particle", "Animation_StepS", Color.Blue);
            #region drawDirection
            xx    = new double[2];
            yy    = new double[2];
            xx[0] = ((Particle)((ArrayList)AniS[Istep])[0]).Position[0];
            yy[0] = ((Particle)((ArrayList)AniS[Istep])[0]).Objective;
            xx[1] = ((Particle)((ArrayList)AniS[Istep])[0]).BestP[0];
            yy[1] = ((Particle)((ArrayList)AniS[Istep])[0]).ObjectiveP;
            DrawGraph.CreateXYCurve(Animation, xx, yy, "direction", "Animation_StepS", Color.Orange);
            xx[1] = ((Particle)Ani[Istep]).BestP[0];
            yy[1] = ((Particle)Ani[Istep]).ObjectiveP;
            DrawGraph.CreateXYCurve(Animation, xx, yy, "direction", "Animation_StepS", Color.Green);
            #endregion
            Step_Animate(pColor, Istep);
            Step_Animate_Swarm(pColor, Istep);
        }