Allow Solver::Options::max_num_line_search_step_size_iterations = 0.

This change only affects the TRUST_REGION minimizer and has no effect
on the LINE_SEARCH minimizer.

This options controls the number of iterations that the line search
algorithm performs. The line search algorithm is as the name implies,
used in the LINE_SEARCH minimizer. It is also used by the TRUST_REGION
minimizer when solving bounds constrained optimization problems.

In some bounds constrained problems, it is enough to project each step
onto the bounds constraints and not perform the line search. This can
have a significant impact on runtime. Setting
Solver::Options::max_num_line_search_step_size_iterations = 0 enables
this functionality.

Changchang Wu (ccwu@google.com) came up with the idea for this
implementation.

https://github.com/ceres-solver/ceres-solver/issues/477

Change-Id: Ifbe0bc5c48eedb2c1231d43cd98e4be7316c0682
diff --git a/include/ceres/solver.h b/include/ceres/solver.h
index 6d9cee9..2141cc4 100644
--- a/include/ceres/solver.h
+++ b/include/ceres/solver.h
@@ -191,6 +191,11 @@
     // Maximum number of trial step size iterations during each line search,
     // if a step size satisfying the search conditions cannot be found within
     // this number of trials, the line search will terminate.
+    //
+    // The minimum allowed value is 0 for trust region minimizer and 1
+    // otherwise. If 0 is specified for the trust region minimizer,
+    // the line search use when solving constrained optimization
+    // problems will be disabled.
     int max_num_line_search_step_size_iterations = 20;
 
     // Maximum number of restarts of the line search direction algorithm before
diff --git a/internal/ceres/solver.cc b/internal/ceres/solver.cc
index 65ddf5b..0627d8c 100644
--- a/internal/ceres/solver.cc
+++ b/internal/ceres/solver.cc
@@ -239,7 +239,8 @@
   OPTION_LT_OPTION(max_line_search_step_contraction,
                    min_line_search_step_contraction);
   OPTION_LE(min_line_search_step_contraction, 1.0);
-  OPTION_GT(max_num_line_search_step_size_iterations, 0);
+  OPTION_GE(max_num_line_search_step_size_iterations,
+            (options.minimizer_type == ceres::TRUST_REGION ? 0 : 1));
   OPTION_GT(line_search_sufficient_function_decrease, 0.0);
   OPTION_LT_OPTION(line_search_sufficient_function_decrease,
                    line_search_sufficient_curvature_decrease);
diff --git a/internal/ceres/trust_region_minimizer.cc b/internal/ceres/trust_region_minimizer.cc
index 5505cbb..aacd991 100644
--- a/internal/ceres/trust_region_minimizer.cc
+++ b/internal/ceres/trust_region_minimizer.cc
@@ -93,7 +93,8 @@
       continue;
     }
 
-    if (options_.is_constrained) {
+    if (options_.is_constrained &&
+        options_.max_num_line_search_step_size_iterations > 0) {
       // Use a projected line search to enforce the bounds constraints
       // and improve the quality of the step.
       DoLineSearch(x_, gradient_, x_cost_, &delta_);