From 03e95c74a9c9282bdb001f9cc8a7a419aa3f61c0 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Wed, 17 Jul 2013 11:55:20 +0200
Subject: [PATCH 01/47] modify examples according to issue #24, i.e. if
output-folder does not exist, it is created.
---
.../main/java/examples/CompareAlgorithmExample.java | 13 ++++++++++++-
.../main/java/examples/MultipleDepotExample.java | 13 +++++++++++--
.../MultipleDepotExampleWithPenaltyVehicles.java | 11 +++++++++++
.../main/java/examples/RefuseCollectionExample.java | 10 ++++++++++
.../src/main/java/examples/SimpleExample.java | 11 +++++++++++
.../src/main/java/examples/SolomonExample.java | 12 +++++++++++-
6 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/jsprit-examples/src/main/java/examples/CompareAlgorithmExample.java b/jsprit-examples/src/main/java/examples/CompareAlgorithmExample.java
index 65ce758b..cfa4273d 100644
--- a/jsprit-examples/src/main/java/examples/CompareAlgorithmExample.java
+++ b/jsprit-examples/src/main/java/examples/CompareAlgorithmExample.java
@@ -20,6 +20,8 @@
******************************************************************************/
package examples;
+import java.io.File;
+
import readers.SolomonReader;
import algorithms.GreedySchrimpfFactory;
import algorithms.SchrimpfFactory;
@@ -35,7 +37,16 @@ public class CompareAlgorithmExample {
* @param args
*/
public static void main(String[] args) {
-
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
/*
* Build the problem.
*
diff --git a/jsprit-examples/src/main/java/examples/MultipleDepotExample.java b/jsprit-examples/src/main/java/examples/MultipleDepotExample.java
index c05183bb..fc963747 100644
--- a/jsprit-examples/src/main/java/examples/MultipleDepotExample.java
+++ b/jsprit-examples/src/main/java/examples/MultipleDepotExample.java
@@ -1,5 +1,6 @@
package examples;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
@@ -18,7 +19,6 @@ import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
import basics.io.VrpXMLReader;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
-import basics.route.VehicleType;
import basics.route.VehicleTypeImpl;
public class MultipleDepotExample {
@@ -27,7 +27,16 @@ public class MultipleDepotExample {
* @param args
*/
public static void main(String[] args) {
-
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
/*
* Read cordeau-instance p01, BUT only its services without any vehicles
diff --git a/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java b/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java
index dc43639e..51992690 100644
--- a/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java
+++ b/jsprit-examples/src/main/java/examples/MultipleDepotExampleWithPenaltyVehicles.java
@@ -1,5 +1,6 @@
package examples;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
@@ -29,6 +30,16 @@ public class MultipleDepotExampleWithPenaltyVehicles {
* @param args
*/
public static void main(String[] args) {
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
/*
diff --git a/jsprit-examples/src/main/java/examples/RefuseCollectionExample.java b/jsprit-examples/src/main/java/examples/RefuseCollectionExample.java
index 1e9df400..58a3133d 100644
--- a/jsprit-examples/src/main/java/examples/RefuseCollectionExample.java
+++ b/jsprit-examples/src/main/java/examples/RefuseCollectionExample.java
@@ -155,6 +155,16 @@ public class RefuseCollectionExample {
* @throws IOException
*/
public static void main(String[] args) throws IOException {
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
/*
* create vehicle-type and vehicle
diff --git a/jsprit-examples/src/main/java/examples/SimpleExample.java b/jsprit-examples/src/main/java/examples/SimpleExample.java
index e7225411..0bb27c52 100644
--- a/jsprit-examples/src/main/java/examples/SimpleExample.java
+++ b/jsprit-examples/src/main/java/examples/SimpleExample.java
@@ -20,6 +20,7 @@
******************************************************************************/
package examples;
+import java.io.File;
import java.util.Collection;
import util.Coordinate;
@@ -42,6 +43,16 @@ import basics.route.VehicleTypeImpl;
public class SimpleExample {
public static void main(String[] args) {
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
/*
* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2
diff --git a/jsprit-examples/src/main/java/examples/SolomonExample.java b/jsprit-examples/src/main/java/examples/SolomonExample.java
index 62c3897f..baabd7c2 100644
--- a/jsprit-examples/src/main/java/examples/SolomonExample.java
+++ b/jsprit-examples/src/main/java/examples/SolomonExample.java
@@ -20,6 +20,7 @@
******************************************************************************/
package examples;
+import java.io.File;
import java.util.Collection;
import readers.SolomonReader;
@@ -39,7 +40,16 @@ import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
public class SolomonExample {
public static void main(String[] args) {
-
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
/*
* Build the problem.
From 7011ad8c8e9c4b0d6c197347967217d28e32f660 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Wed, 17 Jul 2013 11:56:39 +0200
Subject: [PATCH 02/47] Add VehicleRoutingTransportCostsMatrix to allow
considering pre-compiled time and/or distance matrices. The CostMatrixExample
illustrates its use.
---
.../VehicleRoutingTransportCostsMatrix.java | 56 ++++++++++++++++++-
.../main/java/examples/CostMatrixExample.java | 12 +++-
2 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/jsprit-core/src/main/java/util/VehicleRoutingTransportCostsMatrix.java b/jsprit-core/src/main/java/util/VehicleRoutingTransportCostsMatrix.java
index 2832d66c..4410e18f 100644
--- a/jsprit-core/src/main/java/util/VehicleRoutingTransportCostsMatrix.java
+++ b/jsprit-core/src/main/java/util/VehicleRoutingTransportCostsMatrix.java
@@ -10,7 +10,16 @@ import basics.route.Driver;
import basics.route.Vehicle;
import basics.route.VehicleTypeImpl.VehicleCostParams;
-
+/**
+ * CostMatrix that allows pre-compiled time and distance-matrices to be considered as {@link VehicleRoutingRoutingCosts}
+ * in the {@link VehicleRoutingProblem}.
+ *
Note that you can also use it with distance matrix only (or time matrix). But ones
+ * you set a particular distance, this expects distance-entries for all relations. This counts also
+ * for a particular time. If the method getTransportCosts(...) is then invoked for a relation, where no distance can be found, an
+ * IllegalStateException will be thrown. Thus if you want to only use distances only, do not use addTransportTime(...).
+ * @author schroeder
+ *
+ */
public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTransportCosts {
static class RelationKey {
@@ -74,7 +83,12 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
}
-
+ /**
+ * Builder that builds the matrix.
+ *
+ * @author schroeder
+ *
+ */
public static class Builder {
private static Logger log = Logger.getLogger(Builder.class);
@@ -84,6 +98,16 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
private Map times = new HashMap();
+ private boolean distancesSet = false;
+
+ private boolean timesSet = false;
+
+ /**
+ * Creates a new builder returning the matrix-builder.
+ * If you want to consider symmetric matrices, set isSymmetric to true.
+ * @param isSymmetric
+ * @return
+ */
public static Builder newInstance(boolean isSymmetric){
return new Builder(isSymmetric);
}
@@ -92,8 +116,16 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
this.isSymmetric = isSymmetric;
}
+ /**
+ * Adds a transport-distance for a particular relation.
+ * @param from
+ * @param to
+ * @param distance
+ * @return
+ */
public Builder addTransportDistance(String from, String to, double distance){
RelationKey key = RelationKey.newKey(from, to);
+ if(!distancesSet) distancesSet = true;
if(distances.containsKey(key)){
log.warn("distance from " + from + " to " + to + " already exists. This overrides distance.");
}
@@ -101,8 +133,16 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
return this;
}
+ /**
+ * Adds transport-time for a particular relation.
+ * @param from
+ * @param to
+ * @param time
+ * @return
+ */
public Builder addTransportTime(String from, String to, double time){
RelationKey key = RelationKey.newKey(from, to);
+ if(!timesSet) timesSet = true;
if(times.containsKey(key)){
log.warn("transport-time from " + from + " to " + to + " already exists. This overrides distance.");
}
@@ -110,6 +150,10 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
return this;
}
+ /**
+ * Builds the matrix.
+ * @return
+ */
public VehicleRoutingTransportCostsMatrix build(){
return new VehicleRoutingTransportCostsMatrix(this);
}
@@ -121,10 +165,16 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
private boolean isSymmetric;
+ private boolean timesSet;
+
+ private boolean distancesSet;
+
private VehicleRoutingTransportCostsMatrix(Builder builder){
this.isSymmetric = builder.isSymmetric;
distances.putAll(builder.distances);
times.putAll(builder.times);
+ timesSet = builder.timesSet;
+ distancesSet = builder.distancesSet;
}
@@ -136,6 +186,7 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
private double getTime(String fromId, String toId) {
if(fromId.equals(toId)) return 0.0;
+ if(!timesSet) return 0.0;
RelationKey key = RelationKey.newKey(fromId, toId);
if(!isSymmetric){
if(times.containsKey(key)) return times.get(key);
@@ -153,6 +204,7 @@ public class VehicleRoutingTransportCostsMatrix implements VehicleRoutingTranspo
private double getDistance(String fromId, String toId) {
if(fromId.equals(toId)) return 0.0;
+ if(!distancesSet) return 0.0;
RelationKey key = RelationKey.newKey(fromId, toId);
if(!isSymmetric){
if(distances.containsKey(key)) return distances.get(key);
diff --git a/jsprit-examples/src/main/java/examples/CostMatrixExample.java b/jsprit-examples/src/main/java/examples/CostMatrixExample.java
index 85959b98..0ab81b4e 100644
--- a/jsprit-examples/src/main/java/examples/CostMatrixExample.java
+++ b/jsprit-examples/src/main/java/examples/CostMatrixExample.java
@@ -1,5 +1,6 @@
package examples;
+import java.io.File;
import java.util.Collection;
import util.Solutions;
@@ -32,7 +33,16 @@ public class CostMatrixExample {
* @param args
*/
public static void main(String[] args) {
-
+ /*
+ * some preparation - create output folder
+ */
+ File dir = new File("output");
+ // if the directory does not exist, create it
+ if (!dir.exists()){
+ System.out.println("creating directory ./output");
+ boolean result = dir.mkdir();
+ if(result) System.out.println("./output created");
+ }
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 2).setCostPerDistance(1).setCostPerTime(2).build();
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle").setLocationId("0").setType(type).build();
From 9df98824bb4da6a8c9782638b107fa8bc88f02d5 Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Thu, 18 Jul 2013 15:02:00 +0200
Subject: [PATCH 03/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 81598599..f9d2b60f 100644
--- a/README.md
+++ b/README.md
@@ -31,4 +31,4 @@ Please visit [jsprit-wiki](https://github.com/jsprit/jsprit/wiki) to learn more.
##[About](https://github.com/jsprit/jsprit/wiki/About)
-[](http://githalytics.com/jsprit/jsprit)
+[](http://githalytics.com/jsprit/jsprit)
From 99c2db2d6d3e6ffe57d6677ed98b6b790e058b1c Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Tue, 23 Jul 2013 10:57:11 +0200
Subject: [PATCH 04/47] Update README.md
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index f9d2b60f..4362b983 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,10 @@ It is lightweight and easy-to-use, and based on heuristics currently solving
Modifying the algorithms and visualising the discovered solutions is as easy and handy as
reading classical VRP instances to benchmark your algorithm.
+##In Development
+- VRP with Backhauls
+- Pickup and Delivery
+- Interface to [MATSim](http://matsim.org) which allows network-based problems (e.g. OSM generated) and dynamic visualization
##License
This program is free software; you can redistribute it and/or
From 83f26f10bb581f99f348a4e4d34c721ed9c308f0 Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Tue, 23 Jul 2013 10:58:18 +0200
Subject: [PATCH 05/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 4362b983..f13a366b 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ reading classical VRP instances to benchmark your algorithm.
##In Development
- VRP with Backhauls
- Pickup and Delivery
-- Interface to [MATSim](http://matsim.org) which allows network-based problems (e.g. OSM generated) and dynamic visualization
+- Interface to MATSim which allows network-based problems (e.g. OSM generated) and dynamic visualization
##License
This program is free software; you can redistribute it and/or
From e172f80d4d96b1eb469823180282053c0d505d17 Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Tue, 23 Jul 2013 10:59:07 +0200
Subject: [PATCH 06/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f13a366b..7b48bb97 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ reading classical VRP instances to benchmark your algorithm.
##In Development
- VRP with Backhauls
- Pickup and Delivery
-- Interface to MATSim which allows network-based problems (e.g. OSM generated) and dynamic visualization
+- Interface to MATSim which allows network-based problems (e.g. OSM generated) and dynamic, interactive visualization
##License
This program is free software; you can redistribute it and/or
From dc0ecb307fa4b1575124568a53e17aef11cf2ffa Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Tue, 23 Jul 2013 11:05:33 +0200
Subject: [PATCH 07/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7b48bb97..e0cb9338 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ reading classical VRP instances to benchmark your algorithm.
##In Development
- VRP with Backhauls
- Pickup and Delivery
-- Interface to MATSim which allows network-based problems (e.g. OSM generated) and dynamic, interactive visualization
+- Interface to MATSim which allows network-based problems (e.g. OSM generated), least cost path routing with fast A* and Dijkstra algortihms and dynamic, interactive visualization
##License
This program is free software; you can redistribute it and/or
From 3ccc7563c1a6282ce119cc06ab0c1868ffca3048 Mon Sep 17 00:00:00 2001
From: jsprit <4sschroeder@gmail.com>
Date: Tue, 23 Jul 2013 11:06:37 +0200
Subject: [PATCH 08/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e0cb9338..afbf06f1 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ reading classical VRP instances to benchmark your algorithm.
##In Development
- VRP with Backhauls
- Pickup and Delivery
-- Interface to MATSim which allows network-based problems (e.g. OSM generated), least cost path routing with fast A* and Dijkstra algortihms and dynamic, interactive visualization
+- Interface to MATSim which allows network-based problems (e.g. OSM generated), least cost path routing with fast A* and Dijkstra algorithms and dynamic, interactive visualization
##License
This program is free software; you can redistribute it and/or
From 2849a11cfe7a68542b8cf5ea4198b079b86f81d8 Mon Sep 17 00:00:00 2001
From: jsprit
Date: Thu, 25 Jul 2013 16:04:23 +0200
Subject: [PATCH 09/47] Update README.md
---
README.md | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index afbf06f1..24754e28 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,15 @@ Please visit [jsprit-wiki](https://github.com/jsprit/jsprit/wiki) to learn more.
[Add the latest snapshot to your pom](https://github.com/jsprit/jsprit/wiki/Add-latest-snapshot-to-your-pom).
-##[About](https://github.com/jsprit/jsprit/wiki/About)
+##About
+The jsprit-project is created and maintained by Stefan Schröder. It is motivated by two issues.
+
+First, there is an almost endless list of papers and algorithms to tackle vehicle routing problems, **BUT** there are (as far as I know) only a [very few open source implementations](https://github.com/jsprit/jsprit/wiki/Other-Projects) of one of these thousands alogrithms.
+
+Second, it is motivated by my PhD-project at [KIT](http://www.kit.edu/english/index.php) where I apply vehicle routing algorithms to solve behavioural models of freight agents to assess (freight) transport policy measures.
+
+It is mainly inspired by my research group at [KIT-ECON](http://netze.econ.kit.edu/21.php), and by an awesome open-source project called [MATSim](www.matsim.org) and its developers.
+
+Email: jsprit.vehicle.routing@gmail.com
[](http://githalytics.com/jsprit/jsprit)
From 3d545e904c1366001092b75cf294eb8fee755f07 Mon Sep 17 00:00:00 2001
From: jsprit
Date: Tue, 30 Jul 2013 18:16:56 +0200
Subject: [PATCH 10/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 24754e28..e75f424e 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ Please visit [jsprit-wiki](https://github.com/jsprit/jsprit/wiki) to learn more.
##About
The jsprit-project is created and maintained by Stefan Schröder. It is motivated by two issues.
-First, there is an almost endless list of papers and algorithms to tackle vehicle routing problems, **BUT** there are (as far as I know) only a [very few open source implementations](https://github.com/jsprit/jsprit/wiki/Other-Projects) of one of these thousands alogrithms.
+First, there is an almost endless list of papers and algorithms to tackle vehicle routing problems, **BUT** there are (as far as I know) only a [very few open source implementations](https://github.com/jsprit/jsprit/wiki/Other-Projects) of one of these thousands algorithms.
Second, it is motivated by my PhD-project at [KIT](http://www.kit.edu/english/index.php) where I apply vehicle routing algorithms to solve behavioural models of freight agents to assess (freight) transport policy measures.
From f25c9079dc542a0bad4127900c4e9618e496ba26 Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Mon, 5 Aug 2013 18:38:28 +0200
Subject: [PATCH 11/47] add maxVelocity to vehicleType
---
.../java/basics/route/PenaltyVehicleType.java | 5 +++++
.../main/java/basics/route/VehicleType.java | 2 ++
.../java/basics/route/VehicleTypeImpl.java | 19 ++++++++++++++++---
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/jsprit-core/src/main/java/basics/route/PenaltyVehicleType.java b/jsprit-core/src/main/java/basics/route/PenaltyVehicleType.java
index 9963a00c..29582267 100644
--- a/jsprit-core/src/main/java/basics/route/PenaltyVehicleType.java
+++ b/jsprit-core/src/main/java/basics/route/PenaltyVehicleType.java
@@ -26,6 +26,11 @@ public class PenaltyVehicleType implements VehicleType{
return type.getVehicleCostParams();
}
+ @Override
+ public double getMaxVelocity() {
+ return type.getMaxVelocity();
+ }
+
}
diff --git a/jsprit-core/src/main/java/basics/route/VehicleType.java b/jsprit-core/src/main/java/basics/route/VehicleType.java
index e0870532..9558ba62 100644
--- a/jsprit-core/src/main/java/basics/route/VehicleType.java
+++ b/jsprit-core/src/main/java/basics/route/VehicleType.java
@@ -8,6 +8,8 @@ public interface VehicleType {
public String getTypeId();
public int getCapacity();
+
+ public double getMaxVelocity();
public VehicleCostParams getVehicleCostParams();
diff --git a/jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java b/jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java
index aa3a7820..3e62c292 100644
--- a/jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java
+++ b/jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java
@@ -35,6 +35,7 @@ public class VehicleTypeImpl implements VehicleType {
private String id;
private int capacity;
+ private double maxVelo = Double.MAX_VALUE;
/**
* default cost values for default vehicle type
*/
@@ -48,6 +49,8 @@ public class VehicleTypeImpl implements VehicleType {
this.capacity = capacity;
}
+ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ this.maxVelo = inMeterPerSeconds; return this; }
+
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; }
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; }
@@ -86,9 +89,13 @@ public class VehicleTypeImpl implements VehicleType {
return true;
}
- public final String typeId;
- public final int capacity;
- public final VehicleTypeImpl.VehicleCostParams vehicleCostParams;
+ private final String typeId;
+
+ private final int capacity;
+
+ private final VehicleTypeImpl.VehicleCostParams vehicleCostParams;
+
+ private double maxVelocity;
public static VehicleTypeImpl newInstance(String typeId, int capacity, VehicleTypeImpl.VehicleCostParams para){
return new VehicleTypeImpl(typeId, capacity, para);
@@ -97,6 +104,7 @@ public class VehicleTypeImpl implements VehicleType {
private VehicleTypeImpl(VehicleTypeImpl.Builder builder){
typeId = builder.id;
capacity = builder.capacity;
+ maxVelocity = builder.maxVelo;
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance);
}
@@ -135,4 +143,9 @@ public class VehicleTypeImpl implements VehicleType {
public String toString() {
return "[typeId="+typeId+"][capacity="+capacity+"]" + vehicleCostParams;
}
+
+ @Override
+ public double getMaxVelocity() {
+ return maxVelocity;
+ }
}
\ No newline at end of file
From 07f6af9e56e806d3ad990612cded2445e905df95 Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Mon, 5 Aug 2013 18:38:54 +0200
Subject: [PATCH 12/47] improve GendreauAlgo
---
.../{GendreauPostOpt.java => Gendreau.java} | 8 ++++----
.../algorithms/VehicleRoutingAlgorithms.java | 18 +++++++++---------
.../src/main/java/basics/io/VrpXMLReader.java | 2 +-
.../src/main/resources/algorithm_schema.xsd | 6 ++++--
.../java/algorithms/GendreauPostOptTest.java | 4 ++--
5 files changed, 20 insertions(+), 18 deletions(-)
rename jsprit-core/src/main/java/algorithms/{GendreauPostOpt.java => Gendreau.java} (94%)
diff --git a/jsprit-core/src/main/java/algorithms/GendreauPostOpt.java b/jsprit-core/src/main/java/algorithms/Gendreau.java
similarity index 94%
rename from jsprit-core/src/main/java/algorithms/GendreauPostOpt.java
rename to jsprit-core/src/main/java/algorithms/Gendreau.java
index c7560cee..03d96688 100644
--- a/jsprit-core/src/main/java/algorithms/GendreauPostOpt.java
+++ b/jsprit-core/src/main/java/algorithms/Gendreau.java
@@ -41,9 +41,9 @@ import basics.route.TourActivity.JobActivity;
import util.RandomNumberGeneration;
-final class GendreauPostOpt implements SearchStrategyModule{
+final class Gendreau implements SearchStrategyModule{
- private final static Logger log = Logger.getLogger(GendreauPostOpt.class);
+ private final static Logger log = Logger.getLogger(Gendreau.class);
private final static String NAME = "gendreauPostOpt";
@@ -67,7 +67,7 @@ final class GendreauPostOpt implements SearchStrategyModule{
this.shareOfJobsToRuin = shareOfJobsToRuin;
}
- public GendreauPostOpt(VehicleRoutingProblem vrp, RuinStrategy ruin, AbstractInsertionStrategy insertionStrategy) {
+ public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, AbstractInsertionStrategy insertionStrategy) {
super();
this.routeAlgorithm = insertionStrategy.getRouteAlgorithm();
this.ruin = ruin;
@@ -77,7 +77,7 @@ final class GendreauPostOpt implements SearchStrategyModule{
@Override
public String toString() {
- return "[name=gendreauPostOpt][iterations="+nOfIterations+"][share2ruin="+shareOfJobsToRuin+"]";
+ return "[name=gendreau][iterations="+nOfIterations+"][share2ruin="+shareOfJobsToRuin+"]";
}
public void setRandom(Random random) {
diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
index 71631a38..25daad32 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
@@ -746,11 +746,11 @@ public class VehicleRoutingAlgorithms {
return module;
}
- if(moduleName.equals("gendreauPostOpt")){
+ if(moduleName.equals("gendreau")){
int iterations = moduleConfig.getInt("iterations");
double share = moduleConfig.getDouble("share");
String ruinName = moduleConfig.getString("ruin[@name]");
- if(ruinName == null) throw new IllegalStateException("gendreauPostOpt.ruin[@name] is missing. set it to \"radialRuin\" or \"randomRuin\"");
+ if(ruinName == null) throw new IllegalStateException("gendreau.ruin[@name] is missing. set it to \"radialRuin\" or \"randomRuin\"");
String ruinId = moduleConfig.getString("ruin[@id]");
if(ruinId == null) ruinId = "noId";
ModKey ruinKey = makeKey(ruinName,ruinId);
@@ -762,7 +762,7 @@ public class VehicleRoutingAlgorithms {
}
String insertionName = moduleConfig.getString("insertion[@name]");
- if(insertionName == null) throw new IllegalStateException("gendreauPostOpt.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\"");
+ if(insertionName == null) throw new IllegalStateException("gendreau.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\"");
String insertionId = moduleConfig.getString("insertion[@id]");
if(insertionId == null) insertionId = "noId";
ModKey insertionKey = makeKey(insertionName,insertionId);
@@ -775,12 +775,12 @@ public class VehicleRoutingAlgorithms {
insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, activityStates, prioListeners, executorService, nuOfThreads);
algorithmListeners.addAll(prioListeners);
}
- GendreauPostOpt postOpt = new GendreauPostOpt(vrp, ruin, insertion);
- postOpt.setShareOfJobsToRuin(share);
- postOpt.setNuOfIterations(iterations);
- postOpt.setFleetManager(vehicleFleetManager);
- definedClasses.put(strategyModuleKey, postOpt);
- return postOpt;
+ Gendreau gendreau = new Gendreau(vrp, ruin, insertion);
+ gendreau.setShareOfJobsToRuin(share);
+ gendreau.setNuOfIterations(iterations);
+ gendreau.setFleetManager(vehicleFleetManager);
+ definedClasses.put(strategyModuleKey, gendreau);
+ return gendreau;
}
throw new NullPointerException("no module found with moduleName=" + moduleName +
"\n\tcheck config whether the correct names are used" +
diff --git a/jsprit-core/src/main/java/basics/io/VrpXMLReader.java b/jsprit-core/src/main/java/basics/io/VrpXMLReader.java
index 308e633a..e7c93c63 100644
--- a/jsprit-core/src/main/java/basics/io/VrpXMLReader.java
+++ b/jsprit-core/src/main/java/basics/io/VrpXMLReader.java
@@ -274,7 +274,7 @@ public class VrpXMLReader{
if(distC != null) typeBuilder.setCostPerDistance(distC);
// if(start != null && end != null) typeBuilder.setTimeSchedule(new TimeSchedule(start, end));
VehicleTypeImpl type = typeBuilder.build();
- types.put(type.typeId, type);
+ types.put(type.getTypeId(), type);
vrpBuilder.addVehicleType(type);
}
diff --git a/jsprit-core/src/main/resources/algorithm_schema.xsd b/jsprit-core/src/main/resources/algorithm_schema.xsd
index f3992790..66b1582b 100644
--- a/jsprit-core/src/main/resources/algorithm_schema.xsd
+++ b/jsprit-core/src/main/resources/algorithm_schema.xsd
@@ -166,14 +166,16 @@
-
+
+
+
-
+
diff --git a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
index 7ad448f5..7b23c02c 100644
--- a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
+++ b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
@@ -204,7 +204,7 @@ public class GendreauPostOptTest {
RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
- GendreauPostOpt postOpt = new GendreauPostOpt(vrp, radialRuin, insertionStrategy);
+ Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setFleetManager(fleetManager);
VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol);
@@ -245,7 +245,7 @@ public class GendreauPostOptTest {
RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
- GendreauPostOpt postOpt = new GendreauPostOpt(vrp, radialRuin, insertionStrategy);
+ Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setShareOfJobsToRuin(1.0);
postOpt.setNuOfIterations(1);
postOpt.setFleetManager(fleetManager);
From edcacac758dcc56ec7a47c16de25e9a89dac6c3d Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Tue, 6 Aug 2013 08:56:37 +0200
Subject: [PATCH 13/47] update meta-info in prj-pom
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4be68ef5..7aae13de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,7 @@
Stefan Schroeder
- 4sschroeder@gmail.com
+ jsprit.vehicle.routing@gmail.com
From acc24b1c536849f0172ae0b11fcde6d71cbc7413 Mon Sep 17 00:00:00 2001
From: jsprit
Date: Wed, 7 Aug 2013 12:21:08 +0200
Subject: [PATCH 14/47] Update README.md
---
README.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e75f424e..fb59afdf 100644
--- a/README.md
+++ b/README.md
@@ -12,10 +12,14 @@ It is lightweight and easy-to-use, and based on heuristics currently solving
Modifying the algorithms and visualising the discovered solutions is as easy and handy as
reading classical VRP instances to benchmark your algorithm.
+Additionally, jsprit can be used along with MATSim
+to solve the above problem-types in real networks (wich might be OSM generated). A variety of least cost path algorithms such as Dijkstra and A*
+can be used, and a dynamic and interactive visualiser enhances the analysis part significantly.
+
##In Development
- VRP with Backhauls
- Pickup and Delivery
-- Interface to MATSim which allows network-based problems (e.g. OSM generated), least cost path routing with fast A* and Dijkstra algorithms and dynamic, interactive visualization
+
##License
This program is free software; you can redistribute it and/or
From 4e35a647e93896ebfebb06b1fb40ece99033256d Mon Sep 17 00:00:00 2001
From: jsprit
Date: Wed, 7 Aug 2013 12:27:57 +0200
Subject: [PATCH 15/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index fb59afdf..19b9e06a 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Modifying the algorithms and visualising the discovered solutions is as easy and
reading classical VRP instances to benchmark your algorithm.
Additionally, jsprit can be used along with MATSim
-to solve the above problem-types in real networks (wich might be OSM generated). A variety of least cost path algorithms such as Dijkstra and A*
+to solve the above problem-types in real networks (OSM networks are supported as well). A variety of least cost path algorithms such as Dijkstra and A*
can be used, and a dynamic and interactive visualiser enhances the analysis part significantly.
##In Development
From 54dbdca81dfbc545554124140a9f0582b5e37f9e Mon Sep 17 00:00:00 2001
From: jsprit
Date: Wed, 7 Aug 2013 14:27:55 +0200
Subject: [PATCH 16/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 19b9e06a..d826a36b 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ reading classical VRP instances to benchmark your algorithm.
Additionally, jsprit can be used along with MATSim
to solve the above problem-types in real networks (OSM networks are supported as well). A variety of least cost path algorithms such as Dijkstra and A*
-can be used, and a dynamic and interactive visualiser enhances the analysis part significantly.
+can be used, and a dynamic and interactive visualiser greatly enhances the analysis.
##In Development
- VRP with Backhauls
From 9df4284040c3fe2a18c134c7451cc59e8157d9b8 Mon Sep 17 00:00:00 2001
From: jsprit
Date: Thu, 8 Aug 2013 08:01:05 +0200
Subject: [PATCH 17/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d826a36b..865a27a8 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Modifying the algorithms and visualising the discovered solutions is as easy and
reading classical VRP instances to benchmark your algorithm.
Additionally, jsprit can be used along with MATSim
-to solve the above problem-types in real networks (OSM networks are supported as well). A variety of least cost path algorithms such as Dijkstra and A*
+to solve the above problem-types in real networks (without preprocessing transport times and costs). A variety of least cost path algorithms such as Dijkstra and A*
can be used, and a dynamic and interactive visualiser greatly enhances the analysis.
##In Development
From d78297a2144116a7adfbf9350c7637dec706f2df Mon Sep 17 00:00:00 2001
From: jsprit
Date: Thu, 8 Aug 2013 08:03:43 +0200
Subject: [PATCH 18/47] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 865a27a8..e5999392 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ Modifying the algorithms and visualising the discovered solutions is as easy and
reading classical VRP instances to benchmark your algorithm.
Additionally, jsprit can be used along with MATSim
-to solve the above problem-types in real networks (without preprocessing transport times and costs). A variety of least cost path algorithms such as Dijkstra and A*
+to solve the above problem-types in real networks (i.e. without preprocessing transport times and costs). A variety of least cost path algorithms such as Dijkstra and A*
can be used, and a dynamic and interactive visualiser greatly enhances the analysis.
##In Development
From e2ab285d0188cf3cc42595135bc3459207e72435 Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Fri, 9 Aug 2013 15:52:26 +0200
Subject: [PATCH 19/47] bugfix: copyConstructor of endAct did not copy
end.arrTime() - fixed
---
jsprit-core/src/main/java/basics/route/End.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/jsprit-core/src/main/java/basics/route/End.java b/jsprit-core/src/main/java/basics/route/End.java
index b39aead4..39e585a8 100644
--- a/jsprit-core/src/main/java/basics/route/End.java
+++ b/jsprit-core/src/main/java/basics/route/End.java
@@ -67,6 +67,8 @@ public final class End implements TourActivity {
this.locationId = end.getLocationId();
theoretical_earliestOperationStartTime = end.getTheoreticalEarliestOperationStartTime();
theoretical_latestOperationStartTime = end.getTheoreticalLatestOperationStartTime();
+ arrTime = end.getArrTime();
+ endTime = end.getEndTime();
}
public double getTheoreticalEarliestOperationStartTime() {
From d9391c6d4582b408346054b8f959e807bfd4b186 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Mon, 12 Aug 2013 00:24:42 +0200
Subject: [PATCH 20/47] refactor RuinRadial and RuinRandom
---
.../src/main/java/algorithms/RuinRadial.java | 8 +---
.../src/main/java/algorithms/RuinRandom.java | 43 +++++++++++--------
.../java/basics/route/TourActivities.java | 8 +---
3 files changed, 28 insertions(+), 31 deletions(-)
diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java
index 82cb3ed6..d0fa8f71 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRadial.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java
@@ -29,8 +29,6 @@ import util.RandomNumberGeneration;
import util.StopWatch;
import basics.Job;
import basics.VehicleRoutingProblem;
-import basics.VehicleRoutingProblemSolution;
-import basics.algo.SearchStrategyModule;
import basics.route.VehicleRoute;
@@ -49,7 +47,7 @@ final class RuinRadial implements RuinStrategy {
* @return
*/
static RuinRadial newInstance(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
- return new RuinRadial(vrp, fraction, jobDistance, jobRemover, routeUpdater);
+ return new RuinRadial(vrp, fraction, jobDistance);
}
@@ -92,12 +90,10 @@ final class RuinRadial implements RuinStrategy {
this.random = random;
}
- public RuinRadial(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater) {
+ public RuinRadial(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance) {
super();
this.vrp = vrp;
this.jobDistance = jobDistance;
- this.jobRemover = jobRemover;
- this.routeUpdater = routeUpdater;
this.fractionOfAllNodes2beRuined = fraction;
calculateDistancesFromJob2Job();
logger.info("intialise " + this);
diff --git a/jsprit-core/src/main/java/algorithms/RuinRandom.java b/jsprit-core/src/main/java/algorithms/RuinRandom.java
index 9180f13a..6fcba2f0 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRandom.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRandom.java
@@ -37,7 +37,7 @@ import basics.route.VehicleRoute;
final class RuinRandom implements RuinStrategy {
public static RuinRandom newInstance(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
- return new RuinRandom(vrp, fraction, jobRemover, routeUpdater);
+ return new RuinRandom(vrp, fraction);
}
private Logger logger = Logger.getLogger(RuinRandom.class);
@@ -48,10 +48,6 @@ final class RuinRandom implements RuinStrategy {
private Random random = RandomNumberGeneration.getRandom();
- private JobRemover jobRemover;
-
- private VehicleRouteUpdater vehicleRouteUpdater;
-
public void setRandom(Random random) {
this.random = random;
}
@@ -61,14 +57,10 @@ final class RuinRandom implements RuinStrategy {
*
* @param vrp
* @param fraction which is the fraction of total c
- * @param jobRemover
- * @param vehicleRouteUpdater
*/
- public RuinRandom(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater vehicleRouteUpdater) {
+ public RuinRandom(VehicleRoutingProblem vrp, double fraction) {
super();
this.vrp = vrp;
- this.jobRemover = jobRemover;
- this.vehicleRouteUpdater = vehicleRouteUpdater;
this.fractionOfAllNodes2beRuined = fraction;
logger.info("initialise " + this);
logger.info("done");
@@ -81,9 +73,11 @@ final class RuinRandom implements RuinStrategy {
*/
@Override
public Collection ruin(Collection vehicleRoutes) {
+
List unassignedJobs = new ArrayList();
int nOfJobs2BeRemoved = selectNuOfJobs2BeRemoved();
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
+
return unassignedJobs;
}
@@ -92,19 +86,22 @@ final class RuinRandom implements RuinStrategy {
*/
@Override
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) {
+ ruinStarts(vehicleRoutes);
List unassignedJobs = new ArrayList();
if(targetJob != null){
boolean removed = false;
for (VehicleRoute route : vehicleRoutes) {
- removed = jobRemover.removeJobWithoutTourUpdate(targetJob, route);
+ removed = route.getTourActivities().removeJob(targetJob);
if (removed) {
nOfJobs2BeRemoved--;
unassignedJobs.add(targetJob);
+ jobRemoved(targetJob,route);
break;
}
}
}
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
+ ruinEnds(vehicleRoutes);
return unassignedJobs;
}
@@ -120,19 +117,29 @@ final class RuinRandom implements RuinStrategy {
unassignedJobs.add(job);
availableJobs.remove(job);
for (VehicleRoute route : vehicleRoutes) {
- boolean removed = jobRemover.removeJobWithoutTourUpdate(job, route);
- if (removed) break;
+ boolean removed = route.getTourActivities().removeJob(job);
+ if (removed) {
+ jobRemoved(job,route);
+ break;
+ }
}
}
- updateRoutes(vehicleRoutes);
}
- private void updateRoutes(Collection vehicleRoutes) {
- for(VehicleRoute route : vehicleRoutes){
- vehicleRouteUpdater.updateRoute(route);
- }
+ private void ruinEnds(Collection vehicleRoutes) {
+ // TODO Auto-generated method stub
+
}
+ private void ruinStarts(Collection vehicleRoutes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void jobRemoved(Job job, VehicleRoute route) {
+ // TODO Auto-generated method stub
+
+ }
@Override
public String toString() {
diff --git a/jsprit-core/src/main/java/basics/route/TourActivities.java b/jsprit-core/src/main/java/basics/route/TourActivities.java
index eed81154..2524b13b 100644
--- a/jsprit-core/src/main/java/basics/route/TourActivities.java
+++ b/jsprit-core/src/main/java/basics/route/TourActivities.java
@@ -76,15 +76,9 @@ public class TourActivities {
}
private final ArrayList tourActivities = new ArrayList();
-// private final LinkedList tourActivities = new LinkedList();
-// private final TreeList tourActivities = new TreeList();
private final Set jobs = new HashSet();
- private int load = 0;
-
- private double cost = 0.0;
-
private ReverseActivityIterator backward;
private TourActivities(TourActivities tour2copy) {
@@ -125,7 +119,7 @@ public class TourActivities {
}
/**
- * Removes job AND belonging activity from tour.
+ * Removes job AND belonging activity from tour and returns true if job has been removed, otherwise false.
*
* @param job
* @return
From f78886767bbe24f53b7876ace04a65afb4b26046 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Mon, 12 Aug 2013 22:27:07 +0200
Subject: [PATCH 21/47] internal ruinStrat improvement
---
.../java/algorithms/AbstractRuinStrategy.java | 22 +++++++++++++++
.../src/main/java/algorithms/RuinRadial.java | 27 +++++++++++++------
.../src/main/java/algorithms/RuinRandom.java | 2 --
3 files changed, 41 insertions(+), 10 deletions(-)
create mode 100644 jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
diff --git a/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java b/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
new file mode 100644
index 00000000..f5264601
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
@@ -0,0 +1,22 @@
+package algorithms;
+
+import java.util.Collection;
+
+import basics.Job;
+import basics.route.VehicleRoute;
+
+abstract class AbstractRuinStrategy implements RuinStrategy{
+
+ public void ruinStarts(Collection routes){
+
+ }
+
+ public void ruinEnds(Collection routes){
+
+ }
+
+ public void jobRemoved(Job job, VehicleRoute fromRoute){
+
+ }
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java
index d0fa8f71..22296066 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRadial.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java
@@ -82,10 +82,6 @@ final class RuinRadial implements RuinStrategy {
private JobDistance jobDistance;
- private JobRemover jobRemover;
-
- private VehicleRouteUpdater routeUpdater;
-
public void setRandom(Random random) {
this.random = random;
}
@@ -154,6 +150,7 @@ final class RuinRadial implements RuinStrategy {
}
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){
+ ruinStarts(vehicleRoutes);
List unassignedJobs = new ArrayList();
TreeSet tree = distanceNodeTree.get(targetJob.getId());
Iterator descendingIterator = tree.descendingIterator();
@@ -165,18 +162,32 @@ final class RuinRadial implements RuinStrategy {
counter++;
boolean removed = false;
for (VehicleRoute route : vehicleRoutes) {
- removed = jobRemover.removeJobWithoutTourUpdate(job, route);
+ removed = route.getTourActivities().removeJob(job);;
if (removed) {
+ jobRemoved(job,route);
break;
}
}
}
- for(VehicleRoute route : vehicleRoutes){
- routeUpdater.updateRoute(route);
- }
+ ruinEnds(vehicleRoutes);
return unassignedJobs;
}
+ private void ruinEnds(Collection vehicleRoutes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void jobRemoved(Job job, VehicleRoute route) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void ruinStarts(Collection vehicleRoutes) {
+ // TODO Auto-generated method stub
+
+ }
+
private Job pickRandomJob() {
int totNuOfJobs = vrp.getJobs().values().size();
int randomIndex = random.nextInt(totNuOfJobs);
diff --git a/jsprit-core/src/main/java/algorithms/RuinRandom.java b/jsprit-core/src/main/java/algorithms/RuinRandom.java
index 6fcba2f0..31c78483 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRandom.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRandom.java
@@ -73,11 +73,9 @@ final class RuinRandom implements RuinStrategy {
*/
@Override
public Collection ruin(Collection vehicleRoutes) {
-
List unassignedJobs = new ArrayList();
int nOfJobs2BeRemoved = selectNuOfJobs2BeRemoved();
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
-
return unassignedJobs;
}
From 59b25d3d8e61ce635dcb4070fb8d571c631b4fe8 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 13 Aug 2013 12:00:31 +0200
Subject: [PATCH 22/47] improve ruinApi
---
.../java/algorithms/AbstractRuinStrategy.java | 22 ---------
.../main/java/algorithms/RuinListeners.java | 33 +++++++++++++
.../src/main/java/algorithms/RuinRadial.java | 46 +++++--------------
.../src/main/java/algorithms/RuinRandom.java | 34 +++++---------
.../main/java/algorithms/RuinStrategy.java | 8 ++++
.../algorithms/VehicleRoutingAlgorithms.java | 6 +--
.../java/algorithms/GendreauPostOptTest.java | 4 +-
.../java/algorithms/TestAlgorithmReader.java | 6 +++
8 files changed, 76 insertions(+), 83 deletions(-)
delete mode 100644 jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
create mode 100644 jsprit-core/src/main/java/algorithms/RuinListeners.java
diff --git a/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java b/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
deleted file mode 100644
index f5264601..00000000
--- a/jsprit-core/src/main/java/algorithms/AbstractRuinStrategy.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package algorithms;
-
-import java.util.Collection;
-
-import basics.Job;
-import basics.route.VehicleRoute;
-
-abstract class AbstractRuinStrategy implements RuinStrategy{
-
- public void ruinStarts(Collection routes){
-
- }
-
- public void ruinEnds(Collection routes){
-
- }
-
- public void jobRemoved(Job job, VehicleRoute fromRoute){
-
- }
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/RuinListeners.java b/jsprit-core/src/main/java/algorithms/RuinListeners.java
new file mode 100644
index 00000000..f48df19d
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/RuinListeners.java
@@ -0,0 +1,33 @@
+package algorithms;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import algorithms.RuinStrategy.RuinListener;
+import basics.Job;
+import basics.route.VehicleRoute;
+
+class RuinListeners {
+
+ private Collection ruinListeners = new ArrayList();
+
+ void ruinStarts(Collection routes){
+ for(RuinListener l : ruinListeners) l.ruinStarts(routes);
+ }
+
+ void ruinEnds(Collection routes, Collection unassignedJobs){
+ for(RuinListener l : ruinListeners) l.ruinEnds(routes, unassignedJobs);
+ }
+
+ void removed(Job job, VehicleRoute fromRoute){
+ for(RuinListener l : ruinListeners) l.removed(job, fromRoute);
+ }
+
+ void addListener(RuinListener ruinListener){
+ ruinListeners.add(ruinListener);
+ }
+
+ void removeListener(RuinListener ruinListener){
+ ruinListeners.remove(ruinListener);
+ }
+}
diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java
index 22296066..3e10b10e 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRadial.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java
@@ -34,22 +34,6 @@ import basics.route.VehicleRoute;
final class RuinRadial implements RuinStrategy {
-
- private final static String NAME = "radialRuin";
-
- /**
- * returns a new creation of instance of ruinRadial
- * @param vrp
- * @param fraction TODO
- * @param jobDistance
- * @param jobRemover TODO
- * @param routeUpdater TODO
- * @return
- */
- static RuinRadial newInstance(VehicleRoutingProblem vrp, double fraction, JobDistance jobDistance, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
- return new RuinRadial(vrp, fraction, jobDistance);
- }
-
static class ReferencedJob {
private Job job;
@@ -82,6 +66,8 @@ final class RuinRadial implements RuinStrategy {
private JobDistance jobDistance;
+ private RuinListeners ruinListeners;
+
public void setRandom(Random random) {
this.random = random;
}
@@ -91,6 +77,7 @@ final class RuinRadial implements RuinStrategy {
this.vrp = vrp;
this.jobDistance = jobDistance;
this.fractionOfAllNodes2beRuined = fraction;
+ ruinListeners = new RuinListeners();
calculateDistancesFromJob2Job();
logger.info("intialise " + this);
}
@@ -150,7 +137,7 @@ final class RuinRadial implements RuinStrategy {
}
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){
- ruinStarts(vehicleRoutes);
+ ruinListeners.ruinStarts(vehicleRoutes);
List unassignedJobs = new ArrayList();
TreeSet tree = distanceNodeTree.get(targetJob.getId());
Iterator descendingIterator = tree.descendingIterator();
@@ -164,30 +151,15 @@ final class RuinRadial implements RuinStrategy {
for (VehicleRoute route : vehicleRoutes) {
removed = route.getTourActivities().removeJob(job);;
if (removed) {
- jobRemoved(job,route);
+ ruinListeners.removed(job,route);
break;
}
}
}
- ruinEnds(vehicleRoutes);
+ ruinListeners.ruinEnds(vehicleRoutes, unassignedJobs);
return unassignedJobs;
}
- private void ruinEnds(Collection vehicleRoutes) {
- // TODO Auto-generated method stub
-
- }
-
- private void jobRemoved(Job job, VehicleRoute route) {
- // TODO Auto-generated method stub
-
- }
-
- private void ruinStarts(Collection vehicleRoutes) {
- // TODO Auto-generated method stub
-
- }
-
private Job pickRandomJob() {
int totNuOfJobs = vrp.getJobs().values().size();
int randomIndex = random.nextInt(totNuOfJobs);
@@ -200,6 +172,12 @@ final class RuinRadial implements RuinStrategy {
* fractionOfAllNodes2beRuined);
}
+ @Override
+ public void addListener(RuinListener ruinListener) {
+ // TODO Auto-generated method stub
+
+ }
+
// @Override
// public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
// ruin(vrpSolution.getRoutes());
diff --git a/jsprit-core/src/main/java/algorithms/RuinRandom.java b/jsprit-core/src/main/java/algorithms/RuinRandom.java
index 31c78483..57081db9 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRandom.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRandom.java
@@ -35,10 +35,6 @@ import basics.route.VehicleRoute;
*/
final class RuinRandom implements RuinStrategy {
-
- public static RuinRandom newInstance(VehicleRoutingProblem vrp, double fraction, JobRemover jobRemover, VehicleRouteUpdater routeUpdater){
- return new RuinRandom(vrp, fraction);
- }
private Logger logger = Logger.getLogger(RuinRandom.class);
@@ -47,6 +43,8 @@ final class RuinRandom implements RuinStrategy {
private double fractionOfAllNodes2beRuined;
private Random random = RandomNumberGeneration.getRandom();
+
+ private RuinListeners ruinListeners;
public void setRandom(Random random) {
this.random = random;
@@ -62,6 +60,7 @@ final class RuinRandom implements RuinStrategy {
super();
this.vrp = vrp;
this.fractionOfAllNodes2beRuined = fraction;
+ ruinListeners = new RuinListeners();
logger.info("initialise " + this);
logger.info("done");
}
@@ -84,7 +83,7 @@ final class RuinRandom implements RuinStrategy {
*/
@Override
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) {
- ruinStarts(vehicleRoutes);
+ ruinListeners.ruinStarts(vehicleRoutes);
List unassignedJobs = new ArrayList();
if(targetJob != null){
boolean removed = false;
@@ -93,13 +92,13 @@ final class RuinRandom implements RuinStrategy {
if (removed) {
nOfJobs2BeRemoved--;
unassignedJobs.add(targetJob);
- jobRemoved(targetJob,route);
+ ruinListeners.removed(targetJob,route);
break;
}
}
}
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
- ruinEnds(vehicleRoutes);
+ ruinListeners.ruinEnds(vehicleRoutes, unassignedJobs);
return unassignedJobs;
}
@@ -117,28 +116,14 @@ final class RuinRandom implements RuinStrategy {
for (VehicleRoute route : vehicleRoutes) {
boolean removed = route.getTourActivities().removeJob(job);
if (removed) {
- jobRemoved(job,route);
+ ruinListeners.removed(job,route);
break;
}
}
}
}
- private void ruinEnds(Collection vehicleRoutes) {
- // TODO Auto-generated method stub
- }
-
- private void ruinStarts(Collection vehicleRoutes) {
- // TODO Auto-generated method stub
-
- }
-
- private void jobRemoved(Job job, VehicleRoute route) {
- // TODO Auto-generated method stub
-
- }
-
@Override
public String toString() {
return "[name=randomRuin][fraction="+fractionOfAllNodes2beRuined+"]";
@@ -153,4 +138,9 @@ final class RuinRandom implements RuinStrategy {
return (int) Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined);
}
+ @Override
+ public void addListener(RuinListener ruinListener) {
+ ruinListeners.addListener(ruinListener);
+ }
+
}
diff --git a/jsprit-core/src/main/java/algorithms/RuinStrategy.java b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
index 67cf868a..8f425c6a 100644
--- a/jsprit-core/src/main/java/algorithms/RuinStrategy.java
+++ b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
@@ -31,6 +31,12 @@ interface RuinStrategy {
public static interface RuinListener {
+ public void ruinStarts(Collection routes);
+
+ public void ruinEnds(Collection routes, Collection unassignedJobs);
+
+ public void removed(Job job, VehicleRoute fromRoute);
+
}
/**
@@ -43,5 +49,7 @@ interface RuinStrategy {
public Collection ruin(Collection vehicleRoutes);
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved);
+
+ public void addListener(RuinListener ruinListener);
}
diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
index 25daad32..d8b49a8d 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
@@ -757,7 +757,7 @@ public class VehicleRoutingAlgorithms {
RuinStrategyKey stratKey = new RuinStrategyKey(ruinKey);
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
- ruin = RuinRadial.newInstance(vrp, 0.3, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts()));
+ ruin = new RuinRadial(vrp, 0.3, new JobDistanceAvgCosts(vrp.getTransportCosts()));
definedClasses.put(stratKey, ruin);
}
@@ -795,7 +795,7 @@ public class VehicleRoutingAlgorithms {
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
- ruin = RuinRadial.newInstance(vrp, shareToRuin, jobDistance, new JobRemoverImpl(), new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts()));
+ ruin = new RuinRadial(vrp, shareToRuin, jobDistance);
definedClasses.put(stratKey, ruin);
}
return ruin;
@@ -807,7 +807,7 @@ public class VehicleRoutingAlgorithms {
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
- ruin = RuinRandom.newInstance(vrp, shareToRuin, new JobRemoverImpl(), new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts()));
+ ruin = new RuinRandom(vrp, shareToRuin);
definedClasses.put(stratKey, ruin);
}
return ruin;
diff --git a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
index 7b23c02c..2ab58a40 100644
--- a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
+++ b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
@@ -202,7 +202,7 @@ public class GendreauPostOptTest {
assertEquals(110.0, sol.getCost(), 0.5);
- RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
+ RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setFleetManager(fleetManager);
@@ -243,7 +243,7 @@ public class GendreauPostOptTest {
assertEquals(110.0, sol.getCost(), 0.5);
- RuinRadial radialRuin = RuinRadial.newInstance(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()), new JobRemoverImpl(), updater);
+ RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setShareOfJobsToRuin(1.0);
diff --git a/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java b/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java
index db93a116..3e6416a9 100644
--- a/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java
+++ b/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java
@@ -169,6 +169,12 @@ public class TestAlgorithmReader {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public void addListener(RuinListener ruinListener) {
+ // TODO Auto-generated method stub
+
+ }
};
From 9ef3a775e9aa4503ee1e87cc20ab27293af3afa7 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 13 Aug 2013 14:34:10 +0200
Subject: [PATCH 23/47] internal ruinImprovement
---
.../algorithms/VehicleRoutingAlgorithms.java | 21 +++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
index d8b49a8d..1d57ad24 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
@@ -36,6 +36,7 @@ import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;
import util.RouteUtils;
+import algorithms.RuinStrategy.RuinListener;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AbstractInsertionKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AbstractKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
@@ -59,16 +60,17 @@ import basics.algo.InsertionListener;
import basics.algo.IterationWithoutImprovementBreaker;
import basics.algo.PrematureAlgorithmBreaker;
import basics.algo.SearchStrategy;
+import basics.algo.SearchStrategy.DiscoveredSolution;
import basics.algo.SearchStrategyManager;
import basics.algo.SearchStrategyModule;
import basics.algo.SearchStrategyModuleListener;
import basics.algo.TimeBreaker;
import basics.algo.VariationCoefficientBreaker;
-import basics.algo.SearchStrategy.DiscoveredSolution;
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
import basics.io.AlgorithmConfig;
import basics.io.AlgorithmConfigXmlReader;
+import basics.route.VehicleRoute;
@@ -801,13 +803,24 @@ public class VehicleRoutingAlgorithms {
return ruin;
}
- private static RuinStrategy getRandomRuin(VehicleRoutingProblem vrp,
- RouteStates activityStates, TypedMap definedClasses,
- ModKey modKey, double shareToRuin) {
+ private static RuinStrategy getRandomRuin(VehicleRoutingProblem vrp, RouteStates activityStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) {
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
ruin = new RuinRandom(vrp, shareToRuin);
+ ruin.addListener(new RuinListener() {
+
+ @Override
+ public void ruinStarts(Collection routes) {}
+
+ @Override
+ public void ruinEnds(Collection routes, Collection unassignedJobs) {
+// new
+ }
+
+ @Override
+ public void removed(Job job, VehicleRoute fromRoute) {}
+ });
definedClasses.put(stratKey, ruin);
}
return ruin;
From 4f3c76ff28c94c7993c8c6c21f33229aa9ea9cd8 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 13 Aug 2013 20:29:51 +0200
Subject: [PATCH 24/47] improve ruinApi
---
.../src/main/java/algorithms/RuinRadial.java | 13 +---
.../src/main/java/algorithms/RuinRandom.java | 4 +-
.../algorithms/VehicleRoutingAlgorithms.java | 66 +++++++++++++++----
3 files changed, 56 insertions(+), 27 deletions(-)
diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java
index 3e10b10e..f40cf375 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRadial.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java
@@ -174,19 +174,8 @@ final class RuinRadial implements RuinStrategy {
@Override
public void addListener(RuinListener ruinListener) {
- // TODO Auto-generated method stub
-
+ ruinListeners.addListener(ruinListener);
}
-// @Override
-// public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
-// ruin(vrpSolution.getRoutes());
-// return vrpSolution;
-// }
-//
-// @Override
-// public String getName() {
-// return NAME;
-// }
}
diff --git a/jsprit-core/src/main/java/algorithms/RuinRandom.java b/jsprit-core/src/main/java/algorithms/RuinRandom.java
index 57081db9..8079c7fa 100644
--- a/jsprit-core/src/main/java/algorithms/RuinRandom.java
+++ b/jsprit-core/src/main/java/algorithms/RuinRandom.java
@@ -72,9 +72,11 @@ final class RuinRandom implements RuinStrategy {
*/
@Override
public Collection ruin(Collection vehicleRoutes) {
+ ruinListeners.ruinStarts(vehicleRoutes);
List unassignedJobs = new ArrayList();
int nOfJobs2BeRemoved = selectNuOfJobs2BeRemoved();
ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs);
+ ruinListeners.ruinEnds(vehicleRoutes, unassignedJobs);
return unassignedJobs;
}
@@ -107,7 +109,7 @@ final class RuinRandom implements RuinStrategy {
logger.info("fraction set " + this);
}
- private void ruin(Collection vehicleRoutes,int nOfJobs2BeRemoved, List unassignedJobs) {
+ private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) {
LinkedList availableJobs = new LinkedList(vrp.getJobs().values());
for (int i = 0; i < nOfJobs2BeRemoved; i++) {
Job job = pickRandomJob(availableJobs);
diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
index 1d57ad24..51e73e7b 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
@@ -655,8 +655,8 @@ public class VehicleRoutingAlgorithms {
}
}
- private static SearchStrategyModule buildModule(HierarchicalConfiguration moduleConfig, VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager,
- RouteStates activityStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads) {
+ private static SearchStrategyModule buildModule(HierarchicalConfiguration moduleConfig, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager,
+ final RouteStates activityStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads) {
String moduleName = moduleConfig.getString("[@name]");
if(moduleName == null) throw new IllegalStateException("module(-name) is missing.");
String moduleId = moduleConfig.getString("[@id]");
@@ -760,6 +760,23 @@ public class VehicleRoutingAlgorithms {
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
ruin = new RuinRadial(vrp, 0.3, new JobDistanceAvgCosts(vrp.getTransportCosts()));
+ ruin.addListener(new RuinListener() {
+
+ TourStateUpdater updater = new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts());
+
+ @Override
+ public void ruinStarts(Collection routes) {}
+
+ @Override
+ public void ruinEnds(Collection routes, Collection unassignedJobs) {
+ for(VehicleRoute route : routes){
+ updater.updateRoute(route);
+ }
+ }
+
+ @Override
+ public void removed(Job job, VehicleRoute fromRoute) {}
+ });
definedClasses.put(stratKey, ruin);
}
@@ -793,29 +810,50 @@ public class VehicleRoutingAlgorithms {
"\n\tgendreauPostOpt");
}
- private static RuinStrategy getRadialRuin(VehicleRoutingProblem vrp, RouteStates activityStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) {
+ private static RuinStrategy getRadialRuin(final VehicleRoutingProblem vrp, final RouteStates activityStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) {
RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
RuinStrategy ruin = definedClasses.get(stratKey);
if(ruin == null){
ruin = new RuinRadial(vrp, shareToRuin, jobDistance);
- definedClasses.put(stratKey, ruin);
- }
- return ruin;
- }
-
- private static RuinStrategy getRandomRuin(VehicleRoutingProblem vrp, RouteStates activityStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) {
- RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
- RuinStrategy ruin = definedClasses.get(stratKey);
- if(ruin == null){
- ruin = new RuinRandom(vrp, shareToRuin);
ruin.addListener(new RuinListener() {
+ TourStateUpdater updater = new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts());
+
@Override
public void ruinStarts(Collection routes) {}
@Override
public void ruinEnds(Collection routes, Collection unassignedJobs) {
-// new
+ for(VehicleRoute route : routes){
+ updater.updateRoute(route);
+ }
+ }
+
+ @Override
+ public void removed(Job job, VehicleRoute fromRoute) {}
+ });
+ definedClasses.put(stratKey, ruin);
+ }
+ return ruin;
+ }
+
+ private static RuinStrategy getRandomRuin(final VehicleRoutingProblem vrp, final RouteStates activityStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) {
+ RuinStrategyKey stratKey = new RuinStrategyKey(modKey);
+ RuinStrategy ruin = definedClasses.get(stratKey);
+ if(ruin == null){
+ ruin = new RuinRandom(vrp, shareToRuin);
+ ruin.addListener(new RuinListener() {
+
+ TourStateUpdater updater = new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts());
+
+ @Override
+ public void ruinStarts(Collection routes) {}
+
+ @Override
+ public void ruinEnds(Collection routes, Collection unassignedJobs) {
+ for(VehicleRoute route : routes){
+ updater.updateRoute(route);
+ }
}
@Override
From d46fed424d5252b9ce621fabb56d18b4a4b17cc8 Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 13 Aug 2013 20:44:42 +0200
Subject: [PATCH 25/47] improve ruinApi
---
.../src/main/java/algorithms/JobRemover.java | 36 -------------
.../main/java/algorithms/JobRemoverImpl.java | 54 -------------------
.../main/java/algorithms/RuinStrategy.java | 1 -
3 files changed, 91 deletions(-)
delete mode 100644 jsprit-core/src/main/java/algorithms/JobRemover.java
delete mode 100644 jsprit-core/src/main/java/algorithms/JobRemoverImpl.java
diff --git a/jsprit-core/src/main/java/algorithms/JobRemover.java b/jsprit-core/src/main/java/algorithms/JobRemover.java
deleted file mode 100644
index c8d34d15..00000000
--- a/jsprit-core/src/main/java/algorithms/JobRemover.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import basics.Job;
-import basics.route.VehicleRoute;
-
-interface JobRemover {
-
- /**
- * Removes jobs from vehicRoute and return true if job has been successfully removed.
- *
- * @return true if job removed successfully, otherwise false
- */
- public boolean removeJobWithoutTourUpdate(Job job, VehicleRoute vehicleRoute);
-
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/JobRemoverImpl.java b/jsprit-core/src/main/java/algorithms/JobRemoverImpl.java
deleted file mode 100644
index 737fca0a..00000000
--- a/jsprit-core/src/main/java/algorithms/JobRemoverImpl.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import basics.Job;
-import basics.route.VehicleRoute;
-
-class JobRemoverImpl implements JobRemover{
-
- interface RemoverListener {
- public void informRemovedJob(Job j, VehicleRoute r);
- }
-
- private List remListeners = new ArrayList();
-
- @Override
- public boolean removeJobWithoutTourUpdate(Job job, VehicleRoute vehicleRoute) {
- boolean jobRemoved = vehicleRoute.getTourActivities().removeJob(job);
- if(jobRemoved) informRemovedJob(job,vehicleRoute);
- return jobRemoved;
- }
-
- private void informRemovedJob(Job job, VehicleRoute vehicleRoute) {
- for(RemoverListener l : remListeners) l.informRemovedJob(job, vehicleRoute);
- }
-
- public List getRemListeners() {
- return remListeners;
- }
-
-
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/RuinStrategy.java b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
index 8f425c6a..37d9e109 100644
--- a/jsprit-core/src/main/java/algorithms/RuinStrategy.java
+++ b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
@@ -13,7 +13,6 @@
package algorithms;
import java.util.Collection;
-import java.util.List;
import basics.Job;
import basics.route.VehicleRoute;
From 5b0857d6bff599214a852d1369c199264eb66e8b Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Tue, 13 Aug 2013 20:55:17 +0200
Subject: [PATCH 26/47] add javaDoc to RuinStrategy
---
.../main/java/algorithms/RuinStrategy.java | 39 +++++++++++++++++--
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/jsprit-core/src/main/java/algorithms/RuinStrategy.java b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
index 37d9e109..18c893cb 100644
--- a/jsprit-core/src/main/java/algorithms/RuinStrategy.java
+++ b/jsprit-core/src/main/java/algorithms/RuinStrategy.java
@@ -28,27 +28,58 @@ import basics.route.VehicleRoute;
interface RuinStrategy {
+ /**
+ * Listener that listens to the ruin-process. It informs whoever is interested about start, end and about a removal of a job.
+ *
+ * @author schroeder
+ *
+ */
public static interface RuinListener {
+ /**
+ * informs about ruin-start.
+ *
+ * @param routes
+ */
public void ruinStarts(Collection routes);
+ /**
+ * informs about ruin-end.
+ *
+ * @param routes
+ * @param unassignedJobs
+ */
public void ruinEnds(Collection routes, Collection unassignedJobs);
+ /**
+ * informs if a {@link Job} has been removed from a {@link VehicleRoute}.
+ *
+ * @param job
+ * @param fromRoute
+ */
public void removed(Job job, VehicleRoute fromRoute);
}
/**
- * Ruins a current solution, i.e. removes jobs from service providers and
- * returns a collection of these removed, and thus unassigned, jobs.
+ * Ruins a current solution, i.e. a collection of vehicle-routes and
+ * returns a collection of removed and thus unassigned jobs.
*
- * @param vehicleRoutes
- * @return
+ * @param {@link VehicleRoute}
+ * @return Collection of {@link Job}
*/
public Collection ruin(Collection vehicleRoutes);
+ /**
+ * Removes targetJob as well as its neighbors with a size of (nOfJobs2BeRemoved-1).
+ */
public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved);
+ /**
+ * Adds a ruin-listener.
+ *
+ * @param {@link RuinListener}
+ */
public void addListener(RuinListener ruinListener);
}
From cd65f66c86705cc526024ee5334b794145c6118d Mon Sep 17 00:00:00 2001
From: oblonski <4sschroeder@gmail.com>
Date: Fri, 16 Aug 2013 09:28:59 +0200
Subject: [PATCH 27/47] internal refactoring of insertionStrategy
---
.../main/java/algorithms/BestInsertion.java | 6 +-
.../algorithms/CreateInitialSolution.java | 6 +-
.../src/main/java/algorithms/Gendreau.java | 4 +-
.../java/algorithms/InsertionListeners.java | 57 +++++++++++++++++++
.../java/algorithms/InsertionStrategy.java | 3 +
5 files changed, 69 insertions(+), 7 deletions(-)
create mode 100644 jsprit-core/src/main/java/algorithms/InsertionListeners.java
diff --git a/jsprit-core/src/main/java/algorithms/BestInsertion.java b/jsprit-core/src/main/java/algorithms/BestInsertion.java
index aec62ea0..8d088b59 100644
--- a/jsprit-core/src/main/java/algorithms/BestInsertion.java
+++ b/jsprit-core/src/main/java/algorithms/BestInsertion.java
@@ -45,6 +45,8 @@ final class BestInsertion extends AbstractInsertionStrategy{
private Random random = RandomNumberGeneration.getRandom();
+ private InsertionListeners insertionsListeners;
+
private RouteAlgorithm routeAlgorithm;
public void setExperimentalPreferredRoute(Map experimentalPreferredRoute) {
@@ -67,6 +69,7 @@ final class BestInsertion extends AbstractInsertionStrategy{
public BestInsertion(RouteAlgorithm routeAlgorithm) {
super();
this.routeAlgorithm = routeAlgorithm;
+ this.insertionsListeners = new InsertionListeners();
logger.info("initialise " + this);
}
@@ -86,8 +89,7 @@ final class BestInsertion extends AbstractInsertionStrategy{
informInsertionStarts(vehicleRoutes,unassignedJobs.size());
int inserted = 0;
List reasons = new ArrayList();
- for(Job unassignedJob : unassignedJobList){
-
+ for(Job unassignedJob : unassignedJobList){
VehicleRoute insertIn = null;
Insertion bestInsertion = null;
double bestInsertionCost = Double.MAX_VALUE;
diff --git a/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java b/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
index dcaee915..08f19f1d 100644
--- a/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
+++ b/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
@@ -51,7 +51,7 @@ final class CreateInitialSolution implements InitialSolutionFactory {
private static final Logger logger = Logger.getLogger(CreateInitialSolution.class);
- private final AbstractInsertionStrategy insertion;
+ private final InsertionStrategy insertion;
private boolean generateAsMuchAsRoutesAsVehiclesExist = false;
@@ -59,9 +59,9 @@ final class CreateInitialSolution implements InitialSolutionFactory {
this.generateAsMuchAsRoutesAsVehiclesExist = generateAsMuchAsRoutesAsVehiclesExist;
}
- public CreateInitialSolution(AbstractInsertionStrategy insertion) {
+ public CreateInitialSolution(InsertionStrategy insertionStrategy) {
super();
- this.insertion = insertion;
+ this.insertion = insertionStrategy;
}
@Override
diff --git a/jsprit-core/src/main/java/algorithms/Gendreau.java b/jsprit-core/src/main/java/algorithms/Gendreau.java
index 03d96688..d94c4b1c 100644
--- a/jsprit-core/src/main/java/algorithms/Gendreau.java
+++ b/jsprit-core/src/main/java/algorithms/Gendreau.java
@@ -51,7 +51,7 @@ final class Gendreau implements SearchStrategyModule{
private final VehicleRoutingProblem vrp;
- private final AbstractInsertionStrategy insertionStrategy;
+ private final InsertionStrategy insertionStrategy;
private final RouteAlgorithm routeAlgorithm;
@@ -67,7 +67,7 @@ final class Gendreau implements SearchStrategyModule{
this.shareOfJobsToRuin = shareOfJobsToRuin;
}
- public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, AbstractInsertionStrategy insertionStrategy) {
+ public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, InsertionStrategy insertionStrategy) {
super();
this.routeAlgorithm = insertionStrategy.getRouteAlgorithm();
this.ruin = ruin;
diff --git a/jsprit-core/src/main/java/algorithms/InsertionListeners.java b/jsprit-core/src/main/java/algorithms/InsertionListeners.java
new file mode 100644
index 00000000..e0c9d2e3
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/InsertionListeners.java
@@ -0,0 +1,57 @@
+package algorithms;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import basics.Job;
+import basics.algo.InsertionEndsListener;
+import basics.algo.InsertionListener;
+import basics.algo.InsertionStartsListener;
+import basics.algo.JobInsertedListener;
+import basics.route.VehicleRoute;
+
+class InsertionListeners {
+
+ private Collection listeners = new ArrayList();
+
+ public void informJobInserted(int nOfJobs2Recreate, Job insertedJob, VehicleRoute insertedIn){
+ for(InsertionListener l : listeners){
+ if(l instanceof JobInsertedListener){
+ ((JobInsertedListener)l).informJobInserted(nOfJobs2Recreate, insertedJob, insertedIn);
+ }
+ }
+ }
+
+ public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route){
+ for(InsertionListener l : listeners){
+ if(l instanceof BeforeJobInsertionListener){
+ ((BeforeJobInsertionListener)l).informBeforeJobInsertion(job, data, route);
+ }
+ }
+ }
+
+ public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate){
+ for(InsertionListener l : listeners){
+ if(l instanceof InsertionStartsListener){
+ ((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes,nOfJobs2Recreate);
+ }
+ }
+ }
+
+ public void informInsertionEndsListeners(Collection vehicleRoutes) {
+ for(InsertionListener l : listeners){
+ if(l instanceof InsertionEndsListener){
+ ((InsertionEndsListener)l).informInsertionEnds(vehicleRoutes);
+ }
+ }
+ }
+
+ public void addListener(InsertionListener insertionListener){
+ listeners.add(insertionListener);
+ }
+
+ public void removeListener(InsertionListener insertionListener){
+ listeners.remove(insertionListener);
+ }
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/InsertionStrategy.java b/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
index 7c56995b..3d2e07d2 100644
--- a/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
+++ b/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
@@ -15,6 +15,7 @@ package algorithms;
import java.util.Collection;
import basics.Job;
+import basics.algo.InsertionListener;
import basics.route.VehicleRoute;
@@ -62,5 +63,7 @@ interface InsertionStrategy {
* @param result2beat
*/
public void run(Collection vehicleRoutes, Collection unassignedJobs, double result2beat);
+
+ public void addListener(InsertionListener insertionListener);
}
From e35603ed34d8ee21fe7e723c403fe156208a8d5b Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Fri, 16 Aug 2013 16:30:29 +0200
Subject: [PATCH 28/47] API CHANGED - insertionStarts (method para changed),
jobInserted (method para changed) and vehicleRoute (new method)
---
.../src/main/java/basics/algo/InsertionStartsListener.java | 3 ++-
.../src/main/java/basics/algo/JobInsertedListener.java | 2 +-
jsprit-core/src/main/java/basics/route/VehicleRoute.java | 5 +++++
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/jsprit-core/src/main/java/basics/algo/InsertionStartsListener.java b/jsprit-core/src/main/java/basics/algo/InsertionStartsListener.java
index a62459cd..8f8ea757 100644
--- a/jsprit-core/src/main/java/basics/algo/InsertionStartsListener.java
+++ b/jsprit-core/src/main/java/basics/algo/InsertionStartsListener.java
@@ -22,10 +22,11 @@ package basics.algo;
import java.util.Collection;
+import basics.Job;
import basics.route.VehicleRoute;
public interface InsertionStartsListener extends InsertionListener {
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate);
+ public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs);
}
diff --git a/jsprit-core/src/main/java/basics/algo/JobInsertedListener.java b/jsprit-core/src/main/java/basics/algo/JobInsertedListener.java
index 5cce5484..510a9ded 100644
--- a/jsprit-core/src/main/java/basics/algo/JobInsertedListener.java
+++ b/jsprit-core/src/main/java/basics/algo/JobInsertedListener.java
@@ -30,5 +30,5 @@ import basics.route.VehicleRoute;
public interface JobInsertedListener extends InsertionListener{
- public void informJobInserted(int nOfJobsStill2Recreate, Job job2insert, VehicleRoute insertedIn);
+ public void informJobInserted(Job job2insert, VehicleRoute inRoute);
}
diff --git a/jsprit-core/src/main/java/basics/route/VehicleRoute.java b/jsprit-core/src/main/java/basics/route/VehicleRoute.java
index e7bf3814..95c8f3e0 100644
--- a/jsprit-core/src/main/java/basics/route/VehicleRoute.java
+++ b/jsprit-core/src/main/java/basics/route/VehicleRoute.java
@@ -158,6 +158,11 @@ public class VehicleRoute {
start.setEndTime(vehicleDepTime);
}
+ public double getDepartureTime(){
+ if(start == null) throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
+ return start.getEndTime();
+ }
+
private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) {
if(!(vehicle instanceof NoVehicle)){
if(start == null && end == null){
From 3f7d6b8b01157fac0a85c80b1db9d2598cd22f78 Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Fri, 16 Aug 2013 16:31:32 +0200
Subject: [PATCH 29/47] internal optimization of insertion-issues
---
.../algorithms/AbstractInsertionStrategy.java | 95 -------------
.../main/java/algorithms/BestInsertion.java | 126 ++++++++----------
.../algorithms/BestInsertionConcurrent.java | 31 +++--
.../ConfigureFixCostCalculator.java | 12 +-
.../algorithms/CreateInitialSolution.java | 2 +-
.../java/algorithms/FindCheaperVehicle.java | 3 +-
.../src/main/java/algorithms/Gendreau.java | 20 +--
.../src/main/java/algorithms/Inserter.java | 36 +++++
.../java/algorithms/InsertionFactory.java | 22 ++-
.../java/algorithms/InsertionListeners.java | 25 +++-
.../java/algorithms/InsertionStrategy.java | 7 +-
.../src/main/java/algorithms/JobObserver.java | 10 +-
.../main/java/algorithms/RegretInsertion.java | 27 +++-
.../java/algorithms/RemoveEmptyVehicles.java | 18 +--
.../algorithms/ResetAndIniFleetManager.java | 13 +-
.../src/main/java/algorithms/UpdateRoute.java | 36 +++++
.../algorithms/VehicleRoutingAlgorithms.java | 44 +++---
.../main/java/algorithms/VehicleSwitched.java | 5 +-
.../algorithms/VehicleSwitchedListener.java | 11 ++
.../java/algorithms/GendreauPostOptTest.java | 54 +++++---
20 files changed, 315 insertions(+), 282 deletions(-)
delete mode 100644 jsprit-core/src/main/java/algorithms/AbstractInsertionStrategy.java
create mode 100644 jsprit-core/src/main/java/algorithms/Inserter.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateRoute.java
create mode 100644 jsprit-core/src/main/java/algorithms/VehicleSwitchedListener.java
diff --git a/jsprit-core/src/main/java/algorithms/AbstractInsertionStrategy.java b/jsprit-core/src/main/java/algorithms/AbstractInsertionStrategy.java
deleted file mode 100644
index f2dfca54..00000000
--- a/jsprit-core/src/main/java/algorithms/AbstractInsertionStrategy.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import basics.Job;
-import basics.algo.InsertionEndsListener;
-import basics.algo.InsertionListener;
-import basics.algo.InsertionStartsListener;
-import basics.algo.JobInsertedListener;
-import basics.route.VehicleRoute;
-
-
-
-
-abstract class AbstractInsertionStrategy implements InsertionStrategy{
-
- private static Logger log = Logger.getLogger(AbstractInsertionStrategy.class);
-
- private Collection listener = new ArrayList();
-
- public abstract RouteAlgorithm getRouteAlgorithm();
-
- public void informJobInserted(int nOfJobs2Recreate, Job insertedJob, VehicleRoute insertedIn){
- for(InsertionListener l : listener){
- if(l instanceof JobInsertedListener){
- ((JobInsertedListener)l).informJobInserted(nOfJobs2Recreate, insertedJob, insertedIn);
- }
- }
- }
-
- public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route){
- for(InsertionListener l : listener){
- if(l instanceof BeforeJobInsertionListener){
- ((BeforeJobInsertionListener)l).informBeforeJobInsertion(job, data, route);
- }
- }
- }
-
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate){
- for(InsertionListener l : listener){
- if(l instanceof InsertionStartsListener){
- ((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes,nOfJobs2Recreate);
- }
- }
- }
-
- public void informInsertionEndsListeners(Collection vehicleRoutes) {
- for(InsertionListener l : listener){
- if(l instanceof InsertionEndsListener){
- ((InsertionEndsListener)l).informInsertionEnds(vehicleRoutes);
- }
- }
- }
-
- public Collection getListener() {
- return Collections.unmodifiableCollection(listener);
- }
-
- public void addListener(InsertionListener l){
- log.info("add insertion-listener " + l);
- listener.add(l);
- }
-
- public void addAllListener(List list) {
- for(InsertionListener l : list) addListener(l);
- }
-
-
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/BestInsertion.java b/jsprit-core/src/main/java/algorithms/BestInsertion.java
index 8d088b59..bee3394b 100644
--- a/jsprit-core/src/main/java/algorithms/BestInsertion.java
+++ b/jsprit-core/src/main/java/algorithms/BestInsertion.java
@@ -15,9 +15,7 @@ package algorithms;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Random;
import org.apache.log4j.Logger;
@@ -25,6 +23,9 @@ import org.apache.log4j.Logger;
import util.RandomNumberGeneration;
import algorithms.InsertionData.NoInsertionFound;
import basics.Job;
+import basics.algo.InsertionListener;
+import basics.route.Driver;
+import basics.route.Vehicle;
import basics.route.VehicleRoute;
@@ -35,47 +36,37 @@ import basics.route.VehicleRoute;
*
*/
-final class BestInsertion extends AbstractInsertionStrategy{
-
- public static BestInsertion newInstance(RouteAlgorithm routeAlgorithm){
- return new BestInsertion(routeAlgorithm);
- }
+final class BestInsertion implements InsertionStrategy{
private static Logger logger = Logger.getLogger(BestInsertion.class);
private Random random = RandomNumberGeneration.getRandom();
+ private final static double NO_NEW_DEPARTURE_TIME_YET = -12345.12345;
+
+ private final static Vehicle NO_NEW_VEHICLE_YET = null;
+
+ private final static Driver NO_NEW_DRIVER_YET = null;
+
private InsertionListeners insertionsListeners;
- private RouteAlgorithm routeAlgorithm;
+ private Inserter inserter;
- public void setExperimentalPreferredRoute(Map experimentalPreferredRoute) {
- }
+ private JobInsertionCalculator bestInsertionCostCalculator;
- private boolean allowUnassignedJobs = false;
-
- private boolean fixRouteSet = false;
-
private boolean minVehiclesFirst = false;
-
- public void setFixRouteSet(boolean fixRouteSet) {
- this.fixRouteSet = fixRouteSet;
- }
public void setRandom(Random random) {
this.random = random;
}
- public BestInsertion(RouteAlgorithm routeAlgorithm) {
+ public BestInsertion(JobInsertionCalculator jobInsertionCalculator) {
super();
- this.routeAlgorithm = routeAlgorithm;
this.insertionsListeners = new InsertionListeners();
+ inserter = new Inserter(insertionsListeners);
+ bestInsertionCostCalculator = jobInsertionCalculator;
logger.info("initialise " + this);
}
-
- public RouteAlgorithm getRouteAlgorithm(){
- return routeAlgorithm;
- }
@Override
public String toString() {
@@ -83,18 +74,15 @@ final class BestInsertion extends AbstractInsertionStrategy{
}
@Override
- public void run(Collection vehicleRoutes, Collection unassignedJobs, double result2beat) {
+ public void insertJobs(Collection vehicleRoutes, Collection unassignedJobs) {
+ insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs);
List unassignedJobList = new ArrayList(unassignedJobs);
Collections.shuffle(unassignedJobList, random);
- informInsertionStarts(vehicleRoutes,unassignedJobs.size());
- int inserted = 0;
- List reasons = new ArrayList();
for(Job unassignedJob : unassignedJobList){
- VehicleRoute insertIn = null;
Insertion bestInsertion = null;
double bestInsertionCost = Double.MAX_VALUE;
for(VehicleRoute vehicleRoute : vehicleRoutes){
- InsertionData iData = routeAlgorithm.calculateBestInsertion(vehicleRoute, unassignedJob, bestInsertionCost);
+ InsertionData iData = bestInsertionCostCalculator.calculate(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
if(iData instanceof NoInsertionFound) {
continue;
}
@@ -105,56 +93,54 @@ final class BestInsertion extends AbstractInsertionStrategy{
}
if(!minVehiclesFirst){
VehicleRoute newRoute = VehicleRoute.emptyRoute();
- InsertionData newIData = routeAlgorithm.calculateBestInsertion(newRoute, unassignedJob, Double.MAX_VALUE);
+ InsertionData newIData = bestInsertionCostCalculator.calculate(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
if(newIData.getInsertionCost() < bestInsertionCost){
bestInsertion = new Insertion(newRoute,newIData);
bestInsertionCost = newIData.getInsertionCost();
vehicleRoutes.add(newRoute);
}
- }
- if(bestInsertion != null){
- informBeforeJobInsertion(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
- insertIn = bestInsertion.getRoute();
-// logger.debug("insert job="+unassignedJob+" at index=" + bestInsertion.getInsertionData().getInsertionIndex() + " delta cost=" + bestInsertion.getInsertionData().getInsertionCost());
- routeAlgorithm.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
- }
- else {
- if(fixRouteSet){
- if(allowUnassignedJobs) logger.warn("cannot insert job yet " + unassignedJob);
- else throw new IllegalStateException("given the vehicles, could not insert job\n");
+ }
+ if(bestInsertion == null){
+ VehicleRoute newRoute = VehicleRoute.emptyRoute();
+ InsertionData bestI = bestInsertionCostCalculator.calculate(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE);
+ if(bestI instanceof InsertionData.NoInsertionFound){
+ throw new IllegalStateException(getErrorMsg(unassignedJob));
}
else{
- VehicleRoute newRoute = VehicleRoute.emptyRoute();
- InsertionData bestI = routeAlgorithm.calculateBestInsertion(newRoute, unassignedJob, Double.MAX_VALUE);
- if(bestI instanceof InsertionData.NoInsertionFound){
- if(allowUnassignedJobs){
- logger.warn("cannot insert job yet " + unassignedJob);
- }
- else {
- for(String s : reasons){
- System.out.println("reason="+s);
- }
- throw new IllegalStateException("given the vehicles, could not insert job\n" +
- "\t" + unassignedJob +
- "\n\tthis might have the following reasons:\n" +
- "\t- no vehicle has the capacity to transport the job [check whether there is at least one vehicle that is capable to transport the job]\n" +
- "\t- the time-window cannot be met, even in a commuter tour the time-window is missed [check whether it is possible to reach the time-window on the shortest path or make hard time-windows soft]\n" +
- "\t- if you deal with finite vehicles, and the available vehicles are already fully employed, no vehicle can be found anymore to transport the job [add penalty-vehicles]"
- );
- }
- }
- else{
- insertIn = newRoute;
- informBeforeJobInsertion(unassignedJob,bestI,newRoute);
- routeAlgorithm.insertJob(unassignedJob,bestI,newRoute);
- vehicleRoutes.add(newRoute);
- }
+ bestInsertion = new Insertion(newRoute,bestI);
+ vehicleRoutes.add(newRoute);
}
}
- inserted++;
- informJobInserted((unassignedJobList.size()-inserted), unassignedJob, insertIn);
+
+ inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
+
}
- informInsertionEndsListeners(vehicleRoutes);
+ insertionsListeners.informInsertionEndsListeners(vehicleRoutes);
+ }
+
+ private String getErrorMsg(Job unassignedJob) {
+ return "given the vehicles, could not insert job\n" +
+ "\t" + unassignedJob +
+ "\n\tthis might have the following reasons:\n" +
+ "\t- no vehicle has the capacity to transport the job [check whether there is at least one vehicle that is capable to transport the job]\n" +
+ "\t- the time-window cannot be met, even in a commuter tour the time-window is missed [check whether it is possible to reach the time-window on the shortest path or make hard time-windows soft]\n" +
+ "\t- if you deal with finite vehicles, and the available vehicles are already fully employed, no vehicle can be found anymore to transport the job [add penalty-vehicles]";
+ }
+
+ @Override
+ public void removeListener(InsertionListener insertionListener) {
+ insertionsListeners.removeListener(insertionListener);
+ }
+
+ @Override
+ public Collection getListeners() {
+ return Collections.unmodifiableCollection(insertionsListeners.getListeners());
+ }
+
+ @Override
+ public void addListener(InsertionListener insertionListener) {
+ insertionsListeners.addListener(insertionListener);
+
}
}
diff --git a/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java b/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
index cfe56404..742e29b4 100644
--- a/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
+++ b/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
@@ -30,6 +30,7 @@ import org.apache.log4j.Logger;
import util.RandomNumberGeneration;
import algorithms.InsertionData.NoInsertionFound;
import basics.Job;
+import basics.algo.InsertionListener;
import basics.route.VehicleRoute;
@@ -40,7 +41,7 @@ import basics.route.VehicleRoute;
*
*/
-final class BestInsertionConcurrent extends AbstractInsertionStrategy{
+final class BestInsertionConcurrent implements InsertionStrategy{
public static BestInsertionConcurrent newInstance(RouteAlgorithm routeAlgorithm, ExecutorService executor, int nuOfThreads){
return new BestInsertionConcurrent(routeAlgorithm, executor, nuOfThreads);
@@ -82,10 +83,10 @@ final class BestInsertionConcurrent extends AbstractInsertionStrategy{
}
@Override
- public void run(Collection vehicleRoutes, Collection unassignedJobs, double result2beat) {
+ public void insertJobs(Collection vehicleRoutes, Collection unassignedJobs) {
List unassignedJobList = new ArrayList(unassignedJobs);
Collections.shuffle(unassignedJobList, random);
- informInsertionStarts(vehicleRoutes,unassignedJobs.size());
+// informInsertionStarts(vehicleRoutes,unassignedJobs.size());
int inserted = 0;
for(final Job unassignedJob : unassignedJobList){
VehicleRoute insertIn = null;
@@ -127,7 +128,7 @@ final class BestInsertionConcurrent extends AbstractInsertionStrategy{
}
if(bestInsertion != null){
- informBeforeJobInsertion(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
+// informBeforeJobInsertion(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
insertIn = bestInsertion.getRoute();
// logger.debug("insert job="+unassignedJob+" at index=" + bestInsertion.getInsertionData().getInsertionIndex() + " delta cost=" + bestInsertion.getInsertionData().getInsertionCost());
routeAlgorithm.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
@@ -144,9 +145,9 @@ final class BestInsertionConcurrent extends AbstractInsertionStrategy{
// vehicleRoutes.add(newRoute);
}
inserted++;
- informJobInserted((unassignedJobList.size()-inserted), unassignedJob, insertIn);
+// informJobInserted((unassignedJobList.size()-inserted), unassignedJob, insertIn);
}
- informInsertionEndsListeners(vehicleRoutes);
+// informInsertionEndsListeners(vehicleRoutes);
}
private Insertion getBestInsertion(Batch batch, Job unassignedJob) {
@@ -191,9 +192,23 @@ final class BestInsertionConcurrent extends AbstractInsertionStrategy{
return batches;
}
+
@Override
- public RouteAlgorithm getRouteAlgorithm() {
- return routeAlgorithm;
+ public void removeListener(InsertionListener insertionListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Collection getListeners() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void addListener(InsertionListener insertionListener) {
+ // TODO Auto-generated method stub
+
}
}
diff --git a/jsprit-core/src/main/java/algorithms/ConfigureFixCostCalculator.java b/jsprit-core/src/main/java/algorithms/ConfigureFixCostCalculator.java
index 179164da..650cbedf 100644
--- a/jsprit-core/src/main/java/algorithms/ConfigureFixCostCalculator.java
+++ b/jsprit-core/src/main/java/algorithms/ConfigureFixCostCalculator.java
@@ -42,6 +42,8 @@ final class ConfigureFixCostCalculator implements InsertionStartsListener, JobIn
VehicleRoutingProblem vrp;
CalculatesServiceInsertionConsideringFixCost calcConsideringFix;
+
+ private int nuOfJobsToRecreate;
public ConfigureFixCostCalculator(VehicleRoutingProblem vrp, CalculatesServiceInsertionConsideringFixCost calcConsideringFix) {
super();
@@ -55,15 +57,17 @@ final class ConfigureFixCostCalculator implements InsertionStartsListener, JobIn
}
@Override
- public void informInsertionStarts(Collection routes, int nOfJobs2Recreate) {
- double completenessRatio = (1-((double)nOfJobs2Recreate/(double)vrp.getJobs().values().size()));
+ public void informInsertionStarts(Collection routes, Collection unassignedJobs) {
+ this.nuOfJobsToRecreate = unassignedJobs.size();
+ double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size()));
calcConsideringFix.setSolutionCompletenessRatio(completenessRatio);
// log.debug("initialise completenessRatio to " + completenessRatio);
}
@Override
- public void informJobInserted(int nOfJobsStill2Recreate, Job job2insert, VehicleRoute insertedIn) {
- double completenessRatio = (1-((double)nOfJobsStill2Recreate/(double)vrp.getJobs().values().size()));
+ public void informJobInserted(Job job2insert, VehicleRoute inRoute) {
+ nuOfJobsToRecreate--;
+ double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size()));
calcConsideringFix.setSolutionCompletenessRatio(completenessRatio);
// log.debug("set completenessRatio to " + completenessRatio);
}
diff --git a/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java b/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
index 08f19f1d..e0b1cd6d 100644
--- a/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
+++ b/jsprit-core/src/main/java/algorithms/CreateInitialSolution.java
@@ -73,7 +73,7 @@ final class CreateInitialSolution implements InitialSolutionFactory {
vehicleRoutes.add(VehicleRoute.newInstance(TourActivities.emptyTour(), DriverImpl.noDriver(), vehicle));
}
}
- insertion.run(vehicleRoutes, getUnassignedJobs(vrp), Double.MAX_VALUE);
+ insertion.insertJobs(vehicleRoutes, getUnassignedJobs(vrp));
double totalCost = getTotalCost(vehicleRoutes);
logger.info("creation done");
return new VehicleRoutingProblemSolution(vehicleRoutes, totalCost);
diff --git a/jsprit-core/src/main/java/algorithms/FindCheaperVehicle.java b/jsprit-core/src/main/java/algorithms/FindCheaperVehicle.java
index 9a19f579..807cc36a 100644
--- a/jsprit-core/src/main/java/algorithms/FindCheaperVehicle.java
+++ b/jsprit-core/src/main/java/algorithms/FindCheaperVehicle.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import basics.Job;
import basics.algo.InsertionStartsListener;
import basics.route.VehicleRoute;
@@ -37,7 +38,7 @@ class FindCheaperVehicle implements InsertionStartsListener{
}
@Override
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate) {
+ public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) {
List newRoutes = new ArrayList();
for(VehicleRoute route : vehicleRoutes){
if(route.isEmpty()) continue;
diff --git a/jsprit-core/src/main/java/algorithms/Gendreau.java b/jsprit-core/src/main/java/algorithms/Gendreau.java
index d94c4b1c..70125dc4 100644
--- a/jsprit-core/src/main/java/algorithms/Gendreau.java
+++ b/jsprit-core/src/main/java/algorithms/Gendreau.java
@@ -21,6 +21,7 @@
package algorithms;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -30,16 +31,15 @@ import java.util.Set;
import org.apache.log4j.Logger;
+import util.RandomNumberGeneration;
import basics.Job;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.algo.SearchStrategyModule;
import basics.algo.SearchStrategyModuleListener;
import basics.route.TourActivity;
-import basics.route.VehicleRoute;
import basics.route.TourActivity.JobActivity;
-
-import util.RandomNumberGeneration;
+import basics.route.VehicleRoute;
final class Gendreau implements SearchStrategyModule{
@@ -53,7 +53,7 @@ final class Gendreau implements SearchStrategyModule{
private final InsertionStrategy insertionStrategy;
- private final RouteAlgorithm routeAlgorithm;
+ private final Inserter inserter;
private VehicleFleetManager fleetManager;
@@ -69,7 +69,9 @@ final class Gendreau implements SearchStrategyModule{
public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, InsertionStrategy insertionStrategy) {
super();
- this.routeAlgorithm = insertionStrategy.getRouteAlgorithm();
+ InsertionListeners insertionListeners = new InsertionListeners();
+ insertionListeners.addAllListeners(insertionStrategy.getListeners());
+ inserter = new Inserter(insertionListeners);
this.ruin = ruin;
this.vrp = vrp;
this.insertionStrategy = insertionStrategy;
@@ -119,16 +121,18 @@ final class Gendreau implements SearchStrategyModule{
VehicleRoute emptyRoute1 = VehicleRoute.emptyRoute();
copiedRoutes.add(emptyRoute1);
- routeAlgorithm.insertJob(targetJob, routeAlgorithm.calculateBestInsertion(emptyRoute1, targetJob, Double.MAX_VALUE), emptyRoute1);
+ insertionStrategy.insertJobs(Arrays.asList(emptyRoute1), Arrays.asList(targetJob));
+// routeAlgorithm.insertJob(targetJob, routeAlgorithm.calculateBestInsertion(emptyRoute1, targetJob, Double.MAX_VALUE), emptyRoute1);
unassignedJobs.remove(targetJob);
VehicleRoute emptyRoute2 = VehicleRoute.emptyRoute();
copiedRoutes.add(emptyRoute2);
Job job2 = jobsInRoute.get(1);
- routeAlgorithm.insertJob(job2, routeAlgorithm.calculateBestInsertion(emptyRoute2, job2, Double.MAX_VALUE), emptyRoute2);
+ insertionStrategy.insertJobs(Arrays.asList(emptyRoute2), Arrays.asList(job2));
+// routeAlgorithm.insertJob(job2, routeAlgorithm.calculateBestInsertion(emptyRoute2, job2, Double.MAX_VALUE), emptyRoute2);
unassignedJobs.remove(job2);
- insertionStrategy.run(copiedRoutes, unassignedJobs, Double.MAX_VALUE);
+ insertionStrategy.insertJobs(copiedRoutes, unassignedJobs);
double cost = getCost(copiedRoutes);
if(cost < bestSolution.getCost()){
diff --git a/jsprit-core/src/main/java/algorithms/Inserter.java b/jsprit-core/src/main/java/algorithms/Inserter.java
new file mode 100644
index 00000000..4a322790
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/Inserter.java
@@ -0,0 +1,36 @@
+package algorithms;
+
+import algorithms.InsertionData.NoInsertionFound;
+import basics.Job;
+import basics.Service;
+import basics.route.ServiceActivity;
+import basics.route.VehicleRoute;
+
+class Inserter {
+
+ private InsertionListeners insertionListeners;
+
+ public Inserter(InsertionListeners insertionListeners) {
+ this.insertionListeners = insertionListeners;
+ }
+
+ public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute){
+ insertionListeners.informBeforeJobInsertion(job, insertionData, vehicleRoute);
+
+ if(insertionData == null || (insertionData instanceof NoInsertionFound)) throw new IllegalStateException("insertionData null. cannot insert job.");
+ if(job == null) throw new IllegalStateException("cannot insert null-job");
+ if(!(vehicleRoute.getVehicle().getId().toString().equals(insertionData.getSelectedVehicle().getId().toString()))){
+ insertionListeners.informVehicleSwitched(vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle());
+ vehicleRoute.setVehicle(insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime());
+ }
+// if(vehicleRoute.getDepartureTime() != vehicleRoute.g)
+ if(job instanceof Service) {
+ vehicleRoute.getTourActivities().addActivity(insertionData.getDeliveryInsertionIndex(), ServiceActivity.newInstance((Service)job));
+ vehicleRoute.setDepartureTime(insertionData.getVehicleDepartureTime());
+ }
+ else throw new IllegalStateException("neither service nor shipment. this is not supported.");
+
+ insertionListeners.informJobInserted(job, vehicleRoute);
+// updateTour(vehicleRoute);
+ }
+}
diff --git a/jsprit-core/src/main/java/algorithms/InsertionFactory.java b/jsprit-core/src/main/java/algorithms/InsertionFactory.java
index b7cc4093..de09488d 100644
--- a/jsprit-core/src/main/java/algorithms/InsertionFactory.java
+++ b/jsprit-core/src/main/java/algorithms/InsertionFactory.java
@@ -37,7 +37,7 @@ class InsertionFactory {
private static Logger log = Logger.getLogger(InsertionFactory.class);
- public static AbstractInsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config,
+ public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config,
VehicleFleetManager vehicleFleetManager, RouteStates activityStates, List algorithmListeners, ExecutorService executorService, int nuOfThreads){
boolean concurrentInsertion = false;
if(executorService != null) concurrentInsertion = true;
@@ -46,7 +46,7 @@ class InsertionFactory {
if(!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")){
new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\"");
}
- AbstractInsertionStrategy insertionStrategy = null;
+ InsertionStrategy insertionStrategy = null;
List insertionListeners = new ArrayList();
List algoListeners = new ArrayList();
@@ -96,7 +96,7 @@ class InsertionFactory {
JobInsertionCalculator jic = calcBuilder.build();
TourStateUpdater tourStateCalculator = new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts());
RouteAlgorithm routeAlgorithm = RouteAlgorithmImpl.newInstance(jic, tourStateCalculator);
- routeAlgorithm.getListeners().add(new VehicleSwitched(vehicleFleetManager));
+// routeAlgorithm.getListeners().add(new VehicleSwitched(vehicleFleetManager));
((RouteAlgorithmImpl) routeAlgorithm).setActivityStates(activityStates);
if(insertionName.equals("bestInsertion")){
@@ -104,24 +104,18 @@ class InsertionFactory {
insertionStrategy = BestInsertionConcurrent.newInstance(routeAlgorithm,executorService,nuOfThreads);
}
else{
- insertionStrategy = BestInsertion.newInstance(routeAlgorithm);
+ insertionStrategy = new BestInsertion(jic);
}
}
else if(insertionName.equals("regretInsertion")){
insertionStrategy = RegretInsertion.newInstance(routeAlgorithm);
}
-// else if(insertionName.equals("concurrentBestInsertion")){
-// String processorsString = config.getString("[@processors]");
-// int processors = 1;
-// if(processorsString != null) processors = Integer.parseInt(processorsString);
-//// BestInsertionConcurrent.newInstance(routeAlgorithm,)
-//
-//
-// }
-// insertionStrategy.addListener(new RemoveEmptyVehicles(vehicleFleetManager));
+ insertionStrategy.addListener(new RemoveEmptyVehicles(vehicleFleetManager));
insertionStrategy.addListener(new ResetAndIniFleetManager(vehicleFleetManager));
- insertionStrategy.addAllListener(insertionListeners);
+ insertionStrategy.addListener(new VehicleSwitched(vehicleFleetManager));
+ insertionStrategy.addListener(new UpdateRoute(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts()));
+ for(InsertionListener l : insertionListeners) insertionStrategy.addListener(l);
// insertionStrategy.addListener(new FindCheaperVehicle(
// new FindCheaperVehicleAlgoNew(vehicleFleetManager, tourStateCalculator, auxCalculator)));
diff --git a/jsprit-core/src/main/java/algorithms/InsertionListeners.java b/jsprit-core/src/main/java/algorithms/InsertionListeners.java
index e0c9d2e3..d35e5434 100644
--- a/jsprit-core/src/main/java/algorithms/InsertionListeners.java
+++ b/jsprit-core/src/main/java/algorithms/InsertionListeners.java
@@ -8,16 +8,29 @@ import basics.algo.InsertionEndsListener;
import basics.algo.InsertionListener;
import basics.algo.InsertionStartsListener;
import basics.algo.JobInsertedListener;
+import basics.route.Vehicle;
import basics.route.VehicleRoute;
class InsertionListeners {
private Collection listeners = new ArrayList();
- public void informJobInserted(int nOfJobs2Recreate, Job insertedJob, VehicleRoute insertedIn){
+ public Collection getListeners(){
+ return listeners;
+ }
+
+ public void informJobInserted(Job insertedJob, VehicleRoute inRoute){
for(InsertionListener l : listeners){
if(l instanceof JobInsertedListener){
- ((JobInsertedListener)l).informJobInserted(nOfJobs2Recreate, insertedJob, insertedIn);
+ ((JobInsertedListener)l).informJobInserted(insertedJob, inRoute);
+ }
+ }
+ }
+
+ public void informVehicleSwitched(VehicleRoute route, Vehicle oldVehicle, Vehicle newVehicle){
+ for(InsertionListener l : listeners){
+ if(l instanceof VehicleSwitchedListener){
+ ((VehicleSwitchedListener) l).vehicleSwitched(route, oldVehicle, newVehicle);
}
}
}
@@ -30,10 +43,10 @@ class InsertionListeners {
}
}
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate){
+ public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs){
for(InsertionListener l : listeners){
if(l instanceof InsertionStartsListener){
- ((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes,nOfJobs2Recreate);
+ ((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes, unassignedJobs);
}
}
}
@@ -54,4 +67,8 @@ class InsertionListeners {
listeners.remove(insertionListener);
}
+ public void addAllListeners(Collection listeners) {
+ for(InsertionListener l : listeners) addListener(l);
+ }
+
}
diff --git a/jsprit-core/src/main/java/algorithms/InsertionStrategy.java b/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
index 3d2e07d2..4ebc9ffa 100644
--- a/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
+++ b/jsprit-core/src/main/java/algorithms/InsertionStrategy.java
@@ -60,10 +60,13 @@ interface InsertionStrategy {
*
* @param vehicleRoutes
* @param unassignedJobs
- * @param result2beat
*/
- public void run(Collection vehicleRoutes, Collection unassignedJobs, double result2beat);
+ public void insertJobs(Collection vehicleRoutes, Collection unassignedJobs);
public void addListener(InsertionListener insertionListener);
+
+ public void removeListener(InsertionListener insertionListener);
+
+ public Collection getListeners();
}
diff --git a/jsprit-core/src/main/java/algorithms/JobObserver.java b/jsprit-core/src/main/java/algorithms/JobObserver.java
index 43641b04..f45f1799 100644
--- a/jsprit-core/src/main/java/algorithms/JobObserver.java
+++ b/jsprit-core/src/main/java/algorithms/JobObserver.java
@@ -76,14 +76,14 @@ class JobObserver implements JobInsertedListener, BeforeJobInsertionListener, Al
Collection infos = new ArrayList();
@Override
- public void informJobInserted(int nOfJobsStill2Recreate, Job job2insert, VehicleRoute insertedIn) {
+ public void informJobInserted(Job job2insert, VehicleRoute inRoute) {
if(job2insert instanceof Service){
if(((Service) job2insert).getLocationId().equals(locationId)){
- double actualMC = insertedIn.getCost()-routeCostBefore;
- TourActivity act = getAct(job2insert,insertedIn);
+ double actualMC = inRoute.getCost()-routeCostBefore;
+ TourActivity act = getAct(job2insert,inRoute);
double error = (estimatedMC-actualMC);
- int tourSize = insertedIn.getTourActivities().getActivities().size();
- int insertionIndex = getIndexOf(job2insert, insertedIn);
+ int tourSize = inRoute.getTourActivities().getActivities().size();
+ int insertionIndex = getIndexOf(job2insert, inRoute);
// infos.add(new Info())
double depTime = state(act).getEarliestOperationStart()+act.getOperationTime();
infos.add(new Info(depTime,tourSize,insertionIndex,error));
diff --git a/jsprit-core/src/main/java/algorithms/RegretInsertion.java b/jsprit-core/src/main/java/algorithms/RegretInsertion.java
index 46ad780b..d6eee459 100644
--- a/jsprit-core/src/main/java/algorithms/RegretInsertion.java
+++ b/jsprit-core/src/main/java/algorithms/RegretInsertion.java
@@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
import algorithms.InsertionData.NoInsertionFound;
import basics.Job;
import basics.Service;
+import basics.algo.InsertionListener;
import basics.route.VehicleRoute;
@@ -35,7 +36,7 @@ import basics.route.VehicleRoute;
* @author stefan schroeder
*
*/
-final class RegretInsertion extends AbstractInsertionStrategy{
+final class RegretInsertion implements InsertionStrategy{
/**
* Scorer to include other impacts on score such as time-window length or distance to depot.
@@ -127,9 +128,9 @@ final class RegretInsertion extends AbstractInsertionStrategy{
*
*/
@Override
- public void run(Collection routes, Collection unassignedJobs, double resultToBeat) {
+ public void insertJobs(Collection routes, Collection unassignedJobs) {
List jobs = new ArrayList(unassignedJobs);
- informInsertionStarts(routes,unassignedJobs.size());
+// informInsertionStarts(routes,unassignedJobs);
int inserted = 0;
while(!jobs.isEmpty()){
List unassignedJobList = new ArrayList(jobs);
@@ -191,7 +192,7 @@ final class RegretInsertion extends AbstractInsertionStrategy{
jobs.remove(bestScoredJob.getJob());
}
inserted++;
- informJobInserted((unassignedJobList.size()-inserted), assignedJob, insertIn);
+// informJobInserted(assignedJob, insertIn);
}
}
@@ -206,5 +207,23 @@ final class RegretInsertion extends AbstractInsertionStrategy{
return (secondBest.getInsertionCost()-best.getInsertionCost()) + scoringFunction.score(unassignedJob);
}
+
+ @Override
+ public void removeListener(InsertionListener insertionListener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Collection getListeners() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void addListener(InsertionListener insertionListener) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java b/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java
index 49d12618..3a1e7f0b 100644
--- a/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java
+++ b/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java
@@ -26,11 +26,12 @@ import java.util.List;
import org.apache.log4j.Logger;
+import basics.Job;
import basics.algo.InsertionEndsListener;
import basics.algo.InsertionStartsListener;
import basics.route.VehicleRoute;
-class RemoveEmptyVehicles implements InsertionStartsListener, InsertionEndsListener{
+class RemoveEmptyVehicles implements InsertionEndsListener{
private static Logger log = Logger.getLogger(RemoveEmptyVehicles.class);
@@ -41,21 +42,6 @@ class RemoveEmptyVehicles implements InsertionStartsListener, InsertionEndsListe
this.fleetManager = fleetManager;
}
- @Override
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate) {
-// List routes = new ArrayList(vehicleRoutes);
-// for(VehicleRoute route : routes){
-// if(route.isEmpty()) { vehicleRoutes.remove(route); }
-// }
-// List routes = new ArrayList(vehicleRoutes);
-// for(VehicleRoute route : routes){
-// if(route.isEmpty()) {
-// fleetManager.unlock(route.getVehicle());
-// vehicleRoutes.remove(route);
-// }
-// }
- }
-
@Override
public String toString() {
return "[name=removeEmptyVehicles]";
diff --git a/jsprit-core/src/main/java/algorithms/ResetAndIniFleetManager.java b/jsprit-core/src/main/java/algorithms/ResetAndIniFleetManager.java
index be009119..ff94bbbc 100644
--- a/jsprit-core/src/main/java/algorithms/ResetAndIniFleetManager.java
+++ b/jsprit-core/src/main/java/algorithms/ResetAndIniFleetManager.java
@@ -25,6 +25,7 @@ import java.util.Collection;
import org.apache.log4j.Logger;
+import basics.Job;
import basics.algo.InsertionStartsListener;
import basics.route.VehicleRoute;
@@ -40,16 +41,16 @@ class ResetAndIniFleetManager implements InsertionStartsListener{
}
@Override
- public void informInsertionStarts(Collection vehicleRoutes, int nOfJobs2Recreate) {
+ public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) {
vehicleFleetManager.unlockAll();
Collection routes = new ArrayList(vehicleRoutes);
for(VehicleRoute route : routes){
- if(route.isEmpty()){
- vehicleRoutes.remove(route);
- }
- else{
+// if(route.isEmpty()){
+// vehicleRoutes.remove(route);
+// }
+// else{
vehicleFleetManager.lock(route.getVehicle());
- }
+// }
}
}
diff --git a/jsprit-core/src/main/java/algorithms/UpdateRoute.java b/jsprit-core/src/main/java/algorithms/UpdateRoute.java
new file mode 100644
index 00000000..2fda8f33
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/UpdateRoute.java
@@ -0,0 +1,36 @@
+package algorithms;
+
+import java.util.Collection;
+
+import algorithms.RuinStrategy.RuinListener;
+import basics.Job;
+import basics.algo.JobInsertedListener;
+import basics.costs.VehicleRoutingActivityCosts;
+import basics.costs.VehicleRoutingTransportCosts;
+import basics.route.VehicleRoute;
+
+public class UpdateRoute implements JobInsertedListener, RuinListener{
+
+ private TourStateUpdater routeStateUpdater;
+
+ public UpdateRoute(RouteStates routeStates, VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
+ routeStateUpdater = new TourStateUpdater(routeStates, routingCosts, activityCosts);
+ }
+
+ @Override
+ public void informJobInserted(Job job2insert, VehicleRoute inRoute) {
+ routeStateUpdater.updateRoute(inRoute);
+ }
+
+ @Override
+ public void ruinStarts(Collection routes) {}
+
+ @Override
+ public void ruinEnds(Collection routes,Collection unassignedJobs) {
+ for(VehicleRoute route : routes) routeStateUpdater.updateRoute(route);
+ }
+
+ @Override
+ public void removed(Job job, VehicleRoute fromRoute) {}
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
index 51e73e7b..b0d5304a 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithms.java
@@ -37,7 +37,7 @@ import org.apache.log4j.Logger;
import util.RouteUtils;
import algorithms.RuinStrategy.RuinListener;
-import algorithms.VehicleRoutingAlgorithms.TypedMap.AbstractInsertionKey;
+import algorithms.VehicleRoutingAlgorithms.TypedMap.InsertionStrategyKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AbstractKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
import algorithms.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey;
@@ -260,11 +260,11 @@ public class VehicleRoutingAlgorithms {
}
- static class AbstractInsertionKey implements AbstractKey{
+ static class InsertionStrategyKey implements AbstractKey{
private ModKey modKey;
- public AbstractInsertionKey(ModKey modKey) {
+ public InsertionStrategyKey(ModKey modKey) {
super();
this.modKey = modKey;
}
@@ -286,7 +286,7 @@ public class VehicleRoutingAlgorithms {
return false;
if (getClass() != obj.getClass())
return false;
- AbstractInsertionKey other = (AbstractInsertionKey) obj;
+ InsertionStrategyKey other = (InsertionStrategyKey) obj;
if (modKey == null) {
if (other.modKey != null)
return false;
@@ -298,8 +298,8 @@ public class VehicleRoutingAlgorithms {
@Override
- public Class getType() {
- return AbstractInsertionStrategy.class;
+ public Class getType() {
+ return InsertionStrategy.class;
}
}
@@ -535,16 +535,14 @@ public class VehicleRoutingAlgorithms {
private static void registerInsertionListeners(TypedMap definedClasses, List insertionListeners) {
for(AbstractKey> key : definedClasses.keySet()){
- if(key instanceof AbstractInsertionKey){
- AbstractInsertionKey insertionKey = (AbstractInsertionKey) key;
- AbstractInsertionStrategy insertionStrategy = definedClasses.get(insertionKey);
+ if(key instanceof InsertionStrategyKey){
+ InsertionStrategyKey insertionKey = (InsertionStrategyKey) key;
+ InsertionStrategy insertionStrategy = definedClasses.get(insertionKey);
for(InsertionListener l : insertionListeners){
- // log.info("add insertionListener " + l + " to " + insertionStrategy);
insertionStrategy.addListener(l);
}
}
}
- // log.warn("cannot register insertion listeners yet");
}
private static String getName(HierarchicalConfiguration strategyConfig) {
@@ -570,15 +568,15 @@ public class VehicleRoutingAlgorithms {
String insertionId = modConfig.getString("[@id]");
if(insertionId == null) insertionId = "noId";
ModKey modKey = makeKey(insertionName,insertionId);
- AbstractInsertionKey insertionStrategyKey = new AbstractInsertionKey(modKey);
- AbstractInsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey);
+ InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey);
+ InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey);
if(insertionStrategy == null){
List prioListeners = new ArrayList();
insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, activityStates, prioListeners, executorService, nuOfThreads);
algorithmListeners.addAll(prioListeners);
definedClasses.put(insertionStrategyKey,insertionStrategy);
}
- final AbstractInsertionStrategy finalInsertionStrategy = insertionStrategy;
+ final InsertionStrategy finalInsertionStrategy = insertionStrategy;
return new AlgorithmStartsListener() {
@@ -699,8 +697,8 @@ public class VehicleRoutingAlgorithms {
String insertionId = moduleConfig.getString("insertion[@id]");
if(insertionId == null) insertionId = "noId";
ModKey insertionKey = makeKey(insertionName,insertionId);
- AbstractInsertionKey insertionStrategyKey = new AbstractInsertionKey(insertionKey);
- AbstractInsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
+ InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey);
+ InsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
if(insertion == null){
List insertionConfigs = moduleConfig.configurationsAt("insertion");
if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1");
@@ -708,7 +706,7 @@ public class VehicleRoutingAlgorithms {
insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, activityStates, prioListeners, executorService, nuOfThreads);
algorithmListeners.addAll(prioListeners);
}
- final AbstractInsertionStrategy final_insertion = insertion;
+ final InsertionStrategy final_insertion = insertion;
SearchStrategyModule module = new SearchStrategyModule() {
private Logger logger = Logger.getLogger(SearchStrategyModule.class);
@@ -716,7 +714,7 @@ public class VehicleRoutingAlgorithms {
@Override
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
Collection ruinedJobs = ruin.ruin(vrpSolution.getRoutes());
- final_insertion.run(vrpSolution.getRoutes(), ruinedJobs, Double.MAX_VALUE);
+ final_insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobs);
double totalCost = RouteUtils.getTotalCost(vrpSolution.getRoutes());
vrpSolution.setCost(totalCost);
return vrpSolution;
@@ -736,7 +734,7 @@ public class VehicleRoutingAlgorithms {
public void addModuleListener(SearchStrategyModuleListener moduleListener) {
if(moduleListener instanceof InsertionListener){
InsertionListener iListener = (InsertionListener) moduleListener;
- if(!final_insertion.getListener().contains(iListener)){
+ if(!final_insertion.getListeners().contains(iListener)){
logger.info("register moduleListener " + moduleListener);
final_insertion.addListener(iListener);
}
@@ -785,8 +783,8 @@ public class VehicleRoutingAlgorithms {
String insertionId = moduleConfig.getString("insertion[@id]");
if(insertionId == null) insertionId = "noId";
ModKey insertionKey = makeKey(insertionName,insertionId);
- AbstractInsertionKey insertionStrategyKey = new AbstractInsertionKey(insertionKey);
- AbstractInsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
+ InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey);
+ InsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
if(insertion == null){
List insertionConfigs = moduleConfig.configurationsAt("insertion");
if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1");
@@ -864,8 +862,8 @@ public class VehicleRoutingAlgorithms {
return ruin;
}
- private static AbstractInsertionStrategy createInsertionStrategy(HierarchicalConfiguration moduleConfig, VehicleRoutingProblem vrp,VehicleFleetManager vehicleFleetManager, RouteStates activityStates, List algorithmListeners, ExecutorService executorService, int nuOfThreads) {
- AbstractInsertionStrategy insertion = InsertionFactory.createInsertion(vrp, moduleConfig, vehicleFleetManager, activityStates, algorithmListeners, executorService, nuOfThreads);
+ private static InsertionStrategy createInsertionStrategy(HierarchicalConfiguration moduleConfig, VehicleRoutingProblem vrp,VehicleFleetManager vehicleFleetManager, RouteStates activityStates, List algorithmListeners, ExecutorService executorService, int nuOfThreads) {
+ InsertionStrategy insertion = InsertionFactory.createInsertion(vrp, moduleConfig, vehicleFleetManager, activityStates, algorithmListeners, executorService, nuOfThreads);
return insertion;
}
diff --git a/jsprit-core/src/main/java/algorithms/VehicleSwitched.java b/jsprit-core/src/main/java/algorithms/VehicleSwitched.java
index cd0b6bb4..1ffabe42 100644
--- a/jsprit-core/src/main/java/algorithms/VehicleSwitched.java
+++ b/jsprit-core/src/main/java/algorithms/VehicleSwitched.java
@@ -21,7 +21,8 @@
package algorithms;
import basics.route.Vehicle;
-import algorithms.RouteAlgorithm.VehicleSwitchedListener;
+import basics.route.VehicleRoute;
+
class VehicleSwitched implements VehicleSwitchedListener{
@@ -32,7 +33,7 @@ class VehicleSwitched implements VehicleSwitchedListener{
}
@Override
- public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
+ public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) {
fleetManager.unlock(oldVehicle);
fleetManager.lock(newVehicle);
}
diff --git a/jsprit-core/src/main/java/algorithms/VehicleSwitchedListener.java b/jsprit-core/src/main/java/algorithms/VehicleSwitchedListener.java
new file mode 100644
index 00000000..a3589f5d
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/VehicleSwitchedListener.java
@@ -0,0 +1,11 @@
+package algorithms;
+
+import basics.algo.InsertionListener;
+import basics.route.Vehicle;
+import basics.route.VehicleRoute;
+
+interface VehicleSwitchedListener extends InsertionListener{
+
+ public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle);
+
+}
diff --git a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
index 2ab58a40..dc0ee95a 100644
--- a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
+++ b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java
@@ -37,6 +37,7 @@ import basics.Job;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
+import basics.costs.VehicleRoutingActivityCosts;
import basics.costs.VehicleRoutingTransportCosts;
import basics.route.Driver;
import basics.route.DriverImpl;
@@ -60,6 +61,8 @@ public class GendreauPostOptTest {
VehicleRoutingTransportCosts cost;
+ VehicleRoutingActivityCosts activityCosts;
+
VehicleRoutingProblem vrp;
Service job1;
@@ -77,6 +80,8 @@ public class GendreauPostOptTest {
private VehicleFleetManagerImpl fleetManager;
private RouteAlgorithmImpl routeAlgorithm;
+
+ private JobInsertionCalculator insertionCalc;
@Before
public void setUp(){
@@ -148,29 +153,31 @@ public class GendreauPostOptTest {
fleetManager = new VehicleFleetManagerImpl(vehicles);
states = new RouteStates();
- ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction();
+ activityCosts = new ExampleActivityCostFunction();
CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(cost, activityCosts);
standardServiceInsertion.setActivityStates(states);
CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion, states);
withFixCost.setWeightOfFixCost(1.2);
- final JobInsertionCalculator vehicleTypeDepInsertionCost = new CalculatesVehTypeDepServiceInsertion(fleetManager, withFixCost);
+ insertionCalc = new CalculatesVehTypeDepServiceInsertion(fleetManager, withFixCost);
+
updater = new TourStateUpdater(states, cost, activityCosts);
-
- routeAlgorithm = RouteAlgorithmImpl.newInstance(vehicleTypeDepInsertionCost, updater);
- routeAlgorithm.setActivityStates(states);
- if(fleetManager != null){
- routeAlgorithm.getListeners().add(new RouteAlgorithm.VehicleSwitchedListener() {
-
- @Override
- public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
- fleetManager.unlock(oldVehicle);
- fleetManager.lock(newVehicle);
- }
- });
- }
+//
+//
+// routeAlgorithm = RouteAlgorithmImpl.newInstance(insertionCalc, updater);
+// routeAlgorithm.setActivityStates(states);
+// if(fleetManager != null){
+// routeAlgorithm.getListeners().add(new RouteAlgorithm.VehicleSwitchedListener() {
+//
+// @Override
+// public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
+// fleetManager.unlock(oldVehicle);
+// fleetManager.lock(newVehicle);
+// }
+// });
+// }
}
@@ -202,10 +209,17 @@ public class GendreauPostOptTest {
assertEquals(110.0, sol.getCost(), 0.5);
+ UpdateRoute stateUpdater = new UpdateRoute(states, vrp.getTransportCosts(), vrp.getActivityCosts());
+
RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
- AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
+ radialRuin.addListener(stateUpdater);
+
+ InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc);
+ insertionStrategy.addListener(stateUpdater);
+ insertionStrategy.addListener(new VehicleSwitched(fleetManager));
Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setFleetManager(fleetManager);
+
VehicleRoutingProblemSolution newSolution = postOpt.runAndGetSolution(sol);
assertEquals(2,RouteUtils.getNuOfActiveRoutes(newSolution.getRoutes()));
@@ -236,15 +250,17 @@ public class GendreauPostOptTest {
Collection routes = new ArrayList();
routes.add(route);
-// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
-// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, route.getCost());
assertEquals(110.0, sol.getCost(), 0.5);
+ UpdateRoute stateUpdater = new UpdateRoute(states, vrp.getTransportCosts(), vrp.getActivityCosts());
+
RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
- AbstractInsertionStrategy insertionStrategy = new BestInsertion(routeAlgorithm);
+ InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc);
+ insertionStrategy.addListener(stateUpdater);
+ insertionStrategy.addListener(new VehicleSwitched(fleetManager));
Gendreau postOpt = new Gendreau(vrp, radialRuin, insertionStrategy);
postOpt.setShareOfJobsToRuin(1.0);
postOpt.setNuOfIterations(1);
From 50ca0971a5f82427d7fb0504a865b21d9d5af597 Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Mon, 19 Aug 2013 15:08:34 +0200
Subject: [PATCH 30/47] introduce new stateContainer for route and
activityStates
---
...sActivityInsertionWithHardTimeWindows.java | 107 -----------
.../CalculatesServiceInsertion.java | 6 +-
.../java/algorithms/InsertionFactory.java | 2 +-
.../main/java/algorithms/RouteAlgorithm.java | 92 ----------
.../java/algorithms/RouteAlgorithmImpl.java | 171 ------------------
.../src/main/java/algorithms/StateTypes.java | 7 +
.../main/java/algorithms/StatesContainer.java | 50 +++++
.../java/algorithms/StatesContainerImpl.java | 49 +++++
.../java/algorithms/TourStateUpdater.java | 4 +-
.../UpdateTourStatesBackwardInTime.java | 2 +-
.../UpdateTourStatesForwardInTime.java | 2 +-
11 files changed, 114 insertions(+), 378 deletions(-)
delete mode 100644 jsprit-core/src/main/java/algorithms/CalculatesActivityInsertionWithHardTimeWindows.java
delete mode 100644 jsprit-core/src/main/java/algorithms/RouteAlgorithm.java
delete mode 100644 jsprit-core/src/main/java/algorithms/RouteAlgorithmImpl.java
create mode 100644 jsprit-core/src/main/java/algorithms/StateTypes.java
create mode 100644 jsprit-core/src/main/java/algorithms/StatesContainer.java
create mode 100644 jsprit-core/src/main/java/algorithms/StatesContainerImpl.java
diff --git a/jsprit-core/src/main/java/algorithms/CalculatesActivityInsertionWithHardTimeWindows.java b/jsprit-core/src/main/java/algorithms/CalculatesActivityInsertionWithHardTimeWindows.java
deleted file mode 100644
index 3eaf5dc6..00000000
--- a/jsprit-core/src/main/java/algorithms/CalculatesActivityInsertionWithHardTimeWindows.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Stefan Schroeder.
- * eMail: stefan.schroeder@kit.edu
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import org.apache.log4j.Logger;
-
-import algorithms.RouteStates.ActivityState;
-import basics.costs.VehicleRoutingActivityCosts;
-import basics.costs.VehicleRoutingTransportCosts;
-import basics.route.Driver;
-import basics.route.End;
-import basics.route.Start;
-import basics.route.TourActivity;
-import basics.route.Vehicle;
-import basics.route.VehicleRoute;
-
-
-
-final class CalculatesActivityInsertionWithHardTimeWindows {
-
- private static Logger logger = Logger.getLogger(CalculatesActivityInsertionWithHardTimeWindows.class);
-
- private RouteStates routeStates;
-
- private VehicleRoutingTransportCosts routingCosts;
-
- private VehicleRoutingActivityCosts activityCosts;
-
- public CalculatesActivityInsertionWithHardTimeWindows(RouteStates activityStates, VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts){
- this.routeStates = activityStates;
- this.routingCosts = routingCosts;
- this.activityCosts = activityCosts;
- logger.info("initialise " + this);
- }
-
- public double calculate(VehicleRoute vehicleRoute, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, Driver driver, Vehicle vehicle) {
- boolean prevIsStart = false;
-
- if(prevAct instanceof Start){
- prevIsStart = true;
- }
-
- double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), prevAct.getEndTime(), driver, vehicle);
- double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevAct.getEndTime(), driver, vehicle);
-
- double newAct_arrTime = prevAct.getEndTime() + tp_time_prevAct_newAct;
- double newAct_operationStartTime = Math.max(newAct_arrTime, newAct.getTheoreticalEarliestOperationStartTime());
-
- double newAct_endTime = newAct_operationStartTime + newAct.getOperationTime();
-
- double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, driver, vehicle);
-
- double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, driver, vehicle);
- double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, driver, vehicle);
-
- double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct;
- double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, driver, vehicle);
-
- double activityInsertionCosts;
-
- double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + act_costs_newAct + act_costs_nextAct;
-
- if(nextAct_arrTime > getLatestOperationStart(nextAct)){
- activityInsertionCosts = Double.MAX_VALUE;
- }
- else if(vehicleRoute.isEmpty()){
- activityInsertionCosts = totalCosts;
- }
- else{
- double oldCostOfPrevAct;
- if(prevIsStart) oldCostOfPrevAct = 0.0;
- else oldCostOfPrevAct = state(prevAct).getCurrentCost();
- double oldCostOfNextAct;
- if(nextAct instanceof End) oldCostOfNextAct = routeStates.getRouteState(vehicleRoute).getCosts();
- else oldCostOfNextAct = state(nextAct).getCurrentCost();
- activityInsertionCosts = (totalCosts) - (oldCostOfNextAct-oldCostOfPrevAct);
- }
- return activityInsertionCosts;
- }
-
- private ActivityState state(TourActivity act) {
- return routeStates.getState(act);
- }
-
- private double getLatestOperationStart(TourActivity act) {
- if(state(act) != null){
- return state(act).getLatestOperationStart();
- }
- return act.getTheoreticalLatestOperationStartTime();
- }
-
- @Override
- public String toString() {
- return "[name=calculatesHardTimeWindowActivityInsertion]";
- }
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/CalculatesServiceInsertion.java b/jsprit-core/src/main/java/algorithms/CalculatesServiceInsertion.java
index c2c133a2..482036f9 100644
--- a/jsprit-core/src/main/java/algorithms/CalculatesServiceInsertion.java
+++ b/jsprit-core/src/main/java/algorithms/CalculatesServiceInsertion.java
@@ -112,7 +112,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
for(TourActivity nextAct : tour.getActivities()){
double nextCostInOriginalTour = state(nextAct).getCurrentCost();
if(neighborhood.areNeighbors(deliveryAct2Insert.getLocationId(), prevAct.getLocationId()) && neighborhood.areNeighbors(deliveryAct2Insert.getLocationId(), nextAct.getLocationId())){
- double mc = calculate(tour, prevAct, nextAct, deliveryAct2Insert, newDriver, newVehicle, bestCost, nextCostInOriginalTour - prevCostInOriginalTour);
+ double mc = calculate(prevAct, nextAct, deliveryAct2Insert, newDriver, newVehicle, bestCost, nextCostInOriginalTour - prevCostInOriginalTour);
if(mc < bestCost){
bestCost = mc;
insertionIndex = actIndex;
@@ -124,7 +124,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
}
End nextAct = end;
if(neighborhood.areNeighbors(deliveryAct2Insert.getLocationId(), prevAct.getLocationId()) && neighborhood.areNeighbors(deliveryAct2Insert.getLocationId(), nextAct.getLocationId())){
- double mc = calculate(tour, prevAct, nextAct, deliveryAct2Insert, newDriver, newVehicle, bestCost, routeStates.getRouteState(currentRoute).getCosts() - prevCostInOriginalTour);
+ double mc = calculate(prevAct, nextAct, deliveryAct2Insert, newDriver, newVehicle, bestCost, routeStates.getRouteState(currentRoute).getCosts() - prevCostInOriginalTour);
if(mc < bestCost){
bestCost = mc;
insertionIndex = actIndex;
@@ -162,7 +162,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
}
}
- public double calculate(TourActivities tour, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, Driver driver, Vehicle vehicle, double bestKnownCosts, double costWithoutNewJob) {
+ public double calculate(TourActivity prevAct, TourActivity nextAct, TourActivity newAct, Driver driver, Vehicle vehicle, double bestKnownCosts, double costWithoutNewJob) {
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), prevAct.getEndTime(), driver, vehicle);
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevAct.getEndTime(), driver, vehicle);
diff --git a/jsprit-core/src/main/java/algorithms/InsertionFactory.java b/jsprit-core/src/main/java/algorithms/InsertionFactory.java
index de09488d..87ac2502 100644
--- a/jsprit-core/src/main/java/algorithms/InsertionFactory.java
+++ b/jsprit-core/src/main/java/algorithms/InsertionFactory.java
@@ -97,7 +97,7 @@ class InsertionFactory {
TourStateUpdater tourStateCalculator = new TourStateUpdater(activityStates, vrp.getTransportCosts(), vrp.getActivityCosts());
RouteAlgorithm routeAlgorithm = RouteAlgorithmImpl.newInstance(jic, tourStateCalculator);
// routeAlgorithm.getListeners().add(new VehicleSwitched(vehicleFleetManager));
- ((RouteAlgorithmImpl) routeAlgorithm).setActivityStates(activityStates);
+ ((RouteAlgorithmImpl) routeAlgorithm).setStates(activityStates);
if(insertionName.equals("bestInsertion")){
if(concurrentInsertion){
diff --git a/jsprit-core/src/main/java/algorithms/RouteAlgorithm.java b/jsprit-core/src/main/java/algorithms/RouteAlgorithm.java
deleted file mode 100644
index 351a9fa6..00000000
--- a/jsprit-core/src/main/java/algorithms/RouteAlgorithm.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import java.util.Collection;
-
-import basics.Job;
-import basics.route.Vehicle;
-import basics.route.VehicleRoute;
-
-
-interface RouteAlgorithm {
-
- interface RouteAlgorithmListener {
-
- }
-
- interface JobRemovedListener extends RouteAlgorithmListener{
- public void removed(VehicleRoute route, Job job);
- }
-
- interface JobInsertedListener extends RouteAlgorithmListener{
- public void inserted(VehicleRoute route, Job job);
- }
-
- interface VehicleSwitchedListener extends RouteAlgorithmListener{
- public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle);
- }
-
- /**
- * Calculates the best insertion position and the corresponding marginal costs of inserting the job (according to the insertionCostCalculator).
- * This does not affect any input parameter, thus the vehicleRoute and its data will not be changed/affected.
- *
- * @param VehicleRoute, Job, double
- * @return InsertionData
- */
- public InsertionData calculateBestInsertion(VehicleRoute vehicleRoute, Job job, double bestKnownPrice);
-
- /**
- * Removes job from vehicleRoute and does not update the resulting tour. Thus the tour state might not be valid anymore.
- * Note that this changes vehicleRoute!
- *
- * @return true if job removed successfully, otherwise false
- */
- public boolean removeJobWithoutTourUpdate(Job job, VehicleRoute vehicleRoute);
-
- /**
- * Removes job from input parameter vehicleRoute AND updates the state of the resulting tour with tourStateCalc.
- * Note that this changes para vehicleRoute!
- */
- public boolean removeJob(Job job, VehicleRoute vehicleRoute);
-
- /**
- * Inserts job into vehicleRoute.getTour().
- * Please note, that this changes the parameter vehicleRoute!
- */
- public void insertJobWithoutTourUpdate(VehicleRoute vehicleRoute, Job job, InsertionData insertionData);
-
- /**
- * Inserts job into vehicleRoute.getTour().
- * Please note, that this changes the parameter vehicleRoute!
- */
- public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute);
-
- /**
- * Updates vehicleRoute, i.e. uses the tourStateCalculator to update for example timeWindows and loads on vehicleRoute.getTour()
- * Note that this changes the parameter vehicleRoute!
- */
- public void updateTour(VehicleRoute vehicleRoute);
-
- public Collection getListeners();
-
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/RouteAlgorithmImpl.java b/jsprit-core/src/main/java/algorithms/RouteAlgorithmImpl.java
deleted file mode 100644
index 6510d054..00000000
--- a/jsprit-core/src/main/java/algorithms/RouteAlgorithmImpl.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Stefan Schroeder.
- * eMail: stefan.schroeder@kit.edu
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *
- * Contributors:
- * Stefan Schroeder - initial API and implementation
- ******************************************************************************/
-package algorithms;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.log4j.Logger;
-
-import algorithms.RouteStates.ActivityState;
-import algorithms.InsertionData.NoInsertionFound;
-import basics.Job;
-import basics.Service;
-import basics.route.ServiceActivity;
-import basics.route.TourActivity;
-import basics.route.Vehicle;
-import basics.route.VehicleRoute;
-
-
-/**
- *
- * @author stefan schroeder
- *
- */
-
-final class RouteAlgorithmImpl implements RouteAlgorithm {
-
- private static Logger logger = Logger.getLogger(RouteAlgorithmImpl.class);
-
- static double NO_DEPARTURE_TIME = -12345.12345;
-
- private String algoDescription = "algorithm to remove and insert jobs from vehicleRoutes. it also calculates marginal costs of the best insertion of a " +
- "job into the given vehicle route";
-
- public static RouteAlgorithmImpl newInstance(JobInsertionCalculator jobInsertionCalculator, VehicleRouteUpdater tourStateCalculator){
- return new RouteAlgorithmImpl(jobInsertionCalculator, tourStateCalculator);
- }
-
- private Collection listeners = new ArrayList();
-
- private VehicleRouteUpdater tourCalculator;
-
- private JobInsertionCalculator insertionCostCalculator;
-
- private RouteStates actStates;
-
- public void setActivityStates(RouteStates actStates){
- this.actStates = actStates;
- }
-
- public ActivityState state(TourActivity act){
- return actStates.getState(act);
- }
-
- private RouteAlgorithmImpl(JobInsertionCalculator insertionCostCalculator, VehicleRouteUpdater tourCalculator){
- this.tourCalculator = tourCalculator;
- this.insertionCostCalculator = insertionCostCalculator;
- }
-
-
- public InsertionData calculateBestInsertion(VehicleRoute vehicleRoute, Job job, double bestKnownCost) {
- return insertionCostCalculator.calculate(vehicleRoute, job, null, NO_DEPARTURE_TIME, null, bestKnownCost);
- }
-
-
- public boolean removeJobWithoutTourUpdate(Job job, VehicleRoute vehicleRoute) {
- boolean removed = vehicleRoute.getTourActivities().removeJob(job);
- if(removed){
- jobRemoved(vehicleRoute,job);
- }
- return removed;
- }
-
- private void jobRemoved(VehicleRoute vehicleRoute, Job job) {
- for(RouteAlgorithmListener l : listeners){
- if(l instanceof JobRemovedListener){
- ((JobRemovedListener) l).removed(vehicleRoute, job);
- }
- }
- }
-
-
- public boolean removeJob(Job job, VehicleRoute vehicleRoute){
- boolean removed = removeJobWithoutTourUpdate(job, vehicleRoute);
- if(removed) updateTour(vehicleRoute);
- return removed;
- }
-
-
- public void updateTour(VehicleRoute vehicleRoute){
- boolean tourIsFeasible = tourCalculator.updateRoute(vehicleRoute);
- if(!tourIsFeasible){
- throw new IllegalStateException("At this point tour should be feasible. but it is not. \n currentTour=" + vehicleRoute.getTourActivities() +
- "\n error sources: check jobInsertionCostCalculators and actInsertionCalculators. somehow an insertion is made, althought a hard constraint is broken. Here, hard constraints refer to \n" +
- "hard time-window constraints. If you want to deal with such constraints, make sure a violation is penalized properly (such that it can never be the best insertion position). \n" +
- "If you use CalculatesServiceInsertion and CalculatesActivityInsertion, the only hard constraint is the vehicle-capacity constraints. A violation of time-windows must be penalized in \n" +
- "the vehicleRouteCostFunction. For example: in handleActivity(....) one can check whether the act start-time is higher than the latestOperationStartTime. If so penalize it with a very high value. \n" +
- "For example: \n" +
- "public void handleActivity(TourActivity tourAct, double startTime, double endTime) {\n" +
- "\tif(startTime > tourAct.getLatestOperationStartTime()){\n" +
- "\t\tcost += Double.MAX_VALUE;\n" +
- "\t}\n" +
- "});");
- }
- }
-
-
- @Override
- public void insertJobWithoutTourUpdate(VehicleRoute vehicleRoute, Job job, InsertionData insertionData) {
- if(insertionData == null || (insertionData instanceof NoInsertionFound)) throw new IllegalStateException("insertionData null. cannot insert job.");
- if(job == null) throw new IllegalStateException("cannot insert null-job");
- if(!(vehicleRoute.getVehicle().getId().toString().equals(insertionData.getSelectedVehicle().getId().toString()))){
- vehicleSwitched(vehicleRoute.getVehicle(),insertionData.getSelectedVehicle());
- vehicleRoute.setVehicle(insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime());
- }
- if(job instanceof Service) {
- vehicleRoute.getTourActivities().addActivity(insertionData.getDeliveryInsertionIndex(), ServiceActivity.newInstance((Service)job));
- vehicleRoute.setDepartureTime(insertionData.getVehicleDepartureTime());
- }
- else throw new IllegalStateException("neither service nor shipment. this is not supported.");
- jobInserted(vehicleRoute,job);
- }
-
-
-
- private void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) {
- for(RouteAlgorithmListener l : listeners){
- if(l instanceof VehicleSwitchedListener){
- ((VehicleSwitchedListener) l).vehicleSwitched(oldVehicle,newVehicle);
- }
- }
- }
-
- private void jobInserted(VehicleRoute vehicleRoute, Job job) {
- for(RouteAlgorithmListener l : listeners){
- if(l instanceof JobInsertedListener){
- ((JobInsertedListener) l).inserted(vehicleRoute, job);
- }
- }
- }
-
-
- public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute){
- insertJobWithoutTourUpdate(vehicleRoute, job, insertionData);
- updateTour(vehicleRoute);
- }
-
- @Override
- public String toString() {
- return algoDescription;
- }
-
- public Collection getListeners() {
- return listeners;
- }
-
- public void setAlgoDescription(String algoDescription) {
- this.algoDescription = algoDescription;
- }
-
-}
diff --git a/jsprit-core/src/main/java/algorithms/StateTypes.java b/jsprit-core/src/main/java/algorithms/StateTypes.java
new file mode 100644
index 00000000..21bdde4e
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/StateTypes.java
@@ -0,0 +1,7 @@
+package algorithms;
+
+class StateTypes {
+ final static String LOAD = "load";
+
+ final static String DURATION = "duration";
+}
diff --git a/jsprit-core/src/main/java/algorithms/StatesContainer.java b/jsprit-core/src/main/java/algorithms/StatesContainer.java
new file mode 100644
index 00000000..99a16897
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/StatesContainer.java
@@ -0,0 +1,50 @@
+package algorithms;
+
+import java.util.Map;
+
+import basics.route.TourActivity;
+import basics.route.VehicleRoute;
+
+interface StatesContainer {
+
+ interface State {
+ double getState();
+ }
+
+ class StateImpl implements State{
+ double state;
+
+ public StateImpl(double state) {
+ super();
+ this.state = state;
+ }
+
+ @Override
+ public double getState() {
+ return state;
+ }
+
+// public void setState(double val){
+// state=val;
+// }
+ }
+
+ interface States {
+
+// void putState(String key, State state);
+
+ State getState(String key);
+
+ }
+
+
+
+ Map getRouteStates();
+
+// void put(VehicleRoute route, States states);
+
+ Map getActivityStates();
+
+// void put(TourActivity act, States states);
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/StatesContainerImpl.java b/jsprit-core/src/main/java/algorithms/StatesContainerImpl.java
new file mode 100644
index 00000000..b54e939a
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/StatesContainerImpl.java
@@ -0,0 +1,49 @@
+package algorithms;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import basics.route.TourActivity;
+import basics.route.VehicleRoute;
+
+public class StatesContainerImpl implements StatesContainer{
+
+ class StatesImpl implements States{
+
+ private Map states = new HashMap();
+
+ public void putState(String key, State state) {
+ states.put(key, state);
+ }
+
+ @Override
+ public State getState(String key) {
+ return states.get(key);
+ }
+
+ }
+
+ private Map vehicleRoutes = new HashMap();
+
+ private Map tourActivities = new HashMap();
+
+ @Override
+ public Map getRouteStates() {
+ return Collections.unmodifiableMap(vehicleRoutes);
+ }
+
+ public void put(VehicleRoute route, States states) {
+ vehicleRoutes.put(route, states);
+ }
+
+ @Override
+ public Map getActivityStates() {
+ return Collections.unmodifiableMap(tourActivities);
+ }
+
+ public void put(TourActivity act, States states) {
+ tourActivities.put(act, states);
+ }
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/TourStateUpdater.java b/jsprit-core/src/main/java/algorithms/TourStateUpdater.java
index b46af2ec..b98e3896 100644
--- a/jsprit-core/src/main/java/algorithms/TourStateUpdater.java
+++ b/jsprit-core/src/main/java/algorithms/TourStateUpdater.java
@@ -61,8 +61,8 @@ class TourStateUpdater implements VehicleRouteUpdater{
forwardUpdate = new UpdateTourStatesForwardInTime(costs, costs, costFunction);
backwardUpdate = new UpdateTourStatesBackwardInTime(costs);
actStates=activityStates;
- forwardUpdate.setActivityStates(actStates);
- backwardUpdate.setActivityStates(actStates);
+ forwardUpdate.setStates(actStates);
+ backwardUpdate.setStates(actStates);
}
/*
diff --git a/jsprit-core/src/main/java/algorithms/UpdateTourStatesBackwardInTime.java b/jsprit-core/src/main/java/algorithms/UpdateTourStatesBackwardInTime.java
index 19a8d5e3..8a84a1d6 100644
--- a/jsprit-core/src/main/java/algorithms/UpdateTourStatesBackwardInTime.java
+++ b/jsprit-core/src/main/java/algorithms/UpdateTourStatesBackwardInTime.java
@@ -46,7 +46,7 @@ class UpdateTourStatesBackwardInTime implements VehicleRouteUpdater{
private RouteStates actStates;
- public void setActivityStates(RouteStates actStates){
+ public void setStates(RouteStates actStates){
this.actStates = actStates;
}
diff --git a/jsprit-core/src/main/java/algorithms/UpdateTourStatesForwardInTime.java b/jsprit-core/src/main/java/algorithms/UpdateTourStatesForwardInTime.java
index 96732e5c..9c534b4a 100644
--- a/jsprit-core/src/main/java/algorithms/UpdateTourStatesForwardInTime.java
+++ b/jsprit-core/src/main/java/algorithms/UpdateTourStatesForwardInTime.java
@@ -50,7 +50,7 @@ class UpdateTourStatesForwardInTime implements VehicleRouteUpdater{
private boolean activityStatesSet = false;
- public void setActivityStates(RouteStates actStates){
+ public void setStates(RouteStates actStates){
this.routeStates = actStates;
activityStatesSet = true;
}
From 099d01ddd8682513033f193163512bd26c3f5e7a Mon Sep 17 00:00:00 2001
From: Stefan Schroeder <4sschroeder@gmail.com>
Date: Wed, 21 Aug 2013 13:53:27 +0200
Subject: [PATCH 31/47] experiment with insertionCalcs
---
.../algorithms/BackwardInTimeListeners.java | 50 ++
.../algorithms/BestInsertionConcurrent.java | 352 +++++++-------
.../CalculatesServiceInsertion.java | 60 +--
...tesServiceInsertionConsideringFixCost.java | 16 +-
...alculatesServiceInsertionOnRouteLevel.java | 22 +-
...erviceInsertionWithTriangleInequality.java | 211 ++++++++
.../CalculatesVehTypeDepServiceInsertion.java | 15 +-
.../java/algorithms/CalculatorBuilder.java | 36 +-
.../ConfigureFixCostCalculator.java | 2 +-
.../algorithms/FindCheaperVehicleAlgo.java | 2 +-
.../algorithms/ForwardInTimeListeners.java | 39 ++
.../main/java/algorithms/HardConstraint.java | 7 +
.../src/main/java/algorithms/Inserter.java | 2 +-
.../main/java/algorithms/InsertionData.java | 16 +
.../java/algorithms/InsertionFactory.java | 27 +-
.../java/algorithms/InsertionListeners.java | 4 +-
.../IterateRouteBackwardInTime.java | 69 +++
.../algorithms/IterateRouteForwardInTime.java | 85 ++++
.../src/main/java/algorithms/JobObserver.java | 2 +-
.../main/java/algorithms/RegretInsertion.java | 456 +++++++++---------
.../src/main/java/algorithms/StateTypes.java | 8 +-
.../main/java/algorithms/StatesContainer.java | 8 +-
.../java/algorithms/StatesContainerImpl.java | 92 +++-
.../java/algorithms/TourStateUpdater.java | 91 ----
.../algorithms/UdateCostsAtRouteLevel.java | 53 ++
.../java/algorithms/UpdateActivityTimes.java | 26 +
.../algorithms/UpdateCostsAtAllLevels.java | 81 ++++
...EarliestStartTimeWindowAtActLocations.java | 31 ++
...atestOperationStartTimeAtActLocations.java | 32 ++
.../algorithms/UpdateLoadAtAllLevels.java | 46 ++
.../algorithms/UpdateLoadAtRouteLevel.java | 42 ++
.../src/main/java/algorithms/UpdateRoute.java | 36 --
.../main/java/algorithms/UpdateStates.java | 55 +++
.../UpdateTourStatesBackwardInTime.java | 105 ----
.../UpdateTourStatesForwardInTime.java | 156 ------
.../java/algorithms/VehicleRouteUpdater.java | 2 +-
.../algorithms/VehicleRoutingAlgorithms.java | 95 ++--
.../java/basics/algo/JobInsertedListener.java | 2 +-
.../src/main/java/basics/route/End.java | 1 +
.../test/java/algorithms/AlgorithmsSuite.java | 1 -
.../java/algorithms/GendreauPostOptTest.java | 64 +--
.../TestCalculatesActivityInsertion.java | 286 -----------
.../TestCalculatesServiceInsertion.java | 44 +-
...alculatesServiceInsertionOnRouteLevel.java | 14 +-
.../TestIterateRouteForwardInTime.java | 196 ++++++++
.../TestTourStateUpdaterWithService.java | 10 +-
jsprit-examples/input/algorithmConfig.xml | 4 +-
47 files changed, 1711 insertions(+), 1343 deletions(-)
create mode 100644 jsprit-core/src/main/java/algorithms/BackwardInTimeListeners.java
create mode 100644 jsprit-core/src/main/java/algorithms/CalculatesServiceInsertionWithTriangleInequality.java
create mode 100644 jsprit-core/src/main/java/algorithms/ForwardInTimeListeners.java
create mode 100644 jsprit-core/src/main/java/algorithms/HardConstraint.java
create mode 100644 jsprit-core/src/main/java/algorithms/IterateRouteBackwardInTime.java
create mode 100644 jsprit-core/src/main/java/algorithms/IterateRouteForwardInTime.java
delete mode 100644 jsprit-core/src/main/java/algorithms/TourStateUpdater.java
create mode 100644 jsprit-core/src/main/java/algorithms/UdateCostsAtRouteLevel.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateActivityTimes.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateCostsAtAllLevels.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateEarliestStartTimeWindowAtActLocations.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateLatestOperationStartTimeAtActLocations.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateLoadAtAllLevels.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateLoadAtRouteLevel.java
delete mode 100644 jsprit-core/src/main/java/algorithms/UpdateRoute.java
create mode 100644 jsprit-core/src/main/java/algorithms/UpdateStates.java
delete mode 100644 jsprit-core/src/main/java/algorithms/UpdateTourStatesBackwardInTime.java
delete mode 100644 jsprit-core/src/main/java/algorithms/UpdateTourStatesForwardInTime.java
delete mode 100644 jsprit-core/src/test/java/algorithms/TestCalculatesActivityInsertion.java
create mode 100644 jsprit-core/src/test/java/algorithms/TestIterateRouteForwardInTime.java
diff --git a/jsprit-core/src/main/java/algorithms/BackwardInTimeListeners.java b/jsprit-core/src/main/java/algorithms/BackwardInTimeListeners.java
new file mode 100644
index 00000000..1904155b
--- /dev/null
+++ b/jsprit-core/src/main/java/algorithms/BackwardInTimeListeners.java
@@ -0,0 +1,50 @@
+package algorithms;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import basics.route.TourActivity;
+import basics.route.VehicleRoute;
+
+class BackwardInTimeListeners {
+
+ interface BackwardInTimeListener{
+
+ public void start(VehicleRoute route);
+
+ public void prevActivity(TourActivity act, double latestDepartureTime, double latestOperationStartTime);
+
+ public void finnish();
+
+ }
+
+ private Collection listeners = new ArrayList();
+
+ public void addListener(BackwardInTimeListener l){
+ listeners.add(l);
+ }
+
+ public void start(VehicleRoute route){
+ for(BackwardInTimeListener l : listeners){ l.start(route); }
+ }
+
+ /**
+ * Informs listener about nextActivity.
+ *
+ * LatestDepartureTime is the theoretical latest departureTime to meet the latestOperationStartTimeWindow at the nextActivity (forward in time), i.e.
+ * assume act_i and act_j are two successive activities and the latestDepTime of act_j is 10pm. With a travelTime from act_i to act_j of 1h the latestDepartureTime at act_i is 9pm.
+ * However, the latestOperationStartTime of act_i is 8pm, then (with a serviceTime of 0) the latestOperationStartTime at act_i amounts to 8pm.
+ *
+ * @param act
+ * @param latestDepartureTime
+ * @param latestOperationStartTime
+ */
+ public void prevActivity(TourActivity act, double latestDepartureTime, double latestOperationStartTime){
+ for(BackwardInTimeListener l : listeners){ l.prevActivity(act,latestDepartureTime,latestOperationStartTime); }
+ }
+
+ public void finnish(){
+ for(BackwardInTimeListener l : listeners){ l.finnish(); }
+ }
+
+}
diff --git a/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java b/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
index 742e29b4..4f41d2e0 100644
--- a/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
+++ b/jsprit-core/src/main/java/algorithms/BestInsertionConcurrent.java
@@ -33,182 +33,182 @@ import basics.Job;
import basics.algo.InsertionListener;
import basics.route.VehicleRoute;
-
-
-/**
- *
- * @author stefan schroeder
- *
- */
-
-final class BestInsertionConcurrent implements InsertionStrategy{
-
- public static BestInsertionConcurrent newInstance(RouteAlgorithm routeAlgorithm, ExecutorService executor, int nuOfThreads){
- return new BestInsertionConcurrent(routeAlgorithm, executor, nuOfThreads);
- }
-
- static class Batch {
- List routes = new ArrayList();
-
- }
-
- private static Logger logger = Logger.getLogger(BestInsertionConcurrent.class);
-
- private Random random = RandomNumberGeneration.getRandom();
-
- private RouteAlgorithm routeAlgorithm;
-
-// private ExecutorService executor;
-
- private int nuOfBatches;
-
- private ExecutorCompletionService completionService;
-
- public void setRandom(Random random) {
- this.random = random;
- }
-
- private BestInsertionConcurrent(RouteAlgorithm routeAlgorithm, ExecutorService executor, int nuOfThreads) {
- super();
- this.routeAlgorithm = routeAlgorithm;
-// this.executor = executor;
- logger.info("initialise " + this);
- this.nuOfBatches = nuOfThreads;
- completionService = new ExecutorCompletionService(executor);
- }
-
- @Override
- public String toString() {
- return "[name=concurrentBestInsertion]";
- }
-
- @Override
- public void insertJobs(Collection vehicleRoutes, Collection unassignedJobs) {
- List unassignedJobList = new ArrayList(unassignedJobs);
- Collections.shuffle(unassignedJobList, random);
-// informInsertionStarts(vehicleRoutes,unassignedJobs.size());
- int inserted = 0;
- for(final Job unassignedJob : unassignedJobList){
- VehicleRoute insertIn = null;
- Insertion bestInsertion = null;
- double bestInsertionCost = Double.MAX_VALUE;
-
- List batches = distributeRoutes(vehicleRoutes,nuOfBatches);
-
- for(final Batch batch : batches){
- completionService.submit(new Callable() {
-
- @Override
- public Insertion call() throws Exception {
- return getBestInsertion(batch,unassignedJob);
- }
-
- });
-
- }
-
- try{
- for(int i=0;i futureIData = completionService.take();
- Insertion insertion = futureIData.get();
- if(insertion == null) continue;
- if(insertion.getInsertionData().getInsertionCost() < bestInsertionCost){
- bestInsertion = insertion;
- bestInsertionCost = insertion.getInsertionData().getInsertionCost();
- }
- }
- }
- catch(InterruptedException e){
- Thread.currentThread().interrupt();
- }
- catch (ExecutionException e) {
- e.printStackTrace();
- logger.error(e.getCause().toString());
- System.exit(1);
- }
-
- if(bestInsertion != null){
-// informBeforeJobInsertion(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
- insertIn = bestInsertion.getRoute();
-// logger.debug("insert job="+unassignedJob+" at index=" + bestInsertion.getInsertionData().getInsertionIndex() + " delta cost=" + bestInsertion.getInsertionData().getInsertionCost());
- routeAlgorithm.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
- }
- else {
-// VehicleRoute newRoute = VehicleRoute.emptyRoute();
-// InsertionData bestI = routeAlgorithm.calculateBestInsertion(newRoute, unassignedJob, Double.MAX_VALUE);
-// if(bestI instanceof InsertionData.NoInsertionFound)
- throw new IllegalStateException("given the vehicles, could not create a valid solution.\n\tthe reason might be" +
- " inappropriate vehicle capacity.\n\tthe job that does not fit in any vehicle anymore is \n\t" + unassignedJob);
-// insertIn = newRoute;
-// informBeforeJobInsertion(unassignedJob,bestI,newRoute);
-// routeAlgorithm.insertJob(unassignedJob,bestI,newRoute);
-// vehicleRoutes.add(newRoute);
- }
- inserted++;
-// informJobInserted((unassignedJobList.size()-inserted), unassignedJob, insertIn);
- }
-// informInsertionEndsListeners(vehicleRoutes);
- }
-
- private Insertion getBestInsertion(Batch batch, Job unassignedJob) {
- Insertion bestInsertion = null;
- double bestInsertionCost = Double.MAX_VALUE;
- for(VehicleRoute vehicleRoute : batch.routes){
- InsertionData iData = routeAlgorithm.calculateBestInsertion(vehicleRoute, unassignedJob, bestInsertionCost);
- if(iData instanceof NoInsertionFound) continue;
- if(iData.getInsertionCost() < bestInsertionCost){
- bestInsertion = new Insertion(vehicleRoute,iData);
- bestInsertionCost = iData.getInsertionCost();
- }
- }
- return bestInsertion;
- }
-
- private List distributeRoutes(Collection vehicleRoutes, int nuOfBatches) {
- List batches = new ArrayList();
- for(int i=0;i routes = new ArrayList();
+//
+// }
+//
+// private static Logger logger = Logger.getLogger(BestInsertionConcurrent.class);
+//
+// private Random random = RandomNumberGeneration.getRandom();
+//
+// private RouteAlgorithm routeAlgorithm;
+//
+//// private ExecutorService executor;
+//
+// private int nuOfBatches;
+//
+// private ExecutorCompletionService completionService;
+//
+// public void setRandom(Random random) {
+// this.random = random;
+// }
+//
+// private BestInsertionConcurrent(RouteAlgorithm routeAlgorithm, ExecutorService executor, int nuOfThreads) {
+// super();
+// this.routeAlgorithm = routeAlgorithm;
+//// this.executor = executor;
+// logger.info("initialise " + this);
+// this.nuOfBatches = nuOfThreads;
+// completionService = new ExecutorCompletionService(executor);
+// }
+//
+// @Override
+// public String toString() {
+// return "[name=concurrentBestInsertion]";
+// }
+//
+// @Override
+// public void insertJobs(Collection vehicleRoutes, Collection unassignedJobs) {
+// List unassignedJobList = new ArrayList(unassignedJobs);
+// Collections.shuffle(unassignedJobList, random);
+//// informInsertionStarts(vehicleRoutes,unassignedJobs.size());
+// int inserted = 0;
+// for(final Job unassignedJob : unassignedJobList){
+// VehicleRoute insertIn = null;
+// Insertion bestInsertion = null;
+// double bestInsertionCost = Double.MAX_VALUE;
+//
+// List batches = distributeRoutes(vehicleRoutes,nuOfBatches);
+//
+// for(final Batch batch : batches){
+// completionService.submit(new Callable() {
+//
+// @Override
+// public Insertion call() throws Exception {
+// return getBestInsertion(batch,unassignedJob);
+// }
+//
+// });
+//
+// }
+//
+// try{
+// for(int i=0;i futureIData = completionService.take();
+// Insertion insertion = futureIData.get();
+// if(insertion == null) continue;
+// if(insertion.getInsertionData().getInsertionCost() < bestInsertionCost){
+// bestInsertion = insertion;
+// bestInsertionCost = insertion.getInsertionData().getInsertionCost();
+// }
+// }
+// }
+// catch(InterruptedException e){
+// Thread.currentThread().interrupt();
+// }
+// catch (ExecutionException e) {
+// e.printStackTrace();
+// logger.error(e.getCause().toString());
+// System.exit(1);
+// }
+//
+// if(bestInsertion != null){
+//// informBeforeJobInsertion(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
+// insertIn = bestInsertion.getRoute();
+//// logger.debug("insert job="+unassignedJob+" at index=" + bestInsertion.getInsertionData().getInsertionIndex() + " delta cost=" + bestInsertion.getInsertionData().getInsertionCost());
+// routeAlgorithm.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
+// }
+// else {
+//// VehicleRoute newRoute = VehicleRoute.emptyRoute();
+//// InsertionData bestI = routeAlgorithm.calculateBestInsertion(newRoute, unassignedJob, Double.MAX_VALUE);
+//// if(bestI instanceof InsertionData.NoInsertionFound)
+// throw new IllegalStateException("given the vehicles, could not create a valid solution.\n\tthe reason might be" +
+// " inappropriate vehicle capacity.\n\tthe job that does not fit in any vehicle anymore is \n\t" + unassignedJob);
+//// insertIn = newRoute;
+//// informBeforeJobInsertion(unassignedJob,bestI,newRoute);
+//// routeAlgorithm.insertJob(unassignedJob,bestI,newRoute);
+//// vehicleRoutes.add(newRoute);
+// }
+// inserted++;
+//// informJobInserted((unassignedJobList.size()-inserted), unassignedJob, insertIn);
+// }
+//// informInsertionEndsListeners(vehicleRoutes);
+// }
+//
+// private Insertion getBestInsertion(Batch batch, Job unassignedJob) {
+// Insertion bestInsertion = null;
+// double bestInsertionCost = Double.MAX_VALUE;
+// for(VehicleRoute vehicleRoute : batch.routes){
+// InsertionData iData = routeAlgorithm.calculateBestInsertion(vehicleRoute, unassignedJob, bestInsertionCost);
+// if(iData instanceof NoInsertionFound) continue;
+// if(iData.getInsertionCost() < bestInsertionCost){
+// bestInsertion = new Insertion(vehicleRoute,iData);
+// bestInsertionCost = iData.getInsertionCost();
// }
// }
-// else{
- vehicleRoutes.add(VehicleRoute.emptyRoute());
+// return bestInsertion;
+// }
+//
+// private List distributeRoutes(Collection vehicleRoutes, int nuOfBatches) {
+// List