10 Built-in Swarm Algorithms
PyBullet Swarm Sim includes a diverse library of foundational and advanced swarm intelligence algorithms. All algorithms implement the BaseAlgorithm interface and generate continuous velocity vectors based on the collective SwarmState.
- Reynolds Boids: The classic flocking model relying on Separation, Alignment, and Cohesion to simulate bird-like flight.
- Formation Flight: A structural planner that maintains precise geometric shapes like Lines, V-shapes, Grids, Rings, and Helices.
- Hover Swarm: A baseline fixed-point station-keeping algorithm to evaluate core physics and PID stability.
- PSO (Particle Swarm Optimization): A search algorithm where drones act as particles converging on a globally optimal target.
- ACO (Ant Colony Optimization): A path-planning strategy where agents lay digital pheromones to discover and reinforce optimal routes.
- Consensus: A distributed algorithm driving the swarm to rendezvous at a shared central point or reach state agreement.
- APF (Artificial Potential Fields): Uses attractive forces toward a goal and repulsive forces from obstacles and peers for dynamic navigation.
- ABC (Artificial Bee Colony): A foraging dynamics model splitting the swarm into Employed, Onlooker, and Scout roles for exploration.
- Voronoi Coverage: Utilizes Lloyd's algorithm to compute spatial Voronoi tessellations, optimally dispersing drones to maximize area coverage.
- MARL (PPO): A Multi-Agent Reinforcement Learning policy trained using parameter-sharing to achieve cooperative, collision-free goal seeking.
Custom Algorithm Upload (.py)
The dashboard provides a powerful feature to test your own experimental algorithms instantly without touching the core codebase or restarting the server. You can upload a custom Python (.py) file directly through the UI.
How it works
- Create a Python file containing a class that inherits from
BaseAlgorithm. - Implement the
compute(self, state)method. - Upload the file in the "Upload Algorithm (.py)" section on the dashboard and click Run.
Your method will receive a SwarmState object every timestep containing the absolute positions and velocities of all drones, and it must return an (N, 3) NumPy array representing the target velocity vectors.
from swarm_sim.algorithms.base_algorithm import BaseAlgorithm
import numpy as np
class MyCustomSwarm(BaseAlgorithm):
def __init__(self, num_drones, **kwargs):
super().__init__(num_drones)
self.speed = 1.0
def compute(self, state):
# state.positions: (N, 3) array of drone absolute (x,y,z) coordinates
# state.velocities: (N, 3) array of drone velocities
target_velocities = np.zeros((self.n, 3))
# Example logic: Command all drones to move straight up
target_velocities[:, 2] = self.speed
return target_velocities