mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add new insertion strat
This commit is contained in:
parent
5d7d662124
commit
54f1d8819e
2 changed files with 17 additions and 26 deletions
|
|
@ -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
|
||||||
|
|
@ -17,9 +17,8 @@
|
||||||
package jsprit.core.algorithm.io;
|
package jsprit.core.algorithm.io;
|
||||||
|
|
||||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||||
import jsprit.core.algorithm.recreate.BestInsertionBuilder;
|
import jsprit.core.algorithm.recreate.InsertionBuilder;
|
||||||
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
import jsprit.core.algorithm.recreate.InsertionStrategy;
|
||||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
|
||||||
import jsprit.core.algorithm.state.StateManager;
|
import jsprit.core.algorithm.state.StateManager;
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
import jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import jsprit.core.problem.constraint.ConstraintManager;
|
import jsprit.core.problem.constraint.ConstraintManager;
|
||||||
|
|
@ -28,7 +27,6 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
|
@ -39,18 +37,16 @@ class InsertionFactory {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config,
|
public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config,
|
||||||
VehicleFleetManager vehicleFleetManager, StateManager routeStates, List<PrioritizedVRAListener> algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators){
|
VehicleFleetManager vehicleFleetManager, StateManager stateManager, List<PrioritizedVRAListener> algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators){
|
||||||
|
|
||||||
if(config.containsKey("[@name]")){
|
if(config.containsKey("[@name]")){
|
||||||
String insertionName = config.getString("[@name]");
|
String insertionName = config.getString("[@name]");
|
||||||
if(!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")){
|
if(!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")){
|
||||||
new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\"");
|
throw new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\"");
|
||||||
}
|
}
|
||||||
InsertionStrategy insertionStrategy = null;
|
|
||||||
List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>();
|
|
||||||
List<PrioritizedVRAListener> algoListeners = new ArrayList<PrioritizedVRAListener>();
|
|
||||||
|
|
||||||
BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, vehicleFleetManager, routeStates, constraintManager);
|
|
||||||
|
InsertionBuilder iBuilder = new InsertionBuilder(vrp, vehicleFleetManager, stateManager, constraintManager);
|
||||||
|
|
||||||
if(executorService != null){
|
if(executorService != null){
|
||||||
iBuilder.setConcurrentMode(executorService, nuOfThreads);
|
iBuilder.setConcurrentMode(executorService, nuOfThreads);
|
||||||
|
|
@ -105,16 +101,11 @@ class InsertionFactory {
|
||||||
if(allowVehicleSwitch != null){
|
if(allowVehicleSwitch != null){
|
||||||
iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch));
|
iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch));
|
||||||
}
|
}
|
||||||
if(insertionName.equals("bestInsertion")){
|
|
||||||
insertionStrategy = iBuilder.build();
|
if(insertionName.equals("regretInsertion")){
|
||||||
|
iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET);
|
||||||
}
|
}
|
||||||
else throw new IllegalStateException("currently only 'bestInsertion' is supported");
|
return iBuilder.build();
|
||||||
|
|
||||||
for(InsertionListener l : insertionListeners) insertionStrategy.addListener(l);
|
|
||||||
|
|
||||||
algorithmListeners.addAll(algoListeners);
|
|
||||||
|
|
||||||
return insertionStrategy;
|
|
||||||
}
|
}
|
||||||
else throw new IllegalStateException("cannot create insertionStrategy, since it has no name.");
|
else throw new IllegalStateException("cannot create insertionStrategy, since it has no name.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ public class VehicleRoutingAlgorithms {
|
||||||
SolutionAcceptor acceptor = getAcceptor(strategyConfig,vrp,algorithmListeners,definedClasses,solutionMemory);
|
SolutionAcceptor acceptor = getAcceptor(strategyConfig,vrp,algorithmListeners,definedClasses,solutionMemory);
|
||||||
SolutionSelector selector = getSelector(strategyConfig,vrp,algorithmListeners,definedClasses);
|
SolutionSelector selector = getSelector(strategyConfig,vrp,algorithmListeners,definedClasses);
|
||||||
|
|
||||||
SearchStrategy strategy = new SearchStrategy(selector, acceptor, costCalculator);
|
SearchStrategy strategy = new SearchStrategy(name, selector, acceptor, costCalculator);
|
||||||
strategy.setName(name);
|
strategy.setName(name);
|
||||||
List<HierarchicalConfiguration> modulesConfig = strategyConfig.configurationsAt("modules.module");
|
List<HierarchicalConfiguration> modulesConfig = strategyConfig.configurationsAt("modules.module");
|
||||||
for(HierarchicalConfiguration moduleConfig : modulesConfig){
|
for(HierarchicalConfiguration moduleConfig : modulesConfig){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue