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.
@@ -352,7 +352,7 @@ class Edmonds:
|
||||
d[partition] = data.get(partition)
|
||||
|
||||
if preserve_attrs:
|
||||
for (d_k, d_v) in data.items():
|
||||
for d_k, d_v in data.items():
|
||||
if d_k != attr:
|
||||
d[d_k] = d_v
|
||||
|
||||
@@ -698,7 +698,7 @@ class Edmonds:
|
||||
# Optionally, preserve the other edge attributes of the original
|
||||
# graph
|
||||
if preserve_attrs:
|
||||
for (key, value) in d.items():
|
||||
for key, value in d.items():
|
||||
if key not in [self.attr, self.candidate_attr]:
|
||||
dd[key] = value
|
||||
|
||||
@@ -932,7 +932,7 @@ class ArborescenceIterator:
|
||||
self.partition_queue.put(
|
||||
self.Partition(
|
||||
mst_weight if self.minimum else -mst_weight,
|
||||
dict()
|
||||
{}
|
||||
if self.init_partition is None
|
||||
else self.init_partition.partition_dict,
|
||||
)
|
||||
|
||||
@@ -334,12 +334,22 @@ def prim_mst_edges(G, minimum, weight="weight", keys=True, data=True, ignore_nan
|
||||
continue
|
||||
for k2, d2 in keydict.items():
|
||||
new_weight = d2.get(weight, 1) * sign
|
||||
if isnan(new_weight):
|
||||
if ignore_nan:
|
||||
continue
|
||||
msg = f"NaN found as an edge weight. Edge {(v, w, k2, d2)}"
|
||||
raise ValueError(msg)
|
||||
push(frontier, (new_weight, next(c), v, w, k2, d2))
|
||||
else:
|
||||
for w, d2 in G.adj[v].items():
|
||||
if w in visited:
|
||||
continue
|
||||
new_weight = d2.get(weight, 1) * sign
|
||||
if isnan(new_weight):
|
||||
if ignore_nan:
|
||||
continue
|
||||
msg = f"NaN found as an edge weight. Edge {(v, w, d2)}"
|
||||
raise ValueError(msg)
|
||||
push(frontier, (new_weight, next(c), v, w, d2))
|
||||
|
||||
|
||||
@@ -603,7 +613,7 @@ def partition_spanning_tree(
|
||||
"""
|
||||
Find a spanning tree while respecting a partition of edges.
|
||||
|
||||
Edges can be flagged as either `INLCUDED` which are required to be in the
|
||||
Edges can be flagged as either `INCLUDED` which are required to be in the
|
||||
returned tree, `EXCLUDED`, which cannot be in the returned tree and `OPEN`.
|
||||
|
||||
This is used in the SpanningTreeIterator to create new partitions following
|
||||
@@ -732,7 +742,7 @@ def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None):
|
||||
is based on the product of edge weights, and if ``multiplicative=False``
|
||||
it is based on the sum of the edge weight. However, since it is
|
||||
easier to determine the total weight of all spanning trees for the
|
||||
multiplicative verison, that is significantly faster and should be used if
|
||||
multiplicative version, that is significantly faster and should be used if
|
||||
possible. Additionally, setting `weight` to `None` will cause a spanning tree
|
||||
to be selected with uniform probability.
|
||||
|
||||
@@ -1022,7 +1032,7 @@ class SpanningTreeIterator:
|
||||
).size(weight=self.weight)
|
||||
|
||||
self.partition_queue.put(
|
||||
self.Partition(mst_weight if self.minimum else -mst_weight, dict())
|
||||
self.Partition(mst_weight if self.minimum else -mst_weight, {})
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
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.
@@ -1,4 +1,5 @@
|
||||
import math
|
||||
from operator import itemgetter
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -199,6 +200,26 @@ def test_greedy_max1():
|
||||
assert_equal_branchings(B, B_)
|
||||
|
||||
|
||||
def test_greedy_branching_kwarg_kind():
|
||||
G = G1()
|
||||
with pytest.raises(nx.NetworkXException, match="Unknown value for `kind`."):
|
||||
B = branchings.greedy_branching(G, kind="lol")
|
||||
|
||||
|
||||
def test_greedy_branching_for_unsortable_nodes():
|
||||
G = nx.DiGraph()
|
||||
G.add_weighted_edges_from([((2, 3), 5, 1), (3, "a", 1), (2, 4, 5)])
|
||||
edges = [(u, v, data.get("weight", 1)) for (u, v, data) in G.edges(data=True)]
|
||||
with pytest.raises(TypeError):
|
||||
edges.sort(key=itemgetter(2, 0, 1), reverse=True)
|
||||
B = branchings.greedy_branching(G, kind="max").edges(data=True)
|
||||
assert list(B) == [
|
||||
((2, 3), 5, {"weight": 1}),
|
||||
(3, "a", {"weight": 1}),
|
||||
(2, 4, {"weight": 5}),
|
||||
]
|
||||
|
||||
|
||||
def test_greedy_max2():
|
||||
# Different default weight.
|
||||
#
|
||||
@@ -427,6 +448,38 @@ def test_edge_attribute_preservation_multigraph():
|
||||
assert B[0][1][0]["otherattr2"] == 3
|
||||
|
||||
|
||||
def test_Edmond_kind():
|
||||
G = nx.MultiGraph()
|
||||
|
||||
edgelist = [
|
||||
(0, 1, [("weight", 5), ("otherattr", 1), ("otherattr2", 3)]),
|
||||
(0, 2, [("weight", 5), ("otherattr", 2), ("otherattr2", 2)]),
|
||||
(1, 2, [("weight", 6), ("otherattr", 3), ("otherattr2", 1)]),
|
||||
]
|
||||
G.add_edges_from(edgelist * 2) # Make sure we have duplicate edge paths
|
||||
ed = branchings.Edmonds(G)
|
||||
with pytest.raises(nx.NetworkXException, match="Unknown value for `kind`."):
|
||||
ed.find_optimum(kind="lol", preserve_attrs=True)
|
||||
|
||||
|
||||
def test_MultiDiGraph_EdgeKey():
|
||||
# test if more than one edges has the same key
|
||||
G = branchings.MultiDiGraph_EdgeKey()
|
||||
G.add_edge(1, 2, "A")
|
||||
with pytest.raises(Exception, match="Key 'A' is already in use."):
|
||||
G.add_edge(3, 4, "A")
|
||||
# test if invalid edge key was specified
|
||||
with pytest.raises(KeyError, match="Invalid edge key 'B'"):
|
||||
G.remove_edge_with_key("B")
|
||||
# test remove_edge_with_key works
|
||||
if G.remove_edge_with_key("A"):
|
||||
assert list(G.edges(data=True)) == []
|
||||
# test that remove_edges_from doesn't work
|
||||
G.add_edge(1, 3, "A")
|
||||
with pytest.raises(NotImplementedError):
|
||||
G.remove_edges_from([(1, 3)])
|
||||
|
||||
|
||||
def test_edge_attribute_discard():
|
||||
# Test that edge attributes are discarded if we do not specify to keep them
|
||||
G = nx.Graph()
|
||||
|
||||
@@ -165,7 +165,7 @@ class MinimumSpanningTreeTestBase:
|
||||
assert edges_equal(actual, self.maximum_spanning_edgelist)
|
||||
|
||||
def test_disconnected(self):
|
||||
G = nx.Graph([(0, 1, dict(weight=1)), (2, 3, dict(weight=2))])
|
||||
G = nx.Graph([(0, 1, {"weight": 1}), (2, 3, {"weight": 2})])
|
||||
T = nx.minimum_spanning_tree(G, algorithm=self.algo)
|
||||
assert nodes_equal(list(T), list(range(4)))
|
||||
assert edges_equal(list(T.edges()), [(0, 1), (2, 3)])
|
||||
@@ -253,6 +253,36 @@ class TestKruskal(MultigraphMSTTestBase):
|
||||
|
||||
algorithm = "kruskal"
|
||||
|
||||
def test_key_data_bool(self):
|
||||
"""Tests that the keys and data values are included in
|
||||
MST edges based on whether keys and data parameters are
|
||||
true or false"""
|
||||
G = nx.MultiGraph()
|
||||
G.add_edge(1, 2, key=1, weight=2)
|
||||
G.add_edge(1, 2, key=2, weight=3)
|
||||
G.add_edge(3, 2, key=1, weight=2)
|
||||
G.add_edge(3, 1, key=1, weight=4)
|
||||
|
||||
# keys are included and data is not included
|
||||
mst_edges = nx.minimum_spanning_edges(
|
||||
G, algorithm=self.algo, keys=True, data=False
|
||||
)
|
||||
assert edges_equal([(1, 2, 1), (2, 3, 1)], list(mst_edges))
|
||||
|
||||
# keys are not included and data is included
|
||||
mst_edges = nx.minimum_spanning_edges(
|
||||
G, algorithm=self.algo, keys=False, data=True
|
||||
)
|
||||
assert edges_equal(
|
||||
[(1, 2, {"weight": 2}), (2, 3, {"weight": 2})], list(mst_edges)
|
||||
)
|
||||
|
||||
# both keys and data are not included
|
||||
mst_edges = nx.minimum_spanning_edges(
|
||||
G, algorithm=self.algo, keys=False, data=False
|
||||
)
|
||||
assert edges_equal([(1, 2), (2, 3)], list(mst_edges))
|
||||
|
||||
|
||||
class TestPrim(MultigraphMSTTestBase):
|
||||
"""Unit tests for computing a minimum (or maximum) spanning tree
|
||||
@@ -261,6 +291,25 @@ class TestPrim(MultigraphMSTTestBase):
|
||||
|
||||
algorithm = "prim"
|
||||
|
||||
def test_ignore_nan(self):
|
||||
"""Tests that the edges with NaN weights are ignored or
|
||||
raise an Error based on ignore_nan is true or false"""
|
||||
H = nx.MultiGraph()
|
||||
H.add_edge(1, 2, key=1, weight=float("nan"))
|
||||
H.add_edge(1, 2, key=2, weight=3)
|
||||
H.add_edge(3, 2, key=1, weight=2)
|
||||
H.add_edge(3, 1, key=1, weight=4)
|
||||
|
||||
# NaN weight edges are ignored when ignore_nan=True
|
||||
mst_edges = nx.minimum_spanning_edges(H, algorithm=self.algo, ignore_nan=True)
|
||||
assert edges_equal(
|
||||
[(1, 2, 2, {"weight": 3}), (2, 3, 1, {"weight": 2})], list(mst_edges)
|
||||
)
|
||||
|
||||
# NaN weight edges raise Error when ignore_nan=False
|
||||
with pytest.raises(ValueError):
|
||||
list(nx.minimum_spanning_edges(H, algorithm=self.algo, ignore_nan=False))
|
||||
|
||||
def test_multigraph_keys_tree(self):
|
||||
G = nx.MultiGraph()
|
||||
G.add_edge(0, 1, key="a", weight=2)
|
||||
|
||||
@@ -4,13 +4,11 @@ import networkx as nx
|
||||
|
||||
|
||||
class TestTreeRecognition:
|
||||
|
||||
graph = nx.Graph
|
||||
multigraph = nx.MultiGraph
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
|
||||
cls.T1 = cls.graph()
|
||||
|
||||
cls.T2 = cls.graph()
|
||||
|
||||
Reference in New Issue
Block a user