Changeset 29450 in project


Ignore:
Timestamp:
07/29/13 14:43:22 (6 years ago)
Author:
Peter Danenberg
Message:

Document success?', xor', `random-map'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/aima

    r29395 r29450  
    157157* [[#csp-domains]]
    158158* [[#csp-neighbors]]
     159* [[#failure]]
    159160* [[#failure?]]
    160161* [[#inference]]
    161162* [[#make-csp]]
    162163* [[#neq?]]
     164* [[#random-map]]
     165* [[#set-alldiff-constraints!]]
     166* [[#set-bidirectional-constraint!]]
     167* [[#set-pairwise-bidirectional-constraints!]]
     168* [[#set-pairwise-constraints!]]
     169* [[#set-domains!]]
    163170* [[#success?]]
    164171* [[#xor]]
     
    266273; y : Comparator
    267274<enscript highlight="scheme">(define neq? (complement eq?))
     275</enscript>
     276==== {{random-map}}
     277<procedure>(random-map n) → hash-table</procedure>
     278Create a random k-coloring problem; returns an adjacency-list of
     279nodes as a hash-table.
     280; n : The number of nodes in the problem
     281<enscript highlight="scheme">(define (random-map n)
     282  (let ((random-points (random-points n)) (connections (make-hash-table)))
     283    (let iter-point ((points random-points) (modified? #f))
     284      (if (null? points)
     285        (if modified? (iter-point (shuffle random-points) #f) connections)
     286        (let ((point (car points)))
     287          (let iter-counter-point ((counter-points
     288                                     (sort-by-proximity
     289                                       point
     290                                       (delete point random-points))))
     291            (if (null? counter-points)
     292              (iter-point (cdr points) modified?)
     293              (let ((counter-point (car counter-points)))
     294                (if (member
     295                      point
     296                      (hash-table-ref/default connections counter-point '()))
     297                  (iter-counter-point (cdr counter-points))
     298                  (if (intersects-other? connections point counter-point)
     299                    (iter-counter-point (cdr counter-points))
     300                    (begin
     301                      (hash-table-update!/default
     302                        connections
     303                        point
     304                        (lambda (counter-points)
     305                          (lset-adjoin eq? counter-points counter-point))
     306                        '())
     307                      (hash-table-update!/default
     308                        connections
     309                        counter-point
     310                        (lambda (points) (lset-adjoin eq? points point))
     311                        '())
     312                      (iter-point (cdr points) #t))))))))))))
    268313</enscript>
    269314=== AIMA-Tessellation
Note: See TracChangeset for help on using the changeset viewer.