private void readLocationDistancesShuttles() throws IOException { List<RoadLocation> locationList = solution.getLocationList(); int locationListSize = locationList.size(); File file = new File(inputFile.getParentFile(), "DistanceTimesData_SHUTTLES.csv"); int locationListIndex = 0; try (BufferedReader subBufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { subBufferedReader.readLine(); // Ignore first line (comment) for (String line = subBufferedReader.readLine(); line != null; line = subBufferedReader.readLine()) { if (line.isEmpty()) { continue; } RoadLocation sourceLocation = locationList.get(locationListIndex); locationListIndex++; String[] lineTokens = splitBySemicolonSeparatedValue(line, locationListSize * 2); for (int i = 0; i < locationListSize; i++) { RoadLocation targetLocation = locationList.get(i); RoadLocationArc locationArc = sourceLocation.getTravelDistanceMap().get(targetLocation); locationArc.setShuttleDistance(Integer.parseInt(lineTokens[i * 2])); locationArc.setShuttleDuration(Integer.parseInt(lineTokens[i * 2 + 1])); } } } catch (IOException e) { throw new IllegalArgumentException("Could not read the file (" + file.getName() + ").", e); } }
private void readLocationList() throws IOException { File file = new File(inputFile.getParentFile(), "DistanceTimesCoordinates.csv"); latLongToLocationMap = new HashMap<>(); List<RoadLocation> locationList = new ArrayList<>(); long locationId = 0L; try (BufferedReader subBufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { subBufferedReader.readLine(); // Ignore first line (comment) for (String line = subBufferedReader.readLine(); line != null; line = subBufferedReader.readLine()) { if (line.isEmpty()) { continue; } String[] lineTokens = splitBySemicolonSeparatedValue(line, 2); RoadLocation location = new RoadLocation(); location.setId(locationId); locationId++; location.setLatitude(Double.parseDouble(lineTokens[0])); location.setLongitude(Double.parseDouble(lineTokens[1])); locationList.add(location); latLongToLocationMap.put( Arrays.asList(location.getLatitude(), location.getLongitude()), location); } } catch (IOException e) { throw new IllegalArgumentException("Could not read the file (" + file.getName() + ").", e); } solution.setLocationList(locationList); for (RoadLocation sourceLocation : locationList) { LinkedHashMap<RoadLocation, RoadLocationArc> travelDistanceMap = new LinkedHashMap<>(locationList.size()); for (RoadLocation targetLocation : locationList) { travelDistanceMap.put(targetLocation, new RoadLocationArc()); } sourceLocation.setTravelDistanceMap(travelDistanceMap); } readLocationDistancesCoaches(); readLocationDistancesShuttles(); }