Fix bugs and cleanup
This commit is contained in:
parent
5827c0ccfa
commit
f76623dd5f
|
@ -978,9 +978,9 @@ def _substage_scan(
|
||||||
|
|
||||||
# Take a vertex from the queue.
|
# Take a vertex from the queue.
|
||||||
v = stage_data.queue.pop()
|
v = stage_data.queue.pop()
|
||||||
vblossom = matching.vertex_blossom[v]
|
|
||||||
|
|
||||||
# Double-check that "v" is an S-vertex.
|
# Double-check that "v" is an S-vertex.
|
||||||
|
vblossom = matching.vertex_blossom[v]
|
||||||
assert stage_data.blossom_label[vblossom] == _LABEL_S
|
assert stage_data.blossom_label[vblossom] == _LABEL_S
|
||||||
|
|
||||||
# Scan the edges that are incident on "v".
|
# Scan the edges that are incident on "v".
|
||||||
|
@ -992,6 +992,9 @@ def _substage_scan(
|
||||||
# Try to pull this edge into an alternating tree.
|
# Try to pull this edge into an alternating tree.
|
||||||
|
|
||||||
# Ignore edges that are internal to a blossom.
|
# Ignore edges that are internal to a blossom.
|
||||||
|
# Note: blossom index of vertex "v" may change during this loop,
|
||||||
|
# so we need to refresh it here.
|
||||||
|
vblossom = matching.vertex_blossom[v]
|
||||||
wblossom = matching.vertex_blossom[w]
|
wblossom = matching.vertex_blossom[w]
|
||||||
if vblossom == wblossom:
|
if vblossom == wblossom:
|
||||||
continue
|
continue
|
||||||
|
@ -1028,11 +1031,13 @@ def _substage_scan(
|
||||||
assert best_edge_set is not None
|
assert best_edge_set is not None
|
||||||
best_edge_set.append(e)
|
best_edge_set.append(e)
|
||||||
|
|
||||||
# Update tracking of least-slack edges between vertex "w" and
|
if wlabel != _LABEL_S:
|
||||||
# any S-vertex. We do this even for edges that have zero slack.
|
# Update tracking of least-slack edges from vertex "w" to
|
||||||
# (If "w" is part of a T-blossom, it may become unlabeled later.
|
# any S-vertex. We do this only for T-vertices and unlabeled
|
||||||
# At that point we will need this edge to relabel vertex "w".
|
# vertices. Edges which have zero slack are also tracked.
|
||||||
# And we will find this edge through least-slack edge tracking.)
|
# If "w" is part of a T-blossom, it may become unlabeled
|
||||||
|
# later. At that point we will need a zero-slack edge to
|
||||||
|
# relabel vertex "w".
|
||||||
best_edge = stage_data.vertex_best_edge[w]
|
best_edge = stage_data.vertex_best_edge[w]
|
||||||
if best_edge < 0 or slack < matching.edge_slack(best_edge):
|
if best_edge < 0 or slack < matching.edge_slack(best_edge):
|
||||||
stage_data.vertex_best_edge[w] = e
|
stage_data.vertex_best_edge[w] = e
|
||||||
|
@ -1150,17 +1155,9 @@ def _expand_t_blossom(
|
||||||
# path_nodes[i] has already been labeled T.
|
# path_nodes[i] has already been labeled T.
|
||||||
# We now assign labels to path_nodes[i+1] and path_nodes[i+2].
|
# We now assign labels to path_nodes[i+1] and path_nodes[i+2].
|
||||||
|
|
||||||
# Assign label S to path_nodes[i+1] and attach it to path_nodes[i].
|
# Assign label S to path_nodes[i+1].
|
||||||
sub = path_nodes[i+1]
|
(w, v) = path_edges[i]
|
||||||
stage_data.blossom_label[sub] = _LABEL_S
|
_substage_assign_label_s(matching, stage_data, v)
|
||||||
stage_data.blossom_link[sub] = path_edges[i]
|
|
||||||
|
|
||||||
# Put vertices in the newly labeled S-blossom in the queue.
|
|
||||||
# TODO : It feels like we have seen this code pattern a few times; try to generalize it.
|
|
||||||
if sub < num_vertex:
|
|
||||||
stage_data.queue.append(sub)
|
|
||||||
else:
|
|
||||||
stage_data.queue.extend(matching.blossom_vertices(sub))
|
|
||||||
|
|
||||||
# Assign label T to path_nodes[i+2] and attach it to path_nodes[i+1].
|
# Assign label T to path_nodes[i+2] and attach it to path_nodes[i+1].
|
||||||
sub = path_nodes[i+2]
|
sub = path_nodes[i+2]
|
||||||
|
@ -1434,14 +1431,13 @@ def _apply_delta_step(
|
||||||
|
|
||||||
# Apply delta to dual variables of top-level non-trivial blossoms.
|
# Apply delta to dual variables of top-level non-trivial blossoms.
|
||||||
for b in range(num_vertex, 2 * num_vertex):
|
for b in range(num_vertex, 2 * num_vertex):
|
||||||
|
if matching.blossom_parent[b] == -1:
|
||||||
blabel = stage_data.blossom_label[b]
|
blabel = stage_data.blossom_label[b]
|
||||||
if blabel == _LABEL_S:
|
if blabel == _LABEL_S:
|
||||||
# S-blossom: add 2*delta to dual variable.
|
# S-blossom: add 2*delta to dual variable.
|
||||||
assert matching.blossom_parent[b] == -1
|
|
||||||
matching.get_blossom(b).half_dual_var += delta
|
matching.get_blossom(b).half_dual_var += delta
|
||||||
elif blabel == _LABEL_T:
|
elif blabel == _LABEL_T:
|
||||||
# T-blossom: subtract 2*delta from dual variable.
|
# T-blossom: subtract 2*delta from dual variable.
|
||||||
assert matching.blossom_parent[b] == -1
|
|
||||||
matching.get_blossom(b).half_dual_var -= delta
|
matching.get_blossom(b).half_dual_var -= delta
|
||||||
|
|
||||||
|
|
||||||
|
@ -1604,7 +1600,7 @@ def _verify_optimum(
|
||||||
|
|
||||||
# List blossoms that contain the edge (i, j).
|
# List blossoms that contain the edge (i, j).
|
||||||
edge_blossoms = []
|
edge_blossoms = []
|
||||||
for (bi, bj) in zip(iblossoms, jblossoms):
|
for (bi, bj) in zip(reversed(iblossoms), reversed(jblossoms)):
|
||||||
if bi != bj:
|
if bi != bj:
|
||||||
break
|
break
|
||||||
edge_blossoms.append(bi)
|
edge_blossoms.append(bi)
|
||||||
|
|
Loading…
Reference in New Issue