1
0
Fork 0
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:
oblonski 2014-12-17 20:18:07 +01:00
parent 7e39d08e3d
commit 7ea5c5d650
51 changed files with 904 additions and 800 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -119,13 +119,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));

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,13 +8,11 @@
*
* 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.
* 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;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,9 +16,6 @@
******************************************************************************/
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();

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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++;

View file

@ -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);

View file

@ -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;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,13 +8,11 @@
*
* 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.
* 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;

View file

@ -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());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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){

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,13 +8,11 @@
*
* 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.
* 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);

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,13 +8,11 @@
*
* 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.
* 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;
}

View file

@ -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 ---|

View file

@ -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 ---|

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,35 +8,34 @@
*
* 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.
* 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);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,12 @@
******************************************************************************/
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);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,12 @@
******************************************************************************/
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);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,12 @@
******************************************************************************/
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);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,12 @@
******************************************************************************/
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);
}

View file

@ -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));

View file

@ -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;

View file

@ -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.");
}

View file

@ -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) {

View file

@ -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) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,18 +8,14 @@
*
* 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.
* 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;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,6 +16,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;
@ -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());
}
}

View file

@ -18,6 +18,7 @@ package jsprit.core.algorithm;
import jsprit.core.algorithm.box.SchrimpfFactory;
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
@ -116,25 +117,25 @@ public class RefuseCollection_IT {
}
@Override
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, departureTime, driver, vehicle);
}
@Override
public double getBackwardTransportTime(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, arrivalTime, driver, vehicle);
}
@Override
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
if(fromId.equals(toId)) return 0.0;
RelationKey key = RelationKey.newKey(fromId, toId);
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
if(from.equals(to)) return 0.0;
RelationKey key = RelationKey.newKey(from.getId(), to.getId());
return distances.get(key);
}
@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);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,9 @@
******************************************************************************/
package jsprit.core.algorithm.recreate;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
@ -36,6 +33,10 @@ import jsprit.core.util.Coordinate;
import jsprit.core.util.CrowFlyCosts;
import jsprit.core.util.Solutions;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
public class CalcWithTimeSchedulingTest {
@ -65,26 +66,26 @@ public class CalcWithTimeSchedulingTest {
return new VehicleRoutingTransportCosts() {
@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);
}
@Override
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) {
if(departureTime < 50){
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle)*2.0;
return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle)*2.0;
}
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle);
return baseCosts.getTransportCost(from, to, departureTime, driver, 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 getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, departureTime, driver, vehicle);
}
};
}

View file

@ -18,6 +18,7 @@
package jsprit.core.algorithm.recreate;
import jsprit.core.algorithm.recreate.listener.BeforeJobInsertionListener;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Job;
@ -169,7 +170,7 @@ public class RegretInsertionTest {
Vehicle vehicle = vrp.getVehicles().iterator().next();
InsertionData iData = null;
if(currentRoute.isEmpty()){
double mc = getCost(service.getLocationId(), vehicle.getStartLocationId());
double mc = getCost(service.getLocation(), vehicle.getStartLocation());
iData = new InsertionData(2*mc,-1,0,vehicle,newDriver);
}
else {
@ -197,13 +198,13 @@ public class RegretInsertionTest {
}
private double getMarginalCost(Service service, TourActivity prevAct, TourActivity act) {
double prev_new = getCost(prevAct.getLocationId(),service.getLocationId());
double new_act = getCost(service.getLocationId(),act.getLocationId());
double prev_act = getCost(prevAct.getLocationId(),act.getLocationId());
double prev_new = getCost(prevAct.getLocation(),service.getLocation());
double new_act = getCost(service.getLocation(),act.getLocation());
double prev_act = getCost(prevAct.getLocation(),act.getLocation());
return prev_new + new_act - prev_act;
}
private double getCost(String loc1, String loc2) {
private double getCost(Location loc1, Location loc2) {
return vrp.getTransportCosts().getTransportCost(loc1,loc2,0.,null,null);
}
};

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.core.algorithm.recreate;
import jsprit.core.problem.Location;
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.solution.route.activity.End;
@ -45,22 +46,26 @@ public class TestAuxilliaryCostCalculator {
routingCosts = mock(VehicleRoutingTransportCosts.class);
actCosts = mock(VehicleRoutingActivityCosts.class);
when(routingCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
when(routingCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0);
when(routingCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
}
private Location loc(String i) {
return Location.Builder.newInstance().setId(i).build();
}
@Test
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v1(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
TourActivity nextAct = mock(TourActivity.class);
when(nextAct.getLocationId()).thenReturn("j");
when(nextAct.getLocation()).thenReturn(loc("j"));
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(true);
@ -72,10 +77,10 @@ public class TestAuxilliaryCostCalculator {
@Test
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
End nextAct = new End("j", 0.0, 0.0);
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(true);
@ -87,11 +92,11 @@ public class TestAuxilliaryCostCalculator {
@Test
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v1(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
TourActivity nextAct = mock(TourActivity.class);
when(nextAct.getLocationId()).thenReturn("j");
when(nextAct.getLocation()).thenReturn(loc("j"));
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(false);
@ -103,10 +108,10 @@ public class TestAuxilliaryCostCalculator {
@Test
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v2(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
End nextAct = End.newInstance("j", 0.0, 0.0);
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(false);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -19,6 +19,7 @@ package jsprit.core.algorithm.recreate;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.problem.AbstractActivity;
import jsprit.core.problem.JobActivityFactory;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
@ -98,13 +99,13 @@ public class TestCalculatesServiceInsertion {
costs = new AbstractForwardVehicleRoutingTransportCosts() {
@Override
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
}
};
@ -231,13 +232,13 @@ public class TestCalculatesServiceInsertion {
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
@Override
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, departureTime, driver, vehicle);
}
@Override
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
return EuclideanDistanceCalculator.calculateDistance(coords.get(fromId), coords.get(toId));
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
}
};
Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocationId("oldV").build();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -19,10 +19,7 @@ package jsprit.core.algorithm.recreate;
import jsprit.core.algorithm.ExampleActivityCostFunction;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.algorithm.state.UpdateVariableCosts;
import jsprit.core.problem.AbstractActivity;
import jsprit.core.problem.AbstractVehicle;
import jsprit.core.problem.JobActivityFactory;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.*;
import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
@ -90,13 +87,13 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
VehicleRoutingTransportCosts routingCosts = CostFactory.createManhattanCosts();
@Override
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) {
return 0;
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
double tpCosts = routingCosts.getTransportCost(fromId,toId,departureTime,driver,vehicle);
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
double tpCosts = routingCosts.getTransportCost(from, to,departureTime,driver,vehicle);
if(vehicle.getId().equals("v1")) return tpCosts;
return 2. * tpCosts;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,16 +8,15 @@
*
* 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.
* 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;
import jsprit.core.problem.Location;
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.misc.JobInsertionContext;
@ -59,25 +58,29 @@ public class TestLocalActivityInsertionCostsCalculator {
when(jic.getNewVehicle()).thenReturn(vehicle);
tpCosts = mock(VehicleRoutingTransportCosts.class);
when(tpCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
when(tpCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0);
when(tpCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
actCosts = mock(VehicleRoutingActivityCosts.class);
calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
}
@Test
private Location loc(String i) {
return Location.Builder.newInstance().setId(i).build();
}
@Test
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
TourActivity nextAct = mock(TourActivity.class);
when(nextAct.getLocationId()).thenReturn("j");
when(nextAct.getLocation()).thenReturn(loc("j"));
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(true);
@ -88,10 +91,10 @@ public class TestLocalActivityInsertionCostsCalculator {
@Test
public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
End nextAct = End.newInstance("j", 0.0, 0.0);
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(true);
@ -102,11 +105,11 @@ public class TestLocalActivityInsertionCostsCalculator {
@Test
public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
TourActivity nextAct = mock(TourActivity.class);
when(nextAct.getLocationId()).thenReturn("j");
when(nextAct.getLocation()).thenReturn(loc("j"));
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(false);
@ -117,10 +120,10 @@ public class TestLocalActivityInsertionCostsCalculator {
@Test
public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
when(prevAct.getLocation()).thenReturn(loc("i"));
End nextAct = End.newInstance("j", 0.0, 0.0);
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");
when(newAct.getLocation()).thenReturn(loc("k"));
when(vehicle.isReturnToDepot()).thenReturn(false);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -16,12 +16,11 @@
******************************************************************************/
package jsprit.core.algorithm.ruin.distance;
import jsprit.core.algorithm.ruin.distance.AvgServiceDistance;
import jsprit.core.problem.Location;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.vehicle.Vehicle;
import org.junit.Test;
@ -31,20 +30,20 @@ public class TestJobDistanceAvgCosts {
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
@Override
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) {
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
public double getBackwardTransportCost(Location from, Location to,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId,
public double getTransportCost(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
@SuppressWarnings("unused")
String vehicleId = vehicle.getId();
@ -52,7 +51,7 @@ public class TestJobDistanceAvgCosts {
}
@Override
public double getTransportTime(String fromId, String toId,
public double getTransportTime(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
@ -68,20 +67,20 @@ public class TestJobDistanceAvgCosts {
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
@Override
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) {
return 0;
}
@Override
public double getBackwardTransportCost(String fromId, String toId,
public double getBackwardTransportCost(Location from, Location to,
double arrivalTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getTransportCost(String fromId, String toId,
public double getTransportCost(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
@SuppressWarnings("unused")
String vehicleId = vehicle.getId();
@ -89,7 +88,7 @@ public class TestJobDistanceAvgCosts {
}
@Override
public double getTransportTime(String fromId, String toId,
public double getTransportTime(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
// TODO Auto-generated method stub
return 0;

View file

@ -262,22 +262,26 @@ public class VehicleRoutingProblemTest {
builder.setRoutingCost(new AbstractForwardVehicleRoutingTransportCosts() {
@Override
public double getTransportTime(String fromId, String toId,
public double getTransportTime(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
return 0;
}
@Override
public double getTransportCost(String fromId, String toId,
public double getTransportCost(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
return 4.0;
}
});
VehicleRoutingProblem problem = builder.build();
assertEquals(4.0,problem.getTransportCosts().getTransportCost("", "", 0.0, null, null),0.01);
assertEquals(4.0,problem.getTransportCosts().getTransportCost(loc(""), loc(""), 0.0, null, null),0.01);
}
private Location loc(String i) {
return Location.Builder.newInstance().setId(i).build();
}
@Test
public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,19 +8,18 @@
*
* 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.
* 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;
import jsprit.core.algorithm.state.InternalStates;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
@ -60,12 +59,12 @@ public class ServiceLoadRouteLevelConstraintTest {
VehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
@Override
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) {
return 0;
}
@Override
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) {
return 0;
}
};

View file

@ -152,6 +152,7 @@ public class VrpXMLWriterTest {
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
Shipment s1_read = (Shipment) readVrp.getJobs().get("1");
assertTrue(s1_read.getName().equals("cleaning"));
assertEquals(1,s1_read.getPickupLocation().getIndex());
}
@Test

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,24 +8,23 @@
*
* 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.
* 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 jsprit.core.problem.Location;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import org.junit.Test;
public class VehicleRoutingTransportCostsMatrixTest {
@ -34,9 +33,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
matrixBuilder.addTransportDistance("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportCost("1", "2", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getDistance("1", "2"),0.1);
assertEquals(2.,matrix.getTransportCost("2", "1", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getDistance("2", "1"),0.1);
}
@ -45,9 +44,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
matrixBuilder.addTransportDistance("from", "to", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getDistance("from", "to"),0.1);
assertEquals(2.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getDistance("from", "to"),0.1);
}
@ -59,9 +58,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
matrixBuilder.addTransportDistance("from", "to", 4.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
}
@ -73,9 +72,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
matrixBuilder.addTransportDistance("to", "from", 4.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
}
@ -84,15 +83,19 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
matrixBuilder.addTransportDistance("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportCost("1", "2", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1);
}
@Test(expected=IllegalStateException.class)
private Location loc(String s) {
return Location.Builder.newInstance().setId(s).build();
}
@Test(expected=IllegalStateException.class)
public void whenRequestingRelationThatDoesNotExist_itShouldThrowException(){
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
matrixBuilder.addTransportDistance("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
matrix.getTransportCost("2", "1", 0.0, null, null);
matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null);
}
@Test
@ -101,8 +104,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
matrixBuilder.addTransportDistance("from", "to", 2.);
matrixBuilder.addTransportDistance("to", "from", 4.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
}
@Test
@ -110,8 +113,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
matrixBuilder.addTransportTime("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportTime("1", "2", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime("2", "1", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null),0.1);
}
@Test
@ -119,8 +122,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
matrixBuilder.addTransportTime("from", "to", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1);
}
@Test
@ -128,7 +131,7 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
matrixBuilder.addTransportTime("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportTime("1", "2", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null),0.1);
}
@Test(expected=IllegalStateException.class)
@ -136,7 +139,7 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
matrixBuilder.addTransportTime("1", "2", 2.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
matrix.getTransportTime("2", "1", 0.0, null, null);
matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null);
}
@Test
@ -145,8 +148,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
matrixBuilder.addTransportTime("from", "to", 2.);
matrixBuilder.addTransportTime("to", "from", 4.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1);
assertEquals(4.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1);
}
@Test
@ -160,8 +163,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
// assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
// assertEquals(4.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
}
@Test
@ -173,8 +176,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
Vehicle vehicle = mock(Vehicle.class);
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
when(vehicle.getType()).thenReturn(type);
assertEquals(24.,matrix.getTransportCost("1", "2", 0.0, null, vehicle),0.1);
assertEquals(24.,matrix.getTransportCost("2", "1", 0.0, null, vehicle),0.1);
assertEquals(24.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1);
assertEquals(24.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1);
}
@Test
@ -185,8 +188,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
when(vehicle.getType()).thenReturn(type);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
}
@Test
@ -198,8 +201,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
Vehicle vehicle = mock(Vehicle.class);
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
when(vehicle.getType()).thenReturn(type);
assertEquals(4.,matrix.getTransportCost("1", "2", 0.0, null, vehicle),0.1);
assertEquals(16.,matrix.getTransportCost("2", "1", 0.0, null, vehicle),0.1);
assertEquals(4.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1);
assertEquals(16.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1);
}
@Test
@ -213,8 +216,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
Vehicle vehicle = mock(Vehicle.class);
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
when(vehicle.getType()).thenReturn(type);
assertEquals(5.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
assertEquals(11.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
assertEquals(5.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
assertEquals(11.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
}
@ -231,8 +234,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
matrixBuilder.addTransportDistance("to", "from", 5.);
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
assertEquals(8.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
assertEquals(14.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
assertEquals(8.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
assertEquals(14.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
}
@Test
@ -251,8 +254,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
when(vehicle.getType()).thenReturn(type);
assertEquals(1.,matrix.getDistance("from", "to"),0.1);
assertEquals(1.,matrix.getDistance("to", "from"),0.1);
assertEquals(1.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
assertEquals(1.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
assertEquals(1.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
assertEquals(1.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
}
}

View file

@ -21,37 +21,87 @@
<problemType>
<fleetSize>INFINITE</fleetSize>
</problemType>
<shipments>
<shipment id="1">
<pickup>
<location>
<id>pick</id>
<index>1</index>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>del</id>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</delivery>
<vehicles>
<vehicle>
<id>v1</id>
<typeId>vehType</typeId>
<startLocation>
<id>loc</id>
</startLocation>
<endLocation>
<id>loc</id>
</endLocation>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity-dimensions>
<dimension index="0">0</dimension>
<dimension index="0">20</dimension>
</capacity-dimensions>
<name>cleaning</name>
</shipment>
</shipments>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="2" type="service">
<location>
<id>loc2</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="1" type="service">
<location>
<id>loc</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>10.0</cost>
<routes>
<route>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>0.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>0.0</arrTime>
<endTime>0.0</endTime>
</act>
<end>0.0</end>
</route>
</routes>
<unassignedJobs>
<job id="2"/>
</unassignedJobs>
</solution>
</solutions>
</problem>

View file

@ -1,5 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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/>.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<algorithm xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
@ -14,7 +31,7 @@
<strategy>
<memory>1</memory>
<searchStrategies>
<searchStrategy name="radialRuinAndRecreate">
<searchStrategy name="randomRR">
<selector name="selectBest"/>
<acceptor name="schrimpfAcceptance">
<alpha>0.2</alpha>
@ -32,7 +49,7 @@
<probability>0.5</probability>
</searchStrategy>
<searchStrategy name="radialRuinAndRecreate">
<searchStrategy name="radialRR">
<selector name="selectBest"/>
<acceptor name="schrimpfAcceptance"/>
<modules>

View file

@ -104,7 +104,7 @@ public class BicycleMessenger {
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts,TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
//make sure vehicle can manage direct path
double arrTime_at_nextAct_onDirectRoute = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
double arrTime_at_nextAct_onDirectRoute = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
Double latest_arrTime_at_nextAct = stateManager.getActivityState(nextAct, latest_act_arrival_time_stateId, Double.class);
if(latest_arrTime_at_nextAct == null) latest_arrTime_at_nextAct = nextAct.getTheoreticalLatestOperationStartTime();
if(arrTime_at_nextAct_onDirectRoute > latest_arrTime_at_nextAct){
@ -112,7 +112,7 @@ public class BicycleMessenger {
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
double arrTime_at_newAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
double arrTime_at_newAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
//local impact
//no matter whether it is a pickupShipment or deliverShipment activities. both arrivalTimes must be < 3*best.
double directTimeOfNearestMessenger = bestMessengers.get(((JobActivity) newAct).getJob().getId());
@ -123,12 +123,12 @@ public class BicycleMessenger {
//impact on whole route, since insertion of newAct shifts all subsequent activities forward in time
double departureTime_at_newAct = arrTime_at_newAct + newAct.getOperationTime();
double latest_arrTime_at_newAct = latest_arrTime_at_nextAct - routingCosts.getTransportTime(newAct.getLocationId(),nextAct.getLocationId(),departureTime_at_newAct,iFacts.getNewDriver(),iFacts.getNewVehicle());
double latest_arrTime_at_newAct = latest_arrTime_at_nextAct - routingCosts.getTransportTime(newAct.getLocation(),nextAct.getLocation(),departureTime_at_newAct,iFacts.getNewDriver(),iFacts.getNewVehicle());
if(arrTime_at_newAct > latest_arrTime_at_newAct){
return ConstraintsStatus.NOT_FULFILLED;
}
double arrTime_at_nextAct = departureTime_at_newAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
double arrTime_at_nextAct = departureTime_at_newAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
//here you need an activity state
if(arrTime_at_nextAct > latest_arrTime_at_nextAct){
return ConstraintsStatus.NOT_FULFILLED;
@ -210,7 +210,7 @@ public class BicycleMessenger {
public void visit(TourActivity currAct) {
double timeOfNearestMessenger = bestMessengers.get(((JobActivity)currAct).getJob().getId());
double potential_latest_arrTime_at_currAct =
latest_arrTime_at_prevAct - routingCosts.getBackwardTransportTime(currAct.getLocationId(), prevAct.getLocationId(), latest_arrTime_at_prevAct, route.getDriver(),route.getVehicle()) - currAct.getOperationTime();
latest_arrTime_at_prevAct - routingCosts.getBackwardTransportTime(currAct.getLocation(), prevAct.getLocation(), latest_arrTime_at_prevAct, route.getDriver(),route.getVehicle()) - currAct.getOperationTime();
double latest_arrTime_at_currAct = Math.min(3*timeOfNearestMessenger, potential_latest_arrTime_at_currAct);
stateManager.putActivityState(currAct, latest_act_arrival_time_stateId, latest_arrTime_at_currAct);
assert currAct.getArrTime() <= latest_arrTime_at_currAct : "this must not be since it breaks condition; actArrTime: " + currAct.getArrTime() + " latestArrTime: " + latest_arrTime_at_currAct + " vehicle: " + route.getVehicle().getId();
@ -340,8 +340,8 @@ public class BicycleMessenger {
static double getTimeOfDirectRoute(Job job, Vehicle v, VehicleRoutingTransportCosts routingCosts) {
Shipment envelope = (Shipment) job;
return routingCosts.getTransportTime(v.getStartLocationId(), envelope.getPickupLocationId(), 0.0, DriverImpl.noDriver(), v) +
routingCosts.getTransportTime(envelope.getPickupLocationId(), envelope.getDeliveryLocationId(), 0.0, DriverImpl.noDriver(), v);
return routingCosts.getTransportTime(v.getStartLocation(), envelope.getPickupLocation(), 0.0, DriverImpl.noDriver(), v) +
routingCosts.getTransportTime(envelope.getPickupLocation(), envelope.getDeliveryLocation(), 0.0, DriverImpl.noDriver(), v);
}
private static void readEnvelopes(Builder problemBuilder) throws IOException {

View file

@ -34,6 +34,7 @@ import jsprit.core.algorithm.ruin.distance.AvgServiceAndShipmentDistance;
import jsprit.core.algorithm.selector.SelectBest;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.analysis.SolutionAnalyser;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.job.Job;
@ -205,8 +206,8 @@ public class BuildAlgorithmFromScratch {
public double getCosts(VehicleRoutingProblemSolution solution) {
SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution,new SolutionAnalyser.DistanceCalculator() {
@Override
public double getDistance(String fromLocationId, String toLocationId) {
return vrp.getTransportCosts().getTransportCost(fromLocationId,toLocationId,0.,null,null);
public double getDistance(Location from, Location to) {
return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null);
}
});
return analyser.getVariableTransportCosts() + solution.getUnassignedJobs().size() * 500.;

View file

@ -23,6 +23,7 @@ import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.algorithm.selector.SelectBest;
import jsprit.core.analysis.SolutionAnalyser;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
@ -99,8 +100,8 @@ public class PickupAndDeliveryExample {
SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution,new SolutionAnalyser.DistanceCalculator() {
@Override
public double getDistance(String fromLocationId, String toLocationId) {
return vrp.getTransportCosts().getTransportCost(fromLocationId,toLocationId,0.,null,null);
public double getDistance(Location from, Location to) {
return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null);
}
});

View file

@ -22,6 +22,7 @@ import jsprit.core.algorithm.selector.SelectBest;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.analysis.SolutionAnalyser;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
@ -113,8 +114,8 @@ public class VRPWithBackhaulsExample2 {
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new SolutionAnalyser.DistanceCalculator() {
@Override
public double getDistance(String fromLocationId, String toLocationId) {
return vrp.getTransportCosts().getTransportCost(fromLocationId,toLocationId,0.,null,null);
public double getDistance(Location from, Location to) {
return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null);
}
});

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.instance.reader;
import jsprit.core.problem.Location;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.vehicle.Vehicle;
@ -114,25 +115,25 @@ public class Figliozzi {
}
@Override
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId),locations.getCoord(toId)) +
transportTimeParameter * getTransportTime(fromId,toId,departureTime, driver, vehicle);
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
transportTimeParameter * getTransportTime(from, to,departureTime, driver, vehicle);
}
@Override
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId),locations.getCoord(toId)) +
transportTimeParameter * getBackwardTransportTime(fromId, toId, arrivalTime, driver, vehicle);
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle);
}
@Override
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
if(fromId.equals(toId)){
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
if(from.equals(to)){
return 0.0;
}
double totalTravelTime = 0.0;
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
double currentTime = departureTime;
for(int i=0;i<timeBins.size();i++){
double timeThreshold = timeBins.get(i);
@ -154,12 +155,12 @@ public class Figliozzi {
@Override
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
if(fromId.equals(toId)){
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
if(from.equals(to)){
return 0.0;
}
double totalTravelTime = 0.0;
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
double currentTime = arrivalTime;
for(int i=timeBins.size()-1;i>=0;i--){
double nextLowerTimeThreshold;

View file

@ -18,6 +18,7 @@
package jsprit.instance.reader;
import jsprit.core.problem.Location;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Locations;
import junit.framework.Assert;
@ -175,7 +176,11 @@ public class FigliozziTest {
@Test
public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100(){
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
Assert.assertEquals(100., tdCosts.getTransportTime("from", "to", 0., null, null), 0.01);
Assert.assertEquals(100., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
}
private Location loc(String from) {
return Location.Builder.newInstance().setId(from).build();
}
@Test
@ -191,7 +196,7 @@ public class FigliozziTest {
20
*/
Assert.assertEquals(76.875,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
Assert.assertEquals(76.875,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
}
@Test
@ -208,7 +213,7 @@ public class FigliozziTest {
20
*/
Assert.assertEquals(65.,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
Assert.assertEquals(65.,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
}
@Test
@ -221,7 +226,7 @@ public class FigliozziTest {
(20,40) 2.5 = 20 --> 50 dist, 20 time : 70 dist, 40 time
(40,60) 1.75 = 30 dist, 17.1428571429 time : 100 dist, 57.1428571429 time
*/
Assert.assertEquals(57.1428571429,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
Assert.assertEquals(57.1428571429,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
}
@Test
@ -238,7 +243,7 @@ public class FigliozziTest {
20
*/
Assert.assertEquals(65.,tdCosts.getBackwardTransportTime("from", "to", 100., null, null),0.01);
Assert.assertEquals(65.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
}
@Test
@ -254,13 +259,13 @@ public class FigliozziTest {
20
*/
Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime("from", "to", 100., null, null),0.01);
Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
}
@Test
public void backwardTimeShouldBeCalculatedCorrectly(){
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
Assert.assertEquals(100.,tdCosts.getBackwardTransportTime("from","to",100.,null,null),0.01);
Assert.assertEquals(100.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"),100.,null,null),0.01);
}
@Test
@ -276,7 +281,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -293,7 +298,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -310,7 +315,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -327,7 +332,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -344,7 +349,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -361,7 +366,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -378,7 +383,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -395,7 +400,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -412,7 +417,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -429,7 +434,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -446,7 +451,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
@ -463,7 +468,7 @@ public class FigliozziTest {
};
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d,100);
double time = tdCosts.getTransportTime("from","to",0.,null,null);
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
Assert.assertEquals(100.,time,0.01);
}
}