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

merge min-waiting-time branch

This commit is contained in:
oblonski 2015-09-12 13:39:23 +02:00
parent a9d1e03c56
commit 842067231d
62 changed files with 2770 additions and 2863 deletions

View file

@ -36,7 +36,6 @@ import java.util.Collection;
* Algorithm that solves a {@link VehicleRoutingProblem}. * Algorithm that solves a {@link VehicleRoutingProblem}.
* *
* @author stefan schroeder * @author stefan schroeder
*
*/ */
public class VehicleRoutingAlgorithm { public class VehicleRoutingAlgorithm {
@ -257,7 +256,6 @@ public class VehicleRoutingAlgorithm {
} }
private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) { private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) {
if (discoveredSolution == null) return; if (discoveredSolution == null) return;
if (bestEver == null) bestEver = discoveredSolution.getSolution(); if (bestEver == null) bestEver = discoveredSolution.getSolution();

View file

@ -245,13 +245,15 @@ public class Jsprit {
} }
public RuinShareFactoryImpl(int minShare, int maxShare) { public RuinShareFactoryImpl(int minShare, int maxShare) {
if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); if (maxShare < minShare)
throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
this.minShare = minShare; this.minShare = minShare;
this.maxShare = maxShare; this.maxShare = maxShare;
} }
public RuinShareFactoryImpl(int minShare, int maxShare, Random random) { public RuinShareFactoryImpl(int minShare, int maxShare, Random random) {
if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); if (maxShare < minShare)
throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
this.minShare = minShare; this.minShare = minShare;
this.maxShare = maxShare; this.maxShare = maxShare;
this.random = random; this.random = random;
@ -297,8 +299,7 @@ public class Jsprit {
VehicleFleetManager fm; VehicleFleetManager fm;
if (vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)) { if (vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)) {
fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
} } else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
if (stateManager == null) { if (stateManager == null) {
stateManager = new StateManager(vrp); stateManager = new StateManager(vrp);
@ -356,8 +357,7 @@ public class Jsprit {
if (random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) { if (random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) {
return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString())) return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString()))
* noiseMaker.maxCosts * random.nextDouble(); * noiseMaker.maxCosts * random.nextDouble();
} } else return 0.;
else return 0.;
} }
}); });
} }
@ -392,8 +392,7 @@ public class Jsprit {
scorer = getRegretScorer(vrp); scorer = getRegretScorer(vrp);
regretInsertion.setScoringFunction(scorer); regretInsertion.setScoringFunction(scorer);
regret = regretInsertion; regret = regretInsertion;
} } else {
else {
RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager) RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET) .setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
@ -413,8 +412,7 @@ public class Jsprit {
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
.build(); .build();
best = bestInsertion; best = bestInsertion;
} } else {
else{
BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager) BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
.setInsertionStrategy(InsertionBuilder.Strategy.BEST) .setInsertionStrategy(InsertionBuilder.Strategy.BEST)
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString()))) .considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
@ -477,8 +475,7 @@ public class Jsprit {
.withStrategy(clusters_best, toDouble(getProperty(Strategy.CLUSTER_BEST.toString()))); .withStrategy(clusters_best, toDouble(getProperty(Strategy.CLUSTER_BEST.toString())));
if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())) { if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())) {
prettyBuilder.constructInitialSolutionWith(best, objectiveFunction); prettyBuilder.constructInitialSolutionWith(best, objectiveFunction);
} } else {
else{
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction); prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
} }

View file

@ -32,8 +32,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class JobInsertionCostsCalculatorBuilder { public class JobInsertionCostsCalculatorBuilder {
private static class CalculatorPlusListeners { private static class CalculatorPlusListeners {
@ -97,7 +95,7 @@ public class JobInsertionCostsCalculatorBuilder {
/** /**
* Constructs the builder. * Constructs the builder.
* * <p/>
* <p>Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them. * <p>Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them.
* These listeners are cached in the according list and can thus be added when its time to add them. * These listeners are cached in the according list and can thus be added when its time to add them.
* *
@ -112,8 +110,8 @@ public class JobInsertionCostsCalculatorBuilder {
/** /**
* Sets activityStates. MUST be set. * Sets activityStates. MUST be set.
* @param stateManager
* *
* @param stateManager
* @return * @return
*/ */
public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager) { public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager) {
@ -145,8 +143,9 @@ public class JobInsertionCostsCalculatorBuilder {
/** /**
* Sets a flag to build a calculator based on local calculations. * Sets a flag to build a calculator based on local calculations.
* * <p/>
* <p>Insertion of a job and job-activity is evaluated based on the previous and next activity. * <p>Insertion of a job and job-activity is evaluated based on the previous and next activity.
*
* @param addDefaultCostCalc * @param addDefaultCostCalc
*/ */
public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc) { public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc) {
@ -200,15 +199,17 @@ public class JobInsertionCostsCalculatorBuilder {
* @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null. * @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null.
*/ */
public JobInsertionCostsCalculator build() { public JobInsertionCostsCalculator build() {
if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))"); if (vrp == null)
if(states == null) throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))"); throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
if(fleetManager == null) throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))"); if (states == null)
throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))");
if (fleetManager == null)
throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))");
JobInsertionCostsCalculator baseCalculator = null; JobInsertionCostsCalculator baseCalculator = null;
CalculatorPlusListeners standardLocal = null; CalculatorPlusListeners standardLocal = null;
if (local) { if (local) {
standardLocal = createStandardLocal(vrp, states); standardLocal = createStandardLocal(vrp, states);
} } else {
else{
checkServicesOnly(); checkServicesOnly();
standardLocal = createStandardRoute(vrp, states, forwardLooking, memory); standardLocal = createStandardRoute(vrp, states, forwardLooking, memory);
} }
@ -263,8 +264,7 @@ public class JobInsertionCostsCalculatorBuilder {
if (activityInsertionCostCalculator == null && addDefaultCostCalc) { if (activityInsertionCostCalculator == null && addDefaultCostCalc) {
actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager); actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager);
configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc); configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc);
} } else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
actInsertionCalc = new ActivityInsertionCostsCalculator() { actInsertionCalc = new ActivityInsertionCostsCalculator() {
@Override @Override
@ -274,8 +274,7 @@ public class JobInsertionCostsCalculatorBuilder {
} }
}; };
} } else {
else{
actInsertionCalc = activityInsertionCostCalculator; actInsertionCalc = activityInsertionCostCalculator;
} }
@ -319,8 +318,7 @@ public class JobInsertionCostsCalculatorBuilder {
RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2); RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2);
routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking); routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking);
routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator; routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator;
} } else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
routeLevelCostEstimator = new ActivityInsertionCostsCalculator() { routeLevelCostEstimator = new ActivityInsertionCostsCalculator() {
final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0., 0.); final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0., 0.);
@ -332,8 +330,7 @@ public class JobInsertionCostsCalculatorBuilder {
} }
}; };
} } else {
else{
routeLevelCostEstimator = activityInsertionCostCalculator; routeLevelCostEstimator = activityInsertionCostCalculator;
} }
ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager); ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager);

View file

@ -1,4 +1,3 @@
/******************************************************************************* /*******************************************************************************
* Copyright (C) 2014 Stefan Schroeder * Copyright (C) 2014 Stefan Schroeder
* *
@ -32,11 +31,10 @@ import jsprit.core.util.CalculationUtils;
* Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between * Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between
* activity i (prevAct) and j (nextAct). * activity i (prevAct) and j (nextAct).
* Additional costs are then basically calculated as delta c = c_ik + c_kj - c_ij. * Additional costs are then basically calculated as delta c = c_ik + c_kj - c_ij.
* * <p/>
* <p>Note once time has an effect on costs this class requires activity endTimes. * <p>Note once time has an effect on costs this class requires activity endTimes.
* *
* @author stefan * @author stefan
*
*/ */
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator { class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator {
@ -81,8 +79,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
if (iFacts.getRoute().isEmpty()) { if (iFacts.getRoute().isEmpty()) {
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), 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; oldCosts += tp_costs_prevAct_nextAct;
} } else {
else{
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), 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 = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct, nextAct); double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct, nextAct);

View file

@ -47,11 +47,10 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
/** /**
* true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle * true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle
* * <p/>
* <p>vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one * <p>vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one
* can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e. * can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e.
* bigger vehicles can take over the route that was previously served by a small vehicle. * bigger vehicles can take over the route that was previously served by a small vehicle.
*
*/ */
private boolean vehicleSwitchAllowed = false; private boolean vehicleSwitchAllowed = false;
@ -104,8 +103,7 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) { if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) {
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle)); relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
} }
} } else { //if no vehicle has been assigned, i.e. it is an empty route
else{ //if no vehicle has been assigned, i.e. it is an empty route
relevantVehicles.addAll(fleetManager.getAvailableVehicles()); relevantVehicles.addAll(fleetManager.getAvailableVehicles());
} }
for (Vehicle v : relevantVehicles) { for (Vehicle v : relevantVehicles) {

View file

@ -25,7 +25,6 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
* Updates and memorizes latest operation start times at activities. * Updates and memorizes latest operation start times at activities.
* *
* @author schroeder * @author schroeder
*
*/ */
public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater { public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater {
@ -56,5 +55,6 @@ public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUp
} }
@Override @Override
public void finish() {} public void finish() {
}
} }

View file

@ -104,7 +104,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
} }
public void finish() {} public void finish() {
}
} }

View file

@ -41,18 +41,15 @@ import java.util.*;
/** /**
* Contains and defines the vehicle routing problem. * Contains and defines the vehicle routing problem.
* * <p/>
* <p>A routing problem is defined as jobs, vehicles, costs and constraints. * <p>A routing problem is defined as jobs, vehicles, costs and constraints.
* * <p/>
* <p> To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance(). * <p> To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance().
* * <p/>
* <p>By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts), * <p>By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts),
* and activity-costs are set to zero. * and activity-costs are set to zero.
* *
*
*
* @author stefan schroeder * @author stefan schroeder
*
*/ */
public class VehicleRoutingProblem { public class VehicleRoutingProblem {
@ -60,18 +57,18 @@ public class VehicleRoutingProblem {
* Builder to build the routing-problem. * Builder to build the routing-problem.
* *
* @author stefan schroeder * @author stefan schroeder
*
*/ */
public static class Builder { public static class Builder {
/** /**
* Returns a new instance of this builder. * Returns a new instance of this builder.
* *
* @return builder * @return builder
*/ */
public static Builder newInstance(){ return new Builder(); } public static Builder newInstance() {
return new Builder();
}
private VehicleRoutingTransportCosts transportCosts; private VehicleRoutingTransportCosts transportCosts;
@ -100,8 +97,7 @@ public class VehicleRoutingProblem {
List<AbstractActivity> acts = new ArrayList<AbstractActivity>(); List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
if (job instanceof Service) { if (job instanceof Service) {
acts.add(serviceActivityFactory.createActivity((Service) job)); acts.add(serviceActivityFactory.createActivity((Service) job));
} } else if (job instanceof Shipment) {
else if(job instanceof Shipment){
acts.add(shipmentActivityFactory.createPickup((Shipment) job)); acts.add(shipmentActivityFactory.createPickup((Shipment) job));
acts.add(shipmentActivityFactory.createDelivery((Shipment) job)); acts.add(shipmentActivityFactory.createDelivery((Shipment) job));
} }
@ -134,7 +130,9 @@ public class VehicleRoutingProblem {
activityIndexCounter++; activityIndexCounter++;
} }
private void incVehicleTypeIdIndexCounter() { vehicleTypeIdIndexCounter++; } private void incVehicleTypeIdIndexCounter() {
vehicleTypeIdIndexCounter++;
}
/** /**
* Returns the unmodifiable map of collected locations (mapped by their location-id). * Returns the unmodifiable map of collected locations (mapped by their location-id).
@ -147,12 +145,11 @@ public class VehicleRoutingProblem {
/** /**
* Returns the locations collected SO FAR by this builder. * Returns the locations collected SO FAR by this builder.
* * <p/>
* <p>Locations are cached when adding a shipment, service, depot, vehicle. * <p>Locations are cached when adding a shipment, service, depot, vehicle.
* *
* @return locations * @return locations
* */
**/
public Locations getLocations() { public Locations getLocations() {
return new Locations() { return new Locations() {
@ -179,7 +176,7 @@ public class VehicleRoutingProblem {
/** /**
* Sets the type of fleetSize. * Sets the type of fleetSize.
* * <p/>
* <p>FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE. * <p>FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE.
* *
* @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE * @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE
@ -192,7 +189,7 @@ public class VehicleRoutingProblem {
/** /**
* Adds a job which is either a service or a shipment. * Adds a job which is either a service or a shipment.
* * <p/>
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id. * <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
* *
* @param job job to be added * @param job job to be added
@ -208,7 +205,7 @@ public class VehicleRoutingProblem {
/** /**
* Adds a job which is either a service or a shipment. * Adds a job which is either a service or a shipment.
* * <p/>
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id. * <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
* *
* @param job job to be added * @param job job to be added
@ -216,8 +213,10 @@ public class VehicleRoutingProblem {
* @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added. * @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added.
*/ */
public Builder addJob(AbstractJob job) { public Builder addJob(AbstractJob job) {
if(tentativeJobs.containsKey(job.getId())) throw new IllegalStateException("jobList already contains a job with id " + job.getId() + ". make sure you use unique ids for your jobs (i.e. service and shipments)"); if (tentativeJobs.containsKey(job.getId()))
if(!(job instanceof Service || job instanceof Shipment)) throw new IllegalStateException("job must be either a service or a shipment"); throw new IllegalStateException("jobList already contains a job with id " + job.getId() + ". make sure you use unique ids for your jobs (i.e. service and shipments)");
if (!(job instanceof Service || job instanceof Shipment))
throw new IllegalStateException("job must be either a service or a shipment");
job.setIndex(jobIndexCounter); job.setIndex(jobIndexCounter);
incJobIndexCounter(); incJobIndexCounter();
tentativeJobs.put(job.getId(), job); tentativeJobs.put(job.getId(), job);
@ -228,8 +227,7 @@ public class VehicleRoutingProblem {
private void addLocationToTentativeLocations(Job job) { private void addLocationToTentativeLocations(Job job) {
if (job instanceof Service) { if (job instanceof Service) {
tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate()); tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate());
} } else if (job instanceof Shipment) {
else if(job instanceof Shipment){
Shipment shipment = (Shipment) job; Shipment shipment = (Shipment) job;
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate()); tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate()); tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate());
@ -240,8 +238,7 @@ public class VehicleRoutingProblem {
if (job instanceof Service) { if (job instanceof Service) {
Service service = (Service) job; Service service = (Service) job;
addService(service); addService(service);
} } else if (job instanceof Shipment) {
else if(job instanceof Shipment){
Shipment shipment = (Shipment) job; Shipment shipment = (Shipment) job;
addShipment(shipment); addShipment(shipment);
} }
@ -278,7 +275,8 @@ public class VehicleRoutingProblem {
} }
private void registerLocation(Job job) { private void registerLocation(Job job) {
if (job instanceof Service) tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate()); if (job instanceof Service)
tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate());
if (job instanceof Shipment) { if (job instanceof Shipment) {
Shipment shipment = (Shipment) job; Shipment shipment = (Shipment) job;
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate()); tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
@ -309,7 +307,9 @@ public class VehicleRoutingProblem {
} }
private void addShipment(Shipment job) { private void addShipment(Shipment job) {
if(jobs.containsKey(job.getId())){ logger.warn("job " + job + " already in job list. overrides existing job."); } if (jobs.containsKey(job.getId())) {
logger.warn("job " + job + " already in job list. overrides existing job.");
}
tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate()); tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate());
tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate()); tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate());
jobs.put(job.getId(), job); jobs.put(job.getId(), job);
@ -318,21 +318,20 @@ public class VehicleRoutingProblem {
/** /**
* Adds a vehicle. * Adds a vehicle.
* *
*
* @param vehicle vehicle to be added * @param vehicle vehicle to be added
* @return this builder * @return this builder
* @deprecated use addVehicle(AbstractVehicle vehicle) instead * @deprecated use addVehicle(AbstractVehicle vehicle) instead
*/ */
@Deprecated @Deprecated
public Builder addVehicle(Vehicle vehicle) { public Builder addVehicle(Vehicle vehicle) {
if(!(vehicle instanceof AbstractVehicle)) throw new IllegalStateException("vehicle must be an AbstractVehicle"); if (!(vehicle instanceof AbstractVehicle))
throw new IllegalStateException("vehicle must be an AbstractVehicle");
return addVehicle((AbstractVehicle) vehicle); return addVehicle((AbstractVehicle) vehicle);
} }
/** /**
* Adds a vehicle. * Adds a vehicle.
* *
*
* @param vehicle vehicle to be added * @param vehicle vehicle to be added
* @return this builder * @return this builder
*/ */
@ -343,8 +342,7 @@ public class VehicleRoutingProblem {
} }
if (typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())) { if (typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())) {
vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier())); vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier()));
} } else {
else {
vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter); vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter);
typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(), vehicleTypeIdIndexCounter); typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(), vehicleTypeIdIndexCounter);
incVehicleTypeIdIndexCounter(); incVehicleTypeIdIndexCounter();
@ -367,7 +365,7 @@ public class VehicleRoutingProblem {
/** /**
* Sets the activity-costs. * Sets the activity-costs.
* * <p/>
* <p>By default it is set to zero. * <p>By default it is set to zero.
* *
* @param activityCosts activity costs of the problem * @param activityCosts activity costs of the problem
@ -381,7 +379,7 @@ public class VehicleRoutingProblem {
/** /**
* Builds the {@link VehicleRoutingProblem}. * Builds the {@link VehicleRoutingProblem}.
* * <p/>
* <p>If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used. * <p>If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used.
* *
* @return {@link VehicleRoutingProblem} * @return {@link VehicleRoutingProblem}
@ -474,7 +472,6 @@ public class VehicleRoutingProblem {
* Enum that characterizes the fleet-size. * Enum that characterizes the fleet-size.
* *
* @author sschroeder * @author sschroeder
*
*/ */
public static enum FleetSize { public static enum FleetSize {
FINITE, INFINITE FINITE, INFINITE
@ -555,7 +552,7 @@ public class VehicleRoutingProblem {
/** /**
* Returns type of fleetSize, either INFINITE or FINITE. * Returns type of fleetSize, either INFINITE or FINITE.
* * <p/>
* <p>By default, it is INFINITE. * <p>By default, it is INFINITE.
* *
* @return either FleetSize.INFINITE or FleetSize.FINITE * @return either FleetSize.INFINITE or FleetSize.FINITE
@ -642,7 +639,9 @@ public class VehicleRoutingProblem {
/** /**
* @return total number of activities * @return total number of activities
*/ */
public int getNuActivities(){ return nuActivities; } public int getNuActivities() {
return nuActivities;
}
/** /**
* @return factory that creates the activities associated to a job * @return factory that creates the activities associated to a job

View file

@ -25,8 +25,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
class InfiniteVehicles implements VehicleFleetManager { class InfiniteVehicles implements VehicleFleetManager {
private static Logger logger = LogManager.getLogger(InfiniteVehicles.class); private static Logger logger = LogManager.getLogger(InfiniteVehicles.class);

View file

@ -114,7 +114,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
/** /**
* Returns a collection of available vehicles. * Returns a collection of available vehicles.
* * <p/>
* <p>If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with * <p>If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with
* this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned. * this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned.
*/ */
@ -124,8 +124,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
for (VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()) { for (VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()) {
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) { if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle()); vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
} } else {
else{
if (penaltyVehicles.containsKey(key)) { if (penaltyVehicles.containsKey(key)) {
vehicles.add(penaltyVehicles.get(key)); vehicles.add(penaltyVehicles.get(key));
} }
@ -142,8 +141,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
if (key.equals(thisKey)) continue; if (key.equals(thisKey)) continue;
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) { if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle()); vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
} } else {
else{
if (penaltyVehicles.containsKey(key)) { if (penaltyVehicles.containsKey(key)) {
vehicles.add(penaltyVehicles.get(key)); vehicles.add(penaltyVehicles.get(key));
} }

View file

@ -23,25 +23,20 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
/** /**
* Implementation of {@link Vehicle}. * Implementation of {@link Vehicle}.
* *
* @author stefan schroeder * @author stefan schroeder
*
*/ */
public class VehicleImpl extends AbstractVehicle { public class VehicleImpl extends AbstractVehicle {
/** /**
* Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle' * Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle'
* (to avoid null). * (to avoid null).
* *
* @author schroeder * @author schroeder
*
*/ */
public static class NoVehicle extends AbstractVehicle { public static class NoVehicle extends AbstractVehicle {
@ -95,13 +90,12 @@ public class VehicleImpl extends AbstractVehicle{
/** /**
* Builder that builds the vehicle. * Builder that builds the vehicle.
* * <p/>
* <p>By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE, * <p>By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE,
* it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default' * it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default'
* and a capacity of 0. * and a capacity of 0.
* *
* @author stefan * @author stefan
*
*/ */
public static class Builder { public static class Builder {
@ -134,8 +128,8 @@ public class VehicleImpl extends AbstractVehicle{
* Sets the {@link VehicleType}.<br> * Sets the {@link VehicleType}.<br>
* *
* @param type the type to be set * @param type the type to be set
* @throws IllegalStateException if type is null
* @return this builder * @return this builder
* @throws IllegalStateException if type is null
*/ */
public Builder setType(VehicleType type) { public Builder setType(VehicleType type) {
if (type == null) throw new IllegalStateException("type cannot be null."); if (type == null) throw new IllegalStateException("type cannot be null.");
@ -145,11 +139,11 @@ public class VehicleImpl extends AbstractVehicle{
/** /**
* Sets the flag whether the vehicle must return to depot or not. * Sets the flag whether the vehicle must return to depot or not.
* * <p/>
* <p>If returnToDepot is true, the vehicle must return to specified end-location. If you * <p>If returnToDepot is true, the vehicle must return to specified end-location. If you
* omit specifying the end-location, vehicle returns to start-location (that must to be set). If * omit specifying the end-location, vehicle returns to start-location (that must to be set). If
* you specify it, it returns to specified end-location. * you specify it, it returns to specified end-location.
* * <p/>
* <p>If returnToDepot is false, the end-location of the vehicle is endogenous. * <p>If returnToDepot is false, the end-location of the vehicle is endogenous.
* *
* @param returnToDepot true if vehicle need to return to depot, otherwise false * @param returnToDepot true if vehicle need to return to depot, otherwise false
@ -162,6 +156,7 @@ public class VehicleImpl extends AbstractVehicle{
/** /**
* Sets start location. * Sets start location.
*
* @param startLocation start location * @param startLocation start location
* @return start location * @return start location
*/ */
@ -204,10 +199,10 @@ public class VehicleImpl extends AbstractVehicle{
/** /**
* Builds and returns the vehicle. * Builds and returns the vehicle.
* * <p/>
* <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and * <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
* capacity=0 * capacity=0
* * <p/>
* <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString() * <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString()
* and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val]) * and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val])
* <p>if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString() * <p>if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString()
@ -220,7 +215,8 @@ public class VehicleImpl extends AbstractVehicle{
*/ */
public VehicleImpl build() { public VehicleImpl build() {
if (startLocation != null && endLocation != null) { if (startLocation != null && endLocation != null) {
if( !startLocation.getId().equals(endLocation.getId()) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" + if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
} }
if (startLocation != null && endLocation == null) { if (startLocation != null && endLocation == null) {
@ -239,7 +235,9 @@ public class VehicleImpl extends AbstractVehicle{
* @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles * @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles
* @return vehicle builder * @return vehicle builder
*/ */
public static Builder newInstance(String vehicleId){ return new Builder(vehicleId); } public static Builder newInstance(String vehicleId) {
return new Builder(vehicleId);
}
public Builder addSkills(Skills skills) { public Builder addSkills(Skills skills) {
this.skillBuilder.addAllSkills(skills.values()); this.skillBuilder.addAllSkills(skills.values());
@ -249,7 +247,7 @@ public class VehicleImpl extends AbstractVehicle{
/** /**
* Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id. * Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id.
* * <p/>
* <p>NoVehicle has id="noVehicle" and extends {@link VehicleImpl} * <p>NoVehicle has id="noVehicle" and extends {@link VehicleImpl}
* *
* @return emptyVehicle * @return emptyVehicle
@ -283,12 +281,12 @@ public class VehicleImpl extends AbstractVehicle{
skills = builder.skills; skills = builder.skills;
endLocation = builder.endLocation; endLocation = builder.endLocation;
startLocation = builder.startLocation; startLocation = builder.startLocation;
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills)); setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot));
} }
/** /**
* Returns String with attributes of this vehicle * Returns String with attributes of this vehicle
* * <p/>
* <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn] * <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
*/ */
@Override @Override
@ -379,6 +377,4 @@ public class VehicleImpl extends AbstractVehicle{
} }
} }

View file

@ -21,11 +21,10 @@ import jsprit.core.problem.Capacity;
/** /**
* Implementation of {@link VehicleType}. * Implementation of {@link VehicleType}.
* * <p/>
* <p>Two vehicle-types are equal if they have the same typeId. * <p>Two vehicle-types are equal if they have the same typeId.
* *
* @author schroeder * @author schroeder
*
*/ */
public class VehicleTypeImpl implements VehicleType { public class VehicleTypeImpl implements VehicleType {
@ -33,7 +32,6 @@ public class VehicleTypeImpl implements VehicleType {
* CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter. * CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter.
* *
* @author schroeder * @author schroeder
*
*/ */
public static class VehicleCostParams { public static class VehicleCostParams {
@ -75,12 +73,10 @@ public class VehicleTypeImpl implements VehicleType {
* Builder that builds the vehicle-type. * Builder that builds the vehicle-type.
* *
* @author schroeder * @author schroeder
*
*/ */
public static class Builder { public static class Builder {
public static VehicleTypeImpl.Builder newInstance(String id) { public static VehicleTypeImpl.Builder newInstance(String id) {
if (id == null) throw new IllegalStateException(); if (id == null) throw new IllegalStateException();
return new Builder(id); return new Builder(id);
@ -118,12 +114,13 @@ public class VehicleTypeImpl implements VehicleType {
*/ */
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero"); if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero");
this.maxVelo = inMeterPerSeconds; return this; this.maxVelo = inMeterPerSeconds;
return this;
} }
/** /**
* Sets the fixed costs of the vehicle-type. * Sets the fixed costs of the vehicle-type.
* * <p/>
* <p>by default it is 0. * <p>by default it is 0.
* *
* @param fixedCost * @param fixedCost
@ -138,7 +135,7 @@ public class VehicleTypeImpl implements VehicleType {
/** /**
* Sets the cost per distance unit, for instance per meter. * Sets the cost per distance unit, for instance per meter.
* * <p/>
* <p>by default it is 1.0 * <p>by default it is 1.0
* *
* @param perDistance * @param perDistance
@ -153,7 +150,7 @@ public class VehicleTypeImpl implements VehicleType {
/** /**
* Sets cost per time unit, for instance per second. * Sets cost per time unit, for instance per second.
* * <p/>
* <p>by default it is 0.0 * <p>by default it is 0.0
* *
* @param perTime * @param perTime
@ -170,13 +167,12 @@ public class VehicleTypeImpl implements VehicleType {
/** /**
* Sets cost per time unit, for instance per second. * Sets cost per time unit, for instance per second.
* * <p/>
* <p>by default it is 0.0 * <p>by default it is 0.0
* *
* @param perTime * @param perTime
* @return this builder * @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero * @throws IllegalStateException if costPerTime is smaller than zero
*
*/ */
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) { public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
if (perTime < 0.0) throw new IllegalStateException(); if (perTime < 0.0) throw new IllegalStateException();
@ -186,13 +182,12 @@ public class VehicleTypeImpl implements VehicleType {
/** /**
* Sets cost per waiting time unit, for instance per second. * Sets cost per waiting time unit, for instance per second.
* * <p/>
* <p>by default it is 0.0 * <p>by default it is 0.0
* *
* @param perWaitingTime * @param perWaitingTime
* @return this builder * @return this builder
* @throws IllegalStateException if costPerTime is smaller than zero * @throws IllegalStateException if costPerTime is smaller than zero
*
*/ */
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) { public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
if (perWaitingTime < 0.0) throw new IllegalStateException(); if (perWaitingTime < 0.0) throw new IllegalStateException();
@ -223,7 +218,8 @@ public class VehicleTypeImpl implements VehicleType {
*/ */
public Builder addCapacityDimension(int dimIndex, int dimVal) { public Builder addCapacityDimension(int dimIndex, int dimVal) {
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
if(capacityDimensions != null) throw new IllegalStateException("either build your dimension with build your dimensions with " + if (capacityDimensions != null)
throw new IllegalStateException("either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
dimensionAdded = true; dimensionAdded = true;
@ -233,7 +229,7 @@ public class VehicleTypeImpl implements VehicleType {
/** /**
* Sets capacity dimensions. * Sets capacity dimensions.
* * <p/>
* <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)</code> anymore. Thus either build * <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)</code> anymore. Thus either build
* your dimensions with <code>addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions with * your dimensions with <code>addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions with
* this method. * this method.
@ -243,7 +239,8 @@ public class VehicleTypeImpl implements VehicleType {
* @throws IllegalStateException if capacityDimension has already been added * @throws IllegalStateException if capacityDimension has already been added
*/ */
public Builder setCapacityDimensions(Capacity capacity) { public Builder setCapacityDimensions(Capacity capacity) {
if(dimensionAdded) throw new IllegalStateException("either build your dimension with build your dimensions with " + if (dimensionAdded)
throw new IllegalStateException("either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
this.capacityDimensions = capacity; this.capacityDimensions = capacity;
@ -345,6 +342,8 @@ public class VehicleTypeImpl implements VehicleType {
} }
@Override @Override
public String getProfile(){ return profile; } public String getProfile() {
return profile;
}
} }

View file

@ -23,11 +23,10 @@ import jsprit.core.problem.Skills;
/** /**
* Key to identify similar vehicles * Key to identify similar vehicles
* * <p/>
* <p>Two vehicles are equal if they share the same type, the same start and end-location and the same earliestStart and latestStart. * <p>Two vehicles are equal if they share the same type, the same start and end-location and the same earliestStart and latestStart.
* *
* @author stefan * @author stefan
*
*/ */
public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey { public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
@ -93,5 +92,4 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
} }
} }

View file

@ -104,5 +104,4 @@ public class VariableDepartureAndWaitingTime_IT {
} }
} }

View file

@ -50,8 +50,6 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class TestCalculatesServiceInsertion { public class TestCalculatesServiceInsertion {
ServiceInsertionCalculator serviceInsertion; ServiceInsertionCalculator serviceInsertion;
@ -132,7 +130,7 @@ public class TestCalculatesServiceInsertion {
VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class); VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class);
serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts), cManager); serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts, states), cManager);
serviceInsertion.setJobActivityFactory(new JobActivityFactory() { serviceInsertion.setJobActivityFactory(new JobActivityFactory() {
@Override @Override
public List<AbstractActivity> createActivities(Job job) { public List<AbstractActivity> createActivities(Job job) {

View file

@ -498,10 +498,6 @@ public class TestLocalActivityInsertionCostsCalculator {
} }
private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) { private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) {
StateManager stateManager = new StateManager(vrp); StateManager stateManager = new StateManager(vrp);
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts())); stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));

View file

@ -54,14 +54,6 @@ public class VehicleImplTest {
assertTrue(v.getSkills().containsSkill("ScrewDriver")); assertTrue(v.getSkills().containsSkill("ScrewDriver"));
} }
@Test
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").build();
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
}
@Test @Test
public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot() { public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot() {
@ -221,26 +213,6 @@ public class VehicleImplTest {
} }
@Test
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").addSkill("screwdriver").build();
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("screwdriver"));
}
@Test
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").addSkill("screwdriver").build();
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("dRill"));
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
}
@Test @Test
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com" <problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType> <problemType>
<fleetSize>FINITE</fleetSize> <fleetSize>FINITE</fleetSize>
</problemType> </problemType>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com" <problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType> <problemType>
<fleetSize>INFINITE</fleetSize> <fleetSize>INFINITE</fleetSize>
</problemType> </problemType>

View file

@ -40,7 +40,6 @@ import java.util.Collection;
* Illustrates how you can use jsprit with an already compiled distance and time matrix. * Illustrates how you can use jsprit with an already compiled distance and time matrix.
* *
* @author schroeder * @author schroeder
*
*/ */
public class CostMatrixExample { public class CostMatrixExample {

View file

@ -26,8 +26,8 @@ public class WaitingTimeExample {
public static void main(String[] args) { public static void main(String[] args) {
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(4.).setCostPerWaitingTime(1.0).build(); VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(4.).setCostPerWaitingTime(4.0).build();
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").setCostPerDistance(4.).setCostPerWaitingTime(1.0).build(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").setCostPerDistance(4.).setCostPerWaitingTime(4.0).build();
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setReturnToDepot(true) VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setReturnToDepot(true)
.setStartLocation(Location.newInstance(0, 0)) .setStartLocation(Location.newInstance(0, 0))

View file

@ -43,41 +43,6 @@ public class WaitingTimeExample2 {
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
final VehicleRoutingProblem vrp = vrpBuilder.build(); final VehicleRoutingProblem vrp = vrpBuilder.build();
// AlgorithmFactory algorithmFactory = new AlgorithmFactory() {
// @Override
// public VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) {
// StateManager stateManager = new StateManager(vrp);
// stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager,vrp.getTransportCosts()));
// ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
//
// return Jsprit.Builder.newInstance(vrp)
// .addCoreStateAndConstraintStuff(true)
// .setStateAndConstraintManager(stateManager, constraintManager)
//// .setProperty(Jsprit.Parameter.THRESHOLD_INI, "0.1")
//// .setProperty(Jsprit.Parameter.THRESHOLD_ALPHA, "0.3")
//// .setProperty(Parameter.)
//// .setProperty(Jsprit.Parameter.CONSTRUCTION, Jsprit.Construction.BEST_INSERTION.toString())
// .setObjectiveFunction(new SolutionCostCalculator() {
// @Override
// public double getCosts(VehicleRoutingProblemSolution solution) {
// double costs = 0.;
// for (VehicleRoute route : solution.getRoutes()) {
// costs += route.getVehicle().getType().getVehicleCostParams().fix;
// TourActivity prevAct = route.getStart();
// for (TourActivity act : route.getActivities()) {
// costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
// costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
// prevAct = act;
// }
// costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
// }
// costs += solution.getUnassignedJobs().size() * 200;
// return costs;
// }
// })
// .buildAlgorithm();
// }
// };
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000); vra.setMaxIterations(1000);
vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); vra.addListener(new AlgorithmSearchProgressChartListener("output/search"));