Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a time-limited optimization option to the Graph class #234

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

svwilliams
Copy link
Contributor

Added a time-limited optimization option to the Graph class

@svwilliams svwilliams merged commit 16942ad into devel Jul 22, 2021
@svwilliams svwilliams deleted the time-limited-optimization branch July 22, 2021 22:01
// Modify the options to enforce the maximum time
auto remaining = max_optimization_time - (created_problem - start);
auto time_constrained_options = options;
time_constrained_options.max_solver_time_in_seconds = std::max(0.0, remaining.toSec());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svwilliams I know I'm a bit late here, but I'd like to remember the max_solver_time_in_seconds can be set with a ROS parameter. This optimizeFor method would override that value, and also include the time spent creating the problem. That sounds like a good idea.

I believe this could be used in place of optimize and in that case pass the max_optimization_time from a ROS parameter. I wonder if that'd be a new parameter, or it'd be based on the max_solver_time_in_seconds one used for the solver options. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I completely follow the request/suggestion. Are you saying that optimize() and optimizeFor() get collapsed into a single call. Something like:

ceres::Solver::Summary optimize(const ceres::Solver::Options& options = ceres::Solver::Options(), const ros::Duration& max_optimization_time = ros::DURATION_MAX)
{
  auto start = ros::Time::now();
  // Construct the ceres::Problem object from scratch
  ceres::Problem problem(problem_options_);
  createProblem(problem);
  auto created_problem = ros::Time::now();

  auto time_constrained_options = options;
  auto max_solver_time = std::min(options.max_solver_time_in_seconds, max_optimization_time.toSec());
  if (max_solver_time < std::numeric_limit<double>::max())
  {
    auto remaining = max_solver_time - (created_problem - start).toSec();
    time_constrained_options.max_solver_time_in_seconds = std::max(0.0, remaining);
  }

  // Run the solver. This will update the variables in place.
  ceres::Solver::Summary summary;
  ceres::Solve(time_constrained_options, &problem, &summary);
  // Return the optimization summary
  return summary;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't very clear.

I wonder if now that we have optimize and optimizeFor, which one should be used, or which one is the preferred one?

For example, in

summary_ = graph_->optimize(params_.solver_options);
optimize is still being used. This means that the max_solver_time_in_seconds ROS parameter is still used to set the corresponding Ceres option.

If we switched it to use optimizeFor, we could either have another parameter, but then it'd somehow be related with the one for the Ceres option, mentioned above.

A possible implementation would be the one in your comment, but I still wonder what would be done in the caller side. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants