View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.optim.univariate;
23  
24  import org.hipparchus.exception.LocalizedCoreFormats;
25  import org.hipparchus.exception.MathIllegalArgumentException;
26  import org.hipparchus.optim.OptimizationData;
27  import org.hipparchus.util.MathUtils;
28  
29  /**
30   * Search interval and (optional) start value.
31   * <br>
32   * Immutable class.
33   *
34   */
35  public class SearchInterval implements OptimizationData {
36      /** Lower bound. */
37      private final double lower;
38      /** Upper bound. */
39      private final double upper;
40      /** Start value. */
41      private final double start;
42  
43      /** Simple constructor.
44       * @param lo Lower bound.
45       * @param hi Upper bound.
46       * @param init Start value.
47       * @throws MathIllegalArgumentException if {@code lo >= hi}.
48       * @throws MathIllegalArgumentException if {@code init < lo} or {@code init > hi}.
49       */
50      public SearchInterval(double lo,
51                            double hi,
52                            double init) {
53          if (lo >= hi) {
54              throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
55                                                     lo, hi);
56          }
57  
58          MathUtils.checkRangeInclusive(init, lo, hi);
59  
60          lower = lo;
61          upper = hi;
62          start = init;
63      }
64  
65      /** Simple constructor.
66       * @param lo Lower bound.
67       * @param hi Upper bound.
68       * @throws MathIllegalArgumentException if {@code lo >= hi}.
69       */
70      public SearchInterval(double lo,
71                            double hi) {
72          this(lo, hi, 0.5 * (lo + hi));
73      }
74  
75      /**
76       * Gets the lower bound.
77       *
78       * @return the lower bound.
79       */
80      public double getMin() {
81          return lower;
82      }
83      /**
84       * Gets the upper bound.
85       *
86       * @return the upper bound.
87       */
88      public double getMax() {
89          return upper;
90      }
91      /**
92       * Gets the start value.
93       *
94       * @return the start value.
95       */
96      public double getStartValue() {
97          return start;
98      }
99  }