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
19 import org.hipparchus.linear.RealMatrix;
20 import org.hipparchus.linear.RealVector;
21
22 /**
23 * Adapter class that exposes an {@link SQPProblem} objective function under the
24 * {@link TwiceDifferentiableFunction} abstraction used by SQP optimizers.
25 *
26 * <p>
27 * This wrapper delegates objective evaluations and gradient computations to
28 * the underlying {@link SQPProblem} implementation. The Hessian is currently
29 * not provided and returns {@code null}, allowing SQP solvers to supply their
30 * own Hessian approximation (e.g. via BFGS or other quasi-Newton strategies).
31 * </p>
32 *
33 * <p>
34 * Instances of this class are typically constructed internally by SQP
35 * optimizers when processing {@link org.hipparchus.optim.OptimizationData} supplied by users.
36 * </p>
37 *
38 * @since 4.1
39 */
40 public class SQPObj extends TwiceDifferentiableFunction {
41
42 /** Optimization problem providing objective and gradient information. */
43 private final SQPProblem problem;
44
45 /**
46 * Creates an adapter exposing the objective of an {@link SQPProblem}
47 * instance through the {@link TwiceDifferentiableFunction} API.
48 *
49 * @param problem SQP formulation from which objective data are obtained
50 */
51 public SQPObj(final SQPProblem problem) {
52 this.problem = problem;
53 }
54
55 /**
56 * {@inheritDoc}
57 *
58 * <p>
59 * Delegates to {@link SQPProblem#getdim()}.
60 * </p>
61 */
62 @Override
63 public int dim() {
64 return this.problem.getdim();
65 }
66
67 /**
68 * {@inheritDoc}
69 *
70 * <p>
71 * Delegates to {@link SQPProblem#getObjectiveEvaluation(RealVector)}.
72 * </p>
73 */
74 @Override
75 public double value(final RealVector rv) {
76 return this.problem.getObjectiveEvaluation(rv);
77 }
78
79 /**
80 * {@inheritDoc}
81 *
82 * <p>
83 * Delegates to {@link SQPProblem#getObjectiveGradient(RealVector)}.
84 * </p>
85 */
86 @Override
87 public RealVector gradient(final RealVector rv) {
88 return this.problem.getObjectiveGradient(rv);
89 }
90
91 /**
92 * {@inheritDoc}
93 *
94 * <p>
95 * Returns {@code null} because {@link SQPProblem} does not define
96 * second-order information. SQP methods typically compute Hessian
97 * approximations internally (e.g. BFGS, SR1, etc.).
98 * </p>
99 *
100 * @return always {@code null}
101 */
102 @Override
103 public RealMatrix hessian(final RealVector rv) {
104 return null;
105 }
106 }