diff --git a/jsprit-instances/instances/vrph/README b/jsprit-instances/instances/vrph/README new file mode 100644 index 00000000..c8e85a3e --- /dev/null +++ b/jsprit-instances/instances/vrph/README @@ -0,0 +1 @@ +use VrpGolderReader to read these files \ No newline at end of file diff --git a/jsprit-instances/instances/vrph/orig/c20_3mix.txt b/jsprit-instances/instances/vrph/c20_3mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c20_3mix.txt rename to jsprit-instances/instances/vrph/c20_3mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c20_4mix.txt b/jsprit-instances/instances/vrph/c20_4mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c20_4mix.txt rename to jsprit-instances/instances/vrph/c20_4mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c20_5mix.txt b/jsprit-instances/instances/vrph/c20_5mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c20_5mix.txt rename to jsprit-instances/instances/vrph/c20_5mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c20_6mix.txt b/jsprit-instances/instances/vrph/c20_6mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c20_6mix.txt rename to jsprit-instances/instances/vrph/c20_6mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c50_13mix.txt b/jsprit-instances/instances/vrph/cn_13mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c50_13mix.txt rename to jsprit-instances/instances/vrph/cn_13mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c50_14mix.txt b/jsprit-instances/instances/vrph/cn_14mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c50_14mix.txt rename to jsprit-instances/instances/vrph/cn_14mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c50_15mix.txt b/jsprit-instances/instances/vrph/cn_15mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c50_15mix.txt rename to jsprit-instances/instances/vrph/cn_15mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c50_16mix.txt b/jsprit-instances/instances/vrph/cn_16mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c50_16mix.txt rename to jsprit-instances/instances/vrph/cn_16mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c75_17mix.txt b/jsprit-instances/instances/vrph/cn_17mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c75_17mix.txt rename to jsprit-instances/instances/vrph/cn_17mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c75_18mix.txt b/jsprit-instances/instances/vrph/cn_18mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c75_18mix.txt rename to jsprit-instances/instances/vrph/cn_18mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c100_19mix.txt b/jsprit-instances/instances/vrph/cn_19mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c100_19mix.txt rename to jsprit-instances/instances/vrph/cn_19mix.txt diff --git a/jsprit-instances/instances/vrph/orig/c100_20mix.txt b/jsprit-instances/instances/vrph/cn_20mix.txt similarity index 100% rename from jsprit-instances/instances/vrph/orig/c100_20mix.txt rename to jsprit-instances/instances/vrph/cn_20mix.txt diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java new file mode 100644 index 00000000..ca1978b1 --- /dev/null +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java @@ -0,0 +1,150 @@ +package jsprit.instance.reader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.VehicleRoutingProblem.Builder; +import jsprit.core.problem.VehicleRoutingProblem.FleetSize; +import jsprit.core.problem.io.VrpXMLWriter; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleTypeImpl; +import jsprit.core.util.Coordinate; + +/** + * diff. options 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 + * + * + * @author schroeder + * + */ +public class VrphGoldenReader { + + public enum VrphType { + VRPH_INFINITE, VRPH_FINITE, VFM, VFMVRC + } + + 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 = null; + 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], Integer.parseInt(tokens[0])); + serviceBuilder.setCoord(Coordinate.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], Integer.parseInt(tokens[2])); + int nuOfVehicles = 1; + if(vrphType.equals(VrphType.VFM)){ + typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); + } + else if(vrphType.equals(VrphType.VFMVRC)){ + 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)){ + 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 + 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"); + } + for(int i=0;i