https://github.com/linares222/SMA-simulator.git
Implementation of a multi-agent system simulator with Q-Learning for navigation and foraging environments.
pip install -r requirements.txt
The run.sh script automatically installs dependencies if needed.
The simulator includes an interactive interface that guides the user through all options:
./run.sh
The CLI allows you to configure:
Ctrl+C# farol environment (default)
python -m sma.run farol
# foraging environment
python -m sma.run foraging
# with visualization
python -m sma.run farol --visual
# specify number of episodes
python -m sma.run foraging -e 200
# save results
python -m sma.run farol -o results.csv
sma/
core/ # Base classes (agent, environment, simulator)
- agente_base.py # Abstract agent class
- ambiente_base.py # Abstract environment class
- simulador.py # Simulation engine
- politicas.py # Q-Learning implementation
- sensores.py # Sensor system
- visualizador.py # Graphical visualization
- resultados.py # Metrics management
agentes/ # Agent implementations
- agente_farol.py # Agent for Farol environment
- agente_forager.py # Agent for Foraging environment
ambientes/ # Environment implementations
- farol.py # Farol navigation environment
- foraging.py # Foraging environment
cli.py # Interactive interface (CLI)
comparar_politicas.py # Policy comparison
gerar_analise.py # Analysis and graph generation
loader.py # Simulation loader
main.py # Main entry point
run.py # Simulation script
config_*.json # Configuration files
resultados/ # Exported results (CSV)
analise/ # Generated graphs (PNG)
qtables/ # Saved Q-tables (JSON)
run.sh # Script to run CLI
requirements.txt # Python dependencies
Characteristics:
Characteristics:
The CLI automatically generates configuration based on user choices. It is not necessary to edit JSON files manually.
The config_*.json files define simulation parameters:
modo_execucao: LEARNING or TESTepisodios: Number of episodesmax_passos: Steps per episodevisualizar: true/falseYou can adjust Q-Learning hyperparameters in the JSON config files under each agent's politica section:
{
"agentes": [
{
"politica": {
"tipo": "qlearning",
"alfa": 0.3, // Learning rate (0.1-0.5): higher = faster learning
"gama": 0.9, // Discount factor (0.8-0.99): higher = more long-term planning
"epsilon": 0.2 // Exploration rate (0.05-0.4): higher = more exploration
}
}
]
}
Parameter guidelines:
sma/core/politicas.py with inline comments explaining each parameter.
The simulator automatically generates:
Compare Fixed Intelligent policy with Q-Learning:
# Via CLI (interactive)
./run.sh
# Select "Comparar politicas (Fixa Inteligente vs Q-Learning)"
# Via command line
python -m sma.comparar_politicas config_farol.json --episodios 10
Q-table Management:
sma/qtables/ after training (overwrites existing ones)relatorio.md: Complete technical report on architecture and implementationThe project follows a modular architecture:
To add new environments or agents:
Ambiente or AgenteThe simulator includes a communication system that allows agents to exchange messages:
simulador.enviar_mensagem() sends a message to a specific agentsimulador.broadcast_mensagem() sends a message to all agentsprocessar_comunicacao() to send messages based on events or proximityobter_mensagens()relatorio.md for detailed documentation on the communication system.
This is a project developed for educational purposes.