calculateDistancesFromJob2Job();
}
private void calculateDistancesFromJob2Job() {
logger.info("preprocess distances between locations ...");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
int nuOfDistancesStored = 0;
for (Job i : vrp.getJobs().values()) {
TreeSet<ReferencedJob> treeSet = new TreeSet<ReferencedJob>(
new Comparator<ReferencedJob>() {
@Override
public int compare(ReferencedJob o1, ReferencedJob o2) {
if (o1.getDistance() <= o2.getDistance()) {
return -1;
} else {
return 1;
}
}
});
distanceNodeTree.put(i.getId(), treeSet);
for (Job j : vrp.getJobs().values()) {
if(i==j) continue;
double distance = jobDistance.getDistance(i, j);
ReferencedJob refNode = new ReferencedJob(j, distance);
if(treeSet.size() < capacity){
treeSet.add(refNode);
nuOfDistancesStored++;
}
else{
if(treeSet.last().getDistance() > distance){
treeSet.pollLast();
treeSet.add(refNode);
}
}
}
assert treeSet.size() <= capacity : "treeSet.size() is bigger than specified capacity";
}
stopWatch.stop();
logger.info("preprocessing comp-time: " + stopWatch + "; nuOfDistances stored: " + nuOfDistancesStored + "; estimated memory: " +
(distanceNodeTree.keySet().size()*64+nuOfDistancesStored*92) + " bytes");
}