Пример #1
0
func (_ HIFF) Evaluate(bits bitset.BitSet) (fitness float64, optimal bool) {

	blockSize := 2
	optimal = true

	for blockSize <= bits.Len() {
		for i := 0; i < bits.Len(); i += blockSize {
			first := bits.Has(i)
			same := true
			for j := i + 1; j < i+blockSize; j++ {
				if bits.Has(j) != first {
					same = false
					optimal = false
					break
				}
			}
			if same {
				fitness += float64(blockSize)
			}
		}
		blockSize *= 2
	}

	return
}
Пример #2
0
func (dt DeceptiveTrap) Evaluate(bits bitset.BitSet) (fitness float64, optimal bool) {
	k := int(dt)
	optimal = true

	for i := 0; i < bits.Len()/k; i++ {
		t := 0 // number of bits set to 1
		for j := 0; j < k; j++ {
			if bits.Has(i*k + j) {
				t++
			}
		}
		if t == k {
			fitness += float64(t)
		} else {
			fitness += float64(k - t - 1)
			optimal = false
		}
	}
	return
}