From 873a9f9bedbbfb07d475e271923a7b86464e515f Mon Sep 17 00:00:00 2001 From: pants Date: Wed, 7 Sep 2016 14:55:30 -0400 Subject: more major refactoring --- src/instance.c | 124 --------------------------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 src/instance.c (limited to 'src/instance.c') diff --git a/src/instance.c b/src/instance.c deleted file mode 100644 index bb1ac8c..0000000 --- a/src/instance.c +++ /dev/null @@ -1,124 +0,0 @@ - -#include "fracture.h" - -net_t *create_instance(graph_t *network, double inf, bool voltage_bound, - bool startnow, cholmod_common *c) { - net_t *instance = (net_t *)calloc(1, sizeof(net_t)); - assert(instance != NULL); - - instance->graph = network; - instance->num_remaining_edges = network->ne; - instance->fuses = (bool *)calloc(network->ne, sizeof(bool)); - assert(instance->fuses != NULL); - instance->inf = inf; - instance->voltage_bound = voltage_bound; - instance->boundary_cond = CHOL_F(zeros)( - network->break_dim, 1, CHOLMOD_REAL, c); - if (network->boundary == TORUS_BOUND) { - for (unsigned int i = 0; i < network->bound_inds[1]; i++) { - ((double *)instance->boundary_cond->x)[network->bound_verts[i]] = 1; - ((double *)instance->boundary_cond->x)[network->nv + i] = -1; - } - ((double *)instance->boundary_cond->x)[network->bound_verts[0]] = 1; - } else if (network->boundary == EMBEDDED_BOUND) { - // do nothing - for (unsigned int i = 0; i < network->bound_inds[1]; i++) { - ((double *)instance->boundary_cond->x)[network->bound_verts[i]] =1; - } - } else { - if (voltage_bound) { - for (unsigned int i = 0; i < network->bound_inds[1]; i++) { - ((double *)instance->boundary_cond->x)[network->bound_verts[i]] =1; - } - } else { - ((double *)instance->boundary_cond->x)[0] = 1; - ((double *)instance->boundary_cond->x)[network->nv] = 1; - ((double *)instance->boundary_cond->x)[network->nv + 1] = -1; - } - } - - if (network->boundary != TORUS_BOUND) instance->adjacency = gen_adjacency(instance, false, false, 0, c); - else instance->adjacency = gen_adjacency(instance, true, false, 0, c); - - if (startnow) { - cholmod_sparse *laplacian = gen_laplacian(instance, c, true); - instance->factor = CHOL_F(analyze)(laplacian, c); - CHOL_F(factorize)(laplacian, instance->factor, c); - CHOL_F(free_sparse)(&laplacian, c); - } - - instance->marks = (unsigned int *)malloc( - (instance->graph->break_dim) * - sizeof(unsigned int)); - instance->dual_marks = (unsigned int *)malloc( - (instance->graph->dnv) * - sizeof(unsigned int)); - assert(instance->marks != NULL); - - for (unsigned int i = 0; - i < (instance->graph->break_dim); - i++) { - instance->marks[i] = 1; - } - for (unsigned int i = 0; - i < (instance->graph->dnv); - i++) { - instance->dual_marks[i] = i+1; - } - instance->num_components = 1; - - return instance; -} - -void finish_instance(net_t *instance, cholmod_common *c) { - cholmod_sparse *laplacian = gen_laplacian(instance, c, true); - instance->factor = CHOL_F(analyze)(laplacian, c); - CHOL_F(factorize)(laplacian, instance->factor, c); - CHOL_F(free_sparse)(&laplacian, c); -} - -net_t *copy_instance(const net_t *instance, cholmod_common *c) { - net_t *instance_copy = (net_t *)calloc(1, sizeof(net_t)); - memcpy(instance_copy, instance, sizeof(net_t)); - - size_t fuses_size = (instance->graph)->ne * sizeof(bool); - instance_copy->fuses = (bool *)malloc(fuses_size); - memcpy(instance_copy->fuses, instance->fuses, fuses_size); - - size_t marks_size = - (instance->graph->break_dim) * - sizeof(unsigned int); - instance_copy->marks = (unsigned int *)malloc(marks_size); - memcpy(instance_copy->marks, instance->marks, marks_size); - - size_t dual_marks_size = - (instance->graph->dnv) * - sizeof(unsigned int); - instance_copy->dual_marks = (unsigned int *)malloc(dual_marks_size); - memcpy(instance_copy->dual_marks, instance->dual_marks, dual_marks_size); - - instance_copy->adjacency = CHOL_F(copy_sparse)(instance->adjacency, c); - instance_copy->boundary_cond = CHOL_F(copy_dense)(instance->boundary_cond, c); - instance_copy->factor = CHOL_F(copy_factor)(instance->factor, c); - - return instance_copy; -} - -void free_instance(net_t *instance, cholmod_common *c) { - free(instance->fuses); - CHOL_F(free_dense)(&(instance->boundary_cond), c); - CHOL_F(free_sparse)(&(instance->adjacency), c); - CHOL_F(free_factor)(&(instance->factor), c); - free(instance->marks); - free(instance->dual_marks); - free(instance); -} - -bool check_instance(const net_t *instance, cholmod_common *c) { - assert(instance != NULL); - assert(instance->fuses != NULL); - assert(CHOL_F(check_dense)(instance->boundary_cond, c)); - assert(CHOL_F(check_factor)(instance->factor, c)); - - return true; -} -- cgit v1.2.3-70-g09d2