summaryrefslogtreecommitdiff
path: root/networkx/utils/tests/test_misc.py
Commit message (Collapse)AuthorAgeFilesLines
* Remove deprecated function iterable (#5742)Mridul Seth2022-06-161-17/+0
| | | | Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove deprecated functions dict_to_numpy_array2 and dict_to_numpy_array1 ↵Mridul Seth2022-06-161-10/+0
| | | | | (#5756) Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Remove deprecated function utils.to_tuple (#5755)Mridul Seth2022-06-151-18/+0
|
* Remove deprecated function make_str (#5739)Mridul Seth2022-06-151-15/+0
| | | | | | | * Remove deprecated function make_str * [skip ci] rm from reference guide. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Remove deprecated function is_string_like (#5738)Mridul Seth2022-06-151-7/+0
|
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-021-4/+5
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Deprecate dict to numpy helpers (#5427)Ross Barnowski2022-03-261-11/+20
| | | | | | | | | | | | | * Convert to private fns and add deprecated public wrappers. * Modify existing tests to use private fns. * Add test that dep warnings are raised. * Add dep note. * Add release note. * Add importorskip(numpy).
* Add Generator support to create_py_random_state. (#5380)Ross Barnowski2022-03-101-0/+4
| | | | | * Add Generator support to create_py_random_state. * Add explicit Generator to create_py_randomstate tests.
* Add support for `numpy.random.Generator` (#5336)Ross Barnowski2022-02-181-3/+32
| | | | | | | * Add numpy.random.Generator to create_random_state. * Modify PythonRandomInterface to support Generator + testing. * Fix failing test.
* Style changes (#5022)Dan Schult2021-08-141-26/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add greedy algorithm for solving TSP Many problems of Combinational Optimization can be represented as graphs. These problems have enormous significance in many aspects of science, but there are not any algorithms to solve some of them in polynomial time. However many, heuristic and metaheuristic algorithms have been published over the past years in order to solve / approximate the solutions to these problems. The purpose of this commit is to add implementation of such algorithms for solve one of the most famous problems of Combinational Optimizations, Travelling Salesman Problem (TSP). A greedy algorithm has been implemented at the moment for this reason. "applications" package has been created which include modules that represent a problem. Each module contains several algorithms for solving the specific problem. At this commit, tsp.py module is added which contains greedy_tsp() function; a implementation of a greedy algorithm. * Fix example error * Trivial changes List of changes: Removal of unnesecary _is_weighted() function Improvements on documentation * Add applications package to setup.py file * Change output of greedy algorithm Algorithm's output is a list of nodes now * Add simulated annealing algorithm Add a metaheuristic local search algorithm for solving TSP * Minor changes * Fix example doc errors * Compatible with python 3 * Move tsp module to algorithms package * Code improvements * Handle small graphs and fix doc examples * Documentation changes and rename variables * Adds Threshold Accepting algorithm for TSP * Implemented maximal matching of minimal weight and created test suite. * Removed useless print * Implemented Christofides. * Coding was missing * Add more general traveling_salesman_problem using christofides Also reconfigure import structure and remove min_weight_matching from module since it is now in matching.py * Add new functions to the docs and minor typos * pep8 fixes * fix pep8 and change .gitignore * Add tests of the approximation namespace update docs in approximation/__init__.py * Fix is_matching to check if edges in G. Other tweaks: doc changes and put not_implemented_for on find_matching functions * Improve is_matching selfloop handling and expand tests * Move tsp to approximation directory. Apply black. * Move tsp tests to approximation tests folder * Attempt to bring tsp up to current code. * commit pep8 that my black didnt change, but pep8speaks did find. ?? * tweak a few things and run black * combine #4083 and #3585 into traveling_salesman.py * Match chistofides output to other tsp functions and adjust calling syntax of tests tweak docs tweak see also section * Put big-O complexity in in-line math env. Prevents sphinx from trying to do variable substitution between pipes. * Minor touchups to christofides docstring. * RST touchups to tsp module docstring. * Rm extra string from tsp module. * Docstring touchups for traveling_salesman_problem. * rst fixups for greedy_tsp docstring. * rst formatting for simulated annealing docstring. * More math in-lining for simulated annealing docstring. * rst and minor grammatical fixes to TA docstring. * Fix path-finding and test all methods for tsp function * the refactoring was incomplete. Now maybe is - Add tests of TSP with all methods. - Refactor tests to match simulated_annealing tests and threshold tests. - Unify treatment of weight so unweighted edges use default weight 1. weight now defaults to "weight" with a default value of 1. - Rename tolerance to max_iterations (tolerance is used for error bound) - Rename iterations to N_inner (each iteration takes this many inner loops) - Introduce idioms like `pairwise` and `cycle.copy()` (over cycle[:]) - Allow passthrough of method kwargs for traveling_salesman_problem Still need to: - add test of case where path is more than one edge less that cycle (incomplete_graph) - require cycle input (maybe make default list(G)??) - consider the complexity claims in the doc_strings * More api changes to TSP functions - `chritofides` now allows (and ignores) selfloops - `move` can be a function as well as "1-1" and "1-0" - `method` for traveling_salesman_problem must have 2 arguments instead of passing kwargs. User must "curry" to set parameters - changed doc_string typos in matching.py * Add test to check that cycle=False can remove many edges * Change init_cycle api to require input from user The idea is to make the user specify the initial cycle to start from rather than relying on the programmers default of a greedy algorithm. To easy usage, I check for a string "greedy" as a shortcut. * Update docs with more correct complexity info. * Check for complete graph now more efficient and selfloops ignored * merge is_matching changes * New Networkx changes * Stub for Asadpour. Needed to create GSoC PR * Update to integrate changes from main * Added function stubs and draft docstrings for the Asadpour algorithm * Skeleton classes and methods for tree iterators * Attempting to set up basic tests for MST of a partition * testing * I'm not entirly sure how the commit hook works... * Moved iterators into the correct files to maintain proper codebase visibility * Including Black reformat * Revert "Merge branch 'networkx:main' into main" This reverts commit 0616a2331adfcc02976d305937aa52272ed48266, reversing changes made to 1ea769371f54c4c6f9a51f860caf4a60aef7d094. * Trying to merge again * Attempting to merge (4) * Now passes all tests except test_namespace_alias in /tests/test_import.py * Everything should FINALLY pass (I wipped my networkx dir and re-download from upstream) * reinstall the pre-commit hook * Grabbing black reformats * Working on debugging ascent method plus black reformats * Ascent method terminating, but at non-optimal solution * minor edits * Fixed termination condition, still given non-optimal result * Minor bugfix, still non-optimal result * Fixed subtle bug in find_epsilon() * Cleaned code and tried something which didn't work * Modified the ArborescenceIterator to accept init partition * Black formats * Branch and bound returning optimal solution * Working Ascent method, code needs cleaning * black formatting changes * Performance tweaks and testing fractional answers * Fixed test bug, I hope * Asadpour output for ascent method * Fixed numpy imports crashing pypi tests * Removed branch and bound method. One unit test misbehaving * Added asymmetric fractional test for the ascent method * Removed printn statements and tweaked final test to be more asymmetric * Draft of spanning_tree_distribution * Black changes * Changed HK to only report on the support of the answer * Fixed contraction bug by changing to MultiGraph. Problem with prob > 1 * Black reformats * Fixed pypi test error * Further testing of dist fix * Can sample spanning trees * Developing test for sampling spanning tree * Changed sample_spanning_tree test to Chi squared test * Tweaked signifiance level * Found true minimum sample size * fixed typo * untested implementation of asadpour_tsp * Fixed issue reading flow_dict * Fixed runtime errors in asadpour_tsp * black reformats * Adding test cases * documentation update * Fixed rounding error with tests * One new test and check * Documentation update for the iterators * Attempting to fix class documentation * Pull out the style changes into a separate branch * fix mixed history * more Co-authored-by: Thodoris Sotiropoulos <theosotr@windowslive.com> Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: mjschwenne <mjschwenne@gmail.com>
* Update documentation and testing of arbitrary_element (#4451)Ross Barnowski2021-01-271-0/+28
| | | | | | | | | | | | | | * Update documentation for arbitrary_element. * Add numpydoc sections to docstring and extensive examples. * Add to reference documentation. * Add tests for arbitrary_element. * Update networkx/utils/misc.py Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
* Standard imports (#4401)Jarrod Millman2020-12-071-17/+15
| | | | | | | | | | | | | | | | | | | | | | | | | * Standardize pytest imports * Standardize numpy/scipy imports * Document import style * Fix * More * Fix matplotlib imports * Revert changes to tests * Motivate import policy Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Fix missed imports * Standard np.testing use Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Add unit tests for utils.misc.flatten (#4359)Suvayu Ali2020-11-161-0/+53
| | | | | | | | | | | | | * utils/tests: add tests for flatten * utils/misc.py: flatten always returns a list * Revert "utils/misc.py: flatten always returns a list" This reverts commit 80286dfae55319ded8fc892cd7826c56f528692e. * utils/misc.py: flatten returns tuple when obj is dict/set * utils/misc.py: flatten always returns a tuple
* Format w/ blackJarrod Millman2020-07-101-25/+24
|
* Remove unused imports (#3855)Alex Henrie2020-07-061-1/+1
| | | | | | | | | * Remove unused imports * remove more unused import statements found by pyflakes * move import of random outside of networkx.utils Co-authored-by: Dan Schult <dschult@colgate.edu>
* Upgrade to Py36 syntaxJarrod Millman2020-01-011-2/+2
| | | | find networkx -name \*.py -exec pyupgrade --py36-plus {} \;
* Remove superfluous encoding informationJarrod Millman2019-11-111-1/+0
|
* PEP8 fixesJarrod Millman2019-10-181-1/+18
|
* PEP8 fixes to testsJarrod Millman2019-10-181-1/+1
|
* Remove code using sys.version_info to detect Python 2Jarrod Millman2019-10-181-12/+4
|
* Remove old Python 2 codeJarrod Millman2019-10-181-10/+2
|
* Replace nose.raises with pytest.raises context managerJarrod Millman2019-10-121-14/+3
|
* Remove nose from classesJarrod Millman2019-10-121-5/+2
|
* Remove nose from utilsJarrod Millman2019-10-121-6/+6
|
* Convert nose.tools.assert_* functions into assertsJarrod Millman2019-10-121-56/+56
|
* Use class methods for class setup/teardownStefan van der Walt2019-10-121-1/+1
|
* Change is_list_of_ints to make_list_of_ints (#3617)Dan Schult2019-10-041-3/+17
| | | | | | | | | | | | * Make is_list_of_ints work with nonlists Idea is to use make_list_of_ints which converts floats to ints * Add tests of nonintegeres to is_<special>graph * Fix error added to exception handling in tests for no numpy. Replaces #3335 Fixes #3322
* Unify random state treatment across package (#3058)Dan Schult2018-07-161-1/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #1764 * Add a doc page to explain random number generator handling * replace deprecated numpy.random.random_integers with randint * First set of random_state decorator updates... utils and some generators * protect numpy import from failure is not there * fix doctests in randomness.rst * Update algorithms for new random_state paradigm * Fix tests dependent on python version * Update random_state paradigm in rest of the modules * fix tests for wierd cases. windows 32bit doesn't like big seeds. smallworld wasn't sending seed to utils.discrete_sequence * Add tests. Rewrite randomstate interface class to fix tests * anogther tweak for osx with no deps * improve doc examples for seed. Check all functions for seed independence. Calling with int seed should not affect global RNG * Add testing script and add more variates to RandomInterface * fix typo and remove unneeded file causing nodetest trouble * fix doctest for randomness.rst
* Add seed keyword argument to random_layout and spring_layout (#2766)Harry2017-12-031-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add random_state keyword arguments to random_layout and fruchterman_reingold_layout * Change random_seed function argument to seed for consistency with NetworkX * Improve docstring wording * spring_layout and random_layout use instances of RandomState, rather than seeding the global rng * Add check_random_state helper function * Use check_random_state to generate the rng * Add random_state decorator function to generate numpy.random.RandomState instances from functions with the random_state keyword argument * Add random_state decorators to random_layout and fruchterman_reingold_layout * Change rng to random_state in _fruchterman_reingold and _sparse_fruchterman_reingold * Fix random_state_index for fruchterman_reingold_layout after threshold argument was added * None or np.random returns an instance of RandomState * Add tests for check_random_state * Decorate _fruchterman_reingold and _sparse_fruchterman_reingold so tests pass * Import numpy in try block * Don't import NumPy in global namespace * Make docstrings compatible with Sphinx * Remove import numpy from try block * Rename test funtion for preserve_random_state * Add tests for random_state decorator * Import SkipTest * doc tweaks and name change to create_random_state * Add exception tests
* Comply with pep8Jarrod Millman2017-07-251-26/+34
|
* Remove pareto_sequenceJarrod Millman2017-07-251-1/+0
|
* Remove uniform_sequenceJarrod Millman2017-07-251-2/+1
|
* removed temporary files from test.Francois Malassenet2016-04-171-1/+7
| | | | implemented jfinkels' comment to_tuple
* node_link_graph converts node lists into tuplesFrancois Malassenet2016-04-171-0/+12
| | | | added to_tuple to utils.misc
* Abstracts many-to-one grouping function.Jeffrey Finkelstein2016-04-131-0/+8
| | | | | | | This commit adds the utility function `groups()`, which, given a dictionary representing a many-to-one mapping, outputs the "inverse" one-to-many mapping, which maps values to the set of keys that have that value.
* Change all X.add_path yp nx.add_path(X,Dan Schult2016-02-021-1/+0
|
* Change argname for pairwise to cyclicDan Schult2016-01-141-2/+2
| | | | single nodes return a self-loop. added to utils.rst file.
* utils.misc.pairwise takes cycle argumentDan Schult2016-01-141-0/+12
| | | | | Add cycle keyword argument to pairwise Add tests for pairwise
* Solve merge conflictsMridul Seth2015-06-171-1/+1
|
* Makes Graph.nodes() return iterator instead of listJeffrey Finkelstein2015-06-111-1/+1
| | | | | | | Previously `Graph.nodes()` returned a list of nodes and `Graph.nodes_iter()` returned an iterator over nodes. With this commit, the former function now returns an iterator and the latter no longer exists.
* Add smoke test when there is no mapping.chebee7i2014-05-131-1/+16
|
* Missed one more.chebee7i2014-05-131-1/+2
|
* Fix hash randomization issue in unittest.chebee7i2014-05-131-25/+19
|
* Force ordering in dict_to_numpy_array functionsAric Hagberg2013-11-091-5/+15
| | | | | | Force ordering to be that of the provided mapping dictionary or else create a mapping using the input data dictionary ordering. Fix tests to determine ordering.
* Make make_str() always return unicode, no matter the Python version.chebee7i2013-10-221-0/+29
|
* Fix missing SkipTest import in utils testsAric Hagberg2013-01-051-0/+1
| | | | nose.SkipTest import needed for skipping numpy tests
* Add converter from dictionary of values to 1d numpy array.Aric Hagberg2012-12-291-0/+34
| | | | | Modify dict_to_numpy_array to handle both dict of values and dict of dict of values. Addresses #787
* Refactor utils.Aric Hagberg2011-07-311-0/+37
Fixes #599 --HG-- rename : networkx/tests/test_utils.py => networkx/utils/tests/test_misc.py