1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.optim;
23
24 import org.hipparchus.exception.LocalizedCoreFormats;
25 import org.hipparchus.exception.MathIllegalArgumentException;
26
27
28
29
30
31
32
33
34
35
36
37 public abstract class BaseMultivariateOptimizer<P>
38 extends BaseOptimizer<P> {
39
40 private double[] start;
41
42 private double[] lowerBound;
43
44 private double[] upperBound;
45
46
47
48
49 protected BaseMultivariateOptimizer(ConvergenceChecker<P> checker) {
50 super(checker);
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64
65 @Override
66 public P optimize(OptimizationData... optData) {
67
68 return super.optimize(optData);
69 }
70
71
72
73
74
75
76
77
78
79
80
81 @Override
82 protected void parseOptimizationData(OptimizationData... optData) {
83
84 super.parseOptimizationData(optData);
85
86
87
88 for (OptimizationData data : optData) {
89 if (data instanceof InitialGuess) {
90 start = ((InitialGuess) data).getInitialGuess();
91 continue;
92 }
93 if (data instanceof SimpleBounds) {
94 final SimpleBounds bounds = (SimpleBounds) data;
95 lowerBound = bounds.getLower();
96 upperBound = bounds.getUpper();
97 continue;
98 }
99 }
100
101
102 checkParameters();
103 }
104
105
106
107
108
109
110 public double[] getStartPoint() {
111 return start == null ? null : start.clone();
112 }
113
114
115
116 public double[] getLowerBound() {
117 return lowerBound == null ? null : lowerBound.clone();
118 }
119
120
121
122 public double[] getUpperBound() {
123 return upperBound == null ? null : upperBound.clone();
124 }
125
126
127
128
129 private void checkParameters() {
130 if (start != null) {
131 final int dim = start.length;
132 if (lowerBound != null) {
133 if (lowerBound.length != dim) {
134 throw new MathIllegalArgumentException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
135 lowerBound.length, dim);
136 }
137 for (int i = 0; i < dim; i++) {
138 final double v = start[i];
139 final double lo = lowerBound[i];
140 if (v < lo) {
141 throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL,
142 v, lo);
143 }
144 }
145 }
146 if (upperBound != null) {
147 if (upperBound.length != dim) {
148 throw new MathIllegalArgumentException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
149 upperBound.length, dim);
150 }
151 for (int i = 0; i < dim; i++) {
152 final double v = start[i];
153 final double hi = upperBound[i];
154 if (v > hi) {
155 throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE,
156 v, hi);
157 }
158 }
159 }
160 }
161 }
162 }