From 1ef29a268cbfb05580387f55617c9447ff16fdd6 Mon Sep 17 00:00:00 2001 From: oblonski Date: Fri, 30 Jun 2017 08:47:55 +0200 Subject: [PATCH] sort jobs acc to priorities --- .../recreate/AccordingToPriorities.java | 35 +++++++++++++++++++ .../algorithm/recreate/BestInsertion.java | 19 +++------- .../recreate/BestInsertionConcurrent.java | 17 +++------ 3 files changed, 45 insertions(+), 26 deletions(-) create mode 100644 jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/AccordingToPriorities.java diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/AccordingToPriorities.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/AccordingToPriorities.java new file mode 100644 index 00000000..928e41a8 --- /dev/null +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/AccordingToPriorities.java @@ -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 { + + @Override + public int compare(Job o1, Job o2) { + return o1.getPriority() - o2.getPriority(); + } + +} diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertion.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertion.java index 9ae1a2cd..576e41f4 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertion.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertion.java @@ -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 badJobs = new ArrayList(unassignedJobs.size()); List unassignedJobList = new ArrayList(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 unassignedJobList) { -// if(random.nextDouble() < 0.5){ - Collections.sort(unassignedJobList, new Comparator() { - @Override - public int compare(Job o1, Job o2) { - return o1.getPriority() - o2.getPriority(); - } - }); - //} - } - } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java index bb7c11eb..c7e6ae94 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java @@ -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 badJobs = new ArrayList(unassignedJobs.size()); List unassignedJobList = new ArrayList(unassignedJobs); Collections.shuffle(unassignedJobList, random); - sometimesSortPriorities(unassignedJobList); + Collections.sort(unassignedJobList, new AccordingToPriorities()); List batches = distributeRoutes(vehicleRoutes, nuOfBatches); List failedConstraintNames = new ArrayList<>(); for (final Job unassignedJob : unassignedJobList) { @@ -149,16 +152,6 @@ public final class BestInsertionConcurrent extends AbstractInsertionStrategy { return badJobs; } - private void sometimesSortPriorities(List unassignedJobList) { - // if(random.nextDouble() < 0.5){ - Collections.sort(unassignedJobList, new Comparator() { - @Override - public int compare(Job o1, Job o2) { - return o1.getPriority() - o2.getPriority(); - } - }); - // } - } private Insertion getBestInsertion(Batch batch, Job unassignedJob) { Insertion bestInsertion = null;