diff options
-rwxr-xr-x | chip_design/generate-chipdesign.py | 12 | ||||
-rwxr-xr-x | chip_design/solution-to-latex.py | 26 | ||||
-rw-r--r-- | part1.tex | 24 |
3 files changed, 32 insertions, 30 deletions
diff --git a/chip_design/generate-chipdesign.py b/chip_design/generate-chipdesign.py index d834078..23328ae 100755 --- a/chip_design/generate-chipdesign.py +++ b/chip_design/generate-chipdesign.py @@ -111,11 +111,15 @@ for i in range(len(powers), len(all_components)): # Power (j) top/right side hits component (i) bottom/left side or # Power (j) bottom/left side hits component (i) top/right side. # (note: copied from above overlap check with '>='/'<=' -> '='.) + # Additionally: to "hit" the power resource over the X axis, an + # component Y coordinate must be within the power resource. + # FIXME need to check whether there is an overlap + pr_range = ' (>= x{j} )' altpreds += fillin([ - '(= (+ y{j} h{j}) y{i})', - '(= (+ x{j} w{j}) x{i})', - '(= y{j} (+ y{i} h{i}))', - '(= x{j} (+ x{i} w{i}))', + '(and (= (+ y{j} h{j}) y{i})'' )', + '(and (= (+ x{j} w{j}) x{i})'' )', + '(and (= y{j} (+ y{i} h{i}))'' )', + '(and (= x{j} (+ x{i} w{i}))'' )', ], vars()) preds += ['(or %s)' % ' \n'.join(altpreds)] diff --git a/chip_design/solution-to-latex.py b/chip_design/solution-to-latex.py index 798267a..6c74f4c 100755 --- a/chip_design/solution-to-latex.py +++ b/chip_design/solution-to-latex.py @@ -70,6 +70,11 @@ def print_boxes(): attrs = ','.join(attrs) + # HACK: print coords for debugging + if sys.argv[-1] == 'debug': + print(x, y, w, h) + continue + # For easier detection, reduce box dimension (add margin) margin = 0.01 x += margin @@ -80,22 +85,15 @@ def print_boxes(): tpl = r"\draw[{attrs}] ({x}, {y}) rectangle ({x2}, {y2});" print(tpl.strip().format(**vars())) + # Reset for printing text + x, y, w, h = component + x2, y2 = x + w, y + h + # Draw number for debugging tx = x + w/2 ty = y + h/2 - text = r"%s\\(%s x %s)" % (i, w, h) + text = r"%s\\(%s,%s)\\(%s x %s)" % (i, x, y, w, h) print(r'\node[align=center] at (%f,%f) {%s};' % (tx, ty, text)) -def print_grid(): - # XXX currently hard-coding grid size - print(r'\draw[step=1,gray,very thin] (0, 0) grid (30, 30);') - -if not True: - # Complete picture - print(r'\begin{tikzpicture}') - print_grid() - print_boxes() - print(r'\end{tikzpicture}') -else: - # Just the boxes. - print_boxes() +# Just the boxes. +print_boxes() @@ -77,29 +77,29 @@ their centres should differ at least 17 in either the x direction or the y direc \draw[red,thick] (-.5, -.5) rectangle (30.5, 30.5); \draw[draw=red,fill=red] (27.01, 20.01) rectangle (29.99, 23.99); -\node[align=center] at (28.510000,22.010000) {0\\(3 x 4)}; +\node[align=center] at (28.500000,22.000000) {0\\(27,20)\\(3 x 4)}; \draw[draw=green,fill=red] (7.01, 11.01) rectangle (9.99, 14.99); -\node[align=center] at (8.510000,13.010000) {1\\(3 x 4)}; +\node[align=center] at (8.500000,13.000000) {1\\(7,11)\\(3 x 4)}; \draw[draw=blue] (10.01, 11.01) rectangle (14.99, 14.99); -\node[align=center] at (12.510000,13.010000) {2\\(5 x 4)}; +\node[align=center] at (12.500000,13.000000) {2\\(10,11)\\(5 x 4)}; \draw[draw=cyan] (21.01, 21.01) rectangle (26.99, 24.99); -\node[align=center] at (24.010000,23.010000) {3\\(6 x 4)}; +\node[align=center] at (24.000000,23.000000) {3\\(21,21)\\(6 x 4)}; \draw[draw=magenta] (10.01, 25.01) rectangle (29.99, 29.99); -\node[align=center] at (20.010000,27.510000) {4\\(20 x 5)}; +\node[align=center] at (20.000000,27.500000) {4\\(10,25)\\(20 x 5)}; \draw[draw=gray] (7.01, 15.01) rectangle (12.99, 23.99); -\node[align=center] at (10.010000,19.510000) {5\\(6 x 9)}; +\node[align=center] at (10.000000,19.500000) {5\\(7,15)\\(6 x 9)}; \draw[draw=darkgray] (0.01, 24.01) rectangle (9.99, 29.99); -\node[align=center] at (5.010000,27.010000) {6\\(10 x 6)}; +\node[align=center] at (5.000000,27.000000) {6\\(0,24)\\(10 x 6)}; \draw[draw=lightgray] (12.01, 0.01) rectangle (17.99, 10.99); -\node[align=center] at (15.010000,5.510000) {7\\(6 x 11)}; +\node[align=center] at (15.000000,5.500000) {7\\(12,0)\\(6 x 11)}; \draw[draw=brown] (13.01, 15.01) rectangle (19.99, 22.99); -\node[align=center] at (16.510000,19.010000) {8\\(7 x 8)}; +\node[align=center] at (16.500000,19.000000) {8\\(13,15)\\(7 x 8)}; \draw[draw=olive] (0.01, 11.01) rectangle (6.99, 22.99); -\node[align=center] at (3.510000,17.010000) {9\\(7 x 12)}; +\node[align=center] at (3.500000,17.000000) {9\\(0,11)\\(7 x 12)}; \draw[draw=orange] (2.01, 1.01) rectangle (11.99, 10.99); -\node[align=center] at (7.010000,6.010000) {10\\(10 x 10)}; +\node[align=center] at (7.000000,6.000000) {10\\(2,1)\\(10 x 10)}; \draw[draw=pink] (20.01, 0.01) rectangle (29.99, 19.99); -\node[align=center] at (25.010000,10.010000) {11\\(10 x 20)}; +\node[align=center] at (25.000000,10.000000) {11\\(20,0)\\(10 x 20)}; \end{tikzpicture} \section*{Problem: Job scheduling} |