Beispiel #1
0
  /*
   * <p> Method terminate </p>
   * @param clientId
   * @return
   * @throws SQLException
   */
  public void terminate() {
    long start = System.currentTimeMillis();
    storableNodes.addAll(nodes.values());
    /*
    for (WebNode node : storableNodes) {
      removeNode(node);
    }
    */
    getQuery().storeVertices(storableNodes);
    getQuery().updateVertexTable();

    DBUtility.controlIndex(
        config.getConnection(),
        config.getDbVendor(),
        getConfig().getDestinationVertexTableEntry(),
        false);
    timeTermination = System.currentTimeMillis() - start;
    query.storeLinks(storableLinks.values());
    DBUtility.controlIndex(
        config.getConnection(), config.getDbVendor(), config.getDestinationEdgeTableEntry(), false);
    /*
     * for (Node node : storableNodes) { getQuery().storeVertices(storableNodes); }
     */

    // LOGGER.info("Finished writing remaining nodes and links after "
    // + timeTermination + "ms.");
    // return getQuery().getIsochroneBoundingBox();
  }
Beispiel #2
0
 private void init() {
   DBUtility.truncateTable(
       config.getConnection(), getConfig().getDestinationVertexTableEntry().getTableName());
   DBUtility.controlIndex(
       config.getConnection(),
       config.getDbVendor(),
       getConfig().getDestinationVertexTableEntry(),
       true);
   DBUtility.truncateTable(
       config.getConnection(),
       getConfig().getDestinationVertexAnnotatedTableEntry().getTableName());
   if (getConfig().enableAreaCalculation()) {
     DBUtility.truncateTable(
         config.getConnection(), getConfig().getDestinationAreaBufferTableEntry().getTableName());
   }
 }
  private void storeResult(ArrayList<DensityEntry> result, String resultTable) throws SQLException {
    DBUtility.createDensityTable(connection, resultTable);

    String sql = "INSERT INTO " + resultTable + " (id,density,e_dist) values(?,?,?)";
    PreparedStatement pStmt = connection.prepareStatement(sql);
    ((PGStatement) pStmt).setPrepareThreshold(1000);

    for (DensityEntry entry : result) {
      pStmt.setInt(1, entry.getId());
      pStmt.setInt(2, entry.getDensity());
      pStmt.setDouble(3, entry.getEDist());
      pStmt.executeUpdate();
    }
    connection.commit();
    // finally create the index
    DBUtility.createDensityTable_Index(connection, resultTable);
  }
  /**
   * 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;
  }