main
Matthew Butterick 10 years ago
parent ca718a9a0f
commit d5fe7ec60c

@ -78,43 +78,23 @@
(let loop2 () (let loop2 ()
;; We have a variable. Do we have any values left? ;; We have a variable. Do we have any values left?
(when (null? values) (when (null? values)
;; No. Go back to last variable, if there's one. ;; No. Go back to last variable, if there's one, else exit.
(hash-remove! assignments variable)
(if #f
(for/or ([i (in-naturals)]) (for/or ([i (in-naturals)])
(hash-remove! assignments variable)
(when (null? queue) (set! want-to-return #t) (return-k)) (when (null? queue) (set! want-to-return #t) (return-k))
(set!-values (variable values pushdomains) (pop-vvp-values! queue)) (set!-values (variable values pushdomains) (pop-vvp-values! queue))
(for-each-send pop-state pushdomains) (for-each-send pop-state pushdomains)
(if (not (null? values)) (not (null? values))))
#t
(hash-remove! assignments variable)))
(let/ec break-loop3
(let loop ()
(when (null? queue)
(set! want-to-return #t)
(return-k))
(set!-values (variable values pushdomains) (pop-vvp-values! queue))
(for-each-send pop-state pushdomains)
(when (not (null? values)) (break-loop3))
(hash-remove! assignments variable)
(loop)))
)
)
;; Got a value. Check it. ;; Got a value. Check it.
(hash-set! assignments variable (car-pop! values)) (hash-set! assignments variable (car-pop! values))
(for-each-send push-state pushdomains) (for-each-send push-state pushdomains)
(let/ec break-for-loop (let/ec break-for-loop
(for ([cvpair (in-list (hash-ref vconstraints variable))]) (if (for/or ([cvpair (in-list (hash-ref vconstraints variable))])
(match-define (list constraint variables) cvpair) (match-define (list constraint variables) cvpair)
(define the_result (send constraint call variables domains assignments pushdomains)) (not (send constraint call variables domains assignments pushdomains)))
(when (not the_result) ; Value is not good. (break-for-loop)
(break-for-loop))) (break-loop2)))
(break-loop2))
(for-each-send pop-state pushdomains) (for-each-send pop-state pushdomains)
(loop2))) (loop2)))

Loading…
Cancel
Save