-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to stop search once a solution is found (#13)
*Rationale*: Even though our main use case for `syntheseus` so far has been to run search for a fixed amount of time and analyze all routes in the resulting search graph, there are some scenarios where we only care about whether or not a route is found (e.g. benchmarking). This is pretty simple to check so I thought it is worth supporting. *Implementation*: previously all algorithms called `time_limit_reached` each iteration to decide whether to stop early. I just augmented this function to also check for stopping once a solution is found. This involved: 1. Adding a `stop_on_first_solution` kwarg to the base algorithm class (defaults to False, which is the most sensible default in my opinion) 2. Adding logic to `time_limit_reached` which checks `self.stop_on_first_solution and graph.root_node.has_solution`. This required adding a `graph` argument to the function (previously it took no arguments), causing changes in all algorithm files. 3. Because of this added functionality, `time_limit_reached` no longer seemed like a descriptive name for the function, so I changed it to `should_stop_search` 4. I added a test to `syntheseus/tests/search/algorithms/test_base.py` which tests the effectiveness of this kwarg for all algorithms (because algorithm-specific tests all subclass the base test) *Rejected alternative*: although it would be appealing to generalize this to "stop after n solutions" or "stop after n diverse solutions" this is not simple or quick to check so I don't think we should support it out-of-the-box. If users want this then they could implement it themselves in a subclass. --------- Co-authored-by: Krzysztof Maziarz <[email protected]>
- Loading branch information
Showing
6 changed files
with
45 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters