/** * calculates uniform distribution with mean=0 and variance=1. * * @return random variable realization */ private static double getUniformlyDistributedRealization() { final double randomVar = MyRandom.nextDouble(); final double randomMu0Sigma1 = SQRT12 * (randomVar - 0.5); return randomMu0Sigma1; }
/** * calculates uniform distribution with mean=0 and variance=1. * * @return random variable realization */ private static double getUniformlyDistributedRealization() { final double randomVar = MyRandom.nextDouble(); final double randomMu0Sigma1 = SQRT12 * (randomVar - 0.5); return randomMu0Sigma1; }
/** * returns a realization of a uniformly distributed random variable in [-1, 1] * * @return a uniformly distributed realization in [-1, 1] */ public static double getUniformDistribution() { return 2 * MyRandom.nextDouble() - 1; }
private VehicleType determineVehicleType() { final double randomNumber = MyRandom.nextDouble(); double sumFraction = 0; for (final VehicleType vehicleType : vehicleTypes.values()) { sumFraction += vehicleType.getFraction(); if (sumFraction >= randomNumber) { return vehicleType; } } throw new IllegalStateException("no vehicle prototype found for randomNumber=" + randomNumber); }
/** * Acc simple. * * @param s * the s * @param v * the v * @param dv * the dv * @param localV0 * the local v0 * @return the double */ private double acc(double s, double v, double dv, double localV0) { final int localIntegerV0 = (int) (localV0 + 0.5); final int vLocal = (int) (v + 0.5); int vNew = 0; final double r1 = MyRandom.nextDouble(); final double pb = (vLocal < 1) ? param.getPSlowStart() : param.getPSlowdown(); final int slowdown = (r1 < pb) ? 1 : 0; final int sLoc = (int) (s + 0.5); vNew = Math.min(vLocal + 1, localIntegerV0); vNew = Math.min(vNew, sLoc); vNew = Math.max(0, vNew - slowdown); return (vNew - vLocal) / dtCA; }
final double r = MyRandom.nextDouble(); // instance of uniform(0,1) distribution final double vNew = vLower + r * (vUpper - vLower); final double aWanted = (vNew - v) / TLocal;
final double r1 = MyRandom.nextDouble(); // noise terms ~ G(0,1) final int xi = (r1 < pb) ? -1 : (r1 < pb + pa) ? 1 : 0;
public Vehicle(String label, LongitudinalModelBase longitudinalModel, VehiclePrototypeConfiguration vehInput, @Nullable LaneChangeModel lcModel) { Preconditions.checkNotNull(longitudinalModel); Preconditions.checkNotNull(vehInput); this.label = label; dimensions = new VehicleDimensions(vehInput.getLength(), vehInput.getWidth()); this.maxDeceleration = vehInput.getMaximumDeceleration(); id = nextId++; randomFix = MyRandom.nextDouble(); initialize(); this.longitudinalModel = longitudinalModel; physQuantities = new PhysicalQuantities(this); this.laneChangeModel = lcModel; if (laneChangeModel != null) { laneChangeModel.initialize(this); } // needs to be > 0 to avoid lane-changing over 2 lanes in one update // step assert FINITE_LANE_CHANGE_TIME_S > 0; this.color = Colors.randomColor(); trafficLightApproaching = new TrafficLightApproaching(); inhomogeneity = new InhomogeneityAdaption(); userData = new VehicleUserData(); }
/** * Constructor. */ public Vehicle(double rearPosition, double speed, int lane, double length, double width) { assert rearPosition >= 0.0; assert speed >= 0.0; id = nextId++; randomFix = MyRandom.nextDouble(); dimensions = new VehicleDimensions(length, width); setRearPosition(rearPosition); this.speed = speed; this.lane = lane; this.laneOld = lane; this.color = 0; maxDeceleration = 10.0; laneChangeModel = null; longitudinalModel = null; label = ""; physQuantities = new PhysicalQuantities(this); slope = 0; route = null; trafficLightApproaching = new TrafficLightApproaching(); inhomogeneity = new InhomogeneityAdaption(); userData = new VehicleUserData(); }
lastUpdateTime = simulationTime - MyRandom.nextDouble() * serviceProvider.getVehicleUpdateInterval();