public class BellmanFord
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.HashMap<Actor,java.lang.String> |
distances
Distances of different actors from the source
|
private java.util.HashMap<Channel,java.lang.String> |
edgeQuantities
Weight for each channel
|
private Graph |
graph
Graph under analysis
|
private int |
MAX_DISTANCE
Maximum distance in the graph.
|
private java.util.HashMap<Actor,Actor> |
predecessors
Predecessor of an actor.
|
Constructor and Description |
---|
BellmanFord(Graph inputGraph,
java.util.HashMap<Channel,java.lang.String> edgQty)
Initialize Bellman-Ford algorithm object.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkForNegativeWeightCycles()
Check for Negative weight cycles.
|
private java.util.Stack<Actor> |
getPath(Actor srcActr,
Actor dstActr)
Get the path between two actors.
|
private boolean |
hasPath(Actor srcActr,
Actor dstActr)
Check if path exists between two actors
|
private void |
initializeGraph(Actor srcActor,
boolean longestPath)
Initialize the edge quantities and distances between actors.
|
void |
printSolutions(Actor srcActr)
Print final solutions.
|
private void |
relaxEdges()
Relax all the edges
|
java.util.Stack<Actor> |
searchPath(Actor srcActr,
Actor dstActr,
boolean longestPath)
Search for a shortest or longest path between two actors.
|
private Graph graph
private java.util.HashMap<Actor,java.lang.String> distances
private java.util.HashMap<Channel,java.lang.String> edgeQuantities
private final int MAX_DISTANCE
private void initializeGraph(Actor srcActor, boolean longestPath)
srcActor
- Starting actorlongestPath
- longest(=true) / shortest(=false) path to calculateprivate void relaxEdges()
private void checkForNegativeWeightCycles()
public void printSolutions(Actor srcActr)
srcActr
- starting actor.private boolean hasPath(Actor srcActr, Actor dstActr)
srcActr
- starting actor of the pathdstActr
- ending actor of the pathprivate java.util.Stack<Actor> getPath(Actor srcActr, Actor dstActr)
srcActr
- starting actor of the pathdstActr
- ending actor of the pathpublic java.util.Stack<Actor> searchPath(Actor srcActr, Actor dstActr, boolean longestPath)
srcActr
- Starting actor of the pathdstActr
- Ending actor of the pathlongestPath
- true to calculate longest path, false to calculate shortest