Small changes

This commit is contained in:
vshcherb 2014-01-17 00:29:41 +01:00
parent ad72ef705b
commit 3fc759ef1c
3 changed files with 93 additions and 6 deletions

View file

@ -14,6 +14,7 @@ import net.osmand.PlatformUtil;
import net.osmand.binary.RouteDataBorderLinePoint; import net.osmand.binary.RouteDataBorderLinePoint;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapRenderingTypes;
import net.osmand.router.RoutingContext.RoutingSubregionTile;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -81,6 +82,8 @@ public class BinaryRoutePlanner {
} }
} }
newSearchRoute(ctx, start, end);
// Initializing priority queue to visit way segments // Initializing priority queue to visit way segments
Comparator<RouteSegment> nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator(); Comparator<RouteSegment> nonHeuristicSegmentsComparator = new NonHeuristicSegmentsComparator();
@ -196,6 +199,61 @@ public class BinaryRoutePlanner {
} }
private void newSearchRoute(RoutingContext ctx, RouteSegment start, RouteSegment end) {
int sx31 = start.getRoad().getPoint31XTile(start.getSegmentStart());
int sy31 = start.getRoad().getPoint31YTile(start.getSegmentStart());
int ex31 = end.getRoad().getPoint31XTile(end.getSegmentStart());
int ey31 = end.getRoad().getPoint31YTile(end.getSegmentStart());
int zoom = 11;
int sz = 31 - zoom;
int sx = sx31 >> sz;
int ex = ex31 >> sz;
int sy = sy31 >> sz;
int ey = ey31 >> sz;
int h = Math.abs(sy - ey);
int w = Math.abs(sx - ex);
int dh = (h + w)/ 6;
int dw = (h + w)/ 6;
System.out.println("Bbox : (" + sx +", " + sy +" - " +ex +", " + ey+ ") - " +
(w + dw * 2) + " x " + (h + dh * 2));
System.out.println("Load tiles " + ((w + dw * 2)*(h + dh * 2)));
int total = 0;
for(int x = -dw; x <= w + dw; x ++) {
for(int y = -dh; y <= h + dh; y++) {
int tileX = Math.min(sx, ex) + x;
int tileY = Math.min(sy, ey) + y;
float lat = (float) MapUtils.getLatitudeFromTile(zoom, tileY);
float lon = (float) MapUtils.getLongitudeFromTile(zoom, tileX);
if((x == -dw && y == -dh)) {
System.out.println("LeftTop : " + lat + ", " + lon);
}
if((x == w + dw && y == h + dh)){
System.out.println("RightBottom : " + lat + ", " + lon);
}
List<RoutingSubregionTile> ts = ctx.loadTileHeaders(sz, tileX, tileY);
if(ts != null) {
total += ts.size();
}
}
}
System.out.println("Total loaded " + total + " "+ ctx.subregionTiles.size());
List<RouteDataObject> ls = new ArrayList<RouteDataObject>();
TLongObjectHashMap<RouteDataObject> dup = new TLongObjectHashMap<RouteDataObject>();
long time = System.currentTimeMillis();
for(RoutingSubregionTile st : ctx.subregionTiles) {
ctx.loadSubregionTile(st, true);
st.loadAllObjects(ls, ctx, dup);
}
System.out.println("Total obj to check " + ls.size());
System.out.println("Time " + ctx.timeToLoadHeaders / 1e6 + " " + (System.currentTimeMillis() - time));
// ctx.loadTileHeaders(zoom, tileX, tileY)
}
private void printMemoryConsumption( String string) { private void printMemoryConsumption( String string) {
long h1 = RoutingContext.runGCUsedMemory(); long h1 = RoutingContext.runGCUsedMemory();
float mb = (1 << 20); float mb = (1 << 20);
@ -212,7 +270,7 @@ public class BinaryRoutePlanner {
ctx.calculationProgress.distanceFromBegin = ctx.calculationProgress.distanceFromBegin =
Math.max(graphDirectSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin); Math.max(graphDirectSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin);
} }
if(graphDirectSegments.size() > 0) { if(graphReverseSegments.size() > 0) {
ctx.calculationProgress.distanceFromEnd = ctx.calculationProgress.distanceFromEnd =
Math.max(graphReverseSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin); Math.max(graphReverseSegments.peek().distanceFromStart, ctx.calculationProgress.distanceFromBegin);
} }
@ -328,6 +386,7 @@ public class BinaryRoutePlanner {
} }
double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed(); double result = distToFinalPoint / ctx.getRouter().getMaxDefaultSpeed();
// result *= 0.8;
return (float) result; return (float) result;
} }

View file

@ -13,6 +13,7 @@ import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment; import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment;
import net.osmand.router.BinaryRoutePlanner.RouteSegment; import net.osmand.router.BinaryRoutePlanner.RouteSegment;
import net.osmand.router.RoutingContext.RoutingSubregionTile;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
public class RouteResultPreparation { public class RouteResultPreparation {
@ -279,6 +280,26 @@ public class RouteResultPreparation {
} }
private void newRoutingAnalyzeDiff(RoutingContext ctx, LatLon start, LatLon end, List<RouteSegmentResult> result, int d) { private void newRoutingAnalyzeDiff(RoutingContext ctx, LatLon start, LatLon end, List<RouteSegmentResult> result, int d) {
System.out.println();
System.out.println("------------");
long id = -2;
long[] ids = ctx.indexedSubregions.keys();
for(long idt : ids) {
long x = idt >> 16;
long y = idt - (x<<16);
// double l = MapUtils.get31LongitudeX((int) (x<<15));
// double t = MapUtils.get31LatitudeY((int) (y<< 15));
// double r = MapUtils.get31LongitudeX((int) ((x+1)<<15));
// double b = MapUtils.get31LatitudeY((int) ((y+1)<<15));
// System.out.println("<node id=\""+(id--)+"\" lat=\""+t+"\" lon=\""+l+"\" />");
// System.out.println("<node id=\""+(id--)+"\" lat=\""+b+"\" lon=\""+r+"\" />");
// System.out.println("<way id=\""+(id--) +"\" >");
// System.out.println("<nd ref=\"" + (id +3)+"\" />");
// System.out.println("<nd ref=\"" + (id +2)+"\" />");
// System.out.println("<tag k=\"man_made\" v=\"cutline\"/>");
// System.out.println("</way>");
// System.out.println();
}
for(int k = 0; k < result.size() - d; k+=d){ for(int k = 0; k < result.size() - d; k+=d){
RouteSegmentResult res1 = result.get(k); RouteSegmentResult res1 = result.get(k);
RouteSegmentResult res2 = result.get(k + d); RouteSegmentResult res2 = result.get(k + d);

View file

@ -419,7 +419,7 @@ public class RoutingContext {
return original; return original;
} }
private void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory) { public void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory) {
boolean wasUnloaded = ts.isUnloaded(); boolean wasUnloaded = ts.isUnloaded();
int ucount = ts.getUnloadCont(); int ucount = ts.getUnloadCont();
if (nativeLib == null) { if (nativeLib == null) {
@ -465,9 +465,12 @@ public class RoutingContext {
final int zoomToLoad = 31 - config.ZOOM_TO_LOAD_TILES; final int zoomToLoad = 31 - config.ZOOM_TO_LOAD_TILES;
int tileX = x31 >> zoomToLoad; int tileX = x31 >> zoomToLoad;
int tileY = y31 >> zoomToLoad; int tileY = y31 >> zoomToLoad;
return loadTileHeaders(zoomToLoad, tileX, tileY);
SearchRequest<RouteDataObject> request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoad, }
(tileX + 1) << zoomToLoad, tileY << zoomToLoad, (tileY + 1) << zoomToLoad, null);
public List<RoutingSubregionTile> loadTileHeaders(final int zoomToLoadM31, int tileX, int tileY) {
SearchRequest<RouteDataObject> request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoadM31,
(tileX + 1) << zoomToLoadM31, tileY << zoomToLoadM31, (tileY + 1) << zoomToLoadM31, null);
List<RoutingSubregionTile> collection = null; List<RoutingSubregionTile> collection = null;
for (Entry<BinaryMapIndexReader, List<RouteSubregion>> r : map.entrySet()) { for (Entry<BinaryMapIndexReader, List<RouteSubregion>> r : map.entrySet()) {
// NOTE: load headers same as we do in non-native (it is not native optimized) // NOTE: load headers same as we do in non-native (it is not native optimized)
@ -693,7 +696,11 @@ public class RoutingContext {
this.subregion = subregion; this.subregion = subregion;
} }
private void loadAllObjects(final List<RouteDataObject> toFillIn, RoutingContext ctx, TLongObjectHashMap<RouteDataObject> excludeDuplications) { public TLongObjectMap<RouteSegment> getRoutes() {
return routes;
}
public void loadAllObjects(final List<RouteDataObject> toFillIn, RoutingContext ctx, TLongObjectHashMap<RouteDataObject> excludeDuplications) {
if(routes != null) { if(routes != null) {
Iterator<RouteSegment> it = routes.valueCollection().iterator(); Iterator<RouteSegment> it = routes.valueCollection().iterator();
while(it.hasNext()){ while(it.hasNext()){