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