1 // Ceres Solver - A fast non-linear least squares minimizer
2 // Copyright 2015 Google Inc. All rights reserved.
3 // http://ceres-solver.org/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
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.
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.
29 // Author: sameragarwal@google.com (Sameer Agarwal)
31 #ifndef CERES_INTERNAL_PREPROCESSOR_H_
32 #define CERES_INTERNAL_PREPROCESSOR_H_
37 #include "ceres/coordinate_descent_minimizer.h"
38 #include "ceres/evaluator.h"
39 #include "ceres/internal/eigen.h"
40 #include "ceres/internal/port.h"
41 #include "ceres/internal/scoped_ptr.h"
42 #include "ceres/iteration_callback.h"
43 #include "ceres/linear_solver.h"
44 #include "ceres/minimizer.h"
45 #include "ceres/problem_impl.h"
46 #include "ceres/program.h"
47 #include "ceres/solver.h"
52 struct PreprocessedProblem;
54 // Given a Problem object and a Solver::Options object indicating the
55 // configuration of the solver, the job of the Preprocessor is to
56 // analyze the Problem and perform the setup needed to solve it using
57 // the desired Minimization algorithm. The setup involves removing
58 // redundancies in the input problem (inactive parameter and residual
59 // blocks), finding fill reducing orderings as needed, configuring and
60 // creating various objects needed by the Minimizer to solve the
61 // problem such as an evaluator, a linear solver etc.
63 // Each Minimizer (LineSearchMinimizer and TrustRegionMinimizer) comes
64 // with a corresponding Preprocessor (LineSearchPreprocessor and
65 // TrustRegionPreprocessor) that knows about its needs and performs
66 // the preprocessing needed.
68 // The output of the Preprocessor is stored in a PreprocessedProblem
73 static Preprocessor* Create(MinimizerType minimizer_type);
74 virtual ~Preprocessor();
75 virtual bool Preprocess(const Solver::Options& options,
77 PreprocessedProblem* pp) = 0;
80 // A PreprocessedProblem is the result of running the Preprocessor on
81 // a Problem and Solver::Options object.
82 struct PreprocessedProblem {
88 Solver::Options options;
89 LinearSolver::Options linear_solver_options;
90 Evaluator::Options evaluator_options;
91 Minimizer::Options minimizer_options;
94 scoped_ptr<ProblemImpl> gradient_checking_problem;
95 scoped_ptr<Program> reduced_program;
96 scoped_ptr<LinearSolver> linear_solver;
97 scoped_ptr<IterationCallback> logging_callback;
98 scoped_ptr<IterationCallback> state_updating_callback;
100 shared_ptr<Evaluator> evaluator;
101 shared_ptr<CoordinateDescentMinimizer> inner_iteration_minimizer;
103 std::vector<double*> removed_parameter_blocks;
104 Vector reduced_parameters;
108 // Common functions used by various preprocessors.
110 // If OpenMP support is not available and user has requested more than
111 // one thread, then set the *_num_threads options as needed to 1.
112 void ChangeNumThreadsIfNeeded(Solver::Options* options);
114 // Extract the effective parameter vector from the preprocessed
115 // problem and setup bits of the Minimizer::Options object that are
116 // common to all Preprocessors.
117 void SetupCommonMinimizerOptions(PreprocessedProblem* pp);
119 } // namespace internal
122 #endif // CERES_INTERNAL_PREPROCESSOR_H_