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

add penalyzer to up the pressure for penalty-vehicles

This commit is contained in:
Stefan Schroeder 2013-12-04 15:07:28 +01:00
parent ebefbb0eb2
commit e7d7d3c799
4 changed files with 55 additions and 12 deletions

View file

@ -259,9 +259,11 @@ class CalculatorBuilder {
switcher.put(Pickup.class, serviceInsertion);
switcher.put(Delivery.class, serviceInsertion);
PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(switcher);
// JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
// ((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(switcher);
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(penalyzeInsertionCosts);
return calcPlusListeners;
}
@ -288,7 +290,10 @@ class CalculatorBuilder {
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setMemorySize(solutionMemory);
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setNeighborhood(vrp.getNeighborhood());
((ServiceInsertionOnRouteLevelCalculator) jobInsertionCalculator).setStates(activityStates2);
CalculatorPlusListeners calcPlusListener = new CalculatorPlusListeners(jobInsertionCalculator);
PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(jobInsertionCalculator);
CalculatorPlusListeners calcPlusListener = new CalculatorPlusListeners(penalyzeInsertionCosts);
return calcPlusListener;
}

View file

@ -0,0 +1,35 @@
package jsprit.core.algorithm.recreate;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.PenaltyVehicleType;
import jsprit.core.problem.vehicle.Vehicle;
class PenalyzeInsertionCostsWithPenaltyVehicle implements JobInsertionCostsCalculator{
JobInsertionCostsCalculator base;
public PenalyzeInsertionCostsWithPenaltyVehicle(JobInsertionCostsCalculator baseInsertionCostsCalculator) {
super();
this.base = baseInsertionCostsCalculator;
}
@Override
public InsertionData getInsertionData(VehicleRoute currentRoute,Job newJob, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownCosts) {
if(newVehicle.getType() instanceof PenaltyVehicleType){
if(currentRoute.getVehicle().getType() instanceof PenaltyVehicleType){
InsertionData iData = base.getInsertionData(currentRoute, newJob, newVehicle, newVehicleDepartureTime, newDriver, bestKnownCosts);
double penaltyC = iData.getInsertionCost()*((PenaltyVehicleType)newVehicle.getType()).getPenaltyFactor();
InsertionData newData = new InsertionData(penaltyC, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), iData.getSelectedVehicle(), iData.getSelectedDriver());
newData.setAdditionalTime(iData.getAdditionalTime());
newData.setVehicleDepartureTime(iData.getVehicleDepartureTime());
return newData;
}
}
return base.getInsertionData(currentRoute, newJob, newVehicle, newVehicleDepartureTime, newDriver, bestKnownCosts);
}
}

View file

@ -33,6 +33,7 @@ import jsprit.core.problem.solution.route.activity.End;
import jsprit.core.problem.solution.route.activity.Start;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.TourShipmentActivityFactory;
import jsprit.core.problem.vehicle.PenaltyVehicleType;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import jsprit.core.util.CalculationUtils;
@ -51,14 +52,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
private HardActivityStateLevelConstraint hardActivityLevelConstraint;
private Neighborhood neighborhood = new Neighborhood() {
@Override
public boolean areNeighbors(String location1, String location2) {
return true;
}
};
private ActivityInsertionCostsCalculator activityInsertionCostsCalculator;
private VehicleRoutingTransportCosts transportCosts;
@ -66,7 +59,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
private TourShipmentActivityFactory activityFactory;
public void setNeighborhood(Neighborhood neighborhood) {
this.neighborhood = neighborhood;
logger.info("initialise neighborhood " + neighborhood);
}
@ -201,7 +193,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
return InsertionData.createEmptyInsertionData();
}
InsertionData insertionData = new InsertionData(bestCost, pickupInsertionIndex, deliveryInsertionIndex, newVehicle, newDriver);
// logger.info("pickupIndex="+pickupInsertionIndex + ";deliveryIndex=" + deliveryInsertionIndex);
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
return insertionData;
}

View file

@ -22,11 +22,23 @@ public class PenaltyVehicleType implements VehicleType{
private VehicleType type;
private double penaltyFactor = 2;
public PenaltyVehicleType(VehicleType type) {
super();
this.type = type;
}
public PenaltyVehicleType(VehicleType type, double penaltyFactor) {
super();
this.type = type;
this.penaltyFactor = penaltyFactor;
}
public double getPenaltyFactor(){
return this.penaltyFactor;
}
@Override
public String getTypeId() {
return type.getTypeId();