|Home|Quick Start|Sprints|Requirements|Architecture|Server Config|API|GIT|Simulation|Agents|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
Using API
SetUp
The first step to run the simulation is to start the API with all its methods. Running the start_simulation.py
file will start the simulation and use the flask module to run the simulation throughout the 'app' file.
Briefly,
- The
start_simulation.py
file calls the 'app.py' file with the flask method. - On the
app.py
file, the___init___.py
inside the src folder its called and uses the create_app method to run the socket app.
Then the simulation is up and running.
Inside the files
There are some main files inside the communication folder (the folder that contains all the API files), they are:
- listeners.py
- emiters.py
The other files are important and used by the API but very simple and could be replaced
The listeners file contains all the possible messages that the agents must send. Each method correspond to a possible call from the agent.
- The 'handle_connection' method uses a method from the
prepare_action.py
file, wich will verify the action sent from the agent so then, if it passes the verification, will add to a list of actions and send to the simulation. - The 'respond_to_request' method will receive all the requests to connect with the API with two verifications, if the agent passes by both of them, it will be added to the agents list. A response will always be sent to the agents informing if their action was or wasn't done.
- The 'respond_to_request_ready' get the simulation pre-step and send to all the agents that called this method.
All the previously methods uses the 'call_responses' method wich is a handler to send the correct response to the agents using the 'emiters.py' file.
The emiters file contains some methods that do the same stuff but with little changes. Each method in this file will send to the agents a response related to an event. The event is the name of the listener that the agent must have to receive the response. The response contains either the action was successfull or not in some cases, on others it contains the pre step of the simulation, but all they do is send the agents some kind of information.
The other files just do some kind of management to the API.