Пример #1
0
        private void Step_Animate_Swarm(Color[] pColor, int s)
        {
            double[] xx = new double[((ArrayList)AniS[s]).Count];
            double[] yy = new double[((ArrayList)AniS[s]).Count];
            //plot the current position of particles and their corresponding fitness (objective values)
            for (int i = 0; i < ((ArrayList)AniS[s]).Count; i++)
            {
                xx[i] = ((Particle)((ArrayList)AniS[s])[i]).Position[0];
                yy[i] = ((Particle)((ArrayList)AniS[s])[i]).Objective;
            }
            DrawGraph.CreateXYScatter(Animation, xx, yy, "particle", "Animation_StepS", pColor[3], 8f, ZedGraph.SymbolType.Circle);
            //plot the best found position of particles and their corresponding best objective values
            for (int i = 0; i < ((ArrayList)AniS[s]).Count; i++)
            {
                xx[i] = ((Particle)((ArrayList)AniS[s])[i]).BestP[0];
                yy[i] = ((Particle)((ArrayList)AniS[s])[i]).ObjectiveP;
            }
            DrawGraph.CreateXYScatter(Animation, xx, yy, "particle", "Animation_StepS", Color.Orange, 9f, ZedGraph.SymbolType.Diamond);

            if ((s % 50 == 0) || (s == AniS.Count))
            {
                Animation.GraphPane.XAxis.Scale.MaxAuto = true;
                Animation.GraphPane.XAxis.Scale.MinAuto = true;
                Animation.GraphPane.YAxis.Scale.MaxAuto = true;
                Animation.GraphPane.YAxis.Scale.MinAuto = true;
            }
            else
            {
                Animation.GraphPane.XAxis.Scale.MaxAuto = false;
                Animation.GraphPane.XAxis.Scale.MinAuto = false;
                Animation.GraphPane.YAxis.Scale.MaxAuto = false;
                Animation.GraphPane.YAxis.Scale.MinAuto = false;
            }
        }
Пример #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;
        }
Пример #3
0
 private void Step_Animate(Color[] pColor, int s)
 {
     double[] xx = new double[1];
     double[] yy = new double[1];
     xx[0] = ((Particle)Ani[s]).BestP[0];
     yy[0] = ((Particle)Ani[s]).ObjectiveP;
     DrawGraph.CreateXYScatter(Animation, xx, yy, "Gbest", "Animation_Step" + s.ToString(), Color.Green, 10f, ZedGraph.SymbolType.Triangle);
     //choose whether the graph should be rescale after a number of step
     if ((s % 50 == 0) || (s == AniS.Count))
     {
         Animation.GraphPane.XAxis.Scale.MaxAuto = true;
         Animation.GraphPane.XAxis.Scale.MinAuto = true;
         Animation.GraphPane.YAxis.Scale.MaxAuto = true;
         Animation.GraphPane.YAxis.Scale.MinAuto = true;
     }
     else
     {
         // Animation.GraphPane.XAxis.Scale.MaxAuto = false;
         // Animation.GraphPane.XAxis.Scale.MinAuto = false;
         // Animation.GraphPane.YAxis.Scale.MaxAuto = false;
         // Animation.GraphPane.YAxis.Scale.MinAuto = false;
     }
 }