blob: c42c32a628ee8c82b163f185c62de9487aba73ad [file] [log] [blame]
Angus Kong0ae28bd2013-02-13 14:56:04 -08001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2010, 2011, 2012 Google Inc. All rights reserved.
3// http://code.google.com/p/ceres-solver/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// * Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28//
29// Author: keir@google.com (Keir Mierle)
30
31#ifndef CERES_INTERNAL_SOLVER_IMPL_H_
32#define CERES_INTERNAL_SOLVER_IMPL_H_
33
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070034#include <set>
Angus Kong0ae28bd2013-02-13 14:56:04 -080035#include <string>
36#include <vector>
37#include "ceres/internal/port.h"
38#include "ceres/ordered_groups.h"
39#include "ceres/problem_impl.h"
40#include "ceres/solver.h"
41
42namespace ceres {
43namespace internal {
44
45class CoordinateDescentMinimizer;
46class Evaluator;
47class LinearSolver;
48class Program;
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070049class TripletSparseMatrix;
Angus Kong0ae28bd2013-02-13 14:56:04 -080050
51class SolverImpl {
52 public:
53 // Mirrors the interface in solver.h, but exposes implementation
54 // details for testing internally.
55 static void Solve(const Solver::Options& options,
56 ProblemImpl* problem_impl,
57 Solver::Summary* summary);
58
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070059 static void TrustRegionSolve(const Solver::Options& options,
60 ProblemImpl* problem_impl,
61 Solver::Summary* summary);
62
63 // Run the TrustRegionMinimizer for the given evaluator and configuration.
64 static void TrustRegionMinimize(
65 const Solver::Options &options,
66 Program* program,
67 CoordinateDescentMinimizer* inner_iteration_minimizer,
68 Evaluator* evaluator,
69 LinearSolver* linear_solver,
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070070 Solver::Summary* summary);
71
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070072 static void LineSearchSolve(const Solver::Options& options,
73 ProblemImpl* problem_impl,
74 Solver::Summary* summary);
75
76 // Run the LineSearchMinimizer for the given evaluator and configuration.
77 static void LineSearchMinimize(const Solver::Options &options,
78 Program* program,
79 Evaluator* evaluator,
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070080 Solver::Summary* summary);
Sascha Haeberling1d2624a2013-07-23 19:00:21 -070081
Angus Kong0ae28bd2013-02-13 14:56:04 -080082 // Create the transformed Program, which has all the fixed blocks
83 // and residuals eliminated, and in the case of automatic schur
84 // ordering, has the E blocks first in the resulting program, with
85 // options.num_eliminate_blocks set appropriately.
86 //
87 // If fixed_cost is not NULL, the residual blocks that are removed
88 // are evaluated and the sum of their cost is returned in fixed_cost.
89 static Program* CreateReducedProgram(Solver::Options* options,
90 ProblemImpl* problem_impl,
91 double* fixed_cost,
Carlos Hernandez79397c22014-08-07 17:51:38 -070092 string* message);
Angus Kong0ae28bd2013-02-13 14:56:04 -080093
94 // Create the appropriate linear solver, taking into account any
95 // config changes decided by CreateTransformedProgram(). The
96 // selected linear solver, which may be different from what the user
97 // selected; consider the case that the remaining elimininated
98 // blocks is zero after removing fixed blocks.
99 static LinearSolver* CreateLinearSolver(Solver::Options* options,
Carlos Hernandez79397c22014-08-07 17:51:38 -0700100 string* message);
Angus Kong0ae28bd2013-02-13 14:56:04 -0800101
102 // Create the appropriate evaluator for the transformed program.
103 static Evaluator* CreateEvaluator(
104 const Solver::Options& options,
105 const ProblemImpl::ParameterMap& parameter_map,
106 Program* program,
Carlos Hernandez79397c22014-08-07 17:51:38 -0700107 string* message);
Angus Kong0ae28bd2013-02-13 14:56:04 -0800108
109 static bool IsOrderingValid(const Solver::Options& options,
110 const ProblemImpl* problem_impl,
Carlos Hernandez79397c22014-08-07 17:51:38 -0700111 string* message);
Angus Kong0ae28bd2013-02-13 14:56:04 -0800112
113 static bool IsParameterBlockSetIndependent(
114 const set<double*>& parameter_block_ptrs,
115 const vector<ResidualBlock*>& residual_blocks);
116
117 static CoordinateDescentMinimizer* CreateInnerIterationMinimizer(
118 const Solver::Options& options,
119 const Program& program,
120 const ProblemImpl::ParameterMap& parameter_map,
Sascha Haeberling1d2624a2013-07-23 19:00:21 -0700121 Solver::Summary* summary);
Angus Kong0ae28bd2013-02-13 14:56:04 -0800122};
123
124} // namespace internal
125} // namespace ceres
126
127#endif // CERES_INTERNAL_SOLVER_IMPL_H_