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

Merge branch 'master' into driver-breaks

This commit is contained in:
oblonski 2015-09-28 09:01:22 +02:00
commit 4925231e03
45 changed files with 152 additions and 175 deletions

View file

@ -0,0 +1,61 @@
package jsprit.core.algorithm.box;
import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.SoftActivityConstraint;
import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.util.RandomNumberGeneration;
import java.util.Collection;
import java.util.Random;
/**
* Created by schroeder on 16/01/15.
*/
class ConcurrentInsertionNoiseMaker implements SoftActivityConstraint, IterationStartsListener {
private final double noiseProbability;
private boolean makeNoise = false;
private double noiseLevel = 0.1;
private Random random = RandomNumberGeneration.newInstance();
private Random[] randomArray;
private double maxCosts;
ConcurrentInsertionNoiseMaker(VehicleRoutingProblem vrp, double maxCosts, double noiseLevel, double noiseProbability) {
this.noiseLevel = noiseLevel;
this.noiseProbability = noiseProbability;
this.maxCosts = maxCosts;
randomArray = new Random[vrp.getNuActivities() + 2];
for (int i = 0; i < randomArray.length; i++) {
Random r = new Random();
r.setSeed(random.nextLong());
randomArray[i] = r;
}
}
@Override
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
if (random.nextDouble() < noiseProbability) {
makeNoise = true;
} else makeNoise = false;
}
@Override
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
if (makeNoise) {
return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble();
}
return 0;
}
public void setRandom(Random random) {
this.random = random;
}
}

View file

@ -1,91 +0,0 @@
package jsprit.core.algorithm.box;
import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.SoftActivityConstraint;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.misc.JobInsertionContext;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.util.RandomNumberGeneration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
/**
* Created by schroeder on 16/01/15.
*/
class InsertionNoiseMaker implements SoftActivityConstraint, IterationStartsListener {
private final double noiseProbability;
private boolean makeNoise = false;
private VehicleRoutingProblem vrp;
double maxCosts = 0.;
private double noiseLevel = 0.1;
private Random random = RandomNumberGeneration.getRandom();
public InsertionNoiseMaker(VehicleRoutingProblem vrp, double noiseLevel, double noiseProbability) {
this.vrp = vrp;
this.noiseLevel = noiseLevel;
this.noiseProbability = noiseProbability;
determineMaxCosts(vrp);
}
//@ToDo refactor determining max costs to allow skipping this
private void determineMaxCosts(VehicleRoutingProblem vrp) {
double max = 0.;
for (Job i : vrp.getJobs().values()) {
List<Location> fromLocations = getLocations(i);
for (Job j : vrp.getJobs().values()) {
List<Location> toLocations = getLocations(j);
for (Location iLoc : fromLocations) {
for (Location jLoc : toLocations) {
max = Math.max(max, vrp.getTransportCosts().getTransportCost(iLoc, jLoc, 0, null, vrp.getVehicles().iterator().next()));
}
}
}
}
maxCosts = max;
}
private List<Location> getLocations(Job j) {
List<Location> locs = new ArrayList<Location>();
if (j instanceof Service) {
locs.add(((Service) j).getLocation());
} else if (j instanceof Shipment) {
locs.add(((Shipment) j).getPickupLocation());
locs.add(((Shipment) j).getDeliveryLocation());
}
return locs;
}
@Override
public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
if (random.nextDouble() < noiseProbability) {
makeNoise = true;
} else makeNoise = false;
}
@Override
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
if (makeNoise) {
return noiseLevel * maxCosts * random.nextDouble();
}
return 0;
}
public void setRandom(Random random) {
this.random = random;
}
}

View file

@ -309,14 +309,29 @@ public class Jsprit {
constraintManager = new ConstraintManager(vrp, stateManager); constraintManager = new ConstraintManager(vrp, stateManager);
} }
if (noThreads == null) {
noThreads = toInteger(getProperty(Parameter.THREADS.toString()));
}
if (noThreads > 1) {
if (es == null) {
setupExecutorInternally = true;
es = Executors.newFixedThreadPool(noThreads);
}
}
double noiseLevel = toDouble(getProperty(Parameter.INSERTION_NOISE_LEVEL.toString())); double noiseLevel = toDouble(getProperty(Parameter.INSERTION_NOISE_LEVEL.toString()));
double noiseProbability = toDouble(getProperty(Parameter.INSERTION_NOISE_PROB.toString())); double noiseProbability = toDouble(getProperty(Parameter.INSERTION_NOISE_PROB.toString()));
final InsertionNoiseMaker noiseMaker = new InsertionNoiseMaker(vrp, noiseLevel, noiseProbability);
noiseMaker.setRandom(random);
constraintManager.addConstraint(noiseMaker);
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();
final double maxCosts = jobNeighborhoods.getMaxDistance();
IterationStartsListener noiseConfigurator;
ConcurrentInsertionNoiseMaker noiseMaker = new ConcurrentInsertionNoiseMaker(vrp, maxCosts, noiseLevel, noiseProbability);
noiseMaker.setRandom(random);
constraintManager.addConstraint(noiseMaker);
noiseConfigurator = noiseMaker;
RuinRadial radial = new RuinRadial(vrp, vrp.getJobs().size(), jobNeighborhoods); RuinRadial radial = new RuinRadial(vrp, vrp.getJobs().size(), jobNeighborhoods);
radial.setRandom(random); radial.setRandom(random);
@ -357,7 +372,7 @@ public class Jsprit {
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(); * maxCosts * random.nextDouble();
} else return 0.; } else return 0.;
} }
}); });
@ -374,15 +389,7 @@ public class Jsprit {
AbstractInsertionStrategy regret; AbstractInsertionStrategy regret;
final RegretInsertion.DefaultScorer scorer; final RegretInsertion.DefaultScorer scorer;
if (noThreads == null) {
noThreads = toInteger(getProperty(Parameter.THREADS.toString()));
}
if (noThreads > 1) {
if (es == null) {
setupExecutorInternally = true;
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)
@ -435,7 +442,7 @@ public class Jsprit {
} }
}; };
SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, noiseMaker.maxCosts); SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, 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));
@ -483,7 +490,7 @@ public class Jsprit {
VehicleRoutingAlgorithm vra = prettyBuilder.build(); VehicleRoutingAlgorithm vra = prettyBuilder.build();
vra.addListener(schrimpfThreshold); vra.addListener(schrimpfThreshold);
vra.addListener(noiseMaker); vra.addListener(noiseConfigurator);
vra.addListener(noise); vra.addListener(noise);
vra.addListener(clusters); vra.addListener(clusters);
vra.addListener(new RuinBreaks()); vra.addListener(new RuinBreaks());

View file

@ -13,4 +13,6 @@ public interface JobNeighborhoods {
public void initialise(); public void initialise();
public double getMaxDistance();
} }

View file

@ -22,6 +22,8 @@ class JobNeighborhoodsImpl implements JobNeighborhoods {
private JobDistance jobDistance; private JobDistance jobDistance;
private double maxDistance = 0.;
public JobNeighborhoodsImpl(VehicleRoutingProblem vrp, JobDistance jobDistance) { public JobNeighborhoodsImpl(VehicleRoutingProblem vrp, JobDistance jobDistance) {
super(); super();
this.vrp = vrp; this.vrp = vrp;
@ -58,6 +60,11 @@ class JobNeighborhoodsImpl implements JobNeighborhoods {
calculateDistancesFromJob2Job(); calculateDistancesFromJob2Job();
} }
@Override
public double getMaxDistance() {
return 0;
}
private void calculateDistancesFromJob2Job() { private void calculateDistancesFromJob2Job() {
logger.debug("preprocess distances between locations ..."); logger.debug("preprocess distances between locations ...");
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
@ -79,6 +86,7 @@ class JobNeighborhoodsImpl implements JobNeighborhoods {
for (Job j : vrp.getJobs().values()) { for (Job j : vrp.getJobs().values()) {
if (i == j) continue; if (i == j) continue;
double distance = jobDistance.getDistance(i, j); double distance = jobDistance.getDistance(i, j);
if (distance > maxDistance) maxDistance = distance;
ReferencedJob refNode = new ReferencedJob(j, distance); ReferencedJob refNode = new ReferencedJob(j, distance);
treeSet.add(refNode); treeSet.add(refNode);
nuOfDistancesStored++; nuOfDistancesStored++;

View file

@ -24,12 +24,14 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods {
private int capacity; private int capacity;
private double maxDistance = 0.;
public JobNeighborhoodsImplWithCapRestriction(VehicleRoutingProblem vrp, JobDistance jobDistance, int capacity) { public JobNeighborhoodsImplWithCapRestriction(VehicleRoutingProblem vrp, JobDistance jobDistance, int capacity) {
super(); super();
this.vrp = vrp; this.vrp = vrp;
this.jobDistance = jobDistance; this.jobDistance = jobDistance;
this.capacity = capacity; this.capacity = capacity;
logger.debug("intialise {}", this); logger.debug("initialize {}", this);
} }
@Override @Override
@ -64,6 +66,11 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods {
calculateDistancesFromJob2Job(); calculateDistancesFromJob2Job();
} }
@Override
public double getMaxDistance() {
return maxDistance;
}
private void calculateDistancesFromJob2Job() { private void calculateDistancesFromJob2Job() {
logger.debug("preprocess distances between locations ..."); logger.debug("preprocess distances between locations ...");
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
@ -85,6 +92,7 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods {
for (Job j : vrp.getJobs().values()) { for (Job j : vrp.getJobs().values()) {
if (i == j) continue; if (i == j) continue;
double distance = jobDistance.getDistance(i, j); double distance = jobDistance.getDistance(i, j);
if (distance > maxDistance) maxDistance = distance;
ReferencedJob refNode = new ReferencedJob(j, distance); ReferencedJob refNode = new ReferencedJob(j, distance);
if (treeSet.size() < capacity) { if (treeSet.size() < capacity) {
treeSet.add(refNode); treeSet.add(refNode);

View file

@ -97,8 +97,8 @@ public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor,
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation, double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation,
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime(); latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct); double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
if(latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()){ if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) {
stateManager.putTypedInternalRouteState(route,vehicle,InternalStates.SWITCH_NOT_FEASIBLE,true); stateManager.putTypedInternalRouteState(route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true);
} }
stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime; latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;

View file

@ -7,7 +7,7 @@ import jsprit.core.problem.misc.JobInsertionContext;
/** /**
* Created by schroeder on 19/09/15. * Created by schroeder on 19/09/15.
*/ */
public class SwitchNotFeasible implements HardRouteConstraint{ public class SwitchNotFeasible implements HardRouteConstraint {
private StateManager stateManager; private StateManager stateManager;
@ -17,8 +17,9 @@ public class SwitchNotFeasible implements HardRouteConstraint{
@Override @Override
public boolean fulfilled(JobInsertionContext insertionContext) { public boolean fulfilled(JobInsertionContext insertionContext) {
Boolean notFeasible = stateManager.getRouteState(insertionContext.getRoute(),insertionContext.getNewVehicle(), InternalStates.SWITCH_NOT_FEASIBLE,Boolean.class); Boolean notFeasible = stateManager.getRouteState(insertionContext.getRoute(), insertionContext.getNewVehicle(), InternalStates.SWITCH_NOT_FEASIBLE, Boolean.class);
if(notFeasible == null || insertionContext.getRoute().getVehicle().getVehicleTypeIdentifier().equals(insertionContext.getNewVehicle().getVehicleTypeIdentifier())) return true; if (notFeasible == null || insertionContext.getRoute().getVehicle().getVehicleTypeIdentifier().equals(insertionContext.getNewVehicle().getVehicleTypeIdentifier()))
return true;
else return !notFeasible; else return !notFeasible;
} }

View file

@ -107,7 +107,7 @@ class TimeWindowConstraint implements HardActivityConstraint {
routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(), routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(),
iFacts.getNewVehicle()) - newAct.getOperationTime()); iFacts.getNewVehicle()) - newAct.getOperationTime());
/* /*
* |--- prevAct ---| * |--- prevAct ---|
* |--- vehicle's arrival @newAct * |--- vehicle's arrival @newAct
* latest arrival of vehicle @newAct ---| * latest arrival of vehicle @newAct ---|
*/ */

View file

@ -66,36 +66,20 @@ public class TourActivities {
} }
} }
public static TourActivities emptyTour() {
return new TourActivities();
}
private final ArrayList<TourActivity> tourActivities = new ArrayList<TourActivity>(); private final ArrayList<TourActivity> tourActivities = new ArrayList<TourActivity>();
private final Set<Job> jobs = new HashSet<Job>(); private final Set<Job> jobs = new HashSet<Job>();
private final Set<TourActivity> activities = new HashSet<TourActivity>();
private ReverseActivityIterator backward; private ReverseActivityIterator backward;
private TourActivities(TourActivities tour2copy) { private TourActivities(TourActivities tour2copy) {
for (TourActivity tourAct : tour2copy.getActivities()) { for (TourActivity tourAct : tour2copy.getActivities()) {
TourActivity newAct = tourAct.duplicate(); TourActivity newAct = tourAct.duplicate();
this.tourActivities.add(newAct); this.tourActivities.add(newAct);
addToActivitySet(newAct);
addJob(newAct); addJob(newAct);
} }
} }
private void addToActivitySet(TourActivity newAct) {
activities.add(newAct);
}
private void removeFromActivitySet(TourActivity act) {
activities.remove(act);
}
public TourActivities() { public TourActivities() {
} }
@ -148,7 +132,6 @@ public class TourActivities {
if (c instanceof JobActivity) { if (c instanceof JobActivity) {
if (job.equals(((JobActivity) c).getJob())) { if (job.equals(((JobActivity) c).getJob())) {
tourActivities.remove(c); tourActivities.remove(c);
removeFromActivitySet(c);
activityRemoved = true; activityRemoved = true;
} }
} }
@ -163,8 +146,9 @@ public class TourActivities {
* @param activity to be looked up * @param activity to be looked up
* @return true if this contains specified activity, false otherwise * @return true if this contains specified activity, false otherwise
*/ */
@Deprecated
public boolean hasActivity(TourActivity activity) { public boolean hasActivity(TourActivity activity) {
return activities.contains(activity); return tourActivities.contains(activity);
} }
/** /**
@ -185,7 +169,6 @@ public class TourActivities {
for (TourActivity act : acts) { for (TourActivity act : acts) {
if (act == activity) { if (act == activity) {
tourActivities.remove(act); tourActivities.remove(act);
removeFromActivitySet(act);
actRemoved = true; actRemoved = true;
} else { } else {
if (act instanceof JobActivity && job != null) { if (act instanceof JobActivity && job != null) {
@ -228,7 +211,6 @@ public class TourActivities {
} else if (insertionIndex >= tourActivities.size()) { } else if (insertionIndex >= tourActivities.size()) {
tourActivities.add(act); tourActivities.add(act);
} }
addToActivitySet(act);
addJob(act); addJob(act);
} }
@ -243,7 +225,6 @@ public class TourActivities {
if (tourActivities.contains(act)) if (tourActivities.contains(act))
throw new IllegalStateException("act " + act + " already in tour. cannot add act twice."); throw new IllegalStateException("act " + act + " already in tour. cannot add act twice.");
tourActivities.add(act); tourActivities.add(act);
addToActivitySet(act);
addJob(act); addJob(act);
} }

View file

@ -119,7 +119,7 @@ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehic
* *
* @return * @return
*/ */
public double[][][] getMatrix(){ public double[][][] getMatrix() {
return matrix; return matrix;
} }

View file

@ -560,7 +560,7 @@ public class MeetTimeWindowConstraint_IT {
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp).buildAlgorithm(); VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp).buildAlgorithm();
algorithm.setMaxIterations(1000); algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){ for (VehicleRoute r : solution.getRoutes()) {
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
} }
@ -576,7 +576,7 @@ public class MeetTimeWindowConstraint_IT {
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(vrp); VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(1000); algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){ for (VehicleRoute r : solution.getRoutes()) {
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
} }
@ -592,7 +592,7 @@ public class MeetTimeWindowConstraint_IT {
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp); VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(1000); algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){ for (VehicleRoute r : solution.getRoutes()) {
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
} }
@ -602,10 +602,10 @@ public class MeetTimeWindowConstraint_IT {
private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException { private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt"))); BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt")));
String line; String line;
FastVehicleRoutingTransportCostsMatrix.Builder builder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11,false); FastVehicleRoutingTransportCostsMatrix.Builder builder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11, false);
while((line = reader.readLine()) != null){ while ((line = reader.readLine()) != null) {
String[] split = line.split("\t"); String[] split = line.split("\t");
builder.addTransportDistance(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Double.parseDouble(split[2])); builder.addTransportDistance(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[2]));
builder.addTransportTime(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[3])); builder.addTransportTime(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[3]));
} }
return builder.build(); return builder.build();

View file

@ -167,7 +167,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
} }
String[] lineTokens = line.split(","); String[] lineTokens = line.split(",");
/* /*
* build service * build service
*/ */
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1]))
.setLocation(Location.newInstance(lineTokens[0])).build(); .setLocation(Location.newInstance(lineTokens[0])).build();

View file

@ -167,7 +167,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndD
} }
String[] lineTokens = line.split(","); String[] lineTokens = line.split(",");
/* /*
* build service * build service
*/ */
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1]))
.setLocation(Location.newInstance(lineTokens[0])).build(); .setLocation(Location.newInstance(lineTokens[0])).build();

View file

@ -115,7 +115,7 @@ public class RefuseCollection_IT {
vrpBuilder.addVehicle(bigVehicle); vrpBuilder.addVehicle(bigVehicle);
/* /*
* create cost-matrix * create cost-matrix
*/ */
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
/* /*

View file

@ -409,7 +409,7 @@ public class TestLocalActivityInsertionCostsCalculator {
//new: 50 - 50 = 0 //new: 50 - 50 = 0
/* /*
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
*/ */
/* /*
old = 10 + 30 + 10 = 50 old = 10 + 30 + 10 = 50

View file

@ -109,7 +109,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
VehicleType vehicleType = vehicleTypeBuilder.build(); VehicleType vehicleType = vehicleTypeBuilder.build();
/* /*
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
*/ */
Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); vehicleBuilder.setStartLocation(Location.newInstance(10, 10));

View file

@ -87,7 +87,7 @@ public class ConfigureAlgorithmInCodeInsteadOfPerXml {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -126,7 +126,7 @@ public class EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample {
VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml"); VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml");
// algorithm.setMaxIterations(30000); // algorithm.setMaxIterations(30000);
/* /*
* and search a solution * and search a solution
*/ */
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();

View file

@ -91,7 +91,7 @@ public class MultipleDepotExample {
VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingProblem vrp = vrpBuilder.build();
/* /*
* plot to see how the problem looks like * plot to see how the problem looks like
*/ */
// SolutionPlotter.plotVrpAsPNG(vrp, "output/problem01.png", "p01"); // SolutionPlotter.plotVrpAsPNG(vrp, "output/problem01.png", "p01");

View file

@ -97,7 +97,7 @@ public class MultipleDepotExample2 {
VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingProblem vrp = vrpBuilder.build();
/* /*
* plot to see how the problem looks like * plot to see how the problem looks like
*/ */
// SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08"); // SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08");

View file

@ -62,7 +62,7 @@ public class MultipleDepotWithInitialRoutesExample {
*/ */
VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingProblem vrp = vrpBuilder.build();
/* /*
* since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they * since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they
* should not be in jobMap anymore (only variable jobs are in jobMap) * should not be in jobMap anymore (only variable jobs are in jobMap)
*/ */
assert !vrp.getJobs().containsKey("26") : "strange. service 26 should not be part of the problem"; assert !vrp.getJobs().containsKey("26") : "strange. service 26 should not be part of the problem";

View file

@ -72,7 +72,7 @@ public class PickupAndDeliveryExample {
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -78,7 +78,7 @@ public class PickupAndDeliveryExample2 {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/* /*
* Retrieve best solution. * Retrieve best solution.
*/ */
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -69,7 +69,7 @@ public class PickupAndDeliveryOpenExample {
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_open.xml"); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_open.xml");
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -110,7 +110,7 @@ public class RefuseCollectionExample {
} }
String[] lineTokens = line.split(","); String[] lineTokens = line.split(",");
/* /*
* build service * build service
*/ */
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocation(Location.newInstance(lineTokens[0])).build(); Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocation(Location.newInstance(lineTokens[0])).build();
/* /*

View file

@ -109,7 +109,7 @@ public class RefuseCollectionWithFastMatrixExample {
} }
String[] lineTokens = line.split(","); String[] lineTokens = line.split(",");
/* /*
* build service * build service
*/ */
Service service = Service.Builder.newInstance(lineTokens[0]) Service service = Service.Builder.newInstance(lineTokens[0])
.addSizeDimension(0, Integer.parseInt(lineTokens[1])) .addSizeDimension(0, Integer.parseInt(lineTokens[1]))

View file

@ -109,7 +109,7 @@ public class ServicePickupsWithMultipleDepotsExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -88,7 +88,7 @@ public class SimpleDepotBoundedPickupAndDeliveryExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -93,7 +93,7 @@ public class SimpleEnRoutePickupAndDeliveryExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -93,7 +93,7 @@ public class SimpleEnRoutePickupAndDeliveryOpenRoutesExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -97,7 +97,7 @@ public class SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample {
VehicleRoutingProblem problem = vrpBuilder.build(); VehicleRoutingProblem problem = vrpBuilder.build();
/* /*
* build the algorithm * build the algorithm
*/ */
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig.xml"); VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig.xml");
vraBuilder.addCoreConstraints(); vraBuilder.addCoreConstraints();

View file

@ -93,7 +93,7 @@ public class SimpleExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -87,7 +87,7 @@ public class SimpleExampleOpenRoutes {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -115,7 +115,7 @@ public class SimpleExampleWithSkills {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/* /*
* get the best * get the best
*/ */
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -103,7 +103,7 @@ public class SimpleVRPWithBackhaulsExample {
SolutionPrinter.print(bestSolution); SolutionPrinter.print(bestSolution);
/* /*
* plot * plot
*/ */
Plotter plotter = new Plotter(problem, bestSolution); Plotter plotter = new Plotter(problem, bestSolution);
plotter.setLabel(Label.SIZE); plotter.setLabel(Label.SIZE);

View file

@ -74,7 +74,7 @@ public class SolomonExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/* /*
* Retrieve best solution. * Retrieve best solution.
*/ */
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -77,7 +77,7 @@ public class SolomonExampleWithSpecifiedVehicleEndLocations {
// vra.setPrematureBreak(100); // vra.setPrematureBreak(100);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -77,7 +77,7 @@ public class SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs {
// vra.setPrematureBreak(100); // vra.setPrematureBreak(100);
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); // vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -69,7 +69,7 @@ public class SolomonOpenExample {
// vra.setPrematureBreak(100); // vra.setPrematureBreak(100);
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); // vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -68,7 +68,7 @@ public class SolomonR101Example {
vra.setMaxIterations(20000); vra.setMaxIterations(20000);
// vra.setPrematureBreak(100); // vra.setPrematureBreak(100);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *

View file

@ -81,7 +81,7 @@ public class SolomonWithRegretInsertionExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/* /*
* Retrieve best solution. * Retrieve best solution.
*/ */
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -186,7 +186,7 @@ public class TransportOfDisabledPeople {
algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
/* /*
* and search a solution * and search a solution
*/ */
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();

View file

@ -77,7 +77,7 @@ public class VRPWithBackhaulsExample {
VehicleRoutingAlgorithm vra = vraBuilder.build(); VehicleRoutingAlgorithm vra = vraBuilder.build();
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/* /*
* Solve the problem. * Solve the problem.
* *
* *
*/ */

View file

@ -105,7 +105,7 @@ public class VRPWithBackhaulsExample2 {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/* /*
* Retrieve best solution. * Retrieve best solution.
*/ */
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);