summaryrefslogtreecommitdiff
path: root/networkx/classes/tests/test_function.py
Commit message (Collapse)AuthorAgeFilesLines
* Lint using Ruff (#6371)danieleades2023-02-191-3/+3
| | | | | | | | | | | | | | | * lint and fix using ruff * add flake8-pie lints * remove useless import alias * bump version * bump deps --------- Co-authored-by: daniel.eades <daniel.eades@hotmail.com>
* Update developer requirements (#6429)Jarrod Millman2023-02-141-2/+2
| | | | | * Update developer requirements * Run linter
* Add clear edges method to the list of methods to be frozen by the nx.… (#6190)Adam Richardson2022-11-151-0/+13
| | | | | * Add clear edges method to the list of methods to be frozen by the nx.freeze function * Change tests to create new graph instead of using class attribute
* Minor docstring touchups and test refactor for `is_path` (#5967)Ross Barnowski2022-09-081-12/+10
| | | | | | | | | | | | | | | * Touch up docstring. * Condense conditional. * Minor refactor of ispath test - parametrize and rm redundant. * Add release note. * Update networkx/classes/function.py Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Change is_path to return False when node not in G instead of raising ↵pmlpm19862022-09-061-0/+4
| | | | | | exception (#5943) Formerly, is_path raised a KeyError when one of the nodes in the input path was not actually in G. This PR modifies the function so that it returns False in this case instead of raising an exception.
* Remove deprecated function nx.info (#5759)Mridul Seth2022-06-211-32/+0
| | | | | | | | | | * Remove deprecated function nx.info * remove functions from TOC * replace print(nx.info(G)) with print(G) in example Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Use isort with pre-commit to enforce import guidelines (#5659)Mridul Seth2022-06-021-1/+3
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Style changes (#5022)Dan Schult2021-08-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Raise ValueError if None is added as a node. (#4892)Dan Schult2021-06-151-5/+5
| | | | | | | * Raise ValueError if None is added as a node. Removed some tests that checked that errors raised when None was a node. * update tutorial to make a stronger statement about None
* Refactor testing utilities (#4829)Jarrod Millman2021-05-261-38/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Refactor testing utilities Change `assert_edges_equal`, `assert_graphs_equal`, and `assert_nodes_equal` to be more pytest-idiomatic. For example, `assert_edges_equal` becomes the Boolean function `edges_equal` and then the assert is done the testing file (i.e., `assert edges_equal(edges1, edges2)`). This also makes these utility functions useful in nontesting situations where you want to compare edges, but not raise an exception based on the result. * Move testing utility functions * Use new testing utilities * Deprecate assert_*_equal testing utilities * Document node, edge, and graph equality helper functions * text nits. * Update networkx/tests/test_convert_pandas.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_sparse6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/readwrite/tests/test_graph6.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/generators/tests/test_classic.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_operations.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tree/tests/test_coding.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/tests/test_dag.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/algorithms/minors/tests/test_contraction.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * add short equality description to docstring * Suppress known warnings Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Refactor and improve test coverage for restricted_view and selfloop_edges ↵Ross Barnowski2020-11-131-47/+91
| | | | | | | | | | | | | | | (#4351) * TST: Improve coverage of restricted_view. Refactor original test into two parametrized tests that cover all graph types. * TST: Break up selfloop edges test into smaller tests. Refactors test_selfloops into four smaller tests, each focused on specific behavior. * TST: improve coverage of selfloop_edges.
* Test and document missing nodes/edges in set_{node/edge}_attributes (#4346)Ross Barnowski2020-11-131-92/+145
| | | | | | | | | | | | | | | | * TST: parametrize set_node_attributes test. * TST: Add test to improve set_node_attribute coverage. * TST: parametrize set_edge_attribute tests. * TST: add test for set_edge_attributes w/ missing edges. * Add tests for missing edges in values dict. * Add examples to set_{node/edge}_attributes docstrings. Add examples illustrating the silent ignoring of nodes/edges in the values dict that are not in G.
* MAINT: Update nx.info (#4193)Andrew Eckart2020-10-011-19/+2
| | | | | Report name, number of nodes, and number of edges of a graph. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Add function to calculate path cost for a specified path (#4069)Danny Niquette2020-07-261-0/+27
| | | | | | | | | | | | | | | | | | | | | | | * Began writing function for specified path cost and associated tests * Cleaned up formatting and finished writing test * Made minor changes as suggested in PR comment. Name changes and syntax changes * polished up and wrote tests for is_path, adjusted tests to include Digraph and MultiDiGraph, added sphinx shorthand in docs * Fixed most pep8 warnings (excluding line too long) * Updated docstring and fixed is_path to have lower memory footprint * minor tweaks to allow rebase * Add credits for contributor * Run black Co-authored-by: DNiquette16 <Dniquette16@gmail.com> Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Jarrod Millman <jarrod.millman@gmail.com>
* Allow G.remove_edges_from(nx.selfloops_edges(G)) (#4080)Dan Schult2020-07-201-0/+25
|
* Format w/ blackJarrod Millman2020-07-101-95/+150
|
* Fixing docs for nx.info(), along with necessary tests (#3893)Pradeep Reddy Raamana2020-04-061-0/+4
| | | | | | | | | | | * documenting the behaviour correctly * adding tests to lock the behaviour * PEP * one-line docstring * pep
* Upgrade to Py36 syntaxJarrod Millman2020-01-011-1/+1
| | | | find networkx -name \*.py -exec pyupgrade --py36-plus {} \;
* Remove shebang from non-executablesJarrod Millman2019-11-111-1/+0
|
* PEP8 fixesJarrod Millman2019-10-181-4/+4
|
* PEP8 fixes to testsJarrod Millman2019-10-181-9/+9
|
* Remove nose from classesJarrod Millman2019-10-121-20/+20
|
* Convert nose.tools.assert_* functions into assertsJarrod Millman2019-10-121-113/+113
|
* Fix test_function checksStefan van der Walt2019-10-121-13/+12
|
* Use class methods for class setup/teardownStefan van der Walt2019-10-121-14/+16
|
* adding support for singleton in add_path and add_star (#3285)Tanay Gahlot2019-01-021-0/+23
| | | | | | | | | | Fixes #3277 * adding support for singleton in add_path and add_star * adding test cases for singleton * adding test cases that cover the try-except loop for add_star and add_cycle
* Deleted a duplicated test_random_graph in bipartite.tests.test_genera… (#2790)Mads Jensen2018-02-021-3/+3
| | | | | | | | | | | | | | | | | | * Deleted a duplicated test_random_graph in bipartite.tests.test_generators * Renamed test_multigraphs_equal to test_multidigraphs_equal in test_utils * Deleted a duplicated test_adjlist_digraph in test_adjlists in readwrite-tests * Renamed a bunch of duplicated test names. * Deleted a duplicate TestEdgelist.test_edgelist_digraph. * Renamed a duplicate TestOpenFileDecorator.test_writer_kwarg_path. * Fix the broken tests that used to be hidden by duplicate name * Change list to sorted in test for py3.4 and py3.5
* fix add_path to add the first node when the length of the given node list is oneSanghack Lee2017-11-181-0/+36
|
* Unravel subgraph chains (#2635)Dan Schult2017-08-261-0/+8
| | | | | | | | | | | | * Shortcut chains of subgraph views in common cases. Turns out the general case of chains of subgraph views is hard to make a shortcut for. So this only does the common case of node induced subgraphs of subgraphs. * Add tests for subgraph chains * Add more tests of chains of subgraphs
* Comply with pep8Jarrod Millman2017-08-171-0/+1
|
* Simplify base classes. (#2604)Dan Schult2017-08-121-9/+25
| | | | | | | | | | * move selfloop methods out of graph classes into function.py * replace G.node with G.nodes. fix Pickle of views * Replace G.edge with G.edges * Add a few lines of docs for release realted to this PR.
* Next attempt to meld graphviews with base classes (#2593)Dan Schult2017-08-121-0/+11
| | | | | | | | | | | | | | | | | | | | | | * Update code to prepare for melding graphviews * Meld graphviews into graph classes * Cleanup subgraph calling sign. and remove duplicate code * Add some tests for raising exceptions * update edge_kcomponents to avoid readonly views. * Add root_graph attribute and tests Update tests for root_graph as well as fresh_copy. I left fresh_copy as an attribute even with root_graph because a view might switch the data structure of the view from directed to undirected. Going to the root_graph.__class__ may not give you what you need to create a graph like the view. Fresh_copy gives a null graph with the directed/multi type of that view or graph.
* Remove automatic assignment of G.name from many generators (#2557)Dan Schult2017-07-271-0/+1
| | | | | | | | | | * Remove default setting of G.name in generators. I left them for Atlas.py and small.py as the seemed to be useful for telling which graph is which when creating many. Fixes #1906 * Fix expected outcomes on tests re G.name
* Refactor set_node_attributes() and set_edge_attributes() (#2553)Michael E. Rose2017-07-261-22/+55
| | | | | | | | | | | | | * make set_node_attriutes() work with any kind of container * switch arguments in docstring and adapt comments * Make set_edge_attributes() with any kind of container * Update release notes with #2553 set/get_node/edge_attributes * Update package codebase with API change for set_*_attributes Fixes #2343
* Doc ordered graph classes (#2516)Jarrod Millman2017-07-161-96/+106
| | | | | | | | | | | | | | | | | | | * Add minimal docstrings * Add note about ordered graph variants * Mention ordered variant in `See Also` section * Comply with pep8 * Replace reference to LogGraph with PrintGraph LogGraph was a reference to a graph that logged each mutation. That's what PrintGraph does and is provided in the examples directory. * Do not claim OrderedGraphs maintain the order of adding edges * Remove OrderedGraph examples and minor cleanup for Sphinx
* Move data structure to private names and replace with readonly structures ↵Dan Schult2017-06-261-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#2475) * Dont assume iterators for nodes/edges/degrees (prep for views) * Add graph view classes for nodes/edges/degree * Add right set operations (not present in python3.3 KeysView * Add nodes before adding edges so python36 tests work By only adding edges, the nodes were added in order (0,1,3,2) and with the ordered nature of python3.6 dicts the tests failed. Could also fix by using nodelist on each call to to_convert_... * weighted graph convert tests testing empty graphs The edge iterator was exhausted for source before being used for dest * allow DegreeView to include case of nbunch * Make node/edge/degree properties of Graph * View contains fix and Viewers can return self. More tests * Add more tests including one for #2347 * Add nbunch tests and pep8 * Rename to EdgeView and EdgeDataView * docs tweaks and pep8 * fix up nodeDataView contains. Add and clean up tests. * Change the graph attributes to read-only properties * Reframe views code and extend _node to all networkx (still need examples) * Clean up and pep8 for view changes * ername AtlasViews, simplify code and add docstrings * Make G[u] return a view, and catch some doc bugs * Update views to use _node,_adj. Add len to EdgeDataView * minor adjustments to example subclass/printgraph
* Base class testsAric Hagberg2016-07-311-2/+12
| | | | | Fix ordering and ambiguity in base class tests. The conversion of multidigraphs to multigraphs is ambigious since the ordering can determin the number of resulting edges. E.g. the multidigraph [(1,2),(2,1),(2,1)] could result in the multigraph [(1,2)] or [(2,1),(2,1)].
* Fix tests.Valentin Lorentz2016-07-301-2/+2
|
* Fix tests failing because of ordering issues.Valentin Lorentz2016-07-301-18/+19
|
* Remove methods add_path/star/cycle and fix miscDan Schult2016-02-021-1/+1
|
* Add functions for add_path/star/cycleDan Schult2016-02-021-0/+43
|
* #1849 modified test case for create_empty_copy()Varun2015-11-171-6/+6
|
* Remove degree_iter(),now degree() returns an integer for single node and ↵Mridul Seth2015-06-271-7/+7
| | | | iterator for else
* Solve merge conflictsMridul Seth2015-06-171-5/+5
|
* Makes Graph.nodes() return iterator instead of listJeffrey Finkelstein2015-06-111-16/+15
| | | | | | | 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 is_empty() and update is_weighted() to cover empty graph.chebee7i2015-04-291-0/+9
|
* Rename to is_negatively_weighted, minor docstring edits.chebee7i2015-04-291-12/+27
| | | | Also add unit tests for corner cases.
* Some code fixesThodoris Sotiropoulos2015-04-271-9/+9
| | | | | | | | List of changes: - Rename function to is_weighted() - Remove unnecessary variable - Fix code allignment on documentation - Remove unnecessary else statement
* Style changesKonstantinos Karakatsanis2015-04-161-1/+1
|
* Add negative_weights functionKonstantinos Karakatsanis2015-04-151-0/+21
|