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:
parent
a87e5b6379
commit
2bea1dccb5
1 changed files with 16 additions and 53 deletions
|
|
@ -120,7 +120,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
|
|
||||||
TourActivity prevAct = start;
|
TourActivity prevAct = start;
|
||||||
double prevActEndTime = newVehicleDepartureTime;
|
double prevActEndTime = newVehicleDepartureTime;
|
||||||
boolean pickupShipmentLoopBroken = false;
|
|
||||||
|
|
||||||
//loops
|
//loops
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -128,7 +127,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
//pickupShipmentLoop
|
//pickupShipmentLoop
|
||||||
List<TourActivity> activities = currentRoute.getTourActivities().getActivities();
|
List<TourActivity> activities = currentRoute.getTourActivities().getActivities();
|
||||||
|
|
||||||
// for(int i=0;i<activities.size();i++){
|
|
||||||
while(!tourEnd){
|
while(!tourEnd){
|
||||||
TourActivity nextAct;
|
TourActivity nextAct;
|
||||||
if(i < activities.size()){
|
if(i < activities.size()){
|
||||||
|
|
@ -138,15 +136,16 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
nextAct = end;
|
nextAct = end;
|
||||||
tourEnd = true;
|
tourEnd = true;
|
||||||
}
|
}
|
||||||
|
// logger.info("activity: " + i + ", act-size: " + activities.size());
|
||||||
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
|
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
|
||||||
if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){
|
if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){
|
||||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
|
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||||
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
|
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
|
||||||
prevAct = nextAct;
|
prevAct = nextAct;
|
||||||
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
|
else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
|
||||||
pickupShipmentLoopBroken = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
|
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime);
|
||||||
|
|
@ -162,15 +161,25 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
insertionContext.setRelatedActivityContext(pickupContext);
|
insertionContext.setRelatedActivityContext(pickupContext);
|
||||||
|
|
||||||
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
|
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
|
||||||
boolean deliverShipmentLoopBroken = false;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
--------------------------------
|
--------------------------------
|
||||||
*/
|
*/
|
||||||
//deliverShipmentLoop
|
//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);
|
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
|
||||||
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
|
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
|
||||||
double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, nextAct_deliveryLoop, prevActEndTime_deliveryLoop);
|
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)){
|
else if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
|
||||||
deliverShipmentLoopBroken = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//update prevAct and endTime
|
//update prevAct and endTime
|
||||||
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
|
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), nextAct_deliveryLoop.getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
|
||||||
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop);
|
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct_deliveryLoop);
|
||||||
prevAct_deliveryLoop = nextAct_deliveryLoop;
|
prevAct_deliveryLoop = nextAct_deliveryLoop;
|
||||||
}
|
j++;
|
||||||
/*
|
|
||||||
--------------------------------
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//update prevAct and endTime
|
//update prevAct and endTime
|
||||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
|
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||||
|
|
@ -215,35 +207,6 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
||||||
prevAct = nextAct;
|
prevAct = nextAct;
|
||||||
i++;
|
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) {
|
if(pickupInsertionIndex == InsertionData.NO_INDEX) {
|
||||||
return InsertionData.createEmptyInsertionData();
|
return InsertionData.createEmptyInsertionData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue