Newer
Older
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "Graph.h"
#include "Match.h"
struct opts Options;
int main(int argc, char **argv) {
struct biparthypergraph HG;
struct contraction C;
long i, j, n, t, v;
int *Matched;
printf("Test FindMatchArbitrary: ");
n= 24; /* must be multiple of 4 */
/* Hypergraph, corresponding to n by n checkerboard matrix
with a(i,j) nonzero if i+j is even */
HG.NrVertices = n;
HG.NrNets = n;
HG.NrPins = n*n/2;
HG.V = (struct vertex *) malloc(HG.NrVertices * sizeof(struct vertex));
HG.N = (struct net *) malloc(HG.NrNets * sizeof(struct net));
HG.VtxAdjncy = (long *) malloc(HG.NrPins * sizeof(long));
HG.NetAdjncy = (long *) malloc(HG.NrPins * sizeof(long));
Matched = (int *) malloc(HG.NrVertices * sizeof(int));
if (HG.V == NULL || HG.N == NULL ||
HG.VtxAdjncy == NULL || HG.NetAdjncy == NULL || Matched == NULL) {
fprintf(stderr, "test_FindMatchArbitrary(): Not enough memory!\n");
printf("Error\n");
exit(1);
}
/* Contraction, at initial stage with no vertices matched yet */
C.NrMatches = 0;
C.MaxNrVertices = n; /* all vertices can end up in the same group */
C.MaxVtxWgt = n/2;
C.Match = (long *) malloc(HG.NrVertices * sizeof(long));
C.Start = (long *) malloc((HG.NrVertices+1) * sizeof(long));
if (C.Match == NULL || C.Start == NULL) {
fprintf(stderr, "test_FindMatchArbitrary(): Not enough memory!\n");
printf("Error\n");
exit(1);
}
C.Start[0] = 0;
/* Initialise vertices */
for (t=0; t<HG.NrVertices; t++) {
HG.V[t].vtxwgt = 1;
HG.V[t].iStart = t*n/2; /* each column has n/2 nonzeros */
HG.V[t].iEnd = (t+1)*n/2;
Matched[t] = FALSE;
}
HG.V[0].vtxwgt = n; /* vertex 0 is very heavy, cannot match */
/* Initialise nets */
for (t=0; t<HG.NrNets; t++) {
HG.N[t].iStartP0 = t*n/2;
HG.N[t].iStartP1 = (t+1)*n/2;
HG.N[t].iEnd = (t+1)*n/2;
}
/* Initialise each adjacency list to 0,2,4,...,n-2 (even rows/columns)
or 1,3,5,...,n-1 (odd rows/columns) */
for (j= 0; j<n; j++) {
for (i=j%2; i<n; i +=2) {
t = j*n/2 + i/2;
HG.VtxAdjncy[t] = i;
}
}
for (i=0; i<n; i++) {
for (j= i%2; j<n; j +=2) {
t = i*n/2 + j/2;
HG.NetAdjncy[t] = j;
}
}
v = n/2;
FindMatchArbitrary(&HG, &C, v, Matched);
/* Check hypergraph dimensions */
if (HG.NrVertices != n ||
HG.NrNets != n ||
HG.NrPins != n*n/2) {
printf("Error\n");
exit(1);
}
/* Check Matched array */
for (j=0; j<HG.NrVertices; j++) {
if (((j%2==0) && j!=0 && (Matched[j] == FALSE)) ||
(j == 0 && Matched[j]) ||
((j%2==1) && Matched[j]) ) {
printf("Error\n");
exit(1);
}
}
/* Check number of matches */
if (C.NrMatches != 1 ||
C.MaxNrVertices != n ||
C.MaxVtxWgt != n/2 ||
C.Start[0] != 0 ||
C.Start[1] != n/2-1) {
printf("Error\n");
exit(1);
}
/* Check matches in contraction */
for (t= C.Start[0]; t < C.Start[1]; t++) {
j = C.Match[t];
if (j == 0 || (j%2==1) || Matched[j] == FALSE) {
printf("Error\n");
exit(1);
}
}
/* Reset all matched vertices */
for (t= C.Start[0]; t < C.Start[1]; t++) {
j = C.Match[t];
Matched[j] = FALSE;
}
/* Check reset Matched array */
for (j=0; j<HG.NrVertices; j++) {
if (Matched[j]) {
printf("Error\n");
exit(1);
}
}
printf("OK\n");
exit(0);
} /* end main */