From 8041aebb0262c76fa04096d3c103cd64f408a836 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Aug 2018 10:05:28 +0200 Subject: [PATCH] Read configuration from file --- .../java/net/osmand/router/GeneralRouter.java | 8 +++++++ .../osmand/router/TransportRoutePlanner.java | 22 ------------------- .../router/TransportRoutingConfiguration.java | 20 +++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index 08e5ea8251..efc99f6982 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -444,6 +444,14 @@ public class GeneralRouter implements VehicleRouter { return attributes.get(attribute); } + public float getFloatAttribute(String attribute, float v) { + return parseSilentFloat(getAttribute(attribute), v); + } + + public int getIntAttribute(String attribute, int v) { + return (int) parseSilentFloat(getAttribute(attribute), v); + } + private static boolean parseSilentBoolean(String t, boolean v) { if (t == null || t.length() == 0) { return v; diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index 97038debe2..bd7561aee9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -5,9 +5,7 @@ import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TLongObjectHashMap; -import java.io.File; import java.io.IOException; -import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -28,24 +26,6 @@ import net.osmand.util.MapUtils; public class TransportRoutePlanner { - public static void main(String[] args) throws IOException { - File fl = new File(System.getProperty("maps.dir"), "Netherlands_noord-holland_europe_2.obf"); - RandomAccessFile raf = new RandomAccessFile(fl, "r"); - BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl); - - LatLon start = new LatLon(52.28094, 4.853248); -// LatLon end = new LatLon(52.320988, 4.87256); - LatLon end = new LatLon(52.349308, 4.9017425); - - TransportRoutingConfiguration cfg = new TransportRoutingConfiguration(); - cfg.maxNumberOfChanges = 3; - cfg.walkRadius = 1500; -// cfg.walkChangeRadius = 500; - TransportRoutingContext ctx = new TransportRoutingContext(cfg, reader); - TransportRoutePlanner planner = new TransportRoutePlanner(); - planner.buildRoute(ctx, start, end); - - } public List buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException { ctx.startCalcTime = System.currentTimeMillis(); @@ -150,8 +130,6 @@ public class TransportRoutePlanner { private List prepareResults(TransportRoutingContext ctx, List results) { Collections.sort(results, new SegmentsComparator(ctx)); List lst = new ArrayList(); - System.out.println("FIX !!! " + ctx.wrongLoadedWays + " " + ctx.loadedWays + " " + - (ctx.loadTime / (1000 * 1000)) + " ms"); System.out.println(String.format("Calculated %.1f seconds, found %d results, visited %d routes, loaded %d tiles (%d ms read, %d ms total),", (System.currentTimeMillis() - ctx.startCalcTime) / 1000.0, results.size(), ctx.visitedRoutesCount, ctx.quadTree.size(), ctx.readTime / (1000 * 1000), ctx.loadTime / (1000 * 1000))); diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java index f4e04618b0..168e7122fa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutingConfiguration.java @@ -2,6 +2,7 @@ package net.osmand.router; public class TransportRoutingConfiguration { + public static final String KEY = "public_transport"; public int ZOOM_TO_LOAD_TILES = 14; @@ -23,4 +24,23 @@ public class TransportRoutingConfiguration { public int maxRouteTime = 60 * 60 * 1000; // 1000 hours + + public TransportRoutingConfiguration(RoutingConfiguration.Builder builder) { + GeneralRouter router = builder == null ? null : builder.getRouter("public_transport"); + if(router != null) { + walkRadius = router.getIntAttribute("walkRadius", walkRadius); + walkChangeRadius = router.getIntAttribute("walkChangeRadius", walkRadius); + ZOOM_TO_LOAD_TILES = router.getIntAttribute("zoomToLoadTiles", ZOOM_TO_LOAD_TILES); + maxNumberOfChanges = router.getIntAttribute("maxNumberOfChanges", maxNumberOfChanges); + finishTimeSeconds = router.getIntAttribute("delayForAlternativesRoutes", finishTimeSeconds); + + travelSpeed = router.getFloatAttribute("defaultTravelSpeed", (float) travelSpeed); + walkSpeed = router.getFloatAttribute("defaultWalkSpeed", (float) walkSpeed); + stopTime = router.getIntAttribute("defaultStopTime", stopTime); + changeTime = router.getIntAttribute("defaultChangeTime", changeTime); + + + } + } + }