Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fixed a bug with pathsearch()
Browse files Browse the repository at this point in the history
  • Loading branch information
meghanamreddy committed Jul 15, 2018
1 parent b222089 commit 6ff2b41
Showing 1 changed file with 98 additions and 29 deletions.
127 changes: 98 additions & 29 deletions src/sage/graphs/connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,21 @@ def bridges(G, labels=True):

from sage.graphs.base.sparse_graph cimport SparseGraph

class Component:
edge_list = []
component_type = 0 #bond = 0, polygon = 1, triconnected = 2
def __init__(self, edges, type_c):
self.edge_list = edges
self.component_type = type_c
print "creating new component ", edges
def add_edge(self, e):
self.edge_list.append(e)
def finish_tric_or_poly(self, e):
self.edge_list.append(e)
if len(self.edge_list) >= 4:
self.component_type = 2
else:
self.component_type = 1

class Triconnectivity:
"""
Expand All @@ -1892,20 +1907,7 @@ class Triconnectivity:
sage: tric.components_list
[]
"""
class Component:
edge_list = []
component_type = 0 #bond = 0, polygon = 1, triconnected = 2
def __init__(self, edges, type_c=0):
self.edge_list = edges
component_type = type_c
def add_edge(self, e):
self.edge_list.append(e)
def finish_tric_or_poly(self, e):
self.edge_list.append(e)
if len(self.edge_list) >= 4:
component_type = 2
else:
component_type = 1


graph_copy = None #type SparseGraph
vertex_to_int = {} # mapping of vertices to integers in c_graph
Expand Down Expand Up @@ -1979,7 +1981,7 @@ class Triconnectivity:
# Triconnectivity algorithm
self.split_multi_egdes()
self.dfs_counter = 0 # Initialisation for dfs1()
self.start_vertex = 7 # Initialisation for dfs1()
self.start_vertex = 0 # Initialisation for dfs1()
self.cut_vertex = self.dfs1(self.start_vertex, check=check)

if check:
Expand Down Expand Up @@ -2013,6 +2015,16 @@ class Triconnectivity:

self.path_search(self.start_vertex)

# last split component
print "last split component ", self.e_stack
c = Component([],0)
print "new component edge list ", c.edge_list
while self.e_stack:
c.add_edge(self.estack_pop())
c.component_type = 2 if len(c.edge_list) > 4 else 1
self.components_list.append(c)
c = None

# Push a triple on Tstack
def tstack_push(self, h, a, b):
self.t_stack_top += 1
Expand All @@ -2035,7 +2047,7 @@ class Triconnectivity:
return e

def new_component(self, edges=[], type_c=0):
c = self.Component(edges, type_c)
c = Component(edges, type_c)
self.components_list.append(c)
# Remove the edges from graph
for e in edges:
Expand All @@ -2061,6 +2073,7 @@ class Triconnectivity:
else:
v = e[1]
self.highpt[v].remove(it)
print "delhigh test ", e, self.highpt[v], it

def split_multi_egdes(self):
"""
Expand Down Expand Up @@ -2103,6 +2116,7 @@ class Triconnectivity:
# It will add k - 1 multiple edges to comp
if sorted_edges[i] == sorted_edges[i + 1]:
self.edge_status[sorted_edges[i]] = 3 # edge removed
print "edge removed: ", sorted_edges[i], self.edge_status[sorted_edges[i]]
comp.append(sorted_edges[i])
else:
if comp:
Expand All @@ -2114,6 +2128,9 @@ class Triconnectivity:
comp.append(sorted_edges[i-1])
comp.append(sorted_edges[i-1])
self.new_component(comp)
print "Edge status after split_multi_edges():"
for e in self.graph_copy.edges():
print e, self.edge_status[e]


def dfs1(self, v, u=None, check=True):
Expand Down Expand Up @@ -2333,10 +2350,18 @@ class Triconnectivity:
"""
y = 0
vnum = self.newnum[v]
adj = self.adj[v]
outv = len(adj)
for e in adj:
outv = len(self.adj[v])
#print "path_search(v) with parameter ", v, " with vnum ", vnum
#print "PRINTING ADJ IN PATHSEARCH ", v
#print self.adj
#for e in adj:
# ERROR fixed
for i in range(len(self.adj[v])):
#it = e
e = self.adj[v][i]
it = e

print "going through edges of ", v, ": edge ", e
if e in self.reverse_edges:
w = e[0] # target
else:
Expand Down Expand Up @@ -2365,13 +2390,22 @@ class Triconnectivity:
temp_target = temp[0]
else:
temp_target = temp[1]
#print "w and its adjacency: ", w, " " , temp
# while vnum is not the start_vertex
while vnum != 0 and ((self.t_stack_a[self.t_stack_top] == vnum) or \
#print "checking the while nvum!=1 test ", vnum
#print "stack_top_num=", self.t_stack_top, " :stack_top=",self.t_stack_a[self.t_stack_top]
#print "degree[w]=", self.degree[w], " target=", temp_target, " last val=", self.newnum[temp_target]
#print "WHILECHECK:", self.adj[w]
while vnum != 1 and ((self.t_stack_a[self.t_stack_top] == vnum) or \
(self.degree[w] == 2 and self.newnum[temp_target] > wnum)):
#print "entered the nvum!=1 while loop ", vnum
a = self.t_stack_a[self.t_stack_top]
b = self.t_stack_b[self.t_stack_top]
e_virt = None

print "list indices NONE?? ", a, b
print self.node_at[a]
print self.node_at[b]
if a == vnum and self.parent[self.node_at[b]] == self.node_at[a]:
self.t_stack_top -= 1

Expand Down Expand Up @@ -2402,7 +2436,10 @@ class Triconnectivity:
if e2_source != w: # OGDF_ASSERT
raise ValueError("graph is not biconnected?")

self.new_component([e1, e2, e_virt], 1)
print "before creating new component ", [e1, e2, e_virt]
comp = Component([e1, e2, e_virt], 1)
self.components_list.append(comp)
comp = None

if self.e_stack:
e1 = self.e_stack[-1]
Expand All @@ -2422,7 +2459,8 @@ class Triconnectivity:
h = self.t_stack_h[self.t_stack_top]
self.t_stack_top -= 1

comp = self.new_component()
print "before creating new component - empty edge_list"
comp = Component([],0)
while True:
xy = self.e_stack[-1]
if xy in self.reverse_edges:
Expand Down Expand Up @@ -2461,18 +2499,27 @@ class Triconnectivity:
self.graph_copy.add_edge(self.node_at[a], self.node_at[b])
e_virt = (self.node_at[a], self.node_at[b], None)
comp.finish_tric_or_poly(e_virt)
self.components_list.append(comp)
comp = None
x = self.node_at[b]

if e_ab is not None:
comp = self.new_component([e_ab, e_virt], type_c=0)
print "before creating new component ", [e_ab, e_virt]
comp = Component([e_ab, e_virt], type_c=0)
self.graph_copy.add_edge(v,x)
e_virt = (v,x,None)
comp.add_edge(e_virt)
self.degree[x] -= 1
self.degree[v] -= 1
self.components_list.append(comp)
comp = None

self.e_stack.append(e_virt)
#it = e_virt
# ERROR fixed
self.adj[v][i] = e_virt
it = e_virt

self.in_adj[e_virt] = it
self.degree[x] += 1
self.degree[v] += 1
Expand All @@ -2482,12 +2529,14 @@ class Triconnectivity:
w = x
wnum = self.newnum[w]

print "going to start type-1 check"
# start type-1 check
if self.lowpt2[w] >= vnum and self.lowpt1[w] < vnum and \
(self.parent[v] != self.start_vertex or outv >= 2):
# type-1 separation pair
print "Found type-1 separation pair (", self.node_at[self.lowpt1[w]], ", ", v, ")"
comp = self.new_component()
print "before creating new component - empty edgelist"
comp = Component([],0)
if not self.e_stack: # OGDF_ASSERT
raise ValueError("stack is empty")
while self.e_stack:
Expand All @@ -2508,13 +2557,18 @@ class Triconnectivity:
self.degree[self.node_at[xx]] -= 1
self.degree[self.node_at[y]] -= 1

#print "TYPE1: xx and y,, and vnum and wnum" , xx, y, vnum, self.lowpt1[w]
self.graph_copy.add_edge(v, self.node_at[self.lowpt1[w]])
e_virt = (v, self.node_at[self.lowpt1[w]], None)
comp.finish_tric_or_poly(e_virt);
comp.finish_tric_or_poly(e_virt)
self.components_list.append(comp)
comp = None

if (xx == vnum and y == self.lowpt1[w]) or \
(y == vnum and xx == self.lowpt1[w]):
comp_bond = self.new_component(type_c = 0)
#print "TYPE1:firstIFcondition"
print "before creating new component - empty edgelist "
comp_bond = Component([],type_c = 0)
eh = self.estack_pop()
if self.in_adj[eh] != it:
if eh in self.reverse_edges:
Expand All @@ -2531,27 +2585,42 @@ class Triconnectivity:
self.degree[v] -= 1
self.degree[self.node_at[self.lowpt1[w]]] -= 1

self.components_list.append(comp_bond)
comp_bond = None

if self.node_at[self.lowpt1[w]] != self.parent[v]:
self.e_stack.append(e_virt)

#it = e_virt
# ERROR fixed
self.adj[v][i] = e_virt
it = e_virt

self.in_adj[e_virt] = it
if not self.in_high[e_virt] and self.high(self.node_at[self.lowpt1[w]]) < vnum:
#print "TYPE1:secondIFcondition ", it, self.in_adj[e_virt]
# ERROR1 fixed:
#if not self.in_high[e_virt] and self.high(self.node_at[self.lowpt1[w]]) < vnum:
if not e_virt in self.in_high and self.high(self.node_at[self.lowpt1[w]]) < vnum:
self.highpt[self.node_at[self.lowpt1[w]]] = [vnum] + self.highpt[self.node_at[self.lowpt1[w]]]
self.in_high[e_virt] = vnum

self.degree[v] += 1
self.degree[self.node_at[self.lowpt1[w]]] += 1

else:
adj.remove(it)
comp_bond = self.new_component([e_virt], type_c=0)
self.adj[v].remove(it)
print "before creating new component ", [e_virt]
comp_bond = Component([e_virt], type_c=0)
self.graph_copy.add_edge(self.node_at[self.lowpt1[w]], v)
e_virt = (self.node_at[self.lowpt1[w]], v, None)
comp_bond.add_edge(e_virt)

eh = self.tree_arc[v];
comp_bond.add_edge(eh)

self.components_list.append(comp_bond)
comp_bond = None

self.tree_arc[v] = e_virt
self.egde_status[e_virt] = 1
self.in_adj[e_virt] = self.in_adj[eh]
Expand Down

0 comments on commit 6ff2b41

Please sign in to comment.