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;
23  
24  import java.util.Arrays;
25  
26  /**
27   * Simple optimization constraints: lower and upper bounds.
28   * The valid range of the parameters is an interval that can be infinite
29   * (in one or both directions).
30   * <br>
31   * Immutable class.
32   *
33   */
34  public class SimpleBounds implements OptimizationData {
35      /** Lower bounds. */
36      private final double[] lower;
37      /** Upper bounds. */
38      private final double[] upper;
39  
40      /** Simple constructor.
41       * @param lB Lower bounds.
42       * @param uB Upper bounds.
43       */
44      public SimpleBounds(double[] lB,
45                          double[] uB) {
46          lower = lB.clone();
47          upper = uB.clone();
48      }
49  
50      /**
51       * Gets the lower bounds.
52       *
53       * @return the lower bounds.
54       */
55      public double[] getLower() {
56          return lower.clone();
57      }
58      /**
59       * Gets the upper bounds.
60       *
61       * @return the upper bounds.
62       */
63      public double[] getUpper() {
64          return upper.clone();
65      }
66  
67      /**
68       * Factory method that creates instance of this class that represents
69       * unbounded ranges.
70       *
71       * @param dim Number of parameters.
72       * @return a new instance suitable for passing to an optimizer that
73       * requires bounds specification.
74       */
75      public static SimpleBounds unbounded(int dim) {
76          final double[] lB = new double[dim];
77          Arrays.fill(lB, Double.NEGATIVE_INFINITY);
78          final double[] uB = new double[dim];
79          Arrays.fill(uB, Double.POSITIVE_INFINITY);
80  
81          return new SimpleBounds(lB, uB);
82      }
83  }