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:
parent
ebefbb0eb2
commit
e7d7d3c799
4 changed files with 55 additions and 12 deletions
|
|
@ -259,9 +259,11 @@ class CalculatorBuilder {
|
||||||
switcher.put(Pickup.class, serviceInsertion);
|
switcher.put(Pickup.class, serviceInsertion);
|
||||||
switcher.put(Delivery.class, serviceInsertion);
|
switcher.put(Delivery.class, serviceInsertion);
|
||||||
|
|
||||||
|
PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(switcher);
|
||||||
|
|
||||||
// JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
// JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||||
// ((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
// ((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(switcher);
|
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(penalyzeInsertionCosts);
|
||||||
|
|
||||||
return calcPlusListeners;
|
return calcPlusListeners;
|
||||||
}
|
}
|
||||||
|
|
@ -288,7 +290,10 @@ class CalculatorBuilder {
|
||||||
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setMemorySize(solutionMemory);
|
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setMemorySize(solutionMemory);
|
||||||
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setNeighborhood(vrp.getNeighborhood());
|
((ServiceInsertionOnRouteLevelCalculator)jobInsertionCalculator).setNeighborhood(vrp.getNeighborhood());
|
||||||
((ServiceInsertionOnRouteLevelCalculator) jobInsertionCalculator).setStates(activityStates2);
|
((ServiceInsertionOnRouteLevelCalculator) jobInsertionCalculator).setStates(activityStates2);
|
||||||
CalculatorPlusListeners calcPlusListener = new CalculatorPlusListeners(jobInsertionCalculator);
|
|
||||||
|
PenalyzeInsertionCostsWithPenaltyVehicle penalyzeInsertionCosts = new PenalyzeInsertionCostsWithPenaltyVehicle(jobInsertionCalculator);
|
||||||
|
|
||||||
|
CalculatorPlusListeners calcPlusListener = new CalculatorPlusListeners(penalyzeInsertionCosts);
|
||||||
return calcPlusListener;
|
return calcPlusListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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.Start;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.activity.TourShipmentActivityFactory;
|
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.Vehicle;
|
||||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||||
import jsprit.core.util.CalculationUtils;
|
import jsprit.core.util.CalculationUtils;
|
||||||
|
|
@ -51,14 +52,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
|
|
||||||
private HardActivityStateLevelConstraint hardActivityLevelConstraint;
|
private HardActivityStateLevelConstraint hardActivityLevelConstraint;
|
||||||
|
|
||||||
private Neighborhood neighborhood = new Neighborhood() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areNeighbors(String location1, String location2) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private ActivityInsertionCostsCalculator activityInsertionCostsCalculator;
|
private ActivityInsertionCostsCalculator activityInsertionCostsCalculator;
|
||||||
|
|
||||||
private VehicleRoutingTransportCosts transportCosts;
|
private VehicleRoutingTransportCosts transportCosts;
|
||||||
|
|
@ -66,7 +59,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
private TourShipmentActivityFactory activityFactory;
|
private TourShipmentActivityFactory activityFactory;
|
||||||
|
|
||||||
public void setNeighborhood(Neighborhood neighborhood) {
|
public void setNeighborhood(Neighborhood neighborhood) {
|
||||||
this.neighborhood = neighborhood;
|
|
||||||
logger.info("initialise neighborhood " + neighborhood);
|
logger.info("initialise neighborhood " + neighborhood);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +193,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
return InsertionData.createEmptyInsertionData();
|
return InsertionData.createEmptyInsertionData();
|
||||||
}
|
}
|
||||||
InsertionData insertionData = new InsertionData(bestCost, pickupInsertionIndex, deliveryInsertionIndex, newVehicle, newDriver);
|
InsertionData insertionData = new InsertionData(bestCost, pickupInsertionIndex, deliveryInsertionIndex, newVehicle, newDriver);
|
||||||
// logger.info("pickupIndex="+pickupInsertionIndex + ";deliveryIndex=" + deliveryInsertionIndex);
|
|
||||||
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
||||||
return insertionData;
|
return insertionData;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,22 @@ public class PenaltyVehicleType implements VehicleType{
|
||||||
|
|
||||||
private VehicleType type;
|
private VehicleType type;
|
||||||
|
|
||||||
|
private double penaltyFactor = 2;
|
||||||
|
|
||||||
public PenaltyVehicleType(VehicleType type) {
|
public PenaltyVehicleType(VehicleType type) {
|
||||||
super();
|
super();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PenaltyVehicleType(VehicleType type, double penaltyFactor) {
|
||||||
|
super();
|
||||||
|
this.type = type;
|
||||||
|
this.penaltyFactor = penaltyFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPenaltyFactor(){
|
||||||
|
return this.penaltyFactor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeId() {
|
public String getTypeId() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue