mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
speed up regret insertion with breaks
This commit is contained in:
parent
d3510048d5
commit
cdc0a45784
3 changed files with 16 additions and 11 deletions
|
|
@ -49,9 +49,9 @@ class ConcurrentInsertionNoiseMaker implements SoftActivityConstraint, Iteration
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||||
if (makeNoise) {
|
// if (makeNoise) {
|
||||||
return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble();
|
// return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble();
|
||||||
}
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ class InsertionNoiseMaker implements SoftActivityConstraint, IterationStartsList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||||
if (makeNoise) {
|
// if (makeNoise) {
|
||||||
return noiseLevel * maxCosts * random.nextDouble();
|
// return noiseLevel * maxCosts * random.nextDouble();
|
||||||
}
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Job> jobs = new ArrayList<Job>(unassignedJobs);
|
List<Job> jobs = new ArrayList<Job>(unassignedJobs);
|
||||||
PriorityQueue<VersionedInsertionData>[] priorityQueues = new PriorityQueue[vrp.getJobs().values().size() + 2];
|
TreeSet<VersionedInsertionData>[] priorityQueues = new TreeSet[vrp.getJobs().values().size() + 2];
|
||||||
VehicleRoute lastModified = null;
|
VehicleRoute lastModified = null;
|
||||||
boolean firstRun = true;
|
boolean firstRun = true;
|
||||||
int updateRound = 0;
|
int updateRound = 0;
|
||||||
|
|
@ -314,13 +314,13 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
return badJobs;
|
return badJobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScoredJob getBest(PriorityQueue<VersionedInsertionData>[] priorityQueues, Map<VehicleRoute, Integer> updates, List<Job> unassignedJobList, List<Job> badJobs) {
|
private ScoredJob getBest(TreeSet<VersionedInsertionData>[] priorityQueues, Map<VehicleRoute, Integer> updates, List<Job> unassignedJobList, List<Job> badJobs) {
|
||||||
ScoredJob bestScoredJob = null;
|
ScoredJob bestScoredJob = null;
|
||||||
for(Job j : unassignedJobList){
|
for(Job j : unassignedJobList){
|
||||||
VehicleRoute bestRoute = null;
|
VehicleRoute bestRoute = null;
|
||||||
InsertionData best = null;
|
InsertionData best = null;
|
||||||
InsertionData secondBest = null;
|
InsertionData secondBest = null;
|
||||||
PriorityQueue<VersionedInsertionData> priorityQueue = priorityQueues[j.getIndex()];
|
TreeSet<VersionedInsertionData> priorityQueue = priorityQueues[j.getIndex()];
|
||||||
Iterator<VersionedInsertionData> iterator = priorityQueue.iterator();
|
Iterator<VersionedInsertionData> iterator = priorityQueue.iterator();
|
||||||
while(iterator.hasNext()){
|
while(iterator.hasNext()){
|
||||||
VersionedInsertionData versionedIData = iterator.next();
|
VersionedInsertionData versionedIData = iterator.next();
|
||||||
|
|
@ -378,6 +378,11 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
badJobs.add(j);
|
badJobs.add(j);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// else {
|
||||||
|
// if(best != null && secondBest != null) {
|
||||||
|
// System.out.println("best " + best.getInsertionCost() + ", secondBest: " + secondBest.getInsertionCost());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
double score = score(j, best, secondBest, scoringFunction);
|
double score = score(j, best, secondBest, scoringFunction);
|
||||||
ScoredJob scoredJob;
|
ScoredJob scoredJob;
|
||||||
if (bestRoute == emptyRoute) {
|
if (bestRoute == emptyRoute) {
|
||||||
|
|
@ -404,10 +409,10 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateInsertionData(PriorityQueue<VersionedInsertionData>[] priorityQueues, Collection<VehicleRoute> routes, List<Job> unassignedJobList, List<Job> badJobList, int updateRound, Map<VehicleRoute, Integer> updates) {
|
private void updateInsertionData(TreeSet<VersionedInsertionData>[] priorityQueues, Collection<VehicleRoute> routes, List<Job> unassignedJobList, List<Job> badJobList, int updateRound, Map<VehicleRoute, Integer> updates) {
|
||||||
for (Job unassignedJob : unassignedJobList) {
|
for (Job unassignedJob : unassignedJobList) {
|
||||||
if(priorityQueues[unassignedJob.getIndex()] == null){
|
if(priorityQueues[unassignedJob.getIndex()] == null){
|
||||||
priorityQueues[unassignedJob.getIndex()] = new PriorityQueue<VersionedInsertionData>(unassignedJobList.size(), getComparator());
|
priorityQueues[unassignedJob.getIndex()] = new TreeSet<VersionedInsertionData>(getComparator());
|
||||||
}
|
}
|
||||||
for(VehicleRoute route : routes) {
|
for(VehicleRoute route : routes) {
|
||||||
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
Collection<Vehicle> relevantVehicles = new ArrayList<Vehicle>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue