// final double lengthTruck = 16.0;
RoadSegment.resetNextId();
Vehicle.resetNextId();
final double roadLength = 1000.0;
final int laneCount = 2;
final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);
final double minimumGap = 2.0;
final double tooSmallGap = 1.0;
final double safeDeceleration = 4.0;
final double politeness = 0.1;
final double thresholdAcceleration = 0.2;
final double rightBiasAcceleration = 0.3;
// set up a vehicle in most inner lane (left lane)
final Vehicle v1 = newVehicle(900.0, 0.0, Lanes.LANE1, lengthCar);
final MOBIL m1 = new MOBIL(v1, createModelParameterMOBIL(minimumGap, safeDeceleration, politeness,
thresholdAcceleration, rightBiasAcceleration));
final LaneChangeModel lcm1 = new LaneChangeModel(v1, createLaneChangeModelType(m1.getParameter()));
v1.setLaneChangeModel(lcm1);
roadSegment.addVehicle(v1);
// set up a vehicle in right lane
final Vehicle v2 = newVehicle(900.0 - lengthCar - tooSmallGap, 0.0, Lanes.LANE2, lengthCar);
final MOBIL m2 = new MOBIL(v2, createModelParameterMOBIL(minimumGap, safeDeceleration, politeness,
thresholdAcceleration, rightBiasAcceleration));
final LaneChangeModel lcm2 = new LaneChangeModel(v2, createLaneChangeModelType(m2.getParameter()));
v2.setLaneChangeModel(lcm2);
roadSegment.addVehicle(v2);
// vehicles too close together, so acceleration balance should be large negative
double balance = m1.calcAccelerationBalance(v1, Lanes.TO_RIGHT, roadSegment);
assertEquals(-Double.MAX_VALUE, balance, delta);
balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
assertEquals(-Double.MAX_VALUE, balance, delta);
// now set up with sufficient gap between vehicles, but v2 needs to decelerate, so it is not
// favourable to change lanes
roadSegment.clearVehicles();
v2.setFrontPosition(v1.getRearPosition() - 2 * minimumGap);
v2.setSpeed(80.0 / 3.6);
roadSegment.addVehicle(v1);
roadSegment.addVehicle(v2);
balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
assertTrue(balance < 0.0);
// now set up with sufficient gap between vehicles, but v1 needs to brake heavily, so it is not
// safe to change lanes
roadSegment.clearVehicles();
v2.setRearPosition(v1.getFrontPosition() + 2 * minimumGap);
v2.setSpeed(80.0 / 3.6); // 80 km/h
v1.setSpeed(120.0 / 3.6); // 120 km/h
roadSegment.addVehicle(v1);
roadSegment.addVehicle(v2);
balance = m2.calcAccelerationBalance(v2, Lanes.TO_LEFT, roadSegment);
assertEquals(-Double.MAX_VALUE, balance, delta);
}