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:
parent
694baae04b
commit
f6d06c0b48
2 changed files with 13 additions and 14 deletions
|
|
@ -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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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.VehicleRoutingProblem.FleetSize;
|
||||||
import jsprit.core.problem.job.Service;
|
import jsprit.core.problem.job.Service;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
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.VehicleImpl;
|
||||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
@ -81,7 +80,7 @@ public class SolomonReader {
|
||||||
int vehicleCapacity = 0;
|
int vehicleCapacity = 0;
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
String line = null;
|
String line;
|
||||||
while((line = readLine(reader)) != null){
|
while((line = readLine(reader)) != null){
|
||||||
line = line.replace("\r", "");
|
line = line.replace("\r", "");
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
@ -92,6 +91,7 @@ public class SolomonReader {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(counter > 9){
|
if(counter > 9){
|
||||||
|
if(tokens.length < 7) continue;
|
||||||
Coordinate coord = makeCoord(tokens[1],tokens[2]);
|
Coordinate coord = makeCoord(tokens[1],tokens[2]);
|
||||||
String customerId = tokens[0];
|
String customerId = tokens[0];
|
||||||
int demand = Integer.parseInt(tokens[3]);
|
int demand = Integer.parseInt(tokens[3]);
|
||||||
|
|
@ -101,13 +101,10 @@ public class SolomonReader {
|
||||||
if(counter == 10){
|
if(counter == 10){
|
||||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
|
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
|
||||||
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
|
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
|
||||||
|
|
||||||
VehicleTypeImpl vehicleType = typeBuilder.build();
|
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();
|
.setStartLocationId(customerId).setStartLocationCoordinate(coord).setType(vehicleType).build();
|
||||||
|
|
||||||
// vrpBuilder.addVehicleType(vehicleType);
|
|
||||||
vrpBuilder.addVehicle(vehicle);
|
vrpBuilder.addVehicle(vehicle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,3 +108,5 @@ CUST NO. XCOORD. YCOORD. DEMAND READY TIME DUE DATE SERVICE TIME
|
||||||
98 58 75 20 30 84 90
|
98 58 75 20 30 84 90
|
||||||
99 55 80 10 743 820 90
|
99 55 80 10 743 820 90
|
||||||
100 55 85 20 647 726 90
|
100 55 85 20 647 726 90
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue