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    *      http://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  package org.apache.commons.math4.legacy.optim;
18  
19  import org.apache.commons.math4.legacy.core.Pair;
20  
21  /**
22   * This class holds a point and the vectorial value of an objective function at
23   * that point.
24   *
25   * @see PointValuePair
26   * @see org.apache.commons.math4.legacy.analysis.MultivariateVectorFunction
27   * @since 3.0
28   */
29  public class PointVectorValuePair extends Pair<double[], double[]> {
30      /**
31       * Builds a point/objective function value pair.
32       *
33       * @param point Point coordinates. This instance will store
34       * a copy of the array, not the array passed as argument.
35       * @param value Value of the objective function at the point.
36       */
37      public PointVectorValuePair(final double[] point,
38                                  final double[] value) {
39          this(point, value, true);
40      }
41  
42      /**
43       * Build a point/objective function value pair.
44       *
45       * @param point Point coordinates.
46       * @param value Value of the objective function at the point.
47       * @param copyArray if {@code true}, the input arrays will be copied,
48       * otherwise they will be referenced.
49       */
50      public PointVectorValuePair(final double[] point,
51                                  final double[] value,
52                                  final boolean copyArray) {
53          super(copyArray ?
54                ((point == null) ? null :
55                 point.clone()) :
56                point,
57                copyArray ?
58                ((value == null) ? null :
59                 value.clone()) :
60                value);
61      }
62  
63      /**
64       * Gets the point.
65       *
66       * @return a copy of the stored point.
67       */
68      public double[] getPoint() {
69          final double[] p = getKey();
70          return p == null ? null : p.clone();
71      }
72  
73      /**
74       * Gets a reference to the point.
75       *
76       * @return a reference to the internal array storing the point.
77       */
78      public double[] getPointRef() {
79          return getKey();
80      }
81  
82      /**
83       * Gets the value of the objective function.
84       *
85       * @return a copy of the stored value of the objective function.
86       */
87      @Override
88      public double[] getValue() {
89          final double[] v = super.getValue();
90          return v == null ? null : v.clone();
91      }
92  
93      /**
94       * Gets a reference to the value of the objective function.
95       *
96       * @return a reference to the internal array storing the value of
97       * the objective function.
98       */
99      public double[] getValueRef() {
100         return super.getValue();
101     }
102 }