Last active
January 30, 2019 10:18
-
-
Save jaume-ferrarons/4f06a5eee5a57b1ad63e676e4150e8fa to your computer and use it in GitHub Desktop.
Tutorial: How to optimize routes with SmartMonkey on Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"status": "success", | |
"processing_time": 4647, | |
"job_id": "5c4b0e523ee5ba00168795f6", | |
"solution": { | |
"routes": [ | |
{ | |
"geometry": "qor{FatfLH\\JXPl@XhADJPv@XbAPl@XhA\rAHVJ`@Xe@fBoC`@q@DS@i@^iIIgAK...", | |
"vehicle_id": "Car", | |
"steps": [ | |
{ | |
"dep_time": 0, | |
"type": "start" | |
}, | |
{ | |
"distance": 1744, | |
"dep_time": 3762, | |
"type": "stop", | |
"id": "Arc de triomf", | |
"arr_time": 162 | |
}, | |
{ | |
"distance": 2167, | |
"dep_time": 7581, | |
"type": "stop", | |
"id": "Sagrada Familia", | |
"arr_time": 3981 | |
}, | |
{ | |
"distance": 2884, | |
"dep_time": 11499, | |
"type": "stop", | |
"id": "Parc Guell", | |
"arr_time": 7899 | |
}, | |
{ | |
"distance": 5657, | |
"type": "end", | |
"arr_time": 11964 | |
} | |
] | |
} | |
], | |
"missing": [] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from smartmonkey import Client | |
# Request SmartMonkey API key. Can be obtained at: https://flake.smartmonkey.io | |
api_key = raw_input("* Type your api key: ") | |
client = Client(api_key) | |
# Create one vehicle | |
vehicles = [ | |
{ | |
"id": str("Car"), | |
"start": {'lat': 41.387617, 'lng': 2.169132}, | |
"end": {'lat': 41.380739, 'lng': 2.122924} | |
} | |
] | |
# Provide service descriptions | |
services = [ | |
{ | |
"id": 'Parc Guell', | |
"location": {'lat': 41.413262, 'lng': 2.152945}, | |
"duration": 3600 | |
}, | |
{ | |
"id": 'Sagrada Familia', | |
"location": {'lat': 41.403378, 'lng': 2.173600}, | |
"duration": 3600 | |
}, | |
{ | |
"id": 'Arc de triomf', | |
"location": {'lat': 41.391485, 'lng': 2.180159}, | |
"duration": 3600 | |
} | |
] | |
# Optimize route | |
optimized_route = client.optimize(vehicles, services) | |
# Print result | |
print(optimized_route) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment