# Solve a route optimization problem Start by reading the introduction to the Route Optimization API. To solve a new vehicle routing problem, make a HTTP POST to this URL It returns the solution to this problem in the JSON response. Please note that this URL is very well suited to solve minor problems. Larger vehicle routing problems, which take longer than 10 seconds to solve, cannot be solved. To solve them, please use the batch mode URL instead. Endpoint: POST /vrp Version: 1.0.0 Security: api_key ## Request fields (application/json): - `vehicles` (array) Specifies the available vehicles. - `vehicles.vehicle_id` (string, required) Specifies the ID of the vehicle. Ids must be unique, i.e. if there are two vehicles with the same ID, an error is returned. Example: "vehicle-1" - `vehicles.type_id` (string) The type ID assigns a vehicle type to this vehicle. You can specify types in the array of vehicle types. If you omit the type ID, the default type is used. The default type is a with a capacity of 0. Example: "my-own-type" - `vehicles.shifts` (array) Array of shifts. - `vehicles.shifts.shift_id` (string) A unique identifier for this vehicle's shift. - `vehicles.shifts.start_address` (object) - `vehicles.shifts.start_address.location_id` (string, required) Specifies the id of the location. Example: "550e8400-e29b-11d4-a716-446655440000" - `vehicles.shifts.start_address.name` (string) Name of location. Example: "Queens Victoria Street 70, Second Floor, Flat 245" - `vehicles.shifts.start_address.lon` (number, required) Longitude of location. Example: -0.092869 - `vehicles.shifts.start_address.lat` (number, required) Latitude of location. Example: 51.512665 - `vehicles.shifts.start_address.street_hint` (string) Optional parameter. Provide a hint that includes only the street name for each address to better snap the coordinates (lon,lat) to road network. E.g. if there is an address or house with two or more neighboring streets you can control for which street the closest location is looked up. Example: "Queens Victoria Street 70" - `vehicles.shifts.start_address.curbside` (string) Optional parameter. Specifies on which side a point should be relative to the driver when she leaves/arrives at a start/target/via point. Only supported for motor vehicles and OpenStreetMap. Enum: "right", "left", "any" - `vehicles.shifts.end_address` (object) If this is omitted AND return_to_depot is true then the vehicle needs to return to its start_address. - `vehicles.shifts.earliest_start` (integer) Earliest start of vehicle in seconds. It is recommended to use the unix timestamp. - `vehicles.shifts.latest_end` (integer) Latest end of vehicle in seconds, i.e. the time the vehicle needs to be at its end location at latest. - `vehicles.shifts.return_to_depot` (boolean) If true, vehicle returns to its start location (or specified end location). If false, vehicle can end at any customer location that optimizes the objective function. - `vehicles.shifts.break` (any) - `vehicles.return_to_depot` (boolean) If it is false, the algorithm decides where to end the vehicle route. It ends in one of your customers' locations. The end is chosen such that it contributes to the overall objective function, e.g. min transport_time. If it is true, you can either specify a specific end location (which is then regarded as end depot) or you can leave it and the driver returns to its start location. - `vehicles.skills` (array) Array of skills, i.e. array of string (not case sensitive). Example: ["drilling_mashine","screw_driver"] - `vehicles.max_distance` (integer) Specifies the maximum distance (in meters) a vehicle can go. Example: 400000 - `vehicles.max_driving_time` (integer) Specifies the maximum drive time (in seconds) a vehicle/driver can go, i.e. the maximum time on the road (service and waiting times are not included here) Example: 28800 - `vehicles.max_jobs` (integer) Specifies the maximum number of jobs a vehicle can load. Example: 12 - `vehicles.min_jobs` (integer) Specifies the minimum number of jobs a vehicle should load. This is a soft constraint, i.e. if it is not possible to fulfill “min_jobs”, we will still try to get as close as possible to this constraint. Example: 12 - `vehicles.max_activities` (integer) Specifies the maximum number of activities a vehicle can conduct. Example: 24 - `vehicles.move_to_end_address` (boolean) Indicates whether a vehicle should be moved even though it has not been assigned any jobs. - `vehicle_types` (array) Specifies the available vehicle types. These types can be assigned to vehicles. - `vehicle_types.type_id` (string, required) Specifies the id of the vehicle type. If a vehicle needs to be of this type, it should refer to this with its type_id attribute. Example: "my-own-type" - `vehicle_types.profile` (string) The routing profile. It determines the network, speed and other physical attributes used when computing the route. See the section about [routing profiles](#tag/Map-Data-and-Routing-Profiles) for more details and valid profile values. - `vehicle_types.capacity` (array) Specifies an array of capacity dimension values which need to be int values. For example, if there are two dimensions such as volume and weight then it needs to be defined as [ 1000, 300 ] assuming a maximum volume of 1000 and a maximum weight of 300. Example: [100,500] - `vehicle_types.speed_factor` (number) Specifies a speed factor for this vehicle type. If the vehicle that uses this type needs to be only half as fast as what is actually calculated with our routing engine then set the speed factor to 0.5. - `vehicle_types.service_time_factor` (number) Specifies a service time factor for this vehicle type. If the vehicle/driver that uses this type is able to conduct the service as double as fast as it is determined in the corresponding service or shipment then set it to 0.5. - `vehicle_types.cost_per_meter` (number) ! Cost parameter per distance unit, here meter is used - `vehicle_types.cost_per_second` (number) ! Cost parameter per time unit, here second is used - `vehicle_types.cost_per_activation` (number) ! Cost parameter vehicle activation, i.e. fixed costs per vehicle - `vehicle_types.consider_traffic` (boolean) Specifies whether traffic should be considered. if "tomtom" is used and this is false, free flow travel times from "tomtom" are calculated. If this is true, historical traffic info are used. We do not yet have traffic data for "openstreetmap", thus, setting this true has no effect at all. - `vehicle_types.network_data_provider` (string) Specifies the network data provider. Either use [](#tag/Map-Data-and-Routing-Profiles/OpenStreetMap) (default) or [](#tag/Map-Data-and-Routing-Profiles/TomTom) (add-on required). Enum: "openstreetmap", "tomtom" - `services` (array) Specifies the orders of the type "service". These are, for example, pick-ups, deliveries or other stops that are to be approached by the specified vehicles. Each of these orders contains only one location. - `services.id` (string, required) Specifies the id of the service. Ids need to be unique so there must not be two services/shipments with the same id. Example: "7fe77504-7df8-4497-843c-02d70b6490ce" - `services.type` (string) Specifies type of service. This makes a difference if items are loaded or unloaded, i.e. if one of the size dimensions > 0. If it is specified as or , items are loaded and will stay in the vehicle for the rest of the route (and thus consumes capacity for the rest of the route). If it is a , items are implicitly loaded at the beginning of the route and will stay in the route until delivery (and thus releases capacity for the rest of the route). Enum: "service", "pickup", "delivery" - `services.priority` (integer) Specifies the priority. Can be 1 = high priority to 10 = low priority. Often there are more services/shipments than the available vehicle fleet can handle. Then you can set priorities to differentiate high priority tasks from those that could be left unassigned. I.e. the lower the priority the earlier these tasks are omitted in the solution. Example: 1 - `services.name` (string) Meaningful name for service, e.g. . Example: "delivery pizza" - `services.address` (object) - `services.duration` (integer) Specifies the duration of the service in seconds, i.e. how long it takes at the customer site. Example: 1800 - `services.preparation_time` (integer) Specifies the preparation time in seconds. It can be used to model parking lot search time since if you have 3 identical locations in a row, it only falls due once. Example: 300 - `services.time_windows` (array) Specifies an array of time window objects (see time_window object below). Specify the time either with the recommended Unix time stamp (the number of seconds since 1970-01-01) or you can also count the seconds relative to Monday morning 00:00 and define the whole week in seconds. For example, Monday 9am is then represented by 9hour 24hour/day 13hour/day * 3600sec/hour = 219600. See this tutorial for more information. Example: [{"earliest":32400,"latest":36000},{"earliest":50400,"latest":54000}] - `services.time_windows.earliest` (integer) Specifies the opening time of the time window in seconds, i.e. the earliest time the service can start. - `services.time_windows.latest` (integer) Specifies the closing time of the time window in seconds, i.e. the latest time the service can start. - `services.size` (array) Size can have multiple dimensions and should be in line with the capacity dimension array of the vehicle type. For example, if the item that needs to be delivered has two size dimension, volume and weight, then specify it as follow [ 20, 5 ] assuming a volume of 20 and a weight of 5. Example: [30,5,1] - `services.required_skills` (array) Specifies an array of required skills, i.e. array of string (not case sensitive). For example, if this service needs to be conducted by a technician having a and a then specify the array as follows: . This means that the service can only be done by a vehicle (technician) that has the skills AND in its skill array. Otherwise it remains unassigned. Example: ["drilling_machine","screw_driver"] - `services.allowed_vehicles` (array) Specifies an array of allowed vehicles, i.e. array of vehicle ids. For example, if this service can only be conducted EITHER by OR specify this as follows: . Example: ["technician_peter","technician_stefan"] - `services.disallowed_vehicles` (array) Specifies an array of disallowed vehicles, i.e. array of vehicle ids. Example: ["driver-A","driver-B"] - `services.preferred_vehicles` (array) Specifies an array of preferred vehicles. - `services.preferred_vehicles.vehicle_id` (string) Id of the preferred vehicle. - `services.preferred_vehicles.priority` (integer) Number between 1 and 10 which indicates the priority of the preferred vehicle. 1 indicates the highest priority, 10 the lowest. - `services.max_time_in_vehicle` (integer) Specifies the maximum time in seconds a delivery can stay in the vehicle. Currently, it only works with services of "type":"delivery". Example: 900 - `services.group` (string) Group this service belongs to. See the group relation and [this post](https://discuss.graphhopper.com/t/4040) on how to utilize this. Example: "group-A" - `shipments` (array) Specifies the available shipments. Each shipment consists of a pickup and a delivery. For a single shipment, the pickup must always occur before the delivery. However, pickups and deliveries from multiple shipments can be sequenced independently. - `shipments.id` (string, required) Specifies the id of the shipment. Ids need to be unique so there must not be two services/shipments with the same id. Example: "7fe77504-7df8-4497-843c-02d70b6490ce" - `shipments.name` (string) Meaningful name for shipment, e.g. "pickup and deliver pizza to Peter". Example: "pickup and deliver pizza to Peter" - `shipments.pickup` (object, required) - `shipments.pickup.address` (object) Specifies pickup or delivery address. - `shipments.pickup.duration` (integer) Specifies the duration of the pickup or delivery in seconds, e.g. how long it takes unload items at the customer site. Example: 1800 - `shipments.pickup.time_windows` (array) Specifies an array of time window objects (see time window object below). For example, if an item needs to be delivered between 7am and 10am then specify the array as follows: [ { "earliest": 25200, "latest" : 32400 } ] (starting the day from 0 in seconds). Example: [{"earliest":32400,"latest":36000},{"earliest":50400,"latest":54000}] - `shipments.pickup.group` (string) Group this stop belongs to. See the group relation and [this post](https://discuss.graphhopper.com/t/4040) on how to utilize this. Example: "ASAP" - `shipments.delivery` (object, required) - `shipments.required_skills` (array) Specifies an array of required skills, i.e. array of string (not case sensitive). For example, if this shipment needs to be conducted by a technician having a and a then specify the array as follows: . This means that the service can only be done by a vehicle (technician) that has the skills AND in its skill array. Otherwise it remains unassigned. Example: ["drilling_machine","screw_driver"] - `shipments.allowed_vehicles` (array) Specifies an array of allowed vehicles, i.e. array of vehicle ids. For example, if this shipment can only be conducted EITHER by "technician_peter" OR "technician_stefan" specify this as follows: ["technician_peter","technician_stefan"]. Example: ["technician_peter","technician_stefan"] - `shipments.max_time_in_vehicle` (integer) Specifies the maximum time in seconds a shipment can stay in the vehicle. Example: 1800 - `relations` (array) Defines additional relationships between orders. - `objectives` (array) Specifies an objective function. The vehicle routing problem is solved in such a way that this objective function is minimized. Example: [{"type":"min","value":"vehicles"},{"type":"min","value":"completion_time"}] - `objectives.type` (string, required) Type of objective function, i.e. or . * : Minimizes the objective value. * : Minimizes the maximum objective value. For instance, -> minimizes the number of employed vehicles. -> minimizes the sum of your vehicle routes' completion time. If you use, for example, -> , it minimizes the maximum of your vehicle routes' completion time, i.e. it minimizes the overall makespan. This only makes sense if you have more than one vehicle. In case of one vehicle, switching from to should not have any impact. If you have more than one vehicle, then the algorithm tries to constantly move stops from one vehicle to another such that the completion time of longest vehicle route can be further reduced. For example, if you have one vehicle that takes 8 hours to serve all customers, adding another vehicle (and using ) might halve the time to serve all customers to 4 hours. However, this usually comes with higher transport costs. If you want to minimize first and, second, , you can also combine different objectives like this: If you want to balance activities or the number of stops among all employed drivers, you need to specify it as follows: Enum: "min", "min-max" - `objectives.value` (string, required) The value of the objective function. The objective value solely considers the time your drivers spend on the road, i.e. transport time. In contrary to , also takes waiting times at customer sites into account. The of a route is defined as the time from starting to ending the route, i.e. the route's transport time, the sum of waiting times plus the sum of activity durations. The , on the other hand, refers to the completion time of the very last order in a tour or, in other words, the completion time without the last section from the last stop to the end of the tour. This is typically used if the orders are to be processed as quickly as possible. The objective value can only be used along with and minimizes vehicles. Enum: "completion_time", "completion_time_last_stop", "transport_time", "vehicles", "activities" - `cost_matrices` (array) Specifies your own tranport time and distance matrices. - `cost_matrices.type` (string) type of cost matrix, currently default or google are supported Enum: "default", "google" - `cost_matrices.location_ids` (array) - `cost_matrices.data` (object) JSON data of matrix response - `cost_matrices.data.times` (array) - `cost_matrices.data.distances` (array) - `cost_matrices.data.info` (object) Additional information for your request - `cost_matrices.data.info.copyrights` (array) - `cost_matrices.data.info.took` (number) - `cost_matrices.profile` (string) vehicle profile or empty if catch all fallback - `configuration` (object) Specifies general configurations. - `configuration.routing` (object) This contains all routing specific configurations. - `configuration.routing.calc_points` (boolean) It lets you specify whether the API should provide you with route geometries for vehicle routes or not. Thus, you do not need to do extra routing to get the polyline for each route. - `configuration.routing.consider_traffic` (boolean) indicates whether historical traffic information should be considered - `configuration.routing.network_data_provider` (string) specifies the data provider, read more about it [here](#tag/Map-Data-and-Routing-Profiles). Enum: "openstreetmap", "tomtom" - `configuration.routing.curbside_strictness` (string) In some cases curbside constraints cannot be fulfilled. For example in one-way streets you cannot arrive at a building that is on the left side of the street such that the building is to the right of you (unless you drove the one-way street the wrong/illegal way). You can set the to to ignore the curbside constraint in such cases or set it to to get an error response instead. You can also set it to to ignore all curbside constraints (this is useful to compare the results with and without constraints without modifying every single address). Enum: "ignore", "soft", "strict" - `configuration.routing.fail_fast` (boolean) indicates whether matrix calculation should fail fast when points cannot be connected - `configuration.routing.return_snapped_waypoints` (boolean) Indicates whether a solution includes snapped waypoints. In contrary to the address coordinate a snapped waypoint is the access point to the (road) network. - `configuration.routing.snap_preventions` (array) Optional parameter. 'Snapping' is the process of finding the closest road location for GPS coordinates provided in the array. The array allows you to prevent snapping to specific types of roads. For example, if the array includes , then the routing engine will avoid snapping to a bridge, even if it is the closest road for the given point. Note that once snapped the routing algorithm can still route over bridges (or the other values). To avoid this you need to use the . Enum: "motorway", "trunk", "bridge", "ford", "tunnel", "ferry" - `configuration.optimization` (object) This contains all optimization specific configurations. - `configuration.optimization.free_insertion` (boolean) If you use groups, you sometimes want to place orders without group assignment in the best position, i.e. sometimes in the middle of a group and not before or after the group. This is not allowed by default. However, if this field here is "true", these orders (without a group assignment) can be inserted freely. - `algorithm` (object) Use instead. - `algorithm.problem_type` (string) Enum: "min", "min-max" - `algorithm.objective` (string) Enum: "transport_time", "completion_time" ## Response 200 fields (application/json): - `copyrights` (array) Example: ["GraphHopper","OpenStreetMap contributors"] - `status` (string) Indicates the current status of the job Enum: "waiting_in_queue", "processing", "finished" - `waiting_time_in_queue` (integer) Waiting time in ms Example: 300000 - `processing_time` (integer) Processing time in ms. If job is still waiting in queue, processing_time is 0 Example: 900000 - `solution` (object) Only available if status field indicates . - `solution.distance` (integer) Overall distance travelled in meter, i.e. the sum of each route's transport distance Example: 1200 - `solution.transport_time` (integer) Overall time travelled in seconds, i.e. the sum of each route's transport time. Example: 12000 - `solution.max_operation_time` (integer) Operation time of longest route in seconds. Example: 4000 - `solution.waiting_time` (integer) Overall waiting time in seconds. Example: 200 - `solution.service_duration` (integer) Overall service time in seconds. Example: 1200 - `solution.preparation_time` (integer) Overall preparation time in seconds. - `solution.completion_time` (integer) Overall completion time in seconds, i.e. the sum of each routes/drivers operation time. Example: 12000 - `solution.no_vehicles` (integer) Number of employed vehicles. Example: 10 - `solution.no_unassigned` (integer) Number of jobs that could not be assigned to final solution. Example: 1 - `solution.routes` (array) An array of routes - `solution.routes.vehicle_id` (string) Id of vehicle that operates route Example: "driver-stefan" - `solution.routes.distance` (integer) Distance of route in meter Example: 10000 - `solution.routes.transport_time` (integer) Transport time of route in seconds Example: 1800 - `solution.routes.completion_time` (integer) Completion time of route in seconds Example: 1800 - `solution.routes.waiting_time` (integer) Waiting time of route in seconds - `solution.routes.service_duration` (integer) Service duration of route in seconds - `solution.routes.preparation_time` (integer) Preparation time of route in seconds - `solution.routes.activities` (array) Array of activities - `solution.routes.activities.type` (string) type of activity Enum: "start", "end", "service", "pickupShipment", "deliverShipment", "pickup", "delivery", "break" - `solution.routes.activities.id` (string) Id referring to the underlying service or shipment, i.e. the shipment or service this activity belongs to - `solution.routes.activities.location_id` (string) Id that refers to address - `solution.routes.activities.address` (object) Address of activity - `solution.routes.activities.address.location_id` (string) Specifies the id of the location. Example: "550e8400-e29b-11d4-a716-446655440000" - `solution.routes.activities.address.name` (string) Name of location. Example: "Queens Victoria Street 70, Second Floor, Flat 245" - `solution.routes.activities.address.lon` (number) Longitude of location. Example: -0.092869 - `solution.routes.activities.address.lat` (number) Latitude of location. Example: 51.512665 - `solution.routes.activities.address.street_hint` (string) Optional parameter. Specifies a hint for each address to better snap the coordinates (lon,lat) to road network. E.g. if there is an address or house with two or more neighboring streets you can control for which street the closest location is looked up. Example: "Queens Victoria Street 70" - `solution.routes.activities.address.snapped_waypoint` (object) Access point to the (road)network. It is only available if is true (be default it is false). - `solution.routes.activities.arr_time` (integer) Arrival time at this activity in seconds. If type is , this is not available (since it makes no sense to have at start). However, is available and actually means \"departure time\" at start location. It is important to note that does not necessarily mean \"start of underlying activity\", it solely means arrival time at activity location. If this activity has no time windows and if there are no further preparation times, is equal to activity start time. - `solution.routes.activities.end_time` (integer) End time of and thus departure time at this activity. If type is , this is not available (since it makes no sense to have an at end) at each activity is equal to the departure time at the activity location. - `solution.routes.activities.end_date_time` (string) Translation of unix timestamp in to end date time string with zone offset. It will be in the following ISO-8601 format: 2007-12-03T10:15:30+01:00. - `solution.routes.activities.arr_date_time` (string) Translation of unix timestamp in to arrival date time string with zone offset. It will be in the following ISO-8601 format: 2007-12-03T10:15:30+01:00. - `solution.routes.activities.waiting_time` (integer) Waiting time at this activity in seconds. A waiting time can occur if the activity has at least one time window. If < a waiting time of - occurs. - `solution.routes.activities.preparation_time` (integer) preparation time at this activity in seconds - `solution.routes.activities.distance` (integer) cumulated distance from start to this activity in m - `solution.routes.activities.driving_time` (integer) cumulated driving time from start to this driver activity in seconds - `solution.routes.activities.load_before` (array) Array with size/capacity dimensions before this activity - `solution.routes.activities.load_after` (array) Array with size/capacity dimensions after this activity - `solution.routes.points` (array) Array of route planning points - `solution.routes.points.type` (string) - `solution.routes.points.coordinates` (array) - `solution.unassigned` (object) - `solution.unassigned.services` (array) An array of ids of unassigned services Example: ["service-1","service-3"] - `solution.unassigned.shipments` (array) An array of ids of unassigned shipments Example: ["shipment-5"] - `solution.unassigned.breaks` (array) An array of ids of unassigned breaks - `solution.unassigned.details` (array) An array of details, i.e. reason for unassigned services or shipments - `solution.unassigned.details.id` (string) Id of unassigned service/shipment - `solution.unassigned.details.code` (integer) Reason code Code | Reason :------|:--------- 1 | cannot serve required skill 2 | cannot be visited within time window 3 | does not fit into any vehicle due to capacity 4 | cannot be assigned due to max distance constraint of vehicles 21 | could not be assigned due to relation constraint 22 | could not be assigned due to allowed vehicle constraint 23 | could not be assigned due to max-time-in-vehicle constraint 24 | driver does not need a break 25 | could not be assigned due to disallowed vehicle constraint 26 | could not be assigned due to max drive time constraint 27 | could not be assigned due to max job constraint 28 | could not be assigned due to max activity constraint 29 | could not be assigned due to group relation constraint 30 | could not be assigned due to driving time break 50 | underlying location cannot be accessed over road network by at least one vehicle - `solution.unassigned.details.reason` (string) Human readable reason as listed above - `solution.costs` (integer) - `solution.time` (integer) Use instead. ## Response 400 fields (application/json): - `message` (string) Short error message Example: "Bad Request" - `hints` (array) Optional error information. - `hints.message` (string) error message Example: "unsupported json property [vehiles]. allowed properties: [vehicles, vehicle_types, services, shipments, relations, algorithm, objectives, cost_matrices, configuration]" - `hints.details` (string) Details Example: "class java.lang.IllegalArgumentException" - `status` (string) status Example: "finished" ## Response 500 fields (application/json): - `code` (integer) Example: 500 - `message` (string) Details Example: "There has been an internal server error."