Example #1
0
 public virtual void Init(ParticleState particleState, double[] velocity, DimensionBound[] bounds = null)
 {
     CurrentState = particleState;
     PersonalBest = particleState;
     Velocity = velocity;
     Bounds = bounds;
 }
Example #2
0
        public static IParticle Create(PsoParticleType type,
            int locationDim,
            int fitnessDim,
            IFitnessFunction<double[], double[]> function,
            double restartEpsilon = double.MaxValue,
            int iterationsToRestart = int.MaxValue,
            DimensionBound[] bounds = null,
            double[] initVelocity = null
            )
        {
            IParticle particle = null;
            var rand = RandomGenerator.GetInstance();
            switch (type)
            {
                case PsoParticleType.Standard:
                case PsoParticleType.FullyInformed:
                    particle = new StandardParticle(restartEpsilon, iterationsToRestart);
                    break;
                case PsoParticleType.ChargedParticle:
                    particle = new ChargedParticle();
                    break;
                case PsoParticleType.DummyParticle:
                    particle = new DummyParticle();
                    break;
            }

            var x = bounds != null ? rand.RandomVector(locationDim, bounds) : rand.RandomVector(locationDim);
            particle.Init(new ParticleState(x, function.Evaluate(x)),
                initVelocity ?? rand.RandomVector(locationDim, MinInitialVelocity, MaxInitialVelocity), bounds);
            return particle;
        }
Example #3
0
 public double[] RandomVector(int dim, DimensionBound[] bounds)
 {
     lock (_randomLock)
     {
         if (bounds == null) throw new ArgumentNullException();
         var v = new double[dim];
         for (var i = 0; i < dim; i++)
         {
             v[i] = Random.NextDouble() * (bounds[i].Max - bounds[i].Min) + bounds[i].Min;
         }
         return v;
     }
 }
Example #4
0
 public override void Init(ParticleState state, double[] velocity, DimensionBound[] bounds = null)
 {
     CurrentState = _proxy.GpuState;
 }
Example #5
0
 public override void Init(ParticleState state, double[] velocity, DimensionBound[] bounds = null)
 {
 }