Package org.hipparchus.util
Class IterationManager
java.lang.Object
org.hipparchus.util.IterationManager
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
ConstructorDescriptionIterationManager
(int maxIterations) Creates a new instance of this class.IterationManager
(int maxIterations, Incrementor.MaxCountExceededCallback callBack) Creates a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIterationListener
(IterationListener listener) Attaches a listener to this manager.void
Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.void
Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.void
Informs all registered listeners that a new iteration (in the main iteration loop) has been started.void
Informs all registered listeners that the final phase (post-iterations) has been completed.int
Returns the number of iterations of this solver, 0 if no iterations has been performed yet.int
Returns the maximum number of iterations.void
Increments the iteration count by one, and throws an exception if the maximum number of iterations is reached.void
removeIterationListener
(IterationListener listener) Removes the specified iteration listener from the list of listeners currently attached tothis
object.void
Sets the iteration count to 0.
-
Constructor Details
-
IterationManager
public IterationManager(int maxIterations) Creates a new instance of this class.- Parameters:
maxIterations
- the maximum number of iterations
-
IterationManager
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- Throws:
NullArgumentException
- ifcallBack
isnull
-
-
Method Details
-
addIterationListener
Attaches a listener to this manager.- Parameters:
listener
- AIterationListener
object.
-
fireInitializationEvent
Informs all registered listeners that the initial phase (prior to the main iteration loop) has been completed.- Parameters:
e
- TheIterationEvent
object.
-
fireIterationPerformedEvent
Informs all registered listeners that a new iteration (in the main iteration loop) has been performed.- Parameters:
e
- TheIterationEvent
object.
-
fireIterationStartedEvent
Informs all registered listeners that a new iteration (in the main iteration loop) has been started.- Parameters:
e
- TheIterationEvent
object.
-
fireTerminationEvent
Informs all registered listeners that the final phase (post-iterations) has been completed.- Parameters:
e
- TheIterationEvent
object.
-
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
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:
MathIllegalStateException
- if the maximum number of iterations is reached.
-
removeIterationListener
Removes the specified iteration listener from the list of listeners currently attached tothis
object. Attempting to remove a listener which was not previously registered does not cause any error.- Parameters:
listener
- TheIterationListener
to be removed.
-
resetIterationCount
public void resetIterationCount()Sets the iteration count to 0. This method must be called during the initial phase.
-