예제 #1
0
        //method to update linear increasing velocity
        public void Update_LinearIncreasingVelocity(Particle gbest, double wt)
        {
            double r1, r2, fi1, fi2;

            for (int i = 0; i < this.numberOfGenes; i++)
            {
                RandomNumGenerator generator = new RandomNumGenerator();
                r1  = generator.Generate_Double();
                r2  = generator.Generate_Double();
                fi1 = 1.5 * r1 + 0.5;
                fi2 = 1.5 * r2 + 0.5;

                double factor1 = fi1 * (this.pbest[i] - this.genes[i]);
                double factor2 = fi2 * (gbest.genes[i] - this.genes[i]);
                double factor3 = this.velocity[i] * wt;
                this.velocity[i] = factor1 + factor2 + factor3;

                //complete equation for velocity update
                //this.velocity[i] = this.velocity[i] * wt + (fi1 * (this.pbest[i] - this.genes[i]) + fi2 * (gbest.genes[i] - this.genes[i]));

                //clamping positive velocity if it is out of range
                if (this.velocity[i] > this.posClampVelocity)
                {
                    this.velocity[i] = this.posClampVelocity;
                }

                //clamping negative velocity if it is out of range
                if (this.velocity[i] < this.negClampVelocity)
                {
                    this.velocity[i] = this.negClampVelocity;
                }
            }
        }
예제 #2
0
        public void Update_LinearDecreasingVelocity(Particle gbest, double wt)
        {
            int    c1 = 2;
            int    c2 = 2;
            double r1, r2;

            for (int i = 0; i < this.numberOfGenes; i++)
            {
                RandomNumGenerator generator = new RandomNumGenerator();

                r1 = generator.Generate_Double();
                r2 = generator.Generate_Double();
                this.velocity[i] = this.velocity[i] * wt + ((c1 * r1 * (this.pbest[i] - this.genes[i])) + (c2 * r2 * (gbest.genes[i] - this.genes[i])));

                //clamping positive velocity if it is out of range
                if (this.velocity[i] > this.posClampVelocity)
                {
                    this.velocity[i] = this.posClampVelocity;
                }

                //clamping negative velocity if it is out of range
                if (this.velocity[i] < this.negClampVelocity)
                {
                    this.velocity[i] = this.negClampVelocity;
                }
            }
        }
예제 #3
0
        public RosenbrockParticle(int lowerRange, int higherRange, int posClampVelocity, int negClampVelocity, int numberOfTimeSteps)
        {
            this.lowerRange        = lowerRange;
            this.higherRange       = higherRange;
            this.posClampVelocity  = posClampVelocity;
            this.negClampVelocity  = negClampVelocity;
            this.numberOfTimeSteps = numberOfTimeSteps;

            RandomNumGenerator rand = new RandomNumGenerator();

            //initializing genes and velocity values
            for (int i = 0; i < 10; i++)
            {
                double number = rand.Generate_Double(this.lowerRange, this.higherRange);
                this.genes.Add(number);
                this.velocity.Add(0);
            }

            this.numberOfGenes = this.genes.Count;

            //initializing pbest list with the initial genes values
            for (int i = 0; i < this.numberOfGenes; i++)
            {
                this.pbest.Add(this.genes[i]);
            }

            //initializing bestFitness
            this.bestFitness = this.CalculateFitness();
        }