Commit 54b635dc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 2c24087e
......@@ -223,7 +223,7 @@ def Restructure(ztree, newStructure):
#
# sum min d(a,b) sum min d(a,b)
# a∈A b∈B b∈B a∈A
# D(A,B) = ────────────── + ──────────────
# D(A,B) = ────────────── + ────────────── XXX
# N(A) N(B)
#
......@@ -232,6 +232,35 @@ def Restructure(ztree, newStructure):
# - bucket.next_bucket will point to bucket that is coming with next keys in the tree
tnew = newStructure.copy()
# assign assignes tree nodes from RNv to ztree nodes from RZv in optimal way.
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
# it is used to associate nodes in tnew to ztree nodes.
def assign(RZv, RNv):
for rzn in RZv:
assert isinstance(rzn, _NodeInRange)
assert isinstance(rzn.node, (ztreeType, zbucketType))
for rn in RNv:
assert isinstance(rn, _NodeInRange)
assert isinstance(rn.node, (Tree|Bucket)
# prepare cost matrix
C = np.zeros((len(RNv), len(RZv)))
for j in range(RNv): # "workers"
for i in range(RZv): # "jobs"
C[j,i] = D(A[i], B[j])
# TODO try to avoid scipy dependency; we could also probably make
# assignments more efficiently taking that Av and Bv are key↑ and the
# property of D function so that if B2 > B1 (all keys in B2 > all keys
# in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
jv, iv = scipy.optimize.linear_sum_assignment(C)
if len(Av) == len(Bv):
# XXX assert the result is 1-1 mapping
# XXX assert assignments are in key↑ order
zrlevelv = list(__zwalkBFS(ztree)) # [] of _NodeInRange
rlevelv = list( __walkBFS(tnew)) # [] of _NodeInRange
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment