use of org.locationtech.geowave.analytic.nn.NeighborList.InferType in project geowave by locationtech.
the class NNProcessor method process.
public void process(final NeighborListFactory<STORE_VALUE> listFactory, final CompleteNotifier<STORE_VALUE> notification) throws IOException, InterruptedException {
LOGGER.info("Processing " + parentPartition.toString() + " with primary = " + primaries.size() + " and other = " + others.size());
LOGGER.info("Processing " + parentPartition.toString() + " with sub-partitions = " + uniqueSetOfPartitions.size());
index = new NeighborIndex<>(listFactory);
double farthestDistance = 0;
ByteArray farthestNeighbor = null;
ByteArray nextStart = startingPoint;
final Set<ByteArray> inspectionSet = new HashSet<>();
inspectionSet.addAll(primaries.keySet());
if ((inspectionSet.size() > 0) && (nextStart == null)) {
nextStart = inspectionSet.iterator().next();
}
while (nextStart != null) {
inspectionSet.remove(nextStart);
farthestDistance = 0;
final Set<PartitionData> partition = idsToPartition.get(nextStart);
final STORE_VALUE primary = primaries.get(nextStart);
final ByteArray primaryId = nextStart;
nextStart = null;
farthestNeighbor = null;
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("processing " + primaryId);
}
if (primary == null) {
if (inspectionSet.size() > 0) {
nextStart = inspectionSet.iterator().next();
}
continue;
}
final NeighborList<STORE_VALUE> primaryList = index.init(primaryId, primary);
for (final PartitionData pd : partition) {
for (final ByteArray neighborId : partitionsToIds.get(pd)) {
if (neighborId.equals(primaryId)) {
continue;
}
boolean isAPrimary = true;
STORE_VALUE neighbor = primaries.get(neighborId);
if (neighbor == null) {
neighbor = others.get(neighborId);
isAPrimary = false;
} else // prior processed primary
if (!inspectionSet.contains(neighborId)) {
continue;
}
if (neighbor == null) {
continue;
}
final InferType inferResult = primaryList.infer(neighborId, neighbor);
if (inferResult == InferType.NONE) {
final DistanceProfile<?> distanceProfile = distanceProfileFn.computeProfile(primary, neighbor);
final double distance = distanceProfile.getDistance();
if (distance <= maxDistance) {
index.add(distanceProfile, primaryId, primary, neighborId, neighbor, isAPrimary);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Neighbor " + neighborId);
}
}
if ((distance > farthestDistance) && inspectionSet.contains(neighborId)) {
farthestDistance = distance;
farthestNeighbor = neighborId;
}
} else if (inferResult == InferType.REMOVE) {
inspectionSet.remove(neighborId);
}
}
}
notification.complete(primaryId, primary, primaryList);
index.empty(primaryId);
if ((farthestNeighbor == null) && (inspectionSet.size() > 0)) {
nextStart = inspectionSet.iterator().next();
} else {
nextStart = farthestNeighbor;
}
}
}
Aggregations