Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed __pycache__/commuter_model.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/commuter_model.cpython-313.pyc
Binary file not shown.
Binary file removed __pycache__/dqn_agent.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/dqn_agent.cpython-313.pyc
Binary file not shown.
Binary file removed __pycache__/dqn_agent.cpython-314.pyc
Binary file not shown.
Binary file removed __pycache__/mbta_env.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/mbta_env.cpython-313.pyc
Binary file not shown.
Binary file removed __pycache__/mbta_env.cpython-314.pyc
Binary file not shown.
22 changes: 17 additions & 5 deletions env/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,23 @@ def single_color(n):
plt.show()

if __name__ == "__main__":
G = build_graph()

# save graph
graph_path = _os.path.join(_PROJECT_ROOT, "outputs", "mbta_graph.pkl")
with open(graph_path, "wb") as f:
pickle.dump(G, f)

if _os.path.exists(graph_path):
rebuild = input(f"Graph already exists at {graph_path}. Rebuild? (y/n): ").strip().lower()
if rebuild == "y":
G = build_graph()
with open(graph_path, "wb") as f:
pickle.dump(G, f)
print("Graph rebuilt and saved.")
else:
with open(graph_path, "rb") as f:
G = pickle.load(f)
print("Loaded existing graph.")
else:
G = build_graph()
with open(graph_path, "wb") as f:
pickle.dump(G, f)
print("Graph built and saved.")

draw_graph(G)