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

View file

@ -2,6 +2,7 @@ package net.osmand.plus.routing;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@ -46,7 +47,7 @@ public class TransportRoutingHelper {
private RoutingHelper routingHelper;
private List<TransportRouteResult> routes;
private Map<TransportRouteResultSegment, RouteCalculationResult> walkingRouteSegments;
private Map<Pair<TransportRouteResultSegment, TransportRouteResultSegment>, RouteCalculationResult> walkingRouteSegments;
private int currentRoute;
private LatLon startLocation;
@ -93,8 +94,8 @@ public class TransportRoutingHelper {
}
@Nullable
public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s) {
return walkingRouteSegments.get(s);
public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) {
return walkingRouteSegments.get(new Pair<>(s1, s2));
}
public void setCurrentRoute(int currentRoute) {
@ -294,14 +295,35 @@ public class TransportRoutingHelper {
}
private class WalkingRouteSegment {
TransportRouteResultSegment s;
TransportRouteResultSegment s1;
TransportRouteResultSegment s2;
LatLon start;
boolean startTransportStop;
LatLon end;
boolean endTransportStop;
WalkingRouteSegment(TransportRouteResultSegment s, LatLon start, LatLon end) {
this.s = s;
WalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) {
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.s2 = s;
end = s2.getStart().getLocation();
endTransportStop = true;
}
WalkingRouteSegment(TransportRouteResultSegment s, LatLon end) {
this.s1 = s;
this.end = end;
start = s1.getEnd().getLocation();
startTransportStop = true;
}
}
@ -311,7 +333,7 @@ public class TransportRoutingHelper {
private Thread prevRunningJob;
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;
public RouteRecalculationThread(String name, TransportRouteCalculationParams params) {
@ -353,12 +375,15 @@ public class TransportRoutingHelper {
LatLon end = new LatLon(walkingRouteSegment.end.getLatitude(), walkingRouteSegment.end.getLongitude());
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();
params.inSnapToRoadMode = true;
params.inPublicTransportMode = true;
params.start = start;
params.end = end;
params.startTransportStop = walkingRouteSegment.startTransportStop;
params.targetTransportStop = walkingRouteSegment.endTransportStop;
RoutingHelper.applyApplicationSettings(params, app.getSettings(), walkingMode);
params.mode = walkingMode;
params.ctx = app;
@ -396,7 +421,7 @@ public class TransportRoutingHelper {
params.resultListener = new RouteCalculationResultListener() {
@Override
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()) {
RouteCalculationParams walkingRouteParams = getWalkingRouteParams();
if (walkingRouteParams != null) {
@ -415,16 +440,21 @@ public class TransportRoutingHelper {
walkingRouteSegments.clear();
if (routes != null && routes.size() > 0) {
for (TransportRouteResult r : routes) {
LatLon start = params.start;
TransportRouteResultSegment prev = null;
for (TransportRouteResultSegment s : r.getSegments()) {
LatLon start = prev != null ? prev.getEnd().getLocation() : params.start;
LatLon end = s.getStart().getLocation();
double dist = MapUtils.getDistance(start, end);
if (dist > 50) {
walkingSegmentsToCalculate.add(new WalkingRouteSegment(s, start, end));
if (start != null && end != null) {
if (prev == null || MapUtils.getDistance(start, end) > 50) {
walkingSegmentsToCalculate.add(prev == null ?
new WalkingRouteSegment(start, s) : new WalkingRouteSegment(prev, s));
}
}
start = s.getEnd().getLocation();
prev = s;
}
if (prev != null) {
walkingSegmentsToCalculate.add(new WalkingRouteSegment(prev, params.end));
}
walkingSegmentsToCalculate.add(new WalkingRouteSegment(r.getFinishWalkSegment(), start, params.end));
}
RouteCalculationParams walkingRouteParams = getWalkingRouteParams();
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) {
if (r != null) {
LatLon p = start;
TransportRouteResultSegment prev = null;
for (TransportRouteResultSegment s : r.getSegments()) {
LatLon floc = s.getStart().getLocation();
addRouteWalk(s, p, floc, res, colors);
addRouteWalk(prev, s, p, floc, res, colors);
List<Way> geometry = s.getGeometry();
res.addAll(geometry);
addColors(s.route, geometry.size(), colors);
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) {
final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s);
private void addRouteWalk(TransportRouteResultSegment s1, TransportRouteResultSegment s2,
LatLon start, LatLon end, List<Way> res, List<Integer> colors) {
final RouteCalculationResult walkingRouteSegment = transportHelper.getWalkingRouteSegment(s1, s2);
if (walkingRouteSegment != null && walkingRouteSegment.getRouteLocations().size() > 0) {
final List<Location> routeLocations = walkingRouteSegment.getRouteLocations();
Way way = new Way(-1);
@ -830,14 +833,12 @@ public class RouteLayer extends OsmandMapLayer {
addColors(null, 1, colors);
} else {
double dist = MapUtils.getDistance(start, end);
if (dist > 50) {
Way way = new Way(-1);
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(end.getLatitude(), end.getLongitude(), -1));
res.add(way);
addColors(null, 1, colors);
}
Way way = new Way(-1);
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(end.getLatitude(), end.getLongitude(), -1));
res.add(way);
addColors(null, 1, colors);
}
}