22 size_t num_shared_neighbors = 0;
23 for (
size_t j = 1; j <
graph[u].nedges; j++) {
27 num_shared_neighbors++;
30 return num_shared_neighbors;
36 for (
size_t j = 1; j <
graph[vtx].nedges; j++) {
37 vtx_vec[
graph[vtx].edges[j]] = 1;
45 for (
size_t j = 1; j <
graph[vtx].nedges; j++) {
46 vtx_vec[
graph[vtx].edges[j]] = 0;
59 for (i = 0; i < n; i++)
60 dij[i] = storage + i * n;
62 for (i = 0; i < n; i++) {
76 for (i = 0; i < n; i++) {
77 dij[i] = storage + i * n;
79 for (i = 0; i < n; i++) {
98 float *old_weights =
graph[0].ewgts;
118 for (k = 0; k <
dim; k++) {
120 (coords[k][i] - coords[k][j]) * (coords[k][i] - coords[k][j]);
125static int fcmpf(
const void *a,
const void *b,
void *context) {
128 float *fvals = context;
129 float d1 = fvals[*ip1];
130 float d2 = fvals[*ip2];
143 gv_sort(ordering + first,
last - first + 1,
sizeof(ordering[0]),
fcmpf, place);
147static int cmp(
const void *a,
const void *b,
void *context) {
150 const double *place = context;
152 if (place[*x] < place[*y]) {
155 if (place[*x] > place[*y]) {
162 gv_sort(ordering, size,
sizeof(ordering[0]),
cmp, place);
171 int *vtx_vec =
gv_calloc(n,
sizeof(
int));
175 for (i = 0; i < n; i++) {
180 for (i = 0; i < n; i++) {
181 graph[i].ewgts = weights;
183 deg_i =
graph[i].nedges - 1;
184 for (
size_t j = 1; j <= deg_i; j++) {
191 weights +=
graph[i].nedges;
201 if (old_weights !=
NULL) {
202 for (i = 0; i < n; i++) {
203 graph[i].ewgts = old_weights;
204 old_weights +=
graph[i].nedges;
static agxbuf last
last message
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
void bfs(int vertex, vtx_data *graph, int n, DistType *dist)
Agraph_t * graph(char *name)
static DistType ** compute_apsp_dijkstra(vtx_data *graph, int n)
static DistType ** compute_apsp_simple(vtx_data *graph, int n)
void compute_new_weights(vtx_data *graph, int n)
void quicksort_place(double *place, int *ordering, int size)
double distance_kD(double **coords, int dim, int i, int j)
void fill_neighbors_vec_unweighted(vtx_data *graph, int vtx, int *vtx_vec)
size_t common_neighbors(vtx_data *graph, int u, int *v_vector)
DistType ** compute_apsp(vtx_data *graph, int n)
void restore_old_weights(vtx_data *graph, int n, float *old_weights)
DistType ** compute_apsp_artificial_weights(vtx_data *graph, int n)
void empty_neighbors_vec(vtx_data *graph, int vtx, int *vtx_vec)
void quicksort_placef(float *place, int *ordering, int first, int last)
static int fcmpf(const void *a, const void *b, void *context)
static int cmp(const void *a, const void *b, void *context)
#define neighbor(t, i, edim, elist)
static int nedges
total no. of edges used in routing
qsort with carried along context
static void gv_sort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg)
qsort with an extra state parameter, ala qsort_r