Skip to content

Instantly share code, notes, and snippets.

@andrewgazelka
Created May 16, 2019 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgazelka/b11555496e289ced537ad281ecc95280 to your computer and use it in GitHub Desktop.
Save andrewgazelka/b11555496e289ced537ad281ecc95280 to your computer and use it in GitHub Desktop.
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