Skip to content
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

[BUG] Fine events may lead to unexpected behavior when used with incremental propagators on initial propagation #1122

Open
cprudhom opened this issue Jan 7, 2025 · 0 comments
Assignees
Labels
Milestone

Comments

@cprudhom
Copy link
Member

cprudhom commented Jan 7, 2025

This small artificial example shows the problem.
An event can be received (and handled) twice: once during initial propagation, the other one during the normal propagation that follows.

private class MyProp extends Propagator{

        BitSet fixed;
        public MyProp(Variable[] vars) {
            super(vars, PropagatorPriority.LINEAR, true);
            fixed = new BitSet(vars.length);
            fixed.clear();
        }

        @Override
        public void propagate(int evtmask) throws ContradictionException {
            for(int i = 0; i < vars.length; i++){
                if(vars[i].isInstantiated()){
                    fixed.set(i);
                }
            }
        }

        @Override
        public void propagate(int idxVarInProp, int mask) throws ContradictionException {
            if(fixed.get(idxVarInProp)){
                throw new UnsupportedOperationException("Should not be called!");
            }
        }

        @Override
        public ESat isEntailed() {
            return TRUE;
        }
    }

    @Test(groups = "1s")
    public void testFineEvents() throws ContradictionException {
        Model m = new Model();
        IntVar[] X = m.intVarArray(2, 0,2);
        X[0].instantiateTo(1, Cause.Null);
        new Constraint("TEST", new MyProp(X)).post();
        m.getSolver().solve();
    }

Fix:

In PropagationEngine.java, update initialize():

    public void initialize() throws SolverException {
        if (!init) {
            notEmpty = 0;
            init = true;
            while (!var_queue.isEmpty()) {
                var_queue.pollFirst().clearEvents();
            }
//...
@cprudhom cprudhom added the bug label Jan 7, 2025
@cprudhom cprudhom self-assigned this Jan 7, 2025
@cprudhom cprudhom added this to the 4.11 milestone Jan 7, 2025
cprudhom added a commit that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant