I want to solve a Travelling Salesman Problem like Google Maps does in its DirectionsRequest with request.setOptimizeWaypoints(true);. It orders some Waypoints in a route so that the travelling-costs are minimal.
My question: Does anybody know which algorithm stands behind it? Any heuristic? Could not find any information by google, so far.
I informed myself and found a lot of insertion-heuristics, nearest neighbour, and so on... Or is it an exact solution procedure?
The Wikipedia page on the Travelling Salesman Problem references a number of algorithms for finding solutions. (But unless N is small, avoid the "exact" algorithms!)
According to this post from a Google employee, the source code for the Googles route calculation algorithms is available here:
http://code.google.com/p/or-tools/source/browse/trunk/examples/cpp/tsp.cc
http://code.google.com/p/or-tools/source/browse/trunk/src/constraint_solver/routing.h
... but it is not entirely clear if this is the "production" code for Google Maps.
From a comment in the source code:
// Solving the vehicle routing problems is mainly done using approximate methods
// (namely local search,
// cf. http://en.wikipedia.org/wiki/Local_search_(optimization)), potentially
// combined with exact techniques based on dynamic programming and exhaustive
// tree search.
This general issue (Google Maps vs TSP) is also discussed in various other SO questions.
References:
Optimal map routing with Google Maps
Travelling Salesman with Google Maps API or any other
What is a practical solution to the Travelling Salesman prblem, using Google Maps?
Related
I am creating a sort of forum, and would like to create a function that gives the user suggestions for similar posts before posting a new post, just like in SO.
I am not sure how to create this function in the most efficient way?
What will be the parameters to determine a similar post? This needs to be searched by the title of the post only, but still not sure what would be the logic behind it.
Also, I am working with cloud Firestore and I am charged by reads, so that logic needs to be efficient in terms of not needing to read every document in my database to bring up the relevant posts. Should be some smart query.
Would appreciate input and advice on that, thanks!
** Tried to google that many times but the search query brings up unrelated results ("how to create similar posts"). So if there's information out there about that I'd love a link too, couldn't find it myself.
You can achieve this by comparing the user input string on each keystroke with the titles stored in database or any other data structures by using a custom made string searching algorithm or by Apache Commons library, which provides efficient algorithms for calculating string similarity.
Levenshtein Distance is one of the popular calculation algorithm, with Levenshtein Distance, the lower the score, the more similar strings are:
StringUtils.getLevenshteinDistance("book", "back") == 2
StringUtils.getLevenshteinDistance("gold", "cold") == 1
StringUtils.getLevenshteinDistance("gold", "coin") == 3
I'm using the Google Distance Matrix API with Java. I want to calculate the train-distance between two cities. One of the cities has no train station. The problem is, google doesn't just calculate the train-distance. It always adds the car-distance from the city without trainstation to the next city with a train station. But for my project i just need the train-distance.
This is a part of my code:
DistanceMatrix matrix = DistanceMatrixApi.newRequest(context)
.origins(origins)
.destinations(destinations)
.mode(TravelMode.TRANSIT)
.transitModes(TransitMode.TRAIN)
.units(Unit.METRIC)
.await();
In the documentation I can't find a solution for this problem.
The Google Maps search algorithms were designed to solve real-world transportation routes, which means that sending a train to a location where the passenger cannot get off is not feasible and therefore not reflected in the routes. I cannot think of any way to extract that information from Google Maps, except possibly doing a direct Directions query, though I doubt it would have different results, since it uses (as far as I can tell) the fundamentally same algorithm for all of its services.
Using a database such as OpenStreetMap (using free, limitless APIs like Overpass to access via HTTP in Java) is probably the best solution. If you want a quick fix, and you are capable of identifying cities without train stations, taking the linear distance between the two cities probably returns a reasonable (though deflated) estimate using the Geometry Library.
Sorry there is not a solution I can see, but this is the best I have.
i'd love to know if in the google maps api exists a method to find street start and end.
I'm looking for something that adds a marker in every intersection and adds it to a mySQL DB in order to do computations over it, like Dijkstra's algorithm.
I was thinking about using the house number, but it's inaccurate and tedious, not talking about computational needs..
Any clue would be really appreciated
Thanks #Andomar for the tip, i've solved the whole problem that limited my project.
I've used OpenStreetMap and Spatialite, which thanks to this article i've set up in no time.
It can even be solved using stored procedures like in this other article.
I actually am trying to find the distance between two places, I am new to this. I came to know about openstreetmap. But I am not sure what to do.
I found a traveling salesman application that uses osm to route.
But here my question is how to get a osm between places .e.g. "http://www.openstreetmap.org/api/0.6/map?bbox=10,30,10,30" this gives me the map of the box (10,30,10,30) .. but if I want to get the map between leeds and sheffield what should be my query.
Or is there any other way to find the distance.(As I am a student I want some open source way for my academic project..)
please suggest..
You should consider implementing this by yourself.
First, I suggest you to use the Overpass API to do your queries.
Then implement this algorithm over the ways you get from the Overpass API :)
For calculating the routing distance between two places you can use one of the various online or offline routers. There is also a list of various information for routing developers containing a list of libraries and other information.
If you have to obtain the location of a specific address before doing the actual routing you can use Nominatim.
Im doing a Java application where I'll have to determine what are the Trending Topics from a specific collection of tweets, obtained trough the Twitter Search. While searching in the web, I found out that the algorithm defines that a topic is trending, when it has a big number of mentions in a specific time, that is, in the exact moment. So there must be a decay calculation so that the topics change often. However, I have another doubt:
How does twitter determines what specific terms in a tweet should be the TT? For example, I've observed that most TT's are hashtag or proper nouns. Does this make any sense? Or do they analyse all words and determine the frequency?
I hope someone can help me! Thanks!
I don't think anyone knows except Twitter, however it seems hashtags do play a big part, but there are other factors in play. I think mining the whole text would take more time than needed, and would result in too many false positives.
Here is an interested article from Mashable:
http://www.sparkmediasolutions.com/pdfs/SMS_Twitter_Trending.pdf
-Ralph Winters
You may be interested in meme tracking, which as I recall, does interesting things with proper nouns, but basically identifies topics in a stream as they become more and less popular:
And in Eddi, interactive topic-based browsing of social status streams