Skip to content

add arithm preprocessing to detect trivial cases#1188

Merged
jgFages merged 5 commits intodevelopfrom
JG/preprocessing
Apr 3, 2026
Merged

add arithm preprocessing to detect trivial cases#1188
jgFages merged 5 commits intodevelopfrom
JG/preprocessing

Conversation

@jgFages
Copy link
Copy Markdown
Contributor

@jgFages jgFages commented Apr 3, 2026

No description provided.

@jgFages jgFages requested a review from cprudhom April 3, 2026 08:46
@ArthurGodet
Copy link
Copy Markdown
Collaborator

I agree on the proposed preprocessing. But why are some tests failing due to these changes ?

@jgFages
Copy link
Copy Markdown
Contributor Author

jgFages commented Apr 3, 2026

I agree on the proposed preprocessing. But why are some tests failing due to these changes ?

Ah, those optimization are no longer possible within a dynamic context...
So even the already existing prepocessing below was wrong actually :

default Constraint arithm(IntVar var1, String op, IntVar var2) {
            if (var2.isInstantiated()) {
                return arithm(var1, op, var2.getValue());
            }
            if (var1.isInstantiated()) {
                return arithm(var2, Operator.getFlip(op), var1.getValue());
            }
...

@cprudhom
Copy link
Copy Markdown
Member

cprudhom commented Apr 3, 2026

Wouldn't be better to move this simplification to IntConstraintFactory ?
That's where preprocessing are commonly applied.

@jgFages
Copy link
Copy Markdown
Contributor Author

jgFages commented Apr 3, 2026

Wouldn't be better to move this simplification to IntConstraintFactory ? That's where preprocessing are commonly applied.

It is already in IIntConstraintFactory, perhaps you meant PreProcessing.java ?

return new Arithmetic(var, Operator.get(op), cste);
default Constraint arithm(IntVar x, String op, int cste) {
// this preprocessing is no longer permitted within a dynamical context
if (ref().getSolver().getNodeCount() == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used to use solver.getSearchState() == SearchState.NEW for instance in cstr.impliedBy(bvar).
I would suggest either to call this method or to create a new method with an accurate name that indicates that such preprocessing can be done safely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there exists a method like that: solver.isSolving()

@jgFages jgFages requested a review from cprudhom April 3, 2026 15:15
@jgFages jgFages merged commit 539d7de into develop Apr 3, 2026
22 checks passed
@jgFages jgFages deleted the JG/preprocessing branch April 3, 2026 18:30
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

Successfully merging this pull request may close these issues.

3 participants