Top Description Fields Constructors Methods
org.apache.commons.math3.util

public Class IterationManager

extends Object
Class Inheritance
Imports
java.util.Collection, java.util.concurrent.CopyOnWriteArrayList, org.apache.commons.math3.exception.MaxCountExceededException

This abstract class provides a general framework for managing iterative algorithms. The maximum number of iterations can be set, and methods are provided to monitor the current iteration count. A lightweight event framework is also provided.

Field Summary

Modifier and TypeField and Description
private IntegerSequence.Incrementor
iterations

Keeps a count of the number of iterations.

private final Collection<IterationListener>
listeners

The collection of all listeners attached to this iterative algorithm.

Constructor Summary

AccessConstructor and Description
public
IterationManager(final int
the maximum number of iterations
maxIterations
)

Creates a new instance of this class.

public
IterationManager(final int
the maximum number of iterations
maxIterations
,
final Incrementor.MaxCountExceededCallback
the function to be called when the maximum number of iterations has been reached
callBack
)

Creates a new instance of this class.

public
IterationManager(final int
the maximum number of iterations
maxIterations
,
final IntegerSequence.Incrementor.MaxCountExceededCallback
the function to be called when the maximum number of iterations has been reached
callBack
)

Creates a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
public void
addIterationListener(final IterationListener
A IterationListener object.
listener
)

Attaches a listener to this manager.

public void
fireInitializationEvent(final IterationEvent
The IterationEvent object.
e
)

Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.

public void
fireIterationPerformedEvent(final IterationEvent
The IterationEvent object.
e
)

Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.

public void
fireIterationStartedEvent(final IterationEvent
The IterationEvent object.
e
)

Informs all registered listeners that a new iteration (in the main iteration loop) has been started.

public void
fireTerminationEvent(final IterationEvent
The IterationEvent object.
e
)

Informs all registered listeners that the final phase (post-iterations) has been completed.

public int

Returns:

the number of iterations.
getIterations
()

Returns the number of iterations of this solver, 0 if no iterations has been performed yet.

public int

Returns:

the maximum number of iterations.
getMaxIterations
()

Returns the maximum number of iterations.

public void
incrementIterationCount()

Increments the iteration count by one, and throws an exception if the maximum number of iterations is reached.

public void
removeIterationListener(final IterationListener
The IterationListener to be removed.
listener
)

Removes the specified iteration listener from the list of listeners currently attached to this object.

public void
resetIterationCount()

Sets the iteration count to 0.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iterationsback to summary
private IntegerSequence.Incrementor iterations

Keeps a count of the number of iterations.

listenersback to summary
private final Collection<IterationListener> listeners

The collection of all listeners attached to this iterative algorithm.

Constructor Detail

IterationManagerback to summary
public IterationManager(final int maxIterations)

Creates a new instance of this class.

Parameters
maxIterations:int

the maximum number of iterations

IterationManagerback to summary
public IterationManager(final int maxIterations, final Incrementor.MaxCountExceededCallback callBack)

Creates a new instance of this class.

Parameters
maxIterations:int

the maximum number of iterations

callBack:Incrementor.MaxCountExceededCallback

the function to be called when the maximum number of iterations has been reached

Annotations
@Deprecated
Exceptions
NullArgumentException:
if callBack is null
Since
3.1
IterationManagerback to summary
public IterationManager(final int maxIterations, final IntegerSequence.Incrementor.MaxCountExceededCallback callBack)

Creates a new instance of this class.

Parameters
maxIterations:int

the maximum number of iterations

callBack:IntegerSequence.Incrementor.MaxCountExceededCallback

the function to be called when the maximum number of iterations has been reached

Exceptions
NullArgumentException:
if callBack is null
Since
3.6

Method Detail

addIterationListenerback to summary
public void addIterationListener(final IterationListener listener)

Attaches a listener to this manager.

Parameters
listener:IterationListener

A IterationListener object.

fireInitializationEventback to summary
public void fireInitializationEvent(final IterationEvent e)

Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.

Parameters
e:IterationEvent

The IterationEvent object.

fireIterationPerformedEventback to summary
public void fireIterationPerformedEvent(final IterationEvent e)

Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.

Parameters
e:IterationEvent

The IterationEvent object.

fireIterationStartedEventback to summary
public void fireIterationStartedEvent(final IterationEvent e)

Informs all registered listeners that a new iteration (in the main iteration loop) has been started.

Parameters
e:IterationEvent

The IterationEvent object.

fireTerminationEventback to summary
public void fireTerminationEvent(final IterationEvent e)

Informs all registered listeners that the final phase (post-iterations) has been completed.

Parameters
e:IterationEvent

The IterationEvent object.

getIterationsback to summary
public int getIterations()

Returns the number of iterations of this solver, 0 if no iterations has been performed yet.

Returns:int

the number of iterations.

getMaxIterationsback to summary
public int getMaxIterations()

Returns the maximum number of iterations.

Returns:int

the maximum number of iterations.

incrementIterationCountback to summary
public void incrementIterationCount() throws MaxCountExceededException

Increments the iteration count by one, and throws an exception if the maximum number of iterations is reached. This method should be called at the beginning of a new iteration.

Exceptions
MaxCountExceededException:
if the maximum number of iterations is reached.
removeIterationListenerback to summary
public void removeIterationListener(final IterationListener listener)

Removes the specified iteration listener from the list of listeners currently attached to this object. Attempting to remove a listener which was not previously registered does not cause any error.

Parameters
listener:IterationListener

The IterationListener to be removed.

resetIterationCountback to summary
public void resetIterationCount()

Sets the iteration count to 0. This method must be called during the initial phase.