001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.commons.math3.optimization;
019    
020    import org.apache.commons.math3.util.Precision;
021    
022    /**
023     * Base class for all convergence checker implementations.
024     *
025     * @param <PAIR> Type of (point, value) pair.
026     *
027     * @version $Id: AbstractConvergenceChecker.java 1422230 2012-12-15 12:11:13Z erans $
028     * @deprecated As of 3.1 (to be removed in 4.0).
029     * @since 3.0
030     */
031    @Deprecated
032    public abstract class AbstractConvergenceChecker<PAIR>
033        implements ConvergenceChecker<PAIR> {
034        /**
035         * Default relative threshold.
036         * @deprecated in 3.1 (to be removed in 4.0) because this value is too small
037         * to be useful as a default (cf. MATH-798).
038         */
039        @Deprecated
040        private static final double DEFAULT_RELATIVE_THRESHOLD = 100 * Precision.EPSILON;
041        /**
042         * Default absolute threshold.
043         * @deprecated in 3.1 (to be removed in 4.0) because this value is too small
044         * to be useful as a default (cf. MATH-798).
045         */
046        @Deprecated
047        private static final double DEFAULT_ABSOLUTE_THRESHOLD = 100 * Precision.SAFE_MIN;
048        /**
049         * Relative tolerance threshold.
050         */
051        private final double relativeThreshold;
052        /**
053         * Absolute tolerance threshold.
054         */
055        private final double absoluteThreshold;
056    
057        /**
058         * Build an instance with default thresholds.
059         * @deprecated in 3.1 (to be removed in 4.0). Convergence thresholds are
060         * problem-dependent. As this class is intended for users who want to set
061         * their own convergence criterion instead of relying on an algorithm's
062         * default procedure, they should also set the thresholds appropriately
063         * (cf. MATH-798).
064         */
065        @Deprecated
066        public AbstractConvergenceChecker() {
067            this.relativeThreshold = DEFAULT_RELATIVE_THRESHOLD;
068            this.absoluteThreshold = DEFAULT_ABSOLUTE_THRESHOLD;
069        }
070    
071        /**
072         * Build an instance with a specified thresholds.
073         *
074         * @param relativeThreshold relative tolerance threshold
075         * @param absoluteThreshold absolute tolerance threshold
076         */
077        public AbstractConvergenceChecker(final double relativeThreshold,
078                                          final double absoluteThreshold) {
079            this.relativeThreshold = relativeThreshold;
080            this.absoluteThreshold = absoluteThreshold;
081        }
082    
083        /**
084         * @return the relative threshold.
085         */
086        public double getRelativeThreshold() {
087            return relativeThreshold;
088        }
089    
090        /**
091         * @return the absolute threshold.
092         */
093        public double getAbsoluteThreshold() {
094            return absoluteThreshold;
095        }
096    
097        /**
098         * {@inheritDoc}
099         */
100        public abstract boolean converged(int iteration,
101                                          PAIR previous,
102                                          PAIR current);
103    }