Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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