chickadee » aima » backtracking-enumeration

backtracking-enumeration cspprocedure
backtracking-enumeration n cspprocedure
backtracking-enumeration csp cons nil stop?procedure

Enumerate up to n solutions of the csp; enumerate all if n is #f or unspecified.

n
Enumerate up to n solutions
csp
The CSP to solve
cons
How to construct enumerations (cons by default)
nil
Base enumeration (() by default)
stop?
Unary function taking the current enumeration: #t stops, #f continues; by default, compares n to the length of the current enumeration.
(define backtracking-enumeration
  (case-lambda
    ((csp) (backtracking-enumeration #f csp))
    ((n csp)
     (backtracking-enumeration
       csp
       cons
       '()
       (lambda (enumeration) (and n (= (length enumeration) n)))))
    ((csp cons nil stop?)
     (let ((enumeration (make-parameter nil)))
       (backtrack-enumerate enumeration (make-assignment csp) csp cons stop?)
       (enumeration)))))