Question

I am currently developing a navigation system in android and I am using dijkstra's shortest path algorithm My Vertex class contains members as shown below:

-------------------------------------
|                 Vertex            |
-------------------------------------
|    |      |           |           |
| id | name | longitude | latitude  |
-------------------------------------

and an edge with members shown below:

---------------------------------------------
|                Edge                       |
---------------------------------------------
|    |      |        |             |        |
| id | name | source | destination | weight |
---------------------------------------------

Since the vertices and edges are based on a real data specifically: Intersections as Vertices and One intersection to another as Edges to put it simply the whole graph of of my application is the road network of my city.

My problem here is that I still can't come up with an algorithm or an arithmetic equation in calculating the weight of an edge based on the distance of one intersection to another and the time it gets to one intersection to another.

Was it helpful?

Solution

It depends on what you want to optimise (you could let the user choose):

If you want the shortest route, the cost of an edge is simply the length of the street.

If you want the fastest route, the cost would be the expected time to travel the street.

If you want the most economical route in terms of fuel consumption, the cost would be `street length / miles per gallon (expected speed)

The fuel economy varies by car, but you can assume that the economy (in miles per gallon) grows linearly with speed up until a certain speed, then starts to drop off [Wikipedia]. As you can always travel slower than the max. speed, assume a constant efficiency. (miles/gallon) / (miles/hour) = (hours/gallon), so the cost is approximately proportional to time with a speed limit applied at the car's most efficient speed (which could be entered by the user).

If you have a source of prepared congestion data, use it to determine the expected car speed.

One way to measure the expected time of travel by observing the cars is to take an average over all cars that left the street in the past {interval} (hour? minute? only the very last car? the last ten cars?). However, that doesn't pick up congestion too quickly. You can take the average speed of all cars still present in the speed. However, this will overestimate the effect of traffic lights.

You could take the average speed of all cars that entered the street in the last one hour. average(distance traveled/time spent) or average(distance traveled)/average(time spent). If the street is devoid of life, simply take its speed limit or use a longer measurement interval.

Remember the expected speed may be different in both directions (depending on your source of data), so always use pairs of directed edges and measure in each direction separately.

[1] http://en.wikipedia.org/wiki/File:Fuel_economy_vs_speed_1997.png

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top