Skip to content

Commit

Permalink
Add unposting of new constraints on backtrack
Browse files Browse the repository at this point in the history
  • Loading branch information
Whebon committed Apr 24, 2024
1 parent 95f44ad commit f8ce924
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/solver/uniform_solver/uniform_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ function post!(solver::UniformSolver, constraint::AbstractLocalConstraint)
return
end
#if the was not deactivated after initial propagation, it can be added to the list of constraints
@assert constraint keys(solver.isactive) "Attempted to post a constraint that was already posted before"
solver.isactive[constraint] = StateInt(solver.sm, 1)
if (constraint keys(solver.isactive))
@assert solver.isactive[constraint] == 0 "Attempted to post a constraint that is already active"
else
solver.isactive[constraint] = StateInt(solver.sm, 0) #initializing the state int as 0 will deactivate it on backtrack
end
set_value!(solver.isactive[constraint], 1)
end


Expand Down
9 changes: 9 additions & 0 deletions test/test_state_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@
@test get_value(a) == 10
@test get_value(b) == 100
end

@testset "behavior needed for constraint unposting" begin
sm = HerbConstraints.StateManager()
save_state!(sm)
a = StateInt(sm, 0) # initialize a new state int, set its value to 0 (post a new constraint)
set_value!(a, 1) # immediately update the state int to 1 (activate the newly posted constraint)
restore!(sm)
@test get_value(a) == 0 # on backtrack, the new constraint should be deactivated
end
end

0 comments on commit f8ce924

Please sign in to comment.