Macro Swarm is a field-based libraries for expressing swarm behaviors in a declarative way. It is built on top of the Aggregate computing framework, which is a distributed computing framework for the JVM. Particularly, it is built of top of ScaFi, a scala library for programming aggregate computing systems. The following simulation are built on top of Alchemist -- a meta-simulator for pervasive like systems.
This is the companion repository for the paper sent at COORDINATION 2023 entitled: MacroSwarm: a Field-based Compositional Framework for Swarm Programming
For running the examples, the simulations and the chart generation, you need to have the following installed:
- A valid JDK installation (>= 11)
- A python installation (>= 3.8)
The examples are located in the src/main/scala/examples folder. Each example has an associated yaml file, which contains the configuration for the Alchemist simulation. In the following we briefly describe how to run each example and what it is the expected result.
For enabling the trace, follow the following video:
Constant movement
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/ConstantMovement | A swarm of agents moving in a straight line | ./gradlew runConstantMovementGraphic |
Explore
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/Explore | A swarm of agents exploring a fixed area | ./gradlew runConstantMovementGraphic |
Obstacle Avoidance
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/ObstacleAvoidance | A swarm that try to avoid obstacles | ./gradlew runObstacleAvoidanceBigGraphic or ./gradlew runObstacleAvoidanceMiddleGraphic or ./gradlew runObstacleAvoidanceGraphic |
Towards Leader
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/TowardsLeader | Nodes go towards a sink point (a leader) | ./gradlew runTowardsLeaderGraphic |
Spin Around a Leader
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/BranchingExample | Nodes spin aroud a leader | ./gradlew runSpinAroundGraphic |
Reynolds Flocking
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/ReynoldFlock | Swarm moving following reynolds rule | ./gradlew runReynoldFlockGraphic |
Team Formation (branching)
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/BranchingExample | Example of team formation through branch | ./gradlew runBranchingExampleGraphic |
Team Formation (logical)
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/TeamFormation | A swarm that create several sub-swarm based on spatial constraints | ./gradlew runTeamFormationGraphic |
Shape Formation
| Example | Description | Command |
|---|---|---|
| src/main/scala/examples/AllShape | A swarm of nodes that form several shapes | ./gradlew runAllShapeGraphic |
For other examples, please refer to the examples folder. For each file, you can run the corresponding example with the following command:
./gradlew run<ExampleName>GraphicWith this API, we propose a use case study highlighting the ability of MacroSwarm to express complex swarm behaviors. In our scenario, we want a fleet of drones to patrol a spatial area of 1km^2. In this environment, dangerous situations may arise (e.g., a fire breaks out, a person gets injured, etc.). In response to these situations, a drone designated as a healer must approach the danger and resolve it. Exploration must be carried out in groups composed of at least one healer and several explorers, who will help the healer identify alarm situations. Initially, 50 explorers and 5 healers are randomly positioned in this area. Each drone has a maximum speed of approximately 20 km/h and a communication range of 100 meters. The alarm situations are randomly generated at different times within the spatial area in a [0, 50] minutes (simulated) timeframe. Each simulation run lasts 90 minutes, during which we expect the number of alarm situations to reach a minimum value
For more details, please refer to the companion paper. For seeing the dynamics of the simulation, you can run the following command:
./gradlew runRescueGraphicIn the following there is a sequence of screenshots of the simulation:
To reproduce the results of the paper, you can run the following command:
./gradlew runRescueBatchThis will launch 64 simulations with different seeds. Each of them, will produce a csv file in the data folder.
In this repository, the data is already loaded,
so you can directly run the following command to generate the plots:
pip install -r requirements.txt
python process.pyThis will produce the following charts stored in charts/:

















