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

Commit

Permalink
trac #18864: correct version
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Jul 13, 2015
1 parent f621777 commit 80cb899
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/sage/graphs/distances_all_pairs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -757,69 +757,57 @@ cdef uint32_t * c_eccentricity_bounding(G) except NULL:
init_short_digraph(sd, G)

# allocated some data structures
cdef bitset_t bits
bitset_init(bits, n)
cdef uint32_t * distances = <uint32_t *>sage_malloc(2 * n * sizeof(uint32_t))
if distances==NULL:
bitset_free(bits)
raise MemoryError()
cdef uint32_t * waiting_list = distances + n

cdef uint32_t * LB = <uint32_t *>sage_calloc(n, sizeof(uint32_t))
cdef uint32_t * UB = <uint32_t *>sage_malloc(n * sizeof(uint32_t))
if LB==NULL or UB==NULL:
bitset_free(bits)
cdef bitset_t seen
bitset_init(seen, n)
cdef uint32_t * distances = <uint32_t *>sage_malloc(3 * n * sizeof(uint32_t))
cdef uint32_t * LB = <uint32_t *>sage_calloc(n, sizeof(uint32_t))
if distances==NULL or LB==NULL:
bitset_free(seen)
sage_free(LB)
sage_free(UB)
sage_free(distances)
free_short_digraph(sd)
raise MemoryError()

cdef uint32_t * waiting_list = distances + n
cdef uint32_t * UB = distances + 2 * n
memset(UB, -1, n * sizeof(uint32_t))

cdef uint32_t v, w, next_v, tmp, cpt = 0

# The first vertex is the one with largest degree
next_v = max((out_degree(sd, v), v) for v in range(n))[1]
bitset_clear(bits)
bitset_complement(bits, bits)

sig_on()
while bitset_len(bits):
while next_v!=UINT32_MAX:

v = next_v
bitset_discard(bits, v)
cpt += 1

# Compute the exact eccentricity of v
LB[v] = simple_BFS(n, sd.neighbors, v, distances, NULL, waiting_list, bits)
LB[v] = simple_BFS(n, sd.neighbors, v, distances, NULL, waiting_list, seen)

if LB[v]==UINT32_MAX:
# The graph is not connected. We set maximum value
# and exit.
# The graph is not connected. We set maximum value and exit.
for w in range(n):
LB[w] = UINT32_MAX
break

# Improve the bounds on the eccentricity of other vertices and select
# source of the next BFS
next_v = UINT32_MAX
w = bitset_first(bits)
while w!=-1:
for w in range(n):
LB[w] = max(LB[w], max(LB[v] - distances[w], distances[w]))
UB[w] = min(UB[w], LB[v] + distances[w])
if LB[w]==UB[w]:
bitset_discard(bits, w)
continue
elif next_v==UINT32_MAX or (cpt%2==0 and LB[w]<LB[next_v]) or (cpt%2==1 and UB[w]>UB[next_v]):
# The next vertex is either the vertex with largest upper bound
# or smallest lower bound
next_v = w
w = bitset_next(bits, w+1)

sig_off()

sage_free(distances)
sage_free(UB)
bitset_free(bits)
bitset_free(seen)
free_short_digraph(sd)

return LB
Expand Down

0 comments on commit 80cb899

Please sign in to comment.