17
17
# This software is distributed under the 3-clause BSD license.
18
18
# ___________________________________________________________________________
19
19
20
- import Graphs as gjl
20
+ import Graphs
21
21
22
22
import JuMPIn: maximum_matching, _is_valid_bipartition
23
23
@@ -27,12 +27,12 @@ In this function, matching must contain a key for every matched node.
27
27
I.e., Set(keys(matching)) == Set(values(matching))
28
28
"""
29
29
function _get_projected_digraph (
30
- graph:: gjl .Graph , nodes:: Vector , matching:: Dict
30
+ graph:: Graphs .Graph , nodes:: Vector , matching:: Dict
31
31
)
32
32
# Note that we are constructing a graph in a projected space, and must
33
33
# be aware of whether coordinates are in original or projected spaces.
34
34
orig_proj_map = Dict (n => i for (i, n) in enumerate (nodes))
35
- n_nodes = gjl . nv (graph)
35
+ n_nodes = Graphs . nv (graph)
36
36
n_nodes_proj = length (nodes)
37
37
matched_nodes = keys (matching)
38
38
node_set = Set (nodes) # Set of nodes in the original space
@@ -41,7 +41,7 @@ function _get_projected_digraph(
41
41
orig_node = nodes[proj_node]
42
42
if orig_node in matched_nodes
43
43
# In-edges from all (other) neighbors of matched node
44
- for nbr in gjl . neighbors (graph, matching[orig_node])
44
+ for nbr in Graphs . neighbors (graph, matching[orig_node])
45
45
if nbr != orig_node
46
46
nbr_proj = orig_proj_map[nbr]
47
47
push! (edge_set, (nbr_proj, proj_node))
@@ -50,29 +50,29 @@ function _get_projected_digraph(
50
50
end
51
51
# TODO : Out edges?
52
52
end
53
- digraph = gjl . DiGraph (n_nodes_proj)
53
+ digraph = Graphs . DiGraph (n_nodes_proj)
54
54
for (n1, n2) in edge_set
55
- gjl . add_edge! (digraph, n1, n2)
55
+ Graphs . add_edge! (digraph, n1, n2)
56
56
end
57
57
return digraph, orig_proj_map
58
58
end
59
59
60
60
61
- function _get_reachable_from (digraph:: gjl .DiGraph , nodes:: Vector )
62
- n_nodes = gjl . nv (digraph)
61
+ function _get_reachable_from (digraph:: Graphs .DiGraph , nodes:: Vector )
62
+ n_nodes = Graphs . nv (digraph)
63
63
source_set = Set (nodes)
64
- gjl . add_vertex! (digraph)
64
+ Graphs . add_vertex! (digraph)
65
65
# Note that root needs to be in this scope so it can be accessed in
66
66
# finally block
67
67
root = n_nodes + 1
68
68
bfs_parents = Vector {Int64} ()
69
69
try
70
70
for node in nodes
71
- gjl . add_edge! (digraph, root, node)
71
+ Graphs . add_edge! (digraph, root, node)
72
72
end
73
- bfs_parents = gjl . bfs_parents (digraph, root)
73
+ bfs_parents = Graphs . bfs_parents (digraph, root)
74
74
finally
75
- gjl . rem_vertex! (digraph, root)
75
+ Graphs . rem_vertex! (digraph, root)
76
76
end
77
77
reachable = [
78
78
node for (node, par) in enumerate (bfs_parents)
@@ -82,11 +82,11 @@ function _get_reachable_from(digraph::gjl.DiGraph, nodes::Vector)
82
82
end
83
83
84
84
85
- function dulmage_mendelsohn (graph:: gjl .Graph , set1:: Set )
85
+ function dulmage_mendelsohn (graph:: Graphs .Graph , set1:: Set )
86
86
if ! _is_valid_bipartition (graph, set1)
87
87
throw (Exception)
88
88
end
89
- n_nodes = gjl . nv (graph)
89
+ n_nodes = Graphs . nv (graph)
90
90
set2 = setdiff (Set (1 : n_nodes), set1)
91
91
92
92
# Compute maximum matching between bipartite sets
0 commit comments