Example #1
0
  /**
   * Emits the k next-neighbours and performs an epsilon-range-query at the parallel. The returned
   * list contains two elements: At index=0 --> list with all k next-neighbours; At index=1 --> list
   * with all dataObjects within epsilon;
   *
   * @param k number of next neighbours
   * @param epsilon Specifies the range for the query
   * @param dataObject the start object
   * @return list with the k-next neighbours (PriorityQueueElements) and a list with candidates from
   *     the epsilon-range-query (EpsilonRange_ListElements)
   */
  public List k_nextNeighbourQuery(int k, double epsilon, DataObject dataObject) {
    Iterator iterator = dataObjectIterator();

    List return_List = new ArrayList();
    List nextNeighbours_List = new ArrayList();
    List epsilonRange_List = new ArrayList();

    PriorityQueue priorityQueue = new PriorityQueue();

    while (iterator.hasNext()) {
      DataObject next_dataObject = (DataObject) iterator.next();
      double dist = dataObject.distance(next_dataObject);

      if (dist <= epsilon)
        epsilonRange_List.add(new EpsilonRange_ListElement(dist, next_dataObject));

      if (priorityQueue.size() < k) {
        priorityQueue.add(dist, next_dataObject);
      } else {
        if (dist < priorityQueue.getPriority(0)) {
          priorityQueue.next(); // removes the highest distance
          priorityQueue.add(dist, next_dataObject);
        }
      }
    }

    while (priorityQueue.hasNext()) {
      nextNeighbours_List.add(0, priorityQueue.next());
    }

    return_List.add(nextNeighbours_List);
    return_List.add(epsilonRange_List);
    return return_List;
  }