1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add check to prevent SolomonReader to throw IndexOutOfBoundsException when reading file ending with empty lines

This commit is contained in:
oblonski 2014-09-16 10:28:05 +02:00
parent 694baae04b
commit f6d06c0b48
2 changed files with 13 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -21,7 +21,6 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.util.Coordinate;
@ -81,7 +80,7 @@ public class SolomonReader {
int vehicleCapacity = 0;
int counter = 0;
String line = null;
String line;
while((line = readLine(reader)) != null){
line = line.replace("\r", "");
line = line.trim();
@ -92,6 +91,7 @@ public class SolomonReader {
continue;
}
if(counter > 9){
if(tokens.length < 7) continue;
Coordinate coord = makeCoord(tokens[1],tokens[2]);
String customerId = tokens[0];
int demand = Integer.parseInt(tokens[3]);
@ -101,13 +101,10 @@ public class SolomonReader {
if(counter == 10){
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
VehicleTypeImpl vehicleType = typeBuilder.build();
Vehicle vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end)
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end)
.setStartLocationId(customerId).setStartLocationCoordinate(coord).setType(vehicleType).build();
// vrpBuilder.addVehicleType(vehicleType);
vrpBuilder.addVehicle(vehicle);
}

View file

@ -108,3 +108,5 @@ CUST NO. XCOORD. YCOORD. DEMAND READY TIME DUE DATE SERVICE TIME
98 58 75 20 30 84 90
99 55 80 10 743 820 90
100 55 85 20 647 726 90