Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdc-counting
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radek Hušek
cdc-counting
Commits
5ff3ddca
Commit
5ff3ddca
authored
4 years ago
by
Radek Hušek
Browse files
Options
Downloads
Patches
Plain Diff
graph_to_gadget: add experimental decomposition
parent
b7a69e8e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
graph_tools/misc.py
+35
-3
35 additions, 3 deletions
graph_tools/misc.py
with
35 additions
and
3 deletions
graph_tools/misc.py
+
35
−
3
View file @
5ff3ddca
...
@@ -52,6 +52,40 @@ def _init_():
...
@@ -52,6 +52,40 @@ def _init_():
return
b
return
b
def
guess_decomposition
(
G
):
from
sage.all
import
flatten
cycles
=
[]
H
=
G
.
copy
()
while
not
H
.
is_forest
():
_
,
c
=
H
.
girth
(
certificate
=
True
)
stack
=
H
.
vertex_boundary
(
c
)
H
.
delete_vertices
(
c
)
while
stack
:
v
=
stack
.
pop
()
if
v
not
in
H
or
H
.
degree
(
v
)
>
1
:
continue
c
=
[
c
,
v
]
stack
.
extend
(
H
.
vertex_boundary
([
v
]))
H
.
delete_vertex
(
v
)
cycles
.
append
(
c
)
score
=
lambda
x
:
len
(
G
.
edge_boundary
(
flatten
([
cycles
[
x
[
0
]],
cycles
[
x
[
1
]]])))
while
len
(
cycles
)
>
2
:
i1
,
i2
=
min
([
(
i
,
j
)
for
i
in
range
(
len
(
cycles
))
for
j
in
range
(
i
)
],
key
=
score
)
c1
=
cycles
[
i1
]
c2
=
cycles
[
i2
]
del
cycles
[
i1
]
del
cycles
[
i2
]
cycles
.
append
([
c1
,
c2
])
assert
(
sorted
(
flatten
(
cycles
))
==
sorted
(
G
.
vertices
()))
return
cycles
def
graph_to_gadget
(
G
,
decomposition
=
None
,
allow_non_graph
=
False
):
def
graph_to_gadget
(
G
,
decomposition
=
None
,
allow_non_graph
=
False
):
"""
Transform graph into a Gadget.
"""
Transform graph into a Gadget.
...
@@ -76,9 +110,7 @@ def _init_():
...
@@ -76,9 +110,7 @@ def _init_():
edges
=
[
(
verts
[
u
],
verts
[
v
])
for
u
,
v
,
_
in
G
.
edges
()
]
edges
=
[
(
verts
[
u
],
verts
[
v
])
for
u
,
v
,
_
in
G
.
edges
()
]
if
decomposition
is
None
:
if
decomposition
is
None
:
decomposition
=
G
.
vertices
()[
0
]
decomposition
=
guess_decomposition
(
G
)
for
v
in
G
.
vertices
()[
1
:]:
decomposition
=
[
v
,
decomposition
]
vert_map
=
{
v
:
[
0
,
1
,
2
]
for
v
in
range
(
len
(
verts
))
}
vert_map
=
{
v
:
[
0
,
1
,
2
]
for
v
in
range
(
len
(
verts
))
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment