com.larvalabs.starfish.algorithm
Class Algorithm

java.lang.Object
  extended bycom.larvalabs.starfish.algorithm.Algorithm
All Implemented Interfaces:
java.io.Serializable

public abstract class Algorithm
extends java.lang.Object
implements java.io.Serializable

Base class for all problems.

See Also:
Serialized Form

Constructor Summary
Algorithm()
           
 
Method Summary
 java.lang.String describeSegment(int segmentNum)
          Override this if you wish to describe specific segments
 void generateSegmentInputData(SegmentInputData segmentInputData)
          Override to generate the input data for each segment.
abstract  java.lang.String getName()
          Returns the name of this algorithm.
 void initialize(Parameters parameters)
          Override this to initialize the Algorithm for the problem described by the included parameters.
 boolean nonNullSegmentResultMeansCompleted()
          Override and return true to indicate that if your Algorithm returns a non null result from processSegment() then that indicates processing on the problem is complete and the answer has been found.
abstract  ProblemResult processResults(Uuid[] resultIds, Resources resources)
          Process the array of resultIds provided by the grid.
abstract  java.io.Serializable processSegment(int segmentNum, java.lang.Object segmentParams)
          Process one segment of the problem.
abstract  void setParameters(ParameterSet parameterSet)
          This method is called to allow the algorithm to specify its parameters.
abstract  int totalNumberOfSegments()
          Return total number of segments this Algorithm will produce to solve the Problem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Algorithm

public Algorithm()
Method Detail

setParameters

public abstract void setParameters(ParameterSet parameterSet)
This method is called to allow the algorithm to specify its parameters.

Parameters:
parameterSet -

initialize

public void initialize(Parameters parameters)
Override this to initialize the Algorithm for the problem described by the included parameters.

Parameters:
parameters -

getName

public abstract java.lang.String getName()
Returns the name of this algorithm.

Returns:

nonNullSegmentResultMeansCompleted

public boolean nonNullSegmentResultMeansCompleted()
Override and return true to indicate that if your Algorithm returns a non null result from processSegment() then that indicates processing on the problem is complete and the answer has been found. This will cause the leader to stop issuing segments from your problem and process the results.

Returns:

processSegment

public abstract java.io.Serializable processSegment(int segmentNum,
                                                    java.lang.Object segmentParams)
Process one segment of the problem.

Parameters:
segmentNum -
Returns:

describeSegment

public java.lang.String describeSegment(int segmentNum)
Override this if you wish to describe specific segments

Parameters:
segmentNum -
Returns:

totalNumberOfSegments

public abstract int totalNumberOfSegments()
Return total number of segments this Algorithm will produce to solve the Problem.

Returns:

generateSegmentInputData

public void generateSegmentInputData(SegmentInputData segmentInputData)
Override to generate the input data for each segment.


processResults

public abstract ProblemResult processResults(Uuid[] resultIds,
                                             Resources resources)
Process the array of resultIds provided by the grid.

Parameters:
resultIds - A list of UUID's for the resultIds generated by processSegment()
Returns:
the result of this problem.