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

modify goldenReader to accomodate the various FSM and HVRP problems

This commit is contained in:
oblonski 2014-01-15 07:13:14 -05:00
parent c723415839
commit 66df42ac2e
3 changed files with 158 additions and 38 deletions

View file

@ -18,15 +18,12 @@ import jsprit.core.util.Coordinate;
/**
* Reads modified files from Taillard's website
* http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html
* http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here:
* jsprit-instances/instances/vrph.
*
* <p>diff. options of VrphType yields to different problem types for
* - vrphe with infinite fleet, i.e. different types with different variable costs and infinite number of vehicles of each type
* - vrphe with finite fleet, i.e. different types with different variable costs and finite number of vehicles of each type
* - vfm, different types with different fixed costs
* - vfmvrc different types with different fixed costs and variable costs
* <p>See {@link VrphType} what kind of problems can be generated
*
* <p>cxxx3-cxxx6 do not have variable costs and nuVehicle, thus they can only be used for vfm.
* <p>Note that c20_3-c20_6 do not have variable costs and a limited nuVehicle, thus they can only be used for FSMF.
*
* @author schroeder
*
@ -35,16 +32,21 @@ public class VrphGoldenReader {
/**
*
* VRPHE_INFINITE - different types with different variable costs and infinite number of vehicles of each type
* <p>VRPHE_FINITE - different types with different variable costs and finite number of vehicles of each type
* <p>VFM - different types with different fixed costs
* <p>VFMVRC - different types with different fixed costs and variable costs
*
* <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 {
VRPH_INFINITE, VRPH_FINITE, VFM, VFMVRC
FSMD,
HVRPD,
FSMF,
FSMFD,
HVRPFD
}
private final VehicleRoutingProblem.Builder vrpBuilder;
@ -87,23 +89,23 @@ public class VrphGoldenReader {
else if(trimedLine.startsWith("v")){
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_"+tokens[1], Integer.parseInt(tokens[2]));
int nuOfVehicles = 1;
if(vrphType.equals(VrphType.VFM)){
if(vrphType.equals(VrphType.FSMF)){
typeBuilder.setFixedCost(Double.parseDouble(tokens[3]));
}
else if(vrphType.equals(VrphType.VFMVRC)){
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.VRPH_INFINITE)){
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 { //VrphType.VRPH_FINITE
else if(vrphType.equals(VrphType.HVRPD)){
if(tokens.length > 4){
typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4]));
nuOfVehicles = Integer.parseInt(tokens[5]);
@ -111,6 +113,15 @@ public class VrphGoldenReader {
}
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();
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle_"+tokens[1]+"_"+i)
@ -156,7 +167,7 @@ public class VrphGoldenReader {
public static void main(String[] args) {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
VrphGoldenReader goldenReader = new VrphGoldenReader(vrpBuilder, VrphType.VRPH_INFINITE);
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");

View file

@ -17,7 +17,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfVehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
assertEquals(17,vrp.getVehicles().size());
@ -26,7 +26,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -41,7 +41,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -56,7 +56,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -71,7 +71,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -86,7 +86,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -101,7 +101,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -116,7 +116,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -131,7 +131,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -146,7 +146,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -161,7 +161,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -176,7 +176,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int nuOfType1Vehicles = 0;
@ -191,7 +191,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
int sumOfType1Cap = 0;
@ -206,7 +206,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_vehicleShouldHvTheCorrectCoord(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
for(Vehicle v : vrp.getVehicles()){
@ -223,7 +223,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service1MustHaveCorrectDemand(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Job job = getJob("1",vrp);
@ -233,7 +233,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service1MustHaveCorrectCoordinate(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Coordinate coord = getCoord("1",vrp);
@ -244,7 +244,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service15MustHaveCorrectCoordinate(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Coordinate coord = getCoord("15",vrp);
@ -257,7 +257,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service50MustHaveCorrectCoordinate(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Coordinate coord = getCoord("50",vrp);
@ -273,7 +273,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service4MustHaveCorrectDemand(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Job job = getJob("4",vrp);
@ -283,7 +283,7 @@ public class GoldenReaderTest {
@Test
public void whenReadingInstance_service50MustHaveCorrectDemand(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrphGoldenReader(vrpBuilder, VrphType.VRPH_FINITE)
new VrphGoldenReader(vrpBuilder, VrphType.HVRPD)
.read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath());
VehicleRoutingProblem vrp = vrpBuilder.build();
Job job = getJob("50",vrp);