mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add VehicleRoutingTransportCostMatrix to easily consider time and
distance matrices, and add an example that illustrates the matrix
This commit is contained in:
parent
13a9122df1
commit
8950d49e5a
6 changed files with 370 additions and 9 deletions
|
|
@ -30,6 +30,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import util.Solutions;
|
||||
import util.VehicleRoutingTransportCostsMatrix;
|
||||
import util.VehicleRoutingTransportCostsMatrix.Builder;
|
||||
import algorithms.GreedySchrimpfFactory;
|
||||
import analysis.SolutionPrinter;
|
||||
import analysis.SolutionPrinter.Print;
|
||||
|
|
@ -179,13 +181,12 @@ public class RefuseCollectionExample {
|
|||
readDemandQuantities(vrpBuilder);
|
||||
|
||||
/*
|
||||
* read distances
|
||||
* create cost-matrix
|
||||
*/
|
||||
Map<RelationKey,Integer> distances = new HashMap<RelationKey, Integer>();
|
||||
readDistances(distances);
|
||||
|
||||
VehicleRoutingTransportCosts routingCosts = new RoutingCosts(distances);
|
||||
vrpBuilder.setRoutingCost(routingCosts);
|
||||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
|
||||
readDistances(matrixBuilder);
|
||||
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
|
|
@ -199,6 +200,7 @@ public class RefuseCollectionExample {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Quantities")));
|
||||
String line = null;
|
||||
|
|
@ -221,7 +223,8 @@ public class RefuseCollectionExample {
|
|||
reader.close();
|
||||
}
|
||||
|
||||
private static void readDistances(Map<RelationKey, Integer> distances) throws IOException {
|
||||
|
||||
private static void readDistances(Builder matrixBuilder) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Distances")));
|
||||
String line = null;
|
||||
boolean firstLine = true;
|
||||
|
|
@ -231,8 +234,7 @@ public class RefuseCollectionExample {
|
|||
continue;
|
||||
}
|
||||
String[] lineTokens = line.split(",");
|
||||
RelationKey key = RelationKey.newKey(lineTokens[0],lineTokens[1]);
|
||||
distances.put(key, Integer.parseInt(lineTokens[2]));
|
||||
matrixBuilder.addTransportDistance(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2]));
|
||||
}
|
||||
reader.close();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue