Read configuration from file
This commit is contained in:
parent
80ef290476
commit
8041aebb02
3 changed files with 28 additions and 22 deletions
|
@ -444,6 +444,14 @@ public class GeneralRouter implements VehicleRouter {
|
||||||
return attributes.get(attribute);
|
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) {
|
private static boolean parseSilentBoolean(String t, boolean v) {
|
||||||
if (t == null || t.length() == 0) {
|
if (t == null || t.length() == 0) {
|
||||||
return v;
|
return v;
|
||||||
|
|
|
@ -5,9 +5,7 @@ import gnu.trove.list.array.TIntArrayList;
|
||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -28,24 +26,6 @@ import net.osmand.util.MapUtils;
|
||||||
public class TransportRoutePlanner {
|
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 {
|
public List<TransportRouteResult> buildRoute(TransportRoutingContext ctx, LatLon start, LatLon end) throws IOException {
|
||||||
ctx.startCalcTime = System.currentTimeMillis();
|
ctx.startCalcTime = System.currentTimeMillis();
|
||||||
|
@ -150,8 +130,6 @@ public class TransportRoutePlanner {
|
||||||
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
|
private List<TransportRouteResult> prepareResults(TransportRoutingContext ctx, List<TransportRouteSegment> results) {
|
||||||
Collections.sort(results, new SegmentsComparator(ctx));
|
Collections.sort(results, new SegmentsComparator(ctx));
|
||||||
List<TransportRouteResult> lst = new ArrayList<TransportRouteResult>();
|
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.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,
|
(System.currentTimeMillis() - ctx.startCalcTime) / 1000.0, results.size(), ctx.visitedRoutesCount,
|
||||||
ctx.quadTree.size(), ctx.readTime / (1000 * 1000), ctx.loadTime / (1000 * 1000)));
|
ctx.quadTree.size(), ctx.readTime / (1000 * 1000), ctx.loadTime / (1000 * 1000)));
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.router;
|
||||||
|
|
||||||
public class TransportRoutingConfiguration {
|
public class TransportRoutingConfiguration {
|
||||||
|
|
||||||
|
public static final String KEY = "public_transport";
|
||||||
|
|
||||||
public int ZOOM_TO_LOAD_TILES = 14;
|
public int ZOOM_TO_LOAD_TILES = 14;
|
||||||
|
|
||||||
|
@ -23,4 +24,23 @@ public class TransportRoutingConfiguration {
|
||||||
|
|
||||||
public int maxRouteTime = 60 * 60 * 1000; // 1000 hours
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue