What Google does (I see it as remains from early days of how it became good) is it takes into consideration the route other people took. So if a lot of people do an illegal u-turn, there’s high probability you’ll be proposed such route too.
It works the other way round too. If a lot of people don’t take an optimal route for whatever reason, there’s less probability it’ll propose it to you.
OsmAnd just tries to connect the dots postman-np-problem style