Last active
February 19, 2018 19:55
-
-
Save Sciss/3a243b11ea0302f97cfb824ea1ff9f21 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
def selectEdges(nv: Int = 18, ne: Int = 12) = { | |
var m = Map.empty[Int, Set[Int]] withDefaultValue Set.empty | |
val vr = (1 to nv) | |
vr.reverse.foreach { v => | |
val s0 = m(v) | |
val cand0 = vr.filterNot(s0.contains) | |
val cand1 = cand0.filter { v2 => m(v2).size < ne } | |
val tk = ne - s0.size | |
val cand = cand1.take(tk) | |
assert (cand.size == tk, s"Woops. wanted $tk got ${cand.size}") | |
val s1 = s0 ++ cand | |
m = m + (v -> s1) | |
cand.foreach { v2 => | |
val s2 = m(v2) | |
val s3 = s2 + v | |
m = m + (v2 -> s3) | |
} | |
} | |
m | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment