summaryrefslogtreecommitdiff
path: root/networkx/algorithms/approximation
diff options
context:
space:
mode:
authorMridul Seth <seth.mridul@gmail.com>2022-06-02 19:54:09 +0400
committerGitHub <noreply@github.com>2022-06-02 08:54:09 -0700
commit5c0b11afb4c0882a070d522ef3fa41482ba935d3 (patch)
tree1b8f21413afd65617420203cf834a8d15d8282ab /networkx/algorithms/approximation
parent4dba24ba22fc8c4906e16f67b5cf103ee0a830b3 (diff)
downloadnetworkx-5c0b11afb4c0882a070d522ef3fa41482ba935d3.tar.gz
Use isort with pre-commit to enforce import guidelines (#5659)
* Add isort to pre-commit * Run isort on all python files (except __init__.py ones)
Diffstat (limited to 'networkx/algorithms/approximation')
-rw-r--r--networkx/algorithms/approximation/clustering_coefficient.py3
-rw-r--r--networkx/algorithms/approximation/dominating_set.py2
-rw-r--r--networkx/algorithms/approximation/kcomponents.py6
-rw-r--r--networkx/algorithms/approximation/maxcut.py2
-rw-r--r--networkx/algorithms/approximation/ramsey.py1
-rw-r--r--networkx/algorithms/approximation/steinertree.py2
-rw-r--r--networkx/algorithms/approximation/tests/test_clique.py10
-rw-r--r--networkx/algorithms/approximation/tests/test_distance_measures.py1
-rw-r--r--networkx/algorithms/approximation/tests/test_dominating_set.py6
-rw-r--r--networkx/algorithms/approximation/tests/test_kcomponents.py1
-rw-r--r--networkx/algorithms/approximation/tests/test_steinertree.py4
-rw-r--r--networkx/algorithms/approximation/tests/test_traveling_salesman.py4
-rw-r--r--networkx/algorithms/approximation/tests/test_treewidth.py15
-rw-r--r--networkx/algorithms/approximation/traveling_salesman.py6
-rw-r--r--networkx/algorithms/approximation/treewidth.py4
15 files changed, 38 insertions, 29 deletions
diff --git a/networkx/algorithms/approximation/clustering_coefficient.py b/networkx/algorithms/approximation/clustering_coefficient.py
index 291753db..d37a7540 100644
--- a/networkx/algorithms/approximation/clustering_coefficient.py
+++ b/networkx/algorithms/approximation/clustering_coefficient.py
@@ -1,5 +1,4 @@
-from networkx.utils import not_implemented_for
-from networkx.utils import py_random_state
+from networkx.utils import not_implemented_for, py_random_state
__all__ = ["average_clustering"]
diff --git a/networkx/algorithms/approximation/dominating_set.py b/networkx/algorithms/approximation/dominating_set.py
index 548e21d5..76853230 100644
--- a/networkx/algorithms/approximation/dominating_set.py
+++ b/networkx/algorithms/approximation/dominating_set.py
@@ -11,8 +11,8 @@ incident to an endpoint of at least one edge in *F*.
"""
-from ..matching import maximal_matching
from ...utils import not_implemented_for
+from ..matching import maximal_matching
__all__ = ["min_weighted_dominating_set", "min_edge_dominating_set"]
diff --git a/networkx/algorithms/approximation/kcomponents.py b/networkx/algorithms/approximation/kcomponents.py
index 7e2333de..239cc0f2 100644
--- a/networkx/algorithms/approximation/kcomponents.py
+++ b/networkx/algorithms/approximation/kcomponents.py
@@ -1,17 +1,15 @@
""" Fast approximation for k-component structure
"""
import itertools
-from functools import cached_property
from collections import defaultdict
from collections.abc import Mapping
+from functools import cached_property
import networkx as nx
+from networkx.algorithms.approximation import local_node_connectivity
from networkx.exception import NetworkXError
from networkx.utils import not_implemented_for
-from networkx.algorithms.approximation import local_node_connectivity
-
-
__all__ = ["k_components"]
diff --git a/networkx/algorithms/approximation/maxcut.py b/networkx/algorithms/approximation/maxcut.py
index d2b5eced..59dfa63c 100644
--- a/networkx/algorithms/approximation/maxcut.py
+++ b/networkx/algorithms/approximation/maxcut.py
@@ -1,5 +1,5 @@
import networkx as nx
-from networkx.utils.decorators import py_random_state, not_implemented_for
+from networkx.utils.decorators import not_implemented_for, py_random_state
__all__ = ["randomized_partitioning", "one_exchange"]
diff --git a/networkx/algorithms/approximation/ramsey.py b/networkx/algorithms/approximation/ramsey.py
index 9337ccfa..1692477b 100644
--- a/networkx/algorithms/approximation/ramsey.py
+++ b/networkx/algorithms/approximation/ramsey.py
@@ -3,6 +3,7 @@ Ramsey numbers.
"""
import networkx as nx
from networkx.utils import not_implemented_for
+
from ...utils import arbitrary_element
__all__ = ["ramsey_R2"]
diff --git a/networkx/algorithms/approximation/steinertree.py b/networkx/algorithms/approximation/steinertree.py
index f999694d..496098b6 100644
--- a/networkx/algorithms/approximation/steinertree.py
+++ b/networkx/algorithms/approximation/steinertree.py
@@ -1,7 +1,7 @@
from itertools import chain
-from networkx.utils import pairwise, not_implemented_for
import networkx as nx
+from networkx.utils import not_implemented_for, pairwise
__all__ = ["metric_closure", "steiner_tree"]
diff --git a/networkx/algorithms/approximation/tests/test_clique.py b/networkx/algorithms/approximation/tests/test_clique.py
index dadde792..ebda285b 100644
--- a/networkx/algorithms/approximation/tests/test_clique.py
+++ b/networkx/algorithms/approximation/tests/test_clique.py
@@ -2,10 +2,12 @@
import networkx as nx
-from networkx.algorithms.approximation import max_clique
-from networkx.algorithms.approximation import clique_removal
-from networkx.algorithms.approximation import large_clique_size
-from networkx.algorithms.approximation import maximum_independent_set
+from networkx.algorithms.approximation import (
+ clique_removal,
+ large_clique_size,
+ max_clique,
+ maximum_independent_set,
+)
def is_independent_set(G, nodes):
diff --git a/networkx/algorithms/approximation/tests/test_distance_measures.py b/networkx/algorithms/approximation/tests/test_distance_measures.py
index c9ffd31f..81251503 100644
--- a/networkx/algorithms/approximation/tests/test_distance_measures.py
+++ b/networkx/algorithms/approximation/tests/test_distance_measures.py
@@ -2,6 +2,7 @@
"""
import pytest
+
import networkx as nx
from networkx.algorithms.approximation import diameter
diff --git a/networkx/algorithms/approximation/tests/test_dominating_set.py b/networkx/algorithms/approximation/tests/test_dominating_set.py
index da1abdc5..892ce34e 100644
--- a/networkx/algorithms/approximation/tests/test_dominating_set.py
+++ b/networkx/algorithms/approximation/tests/test_dominating_set.py
@@ -1,6 +1,8 @@
import networkx as nx
-from networkx.algorithms.approximation import min_weighted_dominating_set
-from networkx.algorithms.approximation import min_edge_dominating_set
+from networkx.algorithms.approximation import (
+ min_edge_dominating_set,
+ min_weighted_dominating_set,
+)
class TestMinWeightDominatingSet:
diff --git a/networkx/algorithms/approximation/tests/test_kcomponents.py b/networkx/algorithms/approximation/tests/test_kcomponents.py
index 60a90e84..6b280313 100644
--- a/networkx/algorithms/approximation/tests/test_kcomponents.py
+++ b/networkx/algorithms/approximation/tests/test_kcomponents.py
@@ -1,5 +1,6 @@
# Test for approximation to k-components algorithm
import pytest
+
import networkx as nx
from networkx.algorithms.approximation import k_components
from networkx.algorithms.approximation.kcomponents import _AntiGraph, _same
diff --git a/networkx/algorithms/approximation/tests/test_steinertree.py b/networkx/algorithms/approximation/tests/test_steinertree.py
index 1f55b06f..d58eb666 100644
--- a/networkx/algorithms/approximation/tests/test_steinertree.py
+++ b/networkx/algorithms/approximation/tests/test_steinertree.py
@@ -1,7 +1,7 @@
import pytest
+
import networkx as nx
-from networkx.algorithms.approximation.steinertree import metric_closure
-from networkx.algorithms.approximation.steinertree import steiner_tree
+from networkx.algorithms.approximation.steinertree import metric_closure, steiner_tree
from networkx.utils import edges_equal
diff --git a/networkx/algorithms/approximation/tests/test_traveling_salesman.py b/networkx/algorithms/approximation/tests/test_traveling_salesman.py
index 193f4379..6f9b3b0c 100644
--- a/networkx/algorithms/approximation/tests/test_traveling_salesman.py
+++ b/networkx/algorithms/approximation/tests/test_traveling_salesman.py
@@ -1,6 +1,8 @@
"""Unit tests for the traveling_salesman module."""
-import pytest
import random
+
+import pytest
+
import networkx as nx
import networkx.algorithms.approximation as nx_app
diff --git a/networkx/algorithms/approximation/tests/test_treewidth.py b/networkx/algorithms/approximation/tests/test_treewidth.py
index 5389b949..37619db6 100644
--- a/networkx/algorithms/approximation/tests/test_treewidth.py
+++ b/networkx/algorithms/approximation/tests/test_treewidth.py
@@ -1,10 +1,15 @@
-import networkx as nx
-from networkx.algorithms.approximation import treewidth_min_degree
-from networkx.algorithms.approximation import treewidth_min_fill_in
-from networkx.algorithms.approximation.treewidth import min_fill_in_heuristic
-from networkx.algorithms.approximation.treewidth import MinDegreeHeuristic
import itertools
+import networkx as nx
+from networkx.algorithms.approximation import (
+ treewidth_min_degree,
+ treewidth_min_fill_in,
+)
+from networkx.algorithms.approximation.treewidth import (
+ MinDegreeHeuristic,
+ min_fill_in_heuristic,
+)
+
def is_tree_decomp(graph, decomp):
"""Check if the given tree decomposition is valid."""
diff --git a/networkx/algorithms/approximation/traveling_salesman.py b/networkx/algorithms/approximation/traveling_salesman.py
index 15b231b4..971f9007 100644
--- a/networkx/algorithms/approximation/traveling_salesman.py
+++ b/networkx/algorithms/approximation/traveling_salesman.py
@@ -37,8 +37,7 @@ import math
import networkx as nx
from networkx.algorithms.tree.mst import random_spanning_tree
-
-from networkx.utils import py_random_state, not_implemented_for, pairwise
+from networkx.utils import not_implemented_for, pairwise, py_random_state
__all__ = [
"traveling_salesman_problem",
@@ -407,9 +406,8 @@ def asadpour_atsp(G, weight="weight", seed=None, source=None):
>>> tour
[0, 2, 1, 0]
"""
+ from math import ceil, exp
from math import log as ln
- from math import exp
- from math import ceil
# Check that G is a complete graph
N = len(G) - 1
diff --git a/networkx/algorithms/approximation/treewidth.py b/networkx/algorithms/approximation/treewidth.py
index 0a302cbf..61fb1e70 100644
--- a/networkx/algorithms/approximation/treewidth.py
+++ b/networkx/algorithms/approximation/treewidth.py
@@ -29,12 +29,12 @@ There are two different functions for computing a tree decomposition:
"""
+import itertools
import sys
+from heapq import heapify, heappop, heappush
import networkx as nx
from networkx.utils import not_implemented_for
-from heapq import heappush, heappop, heapify
-import itertools
__all__ = ["treewidth_min_degree", "treewidth_min_fill_in"]