MGO is a scala library based on the cake pattern for multi-objective evolutionary / genetic algorithms:
- enforcing immutability,
- exposes a modular and extensible architecture,
- implements state of the art algorithms,
- take advantage of multi-core architectures.
MGO implements NGSAII, SMSEMOEA, CMAES and other diversity based evolutionary algorithms.
MGO is licenced under the GNU Affero GPLv3 software licence.
Define a problem, for instance ZDT4:
importfr.iscpif.mgo._importmath._importutil.RandomtraitZDT4extendsGAProblemwithMGFitness {
defmin=Seq.fill(genomeSize)(0.0)
defmax=1.0::Seq.fill(genomeSize -1)(5.0)
typeP=Seq[Double]
overridedefexpress(g: Seq[Double], rng: Random) =Seq(f1(g), f2(g))
overridedefevaluate(p: P, rng: Random) = p
deff1(x: Seq[Double]) = x(0)
deff2(x: Seq[Double]) = g(x) * (1- sqrt(x(0) / g(x)))
defg(x: Seq[Double]) =1+10* (genomeSize -1) + (1 until genomeSize).map { i => pow(x(i), 2) -10* cos(4*Pi* x(i)) }.sum
}Define the optimisation algorithm, for instance NSGAII:
valm=newZDT4withNSGAIIwithCounterTermination {
defsteps=1000defmu=200deflambda=200defgenomeSize=10
}Run the optimisation:
implicitvalrng= newRNG(42)
valres=
m.evolve.untilConverged {
s => println(s.generation)
}
valoutput=Resource.fromFile("/tmp/res.csv")
for {
r <- res.population.toIndividuals
} {
defline= m.scale(m.values.get(r.genome)) ++ m.fitness(r)
output.append(line.mkString(",") +"\n")
}For more examples, have a look at the main/scala/fr/iscpif/mgo/test directory in the repository.
libraryDependencies += "fr.iscpif" %% "mgo" % "version"