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:
parent
461bcfbc0b
commit
1ece0e6819
1 changed files with 10 additions and 2 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue