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
19b9b8f7
Commit
19b9b8f7
authored
5 years ago
by
Radek Hušek
Browse files
Options
Downloads
Patches
Plain Diff
add graph_to_gadget()
parent
0a992383
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
flower_snarks.py
+67
-0
67 additions, 0 deletions
flower_snarks.py
with
67 additions
and
0 deletions
flower_snarks.py
+
67
−
0
View file @
19b9b8f7
...
@@ -392,6 +392,73 @@ def count_cdc_naive(G):
...
@@ -392,6 +392,73 @@ def count_cdc_naive(G):
return
(
b
.
eval
(
CircuitDoubleCover
),
2
**
(
G
.
num_verts
()
//
2
)
//
2
)
return
(
b
.
eval
(
CircuitDoubleCover
),
2
**
(
G
.
num_verts
()
//
2
)
//
2
)
def
graph_to_gadget
(
G
,
decomposition
=
None
):
"""
Transform graph into a Gadget.
EXAMPLES:
>>>
from
sage.all
import
*
>>>
P
=
graphs
.
PetersenGraph
()
>>>
graph_to_gadget
(
P
).
eval
(
CircuitDoubleCover
)
52
>>>
d
=
[
list
(
range
(
5
)),
list
(
range
(
5
,
10
))
]
>>>
P
.
is_isomorphic
(
graph_to_gadget
(
P
,
d
).
eval
(
UnderlayingGraph
))
True
>>>
graph_to_gadget
(
P
,
d
).
eval
(
CircuitDoubleCover
)
52
"""
assert
(
G
.
degree
()
==
[
3
]
*
G
.
num_verts
())
verts
=
{
v
:
i
for
i
,
v
in
enumerate
(
G
.
vertices
())
}
edges
=
[
(
verts
[
u
],
verts
[
v
])
for
u
,
v
,
_
in
G
.
edges
()
]
if
decomposition
is
None
:
decomposition
=
G
.
vertices
()
vert_map
=
{
v
:
[
0
,
1
,
2
]
for
v
in
range
(
len
(
verts
))
}
def
process
(
dec
):
nonlocal
edges
if
not
isinstance
(
dec
,
list
):
return
(
CUBIC_VERTEX
,
set
([
verts
[
dec
]
]))
gadgets
=
[
process
(
x
)
for
x
in
dec
]
vert_to_gadget
=
dict
()
gadget_verts
=
set
()
for
i
,
(
_
,
vs
)
in
enumerate
(
gadgets
):
gadget_verts
.
update
(
vs
)
for
v
in
vs
:
vert_to_gadget
[
v
]
=
i
joins
=
[]
new_edges
=
[]
for
u
,
v
in
edges
:
if
u
not
in
gadget_verts
or
v
not
in
gadget_verts
:
new_edges
.
append
((
u
,
v
))
continue
joins
.
append
((
(
vert_to_gadget
[
u
]
+
1
,
vert_map
[
u
].
pop
()
+
1
),
(
vert_to_gadget
[
v
]
+
1
,
vert_map
[
v
].
pop
()
+
1
)
))
edges
=
new_edges
outs
=
[]
for
v
in
gadget_verts
:
old
=
vert_map
[
v
]
vert_map
[
v
]
=
list
(
range
(
len
(
outs
),
len
(
outs
)
+
len
(
old
)))
for
i
in
old
:
outs
.
append
((
vert_to_gadget
[
v
]
+
1
,
i
+
1
))
return
(
Gadget
.
join
([
g
for
g
,
_
in
gadgets
],
joins
,
outs
),
gadget_verts
)
b
,
_
=
process
(
decomposition
)
assert
b
.
is_graph
()
return
b
def
_tests_
():
def
_tests_
():
"""
Helper to run tests.
"""
Helper to run tests.
...
...
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