1
我試圖運行一個來自Scala的Jenetics HelloWorld示例。Scala的Jenetics HelloWorld
import org.jenetics.{BitChromosome, BitGene, Genotype}
import org.jenetics.engine.{Engine, EvolutionResult}
object BitCounting extends App {
val genotypeFactory = Genotype.of(BitChromosome.of(128, 0.5))
val fitness: java.util.function.Function[Genotype[BitGene], Int] = new java.util.function.Function[Genotype[BitGene], Int] {
override def apply(genotype: Genotype[BitGene]): Int = genotype.asInstanceOf[BitChromosome].bitCount()
}
val engine = Engine.builder(fitness, genotypeFactory).build()
val result = engine
.stream()
.limit(100)
.collect(EvolutionResult.toBestGenotype[BitGene, Int])
println(s"Hello world:\n$result")
}
我在初始化引擎的行上收到編譯錯誤。編譯器抱怨 不存在符合類型的Engine.Builder。誰能解釋爲什麼?