-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.rkt
More file actions
79 lines (71 loc) · 3.2 KB
/
core.rkt
File metadata and controls
79 lines (71 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#lang rosette
(require "helper.rkt")
(provide (all-defined-out))
(define (elim model)
(if (unsat? model) #f model))
(define (find-model solver l r (debug #f))
(displayln "Start...")
(and (<= l r)
(printf "finding model for [~a, ~a]\n" l r)
(let* ([mid (quotient (+ l r) 2)])
(define model (solver mid))
(printf "model for [~a, ~a] is ~aSAT\n" l r (if (unsat? model) "UN" ""))
(if (= l r)
(elim model)
(if (unsat? model)
(find-model solver l (- mid 1))
(or (find-model solver mid r) model))))))
;; this uses a binary search in its algorithm
(define (solve-graph generator algo size model-solver (size-limit (* size size)))
(define graph (generator size))
(define partial-model-solver (model-solver algo graph size-limit))
(define (find-model l r)
(printf "finding for [~a, ~a]\n" l r)
(and (<= l r)
(let* ([mid (quotient (+ l r) 2)]
[model (time (partial-model-solver mid))])
(printf "model for [~a, ~a] is ~asatisfiable\n" l r (if (unsat? model) "un" ""))
(if (= l r)
(elim model)
(if (unsat? model)
(find-model l (- mid 1))
(or (find-model (+ mid 1) r) model))))))
(define model (find-model 1 size-limit))
(vector-map (curry vector-map (λ (x) (if (expression? x) bv1 x))) (evaluate graph model)))
;; this uses the strategy of evaluating the algorithm everytime to get a tighter
;; bound on the size limit
(define (solve-graph+ generator algo size model-solver (size-limit (* size size)))
(define graph #f)
(define (elim model) (if (unsat? model) #f model))
(define (find-model l r)
(printf "finding for [~a, ~a]\n" l r)
(and (<= l r)
(let* ([mid (quotient (+ l r) 2)]
[graph+ (generator size)]
[model (time ((model-solver algo graph+ (+ mid 1)) mid))])
(when (sat? model) (set! graph graph+))
(printf "model for [~a, ~a] is ~asatisfiable\n" l r (if (unsat? model) "un" ""))
(if (= l r)
(elim model)
(if (unsat? model)
(find-model l (- mid 1))
(or (find-model (+ mid 1) r) model))))))
(define model (find-model 1 size-limit))
(vector-map (curry vector-map (λ (x) (if (expression? x) bv1 x))) (evaluate graph model)))
;; this uses the strategy of incremental solving
(define (solve-graph++ generator algo size (size-limit (* size size)))
(define graph (generator size))
(define (elim model) (if (unsat? model) #f model))
(define-symbolic* symbolic-cost integer?)
;(define symbolic-cost (algo graph 0 size-limit))
(define inc (solve+))
(inc (= symbolic-cost (algo graph 0 size-limit)))
(define (find-model cost)
(printf "finding for cost ~a\n" cost)
(and (<= cost size-limit)
(let* ([model (time (inc (>= symbolic-cost cost)))])
(printf "model for cost ~a is ~asatisfiable\n" cost (if (unsat? model) "un" ""))
(if (sat? model)
(or (find-model (+ cost 1)) model) #f))))
(define model (find-model 1))
(vector-map (curry vector-map (λ (x) (if (expression? x) bv1 x))) (evaluate graph model)))