mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
sort jobs acc to priorities
This commit is contained in:
parent
5fa1cea6af
commit
1ef29a268c
3 changed files with 45 additions and 26 deletions
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Licensed to GraphHopper GmbH under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with this work for
|
||||
* additional information regarding copyright ownership.
|
||||
*
|
||||
* GraphHopper GmbH licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.graphhopper.jsprit.core.algorithm.recreate;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 30/06/17.
|
||||
*/
|
||||
class AccordingToPriorities implements Comparator<Job> {
|
||||
|
||||
@Override
|
||||
public int compare(Job o1, Job o2) {
|
||||
return o1.getPriority() - o2.getPriority();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,7 +24,10 @@ import com.graphhopper.jsprit.core.util.NoiseMaker;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +66,7 @@ public final class BestInsertion extends AbstractInsertionStrategy {
|
|||
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
|
||||
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
||||
Collections.shuffle(unassignedJobList, random);
|
||||
sometimesSortPriorities(unassignedJobList);
|
||||
Collections.sort(unassignedJobList, new AccordingToPriorities());
|
||||
for (Job unassignedJob : unassignedJobList) {
|
||||
Insertion bestInsertion = null;
|
||||
InsertionData empty = new InsertionData.NoInsertionFound();
|
||||
|
|
@ -98,16 +101,4 @@ public final class BestInsertion extends AbstractInsertionStrategy {
|
|||
return badJobs;
|
||||
}
|
||||
|
||||
|
||||
private void sometimesSortPriorities(List<Job> unassignedJobList) {
|
||||
// if(random.nextDouble() < 0.5){
|
||||
Collections.sort(unassignedJobList, new Comparator<Job>() {
|
||||
@Override
|
||||
public int compare(Job o1, Job o2) {
|
||||
return o1.getPriority() - o2.getPriority();
|
||||
}
|
||||
});
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
|
||||
|
|
@ -99,7 +102,7 @@ public final class BestInsertionConcurrent extends AbstractInsertionStrategy {
|
|||
List<Job> badJobs = new ArrayList<Job>(unassignedJobs.size());
|
||||
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
||||
Collections.shuffle(unassignedJobList, random);
|
||||
sometimesSortPriorities(unassignedJobList);
|
||||
Collections.sort(unassignedJobList, new AccordingToPriorities());
|
||||
List<Batch> batches = distributeRoutes(vehicleRoutes, nuOfBatches);
|
||||
List<String> failedConstraintNames = new ArrayList<>();
|
||||
for (final Job unassignedJob : unassignedJobList) {
|
||||
|
|
@ -149,16 +152,6 @@ public final class BestInsertionConcurrent extends AbstractInsertionStrategy {
|
|||
return badJobs;
|
||||
}
|
||||
|
||||
private void sometimesSortPriorities(List<Job> unassignedJobList) {
|
||||
// if(random.nextDouble() < 0.5){
|
||||
Collections.sort(unassignedJobList, new Comparator<Job>() {
|
||||
@Override
|
||||
public int compare(Job o1, Job o2) {
|
||||
return o1.getPriority() - o2.getPriority();
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
private Insertion getBestInsertion(Batch batch, Job unassignedJob) {
|
||||
Insertion bestInsertion = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue