private void readTimeWindowedDepotAndCustomers() throws IOException {
String line = bufferedReader.readLine();
int locationListSizeEstimation = 25;
List<Location> locationList = new ArrayList<Location>(locationListSizeEstimation);
depotList = new ArrayList<Depot>(1);
TimeWindowedDepot depot = null;
List<Customer> customerList = new ArrayList<Customer>(locationListSizeEstimation);
boolean first = true;
while (line != null && !line.trim().isEmpty()) {
String[] lineTokens = splitBySpacesOrTabs(line.trim(), 7);
long id = Long.parseLong(lineTokens[0]);
AirLocation location = new AirLocation();
location.setId(id);
location.setLatitude(Double.parseDouble(lineTokens[1]));
location.setLongitude(Double.parseDouble(lineTokens[2]));
locationList.add(location);
int demand = Integer.parseInt(lineTokens[3]);
int readyTime = Integer.parseInt(lineTokens[4]) * 1000;
int dueTime = Integer.parseInt(lineTokens[5]) * 1000;
int serviceDuration = Integer.parseInt(lineTokens[6]) * 1000;
if (first) {
depot = new TimeWindowedDepot();
depot.setId(id);
depot.setLocation(location);
if (demand != 0) {
throw new IllegalArgumentException("The depot with id (" + id
+ ") has a demand (" + demand + ").");
}
depot.setReadyTime(readyTime);
depot.setDueTime(dueTime);
if (serviceDuration != 0) {
throw new IllegalArgumentException("The depot with id (" + id
+ ") has a serviceDuration (" + serviceDuration + ").");
}
depotList.add(depot);
first = false;
} else {
TimeWindowedCustomer customer = new TimeWindowedCustomer();
customer.setId(id);
customer.setLocation(location);
customer.setDemand(demand);
customer.setReadyTime(readyTime);
// Score constraint arrivalAfterDueTimeAtDepot is a build-in hard constraint in VehicleRoutingImporter
int maximumDueTime = depot.getDueTime()
- serviceDuration - location.getDistance(depot.getLocation());
if (dueTime > maximumDueTime) {
logger.warn("The customer ({})'s dueTime ({}) was automatically reduced" +
" to maximumDueTime ({}) because of the depot's dueTime ({}).",
customer, dueTime, maximumDueTime, depot.getDueTime());
dueTime = maximumDueTime;
}
customer.setDueTime(dueTime);
customer.setServiceDuration(serviceDuration);
// Notice that we leave the PlanningVariable properties on null