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 */
017package org.apache.commons.math4.legacy.optim.nonlinear.scalar;
018
019import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
020import org.apache.commons.math4.legacy.optim.Tolerance;
021
022/**
023 * Tolerances for line search.
024 *
025 * @since 4.0
026 */
027public class LineSearchTolerance extends Tolerance {
028    /** Range. */
029    private final double initialBracketingRange;
030
031    /**
032     * @param relative Relative tolerance.
033     * @param absolute Absolute tolerance.
034     * @param range Extent of the initial interval used to find an interval
035     * that brackets the optimum.
036     * If the optimized function varies a lot in the vicinity of the optimum,
037     * it may be necessary to provide a value lower than the distance between
038     * successive local minima.
039     */
040    public LineSearchTolerance(double relative,
041                               double absolute,
042                               double range) {
043        super(relative, absolute);
044
045        if (range <= 0) {
046            throw new NotStrictlyPositiveException(range);
047        }
048
049        initialBracketingRange = range;
050    }
051
052    /** @return the initial bracketing range. */
053    public double getInitialBracketingRange() {
054        return initialBracketingRange;
055    }
056}