Restore the state of the Problem after a call to Evaluate.

Calling Problem::Evaluate mutates the state of the parameter blocks.
In particular, depending on the set and order of parameter blocks
passed to the evaluate call, it will change the internal indexing
used by the Program object used by ProblemImpl. This needs to be
undone before Evaluate returns, otherwise the Problem object
is in an invalid state.

To help with testing and debugging in the future, a new method
Program::IsValid has been added which checks whether the problem
has its parameter and residual blocks in the right state.

Thanks to Stefan Leutenegger for reporting this.

Change-Id: I209b486a31433f0cbb58b570047649eca6d42b56
diff --git a/internal/ceres/program.h b/internal/ceres/program.h
index 5002b7e..4288f60 100644
--- a/internal/ceres/program.h
+++ b/internal/ceres/program.h
@@ -99,6 +99,10 @@
   // position of the parameter in the state and delta vector respectively.
   void SetParameterOffsetsAndIndex();
 
+  // Check if the internal state of the program (the indexing and the
+  // offsets) are correct.
+  bool IsValid() const;
+
   // See problem.h for what these do.
   int NumParameterBlocks() const;
   int NumParameters() const;