32#define MAX_DIST ((DistType)INT_MAX)
38#define left(i) (2*(i))
39#define right(i) (2*(i)+1)
40#define parent(i) ((i)/2)
41#define insideHeap(h,i) ((i)<h->heapSize)
42#define greaterPriority(h,i,j,dist) (dist[h->data[i]]<dist[h->data[j]])
43#define assign(h,i,j,index) {h->data[i]=h->data[j]; index[h->data[i]]=i;}
44#define exchange(h,i,j,index) {int temp; \
46 h->data[i]=h->data[j]; \
48 index[h->data[i]]=i; \
49 index[h->data[j]]=j; \
92 for (count = 0, i = 0; i < n; i++)
93 if (i != startVertex) {
99 for (j = (n - 1) / 2; j >= 0; j--)
110 index[h->
data[0]] = 0;
124 if (
dist[increasedVertex] <= newDist)
127 placeInHeap = index[increasedVertex];
129 dist[increasedVertex] = newDist;
136 h->
data[i] = increasedVertex;
137 index[increasedVertex] = i;
149 for (
int i = 0; i < n; i++)
158 closestDist =
dist[closestVertex];
161 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
166 prevClosestDist = closestDist;
170 for (
int i = 0; i < n; i++)
172 dist[i] = prevClosestDist + 10;
206 for (count = 0, i = 0; i < n; i++)
207 if (i != startVertex) {
213 for (j = (n - 1) / 2; j >= 0; j--)
224 index[h->
data[0]] = 0;
238 if (
dist[increasedVertex] <= newDist)
241 placeInHeap = index[increasedVertex];
243 dist[increasedVertex] = newDist;
250 h->
data[i] = increasedVertex;
251 index[increasedVertex] = i;
266 for (
int i = 0; i < n; i++)
275 closestDist =
dist[closestVertex];
276 if (closestDist == FLT_MAX)
278 for (
size_t i = 1; i <
graph[closestVertex].nedges; i++) {
296 for (
size_t i= 0; i <
graph->n; i++) {
300 for (
size_t i =
graph->sources[source]; i <
graph->sources[source + 1];
302 size_t target =
graph->targets[i];
303 dists[target] =
graph->weights[i];
305 assert(
graph->n <= INT_MAX);
308 int closest = 0,
offset = 0;
310 float d = dists[closest];
323 for (
size_t i =
graph->sources[closest]; i <
graph->sources[closest + 1];
325 size_t target =
graph->targets[i];
326 float weight =
graph->weights[i];
327 assert(target <= (
size_t)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
static double dist(int dim, double *x, double *y)
Agraph_t * graph(char *name)
swig_ptr_object_handlers offset
#define exchange(h, i, j, index)
static bool extractMax(heap *h, int *max, int index[], Word dist[])
static void freeHeap(heap *h)
static void heapify(heap *h, int i, int index[], Word dist[])
static void initHeap(heap *h, int startVertex, int index[], Word dist[], int n)
static void increaseKey(heap *h, int increasedVertex, Word newDist, int index[], Word dist[])
static bool extractMax_f(heap *h, int *max, int index[], float dist[])
void dijkstra_f(int vertex, vtx_data *graph, int n, float *dist)
static void initHeap_f(heap *h, int startVertex, int index[], float dist[], int n)
#define assign(h, i, j, index)
static void heapify_f(heap *h, int i, int index[], float dist[])
static void increaseKey_f(heap *h, int increasedVertex, float newDist, int index[], float dist[])
int dijkstra_sgd(graph_sgd *graph, int source, term_sgd *terms)
#define greaterPriority(h, i, j, dist)
#define neighbor(t, i, edim, elist)