public void addValue(int value, double amount) { counts.put(value, amount + counts.get(value)); total += amount; }
public void addValue(int value, double amount) { counts.put(value, amount + counts.get(value)); total += amount; }
private boolean updateCosts(final int source, final int target, final double newCost, final double heuristic) { final double oldCost = gCosts.getOrDefault(target, Double.MAX_VALUE); if (newCost < oldCost) { gCosts.put(target, newCost); fCosts.put(target, newCost + heuristic); path.put(target, source); return oldCost < Double.MAX_VALUE; } return false; }
private boolean updateCosts(final int source, final int target, final double newCost, final double heuristic) { final double oldCost = gCosts.getOrDefault(target, Double.MAX_VALUE); if (newCost < oldCost) { gCosts.put(target, newCost); fCosts.put(target, newCost + heuristic); path.put(target, source); return oldCost < Double.MAX_VALUE; } return false; }
public void addValue(int value, double amount) { counts.put(value, amount + counts.get(value)); total += amount; }
public void addValue(int value, double amount) { counts.put(value, amount + counts.get(value)); total += amount; }
private boolean updateCosts(int source, int target, double newCosts) { double oldCosts = costs.getOrDefault(target, Double.MAX_VALUE); if (newCosts < oldCosts) { costs.put(target, newCosts); path.put(target, source); return oldCosts < Double.MAX_VALUE; } return false; }
/** * update cost map */ private boolean updateCosts(int source, int target, double newCosts) { double oldCosts = costs.getOrDefault(target, Double.MAX_VALUE); if (newCosts < oldCosts) { costs.put(target, newCosts); path.put(target, source); return oldCosts < Double.MAX_VALUE; } return false; }
/** * compute the shortest paths from startNode * * @param startNode the start node id (original neo4j id) * @return itself */ public ShortestPaths compute(long startNode) { graph.forEachNode(node -> { costs.put(node, Double.POSITIVE_INFINITY); return true; }); final int nodeId = graph.toMappedNodeId(startNode); costs.put(nodeId, 0d); queue.add(nodeId, 0d); run(); return this; }
/** * compute the shortest paths from startNode * * @param startNode the start node id (original neo4j id) * @return itself */ public ShortestPaths compute(long startNode) { graph.forEachNode(node -> { costs.put(node, Double.POSITIVE_INFINITY); return true; }); final int nodeId = graph.toMappedNodeId(startNode); costs.put(nodeId, 0d); queue.add(nodeId, 0d); run(); return this; }
/** * update cost map */ private UpdateResult updateCosts(int source, int target, double newCosts) { double oldCosts = costs.getOrDefault(target, Double.MAX_VALUE); if (oldCosts == Double.MAX_VALUE) { if (!costs.containsKey(target)) { costs.put(target, newCosts); path.put(target, source); return UpdateResult.NO_PREVIOUS_COSTS; } } if (newCosts < oldCosts) { costs.put(target, newCosts); path.put(target, source); return UpdateResult.UPDATED_COST; } return UpdateResult.COST_NOT_COMPETITIVE; }
private void removeWeightForSelfRelationships(int node, IntDoubleMap communityWeights) { graph.forEachRelationship(node, D, (s, t, r) -> { if(s == t) { double currentWeight = communityWeights.get(localCommunities[s]); communityWeights.put(localCommunities[s], currentWeight - graph.weightOf(s, t)); } return true; }); }
private void updateCosts(int source, int target, double newCosts) { if (costs.containsKey(target)) { if (newCosts < costs.getOrDefault(target, Double.MAX_VALUE)) { costs.put(target, newCosts); path.put(target, source); queue.update(target); } } else { if (newCosts < costs.getOrDefault(target, Double.MAX_VALUE)) { costs.put(target, newCosts); path.put(target, source); queue.add(target, newCosts); } } }
private void run() { while (!queue.isEmpty() && running()) { final int node = queue.pop(); double sourceCosts = this.costs.getOrDefault(node, Double.POSITIVE_INFINITY); // scan ALL relationships graph.forEachRelationship( node, Direction.OUTGOING, (source, target, relId, weight) -> { // relax final double targetCosts = this.costs.getOrDefault(target, Double.POSITIVE_INFINITY); if (weight + sourceCosts < targetCosts) { costs.put(target, weight + sourceCosts); queue.set(target, weight + sourceCosts); } return true; }); progressLogger.logProgress((double) node / (nodeCount - 1)); } }
public ShortestPathAStar compute( final long startNode, final long goalNode, final String propertyKeyLat, final String propertyKeyLon, final Direction direction) { reset(); final int startNodeInternal = graph.toMappedNodeId(startNode); final double startNodeLat = getNodeCoordinate(startNodeInternal, propertyKeyLat); final double startNodeLon = getNodeCoordinate(startNodeInternal, propertyKeyLon); final int goalNodeInternal = graph.toMappedNodeId(goalNode); final double goalNodeLat = getNodeCoordinate(goalNodeInternal, propertyKeyLat); final double goalNodeLon = getNodeCoordinate(goalNodeInternal, propertyKeyLon); final double initialHeuristic = computeHeuristic(startNodeLat, startNodeLon, goalNodeLat, goalNodeLon); gCosts.put(startNodeInternal, 0.0); fCosts.put(startNodeInternal, initialHeuristic); openNodes.add(startNodeInternal, 0.0); run(goalNodeInternal, propertyKeyLat, propertyKeyLon, direction); if (path.containsKey(goalNodeInternal)) { totalCost = gCosts.get(goalNodeInternal); int node = goalNodeInternal; while (node != PATH_END) { shortestPath.addFirst(node); node = path.getOrDefault(node, PATH_END); } } return this; }
public ShortestPathAStar compute( final long startNode, final long goalNode, final String propertyKeyLat, final String propertyKeyLon, final Direction direction) { reset(); final int startNodeInternal = graph.toMappedNodeId(startNode); final double startNodeLat = getNodeCoordinate(startNodeInternal, propertyKeyLat); final double startNodeLon = getNodeCoordinate(startNodeInternal, propertyKeyLon); final int goalNodeInternal = graph.toMappedNodeId(goalNode); final double goalNodeLat = getNodeCoordinate(goalNodeInternal, propertyKeyLat); final double goalNodeLon = getNodeCoordinate(goalNodeInternal, propertyKeyLon); final double initialHeuristic = computeHeuristic(startNodeLat, startNodeLon, goalNodeLat, goalNodeLon); gCosts.put(startNodeInternal, 0.0); fCosts.put(startNodeInternal, initialHeuristic); openNodes.add(startNodeInternal, 0.0); run(goalNodeInternal, propertyKeyLat, propertyKeyLon, direction); if (path.containsKey(goalNodeInternal)) { totalCost = gCosts.get(goalNodeInternal); int node = goalNodeInternal; while (node != PATH_END) { shortestPath.addFirst(node); node = path.getOrDefault(node, PATH_END); } } return this; }
private void run() { while (!queue.isEmpty() && running()) { final int node = queue.pop(); double sourceCosts = this.costs.getOrDefault(node, Double.POSITIVE_INFINITY); // scan ALL relationships graph.forEachRelationship( node, Direction.OUTGOING, (source, target, relId, weight) -> { // relax final double targetCosts = this.costs.getOrDefault(target, Double.POSITIVE_INFINITY); if (weight + sourceCosts < targetCosts) { costs.put(target, weight + sourceCosts); queue.set(target, targetCosts); } return true; }); progressLogger.logProgress((double) node / (nodeCount - 1)); } }
hourStdDevCache.put(hour, stdDev);
public ShortestPathDijkstra compute(long startNode, long goalNode, Direction direction) { reset(); int node = graph.toMappedNodeId(startNode); int goal = graph.toMappedNodeId(goalNode); costs.put(node, 0.0); queue.add(node, 0.0); run(goal, direction); if (!path.containsKey(goal)) { return this; } totalCost = costs.get(goal); int last = goal; while (last != PATH_END) { finalPath.addFirst(last); finalPathCosts.addFirst(costs.get(last)); last = path.getOrDefault(last, PATH_END); } // destroy costs and path to remove the data for nodes that are not part of the graph // since clear never downsizes the buffer array costs.release(); path.release(); return this; }
public ShortestPathDijkstra compute(long startNode, long goalNode, Direction direction) { reset(); int node = graph.toMappedNodeId(startNode); int goal = graph.toMappedNodeId(goalNode); costs.put(node, 0.0); queue.add(node, 0.0); run(goal, direction); if (!path.containsKey(goal)) { return this; } totalCost = costs.get(goal); int last = goal; while (last != PATH_END) { finalPath.addFirst(last); finalPathCosts.addFirst(costs.get(last)); last = path.getOrDefault(last, PATH_END); } // destroy costs and path to remove the data for nodes that are not part of the graph // since clear never downsizes the buffer array costs.release(); path.release(); return this; }