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

Add a method for calculating num_edges #32

Merged
merged 4 commits into from
Jun 18, 2024
Merged

Conversation

elham-azd
Copy link
Contributor

@elham-azd elham-azd commented Jun 14, 2024

Closes #28

Copy link
Member

@arcondello arcondello left a comment

Choose a reason for hiding this comment

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

Also needs a release note.

>>> model.num_edges()
0
"""
return sum(1 for sym in self.iter_symbols() for _ in sym.iter_successors())
Copy link
Member

Choose a reason for hiding this comment

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

We might as well do the more performant thing. Something like

        cdef Py_ssize_t num_edges = 0
        for i in range(self._graph.num_nodes()):
            num_edges += self._graph.nodes()[i].successors().size()
        return num_edges

dwave/optimization/model.pyx Outdated Show resolved Hide resolved
@arcondello arcondello added the enhancement New feature or request label Jun 14, 2024
Comment on lines 701 to 702
This example add a single (size 20) decision symbol and
a single (size 3) constant symbol checks the number of
Copy link
Member

Choose a reason for hiding this comment

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

I think these numbers are incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ughh, forgot to update this. Thanks!

---
features:
- |
Adds a method for calculating num_edges
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like

    Add `Model.num_edges()` method. See `#28 <https://github.com/dwavesystems/dwave-optimization/issues/28>`_.

@arcondello arcondello merged commit 3e7b03f into dwavesystems:main Jun 18, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a method for calculating num_edges in model.pyx
2 participants