@@ -16,7 +16,6 @@ class Partition:
16
16
:ivar dict parts: Maps district IDs to the set of nodes in that district.
17
17
:ivar dict subgraphs: Maps district IDs to the induced subgraph of that district.
18
18
"""
19
- default_updaters = {"cut_edges" : cut_edges }
20
19
__slots__ = (
21
20
'graph' ,
22
21
'subgraphs' ,
@@ -30,26 +29,28 @@ class Partition:
30
29
)
31
30
32
31
def __init__ (
33
- self , graph = None , assignment = None , updaters = None , parent = None , flips = None
32
+ self , graph = None , assignment = None , updaters = None , parent = None , flips = None ,
33
+ use_cut_edges = True
34
34
):
35
35
"""
36
36
:param graph: Underlying graph.
37
37
:param assignment: Dictionary assigning nodes to districts.
38
38
:param updaters: Dictionary of functions to track data about the partition.
39
39
The keys are stored as attributes on the partition class,
40
40
which the functions compute.
41
+ :param use_cut_edges: If `False`, do not include `cut_edges` updater by default
42
+ and do not calculate edge flows.
41
43
"""
42
44
if parent is None :
43
- self ._first_time (graph , assignment , updaters )
45
+ self ._first_time (graph , assignment , updaters , use_cut_edges )
44
46
else :
45
47
self ._from_parent (parent , flips )
46
48
47
49
self ._cache = dict ()
48
50
self .subgraphs = SubgraphView (self .graph , self .parts )
49
51
50
- def _first_time (self , graph , assignment , updaters ):
52
+ def _first_time (self , graph , assignment , updaters , use_cut_edges ):
51
53
self .graph = graph
52
-
53
54
self .assignment = get_assignment (assignment , graph )
54
55
55
56
if set (self .assignment ) != set (graph ):
@@ -58,7 +59,11 @@ def _first_time(self, graph, assignment, updaters):
58
59
if updaters is None :
59
60
updaters = dict ()
60
61
61
- self .updaters = self .default_updaters .copy ()
62
+ if use_cut_edges :
63
+ self .updaters = {"cut_edges" : cut_edges }
64
+ else :
65
+ self .updaters = {}
66
+
62
67
self .updaters .update (updaters )
63
68
64
69
self .parent = None
@@ -77,7 +82,9 @@ def _from_parent(self, parent, flips):
77
82
self .updaters = parent .updaters
78
83
79
84
self .flows = flows_from_changes (parent .assignment , flips )
80
- self .edge_flows = compute_edge_flows (self )
85
+
86
+ if "cut_edges" in self .updaters :
87
+ self .edge_flows = compute_edge_flows (self )
81
88
82
89
def __repr__ (self ):
83
90
number_of_parts = len (self )
0 commit comments