tester.py 3.39 KB
Newer Older
Michael Keller's avatar
Michael Keller committed
1
from bruteForce import solver
2
from scorer import score, maxScore, maxScoreAlt
Michael Keller's avatar
Michael Keller committed
3
from grower import growA, growB
4
from simulatedAnealing import simulatedAnnealing, simulatedAnnealingBadPixels
Michael Keller's avatar
Michael Keller committed
5
import numpy as np
Michael Keller's avatar
Michael Keller committed
6
7
8
9
10

# driver

# Agropol Real Sol: [[5, 0, 1, 4, 2], [6, 3, 8, 9, 7]], score: 32, 2 * 5

11
12
13
14
15
16
def print_field(field):
    for row in field:
        for p in row:
            print(p, end="\t")
        print("")

Michael Keller's avatar
Michael Keller committed
17
18
19
def main():

    problems = [
20
21
        # ["Basic -1", 2, 2, lambda a, b: 0 if a == b else 1.0, [1] * 4],
        # ["Basic 0", 2, 4, lambda a, b: 0 if a == b else 1.0, [2] * 4],
Michael Keller's avatar
Michael Keller committed
22
23
        # ["Basic 1", 3, 1, lambda a, b: 1.0 if abs(
        #     a-b) == 1 else -1.0, [1] * 3],
24
25
        ["Basic 2", 2, 3, lambda a, b: 1.0 if abs(
            a-b) == 0 else -1.0, [1, 2, 3]],
Michael Keller's avatar
Michael Keller committed
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
        # ["Agropol Real", 2, 5, lambda a, b:
        #     [[-0.5, 1, 1, 1, 1, 1, 0.5, -1, 0.5, 0.5, 1],
        #      [1, -0.5, -1, 1, 1, 0.5, 0.5, -1, 1, 1, 1],
        #      [1, -1, -0.5, -1, 1, 0, 0.5, 0.5, 0, 0, 0],
        #      [1, 1, -1, -0.5, 0, 0, 0.5, -1, 1, -1, 0],
        #      [1, 1, 1, 0, -0.5, 0, 0.5, 1, 1, 1, 1],
        #      [1, 0.5, 0, 0, 0, -0.5, 0.5, 0, 0, 0, 0],
        #      [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
        #      [-1, -1, 0.5, -1, 1, 0, 0.5, -0.5, 0, 0.5, 0],
        #      [0.5, 1, 0, 1, 1, 0, 0.5, 0, -0.5, 1, 0],
        #      [0.5, 1, 0, -1, 1, 0, 0.5, 0.5, 1, -0.5, 1],
        #      [1, 1, 0, 0, 1, 0, 0.5, 0, 0, 1, -0.5]][a][b],
        #     [2] * 11
        #  ],
        #  ["Agropol Int", 2, 5, lambda a, b: # 0 -> -1, 0.5 to normal sign
        #     [[-1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1],
        #      [1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1],
        #      [1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1],
        #      [1, 1, -1, -1, -1, -1, 1, -1, 1, -1, -1],
        #      [1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1],
        #      [1, 1, -1, -1, -1, -1, 1, -1, -1, -1, -1],
        #      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        #      [-1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1],
        #      [1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1],
        #      [1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 1],
        #      [1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1]][a][b],
        #     [2] * 11
        #  ],
Michael Keller's avatar
Michael Keller committed
54
    ]
Michael Keller's avatar
Michael Keller committed
55
    
Michael Keller's avatar
Michael Keller committed
56
57
58
59
60
61
62
63
    for problem in problems:

        name = problem[0]
        x = problem[1]
        y = problem[2]
        R = problem[3]
        dist = problem[4]

64
65
66
67
68
69
70
71
72
        sol = [[1,2,3,4], [5,6,7,8], [9,10,11,12]]
        print_field(sol)
        print("")
        sol = growB(sol, 5, 7)
        print_field(sol)

        print(maxScore(R, sol))


Michael Keller's avatar
Michael Keller committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

        # print("Field Connections:")
        # conns = [[0 for _ in dist] for _ in dist]
        # for i in range(len(sol)):
        #     for j in range(len(sol[0])):
        #         for n1 in range(-1, 2):
        #             for n2 in range(-1, 2):
        #                 # not a neighbor
        #                 if n1 == 0 and n2 == 0:
        #                     continue

        #                 # test valid neighbor
        #                 if not (0 <= (i + n1) and (i + n1) < len(sol)):
        #                     continue
        #                 if not (0 <= (j + n2) and (j + n2) < len(sol[0])):
        #                     continue

        #                 # update score
        #                 conns[sol[i][j]][sol[i + n1][j + n2]] += 1
        # for row in conns:
        #     print(row)
    
Michael Keller's avatar
Michael Keller committed
95
96
97
98


if __name__ == "__main__":
    main()