A tool for generating synthetic Vehicle Routing Problem (VRP) instances by sampling from OpenStreetMap (OSM) data.
The project contains the following key directories:
scenarios/
: Contains example scenario JSON files that define the input parameters for generating VRP problemspaper_input_models/
: Contains the generated VRP problem files that are created from the scenario files in thescenarios/
directory
- Clone this repository:
git clone https://github.com/yourusername/TAP_TU_SyntheticModelGenerator.git
cd TAP_TU_SyntheticModelGenerator
- Install the required dependencies:
pip install -r requirements.txt
The osm_synthesiser.py
script generates synthetic VRP problems by sampling from OpenStreetMap data. It takes several command-line arguments:
-s, --scenario_file
: Input scenario JSON definition file (required)-o, --output
: Output JSON file (required)-r, --random_seed
: Seed for random number generation (optional)-c, --cache_directory
: OSMnx cache directory (optional, defaults to 'C:\tmp\osmnxcache')-h, --help
: Print help message
python osm_synthesiser.py -s "scenarios/example_scenario.json" -o "paper_input_models/output_problem.json"
python osm_synthesiser.py -s "scenarios/example_scenario.json" -o "paper_input_models/output_problem.json" -r 42
python osm_synthesiser.py -s "scenarios/example_scenario.json" -o "paper_input_models/output_problem.json" -r 42 -c "/tmp"
The input scenario file should be a JSON file with the following structure:
{
"id_prefix": "example",
"place_names": ["London, UK"],
"place_names_choose_one_of": [
["London, UK"],
["Paris, France"],
["Berlin, Germany"]
],
"depot_tags": {
"amenity": "warehouse"
},
"delivery_tags": {
"shop": "supermarket"
},
"pickup_tags": {
"shop": "convenience"
},
"servicing_tags": {
"amenity": "service"
},
"break_locations": {
"amenity": "restaurant"
},
"hub_tags": {
"amenity": "hub"
},
"hub_delivery_tags": {
"shop": "department_store"
},
"hub_pickup_tags": {
"shop": "mall"
},
"target_min_depots": 2,
"target_max_depots": 5,
"target_min_vehicles_per_depot": 3,
"target_max_vehicles_per_depot": 5,
"target_min_break_at_location": 1,
"target_max_break_at_location": 3
}
The script supports two ways to specify place names:
-
Single or Multiple Fixed Places:
- Use the
place_names
field to specify one or more places - Example:
"place_names": ["London, UK", "Manchester, UK"]
- The script will generate a problem that includes locations from all specified places
- This is useful when you want to create a problem spanning multiple cities or regions
- Use the
-
Random Selection from Multiple Options:
- Use the
place_names_choose_one_of
field to specify multiple sets of places - Example:
"place_names_choose_one_of": [ ["London, UK"], ["Paris, France"], ["Berlin, Germany"] ]
- The script will randomly select one set of places from the list
- This is useful for generating different problem instances in different locations
- The selection is deterministic when using the same random seed
- Use the
The scenarios/
directory contains several example scenario files that demonstrate different use cases:
- Basic Urban Delivery Scenario:
{
"id_prefix": "urban_delivery",
"place_names": ["New York, USA"],
"depot_tags": {
"amenity": "warehouse"
},
"delivery_tags": {
"shop": "supermarket"
},
"target_min_depots": 2,
"target_max_depots": 3,
"target_min_vehicles_per_depot": 2,
"target_max_vehicles_per_depot": 4
}
- Multi-City Pickup and Delivery:
{
"id_prefix": "multi_city",
"place_names": ["London, UK", "Manchester, UK"],
"depot_tags": {
"amenity": "warehouse"
},
"pickup_tags": {
"shop": "convenience"
},
"delivery_tags": {
"shop": "supermarket"
},
"target_min_depots": 3,
"target_max_depots": 5,
"target_min_vehicles_per_depot": 3,
"target_max_vehicles_per_depot": 5
}
- Random City Selection:
{
"id_prefix": "random_city",
"place_names_choose_one_of": [
["London, UK"],
["Paris, France"],
["Berlin, Germany"]
],
"depot_tags": {
"amenity": "warehouse"
},
"delivery_tags": {
"shop": "supermarket"
},
"target_min_depots": 2,
"target_max_depots": 3,
"target_min_vehicles_per_depot": 2,
"target_max_vehicles_per_depot": 4
}
The script generates a JSON file containing the synthetic VRP problem with the following structure:
{
"data": {
"jobs": [...],
"vehicles": [...],
"hubs": [...]
},
"_id": "example_42"
}
The generated files are stored in the paper_input_models/
directory, with filenames based on the scenario's id_prefix
and the random seed used.
- The script uses OSMnx to fetch data from OpenStreetMap, so an internet connection is required.
- The cache directory is used to store downloaded OSM data to avoid repeated downloads.
- The random seed can be used to reproduce the same problem instance.
- When using
place_names_choose_one_of
, the script will print the selected place names during execution. - Multiple place names in
place_names
will create a problem that spans across all specified locations. - The script will fetch data for each place name separately and combine them into a single problem instance.
- Example scenarios in the
scenarios/
directory can be used as templates for creating new scenarios. - Generated problem files in
paper_input_models/
can be used as input for VRP solvers.