Giter Club home page Giter Club logo

transportation_simulator's Introduction

An Open-Sourced Network-Based Large-Scale Simulation Platform for Shared Mobility Operations

效果图

Background

Establish an open-sourced network-based simulation platform for shared mobility operations. The simulation explicitly characterizes drivers’ movements on road networks for trip delivery, idle cruising, and en-route pick-up.

Contributions

• We develop a comprehensive, multi-functional and open-sourced simulator for ride-sourcing service, which can be used by both researchers and industrial practitioners on a variety of operational tasks. The proposed simulation platform overcomes a few challenges faced by previous simulators, including the closeness to reality, representation of customers’ and drivers’ heterogeneous behaviors, generalization for different tasks.

• The simulator provide interfaces for the training and testing of different tasks, such as testing of optimization algorithms, training/testing of reinforcement learning based approaches for matching and repositioning, evaluations of economic models for equilibrium analysis and operational strategy designs.

• Based on a vehicle utilization based validation task, some RL based experiments, and one task for theoretical model evaluation, the simulator is validated to be effective and efficient for ride-sourcing related researches. In the future, the simulator can be easily modified for completing other tasks, such as dynamic pricing, ride-pooling service operations, control of shared autonomous vehicles, etc.

Install

  1. Download the code

git clone [email protected]:HKU-Smart-Mobility-Lab/Transportation_Simulator.git

  1. Pull the docker image

docker pull jingyunliu663/simulator

  • after running the code, you can use docker images to check whether the image is available
  • the docker image comes with the conda environment new_simulator and the mongoDB service running in background within the container
  1. Run the docker image & get a docker container
docker run -d -e CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 -v /path/to/the/Transportation_Simulator:/simulator/scripts --name simulator jingyunliu663/simulator
  • Arguments:

    • -d: detach, run in background
    • -v path/to/your/local/file/system:/path/to/your/target/directory/inside/container: This will mount the local directory into the container. Any changes made to the files in this directory within the container will also be reflected on the local host system, and vice versa.
    • --name: name the container as simulator
    • the last argument is the image name (after all, container is a running instance of an image)
  • you can use docker ps to check the running containers

  1. Enter the interactive shell of the conatiner simulator
docker exec -it simultor /bin/bash
  • After enter the interactive shell , you will be in the working directory /simulator, you can navigate yourself to /simulator/scripts directory (the directory you choose to mount to) to run the main function
  • You have to activate the conda environment: conda activate new_simulator

Download Data

Here, we provide you data for Manhattan that we used in our experiments. You can download it from Onedrive.(https://connecthkuhk-my.sharepoint.com/:f:/g/personal/ctj21_connect_hku_hk/EuHy9dMKNy1CkZf5K87GMlYBAI54ZPeGzjanbrpBTZO5CQ?e=95BBYF). And due to the data privacy, we can not provide you the data for Hong Kong and Chengdu.

Survey Data

We conducted a survey in NYC, and one hundred people participated in this survey. The content and results of the questionnaire can be found in the Survey_E-hailing_Taxi_Service_Studies.xlsx file. Hope that this data can help you for your research. And if you use these data in your research, please cite our paper: Feng S., Chen T., Zhang Y., Ke J.* & H. Yang, 2023. A multi-functional simulation platform for on-demand ride service operations. Preprint at ArXiv:2303.12336. https://doi.org/10.48550/arXiv.2303.12336.

File Structure

- simulator
-- input
  -- graph.graphml
  -- order.pickle
  -- driver_info.pickle
-- output
  -- some output files
-- test
  -- test scripts
-- utils
  -- driver_generation.py
  -- find_closest_point.py
  -- handle_raw_data.py
-- dispatch_alg.py
-- simulator_pattern.py
-- simulator_env.py
-- A2C.py
-- sarsa.py
-- main.py
-- config.py
-- LICENSE.md
-- api_doc.md
- readme.md
Data preparing

There are three files in 'input' directory. You can use the driver data and order data provided by us. Also, you can run python handle_raw_data.py to generate orders' information, run python driver_generation.py to generate drviers' information.

In config.py, you can set the parameters of the simulator.

't_initial' # start time of the simulation (s)
't_end'  # end time of the simulation (s)
'delta_t' # interval of the simulation (s) 
'vehicle_speed' # speed of vehicle (km / h)
'repo_speed'  # speed of reposition
'order_sample_ratio' # ratio of order sampling
'order_generation_mode'  # the mode of order generation
'driver_sample_ratio' : 1, # ratio of driver sampling
'maximum_wait_time_mean' : 300, # mean value of maximum waiting time
'maximum_wait_time_std' : 0, # variance of maximum waiting time
"maximum_pickup_time_passenger_can_tolerate_mean":float('inf'),  # s
"maximum_pickup_time_passenger_can_tolerate_std"
"maximum_price_passenger_can_tolerate_mean"
"maximum_price_passenger_can_tolerate_std"
'maximal_pickup_distance'  # km
'request_interval': 5,  #
'cruise_flag' :False, # 
'delivery_mode':'rg',
'pickup_mode':'rg',
'max_idle_time' : 1,
'cruise_mode': 'random',
'reposition_flag': False,
'eligible_time_for_reposition' : 10, # s
'reposition_mode': '',
'track_recording_flag' : True,
'driver_far_matching_cancel_prob_file' : 'driver_far_matching_cancel_prob',
'input_file_path':'input/dataset.csv',
'request_file_name' : 'input/order', #'toy_requests',
'driver_file_name' : 'input/driver_info',
'road_network_file_name' : 'road_network_information.pickle',
'dispatch_method': 'LD', #LD: lagarange decomposition method designed by Peibo Duan
# 'method': 'instant_reward_no_subway',
'simulator_mode' : 'toy_mode',
'experiment_mode' : 'train',
'driver_num':500,
'side':4, # grid side length
'price_per_km':5,  # ¥ / km
'road_information_mode':'load',
'north_lat': 40.8845,
'south_lat': 40.6968,
'east_lng': -74.0831,
'west_lng': -73.8414,
'rl_mode': 'reposition',  # reposition and matching
'method': 'sarsa_no_subway',  #  'sarsa_no_subway' / 'pickup_distance' / 'instant_reward_no_subway'   
'reposition_method' #2C_global_aware',  # A2C, A2C_global_aware, random_cruise, stay  
Real Road Network Module

We use osmnx to acquire the shortest path from the real world. You can set 'north_lat', 'south_lat', 'east_lng' and 'west_lng' in config.py , and you can get road network for the specified region.

Mongodb Module

If your road network is huge, yu can use mongodb to store the road network information and add index on node id which uniquely identifies a node on the road network. You can use the following code to connect your local database route_network and collection route_list which stores the information. After that, you can use find_one interface to achieve the shortest path list easily.

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["route_network"]
mycollect = mydb['route_list']

re_data = {
            'node': str(ori_id) + str(dest_id)
        }
re = mycollect.find_one(re_data)
Price Module

You can set the maximum order price that is normally distributed and acceptable to passengers by modifing maximum_price_passenger_can_tolerate_mean' and maximum_price_passenger_can_tolerate_std.

Cruising and Repositioning Module
Dispatching Module

In dispatch_alg.py, we implement the function LD, we use binary map matching algorithm to dispatch orders.

Experiment

You can modify the parameters in config.py, and then excute python main.py. The records will be recorded in the directory named output.

Tutorials

Technical questions

We welcome your contributions.

Contributors

This simulator is supported by the Smart Mobility Lab at The Univerisity of Hong Kong and Intelligent Transportation Systems (ITS) Laboratory at The Hong Kong University of Science and Technology.

Ownership

The ownership of this repository is Prof. Hai Yang, Dr. Siyuan Feng from ITS Lab at The Hong Kong University of Science and Technology and Dr. Jintao Ke from SML at The Univerisity of Hong Kong.

Citing

If you use this simulator for academic research, you are highly encouraged to cite our paper:

Feng S., Chen T., Zhang Y., Ke J.* & H. Yang, 2023. A multi-functional simulation platform for on-demand ride service operations. Preprint at ArXiv:2303.12336. https://doi.org/10.48550/arXiv.2303.12336

transportation_simulator's People

Contributors

chenhaoling avatar yuhao101 avatar caffretro avatar jingyunliu663 avatar

Stargazers

Shen avatar Yancey avatar Zheng Mingyu avatar  avatar  avatar Xuanlin Zeng avatar liheng avatar  avatar  avatar Simin Chai avatar  avatar Yilun Jin avatar 林越 avatar Jiateng Yin avatar Anke Ye avatar GangwenSi avatar  avatar Shuocheng Guo avatar  avatar  avatar 星巡羽 avatar  avatar Kaihang Zhang avatar  avatar Jintao Ke avatar  avatar  avatar  avatar

Watchers

 avatar

transportation_simulator's Issues

Can you provide the visualization module?

Hi, I saw a really cool visualization on your demo video (https://www.youtube.com/watch?v=q25L7lr77ms).
However, it seems that the only visualization code in this repository is [dynamic_trajectory.py], if I didn't miss something. While this can also visualize the route, it doesn't look so cool or intuitive as the demo video.
So, can you provide the visualization module? Or show me some guide on how to achieve it?

Would you consider adding more description on the code?

Hi, we have a strong interest in your simulation platform, and I have read the paper. I can roughly get the idea of the framework. However, would you consider adding more description on each module function? For example, the description of simulator_env and how it relates to each part. How the RL algorithm is implemented on the simulation part. And there are not too much comments in the code, which makes it a bit hard to read and understand. Would you consider systematically organizing the code and adding more comments? I think this can also help others to access and to enlarge the influence of your platform.

Could you please provide a description about all the packages and versions?

Hi authors,

I tried to run the simulator, but it seems that I am in a wrong version of python/tensorflow/azureml-core combination.

I am using python3.11.5, tensorflow 2.12.0 and azureml-core 1.53.0. These versions create a conflict that, tensorflow 2.12.0 requires urllib3 2.0.5, but azureml-core 1.53.0 requires urllib<2.

Maybe you can help me by telling me what your versions are to ensure smooth running.

Thanks.

Support GPU acceleration?

Hello authors,

Thanks for your patience in helping me running your simulator! It now works OK, but an epoch may take ~900s on CPU. I wonder whether your code can support GPU acceleration (or has supported?)

Reward and matched orders all 0 in 'matching' mode.

Hi authors,

As per your suggestion I debugged the matching mode. Now it can run. However, after several hundreds of epochs, I still receive 0 rewards and 0 matched orders. Is that normal? If not, what can be modified to fix it?

Here are the system messages:

epoch: 1276
epoch running time:  12.907965183258057
epoch total reward:  0
total orders 57.0000001
matched orders 1e-07
step1:order dispatching: 0.03428983688354492
step2:reaction 0.16186165809631348
step3:bootstrap new orders: 0.2233142852783203
step4:cruise: 10.932743549346924
step4_1:track_recording 0.6921463012695312
step5:update state 0.48050379753112793
step6:offline update 0.37604355812072754
step7: update time 9.584426879882812e-05
epoch: 1277
epoch running time:  13.268260955810547
epoch total reward:  0
total orders 63.0000001
matched orders 1e-07
step1:order dispatching: 0.03837323188781738
step2:reaction 0.16072487831115723
step3:bootstrap new orders: 0.2405104637145996
step4:cruise: 11.218846082687378
step4_1:track_recording 0.6832997798919678
step5:update state 0.5146937370300293
step6:offline update 0.40406155586242676
step7: update time 9.036064147949219e-05

I use the following config.py. I think I just modified 'rl_mode' to matching, and nothing else.

env_params = {
't_initial' :36000,
't_end' : 36100,
'delta_t' : 5,  # s
'vehicle_speed' : 22.788,   # km / h
'repo_speed' : 1, #目前的设定需要与vehicle speed保持一致
'order_sample_ratio' : 1,
'order_generation_mode' : 'sample_from_base',
'driver_sample_ratio' : 1,
'maximum_wait_time_mean' : 300,
'maximum_wait_time_std' : 0,
"maximum_pickup_time_passenger_can_tolerate_mean":float('inf'),  # s
"maximum_pickup_time_passenger_can_tolerate_std":0, # s
"maximum_price_passenger_can_tolerate_mean":float('inf'), # ¥
"maximum_price_passenger_can_tolerate_std":0,  # ¥
'maximal_pickup_distance' : 1,  # km
'request_interval': 5,  #
'cruise_flag' :False,
'delivery_mode':'rg',
'pickup_mode':'rg',
'max_idle_time' : 1,
'cruise_mode': 'random',
'reposition_flag': False,
'eligible_time_for_reposition' : 10, # s
'reposition_mode': '',
'track_recording_flag' : True,
'driver_far_matching_cancel_prob_file' : 'driver_far_matching_cancel_prob',
'input_file_path':'input/dataset.csv',
'request_file_name' : 'input/order', #'toy_requests',
'driver_file_name' : 'input/driver_info',
'road_network_file_name' : 'road_network_information.pickle',
'dispatch_method': 'LD', #LD: lagarange decomposition method designed by Peibo Duan
# 'method': 'instant_reward_no_subway',
'simulator_mode' : 'toy_mode',
'experiment_mode' : 'train',
'driver_num':500,
'side':10,
'price_per_km':5,  # ¥ / km
'road_information_mode':'load',
'price_increasing_percentage': 0.2,
'north_lat': 40.8845,
'south_lat': 40.6968,
'east_lng': -74.0831,
'west_lng': -73.8414,
'rl_mode': 'matching',  # reposition and matching
'method': 'sarsa_no_subway',  #  'sarsa_no_subway' / 'pickup_distance' / 'instant_reward_no_subway'   #  rl for matching
'reposition_method': 'A2C_global_aware',  # A2C, A2C_global_aware, random_cruise, stay  # rl for repositioning
'dayparting': True, # if true, simulator_env will compute information based on time periods in a day, e.g. 'morning', 'afternoon'
}
wait_time_params_dict = {'morning': [2.582, 2.491, 0.026, 1.808, 2.581],
                    'evening': [4.862, 2.485, 0, 1.379, 13.456],
                    'midnight_early': [0, 2.388, 2.972, 2.954, 3.14],
                    'other': [0, 2.017, 2.978, 2.764, 2.973]}

pick_time_params_dict = {'morning': [1.877, 2.018, 2.691, 1.865, 6.683],
                    'evening': [2.673,2.049,2.497,1.736,9.208],
                    'midnight_early': [3.589,2.319,2.185,1.664,9.6],
                    'other': [0,1.886,4.099,3.185,3.636]}

price_params_dict = {'short': [1.245,0.599,10.629,10.305,0.451],
                    'short_medium': [0.451,0.219,19.585,58.407,0.18],
                    'medium_long': [14.411,4.421,11.048,9.228,145],
                    'long': [15.821,3.409,0,16.221,838.587]}

# price_increase_params_dict = {'morning': [0.001,1.181,3.583,4.787,0.001],
#                     'evening': [0,1.21,2.914,5.023,0.013],
#                     'midnight_early': [1.16,0,0,6.366,0],
#                     'other': [0,2.053,0.857,4.666,1.961]}
#  rl for matching
# global variable and parameters for sarsa
START_TIMESTAMP = 36000  # the start timestamp
LEN_TIME_SLICE = 5  # the length of a time slice, 5 minute (300 seconds) in this experiment
LEN_TIME = 100 # 3 hours
NUM_EPOCH = 4001  # 4001 / 3001
FLAG_LOAD = False
sarsa_params = dict(learning_rate=0.005, discount_rate=0.95)  # parameters in sarsa algorithm
#  rl for matching

# rl for repositioning
# hyperparameters for rl
# NUM_EPOCH = 101
STOP_EPOCH = 100
DISCOUNT_FACTOR = 0.95
ACTOR_LR = 0.001
CRITIC_LR = 0.005
ACTOR_STRUCTURE = [64,128] # s[16, 32] for A2C, and [64, 128] for A2C global aware
CRITIC_STRUCTURE = [64,128]
# rl for repositioning


#  rl for matching
# parameters for exploration
INIT_EPSILON = 0.9
FINAL_EPSILON = 0
DECAY = 0.997
PRE_STEP = 0
#  rl for matching

#  rl for matching
# TRAIN_DATE_LIST = ['2015-07-06', '2015-07-07', '2015-07-08', '2015-07-09', '2015-07-10',
#                    '2015-07-13', '2015-07-14', '2015-07-15', '2015-07-16', '2015-07-17'
#                    ]
TRAIN_DATE_LIST = ['2015-05-04', '2015-05-05', '2015-05-06', '2015-05-07', '2015-05-08', '2015-05-11', '2015-05-12', '2015-05-13', '2015-05-14', '2015-05-15', '2015-05-18']

TEST_DATE_LIST = ['2015-07-27', '2015-07-28', '2015-07-29', '2015-07-30', '2015-07-31']
#  rl for matching

Missing file under 'matching' mode

Hi authors,

I tried to study matching, and so I set 'rl_mode' to 'matching' in config.py.

Now, when I start to run python3 simulator/main.py, an error popped out

Traceback (most recent call last):
  File "simulator/main.py", line 256, in <module>
    pickle.dump(simulator.record,open("output3/order_record-1103.pickle","wb"))
FileNotFoundError: [Errno 2] No such file or directory: 'output3/order_record-1103.pickle'

It seems that an important file is missing for running matching. Could you please check?

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.