for (Vehicle vehicle : laneSegment) {
index++;
if (vehicle.type() == Vehicle.Type.OBSTACLE) {
continue;
}
final Vehicle vehFront = laneSegment.frontVehicle(vehicle);
final double netDistance = vehicle.getNetDistance(vehFront);
if (netDistance < 0) {
LOG.error("Crash happened!!!");
final StringBuilder sb = new StringBuilder("\n");
sb.append(String.format("Crash of Vehicle i=%d (id=%d) at x=%.4f ", index, vehicle.getId(),
vehicle.getFrontPosition()));
if (vehFront != null) {
sb.append(String.format("with veh (id=%d) in front at x=%.4f on lane=%d\n", vehFront.getId(),
vehFront.getFrontPosition(), vehicle.lane()));
}
sb.append("roadID=").append(id);
sb.append(", user roadID=").append(userId);
sb.append(", net distance=").append(netDistance);
sb.append(", lane=").append(laneSegment.lane());
sb.append(", container.size=").append(laneSegment.vehicleCount());
sb.append(", obstacles=").append(laneSegment.obstacleCount());
sb.append("\n");
for (int j = Math.max(0, index - 8), M = laneSegment.vehicleCount(); j <= Math
.min(index + 8, M - 1); j++) {
final Vehicle veh = laneSegment.getVehicle(j);
sb.append(String
.format("veh=%d, pos=%6.2f, speed=%4.2f, accModel=%4.3f, acc=%4.3f, length=%3.1f, lane=%d, id=%d%n",
j, veh.getFrontPosition(), veh.getSpeed(), veh.accModel(), veh.getAcc(),
veh.getLength(), veh.lane(), veh.getId()));
}
LOG.error(sb.toString());
if (isWithCrashExit) {
LOG.error(" !!! exit after crash !!! ");
System.exit(-99);