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

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadActivityLevelConstraint.java
This commit is contained in:
oblonski 2015-09-11 12:47:16 +02:00
commit b9c7dc3324
5 changed files with 90 additions and 43 deletions

View file

@ -136,7 +136,9 @@ public class PrettyAlgorithmBuilder {
vra.addListener(new AlgorithmStartsListener() {
@Override
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) {
solutions.add(new InsertionInitialSolutionFactory(iniInsertionStrategy, iniObjFunction).createSolution(vrp));
if (solutions.isEmpty()) {
solutions.add(new InsertionInitialSolutionFactory(iniInsertionStrategy, iniObjFunction).createSolution(vrp));
}
}
});
}

View file

@ -145,8 +145,6 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
Thread.currentThread().interrupt();
}
catch (ExecutionException e) {
e.printStackTrace();
logger.error("Exception", e);
throw new RuntimeException(e);
}

View file

@ -25,49 +25,52 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
/**
* Ensures load constraint for inserting ServiceActivity.
* <p/>
*
* <p>When using this, you need to use<br>
*
*
* @author schroeder
*
*/
class ServiceLoadActivityLevelConstraint implements HardActivityConstraint {
public class ServiceLoadActivityLevelConstraint implements HardActivityConstraint {
private RouteAndActivityStateGetter stateManager;
private RouteAndActivityStateGetter stateManager;
private Capacity defaultValue;
public ServiceLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) {
super();
this.stateManager = stateManager;
public ServiceLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) {
super();
this.stateManager = stateManager;
defaultValue = Capacity.Builder.newInstance().build();
}
}
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
Capacity futureMaxLoad;
Capacity prevMaxLoad;
if (prevAct instanceof Start) {
futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class);
if (futureMaxLoad == null) futureMaxLoad = defaultValue;
prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class);
if (prevMaxLoad == null) prevMaxLoad = defaultValue;
} else {
futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class);
if (futureMaxLoad == null) futureMaxLoad = defaultValue;
prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class);
if (prevMaxLoad == null) prevMaxLoad = defaultValue;
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
Capacity futureMaxLoad;
Capacity prevMaxLoad;
if(prevAct instanceof Start){
futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class);
if(futureMaxLoad == null) futureMaxLoad = defaultValue;
prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class);
if(prevMaxLoad == null) prevMaxLoad = defaultValue;
}
else{
futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class);
if(futureMaxLoad == null) futureMaxLoad = defaultValue;
prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class);
if(prevMaxLoad == null) prevMaxLoad = defaultValue;
}
if (newAct instanceof PickupService || newAct instanceof ServiceActivity) {
if (!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) {
return ConstraintsStatus.NOT_FULFILLED;
}
}
if (newAct instanceof DeliverService) {
if (!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) {
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
}
return ConstraintsStatus.FULFILLED;
}
}
if(newAct instanceof PickupService || newAct instanceof ServiceActivity){
if(!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
return ConstraintsStatus.NOT_FULFILLED;
}
}
if(newAct instanceof DeliverService){
if(!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
}
return ConstraintsStatus.FULFILLED;
}
}

View file

@ -32,7 +32,7 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
*
* @author stefan
*/
class ServiceLoadRouteLevelConstraint implements HardRouteConstraint {
public class ServiceLoadRouteLevelConstraint implements HardRouteConstraint {
private RouteAndActivityStateGetter stateManager;