Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created functions to generate random k-tree and partial k-tree graphs #36587

Merged
merged 17 commits into from
Feb 25, 2024

Conversation

damianbasso
Copy link
Contributor

@damianbasso damianbasso commented Oct 30, 2023

Implemented graph generators which produce a random k-tree and a random partial k-tree. The k-tree algorithm first generates a complete graph, before adding vertices one by one, creating a clique utilising random existing vertices and the new vertex. Partial k-trees are generated by producing a k-tree and then randomly removing edges from it.

Previously SageMath lacked a way to generat randomised graphs which have a fixed treewidth value. This provides a methodology to do so .

Addresses #36586

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • 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 accordingly.

@dcoudert
Copy link
Contributor

For your information, there is an (old) open issue about generating k-trees #11369.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution. Random k-trees are useful.

I have a few suggestions for improving the code.

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
@damianbasso
Copy link
Contributor Author

Thank you for this contribution. Random k-trees are useful.

I have a few suggestions for improving the code.

Thanks for reviewing @dcoudert. Just added another commit implementing your suggestions.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

a few more suggestions.

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
@damianbasso
Copy link
Contributor Author

a few more suggestions.

Thanks, some good ideas. I've added to the Pull Request

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

some details.

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

LGTM.

@vbraun
Copy link
Member

vbraun commented Dec 3, 2023

[sagemath_doc_html-none] OSError: /home/release/Sage/src/sage/graphs/generators/random.py:docstring of sage.graphs.generators.random.RandomPartialKTree:11: WARNING: Bullet list ends without a blank line; unexpected unindent.

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 24, 2023
    
Nauty has a generator of k-trees. We add an interface to this generator.
This is a complement of sagemath#36587.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36924
Reported by: David Coudert
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 26, 2023
    
Nauty has a generator of k-trees. We add an interface to this generator.
This is a complement of sagemath#36587.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36924
Reported by: David Coudert
Reviewer(s): Matthias Köppe
@dcoudert
Copy link
Contributor

dcoudert commented Feb 5, 2024

You should certainly rebase the branch on the last beta to launch all the tests.

@damianbasso damianbasso force-pushed the kTreeGenerators branch 2 times, most recently from e745c71 to 92d5967 Compare February 6, 2024 05:25
Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

Some improvements to ensure that the method cannot be called with wrong parameters.

src/sage/graphs/generators/random.py Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

LGTM.

@dcoudert
Copy link
Contributor

I don't understand the last 2 commits. Is it due to the last beta release ?

You should certainly rebase the branch on the last beta.

src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
src/sage/graphs/generators/random.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

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

I have no more comments. Thanks.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 18, 2024
…tial k-tree graphs

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Implemented graph generators which produce a random k-tree and a random
partial k-tree. The k-tree algorithm first generates a complete graph,
before adding vertices one by one, creating a clique utilising random
existing vertices and the new vertex. Partial k-trees are generated by
producing a k-tree and then randomly removing edges from it.

<!-- Why is this change required? What problem does it solve? -->
Previously SageMath lacked a way to generat randomised graphs which have
a fixed treewidth value. This provides a methodology to do so .
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
Addresses sagemath#36586
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.


<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36587
Reported by: Damian Basso
Reviewer(s): Damian Basso, David Coudert
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 19, 2024
…tial k-tree graphs

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->
Implemented graph generators which produce a random k-tree and a random
partial k-tree. The k-tree algorithm first generates a complete graph,
before adding vertices one by one, creating a clique utilising random
existing vertices and the new vertex. Partial k-trees are generated by
producing a k-tree and then randomly removing edges from it.

<!-- Why is this change required? What problem does it solve? -->
Previously SageMath lacked a way to generat randomised graphs which have
a fixed treewidth value. This provides a methodology to do so .
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
Addresses sagemath#36586
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.


<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36587
Reported by: Damian Basso
Reviewer(s): Damian Basso, David Coudert
@vbraun vbraun merged commit 34e5618 into sagemath:develop Feb 25, 2024
4 checks passed
@mkoeppe mkoeppe added this to the sage-10.3 milestone Mar 7, 2024
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.

4 participants