Code Monkey home page Code Monkey logo

colight's Introduction

CoLight

This repository is provided as-is, further updates are included in LibSignal, which supports flexible and cross-platform (CityFlow and SUMO) training and testing in PyTorch. We also actively looking for contributions for LibSignal, feel free to reach out if you would love to contribute to the project!

CoLight is a reinforcement learning agent for network-level traffic signal control.

@inproceedings{colight,
 author = {Wei, Hua and Xu, Nan and Zhang, Huichu and Zheng, Guanjie and Zang, Xinshi and Chen, Chacha and Zhang, Weinan and Zhu, Yamin and Xu, Kai and Li, Zhenhui},
 title = {CoLight: Learning Network-level Cooperation for Traffic Signal Control},
 booktitle = {Proceedings of the 28th ACM International Conference on Information and Knowledge Management},
 series = {CIKM '19},
 year = {2019},
 location = {Beijing, China}
} 

It shares the similar code structure with PressLight (PressLight: Learning Max Pressure Control to Coordinate Traffic Signals in Arterial Network) from KDD 2019.

Usage and more information can be found below.

Usage

How to run the code:

We recommend to run the code through docker. Some brief documentation can be found at https://docs.docker.com/.

  1. Please build a docker image using the dockerfile provided.

sudo docker pull hzw77/colight:v0.1

  1. Pull the codes for CoLight. git clone https://github.com/wingsweihua/colight.git

  2. Please run the built docker image to initiate a docker container. Please remember to mount the code directory.

sudo docker run -it -v /path/to/your/workspace/colight/:/colight/ --shm-size=8gb --name hua_colight hzw77/colight:v0.1 /bin/bash

cd colight

(Alternatively, you can install the packages (included in the dockerfile) on your linux system)

Start an experiment by:

python -O runexp.py

Here, -O option cannot be omitted unless debug is necessary. In the file runexp.py, the args can be changed.

  • runexp.py

    Run the pipeline under different traffic flows. Specific traffic flow files as well as basic configuration can be assigned in this file. For details about config, please turn to config.py.

For most cases, you might only modify traffic files and config parameters in runexp.py.

Dataset

  • synthetic data

    Traffic file and road networks can be found in data/1_3 && data/3_3 && data/6_6 && data/10_10.

  • real-world data

    Traffic file and road networks of New York City can be found in data/NewYork, it contains two networks at different scale: 196 intersection and 48 intersections. Jinan and Hangzhou dataset are also included.

Agent

  • agent.py

    An abstract class of different agents.

  • CoLight_agent.py

    Proposed CoLight agent

Others

More details about this project are demonstrated in this part.

  • config.py

    The whole configuration of this project. Note that some parameters will be replaced in runexp.py while others can only be changed in this file, please be very careful!!!

  • pipeline.py

    The whole pipeline is implemented in this module:

    Start a simulator environment, run a simulation for certain time(one round), construct samples from raw log data, update the model and model pooling.

  • generator.py

    A generator to load a model, start a simulator enviroment, conduct a simulation and log the results.

  • anon_env.py

    Define a simulator environment to interact with the simulator and obtain needed data like features.

  • construct_sample.py

  • Construct training samples from original data. Select desired state features in the config and compute the corrsponding average/instant reward with specific measure time.

  • updater.py

    Define a class of updater for model updating.

colight's People

Contributors

wingsweihua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

colight's Issues

error in CoLight_agent.py

after running the line neighbor_repr = Lambda(lambda x: K.batch_dot(x[0], x[1]))([In_neighbor, neighbor_repr]) in CoLight_agent.py, neighbor_repr.shape = (?, 36, 5, 36, 32), which makes ValueError: total size of new array must be unchanged.
Thank you for your attention!
image

How do you set the parameters of the multihead attention?

How did you set the parameters of the multihead attention?
I tried to set CNN_heads=[5]*len(CNN_layers) and also tried to set embeding dim to [160,160],but the travel time can only achieve to 176.82,174.08,not around 170
Do I need to set more than one GAT layers? Could you please tell me something about the parameters?I would appreciate it if you could help me.

dynamic_attention_datasets

hello,
I see the code in runexp.py,which contains a dataset named"dynamic attention",but I can find the files.Where can I download the datasets?

Thanks!

model pool evaluation fail with FileNotFoundError (sumo_env.conf)

============== model pool evaluation =============
========================================================in model_pool_wrapper print dic_exp_conf
{'RUN_COUNTS': 3600, 'TRAFFIC_FILE': ['anon_6_6_300_0.3_bi.json'], 'MODEL_NAME': 'CoLight', 'NUM_ROUNDS': 60, 'NUM_GENERATORS': 4, 'LIST_MODEL': ['Fixedtime', 'SOTL', 'Deeplight', 'SimpleDQN'], 'LIST_MODEL_NEED_TO_UPDATE': ['Deeplight', 'SimpleDQN', 'CoLight', 'GCN', 'SimpleDQNOne', 'Lit'], 'MODEL_POOL': True, 'NUM_BEST_MODEL': 3, 'PRETRAIN': False, 'PRETRAIN_MODEL_NAME': 'CoLight', 'PRETRAIN_NUM_ROUNDS': 0, 'PRETRAIN_NUM_GENERATORS': 15, 'AGGREGATE': False, 'DEBUG': False, 'EARLY_STOP': False, 'MULTI_TRAFFIC': False, 'MULTI_RANDOM': False, 'ROADNET_FILE': 'roadnet_6_6.json'}
{'RUN_COUNTS': 3600, 'TRAFFIC_FILE': ['anon_6_6_300_0.3_bi.json'], 'MODEL_NAME': 'CoLight', 'NUM_ROUNDS': 60, 'NUM_GENERATORS': 4, 'LIST_MODEL': ['Fixedtime', 'SOTL', 'Deeplight', 'SimpleDQN'], 'LIST_MODEL_NEED_TO_UPDATE': ['Deeplight', 'SimpleDQN', 'CoLight', 'GCN', 'SimpleDQNOne', 'Lit'], 'MODEL_POOL': True, 'NUM_BEST_MODEL': 3, 'PRETRAIN': False, 'PRETRAIN_MODEL_NAME': 'CoLight', 'PRETRAIN_NUM_ROUNDS': 0, 'PRETRAIN_NUM_GENERATORS': 15, 'AGGREGATE': False, 'DEBUG': False, 'EARLY_STOP': False, 'MULTI_TRAFFIC': False, 'MULTI_RANDOM': False, 'ROADNET_FILE': 'roadnet_6_6.json'}
Start testing model pool
Process Process-1:313:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/opt/conda/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/colight/pipeline.py", line 218, in model_pool_wrapper
model_pool.model_compare(cnt_round)
File "/colight/model_pool.py", line 179, in model_compare
dic_sumo_env_conf = json.load(open(os.path.join(records_dir, "sumo_env.conf"), "r"))
FileNotFoundError: [Errno 2] No such file or directory: 'records/0515_afternoon_Colight_6_6_bi/anon_6_6_300_0.3_bi.json_04_30_07_15_44/sumo_env.conf'
model_pool to join
model_pool finish join

the available conf files in the folder are as follow:

records/0515_afternoon_Colight_6_6_bi/anon_6_6_300_0.3_bi.json_04_30_07_15_44/agent.conf
records/0515_afternoon_Colight_6_6_bi/anon_6_6_300_0.3_bi.json_04_30_07_15_44/exp.conf
records/0515_afternoon_Colight_6_6_bi/anon_6_6_300_0.3_bi.json_04_30_07_15_44/test_exp.conf
records/0515_afternoon_Colight_6_6_bi/anon_6_6_300_0.3_bi.json_04_30_07_15_44/traffic_env.conf

Questino about how to get the performance

Paper: "Table 2: Performance on synthetic data and real-world data w.r.t average travel time. CoLight is the best"

In the code, to get the att(average travel time), run the summary_multi_anon.py and get data from file and then calculate the att.

But I find we can get it from CityFlow.eng: self.eng.get_average_travel_time(). Why not use that as att result? Is there a diff?

"write roadnet file error"

hello, i wonder whether you implement the data generation of roadnetLogFile and replayLogFile. After i run runexp.py, an error information "write roadnet file error" appears. Thanks a lot

replay does not work.

Hello. I have a few questions.

First,
The index.html file on the frontend does not work. So I used the index.html file in cityflow.
Can I use the index.html in colight normally?

second,
When replay is executed with the index.html file in cityflow,
The number of steps and vehicles increase, but no vehicles are visible.

How can I fix it?

Third,
Is there a reference for colight's learning mechanism?

Thanks.

RuntimeError: Json parsing error

I encountered a very strange thing. The first time I reproduced the code, I did not encounter this error, but the second time, I encountered:
Traceback (most recent call last):
File "/home/user/.conda/envs/traffic/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/user/.conda/envs/traffic/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/data1/user/colight/pipeline.py", line 189, in generator_wrapper
best_round=best_round
File "/data1/user/colight/generator.py", line 31, in init
self.env.reset()
File "/data1/user/colight/anon_env.py", line 822, in reset
self.eng = engine.Engine(new_path, thread_num=1)
RuntimeError: Json parsing error

I feel very puzzled. I have looked at the homepage of cityflow ,and the configuration file for cityflow.Engine() should be right. Why does it indicate 'RuntimeError: Json parsing error'? Does any friend help me ?I would appreciate it !

Question about the MIN_ACTION_TIME

what is the value of MIN_ACTION_TIME when in Table2 Performance?

MIN_ACTION_TIME in run_baseline.py got 2 values(10, 20). in updater.py is 10 and in anon_env.py is 10. So when you are compare diff method, the value of MIN_ACTION_TIME is 10, right?

Do you have summary file for Cityflow engine?

I just found summary.py for SUMO which reads the results as .xml. When I change .xml into .json and try to plot, I got samples with all None. So could you upload a summary file for Cityflow engine? Thanks a lot.

Frontend problem

Is it since the files in frontend can't work?
Some configuration files are missing
image

KeyError: 'CNN_layers'

When run CoLight_agent.py.

  File "CoLight_agent.py", line 66, in __init__
    self.CNN_layers=dic_agent_conf['CNN_layers']
KeyError: 'CNN_layers'

About pretraining

The code of pretraining seems to be Incomplete. how could I use the pretraining correctly?

open empty log file

There always exist EOFError.
pipline.py 228
logging_data = pickle.load(f_logging_data)
EOFError: Ran out of input

road network data

hello,your experience use the jinan and hangzhou roaddata。But, why the road network data is same as the 3x4 simulated data。 the intersection instance and the lanes number is same。

Replay file is not getting generated

Hi Even after setting "SAVEREPLAY": "True" at all possible places, replay file is not being created. Could you please help what should I do to save it?

quick question, multi-agent or single agent?

Hi, Hua Wei. Thanks for your great project.
Colight is multi-agent (number of agents = number of intersections, each agent control one intersection) or single agent (one agent control all intersections)?

Not display vehicle

I used the index.html in CityFlow repository to simulater the result from "python -O runexp.py". But I don't see any vehicle which show in CityFlow although "number of vehicle" and "Step" work normally.

Questions About Intersection/Road Id Settings When Reproducing `CoLight`

Hi, I am trying to reproduce the CoLight experiment on Hangzhou_4x4_real dataset and I have some questions about the detailed implementation of index setting in anon_env.py.

An Example of the intersection information in the road net is shown below:

inter_id: (1, 1)
inter_name: intersection_1_1
dic_entering_approach_to_edge: {'W': 'road_0_1_0', 'E': 'road_2_1_2', 'N': 'road_1_0_1', 'S': 'road_1_2_3'}
dic_exiting_approach_to_edge: {'W': 'road_1_1_2', 'E': 'road_1_1_0', 'N': 'road_1_1_1', 'S': 'road_1_1_3'}
list_entering_lanes: ['road_0_1_0_0', 'road_0_1_0_1', 'road_0_1_0_2', 'road_2_1_2_0', 'road_2_1_2_1', 'road_2_1_2_2', 'road_1_0_1_0', 'road_1_0_1_1', 'road_1_0_1_2', 'road_1_2_3_0', 'road_1_2_3_1', 'road_1_2_3_2']
list_exiting_lanes: ['road_1_1_2_0', 'road_1_1_2_1', 'road_1_1_2_2', 'road_1_1_0_0', 'road_1_1_0_1', 'road_1_1_0_2', 'road_1_1_1_0', 'road_1_1_1_1', 'road_1_1_1_2', 'road_1_1_3_0', 'road_1_1_3_1', 'road_1_1_3_2']
neighbor_ENWS: ['intersection_2_1', 'intersection_1_2', None, None]

Question 1:
The ids of intersections are identified as Intersection_i_j. Inferred based on the example, i refers to the column index and j refers to the row index. However, in 'anon_env.py', i is defined as row index and j is defined as i index. Check

colight/anon_env.py

Lines 827 to 830 in 8772ac1

self.list_intersection = [Intersection((i+1, j+1), self.dic_traffic_env_conf, self.eng,
self.traffic_light_node_dict["intersection_{0}_{1}".format(i+1, j+1)],self.path_to_log)
for i in range(self.dic_traffic_env_conf["NUM_ROW"])
for j in range(self.dic_traffic_env_conf["NUM_COL"])]

Question 2:
Pairs (i, j) in dic_entering_approach_to_edge and neighbor_ENWS do not match well. That is, N in dic_entering_approach_to_edge is 'road_1_0_1', sent from virtual intersection 'Intersection_1_0' and N in neighbor_ENWS indicates 'intersection_1_2'.

Thank you very much. A quick response will be appreciated a lot.

The file 'vehicle_inter_{i}.csv' is not appearing.

Hello, I would like to inquire about a situation that occurs after running the 'runexp.py' file. Around round 64, there is an error stating that the file 'vehicle_inter_{i}.csv' does not exist. Is this normal?

Results on Colight and dqn

I conducted experiments using dqn and colight methods on a 6x6 network, and the final results were as follows:
Dqn: Final Travel Time is 214.5438, mean rewards: -14.1031, queue: 0.4005, delay: 0.0308, throughput: 4652 Total time token: 18397.876304388046
Colight: Final Travel Time is 206.8853, mean rewards: -4.6692, queue: 0.1022, delay: 0.0111, throughput: 4650 Total time token: 16563.93673968315

It seems that there is not much difference in the results between the two methods. Is it my mistake in implementing the method?

Reproducing colight's results

Hi,

I would like to reproduce the results you have published in your article. I cloned your repo and ran all default configurations:
python -O runexp.py

I guess the model it runs by default has the following configurations, (please correct me if I am wrong):

Scenario: Grid 6x6 bidirectional
Model Colight
Rounds: 100
Count: 3600

Afterwards, I moved the records/<experiment_folder> folder to records/initial/<experiment_folder> and ran:

python summary_multi_anon.py

I was expecting to find 170.11 travel time but got ave. duration 182.72. Is the reported travel time on the article the same thing as ave. duration? The difference is relatively small, but I just would like to confirm that I am doing the right thing. Am I?

install

Do you still need to download the dependency package in requirements again after Git?

CUDA_OUT_OF_MEMORY

Did you meet the conditions that: CUDA_OUT_OF_MEMORY when using GPU to train the agent.
It seems that the GPU can't release the memory right away after training one agent.
But how could I solve it?

Empty Repository

Hello,
I read your paper and wanted to reproduce results for my research and found this repository. But it is empty. Could you guide me on how I can reproduce results?

run LitAgent method

When I changed the argument mod to Lit instead of CoLight in the runexp.py, the code will report an error. May I ask how should I do some modifications so that I can successfully run LitAgent method?

A quick question about the datasets

Hi,

I notice that there are three volumns of Hangzhou datasets as well as Jinan datasets in the data folder.

Hangzhou:

  • anon_4_4_hangzhou_real.json
  • anon_4_4_hangzhou_real_5734.json
  • anon_4_4_hangzhou_real_5816.json

Jinan

  • anon_3_4_jinan_real_2000.json
  • anon_3_4_jinan_real_2500.json
  • anon_3_4_jinan_real.json

It is not very clear which ones were being measured in the performance table (i.e., Table 2) of your paper.

table

Thanks a lot.

Colight is empty

Hello.
I follow the Docker steps, but my colight file is empty.

Like this:(The steps 1, 2 and 3 have been finished)

root@ca3f1103b7ab:/# cd colight/
root@ca3f1103b7ab:/colight# ls
root@ca3f1103b7ab:/colight#

Can someone give me some points please?
Thanks

How to run other algorithms?

Thanks for your project.
Here I want to know how I can run other algorithms, such as SimpleDQN.
When I ran it, I always got these errors:
"AttributeError: ' SimpleDQNAgent' object has no attribute 'q_ network '".
But I didn't how to save it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.