Package edu.uci.ics.jung.algorithms.util
Class IterativeProcess
- java.lang.Object
-
- edu.uci.ics.jung.algorithms.util.IterativeProcess
-
- All Implemented Interfaces:
IterativeContext
- Direct Known Subclasses:
AbstractRanker,EdmondsKarpMaxFlow
public abstract class IterativeProcess extends java.lang.Object implements IterativeContext
Provides basic infrastructure for iterative algorithms. Services provided include:- storage of current and max iteration count
- framework for initialization, iterative evaluation, and finalization
- test for convergence
- etc.
Algorithms that subclass this class are typically used in the following way:
FooAlgorithm foo = new FooAlgorithm(...) foo.setMaximumIterations(100); //set up conditions ... foo.evaluate(); //key method which initiates iterative process foo.getSomeResult();
-
-
Field Summary
Fields Modifier and Type Field Description private doubledesiredPrecisionDesired precision.private intiterationsNumber of iterations performed.private intmaximumIterationsMaximum allowed number of iterations.private doubleprecisionAchieved precision.
-
Constructor Summary
Constructors Constructor Description IterativeProcess()Generic constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleandone()voidevaluate()Performs the iterative process.protected voidfinalizeIterations()Perform eventual clean-up operations (must be implement by subclass when needed).doublegetDesiredPrecision()intgetIterations()intgetMaximumIterations()doublegetPrecision()booleanhasConverged()Check to see if the result has been attained.protected voidinitializeIterations()Initializes internal parameters to start the iterative process.doublerelativePrecision(double epsilon, double x)voidreset()voidsetDesiredPrecision(double prec)voidsetMaximumIterations(int maxIter)voidsetPrecision(double precision)abstract voidstep()Evaluate the result of the current iteration.
-
-
-
Method Detail
-
evaluate
public void evaluate()
Performs the iterative process. Note: this method does not return anything because Java does not allow mixing double, int, or objects
-
step
public abstract void step()
Evaluate the result of the current iteration.- Specified by:
stepin interfaceIterativeContext
-
finalizeIterations
protected void finalizeIterations()
Perform eventual clean-up operations (must be implement by subclass when needed).
-
getDesiredPrecision
public double getDesiredPrecision()
- Returns:
- the desired precision.
-
getIterations
public int getIterations()
- Returns:
- the number of iterations performed.
-
getMaximumIterations
public int getMaximumIterations()
- Returns:
- the maximum allowed number of iterations.
-
getPrecision
public double getPrecision()
- Returns:
- the attained precision.
-
setPrecision
public void setPrecision(double precision)
- Parameters:
precision- the precision to set
-
hasConverged
public boolean hasConverged()
Check to see if the result has been attained.- Returns:
- boolean
-
done
public boolean done()
- Specified by:
donein interfaceIterativeContext- Returns:
trueif this iterative process is finished, andfalseotherwise.
-
initializeIterations
protected void initializeIterations()
Initializes internal parameters to start the iterative process.
-
reset
public void reset()
-
relativePrecision
public double relativePrecision(double epsilon, double x)- Parameters:
epsilon- doublex- double- Returns:
- double
-
setDesiredPrecision
public void setDesiredPrecision(double prec) throws java.lang.IllegalArgumentException- Parameters:
prec- the desired precision.- Throws:
java.lang.IllegalArgumentException
-
setMaximumIterations
public void setMaximumIterations(int maxIter) throws java.lang.IllegalArgumentException- Parameters:
maxIter- the maximum allowed number of iterations- Throws:
java.lang.IllegalArgumentException
-
-