User:Erik Lundin/Routing and enforcement
Due to the proposal of enforcement, I started to think of how to place the nodes to best interact with software that might be using the feature. Does it matter to a routing software if the distance between the "from" node and the camera is 5 or 500 meters? To straighten my thoughts out I've constructed some cases (mostly with enforcement example 3b in mind) which highlights some aspects that I think has to be considered when interacting with for instance routing software.
What I'm searching for is an algorithm that handles the cases in a satisfying way, and what implications that has for how to place the nodes in the enforcement relation.
Case 1: __ (50) ># -= ó~~ò | | -------------------------------------------------*-----------|-------|-----*---------- / from / to This driver wants a warning device before the changed speed limit.
Case 2: __ ># -= ó~~ò | ---*---------------------------------------------------------------------------------|-----*---------- from / / to And this one doesn't want device to hear anything until here (say 150 m. from camera).
Case 3: ># | -----------------*--------------------------------+------------------------|-------*------- from | / to | device | | <- Intersecting /o| road The driver here doesn't --> | || really need to know about |_o| the camera until he turns | right. He has to slow ||| down in the intersection. || | | |
Case 4: ># | -----------------*-----------------------------------------------+---------|-------*------- from ´ / to ´ device __ ´ -= ó~~ò ´ ------------------------------- ´ / This driver would like to know about the camera quite soon, because he doesn't need to slow down where the two roads are merging.
Approaches/algorithms
I claim in no way that I know how to write routing software, but these are the main approaches I intuitively can think of when it comes to how to detect a speed camera and warn the driver:
A - Plain distance
Found a camera If (The distance (or time) to the camera < threshold && Speed > maximum allowed) Then warn the driver
- + Simple.
- + Will work for case 1, 2 and 4.
- + Independent of where "from" is placed.
- - Warns for cameras aiming in the opposite direction.
- - Will warn the driver in case 3 even if he intends to turn left.
- - Will continue to warn when you have passed the camera, until the distance is big enough.
B - Vectors (dot product)
Found a camera Calculate the dot product of the vector from-to (normalised) and the velocity vector of the vehicle. It will be at a maximum when we're approaching the camera front to front in high speed. If (The dot product > some threshold && Distance (or time) to the camera < some other threshold && Speed > maximum allowed) Then warn the driver
- + Elegant solution.
- + Will work for case 1, 2, and 3.
- + Stops warning when you have passed the camera.
- - The "from" and "to" nodes have to be placed so the line between them lines up with the road.
- - Possible bad performance for cars approaching the camera in a curve - need to be examined.
C - Close enough AND is between "from" and "to"
Found a camera If (The distance (or time) to the camera < threshold && We're on a road section between "from" and "to" && Speed > maximum allowed) Then warn the driver
- + Will work for case 2.
- + The driver in case 3 doesn't have to bother about the camera if he not turns right in the intersection.
- - Needs "from" to be placed far enough from the camera.
- - Doesn't provide a solution to case 1 and 4.
- - Will continue to warn when you have passed the camera, until the distance is big enough or you have passed "to".
D - Close enough OR is between "from" and "to"
Found a camera If ((The distance (or time) to the camera < threshold || We're on a road section between "from" and "to") && Speed > maximum allowed) Then warn the driver
- + Will work for case 1.
- - Needs "from" to be placed close enough to the camera.
- - Warns for cameras aiming in the opposite direction.
- - Doesn't provide a solution to case 2.
- - Will warn the driver in case 3 even if he intends to turn left.
- - Will continue to warn when you have passed the camera, until the distance is big enough and you have passed "to".
E - Mini routing
Found a camera Calculate the route between current position and the camera If (The distance (or time) to the camera < threshold && Calculated route has some section common with from-to && Speed > maximum allowed Then warn the driver
- + Will work for case 1, 2 and 4.
- + Independent of where "from" is placed.
- + Stops warning when you have passed the camera.
- - Possible somewhat more cpu-intensive due to the routing.
- - Will warn the driver in case 3 even if he intends to turn left.