From 90effa5431e341cc6ae56de08a43b945f8052ff9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 2 Oct 2014 18:56:08 -0700 Subject: [PATCH] use in-parallel --- csp/constraint.rkt | 2 +- csp/problem.rkt | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/csp/constraint.rkt b/csp/constraint.rkt index 786928eb..ed64eb4b 100644 --- a/csp/constraint.rkt +++ b/csp/constraint.rkt @@ -17,7 +17,7 @@ ;; prune the search space. #t) - (define/public (preProcess variables domains constraints vconstraints) + (define/public (preprocess variables domains constraints vconstraints) ;; Preprocess variable domains ;; This method is called before starting to look for solutions, ;; and is used to prune domains with specific constraint logic diff --git a/csp/problem.rkt b/csp/problem.rkt index 3f6ab6d9..37dc5f64 100644 --- a/csp/problem.rkt +++ b/csp/problem.rkt @@ -1,5 +1,5 @@ #lang racket/base -(require racket/class sugar/container sugar/debug racket/contract racket/match racket/generator) +(require racket/class sugar/container sugar/debug racket/contract racket/match racket/generator racket/list) (require "domain.rkt" "helper.rkt" "constraint.rkt" "solver.rkt") (provide (all-defined-out)) @@ -99,8 +99,7 @@ ;; set up constraints (define constraints - (for/list ([constraint-variables-pair (in-list _constraints)]) - (match-define (list constraint variables) constraint-variables-pair) + (for/list ([(constraint variables) (in-parallel (map first _constraints) (map second _constraints))]) (list constraint (if (null? variables) all-variables variables)))) ;; set up vconstraints @@ -109,13 +108,13 @@ (for/hash ([variable (in-hash-keys variable-domains)]) (values variable null)))) - (for ([constraint-variables-pair (in-list constraints)]) - (match-define (list constraint variables) constraint-variables-pair) + (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))))))) - (for ([constraint-variables-pair (in-list constraints)]) - (match-define (list constraint variables) constraint-variables-pair) - (send constraint preProcess variables variable-domains constraints vconstraints)) + + (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))])