in-solutions

main
Matthew Butterick 6 years ago
parent 0af5d7e57b
commit 6e942167bf

@ -1,6 +1,6 @@
#lang debug racket #lang debug racket
(require racket/generator graph) (require racket/generator graph)
(provide (all-defined-out)) (provide (except-out (all-defined-out) define/contract))
(define-syntax-rule (define/contract EXPR CONTRACT . BODY) (define-syntax-rule (define/contract EXPR CONTRACT . BODY)
(define EXPR . BODY)) (define EXPR . BODY))
@ -23,7 +23,7 @@
(if (null? argss) (if (null? argss)
(yield (reverse acc)) (yield (reverse acc))
(for ([arg (car argss)]) (for ([arg (car argss)])
(loop (cdr argss) (cons arg acc)))))))) (loop (cdr argss) (cons arg acc))))))))
(struct csp (vars constraints) #:mutable #:transparent) (struct csp (vars constraints) #:mutable #:transparent)
(define constraints csp-constraints) (define constraints csp-constraints)
@ -39,7 +39,7 @@
(raise-argument-error 'constraint "csp" prob)) (raise-argument-error 'constraint "csp" prob))
;; apply proc in many-to-many style ;; apply proc in many-to-many style
(for/and ([args (in-cartesian (map (λ (name) (find-domain prob name)) (constraint-names const)))]) (for/and ([args (in-cartesian (map (λ (name) (find-domain prob name)) (constraint-names const)))])
(apply (constraint-proc const) args)))) (apply (constraint-proc const) args))))
(define name? symbol?) (define name? symbol?)
@ -100,11 +100,11 @@
((csp? procedure? (listof (listof name?))) ((or/c #false name?)) . ->* . void?) ((csp? procedure? (listof (listof name?))) ((or/c #false name?)) . ->* . void?)
(set-csp-constraints! prob (append (constraints prob) (set-csp-constraints! prob (append (constraints prob)
(for/list ([names (in-list namess)]) (for/list ([names (in-list namess)])
(for ([name (in-list names)]) (for ([name (in-list names)])
(check-name-in-csp! 'add-constraints! prob name)) (check-name-in-csp! 'add-constraints! prob name))
(make-constraint names (if proc-name (make-constraint names (if proc-name
(procedure-rename proc proc-name) (procedure-rename proc proc-name)
proc)))))) proc))))))
(define/contract (add-pairwise-constraint! prob proc names [proc-name #false]) (define/contract (add-pairwise-constraint! prob proc names [proc-name #false])
((csp? procedure? (listof name?)) (name?) . ->* . void?) ((csp? procedure? (listof name?)) (name?) . ->* . void?)
@ -143,7 +143,7 @@
(check-name-in-csp! 'find-var prob name) (check-name-in-csp! 'find-var prob name)
(for/first ([vr (in-vars prob)] (for/first ([vr (in-vars prob)]
#:when (eq? name (var-name vr))) #:when (eq? name (var-name vr)))
vr)) vr))
(define/contract (find-domain prob name) (define/contract (find-domain prob name)
(csp? name? . -> . (listof any/c)) (csp? name? . -> . (listof any/c))
@ -186,20 +186,20 @@
(ormap assigned? (constraint-names constraint))) (ormap assigned? (constraint-names constraint)))
(make-csp (vars prob) (make-csp (vars prob)
(for/list ([const (in-constraints prob)]) (for/list ([const (in-constraints prob)])
(cond (cond
;; no point reducing 2-arity functions because they will be consumed by forward checking ;; no point reducing 2-arity functions because they will be consumed by forward checking
[(and (or (not minimum-arity) (<= minimum-arity (constraint-arity const))) [(and (or (not minimum-arity) (<= minimum-arity (constraint-arity const)))
(partially-assigned? const)) (partially-assigned? const))
(match-define (constraint cnames proc) const) (match-define (constraint cnames proc) const)
;; pattern is mix of values and boxed symbols (indicating variables to persist) ;; pattern is mix of values and boxed symbols (indicating variables to persist)
;; use boxes here as cheap way to distinguish id symbols from value symbols ;; use boxes here as cheap way to distinguish id symbols from value symbols
(define arity-reduction-pattern (for/list ([cname (in-list cnames)]) (define arity-reduction-pattern (for/list ([cname (in-list cnames)])
(if (assigned? cname) (if (assigned? cname)
(first (find-domain prob cname)) (first (find-domain prob cname))
(box cname)))) (box cname))))
(constraint (filter-not assigned? cnames) (constraint (filter-not assigned? cnames)
(reduce-function-arity proc arity-reduction-pattern))] (reduce-function-arity proc arity-reduction-pattern))]
[else const])))) [else const]))))
(define nassns 0) (define nassns 0)
(define nfchecks 0) (define nfchecks 0)
@ -214,9 +214,9 @@
(begin0 (begin0
(make-csp (make-csp
(for/list ([vr (in-vars prob)]) (for/list ([vr (in-vars prob)])
(if (eq? name (var-name vr)) (if (eq? name (var-name vr))
(assigned-var name (list val)) (assigned-var name (list val))
vr)) vr))
(constraints prob)) (constraints prob))
(when-debug (set! nassns (add1 nassns))))) (when-debug (set! nassns (add1 nassns)))))
@ -246,7 +246,7 @@
(for/list ([x (in-list xs)] (for/list ([x (in-list xs)]
[val (in-list vals)] [val (in-list vals)]
#:when (= val target-val)) #:when (= val target-val))
x)])) x)]))
(define/contract (argmax* proc xs) (define/contract (argmax* proc xs)
(procedure? (listof any/c) . -> . (listof any/c)) (procedure? (listof any/c) . -> . (listof any/c))
@ -271,7 +271,7 @@
(csp? var? . -> . natural?) (csp? var? . -> . natural?)
(for/sum ([const (in-constraints prob)] (for/sum ([const (in-constraints prob)]
#:when (memq (var-name var) (constraint-names const))) #:when (memq (var-name var) (constraint-names const)))
1)) 1))
(define/contract (domain-length var) (define/contract (domain-length var)
(var? . -> . natural?) (var? . -> . natural?)
@ -280,7 +280,7 @@
(define/contract (state-count csp) (define/contract (state-count csp)
(csp? . -> . natural?) (csp? . -> . natural?)
(for/product ([vr (in-vars csp)]) (for/product ([vr (in-vars csp)])
(domain-length vr))) (domain-length vr)))
(define/contract (mrv-degree-hybrid prob) (define/contract (mrv-degree-hybrid prob)
(csp? . -> . (or/c #f var?)) (csp? . -> . (or/c #f var?))
@ -299,8 +299,8 @@
[cnames (in-value (constraint-names const))] [cnames (in-value (constraint-names const))]
#:when (and (= (length names) (length cnames)) #:when (and (= (length names) (length cnames))
(for/and ([name (in-list names)]) (for/and ([name (in-list names)])
(memq name cnames)))) (memq name cnames))))
const)) const))
(define (one-arity? const) (= 1 (constraint-arity const))) (define (one-arity? const) (= 1 (constraint-arity const)))
(define (two-arity? const) (= 2 (constraint-arity const))) (define (two-arity? const) (= 2 (constraint-arity const)))
@ -314,7 +314,7 @@
((listof (and/c constraint? two-arity?)) . -> . (listof arc?)) ((listof (and/c constraint? two-arity?)) . -> . (listof arc?))
(for*/list ([const (in-list constraints)] (for*/list ([const (in-list constraints)]
[name (in-list (constraint-names const))]) [name (in-list (constraint-names const))])
(arc name const))) (arc name const)))
(require sugar/debug) (require sugar/debug)
(define/contract (reduce-domain prob ark) (define/contract (reduce-domain prob ark)
@ -326,16 +326,16 @@
(λ (val other-val) (constraint-proc other-val val)))) ; otherwise reverse arg order (λ (val other-val) (constraint-proc other-val val)))) ; otherwise reverse arg order
(define (satisfies-arc? val) (define (satisfies-arc? val)
(for/or ([other-val (in-list (find-domain prob other-name))]) (for/or ([other-val (in-list (find-domain prob other-name))])
(proc val other-val))) (proc val other-val)))
(make-csp (make-csp
(for/list ([vr (in-vars prob)]) (for/list ([vr (in-vars prob)])
(cond (cond
[(assigned-var? vr) vr] [(assigned-var? vr) vr]
[(eq? name (var-name vr)) [(eq? name (var-name vr))
(make-var name (match (filter satisfies-arc? (domain vr)) (make-var name (match (filter satisfies-arc? (domain vr))
[(? empty?) (backtrack!)] [(? empty?) (backtrack!)]
[vals vals]))] [vals vals]))]
[else vr])) [else vr]))
(constraints prob))) (constraints prob)))
(define/contract (terminating-at? arcs name) (define/contract (terminating-at? arcs name)
@ -344,7 +344,7 @@
#:when (and #:when (and
(memq name (constraint-names (arc-const arc))) (memq name (constraint-names (arc-const arc)))
(not (eq? name (arc-name arc))))) (not (eq? name (arc-name arc)))))
arc)) arc))
(define/contract (ac-3 prob ref-name) (define/contract (ac-3 prob ref-name)
(csp? name? . -> . csp?) (csp? name? . -> . csp?)
@ -355,8 +355,8 @@
(two-arity-constraints->arcs (for/list ([const (in-constraints prob)] (two-arity-constraints->arcs (for/list ([const (in-constraints prob)]
#:when (and (two-arity? const) #:when (and (two-arity? const)
(for/and ([cname (in-list (constraint-names const))]) (for/and ([cname (in-list (constraint-names const))])
(memq cname checkable-names)))) (memq cname checkable-names))))
const))) const)))
(for/fold ([prob prob] (for/fold ([prob prob]
[arcs (sort starting-arcs < #:key (λ (a) (length (find-domain prob (arc-name a)))) #:cache-keys? #true)] [arcs (sort starting-arcs < #:key (λ (a) (length (find-domain prob (arc-name a)))) #:cache-keys? #true)]
#:result (prune-singleton-constraints prob)) #:result (prune-singleton-constraints prob))
@ -386,10 +386,10 @@
(define new-vals (define new-vals
(for/list ([val (in-list vals)] (for/list ([val (in-list vals)]
#:when (for/and ([const (in-list constraints)]) #:when (for/and ([const (in-list constraints)])
(match const (match const
[(constraint (list (== name eq?) _) proc) (proc val ref-val)] [(constraint (list (== name eq?) _) proc) (proc val ref-val)]
[(constraint _ proc) (proc ref-val val)]))) [(constraint _ proc) (proc ref-val val)])))
val)) val))
(checked-variable name new-vals (cons (cons ref-name ref-val) (match vr (checked-variable name new-vals (cons (cons ref-name ref-val) (match vr
[(checked-variable _ _ history) history] [(checked-variable _ _ history) history]
[_ null])))])])) [_ null])))])]))
@ -398,15 +398,15 @@
((csp?) ((or/c #false name?)) . ->* . csp?) ((csp?) ((or/c #false name?)) . ->* . csp?)
(define singleton-var-names (for/list ([vr (in-vars prob)] (define singleton-var-names (for/list ([vr (in-vars prob)]
#:when (singleton-var? vr)) #:when (singleton-var? vr))
(var-name vr))) (var-name vr)))
(make-csp (make-csp
(vars prob) (vars prob)
(for/list ([const (in-constraints prob)] (for/list ([const (in-constraints prob)]
#:unless (and (two-arity? const) #:unless (and (two-arity? const)
(or (not ref-name) (constraint-relates? const ref-name)) (or (not ref-name) (constraint-relates? const ref-name))
(for/and ([cname (in-list (constraint-names const))]) (for/and ([cname (in-list (constraint-names const))])
(memq cname singleton-var-names)))) (memq cname singleton-var-names))))
const))) const)))
(define/contract (forward-check prob ref-name) (define/contract (forward-check prob ref-name)
(csp? name? . -> . csp?) (csp? name? . -> . csp?)
@ -415,7 +415,7 @@
;; conflict-set will be empty if there are no empty domains (as we would hope) ;; conflict-set will be empty if there are no empty domains (as we would hope)
(define conflict-set (for/list ([cvr (in-list checked-vars)] (define conflict-set (for/list ([cvr (in-list checked-vars)]
#:when (empty? (domain cvr))) #:when (empty? (domain cvr)))
(history cvr))) (history cvr)))
;; for conflict-directed backjumping it's essential to forward-check ALL vars ;; for conflict-directed backjumping it's essential to forward-check ALL vars
;; (even after an empty domain is generated) and combine their conflicts ;; (even after an empty domain is generated) and combine their conflicts
;; so we can discover the *most recent past var* that could be the culprit. ;; so we can discover the *most recent past var* that could be the culprit.
@ -432,7 +432,7 @@
;; constraint is checkable if all constraint names ;; constraint is checkable if all constraint names
;; are in target list of names. ;; are in target list of names.
(for/and ([cname (in-list (constraint-names const))]) (for/and ([cname (in-list (constraint-names const))])
(memq cname names))) (memq cname names)))
(define/contract (constraint-arity const) (define/contract (constraint-arity const)
(constraint? . -> . natural?) (constraint? . -> . natural?)
@ -449,21 +449,21 @@
(partition (λ (const) (and (constraint-checkable? const assigned-varnames) (partition (λ (const) (and (constraint-checkable? const assigned-varnames)
(or (not mandatory-names) (or (not mandatory-names)
(for/and ([name (in-list mandatory-names)]) (for/and ([name (in-list mandatory-names)])
(constraint-relates? const name))))) (constraint-relates? const name)))))
(constraints prob))) (constraints prob)))
(cond (cond
[conflict-count? [conflict-count?
(define conflict-count (define conflict-count
(for/sum ([constraint (in-list checkable-consts)] (for/sum ([constraint (in-list checkable-consts)]
#:unless (constraint prob)) #:unless (constraint prob))
1)) 1))
(when-debug (set! nchecks (+ conflict-count nchecks))) (when-debug (set! nchecks (+ conflict-count nchecks)))
conflict-count] conflict-count]
[else [else
(for ([(constraint idx) (in-indexed checkable-consts)] (for ([(constraint idx) (in-indexed checkable-consts)]
#:unless (constraint prob)) #:unless (constraint prob))
(when-debug (set! nchecks (+ (add1 idx) nchecks))) (when-debug (set! nchecks (+ (add1 idx) nchecks)))
(backtrack!)) (backtrack!))
;; discard checked constraints, since they have no further reason to live ;; discard checked constraints, since they have no further reason to live
(make-csp (vars prob) other-consts)])) (make-csp (vars prob) other-consts)]))
@ -475,19 +475,19 @@
prob prob
(make-csp (make-csp
(for/list ([vr (in-vars prob)]) (for/list ([vr (in-vars prob)])
(match-define (var name vals) vr) (match-define (var name vals) vr)
(define name-constraints (filter (λ (const) (constraint-relates? const name)) unary-constraints)) (define name-constraints (filter (λ (const) (constraint-relates? const name)) unary-constraints))
(make-var name (for/list ([val (in-list vals)] (make-var name (for/list ([val (in-list vals)]
#:when (for/and ([const (in-list name-constraints)]) #:when (for/and ([const (in-list name-constraints)])
((constraint-proc const) val))) ((constraint-proc const) val)))
val))) val)))
other-constraints))) other-constraints)))
(define ((make-hist-proc assocs) . xs) (define ((make-hist-proc assocs) . xs)
(not (not
(for/and ([x (in-list xs)] (for/and ([x (in-list xs)]
[val (in-list (map cdr assocs))]) [val (in-list (map cdr assocs))])
(equal? x val)))) (equal? x val))))
(define/contract (backtracking-solver (define/contract (backtracking-solver
prob prob
@ -508,7 +508,7 @@
(and (backtrack? exn) (or (let ([bths (backtrack-histories exn)]) (and (backtrack? exn) (or (let ([bths (backtrack-histories exn)])
(or (empty? bths) (for*/or ([bth bths] (or (empty? bths) (for*/or ([bth bths]
[rec bth]) [rec bth])
(eq? name (car rec)))))))) (eq? name (car rec))))))))
(for/fold ([conflicts null] (for/fold ([conflicts null]
#:result (void)) #:result (void))
([val (in-list (order-domain-values domain))]) ([val (in-list (order-domain-values domain))])
@ -518,7 +518,7 @@
(append conflicts (remq name (remove-duplicates (append conflicts (remq name (remove-duplicates
(for*/list ([bth (in-list bths)] (for*/list ([bth (in-list bths)]
[rec (in-list bth)]) [rec (in-list bth)])
(car rec)) eq?))))]) (car rec)) eq?))))])
(let* ([prob (assign-val prob name val)] (let* ([prob (assign-val prob name val)]
;; reduce constraints before inference, ;; reduce constraints before inference,
;; to create more forward-checkable (binary) constraints ;; to create more forward-checkable (binary) constraints
@ -560,9 +560,9 @@
((csp?) (integer?) . ->* . generator?) ((csp?) (integer?) . ->* . generator?)
(generator () (generator ()
(for ([thread-count (or (current-thread-count) 1)]) ; todo: what is ideal thread count? (for ([thread-count (or (current-thread-count) 1)]) ; todo: what is ideal thread count?
(make-min-conflcts-thread prob thread-count max-steps)) (make-min-conflcts-thread prob thread-count max-steps))
(for ([i (in-naturals)]) (for ([i (in-naturals)])
(yield (thread-receive))))) (yield (thread-receive)))))
(define/contract (optimal-stop-min proc xs) (define/contract (optimal-stop-min proc xs)
(procedure? (listof any/c) . -> . any/c) (procedure? (listof any/c) . -> . any/c)
@ -570,7 +570,7 @@
(define threshold (argmin proc sample)) (define threshold (argmin proc sample))
(or (for/first ([candidate (in-list candidates)] (or (for/first ([candidate (in-list candidates)]
#:when (<= (proc candidate) threshold)) #:when (<= (proc candidate) threshold))
candidate) candidate)
(last candidates))) (last candidates)))
(define/contract (conflicted-variable-names prob) (define/contract (conflicted-variable-names prob)
@ -578,7 +578,7 @@
;; Return a list of variables in current assignment that are conflicted ;; Return a list of variables in current assignment that are conflicted
(for/list ([name (in-var-names prob)] (for/list ([name (in-var-names prob)]
#:when (positive? (nconflicts prob name))) #:when (positive? (nconflicts prob name)))
name)) name))
(define/contract (min-conflicts-value prob name vals) (define/contract (min-conflicts-value prob name vals)
(csp? name? (listof any/c) . -> . any/c) (csp? name? (listof any/c) . -> . any/c)
@ -587,7 +587,7 @@
#:cache-keys? #true)) #:cache-keys? #true))
(for/first ([val (in-list vals-by-conflict)] (for/first ([val (in-list vals-by-conflict)]
#:unless (equal? val (first (find-domain prob name)))) ;; but change the value #:unless (equal? val (first (find-domain prob name)))) ;; but change the value
val)) val))
(define no-value-sig (gensym)) (define no-value-sig (gensym))
@ -602,11 +602,11 @@
((csp?) ((listof name?)) . ->* . (listof (cons/c name? any/c))) ((csp?) ((listof name?)) . ->* . (listof (cons/c name? any/c)))
(define assocs (define assocs
(for/list ([vr (in-vars prob)]) (for/list ([vr (in-vars prob)])
(match vr (match vr
[(var name (list val)) (cons name val)]))) [(var name (list val)) (cons name val)])))
(if keys (if keys
(for/list ([key (in-list keys)]) (for/list ([key (in-list keys)])
(assq key assocs)) (assq key assocs))
assocs)) assocs))
(define/contract (combine-csps probs) (define/contract (combine-csps probs)
@ -621,45 +621,51 @@
(make-csp (make-csp
(for/list ([vr (in-vars prob)] (for/list ([vr (in-vars prob)]
#:when (memq (var-name vr) names)) #:when (memq (var-name vr) names))
vr) vr)
(for/list ([const (in-constraints prob)] (for/list ([const (in-constraints prob)]
#:when (for/and ([cname (in-list (constraint-names const))]) #:when (for/and ([cname (in-list (constraint-names const))])
(memq cname names))) (memq cname names)))
const))) const)))
(define/contract (solve* prob (define (decompose-prob prob)
; decompose into independent csps. `cc` determines "connected components"
(if (current-decompose)
(for/list ([nodeset (in-list (cc (csp->graph prob)))])
(extract-subcsp prob nodeset))
(list prob)))
(define (make-solution-generator prob)
(generator ()
(define subprobs (decompose-prob prob))
(define solgens (map (current-solver) subprobs))
(define solstreams (for/list ([solgen (in-list solgens)])
(for/stream ([sol (in-producer solgen (void))])
sol)))
(for ([solution-pieces (in-cartesian solstreams)])
(yield (combine-csps solution-pieces)))))
(define-syntax-rule (in-solutions PROB)
(in-producer (make-solution-generator PROB) (void)))
(define/contract (solve* prob [max-solutions +inf.0]
#:finish-proc [finish-proc (λ (p) (csp->assocs p (map var-name (vars prob))))] #:finish-proc [finish-proc (λ (p) (csp->assocs p (map var-name (vars prob))))]
#:solver [solver (or (current-solver) backtracking-solver)] #:solver [solver #f])
#:count [max-solutions +inf.0]) ((csp?) (natural? #:finish-proc procedure? #:solver procedure?) . ->* . (listof any/c))
((csp?) (#:finish-proc procedure? #:solver procedure? #:count natural?)
. ->* . (listof any/c))
(when-debug (reset-nassns!) (reset-nfchecks!) (reset-nchecks!)) (when-debug (reset-nassns!) (reset-nfchecks!) (reset-nchecks!))
(define subcsps ; decompose into independent csps. `cc` determines "connected components" (parameterize ([current-solver (or solver (current-solver) backtracking-solver)])
(if (current-decompose) (for/list ([sol (in-solutions prob)]
(for/list ([nodeset (in-list (cc (csp->graph prob)))]) [idx (in-range max-solutions)])
(extract-subcsp prob nodeset)) (finish-proc sol))))
(list prob)))
(define solgens (map solver subcsps))
(define solstreams (for/list ([solgen (in-list solgens)])
(for/stream ([sol (in-producer solgen (void))])
sol)))
(for/list ([solution-pieces (in-cartesian solstreams)]
[idx (in-range max-solutions)])
(finish-proc (combine-csps solution-pieces))))
(define/contract (solve prob (define/contract (solve prob
#:finish-proc [finish-proc (λ (p) (csp->assocs p (map var-name (vars prob))))] #:finish-proc [finish-proc (λ (p) (csp->assocs p (map var-name (vars prob))))]
#:solver [solver (or (current-solver) backtracking-solver)] #:solver [solver #f])
#:count [max-solutions 1]) ((csp?) (#:finish-proc procedure? #:solver procedure?)
((csp?) (#:finish-proc procedure? #:solver procedure? #:count natural?)
. ->* . (or/c #false any/c)) . ->* . (or/c #false any/c))
(match (solve* prob #:finish-proc finish-proc #:solver solver #:count max-solutions) (match (solve* prob 1 #:finish-proc finish-proc #:solver solver)
[(list solution) solution] [(list solution) solution]
[(list) #false] [_ #false]))
[(list solutions ...) solutions]))
(define (<> a b) (not (= a b))) (define (<> a b) (not (= a b)))
(define (neq? a b) (not (eq? a b))) (define (neq? a b) (not (eq? a b)))

@ -8,7 +8,7 @@
@(define-syntax-rule (my-examples ARG ...) @(define-syntax-rule (my-examples ARG ...)
(examples #:label #f #:eval my-eval ARG ...)) (examples #:label #f #:eval my-eval ARG ...))
@title{Constraint-satisfaction problems} @title{Constraint-satisfaction problems (and how to solve them)}
@author[(author+email "Matthew Butterick" "mb@mbtype.com")] @author[(author+email "Matthew Butterick" "mb@mbtype.com")]
@ -120,11 +120,11 @@ We should use @racket[solve*] with care. It can't finish until the CSP solver e
(state-count triples) (state-count triples)
] ]
It's easy for a CSP to have a state count in the zillions. For this reason we can supply @racket[solve*] with an optional @racket[#:count] argument that will only generate a certain number of solutions: It's easy for a CSP to have a state count in the zillions. For this reason we can supply @racket[solve*] with an optional argument that will only generate a certain number of solutions:
@examples[#:label #f #:eval my-eval @examples[#:label #f #:eval my-eval
(time (solve* triples)) (time (solve* triples))
(time (solve* triples #:count 2)) (time (solve* triples 2))
] ]
Here, the answers are the same. But the second call to @racket[solve*] finishes sooner, because it quits as soon as it's found two solutions. Here, the answers are the same. But the second call to @racket[solve*] finishes sooner, because it quits as soon as it's found two solutions.
@ -159,7 +159,7 @@ The whole example in one block:
(add-constraint! triples <= '(a b)) (add-constraint! triples <= '(a b))
(solve* triples #:count 2) (solve* triples 2)
] ]
@section{Interlude} @section{Interlude}
@ -282,19 +282,21 @@ TK
} }
@defproc[(solve @defproc[(solve
[prob csp?] [prob csp?] )
[#:count count natural? 1])
(or/c #false any/c (listof any/c))]{ (or/c #false any/c (listof any/c))]{
TK TK
} }
@defproc[(solve* @defproc[(solve*
[prob csp?] [prob csp?]
[#:count count natural? +inf.0]) [count natural? +inf.0])
(listof any/c)]{ (listof any/c)]{
TK TK
} }
@defform[(in-solutions prob)]{
TK
}
@section{Sideshows} @section{Sideshows}

Loading…
Cancel
Save