valhalla_traffic_poc
valhalla_traffic_poc copied to clipboard
Live speed does not match input
Hi there,
first of all thank you for this repo, it is helping a lot in understanding how the valhalla traffic component is working.
However, when following the instructions, I obtain different responses. While generation of live traffic is technically working, the contents do not match the inputs. For instance, the response when changing the overall speed to 30, the response is:
[{'input_lon': 24.771085, 'input_lat': 59.430463, 'nodes': [], 'edges': [{'predicted_speeds': [6, 6, 6, ...], ...,
'live_speed': {'congestion_2': None, 'breakpoint_1': 1.0, 'congestion_1': None, 'speed_1': 40, 'congestion_0': None, 'speed_2': 40, 'breakpoint_0': 1.0, 'speed_0': 40, 'overall_speed': 60}, 'correlated_lat': 59.430464}]}]
The overall speed is always twice the size than the input (I played around with it a lot), and the congestion attributes are always empty.
Do you have an idea where this can come from and how this can be fixed?
Thank you very much!
I think I found out why the speed is always twice as high as the input:
As documented in https://github.com/valhalla/valhalla/blob/master/valhalla/baldr/traffictile.h, the speed is encoded in 2kph resolution to map it to a 7bit number. Meaning, it is necessary to divide the speed data from external data by 2 to get it in the right format. This is also done as such that in your dockerfile.
The only open question for me is the different response in the congestion fields from my request to the ones in the Introduction. I actually do not know how to interpret them. How do I have to set up traffic to be able to make use of them?
Hello! Sorry for the late answer. I took a look and indeed, the live speed result shown in the README was wrong, probably from one of my older runs when I was experimenting.
The speeds were showing up as null most probably because I was setting them to zero here: https://github.com/alinmindroc/valhalla_traffic_poc/blob/main/valhalla_code_overwrites/src/mjolnir/valhalla_traffic_demo_utils.cc#L117
I have updated that tool to generate different values for the congestion values, based on the definition of struct TrafficSpeed
from https://github.com/valhalla/valhalla/blob/master/valhalla/baldr/traffictile.h.
Now the returned values are non-null when querying the edge with /locate
, but the service returns different values than what's configured in valhalla_traffic_demo_utils
. It probably has to do with the way valhalla interprets these values. Unfortunately I can't dive into details at the moment, but the answer is probably somewhere in the traffictile.h logic too. Or you could try to ask in a Valhalla discussion: https://github.com/valhalla/valhalla/discussions
Hi, thanks for the fix and helping me to understand the internals of Valhalla better.
You pointed out that the service returns different values than what's configured now. Can you elaborate where you see this behavior? When I follow your documentation, I only see that the "overall speed" is twice the input value, which due to the encoding of 2kph resolution in Valhalla internally. I see nothing odd going on anymore at this point.
Can you elaborate where you see this behavior?
Yep, the overall speeds make sense now, but I was mentioning the congestion values: even though I set them as congestion1 = 1, congestion2 = 2, congestion3 = 3
in the dummy traffic tile at https://github.com/alinmindroc/valhalla_traffic_poc/blob/main/valhalla_code_overwrites/src/mjolnir/valhalla_traffic_demo_utils.cc#L117, the answer from the /locate
endpoint contains:
"live_speed": {
...
"congestion_2": 0.03,
"congestion_1": 0.02,
"congestion_0": 0,
},
This is what I would expect. I understand the /locate
endpoint as such that it provides the processed values and not the raw values that were set in the traffic.tar file.
For speed the processed values are the absolute speed values (not the raw 2kph resolution) while for congestion levels the relative congestion level is provided. The relative congestion value is the raw value divided by 63 as commented at https://github.com/valhalla/valhalla/blob/e36f7cd2b63d2686bd228a52d2fc1926ead5959a/valhalla/baldr/traffictile.h#L61. This would fit to the values to got in return when setting congestion_2 = 2 and congestion_3 = 3.
For me, it is still unknown what is happening with these values once speed is set and how to use them correctly when having traffic info. Also what the difference of congestion_1, congestion_2 and congestion_3 is, is open.
Hi, i fixed it like: current->overall_encoded_speed = constant_encoded_speed >> 1;
converting 8-bit to 7 bit
see https://github.com/valhalla/valhalla/blob/e36f7cd2b63d2686bd228a52d2fc1926ead5959a/valhalla/baldr/traffictile.h#L94