Coder Social home page Coder Social logo

"fewest turns" refinement? about ngraph.path HOT 5 OPEN

anvaka avatar anvaka commented on May 17, 2024 3
"fewest turns" refinement?

from ngraph.path.

Comments (5)

anvaka avatar anvaka commented on May 17, 2024

I remember asking similar question to @redblobgames (Amit Patel) and if I recall correctly, Amit suggested to model turns as additional edges in a graph with non-zero cost.

That way turns will be more costly and algorithm should try to reduce their amount

from ngraph.path.

redblobgames avatar redblobgames commented on May 17, 2024

The A* graph nodes should be the important state for making decisions. Normally we just use location for this. But if you want to take turns into account you would want location and direction for the graph nodes.

The edges can be two types:

  • road: (location A, east) → (location B, east) is traveling along a road, keeping the same direction
  • intersection: (location A, east) → (location A, south) is turning right at an intersection

You can then assign costs to the turns, e.g. left turns (X, east) → (X, north) might cost more than right turns (X, east) → (X, south), and both might cost more than going straight through an intersection (X, east) → (X, east).

(It is also possible to merge these two into one edge type but that's an optimization that adds some complexity)

One of these days I should make an interactive demo showing how this works.

from ngraph.path.

leeoniya avatar leeoniya commented on May 17, 2024

i wonder if it'd be practical to pre-adjust the cost of some edges using custom weighting criteria, eg. known traffic, street capacity/size, typical speed, number of intersections/stop signs, construction, potholes. this could force the existing algo to prefer main roads more frequently than small ones (which is usually where this behavior becomes a nuisance). then it would just be a matter of properly tweaking the weighting amount.

from ngraph.path.

redblobgames avatar redblobgames commented on May 17, 2024

There are lots of fun things to do with costs once you switch from "cost is distance" to "cost is time" and then "cost is time plus annoyance" or "cost is upper bound on time" or other things like that. You can also model time of day or current traffic (as Google Maps does) if you want the costs to vary. And another possibly fun thing is to refine the path further by taking into account lanes. The road link A → B would be A₁ → B₁ (stay in right lane), A₁ → B₂ (change lanes), A₂ → B₁ (change lanes), A₂ → B₂ (stay in left lane). Then you can have intersections model turn restrictions, such as you can only turn right from the right lane or only turn left from the left lane. That then allows you to factor in annoying maneuvers like "you just turned right onto a road but you have to quickly get into the left lane to make the next left". Lots of tweaks and additional modeling you can do (in theory) depending on how important it is to the application. However I haven't worked with ngraph to see which ones work nicely with it.

Intersection with multiple lanes

from ngraph.path.

georeith avatar georeith commented on May 17, 2024

I've made a PR to expose the parent node to the distance() function to enable this: #42

from ngraph.path.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.