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 import org.apache.commons.math.analysis.MultivariateVectorialFunction;
023
024 /**
025 * This class holds a point and the vectorial value of an objective function at this point.
026 * <p>This is a simple immutable container.</p>
027 * @see RealPointValuePair
028 * @see MultivariateVectorialFunction
029 * @version $Revision: 758049 $ $Date: 2009-03-24 18:09:34 -0400 (Tue, 24 Mar 2009) $
030 * @since 2.0
031 */
032 public class VectorialPointValuePair implements Serializable {
033
034 /** Serializable version identifier. */
035 private static final long serialVersionUID = 1003888396256744753L;
036
037 /** Point coordinates. */
038 private final double[] point;
039
040 /** Vectorial value of the objective function at the point. */
041 private final double[] value;
042
043 /** Build a point/objective function value pair.
044 * @param point point coordinates (the built instance will store
045 * a copy of the array, not the array passed as argument)
046 * @param value value of an objective function at the point
047 */
048 public VectorialPointValuePair(final double[] point, final double[] value) {
049 this.point = point.clone();
050 this.value = value.clone();
051 }
052
053 /** Build a point/objective function value pair.
054 * @param point point coordinates (the built instance will store
055 * a copy of the array, not the array passed as argument)
056 * @param value value of an objective function at the point
057 * @param copyArray if true, the input arrays will be copied, otherwise
058 * they will be referenced
059 */
060 public VectorialPointValuePair(final double[] point, final double[] value,
061 final boolean copyArray) {
062 this.point = copyArray ? point.clone() : point;
063 this.value = copyArray ? value.clone() : value;
064 }
065
066 /** Get the point.
067 * @return a copy of the stored point
068 */
069 public double[] getPoint() {
070 return point.clone();
071 }
072
073 /** Get a reference to the point.
074 * <p>This method is provided as a convenience to avoid copying
075 * the array, the elements of the array should <em>not</em> be modified.</p>
076 * @return a reference to the internal array storing the point
077 */
078 public double[] getPointRef() {
079 return point;
080 }
081
082 /** Get the value of the objective function.
083 * @return a copy of the stored value of the objective function
084 */
085 public double[] getValue() {
086 return value.clone();
087 }
088
089 /** Get a reference to the value of the objective function.
090 * <p>This method is provided as a convenience to avoid copying
091 * the array, the elements of the array should <em>not</em> be modified.</p>
092 * @return a reference to the internal array storing the value of the objective function
093 */
094 public double[] getValueRef() {
095 return value;
096 }
097
098 }