Silence LineSearch on demand.

Add LineSearch::Options::is_silent which allows the user to turn
off all LOG(WARNING) logging off.

This is useful when calling LineSearch from the TrustRegionMinimizer
where the verbosity of the line search is of no use.

Change-Id: I4f1855e98f3cf3c3659d92b54586ff88d64e5ebe
diff --git a/internal/ceres/line_search.cc b/internal/ceres/line_search.cc
index a396691..bacad48 100644
--- a/internal/ceres/line_search.cc
+++ b/internal/ceres/line_search.cc
@@ -276,7 +276,7 @@
                        "satisfying the sufficient decrease condition within "
                        "specified max_num_iterations: %d.",
                        options().max_num_iterations);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return;
     }
 
@@ -294,7 +294,7 @@
           StringPrintf("Line search failed: step_size too small: %.5e "
                        "with descent_direction_max_norm: %.5e.", step_size,
                        descent_direction_max_norm);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return;
     }
 
@@ -547,15 +547,16 @@
       // conditions, or a valid bracket containing such a point. Stop searching
       // and set bracket_low to the size size amongst all those tested which
       // minimizes f() and satisfies the Armijo condition.
-      LOG(WARNING) << "Line search failed: Wolfe bracketing phase shrank "
-                   << "bracket width: " << fabs(current.x - previous.x)
-                   <<  ", to < tolerance: " << options().min_step_size
-                   << ", with descent_direction_max_norm: "
-                   << descent_direction_max_norm << ", and failed to find "
-                   << "a point satisfying the strong Wolfe conditions or a "
-                   << "bracketing containing such a point. Accepting "
-                   << "point found satisfying Armijo condition only, to "
-                   << "allow continuation.";
+      LOG_IF(WARNING, !options().is_silent)
+          << "Line search failed: Wolfe bracketing phase shrank "
+          << "bracket width: " << fabs(current.x - previous.x)
+          <<  ", to < tolerance: " << options().min_step_size
+          << ", with descent_direction_max_norm: "
+          << descent_direction_max_norm << ", and failed to find "
+          << "a point satisfying the strong Wolfe conditions or a "
+          << "bracketing containing such a point. Accepting "
+          << "point found satisfying Armijo condition only, to "
+          << "allow continuation.";
       *bracket_low = current;
       break;
 
@@ -568,7 +569,7 @@
                        "find a point satisfying strong Wolfe conditions, or a "
                        "bracket containing such a point within specified "
                        "max_num_iterations: %d", options().max_num_iterations);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       // Ensure that bracket_low is always set to the step size amongst all
       // those tested which minimizes f() and satisfies the Armijo condition
       // when we terminate due to the 'artificial' max_num_iterations condition.
@@ -607,7 +608,7 @@
           StringPrintf("Line search failed: step_size too small: %.5e "
                        "with descent_direction_max_norm: %.5e", step_size,
                        descent_direction_max_norm);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return false;
     }
 
@@ -691,7 +692,7 @@
                      initial_position.ToDebugString().c_str(),
                      bracket_low.ToDebugString().c_str(),
                      bracket_high.ToDebugString().c_str());
-    LOG(WARNING) << summary->error;
+    LOG_IF(WARNING, !options().is_silent) << summary->error;
     solution->value_is_valid = false;
     return false;
   }
@@ -712,7 +713,7 @@
                        "within specified max_num_iterations: %d, "
                        "(num iterations taken for bracketing: %d).",
                        options().max_num_iterations, num_bracketing_iterations);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return false;
     }
     if (fabs(bracket_high.x - bracket_low.x) * descent_direction_max_norm
@@ -724,7 +725,7 @@
                        "too small with descent_direction_max_norm: %.5e.",
                        fabs(bracket_high.x - bracket_low.x),
                        descent_direction_max_norm);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return false;
     }
 
@@ -775,7 +776,7 @@
                        "between low_step: %.5e and high_step: %.5e "
                        "at which function is valid.",
                        solution->x, bracket_low.x, bracket_high.x);
-      LOG(WARNING) << summary->error;
+      LOG_IF(WARNING, !options().is_silent) << summary->error;
       return false;
     }
 
diff --git a/internal/ceres/line_search.h b/internal/ceres/line_search.h
index 5f24e9f..57ef9e7 100644
--- a/internal/ceres/line_search.h
+++ b/internal/ceres/line_search.h
@@ -71,6 +71,7 @@
           max_num_iterations(20),
           sufficient_curvature_decrease(0.9),
           max_step_expansion(10.0),
+          is_silent(false),
           function(NULL) {}
 
     // Degree of the polynomial used to approximate the objective
@@ -144,6 +145,8 @@
     // By definition for expansion, max_step_expansion > 1.0.
     double max_step_expansion;
 
+    bool is_silent;
+
     // The one dimensional function that the line search algorithm
     // minimizes.
     Function* function;