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

Compare commits

...

3 commits

Author SHA1 Message Date
oblonski
267775d252
clean up 2019-06-19 10:24:47 +02:00
oblonski
a20db5e119
Merge remote-tracking branch 'origin/master' 2019-06-19 10:04:22 +02:00
oblonski
787a6835fa
clean up 2019-06-19 10:04:14 +02:00
3 changed files with 20 additions and 37 deletions

View file

@ -62,12 +62,9 @@ class InsertionDataUpdater {
}
static Comparator<VersionedInsertionData> getComparator(){
return new Comparator<VersionedInsertionData>() {
@Override
public int compare(VersionedInsertionData o1, VersionedInsertionData o2) {
if(o1.getiData().getInsertionCost() < o2.getiData().getInsertionCost()) return -1;
return 1;
}
return (o1, o2) -> {
if (o1.getiData().getInsertionCost() < o2.getiData().getInsertionCost()) return -1;
return 1;
};
}
@ -161,7 +158,7 @@ class InsertionDataUpdater {
return bestScoredJob;
}
static double score(Job unassignedJob, InsertionData best, InsertionData secondBest, ScoringFunction scoringFunction) {
private static double score(Job unassignedJob, InsertionData best, InsertionData secondBest, ScoringFunction scoringFunction) {
return Scorer.score(unassignedJob,best,secondBest,scoringFunction);
}

View file

@ -29,7 +29,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
/**
* Insertion based on regret approach.
@ -68,7 +71,7 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
this.scoringFunction = new DefaultScorer(vehicleRoutingProblem);
this.insertionCostsCalculator = jobInsertionCalculator;
this.vrp = vehicleRoutingProblem;
completionService = new ExecutorCompletionService<ScoredJob>(executorService);
completionService = new ExecutorCompletionService<>(executorService);
logger.debug("initialise " + this);
}
@ -87,7 +90,7 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
*/
@Override
public Collection<Job> insertUnassignedJobs(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
List<Job> badJobs = new ArrayList<>(unassignedJobs.size());
Iterator<Job> jobIterator = unassignedJobs.iterator();
while (jobIterator.hasNext()){
@ -135,14 +138,7 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
ScoredJob bestScoredJob = null;
for (final Job unassignedJob : unassignedJobList) {
completionService.submit(new Callable<ScoredJob>() {
@Override
public ScoredJob call() throws Exception {
return RegretInsertion.getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction);
}
});
completionService.submit(() -> RegretInsertion.getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction));
}
try {

View file

@ -93,7 +93,7 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
}
private Set<String> getInitialVehicleIds(VehicleRoutingProblem vehicleRoutingProblem) {
Set<String> ids = new HashSet<String>();
Set<String> ids = new HashSet<>();
for(VehicleRoute r : vehicleRoutingProblem.getInitialVehicleRoutes()){
ids.add(r.getVehicle().getId());
}
@ -114,7 +114,7 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
*/
@Override
public Collection<Job> insertUnassignedJobs(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
List<Job> badJobs = new ArrayList<>(unassignedJobs.size());
Iterator<Job> jobIterator = unassignedJobs.iterator();
while (jobIterator.hasNext()){
@ -136,12 +136,12 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
}
}
List<Job> jobs = new ArrayList<Job>(unassignedJobs);
List<Job> jobs = new ArrayList<>(unassignedJobs);
TreeSet<VersionedInsertionData>[] priorityQueues = new TreeSet[vrp.getJobs().values().size() + 2];
VehicleRoute lastModified = null;
boolean firstRun = true;
int updateRound = 0;
Map<VehicleRoute,Integer> updates = new HashMap<VehicleRoute, Integer>();
Map<VehicleRoute, Integer> updates = new HashMap<>();
while (!jobs.isEmpty()) {
List<Job> unassignedJobList = new ArrayList<>(jobs);
List<ScoredJob> badJobList = new ArrayList<>();
@ -170,7 +170,7 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
}
private void updateInsertionData(final TreeSet<VersionedInsertionData>[] priorityQueues, final Collection<VehicleRoute> routes, List<Job> unassignedJobList, final int updateRound, final boolean firstRun, final VehicleRoute lastModified, Map<VehicleRoute, Integer> updates) {
List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
List<Callable<Boolean>> tasks = new ArrayList<>();
boolean updatedAllRoutes = false;
for (final Job unassignedJob : unassignedJobList) {
if(priorityQueues[unassignedJob.getIndex()] == null){
@ -178,7 +178,7 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
}
if(firstRun) {
updatedAllRoutes = true;
makeCallables(tasks, updatedAllRoutes, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes, lastModified);
makeCallables(tasks, true, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes, lastModified);
}
else{
if(dependencyTypes == null || dependencyTypes[unassignedJob.getIndex()] == null){
@ -188,7 +188,7 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
DependencyType dependencyType = dependencyTypes[unassignedJob.getIndex()];
if (dependencyType.equals(DependencyType.INTER_ROUTE) || dependencyType.equals(DependencyType.INTRA_ROUTE)) {
updatedAllRoutes = true;
makeCallables(tasks, updatedAllRoutes, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes, lastModified);
makeCallables(tasks, true, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes, lastModified);
} else {
makeCallables(tasks, updatedAllRoutes, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes, lastModified);
}
@ -211,20 +211,10 @@ public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy {
private void makeCallables(List<Callable<Boolean>> tasks, boolean updateAll, final TreeSet<VersionedInsertionData> priorityQueue, final int updateRound, final Job unassignedJob, final Collection<VehicleRoute> routes, final VehicleRoute lastModified) {
if(updateAll) {
tasks.add(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return InsertionDataUpdater.update(switchAllowed, initialVehicleIds, fleetManager, insertionCostsCalculator, priorityQueue, updateRound, unassignedJob, routes);
}
});
tasks.add(() -> InsertionDataUpdater.update(switchAllowed, initialVehicleIds, fleetManager, insertionCostsCalculator, priorityQueue, updateRound, unassignedJob, routes));
}
else {
tasks.add(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return InsertionDataUpdater.update(switchAllowed, initialVehicleIds, fleetManager, insertionCostsCalculator, priorityQueue, updateRound, unassignedJob, Arrays.asList(lastModified));
}
});
tasks.add(() -> InsertionDataUpdater.update(switchAllowed, initialVehicleIds, fleetManager, insertionCostsCalculator, priorityQueue, updateRound, unassignedJob, Arrays.asList(lastModified)));
}
}