mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add service/shipmentInsertionCalcSwitcher, some renaming and first tests
This commit is contained in:
parent
3740225058
commit
690bcb532a
10 changed files with 57 additions and 15 deletions
|
|
@ -216,9 +216,9 @@ class CalculatorBuilder {
|
|||
if(constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
||||
|
||||
ActivityInsertionCostsCalculator defaultCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), constraintManager);
|
||||
JobInsertionCalculator standardServiceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), defaultCalc, constraintManager);
|
||||
JobInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), defaultCalc, constraintManager);
|
||||
|
||||
((CalculatesServiceInsertion) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(standardServiceInsertion);
|
||||
|
||||
return calcPlusListeners;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package algorithms;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import basics.Job;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public class JobCalculatorSwitcher implements JobInsertionCalculator{
|
||||
|
||||
private Map<Class<? extends Job>,JobInsertionCalculator> calcMap = new HashMap<Class<? extends Job>, JobInsertionCalculator>();
|
||||
|
||||
void put(Class<? extends Job> jobClass, JobInsertionCalculator jic){
|
||||
calcMap.put(jobClass, jic);
|
||||
}
|
||||
|
||||
public InsertionData calculate(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore){
|
||||
JobInsertionCalculator jic = calcMap.get(jobToInsert.getClass());
|
||||
if(jic==null) throw new IllegalStateException("cannot find calculator for " + jobToInsert.getClass());
|
||||
return jic.calculate(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownScore);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,9 +36,9 @@ import basics.route.VehicleRoute;
|
|||
|
||||
|
||||
|
||||
final class CalculatesServiceInsertion implements JobInsertionCalculator{
|
||||
final class ServiceInsertionCalculator implements JobInsertionCalculator{
|
||||
|
||||
private static final Logger logger = Logger.getLogger(CalculatesServiceInsertion.class);
|
||||
private static final Logger logger = Logger.getLogger(ServiceInsertionCalculator.class);
|
||||
|
||||
private HardRouteLevelConstraint hardRouteLevelConstraint;
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
|
|||
logger.info("initialise neighborhood " + neighborhood);
|
||||
}
|
||||
|
||||
public CalculatesServiceInsertion(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, HardRouteLevelConstraint hardRouteLevelConstraint) {
|
||||
public ServiceInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, HardRouteLevelConstraint hardRouteLevelConstraint) {
|
||||
super();
|
||||
this.activityInsertionCostsCalculator = activityInsertionCostsCalculator;
|
||||
this.hardRouteLevelConstraint = hardRouteLevelConstraint;
|
||||
|
|
@ -81,4 +81,8 @@ public final class DeliverService implements DeliveryActivity{
|
|||
return delivery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ public final class PickupService implements PickupActivity{
|
|||
return pickup.getCapacityDemand();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class BuildCVRPAlgoFromScratchTest {
|
|||
}
|
||||
};
|
||||
ActivityInsertionCostsCalculator marginalCalculus = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), hardActLevelConstraint);
|
||||
CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||
|
||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class BuildPDVRPAlgoFromScratchTest {
|
|||
|
||||
ActivityInsertionCostsCalculator marginalCalculus = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actLevelConstraintAccumulator);
|
||||
|
||||
CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardPickupAndDeliveryLoadConstraint(stateManager));
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardPickupAndDeliveryLoadConstraint(stateManager));
|
||||
// CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||
|
||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import algorithms.selectors.SelectBest;
|
|||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
|
@ -69,7 +70,11 @@ public class BuildPDVRPWithShipmentsAlgoFromScratchTest {
|
|||
|
||||
Shipment s1 = Shipment.Builder.newInstance("s1", 1).setPickupCoord(Coordinate.newInstance(0, 0)).setDeliveryCoord(Coordinate.newInstance(10, 10)).build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2", 1).setPickupCoord(Coordinate.newInstance(1, 1)).setDeliveryCoord(Coordinate.newInstance(10, 10)).build();
|
||||
builder.addJob(s1).addJob(s2);
|
||||
|
||||
Service serv1 = Service.Builder.newInstance("serv1", 1).setCoord(Coordinate.newInstance(0, 5)).build();
|
||||
Service serv2 = Service.Builder.newInstance("serv2", 1).setCoord(Coordinate.newInstance(5, 0)).build();
|
||||
|
||||
builder.addJob(s1).addJob(s2).addJob(serv1).addJob(serv2);
|
||||
builder.addVehicle(v);
|
||||
|
||||
vrp = builder.build();
|
||||
|
|
@ -82,11 +87,16 @@ public class BuildPDVRPWithShipmentsAlgoFromScratchTest {
|
|||
|
||||
ActivityInsertionCostsCalculator marginalCalculus = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), actLevelConstraintAccumulator);
|
||||
|
||||
ShipmentInsertionCalculator serviceInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardPickupAndDeliveryLoadConstraint(stateManager));
|
||||
// CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||
ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardPickupAndDeliveryLoadConstraint(stateManager));
|
||||
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||
|
||||
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
|
||||
switcher.put(Shipment.class, shipmentInsertion);
|
||||
switcher.put(Service.class, serviceInsertion);
|
||||
|
||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, switcher);
|
||||
|
||||
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public class GendreauPostOptTest {
|
|||
|
||||
activityCosts = new ExampleActivityCostFunction();
|
||||
|
||||
CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(cost, new LocalActivityInsertionCostsCalculator(cost, activityCosts, new HardConstraints.HardTimeWindowActivityLevelConstraint(states, cost)), new HardConstraints.HardLoadConstraint(states));
|
||||
ServiceInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(cost, new LocalActivityInsertionCostsCalculator(cost, activityCosts, new HardConstraints.HardTimeWindowActivityLevelConstraint(states, cost)), new HardConstraints.HardLoadConstraint(states));
|
||||
|
||||
CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion, states);
|
||||
withFixCost.setWeightOfFixCost(1.2);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import basics.route.VehicleRoute;
|
|||
|
||||
public class TestCalculatesServiceInsertion {
|
||||
|
||||
CalculatesServiceInsertion serviceInsertion;
|
||||
ServiceInsertionCalculator serviceInsertion;
|
||||
|
||||
VehicleRoutingTransportCosts costs;
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction();
|
||||
|
||||
serviceInsertion = new CalculatesServiceInsertion(costs, new LocalActivityInsertionCostsCalculator(costs, activityCosts, new HardConstraints.HardTimeWindowActivityLevelConstraint(states, costs)), new HardConstraints.HardLoadConstraint(states));
|
||||
serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, activityCosts, new HardConstraints.HardTimeWindowActivityLevelConstraint(states, costs)), new HardConstraints.HardLoadConstraint(states));
|
||||
|
||||
stateUpdater = new UpdateStates(states, costs, activityCosts);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue