Fix public transport routing (walking part)

This commit is contained in:
crimean 2018-12-10 16:54:57 +03:00
parent 6853d7ca76
commit e35c72067c
3 changed files with 59 additions and 34 deletions

View file

@ -162,7 +162,6 @@ public class TransportRoutePlanner {
} }
p = p.parentRoute; p = p.parentRoute;
} }
route.finishWalkSegment = new TransportRouteResultSegment(null, 0, 0, route.finishWalkDist, -1);
// test if faster routes fully included // test if faster routes fully included
boolean include = false; boolean include = false;
for(TransportRouteResult s : lst) { for(TransportRouteResult s : lst) {
@ -317,7 +316,6 @@ public class TransportRoutePlanner {
public static class TransportRouteResult { public static class TransportRouteResult {
List<TransportRouteResultSegment> segments = new ArrayList<TransportRouteResultSegment>(4); List<TransportRouteResultSegment> segments = new ArrayList<TransportRouteResultSegment>(4);
TransportRouteResultSegment finishWalkSegment;
double finishWalkDist; double finishWalkDist;
double routeTime; double routeTime;
private final TransportRoutingConfiguration cfg; private final TransportRoutingConfiguration cfg;
@ -330,10 +328,6 @@ public class TransportRoutePlanner {
return segments; return segments;
} }
public TransportRouteResultSegment getFinishWalkSegment() {
return finishWalkSegment;
}
public double getWalkDist() { public double getWalkDist() {
double d = finishWalkDist; double d = finishWalkDist;
for (TransportRouteResultSegment s : segments) { for (TransportRouteResultSegment s : segments) {

View file

@ -2,6 +2,7 @@ package net.osmand.plus.routing;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Pair;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -46,7 +47,7 @@ public class TransportRoutingHelper {
private RoutingHelper routingHelper; private RoutingHelper routingHelper;
private List<TransportRouteResult> routes; private List<TransportRouteResult> routes;
private Map<TransportRouteResultSegment, RouteCalculationResult> walkingRouteSegments; private Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments;
private int currentRoute; private int currentRoute;
private LatLon startLocation; private LatLon startLocation;
@ -93,8 +94,8 @@ public class TransportRoutingHelper {
} }
@Nullable @Nullable
public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s) { public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) {
return walkingRouteSegments.get(s); return walkingRouteSegments.get(new Pair<>(s1, s2));
} }
public void setCurrentRoute(int currentRoute) { public void setCurrentRoute(int currentRoute) {
@ -294,14 +295,35 @@ public class TransportRoutingHelper {
} }
private class WalkingRouteSegment { private class WalkingRouteSegment {
TransportRouteResultSegment s; TransportRouteResultSegment s1;
TransportRouteResultSegment s2;
LatLon start; LatLon start;
boolean startTransportStop;
LatLon end; LatLon end;
boolean endTransportStop;
WalkingRouteSegment(TransportRouteResultSegment s, LatLon start, LatLon end) { WalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) {
this.s = s; this.s1 = s1;
this.s2 = s2;
start = s1.getEnd().getLocation();
end = s2.getStart().getLocation();
startTransportStop = true;
endTransportStop = true;
}
WalkingRouteSegment(LatLon start, TransportRouteResultSegment s) {
this.start = start; this.start = start;
this.s2 = s;
end = s2.getStart().getLocation();
endTransportStop = true;
}
WalkingRouteSegment(TransportRouteResultSegment s, LatLon end) {
this.s1 = s;
this.end = end; this.end = end;
start = s1.getEnd().getLocation();
startTransportStop = true;
} }
} }
@ -311,7 +333,7 @@ public class TransportRoutingHelper {
private Thread prevRunningJob; private Thread prevRunningJob;
private final Queue<WalkingRouteSegment> walkingSegmentsToCalculate = new ConcurrentLinkedQueue<>(); private final Queue<WalkingRouteSegment> walkingSegmentsToCalculate = new ConcurrentLinkedQueue<>();
private Map<TransportRouteResultSegment, RouteCalculationResult> walkingRouteSegments = new HashMap<>(); private Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments = new HashMap<>();
private boolean walkingSegmentsCalculated; private boolean walkingSegmentsCalculated;
public RouteRecalculationThread(String name, TransportRouteCalculationParams params) { public RouteRecalculationThread(String name, TransportRouteCalculationParams params) {
@ -353,12 +375,15 @@ public class TransportRoutingHelper {
LatLon end = new LatLon(walkingRouteSegment.end.getLatitude(), walkingRouteSegment.end.getLongitude()); LatLon end = new LatLon(walkingRouteSegment.end.getLatitude(), walkingRouteSegment.end.getLongitude());
final float currentDistanceFromBegin = final float currentDistanceFromBegin =
RouteRecalculationThread.this.params.calculationProgress.distanceFromBegin + (float) walkingRouteSegment.s.getTravelDist(); RouteRecalculationThread.this.params.calculationProgress.distanceFromBegin +
(walkingRouteSegment.s1 != null ? (float) walkingRouteSegment.s1.getTravelDist() : 0);
final RouteCalculationParams params = new RouteCalculationParams(); final RouteCalculationParams params = new RouteCalculationParams();
params.inSnapToRoadMode = true; params.inPublicTransportMode = true;
params.start = start; params.start = start;
params.end = end; params.end = end;
params.startTransportStop = walkingRouteSegment.startTransportStop;
params.targetTransportStop = walkingRouteSegment.endTransportStop;
RoutingHelper.applyApplicationSettings(params, app.getSettings(), walkingMode); RoutingHelper.applyApplicationSettings(params, app.getSettings(), walkingMode);
params.mode = walkingMode; params.mode = walkingMode;
params.ctx = app; params.ctx = app;
@ -396,7 +421,7 @@ public class TransportRoutingHelper {
params.resultListener = new RouteCalculationResultListener() { params.resultListener = new RouteCalculationResultListener() {
@Override @Override
public void onRouteCalculated(RouteCalculationResult route) { public void onRouteCalculated(RouteCalculationResult route) {
RouteRecalculationThread.this.walkingRouteSegments.put(walkingRouteSegment.s, route); RouteRecalculationThread.this.walkingRouteSegments.put(new Pair<>(walkingRouteSegment.s1, walkingRouteSegment.s2), route);
if (!walkingSegmentsToCalculate.isEmpty()) { if (!walkingSegmentsToCalculate.isEmpty()) {
RouteCalculationParams walkingRouteParams = getWalkingRouteParams(); RouteCalculationParams walkingRouteParams = getWalkingRouteParams();
if (walkingRouteParams != null) { if (walkingRouteParams != null) {
@ -415,16 +440,21 @@ public class TransportRoutingHelper {
walkingRouteSegments.clear(); walkingRouteSegments.clear();
if (routes != null && routes.size() > 0) { if (routes != null && routes.size() > 0) {
for (TransportRouteResult r : routes) { for (TransportRouteResult r : routes) {
LatLon start = params.start; TransportRouteResultSegment prev = null;
for (TransportRouteResultSegment s : r.getSegments()) { for (TransportRouteResultSegment s : r.getSegments()) {
LatLon start = prev != null ? prev.getEnd().getLocation() : params.start;
LatLon end = s.getStart().getLocation(); LatLon end = s.getStart().getLocation();
double dist = MapUtils.getDistance(start, end); if (start != null && end != null) {
if (dist > 50) { if (prev == null || MapUtils.getDistance(start, end) > 50) {
walkingSegmentsToCalculate.add(new WalkingRouteSegment(s, start, end)); walkingSegmentsToCalculate.add(prev == null ?
new WalkingRouteSegment(start, s) : new WalkingRouteSegment(prev, s));
} }
start = s.getEnd().getLocation();
} }
walkingSegmentsToCalculate.add(new WalkingRouteSegment(r.getFinishWalkSegment(), start, params.end)); prev = s;
}
if (prev != null) {
walkingSegmentsToCalculate.add(new WalkingRouteSegment(prev, params.end));
}
} }
RouteCalculationParams walkingRouteParams = getWalkingRouteParams(); RouteCalculationParams walkingRouteParams = getWalkingRouteParams();
if (walkingRouteParams != null) { if (walkingRouteParams != null) {

View file

@ -805,20 +805,23 @@ public class RouteLayer extends OsmandMapLayer {
private void calculateTransportResult(LatLon start, LatLon end, TransportRouteResult r, List<Way> res, List<Integer> colors) { private void calculateTransportResult(LatLon start, LatLon end, TransportRouteResult r, List<Way> res, List<Integer> colors) {
if (r != null) { if (r != null) {
LatLon p = start; LatLon p = start;
TransportRouteResultSegment prev = null;
for (TransportRouteResultSegment s : r.getSegments()) { for (TransportRouteResultSegment s : r.getSegments()) {
LatLon floc = s.getStart().getLocation(); LatLon floc = s.getStart().getLocation();
addRouteWalk(s, p, floc, res, colors); addRouteWalk(prev, s, p, floc, res, colors);
List<Way> geometry = s.getGeometry(); List<Way> geometry = s.getGeometry();
res.addAll(geometry); res.addAll(geometry);
addColors(s.route, geometry.size(), colors); addColors(s.route, geometry.size(), colors);
p = s.getEnd().getLocation(); p = s.getEnd().getLocation();
prev = s;
} }
addRouteWalk(r.getFinishWalkSegment(), p, end, res, colors); addRouteWalk(prev, null, p, end, res, colors);
} }
} }
private void addRouteWalk(TransportRouteResultSegment s, LatLon start, LatLon end, List<Way> res, List<Integer> colors) { private void addRouteWalk(TransportRouteResultSegment s1, TransportRouteResultSegment s2,
final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s); LatLon start, LatLon end, List<Way> res, List<Integer> colors) {
final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s1, s2);
if (walkingRouteSegment != null && walkingRouteSegment.getRouteLocations().size() > 0) { if (walkingRouteSegment != null && walkingRouteSegment.getRouteLocations().size() > 0) {
final List<Location> routeLocations = walkingRouteSegment.getRouteLocations(); final List<Location> routeLocations = walkingRouteSegment.getRouteLocations();
Way way = new Way(-1); Way way = new Way(-1);
@ -830,7 +833,6 @@ public class RouteLayer extends OsmandMapLayer {
addColors(null, 1, colors); addColors(null, 1, colors);
} else { } else {
double dist = MapUtils.getDistance(start, end); double dist = MapUtils.getDistance(start, end);
if (dist > 50) {
Way way = new Way(-1); Way way = new Way(-1);
way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %.1f m", dist)); way.putTag(OSMSettings.OSMTagKey.NAME.getValue(), String.format(Locale.US, "Walk %.1f m", dist));
way.addNode(new Node(start.getLatitude(), start.getLongitude(), -1)); way.addNode(new Node(start.getLatitude(), start.getLongitude(), -1));
@ -839,7 +841,6 @@ public class RouteLayer extends OsmandMapLayer {
addColors(null, 1, colors); addColors(null, 1, colors);
} }
} }
}
private void addColors(TransportRoute route, int count, List<Integer> colors) { private void addColors(TransportRoute route, int count, List<Integer> colors) {
int color; int color;