File matchmtx.c copied from file seqauction.c (similarity 51%) (mode: 100644) (index 6c4e1e7..2eedf95) |
24 |
24 |
#define restrict |
#define restrict |
25 |
25 |
#endif |
#endif |
26 |
26 |
|
|
27 |
|
static int icntl[10]; |
|
28 |
|
void mc64ad_ (int* JOB, |
|
29 |
|
int* N, |
|
30 |
|
int* NE, |
|
31 |
|
int* IP, |
|
32 |
|
int* IRN, |
|
33 |
|
double* A, |
|
34 |
|
int* NUM, |
|
35 |
|
int* CPERM, |
|
36 |
|
int* LIW, |
|
37 |
|
int* IW, |
|
38 |
|
int* LDW, |
|
39 |
|
double* DW, |
|
40 |
|
int* ICNTL, |
|
41 |
|
int* INFO); |
|
42 |
|
|
|
43 |
|
void mc64wd_ (int* n, int* ne, int* ip, int* irn, double* a, |
|
44 |
|
int* iperm, int* num, int* jperm, int* out, |
|
45 |
|
int* pr, int* q, int* L, double* U, double* D); |
|
46 |
|
|
|
47 |
27 |
int |
int |
48 |
28 |
main (int argc, char **argv) |
main (int argc, char **argv) |
49 |
29 |
{ |
{ |
|
... |
... |
main (int argc, char **argv) |
53 |
33 |
struct spcsr_t A; |
struct spcsr_t A; |
54 |
34 |
|
|
55 |
35 |
double mu_min; |
double mu_min; |
|
36 |
|
int relgap = 0; |
56 |
37 |
|
|
57 |
38 |
double *R, *C; |
double *R, *C; |
58 |
39 |
double *expint; |
double *expint; |
|
... |
... |
main (int argc, char **argv) |
81 |
62 |
return -1; |
return -1; |
82 |
63 |
} |
} |
83 |
64 |
|
|
84 |
|
if (argc > 2) { |
|
85 |
|
fout = fopen (argv[2], "wb"); |
|
86 |
|
} |
|
|
65 |
|
mu_min = 1.0 / A.nr; |
|
66 |
|
if (argc > 3) |
|
67 |
|
mu_min = strtod(argv[3], NULL); |
|
68 |
|
if (argc > 4) |
|
69 |
|
relgap = 1; |
87 |
70 |
|
|
88 |
71 |
err = spcsr_load_binfile (f, &A); |
err = spcsr_load_binfile (f, &A); |
89 |
72 |
if (err) { |
if (err) { |
|
... |
... |
main (int argc, char **argv) |
111 |
94 |
spcsr_lascale (&A, R, C); |
spcsr_lascale (&A, R, C); |
112 |
95 |
#endif |
#endif |
113 |
96 |
|
|
114 |
|
#if 1 |
|
|
97 |
|
#if 0 |
115 |
98 |
auction_toexpint (&A, expint); |
auction_toexpint (&A, expint); |
116 |
99 |
#else |
#else |
117 |
100 |
auction_toexp (&A, expint); |
auction_toexp (&A, expint); |
|
... |
... |
main (int argc, char **argv) |
129 |
112 |
printf ("expint max: %g , min %g\n", mx, mn); |
printf ("expint max: %g , min %g\n", mx, mn); |
130 |
113 |
} |
} |
131 |
114 |
|
|
132 |
|
cacheblast(); |
|
133 |
|
|
|
134 |
|
mu_min = 1.0 / A.nr; |
|
135 |
|
/* be approximate */ |
|
136 |
|
/*mu_min = 1.0;*/ |
|
137 |
|
/*mu_min = 100.0 / A.nr;*/ |
|
138 |
|
|
|
139 |
|
#if 0 |
|
140 |
|
{ |
|
141 |
|
int n_unmatched; |
|
142 |
|
double mu_min; |
|
143 |
|
double p, d; |
|
144 |
|
|
|
145 |
|
initialize_timer (&timer); |
|
146 |
|
start_timer (&timer); |
|
147 |
|
n_unmatched = auction_simple (A, expint, match, price, mu_min); |
|
148 |
|
stop_timer (&timer); |
|
149 |
|
auction_eval_primal_mdual (A, expint, match, price, &p, &d); |
|
150 |
|
printf ("* Primal: %20g\n* Dual: %20g\n* Time: %20g\n", p, d, |
|
151 |
|
timer_duration(timer)); |
|
152 |
|
a_printstats (); |
|
153 |
|
} |
|
154 |
|
#endif |
|
155 |
|
|
|
156 |
|
cacheblast(); |
|
157 |
|
|
|
158 |
115 |
memset (match, -1, A.nc * sizeof(int)); |
memset (match, -1, A.nc * sizeof(int)); |
159 |
116 |
memset (price, 0, A.nc * sizeof(double)); |
memset (price, 0, A.nc * sizeof(double)); |
|
117 |
|
|
160 |
118 |
CALLGRIND_START_INSTRUMENTATION(); |
CALLGRIND_START_INSTRUMENTATION(); |
161 |
119 |
initialize_timer (&timer); |
initialize_timer (&timer); |
162 |
120 |
start_timer (&timer); |
start_timer (&timer); |
163 |
|
errflg = auction_scaling (A, expint, match, price, mu_min); |
|
|
121 |
|
errflg = auction_scaling (A, expint, match, price, mu_min, relgap); |
164 |
122 |
stop_timer (&timer); |
stop_timer (&timer); |
165 |
123 |
if (errflg) |
if (errflg) |
166 |
124 |
fprintf (stderr, "Errflg: %d\n", errflg); |
fprintf (stderr, "Errflg: %d\n", errflg); |
167 |
125 |
|
|
168 |
126 |
|
|
|
127 |
|
CALLGRIND_STOP_INSTRUMENTATION(); |
|
128 |
|
|
169 |
129 |
auction_eval_primal_mdual (A, expint, match, price, &auction_primal, &d); |
auction_eval_primal_mdual (A, expint, match, price, &auction_primal, &d); |
170 |
130 |
printf ("Primal: %20g\nDual: %20g\nTime: %20g\nmu_min: %20g\n", |
printf ("Primal: %20g\nDual: %20g\nTime: %20g\nmu_min: %20g\n", |
171 |
131 |
auction_primal, d, timer_duration(timer), mu_min); |
auction_primal, d, timer_duration(timer), mu_min); |
172 |
132 |
|
|
173 |
|
a_printstats(); |
|
174 |
|
|
|
175 |
133 |
{ |
{ |
176 |
134 |
int i, j; |
int i, j; |
177 |
135 |
for (j = 0; j < A.nc; ++j) { |
for (j = 0; j < A.nc; ++j) { |
|
... |
... |
main (int argc, char **argv) |
191 |
149 |
} |
} |
192 |
150 |
} |
} |
193 |
151 |
|
|
194 |
|
if (fout) { |
|
195 |
|
int tag = 1; |
|
196 |
|
fwrite (&tag, sizeof(int), 1, fout); |
|
197 |
|
fwrite (&A.nc, sizeof(int), 1, fout); |
|
198 |
|
fwrite (match, sizeof(int), A.nc, fout); |
|
199 |
|
} |
|
200 |
|
|
|
201 |
|
#if 0 |
|
202 |
|
cacheblast(); |
|
203 |
|
|
|
204 |
|
{ |
|
205 |
|
int n_unmatched; |
|
206 |
|
double mu_min; |
|
207 |
|
double p, d; |
|
208 |
|
|
|
209 |
|
initialize_timer (&timer); |
|
210 |
|
start_timer (&timer); |
|
211 |
|
n_unmatched = auction_scaling_cache (A, expint, match, price, mu_min); |
|
212 |
|
stop_timer (&timer); |
|
213 |
|
auction_eval_primal_mdual (A, expint, match, price, &p, &d); |
|
214 |
|
printf ("_ Primal: %20g\n_ Dual: %20g\n_ Time: %20g\n", p, d, |
|
215 |
|
timer_duration(timer)); |
|
216 |
|
a_printstats (); |
|
217 |
|
} |
|
218 |
|
#endif |
|
219 |
|
|
|
220 |
|
CALLGRIND_STOP_INSTRUMENTATION(); |
|
221 |
|
|
|
222 |
|
cacheblast(); |
|
223 |
|
|
|
224 |
|
/* mc64 */ |
|
225 |
|
{ |
|
226 |
|
int job = 4; /* sum of diag, already log scale */ |
|
227 |
|
int num_on_diag = 0; |
|
228 |
|
int liw; |
|
229 |
|
int *iw; |
|
230 |
|
int ldw; |
|
231 |
|
double *dw; |
|
232 |
|
int info = 0; |
|
233 |
|
|
|
234 |
|
int i, k; |
|
235 |
|
|
|
236 |
|
for (i = 0; i <= A.nr; ++i) |
|
237 |
|
++A.rowoff[i]; |
|
238 |
|
for (k = 0; k < A.nent; ++k) |
|
239 |
|
++A.colind[k]; |
|
240 |
|
|
|
241 |
|
initialize_timer (&timer); |
|
242 |
|
start_timer (&timer); |
|
243 |
|
liw = 5 * A.nr; |
|
244 |
|
iw = malloc (liw * sizeof(int)); |
|
245 |
|
ldw = 2 * A.nr + A.nent; |
|
246 |
|
dw = malloc (ldw * sizeof(double)); |
|
247 |
|
memset (icntl, 0, 10 * sizeof(int)); |
|
248 |
|
icntl[0] = 6; icntl[1] = 6; icntl[2] = -1; |
|
249 |
|
#if !defined(NDEBUG) |
|
250 |
|
icntl[3] = 0; |
|
251 |
|
#else |
|
252 |
|
icntl[3] = -1; |
|
253 |
|
#endif |
|
254 |
|
mc64ad_ (&job, &A.nr, &A.nent, A.rowoff, A.colind, expint, |
|
255 |
|
&num_on_diag, invmatch, &liw, iw, &ldw, dw, icntl, |
|
256 |
|
&info); |
|
257 |
|
free (iw); |
|
258 |
|
free (dw); |
|
259 |
|
stop_timer (&timer); |
|
260 |
|
|
|
261 |
|
for (i = 0; i < A.nr; ++i) --invmatch[i]; |
|
262 |
|
for (i = 0; i <= A.nr; ++i) --A.rowoff[i]; |
|
263 |
|
for (k = 0; k < A.nent; ++k) |
|
264 |
|
--A.colind[k]; |
|
265 |
|
|
|
266 |
|
} |
|
267 |
|
|
|
268 |
|
for (i = 0; i < A.nr; ++i) { |
|
269 |
|
if (invmatch[i] < 0) printf("mc64: row %d is unmatched\n", i); |
|
|
152 |
|
if (argc > 2) { |
|
153 |
|
fout = fopen (argv[2], "wb"); |
270 |
154 |
} |
} |
271 |
155 |
|
|
272 |
|
memset (match, -1, A.nc * sizeof(int)); |
|
273 |
|
for (i = 0; i < A.nr; ++i) { |
|
274 |
|
const int j = invmatch[i]; |
|
275 |
|
match[j] = i; |
|
276 |
|
} |
|
277 |
|
for (j = 0; j < A.nc; ++j) { |
|
278 |
|
if (match[j] < 0) printf("mc64: col %d is unmatched\n", j); |
|
|
156 |
|
if (fout) { |
|
157 |
|
int k; |
|
158 |
|
smut_write_bin_vectors (1, A.nc, price, fout); |
|
159 |
|
for (k = 0; k < A.nc; ++k) { |
|
160 |
|
price[k] = match[k]; |
|
161 |
|
} |
|
162 |
|
smut_write_bin_vectors (1, A.nc, price, fout); |
279 |
163 |
} |
} |
280 |
|
auction_eval_primal_mdual (A, expint, invmatch, price, &mc64_primal, &d); |
|
281 |
|
printf ("mc64 Primal: %20g\nmc64 Time: %20g\n", mc64_primal, |
|
282 |
|
timer_duration(timer)); |
|
283 |
|
printf (" primal diff: %20g\n", auction_primal - mc64_primal); |
|
284 |
164 |
|
|
285 |
165 |
free (price); |
free (price); |
286 |
166 |
free (invmatch); |
free (invmatch); |