mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
make it even easier to implement new InsertionStrategies
This commit is contained in:
parent
51c14afd73
commit
8ed138dddc
6 changed files with 102 additions and 41 deletions
|
|
@ -126,7 +126,7 @@ public class BestInsertionBuilder {
|
||||||
public InsertionStrategy build() {
|
public InsertionStrategy build() {
|
||||||
List<InsertionListener> iListeners = new ArrayList<InsertionListener>();
|
List<InsertionListener> iListeners = new ArrayList<InsertionListener>();
|
||||||
List<PrioritizedVRAListener> algorithmListeners = new ArrayList<PrioritizedVRAListener>();
|
List<PrioritizedVRAListener> algorithmListeners = new ArrayList<PrioritizedVRAListener>();
|
||||||
CalculatorBuilder calcBuilder = new CalculatorBuilder(iListeners, algorithmListeners);
|
JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners);
|
||||||
if(local){
|
if(local){
|
||||||
calcBuilder.setLocalLevel(addDefaultCostCalc);
|
calcBuilder.setLocalLevel(addDefaultCostCalc);
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +134,7 @@ public class BestInsertionBuilder {
|
||||||
calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc);
|
calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc);
|
||||||
}
|
}
|
||||||
calcBuilder.setConstraintManager(constraintManager);
|
calcBuilder.setConstraintManager(constraintManager);
|
||||||
calcBuilder.setStates(stateManager);
|
calcBuilder.setStateManager(stateManager);
|
||||||
calcBuilder.setVehicleRoutingProblem(vrp);
|
calcBuilder.setVehicleRoutingProblem(vrp);
|
||||||
calcBuilder.setVehicleFleetManager(fleetManager);
|
calcBuilder.setVehicleFleetManager(fleetManager);
|
||||||
calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator);
|
calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator);
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class InsertionBuilder {
|
||||||
public InsertionStrategy build() {
|
public InsertionStrategy build() {
|
||||||
List<InsertionListener> iListeners = new ArrayList<InsertionListener>();
|
List<InsertionListener> iListeners = new ArrayList<InsertionListener>();
|
||||||
List<PrioritizedVRAListener> algorithmListeners = new ArrayList<PrioritizedVRAListener>();
|
List<PrioritizedVRAListener> algorithmListeners = new ArrayList<PrioritizedVRAListener>();
|
||||||
CalculatorBuilder calcBuilder = new CalculatorBuilder(iListeners, algorithmListeners);
|
JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners);
|
||||||
if(local){
|
if(local){
|
||||||
calcBuilder.setLocalLevel(addDefaultCostCalc);
|
calcBuilder.setLocalLevel(addDefaultCostCalc);
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +145,7 @@ public class InsertionBuilder {
|
||||||
calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc);
|
calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc);
|
||||||
}
|
}
|
||||||
calcBuilder.setConstraintManager(constraintManager);
|
calcBuilder.setConstraintManager(constraintManager);
|
||||||
calcBuilder.setStates(stateManager);
|
calcBuilder.setStateManager(stateManager);
|
||||||
calcBuilder.setVehicleRoutingProblem(vrp);
|
calcBuilder.setVehicleRoutingProblem(vrp);
|
||||||
calcBuilder.setVehicleFleetManager(fleetManager);
|
calcBuilder.setVehicleFleetManager(fleetManager);
|
||||||
calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator);
|
calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -28,7 +28,7 @@ import jsprit.core.problem.vehicle.Vehicle;
|
||||||
*/
|
*/
|
||||||
public class InsertionData {
|
public class InsertionData {
|
||||||
|
|
||||||
static class NoInsertionFound extends InsertionData{
|
public static class NoInsertionFound extends InsertionData{
|
||||||
|
|
||||||
public NoInsertionFound() {
|
public NoInsertionFound() {
|
||||||
super(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null);
|
super(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -34,7 +34,7 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CalculatorBuilder {
|
public class JobInsertionCostsCalculatorBuilder {
|
||||||
|
|
||||||
private static class CalculatorPlusListeners {
|
private static class CalculatorPlusListeners {
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ class CalculatorBuilder {
|
||||||
* @param insertionListeners
|
* @param insertionListeners
|
||||||
* @param algorithmListeners
|
* @param algorithmListeners
|
||||||
*/
|
*/
|
||||||
public CalculatorBuilder(List<InsertionListener> insertionListeners, List<PrioritizedVRAListener> algorithmListeners) {
|
public JobInsertionCostsCalculatorBuilder(List<InsertionListener> insertionListeners, List<PrioritizedVRAListener> algorithmListeners) {
|
||||||
super();
|
super();
|
||||||
this.insertionListeners = insertionListeners;
|
this.insertionListeners = insertionListeners;
|
||||||
this.algorithmListeners = algorithmListeners;
|
this.algorithmListeners = algorithmListeners;
|
||||||
|
|
@ -112,12 +112,12 @@ class CalculatorBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets activityStates. MUST be set.
|
* Sets activityStates. MUST be set.
|
||||||
* @param states TODO
|
* @param stateManager TODO
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CalculatorBuilder setStates(RouteAndActivityStateGetter states){
|
public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager){
|
||||||
this.states = states;
|
this.states = stateManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ class CalculatorBuilder {
|
||||||
* @param vehicleRoutingProblem
|
* @param vehicleRoutingProblem
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem){
|
public JobInsertionCostsCalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem){
|
||||||
this.vrp = vehicleRoutingProblem;
|
this.vrp = vehicleRoutingProblem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +138,7 @@ class CalculatorBuilder {
|
||||||
* @param fleetManager
|
* @param fleetManager
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager){
|
public JobInsertionCostsCalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager){
|
||||||
this.fleetManager = fleetManager;
|
this.fleetManager = fleetManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -149,13 +149,15 @@ class CalculatorBuilder {
|
||||||
* <p>Insertion of a job and job-activity is evaluated based on the previous and next activity.
|
* <p>Insertion of a job and job-activity is evaluated based on the previous and next activity.
|
||||||
* @param addDefaultCostCalc TODO
|
* @param addDefaultCostCalc TODO
|
||||||
*/
|
*/
|
||||||
public void setLocalLevel(boolean addDefaultCostCalc){
|
public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc){
|
||||||
local = true;
|
local = true;
|
||||||
this.addDefaultCostCalc = addDefaultCostCalc;
|
this.addDefaultCostCalc = addDefaultCostCalc;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){
|
public JobInsertionCostsCalculatorBuilder setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){
|
||||||
this.activityInsertionCostCalculator = activityInsertionCostsCalculator;
|
this.activityInsertionCostCalculator = activityInsertionCostsCalculator;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -165,10 +167,11 @@ class CalculatorBuilder {
|
||||||
* @param memory
|
* @param memory
|
||||||
* @param addDefaultMarginalCostCalc TODO
|
* @param addDefaultMarginalCostCalc TODO
|
||||||
*/
|
*/
|
||||||
public void setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc){
|
public JobInsertionCostsCalculatorBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc){
|
||||||
local = false;
|
local = false;
|
||||||
this.forwardLooking = forwardLooking;
|
this.forwardLooking = forwardLooking;
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -177,15 +180,17 @@ class CalculatorBuilder {
|
||||||
*
|
*
|
||||||
* @param weightOfFixedCosts
|
* @param weightOfFixedCosts
|
||||||
*/
|
*/
|
||||||
public void considerFixedCosts(double weightOfFixedCosts){
|
public JobInsertionCostsCalculatorBuilder considerFixedCosts(double weightOfFixedCosts){
|
||||||
considerFixedCost = true;
|
considerFixedCost = true;
|
||||||
this.weightOfFixedCost = weightOfFixedCosts;
|
this.weightOfFixedCost = weightOfFixedCosts;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void experimentalTimeScheduler(double timeSlice, int neighbors){
|
public JobInsertionCostsCalculatorBuilder experimentalTimeScheduler(double timeSlice, int neighbors){
|
||||||
timeScheduling = true;
|
timeScheduling = true;
|
||||||
this.timeSlice = timeSlice;
|
this.timeSlice = timeSlice;
|
||||||
this.neighbors = neighbors;
|
this.neighbors = neighbors;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -196,7 +201,7 @@ class CalculatorBuilder {
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculator build(){
|
public JobInsertionCostsCalculator build(){
|
||||||
if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
||||||
if(states == null) throw new IllegalStateException("states is null, but is must be set (this.setStates(states))");
|
if(states == null) throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))");
|
||||||
if(fleetManager == null) throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))");
|
if(fleetManager == null) throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))");
|
||||||
JobInsertionCostsCalculator baseCalculator = null;
|
JobInsertionCostsCalculator baseCalculator = null;
|
||||||
CalculatorPlusListeners standardLocal = null;
|
CalculatorPlusListeners standardLocal = null;
|
||||||
|
|
@ -352,12 +357,14 @@ class CalculatorBuilder {
|
||||||
return vehicleTypeDependentJobInsertionCalculator;
|
return vehicleTypeDependentJobInsertionCalculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstraintManager(ConstraintManager constraintManager) {
|
public JobInsertionCostsCalculatorBuilder setConstraintManager(ConstraintManager constraintManager) {
|
||||||
this.constraintManager = constraintManager;
|
this.constraintManager = constraintManager;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllowVehicleSwitch(boolean allowVehicleSwitch) {
|
public JobInsertionCostsCalculatorBuilder setAllowVehicleSwitch(boolean allowVehicleSwitch) {
|
||||||
this.allowVehicleSwitch = allowVehicleSwitch;
|
this.allowVehicleSwitch = allowVehicleSwitch;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3.0 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package jsprit.core.algorithm.recreate;
|
||||||
|
|
||||||
|
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners;
|
||||||
|
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||||
|
import jsprit.core.algorithm.state.StateManager;
|
||||||
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
import jsprit.core.problem.constraint.ConstraintManager;
|
||||||
|
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by schroeder on 11.12.14.
|
||||||
|
*/
|
||||||
|
public class JobInsertionCostsCalculatorFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns standard insertion calculator, i.e. the calculator that identifies best insertion positions for the
|
||||||
|
* jobs to be inserted. The position basically consists of the route and the according indices.
|
||||||
|
*
|
||||||
|
* @param vrp vehicle routing problem
|
||||||
|
* @param fleetManager fleet manager
|
||||||
|
* @param stateManager state manager
|
||||||
|
* @param constraintManager constraint manager
|
||||||
|
* @return insertion calculator
|
||||||
|
*/
|
||||||
|
public static JobInsertionCostsCalculator createStandardCalculator(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager){
|
||||||
|
List<VehicleRoutingAlgorithmListeners.PrioritizedVRAListener> al = new ArrayList<VehicleRoutingAlgorithmListeners.PrioritizedVRAListener>();
|
||||||
|
List<InsertionListener> il = new ArrayList<InsertionListener>();
|
||||||
|
JobInsertionCostsCalculatorBuilder builder = new JobInsertionCostsCalculatorBuilder(il,al);
|
||||||
|
builder.setVehicleRoutingProblem(vrp).setConstraintManager(constraintManager).setStateManager(stateManager).setVehicleFleetManager(fleetManager);
|
||||||
|
JobInsertionCostsCalculator calculator = builder.build();
|
||||||
|
return calculator;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -16,14 +16,14 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.algorithm.recreate.listener;
|
package jsprit.core.algorithm.recreate.listener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import jsprit.core.algorithm.recreate.InsertionData;
|
import jsprit.core.algorithm.recreate.InsertionData;
|
||||||
import jsprit.core.problem.job.Job;
|
import jsprit.core.problem.job.Job;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.vehicle.Vehicle;
|
import jsprit.core.problem.vehicle.Vehicle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
||||||
public class InsertionListeners {
|
public class InsertionListeners {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue