-
Notifications
You must be signed in to change notification settings - Fork 25
Improvements to using the proof processor #385
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82b7b20
feat(pumpkin-proof-processor): Configure log level through CLI
maartenflippo fc8653d
feat(pumpkin-proof-processor): Log proof statistics
maartenflippo fdfa4a5
fix(pumpkin-proof-processor): Suppress processor output in tests
maartenflippo fdb969b
refactor(pumpkin-proof-processor): Simplify the predicate heap
maartenflippo 1165d1f
chore(pumpkin-proof-processor): Assert that trimming happens
maartenflippo ce396a0
chore: Clarify documentation for PredicateHeap
maartenflippo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| use std::cmp::Ordering; | ||
| use std::collections::BinaryHeap; | ||
|
|
||
| use pumpkin_core::predicates::Predicate; | ||
| use pumpkin_core::state::State; | ||
|
|
||
| /// A max-heap of predicates. The keys are based on the trail positions of the predicates in the | ||
| /// state, meaning predicates are popped in reverse trail order. Implied predicates are popped | ||
| /// before the predicate on the trail that implies the predicate. | ||
| #[derive(Clone, Debug, Default)] | ||
| pub(crate) struct PredicateHeap { | ||
| heap: BinaryHeap<PredicateToExplain>, | ||
| } | ||
|
|
||
| impl PredicateHeap { | ||
| /// See [`BinaryHeap::is_empty`]. | ||
| pub(crate) fn is_empty(&self) -> bool { | ||
| self.heap.is_empty() | ||
| } | ||
|
|
||
| /// See [`BinaryHeap::pop`]. | ||
| pub(crate) fn pop(&mut self) -> Option<Predicate> { | ||
| self.heap.pop().map(|to_explain| to_explain.predicate) | ||
| } | ||
|
|
||
| /// Push a new predicate onto the heap. | ||
| /// | ||
| /// Its priority will be based on its trail position in the given `state`. This heap will | ||
| /// return elements through [`Self::pop`] by reverse-trail order. | ||
|
ImkoMarijnissen marked this conversation as resolved.
|
||
| /// | ||
| /// If the predicate is not true in the given state, this method panics. | ||
| pub(crate) fn push(&mut self, predicate: Predicate, state: &State) { | ||
| let trail_position = state | ||
| .trail_position(predicate) | ||
| .expect("predicate must be true in given state"); | ||
|
|
||
| let priority = if state.is_on_trail(predicate) { | ||
| trail_position * 2 | ||
| } else { | ||
| trail_position * 2 + 1 | ||
| }; | ||
|
|
||
| self.heap.push(PredicateToExplain { | ||
| predicate, | ||
| priority, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /// Used to order the predicates in the [`PredicateHeap`]. | ||
| /// | ||
| /// The priority is calculated based on the trail position of the predicate and whether the | ||
| /// predicate is on the trail or implied. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| struct PredicateToExplain { | ||
| predicate: Predicate, | ||
| priority: usize, | ||
| } | ||
|
|
||
| impl PartialOrd for PredicateToExplain { | ||
| fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
| Some(self.cmp(other)) | ||
| } | ||
| } | ||
|
|
||
| impl Ord for PredicateToExplain { | ||
| fn cmp(&self, other: &Self) -> Ordering { | ||
| self.priority.cmp(&other.priority) | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.