Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* #%L
* JavaUtil
* %%
* Copyright (C) 2012 - 2013 Emory University
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.protempa.graph;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* An implementation of the Bellman-Ford single-source shortest paths algorithm.
* The implementation can look for the shortest paths from a source or to a
* destination. It runs in O(n^2) time, where n is the number of vertices in the
* graph.
*
* @author Andrew Post
*/
public final class BellmanFord {
/**
* For setting whether the Bellman-Ford algorithm should look for the
* shortest paths from a source or to a destination.
*
* @author Andrew Post
*/
public static enum Mode {
SOURCE, DESTINATION
}
/**
* Constructor for BellmanFord (private).
*/
private BellmanFord() {
}
/**
* Calculates the distance of every object in a graph from a source object.
* It calls hasNegativeCycles(), and if no negative cycles
* are found, returns the shortest distances.
*
* @param sourceOrDest
* a vertex.
* @return a newly created Map of objects and their distances
* from the source object, or null if a negative
* cycle was encountered.
*/
public static Map, Weight> calcShortestDistances(
Object sourceOrDest, DirectedGraph g, Mode mode) {
Map