Class IterationManager
- java.lang.Object
-
- org.apache.commons.math4.legacy.linear.IterationManager
-
public class IterationManager extends Object
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.
-
-
Constructor Summary
Constructors Constructor Description IterationManager(int maxIterations)Creates a new instance of this class.IterationManager(int maxIterations, IntegerSequence.Incrementor.MaxCountExceededCallback callback)Creates a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIterationListener(IterationListener listener)Attaches a listener to this manager.voidfireInitializationEvent(IterationEvent e)Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.voidfireIterationPerformedEvent(IterationEvent e)Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.voidfireIterationStartedEvent(IterationEvent e)Informs all registered listeners that a new iteration (in the main iteration loop) has been started.voidfireTerminationEvent(IterationEvent e)Informs all registered listeners that the final phase (post-iterations) has been completed.intgetIterations()Returns the number of iterations of this solver, 0 if no iterations has been performed yet.intgetMaxIterations()Returns the maximum number of iterations.voidincrementIterationCount()Increments the iteration count by one, and throws an exception if the maximum number of iterations is reached.voidremoveIterationListener(IterationListener listener)Removes the specified iteration listener from the list of listeners currently attached tothisobject.voidresetIterationCount()Sets the iteration count to 0.
-
-
-
Constructor Detail
-
IterationManager
public IterationManager(int maxIterations)
Creates a new instance of this class.- Parameters:
maxIterations- Maximum number of iterations.MaxCountExceededExceptionwill be raised at counter exhaustion.
-
IterationManager
public IterationManager(int maxIterations, IntegerSequence.Incrementor.MaxCountExceededCallback callback)
Creates a new instance of this class.- Parameters:
maxIterations- the maximum number of iterationscallback- the function to be called when the maximum number of iterations has been reached. Ifnull,MaxCountExceededExceptionwill be raised at counter exhaustion.- Since:
- 3.1
-
-
Method Detail
-
addIterationListener
public void addIterationListener(IterationListener listener)
Attaches a listener to this manager.- Parameters:
listener- AIterationListenerobject.
-
fireInitializationEvent
public void fireInitializationEvent(IterationEvent e)
Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.- Parameters:
e- TheIterationEventobject.
-
fireIterationPerformedEvent
public void fireIterationPerformedEvent(IterationEvent e)
Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.- Parameters:
e- TheIterationEventobject.
-
fireIterationStartedEvent
public void fireIterationStartedEvent(IterationEvent e)
Informs all registered listeners that a new iteration (in the main iteration loop) has been started.- Parameters:
e- TheIterationEventobject.
-
fireTerminationEvent
public void fireTerminationEvent(IterationEvent e)
Informs all registered listeners that the final phase (post-iterations) has been completed.- Parameters:
e- TheIterationEventobject.
-
getIterations
public int getIterations()
Returns the number of iterations of this solver, 0 if no iterations has been performed yet.- Returns:
- the number of iterations.
-
getMaxIterations
public int getMaxIterations()
Returns the maximum number of iterations.- Returns:
- the maximum number of iterations.
-
incrementIterationCount
public void incrementIterationCount()
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.- Throws:
MaxCountExceededException- if the maximum number of iterations is reached.
-
removeIterationListener
public void removeIterationListener(IterationListener listener)
Removes the specified iteration listener from the list of listeners currently attached tothisobject. Attempting to remove a listener which was not previously registered does not cause any error.- Parameters:
listener- TheIterationListenerto be removed.
-
resetIterationCount
public void resetIterationCount()
Sets the iteration count to 0. This method must be called during the initial phase.
-
-