tester.py 2.59 KB
Newer Older
Michael Keller's avatar
Michael Keller committed
1
2
3
4
from bruteForce import solver
from scorer import score, maxScore
from grower import growA, growB
import numpy as np
Michael Keller's avatar
Michael Keller committed
5
6
7
8
9
10
11
12
13
14
15
16

# driver

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

def main():

    problems = [
        ["Basic 1", 3, 1, lambda a, b: 1.0 if abs(
            a-b) == 1 else -1.0, [1] * 3],
        ["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
17
        ["Agropol Real", 2, 5, lambda a, b:
Michael Keller's avatar
Michael Keller committed
18
19
20
21
22
23
24
25
26
27
28
29
30
            [[-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
         ],
Michael Keller's avatar
Michael Keller committed
31
         ["Agropol Int", 2, 5, lambda a, b: # 0 -> -1, 0.5 to normal sign
Michael Keller's avatar
Michael Keller committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
            [[-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
46
    '''
Michael Keller's avatar
Michael Keller committed
47
48
49
50
51
52
53
54
55
    for problem in problems:

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

        sol = solver(x, y, R, dist)
Michael Keller's avatar
Michael Keller committed
56
57
58
59
60
61
62
63
64
65
        print(name, " Score: ", score(R, sol), " Efficiency: ", score(R, sol) / maxScore(R, sol))
    '''
    sol = [[5, 0, 1, 4, 2], [6, 3, 8, 9, 7]]
    print("Agropol Real", " Score: ", score(problems[2][3], sol), " Efficiency: ", score(problems[2][3], sol) / maxScore(problems[2][3], sol))
    for i in range(5):
        sol = growA(sol)
        solTransposed = np.array(sol).T.tolist()
        sol = growA(solTransposed)
    print("Grown Agropol Real", " Score: ", score(problems[2][3], sol), " Efficiency: ", score(problems[2][3], sol) / maxScore(problems[2][3], sol))
    
Michael Keller's avatar
Michael Keller committed
66
67
68
69


if __name__ == "__main__":
    main()