i am currently testing outh the HERE CalculateMatrix API. My goal is to get all possible routes and find out the shortest one. Now im asking myself the following question:
Is it possible to define interim waypoints that an Route has to pass?
And is it possible that the order that these waypoints are passed is not defined?
So that i have for example the starting point: A, interim points: B and C an the destination: D,
and the Matrix should then calculate the following possible Routes:
A-B-C-D,
A-C-B-D
so im not using different destinations but different waypoints in between
As Raymond already mentioned in comments, it is not possible to use Calculate Matrix API for a use case of "sortable" way-points. The Fleet Telematics API does provide something close, although it would only provide the most optimal route and not all possible routes. In the API, some way-points can be marked as "sort" which means their order is not fixed and the API would then find the most optimal route.
From API reference (https://developer.here.com/documentation/fleet-telematics/dev_guide/topics/waypoint-sort-pickup-opening-times.html)
Sorting Waypoints (Travelling Salesman Problem) Routing can find the
optimal sequence order for the waypoints. Activate this feature by
following waypoint parameters:
&waypoint1=...;sort
All sections of waypoints flagged with "sort" can be rearranged by the
router for cost optimization. For example, in the waypoint list of
WP0, WP1;sort, WP2;sort, WP3;sort, WP4, WP5;sort, WP6;sort, WP7 the
router can change the sequence order among WP1, WP2 and WP3, and it
can change the sequence order among WP5 and WP6. If the last waypoint
is "sort"able then the route may end at any of the sortable waypoints.
Use this if the driver does his overnight stay simply at/after the
last waypoint he visited throughout the day.
&waypoint1=...;before:3,5
Enforces that the route meets waypoint 1 before the waypoints 3 and 5.
Use it in combination with either "sort" or "optional".
&waypoint1=...;implies:4,8
Enforces that if waypoint 1 is part of the route then also waypoints 4
and 8 must be part of the route. Use it in combination with "optional"
waypoints.
Related
The OR-Tools documentation (https://developers.google.com/optimization/routing/routing_options) for the VRP routing options describes the two first solution strategies the following way:
PATH_CHEAPEST_ARC: Starting from a route "start" node, connect it to the node which produces the cheapest route segment, then extend the route by iterating on the last node added to the route.
GLOBAL_CHEAPEST_ARC: Iteratively connect two nodes which produce the cheapest route segment.
Can someone explain me what the difference between the two heuristics is? Unfortunately I haven't found any other information on the internet or the documentation.
The first one grows a route by extending it.
The second one connect the closest nodes together until it creates routes.
I have same question like VRP with different vehicle types using or-tools
two types of vehicles :trucks and iveco
according to the traffic control policy of the local ,each types of vehicles can used routes was different :
for example:some road only can be used by trucks , others road only can be used by iveco, some accept both trucks and iveco...
despite this ,using only either trucks or iveco still can traverse all customers finally
now, already get the distance_matrix and time_matrix using only trucks ,and distance_matrix and time_matrix using only iveco
but I couldn't find the right function calculated the best routes , did anyone help?
you can register a transit function per vehicle type then pass an array of registered transit indices when creating a Dimension.
see this sample on gist: vrp_multiple_transit.py
Is it possible to solve the Multiple Depot Vehicle Scheduling Problem (MDVSP) in OR-tools?
The problem is detailed in this paper, but here is a brief summary.
We are given a set of depots and the number of available vehicles at each. We are given a set of timetabled trips, and we know the origin, destination, start time, end time, and a set of depots that can serve a given trip. While connecting two trips, that is assigning a vehicle to serve for two trips sequentially, there may be an unoccupied travel, so called a dead-head trip. There are also dead-heads while going from a depot to the first trip and returning from the last trip to a depot. The objective is to minimize the sum of all dead-head trip costs while ensuring each trip is served by exactly one vehicle and the number of vehicles used does not exceed the availability. (Other trips/links, i.e., occupied trips, must in any case need to be served/traversed; so, there is no need to include them in the objective).
Seems you want to take into account the arc cost only if vehicle is empty. (note: fixed typo)
AFAIK, there is no easy way to do it using OR-Tools. In C++ you may use the DimensionDependentDimension and returning the arc cost if a capacity dimension is zero, and zero otherwise...
Also I'm curious why you would like to only count dead-trip e.g. if the overall vehicle route is several time longer with very few dead-trip instead of a shorter route with few dead-trip why would you want to incentive the first one ?
e.g. a route of 100km with 1km dead-trip is two time better than a 50km route with 2km dead-trip...
For multiple depots please take a look at
vrp_starts_ends.py
For TimeWindows: vrp_time_windows.py
Did you take a look at the documentation ?
e.g. https://developers.google.com/optimization/routing/cvrp
using routing.NextVar(A).SetValues([A, B]) you can force the chain A->B
ref: https://github.com/google/or-tools/blob/49b6301e1e1e231d654d79b6032e79809868a70e/ortools/constraint_solver/routing.h#L1364-L1366
note: Solver won't have the possibility to use A->C->B even if is shorter than A->B->C or C->A->B (supposing TW allow both of them...)
Context
The service I'm building needs to performs two steps using the HERE API.
It needs to calculate the optional route between multiple waypoints. This can be achieved using the Waypoint Sequencing API.
It also needs to display the route on a map, so I need polylines for the route. This can be retrieved using the Routing API.
The problem
According to the docs:
The Fleet Telematics Waypoints Sequence does not include route details in its responses. To request a route, use the HERE Routing API.
That is, the use of the two distinct services cannot be avoided. However, there seem to be major differences between the services. For example, when calculating the optimal route, you may restrict certain road types, such as tollroad or motorway, to a degree. On the other hand, Routing API, I can only avoid certain types, and it's an either-or choice.
Here's (no pun intended) an example: let's say the user wants to avoid toll roads unless absolutely necessary, thus he sets tollroad to -3 in the Waypoint Sequencing API. When the actual route is calculated, we only have the choice to allow toll roads, meaning, potentially every part of the route will go through such roads, or disallow them entirely.
The question itself
Is there any way I'm missing to "mediate" between the results of the two services? Essentially, I would like to display the route the Waypoint Sequencing API found to be ideal for all the provided options.
The HERE Waypoints Sequence API v8 resource findsequence allows you to optimize for distance covered in a journey or for travel time. Use the parameter improvefor (available values: distance and time). By default, HERE Waypoints Sequence optimizes waypoints for travel time.
So HERE WSE service optimizes waypoints for travel time and travel distance.
Check this for all parameters of WSE : https://developer.here.com/documentation/routing-waypoints/api-reference.html
And requests to the Routing API must include the route travel mode and two consecutive waypoint coordinates from the response from HERE Waypoints Sequence API v8
I'm working an a map app where I can add waypoints along specific routes. I need to pull my waypoints out in order obviously so I can get directions from A-D in the correct order.
I've read a bit about geoJSON in mongodb but I'm curious if theres a way to query my data so that my points come out ordered by how close they are together rather than the order I've put them in.
Basically what I'm asking...Is there a way to do a "Traveling Salesman query" so that my waypoints are ordered in the smartest order?
I think the short answer is no. You're going to need to add an order key to your waypoints. This is a pretty standard pattern for any nav system with waypoints. At the very least you need to know which point is first and which is last so that you can then solve the TSP.