/** * Constructs a new {@link DijkstraForCentrality} object. * * @param graph The graph. * @param stack The stack which will return nodes ordered by non-increasing * distance from startNode. */ public DijkstraForCentrality( Graph<VWCent, E> graph, Stack<VWCent> stack) { super(graph); this.stack = stack; this.pathsFromStartNode = new WeightedPathLengthData(); }
@Override public double getAverageLength() { if (getCount() == 0) { throw new IllegalStateException(SPL_ERROR); } return getTotalLength() / getCount(); } }
@Override protected void init(VWCent startNode) { super.init(startNode); stack.clear(); pathsFromStartNode.clear(); }
/** * Before relaxing the outgoing edges of u, we push it to the stack and * record its shortest path length. * * @param startNode * @param u Vertex u. * @return */ @Override protected boolean preRelaxStep(VWCent startNode, VWCent u) { // Push it to the stack. if (canPushToStack(u)) { stack.push(u); } else { throw new IllegalStateException( "Cannot push node " + u.getID() + " to the stack."); } // Record this shortest path length (for closeness). if (!u.equals(startNode)) { pathsFromStartNode.addSPLength(u.getDistance()); } // Don't stop the search. return false; }