nysol-take 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/bin/mbiclique.rb +317 -0
  3. data/bin/mbipolish.rb +362 -0
  4. data/bin/mccomp.rb +235 -0
  5. data/bin/mclique.rb +295 -0
  6. data/bin/mclique2g.rb +105 -0
  7. data/bin/mcliqueInfo.rb +203 -0
  8. data/bin/mfriends.rb +202 -0
  9. data/bin/mgdiff.rb +252 -0
  10. data/bin/mhifriend.rb +456 -0
  11. data/bin/mhipolish.rb +465 -0
  12. data/bin/mitemset.rb +168 -0
  13. data/bin/mpal.rb +410 -0
  14. data/bin/mpolishing.rb +399 -0
  15. data/bin/msequence.rb +165 -0
  16. data/bin/mtra2g.rb +476 -0
  17. data/bin/mtra2gc.rb +360 -0
  18. data/ext/grhfilrun/extconf.rb +12 -0
  19. data/ext/grhfilrun/grhfilrun.c +85 -0
  20. data/ext/grhfilrun/src/_sspc.c +358 -0
  21. data/ext/grhfilrun/src/aheap.c +545 -0
  22. data/ext/grhfilrun/src/aheap.h +251 -0
  23. data/ext/grhfilrun/src/base.c +92 -0
  24. data/ext/grhfilrun/src/base.h +59 -0
  25. data/ext/grhfilrun/src/fstar.c +497 -0
  26. data/ext/grhfilrun/src/fstar.h +80 -0
  27. data/ext/grhfilrun/src/grhfil.c +214 -0
  28. data/ext/grhfilrun/src/itemset.c +713 -0
  29. data/ext/grhfilrun/src/itemset.h +170 -0
  30. data/ext/grhfilrun/src/problem.c +415 -0
  31. data/ext/grhfilrun/src/problem.h +179 -0
  32. data/ext/grhfilrun/src/queue.c +533 -0
  33. data/ext/grhfilrun/src/queue.h +182 -0
  34. data/ext/grhfilrun/src/sample.c +19 -0
  35. data/ext/grhfilrun/src/sspc.c +597 -0
  36. data/ext/grhfilrun/src/sspc2.c +491 -0
  37. data/ext/grhfilrun/src/stdlib2.c +1482 -0
  38. data/ext/grhfilrun/src/stdlib2.h +892 -0
  39. data/ext/grhfilrun/src/trsact.c +817 -0
  40. data/ext/grhfilrun/src/trsact.h +160 -0
  41. data/ext/grhfilrun/src/vec.c +745 -0
  42. data/ext/grhfilrun/src/vec.h +172 -0
  43. data/ext/lcmrun/extconf.rb +20 -0
  44. data/ext/lcmrun/lcmrun.cpp +99 -0
  45. data/ext/lcmrun/src/aheap.c +216 -0
  46. data/ext/lcmrun/src/aheap.h +111 -0
  47. data/ext/lcmrun/src/base.c +92 -0
  48. data/ext/lcmrun/src/base.h +59 -0
  49. data/ext/lcmrun/src/itemset.c +496 -0
  50. data/ext/lcmrun/src/itemset.h +157 -0
  51. data/ext/lcmrun/src/lcm.c +427 -0
  52. data/ext/lcmrun/src/problem.c +349 -0
  53. data/ext/lcmrun/src/problem.h +177 -0
  54. data/ext/lcmrun/src/queue.c +528 -0
  55. data/ext/lcmrun/src/queue.h +176 -0
  56. data/ext/lcmrun/src/sgraph.c +359 -0
  57. data/ext/lcmrun/src/sgraph.h +173 -0
  58. data/ext/lcmrun/src/stdlib2.c +1282 -0
  59. data/ext/lcmrun/src/stdlib2.h +823 -0
  60. data/ext/lcmrun/src/trsact.c +747 -0
  61. data/ext/lcmrun/src/trsact.h +159 -0
  62. data/ext/lcmrun/src/vec.c +731 -0
  63. data/ext/lcmrun/src/vec.h +171 -0
  64. data/ext/lcmseq0run/extconf.rb +20 -0
  65. data/ext/lcmseq0run/lcmseq0run.cpp +59 -0
  66. data/ext/lcmseq0run/src/aheap.c +216 -0
  67. data/ext/lcmseq0run/src/aheap.h +111 -0
  68. data/ext/lcmseq0run/src/base.c +92 -0
  69. data/ext/lcmseq0run/src/base.h +59 -0
  70. data/ext/lcmseq0run/src/itemset.c +518 -0
  71. data/ext/lcmseq0run/src/itemset.h +157 -0
  72. data/ext/lcmseq0run/src/itemset_zero.c +522 -0
  73. data/ext/lcmseq0run/src/lcm_seq.c +446 -0
  74. data/ext/lcmseq0run/src/lcm_seq_zero.c +446 -0
  75. data/ext/lcmseq0run/src/problem.c +439 -0
  76. data/ext/lcmseq0run/src/problem.h +179 -0
  77. data/ext/lcmseq0run/src/problem_zero.c +439 -0
  78. data/ext/lcmseq0run/src/queue.c +533 -0
  79. data/ext/lcmseq0run/src/queue.h +182 -0
  80. data/ext/lcmseq0run/src/stdlib2.c +1350 -0
  81. data/ext/lcmseq0run/src/stdlib2.h +864 -0
  82. data/ext/lcmseq0run/src/trsact.c +747 -0
  83. data/ext/lcmseq0run/src/trsact.h +159 -0
  84. data/ext/lcmseq0run/src/vec.c +779 -0
  85. data/ext/lcmseq0run/src/vec.h +172 -0
  86. data/ext/lcmseqrun/extconf.rb +20 -0
  87. data/ext/lcmseqrun/lcmseqrun.cpp +101 -0
  88. data/ext/lcmseqrun/src/aheap.c +216 -0
  89. data/ext/lcmseqrun/src/aheap.h +111 -0
  90. data/ext/lcmseqrun/src/base.c +92 -0
  91. data/ext/lcmseqrun/src/base.h +59 -0
  92. data/ext/lcmseqrun/src/itemset.c +518 -0
  93. data/ext/lcmseqrun/src/itemset.h +157 -0
  94. data/ext/lcmseqrun/src/itemset_zero.c +522 -0
  95. data/ext/lcmseqrun/src/lcm_seq.c +447 -0
  96. data/ext/lcmseqrun/src/lcm_seq_zero.c +446 -0
  97. data/ext/lcmseqrun/src/problem.c +439 -0
  98. data/ext/lcmseqrun/src/problem.h +179 -0
  99. data/ext/lcmseqrun/src/problem_zero.c +439 -0
  100. data/ext/lcmseqrun/src/queue.c +533 -0
  101. data/ext/lcmseqrun/src/queue.h +182 -0
  102. data/ext/lcmseqrun/src/stdlib2.c +1350 -0
  103. data/ext/lcmseqrun/src/stdlib2.h +864 -0
  104. data/ext/lcmseqrun/src/trsact.c +747 -0
  105. data/ext/lcmseqrun/src/trsact.h +159 -0
  106. data/ext/lcmseqrun/src/vec.c +779 -0
  107. data/ext/lcmseqrun/src/vec.h +172 -0
  108. data/ext/lcmtransrun/extconf.rb +18 -0
  109. data/ext/lcmtransrun/lcmtransrun.cpp +264 -0
  110. data/ext/macerun/extconf.rb +20 -0
  111. data/ext/macerun/macerun.cpp +57 -0
  112. data/ext/macerun/src/aheap.c +217 -0
  113. data/ext/macerun/src/aheap.h +112 -0
  114. data/ext/macerun/src/itemset.c +491 -0
  115. data/ext/macerun/src/itemset.h +158 -0
  116. data/ext/macerun/src/mace.c +503 -0
  117. data/ext/macerun/src/problem.c +346 -0
  118. data/ext/macerun/src/problem.h +174 -0
  119. data/ext/macerun/src/queue.c +529 -0
  120. data/ext/macerun/src/queue.h +177 -0
  121. data/ext/macerun/src/sgraph.c +360 -0
  122. data/ext/macerun/src/sgraph.h +174 -0
  123. data/ext/macerun/src/stdlib2.c +993 -0
  124. data/ext/macerun/src/stdlib2.h +811 -0
  125. data/ext/macerun/src/vec.c +634 -0
  126. data/ext/macerun/src/vec.h +170 -0
  127. data/ext/sspcrun/extconf.rb +20 -0
  128. data/ext/sspcrun/src/_sspc.c +358 -0
  129. data/ext/sspcrun/src/aheap.c +545 -0
  130. data/ext/sspcrun/src/aheap.h +251 -0
  131. data/ext/sspcrun/src/base.c +92 -0
  132. data/ext/sspcrun/src/base.h +59 -0
  133. data/ext/sspcrun/src/fstar.c +496 -0
  134. data/ext/sspcrun/src/fstar.h +80 -0
  135. data/ext/sspcrun/src/grhfil.c +213 -0
  136. data/ext/sspcrun/src/itemset.c +713 -0
  137. data/ext/sspcrun/src/itemset.h +170 -0
  138. data/ext/sspcrun/src/problem.c +415 -0
  139. data/ext/sspcrun/src/problem.h +179 -0
  140. data/ext/sspcrun/src/queue.c +533 -0
  141. data/ext/sspcrun/src/queue.h +182 -0
  142. data/ext/sspcrun/src/sample.c +19 -0
  143. data/ext/sspcrun/src/sspc.c +598 -0
  144. data/ext/sspcrun/src/sspc2.c +491 -0
  145. data/ext/sspcrun/src/stdlib2.c +1482 -0
  146. data/ext/sspcrun/src/stdlib2.h +892 -0
  147. data/ext/sspcrun/src/trsact.c +817 -0
  148. data/ext/sspcrun/src/trsact.h +160 -0
  149. data/ext/sspcrun/src/vec.c +745 -0
  150. data/ext/sspcrun/src/vec.h +172 -0
  151. data/ext/sspcrun/sspcrun.cpp +54 -0
  152. data/lib/nysol/enumLcmEp.rb +338 -0
  153. data/lib/nysol/enumLcmEsp.rb +284 -0
  154. data/lib/nysol/enumLcmIs.rb +275 -0
  155. data/lib/nysol/enumLcmSeq.rb +143 -0
  156. data/lib/nysol/items.rb +201 -0
  157. data/lib/nysol/seqDB.rb +256 -0
  158. data/lib/nysol/take.rb +39 -0
  159. data/lib/nysol/taxonomy.rb +113 -0
  160. data/lib/nysol/traDB.rb +257 -0
  161. metadata +239 -0
@@ -0,0 +1,92 @@
1
+ /*
2
+ blocked memory allocation library
3
+ 12/Mar/2002 by Takeaki Uno e-mail:uno@nii.jp,
4
+ homepage: http://research.nii.ac.jp/~uno/index.html */
5
+ /* This program is available for only academic use, basically.
6
+ Anyone can modify this program, but he/she has to write down
7
+ the change of the modification on the top of the source code.
8
+ Neither contact nor appointment to Takeaki Uno is needed.
9
+ If one wants to re-distribute this code, please
10
+ refer the newest code, and show the link to homepage of
11
+ Takeaki Uno, to notify the news about the codes for the users. */
12
+
13
+ #ifndef _base_c_
14
+ #define _base_c_
15
+
16
+ #include"base.h"
17
+
18
+ BASE INIT_BASE = {TYPE_BASE,NULL,0,0,0,0,-1,NULL};
19
+
20
+ /* initialization, and allocate memory for header */
21
+ void BASE_alloc (BASE *B, int unit, int block_siz){
22
+ *B = INIT_BASE;
23
+ B->dellist = B;
24
+ B->unit = unit;
25
+ B->block_siz = block_siz;
26
+ B->num = block_siz;
27
+ B->block_num = -1;
28
+ calloc2 (B->base, 20, EXIT);
29
+ B->block_end = 20;
30
+ }
31
+
32
+ /* termination */
33
+ void BASE_end (BASE *B){
34
+ int i;
35
+ FLOOP (i, 0, B->block_end) free2 (B->base[i]);
36
+ free2 (B->base);
37
+ *B = INIT_BASE;
38
+ }
39
+
40
+ /* return pointer to the cell corresponding to the given index */
41
+ void *BASE_pnt (BASE *B, size_t i){
42
+ return ( B->base[i/BASE_BLOCK] + (i%BASE_BLOCK)*B->unit);
43
+ }
44
+ /* return index corresponding to the given pointer */
45
+ size_t BASE_index (BASE *B, void *x){
46
+ size_t i;
47
+ FLOOP (i, 0, (size_t)(B->block_end+1)){
48
+ if ( ((char*)x)>= B->base[i] && ((char*)x)<=B->base[i]+B->unit*BASE_BLOCK )
49
+ return ( i*BASE_BLOCK + ((size_t)(((char *)x) - B->base[i])) / B->unit);
50
+ }
51
+ return (0);
52
+ }
53
+
54
+ /* increment the current memory block pointer and (re)allcate memory if necessary */
55
+ void *BASE_get_memory (BASE *B, int i){
56
+ B->num += i;
57
+ if ( B->num >= B->block_siz ){ /* if reach to the end of base array */
58
+ B->num = i; /* allocate one more base array, and increment the counter */
59
+ B->block_num++;
60
+ reallocx(B->base, B->block_end, B->block_num, NULL, EXIT0);
61
+ if ( B->base[B->block_num] == NULL )
62
+ malloc2 (B->base[B->block_num], B->block_siz*B->unit, EXIT0);
63
+ return (B->base[B->block_num]);
64
+ }
65
+ return (B->base[B->block_num] + (B->num-i)*B->unit);
66
+ }
67
+
68
+
69
+ /* allocate new cell */
70
+ void *BASE_new (BASE *B){
71
+ char *x;
72
+
73
+ /* use deleted cell if it exists */
74
+ if ( B->dellist != ((void *)B) ){
75
+ x = (char *)B->dellist; /* return the deleted cell */
76
+ B->dellist = (void *)(*((char **)x)); /* increment the head of the list */
77
+ } else {
78
+ /* take a new cell from the base array if no deleted one exists */
79
+ x = (char *)BASE_get_memory (B, 1);
80
+ }
81
+ return (x);
82
+ }
83
+
84
+ /* delete one cell. (add to the deleted list) */
85
+ void BASE_del (BASE *B, void *x){
86
+ *((void **)x) = B->dellist;
87
+ B->dellist = x;
88
+ }
89
+
90
+ #endif
91
+
92
+
@@ -0,0 +1,59 @@
1
+ /*
2
+ blocked memory allocation library
3
+ 12/Mar/2002 by Takeaki Uno e-mail:uno@nii.jp,
4
+ homepage: http://research.nii.ac.jp/~uno/index.html */
5
+ /* This program is available for only academic use, basically.
6
+ Anyone can modify this program, but he/she has to write down
7
+ the change of the modification on the top of the source code.
8
+ Neither contact nor appointment to Takeaki Uno is needed.
9
+ If one wants to re-distribute this code, please
10
+ refer the newest code, and show the link to homepage of
11
+ Takeaki Uno, to notify the news about the codes for the users. */
12
+
13
+
14
+ #ifndef _base_h_
15
+ #define _base_h_
16
+
17
+ #include"stdlib2.h"
18
+
19
+ /* structure for base array */
20
+ #define BASE_UNIT 16
21
+ #define BASE_BLOCK 65536
22
+
23
+ typedef struct {
24
+ unsigned char type;
25
+ char **base;
26
+ int block_siz; // size of one block of memory
27
+ int block_num; // currently using block
28
+ int unit; // size of one unit memory
29
+ int num; // current position in a block
30
+ int block_end; // current end of the block
31
+ void *dellist;
32
+ } BASE;
33
+
34
+ extern BASE INIT_BASE;
35
+
36
+ /* initialization, and allocate memory for header */
37
+ void BASE_alloc (BASE *B, int unit, int block_siz);
38
+
39
+ /* termination */
40
+ void BASE_end (BASE *B);
41
+
42
+ /* return pointer to the cell corresponding to the given index */
43
+ void *BASE_pnt (BASE *B, size_t i);
44
+
45
+ /* return index corresponding to the given pointer */
46
+ size_t BASE_index (BASE *B, void *x);
47
+
48
+ /* increment the current memory block pointer and (re)allcate memory if necessary */
49
+ void *BASE_get_memory (BASE *B, int i);
50
+
51
+ /* allocate new cell */
52
+ void *BASE_new (BASE *B);
53
+
54
+ /* delete one cell. (add to the deleted list) */
55
+ void BASE_del (BASE *B, void *x);
56
+
57
+
58
+ #endif
59
+
@@ -0,0 +1,518 @@
1
+ /* itemset search input/output common routines
2
+ 25/Nov/2007 by Takeaki Uno e-mail:uno@nii.jp,
3
+ homepage: http://research.nii.ac.jp/~uno/index.html */
4
+ /* This program is available for only academic use, basically.
5
+ Anyone can modify this program, but he/she has to write down
6
+ the change of the modification on the top of the source code.
7
+ Neither contact nor appointment to Takeaki Uno is needed.
8
+ If one wants to re-distribute this code, please
9
+ refer the newest code, and show the link to homepage of
10
+ Takeaki Uno, to notify the news about the codes for the users. */
11
+
12
+ /* routines for itemset mining */
13
+
14
+ #ifndef _itemset_c_
15
+ #define _itemset_c_
16
+
17
+ #include"itemset.h"
18
+ #include"queue.c"
19
+ #include"aheap.c"
20
+
21
+ /* flush the write buffer, available for multi-core mode */
22
+ void ITEMSET_flush (ITEMSET *I, FILE2 *fp){
23
+ if ( !(I->flag&ITEMSET_MULTI_OUTPUT) || (fp->buf-fp->buf_org) > FILE2_BUFSIZ/2 ){
24
+ SPIN_LOCK(I->multi_core, I->lock_output);
25
+ FILE2_flush (fp);
26
+ SPIN_UNLOCK(I->multi_core, I->lock_output);
27
+ }
28
+ }
29
+
30
+ /* Output information about ITEMSET structure. flag&1: print frequency constraint */
31
+ void ITEMSET_print (ITEMSET *I, int flag){
32
+ if ( I->lb>0 || I->ub<INTHUGE ){
33
+ if ( I->lb > 0 ) print_err ("%d <= ", I->lb);
34
+ print_err ("itemsets ");
35
+ if ( I->ub < INTHUGE ) print_err (" <= %d\n", I->ub);
36
+ print_err ("\n");
37
+ }
38
+ if ( flag&1 ){
39
+ if ( I->frq_lb > -WEIGHTHUGE ) print_err (WEIGHTF" <=", I->frq_lb);
40
+ print_err (" frequency ");
41
+ if ( I->frq_ub < WEIGHTHUGE ) print_err (" <="WEIGHTF, I->frq_ub);
42
+ print_err ("\n");
43
+ }
44
+ }
45
+
46
+ /* ITEMSET initialization */
47
+ void ITEMSET_init (ITEMSET *I){
48
+ I->flag = 0;
49
+ I->progress = 0;
50
+ I->iters = I->iters2 = I->iters3 = 0;
51
+ I->solutions = I->solutions2 = I->max_solutions = I->outputs = I->outputs2 = 0;
52
+ I->topk.end = 0;
53
+ I->item_max = I->item_max_org = 0;
54
+ I->ub = I->len_ub = I->gap_ub = INTHUGE;
55
+ I->lb = I->len_lb = I->gap_lb = 0;
56
+ I->frq = I->pfrq = I->total_weight = 0;
57
+ I->ratio = I->prob = 0.0;
58
+ I->posi_ub = I->nega_ub = I->frq_ub = WEIGHTHUGE;
59
+ I->posi_lb = I->nega_lb = I->frq_lb = I->setrule_lb = -WEIGHTHUGE;
60
+ I->dir = 0;
61
+ I->target = INTHUGE;
62
+ I->prob_ub = I->ratio_ub = I->rposi_ub = 1;
63
+ I->prob_lb = I->ratio_lb = I->rposi_lb = 0;
64
+ I->itemflag = NULL;
65
+ I->perm = NULL;
66
+ I->item_frq = NULL;
67
+ I->sc = NULL;
68
+ I->X = NULL;
69
+ I->fp = NULL;
70
+ I->separator = ' ';
71
+ I->topk = INIT_AHEAP;
72
+ I->itemset = I->add = INIT_QUEUE;
73
+ I->set_weight = NULL;
74
+ I->set_occ = NULL;
75
+
76
+ I->multi_iters = I->multi_iters2 = I->multi_iters3 = NULL;
77
+ I->multi_outputs = I->multi_outputs2 = NULL;
78
+ I->multi_solutions = I->multi_solutions2 = NULL;
79
+ I->multi_fp = NULL;
80
+
81
+ I->multi_core = 0;
82
+ }
83
+
84
+
85
+ /* second initialization
86
+ topk.end>0 => initialize heap for topk mining */
87
+ /* all pointers will be set to 0, but not for */
88
+ /* if topK mining, set topk.end to "K" */
89
+ void ITEMSET_alloc (ITEMSET *I, char *fname, PERM *perm, QUEUE_INT item_max, size_t item_max_org){
90
+ LONG i;
91
+ size_t siz = (I->flag&ITEMSET_USE_ORG)?item_max_org+2: item_max+2;
92
+ int j;
93
+
94
+ I->prob = I->ratio = 1.0;
95
+ I->frq = 0;
96
+ I->perm = perm;
97
+ if ( I->topk.end>0 ){
98
+ AHEAP_alloc (&I->topk, I->topk.end);
99
+ FLOOP (i, 0, I->topk.end) AHEAP_chg (&I->topk, (AHEAP_ID)i, -WEIGHTHUGE);
100
+ I->frq_lb = -WEIGHTHUGE;
101
+ } else I->topk.v = NULL;
102
+ QUEUE_alloc (&I->itemset, (QUEUE_ID)siz); I->itemset.end = (QUEUE_ID)siz;
103
+ if ( I->flag&ITEMSET_ADD ) QUEUE_alloc (&I->add, (QUEUE_ID)siz);
104
+ calloc2 (I->sc, siz+2, goto ERR);
105
+ if ( I->flag&ITEMSET_SET_RULE ){
106
+ calloc2 (I->set_weight, siz, goto ERR);
107
+ if ( I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT) )
108
+ calloc2 (I->set_occ, siz, goto ERR);
109
+ }
110
+ I->iters = I->iters2 = I->solutions = 0;
111
+ I->item_max = item_max;
112
+ I->item_max_org = (QUEUE_INT)item_max_org;
113
+ if ( fname ){
114
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
115
+ I->fp = (FILE *)1;
116
+ #else
117
+ if ( strcmp (fname, "-") == 0 ) I->fp = stdout;
118
+ else fopen2 (I->fp, fname, (I->flag&ITEMSET_APPEND)?"a":"w", goto ERR);
119
+ #endif
120
+ } else I->fp = 0;
121
+ if ( I->flag&ITEMSET_ITEMFRQ )
122
+ malloc2 (I->item_frq, item_max+2, goto ERR);
123
+ if ( I->flag&ITEMSET_RULE ){
124
+ calloc2 (I->itemflag, item_max+2, goto ERR);
125
+ }
126
+ I->total_weight = 1;
127
+ j = MAX(I->multi_core,1);
128
+ calloc2 (I->multi_iters, j*7, goto ERR);
129
+ I->multi_iters2 = I->multi_iters + j;
130
+ I->multi_iters3 = I->multi_iters2 + j;
131
+ I->multi_outputs = I->multi_iters3 + j;
132
+ I->multi_outputs2 = I->multi_outputs + j;
133
+ I->multi_solutions = I->multi_outputs2 + j;
134
+ I->multi_solutions2 = I->multi_solutions + j;
135
+
136
+ calloc2 (I->multi_fp, j, goto ERR);
137
+ FLOOP (i, 0, j)
138
+ FILE2_open_ (I->multi_fp[i], I->fp, goto ERR);
139
+ #ifdef MULTI_CORE
140
+ if ( I->multi_core > 0 ){
141
+ pthread_spin_init (&I->lock_counter, PTHREAD_PROCESS_PRIVATE);
142
+ pthread_spin_init (&I->lock_sc, PTHREAD_PROCESS_PRIVATE);
143
+ pthread_spin_init (&I->lock_output, PTHREAD_PROCESS_PRIVATE);
144
+ }
145
+ #endif
146
+ return;
147
+ ERR:;
148
+ ITEMSET_end (I);
149
+ EXIT;
150
+ }
151
+
152
+ /* sum the counters computed by each thread */
153
+ void ITEMSET_merge_counters (ITEMSET *I){
154
+ int i;
155
+ FLOOP (i, 0, MAX(I->multi_core,1)){
156
+ I->iters += I->multi_iters[i];
157
+ I->iters2 += I->multi_iters2[i];
158
+ I->iters3 += I->multi_iters3[i];
159
+ I->outputs += I->multi_outputs[i];
160
+ I->outputs2 += I->multi_outputs2[i];
161
+ I->solutions += I->multi_solutions[i];
162
+ I->solutions2 += I->multi_solutions2[i];
163
+ if ( I->multi_fp[i].buf ) FILE2_flush_last (&I->multi_fp[i]);
164
+ }
165
+ ARY_FILL (I->multi_iters, 0, MAX(I->multi_core,1)*7, 0);
166
+ }
167
+
168
+ /*******************************************************************/
169
+ /* termination of ITEMSET */
170
+ /*******************************************************************/
171
+ void ITEMSET_end (ITEMSET *I){
172
+ int i;
173
+ QUEUE_end (&I->itemset);
174
+ QUEUE_end (&I->add);
175
+ AHEAP_end (&I->topk);
176
+ #ifndef _FILE2_LOAD_FROM_MEMORY_
177
+ fclose2 (I->fp);
178
+ #endif
179
+ mfree (I->sc, I->item_frq, I->itemflag, I->perm, I->set_weight, I->set_occ);
180
+
181
+ if ( I->multi_fp )
182
+ FLOOP (i, 0, MAX(I->multi_core,1)) free2 (I->multi_fp[i].buf_org);
183
+ mfree (I->multi_iters, I->multi_fp);
184
+ #ifdef MULTI_CORE
185
+ if ( I->multi_core>0 ){
186
+ pthread_spin_destroy(&I->lock_counter);
187
+ pthread_spin_destroy(&I->lock_sc);
188
+ pthread_spin_destroy(&I->lock_output);
189
+ }
190
+ #endif
191
+ ITEMSET_init (I);
192
+ }
193
+
194
+ /*******************************************************************/
195
+ /* output at the termination of the algorithm */
196
+ /* print #of itemsets of size k, for each k */
197
+ /*******************************************************************/
198
+ void ITEMSET_last_output (ITEMSET *I){
199
+ QUEUE_ID i;
200
+ LONG n=0, nn=0;
201
+
202
+ ITEMSET_merge_counters (I);
203
+ if ( !(I->flag&SHOW_MESSAGE) ) return; // "no message" is specified
204
+ if ( I->topk.end > 0 ){
205
+ i = AHEAP_findmin_head (&I->topk);
206
+ fprint_WEIGHT (stdout, AHEAP_H (I->topk, i));
207
+ printf ("\n");
208
+ return;
209
+ }
210
+ FLOOP (i, 0, I->itemset.end+1){
211
+ n += I->sc[i];
212
+ if ( I->sc[i] != 0 ) nn = i;
213
+ }
214
+ if ( n!=0 ){
215
+ printf (LONGF "\n", n);
216
+ FLOOP (i, 0, nn+1) printf (LONGF "\n", I->sc[i]);
217
+ }
218
+ print_err ("iters=" LONGF, I->iters);
219
+ if ( I->flag&ITEMSET_ITERS2 ) print_err (", iters2=" LONGF, I->iters2);
220
+ print_err ("\n");
221
+ }
222
+
223
+ /* output frequency, coverage */
224
+ void ITEMSET_output_frequency (ITEMSET *I, int core_id){
225
+ FILE2 *fp = &I->multi_fp[core_id];
226
+ if ( I->flag&(ITEMSET_FREQ+ITEMSET_PRE_FREQ) ){
227
+ if ( I->flag&ITEMSET_FREQ ) FILE2_putc (fp, ' ');
228
+ FILE2_print_WEIGHT (fp, I->frq, 4, '(');
229
+ FILE2_putc (fp, ')');
230
+ if ( I->flag&ITEMSET_PRE_FREQ ) FILE2_putc (fp, ' ');
231
+ }
232
+ if ( I->flag&ITEMSET_OUTPUT_POSINEGA ){ // output positive sum, negative sum in the occurrence
233
+ FILE2_putc (fp, ' ');
234
+ FILE2_print_WEIGHT (fp, I->pfrq, 4, '(');
235
+ FILE2_print_WEIGHT (fp, I->pfrq-I->frq, 4, ',');
236
+ FILE2_print_WEIGHT (fp, I->pfrq/(2*I->pfrq-I->frq), 4, ',');
237
+ FILE2_putc (fp, ')');
238
+ }
239
+ }
240
+
241
+ #ifdef _trsact_h_
242
+ void ITEMSET_output_occ (ITEMSET *I, QUEUE *occ, int core_id){
243
+ QUEUE_ID i;
244
+ QUEUE_INT *x;
245
+ FILE2 *fp = &I->multi_fp[core_id];
246
+ TRSACT *TT = (TRSACT *)(I->X);
247
+ VEC_ID j, ee = TT->rows_org;
248
+ int flag = I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT);
249
+
250
+ i=0; MQUE_FLOOP_ (*occ, x, TT->occ_unit){
251
+ if ( (I->flag&ITEMSET_RM_DUP_TRSACT)==0 || *x != ee ){
252
+ FILE2_print_int (fp, TT->trperm? TT->trperm[*x]: *x, I->separator);
253
+ if (flag == ITEMSET_MULTI_OCC_PRINT ){
254
+ FLOOP (j, 1, (VEC_ID)(TT->occ_unit/sizeof(QUEUE_INT)))
255
+ FILE2_print_int (fp, *(x+j), I->separator);
256
+ } else if ( flag == (ITEMSET_MULTI_OCC_PRINT+ITEMSET_TRSACT_ID) ){
257
+ FILE2_print_int (fp, *(x+1), I->separator);
258
+ }
259
+ }
260
+ ee = *x;
261
+ if ( (++i)%256==0 ) ITEMSET_flush (I, fp);
262
+ }
263
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
264
+ *((int *)__write_to_memory__) = INTHUGE;
265
+ __write_to_memory__ = (char *)(((int *)__write_to_memory__) + 1);
266
+ #else
267
+ FILE2_putc (fp, '\n');
268
+ #endif
269
+ }
270
+ #endif
271
+
272
+ /* output an itemset to the output file */
273
+ void ITEMSET_output_itemset (ITEMSET *I, QUEUE *occ, int core_id){
274
+ QUEUE_ID i;
275
+ QUEUE_INT e;
276
+ #ifdef _agraph_h_
277
+ QUEUE_INT ee;
278
+ #endif
279
+
280
+ FILE2 *fp = &I->multi_fp[core_id];
281
+
282
+ I->multi_outputs[core_id]++;
283
+ if ( (I->flag&SHOW_PROGRESS ) && (I->multi_outputs[core_id]%(ITEMSET_INTERVAL) == 0) )
284
+ print_err ("---- " LONGF " solutions in " LONGF " candidates\n",
285
+ I->multi_solutions[core_id], I->multi_outputs[core_id]);
286
+ if ( I->itemset.t < I->lb || I->itemset.t > I->ub ) return;
287
+ if ( (I->flag&ITEMSET_IGNORE_BOUND)==0 && (I->frq < I->frq_lb || I->frq > I->frq_ub) ) return;
288
+ if ( (I->flag&ITEMSET_IGNORE_BOUND)==0 && (I->pfrq < I->posi_lb || I->pfrq > I->posi_ub || (I->frq - I->pfrq) > I->nega_ub || (I->frq - I->pfrq) < I->nega_lb) ) return;
289
+
290
+ I->multi_solutions[core_id]++;
291
+ if ( I->max_solutions>0 && I->multi_solutions[core_id] > I->max_solutions ){
292
+ ITEMSET_last_output (I);
293
+ ERROR_MES = "reached to maximum number of solutions";
294
+ EXIT;
295
+ }
296
+ if ( I->topk.v ){
297
+ e = AHEAP_findmin_head (&(I->topk));
298
+ if ( I->frq > AHEAP_H (I->topk, e) ){
299
+ AHEAP_chg (&(I->topk), e, I->frq);
300
+ e = AHEAP_findmin_head (&(I->topk));
301
+ I->frq_lb = AHEAP_H (I->topk, e);
302
+ }
303
+ } else if ( I->fp ){
304
+ if ( I->flag&ITEMSET_PRE_FREQ ) ITEMSET_output_frequency (I, core_id);
305
+ if ( (I->flag & ITEMSET_NOT_ITEMSET) == 0 ){
306
+ #ifdef _agraph_h_
307
+ if ( I->flag&ITEMSET_OUTPUT_EDGE ){
308
+ FLOOP (i, 0, I->itemset.t){
309
+ e = I->itemset.v[i];
310
+ ee = AGRAPH_INC_FROM(*((AGRAPH *)(I->X)), e, I->dir);
311
+ FILE2_print_int (fp, I->perm? I->perm[ee]: ee, '(' );
312
+ ee = AGRAPH_INC_TO(*((AGRAPH *)(I->X)), e, I->dir);
313
+ FILE2_print_int (fp, I->perm? I->perm[ee]: ee, I->separator);
314
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
315
+ FILE2_putc (fp, ')');
316
+ #endif
317
+ if ( i<I->itemset.t-1 ) FILE2_putc (fp, I->separator);
318
+ if ( (i+1)%256==0 ) ITEMSET_flush (I, fp);
319
+ }
320
+ goto NEXT;
321
+ }
322
+ #endif
323
+ FLOOP (i, 0, I->itemset.t){
324
+ e = I->itemset.v[i];
325
+ FILE2_print_int (fp, I->perm? I->perm[e]: e, i==0? 0: I->separator);
326
+ if ( (i+1)%256==0 ) ITEMSET_flush (I, fp);
327
+ }
328
+ #ifdef _agraph_h_
329
+ NEXT:;
330
+ #endif
331
+ }
332
+ if ( !(I->flag&ITEMSET_PRE_FREQ) ) ITEMSET_output_frequency (I, core_id);
333
+ if ( ((I->flag & ITEMSET_NOT_ITEMSET) == 0) || (I->flag&ITEMSET_FREQ) || (I->flag&ITEMSET_PRE_FREQ) ){
334
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
335
+ FILE2_WRITE_MEMORY (QUEUE_INT, FILE2_LOAD_FROM_MEMORY_END);
336
+ #else
337
+ FILE2_putc (fp, '\n');
338
+ #endif
339
+ }
340
+ #ifdef _trsact_h_
341
+ if (I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT)) ITEMSET_output_occ (I, occ, core_id);
342
+ #endif
343
+ }
344
+ I->sc[I->itemset.t]++;
345
+ ITEMSET_flush (I, fp);
346
+ }
347
+
348
+ /* output itemsets with adding all combination of "add"
349
+ at the first call, i has to be "add->t" */
350
+ void ITEMSET_solution_iter (ITEMSET *I, QUEUE *occ, int core_id){
351
+ QUEUE_ID t=I->add.t;
352
+ if ( I->itemset.t > I->ub ) return;
353
+ ITEMSET_output_itemset (I, occ, core_id);
354
+ if ( ERROR_MES ) return;
355
+ BLOOP (I->add.t, I->add.t, 0){
356
+ QUE_INS (I->itemset, I->add.v[I->add.t]);
357
+ ITEMSET_solution_iter (I, occ, core_id);
358
+ if ( ERROR_MES ) return;
359
+ I->itemset.t--;
360
+ }
361
+ I->add.t = t;
362
+ }
363
+
364
+ void ITEMSET_solution (ITEMSET *I, QUEUE *occ, int core_id){
365
+ QUEUE_ID i;
366
+ LONG s;
367
+ if ( I->itemset.t > I->ub ) return;
368
+ if ( I->flag & ITEMSET_ALL ){
369
+ if ( I->fp || I->topk.v ) ITEMSET_solution_iter (I, occ, core_id);
370
+ else {
371
+ s=1; FLOOP (i, 0, I->add.t+1){
372
+ I->sc[I->itemset.t+i] += s;
373
+ s = s*(I->add.t-i)/(i+1);
374
+ }
375
+ }
376
+ } else {
377
+ FLOOP (i, 0, I->add.t) QUE_INS (I->itemset, I->add.v[i]);
378
+ ITEMSET_output_itemset (I, occ, core_id);
379
+ I->itemset.t -= I->add.t;
380
+ }
381
+ }
382
+
383
+ /*************************************************************************/
384
+ /* ourput a rule */
385
+ /*************************************************************************/
386
+ void ITEMSET_output_rule (ITEMSET *I, QUEUE *occ, double p1, double p2, size_t item, int core_id){
387
+ FILE2 *fp = &I->multi_fp[core_id];
388
+ if ( fp->fp && !(I->topk.v) ){
389
+ FILE2_print_real (fp, p1, 4, '(');
390
+ FILE2_print_real (fp, p2, 4, ',');
391
+ FILE2_putc (fp, ')');
392
+ FILE2_print_int (fp, I->perm[item], I->separator);
393
+ FILE2_puts (fp, " <= ");
394
+ }
395
+ if ( I->flag & ITEMSET_RULE ){
396
+ if ( I->flag & ITEMSET_RULE_ADD ) ITEMSET_solution (I, occ, core_id);
397
+ else ITEMSET_output_itemset (I, occ, core_id);
398
+ } else ITEMSET_solution (I, occ, core_id);
399
+ }
400
+ /*************************************************************************/
401
+ /* check all rules for a pair of itemset and item */
402
+ /*************************************************************************/
403
+ void ITEMSET_check_rule (ITEMSET *I, WEIGHT *w, QUEUE *occ, size_t item, int core_id){
404
+ double p = w[item]/I->frq, pp, ff;
405
+ // printf ("[ratio] %f, p=%f, (%f/ %f), %d(%d) <= ", I->ratio_lb, p, w[item], I->frq, I->perm[item], I->itemflag[item]);
406
+ if ( I->itemflag[item]==1 ) return;
407
+ if ( w[item] <= -WEIGHTHUGE ) p = 0;
408
+ pp = p; ff = I->item_frq[item];
409
+ if ( I->flag & ITEMSET_RULE_SUPP ){ pp = w[item]; ff *= I->total_weight; }
410
+
411
+ if ( I->flag & (ITEMSET_RULE_FRQ+ITEMSET_RULE_INFRQ)){
412
+ if ( (I->flag & ITEMSET_RULE_FRQ) && p < I->ratio_lb ) return;
413
+ if ( (I->flag & ITEMSET_RULE_INFRQ) && p > I->ratio_ub ) return;
414
+ ITEMSET_output_rule (I, occ, p, ff, item, core_id);
415
+ } else if ( I->flag & (ITEMSET_RULE_RFRQ+ITEMSET_RULE_RINFRQ) ){
416
+ if ( (I->flag & ITEMSET_RULE_RFRQ) && (1-p) > I->ratio_lb * (1-I->item_frq[item]) ) return;
417
+ if ( (I->flag & ITEMSET_RULE_RINFRQ) && p > I->ratio_ub * I->item_frq[item] ) return;
418
+ ITEMSET_output_rule (I, occ, pp, ff, item, core_id);
419
+ }
420
+ }
421
+
422
+ /*************************************************************************/
423
+ /* check all rules for an itemset and all items */
424
+ /*************************************************************************/
425
+ void ITEMSET_check_all_rule (ITEMSET *I, WEIGHT *w, QUEUE *occ, QUEUE *jump, WEIGHT total, int core_id){
426
+ QUEUE_ID i, t;
427
+ QUEUE_INT e, f=0, *x;
428
+ WEIGHT d = I->frq/total;
429
+
430
+ // checking out of range for itemset size and (posi/nega) frequency
431
+ if ( I->itemset.t+I->add.t < I->lb || I->itemset.t>I->ub || (!(I->flag&ITEMSET_ALL) && I->itemset.t+I->add.t>I->ub)) return;
432
+ if ( !(I->flag&ITEMSET_IGNORE_BOUND) && (I->frq < I->frq_lb || I->frq > I->frq_ub) ) return;
433
+ if ( !(I->flag&ITEMSET_IGNORE_BOUND) && (I->pfrq < I->posi_lb || I->pfrq > I->posi_ub || (I->frq - I->pfrq) > I->nega_ub || (I->frq - I->pfrq) < I->nega_lb) ) return;
434
+
435
+ if ( I->flag&ITEMSET_SET_RULE ){ // itemset->itemset rule for sequence mining
436
+ FLOOP (i, 0, I->itemset.t-1){
437
+ if ( I->frq/I->set_weight[i] >= I->setrule_lb && I->fp ){
438
+ I->sc[i]++;
439
+ if ( I->flag&ITEMSET_PRE_FREQ ) ITEMSET_output_frequency (I, core_id);
440
+ FLOOP (t, 0, I->itemset.t){
441
+ FILE2_print_int (&I->multi_fp[core_id], I->itemset.v[t], t?I->separator:0);
442
+ if ( t == i ){
443
+ FILE2_putc (&I->multi_fp[core_id], ' ');
444
+ FILE2_putc (&I->multi_fp[core_id], '=');
445
+ FILE2_putc (&I->multi_fp[core_id], '>');
446
+ }
447
+ }
448
+ if ( !(I->flag&ITEMSET_PRE_FREQ) ) ITEMSET_output_frequency ( I, core_id);
449
+ FILE2_putc (&I->multi_fp[core_id], ' ');
450
+ FILE2_print_real (&I->multi_fp[core_id], I->frq/I->set_weight[i], 4, '(');
451
+ FILE2_putc (&I->multi_fp[core_id], ')');
452
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
453
+ FILE2_WRITE_MEMORY (QUEUE_INT, FILE2_LOAD_FROM_MEMORY_END);
454
+ #else
455
+ FILE2_putc (&I->multi_fp[core_id], '\n');
456
+ #endif
457
+ #ifdef _trsact_h_
458
+ if ( I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT) ){
459
+ ITEMSET_output_occ (I, I->set_occ[i], core_id);
460
+ }
461
+ #endif
462
+ ITEMSET_flush (I, &I->multi_fp[core_id]);
463
+ }
464
+ }
465
+ }
466
+ // constraint of relational frequency
467
+ if ( ((I->flag&ITEMSET_RFRQ)==0 || d >= I->prob_lb * I->prob )
468
+ && ((I->flag&ITEMSET_RINFRQ)==0 || d <= I->prob * I->prob_ub) ){
469
+ if ( I->flag&ITEMSET_RULE ){ // rule mining routines
470
+ if ( I->itemset.t == 0 ) return;
471
+ if ( I->target < I->item_max ){
472
+ MQUE_FLOOP (*jump, x){
473
+ if ( *x == I->target ){
474
+ ITEMSET_check_rule (I, w, occ, *x, core_id); if (ERROR_MES) return;
475
+ }
476
+ }
477
+ // ITEMSET_check_rule (I, w, occ, I->target, core_id); if (ERROR_MES) return;
478
+ } else {
479
+ if ( I->flag & (ITEMSET_RULE_FRQ + ITEMSET_RULE_RFRQ) ){
480
+ if ( I->add.t>0 ){
481
+ // if ( I->itemflag[I->add.v[0]] ) // for POSI_EQUISUPP (occ_w[e] may not be 100%, in the case)
482
+ f = I->add.v[I->add.t-1]; t = I->add.t; I->add.t--;
483
+ FLOOP (i, 0, t){
484
+ e = I->add.v[i];
485
+ I->add.v[i] = f;
486
+ ITEMSET_check_rule (I, w, occ, e, core_id); if (ERROR_MES) return;
487
+ I->add.v[i] = e;
488
+ }
489
+ I->add.t++;
490
+ }
491
+ MQUE_FLOOP (*jump, x)
492
+ ITEMSET_check_rule (I, w, occ, *x, core_id); if (ERROR_MES) return;
493
+ } else {
494
+ if ( I->flag & (ITEMSET_RULE_INFRQ + ITEMSET_RULE_RINFRQ) ){
495
+ // ARY_FLOOP ( *jump, i, e ) I->itemflag[e]--;
496
+ FLOOP (i, 0, I->item_max){
497
+ if ( I->itemflag[i] != 1 ){
498
+ ITEMSET_check_rule (I, w, occ, i, core_id); if (ERROR_MES) return;
499
+ }
500
+ }
501
+ // ARY_FLOOP ( *jump, i, e ) I->itemflag[e]++;
502
+ // }
503
+ // ARY_FLOOP ( *jump, i, e ) ITEMSET_check_rule (I, w, occ, e);
504
+ }
505
+ }
506
+ }
507
+ } else { // usual mining (not rule mining)
508
+ if ( I->fp && (I->flag&(ITEMSET_RFRQ+ITEMSET_RINFRQ))){
509
+ FILE2_print_real (&I->multi_fp[core_id], d, 4, '[');
510
+ FILE2_print_real (&I->multi_fp[core_id], I->prob, 4, ',');
511
+ FILE2_putc (&I->multi_fp[core_id], ']');
512
+ }
513
+ ITEMSET_solution (I, occ, core_id);
514
+ }
515
+ }
516
+ }
517
+
518
+ #endif