diff options
Diffstat (limited to 'src/break_edge.c')
-rw-r--r-- | src/break_edge.c | 121 |
1 files changed, 34 insertions, 87 deletions
diff --git a/src/break_edge.c b/src/break_edge.c index 4e8bdcf..2f112c2 100644 --- a/src/break_edge.c +++ b/src/break_edge.c @@ -1,104 +1,51 @@ #include "fracture.h" -bool break_edge(net_t *instance, uint_t edge, cholmod_common *c) { - instance->fuses[edge] = true; - instance->num_broken++; - if (instance->factor != NULL) { - uint_t w1 = instance->graph->ev_break[2 * edge]; - uint_t w2 = instance->graph->ev_break[2 * edge + 1]; - factor_update(instance->factor, w1, w2, c); - } - - uint_t v1, v2, s1, s2, dv1, dv2, ds1, ds2; +bool break_edge(net_t *net, uint_t edge, cholmod_common *c) { + net->fuses[edge] = true; + net->num_broken++; - v1 = instance->graph->ev[2 * edge]; - v2 = instance->graph->ev[2 * edge + 1]; - dv1 = instance->graph->dev[2 * edge]; - dv2 = instance->graph->dev[2 * edge + 1]; + double *x = (double *)net->boundary_cond->x; + const graph_t *g = net->graph; - s1 = v1 > v2 ? v1 : v2; - s2 = v1 > v2 ? v2 : v1; - ds1 = dv1 > dv2 ? dv1 : dv2; - ds2 = dv1 > dv2 ? dv2 : dv1; + uint_t v1 = net->graph->ev[2 * edge]; + uint_t v2 = net->graph->ev[2 * edge + 1]; - { - int_t *lap_p = (int_t *)instance->adjacency->p; - int_t *lap_i = (int_t *)instance->adjacency->i; - double *lap_x = (double *)instance->adjacency->x; + uint_t s1 = v1 < v2 ? v1 : v2; + uint_t s2 = v1 < v2 ? v2 : v1; - for (int i = 0; i < lap_p[s1 + 1] - lap_p[s1]; i++) { - if (lap_i[lap_p[s1] + i] == s2) - lap_x[lap_p[s1] + i] = 0; + if (net->graph->boundary == TORUS_BOUND) { + if (net->graph->bq[edge]) { + double v1y = g->vx[2 * v1 + 1]; + double v2y = g->vx[2 * v2 + 1]; + uint_t ind = v1y < v2y ? 0 : 1; + x[g->ev[2 * edge + ind]] -= 1; + x[g->ev[2 * edge + !ind]] += 1; } - for (int i = 0; i < lap_p[s2 + 1] - lap_p[s2]; i++) { - if (lap_i[lap_p[s2] + i] == s1) - lap_x[lap_p[s2] + i] = 0; + if (net->factor != NULL) { + factor_update(net->factor, s1, s2, c); } - } - - int_t old_num_components = instance->num_components; - - instance->num_components = update_components( - instance->adjacency, instance->marks, old_num_components, s1, s2, 0); - - - if (instance->graph->boundary == TORUS_BOUND) { - if (instance->dual_marks[dv1] == instance->dual_marks[dv2]) { - int **cycles = (int **)malloc(4*instance->graph->ne * sizeof(int *)); - unsigned int num_cycles = find_cycles(instance->graph->ne, instance->fuses, instance->graph->dev, instance->graph->dvei, instance->graph->dve, cycles); - - for (unsigned int i = 0; i < num_cycles; i++) { - int x_num_crossings = 0; - int y_num_crossings = 0; - int ee; unsigned int j = 0; - while ((ee = cycles[2*i][j]) >= 0) { - int side = cycles[2*i+1][j]; - j++; - unsigned int v1, v2; - double v1x, v1y, v2x, v2y; - v1 = instance->graph->dev[2 * ee + !side]; - v2 = instance->graph->dev[2 * ee + side]; - v1x = instance->graph->dvx[2 * v1]; - v1y = instance->graph->dvx[2 * v1 + 1]; - v2x = instance->graph->dvx[2 * v2]; - v2y = instance->graph->dvx[2 * v2 + 1]; - double dx = v1x - v2x; - double dy = v1y - v2y; - if (((v1x > 0.5 && v2x < 0.5) || (v1x < 0.5 && v2x > 0.5)) && fabs(dx) < 0.5) { - x_num_crossings += dx > 0 ? 1 : -1; - } - if (((v1y > 0.5 && v2y < 0.5) || (v1y < 0.5 && v2y > 0.5)) && fabs(dy) < 0.5) { - y_num_crossings += dy > 0 ? 1 : -1; - } - } - if ((abs(y_num_crossings) == 0 && abs(x_num_crossings) > 0) || (abs(y_num_crossings) > 0 && abs(x_num_crossings) > 0 && num_cycles > 1)) { - instance->num_components = 2; - } - free(cycles[2*i]); - free(cycles[2*i+1]); + } else if (net->voltage_bound) { + if (g->bq[v1] || g->bq[v2]) { + uint_t vv = g->bq[v1] ? v2 : v1; + uint_t uu = v1 == vv ? v2 : v1; + if (is_in(g->bi[1], g->b, uu)) { + x[g->bni[vv]] -= 1; + } + if (net->factor != NULL) { + factor_update2(net->factor, g->bni[vv], c); + } + } else { + if (net->factor != NULL) { + factor_update(net->factor, g->bni[s1], g->bni[s2], c); } - free(cycles); - } - } - - { - int_t *lap_p = (int_t *)instance->dual_adjacency->p; - int_t *lap_i = (int_t *)instance->dual_adjacency->i; - double *lap_x = (double *)instance->dual_adjacency->x; - - for (int i = 0; i < lap_p[ds1 + 1] - lap_p[ds1]; i++) { - if (lap_i[lap_p[ds1] + i] == ds2) - lap_x[lap_p[ds1] + i] = 1; } - for (int i = 0; i < lap_p[ds2 + 1] - lap_p[ds2]; i++) { - if (lap_i[lap_p[ds2] + i] == ds1) - lap_x[lap_p[ds2] + i] = 1; + } else { + if (net->factor != NULL) { + factor_update(net->factor, s1, s2, c); } } - set_connected(instance->dual_adjacency, instance->dual_marks, dv1, instance->dual_marks[dv2], -1, 0); - return true; } |