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:
parent
a9d1e03c56
commit
842067231d
62 changed files with 2770 additions and 2863 deletions
|
|
@ -36,7 +36,6 @@ import java.util.Collection;
|
|||
* Algorithm that solves a {@link VehicleRoutingProblem}.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class VehicleRoutingAlgorithm {
|
||||
|
||||
|
|
@ -257,7 +256,6 @@ public class VehicleRoutingAlgorithm {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) {
|
||||
if (discoveredSolution == null) return;
|
||||
if (bestEver == null) bestEver = discoveredSolution.getSolution();
|
||||
|
|
|
|||
|
|
@ -245,13 +245,15 @@ public class Jsprit {
|
|||
}
|
||||
|
||||
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.maxShare = maxShare;
|
||||
}
|
||||
|
||||
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.maxShare = maxShare;
|
||||
this.random = random;
|
||||
|
|
@ -297,8 +299,7 @@ public class Jsprit {
|
|||
VehicleFleetManager fm;
|
||||
if (vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)) {
|
||||
fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||
}
|
||||
else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||
} else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||
|
||||
if (stateManager == null) {
|
||||
stateManager = new StateManager(vrp);
|
||||
|
|
@ -356,8 +357,7 @@ public class Jsprit {
|
|||
if (random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) {
|
||||
return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString()))
|
||||
* noiseMaker.maxCosts * random.nextDouble();
|
||||
}
|
||||
else return 0.;
|
||||
} else return 0.;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -392,8 +392,7 @@ public class Jsprit {
|
|||
scorer = getRegretScorer(vrp);
|
||||
regretInsertion.setScoringFunction(scorer);
|
||||
regret = regretInsertion;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||
|
|
@ -413,8 +412,7 @@ public class Jsprit {
|
|||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||
.build();
|
||||
best = bestInsertion;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
||||
.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())));
|
||||
if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())) {
|
||||
prettyBuilder.constructInitialSolutionWith(best, objectiveFunction);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
||||
public class JobInsertionCostsCalculatorBuilder {
|
||||
|
||||
private static class CalculatorPlusListeners {
|
||||
|
|
@ -97,7 +95,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
|
||||
/**
|
||||
* Constructs the builder.
|
||||
*
|
||||
* <p/>
|
||||
* <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.
|
||||
*
|
||||
|
|
@ -112,8 +110,8 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
|
||||
/**
|
||||
* Sets activityStates. MUST be set.
|
||||
* @param stateManager
|
||||
*
|
||||
* @param stateManager
|
||||
* @return
|
||||
*/
|
||||
public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager) {
|
||||
|
|
@ -145,8 +143,9 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param addDefaultCostCalc
|
||||
*/
|
||||
public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc) {
|
||||
|
|
@ -200,15 +199,17 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
* @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null.
|
||||
*/
|
||||
public JobInsertionCostsCalculator build() {
|
||||
if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
||||
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))");
|
||||
if (vrp == null)
|
||||
throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
||||
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;
|
||||
CalculatorPlusListeners standardLocal = null;
|
||||
if (local) {
|
||||
standardLocal = createStandardLocal(vrp, states);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
checkServicesOnly();
|
||||
standardLocal = createStandardRoute(vrp, states, forwardLooking, memory);
|
||||
}
|
||||
|
|
@ -263,8 +264,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
if (activityInsertionCostCalculator == null && addDefaultCostCalc) {
|
||||
actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager);
|
||||
configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc);
|
||||
}
|
||||
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
|
||||
} else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
|
||||
actInsertionCalc = new ActivityInsertionCostsCalculator() {
|
||||
|
||||
@Override
|
||||
|
|
@ -274,8 +274,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
}
|
||||
|
||||
};
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
actInsertionCalc = activityInsertionCostCalculator;
|
||||
}
|
||||
|
||||
|
|
@ -319,8 +318,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2);
|
||||
routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking);
|
||||
routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator;
|
||||
}
|
||||
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
|
||||
} else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
|
||||
routeLevelCostEstimator = new ActivityInsertionCostsCalculator() {
|
||||
|
||||
final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0., 0.);
|
||||
|
|
@ -332,8 +330,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
|||
}
|
||||
|
||||
};
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
routeLevelCostEstimator = activityInsertionCostCalculator;
|
||||
}
|
||||
ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*******************************************************************************
|
||||
* 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
|
||||
* activity i (prevAct) and j (nextAct).
|
||||
* 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.
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator {
|
||||
|
||||
|
|
@ -81,8 +79,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
if (iFacts.getRoute().isEmpty()) {
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
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 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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
* <p/>
|
||||
* <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.
|
||||
* bigger vehicles can take over the route that was previously served by a small vehicle.
|
||||
*
|
||||
*/
|
||||
private boolean vehicleSwitchAllowed = false;
|
||||
|
||||
|
|
@ -104,8 +103,7 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
|||
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(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());
|
||||
}
|
||||
for (Vehicle v : relevantVehicles) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
|
|||
* Updates and memorizes latest operation start times at activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater {
|
||||
|
||||
|
|
@ -56,5 +55,6 @@ public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUp
|
|||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
public void finish() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
|||
}
|
||||
|
||||
|
||||
public void finish() {}
|
||||
public void finish() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,18 +41,15 @@ import java.util.*;
|
|||
|
||||
/**
|
||||
* Contains and defines the vehicle routing problem.
|
||||
*
|
||||
* <p/>
|
||||
* <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/>
|
||||
* <p>By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts),
|
||||
* and activity-costs are set to zero.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public class VehicleRoutingProblem {
|
||||
|
||||
|
|
@ -60,18 +57,18 @@ public class VehicleRoutingProblem {
|
|||
* Builder to build the routing-problem.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new instance of this builder.
|
||||
*
|
||||
* @return builder
|
||||
*/
|
||||
public static Builder newInstance(){ return new Builder(); }
|
||||
public static Builder newInstance() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
|
|
@ -100,8 +97,7 @@ public class VehicleRoutingProblem {
|
|||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
if (job instanceof Service) {
|
||||
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.createDelivery((Shipment) job));
|
||||
}
|
||||
|
|
@ -134,7 +130,9 @@ public class VehicleRoutingProblem {
|
|||
activityIndexCounter++;
|
||||
}
|
||||
|
||||
private void incVehicleTypeIdIndexCounter() { vehicleTypeIdIndexCounter++; }
|
||||
private void incVehicleTypeIdIndexCounter() {
|
||||
vehicleTypeIdIndexCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* <p/>
|
||||
* <p>Locations are cached when adding a shipment, service, depot, vehicle.
|
||||
*
|
||||
* @return locations
|
||||
*
|
||||
**/
|
||||
*/
|
||||
public Locations getLocations() {
|
||||
return new Locations() {
|
||||
|
||||
|
|
@ -179,7 +176,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* Sets the type of fleetSize.
|
||||
*
|
||||
* <p/>
|
||||
* <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
|
||||
|
|
@ -192,7 +189,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param job job to be added
|
||||
|
|
@ -208,7 +205,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
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(!(job instanceof Service || job instanceof Shipment)) throw new IllegalStateException("job must be either a service or a shipment");
|
||||
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 (!(job instanceof Service || job instanceof Shipment))
|
||||
throw new IllegalStateException("job must be either a service or a shipment");
|
||||
job.setIndex(jobIndexCounter);
|
||||
incJobIndexCounter();
|
||||
tentativeJobs.put(job.getId(), job);
|
||||
|
|
@ -228,8 +227,7 @@ public class VehicleRoutingProblem {
|
|||
private void addLocationToTentativeLocations(Job job) {
|
||||
if (job instanceof Service) {
|
||||
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;
|
||||
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
||||
tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate());
|
||||
|
|
@ -240,8 +238,7 @@ public class VehicleRoutingProblem {
|
|||
if (job instanceof Service) {
|
||||
Service service = (Service) job;
|
||||
addService(service);
|
||||
}
|
||||
else if(job instanceof Shipment){
|
||||
} else if (job instanceof Shipment) {
|
||||
Shipment shipment = (Shipment) job;
|
||||
addShipment(shipment);
|
||||
}
|
||||
|
|
@ -278,7 +275,8 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
|
||||
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) {
|
||||
Shipment shipment = (Shipment) job;
|
||||
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
||||
|
|
@ -309,7 +307,9 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
|
||||
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.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate());
|
||||
jobs.put(job.getId(), job);
|
||||
|
|
@ -318,21 +318,20 @@ public class VehicleRoutingProblem {
|
|||
/**
|
||||
* Adds a vehicle.
|
||||
*
|
||||
*
|
||||
* @param vehicle vehicle to be added
|
||||
* @return this builder
|
||||
* @deprecated use addVehicle(AbstractVehicle vehicle) instead
|
||||
*/
|
||||
@Deprecated
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a vehicle.
|
||||
*
|
||||
*
|
||||
* @param vehicle vehicle to be added
|
||||
* @return this builder
|
||||
*/
|
||||
|
|
@ -343,8 +342,7 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
if (typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())) {
|
||||
vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier()));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter);
|
||||
typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(), vehicleTypeIdIndexCounter);
|
||||
incVehicleTypeIdIndexCounter();
|
||||
|
|
@ -367,7 +365,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* Sets the activity-costs.
|
||||
*
|
||||
* <p/>
|
||||
* <p>By default it is set to zero.
|
||||
*
|
||||
* @param activityCosts activity costs of the problem
|
||||
|
|
@ -381,7 +379,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* Builds the {@link VehicleRoutingProblem}.
|
||||
*
|
||||
* <p/>
|
||||
* <p>If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used.
|
||||
*
|
||||
* @return {@link VehicleRoutingProblem}
|
||||
|
|
@ -474,7 +472,6 @@ public class VehicleRoutingProblem {
|
|||
* Enum that characterizes the fleet-size.
|
||||
*
|
||||
* @author sschroeder
|
||||
*
|
||||
*/
|
||||
public static enum FleetSize {
|
||||
FINITE, INFINITE
|
||||
|
|
@ -555,7 +552,7 @@ public class VehicleRoutingProblem {
|
|||
|
||||
/**
|
||||
* Returns type of fleetSize, either INFINITE or FINITE.
|
||||
*
|
||||
* <p/>
|
||||
* <p>By default, it is INFINITE.
|
||||
*
|
||||
* @return either FleetSize.INFINITE or FleetSize.FINITE
|
||||
|
|
@ -642,7 +639,9 @@ public class VehicleRoutingProblem {
|
|||
/**
|
||||
* @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
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
|
||||
|
||||
|
||||
class InfiniteVehicles implements VehicleFleetManager {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(InfiniteVehicles.class);
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
|
||||
/**
|
||||
* 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
|
||||
* 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()) {
|
||||
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
|
||||
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
if (penaltyVehicles.containsKey(key)) {
|
||||
vehicles.add(penaltyVehicles.get(key));
|
||||
}
|
||||
|
|
@ -142,8 +141,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
if (key.equals(thisKey)) continue;
|
||||
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
|
||||
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
if (penaltyVehicles.containsKey(key)) {
|
||||
vehicles.add(penaltyVehicles.get(key));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,25 +23,20 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Vehicle}.
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
|
||||
public class VehicleImpl extends AbstractVehicle {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle'
|
||||
* (to avoid null).
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public static class NoVehicle extends AbstractVehicle {
|
||||
|
||||
|
|
@ -95,13 +90,12 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
|
||||
/**
|
||||
* Builder that builds the vehicle.
|
||||
*
|
||||
* <p/>
|
||||
* <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'
|
||||
* and a capacity of 0.
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
|
|
@ -134,8 +128,8 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
* Sets the {@link VehicleType}.<br>
|
||||
*
|
||||
* @param type the type to be set
|
||||
* @throws IllegalStateException if type is null
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if type is null
|
||||
*/
|
||||
public Builder setType(VehicleType type) {
|
||||
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.
|
||||
*
|
||||
* <p/>
|
||||
* <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
|
||||
* you specify it, it returns to specified end-location.
|
||||
*
|
||||
* <p/>
|
||||
* <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
|
||||
|
|
@ -162,6 +156,7 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
|
||||
/**
|
||||
* Sets start location.
|
||||
*
|
||||
* @param startLocation start location
|
||||
* @return start location
|
||||
*/
|
||||
|
|
@ -204,10 +199,10 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
|
||||
/**
|
||||
* Builds and returns the vehicle.
|
||||
*
|
||||
* <p/>
|
||||
* <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
|
||||
* capacity=0
|
||||
*
|
||||
* <p/>
|
||||
* <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])
|
||||
* <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() {
|
||||
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 (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
|
||||
* @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) {
|
||||
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.
|
||||
*
|
||||
* <p/>
|
||||
* <p>NoVehicle has id="noVehicle" and extends {@link VehicleImpl}
|
||||
*
|
||||
* @return emptyVehicle
|
||||
|
|
@ -283,12 +281,12 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
skills = builder.skills;
|
||||
endLocation = builder.endLocation;
|
||||
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
|
||||
*
|
||||
* <p/>
|
||||
* <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -379,6 +377,4 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,10 @@ import jsprit.core.problem.Capacity;
|
|||
|
||||
/**
|
||||
* Implementation of {@link VehicleType}.
|
||||
*
|
||||
* <p/>
|
||||
* <p>Two vehicle-types are equal if they have the same typeId.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public static class VehicleCostParams {
|
||||
|
||||
|
|
@ -75,12 +73,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* Builder that builds the vehicle-type.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
|
||||
|
||||
public static VehicleTypeImpl.Builder newInstance(String id) {
|
||||
if (id == null) throw new IllegalStateException();
|
||||
return new Builder(id);
|
||||
|
|
@ -118,12 +114,13 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*/
|
||||
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
|
||||
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.
|
||||
*
|
||||
* <p/>
|
||||
* <p>by default it is 0.
|
||||
*
|
||||
* @param fixedCost
|
||||
|
|
@ -138,7 +135,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
/**
|
||||
* Sets the cost per distance unit, for instance € per meter.
|
||||
*
|
||||
* <p/>
|
||||
* <p>by default it is 1.0
|
||||
*
|
||||
* @param perDistance
|
||||
|
|
@ -153,7 +150,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
/**
|
||||
* Sets cost per time unit, for instance € per second.
|
||||
*
|
||||
* <p/>
|
||||
* <p>by default it is 0.0
|
||||
*
|
||||
* @param perTime
|
||||
|
|
@ -170,13 +167,12 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
/**
|
||||
* Sets cost per time unit, for instance € per second.
|
||||
*
|
||||
* <p/>
|
||||
* <p>by default it is 0.0
|
||||
*
|
||||
* @param perTime
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||
*
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
|
||||
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.
|
||||
*
|
||||
* <p/>
|
||||
* <p>by default it is 0.0
|
||||
*
|
||||
* @param perWaitingTime
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||
*
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
|
||||
if (perWaitingTime < 0.0) throw new IllegalStateException();
|
||||
|
|
@ -223,7 +218,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*/
|
||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||
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)." +
|
||||
"You used both methods.");
|
||||
dimensionAdded = true;
|
||||
|
|
@ -233,7 +229,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
/**
|
||||
* Sets capacity dimensions.
|
||||
*
|
||||
* <p/>
|
||||
* <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
|
||||
* this method.
|
||||
|
|
@ -243,7 +239,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @throws IllegalStateException if capacityDimension has already been added
|
||||
*/
|
||||
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)." +
|
||||
"You used both methods.");
|
||||
this.capacityDimensions = capacity;
|
||||
|
|
@ -345,6 +342,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getProfile(){ return profile; }
|
||||
public String getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,10 @@ import jsprit.core.problem.Skills;
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||
|
||||
|
|
@ -93,5 +92,4 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,5 +104,4 @@ public class VariableDepartureAndWaitingTime_IT {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,8 +50,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
||||
|
||||
|
||||
public class TestCalculatesServiceInsertion {
|
||||
|
||||
ServiceInsertionCalculator serviceInsertion;
|
||||
|
|
@ -132,7 +130,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
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() {
|
||||
@Override
|
||||
public List<AbstractActivity> createActivities(Job job) {
|
||||
|
|
|
|||
|
|
@ -498,10 +498,6 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) {
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
|
|
|
|||
|
|
@ -54,14 +54,6 @@ public class VehicleImplTest {
|
|||
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
|
||||
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
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<fleetSize>FINITE</fleetSize>
|
||||
</problemType>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<fleetSize>INFINITE</fleetSize>
|
||||
</problemType>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import java.util.Collection;
|
|||
* Illustrates how you can use jsprit with an already compiled distance and time matrix.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class CostMatrixExample {
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ public class WaitingTimeExample {
|
|||
|
||||
public static void main(String[] args) {
|
||||
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(4.).setCostPerWaitingTime(1.0).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").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(4.0).build();
|
||||
|
||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setReturnToDepot(true)
|
||||
.setStartLocation(Location.newInstance(0, 0))
|
||||
|
|
|
|||
|
|
@ -43,41 +43,6 @@ public class WaitingTimeExample2 {
|
|||
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||
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);
|
||||
vra.setMaxIterations(1000);
|
||||
vra.addListener(new AlgorithmSearchProgressChartListener("output/search"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue