giny.util
Class IntNodeDistances

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

public class IntNodeDistances
extends java.lang.Object
implements MonitorableTask

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

See Also:
NodeDistances

Field Summary
protected  boolean canceled
           
protected  int currentProgress
           
protected  boolean directed
           
protected  int[][] distances
           
protected  boolean done
           
static int INFINITY
           
protected  int lengthOfTask
           
protected  int[] nodesArray
           
protected  GraphPerspective perspective
           
protected  java.lang.String statusMessage
           
 
Constructor Summary
IntNodeDistances(int[] nodes_array, int[][] distances, GraphPerspective perspective)
          Constructor, it assumes that the graph is undirected.
IntNodeDistances(int[] nodes_array, int[][] distances, GraphPerspective perspective, boolean directed)
          Constructor, specifies whether the graph should be trated as a directed graph or not.
 
Method Summary
 int[][] calculate()
          Calculates the distances.
 int getCurrentProgress()
           
 java.lang.String getCurrentStatusMessage()
           
 int[][] getDistances()
           
 int getLengthOfTask()
           
 java.lang.String getTaskDescription()
           
 boolean isDone()
           
 void start(boolean return_when_done)
          Starts doing the task in a separate thread so that the GUI stays responsive
 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

nodesArray

protected int[] nodesArray

perspective

protected GraphPerspective perspective

distances

protected int[][] distances

directed

protected boolean directed

currentProgress

protected int currentProgress

lengthOfTask

protected int lengthOfTask

done

protected boolean done

canceled

protected boolean canceled

statusMessage

protected java.lang.String statusMessage
Constructor Detail

IntNodeDistances

public IntNodeDistances(int[] nodes_array,
                        int[][] distances,
                        GraphPerspective perspective)
Constructor, it assumes that the graph is undirected.

Parameters:
nodes_array - an array of giny.model.GraphPerspective node indices for which distances will be calculated
distances - the 2D array where distances will be stored (possibly null)
perspective - the giny.model.GraphPerspective in which the nodes reside

IntNodeDistances

public IntNodeDistances(int[] nodes_array,
                        int[][] distances,
                        GraphPerspective perspective,
                        boolean directed)
Constructor, specifies whether the graph should be trated as a directed graph or not.

Parameters:
nodes_array - an array of giny.model.GraphPerspective node indices for which distances will be calculated
distances - the 2D array where distances will be stored (possibly null)
perspective - the giny.model.GraphPerspective in which the nodes reside
directed - if true, the graph is treated as a directed graph, else, it is treated as an undirected graph
Method Detail

isDone

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

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).

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 distances.

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

getDistances

public int[][] getDistances()

start

public void start(boolean return_when_done)
Starts doing the task in a separate thread so that the GUI stays responsive

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