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 018package org.apache.commons.math3.optimization; 019 020import java.io.Serializable; 021 022import org.apache.commons.math3.util.Pair; 023 024/** 025 * This class holds a point and the value of an objective function at 026 * that point. 027 * 028 * @see PointVectorValuePair 029 * @see org.apache.commons.math3.analysis.MultivariateFunction 030 * @deprecated As of 3.1 (to be removed in 4.0). 031 * @since 3.0 032 */ 033@Deprecated 034public class PointValuePair extends Pair<double[], Double> implements Serializable { 035 036 /** Serializable UID. */ 037 private static final long serialVersionUID = 20120513L; 038 039 /** 040 * Builds a point/objective function value pair. 041 * 042 * @param point Point coordinates. This instance will store 043 * a copy of the array, not the array passed as argument. 044 * @param value Value of the objective function at the point. 045 */ 046 public PointValuePair(final double[] point, 047 final double value) { 048 this(point, value, true); 049 } 050 051 /** 052 * Builds a point/objective function value pair. 053 * 054 * @param point Point coordinates. 055 * @param value Value of the objective function at the point. 056 * @param copyArray if {@code true}, the input array will be copied, 057 * otherwise it will be referenced. 058 */ 059 public PointValuePair(final double[] point, 060 final double value, 061 final boolean copyArray) { 062 super(copyArray ? ((point == null) ? null : 063 point.clone()) : 064 point, 065 value); 066 } 067 068 /** 069 * Gets the point. 070 * 071 * @return a copy of the stored point. 072 */ 073 public double[] getPoint() { 074 final double[] p = getKey(); 075 return p == null ? null : p.clone(); 076 } 077 078 /** 079 * Gets a reference to the point. 080 * 081 * @return a reference to the internal array storing the point. 082 */ 083 public double[] getPointRef() { 084 return getKey(); 085 } 086 087 /** 088 * Replace the instance with a data transfer object for serialization. 089 * @return data transfer object that will be serialized 090 */ 091 private Object writeReplace() { 092 return new DataTransferObject(getKey(), getValue()); 093 } 094 095 /** Internal class used only for serialization. */ 096 private static class DataTransferObject implements Serializable { 097 /** Serializable UID. */ 098 private static final long serialVersionUID = 20120513L; 099 /** 100 * Point coordinates. 101 * @Serial 102 */ 103 private final double[] point; 104 /** 105 * Value of the objective function at the point. 106 * @Serial 107 */ 108 private final double value; 109 110 /** Simple constructor. 111 * @param point Point coordinates. 112 * @param value Value of the objective function at the point. 113 */ 114 DataTransferObject(final double[] point, final double value) { 115 this.point = point.clone(); 116 this.value = value; 117 } 118 119 /** Replace the deserialized data transfer object with a {@link PointValuePair}. 120 * @return replacement {@link PointValuePair} 121 */ 122 private Object readResolve() { 123 return new PointValuePair(point, value, false); 124 } 125 126 } 127 128}