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