示例#1
0
 /**
  * Method remove
  *
  * @param node
  */
 public void removeNode(WebNode node) {
   storableNodes.add(node);
   if (storableNodes.size() >= config.getBatchSize()) {
     long start = System.currentTimeMillis(); // Counter
     getQuery().storeVertices(storableNodes);
     storableNodes.clear();
     timeStoreVertices += System.currentTimeMillis() - start; // Counter
   }
   if (removedNodeIds.contains(node.getId())) {
     LOGGER.warning("Node: " + node.getId() + " already removed");
   } else {
     nodes.remove(node.getId());
     removedNodeIds.add(node.getId());
   }
 }
示例#2
0
 @Override
 public Map<Integer, Double> getAdjacentNodesCost(
     INode node,
     Set<Short> routeIds,
     Set<Integer> departureDateCodes,
     long fromTime,
     long toTime) {
   HashMap<Integer, Double> nodeDistances = new HashMap<Integer, Double>();
   DBResult dbResult = null;
   try {
     long time = System.currentTimeMillis(); // Counter
     if (config.isIncoming()) {
       dbResult =
           query.getLatestDepartureTimes(
               node.getId(),
               routeIds,
               departureDateCodes,
               fromTime,
               Math.round(toTime - node.getDistance()));
       ResultSet resultSet = dbResult.getResultSet();
       while (resultSet.next()) {
         int adjacentNodeId = resultSet.getInt("SOURCE");
         long departureTime = resultSet.getLong("TIME_D");
         long arrivalTime = resultSet.getLong("TIME_A");
         short routeId = resultSet.getShort("ROUTE_ID");
         WebNode adjacentWebNode = nodes.get(adjacentNodeId);
         adjacentWebNode.setDepartureTime(routeId, departureTime);
         WebNode webNode = ((WebNode) node);
         webNode.setArrivalTime(routeId, arrivalTime);
         double distance = toTime - departureTime;
         if (nodeDistances.get(adjacentNodeId) == null
             || distance < nodeDistances.get(adjacentNodeId)) {
           nodeDistances.put(adjacentNodeId, distance);
           adjacentWebNode.setCheapestReachedRouteId(routeId);
         }
       }
     } else {
       dbResult =
           query.getEarliestArrivalTimes(
               node.getId(),
               routeIds,
               departureDateCodes,
               Math.round(fromTime + node.getDistance()),
               toTime);
       ResultSet resultSet = dbResult.getResultSet();
       while (resultSet.next()) {
         int adjacentNodeId = resultSet.getInt("TARGET");
         long departureTime = resultSet.getLong("TIME_D");
         long arrivalTime = resultSet.getLong("TIME_A");
         short routeId = resultSet.getShort("ROUTE_ID");
         WebNode adjacentWebNode = nodes.get(adjacentNodeId);
         adjacentWebNode.setArrivalTime(routeId, arrivalTime);
         WebNode webNode = ((WebNode) node);
         webNode.setDepartureTime(routeId, departureTime);
         double distance = arrivalTime > 0 ? arrivalTime - fromTime : INode.Value.INFINITY;
         if (nodeDistances.get(adjacentNodeId) == null
             || distance < nodeDistances.get(adjacentNodeId)) {
           nodeDistances.put(adjacentNodeId, distance);
           adjacentWebNode.setCheapestReachedRouteId(routeId);
         }
       }
     }
     statistic.logRuntime(DBType.GET_DISCRETE_HETERO_COST, System.currentTimeMillis() - time);
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     dbResult.close();
   }
   return nodeDistances;
 }
示例#3
0
 @Override
 public double getAdjacentNodeCost(
     INode node,
     INode adjacentNode,
     Set<Short> routeIds,
     Set<Integer> dateCodes,
     long fromTime,
     long toTime) {
   double minDistance = INode.Value.INFINITY;
   DBResult dbResult = null;
   try {
     long time = System.currentTimeMillis();
     if (config.isIncoming()) {
       dbResult =
           query.getLatestDepartureTime(
               adjacentNode.getId(),
               node.getId(),
               routeIds,
               dateCodes,
               fromTime,
               Math.round(toTime - node.getDistance()));
       ResultSet resultSet = dbResult.getResultSet();
       while (resultSet.next()) {
         long departureTime = resultSet.getLong("TIME_D");
         long arrivalTime = resultSet.getLong("TIME_A");
         short routeId = resultSet.getShort("ROUTE_ID");
         WebNode adjacentWebNode = ((WebNode) adjacentNode);
         adjacentWebNode.setDepartureTime(routeId, departureTime);
         WebNode webNode = ((WebNode) node);
         webNode.setArrivalTime(routeId, arrivalTime);
         double distance = toTime - departureTime;
         if (distance < minDistance) {
           minDistance = distance;
           adjacentWebNode.setCheapestReachedRouteId(routeId);
         }
       }
     } else {
       dbResult =
           query.getEarliestArrivalTime(
               node.getId(),
               adjacentNode.getId(),
               routeIds,
               dateCodes,
               Math.round(fromTime + node.getDistance()),
               toTime);
       ResultSet resultSet = dbResult.getResultSet();
       while (resultSet.next()) {
         long departureTime = resultSet.getLong("TIME_D");
         long arrivalTime = resultSet.getLong("TIME_A");
         short routeId = resultSet.getShort("ROUTE_ID");
         WebNode adjacentWebNode = ((WebNode) adjacentNode);
         adjacentWebNode.setArrivalTime(routeId, arrivalTime);
         WebNode webNode = ((WebNode) node);
         webNode.setDepartureTime(routeId, departureTime);
         double distance = arrivalTime > 0 ? arrivalTime - fromTime : INode.Value.INFINITY;
         if (distance < minDistance) {
           minDistance = distance;
           adjacentWebNode.setCheapestReachedRouteId(routeId);
         }
       }
     }
     statistic.logRuntime(DBType.GET_DISCRETE_HOMO_COST, System.currentTimeMillis() - time);
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     dbResult.close();
   }
   return minDistance;
 }