-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
133 changed files
with
5,742 additions
and
4,668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,36 @@ | ||
#lang racket | ||
|
||
(require "../inst.rkt" "../enumerator.rkt") | ||
(require "../inst.rkt" "../enumerator.rkt" "GA-machine.rkt") | ||
(require racket/generator) | ||
|
||
(provide GA-enumerator%) | ||
|
||
(define GA-enumerator% | ||
(class enumerator% | ||
(super-new) | ||
(init-field machine printer) | ||
(override get-flag generate-inst) | ||
|
||
(inherit-field machine) | ||
|
||
(define opcodes (get-field opcodes machine)) | ||
(define arith-inst | ||
(map (lambda (x) (vector-member x opcodes)) '(+* 2* 2/ - + and or drop))) | ||
(define mem-inst | ||
(map (lambda (x) (vector-member x opcodes)) '(! !b @ @b))) | ||
|
||
(define-syntax-rule (min-list x) (foldl min (car x) (cdr x))) | ||
(define-syntax-rule (max-list x) (foldl max (car x) (cdr x))) | ||
(map (lambda (x) (vector-member x opcodes)) '(! !+ !b @ @+ @b))) | ||
|
||
;; Since we don't use live-in and live-out to prune the search space here, we just return #f for both of them. | ||
(define (generate-inst | ||
live-in live-out flag-in flag-out | ||
#:no-args [no-args #f] #:try-cmp [try-cmp #f]) | ||
(define const-range (get-field const-range machine)) | ||
;; (define inst-choice '(drop @p b! !b)) | ||
;; (define opcode-pool (map (lambda (x) (vector-member x opcodes)) inst-choice)) | ||
(define opcode-pool (get-field opcode-pool machine)) | ||
(when no-args | ||
(set! opcode-pool | ||
(filter (lambda (x) (member x arith-inst)) opcode-pool))) | ||
(when (and flag-in flag-out) | ||
(cond | ||
[(= (add1 flag-in) (min-list flag-out)) | ||
(set! opcode-pool (filter (lambda (x) (member x mem-inst)) opcode-pool))] | ||
[(< flag-in (min-list flag-out)) (set! opcode-pool (list))] | ||
[(> flag-in (max-list flag-out)) (set! opcode-pool (list))] | ||
)) | ||
|
||
(generator | ||
() | ||
(for ([opcode-id opcode-pool]) | ||
(let ([opcode-name (vector-ref opcodes opcode-id)]) | ||
(cond | ||
[(equal? opcode-name `nop) (void)] | ||
[(equal? opcode-name `@p) | ||
(for ([c const-range]) | ||
(yield (list (inst opcode-id c) #f #f)))] | ||
[else | ||
(yield (list (inst opcode-id #f) #f #f))]))) | ||
(yield (list #f #f #f)))) | ||
(define/override (filter-with-pruning-info opcode-pool prune-in prune-out | ||
#:try-cmp [try-cmp #f] #:no-args [no-args #f]) | ||
(define-syntax-rule (min-list x) (foldl min (car x) (cdr x))) | ||
(define-syntax-rule (max-list x) (foldl max (car x) (cdr x))) | ||
(cond | ||
[(and prune-in prune-out) | ||
(cond | ||
[(= (add1 prune-in) (min-list prune-out)) | ||
(filter (lambda (x) (member x mem-inst)) opcode-pool)] | ||
[(< prune-in (min-list prune-out)) (list)] | ||
[(> prune-in (max-list prune-out)) (list)] | ||
[else opcode-pool] | ||
) | ||
] | ||
|
||
[else opcode-pool])) | ||
|
||
(define (get-flag state-vec) (length (vector-ref state-vec 9))) | ||
(define/override (get-pruning-info state-vec) (get-field index (progstate-comm state-vec))) | ||
|
||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.