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
139
140
141
142
143
144
145
146
147
148
149
150
151
#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, *Visited, *Inprod;
int *Matched;
double *ScInprod;
printf("Test FindMatchInprod: ");
n= 40;
/* Hypergraph, corresponding to n by n upper triangular matrix */
HG.NrVertices = n;
HG.NrNets = n;
HG.NrPins = n*(n+1)/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));
Inprod = (long *) malloc(HG.NrVertices * sizeof(long));
Visited = (long *) malloc(HG.NrVertices * sizeof(long));
ScInprod = (double *) malloc(HG.NrVertices * sizeof(double));
if (HG.V == NULL || HG.N == NULL ||
HG.VtxAdjncy == NULL || HG.NetAdjncy == NULL || Matched == NULL ||
Inprod == NULL || Visited == NULL || ScInprod == NULL) {
fprintf(stderr, "test_FindMatchInprod(): Not enough memory!\n");
printf("Error\n");
exit(1);
}
/* Contraction, at initial stage with no vertices matched yet */
C.NrMatches = 0;
C.MaxNrVertices = 2; /* pairwise matching */
C.MaxVtxWgt = n*n; /* no limit on weight */
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_FindMatchInprod(): 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 = t+1;
HG.V[t].iStart = t*(t+1)/2; /* 1+2+3+...+t */
HG.V[t].iEnd = (t+1)*(t+2)/2;
Matched[t] = FALSE;
}
/* Initialise nets */
for (t=0; t<HG.NrNets; t++) {
HG.N[t].iStartP0 = t*n - (t-1)*t/2; /* n+(n-1)+...+(n-t+1) */
HG.N[t].iStartP1 = (t+1)*n - t*(t+1)/2; /* n+(n-1)+...+(n-t) */
HG.N[t].iEnd = (t+1)*n - t*(t+1)/2;
}
/* Initialise each vertex adjacency list j to 0, 1, 2, 3, ..., j */
for (j= 0; j<n; j++) {
for (i=0; i<=j; i++) {
t = j*(j+1)/2 + i;
HG.VtxAdjncy[t] = i;
}
}
/* Initialise each net adjacency list i to i, i+1, ..., n-1 */
for (i=0; i<n; i++) {
for (j=i; j<n; j++) {
t = i*n - (i-1)*i/2 + j-i;
HG.NetAdjncy[t] = j;
}
}
/* Initialise Inprod and ScInprod */
for (j= 0; j<n; j++) {
Inprod[j] = 0;
ScInprod[j] = 0;
}
Options.Coarsening_NetScaling = NoNetScaling;
Options.Coarsening_MatchIdenticalFirst = MatchIdYes;
Options.Coarsening_InprodScaling = IpSclCos;
v = n-2;
FindMatchInprod(&HG, &C, v, Matched, Visited, Inprod, ScInprod, &Options);
/* Check hypergraph dimensions */
if (HG.NrVertices != n ||
HG.NrNets != n ||
HG.NrPins != n*(n+1)/2) {
printf("Error\n");
exit(1);
}
/* Check Matched, Inprod, ScInprod arrays */
for (j=0; j<HG.NrVertices; j++) {
if (((j >= n-2) && (Matched[j] == FALSE)) ||
(j < n-2 && Matched[j]) ||
Inprod[j] != 0 || ScInprod[j] != 0) {
printf("Error\n");
exit(1);
}
}
/* Check number of matches */
if (C.NrMatches != 1 ||
C.MaxNrVertices != 2 ||
C.MaxVtxWgt != n*n ||
C.Start[0] != 0 ||
C.Start[1] != 2) {
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 < n-2 || 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 */