33#define MAX_DIST ((DistType)INT_MAX)
39static int left(
int i) {
return 2 * i; }
41static int right(
int i) {
return 2 * i + 1; }
43static int parent(
int i) {
return i / 2; }
107 for (count = 0, i = 0; i < n; i++)
108 if (i != startVertex) {
114 for (j = (n - 1) / 2; j >= 0; j--)
137 if (
dist[increasedVertex] <= newDist)
140 placeInHeap = h->
index[increasedVertex];
142 dist[increasedVertex] = newDist;
149 h->
data[i] = increasedVertex;
150 h->
index[increasedVertex] = i;
159 for (
int i = 0; i < n; i++)
168 closestDist =
dist[closestVertex];
171 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
176 prevClosestDist = closestDist;
180 for (
int i = 0; i < n; i++)
182 dist[i] = prevClosestDist + 10;
215 for (count = 0, i = 0; i < n; i++)
216 if (i != startVertex) {
222 for (j = (n - 1) / 2; j >= 0; j--)
246 if (
dist[increasedVertex] <= newDist)
249 placeInHeap = h->
index[increasedVertex];
251 dist[increasedVertex] = newDist;
258 h->
data[i] = increasedVertex;
259 h->
index[increasedVertex] = i;
271 for (
int i = 0; i < n; i++)
280 closestDist =
dist[closestVertex];
281 if (closestDist == FLT_MAX)
283 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
298 for (
size_t i= 0; i <
graph->n; i++) {
302 for (
size_t i =
graph->sources[source]; i <
graph->sources[source + 1];
304 size_t target =
graph->targets[i];
305 dists[target] =
graph->weights[i];
307 assert(
graph->n <= INT_MAX);
310 int closest = 0, offset = 0;
312 float d = dists[closest];
319 terms[offset].
i = source;
320 terms[offset].
j = closest;
322 terms[offset].
w = 1 / (d*d);
325 for (
size_t i =
graph->sources[closest]; i <
graph->sources[closest + 1];
327 size_t target =
graph->targets[i];
328 float weight =
graph->weights[i];
329 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)