LinearBoundedConstraint.java

  1. /*
  2.  * Licensed to the Hipparchus project 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 Hipparchus project 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.  *      https://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.hipparchus.optim.nonlinear.vector.constrained;


  18. import org.hipparchus.linear.Array2DRowRealMatrix;
  19. import org.hipparchus.linear.ArrayRealVector;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.hipparchus.linear.RealVector;
  22. import org.hipparchus.optim.OptimizationData;

  23. /** A set of linear inequality constraints expressed as ub>Ax>lb.
  24.  * @since 3.1
  25.  */
  26. public class LinearBoundedConstraint extends BoundedConstraint implements OptimizationData {

  27.     /** The corresponding set of individual linear constraint functions. */
  28.     private final RealMatrix a;

  29.     /** Construct a set of linear inequality constraints from Ax < B
  30.      * @param a A matrix linear coefficient vectors
  31.      * @param lower lower bound
  32.      * @param upper upper bound
  33.      */
  34.     public LinearBoundedConstraint(final RealMatrix a, final RealVector lower, final RealVector upper) {
  35.         super(lower, upper);
  36.         this.a = a;
  37.     }

  38.     /** Construct a set of linear inequality constraints from Ax < B
  39.      * @param a A matrix linear coefficient vectors
  40.      * @param lower lower bound
  41.      * @param upper upper bound
  42.      */
  43.     public LinearBoundedConstraint(final double[][] a, final double[] lower, final double[] upper) {
  44.         this(new Array2DRowRealMatrix(a), new ArrayRealVector(lower), new ArrayRealVector(upper));
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     public double[] value(final double[] x) {
  49.         return this.a.operate(x);
  50.     }

  51.     /** {@inheritDoc} */
  52.     @Override
  53.     public int dim() {
  54.         return a.getColumnDimension();
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public RealVector value(final RealVector x) {
  59.         return a.operate(x);
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public RealMatrix jacobian(final RealVector x) {
  64.         return a.copy();
  65.     }

  66. }