func (b BitSample) CrossOver(mateCandidate Sample) Sample { mate := mateCandidate.(BitSample) length := b.field.Size() child := BitSample{bitfield.New(length)} i, j := uint32(randInt(length)), uint32(randInt(length)) if i > j { i, j = j, i } for k := uint32(0); k < uint32(length); k++ { if k < i || k > j { if b.field.Test(k) { child.field.Set(k) } } else { if mate.field.Test(k) { child.field.Set(k) } } } return child }
func NewBitSample(size int) BitSample { return BitSample{bitfield.New(size)} }