org.omegahat.Numerics.Optimizers
Class IterationCounter

java.lang.Object
  |
  +--org.omegahat.Numerics.Optimizers.IterationCounter
All Implemented Interfaces:
CounterListener, java.util.EventListener, IterationListener

public class IterationCounter
extends java.lang.Object
implements CounterListener

A basic, class for counter listeners.

This implements the count and the maximum value. Its continueIteration method adds one to the count and sets the state of the optimizer iterator to OptimizerIterator.TOO_MANY_STEPS if the maximum is exceeded.

Objects from this class provide standard control for optimizers. Extensions of the class can modify continueIteration, either to count something different (e.g., to use the number of function calls, recorded by the evaluator), or to do something different on overflow, such as modifying some part of the optimizer's strategy.


Field Summary
protected  int count
          The current count.
protected  int max
          The maximum count.
 
Constructor Summary
IterationCounter()
          Create a counter with a default maximum (1000).
IterationCounter(int max)
          Create a counter with a chosen maximum.
 
Method Summary
 boolean continueIteration(IterationEvent ev)
          The method called after each step in the iteration is peformed.
 int getCount()
          Accessor for count field
 int getMax()
          Accessor for max field
 int setCount(int value)
          Accessor for setting count field.
 int setMax(int value)
          Accessor for setting max field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

protected int max
The maximum count. Set it to -1 to simulate infinity.

count

protected int count
The current count. Initialized to 0.
Constructor Detail

IterationCounter

public IterationCounter(int max)
Create a counter with a chosen maximum.

IterationCounter

public IterationCounter()
Create a counter with a default maximum (1000).
Method Detail

getMax

public int getMax()
Accessor for max field
Specified by:
getMax in interface CounterListener

setMax

public int setMax(int value)
Accessor for setting max field
Specified by:
setMax in interface CounterListener

getCount

public int getCount()
Accessor for count field
Specified by:
getCount in interface CounterListener

setCount

public int setCount(int value)
Accessor for setting count field.

Note that this does not throw an exception, even if the value exceeds the current max.

Specified by:
setCount in interface CounterListener

continueIteration

public boolean continueIteration(IterationEvent ev)
The method called after each step in the iteration is peformed.

Increments the count, and sets the optimizer's state to OptimizerIterator.TOO_MANY_STEPS if the max is not negative and count exceeds the max.

Specified by:
continueIteration in interface IterationListener