int
bfs_bounded(int vertex, vtx_data * graph, DistType * dist,
- Queue * Q, int bound, int *visited_nodes)
+ int bound, int *visited_nodes, int queue_size)
/* compute vector 'dist' of distances of all nodes from 'vertex' */
/* ignore nodes whose distance to 'vertex' is more than bound */
{
dist[vertex] = 0;
- initQueue(Q, vertex);
+ Queue Q;
+ mkQueue(&Q, queue_size);
+ initQueue(&Q, vertex);
num_visit = 0;
- while (deQueue(Q, &closestVertex)) {
+ while (deQueue(&Q, &closestVertex)) {
closestDist = dist[closestVertex];
if (closestDist > bound) {
dist[closestVertex] = -1;
neighbor = graph[closestVertex].edges[i];
if (dist[neighbor] < -0.5) { /* first time to reach neighbor */
dist[neighbor] = closestDist + 1;
- enQueue(Q, neighbor);
+ enQueue(&Q, neighbor);
}
}
}
+ freeQueue(&Q);
/* set distances of all nodes in Queue to -1 */
/* for next run */
- while (deQueue(Q, &closestVertex)) {
+ while (deQueue(&Q, &closestVertex)) {
dist[closestVertex] = -1;
}
dist[vertex] = -1;
extern bool enQueue(Queue *, int);
extern void bfs(int, vtx_data*, int, DistType*);
- extern int bfs_bounded(int, vtx_data*, DistType *, Queue*, int, int*);
+ extern int bfs_bounded(int, vtx_data*, DistType*, int, int*, int);
#ifdef __cplusplus
}
{
int num_visited_nodes;
int i;
- Queue Q;
heap H;
int closestVertex, neighbor;
DistType closestDist;
int num_found = 0;
/* first, perform BFS to find the nodes in the region */
- mkQueue(&Q, n);
/* remember that dist should be init. with -1's */
for (i = 0; i < n; i++) {
dist[i] = -1; /* far, TOO COSTLY (O(n))! */
}
num_visited_nodes =
- bfs_bounded(vertex, graph, dist, &Q, bound, visited_nodes);
+ bfs_bounded(vertex, graph, dist, bound, visited_nodes, n);
bitarray_t node_in_neighborhood = bitarray_new(n);
for (i = 0; i < num_visited_nodes; i++) {
bitarray_set(&node_in_neighborhood, visited_nodes[i], true);
bitarray_reset(&node_in_neighborhood);
freeHeap(&H);
free(index);
- freeQueue(&Q);
return num_visited_nodes;
}
/* if i is a pivot than CenterIndex[i] is its index, otherwise CenterIndex[i]= -1 */
int *CenterIndex;
int *invCenterIndex; /* list the pivot nodes */
- Queue Q;
float *old_weights;
/* this matrix stores the distance between each node and each "center" */
DistType **Dij;
}
invCenterIndex = NULL;
- mkQueue(&Q, n);
old_weights = graph[0].ewgts;
if (reweight_graph) {
visited_nodes);
} else {
num_visited_nodes =
- bfs_bounded(i, graph, dist, &Q, dist_bound, visited_nodes);
+ bfs_bounded(i, graph, dist, dist_bound, visited_nodes, n);
}
/* filter the pivots out of the visited nodes list, and the self loop: */
for (j = 0; j < num_visited_nodes;) {
}
free(subspace[0]);
free(subspace);
- freeQueue(&Q);
return iterations;
}