-
Notifications
You must be signed in to change notification settings - Fork 25
refactor(pumpkin-solver): Bulk create propagators before root propagation in FlatZinc reader #407
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
47ec9a4
feat(pumpkin-core): Create solver based on a precreated `State`
maartenflippo c4c00a1
Refactor `Constraint` trait to use `State` instead of `Solver`
maartenflippo f9103d1
Patch signatures of constraints
maartenflippo cd56ad5
Import state in all constraints
maartenflippo eb5463e
Rename variables and remove ?
maartenflippo 621f14f
Refactor clause and conjunction constraints
maartenflippo 32ee0a6
Refactor table and negative table
maartenflippo a8d1067
Refactor equality constraint
maartenflippo e2cbc9e
Fix clippy
maartenflippo 3246b00
Fixup flatzinc frontend and statistic logging
maartenflippo f55a3e0
Fix warnings
maartenflippo de0f091
Fix compile errors in non-default targets
maartenflippo 4c34182
Fix clippy warnings
maartenflippo a2d4f4b
Get everything to compile
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
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 |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| use pumpkin_core::ConstraintOperationError; | ||
| use pumpkin_core::Solver; | ||
| use pumpkin_core::constraints::Constraint; | ||
| use pumpkin_core::constraints::NegatableConstraint; | ||
| use pumpkin_core::proof::ConstraintTag; | ||
| use pumpkin_core::state::State; | ||
| use pumpkin_core::variables::IntegerVariable; | ||
| use pumpkin_core::variables::Literal; | ||
| use pumpkin_propagators::arithmetic::LinearLessOrEqualPropagatorArgs; | ||
|
|
@@ -107,26 +106,22 @@ struct Inequality<Var> { | |
| } | ||
|
|
||
| impl<Var: IntegerVariable + 'static> Constraint for Inequality<Var> { | ||
| fn post(self, solver: &mut Solver) -> Result<(), ConstraintOperationError> { | ||
| fn post(self, state: &mut State) { | ||
| LinearLessOrEqualPropagatorArgs { | ||
| x: self.terms, | ||
| c: self.rhs, | ||
| constraint_tag: self.constraint_tag, | ||
| } | ||
| .post(solver) | ||
| .post(state) | ||
| } | ||
|
|
||
| fn implied_by( | ||
| self, | ||
| solver: &mut Solver, | ||
| reification_literal: Literal, | ||
| ) -> Result<(), ConstraintOperationError> { | ||
| fn implied_by(self, state: &mut State, reification_literal: Literal) { | ||
| LinearLessOrEqualPropagatorArgs { | ||
| x: self.terms, | ||
| c: self.rhs, | ||
| constraint_tag: self.constraint_tag, | ||
| } | ||
| .implied_by(solver, reification_literal) | ||
| .implied_by(state, reification_literal) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -141,38 +136,3 @@ impl<Var: IntegerVariable + 'static> NegatableConstraint for Inequality<Var> { | |
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn less_than_conflict() { | ||
| let mut solver = Solver::default(); | ||
|
|
||
| let constraint_tag = solver.new_constraint_tag(); | ||
| let x = solver.new_named_bounded_integer(0, 0, "x"); | ||
|
|
||
| let result = less_than([x], 0, constraint_tag).post(&mut solver); | ||
| assert_eq!( | ||
| result, | ||
| Err(ConstraintOperationError::InfeasiblePropagator), | ||
| "Expected {result:?} to be an `InfeasiblePropagator` error" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn greater_than_conflict() { | ||
| let mut solver = Solver::default(); | ||
|
|
||
| let constraint_tag = solver.new_constraint_tag(); | ||
| let x = solver.new_named_bounded_integer(0, 0, "x"); | ||
|
|
||
| let result = greater_than([x], 0, constraint_tag).post(&mut solver); | ||
| assert_eq!( | ||
| result, | ||
| Err(ConstraintOperationError::InfeasiblePropagator), | ||
| "Expected {result:?} to be an `InfeasiblePropagator` error" | ||
| ); | ||
| } | ||
| } | ||
|
Comment on lines
-144
to
-178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should not be removed |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be better to create a separate
binary_equalsconstraint for this behaviour, no? Now it is a lot of passing around in places where it does not make sense