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

clean shipment insertion

This commit is contained in:
oblonski 2015-05-26 10:05:38 +02:00
parent a87e5b6379
commit 2bea1dccb5

View file

@ -120,7 +120,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
TourActivity prevAct = start;
double prevActEndTime = newVehicleDepartureTime;
boolean pickupShipmentLoopBroken = false;
//loops
int i = 0;
@ -128,7 +127,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
//pickupShipmentLoop
List<TourActivity> activities = currentRoute.getTourActivities().getActivities();
// for(int i=0;i<activities.size();i++){
while(!tourEnd){
TourActivity nextAct;
if(i < activities.size()){
@ -138,15 +136,16 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
nextAct = end;
tourEnd = true;
}
// logger.info("activity: " + i + ", act-size: " + activities.size());
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
prevAct = nextAct;
i++;
continue;
}
else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
pickupShipmentLoopBroken = true;
break;
}
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
@ -162,15 +161,25 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
insertionContext.setRelatedActivityContext(pickupContext);
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
boolean deliverShipmentLoopBroken = false;
/*
--------------------------------
*/
//deliverShipmentLoop
int j = i;
boolean tourEnd_deliveryLoop = false;
while(!tourEnd_deliveryLoop){
// for(int j=i;j<activities.size();j++){
TourActivity nextAct_deliveryLoop;
if(j < activities.size()) {
nextAct_deliveryLoop = activities.get(j);
}
else{
nextAct_deliveryLoop = end;
tourEnd_deliveryLoop = true;
}
for(int j=i;j<activities.size();j++){
TourActivity nextAct_deliveryLoop = activities.get(j);
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
@ -184,30 +193,13 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
}
}
else if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
deliverShipmentLoopBroken = true;
break;
}
//update prevAct and endTime
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop);
prevAct_deliveryLoop = nextAct_deliveryLoop;
}
/*
--------------------------------
*/
if(!deliverShipmentLoopBroken){ //check insertion between lastAct and endOfTour
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
double deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
double totalActivityInsertionCosts = pickupAIC + deliveryAIC
+ additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
if(totalActivityInsertionCosts < bestCost){
bestCost = totalActivityInsertionCosts;
pickupInsertionIndex = i;
deliveryInsertionIndex = activities.size();
}
}
j++;
}
//update prevAct and endTime
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
@ -215,35 +207,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
prevAct = nextAct;
i++;
}
// if(!pickupShipmentLoopBroken){ //check insertion of pickupShipment and deliverShipment at just before tour ended
// ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, end, prevActEndTime);
// if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
// double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, end, prevActEndTime);
// double pickupAIC = calculate(insertionContext,prevAct,pickupShipment,end,prevActEndTime);
// TourActivity prevAct_deliveryLoop = pickupShipment;
// double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
// double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
// double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
//
// pickupContext.setArrivalTime(shipmentPickupArrTime);
// pickupContext.setEndTime(shipmentPickupEndTime);
// pickupContext.setInsertionIndex(activities.size());
// insertionContext.setRelatedActivityContext(pickupContext);
//
// ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
// if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
// double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
// double deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
// double totalActivityInsertionCosts = pickupAIC + deliveryAIC
// + additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
// if(totalActivityInsertionCosts < bestCost){
// bestCost = totalActivityInsertionCosts;
// pickupInsertionIndex = activities.size();
// deliveryInsertionIndex = activities.size();
// }
// }
// }
// }
if(pickupInsertionIndex == InsertionData.NO_INDEX) {
return InsertionData.createEmptyInsertionData();
}