find passing routes by Enumerable methods
Nobody is happy in the traffic. It'd be great if cars can drive by themselves. Nowadays some new cars come with "traffic jam assistance" for auto-turning or stop&accelerate. But it's not enough for auto-driving. Finding path with obstacle avoidance is critical in addition to GPS routing. Let's take a look at the road and find the route for steering behaviour of an autonomous car.
Let's say the magic radar detect all obstacles on the road, how can we figure out the driving path from the left to the right? As an Array lover I'd put the radar readings into 3 arrays corresponding to 3 lanes:
"Wait a second!" you might think "What's that chunk?". It's a wonderful Enumerable Method told by one of our great cohort mate, Yumiko.
chunk finds consecutive elements by the assigned definition. In this case it finds consecutive integers and we can list all "true" elements it found as the identified cleared path for autonomous driving:
Now with the power of the
chunk method we store all drivable sections into 2D arrays. However, the car cannot proceed without changing lanes, how can we find the path for passing? For clarity here I show only from land C but the same procedure can be applied into any lanes. So we start to drive on cpath, let's check where could we switch to lane B by
Cool, we just drive through land C cpath to land B bpath. When drive to the end of bpath, should we change to lane A or lane C? Let's make a decision now:
See now we can drive on cpath to the right. Thus our autopilot route is cpath→bpath→cpath. Of course this is very simple case, but we can use this procedure to calculate the weighing of paths and apply to a much complicate situation. What a great method!