Search code examples
commitrollbackconstraint-programming

is there a bug in my rollback system?


I have a set of unassigned variables and by branching and propagating I want to find the correct value assignments. When propagation fails, I'll branch back and undo the propagation. To undo the propagation, I use a commit/rollback system, where multiple rollbacks will break through multiple commits. There's a bug, I'm wondering if I'm calling commit and rollback at the right times? propagate(), commit() and rollback() will not interfere with the assignment array.

i = 0;
while (i>=0 && i<var.length) {
    if (assignment[var[i]] == "unassigned") {
        commit();
        assignment[var[i]] = 1;
        if (propagate()) {
            i++;
        }
        continue;
    }
    if (assignment[var[i]] == 1) {
        rollback();
        assignment[var[i]] = 0;
        if (propagate()) {
            i++;
        }
        continue;
    }
    // assignment[var[i]] == 0 
    assignment[var[i]] = "unassigned";
    i--;
}

Somehow I think this should work but on the other hand the bug must be somewhere.


Solution

  • The above code is correct. I found the bug somewhere else.