summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/correlations.c147
1 files changed, 50 insertions, 97 deletions
diff --git a/src/correlations.c b/src/correlations.c
index 3e7749c..e80c792 100644
--- a/src/correlations.c
+++ b/src/correlations.c
@@ -2,9 +2,9 @@
#include "fracture.h"
struct fibn {
- unsigned int value;
- unsigned int priority;
- unsigned int rank;
+ uint_t value;
+ uint_t priority;
+ uint_t rank;
bool marked;
struct fibn *first_child;
struct fibn *parent;
@@ -14,12 +14,14 @@ struct fibn {
typedef struct {
struct fibn *min;
- unsigned int rank;
- unsigned int trees;
+ uint_t rank;
+ uint_t trees;
struct fibn **vertex_to_node;
} fibh;
-unsigned int fib_findmin(fibh *heap) { return heap->min->value; }
+uint_t fib_findmin(fibh *heap) {
+ return heap->min->value;
+}
void ll_setparent(struct fibn *ll, struct fibn *parent) {
struct fibn *curnode = ll->next;
@@ -70,7 +72,7 @@ struct fibn *ll_delroot(struct fibn *ll) {
return ll_beg;
}
-void fib_insert(fibh *heap, unsigned int value, unsigned int priority) {
+void fib_insert(fibh *heap, uint_t value, uint_t priority) {
struct fibn *newnode = calloc(1, sizeof(struct fibn));
newnode->value = value;
newnode->priority = priority;
@@ -89,7 +91,7 @@ void fib_insert(fibh *heap, unsigned int value, unsigned int priority) {
}
void fib_deletemin(fibh *heap) {
- unsigned int min_rank = heap->min->rank;
+ uint_t min_rank = heap->min->rank;
struct fibn *min_children = heap->min->first_child;
struct fibn *trees = ll_delroot(heap->min);
@@ -108,11 +110,11 @@ void fib_deletemin(fibh *heap) {
heap->rank = 0;
} else {
// min had children or there were other trees
- unsigned int min_val = UINT_MAX;
+ uint_t min_val = UINT_MAX;
struct fibn *min_ptr = NULL;
- unsigned int max_rank = 0;
+ uint_t max_rank = 0;
struct fibn *curnode = trees;
- for (unsigned int i = 0; i < heap->trees; i++) {
+ for (uint_t i = 0; i < heap->trees; i++) {
if (curnode->priority < min_val) {
min_ptr = curnode;
min_val = curnode->priority;
@@ -160,8 +162,7 @@ void fib_deletemin(fibh *heap) {
}
}
-void fib_decreasekey(fibh *heap, unsigned int value,
- unsigned int new_priority) {
+void fib_decreasekey(fibh *heap, uint_t value, uint_t new_priority) {
struct fibn *node = heap->vertex_to_node[value];
if (node != NULL) {
node->priority = new_priority;
@@ -197,17 +198,17 @@ void fib_decreasekey(fibh *heap, unsigned int value,
}
}
-unsigned int *dijkstra(const graph_t *network, unsigned int source) {
- unsigned int nv = network->dnv;
- unsigned int *vei = network->dvei;
- unsigned int *ve = network->dve;
- unsigned int *ev = network->dev;
+uint_t *dijkstra(const graph_t *network, uint_t source) {
+ uint_t nv = network->dnv;
+ uint_t *vei = network->dvei;
+ uint_t *ve = network->dve;
+ uint_t *ev = network->dev;
- unsigned int *dist = (unsigned int *)calloc(nv, sizeof(unsigned int));
+ uint_t *dist = (uint_t *)calloc(nv, sizeof(uint_t));
fibh *Q = (fibh *)calloc(1, sizeof(fibh));
Q->vertex_to_node = (struct fibn **)calloc(nv, sizeof(struct fibn *));
- for (unsigned int i = 0; i < nv; i++) {
+ for (uint_t i = 0; i < nv; i++) {
if (i != source) {
dist[i] = UINT_MAX;
}
@@ -216,13 +217,13 @@ unsigned int *dijkstra(const graph_t *network, unsigned int source) {
}
while (Q->min != NULL) {
- unsigned int u = fib_findmin(Q);
+ uint_t u = fib_findmin(Q);
fib_deletemin(Q);
- for (unsigned int i = 0; i < vei[u + 1] - vei[u]; i++) {
- unsigned int e = ve[vei[u] + i];
- unsigned int v = ev[2 * e] == u ? ev[2 * e + 1] : ev[2 * e];
- unsigned int alt = dist[u] + 1;
+ for (uint_t i = 0; i < vei[u + 1] - vei[u]; i++) {
+ uint_t e = ve[vei[u] + i];
+ uint_t v = ev[2 * e] == u ? ev[2 * e + 1] : ev[2 * e];
+ uint_t alt = dist[u] + 1;
if (alt < dist[v]) {
dist[v] = alt;
fib_decreasekey(Q, v, alt);
@@ -236,48 +237,48 @@ unsigned int *dijkstra(const graph_t *network, unsigned int source) {
return dist;
}
-unsigned int **get_dists(const graph_t *network) {
- unsigned int nv = network->dnv;
- unsigned int **dists = (unsigned int **)malloc(nv * sizeof(unsigned int *));
+uint_t **get_dists(const graph_t *network) {
+ uint_t nv = network->dnv;
+ uint_t **dists = (uint_t **)malloc(nv * sizeof(uint_t *));
-#pragma omp parallel for
- for (unsigned int i = 0; i < nv; i++) {
+ #pragma omp parallel for
+ for (uint_t i = 0; i < nv; i++) {
dists[i] = dijkstra(network, i);
}
return dists;
}
-double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c) {
- unsigned int nv = instance->graph->dnv;
- unsigned int ne = instance->graph->ne;
- unsigned int *ev = instance->graph->dev;
+double *get_corr(net_t *instance, uint_t **dists, cholmod_common *c) {
+ uint_t nv = instance->graph->dnv;
+ uint_t ne = instance->graph->ne;
+ uint_t *ev = instance->graph->dev;
bool nulldists = false;
if (dists == NULL) {
dists = get_dists(instance->graph);
nulldists = true;
}
double *corr = calloc(nv, sizeof(double));
- unsigned int *marks = get_clusters(instance, c);
- unsigned int *numat = calloc(nv, sizeof(unsigned int));
-
- for (unsigned int i = 0; i < ne; i++) {
- unsigned int v1 = ev[2 * i];
- unsigned int v2 = ev[2 * i + 1];
- for (unsigned int j = 0; j < ne; j++) {
- unsigned int v3 = ev[2 * j];
- unsigned int v4 = ev[2 * j + 1];
- unsigned int dist1 = dists[v1][v3];
- unsigned int dist2 = dists[v1][v4];
- unsigned int dist3 = dists[v2][v3];
- unsigned int dist4 = dists[v2][v4];
- unsigned int dist = (dist1 + dist2 + dist3 + dist4) / 4;
+ uint_t *marks = get_clusters(instance, c);
+ uint_t *numat = calloc(nv, sizeof(uint_t));
+
+ for (uint_t i = 0; i < ne; i++) {
+ uint_t v1 = ev[2 * i];
+ uint_t v2 = ev[2 * i + 1];
+ for (uint_t j = 0; j < ne; j++) {
+ uint_t v3 = ev[2 * j];
+ uint_t v4 = ev[2 * j + 1];
+ uint_t dist1 = dists[v1][v3];
+ uint_t dist2 = dists[v1][v4];
+ uint_t dist3 = dists[v2][v3];
+ uint_t dist4 = dists[v2][v4];
+ uint_t dist = (dist1 + dist2 + dist3 + dist4) / 4;
corr[dist] += instance->fuses[i] && instance->fuses[j];
numat[dist]++;
}
}
- for (unsigned int i = 0; i < nv; i++) {
+ for (uint_t i = 0; i < nv; i++) {
if (numat[i] > 0) {
corr[i] /= numat[i];
}
@@ -295,51 +296,3 @@ double *get_corr(net_t *instance, unsigned int **dists, cholmod_common *c) {
return corr;
}
-/*
-double *get_space_corr(net_t *instance, cholmod_common *c) {
- unsigned int nv = instance->graph->dnv;
- double *vc = instance->graph->dvx;
- unsigned int ne = instance->graph->ne;
- unsigned int *ev = instance->graph->dev;
- double *corr = calloc(nv, sizeof(unsigned int));
- unsigned int *numat = calloc(nv, sizeof(unsigned int));
-
- for (unsigned int i = 0; i < ne; i++) {
- unsigned int v1 = ev[2 * i];
- unsigned int v2 = ev[2 * i + 1];
- double v1x = vc[2 * v1];
- double v1y = vc[2 * v1 + 1];
- double v2x = vc[2 * v2];
- double v2y = vc[2 * v2 + 1];
- double e1x = (v1x + v2x) / 2;
- double e1y = (v1y + v2y) / 2;
- for (unsigned int j = 0; j < ne; j++) {
- unsigned int v3 = ev[2 * j];
- unsigned int v4 = ev[2 * j + 1];
- double v1x = vc[2 * v1];
- double v1y = vc[2 * v1 + 1];
- double v2x = vc[2 * v2];
- double v2y = vc[2 * v2 + 1];
- double e1x = (v1x + v2x) / 2;
- double e1y = (v1y + v2y) / 2;
- corr[dist] += instance->fuses[i] && instance->fuses[j];
- numat[dist]++;
- }
- }
-
- for (unsigned int i = 0; i < nv; i++) {
- if (numat[i] > 0) {
- corr[i] /= numat[i];
- }
- }
-
- for (int i = 0; i < nv; i++) {
- free(dists[i]);
- }
-
- free(marks);
- free(dists);
-
- return corr;
-}
-*/