}
int colorIndex = 0;
// TODO Too many nested for loops
for (VrpVehicle vehicle : schedule.getVehicleList()) {
g.setColor(TangoColors.SEQUENCE_2[colorIndex]);
VrpCustomer vehicleInfoCustomer = null;
int longestNonDepotDistance = -1;
int load = 0;
for (VrpCustomer customer : schedule.getCustomerList()) {
if (customer.getPreviousAppearance() != null && customer.getVehicle() == vehicle) {
load += customer.getDemand();
VrpLocation previousLocation = customer.getPreviousAppearance().getLocation();
int previousX = translator.translateLongitudeToX(previousLocation.getLongitude());
int previousY = translator.translateLatitudeToY(previousLocation.getLatitude());
VrpLocation location = customer.getLocation();
int x = translator.translateLongitudeToX(location.getLongitude());
int y = translator.translateLatitudeToY(location.getLatitude());
g.drawLine(previousX, previousY, x, y);
// Determine where to draw the vehicle info
int distance = customer.getDistanceToPreviousAppearance();
if (customer.getPreviousAppearance() instanceof VrpCustomer) {
if (longestNonDepotDistance < distance) {
longestNonDepotDistance = distance;
vehicleInfoCustomer = customer;
}
} else if (vehicleInfoCustomer == null) {
// If there is only 1 customer in this chain, draw it on a line to the Depot anyway
vehicleInfoCustomer = customer;
}
// Line back to the vehicle depot
boolean needsBackToVehicleLineDraw = true;
for (VrpCustomer trailingCustomer : schedule.getCustomerList()) {
if (trailingCustomer.getPreviousAppearance() == customer) {
needsBackToVehicleLineDraw = false;
break;
}
}
if (needsBackToVehicleLineDraw) {
VrpLocation vehicleLocation = vehicle.getLocation();
int vehicleX = translator.translateLongitudeToX(vehicleLocation.getLongitude());
int vehicleY = translator.translateLatitudeToY(vehicleLocation.getLatitude());
g.drawLine(x, y,vehicleX, vehicleY);
}
}
}
// Draw vehicle info
if (vehicleInfoCustomer != null) {
if (load > vehicle.getCapacity()) {
g.setColor(TangoColors.SCARLET_2);
}
VrpLocation previousLocation = vehicleInfoCustomer.getPreviousAppearance().getLocation();
VrpLocation location = vehicleInfoCustomer.getLocation();
double longitude = (previousLocation.getLongitude() + location.getLongitude()) / 2.0;
int x = translator.translateLongitudeToX(longitude);
double latitude = (previousLocation.getLatitude() + location.getLatitude()) / 2.0;
int y = translator.translateLatitudeToY(latitude);
boolean ascending = (previousLocation.getLongitude() < location.getLongitude())