Skip to content

Commit

Permalink
Fix tests for approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
vshcherb committed Sep 16, 2024
1 parent 5b29304 commit cb60e21
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ build

#Rendering test files
OsmAnd-java/src/test/resources/rendering/*

OsmAnd-shared/bin
# ApproximationTest resources
OsmAnd-java/src/test/resources/approximation/*
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ public class GpxMultiSegmentsApproximation {
private static final double MIN_BRANCHING_DIST = 10; // 5 m for branching
private static boolean EAGER_ALGORITHM = false;
private static boolean PRIORITY_ALGORITHM = !EAGER_ALGORITHM;
private final boolean TEST_SHIFT_GPX_POINTS = false;
private static boolean DEBUG = false;
/////////////////////////

private static final int ROUTE_POINTS = 12;
private static final int GPX_MAX = 30; // 1M

private final RoutePlannerFrontEnd frontEnd;
private final GpxRouteApproximation gctx;
private final List<GpxPoint> gpxPoints;
private final float minPointApproximation;
private final float initDist;
/// Evaluation variables

Comparator<RouteSegmentAppr> METRICS_COMPARATOR = new Comparator<RouteSegmentAppr>() {
final Comparator<RouteSegmentAppr> METRICS_COMPARATOR = new Comparator<RouteSegmentAppr>() {

@Override
public int compare(RouteSegmentAppr o1, RouteSegmentAppr o2) {
return Double.compare(o1.metric(), o2.metric());
}
};
java.util.PriorityQueue<RouteSegmentAppr> queue = new java.util.PriorityQueue<>(METRICS_COMPARATOR);
private TLongHashSet visited = new TLongHashSet();

private final boolean TEST_SHIFT_GPX_POINTS = false;
private static boolean DEBUG = false;
/// Evaluation variables
private final RoutePlannerFrontEnd frontEnd;
private final GpxRouteApproximation gctx;
private final List<GpxPoint> gpxPoints;
private final float minPointApproximation;
private final float initDist;
java.util.PriorityQueue<RouteSegmentAppr> queue = new java.util.PriorityQueue<>(METRICS_COMPARATOR);
TLongHashSet visited = new TLongHashSet();


private static class RouteSegmentAppr {
private final RouteSegment segment;
Expand Down Expand Up @@ -378,7 +378,8 @@ private void wrapupRoute(List<GpxPoint> gpxPoints, RouteSegmentAppr bestRoute) {
r.setGpxPointIndex(startInd); // required for reconstructFinalPointsFromFullRoute()
}
gpxPoints.get(startInd).routeToTarget = res;
gpxPoints.get(startInd).targetInd = last;
gpxPoints.get(startInd).targetInd = last; // keep straight line
gpxPoints.get(startInd).breakSegment = true;
}

private static long calculateRoutePointId(RouteSegmentAppr segm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ private void calculateGpxRoute(GpxRouteApproximation gctx, List<RoutePlannerFron
RoutePlannerFrontEnd.GpxPoint straightPointStart = null;
for (int i = 0; i < gpxPoints.size() && !gctx.ctx.calculationProgress.isCancelled; ) {
RoutePlannerFrontEnd.GpxPoint pnt = gpxPoints.get(i);
boolean breakSegment = false;
if (pnt.routeToTarget != null && !pnt.routeToTarget.isEmpty()) {
LatLon startPoint = pnt.getFirstRouteRes().getStartPoint();
if (lastStraightLine != null) {
Expand All @@ -381,6 +382,10 @@ private void calculateGpxRoute(GpxRouteApproximation gctx, List<RoutePlannerFron
i = pnt.targetInd;
} else {
// add straight line from i -> i+1
breakSegment = true;
i++;
}
if (breakSegment || pnt.breakSegment) {
if (lastStraightLine == null) {
lastStraightLine = new ArrayList<LatLon>();
if (gctx.getLastPoint() != null && gctx.finalPoints.size() > 0) {
Expand All @@ -390,38 +395,38 @@ private void calculateGpxRoute(GpxRouteApproximation gctx, List<RoutePlannerFron
}
straightPointStart = pnt;
}
lastStraightLine.add(pnt.loc);
i++;
if (!pnt.breakSegment) {
lastStraightLine.add(pnt.loc);
}
}
}
if (lastStraightLine != null) {
addStraightLine(gctx, lastStraightLine, straightPointStart, reg);
lastStraightLine = null;
}

if (router.isUseGeometryBasedApproximation()) {
new RouteResultPreparation().prepareResult(gctx.ctx, gctx.fullRoute); // not required by classic method
}

// clean turns to recalculate them
cleanupResultAndAddTurns(gctx);
}

private void cleanupResultAndAddTurns(GpxRouteApproximation gctx) {
// cleanup double joints
int LOOK_AHEAD = 4;
for (int i = 0; i < gctx.fullRoute.size() && !gctx.ctx.calculationProgress.isCancelled; i++) {
RouteSegmentResult s = gctx.fullRoute.get(i);
for (int j = i + 2; j <= i + LOOK_AHEAD && j < gctx.fullRoute.size(); j++) {
RouteSegmentResult e = gctx.fullRoute.get(j);
if (e.getStartPoint().equals(s.getEndPoint())) {
while ((--j) != i) {
gctx.fullRoute.remove(j);
}
break;
}
}
}
// FIXME
// int LOOK_AHEAD = 4;
// for (int i = 0; i < gctx.fullRoute.size() && !gctx.ctx.calculationProgress.isCancelled; i++) {
// RouteSegmentResult s = gctx.fullRoute.get(i);
// for (int j = i + 2; j <= i + LOOK_AHEAD && j < gctx.fullRoute.size(); j++) {
// RouteSegmentResult e = gctx.fullRoute.get(j);
// if (e.getStartPoint().equals(s.getEndPoint())) {
// while ((--j) != i) {
// gctx.fullRoute.remove(j);
// }
// break;
// }
// }
// }

RouteResultPreparation preparation = new RouteResultPreparation();
preparation.validateAllPointsConnected(gctx.fullRoute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static class GpxPoint {
public long time = 0;
public double cumDist;
public RouteSegmentPoint pnt;
public boolean breakSegment = false;
public List<RouteSegmentResult> routeToTarget;
public List<RouteSegmentResult> stepBackRoute;
public int targetInd = -1;
Expand Down

0 comments on commit cb60e21

Please sign in to comment.