/** * Creates a new instance of this class. * * @param maxIterations the maximum number of iterations * @param callBack the function to be called when the maximum number of * iterations has been reached * @throws org.apache.commons.math3.exception.NullArgumentException if {@code callBack} is {@code null} * @since 3.6 */ public IterationManager(final int maxIterations, final IntegerSequence.Incrementor.MaxCountExceededCallback callBack) { this.iterations = IntegerSequence.Incrementor.create().withMaximalCount(maxIterations).withCallback(callBack); this.listeners = new CopyOnWriteArrayList<IterationListener>(); }
evaluations = evaluations.withMaximalCount(maxEval).withStart(0); T zero = field.getZero(); T nan = zero.add(Double.NaN); evaluations.increment(); y[1] = f.value(x[1]); if (Precision.equals(y[1].getReal(), 0.0, 1)) { evaluations.increment(); y[0] = f.value(x[0]); if (Precision.equals(y[0].getReal(), 0.0, 1)) { evaluations.increment(); y[2] = f.value(x[2]); if (Precision.equals(y[2].getReal(), 0.0, 1)) { evaluations.increment(); final T nextY = f.value(nextX); if (Precision.equals(nextY.getReal(), 0.0, 1)) {
/** * Performs multiple increments. * * @param nTimes Number of increments. * @throws MaxCountExceededException at counter exhaustion. * @throws NotStrictlyPositiveException if {@code nTimes <= 0}. * * @see #increment() */ public void increment(int nTimes) throws MaxCountExceededException { if (nTimes <= 0) { throw new NotStrictlyPositiveException(nTimes); } if (!canIncrement(0)) { maxCountCallback.trigger(maximalCount); } count += nTimes * increment; }
/** * Creates a new instance with a given increment. * The counter is reset to the initial value. * * @param step Increment. * @return a new instance. */ public Incrementor withIncrement(int step) { if (step == 0) { throw new ZeroException(); } return new Incrementor(this.init, this.maximalCount, step, this.maxCountCallback); }
/** * Performs multiple increments. * * @param nTimes Number of increments. * @throws MaxCountExceededException at counter exhaustion. * @throws NotStrictlyPositiveException if {@code nTimes <= 0}. * * @see #increment() */ public void increment(int nTimes) throws MaxCountExceededException { if (nTimes <= 0) { throw new NotStrictlyPositiveException(nTimes); } if (!canIncrement(0)) { maxCountCallback.trigger(maximalCount); } count += nTimes * increment; }
/** * Creates a new instance with a given increment. * The counter is reset to the initial value. * * @param step Increment. * @return a new instance. */ public Incrementor withIncrement(int step) { if (step == 0) { throw new ZeroException(); } return new Incrementor(this.init, this.maximalCount, step, this.maxCountCallback); }
/** Prepare the start of an integration. * @param t0 start value of the independent <i>time</i> variable * @param y0 array containing the start value of the state vector * @param t target time for the integration */ protected void initIntegration(final double t0, final double[] y0, final double t) { evaluations = evaluations.withStart(0); for (final EventState state : eventsStates) { state.setExpandable(expandable); state.getEventHandler().init(t0, y0, t); } for (StepHandler handler : stepHandlers) { handler.init(t0, y0, t); } setStateInitialized(false); }
/** * Creates a new instance with a given callback. * The counter is reset to the initial value. * * @param cb Callback to be called at counter exhaustion. * @return a new instance. */ public Incrementor withCallback(MaxCountExceededCallback cb) { return new Incrementor(this.init, this.maximalCount, this.increment, cb); }
/** * Creates a new instance with a given initial value. * The counter is reset to the initial value. * * @param start Initial value of the counter. * @return a new instance. */ public Incrementor withStart(int start) { return new Incrementor(start, this.maximalCount, this.increment, this.maxCountCallback); }
/** * Creates a new instance with a given initial value. * The counter is reset to the initial value. * * @param start Initial value of the counter. * @return a new instance. */ public Incrementor withStart(int start) { return new Incrementor(start, this.maximalCount, this.increment, this.maxCountCallback); }
/** * Creates a new instance with a given maximal count. * The counter is reset to the initial value. * * @param max Maximal count. * @return a new instance. */ public Incrementor withMaximalCount(int max) { return new Incrementor(this.init, max, this.increment, this.maxCountCallback); }
/** {@inheritDoc} */ public int getMaximalIterationCount() { return count.getMaximalCount(); }
/** Build an instance. * @param field field to which the time and state vector elements belong * @param name name of the method */ protected AbstractFieldIntegrator(final Field<T> field, final String name) { this.field = field; this.name = name; stepHandlers = new ArrayList<FieldStepHandler<T>>(); stepStart = null; stepSize = null; eventsStates = new ArrayList<FieldEventState<T>>(); statesInitialized = false; evaluations = IntegerSequence.Incrementor.create().withMaximalCount(Integer.MAX_VALUE); }
/** * Creates a new instance with a given maximal count. * The counter is reset to the initial value. * * @param max Maximal count. * @return a new instance. */ public Incrementor withMaximalCount(int max) { return new Incrementor(this.init, max, this.increment, this.maxCountCallback); }
/** {@inheritDoc} */ public boolean hasNext() { return canIncrement(0); }
/** * Creates a new instance of this class. * * @param maxIterations the maximum number of iterations * @param callBack the function to be called when the maximum number of * iterations has been reached * @throws org.apache.commons.math3.exception.NullArgumentException if {@code callBack} is {@code null} * @since 3.6 */ public IterationManager(final int maxIterations, final IntegerSequence.Incrementor.MaxCountExceededCallback callBack) { this.iterations = IntegerSequence.Incrementor.create().withMaximalCount(maxIterations).withCallback(callBack); this.listeners = new CopyOnWriteArrayList<IterationListener>(); }
/** {@inheritDoc} */ public int getEvaluations() { return evaluations.getCount(); }
/** * Get the number of evaluations of the objective function. * The number of evaluations corresponds to the last call to the * {@code optimize} method. It is 0 if the method has not been * called yet. * * @return the number of evaluations of the objective function. */ public int getEvaluations() { return evaluations.getCount(); }
/** * Returns the number of iterations of this solver, 0 if no iterations has * been performed yet. * * @return the number of iterations. */ public int getIterations() { return iterations.getCount(); }
/** * Factory method that creates a default instance. * The initial and maximal values are set to 0. * For the new instance to be useful, the maximal count must be set * by calling {@link #withMaximalCount(int) withMaximalCount}. * * @return an new instance. */ public static Incrementor create() { return new Incrementor(0, 0, 1, CALLBACK); }