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

make noise maker reproducable

This commit is contained in:
oblonski 2015-09-24 15:46:27 +02:00
parent 461bcfbc0b
commit 1ece0e6819

View file

@ -32,12 +32,20 @@ class InsertionNoiseMaker implements SoftActivityConstraint, IterationStartsList
private double noiseLevel = 0.1; private double noiseLevel = 0.1;
private Random random = RandomNumberGeneration.getRandom(); private Random random = RandomNumberGeneration.newInstance();
private Random[] randomArray;
public InsertionNoiseMaker(VehicleRoutingProblem vrp, double noiseLevel, double noiseProbability) { public InsertionNoiseMaker(VehicleRoutingProblem vrp, double noiseLevel, double noiseProbability) {
this.vrp = vrp; this.vrp = vrp;
this.noiseLevel = noiseLevel; this.noiseLevel = noiseLevel;
this.noiseProbability = noiseProbability; this.noiseProbability = noiseProbability;
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;
}
determineMaxCosts(vrp); determineMaxCosts(vrp);
} }
@ -79,7 +87,7 @@ 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 * randomArray[newAct.getIndex()].nextDouble();
} }
return 0; return 0;
} }