예제 #1
0
 public void IterateTest()
 {
     this.MockedSolution.Setup(s => s.BetterThan(this.CopySolution.Object)).Returns(true);
     this.MockedSolution.Setup(s => s.Copy()).Returns(this.MockedSolution.Object);
     this.Particle.CurrentSolution = this.MockedSolution.Object;
     SpeedParameters speedParams = new SpeedParameters();
 }
예제 #2
0
 public override void UpdateSpeeds(SpeedParameters parameters)
 {
     for (int index = 0; index < this.CurrentSolution.Parameters.Count; index++)
     {
         Double newSpeed = this.Speeds[index];
         newSpeed = newSpeed + this._CalculateInfluence(this.CurrentSolution.Parameters[index], parameters.PersonalBestSolution[index], parameters.PersonalBestBias, parameters.RandomListPersonal[index]);
         newSpeed = newSpeed + this._CalculateInfluence(this.CurrentSolution.Parameters[index], parameters.GlobalBestSolution[index], parameters.GlobalBestBias, parameters.RandomListGlobal[index]);
         this.Speeds[index] = newSpeed;
     }
 }
예제 #3
0
파일: ClassicSwarm.cs 프로젝트: pcacjr/PSO
 public override void createSpeedParameters()
 {
     foreach (IParticle particle in this.Particles)
     {
         SpeedParameters speedParams = new SpeedParameters();
         speedParams.GlobalBestBias = this.GlobalBestBias;
         speedParams.PersonalBestBias = this.PersonalBestBias;
         speedParams.GlobalBestSolution = new Double[particle.PersonalBestSolution.Parameters.Count];
         this.GlobalBestSolution.Parameters.CopyTo(speedParams.GlobalBestSolution);
         speedParams.PersonalBestSolution = new Double[particle.PersonalBestSolution.Parameters.Count];
         particle.PersonalBestSolution.Parameters.CopyTo(speedParams.PersonalBestSolution);
         speedParams.RandomListGlobal = new List<double>(particle.Speeds.Count);
         speedParams.RandomListPersonal = new List<double>(particle.Speeds.Count);
         for (int i = 0; i < particle.Speeds.Count; i++)
         {
             speedParams.RandomListGlobal.Add(this.RandomGenerator.NextDouble());
             speedParams.RandomListPersonal.Add(this.RandomGenerator.NextDouble());
         }
         particle.SetSpeedParameters(speedParams);
     }
 }
예제 #4
0
 public override void SetSpeedParameters(SpeedParameters parameters)
 {
     this._SpeedParameters = parameters;
 }
예제 #5
0
        public void PrepareClassicParticleTests()
        {
            var mockedSolution = new Mock<ISolution>();
            mockedSolution.Name = "original";
            var copySolution = new Mock<ISolution>();
            copySolution.Name = "copy";
            mockedSolution.Setup(s => s.Fitness).Returns(1.0);
            copySolution.Setup(s => s.Fitness).Returns(2.0);
            mockedSolution.Setup(s => s.Copy()).Returns(copySolution.Object);
            mockedSolution.Setup(s => s.Parameters).Returns(new List<Double>(new Double[3] { 2.0, 3.0, 4.0 }));

            this.MockedSolution = mockedSolution;
            this.CopySolution = copySolution;
            this.Speeds = new List<Double>(new Double[3] { 1.0, 1.0, 1.0 });

            ClassicParticleCreationParameters creationParams = new ClassicParticleCreationParameters();
            creationParams.Speeds = this.Speeds;
            creationParams.Solution = mockedSolution.Object;
            this.Particle = new ClassicParticle(creationParams);

            SpeedParameters speedParams = new SpeedParameters();
            speedParams.GlobalBestBias = 2.0;
            speedParams.PersonalBestBias = 4.0;
            speedParams.PersonalBestSolution = new Double[3] { 3.0, 4.0, 5.0 };
            speedParams.GlobalBestSolution = new Double[3] { 3.0, 4.0, 5.0 };
            speedParams.RandomListGlobal = new List<Double>(new Double[3] { 1.0, 1.0, 1.0 });
            speedParams.RandomListPersonal = new List<Double>(new Double[3] { 1.0, 1.0, 1.0 });
            this.Particle.SetSpeedParameters(speedParams);
        }
예제 #6
0
        public override void UpdateSpeeds(SpeedParameters parameters)
        {
            Double currentInertia = this.CalculateInertia();
            for (int i = 0; i < this.Speeds.Count; i++)
            {
                this.Speeds[i] = this.Speeds[i] * currentInertia;
            }

            base.UpdateSpeeds(parameters);
        }
예제 #7
0
 public override void SetSpeedParameters(SpeedParameters parameters)
 {
     base.SetSpeedParameters(parameters);
 }
예제 #8
0
 public override void SetSpeedParameters(SpeedParameters parameters)
 {
     int removed = this.RandomGenerator.Next(this.ConnectedIds.Count - 3);
     removed = removed + 2;
     this.UpdateConnectedParticles(removed);
     this.CreateConnectedParticlesParameters();
     base.SetSpeedParameters(parameters);
 }
예제 #9
0
 public new void UpdateSpeeds(SpeedParameters parameters)
 {
     Double currentInertia = this.CalculateInertia();
     for (int index = 0; index < this.CurrentSolution.Parameters.Count; index++)
     {
         Double newSpeed = this.Speeds[index];
         newSpeed = newSpeed * currentInertia;
         foreach(List<Double> connectedParameters in this.ConnectedParticlesParameters)
         {
             newSpeed = newSpeed + this._CalculateInfluence(this.CurrentSolution.Parameters[index], connectedParameters[index], parameters.PersonalBestBias/(double)this.ConnectedIds.Count, parameters.RandomListPersonal[index]);
         }
         this.Speeds[index] = newSpeed;
     }
 }
예제 #10
0
파일: Particle.cs 프로젝트: pcacjr/PSO
 public abstract void UpdateSpeeds(SpeedParameters parameters);
예제 #11
0
파일: Particle.cs 프로젝트: pcacjr/PSO
 public abstract void SetSpeedParameters(SpeedParameters parameters);
예제 #12
0
 public void UpdateSpeedsFrankensteinTest()
 {
     SpeedParameters testSpeedParameters= new SpeedParameters();
     testSpeedParameters.RandomListPersonal = new List<double>(new Double[3] { 1.0, 1.0, 1.0 });
     testSpeedParameters.PersonalBestBias = 1.0;
     this.Particle.Speeds = new List<double>(new Double[3] { 0.0, 0.0, 0.0 });
     this.Particle.SetSpeedParameters(testSpeedParameters);
     this.Particle.FinalTopologyUpdate = 4;
     for (int i = 0; i < 4; i++)
     {
         this.Particle.UpdateSpeeds(this.Particle.SpeedParameters);
         foreach(double speed in this.Particle.Speeds)
         {
             Assert.AreEqual(Math.Round(1.0 - (1.0 / (7.0 - i)), 12), Math.Round(speed,12));
         }
         this.Particle.UpdateConnectedParticles(2);
         this.Particle.CreateConnectedParticlesParameters();
         this.Particle.Speeds = new List<double>(new Double[3] { 0.0, 0.0, 0.0 });
     }
 }