mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
issue #144 - change VehicleRoutingTransportCosts from String to Location
This commit is contained in:
parent
7e39d08e3d
commit
7ea5c5d650
51 changed files with 904 additions and 800 deletions
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
|
|
@ -57,8 +55,8 @@ class AdditionalAccessEgressCalculator {
|
|||
Driver newDriver = insertionContext.getNewDriver();
|
||||
double newVehicleDepartureTime = insertionContext.getNewDepTime();
|
||||
if(!currentRoute.isEmpty()){
|
||||
double accessTransportCostNew = routingCosts.getTransportCost(newVehicle.getStartLocationId(), currentRoute.getActivities().get(0).getLocationId(), newVehicleDepartureTime, newDriver, newVehicle);
|
||||
double accessTransportCostOld = routingCosts.getTransportCost(currentRoute.getStart().getLocationId(), currentRoute.getActivities().get(0).getLocationId(), currentRoute.getDepartureTime(), currentRoute.getDriver(), currentRoute.getVehicle());
|
||||
double accessTransportCostNew = routingCosts.getTransportCost(newVehicle.getStartLocation(), currentRoute.getActivities().get(0).getLocation(), newVehicleDepartureTime, newDriver, newVehicle);
|
||||
double accessTransportCostOld = routingCosts.getTransportCost(currentRoute.getStart().getLocation(), currentRoute.getActivities().get(0).getLocation(), currentRoute.getDepartureTime(), currentRoute.getDriver(), currentRoute.getVehicle());
|
||||
|
||||
delta_access = accessTransportCostNew - accessTransportCostOld;
|
||||
|
||||
|
|
@ -66,8 +64,8 @@ class AdditionalAccessEgressCalculator {
|
|||
TourActivity lastActivityBeforeEndOfRoute = currentRoute.getActivities().get(currentRoute.getActivities().size()-1);
|
||||
double lastActivityEndTimeWithOldVehicleAndDepartureTime = lastActivityBeforeEndOfRoute.getEndTime();
|
||||
double lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime = Math.max(0.0, lastActivityEndTimeWithOldVehicleAndDepartureTime + (newVehicleDepartureTime - currentRoute.getDepartureTime()));
|
||||
double egressTransportCostNew = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocationId(), newVehicle.getEndLocationId() , lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime, newDriver, newVehicle);
|
||||
double egressTransportCostOld = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocationId(), currentRoute.getEnd().getLocationId(), lastActivityEndTimeWithOldVehicleAndDepartureTime, currentRoute.getDriver(), currentRoute.getVehicle());
|
||||
double egressTransportCostNew = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), newVehicle.getEndLocation() , lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime, newDriver, newVehicle);
|
||||
double egressTransportCostOld = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), currentRoute.getEnd().getLocation(), lastActivityEndTimeWithOldVehicleAndDepartureTime, currentRoute.getDriver(), currentRoute.getVehicle());
|
||||
|
||||
delta_egress = egressTransportCostNew - egressTransportCostOld;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -26,6 +23,9 @@ import jsprit.core.problem.solution.route.activity.End;
|
|||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
final class AuxilliaryCostCalculator {
|
||||
|
|
@ -65,8 +65,8 @@ final class AuxilliaryCostCalculator {
|
|||
return cost;
|
||||
}
|
||||
}
|
||||
double transportCost = routingCosts.getTransportCost(prevAct.getLocationId(), act.getLocationId(), departureTimePrevAct, driver, vehicle);
|
||||
double transportTime = routingCosts.getTransportTime(prevAct.getLocationId(), act.getLocationId(), departureTimePrevAct, driver, vehicle);
|
||||
double transportCost = routingCosts.getTransportCost(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
|
||||
double transportTime = routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle);
|
||||
cost += transportCost;
|
||||
double actStartTime = departureTimePrevAct + transportTime;
|
||||
departureTimePrevAct = Math.max(actStartTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime();
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
@Override
|
||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) {
|
||||
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
|
@ -64,22 +64,22 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
}
|
||||
}
|
||||
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct;
|
||||
double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + act_costs_newAct + act_costs_nextAct;
|
||||
|
||||
double oldCosts;
|
||||
if(iFacts.getRoute().isEmpty()){
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct + actCost_nextAct;
|
||||
}
|
||||
else{
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct + actCost_nextAct;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
|
@ -144,12 +145,12 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
|||
private double scoreShipment(InsertionData best, Job job) {
|
||||
Shipment shipment = (Shipment)job;
|
||||
double maxDepotDistance_1 = Math.max(
|
||||
getDistance(best.getSelectedVehicle().getStartLocationId(),shipment.getPickupLocationId()),
|
||||
getDistance(best.getSelectedVehicle().getStartLocationId(),shipment.getDeliveryLocationId())
|
||||
getDistance(best.getSelectedVehicle().getStartLocation(),shipment.getPickupLocation()),
|
||||
getDistance(best.getSelectedVehicle().getStartLocation(),shipment.getDeliveryLocation())
|
||||
);
|
||||
double maxDepotDistance_2 = Math.max(
|
||||
getDistance(best.getSelectedVehicle().getEndLocationId(),shipment.getPickupLocationId()),
|
||||
getDistance(best.getSelectedVehicle().getEndLocationId(),shipment.getDeliveryLocationId())
|
||||
getDistance(best.getSelectedVehicle().getEndLocation(),shipment.getPickupLocation()),
|
||||
getDistance(best.getSelectedVehicle().getEndLocation(),shipment.getDeliveryLocation())
|
||||
);
|
||||
double maxDepotDistance = Math.max(maxDepotDistance_1,maxDepotDistance_2);
|
||||
double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd()-shipment.getPickupTimeWindow().getStart(),
|
||||
|
|
@ -159,15 +160,15 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
|||
|
||||
private double scoreService(InsertionData best, Job job) {
|
||||
double maxDepotDistance = Math.max(
|
||||
getDistance(best.getSelectedVehicle().getStartLocationId(), ((Service) job).getLocationId()),
|
||||
getDistance(best.getSelectedVehicle().getEndLocationId(), ((Service) job).getLocationId())
|
||||
getDistance(best.getSelectedVehicle().getStartLocation(), ((Service) job).getLocation()),
|
||||
getDistance(best.getSelectedVehicle().getEndLocation(), ((Service) job).getLocation())
|
||||
);
|
||||
return Math.max(tw_param * (((Service)job).getTimeWindow().getEnd() - ((Service)job).getTimeWindow().getStart()),minTimeWindowScore) +
|
||||
depotDistance_param * maxDepotDistance;
|
||||
}
|
||||
|
||||
|
||||
private double getDistance(String loc1, String loc2) {
|
||||
private double getDistance(Location loc1, Location loc2) {
|
||||
return vrp.getTransportCosts().getTransportCost(loc1,loc2,0.,null,null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
loopBroken = true;
|
||||
break;
|
||||
}
|
||||
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActStartTime, newDriver, newVehicle);
|
||||
double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle);
|
||||
prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
|
||||
prevAct = nextAct;
|
||||
actIndex++;
|
||||
|
|
|
|||
|
|
@ -188,8 +188,8 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
/**
|
||||
* calculate transport and activity costs with new vehicle (without inserting k)
|
||||
*/
|
||||
double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime_newVehicle, newDriver, newVehicle);
|
||||
double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime_newVehicle, newDriver, newVehicle);
|
||||
double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
|
||||
double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle);
|
||||
double arrTime_nextAct_newVehicle = prevActDepTime_newVehicle + transportTime_prevAct_nextAct_newVehicle;
|
||||
double activityCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct_newVehicle, newDriver, newVehicle);
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
for(int i=0;i<activities.size();i++){
|
||||
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, activities.get(i), prevActEndTime);
|
||||
if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){
|
||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), activities.get(i).getLocationId(), prevActEndTime, newDriver, newVehicle);
|
||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), activities.get(i).getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(i));
|
||||
prevAct = activities.get(i);
|
||||
continue;
|
||||
|
|
@ -138,7 +138,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, activities.get(i), prevActEndTime);
|
||||
double pickupAIC = calculate(insertionContext,prevAct,pickupShipment,activities.get(i),prevActEndTime);
|
||||
TourActivity prevAct_deliveryLoop = pickupShipment;
|
||||
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), pickupShipment.getLocationId(), prevActEndTime, newDriver, newVehicle);
|
||||
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||
double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
|
||||
|
||||
pickupContext.setArrivalTime(shipmentPickupArrTime);
|
||||
|
|
@ -167,7 +167,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
break;
|
||||
}
|
||||
//update prevAct and endTime
|
||||
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocationId(), activities.get(j).getLocationId(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
|
||||
double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocation(), activities.get(j).getLocation(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
|
||||
prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(j));
|
||||
prevAct_deliveryLoop = activities.get(j);
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
}
|
||||
}
|
||||
//update prevAct and endTime
|
||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), activities.get(i).getLocationId(), prevActEndTime, newDriver, newVehicle);
|
||||
double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), activities.get(i).getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||
prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(i));
|
||||
prevAct = activities.get(i);
|
||||
}
|
||||
|
|
@ -196,7 +196,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
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.getLocationId(), pickupShipment.getLocationId(), prevActEndTime, newDriver, newVehicle);
|
||||
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle);
|
||||
double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
|
||||
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
|
|
@ -36,8 +34,8 @@ public class VariableTransportCostCalculator implements SoftActivityConstraint{
|
|||
|
||||
@Override
|
||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) {
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
|
|
@ -49,16 +47,16 @@ public class VariableTransportCostCalculator implements SoftActivityConstraint{
|
|||
}
|
||||
}
|
||||
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct;
|
||||
|
||||
double oldCosts;
|
||||
if(iFacts.getRoute().isEmpty()){
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
else{
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
return totalCosts - oldCosts;
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
|
||||
|
||||
|
|
@ -70,32 +70,30 @@ public class AvgServiceAndShipmentDistance implements JobDistance {
|
|||
}
|
||||
|
||||
private double calcDist(Service i, Service j) {
|
||||
return calcDist(i.getLocationId(),i.getCoord(),j.getLocationId(),j.getCoord());
|
||||
return calcDist(i.getLocation(),j.getLocation());
|
||||
}
|
||||
|
||||
private double calcDist(Service i, Shipment j) {
|
||||
double c_ij1 = calcDist(i.getLocationId(),i.getCoord(),j.getPickupLocationId(),j.getPickupCoord());
|
||||
double c_ij2 = calcDist(i.getLocationId(),i.getCoord(),j.getDeliveryLocationId(),j.getDeliveryCoord());
|
||||
double c_ij1 = calcDist(i.getLocation(),j.getPickupLocation());
|
||||
double c_ij2 = calcDist(i.getLocation(),j.getDeliveryLocation());
|
||||
return (c_ij1 + c_ij2)/2.0;
|
||||
}
|
||||
|
||||
private double calcDist(Shipment i, Shipment j) {
|
||||
double c_i1j1 = calcDist(i.getPickupLocationId(),i.getPickupCoord(),j.getPickupLocationId(),j.getPickupCoord());
|
||||
double c_i1j2 = calcDist(i.getPickupLocationId(),i.getPickupCoord(),j.getDeliveryLocationId(),j.getDeliveryCoord());
|
||||
double c_i2j1 = calcDist(i.getDeliveryLocationId(),i.getDeliveryCoord(),j.getPickupLocationId(),j.getPickupCoord());
|
||||
double c_i2j2 = calcDist(i.getDeliveryLocationId(),i.getDeliveryCoord(),j.getDeliveryLocationId(),j.getDeliveryCoord());
|
||||
double c_i1j1 = calcDist(i.getPickupLocation(),j.getPickupLocation());
|
||||
double c_i1j2 = calcDist(i.getPickupLocation(),j.getDeliveryLocation());
|
||||
double c_i2j1 = calcDist(i.getDeliveryLocation(),j.getPickupLocation());
|
||||
double c_i2j2 = calcDist(i.getDeliveryLocation(),j.getDeliveryLocation());
|
||||
return (c_i1j1 + c_i1j2 + c_i2j1 + c_i2j2)/4.0;
|
||||
}
|
||||
|
||||
private double calcDist(String location_i, Coordinate coord_i, String location_j, Coordinate coord_j){
|
||||
private double calcDist(Location location_i, Location location_j){
|
||||
try{
|
||||
double c_ij = costs.getTransportCost(location_i, location_j, 0.0, null, null);
|
||||
return c_ij;
|
||||
}
|
||||
return costs.getTransportCost(location_i, location_j, 0.0, null, null);
|
||||
}
|
||||
catch(IllegalStateException e){
|
||||
// now try the euclidean distance between these two services
|
||||
}
|
||||
double c_ij = EuclideanDistanceCalculator.calculateDistance(coord_i, coord_j);
|
||||
return c_ij;
|
||||
return EuclideanDistanceCalculator.calculateDistance(location_i.getCoordinate(), location_j.getCoordinate());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
|
@ -66,7 +66,7 @@ public class AvgServiceDistance implements JobDistance {
|
|||
private double calcDist(Service s_i, Service s_j) {
|
||||
double distance;
|
||||
try{
|
||||
distance = costs.getTransportCost(s_i.getLocationId(), s_j.getLocationId(), 0.0, null, null);
|
||||
distance = costs.getTransportCost(s_i.getLocation(), s_j.getLocation(), 0.0, null, null);
|
||||
return distance;
|
||||
}
|
||||
catch(IllegalStateException e){
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
|
|
@ -56,7 +54,7 @@ class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater
|
|||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
|
||||
states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
public void visit(TourActivity act) {
|
||||
timeTracker.visit(act);
|
||||
|
||||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), act.getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), act.getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
|
||||
totalOperationCost += transportCost;
|
||||
|
|
@ -103,7 +103,7 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
@Override
|
||||
public void finish() {
|
||||
timeTracker.finish();
|
||||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), vehicleRoute.getEnd().getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), vehicleRoute.getEnd().getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
|
||||
totalOperationCost += transportCost;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
|
|
@ -34,7 +52,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi
|
|||
|
||||
private double[] latest_arrTimes_at_prevAct;
|
||||
|
||||
private String[] location_of_prevAct;
|
||||
private Location[] location_of_prevAct;
|
||||
|
||||
private Collection<Vehicle> vehicles;
|
||||
|
||||
|
|
@ -43,7 +61,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi
|
|||
this.stateManager = stateManager;
|
||||
this.transportCosts = tpCosts;
|
||||
latest_arrTimes_at_prevAct = new double[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||
location_of_prevAct = new String[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||
location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||
}
|
||||
|
||||
public void setVehiclesToUpdate(VehiclesToUpdate vehiclesToUpdate){
|
||||
|
|
@ -56,7 +74,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi
|
|||
vehicles = vehiclesToUpdate.get(route);
|
||||
for(Vehicle vehicle : vehicles){
|
||||
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getLatestArrival();
|
||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getEndLocationId();
|
||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getEndLocation();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,13 +82,13 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi
|
|||
public void visit(TourActivity activity) {
|
||||
for(Vehicle vehicle : vehicles){
|
||||
double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||
String prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevLocation,
|
||||
Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
||||
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
|
||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocationId();
|
||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package jsprit.core.analysis;
|
|||
import jsprit.core.algorithm.VariablePlusFixedSolutionCostCalculatorFactory;
|
||||
import jsprit.core.algorithm.state.*;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
|
|
@ -27,7 +28,6 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.*;
|
||||
import jsprit.core.util.ActivityTimeTracker;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ public class SolutionAnalyser {
|
|||
|
||||
public static interface DistanceCalculator {
|
||||
|
||||
public double getDistance(String fromLocationId, String toLocationId);
|
||||
public double getDistance(Location from, Location to);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -337,7 +337,7 @@ public class SolutionAnalyser {
|
|||
}
|
||||
|
||||
private double transportCost(TourActivity activity) {
|
||||
return transportCost.getTransportCost(prevAct.getLocationId(), activity.getLocationId(), prevActDeparture, route.getDriver(), route.getVehicle());
|
||||
return transportCost.getTransportCost(prevAct.getLocation(), activity.getLocation(), prevActDeparture, route.getDriver(), route.getVehicle());
|
||||
}
|
||||
|
||||
private double transportTime(TourActivity activity) {
|
||||
|
|
@ -345,7 +345,7 @@ public class SolutionAnalyser {
|
|||
}
|
||||
|
||||
private double distance(TourActivity activity) {
|
||||
return distanceCalculator.getDistance(prevAct.getLocationId(),activity.getLocationId());
|
||||
return distanceCalculator.getDistance(prevAct.getLocation(),activity.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -386,7 +386,7 @@ public class SolutionAnalyser {
|
|||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
double distance = distanceCalculator.getDistance(prevAct.getLocationId(),activity.getLocationId());
|
||||
double distance = distanceCalculator.getDistance(prevAct.getLocation(),activity.getLocation());
|
||||
sum_distance += distance;
|
||||
stateManager.putActivityState(activity,distance_id,sum_distance);
|
||||
prevAct = activity;
|
||||
|
|
@ -394,7 +394,7 @@ public class SolutionAnalyser {
|
|||
|
||||
@Override
|
||||
public void finish() {
|
||||
double distance = distanceCalculator.getDistance(prevAct.getLocationId(), route.getEnd().getLocationId());
|
||||
double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation());
|
||||
sum_distance += distance;
|
||||
stateManager.putRouteState(route,distance_id,sum_distance);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
|
|
@ -55,8 +53,8 @@ class AdditionalTransportationCosts implements SoftActivityConstraint{
|
|||
*/
|
||||
@Override
|
||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) {
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
|
|
@ -68,16 +66,16 @@ class AdditionalTransportationCosts implements SoftActivityConstraint{
|
|||
}
|
||||
}
|
||||
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct;
|
||||
|
||||
double oldCosts;
|
||||
if(iFacts.getRoute().isEmpty()){
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
else{
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
|
|
@ -46,18 +47,18 @@ import jsprit.core.util.CalculationUtils;
|
|||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival();
|
||||
Double latestArrTimeAtNextAct;
|
||||
String nextActLocation;
|
||||
Location nextActLocation;
|
||||
if(nextAct instanceof End) {
|
||||
latestArrTimeAtNextAct = latestVehicleArrival;
|
||||
nextActLocation = iFacts.getNewVehicle().getEndLocationId();
|
||||
nextActLocation = iFacts.getNewVehicle().getEndLocation();
|
||||
if(!iFacts.getNewVehicle().isReturnToDepot()){
|
||||
nextActLocation = newAct.getLocationId();
|
||||
nextActLocation = newAct.getLocation();
|
||||
}
|
||||
}
|
||||
else{
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, InternalStates.LATEST_OPERATION_START_TIME, Double.class);
|
||||
if(latestArrTimeAtNextAct==null) latestArrTimeAtNextAct=nextAct.getTheoreticalLatestOperationStartTime();
|
||||
nextActLocation = nextAct.getLocationId();
|
||||
nextActLocation = nextAct.getLocation();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -88,7 +89,7 @@ import jsprit.core.util.CalculationUtils;
|
|||
* |- earliest arrival of vehicle
|
||||
* |--- nextAct ---|
|
||||
*/
|
||||
double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
if(arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()){
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
|
@ -101,11 +102,11 @@ import jsprit.core.util.CalculationUtils;
|
|||
}
|
||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
||||
// double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class);
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
|
||||
double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(),latestArrTimeAtNextAct -
|
||||
routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocationId(), latestArrTimeAtNextAct, iFacts.getNewDriver(),
|
||||
routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(),
|
||||
iFacts.getNewVehicle()) - newAct.getOperationTime());
|
||||
/*
|
||||
* |--- prevAct ---|
|
||||
|
|
@ -123,7 +124,7 @@ import jsprit.core.util.CalculationUtils;
|
|||
}
|
||||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
/*
|
||||
* |--- newAct ---|
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
|
|
@ -48,12 +49,12 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival();
|
||||
Double latestArrTimeAtNextAct;
|
||||
String nextActLocation;
|
||||
Location nextActLocation;
|
||||
if(nextAct instanceof End) {
|
||||
latestArrTimeAtNextAct = latestVehicleArrival;
|
||||
nextActLocation = iFacts.getNewVehicle().getEndLocationId();
|
||||
nextActLocation = iFacts.getNewVehicle().getEndLocation();
|
||||
if(!iFacts.getNewVehicle().isReturnToDepot()){
|
||||
nextActLocation = newAct.getLocationId();
|
||||
nextActLocation = newAct.getLocation();
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
|
@ -63,7 +64,7 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
// latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getRoute().getVehicle(), StateFactory.LATEST_OPERATION_START_TIME ,Double.class);
|
||||
if(latestArrTimeAtNextAct == null) //otherwise set it to theoretical_latest_operation_startTime
|
||||
latestArrTimeAtNextAct=nextAct.getTheoreticalLatestOperationStartTime();
|
||||
nextActLocation = nextAct.getLocationId();
|
||||
nextActLocation = nextAct.getLocation();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -94,7 +95,7 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
* |- earliest arrival of vehicle
|
||||
* |--- nextAct ---|
|
||||
*/
|
||||
double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextActLocation, prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextActLocation, prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
if(arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct){
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
|
@ -106,9 +107,9 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||
double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(),latestArrTimeAtNextAct - routingCosts.getBackwardTransportTime(newAct.getLocationId(),nextActLocation,
|
||||
double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(),latestArrTimeAtNextAct - routingCosts.getBackwardTransportTime(newAct.getLocation(),nextActLocation,
|
||||
latestArrTimeAtNextAct,iFacts.getNewDriver(),iFacts.getNewVehicle()));
|
||||
|
||||
/*
|
||||
|
|
@ -127,7 +128,7 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr
|
|||
}
|
||||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextActLocation, endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextActLocation, endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
/*
|
||||
* |--- newAct ---|
|
||||
|
|
|
|||
|
|
@ -1,42 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.cost;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public abstract class AbstractForwardVehicleRoutingTransportCosts implements VehicleRoutingTransportCosts{
|
||||
|
||||
@Override
|
||||
public abstract double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle);
|
||||
public abstract double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
@Override
|
||||
public abstract double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle);
|
||||
public abstract double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportTime(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportTime(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.cost;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public interface BackwardTransportCost {
|
||||
|
||||
public double getBackwardTransportCost(String fromId, String toId,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.cost;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public interface BackwardTransportTime {
|
||||
|
||||
public double getBackwardTransportTime(String fromId, String toId,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.cost;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public interface ForwardTransportCost {
|
||||
|
||||
public double getTransportCost(String fromId, String toId,
|
||||
double departureTime, Driver driver, Vehicle vehicle);
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.cost;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public interface ForwardTransportTime {
|
||||
|
||||
public double getTransportTime(String fromId, String toId,
|
||||
double departureTime, Driver driver, Vehicle vehicle);
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,13 +117,13 @@ public class SolutionPrinter {
|
|||
String jobId;
|
||||
if(act instanceof JobActivity) jobId = ((JobActivity)act).getJob().getId();
|
||||
else jobId = "-";
|
||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocationId(), act.getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
c+= problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
|
||||
costs+=c;
|
||||
System.out.format(leftAlgin, routeNu, getVehicleString(route), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()),Math.round(costs));
|
||||
prevAct=act;
|
||||
}
|
||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocationId(), route.getEnd().getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||
c+= problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle());
|
||||
costs+=c;
|
||||
System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs));
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class ActivityTimeTracker implements ActivityVisitor{
|
|||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
if(!beginFirst) throw new IllegalStateException("never called begin. this however is essential here");
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocationId(), activity.getLocationId(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
|
||||
|
||||
actArrTime = arrivalTimeAtCurrAct;
|
||||
|
|
@ -101,7 +101,7 @@ public class ActivityTimeTracker implements ActivityVisitor{
|
|||
|
||||
@Override
|
||||
public void finish() {
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocationId(), route.getEnd().getLocationId(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle());
|
||||
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
|
||||
|
||||
actArrTime = arrivalTimeAtCurrAct;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
package jsprit.core.util;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -48,10 +49,10 @@ public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
|
||||
double distance;
|
||||
try {
|
||||
distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor;
|
||||
distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) * detourFactor;
|
||||
} catch (NullPointerException e) {
|
||||
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
|
||||
}
|
||||
|
|
@ -65,10 +66,10 @@ public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
|
||||
double distance;
|
||||
try {
|
||||
distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor;
|
||||
distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) * detourFactor;
|
||||
} catch (NullPointerException e) {
|
||||
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package jsprit.core.util;
|
|||
|
||||
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -66,10 +67,10 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double time,Driver driver, Vehicle vehicle) {
|
||||
public double getTransportCost(Location from, Location to, double time,Driver driver, Vehicle vehicle) {
|
||||
double distance;
|
||||
try {
|
||||
distance = getDistance(fromId, toId);
|
||||
distance = getDistance(from.getId(), to.getId());
|
||||
} catch (NullPointerException e) {
|
||||
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
|
||||
}
|
||||
|
|
@ -83,8 +84,8 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
|
||||
return getDistance(fromId, toId) / speed;
|
||||
public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
|
||||
return getDistance(from.getId(), to.getId()) / speed;
|
||||
}
|
||||
|
||||
public double getDistance(String fromId, String toId) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package jsprit.core.util;
|
|||
|
||||
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -40,10 +41,10 @@ public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double time,Driver driver, Vehicle vehicle) {
|
||||
public double getTransportCost(Location from, Location to, double time,Driver driver, Vehicle vehicle) {
|
||||
double distance;
|
||||
try {
|
||||
distance = calculateDistance(fromId, toId);
|
||||
distance = calculateDistance(from.getId(), to.getId());
|
||||
} catch (NullPointerException e) {
|
||||
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
|
||||
}
|
||||
|
|
@ -57,8 +58,8 @@ public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double time,Driver driver, Vehicle vehicle) {
|
||||
return calculateDistance(fromId, toId) / speed;
|
||||
public double getTransportTime(Location from, Location to, double time,Driver driver, Vehicle vehicle) {
|
||||
return calculateDistance(from.getId(), to.getId()) / speed;
|
||||
}
|
||||
|
||||
private double calculateDistance(String fromId, String toId) {
|
||||
|
|
|
|||
|
|
@ -1,25 +1,21 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.state.UpdateActivityTimes;
|
||||
import jsprit.core.problem.cost.TransportTime;
|
||||
import jsprit.core.problem.driver.DriverImpl;
|
||||
|
|
@ -29,6 +25,8 @@ import jsprit.core.problem.solution.route.RouteActivityVisitor;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class RouteUtils {
|
||||
|
||||
/**
|
||||
|
|
@ -60,11 +58,11 @@ public class RouteUtils {
|
|||
TourActivity lastact = r.getStart();
|
||||
double lastActDepTime = r.getDepartureTime();
|
||||
for(TourActivity act : r.getActivities()){
|
||||
tpTime += transportTimes.getTransportTime(lastact.getLocationId(), act.getLocationId(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
tpTime += transportTimes.getTransportTime(lastact.getLocation(), act.getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
lastact=act;
|
||||
lastActDepTime=act.getEndTime();
|
||||
}
|
||||
tpTime+=transportTimes.getTransportTime(lastact.getLocationId(), r.getEnd().getLocationId(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
tpTime+=transportTimes.getTransportTime(lastact.getLocation(), r.getEnd().getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle());
|
||||
}
|
||||
return tpTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.util;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -198,8 +199,8 @@ public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRo
|
|||
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTime(fromId, toId);
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTime(from.getId(), to.getId());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -248,10 +249,10 @@ public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRo
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(vehicle == null) return getDistance(fromId, toId);
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(vehicle == null) return getDistance(from.getId(), to.getId());
|
||||
VehicleCostParams costParams = vehicle.getType().getVehicleCostParams();
|
||||
return costParams.perDistanceUnit*getDistance(fromId, toId) + costParams.perTimeUnit*getTime(fromId, toId);
|
||||
return costParams.perDistanceUnit*getDistance(from.getId(), to.getId()) + costParams.perTimeUnit*getTime(from.getId(), to.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue