main
Matthew Butterick 10 years ago
parent 90effa5431
commit b5ceb26f8b

@ -59,7 +59,7 @@
(for ([value (in-list (get-field _list domain))])
(hash-set! assignments unassignedvariable value)
(when (not (send this call variables domains assignments))
(send domain hideValue value)))
(send domain hide-value value)))
(hash-remove! assignments unassignedvariable))
(when (null? (get-field _list domain))
(set! return-result #f)
@ -125,7 +125,7 @@
(set! domain (hash-ref domains variable))
(for ([value (in-hash-keys seen)])
(when (value . in? . (get-field _list (hash-ref domains variable)))
(send domain hideValue value)
(send domain hide-value value)
(when (null? (get-field _list (hash-ref domains variable)))
(set! return-value #f)
(return-k)))))))
@ -166,7 +166,7 @@
(return-k))
(for ([value (in-list (get-field _list domain))])
(when (not (equal? value singlevalue))
(send domain hideValue value))))))
(send domain hide-value value))))))
(set! return-value #t)
(return-k))
return-value)))

@ -17,19 +17,19 @@
(define/public (custom-display out) (displayln (repr) out))
(define/public (custom-write out) (write (repr) out))
(define/public (resetState)
(define/public (reset-state)
;; Reset to the original domain state, including all possible values
(py-extend! _list _hidden)
(set! _hidden null)
(set! _states null))
(define/public (pushState)
(define/public (push-state)
;; 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)
(define/public (pop-state)
;; Restore domain state from the top of the stack
;; Variables hidden since the last popped state are then available
@ -39,7 +39,7 @@
(py-extend! _list (take-right _hidden diff))
(set! _hidden (take _hidden (- (length _hidden) diff)))))
(define/public (hideValue value)
(define/public (hide-value value)
;; Hide the given value from the domain
;; After that call the given value won't be seen as a possible value

@ -110,18 +110,19 @@
(for ([(constraint variables) (in-parallel (map first constraints) (map second constraints))])
(for ([variable (in-list variables)])
(hash-update! vconstraints variable (λ(val) (append val (list (list constraint variables)))))))
(hash-update! vconstraints variable (λ(val) (cons (list constraint variables) val)))))
;;(hash-update! vconstraints variable (λ(val) (append val (list (list constraint variables)))))))
(for ([(constraint variables) (in-parallel (map first constraints) (map second constraints))])
(send constraint preprocess variables variable-domains constraints vconstraints))
(define result #f)
(let/ec done
(for ([domain (in-list (hash-values variable-domains))])
(send domain resetState)
(when (not domain)
(define result (void))
(let/ec break
(for/last ([domain (in-hash-values variable-domains)])
(send domain reset-state)
(when (null? (get-field _list domain))
(set! result (list null null null))
(done)))
(break)))
(set! result (list variable-domains constraints vconstraints)))
(apply values result))

@ -71,7 +71,7 @@
(set-field! _list values (second variable-values-pushdomains))
(set! pushdomains (third variable-values-pushdomains))
(for ([domain (in-list pushdomains)])
(send domain popState)))
(send domain pop-state)))
;(report variable variable-preloop-2)
;(report assignments assignments-preloop-2)
@ -96,7 +96,7 @@
(set! pushdomains (third variable-values-pushdomains))
(when (not (null? pushdomains))
(for ([domain (in-list pushdomains)])
(send domain popState)))
(send domain pop-state)))
(when (not (null? (get-field _list values))) (break-loop3))
(hash-remove! assignments variable)
(loop3))
@ -108,7 +108,7 @@
(hash-set! assignments variable (send values domain-pop!))
(for ([domain (in-list pushdomains)])
(send domain pushState))
(send domain push-state))
;(report pushdomains pushdomains1)
;(report domains domains1)
@ -126,7 +126,7 @@
(break-loop2)))
(for ([domain (in-list pushdomains)])
(send domain popState))
(send domain pop-state))
(loop2)))

Loading…
Cancel
Save