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

Access solver attributes within problem #17

Closed
TheoGuyard opened this issue May 30, 2022 · 2 comments
Closed

Access solver attributes within problem #17

TheoGuyard opened this issue May 30, 2022 · 2 comments

Comments

@TheoGuyard
Copy link

Hi ! Thank you for the development of this package ! I was wondering if there was a way to call the solver attributes inside the problem methods. For instance, I would like to have access to the best objective within the bound method in the following way :

class Problem(pybnb.Problem):
    ...
    def bound(self):
        best_objective = self.retrieve_solver_attribute("best_objective")
        return do_bounding_using_best_objective()
    ...

Thank you for your answer,
Théo

@ghackebeil
Copy link
Owner

Hi @TheoGuyard. Thanks for your interest in the project!

You can access the best node (i.e., the node with the best objective) each time it is updated by implementing a notify_new_best_node method on your Problem class.

https://pybnb.readthedocs.io/en/stable/reference/problem.html#pybnb.problem.Problem.notify_new_best_node

The best objective is available as the objective attribute on the node passed into that method, along with other information.

https://pybnb.readthedocs.io/en/stable/reference/node.html#pybnb.node.Node

This page shows where that method is called relative to others in the core solver loop:

https://pybnb.readthedocs.io/en/stable/getting_started/index.html#how-the-solver-calls-the-problem-methods

@TheoGuyard
Copy link
Author

Hi @ghackebeil. Thanks for the quick response, I now have all the information I need !

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

No branches or pull requests

2 participants