rm CondaPkg environment
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -195,7 +195,7 @@ def local_node_connectivity(
|
||||
if mapping is None:
|
||||
raise nx.NetworkXError("Invalid auxiliary digraph.")
|
||||
|
||||
kwargs = dict(flow_func=flow_func, residual=residual)
|
||||
kwargs = {"flow_func": flow_func, "residual": residual}
|
||||
if flow_func is shortest_augmenting_path:
|
||||
kwargs["cutoff"] = cutoff
|
||||
kwargs["two_phase"] = True
|
||||
@@ -330,7 +330,7 @@ def node_connectivity(G, s=None, t=None, flow_func=None):
|
||||
# Reuse the auxiliary digraph and the residual network
|
||||
H = build_auxiliary_node_connectivity(G)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, auxiliary=H, residual=R)
|
||||
kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R}
|
||||
|
||||
# Pick a node with minimum degree
|
||||
# Node connectivity is bounded by degree.
|
||||
@@ -405,7 +405,7 @@ def average_node_connectivity(G, flow_func=None):
|
||||
# Reuse the auxiliary digraph and the residual network
|
||||
H = build_auxiliary_node_connectivity(G)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, auxiliary=H, residual=R)
|
||||
kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R}
|
||||
|
||||
num, den = 0, 0
|
||||
for u, v in iter_func(G, 2):
|
||||
@@ -473,7 +473,7 @@ def all_pairs_node_connectivity(G, nbunch=None, flow_func=None):
|
||||
H = build_auxiliary_node_connectivity(G)
|
||||
mapping = H.graph["mapping"]
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, auxiliary=H, residual=R)
|
||||
kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R}
|
||||
|
||||
for u, v in iter_func(nbunch, 2):
|
||||
K = local_node_connectivity(G, u, v, **kwargs)
|
||||
@@ -631,7 +631,7 @@ def local_edge_connectivity(
|
||||
else:
|
||||
H = auxiliary
|
||||
|
||||
kwargs = dict(flow_func=flow_func, residual=residual)
|
||||
kwargs = {"flow_func": flow_func, "residual": residual}
|
||||
if flow_func is shortest_augmenting_path:
|
||||
kwargs["cutoff"] = cutoff
|
||||
kwargs["two_phase"] = True
|
||||
@@ -760,7 +760,7 @@ def edge_connectivity(G, s=None, t=None, flow_func=None, cutoff=None):
|
||||
# reuse auxiliary digraph and residual network
|
||||
H = build_auxiliary_edge_connectivity(G)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, auxiliary=H, residual=R)
|
||||
kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R}
|
||||
|
||||
if G.is_directed():
|
||||
# Algorithm 8 in [1]
|
||||
|
||||
@@ -140,7 +140,7 @@ def minimum_st_edge_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
|
||||
else:
|
||||
H = auxiliary
|
||||
|
||||
kwargs = dict(capacity="capacity", flow_func=flow_func, residual=residual)
|
||||
kwargs = {"capacity": "capacity", "flow_func": flow_func, "residual": residual}
|
||||
|
||||
cut_value, partition = nx.minimum_cut(H, s, t, **kwargs)
|
||||
reachable, non_reachable = partition
|
||||
@@ -281,7 +281,7 @@ def minimum_st_node_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
|
||||
raise nx.NetworkXError("Invalid auxiliary digraph.")
|
||||
if G.has_edge(s, t) or G.has_edge(t, s):
|
||||
return {}
|
||||
kwargs = dict(flow_func=flow_func, residual=residual, auxiliary=H)
|
||||
kwargs = {"flow_func": flow_func, "residual": residual, "auxiliary": H}
|
||||
|
||||
# The edge cut in the auxiliary digraph corresponds to the node cut in the
|
||||
# original graph.
|
||||
@@ -414,7 +414,7 @@ def minimum_node_cut(G, s=None, t=None, flow_func=None):
|
||||
# Reuse the auxiliary digraph and the residual network.
|
||||
H = build_auxiliary_node_connectivity(G)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, auxiliary=H, residual=R)
|
||||
kwargs = {"flow_func": flow_func, "auxiliary": H, "residual": R}
|
||||
|
||||
# Choose a node with minimum degree.
|
||||
v = min(G, key=G.degree)
|
||||
@@ -537,7 +537,7 @@ def minimum_edge_cut(G, s=None, t=None, flow_func=None):
|
||||
# reuse auxiliary digraph and residual network
|
||||
H = build_auxiliary_edge_connectivity(G)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(flow_func=flow_func, residual=R, auxiliary=H)
|
||||
kwargs = {"flow_func": flow_func, "residual": R, "auxiliary": H}
|
||||
|
||||
# Local minimum edge cut if s and t are not None
|
||||
if s is not None and t is not None:
|
||||
|
||||
@@ -173,9 +173,12 @@ def edge_disjoint_paths(
|
||||
|
||||
# Compute maximum flow between source and target. Flow functions in
|
||||
# NetworkX return a residual network.
|
||||
kwargs = dict(
|
||||
capacity="capacity", residual=residual, cutoff=cutoff, value_only=True
|
||||
)
|
||||
kwargs = {
|
||||
"capacity": "capacity",
|
||||
"residual": residual,
|
||||
"cutoff": cutoff,
|
||||
"value_only": True,
|
||||
}
|
||||
if flow_func is preflow_push:
|
||||
del kwargs["cutoff"]
|
||||
if flow_func is shortest_augmenting_path:
|
||||
@@ -369,7 +372,12 @@ def node_disjoint_paths(
|
||||
else:
|
||||
cutoff = min(cutoff, possible)
|
||||
|
||||
kwargs = dict(flow_func=flow_func, residual=residual, auxiliary=H, cutoff=cutoff)
|
||||
kwargs = {
|
||||
"flow_func": flow_func,
|
||||
"residual": residual,
|
||||
"auxiliary": H,
|
||||
"cutoff": cutoff,
|
||||
}
|
||||
|
||||
# The edge disjoint paths in the auxiliary digraph correspond to the node
|
||||
# disjoint paths in the original graph.
|
||||
|
||||
@@ -10,7 +10,7 @@ k-edge-augmentation exists.
|
||||
See Also
|
||||
--------
|
||||
:mod:`edge_kcomponents` : algorithms for finding k-edge-connected components
|
||||
:mod:`connectivity` : algorithms for determening edge connectivity.
|
||||
:mod:`connectivity` : algorithms for determining edge connectivity.
|
||||
"""
|
||||
import itertools as it
|
||||
import math
|
||||
@@ -374,7 +374,7 @@ def partial_k_edge_augmentation(G, k, avail, weight=None):
|
||||
|
||||
# Generate all edges between CCs that could not be k-edge-connected
|
||||
for cc1, cc2 in it.combinations(k_edge_subgraphs, 2):
|
||||
for (u, v) in _edges_between_disjoint(H, cc1, cc2):
|
||||
for u, v in _edges_between_disjoint(H, cc1, cc2):
|
||||
d = H.get_edge_data(u, v)
|
||||
edge = d.get("generator", None)
|
||||
if edge is not None:
|
||||
@@ -1223,7 +1223,7 @@ def greedy_k_edge_augmentation(G, k, avail=None, weight=None, seed=None):
|
||||
|
||||
# Incrementally add edges in until we are k-connected
|
||||
H = G.copy()
|
||||
for (u, v) in avail_uv:
|
||||
for u, v in avail_uv:
|
||||
done = False
|
||||
if not is_locally_k_edge_connected(H, u, v, k=k):
|
||||
# Only add edges in parts that are not yet locally k-edge-connected
|
||||
@@ -1241,7 +1241,7 @@ def greedy_k_edge_augmentation(G, k, avail=None, weight=None, seed=None):
|
||||
|
||||
# Randomized attempt to reduce the size of the solution
|
||||
_compat_shuffle(seed, aug_edges)
|
||||
for (u, v) in list(aug_edges):
|
||||
for u, v in list(aug_edges):
|
||||
# Don't remove if we know it would break connectivity
|
||||
if H.degree(u) <= k or H.degree(v) <= k:
|
||||
continue
|
||||
|
||||
@@ -239,7 +239,7 @@ def bridge_components(G):
|
||||
class EdgeComponentAuxGraph:
|
||||
r"""A simple algorithm to find all k-edge-connected components in a graph.
|
||||
|
||||
Constructing the AuxillaryGraph (which may take some time) allows for the
|
||||
Constructing the auxiliary graph (which may take some time) allows for the
|
||||
k-edge-ccs to be found in linear time for arbitrary k.
|
||||
|
||||
Notes
|
||||
@@ -288,7 +288,7 @@ class EdgeComponentAuxGraph:
|
||||
>>> sorted(map(sorted, aux_graph.k_edge_components(k=4)))
|
||||
[[0], [1], [2], [3], [4], [5], [6], [7]]
|
||||
|
||||
The auxiliary graph is primarilly used for k-edge-ccs but it
|
||||
The auxiliary graph is primarily used for k-edge-ccs but it
|
||||
can also speed up the queries of k-edge-subgraphs by refining the
|
||||
search space.
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ def k_components(G, flow_func=None):
|
||||
"""
|
||||
# Dictionary with connectivity level (k) as keys and a list of
|
||||
# sets of nodes that form a k-component as values. Note that
|
||||
# k-compoents can overlap (but only k - 1 nodes).
|
||||
# k-components can overlap (but only k - 1 nodes).
|
||||
k_components = defaultdict(list)
|
||||
# Define default flow function
|
||||
if flow_func is None:
|
||||
@@ -167,7 +167,7 @@ def _consolidate(sets, k):
|
||||
|
||||
"""
|
||||
G = nx.Graph()
|
||||
nodes = {i: s for i, s in enumerate(sets)}
|
||||
nodes = dict(enumerate(sets))
|
||||
G.add_nodes_from(nodes)
|
||||
G.add_edges_from(
|
||||
(u, v) for u, v in combinations(nodes, 2) if len(nodes[u] & nodes[v]) >= k
|
||||
@@ -178,10 +178,7 @@ def _consolidate(sets, k):
|
||||
|
||||
def _generate_partition(G, cuts, k):
|
||||
def has_nbrs_in_partition(G, node, partition):
|
||||
for n in G[node]:
|
||||
if n in partition:
|
||||
return True
|
||||
return False
|
||||
return any(n in partition for n in G[node])
|
||||
|
||||
components = []
|
||||
nodes = {n for n, d in G.degree() if d > k} - {n for cut in cuts for n in cut}
|
||||
@@ -198,7 +195,7 @@ def _generate_partition(G, cuts, k):
|
||||
|
||||
|
||||
def _reconstruct_k_components(k_comps):
|
||||
result = dict()
|
||||
result = {}
|
||||
max_k = max(k_comps)
|
||||
for k in reversed(range(1, max_k + 1)):
|
||||
if k == max_k:
|
||||
|
||||
@@ -108,7 +108,7 @@ def all_node_cuts(G, k=None, flow_func=None):
|
||||
# Shallow copy is enough.
|
||||
original_H_pred = copy.copy(H._pred)
|
||||
R = build_residual_network(H, "capacity")
|
||||
kwargs = dict(capacity="capacity", residual=R)
|
||||
kwargs = {"capacity": "capacity", "residual": R}
|
||||
# Define default flow function
|
||||
if flow_func is None:
|
||||
flow_func = default_flow_func
|
||||
@@ -189,7 +189,7 @@ def all_node_cuts(G, k=None, flow_func=None):
|
||||
cutset.update((u, w) for w in original_H_pred[u] if w not in S)
|
||||
# The edges in H that form the cutset are internal edges
|
||||
# (ie edges that represent a node of the original graph G)
|
||||
if any([H_nodes[u]["id"] != H_nodes[w]["id"] for u, w in cutset]):
|
||||
if any(H_nodes[u]["id"] != H_nodes[w]["id"] for u, w in cutset):
|
||||
continue
|
||||
node_cut = {H_nodes[u]["id"] for u, _ in cutset}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -47,7 +47,7 @@ def test_average_connectivity():
|
||||
G2.add_edges_from([(1, 3), (1, 4), (0, 3), (0, 4), (3, 4)])
|
||||
G3 = nx.Graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
assert nx.average_node_connectivity(G1, **kwargs) == 1, errmsg
|
||||
assert nx.average_node_connectivity(G2, **kwargs) == 2.2, errmsg
|
||||
@@ -98,7 +98,7 @@ def test_brandes_erlebach():
|
||||
]
|
||||
)
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
assert 3 == local_edge_connectivity(G, 1, 11, **kwargs), errmsg
|
||||
assert 3 == nx.edge_connectivity(G, 1, 11, **kwargs), errmsg
|
||||
|
||||
@@ -70,7 +70,7 @@ def test_brandes_erlebach_book():
|
||||
]
|
||||
)
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge cutsets
|
||||
assert 3 == len(nx.minimum_edge_cut(G, 1, 11, **kwargs)), errmsg
|
||||
@@ -104,7 +104,7 @@ def test_white_harary_paper():
|
||||
for i in range(7, 10):
|
||||
G.add_edge(0, i)
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge cuts
|
||||
edge_cut = nx.minimum_edge_cut(G, **kwargs)
|
||||
@@ -123,7 +123,7 @@ def test_white_harary_paper():
|
||||
def test_petersen_cutset():
|
||||
G = nx.petersen_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge cuts
|
||||
edge_cut = nx.minimum_edge_cut(G, **kwargs)
|
||||
@@ -142,7 +142,7 @@ def test_petersen_cutset():
|
||||
def test_octahedral_cutset():
|
||||
G = nx.octahedral_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge cuts
|
||||
edge_cut = nx.minimum_edge_cut(G, **kwargs)
|
||||
@@ -161,7 +161,7 @@ def test_octahedral_cutset():
|
||||
def test_icosahedral_cutset():
|
||||
G = nx.icosahedral_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge cuts
|
||||
edge_cut = nx.minimum_edge_cut(G, **kwargs)
|
||||
|
||||
@@ -67,7 +67,7 @@ def test_graph_from_pr_2053():
|
||||
]
|
||||
)
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_paths = list(nx.edge_disjoint_paths(G, "A", "Z", **kwargs))
|
||||
@@ -82,7 +82,7 @@ def test_graph_from_pr_2053():
|
||||
def test_florentine_families():
|
||||
G = nx.florentine_families_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_dpaths = list(nx.edge_disjoint_paths(G, "Medici", "Strozzi", **kwargs))
|
||||
@@ -97,7 +97,7 @@ def test_florentine_families():
|
||||
def test_karate():
|
||||
G = nx.karate_club_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 33, **kwargs))
|
||||
@@ -112,7 +112,7 @@ def test_karate():
|
||||
def test_petersen_disjoint_paths():
|
||||
G = nx.petersen_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs))
|
||||
@@ -127,7 +127,7 @@ def test_petersen_disjoint_paths():
|
||||
def test_octahedral_disjoint_paths():
|
||||
G = nx.octahedral_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 5, **kwargs))
|
||||
@@ -142,7 +142,7 @@ def test_octahedral_disjoint_paths():
|
||||
def test_icosahedral_disjoint_paths():
|
||||
G = nx.icosahedral_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
# edge disjoint paths
|
||||
edge_dpaths = list(nx.edge_disjoint_paths(G, 0, 6, **kwargs))
|
||||
@@ -157,7 +157,7 @@ def test_icosahedral_disjoint_paths():
|
||||
def test_cutoff_disjoint_paths():
|
||||
G = nx.icosahedral_graph()
|
||||
for flow_func in flow_funcs:
|
||||
kwargs = dict(flow_func=flow_func)
|
||||
kwargs = {"flow_func": flow_func}
|
||||
errmsg = f"Assertion failed in function: {flow_func.__name__}"
|
||||
for cutoff in [2, 4]:
|
||||
kwargs["cutoff"] = cutoff
|
||||
|
||||
@@ -186,7 +186,7 @@ def test_articulation_points():
|
||||
Ggen = _generate_no_biconnected()
|
||||
for i in range(1): # change 1 to 3 or more for more realizations.
|
||||
G = next(Ggen)
|
||||
articulation_points = list({a} for a in nx.articulation_points(G))
|
||||
articulation_points = [{a} for a in nx.articulation_points(G)]
|
||||
for cut in nx.all_node_cuts(G):
|
||||
assert cut in articulation_points
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ def build_auxiliary_node_connectivity(G):
|
||||
H.add_edge(f"{i}A", f"{i}B", capacity=1)
|
||||
|
||||
edges = []
|
||||
for (source, target) in G.edges():
|
||||
for source, target in G.edges():
|
||||
edges.append((f"{mapping[source]}B", f"{mapping[target]}A"))
|
||||
if not directed:
|
||||
edges.append((f"{mapping[target]}B", f"{mapping[source]}A"))
|
||||
@@ -80,6 +80,6 @@ def build_auxiliary_edge_connectivity(G):
|
||||
else:
|
||||
H = nx.DiGraph()
|
||||
H.add_nodes_from(G.nodes())
|
||||
for (source, target) in G.edges():
|
||||
for source, target in G.edges():
|
||||
H.add_edges_from([(source, target), (target, source)], capacity=1)
|
||||
return H
|
||||
|
||||
Reference in New Issue
Block a user