summaryrefslogtreecommitdiff
path: root/src/coursegrain.c
blob: 1e0d5a7bae88905f766fdb1cd1d9809d9e4a12a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include "fracture.h"

net_t *coursegrain_square(net_t *instance, graph_t *network_p, cholmod_common *c) {
	unsigned int width = sqrt(instance->graph->ne);
	assert(width % 4 == 0);

	net_t *instance_p = create_instance(network_p, instance->inf,
																			instance->voltage_bound, true, c);

	unsigned int width_p = width / 2;
	bool *fuses = instance->fuses;

	for (unsigned int i = 0; i < network_p->ne; i++) {
		int xp = i / width_p;
		int yp = i % width_p;
		unsigned int x1 = 2 * xp;
		unsigned int y1 = (2 * yp - 1) % width;
		unsigned int x2 = 2 * xp;
		unsigned int y2 = 2 * yp;
		unsigned int x3 = 2 * xp + 1;
		unsigned int y3 = (2 * yp - 1) % width;
		unsigned int x4 = 2 * xp + 1;
		unsigned int y4 = 2 * yp;
		bool f1 = fuses[width * x1 + y1];
		bool f2 = fuses[width * x2 + y2];
		bool f3 = fuses[width * x3 + y3];
		bool f4 = fuses[width * x4 + y4];

		if ((f1 && f2) || (f3 && f4)) {
			//		instance_p->fuses[i] = true;
			//		instance_p->num_remaining_edges--;
			break_edge(instance_p, i, c);
		}
	}

	// fin_instance(instance_p, c);

	return instance_p;
}