内容
# Agent-Based Economic Simulation
A dynamic agent-based simulation modeling economic interactions between autonomous agents and limited resources. The system explores resource allocation strategies, price dynamics, and wealth distribution under various economic parameters.
## Key Features
- **Autonomous Agents**:
50 agents with evolving resource needs, income/expense dynamics, and bankruptcy rules
- **Resource Ecosystem**:
3 resources with price elasticity, regeneration patterns, and capacity adaptation
- **Economic Mechanics**:
- Dynamic pricing based on supply/demand
- Tax system with wealth redistribution
- Bankruptcy detection and agent removal
- Resource capacity adaptation to economic output
- **Analysis Tools**:
- Gini coefficient calculation
- Parameter experimentation framework
- Key metric tracking (bankruptcies, balances, prices)
## Getting Started
### Requirements
- Python 3.7+
- NumPy
### Basic Usage
Run full experimentation suite:
```python
python main.py
```
## Code Structure
| File | Purpose |
|--------------------|-------------------------------------------------------------------------|
| `constants.py` | Central configuration of simulation parameters |
| `models.py` | Agent/Resource class definitions with core behaviors |
| `simulation.py` | Main simulation loop and step-by-step execution logic |
| `helpers.py` | Economic calculations and system operations |
| `experimentation.py`| Parameter space exploration and result analysis |
| `main.py` | Entry point for running experiments and viewing results |
## Core Parameters (constants.py)
| Parameter | Description | Default |
|--------------------------------|------------------------------------------------|---------|
| `NUM_AGENTS` | Initial population size | 50 |
| `SIMULATION_STEPS` | Duration of each simulation run | 100 |
| `TAX_RATE` | Wealth redistribution percentage | 2% |
| `PRICE_ELASTICITY` | Demand sensitivity to price changes | 0.05 |
| `RESOURCE_REGEN_RATE` | Base resource regeneration rate | 1% |
| `BANKRUPTCY_THRESHOLD` | Balance level for agent removal | -50 |
| `AGENT_INCOME_CEILING` | Maximum possible agent income | 1.0 |
## Experimentation Insights
The system tests four key parameters across ranges:
1. Price Elasticity (0.01-0.1)
2. Resource Regeneration (0.005-0.02)
3. Tax Rates (0-5%)
4. Expense Rates (10-50%)
Sample findings:
```
Tax rate that minimizes bankruptcies: 0.0278
Regen rate that maximizes average final balance: 0.0189
```
## Key Metrics Tracked
- Average agent balance
- Wealth inequality (Gini coefficient)
- Bankruptcy count
- Resource price stability
- System-wide economic output
## Simulation Flow
1. Price updates based on resource utilization
2. Resource allocation through agent bidding
3. Income distribution and expense deduction
4. Tax collection/redistribution
5. Bankruptcy checks and agent removal
6. Resource regeneration and capacity adjustment
7. Agent behavior adaptation
## Analysis Capabilities
- Parameter sensitivity testing
- Optimal policy identification
- System stability evaluation
- Emergent pattern detection
- Equilibrium state analysis