42 std::unique_ptr<internal::NonlinearOptimizerState>
state)
64 double currentError =
error();
67 if (currentError <=
params.errorTol) {
69 cout <<
"Exiting, as error = " << currentError <<
" < " <<
params.errorTol << endl;
77 cout <<
"Initial error: " << currentError << endl;
82 cout <<
"iterations: " <<
iterations() <<
" >? " <<
params.maxIterations << endl;
88 double newError = currentError;
91 currentError = newError;
106 cout <<
"newError: " << newError << endl;
113 cout <<
"iterations: " <<
iterations() <<
" >? " <<
params.maxIterations << endl;
115 cout <<
"Terminating because reached maximum iterations" << endl;
138 if (
params.isMultifrontal()) {
144 }
else if (
params.isSequential()) {
148 params.getEliminationFunction())
152 params.getEliminationFunction())
154 }
else if (
params.isIterative()) {
156 if (!
params.iterativeParams)
157 throw std::runtime_error(
158 "NonlinearOptimizer::solve: cg parameter has to be assigned ...");
160 if (
auto pcg = std::dynamic_pointer_cast<PCGSolverParameters>(
161 params.iterativeParams)) {
163 }
else if (
auto spcg =
164 std::dynamic_pointer_cast<SubgraphSolverParameters>(
165 params.iterativeParams)) {
167 throw std::runtime_error(
"SubgraphSolver needs an ordering");
170 throw std::runtime_error(
171 "NonlinearOptimizer::solve: special cg parameter type is not handled in LM solver ...");
174 throw std::runtime_error(
"NonlinearOptimizer::solve: Optimization parameter is invalid");
183 double errorThreshold,
double currentError,
double newError,
186 if (newError <= errorThreshold)
187 cout <<
"errorThreshold: " << newError <<
" < " << errorThreshold << endl;
189 cout <<
"errorThreshold: " << newError <<
" > " << errorThreshold << endl;
192 if (newError <= errorThreshold)
196 double absoluteDecrease = currentError - newError;
198 if (absoluteDecrease <= absoluteErrorTreshold)
199 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease <<
" < "
200 << absoluteErrorTreshold << endl;
202 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease
203 <<
" >= " << absoluteErrorTreshold << endl;
207 double relativeDecrease = absoluteDecrease / currentError;
209 if (relativeDecrease <= relativeErrorTreshold)
210 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease <<
" < "
211 << relativeErrorTreshold << endl;
213 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease
214 <<
" >= " << relativeErrorTreshold << endl;
216 bool converged = (relativeErrorTreshold && (relativeDecrease <= relativeErrorTreshold)) ||
217 (absoluteDecrease <= absoluteErrorTreshold);
219 if (absoluteDecrease >= 0.0)
220 cout <<
"converged" << endl;
222 cout <<
"Warning: stopping nonlinear iterations because error increased" << endl;
224 cout <<
"errorThreshold: " << newError <<
" <? " << errorThreshold << endl;
225 cout <<
"absoluteDecrease: " << setprecision(12) << absoluteDecrease <<
" <? "
226 << absoluteErrorTreshold << endl;
227 cout <<
"relativeDecrease: " << setprecision(12) << relativeDecrease <<
" <? "
228 << relativeErrorTreshold << endl;
237 currentError, newError,
params.verbosity);