-
Notifications
You must be signed in to change notification settings - Fork 23
feat: Add interface for nogood minimiser #326
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
7 commits
Select commit
Hold shift + click to select a range
528f830
feat: nogood minimisation interface + implement it for recursive mini…
ImkoMarijnissen a09d961
refactor: use minimisation trait in semantic minimiser
ImkoMarijnissen 0918fdd
fix: pass current nogood when getting current reason in minimisation …
ImkoMarijnissen 7f2669c
Merge branch 'main' into feat/minimiser-interface
ImkoMarijnissen 1763bda
refactor: use explicit helper methods
ImkoMarijnissen cae297a
docs: adding documentation to minimisation context
ImkoMarijnissen a6cd9b9
chore: deref for learned nogood is slice instead of vec
ImkoMarijnissen 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
53 changes: 53 additions & 0 deletions
53
pumpkin-crates/core/src/engine/conflict_analysis/minimisers/minimisation_context.rs
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,53 @@ | ||
| use crate::containers::HashMap; | ||
| use crate::engine::Assignments; | ||
| use crate::engine::SolverStatistics; | ||
| use crate::engine::conflict_analysis::ConflictAnalysisContext; | ||
| #[cfg(doc)] | ||
| use crate::engine::propagation::ReadDomains; | ||
| use crate::engine::propagation::contexts::HasAssignments; | ||
| use crate::predicates::Predicate; | ||
| use crate::proof::InferenceCode; | ||
| use crate::proof::ProofLog; | ||
| use crate::state::CurrentNogood; | ||
| use crate::state::State; | ||
|
|
||
| /// The context used for during nogood minimisation. | ||
| /// | ||
| /// Can be used to get the reason for a [`Predicate`] using | ||
| /// [`MinimisationContext::get_propagation_reason`], and information about integer variables and | ||
| /// [`Predicate`]s (see [`ReadDomains`]). | ||
| pub(crate) struct MinimisationContext<'a> { | ||
| pub(crate) state: &'a mut State, | ||
|
|
||
| pub(crate) proof_log: &'a mut ProofLog, | ||
| pub(crate) unit_nogood_inference_codes: &'a HashMap<Predicate, InferenceCode>, | ||
|
|
||
| pub(crate) counters: &'a mut SolverStatistics, | ||
| } | ||
| impl<'a> MinimisationContext<'a> { | ||
| /// Compute the reason for `predicate` being true. The reason will be stored in | ||
| /// `reason_buffer`. | ||
| /// | ||
| /// If `predicate` is not true, or it is a decision, then this function will panic. | ||
| pub(crate) fn get_propagation_reason( | ||
| &mut self, | ||
| reason_buffer: &mut (impl Extend<Predicate> + AsRef<[Predicate]>), | ||
| input_predicate: Predicate, | ||
| current_nogood: CurrentNogood<'_>, | ||
| ) { | ||
| ConflictAnalysisContext::get_propagation_reason( | ||
| input_predicate, | ||
| current_nogood, | ||
| self.proof_log, | ||
| self.unit_nogood_inference_codes, | ||
| reason_buffer, | ||
| self.state, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| impl<'a> HasAssignments for MinimisationContext<'a> { | ||
| fn assignments(&self) -> &Assignments { | ||
| &self.state.assignments | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
pumpkin-crates/core/src/engine/conflict_analysis/minimisers/minimiser.rs
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,9 @@ | ||
| use crate::engine::conflict_analysis::MinimisationContext; | ||
| use crate::predicates::Predicate; | ||
|
|
||
| /// A trait for the behaviour of nogood minimisation approaches. | ||
| pub(crate) trait NogoodMinimiser: Default { | ||
| /// Takes as input a nogood represented by a [`Vec`] of [`Predicate`]s and minimises the | ||
| /// nogood. | ||
| fn minimise(&mut self, context: MinimisationContext, nogood: &mut Vec<Predicate>); | ||
| } |
4 changes: 4 additions & 0 deletions
4
pumpkin-crates/core/src/engine/conflict_analysis/minimisers/mod.rs
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 |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| mod minimisation_context; | ||
| mod minimiser; | ||
| mod recursive_minimiser; | ||
| mod semantic_minimiser; | ||
|
|
||
| pub(crate) use minimisation_context::*; | ||
| pub(crate) use minimiser::*; | ||
| pub(crate) use recursive_minimiser::*; | ||
| pub(crate) use semantic_minimiser::*; |
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.
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.