-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_project.py
194 lines (170 loc) · 5.32 KB
/
setup_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# setup_project.py
import os
import yaml
def create_init_file(path):
"""Create an empty __init__.py file"""
with open(path, 'w') as f:
f.write("# Generated by project setup script\n")
def create_readme():
"""Create README.md with basic project information"""
content = """# MAESTRO: Multi-Agent Adaptive Signal Traffic Reinforcement Optimization
## Overview
This project implements a multi-agent reinforcement learning system to optimize traffic light patterns in a simulated city grid, reducing congestion and improving traffic flow efficiency through cooperative learning.
## Setup
1. Install requirements: `pip install -r requirements.txt`
2. Install SUMO traffic simulator
3. Set up environment variables
## Project Structure
- `config/`: Configuration files
- `data/`: Data files and SUMO networks
- `src/`: Source code
- `experiments/`: Training and evaluation scripts
- `notebooks/`: Analysis notebooks
- `tests/`: Unit tests
## Running the Project
1. Training: `python experiments/train.py`
2. Evaluation: `python experiments/evaluate.py`
## Team
- George Jiang
- Xiang Fu
"""
with open('README.md', 'w') as f:
f.write(content)
def create_requirements():
"""Create requirements.txt with basic dependencies"""
requirements = """torch>=2.0.0
numpy>=1.21.0
pyyaml>=5.4.1
matplotlib>=3.4.3
pandas>=1.3.0
jupyter>=1.0.0
pytest>=6.2.5
sumolib>=1.10.0
traci>=1.10.0
"""
with open('requirements.txt', 'w') as f:
f.write(requirements)
def create_setup():
"""Create setup.py with basic configuration"""
content = """from setuptools import setup, find_packages
setup(
name="maestro",
version="0.1.0",
packages=find_packages(),
install_requires=[
'torch>=2.0.0',
'numpy>=1.21.0',
'pyyaml>=5.4.1',
],
author="George Jiang, Xiang Fu",
description="Multi-Agent Adaptive Signal Traffic Reinforcement Optimization",
keywords="reinforcement-learning, traffic-optimization, multi-agent",
)
"""
with open('setup.py', 'w') as f:
f.write(content)
def create_configs():
"""Create configuration YAML files"""
env_config = {
'sumo': {
'gui': False,
'simulation_steps': 1000,
'grid_size': {'rows': 3, 'cols': 3},
'traffic_density': 0.3
},
'reward': {
'wait_time_weight': 0.6,
'throughput_weight': 0.4
}
}
agent_config = {
'dqn': {
'learning_rate': 0.001,
'gamma': 0.99,
'epsilon_start': 1.0,
'epsilon_end': 0.01,
'epsilon_decay': 0.995,
'batch_size': 32,
'target_update': 10
},
'training': {
'episodes': 1000,
'max_steps': 500
}
}
with open(os.path.join('config', 'env_config.yaml'), 'w') as f:
yaml.dump(env_config, f, default_flow_style=False)
with open(os.path.join('config', 'agent_config.yaml'), 'w') as f:
yaml.dump(agent_config, f, default_flow_style=False)
def create_directory_structure():
"""Create the full directory structure and files"""
# Create main directories
directories = [
'config',
'data/raw',
'data/processed',
'data/sumo_nets',
'src/agents',
'src/environment',
'src/models',
'src/utils',
'experiments/scenarios',
'notebooks',
'tests/test_agents',
'tests/test_environment',
'tests/test_models'
]
for directory in directories:
os.makedirs(directory, exist_ok=True)
# Create __init__.py files
init_locations = [
'config',
'src',
'src/agents',
'src/environment',
'src/models',
'src/utils',
'experiments',
'tests',
]
for location in init_locations:
create_init_file(os.path.join(location, '__init__.py'))
# Create main project files
create_readme()
create_requirements()
create_setup()
create_configs()
# Create empty placeholder files
placeholder_files = [
'data/sumo_nets/basic_grid.net.xml',
'data/sumo_nets/rush_hour.net.xml',
'src/agents/base_agent.py',
'src/agents/dqn_agent.py',
'src/agents/ppo_agent.py',
'src/agents/maddpg_agent.py',
'src/environment/sumo_env.py',
'src/environment/traffic_env.py',
'src/models/dqn_network.py',
'src/models/policy_network.py',
'src/utils/data_collector.py',
'src/utils/logger.py',
'src/utils/replay_buffer.py',
'src/utils/visualization.py',
'experiments/train.py',
'experiments/evaluate.py',
'experiments/scenarios/baseline.py',
'experiments/scenarios/rush_hour.py',
'experiments/scenarios/incident.py',
'notebooks/data_analysis.ipynb',
'notebooks/results_visualization.ipynb',
]
for file in placeholder_files:
with open(file, 'w') as f:
f.write(f"# {os.path.basename(file)}\n# TODO: Implement this module\n")
if __name__ == "__main__":
# Create the project directory if it doesn't exist
os.makedirs("maestro", exist_ok=True)
os.chdir("maestro")
# Create all directories and files
create_directory_structure()
print("Project structure created successfully!")