JavaGenes, NASA Ames. Written largely by Al Globus

gov.nasa.javaGenes.graph
Class apsp

java.lang.Object
  extended bygov.nasa.javaGenes.graph.apsp

public class apsp
extends java.lang.Object

All-pairs-shortest-path algorithm and supporting functions for graphs.

See Also:
Graph

Constructor Summary
apsp()
           
 
Method Summary
static void Apsp(int[][] d)
          apsp - Floyd Warshall algorithm for computing All-Pairs Shortest Paths.
static int[][] CTabToAdjM(int[][] ct, int n)
          CTabToAdjM - Converts a connection table (CT) into an adjcency matrix.
static void PrintIMat(int[][] m)
          Print a two dimensional integer matrix
static void test(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

apsp

public apsp()
Method Detail

test

public static void test(java.lang.String[] args)

Apsp

public static void Apsp(int[][] d)
apsp - Floyd Warshall algorithm for computing All-Pairs Shortest Paths. Complexity n^3. Mem requirements n^2. Where n is the number of vertices. REF: T. H. Cormen et. al. Introduction to Algorithms, (1989) CH 26.

Parameters:
d - is a adjacency matrix. Usually this will be set up by CTabToAdjM()

CTabToAdjM

public static int[][] CTabToAdjM(int[][] ct,
                                 int n)
CTabToAdjM - Converts a connection table (CT) into an adjcency matrix. Initially all off diagonal vals are set to n+1 which is lager than the longest possible path. All diagonals are set to zero which denotes the identity, i.e. path len is zero. Then the connection table is traversed and adjacent nodes are set to one. Algo is of the order n^2 + 4n (where 4 is max connections)

Parameters:
ct - a connection table. Each row (first index) is an array containing the indices of the vertices that share edges with the vertex at the row index
n - the longest possible path in the graph (maximum is the number of vertices-1) the return value is a connectivity matrix suitable for use by apsp()

PrintIMat

public static void PrintIMat(int[][] m)
Print a two dimensional integer matrix


JavaGenes, NASA Ames. Written largely by Al Globus