View Javadoc
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.Array2DRowRealMatrix;
20  import org.hipparchus.linear.ArrayRealVector;
21  import org.hipparchus.linear.MatrixUtils;
22  import org.hipparchus.linear.RealMatrix;
23  import org.hipparchus.linear.RealVector;
24  
25  public class HockSchittkowskiConstraintEquality71 extends EqualityConstraint {
26  
27      public HockSchittkowskiConstraintEquality71() {
28          super(MatrixUtils.createRealVector(new double[] { 40.0  }));
29      }
30  
31      @Override
32      public RealVector value(RealVector x) {
33          double x1 = x.getEntry(0);
34          double x2 = x.getEntry(1);
35          double x3 = x.getEntry(2);
36          double x4 = x.getEntry(3);
37  
38          RealVector a=new ArrayRealVector(1);
39          a.setEntry(0,x1*x1+x2*x2+x3*x3+x4*x4);
40  
41  
42          return a;
43      }
44  
45      @Override
46      public RealMatrix jacobian(RealVector x) {
47          double x1 = x.getEntry(0);
48          double x2 = x.getEntry(1);
49          double x3 = x.getEntry(2);
50          double x4 = x.getEntry(3);
51          RealMatrix a= new Array2DRowRealMatrix(1,4);
52  
53          a.setEntry(0,0,2.0*x1);
54          a.setEntry(0,1,2.0*x2);
55          a.setEntry(0,2,2.0*x3);
56          a.setEntry(0,3,2.0*x4);
57  
58          return a;
59      }
60  
61      @Override
62      public int dim() {
63          return 4;
64      }
65  }