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
cdab1972
Commit
cdab1972
authored
May 12, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8c550297
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+29
-16
No files found.
wcfs/internal/xbtree.py
View file @
cdab1972
...
@@ -240,6 +240,8 @@ def Restructure(ztree, newStructure):
...
@@ -240,6 +240,8 @@ def Restructure(ztree, newStructure):
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
# 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.
# it is used to associate nodes in tnew to ztree nodes.
def
assign
(
RZv
,
RNv
):
def
assign
(
RZv
,
RNv
):
print
()
print
(
'assign %s <- %s'
%
(
RZv
,
RNv
))
for
rzn
in
RZv
:
for
rzn
in
RZv
:
assert
isinstance
(
rzn
,
_NodeInRange
)
assert
isinstance
(
rzn
,
_NodeInRange
)
assert
isinstance
(
rzn
.
node
,
(
ztreeType
,
zbucketType
))
assert
isinstance
(
rzn
.
node
,
(
ztreeType
,
zbucketType
))
...
@@ -268,8 +270,10 @@ def Restructure(ztree, newStructure):
...
@@ -268,8 +270,10 @@ def Restructure(ztree, newStructure):
# assignments more efficiently taking that Av and Bv are key↑ and the
# 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
# 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).
# in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
print
()
print
(
C
)
print
(
C
)
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
print
(
jv
,
iv
)
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
...
@@ -278,6 +282,7 @@ def Restructure(ztree, newStructure):
...
@@ -278,6 +282,7 @@ def Restructure(ztree, newStructure):
# to newly created Z nodes.
# to newly created Z nodes.
for
j2
in
range
(
len
(
RNv
)):
for
j2
in
range
(
len
(
RNv
)):
if
j2
not
in
jv
:
if
j2
not
in
jv
:
print
(
'
\
n
\
n
\
n
XXX create new @%d
\
n
\
n
\
n
'
%
j2
)
n
=
RNv
[
j2
].
node
n
=
RNv
[
j2
].
node
assert
n
.
Z
is
None
assert
n
.
Z
is
None
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
...
@@ -349,8 +354,10 @@ def Restructure(ztree, newStructure):
...
@@ -349,8 +354,10 @@ def Restructure(ztree, newStructure):
assert
len
(
rbucketv
)
>
0
assert
len
(
rbucketv
)
>
0
for
i
in
range
(
len
(
rbucketv
)
-
1
):
for
i
in
range
(
len
(
rbucketv
)
-
1
):
assert
rbucketv
[
i
].
range
.
khi
<=
rbucketv
[
i
+
1
].
klo
assert
rbucketv
[
i
].
range
.
khi
<=
rbucketv
[
i
+
1
].
klo
rbucketv
[
i
].
node
.
next_bucket
=
rbucketv
[
i
+
1
].
node
rbucketv
[
i
]
.
node
.
next_bucket
=
rbucketv
[
i
+
1
].
node
rbucketv
[
i
+
1
].
node
.
prev_bucket
=
rbucketv
[
i
]
.
node
rbucketv
[
-
1
].
node
.
next_bucket
=
None
rbucketv
[
-
1
].
node
.
next_bucket
=
None
rbucketv
[
0
]
.
node
.
prev_bucket
=
None
# associate every bucket to zbucket
# associate every bucket to zbucket
assign
(
zrbucketv
,
rbucketv
)
assign
(
zrbucketv
,
rbucketv
)
...
@@ -361,18 +368,24 @@ def Restructure(ztree, newStructure):
...
@@ -361,18 +368,24 @@ def Restructure(ztree, newStructure):
for
rnodev
in
rlevelv
:
for
rnodev
in
rlevelv
:
for
rn
in
rnodev
:
for
rn
in
rnodev
:
node
=
rn
.
node
node
=
rn
.
node
assert
isinstance
(
node
,
Tree
)
# buckets were filtered out to rbucketv
assert
isinstance
(
node
,
Tree
)
,
node
# buckets were filtered out to rbucketv
znode
=
node
.
Z
znode
=
node
.
Z
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BTreeTemplate.c#L1087
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BTreeTemplate.c#L1087
zstate
=
unset
=
object
()
if
len
(
node
.
keyv
)
==
0
:
if
len
(
node
.
keyv
)
==
0
:
child
=
node
.
children
[
0
]
child
=
node
.
children
[
0
]
if
isinstance
(
child
,
Bucket
):
if
isinstance
(
child
,
Bucket
):
if
len
(
child
.
keyv
)
==
0
:
# empty bucket noone links to
panic
(
"TODO: empty tree"
)
if
len
(
child
.
keyv
)
==
0
and
child
.
prev_bucket
is
None
:
if
child
.
Z
.
_p_oid
is
None
:
zstate
=
None
# -> empty tree
panic
(
"TODO: tree with bucket without oid"
)
# tree with single bucket noone links to
elif
child
.
Z
.
_p_oid
is
None
and
child
.
prev_bucket
is
None
:
zstate
=
((
child
.
Z
.
__getstate__
(),),)
# tree with bucket without oid
if
zstate
is
unset
:
# normal tree node
zstate
=
()
zstate
=
()
assert
len
(
node
.
children
)
==
len
(
node
.
keyv
)
+
1
assert
len
(
node
.
children
)
==
len
(
node
.
keyv
)
+
1
zstate
+=
node
.
children
[
0
]
zstate
+=
node
.
children
[
0
]
...
...
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