mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added indeces to main elements
This commit is contained in:
parent
aa1b7214ae
commit
4f2689529f
33 changed files with 512 additions and 243 deletions
|
|
@ -16,23 +16,19 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -88,10 +84,10 @@ final class BestInsertion implements InsertionStrategy{
|
|||
this.random = random;
|
||||
}
|
||||
|
||||
public BestInsertion(JobInsertionCostsCalculator jobInsertionCalculator) {
|
||||
public BestInsertion(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem) {
|
||||
super();
|
||||
this.insertionsListeners = new InsertionListeners();
|
||||
inserter = new Inserter(insertionsListeners);
|
||||
inserter = new Inserter(insertionsListeners, vehicleRoutingProblem);
|
||||
bestInsertionCostCalculator = jobInsertionCalculator;
|
||||
logger.info("initialise " + this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
|
|
@ -29,6 +25,10 @@ import jsprit.core.problem.VehicleRoutingProblem;
|
|||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
|
||||
public class BestInsertionBuilder {
|
||||
|
||||
|
|
@ -150,12 +150,10 @@ public class BestInsertionBuilder {
|
|||
JobInsertionCostsCalculator jobInsertions = calcBuilder.build();
|
||||
InsertionStrategy bestInsertion;
|
||||
if(executor == null){
|
||||
bestInsertion = new BestInsertion(jobInsertions);
|
||||
|
||||
bestInsertion = new BestInsertion(jobInsertions,vrp);
|
||||
}
|
||||
else{
|
||||
|
||||
bestInsertion = new BestInsertionConcurrent(jobInsertions,executor,nuOfThreads);
|
||||
bestInsertion = new BestInsertionConcurrent(jobInsertions,executor,nuOfThreads,vrp);
|
||||
|
||||
}
|
||||
for(InsertionListener l : iListeners) bestInsertion.addListener(l);
|
||||
|
|
@ -164,8 +162,8 @@ public class BestInsertionBuilder {
|
|||
|
||||
/**
|
||||
* @deprecated this is experimental and can disappear.
|
||||
* @param parseDouble
|
||||
* @param parseInt
|
||||
* @param timeSlice the time slice
|
||||
* @param nNeighbors number of neighbors
|
||||
*/
|
||||
@Deprecated
|
||||
public void experimentalTimeScheduler(double timeSlice, int nNeighbors) {
|
||||
|
|
|
|||
|
|
@ -16,28 +16,20 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListener;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.RandomNumberGeneration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -104,12 +96,12 @@ final class BestInsertionConcurrent implements InsertionStrategy{
|
|||
this.random = random;
|
||||
}
|
||||
|
||||
public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches) {
|
||||
public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches, VehicleRoutingProblem vehicleRoutingProblem) {
|
||||
super();
|
||||
this.insertionsListeners = new InsertionListeners();
|
||||
this.executor = executorService;
|
||||
this.nuOfBatches = nuOfBatches;
|
||||
inserter = new Inserter(insertionsListeners);
|
||||
inserter = new Inserter(insertionsListeners, vehicleRoutingProblem);
|
||||
bestInsertionCostCalculator = jobInsertionCalculator;
|
||||
completionService = new ExecutorCompletionService<Insertion>(executor);
|
||||
logger.info("initialise " + this);
|
||||
|
|
|
|||
|
|
@ -18,22 +18,23 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.TourShipmentActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class Inserter {
|
||||
|
||||
interface JobInsertionHandler {
|
||||
|
||||
void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route);
|
||||
|
||||
void setNextHandler(JobInsertionHandler handler);
|
||||
|
||||
}
|
||||
|
||||
class JobExceptionHandler implements JobInsertionHandler{
|
||||
|
|
@ -56,8 +57,14 @@ class Inserter {
|
|||
private TourActivityFactory activityFactory = new DefaultTourActivityFactory();
|
||||
|
||||
private JobInsertionHandler delegator = new JobExceptionHandler();
|
||||
|
||||
@Override
|
||||
|
||||
private VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
public ServiceInsertionHandler(VehicleRoutingProblem vehicleRoutingProblem) {
|
||||
this.vehicleRoutingProblem = vehicleRoutingProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) {
|
||||
if(job instanceof Service){
|
||||
route.setVehicleAndDepartureTime(iData.getSelectedVehicle(),iData.getVehicleDepartureTime());
|
||||
|
|
@ -66,7 +73,8 @@ class Inserter {
|
|||
setEndLocation(route,(Service)job);
|
||||
}
|
||||
}
|
||||
route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), this.activityFactory.createActivity((Service)job));
|
||||
TourActivity activity = vehicleRoutingProblem.copyAndGetActivities(job).get(0);
|
||||
route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), activity);
|
||||
}
|
||||
else delegator.handleJobInsertion(job, iData, route);
|
||||
}
|
||||
|
|
@ -82,16 +90,23 @@ class Inserter {
|
|||
}
|
||||
|
||||
class ShipmentInsertionHandler implements JobInsertionHandler {
|
||||
|
||||
private TourShipmentActivityFactory activityFactory = new DefaultShipmentActivityFactory();
|
||||
|
||||
private final VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
private TourShipmentActivityFactory activityFactory = new DefaultShipmentActivityFactory();
|
||||
|
||||
private JobInsertionHandler delegator = new JobExceptionHandler();
|
||||
|
||||
@Override
|
||||
|
||||
public ShipmentInsertionHandler(VehicleRoutingProblem vehicleRoutingProblem) {
|
||||
this.vehicleRoutingProblem = vehicleRoutingProblem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) {
|
||||
if(job instanceof Shipment){
|
||||
TourActivity pickupShipment = this.activityFactory.createPickup((Shipment)job);
|
||||
TourActivity deliverShipment = this.activityFactory.createDelivery((Shipment)job);
|
||||
List<TourActivity> acts = vehicleRoutingProblem.copyAndGetActivities(job);
|
||||
TourActivity pickupShipment = acts.get(0);
|
||||
TourActivity deliverShipment = acts.get(1);
|
||||
route.setVehicleAndDepartureTime(iData.getSelectedVehicle(),iData.getVehicleDepartureTime());
|
||||
if(!iData.getSelectedVehicle().isReturnToDepot()){
|
||||
if(iData.getDeliveryInsertionIndex()>=route.getActivities().size()){
|
||||
|
|
@ -117,12 +132,14 @@ class Inserter {
|
|||
private InsertionListeners insertionListeners;
|
||||
|
||||
private JobInsertionHandler jobInsertionHandler;
|
||||
|
||||
private VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
public Inserter(InsertionListeners insertionListeners) {
|
||||
public Inserter(InsertionListeners insertionListeners, VehicleRoutingProblem vehicleRoutingProblem) {
|
||||
this.insertionListeners = insertionListeners;
|
||||
new DefaultTourActivityFactory();
|
||||
jobInsertionHandler = new ServiceInsertionHandler();
|
||||
jobInsertionHandler.setNextHandler(new ShipmentInsertionHandler());
|
||||
jobInsertionHandler = new ServiceInsertionHandler(vehicleRoutingProblem);
|
||||
jobInsertionHandler.setNextHandler(new ShipmentInsertionHandler(vehicleRoutingProblem));
|
||||
}
|
||||
|
||||
public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute){
|
||||
|
|
@ -130,7 +147,7 @@ class Inserter {
|
|||
|
||||
if(insertionData == null || (insertionData instanceof NoInsertionFound)) throw new IllegalStateException("insertionData null. cannot insert job.");
|
||||
if(job == null) throw new IllegalStateException("cannot insert null-job");
|
||||
if(!(vehicleRoute.getVehicle().getId().toString().equals(insertionData.getSelectedVehicle().getId().toString()))){
|
||||
if(!(vehicleRoute.getVehicle().getId().equals(insertionData.getSelectedVehicle().getId()))){
|
||||
insertionListeners.informVehicleSwitched(vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle());
|
||||
vehicleRoute.setVehicleAndDepartureTime(insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 14.07.14.
|
||||
*/
|
||||
public abstract class AbstractJob implements Job {
|
||||
|
||||
private int index;
|
||||
|
||||
public int getIndex(){ return index; }
|
||||
|
||||
protected void setIndex(int index){ this.index = index; }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 14.07.14.
|
||||
*/
|
||||
public abstract class AbstractTourActivity implements TourActivity {
|
||||
|
||||
private int index;
|
||||
|
||||
public int getIndex(){ return index; }
|
||||
|
||||
protected void setIndex(int index){ this.index = index; }
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 14.07.14.
|
||||
*/
|
||||
public abstract class AbstractVehicle implements Vehicle {
|
||||
|
||||
private int index;
|
||||
|
||||
public int getIndex(){ return index; }
|
||||
|
||||
protected void setIndex(int index){ this.index = index; }
|
||||
}
|
||||
10
jsprit-core/src/main/java/jsprit/core/problem/HasId.java
Normal file
10
jsprit-core/src/main/java/jsprit/core/problem/HasId.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 14.07.14.
|
||||
*/
|
||||
public interface HasId {
|
||||
|
||||
public String getId();
|
||||
|
||||
}
|
||||
10
jsprit-core/src/main/java/jsprit/core/problem/HasIndex.java
Normal file
10
jsprit-core/src/main/java/jsprit/core/problem/HasIndex.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 14.07.14.
|
||||
*/
|
||||
public interface HasIndex {
|
||||
|
||||
public int getIndex();
|
||||
|
||||
}
|
||||
|
|
@ -16,15 +16,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -32,19 +23,17 @@ import jsprit.core.problem.job.Job;
|
|||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.PenaltyVehicleType;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeKey;
|
||||
import jsprit.core.problem.vehicle.*;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.CrowFlyCosts;
|
||||
import jsprit.core.util.Locations;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Contains and defines the vehicle routing problem.
|
||||
|
|
@ -71,7 +60,9 @@ public class VehicleRoutingProblem {
|
|||
*/
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new instance of this builder.
|
||||
*
|
||||
* @return builder
|
||||
|
|
@ -122,6 +113,19 @@ public class VehicleRoutingProblem {
|
|||
|
||||
private Double penaltyFixedCosts = null;
|
||||
|
||||
private int jobIndexCounter = 0;
|
||||
|
||||
private int vehicleIndexCounter = 0;
|
||||
|
||||
private int activityIndexCounter = 0;
|
||||
|
||||
private Map<Job,List<TourActivity>> activityMap = new HashMap<Job, List<TourActivity>>();
|
||||
// private ArrayList<List<TourActivity>> activityList;
|
||||
|
||||
private DefaultShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory();
|
||||
|
||||
private DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory();
|
||||
|
||||
/**
|
||||
* Create a location (i.e. coordinate) and returns the key of the location which is Coordinate.toString().
|
||||
*
|
||||
|
|
@ -141,6 +145,14 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
|
||||
|
||||
private void incJobIndexCounter(){
|
||||
jobIndexCounter++;
|
||||
}
|
||||
|
||||
private void incActivityIndexCounter(){
|
||||
activityIndexCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unmodifiable map of collected locations (mapped by their location-id).
|
||||
*
|
||||
|
|
@ -203,14 +215,32 @@ public class VehicleRoutingProblem {
|
|||
* @param job
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added.
|
||||
* @deprecated use addJob(AbstractJob job) instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder addJob(Job 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");
|
||||
tentativeJobs.put(job.getId(), job);
|
||||
addLocationToTentativeLocations(job);
|
||||
return this;
|
||||
if(!(job instanceof AbstractJob)) throw new IllegalArgumentException("job must be of type AbstractJob");
|
||||
return addJob((AbstractJob)job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a job which is either a service or a shipment.
|
||||
*
|
||||
* <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
|
||||
* @return this builder
|
||||
* @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");
|
||||
job.setIndex(jobIndexCounter);
|
||||
incJobIndexCounter();
|
||||
tentativeJobs.put(job.getId(), job);
|
||||
addLocationToTentativeLocations(job);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addLocationToTentativeLocations(Job job) {
|
||||
if(job instanceof Service) {
|
||||
|
|
@ -223,12 +253,29 @@ public class VehicleRoutingProblem {
|
|||
}
|
||||
}
|
||||
|
||||
private void addJobToFinalJobMap(Job job){
|
||||
if(job instanceof Service) {
|
||||
addService((Service) job);
|
||||
private void addJobToFinalJobMapAndCreateActivities(Job job){
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
if(job instanceof Service) {
|
||||
Service service = (Service) job;
|
||||
addService(service);
|
||||
AbstractTourActivity activity = serviceActivityFactory.createActivity(service);
|
||||
activity.setIndex(activityIndexCounter);
|
||||
incActivityIndexCounter();
|
||||
acts.add(activity);
|
||||
activityMap.put(service, acts);
|
||||
}
|
||||
else if(job instanceof Shipment){
|
||||
addShipment((Shipment)job);
|
||||
Shipment shipment = (Shipment)job;
|
||||
addShipment(shipment);
|
||||
AbstractTourActivity pickup = shipmentActivityFactory.createPickup(shipment);
|
||||
pickup.setIndex(activityIndexCounter);
|
||||
incActivityIndexCounter();
|
||||
AbstractTourActivity delivery = shipmentActivityFactory.createDelivery(shipment);
|
||||
delivery.setIndex(activityIndexCounter);
|
||||
incActivityIndexCounter();
|
||||
acts.add(pickup);
|
||||
acts.add(delivery);
|
||||
activityMap.put(shipment, acts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,23 +319,45 @@ public class VehicleRoutingProblem {
|
|||
*
|
||||
* @param vehicle
|
||||
* @return this builder
|
||||
* @deprecated use addVehicle(AbstractVehicle vehicle) instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder addVehicle(Vehicle vehicle) {
|
||||
uniqueVehicles.add(vehicle);
|
||||
if(!vehicleTypes.contains(vehicle.getType())){
|
||||
vehicleTypes.add(vehicle.getType());
|
||||
}
|
||||
String startLocationId = vehicle.getStartLocationId();
|
||||
coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
|
||||
tentative_coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
|
||||
if(!vehicle.getEndLocationId().equals(startLocationId)){
|
||||
coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
|
||||
tentative_coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
|
||||
}
|
||||
return this;
|
||||
if(!(vehicle instanceof AbstractVehicle)) throw new IllegalStateException("vehicle must be an AbstractVehicle");
|
||||
return addVehicle((AbstractVehicle)vehicle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Adds a vehicle.
|
||||
*
|
||||
*
|
||||
* @param vehicle
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder addVehicle(AbstractVehicle vehicle) {
|
||||
if(!uniqueVehicles.contains(vehicle)){
|
||||
vehicle.setIndex(vehicleIndexCounter);
|
||||
incVehicleIndexCounter();
|
||||
}
|
||||
uniqueVehicles.add(vehicle);
|
||||
if(!vehicleTypes.contains(vehicle.getType())){
|
||||
vehicleTypes.add(vehicle.getType());
|
||||
}
|
||||
String startLocationId = vehicle.getStartLocationId();
|
||||
coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
|
||||
tentative_coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
|
||||
if(!vehicle.getEndLocationId().equals(startLocationId)){
|
||||
coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
|
||||
tentative_coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void incVehicleIndexCounter() {
|
||||
vehicleIndexCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the activity-costs.
|
||||
*
|
||||
* <p>By default it is set to zero.
|
||||
|
|
@ -323,15 +392,15 @@ public class VehicleRoutingProblem {
|
|||
addPenaltyVehicles();
|
||||
}
|
||||
}
|
||||
for(Job job : tentativeJobs.values()){
|
||||
if(!jobsInInitialRoutes.contains(job.getId())){
|
||||
addJobToFinalJobMap(job);
|
||||
}
|
||||
}
|
||||
for(Job job : tentativeJobs.values())
|
||||
if (!jobsInInitialRoutes.contains(job.getId())) {
|
||||
addJobToFinalJobMapAndCreateActivities(job);
|
||||
}
|
||||
return new VehicleRoutingProblem(this);
|
||||
}
|
||||
|
||||
private void addPenaltyVehicles() {
|
||||
|
||||
private void addPenaltyVehicles() {
|
||||
Set<VehicleTypeKey> vehicleTypeKeys = new HashSet<VehicleTypeKey>();
|
||||
List<Vehicle> uniqueVehicles = new ArrayList<Vehicle>();
|
||||
for(Vehicle v : this.uniqueVehicles){
|
||||
|
|
@ -551,6 +620,9 @@ public class VehicleRoutingProblem {
|
|||
private final Collection<jsprit.core.problem.constraint.Constraint> constraints;
|
||||
|
||||
private final Locations locations;
|
||||
|
||||
private Map<Job,List<TourActivity>> activityMap;
|
||||
// private List<List<TourActivity>> activityList;
|
||||
|
||||
private VehicleRoutingProblem(Builder builder) {
|
||||
this.jobs = builder.jobs;
|
||||
|
|
@ -562,6 +634,7 @@ public class VehicleRoutingProblem {
|
|||
this.activityCosts = builder.activityCosts;
|
||||
this.constraints = builder.constraints;
|
||||
this.locations = builder.getLocations();
|
||||
this.activityMap = builder.activityMap;
|
||||
logger.info("initialise " + this);
|
||||
}
|
||||
|
||||
|
|
@ -645,5 +718,17 @@ public class VehicleRoutingProblem {
|
|||
public Locations getLocations(){
|
||||
return locations;
|
||||
}
|
||||
|
||||
public List<TourActivity> getActivities(Job job){
|
||||
return Collections.unmodifiableList(activityMap.get(job));
|
||||
}
|
||||
|
||||
public List<TourActivity> copyAndGetActivities(Job job){
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
for(TourActivity act : activityMap.get(job)){
|
||||
acts.add(act.duplicate());
|
||||
}
|
||||
return acts;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package jsprit.core.problem.job;
|
|||
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.HasId;
|
||||
import jsprit.core.problem.HasIndex;
|
||||
|
||||
/**
|
||||
* Basic interface for all jobs.
|
||||
|
|
@ -25,7 +27,7 @@ import jsprit.core.problem.Capacity;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public interface Job {
|
||||
public interface Job extends HasId, HasIndex {
|
||||
|
||||
/**
|
||||
* Returns the unique identifier (id) of a job.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import jsprit.core.problem.AbstractJob;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
|
@ -31,7 +32,7 @@ import jsprit.core.util.Coordinate;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class Service implements Job {
|
||||
public class Service extends AbstractJob {
|
||||
|
||||
/**
|
||||
* Builder that builds a service.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import jsprit.core.problem.AbstractJob;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
|
@ -39,7 +40,7 @@ import jsprit.core.util.Coordinate;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class Shipment implements Job{
|
||||
public class Shipment extends AbstractJob{
|
||||
|
||||
/**
|
||||
* Builder that builds the shipment.
|
||||
|
|
|
|||
|
|
@ -18,17 +18,18 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public class DefaultShipmentActivityFactory implements TourShipmentActivityFactory{
|
||||
|
||||
@Override
|
||||
public TourActivity createPickup(Shipment shipment) {
|
||||
public AbstractTourActivity createPickup(Shipment shipment) {
|
||||
return new PickupShipment(shipment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TourActivity createDelivery(Shipment shipment) {
|
||||
public AbstractTourActivity createDelivery(Shipment shipment) {
|
||||
return new DeliverShipment(shipment);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
|
@ -23,8 +24,8 @@ import jsprit.core.problem.job.Service;
|
|||
public class DefaultTourActivityFactory implements TourActivityFactory{
|
||||
|
||||
@Override
|
||||
public TourActivity createActivity(Service service) {
|
||||
TourActivity act;
|
||||
public AbstractTourActivity createActivity(Service service) {
|
||||
AbstractTourActivity act;
|
||||
if(service instanceof Pickup){
|
||||
act = new PickupService((Pickup) service);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
|
||||
public final class DeliverService implements DeliveryActivity{
|
||||
public final class DeliverService extends AbstractTourActivity implements DeliveryActivity{
|
||||
|
||||
private Delivery delivery;
|
||||
|
||||
|
|
@ -42,6 +43,7 @@ public final class DeliverService implements DeliveryActivity{
|
|||
this.arrTime=deliveryActivity.getArrTime();
|
||||
this.endTime=deliveryActivity.getEndTime();
|
||||
capacity = deliveryActivity.getSize();
|
||||
setIndex(deliveryActivity.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public final class DeliverShipment implements DeliveryActivity{
|
||||
public final class DeliverShipment extends AbstractTourActivity implements DeliveryActivity{
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
|
|
@ -38,11 +39,13 @@ public final class DeliverShipment implements DeliveryActivity{
|
|||
this.capacity = Capacity.invert(shipment.getSize());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DeliverShipment(DeliverShipment deliveryShipmentActivity) {
|
||||
this.shipment = (Shipment) deliveryShipmentActivity.getJob();
|
||||
this.arrTime = deliveryShipmentActivity.getArrTime();
|
||||
this.endTime = deliveryShipmentActivity.getEndTime();
|
||||
this.capacity = deliveryShipmentActivity.getSize();
|
||||
setIndex(deliveryShipmentActivity.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
public final class End implements TourActivity {
|
||||
public final class End extends AbstractTourActivity implements TourActivity {
|
||||
|
||||
@Deprecated
|
||||
public static int creation = 0;
|
||||
|
||||
public static End newInstance(String locationId, double earliestArrival, double latestArrival) {
|
||||
|
|
@ -69,6 +71,7 @@ public final class End implements TourActivity {
|
|||
theoretical_earliestOperationStartTime = theoreticalStart;
|
||||
theoretical_latestOperationStartTime = theoreticalEnd;
|
||||
endTime = theoreticalEnd;
|
||||
setIndex(-2);
|
||||
}
|
||||
|
||||
public End(End end) {
|
||||
|
|
@ -77,6 +80,7 @@ public final class End implements TourActivity {
|
|||
theoretical_latestOperationStartTime = end.getTheoreticalLatestOperationStartTime();
|
||||
arrTime = end.getArrTime();
|
||||
endTime = end.getEndTime();
|
||||
setIndex(-2);
|
||||
}
|
||||
|
||||
public double getTheoreticalEarliestOperationStartTime() {
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
public final class PickupService implements PickupActivity{
|
||||
public final class PickupService extends AbstractTourActivity implements PickupActivity{
|
||||
|
||||
private Service pickup;
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ public final class PickupService implements PickupActivity{
|
|||
this.pickup=pickupActivity.getJob();
|
||||
this.arrTime=pickupActivity.getArrTime();
|
||||
this.depTime=pickupActivity.getEndTime();
|
||||
setIndex(pickupActivity.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public final class PickupShipment implements PickupActivity{
|
||||
public final class PickupShipment extends AbstractTourActivity implements PickupActivity{
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
|
|
@ -35,10 +36,12 @@ public final class PickupShipment implements PickupActivity{
|
|||
this.shipment = shipment;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public PickupShipment(PickupShipment pickupShipmentActivity) {
|
||||
this.shipment = (Shipment) pickupShipmentActivity.getJob();
|
||||
this.arrTime = pickupShipmentActivity.getArrTime();
|
||||
this.endTime = pickupShipmentActivity.getEndTime();
|
||||
setIndex(pickupShipmentActivity.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
|
||||
|
||||
public class ServiceActivity implements JobActivity{
|
||||
public class ServiceActivity extends AbstractTourActivity implements JobActivity{
|
||||
|
||||
public static int counter = 0;
|
||||
|
||||
|
|
@ -77,6 +78,7 @@ public class ServiceActivity implements JobActivity{
|
|||
this.service = serviceActivity.getJob();
|
||||
this.arrTime = serviceActivity.getArrTime();
|
||||
this.endTime = serviceActivity.getEndTime();
|
||||
setIndex(serviceActivity.getIndex());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
|
||||
public final class Start implements TourActivity {
|
||||
public final class Start extends AbstractTourActivity implements TourActivity {
|
||||
|
||||
public final static String ACTIVITY_NAME = "start";
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static int creation;
|
||||
|
||||
private final static Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -51,7 +53,7 @@ public final class Start implements TourActivity {
|
|||
this.theoretical_earliestOperationStartTime = theoreticalStart;
|
||||
this.theoretical_latestOperationStartTime = theoreticalEnd;
|
||||
this.endTime = theoreticalStart;
|
||||
|
||||
setIndex(-1);
|
||||
}
|
||||
|
||||
private Start(Start start) {
|
||||
|
|
@ -59,6 +61,7 @@ public final class Start implements TourActivity {
|
|||
theoretical_earliestOperationStartTime = start.getTheoreticalEarliestOperationStartTime();
|
||||
theoretical_latestOperationStartTime = start.getTheoreticalLatestOperationStartTime();
|
||||
endTime = start.getEndTime();
|
||||
setIndex(-1);
|
||||
}
|
||||
|
||||
public double getTheoreticalEarliestOperationStartTime() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.HasIndex;
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
||||
/**
|
||||
|
|
@ -27,7 +28,7 @@ import jsprit.core.problem.job.Job;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public interface TourActivity {
|
||||
public interface TourActivity extends HasIndex {
|
||||
|
||||
/**
|
||||
* Basic interface of job-activies.
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
public interface TourActivityFactory {
|
||||
|
||||
public TourActivity createActivity(Service service);
|
||||
public AbstractTourActivity createActivity(Service service);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.AbstractTourActivity;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public interface TourShipmentActivityFactory {
|
||||
|
||||
public TourActivity createPickup(Shipment shipment);
|
||||
public AbstractTourActivity createPickup(Shipment shipment);
|
||||
|
||||
public TourActivity createDelivery(Shipment shipment);
|
||||
public AbstractTourActivity createDelivery(Shipment shipment);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.HasId;
|
||||
import jsprit.core.problem.HasIndex;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
/**
|
||||
|
|
@ -24,7 +26,7 @@ import jsprit.core.util.Coordinate;
|
|||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public interface Vehicle {
|
||||
public interface Vehicle extends HasId, HasIndex {
|
||||
|
||||
/**
|
||||
* Returns the earliest departure of vehicle which should be the lower bound of this vehicle's departure times.
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
*/
|
||||
|
||||
public class VehicleImpl implements Vehicle {
|
||||
public class VehicleImpl extends AbstractVehicle{
|
||||
|
||||
/**
|
||||
* Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue