Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example with explicitly specified type for implicits
class Config(n: Int, k: Int, onePlusOne: Boolean, init: Int, rlAlgorithm: Option[Agent[Int, Int]])
extends OptConfiguration[BitSet, IndexedSeq[Int]]
{
require(n % k == 0)
private implicit val multiple: MultipleCriteria[IndexedSeq[Int]] = MultipleCriteria.fromIndexedSeqWithElementOrdering("XdivK", "OneMax")
private implicit val comparator: EARLCodomainComparator[IndexedSeq[Int]] = EARLCodomainComparator().fromMultipleCriteria(init)
private implicit val evaluator: Evaluator[BitSet, IndexedSeq[Int]] = Evaluator().usingFunction { v: BitSet =>
val oneMax = v.size
val xDivK = oneMax / k
IndexedSeq(xDivK, oneMax)
}
private implicit val initialization: Initialization[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Initialization().fromDomains(Some(BitSet.empty))
private implicit val termination: Termination.Pluggable[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Termination.Pluggable()
private implicit val selection: Selection[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Selection().all
private implicit val update: Update[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Update().best
private implicit val mutation: Mutation[BitSet, IndexedSeq[Int]] = Mutation().using(
if (onePlusOne) {
Mutation.Standard.BitSet.independentPointMutation(n)
} else {
Mutation.Standard.BitSet.singlePointMutation(n)
}
)
private implicit val iteration: Iteration[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Iteration().fromSelectionMutationEvaluateUpdate
private implicit val optimizer: Optimizer[BitSet, IndexedSeq[Int], IndexedSeqWorkingSet] = Optimizer().simple
private implicit val evaluationCount: EvaluationCount[BitSet, IndexedSeq[Int]] = new EvaluationCount()
CodomainThreshold().register(_(0), n / k)
EvaluationLimit().register(1000000)
rlAlgorithm match {
case Some(algo) =>
EARLConfiguration().registerOldWay(algo, v => v(0).output(0), (p, n) => n(0).output(0) - p(0).output(0))
case None =>
}
def run(): Double = {
optimizer() match {
case Optimizer.Result(_, CodomainThreshold) => evaluationCount()
case Optimizer.Result(_, EvaluationLimit) => Double.PositiveInfinity
case Optimizer.Result(_, _) => throw new AssertionError("Should not happen")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.