Shortest total path among set of Latitude/Longitudes - python

I have a set of 52 or so latitude/longitude pairs. I simply need to find the shortest path through all of them; it doesn't matter where staring point or ending point is.
I've implemented Dijkstra's algorithm by hand multiple times before and don't really have the time to do it again. I've found a couple things that come close, but most require raw graphs with pre-computed weights for each edge.
Do you know of any libraries or existing scripts/applications which will compute the shortest path in this manner? The code/libraries would preferably use Python or Clojure but it really doesn't matter.
Thanks

If this is a closed path, it is the Traveling Salesman Problem, and a sub-optimal but quite effective way to resolve it is to use Simulated Annealing

In python, the best graph handling library I was able to put my hands on is networkx. It supports a broad range of different algos for short path search.
Go for it. It's really complete and well designed.

Isn't this the Traveling Salesman Problem, and therefore there is no efficient way to solve it?

Related

Is is still considered a BFS algorithm if I modify it A little bit?

So I'm trying to create a program that finds the shortest path from nodeA to nodeB, however, I want to block certain nodes so that it would find another path. I'm not really aiming for an optimal code here I'm just trying things out, exploring etc.
Is it still considered a BFS if I modify it a little?
Yes, it still is a BFS, with just a few constraints. The essence of BFS algorithm is the way it explores the graph, you are just exploring a subgraph (through filtering out a bit of it).

Routing problems with a large amount of points and one constraint

I am currently tackling a routing problem where I have to create daily schedule for workers to repair some installations. There 200,000 installations and a worker can only work 8 hours per fay. The goal is to make optimal routes on a daily basis; therefore optimizing the distance between the different points he has to visit on a daily basis but there is also a constraint on the priority of each installation. Indeed each installation has a priority between 0 and 1 and higher priority points should be given higher weights.
I am just looking for some suggestions as I have tried implementing some solutions (https://developers.google.com/optimization/routing/tsp) but due to the many points I have, this results in too long computation time.
Thank you.
Best regards,
Charles
As you know, there is no perfect answer for your issue, but maybe I can guide your research :
Alpha-Beta pruning : I've been using it to reduce the amount of possibilities for an AI playing Hex game.
A* pathfinding : I've been using it to simulate a futuristic hyperloop-like capsule-based network, as a complement of Dijkstra algorithm.
You can customize both algorithm according to your needs.
Hoping to be useful !
Due to large scale of the described problem it is nearly impossible to achieve the optimal solution for each case. You could try something based on mixed integer programming, especially in TSP or vehicle routing problem but I assume that it won't work in your case.
What you should try, at least in my opinion, are heuristic approaches for solving TSP/VRP: tabu search, simulated annealing, hill climbing. Given enough time and a proper set of constraints one of these methods would produce "good enough" solutions, which are much better than a random guessing. Take a look at something like Google OR-Tools
That's a massive sized problem. You will need to cluster it into smaller subproblems before tackling it. We've applied sophisticated fuzzy clustering techniques to experimentally solve a 20,000 location problem. For 200,000 you'll probably need to aggregate by geographic regions (e.g. postcode / zipcode) though before you could attempt to run some kind of clustering to split it up. Alternatively you may just want to try a hard split based on geography first of all.

`the shortest path that connects several points` NP-complete algorithms

I am reading `Grokking algorithms" and understand Dijkstran and greedy algorithms,
but, when the author compare them with NP-complete problem
But it’s hard to tell if a problem you’re working on is NP-complete. Usually there’s a very small difference between a problem that’s easy to solve and an NP-complete problem. For example, in the previous chapters, I talked a lot about shortest paths. You know how to calculate the shortest way to get from point A to point B.
But if you want to find the shortest path that connects several points, that’s the traveling-salesperson problem, which is NP-complete. The short answer: there’s no easy way to tell if the problem you’re working on is NP-complete. Here are some giveaways:
The sentence:
But if you want to find the shortest path that connects several points,
What are "the several points"?
I cannot figure out any difference with a basic Dijkstan's algorithms problem.
He means a path through a subset of all the nodes of a graph, I think. (Think the worst case of 'several points')
Note, that for any fixed number of points, say k = 3 or k = 3000 on a graph of n nodes, the problem would be of the same complexity as for two points. While some people may think that several is never greater than seven, or may be seven dozens or seven billion, it is neither a matter of fact nor an exact science.
Less likely he meant the usual formulation of the Traveling salesman problem (all the nodes/points on a connected graph), though a possibility. NP complete any way.

Is there some equation to find the number of paths from the number of junctions?

Suppose I have the following possible paths of maze.
I found the possible paths implementing dead end removal process with image processing.
I wanted to know if there is any equation to find the number of possible paths from the number of available junctions? I am thinking of implementing it in python.
Any other method / algorithm for finding number of possible paths can be suggested.
It'll be great if you could be as specific as possible.
Help will be appreciated.

Driving Distance Between GIS Points

I have a large number of GIS (latitude, longitude) coordinates, and I'd like to get the distance between them. Is there a service that will calculate the shortest path for me? I know about google maps, but I'd like something I can use from Python, and that can handle a large batch of requests at once.
I'm looking for the driving distance, so a straight distance won't do.
Thanks
So I take it based on your question and the answers posted that you are asking what program to use? If you can find a way to get a copy for free or cheap (like through work, school, etc) I'd recommend ArcGIS 9.x. It has its quirks, but it's highly supported by the user community and there are a lot of forums and help/training books available for it. Also, they have adopted Python as their official scripting language for the program (Sweeeet!).
Another option that is less expensive is GRASS. It's a free, open-source, well established, powerful and multiplatform GIS program. It might have a bit steeper learning-curve than ArcGIS, but I've heard very good things about it considering it's a free program.
This website lists info on free, open-source (FOS) GIS programs http://opensourcegis.org/ and could give you some good info on your other choices.
I couldn't tell if you were asking a question about how to measure the distance between two points and finding shortest travel distances in a GIS program or if you were just mentioning that's the kind of stuff you would need to do. Either way, ArcGIS is well suited for those tasks. Some of the tools in ArcGIS's ArcToolbox already have commands to help you find optimal transportation routes. This link lets you explore some of the tools available ArcToolbox Help. Most of the tools in ArcToolbox have a GUI batch processing option automatically included as well. Measuring point to point distances on an individual basis is easy in ArcGIS, and if you needed to measure a bunch of point to point pairs, you could write a quick Python script to easily do it for you.
I think I've answered all of your questions. Feel free to let me know if there is something I missed or that doesn't make sense. Hope this helps, buddy.
Check out OpenStreetMap. You can download their map data and have it lying around on your local system. http://wiki.openstreetmap.org/wiki/Routing discusses the various routing systems for their data.
You are aware that the traveling salesman problem is np-complete?
using Qgis:
Use the delimited text plugin to import the data
save the import as a shape file
Open the shape file
using the ftools plugin, calculate the matrix distance
If you have interconnections between the points you could use Dijkstra's algorithm for a 'shortest path from a single point' or Floyd's algorithm for an 'all pairs' shortest path computation.
Neither are particularly complicated, however they do assume you know the lengths of the roads between the points. You will need to have this data to compute a driving distance.

Categories

Resources