Feature (Gene) translation into Bitfield - Tzaphkiel/G34S GitHub Wiki
Consider N to be the number of Courts in the following example:
- 2 Courts can be represented by 1 bit : [x] where x := {0|1}
- 4 Courts can be represented by a 2 bits : [xx] where x :={0|1}
- 2N bits represents N Courts, therefore:
numBits = ceil(log(N) / log(2))
This equation is valid for any feature.
NB: if the number of distinct elements in the feature is not a power of two, some bit combination will be invalid !
Suppose we have to map 6 players into a bitfield, using the formula above we would get:
# number of players
N=6
# number of bitfields to represent them
ceil((log(N)/log(2))
3
# total number of combinations possible
pow(2,3)
8
There are thus 2 invalid combinations:
invalid = {'110', '111'}
# NB: player one is '000'
These combinations need to be excluded whenever a new chromosome appears!
The example inputs are the following:
- number of Courts : 4
- number of timeslots : 6 & start at 8pm
- number of players : 7
It can be represented by a chromosome of size 11 having the following Gene/features:
- Gene 0 : Player 1 : 3 sig. bits, highest valid: 110 (7 players max)
- Gene 1 : Player 2 : 3 sig. bits, highest valid: 110 (7 players max)
- Gene 2 : Court : 2 sig. bits, highest valid: 11 (4 Courts max)
- Gene 3 : Timeslot : 3 sig. bits, highest valid: 101 (6 Timeslots max)
Below are examples of valid and invalid bitfields:
# 010 111 (invalid) 10 101
invalid='01011110101'
# 100 010 01 001
p5_p3_c2_t2='10001001001'
An alternate representation would be one bit per feature value (but that would create too big a field too quickly...
# [000] [000] [0000] [000000]
# p1 p2 Court Timeslot
A grid is represented as an Individual that is composed of multiple chromosomes. In the example above, it would be represented by num(Timeslot)*num(Court) = 6*4 = 24
chromosomes.