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.optim.OptimizationData;
20 import org.hipparchus.util.Precision;
21
22 /** Parameter for SQP Algorithm.
23 * @since 3.1
24 */
25 public class SQPOption implements OptimizationData {
26
27 /** Default convergence criteria.
28 * @deprecated as of 4.1, only used by deprecated {@link SQPOptimizerS} and {@link SQPOptimizerGM}; will be removed in 5.0
29 */
30 @Deprecated
31 public static final int DEFAULT_CONV_CRITERIA = 1;
32
33 /** Default tolerance for convergence and active constraint(proportional to sqrt of function an constraints evaluation accuracy) */
34 public static final double DEFAULT_EPSILON = 1.0e-7;//>0
35
36 /** Default tolerance for QP convergence(proportional to function and constraints evaluation accuracy) */
37 public static final double DEFAULT_EPSILON_QP = Precision.EPSILON;//>0
38
39 /** Default weight for augmented QP subproblem. */
40 public static final double DEFAULT_RHO = 100.0;//rho>1
41
42 /** Default max value admitted for additional variable in QP subproblem. */
43 public static final double DEFAULT_SIGMA_MAX = 0.90;//0<sigma<1
44
45 /** Default max iteration admitted for QP subproblem. */
46 public static final int DEFAULT_QP_MAX_LOOP = 4;
47
48 /** Default parameter for evaluation of Armijo condition for descend direction. */
49 public static final double DEFAULT_MU = 1.0e-4;//[0,0.5]
50
51 /** Default parameter for quadratic line search. */
52 public static final double DEFAULT_B = 0.1;//[0;1]
53
54 /** Default parameter for alpha min during line search. */
55 public static final double DEFAULT_ALPHA_MIN = 1.0e-14;
56
57 /** Default parameter for non monotone line search history. */
58 public static final int DEFAULT_HISTORY = 10;
59
60 /** Default flag for using BFGS update formula. */
61 public static final boolean DEFAULT_USE_FUNCTION_HESSIAN = false;
62
63 /** Default max iteration before reset hessian. */
64 public static final int DEFAULT_MAX_LINE_SEARCH_ITERATION = 30;
65
66 /** Default Gradient mode. */
67 public static final GradientMode DEFAULT_GRADIENT_MODE = GradientMode.FORWARD;
68
69 /** Default Gradient EPS (proportional to function and constraints evaluation accuracy). */
70 public static final double DEFAULT_GRAD_EPS = Precision.EPSILON;
71
72 /** Default Max Iterations. */
73 public static final int DEFAULT_MAX_ITERATION = 300;
74
75 /** Tolerance for convergence and active constraint evaluation. */
76 private double eps;
77
78 /** Tolerance for qp convergence */
79 private double epsQP;
80
81 /** Weight for augmented QP subproblem. */
82 private double rhoCons;
83
84 /** Max value admitted for the solution of the additional variable in QP subproblem. */
85 private double sigmaMax;
86
87 /** Max iteration admitted for QP subproblem evaluation.
88 * (over this threshold the descend direction will be approximated using the merit function).
89 */
90 private int qpMaxLoop;
91
92 /** Parameter for evaluation of Armijo condition for descend direction.
93 * (fhi(alfa)-fhi(0)<=mu * alfa * fhi'(0)) */
94 private double mu;
95
96 /** Parameter for quadratic line search. */
97 private double b;
98
99 /** Parameter line search alpha min. */
100 private double alphaMin;
101
102 /** Parameter for non monotone line search history. */
103 private int history;
104
105 /** Max Iteration for the line search. */
106 private int maxLineSearchIteration;
107
108 /** Enable or Disable using direct the function Hessian. */
109 private boolean useFunHessian;
110
111 /** Gradient Mode. */
112 private GradientMode gradientMode;
113
114 /** Gradient eps. */
115 private double gradientEps;
116
117 /** Max Iteration */
118 private int maxIteration;
119
120 /** Convergence criteria (only used by deprecated optimizers). */
121 private int convCriteria;
122
123 /** Convergence criteria function for specific problems
124 * to avoid not significative iterations
125 */
126 private SQPCustomCriterion customCovergence;
127
128 /** Simple constructor.
129 * <p>
130 * This constructor uses all defaults values.
131 * </p>
132 */
133 public SQPOption() {
134
135 this.eps = DEFAULT_EPSILON;
136 this.epsQP = DEFAULT_EPSILON_QP;
137 this.rhoCons = DEFAULT_RHO;
138 this.sigmaMax = DEFAULT_SIGMA_MAX;
139 this.qpMaxLoop = DEFAULT_QP_MAX_LOOP;
140 this.mu = DEFAULT_MU;
141 this.b = DEFAULT_B;
142 this.alphaMin = DEFAULT_ALPHA_MIN;
143 this.maxLineSearchIteration = DEFAULT_MAX_LINE_SEARCH_ITERATION;
144 this.useFunHessian = DEFAULT_USE_FUNCTION_HESSIAN;
145 this.gradientMode = DEFAULT_GRADIENT_MODE;
146 this.gradientEps = DEFAULT_GRAD_EPS;
147 this.maxIteration = DEFAULT_MAX_ITERATION;
148 this.convCriteria = DEFAULT_CONV_CRITERIA;
149 this.customCovergence = null;
150 }
151
152 /** Set Gradient mode
153 * @param gradientMode gradient mode
154 */
155 public void setGradientMode(final GradientMode gradientMode) {
156 this.gradientMode = gradientMode;
157 }
158
159 /** Get Gradient Mode.
160 * @return Gradient Mode
161 */
162 public GradientMode getGradientMode() {
163 return gradientMode;
164 }
165
166 /** Set Gradient Eps
167 * Choose value proportional to function and constraints evaluation accuracy)
168 * @param gradientEps gradient mode
169 */
170 public void setGradientEps(final double gradientEps) {
171 this.gradientEps = gradientEps;
172 }
173
174 /** Get Gradient Eps.
175 * @return Gradient Eps
176 */
177 public double getGradientEps() {
178 return gradientEps;
179 }
180
181 /** Set convergence criteria.
182 * @param convCriteria convergence criteria
183 * @deprecated as of 4.1, only used by deprecated {@link SQPOptimizerS} and {@link SQPOptimizerGM}; will be removed in 5.0
184 */
185 @Deprecated
186 public void setConvCriteria(final int convCriteria) {
187 this.convCriteria = convCriteria;
188 }
189
190 /** Get convergence criteria.
191 * @return convergence criteria
192 * @deprecated as of 4.1, only used by deprecated {@link SQPOptimizerS} and {@link SQPOptimizerGM}; will be removed in 5.0
193 */
194 @Deprecated
195 public int getConvCriteria() {
196 return convCriteria;
197 }
198
199 /** Set tolerance for convergence
200 * Choose value proportional to sqrt of function and constraints evaluation accuracy
201 * @param eps tolerance for convergence and active constraint evaluation
202 */
203 public void setEps(final double eps) {
204 this.eps = eps;
205 }
206
207 /** Get tolerance for convergence and active constraint evaluation.
208 * @return tolerance for convergence and active constraint evaluation
209 */
210 public double getEps() {
211 return eps;
212 }
213
214 /** Set tolerance for QP convergence
215 * Choose value proportional to function and constraints evaluation accuracy
216 * @param epsQP tolerance for convergence
217 */
218 public void setEpsQP(final double epsQP) {
219 this.epsQP = epsQP;
220 }
221
222 /** Get tolerance for QP convergence
223 * @return tolerance for QP convergence
224 */
225 public double getEpsQP() {
226 return epsQP;
227 }
228
229
230
231 /** Set weight for augmented QP subproblem.
232 * @param rhoCons weight for augmented QP subproblem
233 */
234 public void setRhoCons(final double rhoCons) {
235 this.rhoCons = rhoCons;
236 }
237
238 /** Get weight for augmented QP subproblem.
239 * @return weight for augmented QP subproblem
240 */
241 public double getRhoCons() {
242 return rhoCons;
243 }
244
245 /** Set max value admitted for the solution of the additional variable in QP subproblem.
246 * @param sigmaMax max value admitted for the solution of the additional variable in QP subproblem
247 */
248 public void setSigmaMax(final double sigmaMax) {
249 this.sigmaMax = sigmaMax;
250 }
251
252 /** Get max value admitted for the solution of the additional variable in QP subproblem.
253 * @return max value admitted for the solution of the additional variable in QP subproblem
254 */
255 public double getSigmaMax() {
256 return sigmaMax;
257 }
258
259 /** Set max iteration admitted for QP subproblem evaluation.
260 * @param qpMaxLoop max iteration admitted for QP subproblem evaluation
261 */
262 public void setQpMaxLoop(final int qpMaxLoop) {
263 this.qpMaxLoop = qpMaxLoop;
264 }
265
266 /** Get max iteration admitted for QP subproblem evaluation.
267 * @return max iteration admitted for QP subproblem evaluation
268 */
269 public int getQpMaxLoop() {
270 return qpMaxLoop;
271 }
272
273 /** Set parameter for evaluation of Armijo condition for descend direction.
274 * @param mu parameter for evaluation of Armijo condition for descend direction
275 */
276 public void setMu(final double mu) {
277 this.mu = mu;
278 }
279
280 /** Get parameter for evaluation of Armijo condition for descend direction.
281 * @return parameter for evaluation of Armijo condition for descend direction
282 */
283 public double getMu() {
284 return mu;
285 }
286
287 /** Set parameter for quadratic line search.
288 * @param b parameter for quadratic line search
289 */
290 public void setB(final double b) {
291 this.b = b;
292 }
293
294 /** Get parameter for quadratic line search.
295 * @return parameter for quadratic line search
296 */
297 public double getB() {
298 return b;
299 }
300
301 /** Set parameter for line search alpha min.
302 * @param alphaMin parameter line search
303 */
304 public void setAlphaMin(final double alphaMin) {
305 this.alphaMin = alphaMin;
306 }
307
308 /** Get parameter line search alpha min.
309 * @return parameter for quadratic line search
310 */
311 public double getAlphaMin() {
312 return this.alphaMin;
313 }
314
315 /** Set parameter for non-monotone line search history.
316 * @param history parameter line search
317 */
318 public void setHistory(final int history) {
319 this.history = history;
320 }
321
322 /** Get parameter fot non-monotone line search history.
323 * @return parameter for non-monotone line search history
324 */
325 public int getHistory() {
326 return this.history;
327 }
328
329 /** Set max Iteration for the line search
330 * @param maxLineSearchIteration max Iteration for the line search
331 */
332 public void setMaxLineSearchIteration(final int maxLineSearchIteration) {
333 this.maxLineSearchIteration = maxLineSearchIteration;
334 }
335
336 /** Get max Iteration for the line search
337 * @return max Iteration for the line search
338 */
339 public int getMaxLineSearchIteration() {
340 return maxLineSearchIteration;
341 }
342
343 /** Set max Iteration
344 * @param maxIteration max Iteration
345 */
346 public void setMaxIteration(final int maxIteration) {
347 this.maxIteration = maxIteration;
348 }
349
350 /** Get max Iteration
351 * @return max Iteration
352 */
353 public int getMaxIteration() {
354 return maxIteration;
355 }
356
357 /** Enable or Disable using direct the function Hessian.
358 * @param useFunHessian enable or Disable using direct the function Hessian
359 */
360 public void setUseFunHessian(final boolean useFunHessian) {
361 this.useFunHessian = useFunHessian;
362 }
363
364 /** Check if using direct the function Hessian is enabled or disabled.
365 * @return true if using direct the function Hessian is enabled
366 */
367 public boolean useFunHessian() {
368 return useFunHessian;
369 }
370
371 /** Set custom convergence criteria function
372 * @param fun convergence criteria function
373 */
374 public void setConvergenceFunction(final SQPCustomCriterion fun) {
375 this.customCovergence = fun;
376 }
377
378 /** Get Convergence criteria Function
379 * @return the function of the custom convergenc criteria
380 */
381 public SQPCustomCriterion getConvergenceFunction() {
382 return this.customCovergence;
383 }
384
385 }