1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.optimization;
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.io.Serializable;
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This class holds a point and the vectorial value of an objective function at this point.
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>This is a simple immutable container.</p>
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @see RealPointValuePair
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @see org.apache.commons.math.analysis.MultivariateVectorialFunction
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 980981 $ $Date: 2010-07-31 00:03:04 +0200 (sam. 31 juil. 2010) $
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @since 2.0
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class VectorialPointValuePair implements Serializable {
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Serializable version identifier. */
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private static final long serialVersionUID = 1003888396256744753L;
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Point coordinates. */
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final double[] point;
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Vectorial value of the objective function at the point. */
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final double[] value;
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Build a point/objective function value pair.
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param point point coordinates (the built instance will store
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * a copy of the array, not the array passed as argument)
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value value of an objective function at the point
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public VectorialPointValuePair(final double[] point, final double[] value) {
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.point = (point == null) ? null : point.clone();
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.value = (value == null) ? null : value.clone();
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Build a point/objective function value pair.
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param point point coordinates (the built instance will store
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * a copy of the array, not the array passed as argument)
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value value of an objective function at the point
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param copyArray if true, the input arrays will be copied, otherwise
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * they will be referenced
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public VectorialPointValuePair(final double[] point, final double[] value,
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                                   final boolean copyArray) {
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.point = copyArray ?
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      ((point == null) ? null : point.clone()) :
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      point;
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.value = copyArray ?
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      ((value == null) ? null : value.clone()) :
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                      value;
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get the point.
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a copy of the stored point
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getPoint() {
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return (point == null) ? null : point.clone();
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get a reference to the point.
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>This method is provided as a convenience to avoid copying
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * the array, the elements of the array should <em>not</em> be modified.</p>
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a reference to the internal array storing the point
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getPointRef() {
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return point;
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get the value of the objective function.
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a copy of the stored value of the objective function
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getValue() {
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return (value == null) ? null : value.clone();
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get a reference to the value of the objective function.
92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>This method is provided as a convenience to avoid copying
93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * the array, the elements of the array should <em>not</em> be modified.</p>
94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a reference to the internal array storing the value of the objective function
95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public double[] getValueRef() {
97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return value;
98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
101