summaryrefslogtreecommitdiff
path: root/networkx/classes/graph.py
Commit message (Collapse)AuthorAgeFilesLines
* Lint using Ruff (#6371)danieleades2023-02-191-1/+1
| | | | | | | | | | | | | | | * 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>
* Fix docstrings (#6329)Jarrod Millman2023-01-041-2/+2
|
* doc: update documentation when providing an iterator over current graph to ↵Sultan Orazbayev2022-12-121-0/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add/remove_edges_from. (#6268) * doc for add_edges_from * doc for digraph * doc for multigraph * multigraph.add_nodes_from returns keylist * update docs for graph - edges * doc update: graph.add_nodes_from * doc update: graph.remove_nodes_from * doc update: graph.add_edges_from * doc update: rewording for graph.add_edges_from * doc update: graph.add_weighted_edges_from rewording * doc update: digraph updated as graph * doc update: digraph minor sync * doc update: multigraph same as graph * Update graph.py * Update digraph.py * Update multigraph.py
* Use scipy.sparse array datastructure (#6037)Jarrod Millman2022-10-121-1/+1
| | | | | | | | | | | | | | * Use scipy.sparse array datastructure * Add reminder to rm wrapper when scipy adds creation fns. * Rm mention of np matrix from code comment. * Update networkx/algorithms/bipartite/matrix.py Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
* Add cache reset for when G._node is changed (#5894)Dan Schult2022-07-251-0/+23
|
* Attempt to reverse slowdown from hasattr needed for cached_property (#5836)Dan Schult2022-07-161-3/+24
| | | | | | | | | | | | | | | | | * Automate reset of cache for _adj,_pred,_succ * Make G._adj a data descriptor that resets G.adj when needed. * update places in the code where both G._succ and G._adj are changed This is no longer needed since G._succ and G._adj are synced during __set__ * testing hasattr(G, `_adj`) no longer ensures an instance. * Make mypy happy * Switch to hardcode attribute names in the data descriptors * Improve doc_strings for the data descriptors
* Move factory attributes to the class instead of instance. (#5850)Dan Schult2022-07-151-7/+0
| | | Move factory attributes to the class instead of instance. ?speedup?
* Remove OrderedGraphs (#5813)Jarrod Millman2022-07-121-5/+0
| | | | | | Removes the deprecated OrderedGraph classes. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Dan Schult <dschult@colgate.edu>
* Remove deprecated function nx.info (#5759)Mridul Seth2022-06-211-1/+2
| | | | | | | | | | * 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-2/+2
| | | | | * Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
* Cache edges, degree, adj properties of Graph classes (#5614)Dan Schult2022-05-111-3/+6
| | | | * Make all graph properties cached properties * one test function is not needed due to test inheritance
* Cache `nodes` property on Graph (#5600)Stefan van der Walt2022-05-081-7/+3
|
* Update .degree() docs: outdated return type (#5529)Brit2022-04-281-6/+4
| | | | | | Fix the return type and description for the `degree` method in the docstrings of all the graph classes. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* More numpy.matrix cleanups for NX2.7 (#5319)Ross Barnowski2022-02-121-4/+4
| | | | | | | | | | | | | | | | | | | * Fix return type in docstring of internal function. * Rm explicit mention of numpy matrix from class docstrings. * Fix return type of floyd_warshall_numpy docstring. * Remove mention of numpy matrix from code comment. * Fix simrank similarity internal docstring. * Rm explicit mention of matrix in favor of 2D array. * Update to_networkx_graph array exception wording. * Remove extraneous mention of numpy matrix. * Don't print array in exception message.
* Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() (#5037)Anutosh Bhat2021-12-121-3/+3
| | | | | | | | | | | | | * Fixed inconsistent documentation for nbunch parameter in DiGraph.edges() * Resolved Requested Changes * Revert changes to degree docstrings. * Update comments in example. * Apply wording to edges method in all graph classes. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Change exception varname e to err (#5130)Dan Schult2021-10-151-8/+8
| | | | A more descriptive variable name for exceptions. This reduces local var naming conflicts when \`e\` is used e.g. to represent edges as a loop variable.
* Changes to rst files to make doctests pass (#4947)Dan Schult2021-07-071-1/+1
| | | | | | | | | | | | | | | | | | | * rst double colons for example code * add nx. prefix to doctest function calls * Remove one line from 1->2 migration rst file the line shows code that works for 1.x *and* 2.x. But it no longer works for all v2.x code. Readers should just use the next line of code, so no reason to keep this in the file. * capture output from subplot and rename DiGraph as DG in introduction.rst * skip running the entire test suite as an example in old_release_log.rst * doctest of examples * remove changes to nexp files
* Raise ValueError if None is added as a node. (#4892)Dan Schult2021-06-151-1/+13
| | | | | | | * 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
* Fix bad import pattern (#4839)Ross Barnowski2021-05-261-0/+2
| | | | | | | | | | | * Add a test to catch importing aliases. * Add test for another bad import pattern. * Fix one bad import pattern. Adds __all__ to some modules where it was missing. * RM networkx namespace test.
* Add approximation algorithms for traveling salesman problem (#4607)Dan Schult2021-05-161-3/+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 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>
* Fix docstrings and remove unused variables (#4501)Andrea Tomassilli2021-01-091-1/+1
| | | | Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* DOC: Switch from napoleon to numpydoc sphinx extension (#4447)Ross Barnowski2020-12-121-6/+8
| | | | | | | * Setup for numpydoc. * Add to doc requirements. * Replace napoleon with numpydoc in conf.py. * DOC: Fixups from numpydoc.
* Safer repr format of variables (#4413)Miroslav Šedivý2020-12-061-1/+1
| | | Use `!r` to trigger string repr with auto quote handling
* DOC: Remove repeated words (#4410)Miroslav Šedivý2020-12-021-2/+2
|
* Remove xml import checks (#4393)Jarrod Millman2020-11-261-1/+1
|
* TST: Refactor to improve coverage. (#4307)Ross Barnowski2020-10-311-8/+9
| | | Refactor exception handling and improve test specificity.
* Add nx.info to str dunder for graph classes (#4241)Ross Barnowski2020-10-091-5/+16
| | | | | | | | | | * Modify graph __str__ to return nx.info. Returns the result of nx.info(self) instead of only the instance name. * TST: Modify tests for new str dunder. * MAINT: move graph summary to __str__ from info
* Format w/ black==20.8b1Jarrod Millman2020-10-061-2/+2
|
* rewrite add_nodes_from to relax code meant to allow ironpython pre-2.7.5 (#4200)Dan Schult2020-09-101-20/+10
|
* Format python in docstrings (#4168)Jarrod Millman2020-08-191-74/+89
| | | | | | | | | | | | | | | | | | | * Format code w/ black * Format docstrings w/ black * Manual cleanup * Tell pytest to ignore planned deprecations * Don't call plt.show during testing * Another known deprecation * DOC: rm duplicate line from docstring example * Minor cleanup Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Format w/ blackJarrod Millman2020-07-101-24/+32
|
* Fix exception causes and messages all over the codebase (#4015)Ram Rachum2020-07-051-8/+8
|
* Add method to clear edges only (#3477)Paolo Lammens2020-07-051-0/+15
| | | | | | | | | | | | | | | | | | | | | | | * feat: `clear_edges` in `networkx.Graph` Method to clear all edges in a graph without altering nodes or graph attributes. Added corresponding test too. * tests: improve `test_clear` in `TestGraph` Added a graph attribute before clearing to test its proper deletion. too. * tests: add tests for `clear` and `clear_edges` specific to DiGraph To test that DiGraph-specific edge records are cleared as well. * fix: specific `clear_edges` for `DiGraph` So that DiGraph's pred/succ also get cleared. * Convert docstrings tests and docs reference links to add clear_edges Co-authored-by: Dan Schult <dschult@colgate.edu>
* Update links to Py3 docs (#4042)Jarrod Millman2020-07-021-3/+3
|
* Fix documentation typo (#3965)Zachary Lawrence2020-05-181-2/+2
|
* Update string formatJarrod Millman2020-01-011-2/+2
| | | | | | | | | find -name "*py" | xargs grep -n '" % ' find -name "*py" | xargs grep -n '"\.format(' find -name "*py" | xargs grep -n "' %" find -name "*py" | xargs grep -n 'msg % ' find -name "*py" | xargs grep -n ' %d ' find -name "*py" | xargs grep -n '\.format('
* Upgrade to Py36 syntaxJarrod Millman2020-01-011-1/+1
| | | | find networkx -name \*.py -exec pyupgrade --py36-plus {} \;
* Convert %-format to fstringJarrod Millman2020-01-011-5/+4
|
* Sample code for subgraph copy: add parenthesis to is_multigraph (#3734)Suny Kim2019-11-271-1/+1
| | | Fixes #3733
* Remove boiler plate from top of modulesJarrod Millman2019-11-111-10/+0
| | | | | | | | | The copyright and author stuff is not necessary, out-of-date, and inconsistent. It takes up visual space and is a pain to police everyone doing the same thing on the top of the module. Git handles authorship in a comprehensive and authoritative way. The LICENSE.txt file applies to all project code.
* Update docs to be more accurate about speed of G.neighbors (#3699)Dan Schult2019-10-301-2/+1
|
* Remove unused importsJarrod Millman2019-10-211-1/+1
|
* Remove unused importsJarrod Millman2019-10-181-3/+0
|
* PEP8 fixesJarrod Millman2019-10-181-1/+1
|
* Remove deprecated functions and methods. add to release notes.Dan Schult2019-10-121-42/+0
|
* Remove future imports needed by Py2Jarrod Millman2019-09-181-1/+0
|
* Fix and Improve docstrings in graph.py (#3569)Salim BELHADDAD2019-09-041-2/+11
| | | Some improvements in the docstrings of the three linked methods: order, number_of_nodes, and _len__.
* Fix a typo in docstring for get_edge_data (#3564)Søren Fuglede Jørgensen2019-08-311-1/+1
| | | This closes #3550.
* Typo fix (#3424)Andy Garfield2019-05-071-1/+1
|
* Update copyrightJarrod Millman2019-03-301-1/+1
|