I currently building an application that similar to Optaplanner Vehicle Routing Examples. The difference is: it is web based and the visualization & distance calculation will be using GWT Google Maps V3 direction service. Just like the optaplanner blog post at here: Visualizing Vehicle Routing with Leaflet and Google Maps
I actually a little bit confused about calculating the distance between each location, should I do it realtime? What I mean realtime is first load the locations (about 350 locations) and then calculate the distance between each location (which will result in 350 x 350 = 122500 direction request) before start the solving phase.
The other way that I could think about is, do the calculation of each locations distance and store it in database, then load the data before start the solving phase. But if I choose this way, how to handle the locations change? i.e. a new location added or an existing location deleted?
Also I have read about google maps API limitation, it state that the services only available for 2500 request per 24 hour. How to solve this limitation?
Any comments and answers will be appreciated. Thanks and regards.
I have successfully used MapPoint together with MPMileage and CDXZipStream to maintain a database of locations (address + coordinates) using MapPoint and CDXZipStream. Drive times between two points were maintained using MPMileage and MapPoint. MapPoint is no longer being sold by Microsoft, but you may be able to find a copy on eBay or find an alternative. MPMileage and CDX just made my job easier. I was able to interrogate MapPoint as much as I wanted - it provided travel time for about 8 trips per second - no limit but your time. My database now holds over 600,000 trips and 15,000 locations. Also, these products require expenditure of some $. I spent about $300 for the three products I mentioned, a lot less than a Google commercial license. Maptitude can be a replacement for MapPoint, but you may not be able to control street speeds as well with Maptitude.
Prior to running a solution, I had a query make certain that the required coordinates were geocoded and that the potential legs (travel between two points) were in the database. If not, I'd fill in or update the values using the tools I mentioned. My particular method is not conducive to on demand work, but you can probably program such a process yourself.
I limited search space by imposing some reasonable assumptions, e.g. no trips over 13 miles in my case. You may be able to impose similar constraints to limit your search space. At any one time, I probably only use about 60,000 of the travel times as only the needed times are loaded - and the rest remain in the database in case I need them in the future. Within the OptaPlanner solution, these are facts, not entities or variables. These facts provide the travel time between the two points.
Hope this helps.
Related
I'm developing an app that tracks walks, bicycle rides, car rides etc. I need precise info, so I basically would like to use only GPS. Still most sources I found recommend using Googles fused API e.g. for power saving reasons, so I went for the fused API.
Now once in a while (once or twice a month) I get one freak value among thousands of good ones. a few of them I got near railway stations, where the freak value is at another railway station, several kilometers away, so I assume it is a wrong interpreted WiFi based position.
Here's one example, where I ride my bicycle from the river towards the main railway station located east of the river. Once I arrive at the main station, I get no position for 126 s (I asked for every 10 sec, so I probably lost the GPS signal), and then suddenly I get a freak GPS value at another railway station 3450m away on the other side of the river. The reported accuracy for the freak value is 20 m.
The problem is that I cannot easily identify and filter these freak values.
Calling currentLocation.getProvider() always returns "fused", which is not very helpful.
Also Location.getAccuracy() returns typical values below 100m.
So today I filter based on evaluating speed combined with unrealistic changes in bearing, but I'm afraid I might also discard good samples in the process.
I scanned a lot of Stackoverflow, but strangely enough I didn't find any relevant answers yet.
I now feel like moving to the old framework location API and use GPS based data only. But is that really necessary, or does anybody have an idea how to avoid getting the freak values, or alternatively how to easily identify and discard all wifi based positions?
And will using the framework location API have bad battery life as a result?
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 was building a prototype of vehicle routing application using google maps and optaplanner. I change the distance based scoring to duration based scoring, where the duration value was calculated using distance / avg speed of vehicle.
Now I want to add traffic jam variable into my application. The traffic jam variable was implemented as additional duration value from the current location to another location (I using a map of location and double just like distance variable in RoadLocation class). When I tried it to run it, the result was always same with the previous one. Here is the result from the first run :
I draw some red line to represent the traffic jam, and then try to re-run the solving phase. Here is the second result:
The result was the same with the previous one. My questions is, what the best method to apply the traffic jam variable into vehicle routing problem? Does anyone has any experience adding this variable? Any comment and suggestion will be appreciated.
Thanks and regards.
This paragraph is just an introduction. If you wanna skip it, do it. ;-)
I have implemented a similar approach with traffic jams, but it was not a real-time system. The solution runs every X minutes, which is absolutely fine.
That gave me the benefit for pre-calculating the ways and routes for the complete road network, before the actual optaPlanner calculation starts.
This saves time for the real calculation of optaPlanner.
The network consists of vertexes and arcs. For each arc you'll have a weight.
Here starts the real deal for you.
Let's assume that you implement a Dijkstra or A-Star algorithm for the precalculation step for all places and how to get there. These way finding algorithm is seleting the arc with the lowest "travelling" costs. For each arc/road, which would be blocked, we assume a distance of DOUBLE.MAX_VALUE. This value can be interpreted as "not driveable" or drastically said: This connection between two vertexes even doesn't exist for the current solution finding process. So the way finding algorithm will simply skip this road. For every driveable road, we calculate the real costs, e.g. distance or take an approximation out of experience.
The optaplanner process itself just uses the precalculated way finding mechanism, e.g. compares the calculated distances for getting from place A to place B.
For setting the distance variable to DOUBLE.MAX_VALUE you can decide between user based information, information of other providers like google or admin based rules. As my experience goes along with user based content vs. admin based actions, I can recommend both ways.
Let's discuss the user based action: The user can have the same set of GUI actions as the admin for flagging a way as "jammed". For the next optaPlanner iteration the flag is going to be involved. If you have GPS data of your users you can get the approximate velocity. For each intervall of the GPS measurement you can calculate that velocity. If the velocity is on a road (not a crossing), and below a defined minimum velocity (let's say 1mph or 2 kmh), then you can ask the user if it's a traffic jam or not via popup OR block that road automatically without asking the user. If you chose the popup dialog then a lot of different users have to vote "yes" within a defined time slot, e.g. half an hour, then the road get's blocked. You can resolve the traffic jam, when a lot of users drive the road again and send the GPS coordinates of that road.
The main advantage of the automatic approach is, that you'll have a system based approach with a low error rate.
If you take the manual approach via admin, then you have to take care of implementing a GUI for displaying the roads and enabling/disabling the blocked attribute for a road.
In my naive beginning Android mind I thought the way to do this would be to loop through each of the objects checking if proximity falls within X range and if so, include the object. This is being done with Google Maps and GeoPoints.
That said, I know this is probably the slowest way possibly. I did a search for Android Proxmity algorithm's and did not get much really. What I am looking for is best options with regard to this the more efficiently.
Are there any libraries I have not been able to find?
If not, should I load these Location objects into SQL then go from there or keep them in a JSONArray?
Once I establish my best datastructure, what is he best method to find all Locations located with X miles of user?
I am not asking for cut and paste code, rather the best method to this efficiently. Then, I can stumble through the code :)
My first gut feeling is to group the Locations by regions but I'm not exactly sure how to do this.
I could potentially have tens of thousands of datapoints.
Any help in simply heading in the right direction is greatly appreciated.
As a side note, I reach this juncture after discovering that a remote API I had been using was.. well.. just PLAIN WRONG and ommiting datapoints from my proximity search. I also realized that if just placed on the datapoints on the phone, then I could allow the user to run the App without internet connection, and only GPS and this would be a HUGE plus. So, with all setbacks come opportunnities!
The answer depends on the representation of the GeoPoints: If these are not sorted you need to scan all of them (this is done in linear time, sorting wrt. distance or clustering will be more expensive). Use Location.distanceTo(Location) or Location.distanceBetween(float, float, float, float, float[]) to calculate the distances.
If the GeoPoints were sorted wrt. distance to your position this task can be done much more efficiently, but since the supplier does not know your position, I assume that this cannot be done.
If the GeoPoints are clustered, i.e. if you have a set of clusters with some center and a radius select each cluster where the distance from your position to the cluster's center is within the limit plus the radius. For these clusters you need to check each GeoPoint contained in the cluster (some of them are possibly farther away from your position than the limit allows). Alternatively you might accept the error and include all points of the cluster (if the radius is relatively small I would recommend this).
Hi
I'm working with google maps api in both javascript and java on respectively a pc and android. There's probably a difference, but I've been looking around in the documentation for a max number of markers that is a good idea to put on the map, to not have a system crash. It's probably a lot smaller on android, but I really have no idea of an estimate is it 25 - 100 - 1000?
So that's why I'm asking you. What is the maximum number of markers on a map that the user system can handle on pc and android? I know that it depends on the individual system, but I also bet that there are some guidelines I'm not aware of, that I can follow to optimize the user friendliness of my applications.
thanks
From the Google documentation
There is no limit to the number of
markers or path vertices supported by
the Google Static Maps API. However
Static Maps API URLs can be a maximum
of approximately 2,000 characters
which constrains the number of markers
and path vertices that can be
specified based on the number of
decimal places used when specifying
each latitude/longitude pair.
However, you should consider whether your application is overloading the users ability to select from so many markers. Ideally, your application should be doing the filtering for them and only showing a few simple, well spaced choices to allow for big thumbs on the touchscreen.
I would suggest that you use a zoom level manager after reading this article that describes one.