# Optimising a Hesitating Mitchell

Output of the program `balans` for optimising a Hesitating Mitchell (also called Expanded Mitchell)

The original quality factor is Qf = 54.88
The quality factor after optimisation is Qf = 82.46
The optimised movement can be found in the text but also separately here.

Inserted comments are displayed like this

command line:

`balans -r1 -t1 -m 14p8rScrEM.txt 14p8rexpandedM.txt`
• -r1 : keeps round 1 fixed
• -t1 : keeps table 1 fixed
• -m 14p8rScrEM.txt : output file
• 14p8rexpandedM.txt : input file
```# option fix round 1
# option fix table 1
12-04-2022 13:28:51
balans v7.62
ensemble size: 4      number of threads: 4
w1=2             w2=1            w1/w2=2             use_Qf1av=1
14p8rexpandedM.txt: 14 pairs, 8 rounds 7 tables, h = 6, S = 336
amount of competition S= 336
number of pairs of pairs N= 91

initial movement scheme:
14  7  8  8 0 g
1- 8  1   2- 9  2   3-10  3   4-11  5   5-12  6   6-13  7   7-14  8
1- 7  2   2- 8  3   3- 9  4   4-10  6   5-11  7   6-12  8  14-13  1
1-14  3   2- 7  4   3- 8  5   4- 9  7   5-10  8   6-11  1  13-12  2
1-13  4   2-14  5   3- 7  6   4- 8  8   5- 9  1   6-10  2  12-11  3
1-12  5   2-13  6   3-14  7   4- 7  1   5- 8  2   6- 9  3  11-10  4
1-11  6   2-12  7   3-13  8   4-14  2   5- 7  3   6- 8  4  10- 9  5
1-10  7   2-11  8   3-12  1   4-13  3   5-14  4   6- 7  5   9- 8  6
1- 9  8   2-10  1   3-11  2   4-12  4   5-13  5   6-14  6   8- 7  7
```
The left matrix indicates the number of times a given board group is played by a given pair
(in this case all pairs nicely play each board group once)
The right matrix is the table of opponent encounters
(in this case: not all pairs meet)
```    1 2 3 5 6 7 8 4     1 2 3 4 5 6 7 8 91011121314
1: 1 1 1 1 1 1 1 1     \ . . . . . 1 1 1 1 1 1 1 1
2: 1 1 1 1 1 1 1 1     . \ . . . . 1 1 1 1 1 1 1 1
3: 1 1 1 1 1 1 1 1     . . \ . . . 1 1 1 1 1 1 1 1
4: 1 1 1 1 1 1 1 1     . . . \ . . 1 1 1 1 1 1 1 1
5: 1 1 1 1 1 1 1 1     . . . . \ . 1 1 1 1 1 1 1 1
6: 1 1 1 1 1 1 1 1     . . . . . \ 1 1 1 1 1 1 1 1
7: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 \ 1 . . . . . 1
8: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 \ 1 . . . . .
9: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 . 1 \ 1 . . . .
10: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 . . 1 \ 1 . . .
11: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 . . . 1 \ 1 . .
12: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 . . . . 1 \ 1 .
13: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 . . . . . 1 \ 1
14: 1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 . . . . . 1 \

the score matrix:
*   8   8   8   8   8   1   1   1   1   1   1   1   1
8   *   8   8   8   8   1   1   1   1   1   1   1   1
8   8   *   8   8   8   1   1   1   1   1   1   1   1
8   8   8   *   8   8   1   1   1   1   1   1   1   1
8   8   8   8   *   8   1   1   1   1   1   1   1   1
8   8   8   8   8   *   1   1   1   1   1   1   1   1
1   1   1   1   1   1   *  11   4   4   4   4   4  11
1   1   1   1   1   1  11   *  11   4   4   4   4   4
1   1   1   1   1   1   4  11   *  11   4   4   4   4
1   1   1   1   1   1   4   4  11   *  11   4   4   4
1   1   1   1   1   1   4   4   4  11   *  11   4   4
1   1   1   1   1   1   4   4   4   4  11   *  11   4
1   1   1   1   1   1   4   4   4   4   4  11   *  11
1   1   1   1   1   1  11   4   4   4   4   4  11   *
```

The average value in this case is 336/91 = 3.69. A perfect balance is therefore not achievable. In the ideal case, this matrix would consist of only 3s and 4s.

Now successively follow
S2=sum of (score - average)^2,
S4=sum of (score - average)^4,
sd= standard deviation,
d4=4th root of (S4)/N,
and the quality factors Qc, Qf and Qo
```sum of squares original:  1055.4
sum of 4th powers: 30501.6
sd= 3.406, d4= 4.279, Qc=54.03, Qf=54.88, Qo=61.54
```
The following is a table of which tables to keep fixed while optimising.
```Fixed tables, indicated by 1
1 1 1 1 1 1 1
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 0 0 0 0 0 0

Trying to Improve the Balance v7.62
algo 0: fast temperature fluctuations between T=1 and T=2000
range for Qf1max: 1 - 14
relative weight of Qf1max:          2
```
During iterations is shown when finding an improvement:
iteration number, temperature, Qf, Qf1av, Qf1max, pair number of this Qf1 maximum, d4, number/fraction of members with best weighted quality
The Windows program `balans.exe` displays this information in a window.
The Windows program `balans3.exe` and balans on Unix/Linux displays the information in the console (stdout), e.g. like this (example for system with 4 logical cpus, so by default 4 independent optimisations carried out in parallel = 4 members of ensemble):
```   iter      T     Qf   Qf1av Qf1max  pair    d4 nBest
0    0.0  54.88  52.205  54.39    1  4.279  4/4
1    1.0  79.95  73.146  77.50   12  2.581  1/4
3    4.0  80.77  73.977  76.86   13  2.484  1/4
4    5.0  80.77  74.104  80.87    8  2.461  1/4
6   10.0  81.61  74.443  78.15   12  2.339  1/4
8   10.0  82.46  75.347  80.17   14  2.249  1/4
9   10.0  82.46  75.347  80.17   14  2.249  2/4
10   10.0  82.46  75.347  80.17   14  2.249  3/4
104   10.0  82.46  75.347  80.17   14  2.249  4/4
=== Results for all   4 members of ensemble: ======
#      T     Qf   Qf1av Qf1max  pair    d4
1   20.0  82.46  75.347  80.17   14  2.249
2   20.0  82.46  75.347  80.17   14  2.249
3   10.0  82.46  75.522  78.81   14  2.249
4   10.0  82.46  75.347  80.17   14  2.249
===================================================
```

(The solution with Qf1av=75.522 and Qf1max=78.81 happens to have exactly the same weighted quality as the others with the default weight of 2).
Afterwards a table is shown in which we can see which tables are turned (arrow switched) in the final selected solution:
```Switched tables indicated by 2, fixed tables indicated by 1
1 1 1 1 1 1 1
1 2 0 0 2 0 2
1 0 0 0 0 2 2
1 0 0 0 2 0 2
1 0 2 2 0 0 2
1 0 0 0 0 2 0
1 0 0 2 2 0 0
1 0 0 2 0 0 0

optimized movement scheme:
14  7  8  8 0 g
1- 8  1   2- 9  2   3-10  3   4-11  5   5-12  6   6-13  7   7-14  8
1- 7  2   8- 2  3   3- 9  4   4-10  6  11- 5  7   6-12  8  13-14  1
1-14  3   2- 7  4   3- 8  5   4- 9  7   5-10  8  11- 6  1  12-13  2
1-13  4   2-14  5   3- 7  6   4- 8  8   9- 5  1   6-10  2  11-12  3
1-12  5   2-13  6  14- 3  7   7- 4  1   5- 8  2   6- 9  3  10-11  4
1-11  6   2-12  7   3-13  8   4-14  2   5- 7  3   8- 6  4  10- 9  5
1-10  7   2-11  8   3-12  1  13- 4  3  14- 5  4   6- 7  5   9- 8  6
1- 9  8   2-10  1   3-11  2  12- 4  4   5-13  5   6-14  6   8- 7  7

the score matrix:
*   6   6   2   2   4   3   5   3   3   5   3   3   3
6   *   4   4   0   2   5   3   5   5   3   5   1   5
6   4   *   0   4   2   5   3   5   5   3   5   5   1
2   4   0   *   4   6   5   3   5   5   3   5   1   5
2   0   4   4   *   6   5   3   5   5   3   5   5   1
4   2   2   6   6   *   3   5   3   3   5   3   3   3
3   5   5   5   5   3   *   5   4   0   2   0   4   7
5   3   3   3   3   5   5   *   5   2   4   2   2   6
3   5   5   5   5   3   4   5   *   7   2   0   4   0
3   5   5   5   5   3   0   2   7   *   5   4   0   4
5   3   3   3   3   5   2   4   2   5   *   5   6   2
3   5   5   5   5   3   0   2   0   4   5   *   7   4
3   1   5   1   5   3   4   2   4   0   6   7   *   7
3   5   1   5   1   3   7   6   0   4   2   4   7   *
```
Summary of results
```sum of squares    was  1055.4, now   287.4
sum of 4th powers was 30501.6, now  2328.8
```
for each pair the Qf1, the value of Qf if this pair is absent
```pair     Qf1
1   70.45
2   75.61
3   74.40
4   73.81
5   75.61
6   72.09
7   78.15
8   74.40
9   76.23
10   73.81
11   75.00
12   78.15
13   78.15
14   80.17
```
and the characteristics of the movement scheme
```Qf1av= 75.347   Qf1max=  80.17, for pair(s) 14
sd= 1.777, d4= 2.249, Qc=81.19, Qf=82.46, Qo=61.54

input file is 14p8rexpandedM.txt, output file is 14p8rScrEM.txt
```