mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
internal refactoring of insertionStrategy
This commit is contained in:
parent
5b0857d6bf
commit
cd65f66c86
5 changed files with 69 additions and 7 deletions
|
|
@ -45,6 +45,8 @@ final class BestInsertion extends AbstractInsertionStrategy{
|
||||||
|
|
||||||
private Random random = RandomNumberGeneration.getRandom();
|
private Random random = RandomNumberGeneration.getRandom();
|
||||||
|
|
||||||
|
private InsertionListeners insertionsListeners;
|
||||||
|
|
||||||
private RouteAlgorithm routeAlgorithm;
|
private RouteAlgorithm routeAlgorithm;
|
||||||
|
|
||||||
public void setExperimentalPreferredRoute(Map<String, VehicleRoute> experimentalPreferredRoute) {
|
public void setExperimentalPreferredRoute(Map<String, VehicleRoute> experimentalPreferredRoute) {
|
||||||
|
|
@ -67,6 +69,7 @@ final class BestInsertion extends AbstractInsertionStrategy{
|
||||||
public BestInsertion(RouteAlgorithm routeAlgorithm) {
|
public BestInsertion(RouteAlgorithm routeAlgorithm) {
|
||||||
super();
|
super();
|
||||||
this.routeAlgorithm = routeAlgorithm;
|
this.routeAlgorithm = routeAlgorithm;
|
||||||
|
this.insertionsListeners = new InsertionListeners();
|
||||||
logger.info("initialise " + this);
|
logger.info("initialise " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +90,6 @@ final class BestInsertion extends AbstractInsertionStrategy{
|
||||||
int inserted = 0;
|
int inserted = 0;
|
||||||
List<String> reasons = new ArrayList<String>();
|
List<String> reasons = new ArrayList<String>();
|
||||||
for(Job unassignedJob : unassignedJobList){
|
for(Job unassignedJob : unassignedJobList){
|
||||||
|
|
||||||
VehicleRoute insertIn = null;
|
VehicleRoute insertIn = null;
|
||||||
Insertion bestInsertion = null;
|
Insertion bestInsertion = null;
|
||||||
double bestInsertionCost = Double.MAX_VALUE;
|
double bestInsertionCost = Double.MAX_VALUE;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ final class CreateInitialSolution implements InitialSolutionFactory {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(CreateInitialSolution.class);
|
private static final Logger logger = Logger.getLogger(CreateInitialSolution.class);
|
||||||
|
|
||||||
private final AbstractInsertionStrategy insertion;
|
private final InsertionStrategy insertion;
|
||||||
|
|
||||||
private boolean generateAsMuchAsRoutesAsVehiclesExist = false;
|
private boolean generateAsMuchAsRoutesAsVehiclesExist = false;
|
||||||
|
|
||||||
|
|
@ -59,9 +59,9 @@ final class CreateInitialSolution implements InitialSolutionFactory {
|
||||||
this.generateAsMuchAsRoutesAsVehiclesExist = generateAsMuchAsRoutesAsVehiclesExist;
|
this.generateAsMuchAsRoutesAsVehiclesExist = generateAsMuchAsRoutesAsVehiclesExist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateInitialSolution(AbstractInsertionStrategy insertion) {
|
public CreateInitialSolution(InsertionStrategy insertionStrategy) {
|
||||||
super();
|
super();
|
||||||
this.insertion = insertion;
|
this.insertion = insertionStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ final class Gendreau implements SearchStrategyModule{
|
||||||
|
|
||||||
private final VehicleRoutingProblem vrp;
|
private final VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
private final AbstractInsertionStrategy insertionStrategy;
|
private final InsertionStrategy insertionStrategy;
|
||||||
|
|
||||||
private final RouteAlgorithm routeAlgorithm;
|
private final RouteAlgorithm routeAlgorithm;
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ final class Gendreau implements SearchStrategyModule{
|
||||||
this.shareOfJobsToRuin = shareOfJobsToRuin;
|
this.shareOfJobsToRuin = shareOfJobsToRuin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, AbstractInsertionStrategy insertionStrategy) {
|
public Gendreau(VehicleRoutingProblem vrp, RuinStrategy ruin, InsertionStrategy insertionStrategy) {
|
||||||
super();
|
super();
|
||||||
this.routeAlgorithm = insertionStrategy.getRouteAlgorithm();
|
this.routeAlgorithm = insertionStrategy.getRouteAlgorithm();
|
||||||
this.ruin = ruin;
|
this.ruin = ruin;
|
||||||
|
|
|
||||||
57
jsprit-core/src/main/java/algorithms/InsertionListeners.java
Normal file
57
jsprit-core/src/main/java/algorithms/InsertionListeners.java
Normal file
|
|
@ -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<InsertionListener> listeners = new ArrayList<InsertionListener>();
|
||||||
|
|
||||||
|
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<VehicleRoute> vehicleRoutes, int nOfJobs2Recreate){
|
||||||
|
for(InsertionListener l : listeners){
|
||||||
|
if(l instanceof InsertionStartsListener){
|
||||||
|
((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes,nOfJobs2Recreate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void informInsertionEndsListeners(Collection<VehicleRoute> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ package algorithms;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
|
import basics.algo.InsertionListener;
|
||||||
import basics.route.VehicleRoute;
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,4 +64,6 @@ interface InsertionStrategy {
|
||||||
*/
|
*/
|
||||||
public void run(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs, double result2beat);
|
public void run(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs, double result2beat);
|
||||||
|
|
||||||
|
public void addListener(InsertionListener insertionListener);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue