001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.math.optimization;
019
020 import java.io.Serializable;
021
022
023 /**
024 * This class holds a point and the value of an objective function at this point.
025 * <p>This is a simple immutable container.</p>
026 * @see VectorialPointValuePair
027 * @see org.apache.commons.math.analysis.MultivariateRealFunction
028 * @version $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $
029 * @since 2.0
030 */
031 public class RealPointValuePair implements Serializable {
032
033 /** Serializable version identifier. */
034 private static final long serialVersionUID = 1003888396256744753L;
035
036 /** Point coordinates. */
037 private final double[] point;
038
039 /** Value of the objective function at the point. */
040 private final double value;
041
042 /** Build a point/objective function value pair.
043 * @param point point coordinates (the built instance will store
044 * a copy of the array, not the array passed as argument)
045 * @param value value of an objective function at the point
046 */
047 public RealPointValuePair(final double[] point, final double value) {
048 this.point = point.clone();
049 this.value = value;
050 }
051
052 /** Build a point/objective function value pair.
053 * @param point point coordinates (the built instance will store
054 * a copy of the array, not the array passed as argument)
055 * @param value value of an objective function at the point
056 * @param copyArray if true, the input array will be copied, otherwise
057 * it will be referenced
058 */
059 public RealPointValuePair(final double[] point, final double value,
060 final boolean copyArray) {
061 this.point = copyArray ? point.clone() : point;
062 this.value = value;
063 }
064
065 /** Get the point.
066 * @return a copy of the stored point
067 */
068 public double[] getPoint() {
069 return point.clone();
070 }
071
072 /** Get a reference to the point.
073 * <p>This method is provided as a convenience to avoid copying
074 * the array, the elements of the array should <em>not</em> be modified.</p>
075 * @return a reference to the internal array storing the point
076 */
077 public double[] getPointRef() {
078 return point;
079 }
080
081 /** Get the value of the objective function.
082 * @return the stored value of the objective function
083 */
084 public double getValue() {
085 return value;
086 }
087
088 }