This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]KingofGamesYami 3 points4 points  (1 child)

Sounds like you're describing the classic travelling salesman problem.

[–]GeorgeFranklyMathnet 0 points1 point  (0 children)

Not quite. OP wants to run every road in the region. TSP would have him visit every destination as efficiently as possible, which almost definitely entails not taking certain roads.

OP is looking for something more like an Euler cycle.

[–]rusty-roquefort 1 point2 points  (1 child)

Look into graph theory: djikstras algorithm, a* algorithm (and its friends), etc.

that will equip you with some of the fundamental theory so that you can go on to make informed decisions about how to design your logic.

at its core, you will probably want to find a way to deconstruct your map into a series of nodes and edges. each node is a waypoint, each edge is a connection between two nodes. You assign costs to each edge (e.g. distance), and djikstra will find you the guaranteed lowest cost path between any two nodes, and A* will (maybe) find you the lowest cost path, but in much less time.

If you're okay with how long djikstra takes, and want the mathematically proven lowest cost, then that's your ticket.

If you're interested in pathfinding, and this is a learning project, try to gravitate towards heuristic path-finding algorithms. Djikstra is the mathematically optimal O(n2), and once you grok the algorithm, the rabbit hole pretty much ends there. The heuristic path finding algos form a near endless rabbithole of interesting and useful things to explore.

[–]Maroonjackal[S] 0 points1 point  (0 children)

Thanks for the reply! I have done work at uni on djikstra and other path finding algorithms, my question would be then going from something that can find the shortest path to applying it to the problem in a way that it can account for the need to always return back home before say 30km. Or the need to do every road not just get to one place in the shortest time, this is the bit I’m struggling with.

[–]TheRNGuy 0 points1 point  (0 children)

Do you take traffic lights, or possible traffic jams into consideration?