How to speed up osm2po when using as java lib?

المشرف العام

Administrator
طاقم الإدارة
I'am trying to utilize osm2po as java lib for calculation of distances matrix between some set of points (lat/lon) and for each pair of points I call the following method that code is based on sample provided at osm2po.de web-site:

public int getDistance(GeoPoint source, GeoPoint target) { int res = Integer.MAX_VALUE; int sourceId = graph.findClosestVertexId(source.getLatitude(), source.getLongitude(), 1); int targetId = graph.findClosestVertexId(target.getLatitude(), target.getLongitude(), 1); router.traverse(graph, sourceId, targetId, Float.MAX_VALUE, params); if (router.isVisited(targetId)) { // Found! int[] path = router.makePath(targetId); float distKm = 0.0f; for (int segmentId : path) { RoutingResultSegment rrs = graph.lookupSegment(segmentId); distKm = distKm + rrs.getKm(); } res = (int)(distKm * 1000); } router.reset(); return res;But I noticed that it takes about 2-3 seconds per one point to calculate whole distance matrix (I have 10-25 points per matrix in average) that looks not too fast (30-60secs per matrix).Could someone advice what could be improved here - especially I am not sure in correct usage of reset() call - when actually it should be done? - it's not too much documentation on osm2po usage within java...
Also I would appreciate any performance tips to improve this code. One more guess I have is that findClosestVertexId() is expensive enough call and cashing its results for subsequent calls could improve the situation.



أكثر...
 
أعلى