I am playing around with swarm robotics and trying to figure out a way to simulate it. Here is my dilemma:
I am trying to simulate thousands of agents that will asynchronously communicate with local neighbors to determine an action so a global behavior can be achieved without a centralized logic center. The initial solution to simulate this seems pretty straightforward - each agent is a thread, however, I can't spawn thousands of threads. I also looked into the actor-model framework, but that also does not work since it's single-threaded so I lose the ability for it to be async and whenever an agent is waiting for a signal, it will be thread blocking so other agents will never be able to execute and logic. Any direction will help. Happy to add any clarification. Below is an example of threading. I am trying to create a swarm of 20,000 agents however I cannot create 20,000 threads. I need each agent to run in parallel as that is how it would work with real hardware.
main.py
n = 20000
for i in range(n):
agent = Agent()
agent.start()
# Additional logic to start sending and receiving messages between agents.
agent.py
class Agent(Thread):
def __init__(self):
...
def send_message_to_neighbor(self):
pass
def receive_message(self, message):
pass
error
error: can't start new thread