Created
September 7, 2017 14:52
-
-
Save mbuzdalov/5ec3a8fdee3ab7d3889c6af0e1a31787 to your computer and use it in GitHub Desktop.
Example with inferred implicits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.fromIndexedSeqWithElementOrdering("XdivK", "OneMax") | |
private implicit val comparator = EARLCodomainComparator().fromMultipleCriteria(init) | |
private implicit val evaluator = Evaluator().usingFunction { v: BitSet => | |
val oneMax = v.size | |
val xDivK = oneMax / k | |
IndexedSeq(xDivK, oneMax) | |
} | |
private implicit val initialization = Initialization().fromDomains(Some(BitSet.empty)) | |
private implicit val termination = Termination.Pluggable() | |
private implicit val selection = Selection().all | |
private implicit val update = Update().best | |
private implicit val mutation = Mutation().using( | |
if (onePlusOne) { | |
Mutation.Standard.BitSet.independentPointMutation(n) | |
} else { | |
Mutation.Standard.BitSet.singlePointMutation(n) | |
} | |
) | |
private implicit val iteration = Iteration().fromSelectionMutationEvaluateUpdate | |
private implicit val optimizer = Optimizer().simple | |
private implicit val evaluationCount = 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