mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add handler if neighborhood tree is null
This commit is contained in:
parent
5648630b0a
commit
708400a34a
3 changed files with 32 additions and 0 deletions
|
|
@ -82,6 +82,11 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-math3</artifactId>
|
||||||
|
<version>3.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,17 @@ class JobNeighborhoodsImpl implements JobNeighborhoods {
|
||||||
|
|
||||||
public Iterator<Job> getNearestNeighborsIterator(int nNeighbors, Job neighborTo){
|
public Iterator<Job> getNearestNeighborsIterator(int nNeighbors, Job neighborTo){
|
||||||
TreeSet<ReferencedJob> tree = distanceNodeTree.get(neighborTo.getId());
|
TreeSet<ReferencedJob> tree = distanceNodeTree.get(neighborTo.getId());
|
||||||
|
if(tree == null) return new Iterator<Job>() {
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Job next() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
Iterator<ReferencedJob> descendingIterator = tree.iterator();
|
Iterator<ReferencedJob> descendingIterator = tree.iterator();
|
||||||
return new NearestNeighborhoodIterator(descendingIterator, nNeighbors);
|
return new NearestNeighborhoodIterator(descendingIterator, nNeighbors);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,24 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods {
|
||||||
logger.info("intialise " + this);
|
logger.info("intialise " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: obviously nearestNeighbor does not work with a single customer
|
||||||
|
*/
|
||||||
public Iterator<Job> getNearestNeighborsIterator(int nNeighbors, Job neighborTo){
|
public Iterator<Job> getNearestNeighborsIterator(int nNeighbors, Job neighborTo){
|
||||||
TreeSet<ReferencedJob> tree = distanceNodeTree.get(neighborTo.getId());
|
TreeSet<ReferencedJob> tree = distanceNodeTree.get(neighborTo.getId());
|
||||||
|
if(tree == null) return new Iterator<Job>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Job next() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
Iterator<ReferencedJob> descendingIterator = tree.iterator();
|
Iterator<ReferencedJob> descendingIterator = tree.iterator();
|
||||||
return new NearestNeighborhoodIterator(descendingIterator, nNeighbors);
|
return new NearestNeighborhoodIterator(descendingIterator, nNeighbors);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue