Skip to content

Commit

Permalink
Added example code that solves two-step routing problems with CFR. (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrasej authored Aug 16, 2023
1 parent 837f66e commit dca66db
Show file tree
Hide file tree
Showing 7 changed files with 3,807 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/two_step_routing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Two-step routing example

This directory contains a Python library that uses the Cloud Fleet Routing (CFR)
API to optimize routes with two-step deliveries: under this model, shipments can
be handled in two ways:
- delivered directly: the vehicle handling the shipment arrives directly to the
final delivery addres.
- delivered through a parking location: when handling the shipment, the vehicle
parks at a specified parking location, while the driver delivers the shipment
by foot.

This library solves the problem by decomposing it into two CFR requests that are
solved using the CFR API, and then combining their solution to build the
combined driving/walking routes.

## Example

```
CLOUD_ACCESS_TOKEN=$(gcloud auth print-access-token)
CLOUD_PROJECT_ID=...
python3 two_step_routing_main.py \
--request=example_request.json \
--parking=example_parking.json \
--project="${CLOUD_PROJECT_ID}" \
--token="${CLOUD_ACCESS_TOKEN}"
```

## License

The example code is licensed under an MIT-style license, see
[LICENSE](../../LICENSE) for details.
Empty file.
26 changes: 26 additions & 0 deletions examples/two_step_routing/example_parking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"parking_locations": [
{
"coordinates": {"latitude": 48.86482, "longitude": 2.34932},
"tag": "P001",
"travel_duration_multiple": 1.1,
"delivery_load_limits": {"ore": 2}
},
{
"coordinates": {"latitude": 48.86482, "longitude": 2.34932},
"tag": "P002",
"travel_mode": 2,
"delivery_load_limits": {"ore": 2}
}
],
"parking_for_shipment": {
"0": "P001",
"1": "P001",
"2": "P001",
"3": "P001",
"4": "P002",
"5": "P002",
"6": "P002",
"7": "P002"
}
}
286 changes: 286 additions & 0 deletions examples/two_step_routing/example_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"model": {
"shipments": [
{
"label": "S001",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86471,
"longitude": 2.34901
}
}
},
"duration": "120s"
}
],
"allowedVehicleIndices": [
0
]
},
{
"label": "S002",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86593,
"longitude": 2.34886
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0
]
},
{
"label": "S003",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86594,
"longitude": 2.34887
}
}
},
"duration": "60s",
"timeWindows": [
{
"startTime": "2023-08-11T12:00:00.000Z"
}
]
}
],
"allowedVehicleIndices": [
0
]
},
{
"label": "S004",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86595,
"longitude": 2.34888
}
}
},
"duration": "60s",
"timeWindows": [
{
"startTime": "2023-08-11T14:00:00.000Z",
"endTime": "2023-08-11T16:00:00.000Z"
}
]
}
],
"allowedVehicleIndices": [
0
]
},
{
"label": "S005",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86596,
"longitude": 2.34889
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0,
1
]
},
{
"label": "S006",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86597,
"longitude": 2.3489
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0,
1
],
"loadDemands": {
"wheat": {
"amount": "3"
},
"ore": {
"amount": "2"
}
}
},
{
"label": "S007",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86597,
"longitude": 2.3489
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0,
1
],
"loadDemands": {
"ore": {
"amount": "1"
},
"wood": {
"amount": "5"
}
}
},
{
"label": "S008",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86597,
"longitude": 2.3489
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0,
1
]
},
{
"label": "S009",
"deliveries": [
{
"arrivalWaypoint": {
"location": {
"latLng": {
"latitude": 48.86597,
"longitude": 2.3489
}
}
},
"duration": "150s"
}
],
"allowedVehicleIndices": [
0,
1
]
}
],
"vehicles": [
{
"label": "V001",
"travelMode": 1,
"travelDurationMultiple": 1,
"costPerHour": 60,
"costPerKilometer": 1,
"startWaypoint": {
"location": {
"latLng": {
"latitude": 48.86321,
"longitude": 2.34767
}
}
},
"endWaypoint": {
"location": {
"latLng": {
"latitude": 48.86321,
"longitude": 2.34767
}
}
},
"startTimeWindows": [
{
"startTime": "2023-08-11T08:00:00.000Z",
"endTime": "2023-08-11T08:00:00.000Z"
}
],
"endTimeWindows": [
{
"startTime": "2023-08-11T16:00:00.000Z",
"endTime": "2023-08-11T21:00:00.000Z"
}
]
},
{
"label": "V002",
"travelMode": 1,
"travelDurationMultiple": 1,
"costPerHour": 60,
"costPerKilometer": 1,
"startWaypoint": {
"location": {
"latLng": {
"latitude": 48.86321,
"longitude": 2.34767
}
}
},
"endWaypoint": {
"location": {
"latLng": {
"latitude": 48.86321,
"longitude": 2.34767
}
}
},
"startTimeWindows": [
{
"startTime": "2023-08-11T08:00:00.000Z",
"endTime": "2023-08-11T08:00:00.000Z"
}
],
"endTimeWindows": [
{
"startTime": "2023-08-11T20:00:00.000Z",
"endTime": "2023-08-11T21:00:00.000Z"
}
]
}
],
"globalStartTime": "2023-08-11T00:00:00.000Z",
"globalEndTime": "2023-08-12T00:00:00.000Z"
},
"searchMode": 1,
"label": "my_little_model",
"parent": "my_awesome_project"
}
Loading

0 comments on commit dca66db

Please sign in to comment.