/** 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); }
public SuurballeAlgorithm(Graph<V,E> graph) { this.graph = graph; this.dijkstraAlgorithm = new DijkstraShortestPath<>(graph, defaultEdgeWeight, true); }
/** 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); }
/** 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 */ YenAlgorithm(Graph<V, E> graph, Transformer<E, Double> nev) { this.K = -1; this.maxLengthInKm = -1; this.maxNumHops = -1; this.maxPropDelayInMs = -1; this.maxRouteCost = -1; this.maxRouteCostFactorRespectToShortestPath = -1; this.maxRouteCostRespectToShortestPath = -1; this.graph = graph; this.nev = nev; dijkstra = new DijkstraShortestPath<V, E>(graph, nev); }
/** * 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); }
public NetworkGraphManager() { networkGraph = new DirectedSparseMultigraph<>(); shortestPath = new DijkstraShortestPath<>(networkGraph); observers = new ArrayList<>(); }
/** * Construct a new instance. * * @param nsv A {@link NotificationService} service instance. */ public RoutingTable(NotificationService nsv) { try { registration.set(nsv.registerNotificationListener(this)); } catch (Exception e) { String msg = "Failed to register VTN topology listener."; LOG.error(msg, e); throw new IllegalStateException(msg, e); } resolver = new DijkstraShortestPath<String, OfMockLink>(this); }
/** * Function called by the dependency manager when all the required * dependencies are satisfied * */ @SuppressWarnings("unchecked") public void init() { log.debug("Routing init() is called"); this.topologyBWAware = new ConcurrentHashMap<Short, Graph<Node, Edge>>(); this.sptBWAware = new ConcurrentHashMap<Short, DijkstraShortestPath<Node, Edge>>(); // Now create the default topology, which doesn't consider the // BW, also create the corresponding Dijkstra calculation Graph<Node, Edge> g = new SparseMultigraph(); Short sZero = Short.valueOf((short) 0); this.topologyBWAware.put(sZero, g); this.sptBWAware.put(sZero, new DijkstraShortestPath(g)); // Topologies for other BW will be added on a needed base }
return; mtp = new DijkstraShortestPath<Node, Edge>(g, mtTransformer);
/** 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 String mTo = (String) JOptionPane.showInputDialog(frame, "Choose B Node", "B Node", JOptionPane.PLAIN_MESSAGE, null, test, test[0]); final Graph<String, String> mGraph = viewerPanel.getCurrentGraph(); DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph);
blockedDijkstra = new DijkstraShortestPath<V, E>(blocked, nev);
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<>(); }
DijkstraShortestPath<V, E> revDijkstra = new DijkstraShortestPath<V, E>(revG, lengthTrans, cached);
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);
alg = new DijkstraShortestPath<>(g, wtTransformer); } else { alg = new DijkstraShortestPath<>(g);