35#define MAX_DIST ((DistType)INT_MAX)
41static int left(
int i) {
return 2 * i; }
43static int right(
int i) {
return 2 * i + 1; }
45static int parent(
int i) {
return i / 2; }
109 for (count = 0, i = 0; i < n; i++)
110 if (i != startVertex) {
116 for (j = (n - 1) / 2; j >= 0; j--)
139 if (
dist[increasedVertex] <= newDist)
142 placeInHeap = h->
index[increasedVertex];
144 dist[increasedVertex] = newDist;
151 h->
data[i] = increasedVertex;
152 h->
index[increasedVertex] = i;
161 for (
int i = 0; i < n; i++)
170 closestDist =
dist[closestVertex];
173 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
178 prevClosestDist = closestDist;
182 for (
int i = 0; i < n; i++)
184 dist[i] = prevClosestDist + 10;
217 for (count = 0, i = 0; i < n; i++)
218 if (i != startVertex) {
224 for (j = (n - 1) / 2; j >= 0; j--)
248 if (
dist[increasedVertex] <= newDist)
251 placeInHeap = h->
index[increasedVertex];
253 dist[increasedVertex] = newDist;
260 h->
data[i] = increasedVertex;
261 h->
index[increasedVertex] = i;
273 for (
int i = 0; i < n; i++)
282 closestDist =
dist[closestVertex];
283 if (closestDist == FLT_MAX)
285 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
300 for (
size_t i= 0; i <
graph->n; i++) {
304 for (
size_t i =
graph->sources[source]; i <
graph->sources[source + 1];
306 size_t target =
graph->targets[i];
307 dists[target] =
graph->weights[i];
309 assert(
graph->n <= INT_MAX);
312 int closest = 0, offset = 0;
314 float d = dists[closest];
321 terms[offset].
i = source;
322 terms[offset].
j = closest;
324 terms[offset].
w = 1 / (d*d);
327 for (
size_t i =
graph->sources[closest]; i <
graph->sources[closest + 1];
329 size_t target =
graph->targets[i];
330 float weight =
graph->weights[i];
331 assert(target <= INT_MAX);
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
API for compacted arrays of booleans.
static bool bitarray_get(bitarray_t self, size_t index)
get the value of the given element
#define greaterPriority(h, i, j)
static double dist(int dim, double *x, double *y)
Agraph_t * graph(char *name)
Arithmetic helper functions.
static void exchange(heap *h, int i, int j)
static bool extractMax(heap *h, int *max, Word dist[])
static void freeHeap(heap *h)
static heap initHeap(int startVertex, Word dist[], int n)
static heap initHeap_f(int startVertex, float dist[], int n)
static bool extractMax_f(heap *h, int *max, float dist[])
static void heapify_f(heap *h, int i, float dist[])
void dijkstra_f(int vertex, vtx_data *graph, int n, float *dist)
static bool greaterPriority_f(const heap *h, int i, int j, const float *dist)
static void increaseKey(heap *h, int increasedVertex, Word newDist, Word dist[])
void ngdijkstra(int vertex, vtx_data *graph, int n, DistType *dist)
static void assign(heap *h, int i, int j)
int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms)
static void heapify(heap *h, int i, Word dist[])
static void increaseKey_f(heap *h, int increasedVertex, float newDist, float dist[])
#define neighbor(t, i, edim, elist)