diff --git a/csp/constraint.rkt b/csp/constraint.rkt index 7cb337ec..11e630f8 100644 --- a/csp/constraint.rkt +++ b/csp/constraint.rkt @@ -137,7 +137,8 @@ (check-equal? (get-field _variables (new Problem)) (make-hash)) (define problem (new Problem)) ;; test from line 125 - (send problem addVariable "a" '(1)) + (send problem addVariable "ab" '(1 2)) + (send problem addVariable "c" '(3)) ; (check-equal? (get-field _list (hash-ref (get-field _variables problem) "a")) '(1)) (displayln (format "The solution to ~a is ~a" @@ -180,6 +181,22 @@ (set! _hidden null) (set! _states null)) + (define/public (pushState) + ;; Save current domain state + ;; Variables hidden after that call are restored when that state + ;; is popped from the stack. + (py-append! _states (length _list))) + + (define/public (popState) + ;; Restore domain state from the top of the stack + + ;; Variables hidden since the last popped state are then available + ;; again. + (define diff (- (py-pop! _states) (length _list))) + (when (not (= 0 diff)) + (py-extend! _list (take-right _hidden diff)) + (set! _hidden (take _hidden (- (length _hidden) diff))))) + (define/public (domain-pop!) (py-pop! _list)) diff --git a/csp/python-constraint/testconstraint.py b/csp/python-constraint/testconstraint.py index 186fc7c2..a5093279 100644 --- a/csp/python-constraint/testconstraint.py +++ b/csp/python-constraint/testconstraint.py @@ -3,5 +3,6 @@ from constraint import * p = Problem() -p.addVariable("a", [1]) +p.addVariable("ab", [1, 2]) +p.addVariable("c", [3]) print p.getSolutions() \ No newline at end of file