giny.util
Class NodeDistances

java.lang.Object
  extended byginy.util.NodeDistances
All Implemented Interfaces:
MonitorableTask

public class NodeDistances
extends java.lang.Object
implements MonitorableTask

Calculates the all-pairs-shortest-paths (APSP) of a set of giny.model.Node objects that reside in a giny.model.GraphPerspective.

See Also:
IntNodeDistances

Field Summary
protected  boolean canceled
           
protected  int currentProgress
           
protected  boolean directed
           
protected  int[][] distances
           
protected  boolean done
           
static int INFINITY
           
protected  int lengthOfTask
           
protected  java.util.HashMap nodeIndexToMatrixIndexMap
           
protected  java.util.List nodesList
           
protected  GraphPerspective perspective
           
protected  java.lang.String statusMessage
           
 
Constructor Summary
NodeDistances(java.util.List nodesList, GraphPerspective perspective, java.util.HashMap nodeIndexToMatrixIndexMap)
          The main constructor
NodeDistances(java.util.List nodes_list, int[][] distances, GraphPerspective perspective)
          Deprecated. Can't use this now that GraphPerspective uses root graph indices.
NodeDistances(java.util.List nodes_list, int[][] distances, GraphPerspective perspective, boolean directed)
          Deprecated. Can't use this now that GraphPerspective uses root graph indices.
 
Method Summary
 int[][] calculate()
          Calculates the node distances.
 int getCurrentProgress()
           
 java.lang.String getCurrentStatusMessage()
           
 int[][] getDistances()
           
 int getLengthOfTask()
           
 java.lang.String getTaskDescription()
           
 boolean isDone()
           
 void start(boolean return_when_done)
          Calculates the APSP in a separate thread.
 void stop()
          Stops the task if it is currently running.
 boolean wasCanceled()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITY

public static final int INFINITY
See Also:
Constant Field Values

nodesList

protected java.util.List nodesList

perspective

protected GraphPerspective perspective

distances

protected int[][] distances

directed

protected boolean directed

currentProgress

protected int currentProgress

lengthOfTask

protected int lengthOfTask

statusMessage

protected java.lang.String statusMessage

done

protected boolean done

canceled

protected boolean canceled

nodeIndexToMatrixIndexMap

protected java.util.HashMap nodeIndexToMatrixIndexMap
Constructor Detail

NodeDistances

public NodeDistances(java.util.List nodes_list,
                     int[][] distances,
                     GraphPerspective perspective)
Deprecated. Can't use this now that GraphPerspective uses root graph indices.

Constructor, defaults to undirected graph.

Parameters:
nodes_list - a List of giny.model.Node objects for which distances will be calculated
distances - the 2 dimensional array that will hold the calculated distances (possibly null)
perspective - the giny.model.GraphPerspective in which the nodes reside

NodeDistances

public NodeDistances(java.util.List nodes_list,
                     int[][] distances,
                     GraphPerspective perspective,
                     boolean directed)
Deprecated. Can't use this now that GraphPerspective uses root graph indices.

Constructor, specifies whether a the graph should be treated as a directed graph or not.

Parameters:
nodes_list - a List of giny.model.Node objects for which distances will be calculated
distances - the 2 dimensional array that will hold the calculated distances (possibly null)
perspective - the giny.model.GraphPerspective in which the nodes reside
directed - if true, then APSP is calculated assuming a directed graph, if false an undirected graph is assumed

NodeDistances

public NodeDistances(java.util.List nodesList,
                     GraphPerspective perspective,
                     java.util.HashMap nodeIndexToMatrixIndexMap)
The main constructor

Parameters:
nodesList - List of nodes ordered by the index map
perspective - The giny.model.GraphPerspective in which the nodes reside
nodeIndexToMatrixIndexMap - An index map that maps your root graph indices to the returned matrix indices
Method Detail

getCurrentProgress

public int getCurrentProgress()
Specified by:
getCurrentProgress in interface MonitorableTask
Returns:
the current progress

getLengthOfTask

public int getLengthOfTask()
Specified by:
getLengthOfTask in interface MonitorableTask
Returns:
the total length of the task

getTaskDescription

public java.lang.String getTaskDescription()
Specified by:
getTaskDescription in interface MonitorableTask
Returns:
a String describing the task being performed

getCurrentStatusMessage

public java.lang.String getCurrentStatusMessage()
Specified by:
getCurrentStatusMessage in interface MonitorableTask
Returns:
a String status message describing what the task is currently doing (example: "Completed 23% of total.", "Initializing...", etc).

isDone

public boolean isDone()
Specified by:
isDone in interface MonitorableTask
Returns:
true if the task is done, false otherwise

stop

public void stop()
Stops the task if it is currently running.

Specified by:
stop in interface MonitorableTask

wasCanceled

public boolean wasCanceled()
Specified by:
wasCanceled in interface MonitorableTask
Returns:
true if the task was canceled before it was done (for example, by calling MonitorableSwingWorker.stop(), false otherwise

calculate

public int[][] calculate()
Calculates the node distances.

Returns:
the int[][] array of calculated distances or null if the task was canceled or there was an error

getDistances

public int[][] getDistances()
Returns:
the int[][] 2D array of calculated distances or null if not yet calculated

start

public void start(boolean return_when_done)
Calculates the APSP in a separate thread.

Specified by:
start in interface MonitorableTask
Parameters:
return_when_done - if true, then this method will return only when the task is done, else, it will return immediately after spawning the thread that performs the task