Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
S
slabbe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Sébastien Labbé
slabbe
Commits
43627651
Commit
43627651
authored
1 month ago
by
Sébastien Labbé
Browse files
Options
Downloads
Patches
Plain Diff
ajout has_claw_decomposition
parent
38aaafcc
No related branches found
No related tags found
No related merge requests found
Pipeline
#1686004180
skipped
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slabbe/graph.py
+74
-0
74 additions, 0 deletions
slabbe/graph.py
with
74 additions
and
0 deletions
slabbe/graph.py
+
74
−
0
View file @
43627651
...
...
@@ -1048,3 +1048,77 @@ def minimal_eulerian_paths(G, cost=None):
return
paths
def
has_claw_decomposition
(
G
,
certificate
=
False
):
r
"""
Return whether a graph has a claw decomposition.
This is an answer to the question posted at
https://ask.sagemath.org/question/81610/test-if-a-graph-has-a-claw-decomposition/
INPUT:
- ``G`` -- undirected graph
- ``certificate`` -- boolean
OUTPUT:
a boolean or 2-tuple (boolean, solution) if certificate is True
EXAMPLES::
sage: from slabbe.graph import has_claw_decomposition
sage: G1 = Graph( [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3),
...
.:
(
1
,
5
),
(
2
,
3
),
(
2
,
4
),
(
3
,
5
),
(
4
,
6
),
(
4
,
7
),
(
5
,
6
),
(
5
,
7
),
(
6
,
8
),
....:
(
6
,
10
),
(
7
,
9
),
(
7
,
11
),
(
8
,
9
),
(
8
,
10
),
(
9
,
11
),
(
10
,
11
)])
sage
:
has_claw_decomposition
(
G1
)
False
sage
:
has_claw_decomposition
(
G1
,
certificate
=
True
)
(
False
,
None
)
::
sage: G2 = Graph([(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4),
...
.:
(
1
,
5
),
(
2
,
4
),
(
2
,
5
),
(
3
,
5
),
(
4
,
5
)])
sage
:
has_claw_decomposition
(
G2
)
True
sage
:
has_claw_decomposition
(
G2
,
certificate
=
True
)
# random
(
True
,
[[(
0
,
1
),
(
1
,
2
),
(
1
,
5
)],
[(
0
,
3
),
(
1
,
3
),
(
3
,
5
)],
[(
0
,
2
),
(
2
,
4
),
(
2
,
5
)],
[(
0
,
4
),
(
1
,
4
),
(
4
,
5
)]])
"""
import
itertools
from
sage.combinat.matrices.dancing_links
import
dlx_solver
rows
=
[]
id_to_edge
=
[
frozenset
(
edge
)
for
edge
in
G
.
edges
(
labels
=
False
)]
edge_to_id
=
{
edge
:
i
for
(
i
,
edge
)
in
enumerate
(
id_to_edge
)}
for
u
in
G
:
u_neighbors
=
G
.
neighbors
(
u
)
for
three_neighbors
in
itertools
.
combinations
(
u_neighbors
,
3
):
L
=
[
edge_to_id
[
frozenset
((
u
,
v
))]
for
v
in
three_neighbors
]
L
.
sort
()
rows
.
append
(
L
)
d
=
dlx_solver
(
rows
)
solution
=
d
.
one_solution
()
has_solution
=
not
solution
is
None
if
not
certificate
:
return
has_solution
else
:
if
has_solution
:
solution_vertices
=
[[
tuple
(
id_to_edge
[
id
])
for
id
in
rows
[
row_number
]]
for
row_number
in
solution
]
return
(
has_solution
,
solution_vertices
)
else
:
return
(
has_solution
,
solution
)
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