From 072466ecc78bc67c642b8d097ab461c0970d4b86 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 1 Oct 2014 17:19:52 -0700 Subject: [PATCH] works, a little --- csp/constraint.rkt | 19 ++++++++++++++++++- csp/python-constraint/testconstraint.py | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) 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