mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add simple insertionNoiseMaker
This commit is contained in:
parent
4925231e03
commit
57816d2d02
2 changed files with 73 additions and 5 deletions
|
|
@ -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 InsertionNoiseMaker 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;
|
||||||
|
|
||||||
|
InsertionNoiseMaker(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 * random.nextDouble();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRandom(Random random) {
|
||||||
|
this.random = random;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -327,11 +327,18 @@ public class Jsprit {
|
||||||
final double maxCosts = jobNeighborhoods.getMaxDistance();
|
final double maxCosts = jobNeighborhoods.getMaxDistance();
|
||||||
|
|
||||||
IterationStartsListener noiseConfigurator;
|
IterationStartsListener noiseConfigurator;
|
||||||
|
if(noThreads > 1) {
|
||||||
ConcurrentInsertionNoiseMaker noiseMaker = new ConcurrentInsertionNoiseMaker(vrp, maxCosts, noiseLevel, noiseProbability);
|
ConcurrentInsertionNoiseMaker noiseMaker = new ConcurrentInsertionNoiseMaker(vrp, maxCosts, noiseLevel, noiseProbability);
|
||||||
noiseMaker.setRandom(random);
|
noiseMaker.setRandom(random);
|
||||||
constraintManager.addConstraint(noiseMaker);
|
constraintManager.addConstraint(noiseMaker);
|
||||||
noiseConfigurator = noiseMaker;
|
noiseConfigurator = noiseMaker;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
InsertionNoiseMaker noiseMaker = new InsertionNoiseMaker(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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue