private void interpolateGridData(TreeSet<SpatialTemporal> dataPoints) { final int size = dataPoints.size(); final double[] xMicro = new double[size]; final double[] vMicro = new double[size]; final double[] aMicro = new double[size]; int j = 0; for (SpatialTemporal dp : dataPoints) { LOG.debug("data point for interpolation={}", dp); vMicro[j] = dp.speed; xMicro[j] = dp.position; aMicro[j] = dp.acceleration; ++j; } LinearInterpolatedFunction speeds = new LinearInterpolatedFunction(xMicro, vMicro); LinearInterpolatedFunction accelerations = new LinearInterpolatedFunction(xMicro, aMicro); for (int i = 0; i < macroSpeed.length; ++i) { final double x = i * dxOutput; macroSpeed[i] = speeds.value(x); macroAcceleration[i] = accelerations.value(x); } }
private void calcRhoQMax() { Preconditions.checkNotNull(vEqFunction, "first calc equlibrium funcion vEq"); final double incr = rhoMax / (vEqFunction.getNumberOfDataPoints() - 1); qMax = -1.; double rho = 0; while (vEqFunction.value(rho) * rho > qMax) { qMax = vEqFunction.value(rho) * rho; rho += incr; } rhoQMax = rho - incr; LOG.info("rhoQMax = {}/km, qMax={}/h", rhoQMax * 1000, qMax * 3600); }
public double getSpeed(double time) { if (flowFunction == null) { return CONSTANT_INIT_SPEED; } return speedFunction.value(time); }
private void generateTimeSeriesData(List<Inflow> inflow) { final int size = inflow.size(); double[] timeValues = new double[size]; double[] flowValues = new double[size]; double[] speedValues = new double[size]; for (int i = 0; i < size; i++) { final Inflow dataPoint = inflow.get(i); timeValues[i] = dataPoint.getT(); // convert flow per lane per hour in 1/s flowValues[i] = dataPoint.getQPerHour() * Units.INVH_TO_INVS; speedValues[i] = dataPoint.getV(); // in m/s LOG.debug("add data: flow={}, speed={}", flowValues[i], speedValues[i]); } flowFunction = new LinearInterpolatedFunction(timeValues, flowValues); speedFunction = new LinearInterpolatedFunction(timeValues, speedValues); }
@Override public int getVEqCount() { return vEqFunction.getNumberOfDataPoints(); }
public double getFlowPerLane(double time) { if (flowFunction == null) { return CONSTANT_FLOW_PER_LANE; } return flowFunction.value(time); }
private LinearInterpolatedFunction createSpeedProfile(List<SpeedDataType> speedData) { int size = speedData.size(); double[] times = new double[size]; double[] speeds = new double[size]; for (int i = 0; i < size; i++) { SpeedDataType dataPoint = speedData.get(i); times[i] = TimeUtilities.convertToSeconds(dataPoint.getTime(), timeFormat); speeds[i] = dataPoint.getSpeed(); } return new LinearInterpolatedFunction(times, speeds); }
@Override public double getVEq(double rho) { // return Tables.intp(vEqTab, Math.min(rho, rhoMax), 0, rhoMax); return vEqFunction.value(rho); }
public EquilibriumPropertiesImpl(double vehicleLength, LongitudinalModelBase model) { this.rhoMax = 1.0 / Math.max(vehicleLength, TINY_VALUE); if (vehicleLength < TINY_VALUE) { LOG.warn("vehicle length is artificially small={}, assume finite length {}", vehicleLength, TINY_VALUE); } if (model.hasDesiredSpeed()) { vEqFunction = calcEquilibriumSpeedFunction(model); calcRhoQMax(); } else { double[] xDummy = new double[]{0}; vEqFunction = new LinearInterpolatedFunction(xDummy, xDummy); } }
public double rho(double x) { return rhoFct.value(x); } }
private void createFunctions(List<MacroConditionType> macroConditions) { final int size = macroConditions.size(); double[] positions = new double[size]; double[] densities = new double[size]; double[] speeds = new double[size]; for (int i = 0; i < size; i++) { MacroConditionType localMacroIC = macroConditions.get(i); final double rhoLocal = localMacroIC.getDensityPerKm() * Units.INVKM_TO_INVM; if (rhoLocal > MovsimConstants.SMALL_VALUE) { positions[i] = localMacroIC.getPosition(); densities[i] = rhoLocal; if (useUserDefinedSpeeds(macroConditions)) { speeds[i] = Math.min(localMacroIC.getSpeed(), MovsimConstants.MAX_VEHICLE_SPEED); LOG.debug("speed={}", speeds[i]); } } } rhoFct = new LinearInterpolatedFunction(positions, densities); if (useUserDefinedSpeeds(macroConditions)) { speedFct = new LinearInterpolatedFunction(positions, speeds); } }
public double vInit(double x) { Preconditions .checkNotNull(speedFct, "expected usage of equilibrium speeds, check with hasUserDefinedSpeeds"); return speedFct.value(x); }
private void initTables() { double[] uPTatab = new double[NTABMAX]; // tabulated d(U_PT)/da double[] uPTaatab = new double[NTABMAX]; // tabulated d^2(U_PT)/da^2 double[] acc = new double[NTABMAX]; // in File Constructor: Initialize Tables of d(U_PT)/da and d^2(U_PT)/da^2 for (int i = 0; i < NTABMAX; i++) { final double a = param.getBMax() * (-1 + 2 * i / ((double) (NTABMAX - 1))); double x = a / param.getA0(); double lorenz = 1 / (1 + x * x); double g = x * Math.pow(lorenz, delta); double gx = Math.pow(lorenz, delta) - 2 * delta * x * x * Math.pow(lorenz, delta + 1); double gxx = -6 * delta * x * Math.pow(lorenz, delta + 1) + 4 * delta * (delta + 1) * Math.pow(x, 3) * Math.pow(lorenz, delta + 2); double prefactor = param.getWeightMinus() + 0.5 * dw * (1 + Math.tanh(x)); double cosh2 = Math.pow(Math.cosh(x), 2); acc[i] = a; uPTatab[i] = 1 / param.getA0() * (prefactor * gx + 0.5 * dw * g / cosh2); uPTaatab[i] = 1 / (param.getA0() * param.getA0()) * (prefactor * gxx + dw / cosh2 * (gx - Math.tanh(x) * g)); } this.uPTaFunction = new LinearInterpolatedFunction(acc, uPTatab); this.uPaaFunction = new LinearInterpolatedFunction(acc, uPTaatab); }
/** * sets the speeds of externally controlled vehicles in whole road network */ public void setSpeeds(double simulationTime) { for (Entry<Vehicle, LinearInterpolatedFunction> entry : controlledVehicles.entrySet()) { double currentSpeed = entry.getValue().value(simulationTime); Vehicle vehicle = entry.getKey(); vehicle.setSpeed(currentSpeed); } }
return new LinearInterpolatedFunction(rhoTab, vEqTab);
private double get_uPTa(double a) { double wm = param.getWeightMinus(); double bMax = param.getBMax(); double uPT = Math.min(bMax, Math.max(-bMax, uPTaFunction.value(a))); return (a <= -bMax) ? wm * (1 - 2 * delta) * Math.pow(a / param.getA0(), -2 * delta) : (a < bMax) ? uPT : (wm + dw) * (1 - 2 * delta) * Math.pow(a / param.getA0(), -2 * delta); }
private double get_uPTaa(double a) { double bmax = param.getBMax(); double aPT = Math.min(bmax, Math.max(-bmax, uPaaFunction.value(a))); return (a <= -bmax) ? -param.getWeightMinus() * 2 * delta * (1 - 2 * delta) * Math.pow(a / param.getA0(), -2 * delta - 1) : (a < bmax) ? aPT : -(param.getWeightMinus() + dw) * 2 * delta * (1 - 2 * delta) * Math.pow(a / param.getA0(), -2 * delta - 1); }