Add ability to log solver execution to file.
Change-Id: I9996ba2fed5229fe5d621fbb1a027d4c360cd59d
diff --git a/examples/bundle_adjuster.cc b/examples/bundle_adjuster.cc
index 8f1b38b..1ef0766 100644
--- a/examples/bundle_adjuster.cc
+++ b/examples/bundle_adjuster.cc
@@ -54,6 +54,7 @@
#include <algorithm>
#include <cmath>
#include <cstdio>
+#include <cstdlib>
#include <string>
#include <vector>
@@ -103,6 +104,7 @@
DEFINE_int32(random_seed, 38401, "Random seed used to set the state "
"of the pseudo random number generator used to generate "
"the pertubations.");
+DEFINE_string(solver_log, "", "File to record the solver execution to.");
namespace ceres {
namespace examples {
@@ -256,8 +258,28 @@
SetOrdering(bal_problem, options);
}
+// Uniform random numbers between 0 and 1.
+double UniformRandom() {
+ return static_cast<double>(random()) / static_cast<double>(RAND_MAX);
+}
+
+// Normal random numbers using the Box-Mueller algorithm. Its a bit
+// wasteful, as it generates two but only returns one.
+double RandNormal() {
+ double x1, x2, w, y1, y2;
+ do {
+ x1 = 2.0 * UniformRandom() - 1.0;
+ x2 = 2.0 * UniformRandom() - 1.0;
+ w = x1 * x1 + x2 * x2;
+ } while ( w >= 1.0 );
+
+ w = sqrt((-2.0 * log(w)) / w);
+ y1 = x1 * w;
+ y2 = x2 * w;
+ return y1;
+}
+
void BuildProblem(BALProblem* bal_problem, Problem* problem) {
- SetRandomState(FLAGS_random_seed);
const int point_block_size = bal_problem->point_block_size();
const int camera_block_size = bal_problem->camera_block_size();
double* points = bal_problem->mutable_points();
@@ -332,6 +354,7 @@
BuildProblem(&bal_problem, &problem);
Solver::Options options;
SetSolverOptionsFromFlags(&bal_problem, &options);
+ options.solver_log = FLAGS_solver_log;
Solver::Summary summary;
Solve(options, &problem, &summary);
std::cout << summary.FullReport() << "\n";