|
| 1 | +/** |
| 2 | + * Container for link between two Osm nodes |
| 3 | + * |
| 4 | + * @author ab |
| 5 | + */ |
| 6 | +package btools.router; |
| 7 | + |
| 8 | +import java.util.Map; |
| 9 | + |
| 10 | +import btools.expressions.BExpressionContextNode; |
| 11 | +import btools.expressions.BExpressionContextWay; |
| 12 | + |
| 13 | + |
| 14 | +final class KinematicWeightModel extends OsmPathModel { |
| 15 | + public OsmPrePath createPrePath() { |
| 16 | + return new KinematicPrePath(); |
| 17 | + } |
| 18 | + |
| 19 | + public OsmPath createPath() { |
| 20 | + return new KinematicWeightPath(); |
| 21 | + } |
| 22 | + |
| 23 | + public double turnAngleDecayTime; |
| 24 | + public double f_roll; |
| 25 | + public double f_air; |
| 26 | + public double f_recup; |
| 27 | + public double p_standby; |
| 28 | + public double outside_temp; |
| 29 | + public double recup_efficiency; |
| 30 | + public double totalweight; |
| 31 | + public double vmax; |
| 32 | + public double leftWaySpeed; |
| 33 | + public double rightWaySpeed; |
| 34 | + |
| 35 | + // derived values |
| 36 | + public double pw; // balance power |
| 37 | + public double cost0; // minimum possible cost per meter |
| 38 | + |
| 39 | + private int wayIdxMaxspeed; |
| 40 | + private int wayIdxMaxspeedExplicit; |
| 41 | + private int wayIdxMinspeed; |
| 42 | + |
| 43 | + private int nodeIdxMaxspeed; |
| 44 | + |
| 45 | + protected BExpressionContextWay ctxWay; |
| 46 | + protected BExpressionContextNode ctxNode; |
| 47 | + protected Map<String, String> params; |
| 48 | + |
| 49 | + private boolean initDone = false; |
| 50 | + |
| 51 | + private double lastEffectiveLimit; |
| 52 | + private double lastBreakingSpeed; |
| 53 | + |
| 54 | + @Override |
| 55 | + public void init(BExpressionContextWay expctxWay, BExpressionContextNode expctxNode, Map<String, String> extraParams) { |
| 56 | + if (!initDone) { |
| 57 | + ctxWay = expctxWay; |
| 58 | + ctxNode = expctxNode; |
| 59 | + wayIdxMaxspeed = ctxWay.getOutputVariableIndex("maxspeed", false); |
| 60 | + wayIdxMaxspeedExplicit = ctxWay.getOutputVariableIndex("maxspeed_explicit", false); |
| 61 | + wayIdxMinspeed = ctxWay.getOutputVariableIndex("minspeed", false); |
| 62 | + nodeIdxMaxspeed = ctxNode.getOutputVariableIndex("maxspeed", false); |
| 63 | + initDone = true; |
| 64 | + } |
| 65 | + |
| 66 | + params = extraParams; |
| 67 | + |
| 68 | + turnAngleDecayTime = getParam("turnAngleDecayTime", 5.f); |
| 69 | + f_roll = getParam("f_roll", 232.f); |
| 70 | + f_air = getParam("f_air", 0.4f); |
| 71 | + f_recup = getParam("f_recup", 400.f); |
| 72 | + p_standby = getParam("p_standby", 250.f); |
| 73 | + outside_temp = getParam("outside_temp", 20.f); |
| 74 | + recup_efficiency = getParam("recup_efficiency", 0.7f); |
| 75 | + totalweight = getParam("totalweight", 1640.f); |
| 76 | + vmax = getParam("vmax", 80.f) / 3.6; |
| 77 | + leftWaySpeed = getParam("leftWaySpeed", 12.f) / 3.6; |
| 78 | + rightWaySpeed = getParam("rightWaySpeed", 12.f) / 3.6; |
| 79 | + |
| 80 | + pw = 2. * f_air * vmax * vmax * vmax - p_standby; |
| 81 | + cost0 = (pw + p_standby) / vmax + f_roll + f_air * vmax * vmax; |
| 82 | + } |
| 83 | + |
| 84 | + protected float getParam(String name, float defaultValue) { |
| 85 | + String sval = params == null ? null : params.get(name); |
| 86 | + if (sval != null) { |
| 87 | + return Float.parseFloat(sval); |
| 88 | + } |
| 89 | + float v = ctxWay.getVariableValue(name, defaultValue); |
| 90 | + if (params != null) { |
| 91 | + params.put(name, "" + v); |
| 92 | + } |
| 93 | + return v; |
| 94 | + } |
| 95 | + |
| 96 | + public float getWayMaxspeed() { |
| 97 | + return ctxWay.getBuildInVariable(wayIdxMaxspeed) / 3.6f; |
| 98 | + } |
| 99 | + |
| 100 | + public float getWayMaxspeedExplicit() { |
| 101 | + return ctxWay.getBuildInVariable(wayIdxMaxspeedExplicit) / 3.6f; |
| 102 | + } |
| 103 | + |
| 104 | + public float getWayMinspeed() { |
| 105 | + return ctxWay.getBuildInVariable(wayIdxMinspeed) / 3.6f; |
| 106 | + } |
| 107 | + |
| 108 | + public float getNodeMaxspeed() { |
| 109 | + return ctxNode.getBuildInVariable(nodeIdxMaxspeed) / 3.6f; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * get the effective speed limit from the way-limit and vmax/vmin |
| 114 | + */ |
| 115 | + public double getEffectiveSpeedLimit() { |
| 116 | + // performance related inline coding |
| 117 | + double minspeed = getWayMinspeed(); |
| 118 | + double espeed = minspeed > vmax ? minspeed : vmax; |
| 119 | + double maxspeed = getWayMaxspeed(); |
| 120 | + return maxspeed < espeed ? maxspeed : espeed; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * get the breaking speed for current balance-power (pw) and effective speed limit (vl) |
| 125 | + */ |
| 126 | + public double getBreakingSpeed(double vl) { |
| 127 | + if (vl == lastEffectiveLimit) { |
| 128 | + return lastBreakingSpeed; |
| 129 | + } |
| 130 | + |
| 131 | + double v = vl * 0.8; |
| 132 | + double pw2 = pw + p_standby; |
| 133 | + double e = recup_efficiency; |
| 134 | + double x0 = pw2 / vl + f_air * e * vl * vl + (1. - e) * f_roll; |
| 135 | + for (int i = 0; i < 5; i++) { |
| 136 | + double v2 = v * v; |
| 137 | + double x = pw2 / v + f_air * e * v2 - x0; |
| 138 | + double dx = 2. * e * f_air * v - pw2 / v2; |
| 139 | + v -= x / dx; |
| 140 | + } |
| 141 | + lastEffectiveLimit = vl; |
| 142 | + lastBreakingSpeed = v; |
| 143 | + |
| 144 | + return v; |
| 145 | + } |
| 146 | + |
| 147 | +} |
0 commit comments