Skip to content

Conversation

@Mjid1
Copy link

@Mjid1 Mjid1 commented Dec 27, 2025

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

if (not self.is_directed() and not self.has_loops() and not self.has_multiple_edges() and n >= 3):
vertices = list(self)
ore_holds = True
for i, u in enumerate(vertices):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you could use from itertools import combinations and then for u, v in combinations(vertices, 2) to list all pairs.

from itertools import combinations
degree = self.degree(labels=True)
ore_holds = all(degree[u] + degree[v] >= n
                for u, v in combinations(vertices, 2)
                if not self.has_edge(u, v))

# Return a trivial Hamiltonian cycle if possible, else True
# (Here, we just shortcut and return True, or could construct a cycle)
from sage.graphs.graph import Graph
cycle_edges = [(vertices[i], vertices[(i+1)%n]) for i in range(n)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can not ensure that all edges in this list are edges of the graph.
You could implement Palmer's algorithm (see https://en.wikipedia.org/wiki/Ore%27s_theorem) to get a valid cycle.

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Documentation preview for this PR (built with commit 48859cf; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants