/// <summary> /// Retrieves all particles in the same cell as the given particle. Does not include the given particle! /// </summary> /// <param name="particle">Particle identifying the cell to retrieve from</param> /// <returns>All partciles in the same cell</returns> public List<SwarmParticle> GetAdjacentParticlesWithoutGivenParticle(SwarmParticle particle) { Tuple<int, int> cellIndices = ParticlePositionToCellIndices(particle.GetPosition()); List<SwarmParticle> neighbourhood = Mesh[cellIndices.Item1, cellIndices.Item2]; neighbourhood.Remove(particle); return neighbourhood; }
private void UpdateParticleFitness(SwarmParticle particle) { double currentFitness = FitnessStrategy.GetFitness(particle.GetPosition()); double bestFitness = particle.GetOverallBestFitness(); particle.SetCurrentFitness(currentFitness); if (currentFitness < bestFitness) { particle.UpdateFittestValues(currentFitness); } }
private void UpdateParticle(SwarmParticle particle, SwarmParticle fittestNeighbour) { Vector2d Translation = particle.GetTranslation(); Vector2d BestPosition = particle.GetBestLocation(); Vector2d Position = particle.GetPosition(); Translation.X = Translation.X * InertiaWeight + AccelerationConstant * GaussianRandomHelper.GetRandomValue(Mean, StandardDeviation) * (BestPosition.X - Position.X) + AccelerationConstant * GaussianRandomHelper.GetRandomValue(Mean, StandardDeviation) * (fittestNeighbour.GetPosition().X - Position.X); Translation.Y = Translation.Y * InertiaWeight + AccelerationConstant * GaussianRandomHelper.GetRandomValue(Mean, StandardDeviation) * (BestPosition.Y - Position.Y) + AccelerationConstant * GaussianRandomHelper.GetRandomValue(Mean, StandardDeviation) * (fittestNeighbour.GetPosition().Y - Position.Y); particle.SetTranslation(Translation); particle.updatePosition(Translation); UpdateParticleFitness(particle); }
public void AddParticle(SwarmParticle particle) { Tuple<int, int> cellIndices = ParticlePositionToCellIndices(particle.GetPosition()); Mesh[cellIndices.Item1, cellIndices.Item2].Add(particle); ParticleCount++; }
private void UpdateParticleFitness(SwarmParticle particle) { double currentFitness = FitnessStrategy.GetFitness(particle.GetPosition()); if (currentFitness < particle.GetCurrentFitness()) { particle.SetCurrentLocationAsBest(); } particle.SetCurrentFitness(currentFitness); }