Raymond | dee0849 | 2015-04-02 10:43:13 -0700 | [diff] [blame] | 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 | /** |
| 24 | * This class holds a point and the value of an objective function at this point. |
| 25 | * <p>This is a simple immutable container.</p> |
| 26 | * @see VectorialPointValuePair |
| 27 | * @see org.apache.commons.math.analysis.MultivariateRealFunction |
| 28 | * @version $Revision: 980981 $ $Date: 2010-07-31 00:03:04 +0200 (sam. 31 juil. 2010) $ |
| 29 | * @since 2.0 |
| 30 | */ |
| 31 | public class RealPointValuePair implements Serializable { |
| 32 | /** Serializable version identifier. */ |
| 33 | private static final long serialVersionUID = 1003888396256744753L; |
| 34 | |
| 35 | /** Point coordinates. */ |
| 36 | private final double[] point; |
| 37 | |
| 38 | /** 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 RealPointValuePair(final double[] point, final double value) { |
| 47 | this.point = (point == null) ? null : point.clone(); |
| 48 | this.value = value; |
| 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 array will be copied, otherwise |
| 56 | * it will be referenced |
| 57 | */ |
| 58 | public RealPointValuePair(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 = value; |
| 64 | } |
| 65 | |
| 66 | /** Get the point. |
| 67 | * @return a copy of the stored point |
| 68 | */ |
| 69 | public double[] getPoint() { |
| 70 | return (point == null) ? null : point.clone(); |
| 71 | } |
| 72 | |
| 73 | /** Get a reference to the point. |
| 74 | * <p>This method is provided as a convenience to avoid copying |
| 75 | * the array, the elements of the array should <em>not</em> be modified.</p> |
| 76 | * @return a reference to the internal array storing the point |
| 77 | */ |
| 78 | public double[] getPointRef() { |
| 79 | return point; |
| 80 | } |
| 81 | |
| 82 | /** Get the value of the objective function. |
| 83 | * @return the stored value of the objective function |
| 84 | */ |
| 85 | public double getValue() { |
| 86 | return value; |
| 87 | } |
| 88 | } |