Read configuration from file

This commit is contained in:
Victor Shcherb 2018-08-07 10:05:28 +02:00
parent 80ef290476
commit 8041aebb02
3 changed files with 28 additions and 22 deletions

View file

@ -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;

View file

@ -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<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException {
ctx.startCalcTime = System.currentTimeMillis();
@ -150,8 +130,6 @@ public class TransportRoutePlanner {
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
Collections.sort(results, new SegmentsComparator(ctx));
List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>();
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)));

View file

@ -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);
}
}
}