PointVectorValuePair.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.math4.legacy.optim;

  18. import org.apache.commons.math4.legacy.core.Pair;

  19. /**
  20.  * This class holds a point and the vectorial value of an objective function at
  21.  * that point.
  22.  *
  23.  * @see PointValuePair
  24.  * @see org.apache.commons.math4.legacy.analysis.MultivariateVectorFunction
  25.  * @since 3.0
  26.  */
  27. public class PointVectorValuePair extends Pair<double[], double[]> {
  28.     /**
  29.      * Builds a point/objective function value pair.
  30.      *
  31.      * @param point Point coordinates. This instance will store
  32.      * a copy of the array, not the array passed as argument.
  33.      * @param value Value of the objective function at the point.
  34.      */
  35.     public PointVectorValuePair(final double[] point,
  36.                                 final double[] value) {
  37.         this(point, value, true);
  38.     }

  39.     /**
  40.      * Build a point/objective function value pair.
  41.      *
  42.      * @param point Point coordinates.
  43.      * @param value Value of the objective function at the point.
  44.      * @param copyArray if {@code true}, the input arrays will be copied,
  45.      * otherwise they will be referenced.
  46.      */
  47.     public PointVectorValuePair(final double[] point,
  48.                                 final double[] value,
  49.                                 final boolean copyArray) {
  50.         super(copyArray ?
  51.               ((point == null) ? null :
  52.                point.clone()) :
  53.               point,
  54.               copyArray ?
  55.               ((value == null) ? null :
  56.                value.clone()) :
  57.               value);
  58.     }

  59.     /**
  60.      * Gets the point.
  61.      *
  62.      * @return a copy of the stored point.
  63.      */
  64.     public double[] getPoint() {
  65.         final double[] p = getKey();
  66.         return p == null ? null : p.clone();
  67.     }

  68.     /**
  69.      * Gets a reference to the point.
  70.      *
  71.      * @return a reference to the internal array storing the point.
  72.      */
  73.     public double[] getPointRef() {
  74.         return getKey();
  75.     }

  76.     /**
  77.      * Gets the value of the objective function.
  78.      *
  79.      * @return a copy of the stored value of the objective function.
  80.      */
  81.     @Override
  82.     public double[] getValue() {
  83.         final double[] v = super.getValue();
  84.         return v == null ? null : v.clone();
  85.     }

  86.     /**
  87.      * Gets a reference to the value of the objective function.
  88.      *
  89.      * @return a reference to the internal array storing the value of
  90.      * the objective function.
  91.      */
  92.     public double[] getValueRef() {
  93.         return super.getValue();
  94.     }
  95. }