Skip to content
New issue

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

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

Already on GitHub? # to your account

Rerun optimization until valid solution or timeout #53

Merged
merged 4 commits into from
Jun 27, 2023

Conversation

sea-bass
Copy link
Collaborator

This PR continues rerunning optimization within the timeout budget if the validity callback failed, using a random valid initial seed on each restart.

It also creates a Robot::get_random_valid_configuration() member function that is used for this new logic plus in the memetic optimizer. Yay reuse!

Closes #49.

auto const& var = robot.variables[j_idx];
population_[i].genes[j_idx] = rsl::uniform_real(var.clip_min, var.clip_max);
}
population_[i].genes = robot.get_random_valid_configuration();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tylerjw C++ question: Does switching this implementation from modifying elements of a pre-existing vector to returning a brand new one and overwriting the variable affect performance significantly?

Wondering if it makes more sense for this new function to accept a mutable vector by reference instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is one of the reasons that C++ std algorithms take iterators to existing containers. I don't care either way. I think this is easier to read, and I'd always bias towards easier-to-read code unless you have a benchmark showing that the performance difference matters for your use-case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think this is fine especially because it only happens when initializing a new population member and not all the time.

Copy link
Contributor

@tylerjw tylerjw left a comment

Choose a reason for hiding this comment

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

Assuming you've tested this in your application, I'm ok with this change.

auto const& var = robot.variables[j_idx];
population_[i].genes[j_idx] = rsl::uniform_real(var.clip_min, var.clip_max);
}
population_[i].genes = robot.get_random_valid_configuration();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is one of the reasons that C++ std algorithms take iterators to existing containers. I don't care either way. I think this is easier to read, and I'd always bias towards easier-to-read code unless you have a benchmark showing that the performance difference matters for your use-case.

@sea-bass sea-bass merged commit 7384e05 into main Jun 27, 2023
@delete-merged-branch delete-merged-branch bot deleted the pr-rerun-optim-until-valid branch June 27, 2023 13:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider continuing optimization when solution_callback fails but there is still time budget remaining
2 participants