/** * 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); }
/** * 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); }
/** * Returns a list of Network-Topology Links * that represents the Dijkstra's algorithm * shortest path between a source and target * OF Node. * @param source Network-Topology Node * @param target Network-Topology Node * @return links Dijkstra Shortest Path */ @Override public final List<Link> getShortestPath(NodeId source, NodeId target) { return shortestPath.getPath(source, target); }
/** * 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); }
/** * Return the packet route from the source to the destination switch. * * @param src A MD-SAL node identifier corresponding to the source * switch. * @param dst A {MD-SAL node identifier corresponding to the destination * switch. * @return A list of {@link OfMockLink} instances which represents the * packet route. * An empty list is returned if the destination node is the * same as the source. * {@code null} is returned if no route was found. */ public List<OfMockLink> getRoute(String src, String dst) { if (src.equals(dst)) { return Collections.<OfMockLink>emptyList(); } synchronized (this) { try { return resolver.getPath(src, dst); } catch (Exception e) { LOG.trace("A vertex is not yet known: {} -> {}", src, dst); } } return null; }
@Override public synchronized Path getRoute(final Node src, final Node dst, final Short Bw) { DijkstraShortestPath<Node, Edge> spt = this.sptBWAware.get(Bw); if (spt == null) { return null; } List<Edge> path; try { path = spt.getPath(src, dst); } catch (IllegalArgumentException ie) { log.debug("A vertex is yet not known between {} {}", src, dst); return null; } Path res; try { res = new Path(path); } catch (ConstructionException e) { log.debug("A vertex is yet not known between {} {}", src, dst); return null; } return res; }
/** Obtains the sequence of links representing the (unidirectional) shortest path between two nodes. * Links with cost {@code Double.MAX_VALUE} are not considered. * @param nodes Collection of nodes * @param links Collection of links * @param originNode Origin node * @param destinationNode Destination node * @param linkCostMap Cost per link, where the key is the link identifier and the value is the cost of traversing the link. No special iteration-order (i.e. ascending) is required. If <code>null</code>, the shortest path in number of traversed links is returned, * @return Sequence of links in the shortest path (empty, if destination not reachable from origin) */ public static List<Link> getShortestPath(Collection<Node> nodes, Collection<Link> links, Node originNode, Node destinationNode, Map<Link, Double> linkCostMap) { final Collection<Link> linksToUse = linkCostMap == null? links : links.stream().filter(e->linkCostMap.get(e) != Double.MAX_VALUE).collect(Collectors.toList()); final Graph<Node, Link> graph = JUNGUtils.getGraphFromLinkMap(nodes, linksToUse); if (!graph.containsVertex(originNode)) return new LinkedList<>(); if (!graph.containsVertex(destinationNode)) return new LinkedList<>(); final Transformer<Link, Double> nev = JUNGUtils.getEdgeWeightTransformer(linkCostMap); final DijkstraShortestPath<Node, Link> dsp = new DijkstraShortestPath<Node, Link>(graph, nev); final List<Link> path = dsp.getPath(originNode, destinationNode); return path; }
/** 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; }
DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph, wtTransformer); final List<String> mPred = alg.getPath(mFrom, mTo);
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; }
DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph); final List<String> mPred = alg.getPath(mFrom, mTo);
public List<TpId> shortestPathOpti(TpId srcTpId, TpId dstTpId, Topology topology, List<ConstraintMetric> constraintMetrics) { String src = srcTpId.getValue(); String dst = dstTpId.getValue(); Long minBw = (long) 0; for (ConstraintMetric eachConstraint : constraintMetrics) { if (AltoSpceMetric.Bandwidth == eachConstraint.getMetric() && eachConstraint.getMin() != null) { minBw = (minBw > eachConstraint.getMin().longValue()) ? minBw : eachConstraint.getMin().longValue(); } } Graph<String, RouteViewer.Path> networkGraph = getGraphFromTopology(topology, minBw); DijkstraShortestPath<String, RouteViewer.Path> shortestPath = new DijkstraShortestPath<>(networkGraph); List<RouteViewer.Path> path = shortestPath.getPath(extractNodeId(src), extractNodeId(dst)); List<TpId> output = new LinkedList<>(); for (RouteViewer.Path eachPath : path) { output.add(eachPath.src); } return output; }
protected List<E> reverseUpdateEdgesWeight(final Graph<V, E> graph, final Transformer<V, Number> transformer, final List<E> shortestPath, final V initial, final V destination) { for(final E edge1 : shortestPath){ V src = graph.getSource(edge1); V dst = graph.getDest(edge1); graph.removeEdge(edge1); graph.addEdge(edge1, dst, src, EdgeType.DIRECTED); } final List<E> edges = new ArrayList<>(graph.getEdges()); final Map<E, Number> map = new LinkedHashMap<>(); edges.forEach(edge -> { final V source = graph.getSource(edge); final V dest = graph.getDest(edge); Number cost = calculateCost(transformer, edge, source, dest); map.put(edge,cost); }); final DijkstraShortestPath<V, E> reversedDijkstra = new DijkstraShortestPath<>(graph, MapTransformer.getInstance(map)); DijkstraShortestPath<V, E> validatedShortestPath = checkPath(initial, destination, reversedDijkstra); return validatedShortestPath != null ? reversedDijkstra.getPath(initial, destination) : new ArrayList<>(); }
List<MyLink> list = alg.getPath(startNode, endNode);