Fix basic issues
This commit is contained in:
parent
092fc3eec1
commit
03b77cd5c9
4 changed files with 93 additions and 65 deletions
|
@ -598,6 +598,8 @@ public class BinaryMapRouteReaderAdapter {
|
||||||
req.publish(ro);
|
req.publish(ro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// free objects
|
||||||
|
rs.dataObjects = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class BinaryRoutePlanner {
|
||||||
* return list of segments
|
* return list of segments
|
||||||
*/
|
*/
|
||||||
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end) throws IOException {
|
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end) throws IOException {
|
||||||
boolean relaxingStrategy = false;
|
boolean relaxingStrategy = true;
|
||||||
// measure time
|
// measure time
|
||||||
ctx.timeToLoad = 0;
|
ctx.timeToLoad = 0;
|
||||||
ctx.visitedSegments = 0;
|
ctx.visitedSegments = 0;
|
||||||
|
@ -308,7 +308,7 @@ public class BinaryRoutePlanner {
|
||||||
mine = s.distanceToEnd;
|
mine = s.distanceToEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double d = mine * 2.5;
|
double d = mine * 3;
|
||||||
iterator = graphSegments.iterator();
|
iterator = graphSegments.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
RouteSegment s = iterator.next();
|
RouteSegment s = iterator.next();
|
||||||
|
@ -771,6 +771,7 @@ public class BinaryRoutePlanner {
|
||||||
}
|
}
|
||||||
Collections.reverse(result);
|
Collections.reverse(result);
|
||||||
// calculate time
|
// calculate time
|
||||||
|
float completeTime = 0;
|
||||||
for (int i = 0; i < result.size(); i++) {
|
for (int i = 0; i < result.size(); i++) {
|
||||||
RouteSegmentResult rr = result.get(i);
|
RouteSegmentResult rr = result.get(i);
|
||||||
RouteDataObject road = rr.getObject();
|
RouteDataObject road = rr.getObject();
|
||||||
|
@ -790,6 +791,7 @@ public class BinaryRoutePlanner {
|
||||||
// last point turn time can be added
|
// last point turn time can be added
|
||||||
// if(i + 1 < result.size()) { distOnRoadToPass += ctx.getRouter().calculateTurnTime(); }
|
// if(i + 1 < result.size()) { distOnRoadToPass += ctx.getRouter().calculateTurnTime(); }
|
||||||
rr.setSegmentTime((float) distOnRoadToPass);
|
rr.setSegmentTime((float) distOnRoadToPass);
|
||||||
|
completeTime += distOnRoadToPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST) {
|
if (PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST) {
|
||||||
|
@ -799,8 +801,8 @@ public class BinaryRoutePlanner {
|
||||||
double endLat = MapUtils.get31LatitudeY(ctx.targetEndY);
|
double endLat = MapUtils.get31LatitudeY(ctx.targetEndY);
|
||||||
double endLon = MapUtils.get31LongitudeX(ctx.targetEndX);
|
double endLon = MapUtils.get31LongitudeX(ctx.targetEndX);
|
||||||
System.out.println(MessageFormat.format("<test regions=\"\" description=\"\" best_percent=\"\" vehicle=\"\" \n" +
|
System.out.println(MessageFormat.format("<test regions=\"\" description=\"\" best_percent=\"\" vehicle=\"\" \n" +
|
||||||
" start_lat=\"{0}\" start_lon=\"{1}\" target_lat=\"{2}\" target_lon=\"{3}\">",
|
" start_lat=\"{0}\" start_lon=\"{1}\" target_lat=\"{2}\" target_lon=\"{3}\" complete_time=\"{4}\">",
|
||||||
startLat+"", startLon+"", endLat+"", endLon+""));
|
startLat+"", startLon+"", endLat+"", endLon+"", completeTime+""));
|
||||||
for (RouteSegmentResult res : result) {
|
for (RouteSegmentResult res : result) {
|
||||||
String name = "Unknown";//res.object.getName();
|
String name = "Unknown";//res.object.getName();
|
||||||
String ref = "";//res.object.getNameByType(res.object.getMapIndex().refEncodingType);
|
String ref = "";//res.object.getNameByType(res.object.getMapIndex().refEncodingType);
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class RoutingContext {
|
||||||
TIntSet loadedTiles = new TIntHashSet();
|
TIntSet loadedTiles = new TIntHashSet();
|
||||||
// TODO delete this object ?
|
// TODO delete this object ?
|
||||||
TLongObjectHashMap<RouteDataObject> idObjects = new TLongObjectHashMap<RouteDataObject>();
|
TLongObjectHashMap<RouteDataObject> idObjects = new TLongObjectHashMap<RouteDataObject>();
|
||||||
|
int relaxedIteration = 0;
|
||||||
|
|
||||||
// 4. Warm object caches
|
// 4. Warm object caches
|
||||||
TLongSet nonRestrictedIds = new TLongHashSet();
|
TLongSet nonRestrictedIds = new TLongHashSet();
|
||||||
|
@ -58,7 +59,6 @@ public class RoutingContext {
|
||||||
long timeToCalculate = 0;
|
long timeToCalculate = 0;
|
||||||
int visitedSegments = 0;
|
int visitedSegments = 0;
|
||||||
int relaxedSegments = 0;
|
int relaxedSegments = 0;
|
||||||
int relaxedIteration = 0;
|
|
||||||
// callback of processing segments
|
// callback of processing segments
|
||||||
RouteSegmentVisitor visitor = null;
|
RouteSegmentVisitor visitor = null;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import net.osmand.LogUtil;
|
||||||
import net.osmand.OsmAndFormatter;
|
import net.osmand.OsmAndFormatter;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.osm.LatLon;
|
import net.osmand.osm.LatLon;
|
||||||
import net.osmand.osm.MapUtils;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -159,6 +158,35 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end) {
|
||||||
|
// TODO put directions information
|
||||||
|
this.directions = null;
|
||||||
|
this.errorMessage = null;
|
||||||
|
this.locations = new ArrayList<Location>();
|
||||||
|
|
||||||
|
for (RouteSegmentResult s : list) {
|
||||||
|
boolean plus = s.getStartPointIndex() < s.getEndPointIndex();
|
||||||
|
int i = s.getStartPointIndex();
|
||||||
|
while (true) {
|
||||||
|
Location n = new Location(""); //$NON-NLS-1$
|
||||||
|
LatLon point = s.getPoint(i);
|
||||||
|
n.setLatitude(point.getLatitude());
|
||||||
|
n.setLongitude(point.getLongitude());
|
||||||
|
locations.add(n);
|
||||||
|
if (i == s.getEndPointIndex()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (plus) {
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
introduceFirstPoint(start);
|
||||||
|
updateListDistanceTime();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Location> getLocations() {
|
public List<Location> getLocations() {
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
@ -172,24 +200,37 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareResult(Location start, LatLon end) {
|
private void prepareResult(Location start, LatLon end) {
|
||||||
|
|
||||||
if (locations != null && !locations.isEmpty()) {
|
if (locations != null && !locations.isEmpty()) {
|
||||||
// if there is no closest points to start - add it
|
// if there is no closest points to start - add it
|
||||||
if (locations.get(0).distanceTo(start) > 200) {
|
introduceFirstPoint(start);
|
||||||
// add start point
|
|
||||||
locations.add(0, start);
|
checkForDuplicatePoints();
|
||||||
if (directions != null) {
|
// Remove unnecessary go straight from CloudMade
|
||||||
for (RouteDirectionInfo i : directions) {
|
// Remove also last direction because it will be added after
|
||||||
i.routePointOffset++;
|
removeUnnecessaryGoAhead();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateListDistanceTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove unnecessary go straight from CloudMade
|
||||||
|
// Remove also last direction because it will be added after
|
||||||
|
private void removeUnnecessaryGoAhead() {
|
||||||
|
if(directions != null && directions.size() > 1){
|
||||||
|
for (int i = 1; i < directions.size(); ) {
|
||||||
|
RouteDirectionInfo r = directions.get(i);
|
||||||
|
if(r.turnType.getValue().equals(TurnType.C)){
|
||||||
|
RouteDirectionInfo prev = directions.get(i-1);
|
||||||
|
prev.expectedTime += r.expectedTime;
|
||||||
|
directions.remove(i);
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RouteDirectionInfo info = new RouteDirectionInfo();
|
|
||||||
info.turnType = TurnType.valueOf(TurnType.C, false);
|
|
||||||
info.routePointOffset = 0;
|
|
||||||
info.descriptionRoute = "" ;//getString(ctx, R.string.route_head); //$NON-NLS-1$
|
|
||||||
directions.add(0, info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkForDuplicatePoints() {
|
||||||
// check points for duplicates (it is very bad for routing) - cloudmade could return it
|
// check points for duplicates (it is very bad for routing) - cloudmade could return it
|
||||||
for (int i = 0; i < locations.size() - 1; ) {
|
for (int i = 0; i < locations.size() - 1; ) {
|
||||||
if(locations.get(i).distanceTo(locations.get(i+1)) == 0){
|
if(locations.get(i).distanceTo(locations.get(i+1)) == 0){
|
||||||
|
@ -205,22 +246,24 @@ public class RouteProvider {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove unnecessary go straight from CloudMade
|
}
|
||||||
// Remove also last direction because it will be added after
|
private void introduceFirstPoint(Location start) {
|
||||||
if(directions != null && directions.size() > 1){
|
if (locations.get(0).distanceTo(start) > 200) {
|
||||||
for (int i = 1; i < directions.size(); ) {
|
// add start point
|
||||||
RouteDirectionInfo r = directions.get(i);
|
locations.add(0, start);
|
||||||
if(r.turnType.getValue().equals(TurnType.C)){
|
if (directions != null) {
|
||||||
RouteDirectionInfo prev = directions.get(i-1);
|
for (RouteDirectionInfo i : directions) {
|
||||||
prev.expectedTime += r.expectedTime;
|
i.routePointOffset++;
|
||||||
directions.remove(i);
|
}
|
||||||
} else {
|
RouteDirectionInfo info = new RouteDirectionInfo();
|
||||||
i++;
|
info.turnType = TurnType.valueOf(TurnType.C, false);
|
||||||
|
info.routePointOffset = 0;
|
||||||
|
info.descriptionRoute = "" ;//getString(ctx, R.string.route_head); //$NON-NLS-1$
|
||||||
|
directions.add(0, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
private void updateListDistanceTime() {
|
||||||
|
|
||||||
listDistance = new int[locations.size()];
|
listDistance = new int[locations.size()];
|
||||||
if (!locations.isEmpty()) {
|
if (!locations.isEmpty()) {
|
||||||
listDistance[locations.size() - 1] = 0;
|
listDistance[locations.size() - 1] = 0;
|
||||||
|
@ -633,29 +676,10 @@ public class RouteProvider {
|
||||||
if (en == null) {
|
if (en == null) {
|
||||||
return new RouteCalculationResult("End point is far from allowed road.");
|
return new RouteCalculationResult("End point is far from allowed road.");
|
||||||
}
|
}
|
||||||
List<Location> res = new ArrayList<Location>();
|
|
||||||
try {
|
try {
|
||||||
List<RouteSegmentResult> result = router.searchRoute(ctx, st, en);
|
List<RouteSegmentResult> result = router.searchRoute(ctx, st, en);
|
||||||
for (RouteSegmentResult s : result) {
|
|
||||||
boolean plus = s.getStartPointIndex() < s.getEndPointIndex();
|
return new RouteCalculationResult(result, start, end);
|
||||||
int i = s.getStartPointIndex();
|
|
||||||
while (true) {
|
|
||||||
Location n = new Location(""); //$NON-NLS-1$
|
|
||||||
LatLon point = s.getPoint(i);
|
|
||||||
n.setLatitude(point.getLatitude());
|
|
||||||
n.setLongitude(point.getLongitude());
|
|
||||||
res.add(n);
|
|
||||||
if (i == s.getEndPointIndex()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (plus) {
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new RouteCalculationResult(res, null, start, end, null);
|
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
return new RouteCalculationResult("Not enough process memory");
|
return new RouteCalculationResult("Not enough process memory");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue