Пример #1
0
        public Particle Clone()
        {
            Particle p = new Particle(this.particle_number);

            this.x.CopyTo(p.x, 0);
            this.velocity.CopyTo(p.velocity, 0);

            p.SetFitness(this.fitness);
            return p;
        }
Пример #2
0
        // constructor
        public Particle(int p_number)
        {
            // init random
            r = new Random();

            // init array
            this.x = new double[10];
            this.velocity = new double[10];

            // init pbest, velocity
            this.pbest = null; //high number
            this.lbest = null;

            // store particle number
            this.particle_number = p_number;

            // populate x value with random numbers from -10.0 to 10.0
            for (int i = 0; i < 10; i++)
            {
                r = new Random(p_number + i + r.Next());
                this.x[i] = r.Next(-10, 10) * r.NextDouble(); // x[i]
                this.velocity[i] = 0.0;
            }
        }
Пример #3
0
 // set personal best pbest
 public void SetPBest(Particle pbest)
 {
     this.pbest = pbest;
 }
Пример #4
0
 // set local best lbest
 public void SetLBest(Particle lbest)
 {
     this.lbest = lbest;
 }