1 | // Copyright (C) 2004, International Business Machines and others. |
---|
2 | // All Rights Reserved. |
---|
3 | // This code is published under the Common Public License. |
---|
4 | // |
---|
5 | // $Id: IpOptErrorConvCheck.cpp 416 2005-07-29 19:11:41Z andreasw $ |
---|
6 | // |
---|
7 | // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 |
---|
8 | |
---|
9 | #include "IpOptErrorConvCheck.hpp" |
---|
10 | |
---|
11 | namespace Ipopt |
---|
12 | { |
---|
13 | DBG_SET_VERBOSITY(0); |
---|
14 | |
---|
15 | DefineIpoptType(OptimalityErrorConvergenceCheck); |
---|
16 | |
---|
17 | OptimalityErrorConvergenceCheck::OptimalityErrorConvergenceCheck() |
---|
18 | {} |
---|
19 | |
---|
20 | OptimalityErrorConvergenceCheck::~OptimalityErrorConvergenceCheck() |
---|
21 | {} |
---|
22 | |
---|
23 | void OptimalityErrorConvergenceCheck::RegisterOptions(SmartPtr<RegisteredOptions> roptions) |
---|
24 | { |
---|
25 | roptions->AddLowerBoundedIntegerOption( |
---|
26 | "max_iter", |
---|
27 | "Maximum number of iterations.", |
---|
28 | 0, 3000, |
---|
29 | "The algorithm terminates with an error message if the number of " |
---|
30 | "iterations exceeded this number. [Also used in RestoFilterConvCheck]"); |
---|
31 | roptions->AddLowerBoundedNumberOption( |
---|
32 | "dual_inf_tol", |
---|
33 | "Acceptance threshold for the dual infeasibility.", |
---|
34 | 0.0, true, 1e-4, |
---|
35 | "Absolute tolerance on the dual infesaibility. Successful termination " |
---|
36 | "requires that the (unscaled) dual infeasibility is less than this " |
---|
37 | "threshold."); |
---|
38 | roptions->AddLowerBoundedNumberOption( |
---|
39 | "constr_viol_tol", |
---|
40 | "Acceptance threshold for the constraint violation.", |
---|
41 | 0.0, true, 1e-4, |
---|
42 | "Absolute tolerance on the constraint violation. Successful termination " |
---|
43 | "requires that the (unscaled) constraint violation is less than this " |
---|
44 | "threshold."); |
---|
45 | roptions->AddLowerBoundedNumberOption( |
---|
46 | "compl_inf_tol", |
---|
47 | "Acceptance threshold for the complementarity conditions.", |
---|
48 | 0.0, true, 1e-4, |
---|
49 | "Absolute tolerance on the complementarity. Successful termination " |
---|
50 | "requires that the (unscaled) complementarity is less than this " |
---|
51 | "threshold."); |
---|
52 | roptions->AddLowerBoundedIntegerOption( |
---|
53 | "acceptable_iter", |
---|
54 | "Number of acceptable iterates to trigger termination.", |
---|
55 | 0, 15, |
---|
56 | "If the algorithm encounters so many successive acceptable iterates " |
---|
57 | "(see \"acceptable_tol\"), it terminates, assuming that the problem " |
---|
58 | "has been solved to best possible accuracy given round-off. If it is " |
---|
59 | "set to zero, this heuristic is disabled."); |
---|
60 | roptions->AddLowerBoundedNumberOption( |
---|
61 | "acceptable_tol", |
---|
62 | "Acceptable convergence tolerance (relative).", |
---|
63 | 0.0, true, 1e-6, |
---|
64 | "Determines which (scaled) overall optimality error is considered to be " |
---|
65 | "acceptable. If the algorithm encounters \"acceptable_iter\" iterations " |
---|
66 | "in a row that are considered \"acceptable\", it will terminate before " |
---|
67 | "the desired convergence tolerance (\"tol\", \"dual_inf_tol\", etc) is " |
---|
68 | "met."); |
---|
69 | roptions->AddLowerBoundedNumberOption( |
---|
70 | "acceptable_dual_inf_tol", |
---|
71 | "Acceptance threshold for the dual infeasibility.", |
---|
72 | 0.0, true, 1e-2, |
---|
73 | "Absolute tolerance on the dual infesaibility. Acceptable termination " |
---|
74 | "requires that the (unscaled) dual infeasibility is less than this " |
---|
75 | "threshold."); |
---|
76 | roptions->AddLowerBoundedNumberOption( |
---|
77 | "acceptable_constr_viol_tol", |
---|
78 | "Acceptance threshold for the constraint violation.", |
---|
79 | 0.0, true, 1e-2, |
---|
80 | "Absolute tolerance on the constraint violation. Acceptable termination " |
---|
81 | "requires that the (unscaled) constraint violation is less than this " |
---|
82 | "threshold."); |
---|
83 | roptions->AddLowerBoundedNumberOption( |
---|
84 | "acceptable_compl_inf_tol", |
---|
85 | "Acceptance threshold for the complementarity conditions.", |
---|
86 | 0.0, true, 1e-2, |
---|
87 | "Absolute tolerance on the complementarity. Acceptable termination " |
---|
88 | "requires that the (unscaled) complementarity is less than this " |
---|
89 | "threshold."); |
---|
90 | } |
---|
91 | |
---|
92 | bool |
---|
93 | OptimalityErrorConvergenceCheck::InitializeImpl(const OptionsList& options, |
---|
94 | const std::string& prefix) |
---|
95 | { |
---|
96 | options.GetIntegerValue("max_iter", max_iterations_, prefix); |
---|
97 | options.GetNumericValue("dual_inf_tol", dual_inf_tol_, prefix); |
---|
98 | options.GetNumericValue("constr_viol_tol", constr_viol_tol_, prefix); |
---|
99 | options.GetNumericValue("compl_inf_tol", compl_inf_tol_, prefix); |
---|
100 | options.GetIntegerValue("acceptable_iter", acceptable_iter_, prefix); |
---|
101 | options.GetNumericValue("acceptable_tol", acceptable_tol_, prefix); |
---|
102 | options.GetNumericValue("acceptable_dual_inf_tol", acceptable_dual_inf_tol_, prefix); |
---|
103 | options.GetNumericValue("acceptable_constr_viol_tol", acceptable_constr_viol_tol_, prefix); |
---|
104 | options.GetNumericValue("acceptable_compl_inf_tol", acceptable_compl_inf_tol_, prefix); |
---|
105 | acceptable_counter_ = 0; |
---|
106 | |
---|
107 | return true; |
---|
108 | } |
---|
109 | |
---|
110 | ConvergenceCheck::ConvergenceStatus |
---|
111 | OptimalityErrorConvergenceCheck::CheckConvergence() |
---|
112 | { |
---|
113 | DBG_START_METH("OptimalityErrorConvergenceCheck::CheckConvergence", dbg_verbosity); |
---|
114 | |
---|
115 | if (IpData().iter_count() >= max_iterations_) { |
---|
116 | return ConvergenceCheck::MAXITER_EXCEEDED; |
---|
117 | } |
---|
118 | |
---|
119 | Number overall_error = IpCq().curr_nlp_error(); |
---|
120 | Number dual_inf = IpCq().unscaled_curr_dual_infeasibility(NORM_MAX); |
---|
121 | Number constr_viol = IpCq().unscaled_curr_nlp_constraint_violation(NORM_MAX); |
---|
122 | Number compl_inf = IpCq().unscaled_curr_complementarity(0., NORM_MAX); |
---|
123 | |
---|
124 | if (overall_error <= IpData().tol() && |
---|
125 | dual_inf <= dual_inf_tol_ && |
---|
126 | constr_viol <= constr_viol_tol_ && |
---|
127 | compl_inf <= compl_inf_tol_) { |
---|
128 | return ConvergenceCheck::CONVERGED; |
---|
129 | } |
---|
130 | |
---|
131 | if (acceptable_iter_>0 && CurrentIsAcceptable()) { |
---|
132 | IpData().Append_info_string("A"); |
---|
133 | acceptable_counter_++; |
---|
134 | if (acceptable_counter_ >= acceptable_iter_) { |
---|
135 | return ConvergenceCheck::CONVERGED_TO_ACCEPTABLE_POINT; |
---|
136 | } |
---|
137 | } |
---|
138 | else { |
---|
139 | acceptable_counter_ = 0; |
---|
140 | } |
---|
141 | |
---|
142 | return ConvergenceCheck::CONTINUE; |
---|
143 | } |
---|
144 | |
---|
145 | bool OptimalityErrorConvergenceCheck::CurrentIsAcceptable() |
---|
146 | { |
---|
147 | DBG_START_METH("OptimalityErrorConvergenceCheck::CurrentIsAcceptable", |
---|
148 | dbg_verbosity); |
---|
149 | |
---|
150 | Number overall_error = IpCq().curr_nlp_error(); |
---|
151 | Number dual_inf = IpCq().unscaled_curr_dual_infeasibility(NORM_MAX); |
---|
152 | Number constr_viol = IpCq().unscaled_curr_nlp_constraint_violation(NORM_MAX); |
---|
153 | Number compl_inf = IpCq().unscaled_curr_complementarity(0., NORM_MAX); |
---|
154 | |
---|
155 | DBG_PRINT((1, "overall_error = %e\n", overall_error)); |
---|
156 | DBG_PRINT((1, "dual_inf = %e\n", dual_inf)); |
---|
157 | DBG_PRINT((1, "constr_viol = %e\n", constr_viol)); |
---|
158 | DBG_PRINT((1, "compl_inf = %e\n", compl_inf)); |
---|
159 | |
---|
160 | DBG_PRINT((1, "acceptable_tol_ = %e\n", acceptable_tol_)); |
---|
161 | DBG_PRINT((1, "acceptable_dual_inf_tol_ = %e\n", acceptable_dual_inf_tol_)); |
---|
162 | DBG_PRINT((1, "acceptable_constr_viol_tol_ = %e\n", acceptable_constr_viol_tol_)); |
---|
163 | DBG_PRINT((1, "acceptable_compl_inf_tol_ = %e\n", acceptable_compl_inf_tol_)); |
---|
164 | |
---|
165 | return (overall_error <= acceptable_tol_ && |
---|
166 | dual_inf <= acceptable_dual_inf_tol_ && |
---|
167 | constr_viol <= acceptable_constr_viol_tol_ && |
---|
168 | compl_inf <= acceptable_compl_inf_tol_); |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | } // namespace Ipopt |
---|