final ar
[master.git] / ar / assignment1 / src / a2.py
1 #!/usr/bin/env python3
2 pc = [(4, 2), (4, 2), (4, 2)]
3 rc = [(9, 7), (12, 6), (10, 7), (18, 5), (20, 4), (10, 6), (8, 6), (10, 8)]
4 mx = 29
5 my = 22
6 pd = 17
7
8 # Print variables and preamble
9 print('(benchmark a4.smt')
10 print(':logic QF_UFLIA')
11 print(':extrafuns (')
12 for i, (w, h) in enumerate(pc+rc, 1):
13 print('(c{}x Int)'.format(i), end=' ')
14 print('(c{}y Int)'.format(i), end=' ')
15 print('(c{}w Int)'.format(i), end=' ')
16 print('(c{}h Int)'.format(i))
17 print(')')
18
19 print(':formula')
20 print('(and')
21
22 # Print the PC and RC subformulas
23 for i, (w, h) in enumerate(pc+rc, 1):
24 # Print the width and height
25 print(('(or '
26 '(and (= c{0}w {1}) (= c{0}h {2})) '
27 '(and (= c{0}w {2}) (= c{0}h {1})))').format(i, w-1, h-1))
28 # Print the bounds of the coordinates
29 print(('(> c{0}x 0) (> c{0}y 0)'
30 '(<= (+ c{0}x c{0}w) {1}) (<= (+ c{0}y c{0}h) {2})'
31 ).format(i, mx, my))
32
33 # Print the non overlap with others
34 for j in range(1, 1+len(pc+rc)):
35 if i != j:
36 print((
37 '(or '
38 '(> c{0}x (+ c{1}x c{1}w)) (< (+ c{0}x c{0}w) c{1}x) '
39 '(> c{0}y (+ c{1}y c{1}h)) (< (+ c{0}y c{0}h) c{1}y)'
40 ')').format(i, j))
41
42 # Print the PC distance to eachother
43 for i, _ in enumerate(pc, 1):
44 for j, _ in enumerate(pc, 1):
45 if i != j:
46 print(('(or '
47 '(> (- (+ c{0}x (/ c{0}w 2)) (+ c{1}x (/ c{1}w 2))) {2}) '
48 '(> (- (+ c{1}x (/ c{1}w 2)) (+ c{0}x (/ c{0}w 2))) {2}) '
49 '(> (- (+ c{0}y (/ c{0}h 2)) (+ c{1}y (/ c{1}h 2))) {2}) '
50 '(> (- (+ c{1}y (/ c{1}h 2)) (+ c{0}y (/ c{0}h 2))) {2})'
51 ')').format(i, j, pd))
52
53 # Print the constraint that they have to be connected to a ps
54 for i, _ in enumerate(rc, 1+len(pc)):
55 print('(or')
56 for j, _ in enumerate(pc, 1):
57 print(('(not (or '
58 '(> c{0}x (+ c{1}x 1 c{1}w)) (< (+ c{0}x c{0}w) (- c{1}x 1)) '
59 '(> c{0}y (+ c{1}y 1 c{1}h)) (< (+ c{0}y c{0}h) (- c{1}y 1))'
60 '))').format(i, j))
61 print(')')
62
63 # Close the and,benchmark parenthesis
64 print('))')