mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
merged master into multiple tw branch
This commit is contained in:
parent
0b3b07a7de
commit
02c3c96e9c
523 changed files with 77426 additions and 74576 deletions
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -35,113 +35,103 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Reader that reads Christophides, Mingozzi and Toth instances.
|
||||
*
|
||||
* <p/>
|
||||
* <p>Files and file-description can be found <a href="http://neo.lcc.uma.es/vrp/vrp-instances/capacitated-vrp-instances/">here</a>.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*/
|
||||
public class ChristofidesReader {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(ChristofidesReader.class);
|
||||
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
private static Logger logger = LogManager.getLogger(ChristofidesReader.class);
|
||||
|
||||
private double coordProjectionFactor = 1;
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
/**
|
||||
* Constructs the reader.
|
||||
*
|
||||
* @param vrpBuilder the builder
|
||||
*/
|
||||
public ChristofidesReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads instance-file and memorizes vehicles, customers and so forth in
|
||||
* {@link VehicleRoutingProblem.Builder}.
|
||||
*
|
||||
* @param fileName the filename to read
|
||||
*/
|
||||
public void read(String fileName){
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(fileName);
|
||||
int vehicleCapacity = 0;
|
||||
double serviceTime = 0.0;
|
||||
double endTime = Double.MAX_VALUE;
|
||||
int counter = 0;
|
||||
String line;
|
||||
while((line = readLine(reader)) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" ");
|
||||
if(counter == 0){
|
||||
vehicleCapacity = Integer.parseInt(tokens[1].trim());
|
||||
endTime = Double.parseDouble(tokens[2].trim());
|
||||
serviceTime = Double.parseDouble(tokens[3].trim());
|
||||
}
|
||||
else if(counter == 1){
|
||||
Coordinate depotCoord = makeCoord(tokens[0].trim(),tokens[1].trim());
|
||||
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType").addCapacityDimension(0, vehicleCapacity).
|
||||
setCostPerDistance(1.0).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())).
|
||||
setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
else{
|
||||
Coordinate customerCoord = makeCoord(tokens[0].trim(),tokens[1].trim());
|
||||
int demand = Integer.parseInt(tokens[2].trim());
|
||||
String customer = Integer.valueOf(counter-1).toString();
|
||||
Service service = Service.Builder.newInstance(customer).addSizeDimension(0, demand).setServiceTime(serviceTime).setLocation(Location.newInstance(customerCoord.getX(), customerCoord.getY())).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
private double coordProjectionFactor = 1;
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
/**
|
||||
* Constructs the reader.
|
||||
*
|
||||
* @param vrpBuilder the builder
|
||||
*/
|
||||
public ChristofidesReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads instance-file and memorizes vehicles, customers and so forth in
|
||||
* {@link VehicleRoutingProblem.Builder}.
|
||||
*
|
||||
* @param fileName the filename to read
|
||||
*/
|
||||
public void read(String fileName) {
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(fileName);
|
||||
int vehicleCapacity = 0;
|
||||
double serviceTime = 0.0;
|
||||
double endTime = Double.MAX_VALUE;
|
||||
int counter = 0;
|
||||
String line;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" ");
|
||||
if (counter == 0) {
|
||||
vehicleCapacity = Integer.parseInt(tokens[1].trim());
|
||||
endTime = Double.parseDouble(tokens[2].trim());
|
||||
serviceTime = Double.parseDouble(tokens[3].trim());
|
||||
} else if (counter == 1) {
|
||||
Coordinate depotCoord = makeCoord(tokens[0].trim(), tokens[1].trim());
|
||||
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType").addCapacityDimension(0, vehicleCapacity).
|
||||
setCostPerDistance(1.0).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())).
|
||||
setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
} else {
|
||||
Coordinate customerCoord = makeCoord(tokens[0].trim(), tokens[1].trim());
|
||||
int demand = Integer.parseInt(tokens[2].trim());
|
||||
String customer = Integer.valueOf(counter - 1).toString();
|
||||
Service service = Service.Builder.newInstance(customer).addSizeDimension(0, demand).setServiceTime(serviceTime).setLocation(Location.newInstance(customerCoord.getX(), customerCoord.getY())).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor);
|
||||
}
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor);
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -38,140 +38,129 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Reader that reads instances developed by:
|
||||
*
|
||||
* <p>Cordeau, J.-F., Gendreau, M. and Laporte, G. (1997), A tabu search heuristic for periodic and multi-depot vehicle routing problems.
|
||||
* <p/>
|
||||
* <p>Cordeau, J.-F., Gendreau, M. and Laporte, G. (1997), A tabu search heuristic for periodic and multi-depot vehicle routing problems.
|
||||
* Networks, 30: 105–119. doi: 10.1002/(SICI)1097-0037(199709)30:2<105::AID-NET5>3.0.CO;2-G
|
||||
*
|
||||
* <p>Files and file-description can be found <a href="http://neo.lcc.uma.es/vrp/vrp-instances/multiple-depot-vrp-instances/">here</a>.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
* <p/>
|
||||
* <p>Files and file-description can be found <a href="http://neo.lcc.uma.es/vrp/vrp-instances/multiple-depot-vrp-instances/">here</a>.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*/
|
||||
public class CordeauReader {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(CordeauReader.class);
|
||||
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
private static Logger logger = LogManager.getLogger(CordeauReader.class);
|
||||
|
||||
private double coordProjectionFactor = 1;
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private double coordProjectionFactor = 1;
|
||||
|
||||
|
||||
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public void read(String fileName){
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
BufferedReader reader = getReader(fileName);
|
||||
int vrpType;
|
||||
int nOfDepots = 0;
|
||||
int nOfCustomers = 0;
|
||||
int nOfVehiclesAtEachDepot = 0;
|
||||
|
||||
int counter = 0;
|
||||
String line;
|
||||
List<List<Builder>> vehiclesAtDepot = new ArrayList<List<Builder>>();
|
||||
int depotCounter = 0;
|
||||
while((line = readLine(reader)) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split("\\s+");
|
||||
if(counter == 0){
|
||||
vrpType = Integer.parseInt(tokens[0].trim());
|
||||
if(vrpType != 2) throw new IllegalStateException("expect vrpType to be equal to 2 and thus to be MDVRP");
|
||||
nOfVehiclesAtEachDepot = Integer.parseInt(tokens[1].trim());
|
||||
nOfCustomers = Integer.parseInt(tokens[2].trim());
|
||||
nOfDepots = Integer.parseInt(tokens[3].trim());
|
||||
}
|
||||
else if(counter <= nOfDepots){
|
||||
String depot = Integer.valueOf(counter).toString();
|
||||
int duration = Integer.parseInt(tokens[0].trim());
|
||||
if(duration == 0) duration = 999999;
|
||||
int capacity = Integer.parseInt(tokens[1].trim());
|
||||
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance(counter + "_cordeauType").addCapacityDimension(0, capacity).
|
||||
setCostPerDistance(1.0).setFixedCost(0).build();
|
||||
List<Builder> builders = new ArrayList<VehicleImpl.Builder>();
|
||||
for(int vehicleCounter=0;vehicleCounter<nOfVehiclesAtEachDepot;vehicleCounter++){
|
||||
Builder vBuilder = VehicleImpl.Builder.newInstance(depot+"_"+(vehicleCounter+1) + "_cordeauVehicle");
|
||||
vBuilder.setLatestArrival(duration).setType(vehicleType);
|
||||
builders.add(vBuilder);
|
||||
}
|
||||
vehiclesAtDepot.add(builders);
|
||||
}
|
||||
else if(counter <= (nOfCustomers+nOfDepots)){
|
||||
String id = tokens[0].trim();
|
||||
Coordinate customerCoord = makeCoord(tokens[1].trim(),tokens[2].trim());
|
||||
double serviceTime = Double.parseDouble(tokens[3].trim());
|
||||
int demand = Integer.parseInt(tokens[4].trim());
|
||||
Service service = Service.Builder.newInstance(id).addSizeDimension(0, demand).setServiceTime(serviceTime)
|
||||
.setLocation(Location.Builder.newInstance().setId(id).setCoordinate(customerCoord).build()).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
else if(counter <= (nOfCustomers+nOfDepots+nOfDepots)){
|
||||
Coordinate depotCoord = makeCoord(tokens[1].trim(),tokens[2].trim());
|
||||
List<Builder> vBuilders = vehiclesAtDepot.get(depotCounter);
|
||||
for(Builder vBuilder : vBuilders){
|
||||
vBuilder.setStartLocation(Location.newInstance(depotCoord.getX(),depotCoord.getY()));
|
||||
VehicleImpl vehicle = vBuilder.build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
depotCounter++;
|
||||
}
|
||||
else{
|
||||
throw new IllegalStateException("there are more lines than expected in file.");
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
public void read(String fileName) {
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
BufferedReader reader = getReader(fileName);
|
||||
int vrpType;
|
||||
int nOfDepots = 0;
|
||||
int nOfCustomers = 0;
|
||||
int nOfVehiclesAtEachDepot = 0;
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
int counter = 0;
|
||||
String line;
|
||||
List<List<Builder>> vehiclesAtDepot = new ArrayList<List<Builder>>();
|
||||
int depotCounter = 0;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split("\\s+");
|
||||
if (counter == 0) {
|
||||
vrpType = Integer.parseInt(tokens[0].trim());
|
||||
if (vrpType != 2)
|
||||
throw new IllegalStateException("expect vrpType to be equal to 2 and thus to be MDVRP");
|
||||
nOfVehiclesAtEachDepot = Integer.parseInt(tokens[1].trim());
|
||||
nOfCustomers = Integer.parseInt(tokens[2].trim());
|
||||
nOfDepots = Integer.parseInt(tokens[3].trim());
|
||||
} else if (counter <= nOfDepots) {
|
||||
String depot = Integer.valueOf(counter).toString();
|
||||
int duration = Integer.parseInt(tokens[0].trim());
|
||||
if (duration == 0) duration = 999999;
|
||||
int capacity = Integer.parseInt(tokens[1].trim());
|
||||
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance(counter + "_cordeauType").addCapacityDimension(0, capacity).
|
||||
setCostPerDistance(1.0).setFixedCost(0).build();
|
||||
List<Builder> builders = new ArrayList<VehicleImpl.Builder>();
|
||||
for (int vehicleCounter = 0; vehicleCounter < nOfVehiclesAtEachDepot; vehicleCounter++) {
|
||||
Builder vBuilder = VehicleImpl.Builder.newInstance(depot + "_" + (vehicleCounter + 1) + "_cordeauVehicle");
|
||||
vBuilder.setLatestArrival(duration).setType(vehicleType);
|
||||
builders.add(vBuilder);
|
||||
}
|
||||
vehiclesAtDepot.add(builders);
|
||||
} else if (counter <= (nOfCustomers + nOfDepots)) {
|
||||
String id = tokens[0].trim();
|
||||
Coordinate customerCoord = makeCoord(tokens[1].trim(), tokens[2].trim());
|
||||
double serviceTime = Double.parseDouble(tokens[3].trim());
|
||||
int demand = Integer.parseInt(tokens[4].trim());
|
||||
Service service = Service.Builder.newInstance(id).addSizeDimension(0, demand).setServiceTime(serviceTime)
|
||||
.setLocation(Location.Builder.newInstance().setId(id).setCoordinate(customerCoord).build()).build();
|
||||
vrpBuilder.addJob(service);
|
||||
} else if (counter <= (nOfCustomers + nOfDepots + nOfDepots)) {
|
||||
Coordinate depotCoord = makeCoord(tokens[1].trim(), tokens[2].trim());
|
||||
List<Builder> vBuilders = vehiclesAtDepot.get(depotCounter);
|
||||
for (Builder vBuilder : vBuilders) {
|
||||
vBuilder.setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY()));
|
||||
VehicleImpl vehicle = vBuilder.build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
depotCounter++;
|
||||
} else {
|
||||
throw new IllegalStateException("there are more lines than expected in file.");
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor);
|
||||
}
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor);
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -40,36 +40,68 @@ public class Figliozzi {
|
|||
}
|
||||
|
||||
|
||||
public static TDCosts createCosts(Locations locations, SpeedDistribution speedDistribution, double depotClosingTime){
|
||||
public static TDCosts createCosts(Locations locations, SpeedDistribution speedDistribution, double depotClosingTime) {
|
||||
List<Double> timeBins = createTimeBins(depotClosingTime);
|
||||
List<Double> speedValues = createSpeedValues(speedDistribution);
|
||||
return new TDCosts(locations,timeBins,speedValues);
|
||||
return new TDCosts(locations, timeBins, speedValues);
|
||||
}
|
||||
|
||||
static List<Double> createSpeedValues(SpeedDistribution speedDistribution) {
|
||||
List<Double> speedValues = Collections.emptyList();
|
||||
switch(speedDistribution){
|
||||
case TD1a: speedValues = Arrays.asList(1.,1.6,1.05,1.6,1.); break;
|
||||
case TD2a: speedValues = Arrays.asList(1.,2.,1.5,2.,1.); break;
|
||||
case TD3a: speedValues = Arrays.asList(1.,2.5,1.75,2.5,1.); break;
|
||||
switch (speedDistribution) {
|
||||
case TD1a:
|
||||
speedValues = Arrays.asList(1., 1.6, 1.05, 1.6, 1.);
|
||||
break;
|
||||
case TD2a:
|
||||
speedValues = Arrays.asList(1., 2., 1.5, 2., 1.);
|
||||
break;
|
||||
case TD3a:
|
||||
speedValues = Arrays.asList(1., 2.5, 1.75, 2.5, 1.);
|
||||
break;
|
||||
|
||||
case TD1b: speedValues = Arrays.asList(1.6,1.,1.05,1.,1.6); break;
|
||||
case TD2b: speedValues = Arrays.asList(2.,1.,1.5,1.,2.); break;
|
||||
case TD3b: speedValues = Arrays.asList(2.5,1.,1.75,1.,2.5); break;
|
||||
case TD1b:
|
||||
speedValues = Arrays.asList(1.6, 1., 1.05, 1., 1.6);
|
||||
break;
|
||||
case TD2b:
|
||||
speedValues = Arrays.asList(2., 1., 1.5, 1., 2.);
|
||||
break;
|
||||
case TD3b:
|
||||
speedValues = Arrays.asList(2.5, 1., 1.75, 1., 2.5);
|
||||
break;
|
||||
|
||||
case TD1c: speedValues = Arrays.asList(1.6,1.6,1.05,1.,1.); break;
|
||||
case TD2c: speedValues = Arrays.asList(2.,2.,1.5,1.,1.); break;
|
||||
case TD3c: speedValues = Arrays.asList(2.5,2.5,1.75,1.,1.); break;
|
||||
case TD1c:
|
||||
speedValues = Arrays.asList(1.6, 1.6, 1.05, 1., 1.);
|
||||
break;
|
||||
case TD2c:
|
||||
speedValues = Arrays.asList(2., 2., 1.5, 1., 1.);
|
||||
break;
|
||||
case TD3c:
|
||||
speedValues = Arrays.asList(2.5, 2.5, 1.75, 1., 1.);
|
||||
break;
|
||||
|
||||
case TD1d: speedValues = Arrays.asList(1.,1.,1.05,1.6,1.6); break;
|
||||
case TD2d: speedValues = Arrays.asList(1.,1.,1.5,2.,2.); break;
|
||||
case TD3d: speedValues = Arrays.asList(1.,1.,1.75,2.5,2.5); break;
|
||||
case TD1d:
|
||||
speedValues = Arrays.asList(1., 1., 1.05, 1.6, 1.6);
|
||||
break;
|
||||
case TD2d:
|
||||
speedValues = Arrays.asList(1., 1., 1.5, 2., 2.);
|
||||
break;
|
||||
case TD3d:
|
||||
speedValues = Arrays.asList(1., 1., 1.75, 2.5, 2.5);
|
||||
break;
|
||||
|
||||
case TD4: speedValues = Arrays.asList(1.1,0.85,1.1,0.85,1.1); break;
|
||||
case TD5: speedValues = Arrays.asList(1.2,0.8,1.,0.8,1.2); break;
|
||||
case TD6: speedValues = Arrays.asList(1.2,0.7,1.2,0.7,1.2); break;
|
||||
case TD4:
|
||||
speedValues = Arrays.asList(1.1, 0.85, 1.1, 0.85, 1.1);
|
||||
break;
|
||||
case TD5:
|
||||
speedValues = Arrays.asList(1.2, 0.8, 1., 0.8, 1.2);
|
||||
break;
|
||||
case TD6:
|
||||
speedValues = Arrays.asList(1.2, 0.7, 1.2, 0.7, 1.2);
|
||||
break;
|
||||
|
||||
case CLASSIC: speedValues = Arrays.asList(1.,1.,1.,1.,1.); break;
|
||||
case CLASSIC:
|
||||
speedValues = Arrays.asList(1., 1., 1., 1., 1.);
|
||||
break;
|
||||
}
|
||||
return speedValues;
|
||||
}
|
||||
|
|
@ -88,23 +120,23 @@ public class Figliozzi {
|
|||
|
||||
|
||||
public static class TDCosts implements VehicleRoutingTransportCosts {
|
||||
|
||||
private List<Double> timeBins;
|
||||
|
||||
private List<Double> speed;
|
||||
|
||||
private List<Double> timeBins;
|
||||
|
||||
private List<Double> speed;
|
||||
|
||||
private Locations locations;
|
||||
|
||||
private double transportDistanceParameter = 1.;
|
||||
|
||||
private double transportTimeParameter = 1.;
|
||||
|
||||
public TDCosts(Locations locations, List<Double> timeBins, List<Double> speedValues) {
|
||||
super();
|
||||
speed = speedValues;
|
||||
this.timeBins = timeBins;
|
||||
|
||||
public TDCosts(Locations locations, List<Double> timeBins, List<Double> speedValues) {
|
||||
super();
|
||||
speed = speedValues;
|
||||
this.timeBins = timeBins;
|
||||
this.locations = locations;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTransportDistanceParameter(double transportDistanceParameter) {
|
||||
this.transportDistanceParameter = transportDistanceParameter;
|
||||
|
|
@ -115,79 +147,75 @@ public class Figliozzi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getTransportTime(from, to,departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle);
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getTransportTime(from, to, departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(from.equals(to)){
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = departureTime;
|
||||
for(int i=0;i<timeBins.size();i++){
|
||||
double timeThreshold = timeBins.get(i);
|
||||
if(currentTime < timeThreshold){
|
||||
double maxReachableDistance = (timeThreshold-currentTime)*speed.get(i);
|
||||
if(distanceToTravel > maxReachableDistance){
|
||||
distanceToTravel = distanceToTravel - maxReachableDistance;
|
||||
totalTravelTime += (timeThreshold-currentTime);
|
||||
currentTime = timeThreshold;
|
||||
}
|
||||
else{ //<= maxReachableDistance
|
||||
totalTravelTime += distanceToTravel/speed.get(i);
|
||||
return totalTravelTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
@Override
|
||||
public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
if(from.equals(to)){
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = arrivalTime;
|
||||
for(int i=timeBins.size()-1;i>=0;i--){
|
||||
double nextLowerTimeThreshold;
|
||||
if(i>0){
|
||||
nextLowerTimeThreshold = timeBins.get(i-1);
|
||||
}
|
||||
else{
|
||||
nextLowerTimeThreshold = 0;
|
||||
}
|
||||
if(currentTime > nextLowerTimeThreshold){
|
||||
double maxReachableDistance = (currentTime - nextLowerTimeThreshold)*speed.get(i);
|
||||
if(distanceToTravel > maxReachableDistance){
|
||||
distanceToTravel = distanceToTravel - maxReachableDistance;
|
||||
totalTravelTime += (currentTime-nextLowerTimeThreshold);
|
||||
currentTime = nextLowerTimeThreshold;
|
||||
}
|
||||
else{ //<= maxReachableDistance
|
||||
totalTravelTime += distanceToTravel/speed.get(i);
|
||||
return totalTravelTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
@Override
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if (from.equals(to)) {
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = departureTime;
|
||||
for (int i = 0; i < timeBins.size(); i++) {
|
||||
double timeThreshold = timeBins.get(i);
|
||||
if (currentTime < timeThreshold) {
|
||||
double maxReachableDistance = (timeThreshold - currentTime) * speed.get(i);
|
||||
if (distanceToTravel > maxReachableDistance) {
|
||||
distanceToTravel = distanceToTravel - maxReachableDistance;
|
||||
totalTravelTime += (timeThreshold - currentTime);
|
||||
currentTime = timeThreshold;
|
||||
} else { //<= maxReachableDistance
|
||||
totalTravelTime += distanceToTravel / speed.get(i);
|
||||
return totalTravelTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@Override
|
||||
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
if (from.equals(to)) {
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = arrivalTime;
|
||||
for (int i = timeBins.size() - 1; i >= 0; i--) {
|
||||
double nextLowerTimeThreshold;
|
||||
if (i > 0) {
|
||||
nextLowerTimeThreshold = timeBins.get(i - 1);
|
||||
} else {
|
||||
nextLowerTimeThreshold = 0;
|
||||
}
|
||||
if (currentTime > nextLowerTimeThreshold) {
|
||||
double maxReachableDistance = (currentTime - nextLowerTimeThreshold) * speed.get(i);
|
||||
if (distanceToTravel > maxReachableDistance) {
|
||||
distanceToTravel = distanceToTravel - maxReachableDistance;
|
||||
totalTravelTime += (currentTime - nextLowerTimeThreshold);
|
||||
currentTime = nextLowerTimeThreshold;
|
||||
} else { //<= maxReachableDistance
|
||||
totalTravelTime += distanceToTravel / speed.get(i);
|
||||
return totalTravelTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -39,169 +39,167 @@ import java.util.Map;
|
|||
|
||||
|
||||
/**
|
||||
* test instances for the capacitated vrp with pickup and deliveries and time windows.
|
||||
* test instances for the capacitated vrp with pickup and deliveries and time windows.
|
||||
* instances are from li and lim and can be found at:
|
||||
* http://www.top.sintef.no/vrp/benchmarks.html
|
||||
* @author stefan schroeder
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*/
|
||||
|
||||
|
||||
public class LiLimReader {
|
||||
|
||||
static class CustomerData{
|
||||
public Coordinate coord;
|
||||
public double start;
|
||||
public double end;
|
||||
public double serviceTime;
|
||||
|
||||
public CustomerData(Coordinate coord, double start, double end, double serviceTime) {
|
||||
super();
|
||||
this.coord = coord;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.serviceTime = serviceTime;
|
||||
}
|
||||
}
|
||||
|
||||
static class Relation{
|
||||
public String from;
|
||||
public String to;
|
||||
public int demand;
|
||||
public Relation(String from, String to, int demand) {
|
||||
super();
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.demand = demand;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Logger logger = LogManager.getLogger(LiLimReader.class);
|
||||
|
||||
private VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private int vehicleCapacity;
|
||||
|
||||
private String depotId;
|
||||
|
||||
private Map<String,CustomerData> customers;
|
||||
|
||||
private Collection<Relation> relations;
|
||||
|
||||
private double depotOpeningTime;
|
||||
|
||||
private double depotClosingTime;
|
||||
static class CustomerData {
|
||||
public Coordinate coord;
|
||||
public double start;
|
||||
public double end;
|
||||
public double serviceTime;
|
||||
|
||||
private int fixCosts = 0;
|
||||
|
||||
public LiLimReader(Builder vrpBuilder) {
|
||||
customers = new HashMap<String, LiLimReader.CustomerData>();
|
||||
relations = new ArrayList<LiLimReader.Relation>();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public LiLimReader(Builder builder, int fixCosts) {
|
||||
customers = new HashMap<String, LiLimReader.CustomerData>();
|
||||
relations = new ArrayList<LiLimReader.Relation>();
|
||||
this.vrpBuilder = builder;
|
||||
this.fixCosts = fixCosts;
|
||||
}
|
||||
public CustomerData(Coordinate coord, double start, double end, double serviceTime) {
|
||||
super();
|
||||
this.coord = coord;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.serviceTime = serviceTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void read(String filename){
|
||||
readShipments(filename);
|
||||
buildShipments();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, vehicleCapacity)
|
||||
.setCostPerDistance(1.0).setFixedCost(fixCosts).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle")
|
||||
.setEarliestStart(depotOpeningTime).setLatestArrival(depotClosingTime)
|
||||
.setStartLocation(Location.Builder.newInstance().setCoordinate(customers.get(depotId).coord).build()).setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
|
||||
private void buildShipments() {
|
||||
Integer counter = 0;
|
||||
for(Relation rel : relations){
|
||||
counter++;
|
||||
String from = rel.from;
|
||||
String to = rel.to;
|
||||
int demand = rel.demand;
|
||||
Shipment s = Shipment.Builder.newInstance(counter.toString()).addSizeDimension(0, demand)
|
||||
.setPickupLocation(Location.Builder.newInstance().setCoordinate(customers.get(from).coord).build()).setPickupServiceTime(customers.get(from).serviceTime)
|
||||
.setPickupTimeWindow(TimeWindow.newInstance(customers.get(from).start, customers.get(from).end))
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setCoordinate(customers.get(to).coord).build()).setDeliveryServiceTime(customers.get(to).serviceTime)
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(customers.get(to).start, customers.get(to).end)).build();
|
||||
vrpBuilder.addJob(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String file) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
static class Relation {
|
||||
public String from;
|
||||
public String to;
|
||||
public int demand;
|
||||
|
||||
private void readShipments(String file) {
|
||||
BufferedReader reader = getReader(file);
|
||||
String line = null;
|
||||
boolean firstLine = true;
|
||||
try {
|
||||
while((line = reader.readLine()) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split("\t");
|
||||
if(firstLine){
|
||||
int vehicleCapacity = getInt(tokens[1]);
|
||||
this.vehicleCapacity = vehicleCapacity;
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
String customerId = tokens[0];
|
||||
Coordinate coord = makeCoord(tokens[1], tokens[2]);
|
||||
int demand = getInt(tokens[3]);
|
||||
double startTimeWindow = getDouble(tokens[4]);
|
||||
double endTimeWindow = getDouble(tokens[5]);
|
||||
double serviceTime = getDouble(tokens[6]);
|
||||
public Relation(String from, String to, int demand) {
|
||||
super();
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.demand = demand;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Logger logger = LogManager.getLogger(LiLimReader.class);
|
||||
|
||||
private VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private int vehicleCapacity;
|
||||
|
||||
private String depotId;
|
||||
|
||||
private Map<String, CustomerData> customers;
|
||||
|
||||
private Collection<Relation> relations;
|
||||
|
||||
private double depotOpeningTime;
|
||||
|
||||
private double depotClosingTime;
|
||||
|
||||
private int fixCosts = 0;
|
||||
|
||||
public LiLimReader(Builder vrpBuilder) {
|
||||
customers = new HashMap<String, LiLimReader.CustomerData>();
|
||||
relations = new ArrayList<LiLimReader.Relation>();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public LiLimReader(Builder builder, int fixCosts) {
|
||||
customers = new HashMap<String, LiLimReader.CustomerData>();
|
||||
relations = new ArrayList<LiLimReader.Relation>();
|
||||
this.vrpBuilder = builder;
|
||||
this.fixCosts = fixCosts;
|
||||
}
|
||||
|
||||
public void read(String filename) {
|
||||
readShipments(filename);
|
||||
buildShipments();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, vehicleCapacity)
|
||||
.setCostPerDistance(1.0).setFixedCost(fixCosts).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle")
|
||||
.setEarliestStart(depotOpeningTime).setLatestArrival(depotClosingTime)
|
||||
.setStartLocation(Location.Builder.newInstance().setCoordinate(customers.get(depotId).coord).build()).setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
|
||||
private void buildShipments() {
|
||||
Integer counter = 0;
|
||||
for (Relation rel : relations) {
|
||||
counter++;
|
||||
String from = rel.from;
|
||||
String to = rel.to;
|
||||
int demand = rel.demand;
|
||||
Shipment s = Shipment.Builder.newInstance(counter.toString()).addSizeDimension(0, demand)
|
||||
.setPickupLocation(Location.Builder.newInstance().setCoordinate(customers.get(from).coord).build()).setPickupServiceTime(customers.get(from).serviceTime)
|
||||
.setPickupTimeWindow(TimeWindow.newInstance(customers.get(from).start, customers.get(from).end))
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setCoordinate(customers.get(to).coord).build()).setDeliveryServiceTime(customers.get(to).serviceTime)
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(customers.get(to).start, customers.get(to).end)).build();
|
||||
vrpBuilder.addJob(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String file) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
private void readShipments(String file) {
|
||||
BufferedReader reader = getReader(file);
|
||||
String line = null;
|
||||
boolean firstLine = true;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split("\t");
|
||||
if (firstLine) {
|
||||
int vehicleCapacity = getInt(tokens[1]);
|
||||
this.vehicleCapacity = vehicleCapacity;
|
||||
firstLine = false;
|
||||
continue;
|
||||
} else {
|
||||
String customerId = tokens[0];
|
||||
Coordinate coord = makeCoord(tokens[1], tokens[2]);
|
||||
int demand = getInt(tokens[3]);
|
||||
double startTimeWindow = getDouble(tokens[4]);
|
||||
double endTimeWindow = getDouble(tokens[5]);
|
||||
double serviceTime = getDouble(tokens[6]);
|
||||
// vrpBuilder.addLocation(customerId, coord);
|
||||
customers.put(customerId, new CustomerData(coord,startTimeWindow,endTimeWindow, serviceTime));
|
||||
if(customerId.equals("0")){
|
||||
depotId = customerId;
|
||||
depotOpeningTime = startTimeWindow;
|
||||
depotClosingTime = endTimeWindow;
|
||||
}
|
||||
if(demand > 0){
|
||||
relations.add(new Relation(customerId,tokens[8],demand));
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x,y);
|
||||
}
|
||||
|
||||
private double getDouble(String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
customers.put(customerId, new CustomerData(coord, startTimeWindow, endTimeWindow, serviceTime));
|
||||
if (customerId.equals("0")) {
|
||||
depotId = customerId;
|
||||
depotOpeningTime = startTimeWindow;
|
||||
depotClosingTime = endTimeWindow;
|
||||
}
|
||||
if (demand > 0) {
|
||||
relations.add(new Relation(customerId, tokens[8], demand));
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
private int getInt(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
|
||||
private double getDouble(String string) {
|
||||
return Double.parseDouble(string);
|
||||
}
|
||||
|
||||
private int getInt(String string) {
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,42 +27,39 @@ public class LopezIbanezBlumReader {
|
|||
this.builder = builder;
|
||||
}
|
||||
|
||||
public void read(String instanceFile){
|
||||
public void read(String instanceFile) {
|
||||
builder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||
BufferedReader reader = getReader(instanceFile);
|
||||
String line;
|
||||
int noNodes = 0;
|
||||
int lineCount = 1;
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = null;
|
||||
while((line = readLine(reader)) != null){
|
||||
if(line.startsWith("#")) continue;
|
||||
if(lineCount == 1){
|
||||
while ((line = readLine(reader)) != null) {
|
||||
if (line.startsWith("#")) continue;
|
||||
if (lineCount == 1) {
|
||||
noNodes = Integer.parseInt(line);
|
||||
matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noNodes,false);
|
||||
matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noNodes, false);
|
||||
lineCount++;
|
||||
continue;
|
||||
}
|
||||
else if(lineCount <= 1 + noNodes){
|
||||
} else if (lineCount <= 1 + noNodes) {
|
||||
String[] wimaTokens = line.split("\\s+");
|
||||
int nodeIndex = lineCount - 2;
|
||||
for(int toIndex=0;toIndex<wimaTokens.length;toIndex++){
|
||||
matrixBuilder.addTransportDistance(nodeIndex,toIndex, Double.parseDouble(wimaTokens[toIndex]));
|
||||
for (int toIndex = 0; toIndex < wimaTokens.length; toIndex++) {
|
||||
matrixBuilder.addTransportDistance(nodeIndex, toIndex, Double.parseDouble(wimaTokens[toIndex]));
|
||||
matrixBuilder.addTransportTime(nodeIndex, toIndex, Double.parseDouble(wimaTokens[toIndex]));
|
||||
}
|
||||
lineCount++;
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
int nodeIndex = lineCount - 2 - noNodes;
|
||||
String[] twTokens = line.split("\\s+");
|
||||
if(nodeIndex == 0){
|
||||
if (nodeIndex == 0) {
|
||||
VehicleImpl travelingSalesman = VehicleImpl.Builder.newInstance("traveling_salesman").setStartLocation(Location.newInstance(nodeIndex))
|
||||
.setEarliestStart(Double.parseDouble(twTokens[0])).setLatestArrival(Double.parseDouble(twTokens[1])).build();
|
||||
.setEarliestStart(Double.parseDouble(twTokens[0])).setLatestArrival(Double.parseDouble(twTokens[1])).build();
|
||||
builder.addVehicle(travelingSalesman);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
Service s = Service.Builder.newInstance("" + nodeIndex).setLocation(Location.newInstance(nodeIndex))
|
||||
.setTimeWindow(TimeWindow.newInstance(Double.parseDouble(twTokens[0]), Double.parseDouble(twTokens[1]))).build();
|
||||
.setTimeWindow(TimeWindow.newInstance(Double.parseDouble(twTokens[0]), Double.parseDouble(twTokens[1]))).build();
|
||||
builder.addJob(s);
|
||||
}
|
||||
lineCount++;
|
||||
|
|
@ -77,21 +74,19 @@ public class LopezIbanezBlumReader {
|
|||
new LopezIbanezBlumReader(builder).read("input/Dumas/n20w20.001.txt");
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
System.out.println("0->1: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(1), 0, null, null));
|
||||
System.out.println("0->20: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(20),0,null,null));
|
||||
System.out.println("4->18: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(4), Location.newInstance(18),0,null,null));
|
||||
System.out.println("20->8: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(20), Location.newInstance(8),0,null,null));
|
||||
System.out.println("18: " + ((Service)vrp.getJobs().get(""+18)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+18)).getTimeWindow().getEnd());
|
||||
System.out.println("20: " + ((Service)vrp.getJobs().get(""+20)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+20)).getTimeWindow().getEnd());
|
||||
System.out.println("1: " + ((Service)vrp.getJobs().get(""+1)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+1)).getTimeWindow().getEnd());
|
||||
System.out.println("0->20: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(20), 0, null, null));
|
||||
System.out.println("4->18: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(4), Location.newInstance(18), 0, null, null));
|
||||
System.out.println("20->8: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(20), Location.newInstance(8), 0, null, null));
|
||||
System.out.println("18: " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getEnd());
|
||||
System.out.println("20: " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getEnd());
|
||||
System.out.println("1: " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getEnd());
|
||||
}
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +94,7 @@ public class LopezIbanezBlumReader {
|
|||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
return null;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,9 +103,7 @@ public class LopezIbanezBlumReader {
|
|||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -36,155 +36,144 @@ import java.io.IOException;
|
|||
|
||||
public class LuiShenReader {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(LuiShenReader.class);
|
||||
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
private static Logger logger = LogManager.getLogger(LuiShenReader.class);
|
||||
|
||||
private double coordProjectionFactor = 1;
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
public LuiShenReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads input files to build Liu Shen problem.
|
||||
*
|
||||
* <p>The instance-file is a solomon file. The vehicle-file is a
|
||||
* txt-file that has the following columns:
|
||||
* <p>Vehicle;Capacity;Cost_a;Cost_b;Cost_c
|
||||
* <p>Concrete vehicleType:
|
||||
* <p>A;100;300;60;30
|
||||
*
|
||||
* <p>In the example above, the vehicle-type with typeId A has
|
||||
* a capacity of 100, and fixed costs of 100 in cost scenario "a",
|
||||
* 300 in "b" and 30 in "c".
|
||||
private double coordProjectionFactor = 1;
|
||||
|
||||
* @param instanceFile is a solomon-instance-file
|
||||
* @param vehicleFile
|
||||
* @param costScenario is either "a", "b" or "c"
|
||||
*/
|
||||
public void read(String instanceFile, String vehicleFile, String costScenario){
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(instanceFile);
|
||||
int counter = 0;
|
||||
String line = null;
|
||||
while((line = readLine(reader)) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" +");
|
||||
counter++;
|
||||
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]);
|
||||
double start = Double.parseDouble(tokens[4])*coordProjectionFactor ;
|
||||
double end = Double.parseDouble(tokens[5])*coordProjectionFactor;
|
||||
double serviceTime = Double.parseDouble(tokens[6])*coordProjectionFactor;
|
||||
if(counter == 10){
|
||||
createVehicles(vehicleFile,costScenario,customerId,coord,start,end);
|
||||
}
|
||||
else{
|
||||
Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand)
|
||||
.setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime)
|
||||
.setTimeWindow(TimeWindow.newInstance(start, end)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
public LuiShenReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
private void createVehicles(String vehicleFileName, String costScenario, String locationId, Coordinate coord, double start, double end) {
|
||||
BufferedReader reader = getReader(vehicleFileName);
|
||||
|
||||
int costScenarioColumn = getCostScenarioColumn(costScenario);
|
||||
int vehicleIdColumn = 0;
|
||||
int capacityColumn = 1;
|
||||
|
||||
|
||||
|
||||
boolean firstLine = true;
|
||||
String line = null;
|
||||
while((line = readLine(reader)) != null){
|
||||
if(firstLine){
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] tokens = line.split(";");
|
||||
String vehicleId = tokens[vehicleIdColumn];
|
||||
int capacity = Integer.parseInt(tokens[capacityColumn]);
|
||||
int fixCost = Integer.parseInt(tokens[costScenarioColumn]);
|
||||
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(vehicleId).addCapacityDimension(0, capacity);
|
||||
typeBuilder.setFixedCost(fixCost).setCostPerDistance(1.0);
|
||||
|
||||
VehicleTypeImpl type = typeBuilder.build();
|
||||
|
||||
VehicleImpl reprVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(start).setLatestArrival(end).
|
||||
setStartLocation(Location.Builder.newInstance().setId(locationId).setCoordinate(coord).build())
|
||||
.setType(type).build();
|
||||
|
||||
vrpBuilder.addVehicle(reprVehicle);
|
||||
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
private int getCostScenarioColumn(String costScenario) {
|
||||
if(costScenario.equals("a")){
|
||||
return 2;
|
||||
}
|
||||
else if(costScenario.equals("b")){
|
||||
return 3;
|
||||
}
|
||||
else if(costScenario.equals("c")){
|
||||
return 4;
|
||||
}
|
||||
throw new IllegalStateException("costScenario " + costScenario + " not known");
|
||||
}
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
/**
|
||||
* Reads input files to build Liu Shen problem.
|
||||
* <p/>
|
||||
* <p>The instance-file is a solomon file. The vehicle-file is a
|
||||
* txt-file that has the following columns:
|
||||
* <p>Vehicle;Capacity;Cost_a;Cost_b;Cost_c
|
||||
* <p>Concrete vehicleType:
|
||||
* <p>A;100;300;60;30
|
||||
* <p/>
|
||||
* <p>In the example above, the vehicle-type with typeId A has
|
||||
* a capacity of 100, and fixed costs of 100 in cost scenario "a",
|
||||
* 300 in "b" and 30 in "c".
|
||||
*
|
||||
* @param instanceFile is a solomon-instance-file
|
||||
* @param vehicleFile
|
||||
* @param costScenario is either "a", "b" or "c"
|
||||
*/
|
||||
public void read(String instanceFile, String vehicleFile, String costScenario) {
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(instanceFile);
|
||||
int counter = 0;
|
||||
String line = null;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" +");
|
||||
counter++;
|
||||
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]);
|
||||
double start = Double.parseDouble(tokens[4]) * coordProjectionFactor;
|
||||
double end = Double.parseDouble(tokens[5]) * coordProjectionFactor;
|
||||
double serviceTime = Double.parseDouble(tokens[6]) * coordProjectionFactor;
|
||||
if (counter == 10) {
|
||||
createVehicles(vehicleFile, costScenario, customerId, coord, start, end);
|
||||
} else {
|
||||
Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand)
|
||||
.setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime)
|
||||
.setTimeWindow(TimeWindow.newInstance(start, end)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
private void createVehicles(String vehicleFileName, String costScenario, String locationId, Coordinate coord, double start, double end) {
|
||||
BufferedReader reader = getReader(vehicleFileName);
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor);
|
||||
}
|
||||
int costScenarioColumn = getCostScenarioColumn(costScenario);
|
||||
int vehicleIdColumn = 0;
|
||||
int capacityColumn = 1;
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
boolean firstLine = true;
|
||||
String line = null;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] tokens = line.split(";");
|
||||
String vehicleId = tokens[vehicleIdColumn];
|
||||
int capacity = Integer.parseInt(tokens[capacityColumn]);
|
||||
int fixCost = Integer.parseInt(tokens[costScenarioColumn]);
|
||||
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(vehicleId).addCapacityDimension(0, capacity);
|
||||
typeBuilder.setFixedCost(fixCost).setCostPerDistance(1.0);
|
||||
|
||||
VehicleTypeImpl type = typeBuilder.build();
|
||||
|
||||
VehicleImpl reprVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(start).setLatestArrival(end).
|
||||
setStartLocation(Location.Builder.newInstance().setId(locationId).setCoordinate(coord).build())
|
||||
.setType(type).build();
|
||||
|
||||
vrpBuilder.addVehicle(reprVehicle);
|
||||
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
private int getCostScenarioColumn(String costScenario) {
|
||||
if (costScenario.equals("a")) {
|
||||
return 2;
|
||||
} else if (costScenario.equals("b")) {
|
||||
return 3;
|
||||
} else if (costScenario.equals("c")) {
|
||||
return 4;
|
||||
}
|
||||
throw new IllegalStateException("costScenario " + costScenario + " not known");
|
||||
}
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor);
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -36,136 +36,127 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* Reader that reads the well-known solomon-instances.
|
||||
*
|
||||
* <p/>
|
||||
* <p>See: <a href="http://neo.lcc.uma.es/vrp/vrp-instances/capacitated-vrp-with-time-windows-instances/">neo.org</a>
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
* @author stefan
|
||||
*/
|
||||
|
||||
public class SolomonReader {
|
||||
|
||||
/**
|
||||
* @param costProjectionFactor the costProjectionFactor to set
|
||||
*/
|
||||
public void setVariableCostProjectionFactor(double costProjectionFactor) {
|
||||
this.variableCostProjectionFactor = costProjectionFactor;
|
||||
}
|
||||
/**
|
||||
* @param costProjectionFactor the costProjectionFactor to set
|
||||
*/
|
||||
public void setVariableCostProjectionFactor(double costProjectionFactor) {
|
||||
this.variableCostProjectionFactor = costProjectionFactor;
|
||||
}
|
||||
|
||||
private static Logger logger = LogManager.getLogger(SolomonReader.class);
|
||||
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
private static Logger logger = LogManager.getLogger(SolomonReader.class);
|
||||
|
||||
private double coordProjectionFactor = 1;
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private double timeProjectionFactor = 1;
|
||||
|
||||
private double variableCostProjectionFactor = 1;
|
||||
|
||||
private double fixedCostPerVehicle = 0.0;
|
||||
|
||||
public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder, double fixedCostPerVehicle) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
this.fixedCostPerVehicle=fixedCostPerVehicle;
|
||||
}
|
||||
|
||||
public void read(String solomonFile){
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(solomonFile);
|
||||
int vehicleCapacity = 0;
|
||||
|
||||
int counter = 0;
|
||||
String line;
|
||||
while((line = readLine(reader)) != null){
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" +");
|
||||
counter++;
|
||||
if(counter == 5){
|
||||
vehicleCapacity = Integer.parseInt(tokens[1]);
|
||||
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]);
|
||||
double start = Double.parseDouble(tokens[4])*timeProjectionFactor;
|
||||
double end = Double.parseDouble(tokens[5])*timeProjectionFactor;
|
||||
double serviceTime = Double.parseDouble(tokens[6])*timeProjectionFactor;
|
||||
if(counter == 10){
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
|
||||
typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
|
||||
VehicleTypeImpl vehicleType = typeBuilder.build();
|
||||
private double coordProjectionFactor = 1;
|
||||
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end)
|
||||
.setStartLocation(Location.Builder.newInstance().setId(customerId)
|
||||
.setCoordinate(coord).build()).setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
|
||||
}
|
||||
else{
|
||||
Service service = Service.Builder.newInstance(customerId).addSizeDimension(0, demand)
|
||||
.setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime)
|
||||
.setTimeWindow(TimeWindow.newInstance(start, end)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
private double timeProjectionFactor = 1;
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
private double variableCostProjectionFactor = 1;
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
private double fixedCostPerVehicle = 0.0;
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e);
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor);
|
||||
}
|
||||
public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1);
|
||||
System.exit(1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder, double fixedCostPerVehicle) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
this.fixedCostPerVehicle = fixedCostPerVehicle;
|
||||
}
|
||||
|
||||
public void setTimeProjectionFactor(double timeProjection) {
|
||||
this.timeProjectionFactor=timeProjection;
|
||||
|
||||
}
|
||||
public void read(String solomonFile) {
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
BufferedReader reader = getReader(solomonFile);
|
||||
int vehicleCapacity = 0;
|
||||
|
||||
int counter = 0;
|
||||
String line;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
line = line.replace("\r", "");
|
||||
line = line.trim();
|
||||
String[] tokens = line.split(" +");
|
||||
counter++;
|
||||
if (counter == 5) {
|
||||
vehicleCapacity = Integer.parseInt(tokens[1]);
|
||||
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]);
|
||||
double start = Double.parseDouble(tokens[4]) * timeProjectionFactor;
|
||||
double end = Double.parseDouble(tokens[5]) * timeProjectionFactor;
|
||||
double serviceTime = Double.parseDouble(tokens[6]) * timeProjectionFactor;
|
||||
if (counter == 10) {
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity);
|
||||
typeBuilder.setCostPerDistance(1.0 * variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle);
|
||||
VehicleTypeImpl vehicleType = typeBuilder.build();
|
||||
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end)
|
||||
.setStartLocation(Location.Builder.newInstance().setId(customerId)
|
||||
.setCoordinate(coord).build()).setType(vehicleType).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
|
||||
} else {
|
||||
Service service = Service.Builder.newInstance(customerId).addSizeDimension(0, demand)
|
||||
.setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime)
|
||||
.setTimeWindow(TimeWindow.newInstance(start, end)).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(reader);
|
||||
}
|
||||
|
||||
public void setCoordProjectionFactor(double coordProjectionFactor) {
|
||||
this.coordProjectionFactor = coordProjectionFactor;
|
||||
}
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
try {
|
||||
return reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private Coordinate makeCoord(String xString, String yString) {
|
||||
double x = Double.parseDouble(xString);
|
||||
double y = Double.parseDouble(yString);
|
||||
return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor);
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String solomonFile) {
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(solomonFile));
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
public void setTimeProjectionFactor(double timeProjection) {
|
||||
this.timeProjectionFactor = timeProjection;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,27 +30,27 @@ public class TSPLIB95CostMatrixReader {
|
|||
this.costMatrixBuilder = costMatrixBuilder;
|
||||
}
|
||||
|
||||
public void read(String matrixFile){
|
||||
public void read(String matrixFile) {
|
||||
BufferedReader reader = getBufferedReader(matrixFile);
|
||||
String line;
|
||||
boolean isEdgeWeights = false;
|
||||
int fromIndex = 0;
|
||||
while( ( line = getLine(reader) ) != null ){
|
||||
if(line.startsWith("EDGE_WEIGHT_SECTION")){
|
||||
while ((line = getLine(reader)) != null) {
|
||||
if (line.startsWith("EDGE_WEIGHT_SECTION")) {
|
||||
isEdgeWeights = true;
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("DEMAND_SECTION")){
|
||||
if (line.startsWith("DEMAND_SECTION")) {
|
||||
isEdgeWeights = false;
|
||||
continue;
|
||||
}
|
||||
if(isEdgeWeights){
|
||||
if (isEdgeWeights) {
|
||||
String[] tokens = line.split("\\s+");
|
||||
String fromId = "" + (fromIndex + 1);
|
||||
for(int i=0;i<tokens.length;i++){
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
double distance = Double.parseDouble(tokens[i]);
|
||||
String toId = "" + (i+1);
|
||||
costMatrixBuilder.addTransportDistance(fromId,toId,distance);
|
||||
String toId = "" + (i + 1);
|
||||
costMatrixBuilder.addTransportDistance(fromId, toId, distance);
|
||||
costMatrixBuilder.addTransportTime(fromId, toId, distance);
|
||||
}
|
||||
fromIndex++;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class TSPLIB95Reader {
|
|||
this.vrpBuilder = vrpBuilder;
|
||||
}
|
||||
|
||||
public void read(String filename){
|
||||
public void read(String filename) {
|
||||
BufferedReader reader = getBufferedReader(filename);
|
||||
String line_;
|
||||
Coordinate[] coords = null;
|
||||
|
|
@ -65,13 +65,13 @@ public class TSPLIB95Reader {
|
|||
List<Double> edgeWeights = new ArrayList<Double>();
|
||||
int dimensions = 0;
|
||||
int coordIndex = 0;
|
||||
Map<Integer,Integer> indexMap = new HashMap<Integer, Integer>();
|
||||
while( ( line_ = getLine(reader) ) != null ){
|
||||
Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
|
||||
while ((line_ = getLine(reader)) != null) {
|
||||
String line = line_.trim();
|
||||
if(line.startsWith("EOF") || line.contains("EOF")){
|
||||
if (line.startsWith("EOF") || line.contains("EOF")) {
|
||||
break;
|
||||
}
|
||||
if(line.startsWith("DIMENSION")){
|
||||
if (line.startsWith("DIMENSION")) {
|
||||
String[] tokens = line.split(":");
|
||||
String dim = tokens[1].trim();
|
||||
dimensions = Integer.parseInt(dim);
|
||||
|
|
@ -79,86 +79,85 @@ public class TSPLIB95Reader {
|
|||
demands = new int[dimensions];
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("CAPACITY")){
|
||||
if (line.startsWith("CAPACITY")) {
|
||||
String[] tokens = line.trim().split(":");
|
||||
capacity = Integer.parseInt(tokens[1].trim());
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("EDGE_WEIGHT_TYPE")){
|
||||
if (line.startsWith("EDGE_WEIGHT_TYPE")) {
|
||||
String[] tokens = line.trim().split(":");
|
||||
edgeType = tokens[1].trim();
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("EDGE_WEIGHT_FORMAT")){
|
||||
if (line.startsWith("EDGE_WEIGHT_FORMAT")) {
|
||||
String[] tokens = line.trim().split(":");
|
||||
edgeWeightFormat = tokens[1].trim();
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("NODE_COORD_SECTION")){
|
||||
if (line.startsWith("NODE_COORD_SECTION")) {
|
||||
isCoordSection = true;
|
||||
isDemandSection = false;
|
||||
isDepotSection = false;
|
||||
isEdgeWeightSection = false;
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("DEMAND_SECTION")){
|
||||
if (line.startsWith("DEMAND_SECTION")) {
|
||||
isDemandSection = true;
|
||||
isCoordSection = false;
|
||||
isDepotSection = false;
|
||||
isEdgeWeightSection = false;
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("DEPOT_SECTION")){
|
||||
if (line.startsWith("DEPOT_SECTION")) {
|
||||
isDepotSection = true;
|
||||
isDemandSection = false;
|
||||
isCoordSection = false;
|
||||
isEdgeWeightSection = false;
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("EDGE_WEIGHT_SECTION")){
|
||||
if (line.startsWith("EDGE_WEIGHT_SECTION")) {
|
||||
isDepotSection = false;
|
||||
isCoordSection = false;
|
||||
isDemandSection = false;
|
||||
isEdgeWeightSection = true;
|
||||
continue;
|
||||
}
|
||||
if(line.startsWith("DISPLAY_DATA_SECTION")){
|
||||
if (line.startsWith("DISPLAY_DATA_SECTION")) {
|
||||
isDepotSection = false;
|
||||
isCoordSection = true;
|
||||
isDemandSection = false;
|
||||
isEdgeWeightSection = false;
|
||||
continue;
|
||||
}
|
||||
if(isCoordSection){
|
||||
if(coords == null) throw new IllegalStateException("DIMENSION tag missing");
|
||||
if (isCoordSection) {
|
||||
if (coords == null) throw new IllegalStateException("DIMENSION tag missing");
|
||||
String[] tokens = line.trim().split("\\s+");
|
||||
Integer id = Integer.parseInt(tokens[0]);
|
||||
if(switchCoordinates){
|
||||
if (switchCoordinates) {
|
||||
coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[1]));
|
||||
}
|
||||
else coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
|
||||
indexMap.put(id,coordIndex);
|
||||
} else
|
||||
coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
|
||||
indexMap.put(id, coordIndex);
|
||||
coordIndex++;
|
||||
continue;
|
||||
}
|
||||
if(isDemandSection){
|
||||
if(demands == null) throw new IllegalStateException("DIMENSION tag missing");
|
||||
if (isDemandSection) {
|
||||
if (demands == null) throw new IllegalStateException("DIMENSION tag missing");
|
||||
String[] tokens = line.trim().split("\\s+");
|
||||
Integer id = Integer.parseInt(tokens[0]);
|
||||
int index = indexMap.get(id);
|
||||
demands[index] = Integer.parseInt(tokens[1]);
|
||||
continue;
|
||||
}
|
||||
if(isDepotSection){
|
||||
if(line.equals("-1")){
|
||||
if (isDepotSection) {
|
||||
if (line.equals("-1")) {
|
||||
isDepotSection = false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
depotIds.add(Integer.parseInt(line));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(isEdgeWeightSection){
|
||||
if (isEdgeWeightSection) {
|
||||
String[] tokens = line.trim().split("\\s+");
|
||||
for (String s : tokens) edgeWeights.add(Double.parseDouble(s));
|
||||
continue;
|
||||
|
|
@ -166,113 +165,108 @@ public class TSPLIB95Reader {
|
|||
}
|
||||
close(reader);
|
||||
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||
for(Integer depotId : depotIds){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,capacity).build();
|
||||
for (Integer depotId : depotIds) {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, capacity).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle")
|
||||
.setStartLocation(Location.Builder.newInstance().setId(depotId.toString()).setCoordinate(coords[depotId - 1]).build())
|
||||
.setType(type).build();
|
||||
.setStartLocation(Location.Builder.newInstance().setId(depotId.toString()).setCoordinate(coords[depotId - 1]).build())
|
||||
.setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
|
||||
for (Integer id_ : indexMap.keySet()) {
|
||||
String id = id_.toString();
|
||||
int index = indexMap.get(id_);
|
||||
if(depotIds.isEmpty()){
|
||||
if(index == 0) {
|
||||
if (depotIds.isEmpty()) {
|
||||
if (index == 0) {
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("traveling_salesman")
|
||||
.setStartLocation(Location.Builder.newInstance().setId(id)
|
||||
.setCoordinate(coords[index]).setIndex(index).build())
|
||||
.build();
|
||||
.setStartLocation(Location.Builder.newInstance().setId(id)
|
||||
.setCoordinate(coords[index]).setIndex(index).build())
|
||||
.build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Service service = Service.Builder.newInstance(id)
|
||||
.setLocation(Location.Builder.newInstance().setId(id)
|
||||
.setCoordinate(coords[index]).setIndex(index).build())
|
||||
.addSizeDimension(0, demands[index]).build();
|
||||
.setLocation(Location.Builder.newInstance().setId(id)
|
||||
.setCoordinate(coords[index]).setIndex(index).build())
|
||||
.addSizeDimension(0, demands[index]).build();
|
||||
vrpBuilder.addJob(service);
|
||||
}
|
||||
if(edgeType.equals("GEO")){
|
||||
if (edgeType.equals("GEO")) {
|
||||
List<Location> locations = new ArrayList<Location>();
|
||||
for(Vehicle v : vrpBuilder.getAddedVehicles()) locations.add(v.getStartLocation());
|
||||
for(Job j : vrpBuilder.getAddedJobs()) locations.add(((Service)j).getLocation());
|
||||
for (Vehicle v : vrpBuilder.getAddedVehicles()) locations.add(v.getStartLocation());
|
||||
for (Job j : vrpBuilder.getAddedJobs()) locations.add(((Service) j).getLocation());
|
||||
vrpBuilder.setRoutingCost(getGEOMatrix(locations));
|
||||
}
|
||||
else if(edgeType.equals("EXPLICIT")){
|
||||
if(edgeWeightFormat.equals("UPPER_ROW")){
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,true);
|
||||
} else if (edgeType.equals("EXPLICIT")) {
|
||||
if (edgeWeightFormat.equals("UPPER_ROW")) {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, true);
|
||||
int fromIndex = 0;
|
||||
int toIndex = 1;
|
||||
for(int i=0;i<edgeWeights.size();i++){
|
||||
if(toIndex == dimensions){
|
||||
for (int i = 0; i < edgeWeights.size(); i++) {
|
||||
if (toIndex == dimensions) {
|
||||
fromIndex++;
|
||||
toIndex = fromIndex + 1;
|
||||
}
|
||||
matrixBuilder.addTransportDistance(fromIndex, toIndex, edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex, toIndex, edgeWeights.get(i));
|
||||
toIndex++;
|
||||
}
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
}
|
||||
else if(edgeWeightFormat.equals("UPPER_DIAG_ROW")){
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,true);
|
||||
} else if (edgeWeightFormat.equals("UPPER_DIAG_ROW")) {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, true);
|
||||
int fromIndex = 0;
|
||||
int toIndex = 0;
|
||||
for(int i=0;i<edgeWeights.size();i++){
|
||||
if(toIndex == dimensions){
|
||||
for (int i = 0; i < edgeWeights.size(); i++) {
|
||||
if (toIndex == dimensions) {
|
||||
fromIndex++;
|
||||
toIndex = fromIndex;
|
||||
}
|
||||
matrixBuilder.addTransportDistance(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportDistance(fromIndex, toIndex, edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex, toIndex, edgeWeights.get(i));
|
||||
toIndex++;
|
||||
}
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
}
|
||||
else if(edgeWeightFormat.equals("LOWER_DIAG_ROW")){
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,true);
|
||||
} else if (edgeWeightFormat.equals("LOWER_DIAG_ROW")) {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, true);
|
||||
int fromIndex = 0;
|
||||
int toIndex = 0;
|
||||
for(int i=0;i<edgeWeights.size();i++){
|
||||
if(toIndex > fromIndex){
|
||||
for (int i = 0; i < edgeWeights.size(); i++) {
|
||||
if (toIndex > fromIndex) {
|
||||
fromIndex++;
|
||||
toIndex = 0;
|
||||
}
|
||||
matrixBuilder.addTransportDistance(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportDistance(fromIndex, toIndex, edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex, toIndex, edgeWeights.get(i));
|
||||
toIndex++;
|
||||
}
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
}
|
||||
else if(edgeWeightFormat.equals("FULL_MATRIX")){
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,false);
|
||||
} else if (edgeWeightFormat.equals("FULL_MATRIX")) {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, false);
|
||||
int fromIndex = 0;
|
||||
int toIndex = 0;
|
||||
for(int i=0;i<edgeWeights.size();i++){
|
||||
if(toIndex == dimensions){
|
||||
for (int i = 0; i < edgeWeights.size(); i++) {
|
||||
if (toIndex == dimensions) {
|
||||
fromIndex++;
|
||||
toIndex = 0;
|
||||
}
|
||||
matrixBuilder.addTransportDistance(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex,toIndex,edgeWeights.get(i));
|
||||
matrixBuilder.addTransportDistance(fromIndex, toIndex, edgeWeights.get(i));
|
||||
matrixBuilder.addTransportTime(fromIndex, toIndex, edgeWeights.get(i));
|
||||
toIndex++;
|
||||
}
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private VehicleRoutingTransportCosts getGEOMatrix(List<Location> noLocations) {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noLocations.size(),true);
|
||||
for(Location i : noLocations){
|
||||
for(Location j : noLocations){
|
||||
matrixBuilder.addTransportDistance(i.getIndex(),j.getIndex(),getDistance(i,j));
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noLocations.size(), true);
|
||||
for (Location i : noLocations) {
|
||||
for (Location j : noLocations) {
|
||||
matrixBuilder.addTransportDistance(i.getIndex(), j.getIndex(), getDistance(i, j));
|
||||
matrixBuilder.addTransportTime(i.getIndex(), j.getIndex(), getDistance(i, j));
|
||||
}
|
||||
}
|
||||
|
|
@ -284,10 +278,10 @@ public class TSPLIB95Reader {
|
|||
double longitude_to = getLongitude(to);
|
||||
double latitude_from = getLatitude(from);
|
||||
double latitude_to = getLatitude(to);
|
||||
double q1 = Math.cos( longitude_from - longitude_to);
|
||||
double q2 = Math.cos( latitude_from - latitude_to);
|
||||
double q3 = Math.cos( latitude_from + latitude_to);
|
||||
return 6378.388 * Math.acos( .5 * ( ( 1. + q1 ) * q2 - ( 1. - q1 ) * q3 ) ) + 1.;
|
||||
double q1 = Math.cos(longitude_from - longitude_to);
|
||||
double q2 = Math.cos(latitude_from - latitude_to);
|
||||
double q3 = Math.cos(latitude_from + latitude_to);
|
||||
return 6378.388 * Math.acos(.5 * ((1. + q1) * q2 - (1. - q1) * q3)) + 1.;
|
||||
}
|
||||
|
||||
private double getLatitude(Location loc) {
|
||||
|
|
@ -303,7 +297,6 @@ public class TSPLIB95Reader {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void close(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
|
|
@ -316,7 +309,7 @@ public class TSPLIB95Reader {
|
|||
private String getLine(BufferedReader reader) {
|
||||
String s = null;
|
||||
try {
|
||||
s = reader.readLine();
|
||||
s = reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -96,7 +96,7 @@ package jsprit.instance.reader;
|
|||
//
|
||||
//public class Taillard {
|
||||
//
|
||||
//
|
||||
//
|
||||
// static class MyLocations implements Locations{
|
||||
//
|
||||
// private Map<String,Coordinate> locations = new HashMap<String, Coordinate>();
|
||||
|
|
@ -110,9 +110,9 @@ package jsprit.instance.reader;
|
|||
// return locations.get(id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static final String VRPHE = "vrphe";
|
||||
//
|
||||
//
|
||||
// public static final String VFM = "vfm";
|
||||
//
|
||||
// private static Logger logger = Logger.getLogger(Christophides.class);
|
||||
|
|
@ -126,7 +126,7 @@ package jsprit.instance.reader;
|
|||
// private String vehicleFile;
|
||||
//
|
||||
// private String vehicleCostScenario;
|
||||
//
|
||||
//
|
||||
// private String vrpType;
|
||||
//
|
||||
// private ResultWriter resultWriter;
|
||||
|
|
@ -142,15 +142,15 @@ package jsprit.instance.reader;
|
|||
// this.vehicleCostScenario = vehicleCostScenario;
|
||||
// this.vrpType = vrpType;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) throws IOException {
|
||||
// System.out.println("start " + System.currentTimeMillis());
|
||||
// Logger.getRootLogger().setLevel(Level.INFO);
|
||||
//
|
||||
// Logger.getRootLogger().setLevel(Level.INFO);
|
||||
//
|
||||
// int nOfProcessors = Runtime.getRuntime().availableProcessors();
|
||||
// logger.info("nOfProcessors: " + nOfProcessors);
|
||||
// ExecutorService executor = Executors.newFixedThreadPool(nOfProcessors+2);
|
||||
//
|
||||
//
|
||||
// ResultWriter resultWriter = new ResultWriter();
|
||||
//// String vrpType = "VFM";
|
||||
// String vrpType = VRPHE;
|
||||
|
|
@ -159,7 +159,7 @@ package jsprit.instance.reader;
|
|||
//
|
||||
// String problem = "100_" + pblm_abbr + "_LuiShen";
|
||||
// String problemFile = pblm_abbr + ".txt";
|
||||
// Taillard luiShen = new Taillard("/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/cvrptw_solomon/nOfCust100/"+problemFile,
|
||||
// Taillard luiShen = new Taillard("/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/cvrptw_solomon/nOfCust100/"+problemFile,
|
||||
// problem, "/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/vrphe_taillard/"+costScen+".txt", costScen, vrpType);
|
||||
// luiShen.setResultWriter(resultWriter);
|
||||
// luiShen.run(executor);
|
||||
|
|
@ -176,7 +176,7 @@ package jsprit.instance.reader;
|
|||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static String getName(int i) {
|
||||
// if(i<10){
|
||||
// return "0" + i;
|
||||
|
|
@ -188,27 +188,27 @@ package jsprit.instance.reader;
|
|||
//
|
||||
// private void setResultWriter(ResultWriter resultWriter) {
|
||||
// this.resultWriter = resultWriter;
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void run(ExecutorService executor){
|
||||
//
|
||||
//
|
||||
// final MyLocations myLocations = new MyLocations();
|
||||
// Collection<Job> jobs = new ArrayList<Job>();
|
||||
// final Map<String,Service> jobMap = readLocationsAndJobs(myLocations,jobs);
|
||||
//
|
||||
//
|
||||
// VehicleRoutingCosts costs = new VehicleRoutingCosts() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double getBackwardTransportTime(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportTime(fromId, toId, arrivalTime, null, null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double getBackwardTransportCost(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, arrivalTime, null, null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// double variableCost;
|
||||
|
|
@ -220,59 +220,59 @@ package jsprit.instance.reader;
|
|||
// }
|
||||
// return variableCost*EuclideanDistanceCalculator.calculateDistance(myLocations.getCoord(fromId), myLocations.getCoord(toId));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
//
|
||||
// VrpBuilder vrpBuilder = new VrpBuilder(costs);
|
||||
// for(Job j : jobs){
|
||||
// vrpBuilder.addJob(j);
|
||||
// }
|
||||
// createVehicles(vrpBuilder);
|
||||
// VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
//
|
||||
//
|
||||
// VehicleRoutingMetaAlgorithm metaAlgorithm = new VehicleRoutingMetaAlgorithm(vrp);
|
||||
// configure(metaAlgorithm,vrp,executor,myLocations);
|
||||
// metaAlgorithm.run();
|
||||
//
|
||||
//
|
||||
// printSolutions(vrp);
|
||||
//
|
||||
//
|
||||
// VehicleRoutingProblemSolution bestSolution = new SelectBest().selectSolution(vrp);
|
||||
//
|
||||
//
|
||||
// resultWriter.addResult(instanceName+"_"+vehicleCostScenario , instanceName, RouteUtils.getNuOfActiveRoutes(bestSolution.getRoutes()), bestSolution.getCost());
|
||||
// resultWriter.addSolution(bestSolution);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void printSolutions(VehicleRoutingProblem vrp) {
|
||||
// for(VehicleRoutingProblemSolution s : vrp.getSolutions()){
|
||||
// System.out.println("total: " + s.getCost());
|
||||
// System.out.println("activeTours: " + RouteUtils.getNuOfActiveRoutes(s.getRoutes()));
|
||||
// System.out.println("");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void configure(VehicleRoutingMetaAlgorithm metaAlgorithm, final VehicleRoutingProblem vrp, ExecutorService executor, MyLocations myLocations) {
|
||||
// VehicleRoute.VehicleRouteCostCalculator = new VehicleRouteCostCalculator() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public double calculate(Tour tour, Vehicle vehicle, Driver driver) {
|
||||
//// return vehicle.getType().vehicleCostParams.fix + tour.getCost();
|
||||
// return tour.getCost();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// };
|
||||
//
|
||||
//
|
||||
//// final VehicleFleetManager vehicleFleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||
// final VehicleFleetManager vehicleFleetManager = new VehicleFleetManagerImpl(vrp.getVehicles());
|
||||
//
|
||||
//
|
||||
// final VehicleRouteCostFunctionFactory costFuncFac = getFac();
|
||||
//
|
||||
//
|
||||
// AuxilliaryCostCalculator auxilliaryCostCalculator = new AuxilliaryCostCalculator(vrp.getCosts(), costFuncFac);
|
||||
// CalculatesActivityInsertion actInsertion = new CalculatesActivityInsertion(auxilliaryCostCalculator,0,5);
|
||||
//// CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(actInsertion);
|
||||
|
|
@ -280,82 +280,82 @@ package jsprit.instance.reader;
|
|||
// CalculatesServiceInsertionOnRouteLevel.MEMORYSIZE_FORPROMISING_INSERTIONPOSITIONS = 2;
|
||||
// CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion);
|
||||
// withFixCost.setWeightOfFixCost(0.0);
|
||||
//
|
||||
//
|
||||
// final JobInsertionCalculator vehicleTypeDepInsertionCost = new CalculatesVehTypeDepServiceInsertion(vehicleFleetManager, standardServiceInsertion);
|
||||
//
|
||||
//
|
||||
// final TourStateUpdater tourStateCalculator = new TourStateUpdater(vrp.getCosts(),costFuncFac);
|
||||
// tourStateCalculator.setTimeWindowUpdate(false);
|
||||
//
|
||||
//
|
||||
// RouteAgentFactory routeAgentFactory = new RouteAgentFactory(){
|
||||
//
|
||||
// @Override
|
||||
// public RouteAlgorithm createAgent(VehicleRoute route) {
|
||||
// VehicleSwitchedListener switched = new VehicleSwitchedListener() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
|
||||
// vehicleFleetManager.unlock(oldVehicle);
|
||||
// vehicleFleetManager.lock(newVehicle);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// };
|
||||
// RouteAlgorithmImpl agent = new RouteAlgorithmImpl(vehicleTypeDepInsertionCost, tourStateCalculator);
|
||||
// agent.getListeners().add(switched);
|
||||
// return agent;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// };
|
||||
//
|
||||
//
|
||||
// ParRegretInsertion regretInsertion = new ParRegretInsertion(executor, routeAgentFactory);
|
||||
// regretInsertion.getListener().add(new ConfigureFixCostCalculator(vrp, withFixCost));
|
||||
// regretInsertion.setJobDistance(new DepotDistance(myLocations, depotId));
|
||||
// regretInsertion.scoreParam_of_timeWindowLegth = 0.5;
|
||||
// regretInsertion.scoreParam_of_distance = 0.2;
|
||||
// regretInsertion.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId));
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// RecreationBestInsertion bestInsertion = new RecreationBestInsertion(routeAgentFactory);
|
||||
// bestInsertion.getListener().add(new ConfigureFixCostCalculator(vrp, withFixCost));
|
||||
// bestInsertion.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId));
|
||||
//
|
||||
//
|
||||
//// for(int i=0;i<3;i++){
|
||||
// VehicleRoutingProblemSolution vrpSol = new CreateInitialSolution(bestInsertion).createInitialSolution(vrp);
|
||||
// vrp.getSolutions().add(vrpSol);
|
||||
//// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// RadialAndRandomRemoveBestInsert smallNeighborHoodSearchModule = new RadialAndRandomRemoveBestInsert(vrp, vehicleFleetManager, routeAlgorithm);
|
||||
// smallNeighborHoodSearchModule.setCalcConsideringFix(withFixCost);
|
||||
// smallNeighborHoodSearchModule.setStateCalc(tourStateCalculator);
|
||||
// smallNeighborHoodSearchModule.setInsertionStrategy(bestInsertion);
|
||||
// smallNeighborHoodSearchModule.setAuxilliaryCostCalculator(auxilliaryCostCalculator);
|
||||
//
|
||||
//
|
||||
// SearchStrategy smallNeighborHoodSearch = new SearchStrategy(new SelectRandomly(), new AcceptNewRemoveWorst());
|
||||
//
|
||||
//
|
||||
// smallNeighborHoodSearch.addModule(smallNeighborHoodSearchModule);
|
||||
//
|
||||
// GendreauPostOpt postOpt = new GendreauPostOpt(vrp, routeAgentFactory,
|
||||
// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp),
|
||||
// GendreauPostOpt postOpt = new GendreauPostOpt(vrp, routeAgentFactory,
|
||||
// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp),
|
||||
// bestInsertion);
|
||||
// postOpt.setFleetManager(vehicleFleetManager);
|
||||
// postOpt.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId));
|
||||
// postOpt.setMaxIterations(2000);
|
||||
// postOpt.setShareOfJobsToRuin(0.18);
|
||||
//// smallNeighborHoodSearch.addModule(postOpt);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//// SearchStrategy strat2 = new SearchStrategy(new SelectBest(), new AcceptNewRemoveWorst());
|
||||
//// GendreauPostOpt postOpt2 = new GendreauPostOpt(vrp, routeAgentFactory,
|
||||
//// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp),
|
||||
//// GendreauPostOpt postOpt2 = new GendreauPostOpt(vrp, routeAgentFactory,
|
||||
//// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp),
|
||||
//// bestInsertion);
|
||||
//// postOpt2.setFleetManager(vehicleFleetManager);
|
||||
//// postOpt2.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId));
|
||||
//// postOpt2.setMaxIterations(2000);
|
||||
//// postOpt2.setShareOfJobsToRuin(0.1);
|
||||
//// strat2.addModule(postOpt2);
|
||||
//
|
||||
//
|
||||
// SearchStrategyModule solutionVerifier = new SearchStrategyModule() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
|
||||
// logger.info("verify solution");
|
||||
|
|
@ -364,27 +364,27 @@ package jsprit.instance.reader;
|
|||
// }
|
||||
// };
|
||||
// smallNeighborHoodSearch.addModule(solutionVerifier);
|
||||
//
|
||||
//
|
||||
// SearchStrategyManager strategyManager = new SearchStrategyManager();
|
||||
// strategyManager.addStrategy(smallNeighborHoodSearch, 1.0);
|
||||
//// strategyManager.addStrategy(strat2, 0.3);
|
||||
//
|
||||
//
|
||||
// metaAlgorithm.setSearchStrategyManager(strategyManager);
|
||||
// metaAlgorithm.setMaxIterations(20);
|
||||
// VehicleRoutingProblem.SOLUTION_MEMORY = 4;
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private VehicleRouteCostFunctionFactory getFac() {
|
||||
// VehicleRouteCostFunctionFactory fac = new VehicleRouteCostFunctionFactory() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public VehicleRouteCostFunction createCostFunction(Vehicle vehicle, Driver driver) {
|
||||
// return new VehicleRouteCostFunction(){
|
||||
//
|
||||
// double cost = 0.0;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void handleActivity(TourActivity tourAct, double startTime, double endTime) {
|
||||
// if(startTime > tourAct.getLatestOperationStartTime()){
|
||||
|
|
@ -395,7 +395,7 @@ package jsprit.instance.reader;
|
|||
// @Override
|
||||
// public void handleLeg(TourActivity fromAct, TourActivity toAct, double depTime, double tpCost) {
|
||||
// cost += tpCost;
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
|
|
@ -405,15 +405,15 @@ package jsprit.instance.reader;
|
|||
//
|
||||
// @Override
|
||||
// public void finish() {
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void reset() {
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// };
|
||||
// }
|
||||
// };
|
||||
|
|
@ -477,7 +477,7 @@ package jsprit.instance.reader;
|
|||
// int vehicleCap = Integer.parseInt(tokens[1]);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if(counter > 9){
|
||||
// Coordinate coord = makeCoord(tokens[1],tokens[2]);
|
||||
// double depotStart = 0.0;
|
||||
|
|
@ -492,18 +492,18 @@ package jsprit.instance.reader;
|
|||
// depotStart = start;
|
||||
// depotEnd = end;
|
||||
// depotId = tokens[0];
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else{
|
||||
// Service service = VrpUtils.createService("" + counter, customerId, demand, 0.0, 0.0, Double.MAX_VALUE);
|
||||
//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand,
|
||||
//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand,
|
||||
//// VrpUtils.createTimeWindow(depotStart, depotEnd), VrpUtils.createTimeWindow(start, end));
|
||||
//// shipment.setDeliveryServiceTime(serviceTime);
|
||||
// jobs.add(service);
|
||||
// jobMap.put(customerId, service);
|
||||
//// jobs.add(shipment);
|
||||
//// j
|
||||
//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand,
|
||||
//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand,
|
||||
//// VrpUtils.createTimeWindow(depotStart, depotEnd), VrpUtils.createTimeWindow(start, end));
|
||||
//// shipment.setDeliveryServiceTime(serviceTime);
|
||||
//// jobs.add(shipment);
|
||||
|
|
@ -520,7 +520,7 @@ package jsprit.instance.reader;
|
|||
// }
|
||||
// return jobMap;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private Coordinate makeCoord(String xString, String yString) {
|
||||
// double x = Double.parseDouble(xString);
|
||||
// double y = Double.parseDouble(yString);
|
||||
|
|
|
|||
|
|
@ -30,158 +30,144 @@ import jsprit.core.util.Coordinate;
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Reads modified files from Taillard's website
|
||||
* http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here:
|
||||
* Reads modified files from Taillard's website
|
||||
* http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here:
|
||||
* jsprit-instances/instances/vrph.
|
||||
*
|
||||
* <p/>
|
||||
* <p>See {@link VrphType} what kind of problems can be generated
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
public class VrphGoldenReader {
|
||||
|
||||
/**
|
||||
*
|
||||
* <b>FSMD</b> - Fleet Size and Mix with Dependent costs
|
||||
* <p><b>FSMF</b> - Fleet Size and Mix with Fixed costs
|
||||
* <p><b>FSMFD</b> - Fleet Size and Mix with Fixed and Dependent costs
|
||||
* <p><b>HVRPD</b> - Heterogeneous Vehicle Routing Problem with Dependent costs and finite (limited) fleet
|
||||
* <p><b>HVRPFD</b> - Heterogeneous Vehicle Routing Problem with Fixed and Dependent costs and finite (limited) fleet
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public enum VrphType {
|
||||
FSMD,
|
||||
HVRPD,
|
||||
FSMF,
|
||||
FSMFD,
|
||||
HVRPFD
|
||||
}
|
||||
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private final VrphType vrphType;
|
||||
|
||||
public VrphGoldenReader(Builder vrpBuilder, VrphType vrphType) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
this.vrphType = vrphType;
|
||||
}
|
||||
|
||||
public void read(String filename){
|
||||
BufferedReader reader = getReader(filename);
|
||||
String line;
|
||||
boolean firstline = true;
|
||||
Coordinate depotCoord = null;
|
||||
int customerCount=0;
|
||||
Integer nuOfCustomer = 0;
|
||||
while((line=readLine(reader))!=null){
|
||||
String trimedLine = line.trim();
|
||||
if(trimedLine.startsWith("//")) continue;
|
||||
String[] tokens = trimedLine.split("\\s+");
|
||||
if(firstline){
|
||||
nuOfCustomer=Integer.parseInt(tokens[0]);
|
||||
customerCount=0;
|
||||
firstline=false;
|
||||
}
|
||||
else if(customerCount<=nuOfCustomer) {
|
||||
if(customerCount == 0){
|
||||
depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
|
||||
}
|
||||
else{
|
||||
Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0]).addSizeDimension(0, Integer.parseInt(tokens[3]));
|
||||
serviceBuilder.setLocation(Location.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])));
|
||||
vrpBuilder.addJob(serviceBuilder.build());
|
||||
}
|
||||
customerCount++;
|
||||
}
|
||||
else if(trimedLine.startsWith("v")){
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_"+tokens[1]).addCapacityDimension(0, Integer.parseInt(tokens[2]));
|
||||
int nuOfVehicles = 1;
|
||||
if(vrphType.equals(VrphType.FSMF)){
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
}
|
||||
else if(vrphType.equals(VrphType.FSMFD)){
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
if(tokens.length > 4){
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
}
|
||||
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
}
|
||||
else if(vrphType.equals(VrphType.FSMD)){
|
||||
if(tokens.length > 4){
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
}
|
||||
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
}
|
||||
else if(vrphType.equals(VrphType.HVRPD)){
|
||||
if(tokens.length > 4){
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
nuOfVehicles = Integer.parseInt(tokens[5]);
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
}
|
||||
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
}
|
||||
else if (vrphType.equals(VrphType.HVRPFD)){
|
||||
if(tokens.length > 4){
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
nuOfVehicles = Integer.parseInt(tokens[5]);
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
}
|
||||
else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
}
|
||||
for(int i=0;i<nuOfVehicles;i++){
|
||||
VehicleTypeImpl type = typeBuilder.build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle_"+tokens[1]+"_"+i)
|
||||
.setStartLocation(Location.newInstance(depotCoord.getX(),depotCoord.getY())).setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
closeReader(reader);
|
||||
}
|
||||
/**
|
||||
* <b>FSMD</b> - Fleet Size and Mix with Dependent costs
|
||||
* <p><b>FSMF</b> - Fleet Size and Mix with Fixed costs
|
||||
* <p><b>FSMFD</b> - Fleet Size and Mix with Fixed and Dependent costs
|
||||
* <p><b>HVRPD</b> - Heterogeneous Vehicle Routing Problem with Dependent costs and finite (limited) fleet
|
||||
* <p><b>HVRPFD</b> - Heterogeneous Vehicle Routing Problem with Fixed and Dependent costs and finite (limited) fleet
|
||||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
public enum VrphType {
|
||||
FSMD,
|
||||
HVRPD,
|
||||
FSMF,
|
||||
FSMFD,
|
||||
HVRPFD
|
||||
}
|
||||
|
||||
private void closeReader(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
private final VehicleRoutingProblem.Builder vrpBuilder;
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
String readLine = null;
|
||||
try {
|
||||
readLine = reader.readLine();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
return readLine;
|
||||
}
|
||||
private final VrphType vrphType;
|
||||
|
||||
private BufferedReader getReader(String filename) {
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new FileReader(new File(filename)));
|
||||
return bufferedReader;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
return bufferedReader;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VrphGoldenReader goldenReader = new VrphGoldenReader(vrpBuilder, VrphType.FSMD);
|
||||
goldenReader.read("instances/vrph/orig/cn_13mix.txt");
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
new VrpXMLWriter(vrp).write("instances/vrph/cn_13mix_VRPH_INFINITE.xml");
|
||||
}
|
||||
public VrphGoldenReader(Builder vrpBuilder, VrphType vrphType) {
|
||||
super();
|
||||
this.vrpBuilder = vrpBuilder;
|
||||
this.vrphType = vrphType;
|
||||
}
|
||||
|
||||
public void read(String filename) {
|
||||
BufferedReader reader = getReader(filename);
|
||||
String line;
|
||||
boolean firstline = true;
|
||||
Coordinate depotCoord = null;
|
||||
int customerCount = 0;
|
||||
Integer nuOfCustomer = 0;
|
||||
while ((line = readLine(reader)) != null) {
|
||||
String trimedLine = line.trim();
|
||||
if (trimedLine.startsWith("//")) continue;
|
||||
String[] tokens = trimedLine.split("\\s+");
|
||||
if (firstline) {
|
||||
nuOfCustomer = Integer.parseInt(tokens[0]);
|
||||
customerCount = 0;
|
||||
firstline = false;
|
||||
} else if (customerCount <= nuOfCustomer) {
|
||||
if (customerCount == 0) {
|
||||
depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]));
|
||||
} else {
|
||||
Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0]).addSizeDimension(0, Integer.parseInt(tokens[3]));
|
||||
serviceBuilder.setLocation(Location.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])));
|
||||
vrpBuilder.addJob(serviceBuilder.build());
|
||||
}
|
||||
customerCount++;
|
||||
} else if (trimedLine.startsWith("v")) {
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_" + tokens[1]).addCapacityDimension(0, Integer.parseInt(tokens[2]));
|
||||
int nuOfVehicles = 1;
|
||||
if (vrphType.equals(VrphType.FSMF)) {
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
} else if (vrphType.equals(VrphType.FSMFD)) {
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
if (tokens.length > 4) {
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
} else
|
||||
throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
} else if (vrphType.equals(VrphType.FSMD)) {
|
||||
if (tokens.length > 4) {
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
} else
|
||||
throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
} else if (vrphType.equals(VrphType.HVRPD)) {
|
||||
if (tokens.length > 4) {
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
nuOfVehicles = Integer.parseInt(tokens[5]);
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
} else
|
||||
throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
} else if (vrphType.equals(VrphType.HVRPFD)) {
|
||||
if (tokens.length > 4) {
|
||||
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
|
||||
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
|
||||
nuOfVehicles = Integer.parseInt(tokens[5]);
|
||||
vrpBuilder.setFleetSize(FleetSize.FINITE);
|
||||
} else
|
||||
throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance");
|
||||
}
|
||||
for (int i = 0; i < nuOfVehicles; i++) {
|
||||
VehicleTypeImpl type = typeBuilder.build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle_" + tokens[1] + "_" + i)
|
||||
.setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())).setType(type).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
closeReader(reader);
|
||||
}
|
||||
|
||||
private void closeReader(BufferedReader reader) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedReader reader) {
|
||||
String readLine = null;
|
||||
try {
|
||||
readLine = reader.readLine();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return readLine;
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String filename) {
|
||||
BufferedReader bufferedReader = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new FileReader(new File(filename)));
|
||||
return bufferedReader;
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VrphGoldenReader goldenReader = new VrphGoldenReader(vrpBuilder, VrphType.FSMD);
|
||||
goldenReader.read("instances/vrph/orig/cn_13mix.txt");
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
new VrpXMLWriter(vrp).write("instances/vrph/cn_13mix_VRPH_INFINITE.xml");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.util;
|
||||
|
|
@ -31,216 +31,219 @@ import java.util.List;
|
|||
|
||||
public class Instances {
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Cordeau's p instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 23 p-instances are located with their original name, i.e. p01,p02,...,p23.
|
||||
* <p>It also assumes that solution files are also located in inputFolder ending with .res
|
||||
*
|
||||
* @param inputFolder where cordeau's p instances are located. It must end without '/' such as instances/cordeau.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllCordeauP(String inputFolder){
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<23;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/p"+ getInstanceNu(i+1);
|
||||
new CordeauReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("p" + getInstanceNu(i+1), p, getBestKnown(file), null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Cordeau's p instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 23 p-instances are located with their original name, i.e. p01,p02,...,p23.
|
||||
* <p>It also assumes that solution files are also located in inputFolder ending with .res
|
||||
*
|
||||
* @param inputFolder where cordeau's p instances are located. It must end without '/' such as instances/cordeau.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllCordeauP(String inputFolder) {
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 23; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/p" + getInstanceNu(i + 1);
|
||||
new CordeauReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("p" + getInstanceNu(i + 1), p, getBestKnown(file), null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static double getBestKnown(String file) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(new File(file+".res")));
|
||||
String first = reader.readLine();
|
||||
Double result = Double.valueOf(first);
|
||||
reader.close();
|
||||
return result;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static String getInstanceNu(int i) {
|
||||
if(i<10) return "0"+i;
|
||||
return ""+i;
|
||||
}
|
||||
private static double getBestKnown(String file) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(new File(file + ".res")));
|
||||
String first = reader.readLine();
|
||||
Double result = Double.valueOf(first);
|
||||
reader.close();
|
||||
return result;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Cordeau's pr instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 10 p-instances are located with their original name, i.e. pr01,pr02,...,pr10.
|
||||
* <p>It also assumes that solution files are also located in inputFolder ending with .res
|
||||
* @param inputFolder
|
||||
* @param inputFolder where cordeau's pr instances are located. It must end without '/' such as instances/cordeau.
|
||||
*
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllCordeauPR(String inputFolder){
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<10;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/pr"+ getInstanceNu(i+1);
|
||||
new CordeauReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("pr" + getInstanceNu(i+1), p, getBestKnown(file),null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Christofides vrpnc instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 14 vrpnc-instances are located with their original name, i.e. vrpnc1,vrpnc2,...,vrpnc14.
|
||||
*
|
||||
* @param inputFolder where christofides vrpnc instances are located. It must end without '/' such as instances/christofides.
|
||||
*
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllChristofides(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(524.61,835.26,826.14,1028.42,1291.29,555.43,909.68,865.49,1162.55,1395.85,1042.11,819.56,1541.14,866.37);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<14;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/vrpnc"+ (i+1) + ".txt";
|
||||
new ChristofidesReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("vrpnc" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 9 C1-instances are located with their original name, i.e. C101.txt,C102.txt,...,C109.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder where solomon C1 instances are located. It must end without '/' such as instances/solomon.
|
||||
*
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonC1(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(828.94,828.94,828.06,824.78,828.94,828.94,828.94,828.94,828.94);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<9;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/C1"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("C1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 C2-instances are located with their original name, i.e. C201.txt,C202.txt,...,C208.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder where solomon C2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonC2(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(591.56,591.56,591.17,590.60,588.88,588.49,588.29,588.32);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<8;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/C2"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("C2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 12 R1-instances are located with their original name, i.e. R101.txt,R102.txt,...,R112.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder where solomon R1 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonR1(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(1650.80,1486.12,1292.68,1007.31,1377.11,1252.03,1104.66,960.88,1194.73,1118.84,1096.72,982.14);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(19.0,17.0,13.0,9.0,14.0,12.0,10.0,9.0,11.0,10.0,10.0,9.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<12;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/R1"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("R1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 11 R1-instances are located with their original name, i.e. R201.txt,R202.txt,...,R111.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder
|
||||
* @param inputFolder where solomon R2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonR2(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(1252.37,1191.70,939.50,825.52,994.42,906.14,890.61,726.82,909.16,939.37,885.71);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(4.0,3.0,3.0,2.0,3.0,3.0,2.0,2.0,3.0,3.0,2.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<11;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/R2"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("R2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 RC1-instances are located with their original name, i.e. RC101.txt,RC102.txt,...,RC108.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder where solomon RC1 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonRC1(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(1696.94,1554.75,1261.67,1135.48,1629.44,1424.73,1230.48,1139.82);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(14.0,12.0,11.0,10.0,13.0,11.0,11.0,10.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<8;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/RC1"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("RC1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 RC2-instances are located with their original name, i.e. RC201.txt,RC202.txt,...,RC208.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
* @param inputFolder
|
||||
* @param inputFolder where solomon RC2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonRC2(String inputFolder){
|
||||
List<Double> bestKnown = Arrays.asList(1406.94,1365.65,1049.62,798.46,1297.65,1146.32,1061.14,828.14);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(4.0,3.0,3.0,3.0,4.0,3.0,3.0,3.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for(int i=0;i<8;i++){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/RC2"+ getInstanceNu(i+1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("RC2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
private static String getInstanceNu(int i) {
|
||||
if (i < 10) return "0" + i;
|
||||
return "" + i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Cordeau's pr instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 10 p-instances are located with their original name, i.e. pr01,pr02,...,pr10.
|
||||
* <p>It also assumes that solution files are also located in inputFolder ending with .res
|
||||
*
|
||||
* @param inputFolder
|
||||
* @param inputFolder where cordeau's pr instances are located. It must end without '/' such as instances/cordeau.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllCordeauPR(String inputFolder) {
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/pr" + getInstanceNu(i + 1);
|
||||
new CordeauReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("pr" + getInstanceNu(i + 1), p, getBestKnown(file), null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Christofides vrpnc instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 14 vrpnc-instances are located with their original name, i.e. vrpnc1,vrpnc2,...,vrpnc14.
|
||||
*
|
||||
* @param inputFolder where christofides vrpnc instances are located. It must end without '/' such as instances/christofides.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllChristofides(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(524.61, 835.26, 826.14, 1028.42, 1291.29, 555.43, 909.68, 865.49, 1162.55, 1395.85, 1042.11, 819.56, 1541.14, 866.37);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 14; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/vrpnc" + (i + 1) + ".txt";
|
||||
new ChristofidesReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("vrpnc" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), null));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 9 C1-instances are located with their original name, i.e. C101.txt,C102.txt,...,C109.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder where solomon C1 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonC1(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(828.94, 828.94, 828.06, 824.78, 828.94, 828.94, 828.94, 828.94, 828.94);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/C1" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("C1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 C2-instances are located with their original name, i.e. C201.txt,C202.txt,...,C208.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder where solomon C2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonC2(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(591.56, 591.56, 591.17, 590.60, 588.88, 588.49, 588.29, 588.32);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/C2" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("C2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 12 R1-instances are located with their original name, i.e. R101.txt,R102.txt,...,R112.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder where solomon R1 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonR1(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(1650.80, 1486.12, 1292.68, 1007.31, 1377.11, 1252.03, 1104.66, 960.88, 1194.73, 1118.84, 1096.72, 982.14);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(19.0, 17.0, 13.0, 9.0, 14.0, 12.0, 10.0, 9.0, 11.0, 10.0, 10.0, 9.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 12; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/R1" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("R1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 11 R1-instances are located with their original name, i.e. R201.txt,R202.txt,...,R111.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder
|
||||
* @param inputFolder where solomon R2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonR2(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(1252.37, 1191.70, 939.50, 825.52, 994.42, 906.14, 890.61, 726.82, 909.16, 939.37, 885.71);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(4.0, 3.0, 3.0, 2.0, 3.0, 3.0, 2.0, 2.0, 3.0, 3.0, 2.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/R2" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("R2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 RC1-instances are located with their original name, i.e. RC101.txt,RC102.txt,...,RC108.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder where solomon RC1 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonRC1(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(1696.94, 1554.75, 1261.67, 1135.48, 1629.44, 1424.73, 1230.48, 1139.82);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(14.0, 12.0, 11.0, 10.0, 13.0, 11.0, 11.0, 10.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/RC1" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("RC1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link BenchmarkInstance} which are Solomon instances.
|
||||
* <p>Note that this assumes that within the folder 'inputFolder' 8 RC2-instances are located with their original name, i.e. RC201.txt,RC202.txt,...,RC208.txt.
|
||||
* <p>Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle.
|
||||
*
|
||||
* @param inputFolder
|
||||
* @param inputFolder where solomon RC2 instances are located. It must end without '/' such as instances/solomon.
|
||||
* @return a collection of {@link BenchmarkInstance}
|
||||
*/
|
||||
public static Collection<BenchmarkInstance> getAllSolomonRC2(String inputFolder) {
|
||||
List<Double> bestKnown = Arrays.asList(1406.94, 1365.65, 1049.62, 798.46, 1297.65, 1146.32, 1061.14, 828.14);
|
||||
List<Double> bestKnowVehicles = Arrays.asList(4.0, 3.0, 3.0, 3.0, 4.0, 3.0, 3.0, 3.0);
|
||||
Collection<BenchmarkInstance> instances = new ArrayList<BenchmarkInstance>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
String file = inputFolder + "/RC2" + getInstanceNu(i + 1) + ".txt";
|
||||
new SolomonReader(builder).read(file);
|
||||
VehicleRoutingProblem p = builder.build();
|
||||
instances.add(new BenchmarkInstance("RC2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue()));
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -28,78 +28,76 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
|
||||
public class ChristophidesReaderTest {
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_nuOfCustomersIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(50,vrp.getJobs().values().size());
|
||||
}
|
||||
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if(resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_fleetSizeIsInfinite(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(FleetSize.INFINITE,vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleCapacitiesAreCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(160,v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(30.0,v.getStartLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(40.0,v.getStartLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleDurationsAreCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc13.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(0.0,v.getEarliestDeparture(),0.01);
|
||||
assertEquals(720.0,v.getLatestArrival()-v.getEarliestDeparture(),0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_demandOfCustomerOneIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(7,vrp.getJobs().get("1").getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_serviceDurationOfCustomerTwoIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc13.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(50.0,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_nuOfCustomersIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(50, vrp.getJobs().values().size());
|
||||
}
|
||||
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if (resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_fleetSizeIsInfinite() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(FleetSize.INFINITE, vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleCapacitiesAreCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(160, v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(30.0, v.getStartLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(40.0, v.getStartLocation().getCoordinate().getY(), 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleDurationsAreCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc13.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(0.0, v.getEarliestDeparture(), 0.01);
|
||||
assertEquals(720.0, v.getLatestArrival() - v.getEarliestDeparture(), 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_demandOfCustomerOneIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc1.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(7, vrp.getJobs().get("1").getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_serviceDurationOfCustomerTwoIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new ChristofidesReader(builder).read(getPath("vrpnc13.txt"));
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(50.0, ((Service) vrp.getJobs().get("2")).getServiceDuration(), 0.1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -29,125 +29,129 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
|
||||
public class CordeauReaderTest {
|
||||
|
||||
@Test
|
||||
public void testCordeauReader(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
vrpBuilder.build();
|
||||
|
||||
}
|
||||
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if(resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_fleetSizeIsFinite(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(FleetSize.FINITE, vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
assertEquals(16,vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCordeauInstance_vehiclesHaveTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(80, v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCordeauInstance_vehiclesHaveTheCorrectDuration(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p08"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(0.0,v.getEarliestDeparture(),0.1);
|
||||
assertEquals(310.0, v.getLatestArrival()-v.getEarliestDeparture(),0.1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerOneShouldHaveCorrectCoordinates(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("1");
|
||||
assertEquals(37.0, service.getLocation().getCoordinate().getX(), 0.1);
|
||||
assertEquals(52.0, service.getLocation().getCoordinate().getY(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerTwoShouldHaveCorrectServiceDuration(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("2");
|
||||
assertEquals(0.0, service.getServiceDuration(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerThreeShouldHaveCorrectDemand(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("3");
|
||||
assertEquals(16.0, service.getSize().get(0), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerFortySevenShouldHaveCorrectDemand(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("47");
|
||||
assertEquals(25.0, service.getSize().get(0), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationsAndCapOfVehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
boolean capacityOk = true;
|
||||
boolean loc1ok = false;
|
||||
boolean loc2ok = false;
|
||||
boolean loc3ok = false;
|
||||
boolean loc4ok = false;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getCapacityDimensions().get(0) != 80) capacityOk = false;
|
||||
if(v.getStartLocation().getCoordinate().getX() == 20.0 && v.getStartLocation().getCoordinate().getY() == 20.0) loc1ok = true;
|
||||
if(v.getStartLocation().getCoordinate().getX() == 30.0 && v.getStartLocation().getCoordinate().getY() == 40.0) loc2ok = true;
|
||||
if(v.getStartLocation().getCoordinate().getX() == 50.0 && v.getStartLocation().getCoordinate().getY() == 30.0) loc3ok = true;
|
||||
if(v.getStartLocation().getCoordinate().getX() == 60.0 && v.getStartLocation().getCoordinate().getY() == 50.0) loc4ok = true;
|
||||
}
|
||||
assertTrue(capacityOk);
|
||||
assertTrue(loc1ok);
|
||||
assertTrue(loc2ok);
|
||||
assertTrue(loc3ok);
|
||||
assertTrue(loc4ok);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfCustomers(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(50,vrp.getJobs().values().size());
|
||||
}
|
||||
@Test
|
||||
public void testCordeauReader() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
vrpBuilder.build();
|
||||
|
||||
}
|
||||
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if (resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_fleetSizeIsFinite() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(FleetSize.FINITE, vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfVehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
assertEquals(16, vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCordeauInstance_vehiclesHaveTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(80, v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCordeauInstance_vehiclesHaveTheCorrectDuration() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p08"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(0.0, v.getEarliestDeparture(), 0.1);
|
||||
assertEquals(310.0, v.getLatestArrival() - v.getEarliestDeparture(), 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerOneShouldHaveCorrectCoordinates() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("1");
|
||||
assertEquals(37.0, service.getLocation().getCoordinate().getX(), 0.1);
|
||||
assertEquals(52.0, service.getLocation().getCoordinate().getY(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerTwoShouldHaveCorrectServiceDuration() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("2");
|
||||
assertEquals(0.0, service.getServiceDuration(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerThreeShouldHaveCorrectDemand() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("3");
|
||||
assertEquals(16.0, service.getSize().get(0), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingCustomersCordeauInstance_customerFortySevenShouldHaveCorrectDemand() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Service service = (Service) vrp.getJobs().get("47");
|
||||
assertEquals(25.0, service.getSize().get(0), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationsAndCapOfVehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
boolean capacityOk = true;
|
||||
boolean loc1ok = false;
|
||||
boolean loc2ok = false;
|
||||
boolean loc3ok = false;
|
||||
boolean loc4ok = false;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getCapacityDimensions().get(0) != 80) capacityOk = false;
|
||||
if (v.getStartLocation().getCoordinate().getX() == 20.0 && v.getStartLocation().getCoordinate().getY() == 20.0)
|
||||
loc1ok = true;
|
||||
if (v.getStartLocation().getCoordinate().getX() == 30.0 && v.getStartLocation().getCoordinate().getY() == 40.0)
|
||||
loc2ok = true;
|
||||
if (v.getStartLocation().getCoordinate().getX() == 50.0 && v.getStartLocation().getCoordinate().getY() == 30.0)
|
||||
loc3ok = true;
|
||||
if (v.getStartLocation().getCoordinate().getX() == 60.0 && v.getStartLocation().getCoordinate().getY() == 50.0)
|
||||
loc4ok = true;
|
||||
}
|
||||
assertTrue(capacityOk);
|
||||
assertTrue(loc1ok);
|
||||
assertTrue(loc2ok);
|
||||
assertTrue(loc3ok);
|
||||
assertTrue(loc4ok);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfCustomers() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new CordeauReader(vrpBuilder).read(getPath("p01"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(50, vrp.getJobs().values().size());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,150 +32,150 @@ public class FigliozziTest {
|
|||
Locations locations;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
final Coordinate from = Coordinate.newInstance(0,0);
|
||||
final Coordinate to = Coordinate.newInstance(100,0);
|
||||
public void doBefore() {
|
||||
final Coordinate from = Coordinate.newInstance(0, 0);
|
||||
final Coordinate to = Coordinate.newInstance(100, 0);
|
||||
|
||||
locations = new Locations(){
|
||||
locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return from;
|
||||
if(id.equals("to")) return to;
|
||||
if (id.equals("from")) return from;
|
||||
if (id.equals("to")) return to;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.6,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.05,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1.6, 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.05, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD2a_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD2a_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),2.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.5,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 2., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.5, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD3a_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD3a_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),2.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.75,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 2.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.75, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD1b_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD1b_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b);
|
||||
Assert.assertEquals(speedValues.get(0),1.6,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.05,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),1.6,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1.6, 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.05, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 1.6, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD2b_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD2b_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b);
|
||||
Assert.assertEquals(speedValues.get(0),2.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),2.,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 2., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 2., 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD3b_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD3b_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b);
|
||||
Assert.assertEquals(speedValues.get(0),2.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.75,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),2.5,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 2.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.75, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 2.5, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD1c_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD1c_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c);
|
||||
Assert.assertEquals(speedValues.get(0),1.6,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.6,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.05,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),1.,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1.6, 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1.6, 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.05, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 1., 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD2c_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD2c_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c);
|
||||
Assert.assertEquals(speedValues.get(0),2.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),2.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),1.,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 2., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 2., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 1., 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD3c_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD3c_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c);
|
||||
Assert.assertEquals(speedValues.get(0),2.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),2.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.75,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),1.,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 2.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 2.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.75, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 1., 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD1d_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD1d_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.05,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),1.6,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),1.6,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.05, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 1.6, 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 1.6, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD2d_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD2d_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),2.,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),2.,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 2., 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 2., 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAskingForTD3d_factoryShouldReturnCorrectSpeedDistribution(){
|
||||
public void whenAskingForTD3d_factoryShouldReturnCorrectSpeedDistribution() {
|
||||
List<Double> speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d);
|
||||
Assert.assertEquals(speedValues.get(0),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(1),1.,0.01);
|
||||
Assert.assertEquals(speedValues.get(2),1.75,0.01);
|
||||
Assert.assertEquals(speedValues.get(3),2.5,0.01);
|
||||
Assert.assertEquals(speedValues.get(4),2.5,0.01);
|
||||
Assert.assertEquals(5,speedValues.size());
|
||||
Assert.assertEquals(speedValues.get(0), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(1), 1., 0.01);
|
||||
Assert.assertEquals(speedValues.get(2), 1.75, 0.01);
|
||||
Assert.assertEquals(speedValues.get(3), 2.5, 0.01);
|
||||
Assert.assertEquals(speedValues.get(4), 2.5, 0.01);
|
||||
Assert.assertEquals(5, speedValues.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
|
||||
public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100() {
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC, 100);
|
||||
Assert.assertEquals(100., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -184,8 +184,8 @@ public class FigliozziTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenTimeDistributionTD1a_forwardTimeShouldBeCalculate100(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100);
|
||||
public void whenTimeDistributionTD1a_forwardTimeShouldBeCalculate100() {
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100);
|
||||
/*
|
||||
100
|
||||
(0,20) - 1. --> 20
|
||||
|
|
@ -196,13 +196,13 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(76.875,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
Assert.assertEquals(76.875, tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTimeDistributionTD2a_forwardTimeShouldBeCalculate100(){
|
||||
public void whenTimeDistributionTD2a_forwardTimeShouldBeCalculate100() {
|
||||
//(1.,2.,1.5,2.,1.)
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100);
|
||||
/*
|
||||
100
|
||||
(0,20) - 1. --> 20 dist, 20 time
|
||||
|
|
@ -213,26 +213,26 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(65.,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
Assert.assertEquals(65., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTimeDistributionTD3a_forwardTimeShouldBeCalculate100(){
|
||||
public void whenTimeDistributionTD3a_forwardTimeShouldBeCalculate100() {
|
||||
//(1.,2.5,1.75,2.5,1.)
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a, 100);
|
||||
/*
|
||||
100
|
||||
(0,20) - 1. --> 20 dist, 20 time
|
||||
(20,40) 2.5 = 20 --> 50 dist, 20 time : 70 dist, 40 time
|
||||
(40,60) 1.75 = 30 dist, 17.1428571429 time : 100 dist, 57.1428571429 time
|
||||
*/
|
||||
Assert.assertEquals(57.1428571429,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
Assert.assertEquals(57.1428571429, tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTimeDistributionTD2a_backwardTimeShouldBeCalculate100(){
|
||||
public void whenTimeDistributionTD2a_backwardTimeShouldBeCalculate100() {
|
||||
//(1.,2.,1.5,2.,1.)
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100);
|
||||
/*
|
||||
100
|
||||
(0,20) - 1. --> 20 dist, 20 time
|
||||
|
|
@ -243,12 +243,12 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(65.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
|
||||
Assert.assertEquals(65., tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTimeDistributionTD1a_backwardTimeShouldBeCalculate100(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100);
|
||||
public void whenTimeDistributionTD1a_backwardTimeShouldBeCalculate100() {
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100);
|
||||
/*
|
||||
100
|
||||
(0,20) - 1. --> 20
|
||||
|
|
@ -259,217 +259,217 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
|
||||
Assert.assertEquals(76.875, tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backwardTimeShouldBeCalculatedCorrectly(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
|
||||
Assert.assertEquals(100.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"),100.,null,null),0.01);
|
||||
public void backwardTimeShouldBeCalculatedCorrectly() {
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC, 100);
|
||||
Assert.assertEquals(100., tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD1a_distanceShouldBe25PercentMore(){
|
||||
public void whenTD1a_distanceShouldBe25PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(125.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(125., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD1b_distanceShouldBe25PercentMore(){
|
||||
public void whenTD1b_distanceShouldBe25PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(125.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(125., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD1c_distanceShouldBe25PercentMore(){
|
||||
public void whenTD1c_distanceShouldBe25PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(125.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(125., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD1d_distanceShouldBe25PercentMore(){
|
||||
public void whenTD1d_distanceShouldBe25PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(125.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(125., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD2a_distanceShouldBe50PercentMore(){
|
||||
public void whenTD2a_distanceShouldBe50PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(150.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(150., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD2b_distanceShouldBe50PercentMore(){
|
||||
public void whenTD2b_distanceShouldBe50PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(150.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(150., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD2c_distanceShouldBe50PercentMore(){
|
||||
public void whenTD2c_distanceShouldBe50PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(150.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(150., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD2d_distanceShouldBe50PercentMore(){
|
||||
public void whenTD2d_distanceShouldBe50PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(150.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(150., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD3a_distanceShouldBe75PercentMore(){
|
||||
public void whenTD3a_distanceShouldBe75PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(175.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(175., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD3b_distanceShouldBe75PercentMore(){
|
||||
public void whenTD3b_distanceShouldBe75PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(175.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(175., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD3c_distanceShouldBe75PercentMore(){
|
||||
public void whenTD3c_distanceShouldBe75PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(175.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(175., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTD3d_distanceShouldBe75PercentMore(){
|
||||
public void whenTD3d_distanceShouldBe75PercentMore() {
|
||||
Locations locations = new Locations() {
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
if(id.equals("from")) return Coordinate.newInstance(0,0);
|
||||
if(id.equals("to")) return Coordinate.newInstance(175.,0);
|
||||
if (id.equals("from")) return Coordinate.newInstance(0, 0);
|
||||
if (id.equals("to")) return Coordinate.newInstance(175., 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d,100);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d, 100);
|
||||
double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null);
|
||||
Assert.assertEquals(100., time, 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,297 +30,296 @@ import java.net.URL;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
public class GoldenReaderTest {
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(17,vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if(resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_1")){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_1")){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(80,sumOfType1Cap);
|
||||
}
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfVehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertEquals(17, vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_2")){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(2,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_2") ){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(60,sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_3")){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_3")){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(160,sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_4")){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_4")){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(280,sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_5") ){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(2,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_5")){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(240,sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_6")){
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(1,nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getType().getTypeId().equals("type_6") ){
|
||||
sumOfType1Cap+=v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(200,sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleShouldHvTheCorrectCoord(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
if(v.getStartLocation().getCoordinate().getX() != 40.0){
|
||||
assertFalse(true);
|
||||
}
|
||||
if(v.getStartLocation().getCoordinate().getY() != 40.0){
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service1MustHaveCorrectDemand(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("1",vrp);
|
||||
assertEquals(18,job.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service1MustHaveCorrectCoordinate(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("1",vrp);
|
||||
assertEquals(22.0,coord.getX(),0.01);
|
||||
assertEquals(22.0,coord.getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service15MustHaveCorrectCoordinate(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("15",vrp);
|
||||
assertEquals(62.0,coord.getX(),0.01);
|
||||
assertEquals(24.0,coord.getY(),0.01);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service50MustHaveCorrectCoordinate(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("50",vrp);
|
||||
assertEquals(15.0,coord.getX(),0.01);
|
||||
assertEquals(56.0,coord.getY(),0.01);
|
||||
}
|
||||
|
||||
private Coordinate getCoord(String string, VehicleRoutingProblem vrp) {
|
||||
Job j = getJob(string,vrp);
|
||||
return ((Service)j).getLocation().getCoordinate();
|
||||
}
|
||||
private String getPath(String string) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(string);
|
||||
if (resource == null) throw new IllegalStateException("resource " + string + " does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_1")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_1")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(80, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_2")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(2, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_2")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(60, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_3")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_3")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(160, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_4")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(4, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_4")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(280, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_5")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(2, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_5")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(240, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int nuOfType1Vehicles = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_6")) {
|
||||
nuOfType1Vehicles++;
|
||||
}
|
||||
}
|
||||
assertEquals(1, nuOfType1Vehicles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
int sumOfType1Cap = 0;
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getType().getTypeId().equals("type_6")) {
|
||||
sumOfType1Cap += v.getType().getCapacityDimensions().get(0);
|
||||
}
|
||||
}
|
||||
assertEquals(200, sumOfType1Cap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_vehicleShouldHvTheCorrectCoord() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
if (v.getStartLocation().getCoordinate().getX() != 40.0) {
|
||||
assertFalse(true);
|
||||
}
|
||||
if (v.getStartLocation().getCoordinate().getY() != 40.0) {
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service1MustHaveCorrectDemand() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("1", vrp);
|
||||
assertEquals(18, job.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service1MustHaveCorrectCoordinate() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("1", vrp);
|
||||
assertEquals(22.0, coord.getX(), 0.01);
|
||||
assertEquals(22.0, coord.getY(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service15MustHaveCorrectCoordinate() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("15", vrp);
|
||||
assertEquals(62.0, coord.getX(), 0.01);
|
||||
assertEquals(24.0, coord.getY(), 0.01);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service50MustHaveCorrectCoordinate() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Coordinate coord = getCoord("50", vrp);
|
||||
assertEquals(15.0, coord.getX(), 0.01);
|
||||
assertEquals(56.0, coord.getY(), 0.01);
|
||||
}
|
||||
|
||||
private Coordinate getCoord(String string, VehicleRoutingProblem vrp) {
|
||||
Job j = getJob(string, vrp);
|
||||
return ((Service) j).getLocation().getCoordinate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service4MustHaveCorrectDemand() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("4", vrp);
|
||||
assertEquals(30, job.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service50MustHaveCorrectDemand() {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("50", vrp);
|
||||
assertEquals(22, job.getSize().get(0));
|
||||
}
|
||||
|
||||
private Job getJob(String string, VehicleRoutingProblem vrp) {
|
||||
for (Job j : vrp.getJobs().values()) {
|
||||
if (j.getId().equals(string)) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service4MustHaveCorrectDemand(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("4",vrp);
|
||||
assertEquals(30,job.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingInstance_service50MustHaveCorrectDemand(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
|
||||
.read(getPath("cn_13mix.txt"));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
Job job = getJob("50",vrp);
|
||||
assertEquals(22,job.getSize().get(0));
|
||||
}
|
||||
|
||||
private Job getJob(String string, VehicleRoutingProblem vrp) {
|
||||
for(Job j : vrp.getJobs().values()){
|
||||
if(j.getId().equals(string)){
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +1,60 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class LuiShenReaderTest {
|
||||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new LuiShenReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath(),
|
||||
this.getClass().getClassLoader().getResource("C1_LuiShenVehicles.txt").getPath(), "a");
|
||||
vrp = builder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFleetSize(){
|
||||
assertEquals(FleetSize.INFINITE,vrp.getFleetSize());
|
||||
}
|
||||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
@Test
|
||||
public void testNuOfTypes(){
|
||||
assertEquals(3, vrp.getTypes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfRepresentativeVehicles(){
|
||||
assertEquals(3, vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfJobs(){
|
||||
assertEquals(100,vrp.getJobs().values().size());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void doBefore() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new LuiShenReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath(),
|
||||
this.getClass().getClassLoader().getResource("C1_LuiShenVehicles.txt").getPath(), "a");
|
||||
vrp = builder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFleetSize() {
|
||||
assertEquals(FleetSize.INFINITE, vrp.getFleetSize());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNuOfTypes() {
|
||||
assertEquals(3, vrp.getTypes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfRepresentativeVehicles() {
|
||||
assertEquals(3, vrp.getVehicles().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNuOfJobs() {
|
||||
assertEquals(100, vrp.getJobs().values().size());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
|
@ -28,81 +28,81 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
|
||||
public class SolomonReaderTest {
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_nuOfCustomersIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(100,vrp.getJobs().values().size());
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
URL resource = getClass().getClassLoader().getResource("C101_solomon.txt");
|
||||
if(resource == null) throw new IllegalStateException("file C101_solomon.txt does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_nuOfCustomersIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(100, vrp.getJobs().values().size());
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
URL resource = getClass().getClassLoader().getResource("C101_solomon.txt");
|
||||
if (resource == null) throw new IllegalStateException("file C101_solomon.txt does not exist");
|
||||
return resource.getPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_fleetSizeIsInfinite() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(FleetSize.INFINITE, vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_vehicleCapacitiesAreCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(200, v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for (Vehicle v : vrp.getVehicles()) {
|
||||
assertEquals(40.0, v.getStartLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(50.0, v.getStartLocation().getCoordinate().getY(), 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_demandOfCustomerOneIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(10, vrp.getJobs().get("1").getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_serviceDurationOfCustomerTwoIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(90, ((Service) vrp.getJobs().get("2")).getServiceDuration(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_earliestServiceStartTimeOfCustomerSixtyTwoIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(262.0, ((Service) vrp.getJobs().get("62")).getTimeWindow().getStart(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_latestServiceStartTimeOfCustomerEightySevenIsCorrect() {
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(144.0, ((Service) vrp.getJobs().get("87")).getTimeWindow().getEnd(), 0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_fleetSizeIsInfinite(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(FleetSize.INFINITE,vrp.getFleetSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_vehicleCapacitiesAreCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(200,v.getType().getCapacityDimensions().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
for(Vehicle v : vrp.getVehicles()){
|
||||
assertEquals(40.0,v.getStartLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(50.0,v.getStartLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_demandOfCustomerOneIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(10,vrp.getJobs().get("1").getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_serviceDurationOfCustomerTwoIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(90,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_earliestServiceStartTimeOfCustomerSixtyTwoIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(262.0,((Service)vrp.getJobs().get("62")).getTimeWindow().getStart(),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingSolomonInstance_latestServiceStartTimeOfCustomerEightySevenIsCorrect(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new SolomonReader(builder).read(getPath());
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(144.0,((Service)vrp.getJobs().get("87")).getTimeWindow().getEnd(),0.1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue