@Override public Collection<ILink> getAdjacentContinuousLinks(INode node) { Collection<ILink> adjacentLinks = new ArrayList<ILink>(); DBResult dbResult = null; try { int nodeId = node.getId(); long start = System.currentTimeMillis(); // Counter dbResult = query.getAdjacentContinuousLinks(nodeId); ResultSet resultSet = dbResult.getResultSet(); while (resultSet.next()) { ILink link; int linkId = resultSet.getInt("ID"); int adjacentNodeId = resultSet.getInt("NODE_ID"); short degree = resultSet.getShort("NODE_DEGREE"); double length = resultSet.getDouble("LENGTH"); if (config.isIncoming()) { link = new ContinuousLink(linkId, adjacentNodeId, nodeId, length); } else { link = new ContinuousLink(linkId, nodeId, adjacentNodeId, length); } addNode(adjacentNodeId, degree); adjacentLinks.add(link); statistic.log(Type.LOADED_CONTINUOUS_LINKS); } statistic.logRuntime(DBType.GET_LINKS, System.currentTimeMillis() - start); } catch (SQLException e) { e.printStackTrace(); } finally { if (dbResult != null) { dbResult.close(); } } return adjacentLinks; }
@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; }
@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; }