How to use FastVehicleRoutingTransportCostsMatrix , I have Time Matrix? - java

FastVehicleRoutingTransportCostsMatrix
I am having adjacency Matrix of time ,taken from Mapbox . Mapbox distance API . I don't have the distance Matrix .How can I calculate cost ?

A quick scan of the documentation suggests that the "Distance API" is only capable of returning travel times... how illogical!
Using this API I would say there is no way to do this, but perhaps building your matrix via the Directions API would be possible. The only thing you could do would be to estimate an average driving speed and calculate the estimated distance. But adding .setCostPerDistance with this estimate would have no bearing on the solution because all you do is inflate the travel costs by a fixed factor.
If your issue is that JSprit is throwing errors because both a distance and time matrix are required for a custom matrix (I don't remember), just make fake distances and don't set a cost parameter per distance (or 0 cost).
So, your options are to stick to Mapbox Distance API and not consider cost per distance, or switch API to one that gives you both distance and time. One option would be hosting your own Graphhopper server, and there are simple quick-start guides available to do this. Jsprit and Graphhopper have teamed up, and it is also bundled into ODL Studio.

Related

Does google's Distance matrix api consider "Elevation" too?

Does google's distance matrix api considers "elevation" while showing distance between two latitude-longitude points?
Suppose first person is at upper level at an airport, second person is standing at lower level on same airport in same line, will the distance shown by google's distance matrix api be considering this vertical distance between both persons?
No, but it sounds like you're considering using this API for something it was not built for.
The Google Distance Matrix API will return route distances, be it driving, walking, bicycling or public transportation. The distance (and duration) in each element in a response Distance Matrix API would be that of the route found by the Google Directions API.
It does not calculate straight-line (or geodesic) distances. You can use the Haversine formula.
While the Directions API does find indoor routes for walking directions, this is only available for directions to/from Google MAps places, those that have a Place ID. An arbitraty position in an arbitrary building level cannot be expressed in a Place ID.
Distances from Google Maps (and APIs) do take elevation into account, e.g. this route is 2.1 Km even though it looks like barely 1.5 Km. on the map.
Besides all that, the elevation differences within a building would be tiny compared to the driving distance between them. If you are looking for distances between people inside buildings, you're better off with straight-line distances corrected with average floor elevation (3-5 m.) factored in.

How to get speed and acceleration from trajectory data?

I am using Java to develop a project. I have got some trajectory data by applying a spatial query. My question is, how can I get speed and acceleration for these trajectory data? Does java has useful library to do so?
for more information: points has (x,y,z,t)
no java has not.
speed is distance per time.
to calculate distance you can use the haversine formula, asuming x,y are in latitude longitude. z is ignored.
Depending on the plattform (e.g Android) there is a lib for that,
otherwise search for haversine distance.

OPTICS Clustering algorithm. How to get the best epsilon

I am implementing a project which needs to cluster geographical points. OPTICS algorithm seems to be a very nice solution. It needs just 2 parameters as input(MinPts and Epsilon), which are, respectively, the minimum number of points needed to consider them as a cluster, and the distance value used to compare if two points are in can be placed in same cluster.
My problem is that, due to the extreme variety of the points, I can't set a fixed epsilon.
Just look at the image below.
The same points structure but in a different scale would result very different. Suppose to set MinPts=2 and epsilon = 1Km.
On the left, the algorithm would create 2 clusters(red and blue), but on the right it would create one single cluster containing all of the points(red), but I would like to obtain 2 clusters even on the right.
So my question is: is there any kind of way to calculate dynamically the epsilon value to get this result?
EDIT 05 June 2012 3.15pm:
I thought I was using the OPTICS algorithm implementation from the javaml library, but it seems it is actually a DBSCAN algorithm implementation.
So the question now is: does anybody know a java based implementation of OPTICS algorithm?
Thank you very much and excuse my for my poor english.
Marco
The epsilon value in OPTICS is solely to limit the runtime complexity when using index structures. If you do not have an index for acceleration, you can set it to infinity.
To quote Wikipedia on OPTICS
The parameter \varepsilon is strictly speaking not necessary. It can be set to a maximum value. When a spatial index is available, it does however play a practical role when it comes to complexity.
What you seem to have looks much more like DBSCAN than OPTICS. In OPTICS, you should not need to choose epsilon (it should have been called max-epsilon by the authors!), but your cluster extraction method will take care of that. Are you using the Xi extraction proposed in the OPTICS paper?
minPts is much more important. You should try a value of at least 5 or 10, not 2. With 2, you are essentially performing single-linkage clustering!
The example you gave above should work fine once you increase minPts!
Re: edit: As you can even see in the Wikipedia article, ELKI has a proper OPTICS implementation and it's in Java.
You'd can try to scale epsilon by the total size of the enclosing rectangle. For example, your left data is about 4km x 6km (using my Mark I eyeball to measure) and the right is about 2km x 2km. So, epsilon on the right should be about 2.5 times smaller.
Of course, this doesn't work reliably. If, on your right hand data, there were an additional single point 4km to the right and 2km down, that would make the enclosing rectangle for the right the same as on the left, and you'd get similar (wrong) results.
You can try a minimum spanning tree and then remove the longest edge. The remaining spanning tree and the center of them is the best center for OPTICS and you can count the numbers of points around it.
In your explanation above, it is the change in scale which creates the uncertainty. When your scale gets bigger, your epsilon should change accordingly. Because they are at two very different scales, the two images you've presented are NOT the same set of points. They will not respond identically to your OPTICS algorithm without changing the parameters.
In short, no. there is no way to dynamically calculate epsilon to get this result. Clustering like this is already NP-Hard, and these clustering algorithims (optics, k-means, veroni) can only approximate the optimal solution.

coordinates based search

I am developing a web page where users can create activities and others find them via a search function. When you create an activity you must specify the exact location where it will take place, assisted by google maps I retrieve the latitude and longitude. Now, when doing a search I want to have the functionality to find all activities close to a specified location(also assisted by google maps).
So I have a set of activities with coordinates, the coordinates of a point I want to find activities nearby, and I want to return activities that are no more than, lets say, 5 km(or miles or whatever you prefer) away from this point.
I am having this idea in my head that this can be solved by calculating max/min latitude and longitude, and use these as parameters in an sql-query where I use a where clause for filtering...The problem I'm facing here is firstly calculating these max/min values, secondly in an circular area(with radius 5km), and not a rectangular
Would appreciate any input here!
Thanks!:)
Coordinates you get are probably not x and y but latitude and longitude; you will need spherical distance unless all your points are within rather small radius, e.g. few hundred miles.
If you have many points, direct exhaustive search becomes too slow, spherical or not. Fortunately, GIS extensions available both for MySQL and for Postgres. Commercial DBs also have spatial extensions. These make searches for nearby objects efficient.
Calculate the boundary latitudes and longitudes.
Use the inverse http://en.wikipedia.org/wiki/Haversine_formula
Select everything where the latitude is between your two values for that, and similarly for longitude. If you're not using a spatial index, beware of edge cases on your sphere (a most excellent pun!): crossing 0, 90, or 180 degrees may result in impossible criteria.
Either in your SQL server or your app, execute the Haversine formula against your results. You must have the rectangular bounding values to prevent a table scan, but results in the rectangle will include results outside of your circle.
If you actually stop to think about it, your rectangle and your circle are both misshapen... but that's not really relevant anyway.
Also, check out this, which will expand on distance measuring and mention some other ideas: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
Hope this can help you.
Get nearest places on Google Maps, using MySQL spatial data
However this is MySQl query. You can convert it as your requirement.

Android Speed based on accelerometer values

I need to obtain the velocity of an android device, based on the accelerometer values. I made a code that allows me to get the accelerometer values, and then I calculate the velocity, using the formula:
v = v0 + at. (vector calculation)
My problem is that my velocity only increases and never decreases. I think the problem is that the device never gets an negative acceleration.
Can you help me with this?
Obtaining velocity from the accelerometers might not be possible (forget reliable) because at constant speed there will be no acceleration (other than gravity). You might be better off obtaining GPS location data and their associated time samples and computing velocity by distance over time.
Are you subtracting out the force of gravity? The device is always accelerating -- even if it is just sitting on your desk, it is accelerating at 9.8 m/s^2 away from the center of the Earth.
You can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction as mentioned in this post.
If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.
There are plenty of tutorials on the web for detecting foot steps with an accelerometer.
There an app note here: http://www.analog.com/library/analogDialogue/archives/41-03/pedometer.html that gives a decent mathematical background and an example algorithm. Its of course up to you to extract the math and rewrite it for Android (the example code is written in C). I don't currently know of an open source android library with a footstep detection algorithm.
If you implement something, I would like to get the code, don't forget to post back the results.

Categories