1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

make VehicleRoutingAlgorithms create algorithms with already specified

StateManager
This commit is contained in:
oblonski 2013-12-03 21:07:41 +01:00
parent 39859f379e
commit e8d3bd03ea
2 changed files with 43 additions and 18 deletions

View file

@ -392,12 +392,12 @@ public class VehicleRoutingAlgorithms {
* @return {@link VehicleRoutingAlgorithm} * @return {@link VehicleRoutingAlgorithm}
*/ */
public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, final AlgorithmConfig algorithmConfig){ public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, final AlgorithmConfig algorithmConfig){
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0); return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null);
} }
@Deprecated @Deprecated
public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final XMLConfiguration config){ public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final XMLConfiguration config){
return createAlgo(vrp,config,0); return createAlgo(vrp,config,0, null);
} }
/** /**
@ -411,7 +411,7 @@ public class VehicleRoutingAlgorithms {
AlgorithmConfig algorithmConfig = new AlgorithmConfig(); AlgorithmConfig algorithmConfig = new AlgorithmConfig();
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
xmlReader.read(configURL); xmlReader.read(configURL);
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0); return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null);
} }
/** /**
@ -425,17 +425,26 @@ public class VehicleRoutingAlgorithms {
AlgorithmConfig algorithmConfig = new AlgorithmConfig(); AlgorithmConfig algorithmConfig = new AlgorithmConfig();
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
xmlReader.read(configFileName); xmlReader.read(configFileName);
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0); return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null);
}
public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final String configFileName, StateManager stateManager){
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
xmlReader.read(configFileName);
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, stateManager);
} }
public static VehicleRoutingAlgorithm readAndCreateAlgorithm(VehicleRoutingProblem vrp, int nThreads, String configFileName) { public static VehicleRoutingAlgorithm readAndCreateAlgorithm(VehicleRoutingProblem vrp, int nThreads, String configFileName) {
AlgorithmConfig algorithmConfig = new AlgorithmConfig(); AlgorithmConfig algorithmConfig = new AlgorithmConfig();
AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
xmlReader.read(configFileName); xmlReader.read(configFileName);
return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads); return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads, null);
} }
private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads){
private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, StateManager stateMan){
// map to store constructed modules // map to store constructed modules
@ -484,7 +493,13 @@ public class VehicleRoutingAlgorithms {
final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp); final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp);
//create state-manager //create state-manager
final StateManager stateManager = new StateManager(vrp); final StateManager stateManager;
if(stateMan!=null) {
stateManager = stateMan;
}
else{
stateManager = new StateManager(vrp);
}
stateManager.updateLoadStates(); stateManager.updateLoadStates();
stateManager.updateTimeWindowStates(); stateManager.updateTimeWindowStates();

View file

@ -71,6 +71,10 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
private VehicleRoutingProblem vrp; private VehicleRoutingProblem vrp;
private boolean updateLoad = false;
private boolean updateTWs = false;
public StateManager(VehicleRoutingProblem vrp) { public StateManager(VehicleRoutingProblem vrp) {
super(); super();
this.vrp = vrp; this.vrp = vrp;
@ -276,16 +280,22 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
insertionListeners.informInsertionEndsListeners(vehicleRoutes); insertionListeners.informInsertionEndsListeners(vehicleRoutes);
} }
public void updateLoadStates() { public void updateLoadStates() {
UpdateLoads updateLoads = new UpdateLoads(this); if(!updateLoad){
addActivityVisitor(updateLoads); updateLoad=true;
addListener(updateLoads); UpdateLoads updateLoads = new UpdateLoads(this);
addActivityVisitor(new UpdatePrevMaxLoad(this)); addActivityVisitor(updateLoads);
addActivityVisitor(new UpdateMaxLoad(this)); addListener(updateLoads);
addActivityVisitor(new UpdateMaxLoad_(this)); addActivityVisitor(new UpdatePrevMaxLoad(this));
} addActivityVisitor(new UpdateMaxLoad(this));
addActivityVisitor(new UpdateMaxLoad_(this));
}
}
public void updateTimeWindowStates() { public void updateTimeWindowStates() {
addActivityVisitor(new UpdateTimeWindow(this, vrp.getTransportCosts())); if(!updateTWs){
} updateTWs=true;
addActivityVisitor(new UpdateTimeWindow(this, vrp.getTransportCosts()));
}
}
} }