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 $Id: RealPointValuePair.java 1131229 2011-06-03 20:49:25Z luc $
029 * @since 2.0
030 */
031 public class RealPointValuePair implements Serializable {
032 /** Serializable version identifier. */
033 private static final long serialVersionUID = 1003888396256744753L;
034 /** Point coordinates. */
035 private final double[] point;
036 /** Value of the objective function at the point. */
037 private final double value;
038
039 /** Build a point/objective function value pair.
040 * @param point point coordinates (the built instance will store
041 * a copy of the array, not the array passed as argument)
042 * @param value value of an objective function at the point
043 */
044 public RealPointValuePair(final double[] point, final double value) {
045 this.point = (point == null) ? null : point.clone();
046 this.value = value;
047 }
048
049 /** Build a point/objective function value pair.
050 * @param point point coordinates (the built instance will store
051 * a copy of the array, not the array passed as argument)
052 * @param value value of an objective function at the point
053 * @param copyArray if true, the input array will be copied, otherwise
054 * it will be referenced
055 */
056 public RealPointValuePair(final double[] point, final double value,
057 final boolean copyArray) {
058 this.point = copyArray ?
059 ((point == null) ? null : point.clone()) :
060 point;
061 this.value = value;
062 }
063
064 /** Get the point.
065 * @return a copy of the stored point
066 */
067 public double[] getPoint() {
068 return (point == null) ? null : point.clone();
069 }
070
071 /** Get a reference to the point.
072 * <p>This method is provided as a convenience to avoid copying
073 * the array, the elements of the array should <em>not</em> be modified.</p>
074 * @return a reference to the internal array storing the point
075 */
076 public double[] getPointRef() {
077 return point;
078 }
079
080 /** Get the value of the objective function.
081 * @return the stored value of the objective function
082 */
083 public double getValue() {
084 return value;
085 }
086 }