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'
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -38,6 +33,7 @@ import jsprit.core.problem.job.Pickup;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverService;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -45,10 +41,17 @@ import jsprit.core.problem.vehicle.VehicleImpl;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class ServiceInsertionAndLoadConstraintsTest {
|
||||
|
||||
|
|
@ -83,6 +86,8 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
ActivityInsertionCostsCalculator activityInsertionCostsCalculator;
|
||||
|
||||
ShipmentInsertionCalculator insertionCalculator;
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
Vehicle vehicle;
|
||||
|
||||
|
|
@ -93,6 +98,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
}
|
||||
|
||||
private void createInsertionCalculator(HardRouteStateLevelConstraint hardRouteLevelConstraint) {
|
||||
|
|
@ -112,8 +118,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new DeliverService(delivery));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(delivery)).thenReturn(acts);
|
||||
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
|
|
|||
|
|
@ -18,21 +18,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.*;
|
||||
import jsprit.core.problem.constraint.ConstraintManager.Priority;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardRouteStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||
import jsprit.core.problem.constraint.ShipmentPickupsFirstConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -42,6 +32,8 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -49,14 +41,24 @@ import jsprit.core.problem.vehicle.VehicleImpl;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class ShipmentInsertionCalculatorTest {
|
||||
|
||||
VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem;
|
||||
|
||||
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){
|
||||
|
||||
|
|
@ -97,6 +99,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
}
|
||||
|
||||
private void createInsertionCalculator(HardRouteStateLevelConstraint hardRouteLevelConstraint) {
|
||||
|
|
@ -119,20 +122,31 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||
assertEquals(0.0,iData.getInsertionCost(),0.05);
|
||||
assertEquals(1,iData.getPickupInsertionIndex());
|
||||
assertEquals(2,iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipment) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
PickupShipment pick = new PickupShipment(shipment);
|
||||
DeliverShipment del = new DeliverShipment(shipment);
|
||||
acts.add(pick);
|
||||
acts.add(del);
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
createInsertionCalculator(new HardRouteStateLevelConstraint() {
|
||||
|
||||
@Override
|
||||
|
|
@ -154,7 +168,9 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,10").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
Inserter inserter = new Inserter(new InsertionListeners(),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route);
|
||||
|
||||
|
|
@ -169,9 +185,10 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route);
|
||||
|
||||
|
|
@ -186,13 +203,14 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
|
@ -222,12 +240,12 @@ public class ShipmentInsertionCalculatorTest {
|
|||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
// inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
|
|
@ -237,8 +255,6 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addLoadConstraint();
|
||||
// constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
||||
// constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL);
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,10 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.ExampleActivityCostFunction;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
|
|
@ -45,12 +38,19 @@ import jsprit.core.problem.vehicle.Vehicle;
|
|||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.ManhattanDistanceCalculator;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -60,9 +60,9 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
VehicleRoutingTransportCosts costs;
|
||||
|
||||
Vehicle vehicle;
|
||||
AbstractVehicle vehicle;
|
||||
|
||||
Vehicle newVehicle;
|
||||
AbstractVehicle newVehicle;
|
||||
|
||||
private Service first;
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
vehicle = mock(AbstractVehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1000).build());
|
||||
|
|
@ -91,7 +91,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
newVehicle = mock(AbstractVehicle.class);
|
||||
when(newVehicle.getType()).thenReturn(type);
|
||||
when(newVehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("0,0");
|
||||
|
|
|
|||
|
|
@ -18,25 +18,34 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
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.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TestInserter {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Service service = mock(Service.class);
|
||||
|
|
@ -54,8 +63,13 @@ public class TestInserter {
|
|||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
PickupService act = new PickupService(serviceToInsert);
|
||||
acts.add(act);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(acts);
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(serviceToInsert, iData, route);
|
||||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -79,17 +93,26 @@ public class TestInserter {
|
|||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(1);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(getTourActivities(serviceToInsert));
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem);
|
||||
inserter.insertJob(serviceToInsert, iData, route);
|
||||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),serviceToInsert.getLocationId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
private List<TourActivity> getTourActivities(Service serviceToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new PickupService(serviceToInsert));
|
||||
return acts;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -102,16 +125,20 @@ public class TestInserter {
|
|||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
// Shipment shipmentToInsert = mock(Shipment.class);
|
||||
// when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
// when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
// when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
// when(shipmentToInsert.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(2);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -119,8 +146,15 @@ public class TestInserter {
|
|||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipmentToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
acts.add(new PickupShipment(shipmentToInsert));
|
||||
acts.add(new DeliverShipment(shipmentToInsert));
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -131,16 +165,15 @@ public class TestInserter {
|
|||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(2);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
|
||||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
|
|
@ -159,17 +192,16 @@ public class TestInserter {
|
|||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(2);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
|
||||
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem);
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(route.getEnd().getLocationId(),newVehicle.getEndLocationId());
|
||||
|
|
@ -185,17 +217,16 @@ public class TestInserter {
|
|||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(2);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
|
||||
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals("delLoc",route.getEnd().getLocationId());
|
||||
|
|
@ -212,17 +243,16 @@ public class TestInserter {
|
|||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").build();
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(0);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(0);
|
||||
when(iData.getSelectedVehicle()).thenReturn(newVehicle);
|
||||
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert));
|
||||
Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem );
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
UpdateEndLocationIfRouteIsOpen updateEnd = new UpdateEndLocationIfRouteIsOpen();
|
||||
|
|
|
|||
|
|
@ -16,37 +16,27 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.constraint.Constraint;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.driver.DriverImpl;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.job.*;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
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.*;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class VehicleRoutingProblemTest {
|
||||
|
||||
|
|
@ -186,9 +176,11 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenDelivieriesAreAdded_vrpShouldContainThem(){
|
||||
Delivery s1 = mock(Delivery.class);
|
||||
when(s1.getId()).thenReturn("s1");
|
||||
when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
Delivery s2 = mock(Delivery.class);
|
||||
when(s2.getId()).thenReturn("s2");
|
||||
|
||||
when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addJob(s1).addJob(s2);
|
||||
|
||||
|
|
@ -203,9 +195,11 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenDelivieriesAreAddedAllAtOnce_vrpShouldContainThem(){
|
||||
Delivery s1 = mock(Delivery.class);
|
||||
when(s1.getId()).thenReturn("s1");
|
||||
when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
Delivery s2 = mock(Delivery.class);
|
||||
when(s2.getId()).thenReturn("s2");
|
||||
|
||||
when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addAllJobs(Arrays.asList(s1,s2));
|
||||
|
||||
|
|
@ -541,4 +535,33 @@ public class VehicleRoutingProblemTest {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
assertFalse(vrp.getJobs().containsKey("myService"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoJobs_theyShouldHaveProperIndeces(){
|
||||
Job service = Service.Builder.newInstance("myService").setLocationId("loc").build();
|
||||
Job shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pick").setDeliveryLocation("del").build();
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addJob(service);
|
||||
vrpBuilder.addJob(shipment);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,service.getIndex());
|
||||
assertEquals(1,shipment.getIndex());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoVehicles_theyShouldHaveProperIndeces(){
|
||||
Vehicle veh1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").setStartLocationCoordinate(Coordinate.newInstance(0, 1)).setEndLocationId("end").build();
|
||||
Vehicle veh2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").setStartLocationCoordinate(Coordinate.newInstance(0, 1)).setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(veh1);
|
||||
vrpBuilder.addVehicle(veh2);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,veh1.getIndex());
|
||||
assertEquals(1,veh2.getIndex());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,9 @@
|
|||
******************************************************************************/
|
||||
package jsprit.examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer;
|
||||
import jsprit.analysis.toolbox.GraphStreamViewer.Label;
|
||||
import jsprit.analysis.toolbox.Plotter;
|
||||
|
||||
import jsprit.analysis.toolbox.SolutionPrinter;
|
||||
import jsprit.analysis.toolbox.SolutionPrinter.Print;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
|
|
@ -29,9 +26,13 @@ import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
|||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.instance.reader.SolomonReader;
|
||||
import jsprit.util.Examples;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class SolomonExample {
|
||||
|
||||
|
|
@ -80,7 +81,14 @@ public class SolomonExample {
|
|||
* Retrieve best solution.
|
||||
*/
|
||||
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);
|
||||
|
||||
|
||||
for(VehicleRoute r : solution.getRoutes()){
|
||||
System.out.println(r.getStart() + ";" + r.getStart().getIndex());
|
||||
for(TourActivity act : r.getActivities()){
|
||||
System.out.println(act + ";" + act.getIndex());
|
||||
}
|
||||
System.out.println(r.getEnd() + ";" + r.getEnd().getIndex());
|
||||
}
|
||||
/*
|
||||
* print solution
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue