Skip to content

Maxcut heuristics - #4138

Merged
jarrodmillman merged 41 commits into
networkx:masterfrom
CharJon:maxcut_heuristics
Dec 15, 2020
Merged

jarrodmillman merged 41 commits into
networkx:masterfrom
CharJon:maxcut_heuristics

Conversation

@CharJon

@CharJon CharJon commented Aug 7, 2020

Copy link
Copy Markdown
Contributor

This adds a simple one exchange heuristic to calculate a solution for the maximum cut problem. We mirrored the return values from the already implemented minimum cut functions.

Mohammed Ghannam and others added 11 commits August 7, 2020 12:29
* Simple randomized maxcut heuristic

* Remove approximation guarantee test

Test is not expected to pass all the time due to randomness.

* Preserve random state for cut heuristic

* Add one exchange max cut heuristic

* Fixes && Refactoring && Default deterministic output

* maxcut/simple.py: Add docstring and make initial_cut optional.

* maxcut/simple.py: Add shuffle again. Make initial set a set.

Co-authored-by: Jonas Charfreitag <[email protected]>
* Fix parse_edgelist behavior with multiple attributes

* fixed test case

Co-authored-by: chris <chris@orchid>
* updated draw_networkx + added test

* added newline

* skip test if numpy is not installed

* change skip if numpy is not available

* switch elif to if
* add code for tree isomorphism, with tests

* fix typo in comment

* one more typo in comments

* fix some PEP8 formatting, that flake8 didn't care about

* rename files as tree_isomorphism

* run code through black formatter

* incorporate feedback from dschult in PR4067

* fix missing import for not_implemented_for decorator

* swap edge order randomly in testing routine positive_single_tree

* run black on test_tree_isomorphism.py

* spacing tweak to allow CI test of docs

Co-authored-by: Dan Schult <[email protected]>
@pep8speaks

pep8speaks commented Aug 7, 2020 •

Copy link
Copy Markdown

Hello @CharJon! Thanks for updating this PR.

Line 23:1: F403 'from networkx.algorithms.approximation.maxcut import ' used; unable to detect undefined names
Line 23:1: F401 'networkx.algorithms.approximation.maxcut.
' imported but unused

Please install and run psf/black.

Comment last updated at 2020-10-12 16:05:50 UTC

@dschult

dschult commented Aug 7, 2020

Copy link
Copy Markdown
Member

I guess you should add this to the docs in doc/reference/algorithms/approximation.rst and you can check how it looks on the Details link of the "Circle-CI: build artifact" portion of "All checks have passed" section of the PR webpage. If that isn't clear please ask.

For the tests, can you make the tests deterministic (add seeds for the random generators there)?

Thanks!

@dschult

dschult commented Oct 6, 2020

Copy link
Copy Markdown
Member

I've reviewed this and it looks read to merge.
The docstrings should ideally start with a single short one-line description (used for any links to this function from other parts of the docs) followed by a blank line and then a paragraph describing in more detail what the function does. These two functions have two-line starts to the docstrings. So we'd need to reword them to be shorter and then add a paragraph to complete the description of what they do. Would be good to have a very brief description of what a cut value is in that first paragraph.

I can do the docstring changes if you don't have the time now. I'm going to approve the PR as is so we can move toward getting a second approver. At that point I'll put in docstring changes if they're not in yet. Thanks!!

@rossbar
rossbar self-requested a review October 6, 2020 16:09
@dschult

dschult commented Oct 10, 2020

Copy link
Copy Markdown
Member

Looks like something is wrong with the debian ip address.
I'm not sure how to fix that... wait and then restart I guess...

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like a really nice addition, thanks @CharJon . I took the liberty of taking care of some minor doc/import formatting things and pushed them up to your branch. Other than that, just a few questions/comments (most of which can be ignored). Otherwise LGTM!

@rossbar

rossbar commented Dec 13, 2020

Copy link
Copy Markdown
Contributor

Note that the circleCI build failures would probably be fixed by rebasing on master.

CharJon and others added 8 commits December 14, 2020 09:40
Docstring type error.

Co-authored-by: Ross Barnowski <[email protected]>
Use compact set construction in randomized_partitioning.

Co-authored-by: Ross Barnowski <[email protected]>
Use compact set construction in _swap_node_partition.

Co-authored-by: Ross Barnowski <[email protected]>
Remove comments with no additional information.

Co-authored-by: Ross Barnowski <[email protected]>

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for taking a look at the suggestions @CharJon ! Two minor suggestions but not blockers, this is good as-is IMO. Thanks for the nice addition!

@jarrodmillman jarrodmillman added this to the networkx-2.6 milestone Dec 15, 2020
@jarrodmillman
jarrodmillman merged commit c097575 into networkx:master Dec 15, 2020
MridulS pushed a commit to MridulS/networkx that referenced this pull request Feb 4, 2023
* Simple maxcut heuristics (#2)

* Simple randomized maxcut heuristic

* Remove approximation guarantee test

Test is not expected to pass all the time due to randomness.

* Preserve random state for cut heuristic

* Add one exchange max cut heuristic

* Fixes && Refactoring && Default deterministic output

* maxcut/simple.py: Add docstring and make initial_cut optional.

* maxcut/simple.py: Add shuffle again. Make initial set a set.

Co-authored-by: Jonas Charfreitag <[email protected]>

* Fix parse_edgelist behavior with multiple attributes (networkx#4125)

* Fix parse_edgelist behavior with multiple attributes

* fixed test case

Co-authored-by: chris <chris@orchid>

* CI: temporary fix for CI latex installation issues (networkx#4131)

* Updated draw_networkx to accept numpy array for edgelist (networkx#4132)

* updated draw_networkx + added test

* added newline

* skip test if numpy is not installed

* change skip if numpy is not available

* switch elif to if

* Add tree isomorphism (networkx#4067)

* add code for tree isomorphism, with tests

* fix typo in comment

* one more typo in comments

* fix some PEP8 formatting, that flake8 didn't care about

* rename files as tree_isomorphism

* run code through black formatter

* incorporate feedback from dschult in PR4067

* fix missing import for not_implemented_for decorator

* swap edge order randomly in testing routine positive_single_tree

* run black on test_tree_isomorphism.py

* spacing tweak to allow CI test of docs

Co-authored-by: Dan Schult <[email protected]>

* maxcut/simple.py: Updated documentation and some names.

* maxcut/simple.py (Tests): Add _is_valid_cut function and make use of it.

* Move maxcut code to approximation dir.

* maxcut.py: Add not implemented for decorator to maxcut functions.

* test_maxcut.py: Testcase for global optimality.

* maxcut: Fix line width to 88.

* Maxcut: Add __all__ to maxcut.py.

* Maxcut: Use networkx style seed for functions.

* Maxcut: Move to fully soft dependence on numpy.

* Maxcut: Bugfix. Replace choice with sample in test.

* Remove unnecessary set constructor

* Add Max Cut reference in docs

* Fix seed in Max Cut tests

* Add negative weight test for Max Cut

* Improve docstrings

* Fix formatting

* Fix formatting for test file

* Fix formatting for test file

* Docstring formatting touchups.

* Call graph generator from top-level namespace.

* Update networkx/algorithms/approximation/maxcut.py

Docstring type error.

Co-authored-by: Ross Barnowski <[email protected]>

* Update networkx/algorithms/approximation/maxcut.py

Use compact set construction in randomized_partitioning.

Co-authored-by: Ross Barnowski <[email protected]>

* Update networkx/algorithms/approximation/maxcut.py

Use compact set construction in _swap_node_partition.

Co-authored-by: Ross Barnowski <[email protected]>

* Update networkx/algorithms/approximation/tests/test_maxcut.py

Remove comments with no additional information.

Co-authored-by: Ross Barnowski <[email protected]>

* Change cut_value to scalar.

* test_maxcut: Better naming for import.

* maxcut.py: Remove one whitespace.

* Update networkx/algorithms/approximation/tests/test_maxcut.py

Co-authored-by: Ross Barnowski <[email protected]>

* Add comment to why shuffling nodes in one exchange has some benefit.

Co-authored-by: Mohammed Ghannam <[email protected]>
Co-authored-by: Christoph Martin <[email protected]>
Co-authored-by: chris <chris@orchid>
Co-authored-by: Ross Barnowski <[email protected]>
Co-authored-by: Tanguy Fardet <[email protected]>
Co-authored-by: Craig Schmidt <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Mohammed Ghannam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

9 participants