25 int num_shared_neighbors = 0;
27 for (j = 1; j < graph[u].
nedges; j++) {
28 neighbor = graph[u].
edges[j];
29 if (v_vector[neighbor] > 0) {
31 num_shared_neighbors++;
34 return num_shared_neighbors;
41 for (j = 1; j < graph[vtx].
nedges; j++) {
42 vtx_vec[graph[vtx].
edges[j]] = 1;
51 for (j = 1; j < graph[vtx].
nedges; j++) {
52 vtx_vec[graph[vtx].
edges[j]] = 0;
67 for (i = 0; i < n; i++)
68 dij[i] = storage + i * n;
70 for (i = 0; i < n; i++) {
86 for (i = 0; i < n; i++) {
87 dij[i] = storage + i * n;
90 for (i = 0; i < n; i++) {
91 bfs(i, graph, n, dij[i], &Q);
100 return compute_apsp_dijkstra(graph, n);
102 return compute_apsp_simple(graph, n);
111 float *old_weights = graph[0].
ewgts;
114 Dij = compute_apsp_dijkstra(graph, n);
127 split_by_place(
double *place,
int *nodes,
int first,
int last,
int *middle)
129 unsigned int splitter=((
unsigned int)rand()|((
unsigned int)rand())<<16)%(
unsigned int)(last-first+1)+(
unsigned int)first;
132 int left = first + 1;
136 val = nodes[splitter];
137 nodes[splitter] = nodes[first];
139 place_val = place[val];
141 while (left < right) {
142 while (left < right && place[nodes[left]] <= place_val)
147 while (left < right && place[nodes[right]] > place_val)
164 if (place[nodes[left]] > place_val)
167 nodes[first] = nodes[
left];
176 for (k = 0; k < dim; k++) {
178 (coords[k][i] - coords[k][j]) * (coords[k][i] - coords[k][j]);
185 fcmpf (
int* ip1,
int* ip2)
187 float d1 = fvals[*ip1];
188 float d2 = fvals[*ip2];
189 if (d1 < d2)
return -1;
190 else if (d1 > d2)
return 1;
198 qsort(ordering+first, last-first+1,
sizeof(ordering[0]), (
qsort_cmpf)fcmpf);
203 sorted_place(
double * place,
int * ordering,
int first,
int last)
206 for (i=first+1; i<=last && isSorted; i++) {
207 if (place[ordering[i-1]]>place[ordering[i]]) {
224 split_by_place(place, ordering, first, last, middle);
226 split_by_place(place, ordering, first, last, &middle);
235 if (!sorted_place(place,ordering,first,middle-1))
237 if (!sorted_place(place,ordering,middle+1,last))
249 int *vtx_vec =
N_GNEW(n,
int);
250 int deg_i, deg_j, neighbor;
252 for (i = 0; i < n; i++) {
253 nedges += graph[i].
nedges;
255 weights =
N_GNEW(nedges,
float);
257 for (i = 0; i < n; i++) {
261 for (i = 0; i < n; i++) {
262 graph[i].
ewgts = weights;
264 deg_i = graph[i].
nedges - 1;
265 for (j = 1; j <= deg_i; j++) {
266 neighbor = graph[i].
edges[j];
267 deg_j = graph[neighbor].
nedges - 1;
269 (float) (deg_i + deg_j -
274 weights += graph[i].
nedges;
282 free(graph[0].ewgts);
284 if (old_weights !=
NULL) {
285 for (i = 0; i < n; i++) {
286 graph[i].
ewgts = old_weights;
287 old_weights += graph[i].
nedges;
DistType ** compute_apsp_artifical_weights(vtx_data *graph, int n)
void restore_old_weights(vtx_data *graph, int n, float *old_weights)
int common_neighbors(vtx_data *graph, int v, int u, int *v_vector)
void bfs(int vertex, vtx_data *graph, int n, DistType *dist, Queue *Q)
void freeQueue(Queue *qp)
void fill_neighbors_vec_unweighted(vtx_data *graph, int vtx, int *vtx_vec)
DistType ** compute_apsp(vtx_data *graph, int n)
double distance_kD(double **coords, int dim, int i, int j)
void quicksort_place(double *place, int *ordering, int first, int last)
void dijkstra(int vertex, vtx_data *graph, int n, DistType *dist)
int(* qsort_cmpf)(const void *, const void *)
void empty_neighbors_vec(vtx_data *graph, int vtx, int *vtx_vec)
void mkQueue(Queue *qp, int size)
Agraph_t * graph(char *name)
void compute_new_weights(vtx_data *graph, int n)
void quicksort_placef(float *place, int *ordering, int first, int last)