break;
case ROAD_DISTANCE:
location = new RoadLocation();
break;
case SEGMENTED_ROAD_DISTANCE:
location = new RoadSegmentLocation();
break;
default:
throw new IllegalStateException("The distanceType (" + distanceType
+ ") is not implemented.");
}
location.setId(Long.parseLong(lineTokens[0]));
location.setLatitude(Double.parseDouble(lineTokens[1]));
location.setLongitude(Double.parseDouble(lineTokens[2]));
if (lineTokens.length >= 4) {
location.setName(lineTokens[3]);
}
customerLocationList.add(location);
locationMap.put(location.getId(), location);
}
if (distanceType == DistanceType.ROAD_DISTANCE) {
readConstantLine("EDGE_WEIGHT_SECTION");
for (int i = 0; i < customerListSize; i++) {
RoadLocation location = (RoadLocation) customerLocationList.get(i);
Map<RoadLocation, Double> travelDistanceMap = new LinkedHashMap<RoadLocation, Double>(customerListSize);
String line = bufferedReader.readLine();
String[] lineTokens = splitBySpacesOrTabs(line.trim(), customerListSize);
for (int j = 0; j < customerListSize; j++) {
double travelDistance = Double.parseDouble(lineTokens[j]);
if (i == j) {
if (travelDistance != 0.0) {
throw new IllegalStateException("The travelDistance (" + travelDistance
+ ") should be zero.");
}
} else {
RoadLocation otherLocation = (RoadLocation) customerLocationList.get(j);
travelDistanceMap.put(otherLocation, travelDistance);
}
}
location.setTravelDistanceMap(travelDistanceMap);
}
}
if (distanceType == DistanceType.SEGMENTED_ROAD_DISTANCE) {
readConstantLine("SEGMENTED_EDGE_WEIGHT_SECTION");
int locationListSize = hubLocationList.size() + customerListSize;
for (int i = 0; i < locationListSize; i++) {
String line = bufferedReader.readLine();
String[] lineTokens = splitBySpacesOrTabs(line.trim(), 3, null);
if (lineTokens.length % 2 != 1) {
throw new IllegalArgumentException("Invalid SEGMENTED_EDGE_WEIGHT_SECTION line (" + line + ").");
}
long id = Long.parseLong(lineTokens[0]);
Location location = locationMap.get(id);
if (location == null) {
throw new IllegalArgumentException("The location with id (" + id + ") of line (" + line + ") does not exist.");
}
Map<HubSegmentLocation, Double> hubTravelDistanceMap = new LinkedHashMap<HubSegmentLocation, Double>(lineTokens.length / 2);
Map<RoadSegmentLocation, Double> nearbyTravelDistanceMap = new LinkedHashMap<RoadSegmentLocation, Double>(lineTokens.length / 2);
for (int j = 1; j < lineTokens.length; j += 2) {
Location otherLocation = locationMap.get(Long.parseLong(lineTokens[j]));
double travelDistance = Double.parseDouble(lineTokens[j + 1]);
if (otherLocation instanceof HubSegmentLocation) {
hubTravelDistanceMap.put((HubSegmentLocation) otherLocation, travelDistance);
} else {
nearbyTravelDistanceMap.put((RoadSegmentLocation) otherLocation, travelDistance);
}
}
if (location instanceof HubSegmentLocation) {
HubSegmentLocation hubSegmentLocation = (HubSegmentLocation) location;
hubSegmentLocation.setHubTravelDistanceMap(hubTravelDistanceMap);
hubSegmentLocation.setNearbyTravelDistanceMap(nearbyTravelDistanceMap);
} else {
RoadSegmentLocation roadSegmentLocation = (RoadSegmentLocation) location;
roadSegmentLocation.setHubTravelDistanceMap(hubTravelDistanceMap);
roadSegmentLocation.setNearbyTravelDistanceMap(nearbyTravelDistanceMap);
}
}
}
List<Location> locationList;
if (distanceType == DistanceType.SEGMENTED_ROAD_DISTANCE) {