/** Update particle's velocity and position */ public void update(Swarm swarm, Particle particle) { double position[] = particle.getPosition(); double velocity[] = particle.getVelocity(); double globalBestPosition[] = swarm.getBestPosition(); double particleBestPosition[] = particle.getBestPosition(); // Update velocity and position for (int i = 0; i < position.length; i++) { // Update position position[i] = position[i] + velocity[i]; // Update velocity velocity[i] = swarm.getInertia() * velocity[i] // Inertia + Math.random() * swarm.getParticleIncrement() * (particleBestPosition[i] - position[i]) // Local best + Math.random() * swarm.getGlobalIncrement() * (globalBestPosition[i] - position[i]); // Global best } }