public boolean hasWarnings() {
   return !warningMessages.isEmpty();
 }
Ejemplo n.º 2
0
  /**
   * Method createDensityTable TODO: document me!!
   *
   * @param vertexTable
   * @param sizePoints
   * @return
   * @throws SQLException
   */
  private ArrayList<DensityEntry> createDensityTable(String vertexTable, int[] sizePoints)
      throws SQLException {
    ArrayList<DensityEntry> result = new ArrayList<DensityEntry>();
    int vertexSize = DBUtility.getTotalVertexSize(connection, vertexTable, true);
    Vertex[] V = new Vertex[vertexSize];

    int maxSize = sizePoints[sizePoints.length - 1];

    DBResult dbResult = DBUtility.getAllVerticesSortedByX(connection, vertexTable);
    ResultSet rSet = dbResult.getResultSet();
    int i = 0;
    while (rSet.next()) { // filling the array with values
      V[i++] = new Vertex(rSet.getInt(1), rSet.getDouble(2), rSet.getDouble(3));
    }

    double[] distances = new double[maxSize];

    // defining comparator
    Comparator<Double> descendingCmp =
        new Comparator<Double>() {
          @Override
          public int compare(Double o1, Double o2) {
            if (o1 < o2) return 1;
            if (o1 > o2) return -1;
            return 0;
          }
        };

    AbstractQueue<Double> heap = new PriorityQueue<Double>(maxSize, descendingCmp);
    for (i = 0; i < vertexSize; i++) {
      System.out.println("Iteration: " + i + "/" + vertexSize);
      double k = Double.POSITIVE_INFINITY;
      int size = 0;

      int l = i, r = i, idx = 0;
      while (V[r].x - V[l].x <= 2 * k && idx < vertexSize - 1) {
        if (l == 0) { // left out of range condition
          idx = ++r;
        } else if (r == vertexSize - 1) { // right out of range condition
          idx = --l;
        } else { // choose between left and right element that one with smallest distance to its
                 // neighbor
          idx = V[i].x - V[l - 1].x < V[r + 1].x - V[i].x ? --l : ++r;
        }
        if (size < maxSize) { // as long we do not reach max size we simply add in heap and sort
          heap.add(eDist(V[i], V[idx]));
          size++;
        } else {
          double d = eDist(V[i], V[idx]);
          if (heap.peek() > d) {
            heap.poll();
            heap.add(d);
            k = heap.peek();
          }
        }
      }

      // convert heap to a sorted array
      int j = distances.length - 1;

      while (!heap.isEmpty()) {
        distances[j--] = heap.poll();
      }

      // reading for each size the corresponding euclidean distance
      for (j = 0; j < sizePoints.length; j++) {
        int p = sizePoints[j];
        result.add(new DensityEntry(V[i].id, p, distances[p - 1]));
      }
    }
    return result;
  }