15,798,592 members
See more:
I'm interested in automatically determining the quickest route from one point to another using data and algorithms. However, I'm not just looking for the shortest route, but specifically a route that involves moving always to the left. (Assuming Japan, where traffic moves on the left, it is believed that turning right is less safe than turning left.)

What I have tried:

Currently, I am using the Google Routes API to calculate routes, but I have found that with Google Routes API, the route does not always turn left (for example, there is an option called "side_of_road", and by setting it to True, the safety of the route improves, but it doesn't necessarily make it left-turning). Could you suggest what kind of technology or data I could use to solve this problem?
Posted
Updated 2-Aug-23 23:54pm
v2
Patrice T 3-Aug-23 3:18am
Do not repost same question.
OriginalGriff 3-Aug-23 3:41am
Since Pete has answered this later one, I deleted the original.

## Solution 1

This sounds like you need to create your own version of the Dijkstra algorithm. It works something like this:

1. Start by assigning a tentative distance value to every node in the graph. Set the initial node's distance to 0 and all other nodes' distances to infinity. Keep a set of unvisited nodes.
2. In each iteration, select the unvisited node with the smallest tentative distance. Initially, this will be the starting node.
3. For the current selected node, visit each of its neighbours (nodes directly connected to it) and calculate their tentative distances from the starting node. The tentative distance is the sum of the distance from the starting node to the current node and the weight of the edge connecting the current node to its neighbour. For your version, you would add a step in here to determine whether or not the node has a left turn. In some cases you will find that the route reaches a termination as you encounter a node with no left turn.
4. If the newly calculated tentative distance for a node is smaller than its current assigned distance, update the node's distance with the new smaller value. (Note, this is the traditional form of Dijkstra - in your case, I would maintain a collection of all the different node distances, and start removing from them when I encountered routes with no left turns).
5. After visiting all neighbours of the current node, mark it as visited, and remove it from the set of unvisited nodes.
6. Continue the process by selecting the next unvisited node with the smallest tentative distance, and repeat steps 3 to 5 until all nodes have been visited.

The algorithm terminates when all nodes have been visited, and the shortest distance from the starting node to all other nodes has been determined. At this point, the algorithm will have also computed the shortest path from the starting node to any other node in the graph taking into account your left turn constraint. It is entirely possible that you will not return any possible routes, if there are points where no left turn is possible.