generateVrp(new File(tspImporter.getInputDir(), "usa115475.tsp"), 50000, 500, 1000);
generateVrp(new File(tspImporter.getInputDir(), "usa115475.tsp"), 100000, 500, 2000);
}
public void generateVrp(File tspInputFile, int locationListSize, int vehicleListSize, int capacity) {
TravelingSalesmanTour tour = (TravelingSalesmanTour) tspImporter.readSolution(tspInputFile);
String name = tspInputFile.getName().replaceAll("\\d+\\.tsp", "")
+ "-n" + locationListSize + "-k" + vehicleListSize;
File vrpOutputFile = new File(vehicleRoutingDao.getDataDir(), "import/capacitated/" + name + ".vrp");
if (!vrpOutputFile.getParentFile().exists()) {
throw new IllegalArgumentException("The vrpOutputFile parent directory (" + vrpOutputFile.getParentFile()
+ ") does not exist.");
}
BufferedWriter vrpWriter = null;
try {
vrpWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(vrpOutputFile), "UTF-8"));
vrpWriter.write("NAME: " + name + "\n");
vrpWriter.write("COMMENT: Generated from " + tspInputFile.getName() + "\n");
vrpWriter.write("TYPE: CVRP\n");
vrpWriter.write("DIMENSION: " + locationListSize + "\n");
vrpWriter.write("EDGE_WEIGHT_TYPE: EUC_2D\n");
vrpWriter.write("CAPACITY: " + capacity + "\n");
vrpWriter.write("NODE_COORD_SECTION\n");
List<Location> locationList = tour.getLocationList();
double selectionDecrement = (double) locationListSize / (double) locationList.size();
double selection = (double) locationListSize;
int index = 1;
for (Location location : locationList) {
double newSelection = selection - selectionDecrement;