2018-08-04 13:03:06 +02:00
|
|
|
package net.osmand.router;
|
|
|
|
|
2019-03-17 14:09:41 +01:00
|
|
|
import java.util.BitSet;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
|
import net.osmand.router.GeneralRouter.RouteAttributeContext;
|
|
|
|
import net.osmand.router.GeneralRouter.RouteDataObjectAttribute;
|
|
|
|
|
2018-08-04 13:03:06 +02:00
|
|
|
public class TransportRoutingConfiguration {
|
|
|
|
|
2018-08-07 10:05:28 +02:00
|
|
|
public static final String KEY = "public_transport";
|
2018-08-04 13:03:06 +02:00
|
|
|
|
2019-03-15 14:41:05 +01:00
|
|
|
public int ZOOM_TO_LOAD_TILES = 15;
|
2018-08-04 13:03:06 +02:00
|
|
|
|
2018-08-05 10:55:08 +02:00
|
|
|
public int walkRadius = 1500; // ? 3000
|
2018-08-04 13:03:06 +02:00
|
|
|
|
|
|
|
public int walkChangeRadius = 300;
|
|
|
|
|
2019-03-17 17:06:30 +01:00
|
|
|
public int maxNumberOfChanges = 3;
|
2018-08-04 13:03:06 +02:00
|
|
|
|
|
|
|
public int finishTimeSeconds = 1200;
|
|
|
|
|
2019-03-05 23:49:48 +01:00
|
|
|
public int maxRouteTime = 60 * 60 * 10; // 10 hours
|
2018-08-15 14:43:47 +02:00
|
|
|
|
2019-03-17 14:09:41 +01:00
|
|
|
public GeneralRouter router;
|
|
|
|
// cache values from router for fast access
|
|
|
|
public float walkSpeed = (float) (3.6 / 3.6); // m/s
|
|
|
|
public float defaultTravelSpeed = (float) (60 / 3.6); // m/s
|
|
|
|
public int stopTime = 30;
|
|
|
|
public int changeTime = 180;
|
|
|
|
public int boardingTime = 180;
|
2018-08-15 14:43:47 +02:00
|
|
|
|
2019-03-17 14:09:41 +01:00
|
|
|
public boolean useSchedule;
|
2018-08-15 14:43:47 +02:00
|
|
|
// 10 seconds based
|
2018-08-20 21:00:22 +02:00
|
|
|
public int scheduleTimeOfDay = 12 * 60 * 6; // 12:00 - 60*6*12
|
|
|
|
public int scheduleMaxTime = 50 * 6; // TODO not appropriate variable, should be dynamic
|
2018-08-15 14:43:47 +02:00
|
|
|
// day since 2000
|
|
|
|
public int scheduleDayNumber;
|
2019-03-17 14:09:41 +01:00
|
|
|
|
|
|
|
private Map<String, Integer> rawTypes = new HashMap<String, Integer>();
|
|
|
|
private Map<String, Float> speed = new TreeMap<String, Float>();
|
|
|
|
|
|
|
|
|
|
|
|
public float getSpeedByRouteType(String routeType) {
|
|
|
|
Float sl = speed.get(routeType);
|
|
|
|
if(sl == null) {
|
|
|
|
RouteAttributeContext spds = router.getObjContext(RouteDataObjectAttribute.ROAD_SPEED);
|
|
|
|
sl = spds.evaluateFloat(getRawBitset("route", routeType), defaultTravelSpeed);
|
|
|
|
speed.put(routeType, sl);
|
|
|
|
}
|
|
|
|
return sl.floatValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getRawType(String tg, String vl) {
|
|
|
|
String key = tg + "$"+vl;
|
|
|
|
if(!rawTypes.containsKey(key)) {
|
|
|
|
int at = router.registerTagValueAttribute(tg, vl);
|
|
|
|
rawTypes.put(key, at);
|
|
|
|
}
|
|
|
|
return rawTypes.get(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private BitSet getRawBitset(String tg, String vl) {
|
|
|
|
BitSet bs = new BitSet();
|
|
|
|
bs.set(getRawType(tg, vl));
|
|
|
|
return bs;
|
|
|
|
}
|
2018-08-15 14:43:47 +02:00
|
|
|
|
2018-08-05 22:35:28 +02:00
|
|
|
|
2018-08-20 21:00:22 +02:00
|
|
|
public int getChangeTime() {
|
2019-03-17 14:09:41 +01:00
|
|
|
return useSchedule ? 0 : changeTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBoardingTime() {
|
|
|
|
return boardingTime;
|
2018-08-20 21:00:22 +02:00
|
|
|
}
|
2018-08-07 10:05:28 +02:00
|
|
|
|
|
|
|
public TransportRoutingConfiguration(RoutingConfiguration.Builder builder) {
|
2019-03-17 14:15:54 +01:00
|
|
|
this(builder, new TreeMap<String, String>());
|
2019-03-17 14:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public TransportRoutingConfiguration(RoutingConfiguration.Builder builder, Map<String, String> params) {
|
|
|
|
GeneralRouter prouter = builder == null ? null : builder.getRouter("public_transport");
|
|
|
|
if(prouter != null) {
|
|
|
|
this.router = prouter.build(params);
|
2018-08-07 10:05:28 +02:00
|
|
|
walkRadius = router.getIntAttribute("walkRadius", walkRadius);
|
2019-03-17 14:09:41 +01:00
|
|
|
walkChangeRadius = router.getIntAttribute("walkChangeRadius", walkChangeRadius);
|
2018-08-07 10:05:28 +02:00
|
|
|
ZOOM_TO_LOAD_TILES = router.getIntAttribute("zoomToLoadTiles", ZOOM_TO_LOAD_TILES);
|
|
|
|
maxNumberOfChanges = router.getIntAttribute("maxNumberOfChanges", maxNumberOfChanges);
|
2019-03-06 01:46:23 +01:00
|
|
|
maxRouteTime = router.getIntAttribute("maxRouteTime", maxRouteTime);
|
2018-08-07 10:05:28 +02:00
|
|
|
finishTimeSeconds = router.getIntAttribute("delayForAlternativesRoutes", finishTimeSeconds);
|
2019-03-17 14:09:41 +01:00
|
|
|
String mn = params.get("max_num_changes");
|
|
|
|
maxNumberOfChanges = RoutingConfiguration.parseSilentInt(mn, maxNumberOfChanges);
|
|
|
|
|
|
|
|
walkSpeed = router.getFloatAttribute("minDefaultSpeed", this.walkSpeed * 3.6f) / 3.6f;
|
|
|
|
defaultTravelSpeed = router.getFloatAttribute("maxDefaultSpeed", this.defaultTravelSpeed * 3.6f) / 3.6f;
|
|
|
|
|
|
|
|
RouteAttributeContext obstacles = router.getObjContext(RouteDataObjectAttribute.ROUTING_OBSTACLES);
|
|
|
|
stopTime = obstacles.evaluateInt(getRawBitset("time", "stop"), stopTime);
|
|
|
|
changeTime = obstacles.evaluateInt(getRawBitset("time", "change"), changeTime);
|
|
|
|
boardingTime = obstacles.evaluateInt(getRawBitset("time", "boarding"), boardingTime);
|
|
|
|
|
|
|
|
RouteAttributeContext spds = router.getObjContext(RouteDataObjectAttribute.ROAD_SPEED);
|
|
|
|
walkSpeed = spds.evaluateFloat(getRawBitset("route", "walk"), walkSpeed);
|
|
|
|
|
2018-08-07 10:05:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 13:03:06 +02:00
|
|
|
}
|