// Textbook fragment 13.15 /* Dijkstra's algorithm for the single-source shortest path problem * in an undirected graph whose edges have non-negative integer weights. */ public class Dijkstra { /** Infinity value. */ protected static final Integer INFINITE = Integer.MAX_VALUE; /** Input graph. */ protected Graph graph; /** Decoration key for edge weights */ protected Object WEIGHT; /** Decoration key for vertex distances */ protected Object DIST = new Object(); /** Decoration key for entries in the priority queue */ protected Object ENTRY = new Object(); /** Auxiliary priority queue. */ protected AdaptablePriorityQueue> Q; /** Executes Dijkstra's algorithm. * @param g Input graph * @param s Source vertex * @param w Weight decoration object */ public void execute(Graph g, Vertex s, Object w) { graph = g; WEIGHT = w; DefaultComparator dc = new DefaultComparator(); Q = new HeapAdaptablePriorityQueue>(dc); dijkstraVisit(s); } /** Get the distance of a vertex from the source vertex. * @param u Start vertex for the shortest path tree */ public int getDist(Vertex u) { return (Integer) u.get(DIST); }