Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
54b635dc
Commit
54b635dc
authored
May 12, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
2c24087e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+30
-1
No files found.
wcfs/internal/xbtree.py
View file @
54b635dc
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment