mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
merge min-waiting-time branch
This commit is contained in:
parent
a9d1e03c56
commit
842067231d
62 changed files with 2770 additions and 2863 deletions
|
|
@ -116,7 +116,7 @@ public class PrettyAlgorithmBuilder {
|
||||||
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
||||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS));
|
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS));
|
||||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||||
stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager,vrp.getTransportCosts()));
|
stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager, vrp.getTransportCosts()));
|
||||||
}
|
}
|
||||||
VehicleRoutingAlgorithm vra = new VehicleRoutingAlgorithm(vrp, searchStrategyManager);
|
VehicleRoutingAlgorithm vra = new VehicleRoutingAlgorithm(vrp, searchStrategyManager);
|
||||||
vra.addListener(stateManager);
|
vra.addListener(stateManager);
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import java.util.Collection;
|
||||||
* Algorithm that solves a {@link VehicleRoutingProblem}.
|
* Algorithm that solves a {@link VehicleRoutingProblem}.
|
||||||
*
|
*
|
||||||
* @author stefan schroeder
|
* @author stefan schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VehicleRoutingAlgorithm {
|
public class VehicleRoutingAlgorithm {
|
||||||
|
|
||||||
|
|
@ -44,14 +43,14 @@ public class VehicleRoutingAlgorithm {
|
||||||
|
|
||||||
private Collection<PrematureAlgorithmTermination> terminationCriteria = new ArrayList<PrematureAlgorithmTermination>();
|
private Collection<PrematureAlgorithmTermination> terminationCriteria = new ArrayList<PrematureAlgorithmTermination>();
|
||||||
|
|
||||||
void addTermination(PrematureAlgorithmTermination termination){
|
void addTermination(PrematureAlgorithmTermination termination) {
|
||||||
terminationCriteria.add(termination);
|
terminationCriteria.add(termination);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
|
public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
|
||||||
for(PrematureAlgorithmTermination termination : terminationCriteria){
|
for (PrematureAlgorithmTermination termination : terminationCriteria) {
|
||||||
if(termination.isPrematureBreak(discoveredSolution)){
|
if (termination.isPrematureBreak(discoveredSolution)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,15 +195,15 @@ public class VehicleRoutingAlgorithm {
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>(initialSolutions);
|
Collection<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>(initialSolutions);
|
||||||
algorithmStarts(problem, solutions);
|
algorithmStarts(problem, solutions);
|
||||||
bestEver = Solutions.bestOf(solutions);
|
bestEver = Solutions.bestOf(solutions);
|
||||||
if(logger.isTraceEnabled()) log(solutions);
|
if (logger.isTraceEnabled()) log(solutions);
|
||||||
logger.info("iterations start");
|
logger.info("iterations start");
|
||||||
for(int i=0;i< maxIterations;i++){
|
for (int i = 0; i < maxIterations; i++) {
|
||||||
iterationStarts(i+1,problem,solutions);
|
iterationStarts(i + 1, problem, solutions);
|
||||||
logger.debug("start iteration: {}",i);
|
logger.debug("start iteration: {}", i);
|
||||||
counter.incCounter();
|
counter.incCounter();
|
||||||
SearchStrategy strategy = searchStrategyManager.getRandomStrategy();
|
SearchStrategy strategy = searchStrategyManager.getRandomStrategy();
|
||||||
DiscoveredSolution discoveredSolution = strategy.run(problem, solutions);
|
DiscoveredSolution discoveredSolution = strategy.run(problem, solutions);
|
||||||
if(logger.isTraceEnabled()) log(discoveredSolution);
|
if (logger.isTraceEnabled()) log(discoveredSolution);
|
||||||
memorizeIfBestEver(discoveredSolution);
|
memorizeIfBestEver(discoveredSolution);
|
||||||
selectedStrategy(discoveredSolution, problem, solutions);
|
selectedStrategy(discoveredSolution, problem, solutions);
|
||||||
if (terminationManager.isPrematureBreak(discoveredSolution)) {
|
if (terminationManager.isPrematureBreak(discoveredSolution)) {
|
||||||
|
|
@ -226,16 +225,16 @@ public class VehicleRoutingAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(Collection<VehicleRoutingProblemSolution> solutions) {
|
private void log(Collection<VehicleRoutingProblemSolution> solutions) {
|
||||||
for(VehicleRoutingProblemSolution sol : solutions) log(sol);
|
for (VehicleRoutingProblemSolution sol : solutions) log(sol);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(VehicleRoutingProblemSolution solution){
|
private void log(VehicleRoutingProblemSolution solution) {
|
||||||
logger.trace("solution costs: {}",solution.getCost());
|
logger.trace("solution costs: {}", solution.getCost());
|
||||||
for(VehicleRoute r : solution.getRoutes()){
|
for (VehicleRoute r : solution.getRoutes()) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
b.append(r.getVehicle().getId()).append(" : ").append("[ ");
|
b.append(r.getVehicle().getId()).append(" : ").append("[ ");
|
||||||
for(TourActivity act : r.getActivities()){
|
for (TourActivity act : r.getActivities()) {
|
||||||
if(act instanceof TourActivity.JobActivity){
|
if (act instanceof TourActivity.JobActivity) {
|
||||||
b.append(((TourActivity.JobActivity) act).getJob().getId()).append(" ");
|
b.append(((TourActivity.JobActivity) act).getJob().getId()).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +243,7 @@ public class VehicleRoutingAlgorithm {
|
||||||
}
|
}
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
b.append("unassigned : [ ");
|
b.append("unassigned : [ ");
|
||||||
for(Job j : solution.getUnassignedJobs()){
|
for (Job j : solution.getUnassignedJobs()) {
|
||||||
b.append(j.getId()).append(" ");
|
b.append(j.getId()).append(" ");
|
||||||
}
|
}
|
||||||
b.append("]");
|
b.append("]");
|
||||||
|
|
@ -252,12 +251,11 @@ public class VehicleRoutingAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void log(DiscoveredSolution discoveredSolution) {
|
private void log(DiscoveredSolution discoveredSolution) {
|
||||||
logger.trace("discovered solution: {}",discoveredSolution);
|
logger.trace("discovered solution: {}", discoveredSolution);
|
||||||
log(discoveredSolution.getSolution());
|
log(discoveredSolution.getSolution());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) {
|
private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) {
|
||||||
if (discoveredSolution == null) return;
|
if (discoveredSolution == null) return;
|
||||||
if (bestEver == null) bestEver = discoveredSolution.getSolution();
|
if (bestEver == null) bestEver = discoveredSolution.getSolution();
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,11 @@ public class Jsprit {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
Construction(String name){
|
Construction(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,11 +63,11 @@ public class Jsprit {
|
||||||
|
|
||||||
String strategyName;
|
String strategyName;
|
||||||
|
|
||||||
Strategy(String strategyName){
|
Strategy(String strategyName) {
|
||||||
this.strategyName = strategyName;
|
this.strategyName = strategyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return strategyName;
|
return strategyName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,17 +97,17 @@ public class Jsprit {
|
||||||
|
|
||||||
String paraName;
|
String paraName;
|
||||||
|
|
||||||
Parameter(String name){
|
Parameter(String name) {
|
||||||
this.paraName = name;
|
this.paraName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return paraName;
|
return paraName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vehicleRoutingProblem){
|
public static VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vehicleRoutingProblem) {
|
||||||
return Jsprit.Builder.newInstance(vehicleRoutingProblem).buildAlgorithm();
|
return Jsprit.Builder.newInstance(vehicleRoutingProblem).buildAlgorithm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,53 +131,53 @@ public class Jsprit {
|
||||||
|
|
||||||
private Random random = RandomNumberGeneration.newInstance();
|
private Random random = RandomNumberGeneration.newInstance();
|
||||||
|
|
||||||
public static Builder newInstance(VehicleRoutingProblem vrp){
|
public static Builder newInstance(VehicleRoutingProblem vrp) {
|
||||||
return new Builder(vrp);
|
return new Builder(vrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Builder(VehicleRoutingProblem vrp){
|
private Builder(VehicleRoutingProblem vrp) {
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
properties = new Properties(createDefaultProperties());
|
properties = new Properties(createDefaultProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties createDefaultProperties() {
|
private Properties createDefaultProperties() {
|
||||||
Properties defaults = new Properties();
|
Properties defaults = new Properties();
|
||||||
defaults.put(Strategy.RADIAL_BEST.toString(),"0.");
|
defaults.put(Strategy.RADIAL_BEST.toString(), "0.");
|
||||||
defaults.put(Strategy.RADIAL_REGRET.toString(),".5");
|
defaults.put(Strategy.RADIAL_REGRET.toString(), ".5");
|
||||||
defaults.put(Strategy.RANDOM_BEST.toString(),".5");
|
defaults.put(Strategy.RANDOM_BEST.toString(), ".5");
|
||||||
defaults.put(Strategy.RANDOM_REGRET.toString(),".5");
|
defaults.put(Strategy.RANDOM_REGRET.toString(), ".5");
|
||||||
defaults.put(Strategy.WORST_BEST.toString(),"0.");
|
defaults.put(Strategy.WORST_BEST.toString(), "0.");
|
||||||
defaults.put(Strategy.WORST_REGRET.toString(),"1.");
|
defaults.put(Strategy.WORST_REGRET.toString(), "1.");
|
||||||
defaults.put(Strategy.CLUSTER_BEST.toString(),"0.");
|
defaults.put(Strategy.CLUSTER_BEST.toString(), "0.");
|
||||||
defaults.put(Strategy.CLUSTER_REGRET.toString(),"1.");
|
defaults.put(Strategy.CLUSTER_REGRET.toString(), "1.");
|
||||||
defaults.put(Parameter.FIXED_COST_PARAM.toString(),"0.");
|
defaults.put(Parameter.FIXED_COST_PARAM.toString(), "0.");
|
||||||
defaults.put(Parameter.VEHICLE_SWITCH.toString(),"true");
|
defaults.put(Parameter.VEHICLE_SWITCH.toString(), "true");
|
||||||
defaults.put(Parameter.ITERATIONS.toString(),"2000");
|
defaults.put(Parameter.ITERATIONS.toString(), "2000");
|
||||||
defaults.put(Parameter.REGRET_DISTANCE_SCORER.toString(),".05");
|
defaults.put(Parameter.REGRET_DISTANCE_SCORER.toString(), ".05");
|
||||||
defaults.put(Parameter.REGRET_TIME_WINDOW_SCORER.toString(),"-.1");
|
defaults.put(Parameter.REGRET_TIME_WINDOW_SCORER.toString(), "-.1");
|
||||||
defaults.put(Parameter.THREADS.toString(),"1");
|
defaults.put(Parameter.THREADS.toString(), "1");
|
||||||
int minShare = (int)Math.min(20, Math.max(3,vrp.getJobs().size() * 0.05));
|
int minShare = (int) Math.min(20, Math.max(3, vrp.getJobs().size() * 0.05));
|
||||||
int maxShare = (int)Math.min(50, Math.max(5,vrp.getJobs().size() * 0.3));
|
int maxShare = (int) Math.min(50, Math.max(5, vrp.getJobs().size() * 0.3));
|
||||||
defaults.put(Parameter.RADIAL_MIN_SHARE.toString(),String.valueOf(minShare));
|
defaults.put(Parameter.RADIAL_MIN_SHARE.toString(), String.valueOf(minShare));
|
||||||
defaults.put(Parameter.RADIAL_MAX_SHARE.toString(),String.valueOf(maxShare));
|
defaults.put(Parameter.RADIAL_MAX_SHARE.toString(), String.valueOf(maxShare));
|
||||||
defaults.put(Parameter.WORST_MIN_SHARE.toString(),String.valueOf(minShare));
|
defaults.put(Parameter.WORST_MIN_SHARE.toString(), String.valueOf(minShare));
|
||||||
defaults.put(Parameter.WORST_MAX_SHARE.toString(),String.valueOf(maxShare));
|
defaults.put(Parameter.WORST_MAX_SHARE.toString(), String.valueOf(maxShare));
|
||||||
defaults.put(Parameter.CLUSTER_MIN_SHARE.toString(),String.valueOf(minShare));
|
defaults.put(Parameter.CLUSTER_MIN_SHARE.toString(), String.valueOf(minShare));
|
||||||
defaults.put(Parameter.CLUSTER_MAX_SHARE.toString(),String.valueOf(maxShare));
|
defaults.put(Parameter.CLUSTER_MAX_SHARE.toString(), String.valueOf(maxShare));
|
||||||
int minShare_ = (int)Math.min(70, Math.max(5,vrp.getJobs().size() * 0.5));
|
int minShare_ = (int) Math.min(70, Math.max(5, vrp.getJobs().size() * 0.5));
|
||||||
int maxShare_ = (int)Math.min(70, Math.max(5,vrp.getJobs().size() * 0.5));
|
int maxShare_ = (int) Math.min(70, Math.max(5, vrp.getJobs().size() * 0.5));
|
||||||
defaults.put(Parameter.RANDOM_REGRET_MIN_SHARE.toString(),String.valueOf(minShare_));
|
defaults.put(Parameter.RANDOM_REGRET_MIN_SHARE.toString(), String.valueOf(minShare_));
|
||||||
defaults.put(Parameter.RANDOM_REGRET_MAX_SHARE.toString(),String.valueOf(maxShare_));
|
defaults.put(Parameter.RANDOM_REGRET_MAX_SHARE.toString(), String.valueOf(maxShare_));
|
||||||
defaults.put(Parameter.RANDOM_BEST_MIN_SHARE.toString(),String.valueOf(minShare_));
|
defaults.put(Parameter.RANDOM_BEST_MIN_SHARE.toString(), String.valueOf(minShare_));
|
||||||
defaults.put(Parameter.RANDOM_BEST_MAX_SHARE.toString(),String.valueOf(maxShare_));
|
defaults.put(Parameter.RANDOM_BEST_MAX_SHARE.toString(), String.valueOf(maxShare_));
|
||||||
defaults.put(Parameter.THRESHOLD_ALPHA.toString(),String.valueOf(0.15));
|
defaults.put(Parameter.THRESHOLD_ALPHA.toString(), String.valueOf(0.15));
|
||||||
defaults.put(Parameter.THRESHOLD_INI.toString(),String.valueOf(0.03));
|
defaults.put(Parameter.THRESHOLD_INI.toString(), String.valueOf(0.03));
|
||||||
defaults.put(Parameter.INSERTION_NOISE_LEVEL.toString(),String.valueOf(0.15));
|
defaults.put(Parameter.INSERTION_NOISE_LEVEL.toString(), String.valueOf(0.15));
|
||||||
defaults.put(Parameter.INSERTION_NOISE_PROB.toString(),String.valueOf(0.2));
|
defaults.put(Parameter.INSERTION_NOISE_PROB.toString(), String.valueOf(0.2));
|
||||||
defaults.put(Parameter.RUIN_WORST_NOISE_LEVEL.toString(),String.valueOf(0.15));
|
defaults.put(Parameter.RUIN_WORST_NOISE_LEVEL.toString(), String.valueOf(0.15));
|
||||||
defaults.put(Parameter.RUIN_WORST_NOISE_PROB.toString(),String.valueOf(0.2));
|
defaults.put(Parameter.RUIN_WORST_NOISE_PROB.toString(), String.valueOf(0.2));
|
||||||
defaults.put(Parameter.VEHICLE_SWITCH.toString(),String.valueOf(true));
|
defaults.put(Parameter.VEHICLE_SWITCH.toString(), String.valueOf(true));
|
||||||
defaults.put(Parameter.CONSTRUCTION.toString(),Construction.REGRET_INSERTION.toString());
|
defaults.put(Parameter.CONSTRUCTION.toString(), Construction.REGRET_INSERTION.toString());
|
||||||
return defaults;
|
return defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,23 +188,23 @@ public class Jsprit {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setRandom(Random random){
|
public Builder setRandom(Random random) {
|
||||||
this.random = random;
|
this.random = random;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProperty(String key, String value){
|
public Builder setProperty(String key, String value) {
|
||||||
properties.put(key,value);
|
properties.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProperty(Parameter parameter, String value){
|
public Builder setProperty(Parameter parameter, String value) {
|
||||||
setProperty(parameter.toString(),value);
|
setProperty(parameter.toString(), value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProperty(Strategy strategy, String value){
|
public Builder setProperty(Strategy strategy, String value) {
|
||||||
setProperty(strategy.toString(),value);
|
setProperty(strategy.toString(), value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,7 +224,7 @@ public class Jsprit {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VehicleRoutingAlgorithm buildAlgorithm(){
|
public VehicleRoutingAlgorithm buildAlgorithm() {
|
||||||
return new Jsprit(this).create(vrp);
|
return new Jsprit(this).create(vrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,13 +245,15 @@ public class Jsprit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuinShareFactoryImpl(int minShare, int maxShare) {
|
public RuinShareFactoryImpl(int minShare, int maxShare) {
|
||||||
if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
|
if (maxShare < minShare)
|
||||||
|
throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
|
||||||
this.minShare = minShare;
|
this.minShare = minShare;
|
||||||
this.maxShare = maxShare;
|
this.maxShare = maxShare;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuinShareFactoryImpl(int minShare, int maxShare, Random random) {
|
public RuinShareFactoryImpl(int minShare, int maxShare, Random random) {
|
||||||
if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
|
if (maxShare < minShare)
|
||||||
|
throw new IllegalArgumentException("maxShare must be equal or greater than minShare");
|
||||||
this.minShare = minShare;
|
this.minShare = minShare;
|
||||||
this.maxShare = maxShare;
|
this.maxShare = maxShare;
|
||||||
this.random = random;
|
this.random = random;
|
||||||
|
|
@ -293,18 +295,17 @@ public class Jsprit {
|
||||||
this.random = builder.random;
|
this.random = builder.random;
|
||||||
}
|
}
|
||||||
|
|
||||||
private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp){
|
private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
|
||||||
VehicleFleetManager fm;
|
VehicleFleetManager fm;
|
||||||
if(vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)){
|
if (vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)) {
|
||||||
fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||||
}
|
} else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||||
else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
|
||||||
|
|
||||||
if(stateManager == null){
|
if (stateManager == null) {
|
||||||
stateManager = new StateManager(vrp);
|
stateManager = new StateManager(vrp);
|
||||||
}
|
}
|
||||||
if(constraintManager == null){
|
if (constraintManager == null) {
|
||||||
constraintManager = new ConstraintManager(vrp,stateManager);
|
constraintManager = new ConstraintManager(vrp, stateManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
double noiseLevel = toDouble(getProperty(Parameter.INSERTION_NOISE_LEVEL.toString()));
|
double noiseLevel = toDouble(getProperty(Parameter.INSERTION_NOISE_LEVEL.toString()));
|
||||||
|
|
@ -316,7 +317,7 @@ public class Jsprit {
|
||||||
JobNeighborhoods jobNeighborhoods = new JobNeighborhoodsFactory().createNeighborhoods(vrp, new AvgServiceAndShipmentDistance(vrp.getTransportCosts()), (int) (vrp.getJobs().values().size() * 0.5));
|
JobNeighborhoods jobNeighborhoods = new JobNeighborhoodsFactory().createNeighborhoods(vrp, new AvgServiceAndShipmentDistance(vrp.getTransportCosts()), (int) (vrp.getJobs().values().size() * 0.5));
|
||||||
jobNeighborhoods.initialise();
|
jobNeighborhoods.initialise();
|
||||||
|
|
||||||
RuinRadial radial = new RuinRadial(vrp,vrp.getJobs().size(),jobNeighborhoods);
|
RuinRadial radial = new RuinRadial(vrp, vrp.getJobs().size(), jobNeighborhoods);
|
||||||
radial.setRandom(random);
|
radial.setRandom(random);
|
||||||
radial.setRuinShareFactory(new RuinShareFactoryImpl(
|
radial.setRuinShareFactory(new RuinShareFactoryImpl(
|
||||||
toInteger(properties.getProperty(Parameter.RADIAL_MIN_SHARE.toString())),
|
toInteger(properties.getProperty(Parameter.RADIAL_MIN_SHARE.toString())),
|
||||||
|
|
@ -324,7 +325,7 @@ public class Jsprit {
|
||||||
random)
|
random)
|
||||||
);
|
);
|
||||||
|
|
||||||
final RuinRandom random_for_regret = new RuinRandom(vrp,0.5);
|
final RuinRandom random_for_regret = new RuinRandom(vrp, 0.5);
|
||||||
random_for_regret.setRandom(random);
|
random_for_regret.setRandom(random);
|
||||||
random_for_regret.setRuinShareFactory(new RuinShareFactoryImpl(
|
random_for_regret.setRuinShareFactory(new RuinShareFactoryImpl(
|
||||||
toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MIN_SHARE.toString())),
|
toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MIN_SHARE.toString())),
|
||||||
|
|
@ -332,7 +333,7 @@ public class Jsprit {
|
||||||
random)
|
random)
|
||||||
);
|
);
|
||||||
|
|
||||||
final RuinRandom random_for_best = new RuinRandom(vrp,0.5);
|
final RuinRandom random_for_best = new RuinRandom(vrp, 0.5);
|
||||||
random_for_best.setRandom(random);
|
random_for_best.setRandom(random);
|
||||||
random_for_best.setRuinShareFactory(new RuinShareFactoryImpl(
|
random_for_best.setRuinShareFactory(new RuinShareFactoryImpl(
|
||||||
toInteger(properties.getProperty(Parameter.RANDOM_BEST_MIN_SHARE.toString())),
|
toInteger(properties.getProperty(Parameter.RANDOM_BEST_MIN_SHARE.toString())),
|
||||||
|
|
@ -340,7 +341,7 @@ public class Jsprit {
|
||||||
random)
|
random)
|
||||||
);
|
);
|
||||||
|
|
||||||
final RuinWorst worst = new RuinWorst(vrp, (int) (vrp.getJobs().values().size()*0.5));
|
final RuinWorst worst = new RuinWorst(vrp, (int) (vrp.getJobs().values().size() * 0.5));
|
||||||
worst.setRandom(random);
|
worst.setRandom(random);
|
||||||
worst.setRuinShareFactory(new RuinShareFactoryImpl(
|
worst.setRuinShareFactory(new RuinShareFactoryImpl(
|
||||||
toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())),
|
toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())),
|
||||||
|
|
@ -353,17 +354,16 @@ public class Jsprit {
|
||||||
worst.setNoiseMaker(new NoiseMaker() {
|
worst.setNoiseMaker(new NoiseMaker() {
|
||||||
|
|
||||||
public double makeNoise() {
|
public double makeNoise() {
|
||||||
if(random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) {
|
if (random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) {
|
||||||
return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString()))
|
return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString()))
|
||||||
* noiseMaker.maxCosts * random.nextDouble();
|
* noiseMaker.maxCosts * random.nextDouble();
|
||||||
}
|
} else return 0.;
|
||||||
else return 0.;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final RuinClusters clusters = new RuinClusters(vrp,(int) (vrp.getJobs().values().size()*0.5),jobNeighborhoods);
|
final RuinClusters clusters = new RuinClusters(vrp, (int) (vrp.getJobs().values().size() * 0.5), jobNeighborhoods);
|
||||||
clusters.setRandom(random);
|
clusters.setRandom(random);
|
||||||
clusters.setRuinShareFactory(new RuinShareFactoryImpl(
|
clusters.setRuinShareFactory(new RuinShareFactoryImpl(
|
||||||
toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())),
|
toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())),
|
||||||
|
|
@ -373,16 +373,16 @@ public class Jsprit {
|
||||||
|
|
||||||
AbstractInsertionStrategy regret;
|
AbstractInsertionStrategy regret;
|
||||||
final RegretInsertion.DefaultScorer scorer;
|
final RegretInsertion.DefaultScorer scorer;
|
||||||
if(noThreads == null){
|
if (noThreads == null) {
|
||||||
noThreads = toInteger(getProperty(Parameter.THREADS.toString()));
|
noThreads = toInteger(getProperty(Parameter.THREADS.toString()));
|
||||||
}
|
}
|
||||||
if(noThreads > 1){
|
if (noThreads > 1) {
|
||||||
if(es == null){
|
if (es == null) {
|
||||||
setupExecutorInternally = true;
|
setupExecutorInternally = true;
|
||||||
es = Executors.newFixedThreadPool(noThreads);
|
es = Executors.newFixedThreadPool(noThreads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(es != null) {
|
if (es != null) {
|
||||||
RegretInsertionConcurrent regretInsertion = (RegretInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
RegretInsertionConcurrent regretInsertion = (RegretInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
||||||
.setConcurrentMode(es, noThreads)
|
.setConcurrentMode(es, noThreads)
|
||||||
|
|
@ -392,8 +392,7 @@ public class Jsprit {
|
||||||
scorer = getRegretScorer(vrp);
|
scorer = getRegretScorer(vrp);
|
||||||
regretInsertion.setScoringFunction(scorer);
|
regretInsertion.setScoringFunction(scorer);
|
||||||
regret = regretInsertion;
|
regret = regretInsertion;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
|
|
@ -406,15 +405,14 @@ public class Jsprit {
|
||||||
regret.setRandom(random);
|
regret.setRandom(random);
|
||||||
|
|
||||||
AbstractInsertionStrategy best;
|
AbstractInsertionStrategy best;
|
||||||
if(vrp.getJobs().size() < 250 || es == null) {
|
if (vrp.getJobs().size() < 250 || es == null) {
|
||||||
BestInsertion bestInsertion = (BestInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
BestInsertion bestInsertion = (BestInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
||||||
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
.build();
|
.build();
|
||||||
best = bestInsertion;
|
best = bestInsertion;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager)
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
||||||
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
|
|
@ -425,11 +423,11 @@ public class Jsprit {
|
||||||
}
|
}
|
||||||
best.setRandom(random);
|
best.setRandom(random);
|
||||||
|
|
||||||
final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1,toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString())));
|
final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString())));
|
||||||
IterationStartsListener schrimpfThreshold = new IterationStartsListener() {
|
IterationStartsListener schrimpfThreshold = new IterationStartsListener() {
|
||||||
@Override
|
@Override
|
||||||
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||||
if(i == 1){
|
if (i == 1) {
|
||||||
double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString()));
|
double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString()));
|
||||||
schrimpfAcceptance.setInitialThreshold(initialThreshold);
|
schrimpfAcceptance.setInitialThreshold(initialThreshold);
|
||||||
}
|
}
|
||||||
|
|
@ -437,34 +435,34 @@ public class Jsprit {
|
||||||
};
|
};
|
||||||
|
|
||||||
SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, noiseMaker.maxCosts);
|
SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, noiseMaker.maxCosts);
|
||||||
SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(),new SelectBest(),schrimpfAcceptance, objectiveFunction);
|
SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
radial_regret.addModule(new RuinAndRecreateModule(Strategy.RADIAL_REGRET.toString(), regret, radial));
|
radial_regret.addModule(new RuinAndRecreateModule(Strategy.RADIAL_REGRET.toString(), regret, radial));
|
||||||
|
|
||||||
SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(),best,radial));
|
radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(), best, radial));
|
||||||
|
|
||||||
SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(),best,random_for_best));
|
random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(), best, random_for_best));
|
||||||
|
|
||||||
SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(),regret,random_for_regret));
|
random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(), regret, random_for_regret));
|
||||||
|
|
||||||
SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(),regret,worst));
|
worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(), regret, worst));
|
||||||
|
|
||||||
SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(),best,worst));
|
worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(), best, worst));
|
||||||
|
|
||||||
final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(),regret,clusters));
|
clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(), regret, clusters));
|
||||||
|
|
||||||
final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction);
|
final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
|
||||||
clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(),best,clusters));
|
clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(), best, clusters));
|
||||||
|
|
||||||
|
|
||||||
PrettyAlgorithmBuilder prettyBuilder = PrettyAlgorithmBuilder.newInstance(vrp, fm, stateManager, constraintManager);
|
PrettyAlgorithmBuilder prettyBuilder = PrettyAlgorithmBuilder.newInstance(vrp, fm, stateManager, constraintManager);
|
||||||
prettyBuilder.setRandom(random);
|
prettyBuilder.setRandom(random);
|
||||||
if(addCoreConstraints){
|
if (addCoreConstraints) {
|
||||||
prettyBuilder.addCoreStateAndConstraintStuff();
|
prettyBuilder.addCoreStateAndConstraintStuff();
|
||||||
}
|
}
|
||||||
prettyBuilder.withStrategy(radial_regret, toDouble(getProperty(Strategy.RADIAL_REGRET.toString())))
|
prettyBuilder.withStrategy(radial_regret, toDouble(getProperty(Strategy.RADIAL_REGRET.toString())))
|
||||||
|
|
@ -473,12 +471,11 @@ public class Jsprit {
|
||||||
.withStrategy(random_regret, toDouble(getProperty(Strategy.RANDOM_REGRET.toString())))
|
.withStrategy(random_regret, toDouble(getProperty(Strategy.RANDOM_REGRET.toString())))
|
||||||
.withStrategy(worst_best, toDouble(getProperty(Strategy.WORST_BEST.toString())))
|
.withStrategy(worst_best, toDouble(getProperty(Strategy.WORST_BEST.toString())))
|
||||||
.withStrategy(worst_regret, toDouble(getProperty(Strategy.WORST_REGRET.toString())))
|
.withStrategy(worst_regret, toDouble(getProperty(Strategy.WORST_REGRET.toString())))
|
||||||
.withStrategy(clusters_regret,toDouble(getProperty(Strategy.CLUSTER_REGRET.toString())))
|
.withStrategy(clusters_regret, toDouble(getProperty(Strategy.CLUSTER_REGRET.toString())))
|
||||||
.withStrategy(clusters_best,toDouble(getProperty(Strategy.CLUSTER_BEST.toString())));
|
.withStrategy(clusters_best, toDouble(getProperty(Strategy.CLUSTER_BEST.toString())));
|
||||||
if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())){
|
if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())) {
|
||||||
prettyBuilder.constructInitialSolutionWith(best, objectiveFunction);
|
prettyBuilder.constructInitialSolutionWith(best, objectiveFunction);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
|
prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -504,7 +501,7 @@ public class Jsprit {
|
||||||
|
|
||||||
|
|
||||||
private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) {
|
private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) {
|
||||||
if(setupExecutorInternally){
|
if (setupExecutorInternally) {
|
||||||
vra.addListener(new AlgorithmEndsListener() {
|
vra.addListener(new AlgorithmEndsListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -514,7 +511,7 @@ public class Jsprit {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(es != null) {
|
if (es != null) {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!es.isShutdown()) {
|
if (!es.isShutdown()) {
|
||||||
|
|
@ -526,7 +523,7 @@ public class Jsprit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String getProperty(String key){
|
String getProperty(String key) {
|
||||||
return properties.getProperty(key);
|
return properties.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -543,21 +540,21 @@ public class Jsprit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SolutionCostCalculator getObjectiveFunction(final VehicleRoutingProblem vrp, final double maxCosts) {
|
private SolutionCostCalculator getObjectiveFunction(final VehicleRoutingProblem vrp, final double maxCosts) {
|
||||||
if(objectiveFunction != null) return objectiveFunction;
|
if (objectiveFunction != null) return objectiveFunction;
|
||||||
|
|
||||||
SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
|
SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||||
double costs = 0.;
|
double costs = 0.;
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for (VehicleRoute route : solution.getRoutes()) {
|
||||||
costs += route.getVehicle().getType().getVehicleCostParams().fix;
|
costs += route.getVehicle().getType().getVehicleCostParams().fix;
|
||||||
TourActivity prevAct = route.getStart();
|
TourActivity prevAct = route.getStart();
|
||||||
for(TourActivity act : route.getActivities()){
|
for (TourActivity act : route.getActivities()) {
|
||||||
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(),act.getLocation(),prevAct.getEndTime(),route.getDriver(),route.getVehicle());
|
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||||
costs += vrp.getActivityCosts().getActivityCost(act,act.getArrTime(),route.getDriver(),route.getVehicle());
|
costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
|
||||||
prevAct = act;
|
prevAct = act;
|
||||||
}
|
}
|
||||||
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(),route.getEnd().getLocation(),prevAct.getEndTime(),route.getDriver(),route.getVehicle());
|
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||||
}
|
}
|
||||||
costs += solution.getUnassignedJobs().size() * maxCosts * 2;
|
costs += solution.getUnassignedJobs().size() * maxCosts * 2;
|
||||||
return costs;
|
return costs;
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ public class ConfigureLocalActivityInsertionCalculator implements InsertionStart
|
||||||
@Override
|
@Override
|
||||||
public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
||||||
this.nuOfJobsToRecreate = unassignedJobs.size();
|
this.nuOfJobsToRecreate = unassignedJobs.size();
|
||||||
double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size()));
|
double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size()));
|
||||||
localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5,completenessRatio));
|
localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5, completenessRatio));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||||
nuOfJobsToRecreate--;
|
nuOfJobsToRecreate--;
|
||||||
double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size()));
|
double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size()));
|
||||||
localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5,completenessRatio));
|
localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5, completenessRatio));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class JobInsertionCostsCalculatorBuilder {
|
public class JobInsertionCostsCalculatorBuilder {
|
||||||
|
|
||||||
private static class CalculatorPlusListeners {
|
private static class CalculatorPlusListeners {
|
||||||
|
|
@ -97,7 +95,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the builder.
|
* Constructs the builder.
|
||||||
*
|
* <p/>
|
||||||
* <p>Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them.
|
* <p>Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them.
|
||||||
* These listeners are cached in the according list and can thus be added when its time to add them.
|
* These listeners are cached in the according list and can thus be added when its time to add them.
|
||||||
*
|
*
|
||||||
|
|
@ -112,11 +110,11 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets activityStates. MUST be set.
|
* Sets activityStates. MUST be set.
|
||||||
* @param stateManager
|
|
||||||
*
|
*
|
||||||
|
* @param stateManager
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager){
|
public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager) {
|
||||||
this.states = stateManager;
|
this.states = stateManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +125,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
* @param vehicleRoutingProblem
|
* @param vehicleRoutingProblem
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem){
|
public JobInsertionCostsCalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem) {
|
||||||
this.vrp = vehicleRoutingProblem;
|
this.vrp = vehicleRoutingProblem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -138,24 +136,25 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
* @param fleetManager
|
* @param fleetManager
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager){
|
public JobInsertionCostsCalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager) {
|
||||||
this.fleetManager = fleetManager;
|
this.fleetManager = fleetManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a flag to build a calculator based on local calculations.
|
* Sets a flag to build a calculator based on local calculations.
|
||||||
*
|
* <p/>
|
||||||
* <p>Insertion of a job and job-activity is evaluated based on the previous and next activity.
|
* <p>Insertion of a job and job-activity is evaluated based on the previous and next activity.
|
||||||
|
*
|
||||||
* @param addDefaultCostCalc
|
* @param addDefaultCostCalc
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc){
|
public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc) {
|
||||||
local = true;
|
local = true;
|
||||||
this.addDefaultCostCalc = addDefaultCostCalc;
|
this.addDefaultCostCalc = addDefaultCostCalc;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobInsertionCostsCalculatorBuilder setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){
|
public JobInsertionCostsCalculatorBuilder setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator) {
|
||||||
this.activityInsertionCostCalculator = activityInsertionCostsCalculator;
|
this.activityInsertionCostCalculator = activityInsertionCostsCalculator;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +166,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
* @param memory
|
* @param memory
|
||||||
* @param addDefaultMarginalCostCalc
|
* @param addDefaultMarginalCostCalc
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc){
|
public JobInsertionCostsCalculatorBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc) {
|
||||||
local = false;
|
local = false;
|
||||||
this.forwardLooking = forwardLooking;
|
this.forwardLooking = forwardLooking;
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
|
|
@ -180,13 +179,13 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
*
|
*
|
||||||
* @param weightOfFixedCosts
|
* @param weightOfFixedCosts
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculatorBuilder considerFixedCosts(double weightOfFixedCosts){
|
public JobInsertionCostsCalculatorBuilder considerFixedCosts(double weightOfFixedCosts) {
|
||||||
considerFixedCost = true;
|
considerFixedCost = true;
|
||||||
this.weightOfFixedCost = weightOfFixedCosts;
|
this.weightOfFixedCost = weightOfFixedCosts;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobInsertionCostsCalculatorBuilder experimentalTimeScheduler(double timeSlice, int neighbors){
|
public JobInsertionCostsCalculatorBuilder experimentalTimeScheduler(double timeSlice, int neighbors) {
|
||||||
timeScheduling = true;
|
timeScheduling = true;
|
||||||
this.timeSlice = timeSlice;
|
this.timeSlice = timeSlice;
|
||||||
this.neighbors = neighbors;
|
this.neighbors = neighbors;
|
||||||
|
|
@ -199,31 +198,33 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
* @return jobInsertionCalculator.
|
* @return jobInsertionCalculator.
|
||||||
* @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null.
|
* @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null.
|
||||||
*/
|
*/
|
||||||
public JobInsertionCostsCalculator build(){
|
public JobInsertionCostsCalculator build() {
|
||||||
if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
if (vrp == null)
|
||||||
if(states == null) throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))");
|
throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))");
|
||||||
if(fleetManager == null) throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))");
|
if (states == null)
|
||||||
|
throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))");
|
||||||
|
if (fleetManager == null)
|
||||||
|
throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))");
|
||||||
JobInsertionCostsCalculator baseCalculator = null;
|
JobInsertionCostsCalculator baseCalculator = null;
|
||||||
CalculatorPlusListeners standardLocal = null;
|
CalculatorPlusListeners standardLocal = null;
|
||||||
if(local){
|
if (local) {
|
||||||
standardLocal = createStandardLocal(vrp, states);
|
standardLocal = createStandardLocal(vrp, states);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
checkServicesOnly();
|
checkServicesOnly();
|
||||||
standardLocal = createStandardRoute(vrp, states,forwardLooking,memory);
|
standardLocal = createStandardRoute(vrp, states, forwardLooking, memory);
|
||||||
}
|
}
|
||||||
baseCalculator = standardLocal.getCalculator();
|
baseCalculator = standardLocal.getCalculator();
|
||||||
addAlgorithmListeners(standardLocal.getAlgorithmListener());
|
addAlgorithmListeners(standardLocal.getAlgorithmListener());
|
||||||
addInsertionListeners(standardLocal.getInsertionListener());
|
addInsertionListeners(standardLocal.getInsertionListener());
|
||||||
if(considerFixedCost){
|
if (considerFixedCost) {
|
||||||
CalculatorPlusListeners withFixed = createCalculatorConsideringFixedCosts(vrp, baseCalculator, states, weightOfFixedCost);
|
CalculatorPlusListeners withFixed = createCalculatorConsideringFixedCosts(vrp, baseCalculator, states, weightOfFixedCost);
|
||||||
baseCalculator = withFixed.getCalculator();
|
baseCalculator = withFixed.getCalculator();
|
||||||
addAlgorithmListeners(withFixed.getAlgorithmListener());
|
addAlgorithmListeners(withFixed.getAlgorithmListener());
|
||||||
addInsertionListeners(withFixed.getInsertionListener());
|
addInsertionListeners(withFixed.getInsertionListener());
|
||||||
}
|
}
|
||||||
if(timeScheduling){
|
if (timeScheduling) {
|
||||||
// baseCalculator = new CalculatesServiceInsertionWithTimeSchedulingInSlices(baseCalculator,timeSlice,neighbors);
|
// baseCalculator = new CalculatesServiceInsertionWithTimeSchedulingInSlices(baseCalculator,timeSlice,neighbors);
|
||||||
CalculatesServiceInsertionWithTimeScheduling wts = new CalculatesServiceInsertionWithTimeScheduling(baseCalculator,timeSlice,neighbors);
|
CalculatesServiceInsertionWithTimeScheduling wts = new CalculatesServiceInsertionWithTimeScheduling(baseCalculator, timeSlice, neighbors);
|
||||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(wts);
|
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(wts);
|
||||||
calcPlusListeners.getInsertionListener().add(new CalculatesServiceInsertionWithTimeScheduling.KnowledgeInjection(wts));
|
calcPlusListeners.getInsertionListener().add(new CalculatesServiceInsertionWithTimeScheduling.KnowledgeInjection(wts));
|
||||||
addInsertionListeners(calcPlusListeners.getInsertionListener());
|
addInsertionListeners(calcPlusListeners.getInsertionListener());
|
||||||
|
|
@ -233,8 +234,8 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkServicesOnly() {
|
private void checkServicesOnly() {
|
||||||
for(Job j : vrp.getJobs().values()){
|
for (Job j : vrp.getJobs().values()) {
|
||||||
if(j instanceof Shipment){
|
if (j instanceof Shipment) {
|
||||||
throw new UnsupportedOperationException("currently the 'insert-on-route-level' option is only available for services (i.e. service, pickup, delivery), \n" +
|
throw new UnsupportedOperationException("currently the 'insert-on-route-level' option is only available for services (i.e. service, pickup, delivery), \n" +
|
||||||
"if you want to deal with shipments switch to option 'local-level' by either setting bestInsertionBuilder.setLocalLevel() or \n"
|
"if you want to deal with shipments switch to option 'local-level' by either setting bestInsertionBuilder.setLocalLevel() or \n"
|
||||||
+ "by omitting the xml-tag '<level forwardLooking=2 memory=1>route</level>' when defining your insertionStrategy in algo-config.xml file");
|
+ "by omitting the xml-tag '<level forwardLooking=2 memory=1>route</level>' when defining your insertionStrategy in algo-config.xml file");
|
||||||
|
|
@ -244,28 +245,27 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addInsertionListeners(List<InsertionListener> list) {
|
private void addInsertionListeners(List<InsertionListener> list) {
|
||||||
for(InsertionListener iL : list){
|
for (InsertionListener iL : list) {
|
||||||
insertionListeners.add(iL);
|
insertionListeners.add(iL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAlgorithmListeners(List<PrioritizedVRAListener> list) {
|
private void addAlgorithmListeners(List<PrioritizedVRAListener> list) {
|
||||||
for(PrioritizedVRAListener aL : list){
|
for (PrioritizedVRAListener aL : list) {
|
||||||
algorithmListeners.add(aL);
|
algorithmListeners.add(aL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private CalculatorPlusListeners createStandardLocal(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter statesManager){
|
private CalculatorPlusListeners createStandardLocal(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter statesManager) {
|
||||||
if(constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
if (constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
||||||
|
|
||||||
ActivityInsertionCostsCalculator actInsertionCalc;
|
ActivityInsertionCostsCalculator actInsertionCalc;
|
||||||
ConfigureLocalActivityInsertionCalculator configLocal = null;
|
ConfigureLocalActivityInsertionCalculator configLocal = null;
|
||||||
if(activityInsertionCostCalculator == null && addDefaultCostCalc){
|
if (activityInsertionCostCalculator == null && addDefaultCostCalc) {
|
||||||
actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager);
|
actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager);
|
||||||
configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc);
|
configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc);
|
||||||
}
|
} else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
|
||||||
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
|
actInsertionCalc = new ActivityInsertionCostsCalculator() {
|
||||||
actInsertionCalc = new ActivityInsertionCostsCalculator(){
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct,
|
public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct,
|
||||||
|
|
@ -274,8 +274,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
actInsertionCalc = activityInsertionCostCalculator;
|
actInsertionCalc = activityInsertionCostCalculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,13 +298,13 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
switcher.put(Delivery.class, serviceInsertion);
|
switcher.put(Delivery.class, serviceInsertion);
|
||||||
|
|
||||||
CalculatorPlusListeners calculatorPlusListeners = new CalculatorPlusListeners(switcher);
|
CalculatorPlusListeners calculatorPlusListeners = new CalculatorPlusListeners(switcher);
|
||||||
if(configLocal != null){
|
if (configLocal != null) {
|
||||||
calculatorPlusListeners.insertionListener.add(configLocal);
|
calculatorPlusListeners.insertionListener.add(configLocal);
|
||||||
}
|
}
|
||||||
return calculatorPlusListeners;
|
return calculatorPlusListeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts){
|
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts) {
|
||||||
final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2);
|
final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2);
|
||||||
withFixCost.setWeightOfFixCost(weightOfFixedCosts);
|
withFixCost.setWeightOfFixCost(weightOfFixedCosts);
|
||||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost);
|
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost);
|
||||||
|
|
@ -313,17 +312,16 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
return calcPlusListeners;
|
return calcPlusListeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CalculatorPlusListeners createStandardRoute(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter activityStates2, int forwardLooking, int solutionMemory){
|
private CalculatorPlusListeners createStandardRoute(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter activityStates2, int forwardLooking, int solutionMemory) {
|
||||||
ActivityInsertionCostsCalculator routeLevelCostEstimator;
|
ActivityInsertionCostsCalculator routeLevelCostEstimator;
|
||||||
if(activityInsertionCostCalculator == null && addDefaultCostCalc){
|
if (activityInsertionCostCalculator == null && addDefaultCostCalc) {
|
||||||
RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2);
|
RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2);
|
||||||
routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking);
|
routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking);
|
||||||
routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator;
|
routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator;
|
||||||
}
|
} else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) {
|
||||||
else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){
|
routeLevelCostEstimator = new ActivityInsertionCostsCalculator() {
|
||||||
routeLevelCostEstimator = new ActivityInsertionCostsCalculator(){
|
|
||||||
|
|
||||||
final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0.,0.);
|
final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0., 0.);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct,
|
public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct,
|
||||||
|
|
@ -332,8 +330,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
routeLevelCostEstimator = activityInsertionCostCalculator;
|
routeLevelCostEstimator = activityInsertionCostCalculator;
|
||||||
}
|
}
|
||||||
ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager);
|
ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager);
|
||||||
|
|
@ -349,7 +346,7 @@ public class JobInsertionCostsCalculatorBuilder {
|
||||||
return new CalculatorPlusListeners(jobInsertionCalculator);
|
return new CalculatorPlusListeners(jobInsertionCalculator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){
|
private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2) {
|
||||||
VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, baseCalc);
|
VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, baseCalc);
|
||||||
vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch);
|
vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch);
|
||||||
return vehicleTypeDependentJobInsertionCalculator;
|
return vehicleTypeDependentJobInsertionCalculator;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2014 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
|
|
@ -32,13 +31,12 @@ import jsprit.core.util.CalculationUtils;
|
||||||
* Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between
|
* Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between
|
||||||
* activity i (prevAct) and j (nextAct).
|
* activity i (prevAct) and j (nextAct).
|
||||||
* Additional costs are then basically calculated as delta c = c_ik + c_kj - c_ij.
|
* Additional costs are then basically calculated as delta c = c_ik + c_kj - c_ij.
|
||||||
*
|
* <p/>
|
||||||
* <p>Note once time has an effect on costs this class requires activity endTimes.
|
* <p>Note once time has an effect on costs this class requires activity endTimes.
|
||||||
*
|
*
|
||||||
* @author stefan
|
* @author stefan
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{
|
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator {
|
||||||
|
|
||||||
private VehicleRoutingTransportCosts routingCosts;
|
private VehicleRoutingTransportCosts routingCosts;
|
||||||
|
|
||||||
|
|
@ -67,7 +65,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
||||||
|
|
||||||
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
|
|
||||||
if(isEnd(nextAct) && !toDepot(iFacts.getNewVehicle())) return tp_costs_prevAct_newAct;
|
if (isEnd(nextAct) && !toDepot(iFacts.getNewVehicle())) return tp_costs_prevAct_newAct;
|
||||||
|
|
||||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
|
|
@ -78,14 +76,13 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
||||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + solutionCompletenessRatio * activityCostsWeight * (act_costs_newAct + act_costs_nextAct);
|
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + solutionCompletenessRatio * activityCostsWeight * (act_costs_newAct + act_costs_nextAct);
|
||||||
|
|
||||||
double oldCosts = 0.;
|
double oldCosts = 0.;
|
||||||
if(iFacts.getRoute().isEmpty()){
|
if (iFacts.getRoute().isEmpty()) {
|
||||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
oldCosts += tp_costs_prevAct_nextAct;
|
oldCosts += tp_costs_prevAct_nextAct;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||||
double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||||
double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct,nextAct);
|
double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct, nextAct);
|
||||||
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||||
|
|
||||||
double endTimeDelay_nextAct = Math.max(0, endTime_nextAct_new - endTime_nextAct_old);
|
double endTimeDelay_nextAct = Math.max(0, endTime_nextAct_new - endTime_nextAct_old);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{
|
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator {
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
|
private Logger logger = LogManager.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
|
||||||
|
|
||||||
|
|
@ -47,11 +47,10 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle
|
* true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle
|
||||||
*
|
* <p/>
|
||||||
* <p>vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one
|
* <p>vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one
|
||||||
* can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e.
|
* can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e.
|
||||||
* bigger vehicles can take over the route that was previously served by a small vehicle.
|
* bigger vehicles can take over the route that was previously served by a small vehicle.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private boolean vehicleSwitchAllowed = false;
|
private boolean vehicleSwitchAllowed = false;
|
||||||
|
|
||||||
|
|
@ -65,7 +64,7 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
|
|
||||||
private void getInitialVehicleIds() {
|
private void getInitialVehicleIds() {
|
||||||
Collection<VehicleRoute> initialVehicleRoutes = vrp.getInitialVehicleRoutes();
|
Collection<VehicleRoute> initialVehicleRoutes = vrp.getInitialVehicleRoutes();
|
||||||
for(VehicleRoute initialRoute : initialVehicleRoutes){
|
for (VehicleRoute initialRoute : initialVehicleRoutes) {
|
||||||
initialVehicleIds.add(initialRoute.getVehicle().getId());
|
initialVehicleIds.add(initialRoute.getVehicle().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,24 +98,23 @@ final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCo
|
||||||
InsertionData bestIData = InsertionData.createEmptyInsertionData();
|
InsertionData bestIData = InsertionData.createEmptyInsertionData();
|
||||||
double bestKnownCost_ = bestKnownCost;
|
double bestKnownCost_ = bestKnownCost;
|
||||||
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
||||||
if(!(selectedVehicle instanceof NoVehicle)) {
|
if (!(selectedVehicle instanceof NoVehicle)) {
|
||||||
relevantVehicles.add(selectedVehicle);
|
relevantVehicles.add(selectedVehicle);
|
||||||
if(vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)){
|
if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) {
|
||||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
|
relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle));
|
||||||
}
|
}
|
||||||
}
|
} else { //if no vehicle has been assigned, i.e. it is an empty route
|
||||||
else{ //if no vehicle has been assigned, i.e. it is an empty route
|
|
||||||
relevantVehicles.addAll(fleetManager.getAvailableVehicles());
|
relevantVehicles.addAll(fleetManager.getAvailableVehicles());
|
||||||
}
|
}
|
||||||
for(Vehicle v : relevantVehicles){
|
for (Vehicle v : relevantVehicles) {
|
||||||
double depTime;
|
double depTime;
|
||||||
if(v == selectedVehicle) depTime = currentRoute.getDepartureTime();
|
if (v == selectedVehicle) depTime = currentRoute.getDepartureTime();
|
||||||
else depTime = v.getEarliestDeparture();
|
else depTime = v.getEarliestDeparture();
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(currentRoute, jobToInsert, v, depTime, selectedDriver, bestKnownCost_);
|
InsertionData iData = insertionCalculator.getInsertionData(currentRoute, jobToInsert, v, depTime, selectedDriver, bestKnownCost_);
|
||||||
if(iData instanceof NoInsertionFound) {
|
if (iData instanceof NoInsertionFound) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(iData.getInsertionCost() < bestKnownCost_){
|
if (iData.getInsertionCost() < bestKnownCost_) {
|
||||||
bestIData = iData;
|
bestIData = iData;
|
||||||
bestKnownCost_ = iData.getInsertionCost();
|
bestKnownCost_ = iData.getInsertionCost();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,11 @@ public class InternalStates {
|
||||||
|
|
||||||
public static final StateId SKILLS = new StateFactory.StateIdImpl("skills", 10);
|
public static final StateId SKILLS = new StateFactory.StateIdImpl("skills", 10);
|
||||||
|
|
||||||
public static final StateId WAITING = new StateFactory.StateIdImpl("waiting",11);
|
public static final StateId WAITING = new StateFactory.StateIdImpl("waiting", 11);
|
||||||
|
|
||||||
public static final StateId TIME_SLACK = new StateFactory.StateIdImpl("time_slack",12);
|
public static final StateId TIME_SLACK = new StateFactory.StateIdImpl("time_slack", 12);
|
||||||
|
|
||||||
public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting",13);
|
public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting", 13);
|
||||||
|
|
||||||
public static final StateId EARLIEST_WITHOUT_WAITING = new StateFactory.StateIdImpl("earliest_without_waiting",14);
|
public static final StateId EARLIEST_WITHOUT_WAITING = new StateFactory.StateIdImpl("earliest_without_waiting", 14);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,8 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
* Updates and memorizes latest operation start times at activities.
|
* Updates and memorizes latest operation start times at activities.
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater{
|
public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater {
|
||||||
|
|
||||||
private StateManager states;
|
private StateManager states;
|
||||||
|
|
||||||
|
|
@ -51,10 +50,11 @@ public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity activity) {
|
public void visit(TourActivity activity) {
|
||||||
states.putInternalTypedActivityState(activity,route.getVehicle(),InternalStates.FUTURE_WAITING,futureWaiting);
|
states.putInternalTypedActivityState(activity, route.getVehicle(), InternalStates.FUTURE_WAITING, futureWaiting);
|
||||||
futureWaiting += Math.max(activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime(),0);
|
futureWaiting += Math.max(activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finish() {}
|
public void finish() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,13 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor, StateUpdater{
|
public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor, StateUpdater {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(VehicleRoute route) {
|
public void visit(VehicleRoute route) {
|
||||||
begin(route);
|
begin(route);
|
||||||
Iterator<TourActivity> revIterator = route.getTourActivities().reverseActivityIterator();
|
Iterator<TourActivity> revIterator = route.getTourActivities().reverseActivityIterator();
|
||||||
while(revIterator.hasNext()){
|
while (revIterator.hasNext()) {
|
||||||
visit(revIterator.next());
|
visit(revIterator.next());
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
|
@ -75,7 +75,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
||||||
location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVehiclesToUpdate(VehiclesToUpdate vehiclesToUpdate){
|
public void setVehiclesToUpdate(VehiclesToUpdate vehiclesToUpdate) {
|
||||||
this.vehiclesToUpdate = vehiclesToUpdate;
|
this.vehiclesToUpdate = vehiclesToUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
||||||
public void begin(VehicleRoute route) {
|
public void begin(VehicleRoute route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
vehicles = vehiclesToUpdate.get(route);
|
vehicles = vehiclesToUpdate.get(route);
|
||||||
for(Vehicle vehicle : vehicles){
|
for (Vehicle vehicle : vehicles) {
|
||||||
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getLatestArrival();
|
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getLatestArrival();
|
||||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getEndLocation();
|
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getEndLocation();
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +91,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
||||||
|
|
||||||
|
|
||||||
public void visit(TourActivity activity) {
|
public void visit(TourActivity activity) {
|
||||||
for(Vehicle vehicle : vehicles){
|
for (Vehicle vehicle : vehicles) {
|
||||||
double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||||
Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
|
||||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
|
||||||
|
|
@ -104,7 +104,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void finish() {}
|
public void finish() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,18 +41,15 @@ import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains and defines the vehicle routing problem.
|
* Contains and defines the vehicle routing problem.
|
||||||
*
|
* <p/>
|
||||||
* <p>A routing problem is defined as jobs, vehicles, costs and constraints.
|
* <p>A routing problem is defined as jobs, vehicles, costs and constraints.
|
||||||
*
|
* <p/>
|
||||||
* <p> To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance().
|
* <p> To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance().
|
||||||
*
|
* <p/>
|
||||||
* <p>By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts),
|
* <p>By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts),
|
||||||
* and activity-costs are set to zero.
|
* and activity-costs are set to zero.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author stefan schroeder
|
* @author stefan schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VehicleRoutingProblem {
|
public class VehicleRoutingProblem {
|
||||||
|
|
||||||
|
|
@ -60,26 +57,26 @@ public class VehicleRoutingProblem {
|
||||||
* Builder to build the routing-problem.
|
* Builder to build the routing-problem.
|
||||||
*
|
*
|
||||||
* @author stefan schroeder
|
* @author stefan schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new instance of this builder.
|
* Returns a new instance of this builder.
|
||||||
*
|
*
|
||||||
* @return builder
|
* @return builder
|
||||||
*/
|
*/
|
||||||
public static Builder newInstance(){ return new Builder(); }
|
public static Builder newInstance() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
private VehicleRoutingTransportCosts transportCosts;
|
private VehicleRoutingTransportCosts transportCosts;
|
||||||
|
|
||||||
private VehicleRoutingActivityCosts activityCosts = new WaitingTimeCosts();
|
private VehicleRoutingActivityCosts activityCosts = new WaitingTimeCosts();
|
||||||
|
|
||||||
private Map<String,Job> jobs = new LinkedHashMap<String, Job>();
|
private Map<String, Job> jobs = new LinkedHashMap<String, Job>();
|
||||||
|
|
||||||
private Map<String,Job> tentativeJobs = new LinkedHashMap<String,Job>();
|
private Map<String, Job> tentativeJobs = new LinkedHashMap<String, Job>();
|
||||||
|
|
||||||
private Set<String> jobsInInitialRoutes = new HashSet<String>();
|
private Set<String> jobsInInitialRoutes = new HashSet<String>();
|
||||||
|
|
||||||
|
|
@ -98,10 +95,9 @@ public class VehicleRoutingProblem {
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractActivity> createActivities(Job job) {
|
public List<AbstractActivity> createActivities(Job job) {
|
||||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||||
if(job instanceof Service){
|
if (job instanceof Service) {
|
||||||
acts.add(serviceActivityFactory.createActivity((Service) job));
|
acts.add(serviceActivityFactory.createActivity((Service) job));
|
||||||
}
|
} else if (job instanceof Shipment) {
|
||||||
else if(job instanceof Shipment){
|
|
||||||
acts.add(shipmentActivityFactory.createPickup((Shipment) job));
|
acts.add(shipmentActivityFactory.createPickup((Shipment) job));
|
||||||
acts.add(shipmentActivityFactory.createDelivery((Shipment) job));
|
acts.add(shipmentActivityFactory.createDelivery((Shipment) job));
|
||||||
}
|
}
|
||||||
|
|
@ -118,42 +114,43 @@ public class VehicleRoutingProblem {
|
||||||
|
|
||||||
private int vehicleTypeIdIndexCounter = 1;
|
private int vehicleTypeIdIndexCounter = 1;
|
||||||
|
|
||||||
private Map<VehicleTypeKey,Integer> typeKeyIndices = new HashMap<VehicleTypeKey, Integer>();
|
private Map<VehicleTypeKey, Integer> typeKeyIndices = new HashMap<VehicleTypeKey, Integer>();
|
||||||
|
|
||||||
private Map<Job,List<AbstractActivity>> activityMap = new HashMap<Job, List<AbstractActivity>>();
|
private Map<Job, List<AbstractActivity>> activityMap = new HashMap<Job, List<AbstractActivity>>();
|
||||||
|
|
||||||
private final DefaultShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory();
|
private final DefaultShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory();
|
||||||
|
|
||||||
private final DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory();
|
private final DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory();
|
||||||
|
|
||||||
private void incJobIndexCounter(){
|
private void incJobIndexCounter() {
|
||||||
jobIndexCounter++;
|
jobIndexCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void incActivityIndexCounter(){
|
private void incActivityIndexCounter() {
|
||||||
activityIndexCounter++;
|
activityIndexCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void incVehicleTypeIdIndexCounter() { vehicleTypeIdIndexCounter++; }
|
private void incVehicleTypeIdIndexCounter() {
|
||||||
|
vehicleTypeIdIndexCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unmodifiable map of collected locations (mapped by their location-id).
|
* Returns the unmodifiable map of collected locations (mapped by their location-id).
|
||||||
*
|
*
|
||||||
* @return map with locations
|
* @return map with locations
|
||||||
*/
|
*/
|
||||||
public Map<String,Coordinate> getLocationMap(){
|
public Map<String, Coordinate> getLocationMap() {
|
||||||
return Collections.unmodifiableMap(tentative_coordinates);
|
return Collections.unmodifiableMap(tentative_coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the locations collected SO FAR by this builder.
|
* Returns the locations collected SO FAR by this builder.
|
||||||
*
|
* <p/>
|
||||||
* <p>Locations are cached when adding a shipment, service, depot, vehicle.
|
* <p>Locations are cached when adding a shipment, service, depot, vehicle.
|
||||||
*
|
*
|
||||||
* @return locations
|
* @return locations
|
||||||
*
|
*/
|
||||||
**/
|
public Locations getLocations() {
|
||||||
public Locations getLocations(){
|
|
||||||
return new Locations() {
|
return new Locations() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -171,7 +168,7 @@ public class VehicleRoutingProblem {
|
||||||
* @return builder
|
* @return builder
|
||||||
* @see VehicleRoutingTransportCosts
|
* @see VehicleRoutingTransportCosts
|
||||||
*/
|
*/
|
||||||
public Builder setRoutingCost(VehicleRoutingTransportCosts costs){
|
public Builder setRoutingCost(VehicleRoutingTransportCosts costs) {
|
||||||
this.transportCosts = costs;
|
this.transportCosts = costs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -179,20 +176,20 @@ public class VehicleRoutingProblem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the type of fleetSize.
|
* Sets the type of fleetSize.
|
||||||
*
|
* <p/>
|
||||||
* <p>FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE.
|
* <p>FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE.
|
||||||
*
|
*
|
||||||
* @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE
|
* @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setFleetSize(FleetSize fleetSize){
|
public Builder setFleetSize(FleetSize fleetSize) {
|
||||||
this.fleetSize = fleetSize;
|
this.fleetSize = fleetSize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a job which is either a service or a shipment.
|
* Adds a job which is either a service or a shipment.
|
||||||
*
|
* <p/>
|
||||||
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
|
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
|
||||||
*
|
*
|
||||||
* @param job job to be added
|
* @param job job to be added
|
||||||
|
|
@ -202,13 +199,13 @@ public class VehicleRoutingProblem {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder addJob(Job job) {
|
public Builder addJob(Job job) {
|
||||||
if(!(job instanceof AbstractJob)) throw new IllegalArgumentException("job must be of type AbstractJob");
|
if (!(job instanceof AbstractJob)) throw new IllegalArgumentException("job must be of type AbstractJob");
|
||||||
return addJob((AbstractJob)job);
|
return addJob((AbstractJob) job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a job which is either a service or a shipment.
|
* Adds a job which is either a service or a shipment.
|
||||||
*
|
* <p/>
|
||||||
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
|
* <p>Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id.
|
||||||
*
|
*
|
||||||
* @param job job to be added
|
* @param job job to be added
|
||||||
|
|
@ -216,8 +213,10 @@ public class VehicleRoutingProblem {
|
||||||
* @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added.
|
* @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added.
|
||||||
*/
|
*/
|
||||||
public Builder addJob(AbstractJob job) {
|
public Builder addJob(AbstractJob job) {
|
||||||
if(tentativeJobs.containsKey(job.getId())) throw new IllegalStateException("jobList already contains a job with id " + job.getId() + ". make sure you use unique ids for your jobs (i.e. service and shipments)");
|
if (tentativeJobs.containsKey(job.getId()))
|
||||||
if(!(job instanceof Service || job instanceof Shipment)) throw new IllegalStateException("job must be either a service or a shipment");
|
throw new IllegalStateException("jobList already contains a job with id " + job.getId() + ". make sure you use unique ids for your jobs (i.e. service and shipments)");
|
||||||
|
if (!(job instanceof Service || job instanceof Shipment))
|
||||||
|
throw new IllegalStateException("job must be either a service or a shipment");
|
||||||
job.setIndex(jobIndexCounter);
|
job.setIndex(jobIndexCounter);
|
||||||
incJobIndexCounter();
|
incJobIndexCounter();
|
||||||
tentativeJobs.put(job.getId(), job);
|
tentativeJobs.put(job.getId(), job);
|
||||||
|
|
@ -226,27 +225,25 @@ public class VehicleRoutingProblem {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLocationToTentativeLocations(Job job) {
|
private void addLocationToTentativeLocations(Job job) {
|
||||||
if(job instanceof Service) {
|
if (job instanceof Service) {
|
||||||
tentative_coordinates.put(((Service)job).getLocation().getId(), ((Service)job).getLocation().getCoordinate());
|
tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate());
|
||||||
}
|
} else if (job instanceof Shipment) {
|
||||||
else if(job instanceof Shipment){
|
Shipment shipment = (Shipment) job;
|
||||||
Shipment shipment = (Shipment)job;
|
|
||||||
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
||||||
tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate());
|
tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addJobToFinalJobMapAndCreateActivities(Job job){
|
private void addJobToFinalJobMapAndCreateActivities(Job job) {
|
||||||
if(job instanceof Service) {
|
if (job instanceof Service) {
|
||||||
Service service = (Service) job;
|
Service service = (Service) job;
|
||||||
addService(service);
|
addService(service);
|
||||||
}
|
} else if (job instanceof Shipment) {
|
||||||
else if(job instanceof Shipment){
|
Shipment shipment = (Shipment) job;
|
||||||
Shipment shipment = (Shipment)job;
|
|
||||||
addShipment(shipment);
|
addShipment(shipment);
|
||||||
}
|
}
|
||||||
List<AbstractActivity> jobActs = jobActivityFactory.createActivities(job);
|
List<AbstractActivity> jobActs = jobActivityFactory.createActivities(job);
|
||||||
for(AbstractActivity act : jobActs){
|
for (AbstractActivity act : jobActs) {
|
||||||
act.setIndex(activityIndexCounter);
|
act.setIndex(activityIndexCounter);
|
||||||
incActivityIndexCounter();
|
incActivityIndexCounter();
|
||||||
}
|
}
|
||||||
|
|
@ -260,13 +257,13 @@ public class VehicleRoutingProblem {
|
||||||
* @param route initial route
|
* @param route initial route
|
||||||
* @return the builder
|
* @return the builder
|
||||||
*/
|
*/
|
||||||
public Builder addInitialVehicleRoute(VehicleRoute route){
|
public Builder addInitialVehicleRoute(VehicleRoute route) {
|
||||||
addVehicle((AbstractVehicle)route.getVehicle());
|
addVehicle((AbstractVehicle) route.getVehicle());
|
||||||
for(TourActivity act : route.getActivities()){
|
for (TourActivity act : route.getActivities()) {
|
||||||
AbstractActivity abstractAct = (AbstractActivity) act;
|
AbstractActivity abstractAct = (AbstractActivity) act;
|
||||||
abstractAct.setIndex(activityIndexCounter);
|
abstractAct.setIndex(activityIndexCounter);
|
||||||
incActivityIndexCounter();
|
incActivityIndexCounter();
|
||||||
if(act instanceof TourActivity.JobActivity) {
|
if (act instanceof TourActivity.JobActivity) {
|
||||||
Job job = ((TourActivity.JobActivity) act).getJob();
|
Job job = ((TourActivity.JobActivity) act).getJob();
|
||||||
jobsInInitialRoutes.add(job.getId());
|
jobsInInitialRoutes.add(job.getId());
|
||||||
registerLocation(job);
|
registerLocation(job);
|
||||||
|
|
@ -278,7 +275,8 @@ public class VehicleRoutingProblem {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerLocation(Job job) {
|
private void registerLocation(Job job) {
|
||||||
if (job instanceof Service) tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate());
|
if (job instanceof Service)
|
||||||
|
tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate());
|
||||||
if (job instanceof Shipment) {
|
if (job instanceof Shipment) {
|
||||||
Shipment shipment = (Shipment) job;
|
Shipment shipment = (Shipment) job;
|
||||||
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate());
|
||||||
|
|
@ -287,11 +285,11 @@ public class VehicleRoutingProblem {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerJobAndActivity(AbstractActivity abstractAct, Job job) {
|
private void registerJobAndActivity(AbstractActivity abstractAct, Job job) {
|
||||||
if(activityMap.containsKey(job)) activityMap.get(job).add(abstractAct);
|
if (activityMap.containsKey(job)) activityMap.get(job).add(abstractAct);
|
||||||
else{
|
else {
|
||||||
List<AbstractActivity> actList = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> actList = new ArrayList<AbstractActivity>();
|
||||||
actList.add(abstractAct);
|
actList.add(abstractAct);
|
||||||
activityMap.put(job,actList);
|
activityMap.put(job, actList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,61 +299,61 @@ public class VehicleRoutingProblem {
|
||||||
* @param routes initial routes
|
* @param routes initial routes
|
||||||
* @return the builder
|
* @return the builder
|
||||||
*/
|
*/
|
||||||
public Builder addInitialVehicleRoutes(Collection<VehicleRoute> routes){
|
public Builder addInitialVehicleRoutes(Collection<VehicleRoute> routes) {
|
||||||
for(VehicleRoute r : routes){
|
for (VehicleRoute r : routes) {
|
||||||
addInitialVehicleRoute(r);
|
addInitialVehicleRoute(r);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addShipment(Shipment job) {
|
private void addShipment(Shipment job) {
|
||||||
if(jobs.containsKey(job.getId())){ logger.warn("job " + job + " already in job list. overrides existing job."); }
|
if (jobs.containsKey(job.getId())) {
|
||||||
|
logger.warn("job " + job + " already in job list. overrides existing job.");
|
||||||
|
}
|
||||||
tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate());
|
tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate());
|
||||||
tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate());
|
tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate());
|
||||||
jobs.put(job.getId(),job);
|
jobs.put(job.getId(), job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a vehicle.
|
* Adds a vehicle.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param vehicle vehicle to be added
|
* @param vehicle vehicle to be added
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @deprecated use addVehicle(AbstractVehicle vehicle) instead
|
* @deprecated use addVehicle(AbstractVehicle vehicle) instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder addVehicle(Vehicle vehicle) {
|
public Builder addVehicle(Vehicle vehicle) {
|
||||||
if(!(vehicle instanceof AbstractVehicle)) throw new IllegalStateException("vehicle must be an AbstractVehicle");
|
if (!(vehicle instanceof AbstractVehicle))
|
||||||
return addVehicle((AbstractVehicle)vehicle);
|
throw new IllegalStateException("vehicle must be an AbstractVehicle");
|
||||||
|
return addVehicle((AbstractVehicle) vehicle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a vehicle.
|
* Adds a vehicle.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param vehicle vehicle to be added
|
* @param vehicle vehicle to be added
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder addVehicle(AbstractVehicle vehicle) {
|
public Builder addVehicle(AbstractVehicle vehicle) {
|
||||||
if(!uniqueVehicles.contains(vehicle)){
|
if (!uniqueVehicles.contains(vehicle)) {
|
||||||
vehicle.setIndex(vehicleIndexCounter);
|
vehicle.setIndex(vehicleIndexCounter);
|
||||||
incVehicleIndexCounter();
|
incVehicleIndexCounter();
|
||||||
}
|
}
|
||||||
if(typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())){
|
if (typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())) {
|
||||||
vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier()));
|
vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier()));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter);
|
vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter);
|
||||||
typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(),vehicleTypeIdIndexCounter);
|
typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(), vehicleTypeIdIndexCounter);
|
||||||
incVehicleTypeIdIndexCounter();
|
incVehicleTypeIdIndexCounter();
|
||||||
}
|
}
|
||||||
uniqueVehicles.add(vehicle);
|
uniqueVehicles.add(vehicle);
|
||||||
if(!vehicleTypes.contains(vehicle.getType())){
|
if (!vehicleTypes.contains(vehicle.getType())) {
|
||||||
vehicleTypes.add(vehicle.getType());
|
vehicleTypes.add(vehicle.getType());
|
||||||
}
|
}
|
||||||
String startLocationId = vehicle.getStartLocation().getId();
|
String startLocationId = vehicle.getStartLocation().getId();
|
||||||
tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate());
|
tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate());
|
||||||
if(!vehicle.getEndLocation().getId().equals(startLocationId)){
|
if (!vehicle.getEndLocation().getId().equals(startLocationId)) {
|
||||||
tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate());
|
tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -367,30 +365,30 @@ public class VehicleRoutingProblem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the activity-costs.
|
* Sets the activity-costs.
|
||||||
*
|
* <p/>
|
||||||
* <p>By default it is set to zero.
|
* <p>By default it is set to zero.
|
||||||
*
|
*
|
||||||
* @param activityCosts activity costs of the problem
|
* @param activityCosts activity costs of the problem
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @see VehicleRoutingActivityCosts
|
* @see VehicleRoutingActivityCosts
|
||||||
*/
|
*/
|
||||||
public Builder setActivityCosts(VehicleRoutingActivityCosts activityCosts){
|
public Builder setActivityCosts(VehicleRoutingActivityCosts activityCosts) {
|
||||||
this.activityCosts = activityCosts;
|
this.activityCosts = activityCosts;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the {@link VehicleRoutingProblem}.
|
* Builds the {@link VehicleRoutingProblem}.
|
||||||
*
|
* <p/>
|
||||||
* <p>If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used.
|
* <p>If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used.
|
||||||
*
|
*
|
||||||
* @return {@link VehicleRoutingProblem}
|
* @return {@link VehicleRoutingProblem}
|
||||||
*/
|
*/
|
||||||
public VehicleRoutingProblem build() {
|
public VehicleRoutingProblem build() {
|
||||||
if(transportCosts == null){
|
if (transportCosts == null) {
|
||||||
transportCosts = new CrowFlyCosts(getLocations());
|
transportCosts = new CrowFlyCosts(getLocations());
|
||||||
}
|
}
|
||||||
for(Job job : tentativeJobs.values())
|
for (Job job : tentativeJobs.values())
|
||||||
if (!jobsInInitialRoutes.contains(job.getId())) {
|
if (!jobsInInitialRoutes.contains(job.getId())) {
|
||||||
addJobToFinalJobMapAndCreateActivities(job);
|
addJobToFinalJobMapAndCreateActivities(job);
|
||||||
}
|
}
|
||||||
|
|
@ -411,7 +409,7 @@ public class VehicleRoutingProblem {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public Builder addAllJobs(Collection<? extends Job> jobs) {
|
public Builder addAllJobs(Collection<? extends Job> jobs) {
|
||||||
for(Job j : jobs){
|
for (Job j : jobs) {
|
||||||
addJob(j);
|
addJob(j);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -425,7 +423,7 @@ public class VehicleRoutingProblem {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public Builder addAllVehicles(Collection<? extends Vehicle> vehicles) {
|
public Builder addAllVehicles(Collection<? extends Vehicle> vehicles) {
|
||||||
for(Vehicle v : vehicles){
|
for (Vehicle v : vehicles) {
|
||||||
addVehicle(v);
|
addVehicle(v);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -436,7 +434,7 @@ public class VehicleRoutingProblem {
|
||||||
*
|
*
|
||||||
* @return collection of vehicles
|
* @return collection of vehicles
|
||||||
*/
|
*/
|
||||||
public Collection<Vehicle> getAddedVehicles(){
|
public Collection<Vehicle> getAddedVehicles() {
|
||||||
return Collections.unmodifiableCollection(uniqueVehicles);
|
return Collections.unmodifiableCollection(uniqueVehicles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,7 +443,7 @@ public class VehicleRoutingProblem {
|
||||||
*
|
*
|
||||||
* @return collection of vehicle-types
|
* @return collection of vehicle-types
|
||||||
*/
|
*/
|
||||||
public Collection<VehicleType> getAddedVehicleTypes(){
|
public Collection<VehicleType> getAddedVehicleTypes() {
|
||||||
return Collections.unmodifiableCollection(vehicleTypes);
|
return Collections.unmodifiableCollection(vehicleTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,7 +452,7 @@ public class VehicleRoutingProblem {
|
||||||
*
|
*
|
||||||
* @return collection of jobs
|
* @return collection of jobs
|
||||||
*/
|
*/
|
||||||
public Collection<Job> getAddedJobs(){
|
public Collection<Job> getAddedJobs() {
|
||||||
return Collections.unmodifiableCollection(tentativeJobs.values());
|
return Collections.unmodifiableCollection(tentativeJobs.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,13 +466,12 @@ public class VehicleRoutingProblem {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum that characterizes the fleet-size.
|
* Enum that characterizes the fleet-size.
|
||||||
*
|
*
|
||||||
* @author sschroeder
|
* @author sschroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static enum FleetSize {
|
public static enum FleetSize {
|
||||||
FINITE, INFINITE
|
FINITE, INFINITE
|
||||||
|
|
@ -520,7 +517,7 @@ public class VehicleRoutingProblem {
|
||||||
|
|
||||||
private final Locations locations;
|
private final Locations locations;
|
||||||
|
|
||||||
private Map<Job,List<AbstractActivity>> activityMap;
|
private Map<Job, List<AbstractActivity>> activityMap;
|
||||||
|
|
||||||
private int nuActivities;
|
private int nuActivities;
|
||||||
|
|
||||||
|
|
@ -536,7 +533,7 @@ public class VehicleRoutingProblem {
|
||||||
private VehicleRoutingProblem(Builder builder) {
|
private VehicleRoutingProblem(Builder builder) {
|
||||||
this.jobs = builder.jobs;
|
this.jobs = builder.jobs;
|
||||||
this.fleetSize = builder.fleetSize;
|
this.fleetSize = builder.fleetSize;
|
||||||
this.vehicles=builder.uniqueVehicles;
|
this.vehicles = builder.uniqueVehicles;
|
||||||
this.vehicleTypes = builder.vehicleTypes;
|
this.vehicleTypes = builder.vehicleTypes;
|
||||||
this.initialVehicleRoutes = builder.initialRoutes;
|
this.initialVehicleRoutes = builder.initialRoutes;
|
||||||
this.transportCosts = builder.transportCosts;
|
this.transportCosts = builder.transportCosts;
|
||||||
|
|
@ -555,7 +552,7 @@ public class VehicleRoutingProblem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns type of fleetSize, either INFINITE or FINITE.
|
* Returns type of fleetSize, either INFINITE or FINITE.
|
||||||
*
|
* <p/>
|
||||||
* <p>By default, it is INFINITE.
|
* <p>By default, it is INFINITE.
|
||||||
*
|
*
|
||||||
* @return either FleetSize.INFINITE or FleetSize.FINITE
|
* @return either FleetSize.INFINITE or FleetSize.FINITE
|
||||||
|
|
@ -578,9 +575,9 @@ public class VehicleRoutingProblem {
|
||||||
*
|
*
|
||||||
* @return copied collection of initial vehicle routes
|
* @return copied collection of initial vehicle routes
|
||||||
*/
|
*/
|
||||||
public Collection<VehicleRoute> getInitialVehicleRoutes(){
|
public Collection<VehicleRoute> getInitialVehicleRoutes() {
|
||||||
Collection<VehicleRoute> copiedInitialRoutes = new ArrayList<VehicleRoute>();
|
Collection<VehicleRoute> copiedInitialRoutes = new ArrayList<VehicleRoute>();
|
||||||
for(VehicleRoute route : initialVehicleRoutes){
|
for (VehicleRoute route : initialVehicleRoutes) {
|
||||||
copiedInitialRoutes.add(VehicleRoute.copyOf(route));
|
copiedInitialRoutes.add(VehicleRoute.copyOf(route));
|
||||||
}
|
}
|
||||||
return copiedInitialRoutes;
|
return copiedInitialRoutes;
|
||||||
|
|
@ -592,7 +589,7 @@ public class VehicleRoutingProblem {
|
||||||
* @return unmodifiable collection of types
|
* @return unmodifiable collection of types
|
||||||
* @see VehicleTypeImpl
|
* @see VehicleTypeImpl
|
||||||
*/
|
*/
|
||||||
public Collection<VehicleType> getTypes(){
|
public Collection<VehicleType> getTypes() {
|
||||||
return Collections.unmodifiableCollection(vehicleTypes);
|
return Collections.unmodifiableCollection(vehicleTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -620,14 +617,14 @@ public class VehicleRoutingProblem {
|
||||||
/**
|
/**
|
||||||
* Returns activityCosts.
|
* Returns activityCosts.
|
||||||
*/
|
*/
|
||||||
public VehicleRoutingActivityCosts getActivityCosts(){
|
public VehicleRoutingActivityCosts getActivityCosts() {
|
||||||
return activityCosts;
|
return activityCosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return returns all location, i.e. from vehicles and jobs.
|
* @return returns all location, i.e. from vehicles and jobs.
|
||||||
*/
|
*/
|
||||||
public Locations getLocations(){
|
public Locations getLocations() {
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,19 +632,21 @@ public class VehicleRoutingProblem {
|
||||||
* @param job for which the corresponding activities needs to be returned
|
* @param job for which the corresponding activities needs to be returned
|
||||||
* @return associated activities
|
* @return associated activities
|
||||||
*/
|
*/
|
||||||
public List<AbstractActivity> getActivities(Job job){
|
public List<AbstractActivity> getActivities(Job job) {
|
||||||
return Collections.unmodifiableList(activityMap.get(job));
|
return Collections.unmodifiableList(activityMap.get(job));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return total number of activities
|
* @return total number of activities
|
||||||
*/
|
*/
|
||||||
public int getNuActivities(){ return nuActivities; }
|
public int getNuActivities() {
|
||||||
|
return nuActivities;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return factory that creates the activities associated to a job
|
* @return factory that creates the activities associated to a job
|
||||||
*/
|
*/
|
||||||
public JobActivityFactory getJobActivityFactory(){
|
public JobActivityFactory getJobActivityFactory() {
|
||||||
return jobActivityFactory;
|
return jobActivityFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -655,9 +654,9 @@ public class VehicleRoutingProblem {
|
||||||
* @param job for which the corresponding activities needs to be returned
|
* @param job for which the corresponding activities needs to be returned
|
||||||
* @return a copy of the activities that are associated to the specified job
|
* @return a copy of the activities that are associated to the specified job
|
||||||
*/
|
*/
|
||||||
public List<AbstractActivity> copyAndGetActivities(Job job){
|
public List<AbstractActivity> copyAndGetActivities(Job job) {
|
||||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||||
if(activityMap.containsKey(job)) {
|
if (activityMap.containsKey(job)) {
|
||||||
for (AbstractActivity act : activityMap.get(job)) acts.add((AbstractActivity) act.duplicate());
|
for (AbstractActivity act : activityMap.get(job)) acts.add((AbstractActivity) act.duplicate());
|
||||||
}
|
}
|
||||||
return acts;
|
return acts;
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ public class WaitingTimeCosts implements VehicleRoutingActivityCosts {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||||
if(vehicle != null){
|
if (vehicle != null) {
|
||||||
return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0.,tourAct.getTheoreticalEarliestOperationStartTime()-arrivalTime);
|
return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0., tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,15 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
class InfiniteVehicles implements VehicleFleetManager {
|
||||||
|
|
||||||
class InfiniteVehicles implements VehicleFleetManager{
|
|
||||||
|
|
||||||
private static Logger logger = LogManager.getLogger(InfiniteVehicles.class);
|
private static Logger logger = LogManager.getLogger(InfiniteVehicles.class);
|
||||||
|
|
||||||
private Map<VehicleTypeKey,Vehicle> types = new HashMap<VehicleTypeKey, Vehicle>();
|
private Map<VehicleTypeKey, Vehicle> types = new HashMap<VehicleTypeKey, Vehicle>();
|
||||||
|
|
||||||
// private List<VehicleTypeKey> sortedTypes = new ArrayList<VehicleTypeKey>();
|
// private List<VehicleTypeKey> sortedTypes = new ArrayList<VehicleTypeKey>();
|
||||||
|
|
||||||
public InfiniteVehicles(Collection<Vehicle> vehicles){
|
public InfiniteVehicles(Collection<Vehicle> vehicles) {
|
||||||
extractTypes(vehicles);
|
extractTypes(vehicles);
|
||||||
logger.debug("initialise " + this);
|
logger.debug("initialise " + this);
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +44,9 @@ class InfiniteVehicles implements VehicleFleetManager{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractTypes(Collection<Vehicle> vehicles) {
|
private void extractTypes(Collection<Vehicle> vehicles) {
|
||||||
for(Vehicle v : vehicles){
|
for (Vehicle v : vehicles) {
|
||||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(),v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(), v.isReturnToDepot());
|
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(), v.isReturnToDepot());
|
||||||
types.put(typeKey,v);
|
types.put(typeKey, v);
|
||||||
// sortedTypes.add(typeKey);
|
// sortedTypes.add(typeKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,8 +82,8 @@ class InfiniteVehicles implements VehicleFleetManager{
|
||||||
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
||||||
Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
|
Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills(), withoutThisType.isReturnToDepot());
|
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills(), withoutThisType.isReturnToDepot());
|
||||||
for(VehicleTypeKey key : types.keySet()){
|
for (VehicleTypeKey key : types.keySet()) {
|
||||||
if(!key.equals(thisKey)){
|
if (!key.equals(thisKey)) {
|
||||||
vehicles.add(types.get(key));
|
vehicles.add(types.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import java.util.*;
|
||||||
|
|
||||||
class VehicleFleetManagerImpl implements VehicleFleetManager {
|
class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
|
|
||||||
public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles){
|
public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles) {
|
||||||
return new VehicleFleetManagerImpl(vehicles);
|
return new VehicleFleetManagerImpl(vehicles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,14 +38,14 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
vehicleList = new ArrayList<Vehicle>();
|
vehicleList = new ArrayList<Vehicle>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(Vehicle vehicle){
|
void add(Vehicle vehicle) {
|
||||||
if(vehicleList.contains(vehicle)){
|
if (vehicleList.contains(vehicle)) {
|
||||||
throw new IllegalStateException("cannot add vehicle twice " + vehicle.getId());
|
throw new IllegalStateException("cannot add vehicle twice " + vehicle.getId());
|
||||||
}
|
}
|
||||||
vehicleList.add(vehicle);
|
vehicleList.add(vehicle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(Vehicle vehicle){
|
void remove(Vehicle vehicle) {
|
||||||
vehicleList.remove(vehicle);
|
vehicleList.remove(vehicle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,9 +66,9 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
|
|
||||||
private Set<Vehicle> lockedVehicles;
|
private Set<Vehicle> lockedVehicles;
|
||||||
|
|
||||||
private Map<VehicleTypeKey,TypeContainer> typeMapOfAvailableVehicles;
|
private Map<VehicleTypeKey, TypeContainer> typeMapOfAvailableVehicles;
|
||||||
|
|
||||||
private Map<VehicleTypeKey,Vehicle> penaltyVehicles = new HashMap<VehicleTypeKey, Vehicle>();
|
private Map<VehicleTypeKey, Vehicle> penaltyVehicles = new HashMap<VehicleTypeKey, Vehicle>();
|
||||||
|
|
||||||
|
|
||||||
public VehicleFleetManagerImpl(Collection<Vehicle> vehicles) {
|
public VehicleFleetManagerImpl(Collection<Vehicle> vehicles) {
|
||||||
|
|
@ -87,26 +87,26 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
private void makeMap() {
|
private void makeMap() {
|
||||||
typeMapOfAvailableVehicles = new HashMap<VehicleTypeKey, TypeContainer>();
|
typeMapOfAvailableVehicles = new HashMap<VehicleTypeKey, TypeContainer>();
|
||||||
penaltyVehicles = new HashMap<VehicleTypeKey, Vehicle>();
|
penaltyVehicles = new HashMap<VehicleTypeKey, Vehicle>();
|
||||||
for(Vehicle v : vehicles){
|
for (Vehicle v : vehicles) {
|
||||||
addVehicle(v);
|
addVehicle(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVehicle(Vehicle v) {
|
private void addVehicle(Vehicle v) {
|
||||||
if(v.getType() == null){
|
if (v.getType() == null) {
|
||||||
throw new IllegalStateException("vehicle needs type");
|
throw new IllegalStateException("vehicle needs type");
|
||||||
}
|
}
|
||||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(),v.isReturnToDepot() );
|
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(), v.isReturnToDepot());
|
||||||
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
|
if (!typeMapOfAvailableVehicles.containsKey(typeKey)) {
|
||||||
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
|
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
|
||||||
}
|
}
|
||||||
typeMapOfAvailableVehicles.get(typeKey).add(v);
|
typeMapOfAvailableVehicles.get(typeKey).add(v);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeVehicle(Vehicle v){
|
private void removeVehicle(Vehicle v) {
|
||||||
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(),v.isReturnToDepot() );
|
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(), v.isReturnToDepot());
|
||||||
if(typeMapOfAvailableVehicles.containsKey(key)){
|
if (typeMapOfAvailableVehicles.containsKey(key)) {
|
||||||
typeMapOfAvailableVehicles.get(key).remove(v);
|
typeMapOfAvailableVehicles.get(key).remove(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,19 +114,18 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a collection of available vehicles.
|
* Returns a collection of available vehicles.
|
||||||
*
|
* <p/>
|
||||||
*<p>If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with
|
* <p>If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with
|
||||||
* this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned.
|
* this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<Vehicle> getAvailableVehicles() {
|
public Collection<Vehicle> getAvailableVehicles() {
|
||||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||||
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
|
for (VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()) {
|
||||||
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
|
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
|
||||||
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
||||||
}
|
} else {
|
||||||
else{
|
if (penaltyVehicles.containsKey(key)) {
|
||||||
if(penaltyVehicles.containsKey(key)){
|
|
||||||
vehicles.add(penaltyVehicles.get(key));
|
vehicles.add(penaltyVehicles.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,14 +136,13 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
@Override
|
@Override
|
||||||
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
||||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills(),withoutThisType.isReturnToDepot() );
|
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills(), withoutThisType.isReturnToDepot());
|
||||||
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
|
for (VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()) {
|
||||||
if(key.equals(thisKey)) continue;
|
if (key.equals(thisKey)) continue;
|
||||||
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
|
if (!typeMapOfAvailableVehicles.get(key).isEmpty()) {
|
||||||
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle());
|
||||||
}
|
} else {
|
||||||
else{
|
if (penaltyVehicles.containsKey(key)) {
|
||||||
if(penaltyVehicles.containsKey(key)){
|
|
||||||
vehicles.add(penaltyVehicles.get(key));
|
vehicles.add(penaltyVehicles.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -156,13 +154,13 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#lock(org.matsim.contrib.freight.vrp.basics.Vehicle)
|
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#lock(org.matsim.contrib.freight.vrp.basics.Vehicle)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void lock(Vehicle vehicle){
|
public void lock(Vehicle vehicle) {
|
||||||
if(vehicles.isEmpty() || vehicle instanceof NoVehicle){
|
if (vehicles.isEmpty() || vehicle instanceof NoVehicle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean locked = lockedVehicles.add(vehicle);
|
boolean locked = lockedVehicles.add(vehicle);
|
||||||
removeVehicle(vehicle);
|
removeVehicle(vehicle);
|
||||||
if(!locked){
|
if (!locked) {
|
||||||
throw new IllegalStateException("cannot lock vehicle twice " + vehicle.getId());
|
throw new IllegalStateException("cannot lock vehicle twice " + vehicle.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -171,11 +169,11 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlock(org.matsim.contrib.freight.vrp.basics.Vehicle)
|
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlock(org.matsim.contrib.freight.vrp.basics.Vehicle)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void unlock(Vehicle vehicle){
|
public void unlock(Vehicle vehicle) {
|
||||||
if(vehicles.isEmpty() || vehicle instanceof NoVehicle){
|
if (vehicles.isEmpty() || vehicle instanceof NoVehicle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(vehicle == null) return;
|
if (vehicle == null) return;
|
||||||
lockedVehicles.remove(vehicle);
|
lockedVehicles.remove(vehicle);
|
||||||
addVehicle(vehicle);
|
addVehicle(vehicle);
|
||||||
}
|
}
|
||||||
|
|
@ -194,16 +192,16 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
||||||
@Override
|
@Override
|
||||||
public void unlockAll() {
|
public void unlockAll() {
|
||||||
Collection<Vehicle> locked = new ArrayList<Vehicle>(lockedVehicles);
|
Collection<Vehicle> locked = new ArrayList<Vehicle>(lockedVehicles);
|
||||||
for(Vehicle v : locked){
|
for (Vehicle v : locked) {
|
||||||
unlock(v);
|
unlock(v);
|
||||||
}
|
}
|
||||||
if(!lockedVehicles.isEmpty()){
|
if (!lockedVehicles.isEmpty()) {
|
||||||
throw new IllegalStateException("no vehicle must be locked");
|
throw new IllegalStateException("no vehicle must be locked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int sizeOfLockedVehicles(){
|
public int sizeOfLockedVehicles() {
|
||||||
return lockedVehicles.size();
|
return lockedVehicles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,17 +23,13 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link Vehicle}.
|
* Implementation of {@link Vehicle}.
|
||||||
*
|
*
|
||||||
* @author stefan schroeder
|
* @author stefan schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class VehicleImpl extends AbstractVehicle{
|
public class VehicleImpl extends AbstractVehicle {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,7 +37,6 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* (to avoid null).
|
* (to avoid null).
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class NoVehicle extends AbstractVehicle {
|
public static class NoVehicle extends AbstractVehicle {
|
||||||
|
|
||||||
|
|
@ -95,13 +90,12 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder that builds the vehicle.
|
* Builder that builds the vehicle.
|
||||||
*
|
* <p/>
|
||||||
* <p>By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE,
|
* <p>By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE,
|
||||||
* it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default'
|
* it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default'
|
||||||
* and a capacity of 0.
|
* and a capacity of 0.
|
||||||
*
|
*
|
||||||
* @author stefan
|
* @author stefan
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
|
|
@ -134,43 +128,44 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* Sets the {@link VehicleType}.<br>
|
* Sets the {@link VehicleType}.<br>
|
||||||
*
|
*
|
||||||
* @param type the type to be set
|
* @param type the type to be set
|
||||||
* @throws IllegalStateException if type is null
|
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @throws IllegalStateException if type is null
|
||||||
*/
|
*/
|
||||||
public Builder setType(VehicleType type){
|
public Builder setType(VehicleType type) {
|
||||||
if(type==null) throw new IllegalStateException("type cannot be null.");
|
if (type == null) throw new IllegalStateException("type cannot be null.");
|
||||||
this.type = type;
|
this.type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the flag whether the vehicle must return to depot or not.
|
* Sets the flag whether the vehicle must return to depot or not.
|
||||||
*
|
* <p/>
|
||||||
* <p>If returnToDepot is true, the vehicle must return to specified end-location. If you
|
* <p>If returnToDepot is true, the vehicle must return to specified end-location. If you
|
||||||
* omit specifying the end-location, vehicle returns to start-location (that must to be set). If
|
* omit specifying the end-location, vehicle returns to start-location (that must to be set). If
|
||||||
* you specify it, it returns to specified end-location.
|
* you specify it, it returns to specified end-location.
|
||||||
*
|
* <p/>
|
||||||
* <p>If returnToDepot is false, the end-location of the vehicle is endogenous.
|
* <p>If returnToDepot is false, the end-location of the vehicle is endogenous.
|
||||||
*
|
*
|
||||||
* @param returnToDepot true if vehicle need to return to depot, otherwise false
|
* @param returnToDepot true if vehicle need to return to depot, otherwise false
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setReturnToDepot(boolean returnToDepot){
|
public Builder setReturnToDepot(boolean returnToDepot) {
|
||||||
this.returnToDepot = returnToDepot;
|
this.returnToDepot = returnToDepot;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets start location.
|
* Sets start location.
|
||||||
|
*
|
||||||
* @param startLocation start location
|
* @param startLocation start location
|
||||||
* @return start location
|
* @return start location
|
||||||
*/
|
*/
|
||||||
public Builder setStartLocation(Location startLocation){
|
public Builder setStartLocation(Location startLocation) {
|
||||||
this.startLocation = startLocation;
|
this.startLocation = startLocation;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setEndLocation(Location endLocation){
|
public Builder setEndLocation(Location endLocation) {
|
||||||
this.endLocation = endLocation;
|
this.endLocation = endLocation;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +176,7 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @param earliest_startTime the earliest start time / departure time of the vehicle at its start location
|
* @param earliest_startTime the earliest start time / departure time of the vehicle at its start location
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setEarliestStart(double earliest_startTime){
|
public Builder setEarliestStart(double earliest_startTime) {
|
||||||
this.earliestStart = earliest_startTime;
|
this.earliestStart = earliest_startTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -192,22 +187,22 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @param latest_arrTime the latest arrival time of the vehicle at its end location
|
* @param latest_arrTime the latest arrival time of the vehicle at its end location
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setLatestArrival(double latest_arrTime){
|
public Builder setLatestArrival(double latest_arrTime) {
|
||||||
this.latestArrival = latest_arrTime;
|
this.latestArrival = latest_arrTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder addSkill(String skill){
|
public Builder addSkill(String skill) {
|
||||||
skillBuilder.addSkill(skill);
|
skillBuilder.addSkill(skill);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds and returns the vehicle.
|
* Builds and returns the vehicle.
|
||||||
*
|
* <p/>
|
||||||
* <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
|
* <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
|
||||||
* capacity=0
|
* capacity=0
|
||||||
*
|
* <p/>
|
||||||
* <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString()
|
* <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString()
|
||||||
* and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val])
|
* and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val])
|
||||||
* <p>if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString()
|
* <p>if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString()
|
||||||
|
|
@ -218,15 +213,16 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
|
* @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
|
||||||
* or (endLocationId!=null AND returnToDepot=false)
|
* or (endLocationId!=null AND returnToDepot=false)
|
||||||
*/
|
*/
|
||||||
public VehicleImpl build(){
|
public VehicleImpl build() {
|
||||||
if(startLocation != null && endLocation != null){
|
if (startLocation != null && endLocation != null) {
|
||||||
if( !startLocation.getId().equals(endLocation.getId()) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
||||||
|
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||||
}
|
}
|
||||||
if (startLocation != null && endLocation == null) {
|
if (startLocation != null && endLocation == null) {
|
||||||
endLocation = startLocation;
|
endLocation = startLocation;
|
||||||
}
|
}
|
||||||
if(startLocation == null && endLocation == null) {
|
if (startLocation == null && endLocation == null) {
|
||||||
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
||||||
}
|
}
|
||||||
skills = skillBuilder.build();
|
skills = skillBuilder.build();
|
||||||
|
|
@ -239,7 +235,9 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles
|
* @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles
|
||||||
* @return vehicle builder
|
* @return vehicle builder
|
||||||
*/
|
*/
|
||||||
public static Builder newInstance(String vehicleId){ return new Builder(vehicleId); }
|
public static Builder newInstance(String vehicleId) {
|
||||||
|
return new Builder(vehicleId);
|
||||||
|
}
|
||||||
|
|
||||||
public Builder addSkills(Skills skills) {
|
public Builder addSkills(Skills skills) {
|
||||||
this.skillBuilder.addAllSkills(skills.values());
|
this.skillBuilder.addAllSkills(skills.values());
|
||||||
|
|
@ -249,12 +247,12 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id.
|
* Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id.
|
||||||
*
|
* <p/>
|
||||||
* <p>NoVehicle has id="noVehicle" and extends {@link VehicleImpl}
|
* <p>NoVehicle has id="noVehicle" and extends {@link VehicleImpl}
|
||||||
*
|
*
|
||||||
* @return emptyVehicle
|
* @return emptyVehicle
|
||||||
*/
|
*/
|
||||||
public static NoVehicle createNoVehicle(){
|
public static NoVehicle createNoVehicle() {
|
||||||
return new NoVehicle();
|
return new NoVehicle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +272,7 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
private final Location startLocation;
|
private final Location startLocation;
|
||||||
|
|
||||||
private VehicleImpl(Builder builder){
|
private VehicleImpl(Builder builder) {
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
type = builder.type;
|
type = builder.type;
|
||||||
earliestDeparture = builder.earliestStart;
|
earliestDeparture = builder.earliestStart;
|
||||||
|
|
@ -283,22 +281,22 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
skills = builder.skills;
|
skills = builder.skills;
|
||||||
endLocation = builder.endLocation;
|
endLocation = builder.endLocation;
|
||||||
startLocation = builder.startLocation;
|
startLocation = builder.startLocation;
|
||||||
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
|
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns String with attributes of this vehicle
|
* Returns String with attributes of this vehicle
|
||||||
*
|
* <p/>
|
||||||
* <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
|
* <p>String has the following format [attr1=val1][attr2=val2]...[attrn=valn]
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id="+id+"]" +
|
return "[id=" + id + "]" +
|
||||||
"[type="+type+"]" +
|
"[type=" + type + "]" +
|
||||||
"[startLocation="+startLocation+"]" +
|
"[startLocation=" + startLocation + "]" +
|
||||||
"[endLocation=" + endLocation+"]" +
|
"[endLocation=" + endLocation + "]" +
|
||||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||||
"[skills="+ skills + "]";
|
"[skills=" + skills + "]";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,6 +377,4 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,10 @@ import jsprit.core.problem.Capacity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link VehicleType}.
|
* Implementation of {@link VehicleType}.
|
||||||
*
|
* <p/>
|
||||||
* <p>Two vehicle-types are equal if they have the same typeId.
|
* <p>Two vehicle-types are equal if they have the same typeId.
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VehicleTypeImpl implements VehicleType {
|
public class VehicleTypeImpl implements VehicleType {
|
||||||
|
|
||||||
|
|
@ -33,11 +32,10 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter.
|
* CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter.
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class VehicleCostParams {
|
public static class VehicleCostParams {
|
||||||
|
|
||||||
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){
|
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit, double perDistanceUnit) {
|
||||||
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +46,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
public final double perDistanceUnit;
|
public final double perDistanceUnit;
|
||||||
public final double perWaitingTimeUnit;
|
public final double perWaitingTimeUnit;
|
||||||
|
|
||||||
private VehicleCostParams(double fix, double perTimeUnit,double perDistanceUnit) {
|
private VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit) {
|
||||||
super();
|
super();
|
||||||
this.fix = fix;
|
this.fix = fix;
|
||||||
this.perTimeUnit = perTimeUnit;
|
this.perTimeUnit = perTimeUnit;
|
||||||
|
|
@ -67,7 +65,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[fixed="+fix+"][perTime="+perTransportTimeUnit+"][perDistance="+perDistanceUnit+"][perWaitingTimeUnit="+perWaitingTimeUnit+"]";
|
return "[fixed=" + fix + "][perTime=" + perTransportTimeUnit + "][perDistance=" + perDistanceUnit + "][perWaitingTimeUnit=" + perWaitingTimeUnit + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,14 +73,12 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* Builder that builds the vehicle-type.
|
* Builder that builds the vehicle-type.
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class Builder{
|
public static class Builder {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static VehicleTypeImpl.Builder newInstance(String id) {
|
public static VehicleTypeImpl.Builder newInstance(String id) {
|
||||||
if(id==null) throw new IllegalStateException();
|
if (id == null) throw new IllegalStateException();
|
||||||
return new Builder(id);
|
return new Builder(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,14 +112,15 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalStateException if velocity is smaller than zero
|
* @throws IllegalStateException if velocity is smaller than zero
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){
|
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
|
||||||
if(inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero");
|
if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero");
|
||||||
this.maxVelo = inMeterPerSeconds; return this;
|
this.maxVelo = inMeterPerSeconds;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the fixed costs of the vehicle-type.
|
* Sets the fixed costs of the vehicle-type.
|
||||||
*
|
* <p/>
|
||||||
* <p>by default it is 0.
|
* <p>by default it is 0.
|
||||||
*
|
*
|
||||||
* @param fixedCost
|
* @param fixedCost
|
||||||
|
|
@ -131,29 +128,29 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @throws IllegalStateException if fixedCost is smaller than zero
|
* @throws IllegalStateException if fixedCost is smaller than zero
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
|
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
|
||||||
if(fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero");
|
if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero");
|
||||||
this.fixedCost = fixedCost;
|
this.fixedCost = fixedCost;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the cost per distance unit, for instance € per meter.
|
* Sets the cost per distance unit, for instance € per meter.
|
||||||
*
|
* <p/>
|
||||||
* <p>by default it is 1.0
|
* <p>by default it is 1.0
|
||||||
*
|
*
|
||||||
* @param perDistance
|
* @param perDistance
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalStateException if perDistance is smaller than zero
|
* @throws IllegalStateException if perDistance is smaller than zero
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){
|
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
|
||||||
if(perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero");
|
if (perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero");
|
||||||
this.perDistance = perDistance;
|
this.perDistance = perDistance;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets cost per time unit, for instance € per second.
|
* Sets cost per time unit, for instance € per second.
|
||||||
*
|
* <p/>
|
||||||
* <p>by default it is 0.0
|
* <p>by default it is 0.0
|
||||||
*
|
*
|
||||||
* @param perTime
|
* @param perTime
|
||||||
|
|
@ -162,40 +159,38 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @deprecated use .setCostPerTransportTime(..) instead
|
* @deprecated use .setCostPerTransportTime(..) instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public VehicleTypeImpl.Builder setCostPerTime(double perTime){
|
public VehicleTypeImpl.Builder setCostPerTime(double perTime) {
|
||||||
if(perTime < 0.0) throw new IllegalStateException();
|
if (perTime < 0.0) throw new IllegalStateException();
|
||||||
this.perTime = perTime;
|
this.perTime = perTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets cost per time unit, for instance € per second.
|
* Sets cost per time unit, for instance € per second.
|
||||||
*
|
* <p/>
|
||||||
* <p>by default it is 0.0
|
* <p>by default it is 0.0
|
||||||
*
|
*
|
||||||
* @param perTime
|
* @param perTime
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime){
|
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
|
||||||
if(perTime < 0.0) throw new IllegalStateException();
|
if (perTime < 0.0) throw new IllegalStateException();
|
||||||
this.perTime = perTime;
|
this.perTime = perTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets cost per waiting time unit, for instance € per second.
|
* Sets cost per waiting time unit, for instance € per second.
|
||||||
*
|
* <p/>
|
||||||
* <p>by default it is 0.0
|
* <p>by default it is 0.0
|
||||||
*
|
*
|
||||||
* @param perWaitingTime
|
* @param perWaitingTime
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime){
|
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
|
||||||
if(perWaitingTime < 0.0) throw new IllegalStateException();
|
if (perWaitingTime < 0.0) throw new IllegalStateException();
|
||||||
this.perWaitingTime = perWaitingTime;
|
this.perWaitingTime = perWaitingTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +200,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
*
|
*
|
||||||
* @return VehicleTypeImpl
|
* @return VehicleTypeImpl
|
||||||
*/
|
*/
|
||||||
public VehicleTypeImpl build(){
|
public VehicleTypeImpl build() {
|
||||||
if(capacityDimensions == null){
|
if (capacityDimensions == null) {
|
||||||
capacityDimensions = capacityBuilder.build();
|
capacityDimensions = capacityBuilder.build();
|
||||||
}
|
}
|
||||||
return new VehicleTypeImpl(this);
|
return new VehicleTypeImpl(this);
|
||||||
|
|
@ -222,18 +217,19 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @throws IllegalStateException if capacity dimension is already set
|
* @throws IllegalStateException if capacity dimension is already set
|
||||||
*/
|
*/
|
||||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||||
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||||
if(capacityDimensions != null) throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
if (capacityDimensions != null)
|
||||||
|
throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
||||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||||
"You used both methods.");
|
"You used both methods.");
|
||||||
dimensionAdded = true;
|
dimensionAdded = true;
|
||||||
capacityBuilder.addDimension(dimIndex,dimVal);
|
capacityBuilder.addDimension(dimIndex, dimVal);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets capacity dimensions.
|
* Sets capacity dimensions.
|
||||||
*
|
* <p/>
|
||||||
* <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)</code> anymore. Thus either build
|
* <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)</code> anymore. Thus either build
|
||||||
* your dimensions with <code>addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions with
|
* your dimensions with <code>addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions with
|
||||||
* this method.
|
* this method.
|
||||||
|
|
@ -242,15 +238,16 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalStateException if capacityDimension has already been added
|
* @throws IllegalStateException if capacityDimension has already been added
|
||||||
*/
|
*/
|
||||||
public Builder setCapacityDimensions(Capacity capacity){
|
public Builder setCapacityDimensions(Capacity capacity) {
|
||||||
if(dimensionAdded) throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
if (dimensionAdded)
|
||||||
|
throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
||||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||||
"You used both methods.");
|
"You used both methods.");
|
||||||
this.capacityDimensions = capacity;
|
this.capacityDimensions = capacity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setProfile(String profile){
|
public Builder setProfile(String profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +299,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
*
|
*
|
||||||
* @param builder
|
* @param builder
|
||||||
*/
|
*/
|
||||||
private VehicleTypeImpl(VehicleTypeImpl.Builder builder){
|
private VehicleTypeImpl(VehicleTypeImpl.Builder builder) {
|
||||||
typeId = builder.id;
|
typeId = builder.id;
|
||||||
capacity = builder.capacity;
|
capacity = builder.capacity;
|
||||||
maxVelocity = builder.maxVelo;
|
maxVelocity = builder.maxVelo;
|
||||||
|
|
@ -329,8 +326,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[typeId="+typeId+"]" +
|
return "[typeId=" + typeId + "]" +
|
||||||
"[capacity="+capacityDimensions+"]" +
|
"[capacity=" + capacityDimensions + "]" +
|
||||||
"[costs=" + vehicleCostParams + "]";
|
"[costs=" + vehicleCostParams + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,6 +342,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProfile(){ return profile; }
|
public String getProfile() {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,12 @@ import jsprit.core.problem.Skills;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key to identify similar vehicles
|
* Key to identify similar vehicles
|
||||||
*
|
* <p/>
|
||||||
* <p>Two vehicles are equal if they share the same type, the same start and end-location and the same earliestStart and latestStart.
|
* <p>Two vehicles are equal if they share the same type, the same start and end-location and the same earliestStart and latestStart.
|
||||||
*
|
*
|
||||||
* @author stefan
|
* @author stefan
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
|
public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
|
|
||||||
public final String type;
|
public final String type;
|
||||||
public final String startLocationId;
|
public final String startLocationId;
|
||||||
|
|
@ -47,7 +46,7 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
|
||||||
this.earliestStart = earliestStart;
|
this.earliestStart = earliestStart;
|
||||||
this.latestEnd = latestEnd;
|
this.latestEnd = latestEnd;
|
||||||
this.skills = skills;
|
this.skills = skills;
|
||||||
this.returnToDepot=returnToDepot;
|
this.returnToDepot = returnToDepot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -93,5 +92,4 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,12 @@ public class VariableDepartureAndWaitingTime_IT {
|
||||||
AlgorithmFactory algorithmFactory;
|
AlgorithmFactory algorithmFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void doBefore(){
|
public void doBefore() {
|
||||||
activityCosts = new VehicleRoutingActivityCosts() {
|
activityCosts = new VehicleRoutingActivityCosts() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||||
return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0,tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -49,11 +49,11 @@ public class VariableDepartureAndWaitingTime_IT {
|
||||||
@Override
|
@Override
|
||||||
public VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) {
|
public VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) {
|
||||||
StateManager stateManager = new StateManager(vrp);
|
StateManager stateManager = new StateManager(vrp);
|
||||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
|
||||||
|
|
||||||
return Jsprit.Builder.newInstance(vrp)
|
return Jsprit.Builder.newInstance(vrp)
|
||||||
.addCoreStateAndConstraintStuff(true)
|
.addCoreStateAndConstraintStuff(true)
|
||||||
.setStateAndConstraintManager(stateManager,constraintManager)
|
.setStateAndConstraintManager(stateManager, constraintManager)
|
||||||
.setObjectiveFunction(new SolutionCostCalculator() {
|
.setObjectiveFunction(new SolutionCostCalculator() {
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||||
|
|
@ -72,10 +72,10 @@ public class VariableDepartureAndWaitingTime_IT {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void plainSetupShouldWork(){
|
public void plainSetupShouldWork() {
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10,0)).build();
|
Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(20,0)).build();
|
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(20, 0)).build();
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||||
.addJob(s1).addJob(s2).addVehicle(v)
|
.addJob(s1).addJob(s2).addVehicle(v)
|
||||||
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
||||||
|
|
@ -84,14 +84,14 @@ public class VariableDepartureAndWaitingTime_IT {
|
||||||
.build();
|
.build();
|
||||||
VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp);
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||||
Assert.assertEquals(40.,solution.getCost());
|
Assert.assertEquals(40., solution.getCost());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withTimeWindowsShouldWork(){
|
public void withTimeWindowsShouldWork() {
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
Service s1 = Service.Builder.newInstance("s1").setTimeWindow(TimeWindow.newInstance(1010,1100)).setLocation(Location.newInstance(10,0)).build();
|
Service s1 = Service.Builder.newInstance("s1").setTimeWindow(TimeWindow.newInstance(1010, 1100)).setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service s2 = Service.Builder.newInstance("s2").setTimeWindow(TimeWindow.newInstance(1020,1100)).setLocation(Location.newInstance(20,0)).build();
|
Service s2 = Service.Builder.newInstance("s2").setTimeWindow(TimeWindow.newInstance(1020, 1100)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||||
.addJob(s1).addJob(s2).addVehicle(v)
|
.addJob(s1).addJob(s2).addVehicle(v)
|
||||||
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
||||||
|
|
@ -100,9 +100,8 @@ public class VariableDepartureAndWaitingTime_IT {
|
||||||
.build();
|
.build();
|
||||||
VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp);
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||||
Assert.assertEquals(40.+1000.,solution.getCost());
|
Assert.assertEquals(40. + 1000., solution.getCost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
||||||
|
|
||||||
VehicleRoutingTransportCosts routingCosts;
|
VehicleRoutingTransportCosts routingCosts;
|
||||||
|
|
||||||
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){
|
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getActivityCost(TourActivity tourAct, double arrivalTime,Driver driver, Vehicle vehicle) {
|
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,12 +68,12 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
||||||
HardActivityConstraint hardActivityLevelConstraint = new HardActivityConstraint() {
|
HardActivityConstraint hardActivityLevelConstraint = new HardActivityConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||||
return ConstraintsStatus.FULFILLED;
|
return ConstraintsStatus.FULFILLED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint(){
|
HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||||
|
|
@ -91,7 +91,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
||||||
Vehicle vehicle;
|
Vehicle vehicle;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void doBefore(){
|
public void doBefore() {
|
||||||
routingCosts = CostFactory.createManhattanCosts();
|
routingCosts = CostFactory.createManhattanCosts();
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
||||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
||||||
|
|
|
||||||
|
|
@ -65,16 +65,16 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
|
|
||||||
VehicleRoutingProblem vehicleRoutingProblem;
|
VehicleRoutingProblem vehicleRoutingProblem;
|
||||||
|
|
||||||
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){
|
VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getActivityCost(TourActivity tourAct, double arrivalTime,Driver driver, Vehicle vehicle) {
|
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint(){
|
HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||||
|
|
@ -90,7 +90,7 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
Vehicle vehicle;
|
Vehicle vehicle;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void doBefore(){
|
public void doBefore() {
|
||||||
routingCosts = CostFactory.createManhattanCosts();
|
routingCosts = CostFactory.createManhattanCosts();
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
||||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
||||||
|
|
@ -106,7 +106,7 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue(){
|
public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||||
|
|
@ -116,16 +116,16 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
when(activityFactory.createActivities(shipment)).thenReturn(activities);
|
when(activityFactory.createActivities(shipment)).thenReturn(activities);
|
||||||
insertionCalculator.setJobActivityFactory(activityFactory);
|
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment, vehicle, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertionCalculator.getInsertionData(route, shipment, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||||
assertEquals(40.0,iData.getInsertionCost(),0.05);
|
assertEquals(40.0, iData.getInsertionCost(), 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts(){
|
public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route);
|
||||||
|
|
||||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||||
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
||||||
|
|
@ -135,9 +135,9 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
insertionCalculator.setJobActivityFactory(activityFactory);
|
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||||
|
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||||
assertEquals(0.0,iData.getInsertionCost(),0.05);
|
assertEquals(0.0, iData.getInsertionCost(), 0.05);
|
||||||
assertEquals(1,iData.getPickupInsertionIndex());
|
assertEquals(1, iData.getPickupInsertionIndex());
|
||||||
assertEquals(2,iData.getDeliveryInsertionIndex());
|
assertEquals(2, iData.getDeliveryInsertionIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AbstractActivity> getTourActivities(Shipment shipment) {
|
private List<AbstractActivity> getTourActivities(Shipment shipment) {
|
||||||
|
|
@ -150,12 +150,12 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){
|
public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||||
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route);
|
||||||
createInsertionCalculator(new HardRouteConstraint() {
|
createInsertionCalculator(new HardRouteConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -173,13 +173,13 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
insertionCalculator.setJobActivityFactory(activityFactory);
|
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||||
|
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||||
assertEquals(InsertionData.createEmptyInsertionData(),iData);
|
assertEquals(InsertionData.createEmptyInsertionData(), iData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingThirdShipment_itShouldCalcCorrectVal(){
|
public void whenInsertingThirdShipment_itShouldCalcCorrectVal() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,10")).build();
|
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,10")).build();
|
||||||
|
|
@ -187,9 +187,9 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment));
|
||||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||||
Inserter inserter = new Inserter(new InsertionListeners(),vehicleRoutingProblem );
|
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
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);
|
||||||
|
|
||||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||||
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
||||||
|
|
@ -199,13 +199,13 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
insertionCalculator.setJobActivityFactory(activityFactory);
|
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||||
|
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||||
assertEquals(0.0,iData.getInsertionCost(),0.05);
|
assertEquals(0.0, iData.getInsertionCost(), 0.05);
|
||||||
assertEquals(0,iData.getPickupInsertionIndex());
|
assertEquals(0, iData.getPickupInsertionIndex());
|
||||||
assertEquals(1,iData.getDeliveryInsertionIndex());
|
assertEquals(1, iData.getDeliveryInsertionIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingThirdShipment_itShouldCalcCorrectVal2(){
|
public void whenInsertingThirdShipment_itShouldCalcCorrectVal2() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build();
|
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build();
|
||||||
|
|
@ -213,8 +213,8 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2));
|
||||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
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);
|
||||||
|
|
||||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||||
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
||||||
|
|
@ -225,13 +225,13 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
|
|
||||||
|
|
||||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||||
assertEquals(2.0,iData.getInsertionCost(),0.05);
|
assertEquals(2.0, iData.getInsertionCost(), 0.05);
|
||||||
assertEquals(0,iData.getPickupInsertionIndex());
|
assertEquals(0, iData.getPickupInsertionIndex());
|
||||||
assertEquals(1,iData.getDeliveryInsertionIndex());
|
assertEquals(1, iData.getDeliveryInsertionIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled(){
|
public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build();
|
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build();
|
||||||
|
|
@ -243,16 +243,16 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||||
|
|
||||||
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
||||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
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);
|
||||||
|
|
||||||
StateManager stateManager = new StateManager(vrp);
|
StateManager stateManager = new StateManager(vrp);
|
||||||
stateManager.updateLoadStates();
|
stateManager.updateLoadStates();
|
||||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
|
||||||
constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager), Priority.CRITICAL);
|
||||||
constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL);
|
constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(), Priority.CRITICAL);
|
||||||
|
|
||||||
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator,
|
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator,
|
||||||
constraintManager);
|
constraintManager);
|
||||||
|
|
@ -264,7 +264,7 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData(){
|
public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData() {
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build();
|
||||||
|
|
||||||
|
|
@ -276,14 +276,14 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
|
|
||||||
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
||||||
|
|
||||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
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);
|
||||||
|
|
||||||
StateManager stateManager = new StateManager(vrp);
|
StateManager stateManager = new StateManager(vrp);
|
||||||
stateManager.updateLoadStates();
|
stateManager.updateLoadStates();
|
||||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
|
||||||
constraintManager.addLoadConstraint();
|
constraintManager.addLoadConstraint();
|
||||||
|
|
||||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
@ -296,7 +296,7 @@ public class ShipmentInsertionCalculatorTest {
|
||||||
switcher.put(Shipment.class, insertionCalculator);
|
switcher.put(Shipment.class, insertionCalculator);
|
||||||
|
|
||||||
// Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
// Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
||||||
Pickup service = (Pickup)Pickup.Builder.newInstance("pick").addSizeDimension(0, 1).setLocation(Location.newInstance("5,5")).build();
|
Pickup service = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 1).setLocation(Location.newInstance("5,5")).build();
|
||||||
|
|
||||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||||
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class TestCalculatesServiceInsertion {
|
public class TestCalculatesServiceInsertion {
|
||||||
|
|
||||||
ServiceInsertionCalculator serviceInsertion;
|
ServiceInsertionCalculator serviceInsertion;
|
||||||
|
|
@ -75,7 +73,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
private VehicleRoutingProblem vrp;
|
private VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup(){
|
public void setup() {
|
||||||
|
|
||||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
|
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
|
||||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t1).build();
|
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t1).build();
|
||||||
|
|
@ -85,7 +83,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
|
|
||||||
driver = DriverImpl.noDriver();
|
driver = DriverImpl.noDriver();
|
||||||
|
|
||||||
final Locations locations = new Locations(){
|
final Locations locations = new Locations() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getCoord(String id) {
|
public Coordinate getCoord(String id) {
|
||||||
|
|
@ -99,13 +97,13 @@ public class TestCalculatesServiceInsertion {
|
||||||
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||||
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||||
return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
return vehicle.getType().getVehicleCostParams().perDistanceUnit * ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -126,13 +124,13 @@ public class TestCalculatesServiceInsertion {
|
||||||
states.updateLoadStates();
|
states.updateLoadStates();
|
||||||
states.updateTimeWindowStates();
|
states.updateTimeWindowStates();
|
||||||
|
|
||||||
ConstraintManager cManager = new ConstraintManager(vrp,states);
|
ConstraintManager cManager = new ConstraintManager(vrp, states);
|
||||||
cManager.addLoadConstraint();
|
cManager.addLoadConstraint();
|
||||||
cManager.addTimeWindowConstraint();
|
cManager.addTimeWindowConstraint();
|
||||||
|
|
||||||
VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class);
|
VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||||
|
|
||||||
serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts), cManager);
|
serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts, states), cManager);
|
||||||
serviceInsertion.setJobActivityFactory(new JobActivityFactory() {
|
serviceInsertion.setJobActivityFactory(new JobActivityFactory() {
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractActivity> createActivities(Job job) {
|
public List<AbstractActivity> createActivities(Job job) {
|
||||||
|
|
@ -142,7 +140,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build();
|
||||||
states.informInsertionStarts(Arrays.asList(route), null);
|
states.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
|
|
@ -152,7 +150,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build();
|
||||||
states.informInsertionStarts(Arrays.asList(route), null);
|
states.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
|
|
@ -162,7 +160,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
|
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||||
states.informInsertionStarts(Arrays.asList(route), null);
|
states.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
|
|
@ -172,7 +170,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
|
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||||
states.informInsertionStarts(Arrays.asList(route), null);
|
states.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
|
|
@ -182,7 +180,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
|
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||||
states.informInsertionStarts(Arrays.asList(route), null);
|
states.informInsertionStarts(Arrays.asList(route), null);
|
||||||
|
|
||||||
|
|
@ -192,7 +190,7 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
|
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges() {
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||||
|
|
||||||
|
|
@ -204,28 +202,28 @@ public class TestCalculatesServiceInsertion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingJobAndCurrRouteIsEmpty_accessEggressCalcShouldReturnZero(){
|
public void whenInsertingJobAndCurrRouteIsEmpty_accessEggressCalcShouldReturnZero() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build();
|
||||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs);
|
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs);
|
||||||
Job job = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("1")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
Job job = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("1")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||||
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
||||||
assertEquals(0.0, accessEgressCalc.getCosts(iContex),0.01);
|
assertEquals(0.0, accessEgressCalc.getCosts(iContex), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingJobAndCurrRouteAndVehicleHaveTheSameLocation_accessEggressCalcShouldReturnZero(){
|
public void whenInsertingJobAndCurrRouteAndVehicleHaveTheSameLocation_accessEggressCalcShouldReturnZero() {
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(newVehicle, DriverImpl.noDriver())
|
VehicleRoute route = VehicleRoute.Builder.newInstance(newVehicle, DriverImpl.noDriver())
|
||||||
.addService(first)
|
.addService(first)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs);
|
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs);
|
||||||
JobInsertionContext iContex = new JobInsertionContext(route, first, newVehicle, mock(Driver.class), 0.0);
|
JobInsertionContext iContex = new JobInsertionContext(route, first, newVehicle, mock(Driver.class), 0.0);
|
||||||
assertEquals(0.0, accessEgressCalc.getCosts(iContex),0.01);
|
assertEquals(0.0, accessEgressCalc.getCosts(iContex), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingJobAndCurrRouteAndNewVehicleHaveDifferentLocations_accessEggressCostsMustBeCorrect(){
|
public void whenInsertingJobAndCurrRouteAndNewVehicleHaveDifferentLocations_accessEggressCostsMustBeCorrect() {
|
||||||
final Map<String,Coordinate> coords = new HashMap<String, Coordinate>();
|
final Map<String, Coordinate> coords = new HashMap<String, Coordinate>();
|
||||||
coords.put("oldV", Coordinate.newInstance(1, 0));
|
coords.put("oldV", Coordinate.newInstance(1, 0));
|
||||||
coords.put("newV", Coordinate.newInstance(5, 0));
|
coords.put("newV", Coordinate.newInstance(5, 0));
|
||||||
coords.put("service", Coordinate.newInstance(0, 0));
|
coords.put("service", Coordinate.newInstance(0, 0));
|
||||||
|
|
@ -233,12 +231,12 @@ public class TestCalculatesServiceInsertion {
|
||||||
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||||
return getTransportCost(from, to, departureTime, driver, vehicle);
|
return getTransportCost(from, to, departureTime, driver, vehicle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||||
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
|
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -253,6 +251,6 @@ public class TestCalculatesServiceInsertion {
|
||||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts);
|
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts);
|
||||||
Job job = Service.Builder.newInstance("service2").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build();
|
Job job = Service.Builder.newInstance("service2").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build();
|
||||||
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
||||||
assertEquals(8.0, accessEgressCalc.getCosts(iContex),0.01);
|
assertEquals(8.0, accessEgressCalc.getCosts(iContex), 0.01);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
JobInsertionContext jic;
|
JobInsertionContext jic;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void doBefore(){
|
public void doBefore() {
|
||||||
|
|
||||||
vehicle = mock(Vehicle.class);
|
vehicle = mock(Vehicle.class);
|
||||||
route = mock(VehicleRoute.class);
|
route = mock(VehicleRoute.class);
|
||||||
|
|
@ -91,7 +91,7 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){
|
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts() {
|
||||||
TourActivity prevAct = mock(TourActivity.class);
|
TourActivity prevAct = mock(TourActivity.class);
|
||||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||||
when(prevAct.getIndex()).thenReturn(1);
|
when(prevAct.getIndex()).thenReturn(1);
|
||||||
|
|
@ -105,11 +105,11 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||||
|
|
||||||
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||||
assertEquals(4.0,costs,0.01);
|
assertEquals(4.0, costs, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts(){
|
public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts() {
|
||||||
TourActivity prevAct = mock(TourActivity.class);
|
TourActivity prevAct = mock(TourActivity.class);
|
||||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||||
when(prevAct.getIndex()).thenReturn(1);
|
when(prevAct.getIndex()).thenReturn(1);
|
||||||
|
|
@ -121,11 +121,11 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||||
|
|
||||||
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||||
assertEquals(4.0,costs,0.01);
|
assertEquals(4.0, costs, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts(){
|
public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts() {
|
||||||
TourActivity prevAct = mock(TourActivity.class);
|
TourActivity prevAct = mock(TourActivity.class);
|
||||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||||
when(prevAct.getIndex()).thenReturn(1);
|
when(prevAct.getIndex()).thenReturn(1);
|
||||||
|
|
@ -139,11 +139,11 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||||
|
|
||||||
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||||
assertEquals(4.0,costs,0.01);
|
assertEquals(4.0, costs, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct(){
|
public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct() {
|
||||||
TourActivity prevAct = mock(TourActivity.class);
|
TourActivity prevAct = mock(TourActivity.class);
|
||||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||||
when(prevAct.getIndex()).thenReturn(1);
|
when(prevAct.getIndex()).thenReturn(1);
|
||||||
|
|
@ -155,16 +155,16 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||||
|
|
||||||
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0);
|
||||||
assertEquals(3.0,costs,0.01);
|
assertEquals(3.0, costs, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test(){
|
public void test() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(60, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(60, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,80)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 80)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
||||||
|
|
||||||
|
|
@ -173,12 +173,12 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(), new StateManager(mock(VehicleRoutingProblem.class)));
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(mock(VehicleRoutingProblem.class)));
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
|
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(50.,c,0.01);
|
assertEquals(50., c, 0.01);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
new: dist = 90 & wait = 0
|
new: dist = 90 & wait = 0
|
||||||
|
|
@ -188,10 +188,10 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewBetweenStartAndAct_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewBetweenStartAndAct_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0))
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0))
|
||||||
|
|
@ -199,72 +199,72 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v).build();
|
||||||
|
|
||||||
Start prevAct = new Start(Location.newInstance(0,0),0,100);
|
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),new StateManager(vrp));
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp));
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,0);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 0);
|
||||||
assertEquals(-10.,c,0.01);
|
assertEquals(-10., c, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewBetweenStartAndAct2_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewBetweenStartAndAct2_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0))
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0))
|
||||||
.setTimeWindow(TimeWindow.newInstance(140,150)).build();
|
.setTimeWindow(TimeWindow.newInstance(140, 150)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v2).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v2).build();
|
||||||
|
|
||||||
Start prevAct = new Start(Location.newInstance(0,0),0,100);
|
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v2).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v2).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v2,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v2, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(), new StateManager(vrp));
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp));
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,0);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 0);
|
||||||
assertEquals(-10.,c,0.01);
|
assertEquals(-10., c, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewInEmptyRoute_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewInEmptyRoute_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).setTimeWindow(TimeWindow.newInstance(100, 150)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).setTimeWindow(TimeWindow.newInstance(100, 150)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addVehicle(v).build();
|
||||||
|
|
||||||
Start prevAct = new Start(Location.newInstance(0,0),0,100);
|
Start prevAct = new Start(Location.newInstance(0, 0), 0, 100);
|
||||||
TourActivity newAct = vrp.getActivities(newS).get(0);
|
TourActivity newAct = vrp.getActivities(newS).get(0);
|
||||||
End nextAct = new End(Location.newInstance(0,0),0,100);
|
End nextAct = new End(Location.newInstance(0, 0), 0, 100);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),new StateManager(vrp) );
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp));
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,0);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 0);
|
||||||
assertEquals(110.,c,0.01);
|
assertEquals(110., c, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewBetweenTwoActs_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewBetweenTwoActs_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,50)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 50)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
||||||
|
|
||||||
|
|
@ -273,22 +273,22 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),new StateManager(vrp) );
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp));
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(-10.,c,0.01);
|
assertEquals(-10., c, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,500)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
||||||
|
|
||||||
|
|
@ -297,25 +297,25 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),new StateManager(vrp) );
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp));
|
||||||
calc.setSolutionCompletenessRatio(0.5);
|
calc.setSolutionCompletenessRatio(0.5);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(35.,c,0.01);
|
assertEquals(35., c, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs2_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs2_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100,120)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,500)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
||||||
|
|
||||||
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(400,500)).build();
|
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(400, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(afterNextS).addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(afterNextS).addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build();
|
||||||
|
|
||||||
|
|
@ -325,31 +325,31 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).build();
|
||||||
|
|
||||||
StateManager stateManager = getStateManager(vrp,route);
|
StateManager stateManager = getStateManager(vrp, route);
|
||||||
|
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),stateManager);
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(-10.,c,0.01);
|
assertEquals(-10., c, 0.01);
|
||||||
//
|
//
|
||||||
//old: dist: 0, waiting: 10 + 350 = 360
|
//old: dist: 0, waiting: 10 + 350 = 360
|
||||||
//new: dist: 0, waiting: 80 + 270 = 350
|
//new: dist: 0, waiting: 80 + 270 = 350
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs3_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs3_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
||||||
|
|
||||||
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build();
|
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build();
|
||||||
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build();
|
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
||||||
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
||||||
|
|
@ -362,11 +362,11 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
|
|
||||||
StateManager stateManager = getStateManager(vrp, route);
|
StateManager stateManager = getStateManager(vrp, route);
|
||||||
|
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),stateManager);
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(20.,c,0.01);
|
assertEquals(20., c, 0.01);
|
||||||
//start-delay = new - old = 120 - 40 = 80 > future waiting time savings = 30 + 20 + 10
|
//start-delay = new - old = 120 - 40 = 80 > future waiting time savings = 30 + 20 + 10
|
||||||
//ref: 10 + 50 + 20 = 80
|
//ref: 10 + 50 + 20 = 80
|
||||||
//new: 80 - 10 - 30 - 20 = 20
|
//new: 80 - 10 - 30 - 20 = 20
|
||||||
|
|
@ -376,18 +376,18 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs4_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs4_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100,120)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,500)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
||||||
|
|
||||||
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(80,500)).build();
|
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build();
|
||||||
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50,0)).setTimeWindow(TimeWindow.newInstance(100,500)).build();
|
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
||||||
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
||||||
|
|
@ -397,14 +397,14 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
|
|
||||||
StateManager stateManager = getStateManager(vrp, route);
|
StateManager stateManager = getStateManager(vrp, route);
|
||||||
|
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),stateManager);
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(30.,c,0.01);
|
assertEquals(30., c, 0.01);
|
||||||
//ref: 10 + 30 + 10 = 50
|
//ref: 10 + 30 + 10 = 50
|
||||||
//new: 50 - 50 = 0
|
//new: 50 - 50 = 0
|
||||||
|
|
||||||
|
|
@ -418,18 +418,18 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs4WithVarStart_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs4WithVarStart_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100,120)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,500)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build();
|
||||||
|
|
||||||
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(80,500)).build();
|
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build();
|
||||||
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50,0)).setTimeWindow(TimeWindow.newInstance(100,500)).build();
|
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
||||||
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
||||||
|
|
@ -439,14 +439,14 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
|
|
||||||
StateManager stateManager = getStateManager(vrp, route);
|
StateManager stateManager = getStateManager(vrp, route);
|
||||||
|
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),stateManager);
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(30.,c,0.01);
|
assertEquals(30., c, 0.01);
|
||||||
/*
|
/*
|
||||||
activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings
|
activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings
|
||||||
*/
|
*/
|
||||||
|
|
@ -459,18 +459,18 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingNewWithTWBetweenTwoActs3WithVarStart_itShouldCalcInsertionCostsCorrectly(){
|
public void whenAddingNewWithTWBetweenTwoActs3WithVarStart_itShouldCalcInsertionCostsCorrectly() {
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build();
|
||||||
|
|
||||||
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10,0)).build();
|
Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build();
|
||||||
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(50,70)).setLocation(Location.newInstance(20, 0)).build();
|
Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(50, 70)).setLocation(Location.newInstance(20, 0)).build();
|
||||||
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30,0)).setTimeWindow(TimeWindow.newInstance(40,70)).build();
|
Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 70)).build();
|
||||||
|
|
||||||
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40,0)).setTimeWindow(TimeWindow.newInstance(50,100)).build();
|
Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(50, 100)).build();
|
||||||
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50,0)).setTimeWindow(TimeWindow.newInstance(100,500)).build();
|
Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build();
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS)
|
||||||
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
.addJob(afterNextS).addJob(afterAfterNextS).build();
|
||||||
|
|
@ -480,14 +480,14 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
TourActivity nextAct = vrp.getActivities(nextS).get(0);
|
||||||
|
|
||||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build();
|
||||||
JobInsertionContext context = new JobInsertionContext(route,newS,v,null,0.);
|
JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.);
|
||||||
|
|
||||||
StateManager stateManager = getStateManager(vrp, route);
|
StateManager stateManager = getStateManager(vrp, route);
|
||||||
|
|
||||||
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(),new WaitingTimeCosts(),stateManager);
|
LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager);
|
||||||
calc.setSolutionCompletenessRatio(1.);
|
calc.setSolutionCompletenessRatio(1.);
|
||||||
double c = calc.getCosts(context,prevAct,nextAct,newAct,10);
|
double c = calc.getCosts(context, prevAct, nextAct, newAct, 10);
|
||||||
assertEquals(-10.,c,0.01);
|
assertEquals(-10., c, 0.01);
|
||||||
/*
|
/*
|
||||||
activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings
|
activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings
|
||||||
*/
|
*/
|
||||||
|
|
@ -498,16 +498,12 @@ public class TestLocalActivityInsertionCostsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) {
|
private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) {
|
||||||
StateManager stateManager = new StateManager(vrp);
|
StateManager stateManager = new StateManager(vrp);
|
||||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||||
stateManager.addStateUpdater(new UpdateVehicleDependentPracticalTimeWindows(stateManager,vrp.getTransportCosts()));
|
stateManager.addStateUpdater(new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts()));
|
||||||
stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager,vrp.getTransportCosts()));
|
stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager, vrp.getTransportCosts()));
|
||||||
stateManager.informInsertionStarts(Arrays.asList(route),new ArrayList<Job>());
|
stateManager.informInsertionStarts(Arrays.asList(route), new ArrayList<Job>());
|
||||||
return stateManager;
|
return stateManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class VehicleImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
.addSkill("drill").addSkill("screwdriver").build();
|
||||||
|
|
@ -45,7 +45,7 @@ public class VehicleImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
.addSkill("drill").addSkill("screwdriver").build();
|
||||||
|
|
@ -54,14 +54,6 @@ public class VehicleImplTest {
|
||||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){
|
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
|
||||||
.addSkill("drill").build();
|
|
||||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot() {
|
public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot() {
|
||||||
|
|
@ -221,26 +213,6 @@ public class VehicleImplTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
|
||||||
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
|
||||||
.addSkill("drill").addSkill("screwdriver").build();
|
|
||||||
assertTrue(v.getSkills().containsSkill("drill"));
|
|
||||||
assertTrue(v.getSkills().containsSkill("dRill"));
|
|
||||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<problem xmlns="http://www.w3schools.com"
|
<problem xmlns="http://www.w3schools.com"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||||
<problemType>
|
<problemType>
|
||||||
<fleetSize>FINITE</fleetSize>
|
<fleetSize>FINITE</fleetSize>
|
||||||
</problemType>
|
</problemType>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<problem xmlns="http://www.w3schools.com"
|
<problem xmlns="http://www.w3schools.com"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||||
<problemType>
|
<problemType>
|
||||||
<fleetSize>INFINITE</fleetSize>
|
<fleetSize>INFINITE</fleetSize>
|
||||||
</problemType>
|
</problemType>
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ import java.util.Collection;
|
||||||
* Illustrates how you can use jsprit with an already compiled distance and time matrix.
|
* Illustrates how you can use jsprit with an already compiled distance and time matrix.
|
||||||
*
|
*
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CostMatrixExample {
|
public class CostMatrixExample {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ public class WaitingTimeExample {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(4.).setCostPerWaitingTime(1.0).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(4.).setCostPerWaitingTime(4.0).build();
|
||||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").setCostPerDistance(4.).setCostPerWaitingTime(1.0).build();
|
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").setCostPerDistance(4.).setCostPerWaitingTime(4.0).build();
|
||||||
|
|
||||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setReturnToDepot(true)
|
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setReturnToDepot(true)
|
||||||
.setStartLocation(Location.newInstance(0, 0))
|
.setStartLocation(Location.newInstance(0, 0))
|
||||||
|
|
@ -39,13 +39,13 @@ public class WaitingTimeExample {
|
||||||
.build();
|
.build();
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
Random r = RandomNumberGeneration.newInstance();
|
Random r = RandomNumberGeneration.newInstance();
|
||||||
for(int i=0;i<40;i++){
|
for (int i = 0; i < 40; i++) {
|
||||||
Service s = Service.Builder.newInstance("s_"+i).setServiceTime(5)
|
Service s = Service.Builder.newInstance("s_" + i).setServiceTime(5)
|
||||||
.setLocation(Location.newInstance(1 - r.nextInt(5), 10 + r.nextInt(10))).build();
|
.setLocation(Location.newInstance(1 - r.nextInt(5), 10 + r.nextInt(10))).build();
|
||||||
vrpBuilder.addJob(s);
|
vrpBuilder.addJob(s);
|
||||||
}
|
}
|
||||||
Service s1 = Service.Builder.newInstance("s12").setLocation(Location.newInstance(-3, 15)).setTimeWindow(TimeWindow.newInstance(290, 600)).build();
|
Service s1 = Service.Builder.newInstance("s12").setLocation(Location.newInstance(-3, 15)).setTimeWindow(TimeWindow.newInstance(290, 600)).build();
|
||||||
Service s4 = Service.Builder.newInstance("s13").setLocation(Location.newInstance(0,20)).setTimeWindow(TimeWindow.newInstance(290, 340)).build();
|
Service s4 = Service.Builder.newInstance("s13").setLocation(Location.newInstance(0, 20)).setTimeWindow(TimeWindow.newInstance(290, 340)).build();
|
||||||
Service s2 = Service.Builder.newInstance("s10").setLocation(Location.newInstance(-1, 15)).setTimeWindow(TimeWindow.newInstance(300, 350)).build();
|
Service s2 = Service.Builder.newInstance("s10").setLocation(Location.newInstance(-1, 15)).setTimeWindow(TimeWindow.newInstance(300, 350)).build();
|
||||||
Service s3 = Service.Builder.newInstance("s11").setLocation(Location.newInstance(10, 10)).setTimeWindow(TimeWindow.newInstance(400, 600)).build();
|
Service s3 = Service.Builder.newInstance("s11").setLocation(Location.newInstance(10, 10)).setTimeWindow(TimeWindow.newInstance(400, 600)).build();
|
||||||
vrpBuilder.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addVehicle(v2).addVehicle(v3);
|
vrpBuilder.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addVehicle(v2).addVehicle(v3);
|
||||||
|
|
@ -62,13 +62,13 @@ public class WaitingTimeExample {
|
||||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||||
@Override
|
@Override
|
||||||
public double getDistance(Location from, Location to) {
|
public double getDistance(Location from, Location to) {
|
||||||
return vrp.getTransportCosts().getTransportTime(from,to,0.,null,null);
|
return vrp.getTransportCosts().getTransportTime(from, to, 0., null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
System.out.println("totalWaiting: " + sa.getWaitingTime());
|
System.out.println("totalWaiting: " + sa.getWaitingTime());
|
||||||
System.out.println("brokenTWs: " + sa.getTimeWindowViolation());
|
System.out.println("brokenTWs: " + sa.getTimeWindowViolation());
|
||||||
|
|
||||||
new Plotter(vrp,solution).setLabel(Plotter.Label.ID).plot("output/plot","plot");
|
new Plotter(vrp, solution).setLabel(Plotter.Label.ID).plot("output/plot", "plot");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,46 +38,11 @@ public class WaitingTimeExample2 {
|
||||||
Service s4 = Service.Builder.newInstance("s13").setLocation(Location.newInstance(0, 10)).build();
|
Service s4 = Service.Builder.newInstance("s13").setLocation(Location.newInstance(0, 10)).build();
|
||||||
Service s2 = Service.Builder.newInstance("s10").setLocation(Location.newInstance(1, 12)).build();
|
Service s2 = Service.Builder.newInstance("s10").setLocation(Location.newInstance(1, 12)).build();
|
||||||
Service s3 = Service.Builder.newInstance("s11").setLocation(Location.newInstance(4, 10)).build();
|
Service s3 = Service.Builder.newInstance("s11").setLocation(Location.newInstance(4, 10)).build();
|
||||||
Service s5 = Service.Builder.newInstance("s14").setLocation(Location.newInstance(6, 5)).setTimeWindow(TimeWindow.newInstance(110,220)).build();
|
Service s5 = Service.Builder.newInstance("s14").setLocation(Location.newInstance(6, 5)).setTimeWindow(TimeWindow.newInstance(110, 220)).build();
|
||||||
vrpBuilder.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addVehicle(v2);
|
vrpBuilder.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addVehicle(v2);
|
||||||
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||||
final VehicleRoutingProblem vrp = vrpBuilder.build();
|
final VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
// AlgorithmFactory algorithmFactory = new AlgorithmFactory() {
|
|
||||||
// @Override
|
|
||||||
// public VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) {
|
|
||||||
// StateManager stateManager = new StateManager(vrp);
|
|
||||||
// stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager,vrp.getTransportCosts()));
|
|
||||||
// ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
|
||||||
//
|
|
||||||
// return Jsprit.Builder.newInstance(vrp)
|
|
||||||
// .addCoreStateAndConstraintStuff(true)
|
|
||||||
// .setStateAndConstraintManager(stateManager, constraintManager)
|
|
||||||
//// .setProperty(Jsprit.Parameter.THRESHOLD_INI, "0.1")
|
|
||||||
//// .setProperty(Jsprit.Parameter.THRESHOLD_ALPHA, "0.3")
|
|
||||||
//// .setProperty(Parameter.)
|
|
||||||
//// .setProperty(Jsprit.Parameter.CONSTRUCTION, Jsprit.Construction.BEST_INSERTION.toString())
|
|
||||||
// .setObjectiveFunction(new SolutionCostCalculator() {
|
|
||||||
// @Override
|
|
||||||
// public double getCosts(VehicleRoutingProblemSolution solution) {
|
|
||||||
// double costs = 0.;
|
|
||||||
// for (VehicleRoute route : solution.getRoutes()) {
|
|
||||||
// costs += route.getVehicle().getType().getVehicleCostParams().fix;
|
|
||||||
// TourActivity prevAct = route.getStart();
|
|
||||||
// for (TourActivity act : route.getActivities()) {
|
|
||||||
// costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
|
||||||
// costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
|
|
||||||
// prevAct = act;
|
|
||||||
// }
|
|
||||||
// costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
|
||||||
// }
|
|
||||||
// costs += solution.getUnassignedJobs().size() * 200;
|
|
||||||
// return costs;
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .buildAlgorithm();
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||||
vra.setMaxIterations(1000);
|
vra.setMaxIterations(1000);
|
||||||
vra.addListener(new AlgorithmSearchProgressChartListener("output/search"));
|
vra.addListener(new AlgorithmSearchProgressChartListener("output/search"));
|
||||||
|
|
@ -85,6 +50,6 @@ public class WaitingTimeExample2 {
|
||||||
System.out.println("c: " + solution.getCost());
|
System.out.println("c: " + solution.getCost());
|
||||||
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
|
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
|
||||||
|
|
||||||
new Plotter(vrp,solution).setLabel(Plotter.Label.ID).plot("output/plot","plot");
|
new Plotter(vrp, solution).setLabel(Plotter.Label.ID).plot("output/plot", "plot");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue