-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassoc.cc
319 lines (273 loc) · 8.49 KB
/
assoc.cc
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#ifdef __GNUC__
#pragma implementation "Array.h"
#pragma implementation "Util.h"
#pragma implementation "List.h"
#endif
#include <iostream>
#include <fstream>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <unistd.h>
#include <math.h>
#include <fcntl.h> //file io
#include "assoc.h"
#include "eclat.h"
#include "extl2.h"
#include "partition.h"
#include "Graph.h"
#include "Itemset.h"
#include "timetrack.h"
#include "Count.h"
#include "calcdb.h"
//--------------------------------------
#include "stats.h" //MJZ
double Stats::tottime = 0;
int Stats::totcand = 0;
int Stats::totlarge = 0;
Stats stats;
ofstream summary("summary.out", ios::app);
//--------------------------------------
unsigned long int DB_size=0;
unsigned long int total_scan=0;
unsigned long int sumtidlist=0;
struct timeval tp;
char hdataf[300];
char dataf[300];
char idxf[300];
char conf[300];
char it2f[300];
char tempf[300];
boolean ext_l2_pass = FALSE;
boolean use_char_extl2 = FALSE;
boolean use_maximal = FALSE;
boolean use_lb = FALSE;
boolean use_diff = FALSE;
boolean diff_input = FALSE;
boolean use_output = FALSE;
boolean use_diff_f2 = FALSE;
boolean use_horizontal=FALSE;
boolean use_hash=FALSE;
boolean use_hash_map=FALSE;
boolean memflg = FALSE; //compute tot mem usage
int process_order = IN_SUP;
int maxtidlistsz;
ofstream FOUT;
extern CountAry FreCount,CloCount;
Dbase_Ctrl_Blk *DCB=NULL;
//which algorithm to run and parameters
char *alg_name[] = {
#define BFS 0
"bfs",
#define EQC 1
"eqc",
#define SEARCH 2
"search",
NULL
};
boolean sort_ascend = TRUE;
int DBASE_NUM_TRANS;
int DBASE_MAXITEM;
float DBASE_AVG_TRANS_SZ;
int DBASE_MINTRANS; //works only with 1 partition
int DBASE_MAXTRANS;
int MINSUPPORT=-1;
double MINSUP_PER;
long AVAILMEM = 64*MBYTE;
long TOTMEM=0;
Graph *F2Graph;
void parse_args(int argc, char **argv)
{
extern char * optarg;
char *options, *value;
extern int optind;
int c;
sprintf(tempf,"/tmp/tmp");
if (argc < 2)
cout << "usage: getsup -i<infile>\n";
else{
while ((c=getopt(argc,argv,"a:dDce:hH:i:lm:MoS:s:zZ:x:"))!=-1){
switch(c){
case 'a': //which algorithm to run
options = optarg;
//cout << ((ECLAT_eqc)?"eqc=1":"eqc=0") << " " <<
// ((ECLAT_bfs)?"bfs=1":"bfs=0") << " "<<
// ((ECLAT_search==BOTUP)?"bot":"hyb") << endl;
break;
case 'c':
use_char_extl2 = TRUE;
break;
case 'd':
use_diff = TRUE;
break;
case 'D':
diff_input = TRUE;
use_diff = TRUE;
break;
case 'e': //calculate L2 from inverted dbase
num_partitions = atoi(optarg);
ext_l2_pass = TRUE;
break;
case 'h':
use_horizontal = TRUE;
break;
case 'H':
if (atoi(optarg) == 1) use_hash_map = TRUE;
else use_hash = TRUE;
break;
case 'i': //input files
sprintf(dataf,"%s.tpose", optarg);
sprintf(idxf,"%s.idx", optarg);
sprintf(conf,"%s.conf", optarg);
sprintf(it2f,"%s.2it", optarg);
sprintf(hdataf,"%s.data", optarg);
break;
case 'l':
use_diff_f2 = TRUE;
use_diff = TRUE;
break;
case 'm': //amount of mem available
AVAILMEM = (long) atof(optarg)*MBYTE;
break;
case 'M':
memflg = TRUE;
break;
case 'o':
use_output = TRUE;
break;
case 's': //min support
MINSUP_PER = atof(optarg);
break;
case 'S': //min support
MINSUPPORT = atoi(optarg);
break;
case 'z': //sort items in descending order
sort_ascend = FALSE;
break;
case 'Z': //processing order (lex=0, incr=1 (default) ,decr=2)
process_order = atoi(optarg);
break;
case 'x':
sprintf(tempf,"%s",optarg);
break;
}
}
}
if (diff_input) use_diff_f2 = 0;
if (process_order == IN_SUP) sort_ascend = TRUE;
else if (process_order == DE_SUP) sort_ascend = FALSE;
ifstream cfd(conf,ios::in);
if (!cfd){
perror("ERROR: invalid conf file\n");
exit(errno);
}
cfd.read((char *)&DBASE_NUM_TRANS,ITSZ);
if (MINSUPPORT == -1)
MINSUPPORT = (int) (MINSUP_PER*DBASE_NUM_TRANS+0.5);
//ensure that support is at least 2
if (MINSUPPORT < 1) MINSUPPORT = 1;
//cout << "MINSUPPORT " << MINSUPPORT << " " << " " <<
//MINSUP_PER << " " << DBASE_NUM_TRANS << endl;
cfd.read((char *)&DBASE_MAXITEM,ITSZ);
cfd.read((char *)&DBASE_AVG_TRANS_SZ,sizeof(float));
cfd.read((char *)&DBASE_MINTRANS,ITSZ);
cfd.read((char *)&DBASE_MAXTRANS,ITSZ);
//cout << "CONF " << DBASE_NUM_TRANS << " " << DBASE_MAXITEM << " "
//<< DBASE_AVG_TRANS_SZ << endl;
cfd.close();
if (use_horizontal){
diff_input = FALSE; //no diff input
ext_l2_pass = FALSE; //no vertical ext pass
}
if ((use_hash || use_hash_map) && diff_input){
cout << "HASH AND DIFFIN DO NOT WORK!\n";
exit(0);
}
}
int main(int argc, char **argv)
{
TimeTracker tt,tt1;
tt.Start();
int i;
double te,ts;
seconds(ts);
parse_args(argc, argv);
if (use_horizontal) DCB = new Dbase_Ctrl_Blk(hdataf);
else partition_alloc(dataf, idxf);
maxtidlistsz = make_l1_pass(*DCB);
seconds(te);
iterstat *is = new iterstat(DBASE_MAXITEM, 0, te-ts);
stats.add(is);
Itemset::alloc_tmpiset(maxtidlistsz);
if (use_horizontal) Eqclass::alloc_tmpiset(0);
else Eqclass::alloc_tmpiset(maxtidlistsz);
tt1.Start();
make_l2_pass(ext_l2_pass, it2f, *DCB);
double l2time=tt1.Stop();
is = new iterstat(DBASE_MAXITEM*(DBASE_MAXITEM-1)/2,0,l2time);
stats.add(is);
ECLAT_Find_Freq();
seconds(te);
cout << "TOT TIME " << te-ts << endl;
//cout << "LARGE PATTERNS ";
//for (i=0; i < NumLargeItemset.size(); i++)
// cout << " " << NumLargeItemset[i];
// cout << endl;
// cout << "Total elapsed time " << te-ts << endl;
/* fout << "ASSOC ";
if (ECLAT_search == HYBRID) fout << "MAX ";
if (ECLAT_eqc == 1) fout << "ECLAT ";
else fout << "CLIQUE ";
if (ECLAT_bfs == 0) fout << "DFS ";
fout << dataf << " " << MINSUP_PER << " ";
for (i=0; i < NumLargeItemset.size(); i++)
fout << " " << NumLargeItemset[i];
fout << " " << te-ts << endl;
*/
double cputime1 = tt.Stop();
//cout << "NumIntersect=" << Itemset::NumIntersect
// << " DB size:" << DB_size << " total scan:" << total_scan
// << " scan#:" << (float)total_scan/DB_size << endl;
//cout << "cputime=" << cputime1 << " L2Time=" << l2time
// << " CT-L2T=" << cputime1-l2time << endl;
cout << "CHARM ";
if (diff_input) cout << "DIFFIN ";
else if (use_diff) cout << "DIFF ";
if (process_order == IN_SUP) cout << "IN_SUP ";
else if (process_order == DE_SUP) cout << "DE_SUP ";
else cout << "LEX ";
cout << dataf << " " << MINSUP_PER << " " << DBASE_NUM_TRANS
<< " " << MINSUPPORT << endl;
summary << "CHARM ";
if (diff_input) summary << "DIFFIN ";
else if (use_diff_f2) summary << "DIFF2 ";
else if (use_diff) summary << "DIFF ";
if (process_order == IN_SUP) summary << "IN_SUP ";
else if (process_order == DE_SUP) summary << "DE_SUP ";
else summary << "LEX ";
if (use_hash) summary << "USEHASH ";
if (use_hash_map) summary << "USEHASHMAP ";
if (use_horizontal) summary << "HORIZONTAL ";
summary << dataf << " " << MINSUP_PER << " " << DBASE_NUM_TRANS
<< " " << MINSUPPORT << " ";
for (i=0; i < CloCount.ctr()->size(); i++){
stats.setlarge(i,(*CloCount.ctr())[i]);
stats[i]->avgtid /= (*FreCount.ctr())[i];
cout << i+1 << " " << (*CloCount.ctr())[i] << " "
<< (*FreCount.ctr())[i] << flush << endl;
}
stats.tottime = cputime1;
summary << stats << " " << Itemset::NumIntersect << " "
<< DB_size << " " << total_scan << " " << sumtidlist << " "
<< (float)total_scan/DB_size << " " << te-ts << " "<< maxiter;
struct rusage ruse;
getrusage(RUSAGE_SELF,&ruse);
summary << " " << getsec(ruse.ru_utime) << " "
<< getsec(ruse.ru_stime) << endl;
summary.close();
if (use_horizontal) DCB->delete_tidbuf();
else partition_dealloc();
cout << "TOTCLOSED " << stats.totlarge << endl;
exit(0);
}