Home | History | Annotate | Download | only in ceres
      1 // 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 (at) google.com (Keir Mierle)
     30 
     31 #ifndef CERES_INTERNAL_SOLVER_IMPL_H_
     32 #define CERES_INTERNAL_SOLVER_IMPL_H_
     33 
     34 #include <set>
     35 #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 
     42 namespace ceres {
     43 namespace internal {
     44 
     45 class CoordinateDescentMinimizer;
     46 class Evaluator;
     47 class LinearSolver;
     48 class Program;
     49 class TripletSparseMatrix;
     50 
     51 class 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 
     59   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,
     70       Solver::Summary* summary);
     71 
     72   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,
     80                                  Solver::Summary* summary);
     81 
     82   // 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,
     92                                        string* message);
     93 
     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,
    100                                           string* message);
    101 
    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,
    107       string* message);
    108 
    109   static bool IsOrderingValid(const Solver::Options& options,
    110                               const ProblemImpl* problem_impl,
    111                               string* message);
    112 
    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,
    121       Solver::Summary* summary);
    122 };
    123 
    124 }  // namespace internal
    125 }  // namespace ceres
    126 
    127 #endif  // CERES_INTERNAL_SOLVER_IMPL_H_
    128