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
18 package org.apache.commons.math.optimization;
19
20 import java.io.Serializable;
21
22 /**
23 * This class holds a point and the vectorial value of an objective function at this point.
24 * <p>This is a simple immutable container.</p>
25 * @see RealPointValuePair
26 * @see org.apache.commons.math.analysis.MultivariateVectorialFunction
27 * @version $Id: VectorialPointValuePair.java 1131229 2011-06-03 20:49:25Z luc $
28 * @since 2.0
29 */
30 public class VectorialPointValuePair implements Serializable {
31
32 /** Serializable version identifier. */
33 private static final long serialVersionUID = 1003888396256744753L;
34
35 /** Point coordinates. */
36 private final double[] point;
37
38 /** Vectorial value of the objective function at the point. */
39 private final double[] value;
40
41 /** Build a point/objective function value pair.
42 * @param point point coordinates (the built instance will store
43 * a copy of the array, not the array passed as argument)
44 * @param value value of an objective function at the point
45 */
46 public VectorialPointValuePair(final double[] point, final double[] value) {
47 this.point = (point == null) ? null : point.clone();
48 this.value = (value == null) ? null : value.clone();
49 }
50
51 /** Build a point/objective function value pair.
52 * @param point point coordinates (the built instance will store
53 * a copy of the array, not the array passed as argument)
54 * @param value value of an objective function at the point
55 * @param copyArray if true, the input arrays will be copied, otherwise
56 * they will be referenced
57 */
58 public VectorialPointValuePair(final double[] point, final double[] value,
59 final boolean copyArray) {
60 this.point = copyArray ?
61 ((point == null) ? null : point.clone()) :
62 point;
63 this.value = copyArray ?
64 ((value == null) ? null : value.clone()) :
65 value;
66 }
67
68 /** Get the point.
69 * @return a copy of the stored point
70 */
71 public double[] getPoint() {
72 return (point == null) ? null : point.clone();
73 }
74
75 /** Get a reference to the point.
76 * <p>This method is provided as a convenience to avoid copying
77 * the array, the elements of the array should <em>not</em> be modified.</p>
78 * @return a reference to the internal array storing the point
79 */
80 public double[] getPointRef() {
81 return point;
82 }
83
84 /** Get the value of the objective function.
85 * @return a copy of the stored value of the objective function
86 */
87 public double[] getValue() {
88 return (value == null) ? null : value.clone();
89 }
90
91 /** Get a reference to the value of the objective function.
92 * <p>This method is provided as a convenience to avoid copying
93 * the array, the elements of the array should <em>not</em> be modified.</p>
94 * @return a reference to the internal array storing the value of the objective function
95 */
96 public double[] getValueRef() {
97 return value;
98 }
99
100 }