-
-
Save andrewgazelka/b11555496e289ced537ad281ecc95280 to your computer and use it in GitHub Desktop.
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
fun <A> memoryControl( | |
used: AtomicInteger, | |
max: Int, | |
open: MutableSet<A>, | |
fScores: MutableMap<A, Double>, | |
depths: Map<A, Double>, | |
memoryNeighbors: Map<A, MutableSet<A>>, | |
cameFrom: Map<A, A>, | |
closed: MutableSet<A> | |
) { | |
if (used.get() == max) { | |
val omegaSet = open.maxesBy { fScores[it]!! } | |
val worst = omegaSet.filter { | |
val neighbors = memoryNeighbors[it]?.size ?: 0 | |
neighbors == 0 | |
}.minBy { depths[it] ?: error("need depth for nodes") }!! | |
val parent = cameFrom[worst] | |
if (parent != null) { | |
memoryNeighbors[parent]?.remove(worst) // TODO: this good??? ... should we wipe if size 0 | |
if (parent in closed) { | |
closed.remove(parent) | |
open.add(parent) | |
} | |
} | |
used.getAndDecrement() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment