/** * To calculate the shortest path from lrs (source router) to lrd (destination) * @param lrs - source router identifier. * @param lrd - destination router identifier. * @param topo - topology * @return the links constructing the path. */ private List<Link> calcShortestPath(NodeId nodes, NodeId noded, Graph<NodeId, Link> graph) { DijkstraShortestPath<NodeId, Link> alg = new DijkstraShortestPath<>(graph); return alg.getPath(nodes, noded); }
@Override public synchronized void clearMaxThroughput() { if (mtp != null) { mtp.reset(); // reset max throughput path } }
/** * Returns a <code>LinkedHashMap</code> which maps each node in the graph (including the <code> * source</code> node) to the last edge on the shortest path from the <code>source</code> node. * The map's iterator will return the elements in order of increasing distance from <code> * source</code>. * * @see DijkstraDistance#getDistanceMap(Object,int) * @see DijkstraDistance#getDistance(Object,Object) * @param source the node from which distances are measured */ public Map<N, E> getIncomingEdgeMap(N source) { return getIncomingEdgeMap(source, g.nodes().size()); }
if (dijkstra.getDistance(startVertex, endVertex) == null) return linkDisjointSPs; List<E> sp = dijkstra.getPath(startVertex, endVertex); Map<V, Number> lengthMap = dijkstra.getDistanceMap(startVertex); DijkstraShortestPath<V, E> revDijkstra = new DijkstraShortestPath<V, E>(revG, lengthTrans, cached); Number revDistance = revDijkstra.getDistance(startVertex, endVertex); if (revDistance == null || revDistance.doubleValue() == Double.MAX_VALUE) List<E> revSp = revDijkstra.getPath(startVertex, endVertex);
"and <= g.numVertices()"); singleSourceShortestPath(source, null, numDests); reset(source);
/** This constructor allows to configure if the shortest-path algorithm should cached previous computations. * * @param graph Graph on which shortest paths are searched * @param nev The class responsible for returning weights for edges * @param cached Indicates whether previous computations from the shortest-path algorithm should be cached */ private SuurballeTarjanAlgorithm(Graph<V, E> graph, Transformer<E, Double> nev, boolean cached) { this.graph = graph; this.nev = nev; this.cached = cached; dijkstra = new DijkstraShortestPath<V, E>(graph, nev, cached); }
if (dijkstra.getDistance(startVertex, endVertex) == null) return paths; List<E> aux = dijkstra.getPath(startVertex, endVertex); double cost = GraphUtils.JUNGUtils.getPathWeight(aux, nev); GraphPath<E> shortestPath = new GraphPath<E>(aux, cost); blockedDijkstra = new DijkstraShortestPath<V, E>(blocked, nev); Number dist = blockedDijkstra.getDistance(deviationVertex, endVertex); if (dist == null) continue; List<E> tail = blockedDijkstra.getPath(deviationVertex, endVertex);
/** * Returns a <code>List</code> of the edges on the shortest path from * <code>source</code> to <code>target</code>, in order of their * occurrence on this path. * If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>. */ public List<E> getPath(V source, V target) { return getPath(source,target, true); }
this.topologyBWAware.put(bw, g); topo = this.topologyBWAware.get(bw); this.sptBWAware.put(bw, new DijkstraShortestPath(g)); spt = this.sptBWAware.get(bw); NodeConnector dst = edge.getHeadNodeConnector(); if (spt == null) { spt = new DijkstraShortestPath(topo); this.sptBWAware.put(bw, spt); spt.reset(); if (bw.equals(baseBW)) { clearMaxThroughput();
public final List<List<E>> findShortestPath(final V initial, final V destination){ final List<E> shortestPath = dijkstraAlgorithm.getPath(initial, destination); initialCostMap = dijkstraAlgorithm.getDistanceMap(initial); final List<E> reversedShortestPath = reverseUpdateEdgesWeight(graph, MapTransformer.getInstance(initialCostMap), shortestPath, initial, destination); discardCommonReversedEdges(graph, shortestPath, reversedShortestPath); final List<E> unitedPaths = ListUtils.union(shortestPath, reversedShortestPath); final List<E> resultPath1 = restorePaths(shortestPath, destination, unitedPaths); final List<E> resultPath2 = restorePaths(reversedShortestPath, destination, unitedPaths); List<List<E>> result = mergePaths(resultPath1, resultPath2); if ((result == null) || (result.size() == 0)){ result = new ArrayList<>(); result.add(shortestPath); } return result; }
targets.add(target); if (spath == true) { singleSourceShortestPath(source, targets, g.getVertexCount()); } else { singleSourceMaxThroughputPath(source, targets, g.getVertexCount());
singleSourceShortestPath(source, targets, g.getVertexCount()); Map<V, E> incomingEdges = ((SourcePathData) sourceMap .get(source)).incomingEdges;
private DijkstraShortestPath<V, E> checkPath(final V startPoint, final V endPoint, final DijkstraShortestPath<V, E> reversedDijkstra) { final Number reversedDistance = reversedDijkstra.getDistance(startPoint, endPoint); if ((reversedDistance == null) || (reversedDistance.doubleValue() == Double.MAX_VALUE)){ return null; } return reversedDijkstra; }
/** * <p>Returns the last edge on a shortest path from <code>source</code> * to <code>target</code>, or null if <code>target</code> is not * reachable from <code>source</code>.</p> * * <p>If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>.</p> */ public E getIncomingEdge(V source, V target) { if (!g.containsVertex(source)) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (!g.containsVertex(target)) throw new IllegalArgumentException("Specified target vertex " + target + " is not part of graph " + g); Set<V> targets = new HashSet<V>(); targets.add(target); singleSourceShortestPath(source, targets, g.getVertexCount()); Map<V,E> incomingEdgeMap = ((SourcePathData)sourceMap.get(source)).incomingEdges; E incomingEdge = incomingEdgeMap.get(target); if (!cached) reset(source); return incomingEdge; }
public SuurballeAlgorithm(Graph<V,E> graph) { this.graph = graph; this.dijkstraAlgorithm = new DijkstraShortestPath<>(graph, defaultEdgeWeight, true); }
/** * Returns a <code>List</code> of the edges on the Max Througput Shortest * path from <code>source</code> to <code>target</code>, in order of their * their occurrence on this path. * Important - Transformer fn should return the appropriate edge weight * for this API to return the Path Correctly. * If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>. */ public List<E> getMaxThroughputPath(V source, V target) { return getPath(source,target, false); }
singleSourceShortestPath(source, targets, g.getVertexCount()); @SuppressWarnings("unchecked") Map<V,E> incomingEdges =
/** Returns the shortest path between two nodes using Dijkstra's algorithm. * * @param <V> Vertex type * @param <E> Edge type * @param graph Graph representing the network * @param nev Object responsible for returning weights for edges * @param originNodeId Origin node * @param destinationNodeId Destination node * @return Shortest path */ public static <V, E> List<E> getShortestPath(Graph<V, E> graph, Transformer<E, Double> nev, V originNodeId, V destinationNodeId) { if (!graph.containsVertex(originNodeId)) return new LinkedList<E>(); if (!graph.containsVertex(destinationNodeId)) return new LinkedList<E>(); if (nev == null) nev = getEdgeWeightTransformer(null); final DijkstraShortestPath<V, E> dsp = new DijkstraShortestPath<V, E>(graph, nev); final List<E> path = dsp.getPath(originNodeId, destinationNodeId); return path; }
singleSourceShortestPath(source, null, numDests); reset(source);
/** Default constructor. Links with cost {@code Double.MAX_VALUE} are not considered. * * @param graph Graph on which shortest paths are searched * @param nev The class responsible for returning weights for edges */ private YenAlgorithm(Graph<V, E> graph, Transformer<E, Double> nev, int K, int maxNumHops, double maxLengthInKm, double maxPropDelayInMs, double maxRouteCost, double maxRouteCostFactorRespectToShortestPath, double maxRouteCostRespectToShortestPath) { this.K = K; this.maxLengthInKm = maxLengthInKm; this.maxNumHops = maxNumHops; this.maxPropDelayInMs = maxPropDelayInMs; this.maxRouteCost = maxRouteCost; this.maxRouteCostFactorRespectToShortestPath = maxRouteCostFactorRespectToShortestPath; this.maxRouteCostRespectToShortestPath = maxRouteCostRespectToShortestPath; this.graph = graph; this.nev = nev; dijkstra = new DijkstraShortestPath<V, E>(graph, nev); }