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,496 @@
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
+ if ( strcmp (fname, "-") == 0 ) I->fp = stdout;
115
+ else fopen2 (I->fp, fname, (I->flag&ITEMSET_APPEND)?"a":"w", goto ERR);
116
+ } else I->fp = 0;
117
+ if ( I->flag&ITEMSET_ITEMFRQ )
118
+ malloc2 (I->item_frq, item_max+2, goto ERR);
119
+ if ( I->flag&ITEMSET_RULE ){
120
+ calloc2 (I->itemflag, item_max+2, goto ERR);
121
+ }
122
+ I->total_weight = 1;
123
+ j = MAX(I->multi_core,1);
124
+ calloc2 (I->multi_iters, j*7, goto ERR);
125
+ I->multi_iters2 = I->multi_iters + j;
126
+ I->multi_iters3 = I->multi_iters2 + j;
127
+ I->multi_outputs = I->multi_iters3 + j;
128
+ I->multi_outputs2 = I->multi_outputs + j;
129
+ I->multi_solutions = I->multi_outputs2 + j;
130
+ I->multi_solutions2 = I->multi_solutions + j;
131
+
132
+ malloc2 (I->multi_fp, j, goto ERR);
133
+ FLOOP (i, 0, j)
134
+ FILE2_open_ (I->multi_fp[i], I->fp, goto ERR);
135
+ #ifdef MULTI_CORE
136
+ if ( I->multi_core > 0 ){
137
+ pthread_spin_init (&I->lock_counter, PTHREAD_PROCESS_PRIVATE);
138
+ pthread_spin_init (&I->lock_sc, PTHREAD_PROCESS_PRIVATE);
139
+ pthread_spin_init (&I->lock_output, PTHREAD_PROCESS_PRIVATE);
140
+ }
141
+ #endif
142
+ return;
143
+ ERR:;
144
+ ITEMSET_end (I);
145
+ EXIT;
146
+ }
147
+
148
+ /* sum the counters computed by each thread */
149
+ void ITEMSET_merge_counters (ITEMSET *I){
150
+ int i;
151
+ FLOOP (i, 0, MAX(I->multi_core,1)){
152
+ I->iters += I->multi_iters[i];
153
+ I->iters2 += I->multi_iters2[i];
154
+ I->iters3 += I->multi_iters3[i];
155
+ I->outputs += I->multi_outputs[i];
156
+ I->outputs2 += I->multi_outputs2[i];
157
+ I->solutions += I->multi_solutions[i];
158
+ I->solutions2 += I->multi_solutions2[i];
159
+ if ( I->multi_fp[i].buf ) FILE2_flush_last (&I->multi_fp[i]);
160
+ }
161
+ ARY_FILL (I->multi_iters, 0, MAX(I->multi_core,1)*7, 0);
162
+ }
163
+
164
+ /*******************************************************************/
165
+ /* termination of ITEMSET */
166
+ /*******************************************************************/
167
+ void ITEMSET_end (ITEMSET *I){
168
+ int i;
169
+ QUEUE_end (&I->itemset);
170
+ QUEUE_end (&I->add);
171
+ AHEAP_end (&I->topk);
172
+ fclose2 (I->fp);
173
+ mfree (I->sc, I->item_frq, I->itemflag, I->perm, I->set_weight, I->set_occ);
174
+
175
+ if ( I->multi_fp )
176
+ FLOOP (i, 0, MAX(I->multi_core,1)) free2 (I->multi_fp[i].buf);
177
+ mfree (I->multi_iters, I->multi_fp);
178
+ #ifdef MULTI_CORE
179
+ if ( I->multi_core>0 ){
180
+ pthread_spin_destroy(&I->lock_counter);
181
+ pthread_spin_destroy(&I->lock_sc);
182
+ pthread_spin_destroy(&I->lock_output);
183
+ }
184
+ #endif
185
+ ITEMSET_init (I);
186
+ }
187
+
188
+ /*******************************************************************/
189
+ /* output at the termination of the algorithm */
190
+ /* print #of itemsets of size k, for each k */
191
+ /*******************************************************************/
192
+ void ITEMSET_last_output (ITEMSET *I){
193
+ QUEUE_ID i;
194
+ LONG n=0, nn=0;
195
+
196
+ ITEMSET_merge_counters (I);
197
+ if ( !(I->flag&SHOW_MESSAGE) ) return; // "no message" is specified
198
+ if ( I->topk.end > 0 ){
199
+ i = AHEAP_findmin_head (&I->topk);
200
+ fprint_WEIGHT (stdout, AHEAP_H (I->topk, i));
201
+ printf ("\n");
202
+ return;
203
+ }
204
+ FLOOP (i, 0, I->itemset.end+1){
205
+ n += I->sc[i];
206
+ if ( I->sc[i] != 0 ) nn = i;
207
+ }
208
+ if ( n!=0 ){
209
+ printf (LONGF "\n", n);
210
+ FLOOP (i, 0, nn+1) printf (LONGF "\n", I->sc[i]);
211
+ }
212
+ print_err ("iters=" LONGF, I->iters);
213
+ if ( I->flag&ITEMSET_ITERS2 ) print_err (", iters2=" LONGF, I->iters2);
214
+ print_err ("\n");
215
+ }
216
+
217
+ /* output frequency, coverage */
218
+ void ITEMSET_output_frequency (ITEMSET *I, int core_id){
219
+ FILE2 *fp = &I->multi_fp[core_id];
220
+ if ( I->flag&(ITEMSET_FREQ+ITEMSET_PRE_FREQ) ){
221
+ if ( I->flag&ITEMSET_FREQ ) FILE2_putc (fp, ' ');
222
+ FILE2_print_WEIGHT (fp, I->frq, 4, '(');
223
+ FILE2_putc (fp, ')');
224
+ if ( I->flag&ITEMSET_PRE_FREQ ) FILE2_putc (fp, ' ');
225
+ }
226
+ if ( I->flag&ITEMSET_OUTPUT_POSINEGA ){ // output positive sum, negative sum in the occurrence
227
+ FILE2_putc (fp, ' ');
228
+ FILE2_print_WEIGHT (fp, I->pfrq, 4, '(');
229
+ FILE2_print_WEIGHT (fp, I->pfrq-I->frq, 4, ',');
230
+ FILE2_print_WEIGHT (fp, I->pfrq/(2*I->pfrq-I->frq), 4, ',');
231
+ FILE2_putc (fp, ')');
232
+ }
233
+ }
234
+
235
+ #ifdef _trsact_h_
236
+ void ITEMSET_output_occ (ITEMSET *I, QUEUE *occ, int core_id){
237
+ QUEUE_ID i;
238
+ QUEUE_INT *x;
239
+ FILE2 *fp = &I->multi_fp[core_id];
240
+ TRSACT *TT = (TRSACT *)(I->X);
241
+ VEC_ID j, ee = TT->rows_org;
242
+ int flag = I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT);
243
+
244
+ i=0; MQUE_FLOOP_ (*occ, x, TT->occ_unit){
245
+ if ( (I->flag&ITEMSET_RM_DUP_TRSACT)==0 || *x != ee ){
246
+ FILE2_print_int (fp, TT->trperm? TT->trperm[*x]: *x, I->separator);
247
+ if (flag == ITEMSET_MULTI_OCC_PRINT ){
248
+ FLOOP (j, 1, (VEC_ID)(TT->occ_unit/sizeof(QUEUE_INT)))
249
+ FILE2_print_int (fp, *(x+j), I->separator);
250
+ } else if ( flag == (ITEMSET_MULTI_OCC_PRINT+ITEMSET_TRSACT_ID) ){
251
+ FILE2_print_int (fp, *(x+1), I->separator);
252
+ }
253
+ }
254
+ ee = *x;
255
+ if ( (++i)%256==0 ) ITEMSET_flush (I, fp);
256
+ }
257
+ FILE2_putc (fp, '\n');
258
+ }
259
+ #endif
260
+
261
+ /* output an itemset to the output file */
262
+ void ITEMSET_output_itemset (ITEMSET *I, QUEUE *occ, int core_id){
263
+ QUEUE_ID i;
264
+ QUEUE_INT e;
265
+ #ifdef _agraph_h_
266
+ QUEUE_INT ee;
267
+ #endif
268
+
269
+ FILE2 *fp = &I->multi_fp[core_id];
270
+
271
+ I->multi_outputs[core_id]++;
272
+ if ( (I->flag&SHOW_PROGRESS ) && (I->multi_outputs[core_id]%(ITEMSET_INTERVAL) == 0) )
273
+ print_err ("---- " LONGF " solutions in " LONGF " candidates\n",
274
+ I->multi_solutions[core_id], I->multi_outputs[core_id]);
275
+ if ( I->itemset.t < I->lb || I->itemset.t > I->ub ) return;
276
+ if ( (I->flag&ITEMSET_IGNORE_BOUND)==0 && (I->frq < I->frq_lb || I->frq > I->frq_ub) ) return;
277
+ 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;
278
+
279
+ I->multi_solutions[core_id]++;
280
+ if ( I->max_solutions>0 && I->multi_solutions[core_id] > I->max_solutions ){
281
+ ITEMSET_last_output (I);
282
+ ERROR_MES = "reached to maximum number of solutions";
283
+ EXIT;
284
+ }
285
+ if ( I->topk.v ){
286
+ e = AHEAP_findmin_head (&(I->topk));
287
+ if ( I->frq > AHEAP_H (I->topk, e) ){
288
+ AHEAP_chg (&(I->topk), e, I->frq);
289
+ e = AHEAP_findmin_head (&(I->topk));
290
+ I->frq_lb = AHEAP_H (I->topk, e);
291
+ }
292
+ } else if ( I->fp ){
293
+ if ( I->flag&ITEMSET_PRE_FREQ ) ITEMSET_output_frequency (I, core_id);
294
+ if ( (I->flag & ITEMSET_NOT_ITEMSET) == 0 ){
295
+ #ifdef _agraph_h_
296
+ if ( I->flag&ITEMSET_OUTPUT_EDGE ){
297
+ FLOOP (i, 0, I->itemset.t){
298
+ e = I->itemset.v[i];
299
+ ee = AGRAPH_INC_FROM(*((AGRAPH *)(I->X)), e, I->dir);
300
+ FILE2_print_int (fp, I->perm? I->perm[ee]: ee, '(' );
301
+ ee = AGRAPH_INC_TO(*((AGRAPH *)(I->X)), e, I->dir);
302
+ FILE2_print_int (fp, I->perm? I->perm[ee]: ee, I->separator);
303
+ FILE2_putc (fp, ')');
304
+ if ( i<I->itemset.t-1 ) FILE2_putc (fp, I->separator);
305
+ if ( (i+1)%256==0 ) ITEMSET_flush (I, fp);
306
+ }
307
+ goto NEXT;
308
+ }
309
+ #endif
310
+ FLOOP (i, 0, I->itemset.t){
311
+ e = I->itemset.v[i];
312
+ FILE2_print_int (fp, I->perm? I->perm[e]: e, i==0? 0: I->separator);
313
+ if ( (i+1)%256==0 ) ITEMSET_flush (I, fp);
314
+ }
315
+ #ifdef _agraph_h_
316
+ NEXT:;
317
+ #endif
318
+ }
319
+ if ( !(I->flag&ITEMSET_PRE_FREQ) ) ITEMSET_output_frequency (I, core_id);
320
+ if ( ((I->flag & ITEMSET_NOT_ITEMSET) == 0) || (I->flag&ITEMSET_FREQ) || (I->flag&ITEMSET_PRE_FREQ) ) FILE2_putc (fp, '\n');
321
+
322
+ #ifdef _trsact_h_
323
+ if (I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT)) ITEMSET_output_occ (I, occ, core_id);
324
+ #endif
325
+ }
326
+ I->sc[I->itemset.t]++;
327
+ ITEMSET_flush (I, fp);
328
+ }
329
+
330
+ /* output itemsets with adding all combination of "add"
331
+ at the first call, i has to be "add->t" */
332
+ void ITEMSET_solution_iter (ITEMSET *I, QUEUE *occ, int core_id){
333
+ QUEUE_ID t=I->add.t;
334
+ if ( I->itemset.t > I->ub ) return;
335
+ ITEMSET_output_itemset (I, occ, core_id);
336
+ if ( ERROR_MES ) return;
337
+ BLOOP (I->add.t, I->add.t, 0){
338
+ QUE_INS (I->itemset, I->add.v[I->add.t]);
339
+ ITEMSET_solution_iter (I, occ, core_id);
340
+ if ( ERROR_MES ) return;
341
+ I->itemset.t--;
342
+ }
343
+ I->add.t = t;
344
+ }
345
+
346
+ void ITEMSET_solution (ITEMSET *I, QUEUE *occ, int core_id){
347
+ QUEUE_ID i;
348
+ LONG s;
349
+ if ( I->itemset.t > I->ub ) return;
350
+ if ( I->flag & ITEMSET_ALL ){
351
+ if ( I->fp || I->topk.v ) ITEMSET_solution_iter (I, occ, core_id);
352
+ else {
353
+ s=1; FLOOP (i, 0, I->add.t+1){
354
+ I->sc[I->itemset.t+i] += s;
355
+ s = s*(I->add.t-i)/(i+1);
356
+ }
357
+ }
358
+ } else {
359
+ FLOOP (i, 0, I->add.t) QUE_INS (I->itemset, I->add.v[i]);
360
+ ITEMSET_output_itemset (I, occ, core_id);
361
+ I->itemset.t -= I->add.t;
362
+ }
363
+ }
364
+
365
+ /*************************************************************************/
366
+ /* ourput a rule */
367
+ /*************************************************************************/
368
+ void ITEMSET_output_rule (ITEMSET *I, QUEUE *occ, double p1, double p2, size_t item, int core_id){
369
+ FILE2 *fp = &I->multi_fp[core_id];
370
+ if ( fp->fp && !(I->topk.v) ){
371
+ FILE2_print_real (fp, p1, 4, '(');
372
+ FILE2_print_real (fp, p2, 4, ',');
373
+ FILE2_putc (fp, ')');
374
+ FILE2_print_int (fp, I->perm[item], I->separator);
375
+ FILE2_puts (fp, " <= ");
376
+ }
377
+ if ( I->flag & ITEMSET_RULE ){
378
+ if ( I->flag & ITEMSET_RULE_ADD ) ITEMSET_solution (I, occ, core_id);
379
+ else ITEMSET_output_itemset (I, occ, core_id);
380
+ } else ITEMSET_solution (I, occ, core_id);
381
+ }
382
+ /*************************************************************************/
383
+ /* check all rules for a pair of itemset and item */
384
+ /*************************************************************************/
385
+ void ITEMSET_check_rule (ITEMSET *I, WEIGHT *w, QUEUE *occ, size_t item, int core_id){
386
+ double p = w[item]/I->frq, pp, ff;
387
+ // printf ("[ratio] %f, p=%f, (%f/ %f), %d(%d) <= ", I->ratio_lb, p, w[item], I->frq, I->perm[item], I->itemflag[item]);
388
+ if ( I->itemflag[item]==1 ) return;
389
+ if ( w[item] <= -WEIGHTHUGE ) p = 0;
390
+ pp = p; ff = I->item_frq[item];
391
+ if ( I->flag & ITEMSET_RULE_SUPP ){ pp = w[item]; ff *= I->total_weight; }
392
+
393
+ if ( I->flag & (ITEMSET_RULE_FRQ+ITEMSET_RULE_INFRQ)){
394
+ if ( (I->flag & ITEMSET_RULE_FRQ) && p < I->ratio_lb ) return;
395
+ if ( (I->flag & ITEMSET_RULE_INFRQ) && p > I->ratio_ub ) return;
396
+ ITEMSET_output_rule (I, occ, p, ff, item, core_id);
397
+ } else if ( I->flag & (ITEMSET_RULE_RFRQ+ITEMSET_RULE_RINFRQ) ){
398
+ if ( (I->flag & ITEMSET_RULE_RFRQ) && (1-p) > I->ratio_lb * (1-I->item_frq[item]) ) return;
399
+ if ( (I->flag & ITEMSET_RULE_RINFRQ) && p > I->ratio_ub * I->item_frq[item] ) return;
400
+ ITEMSET_output_rule (I, occ, pp, ff, item, core_id);
401
+ }
402
+ }
403
+
404
+ /*************************************************************************/
405
+ /* check all rules for an itemset and all items */
406
+ /*************************************************************************/
407
+ void ITEMSET_check_all_rule (ITEMSET *I, WEIGHT *w, QUEUE *occ, QUEUE *jump, WEIGHT total, int core_id){
408
+ QUEUE_ID i, t;
409
+ QUEUE_INT e, f=0, *x;
410
+ WEIGHT d = I->frq/total;
411
+
412
+ // checking out of range for itemset size and (posi/nega) frequency
413
+ 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;
414
+ if ( !(I->flag&ITEMSET_IGNORE_BOUND) && (I->frq < I->frq_lb || I->frq > I->frq_ub) ) return;
415
+ 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;
416
+
417
+ if ( I->flag&ITEMSET_SET_RULE ){ // itemset->itemset rule for sequence mining
418
+ FLOOP (i, 0, I->itemset.t-1){
419
+ if ( I->frq/I->set_weight[i] >= I->setrule_lb && I->fp ){
420
+ I->sc[i]++;
421
+ if ( I->flag&ITEMSET_PRE_FREQ ) ITEMSET_output_frequency (I, core_id);
422
+ FLOOP (t, 0, I->itemset.t){
423
+ FILE2_print_int (&I->multi_fp[core_id], I->itemset.v[t], t?I->separator:0);
424
+ if ( t == i ){
425
+ FILE2_putc (&I->multi_fp[core_id], ' ');
426
+ FILE2_putc (&I->multi_fp[core_id], '=');
427
+ FILE2_putc (&I->multi_fp[core_id], '>');
428
+ }
429
+ }
430
+ if ( !(I->flag&ITEMSET_PRE_FREQ) ) ITEMSET_output_frequency ( I, core_id);
431
+ FILE2_putc (&I->multi_fp[core_id], ' ');
432
+ FILE2_print_real (&I->multi_fp[core_id], I->frq/I->set_weight[i], 4, '(');
433
+ FILE2_putc (&I->multi_fp[core_id], ')');
434
+ FILE2_putc (&I->multi_fp[core_id], '\n');
435
+ #ifdef _trsact_h_
436
+ if ( I->flag&(ITEMSET_TRSACT_ID+ITEMSET_MULTI_OCC_PRINT) ){
437
+ ITEMSET_output_occ (I, I->set_occ[i], core_id);
438
+ }
439
+ #endif
440
+ ITEMSET_flush (I, &I->multi_fp[core_id]);
441
+ }
442
+ }
443
+ }
444
+ // constraint of relational frequency
445
+ if ( ((I->flag&ITEMSET_RFRQ)==0 || d >= I->prob_lb * I->prob )
446
+ && ((I->flag&ITEMSET_RINFRQ)==0 || d <= I->prob * I->prob_ub) ){
447
+ if ( I->flag&ITEMSET_RULE ){ // rule mining routines
448
+ if ( I->itemset.t == 0 ) return;
449
+ if ( I->target < I->item_max ){
450
+ MQUE_FLOOP (*jump, x){
451
+ if ( *x == I->target ){
452
+ ITEMSET_check_rule (I, w, occ, *x, core_id); if (ERROR_MES) return;
453
+ }
454
+ }
455
+ // ITEMSET_check_rule (I, w, occ, I->target, core_id); if (ERROR_MES) return;
456
+ } else {
457
+ if ( I->flag & (ITEMSET_RULE_FRQ + ITEMSET_RULE_RFRQ) ){
458
+ if ( I->add.t>0 ){
459
+ // if ( I->itemflag[I->add.v[0]] ) // for POSI_EQUISUPP (occ_w[e] may not be 100%, in the case)
460
+ f = I->add.v[I->add.t-1]; t = I->add.t; I->add.t--;
461
+ FLOOP (i, 0, t){
462
+ e = I->add.v[i];
463
+ I->add.v[i] = f;
464
+ ITEMSET_check_rule (I, w, occ, e, core_id); if (ERROR_MES) return;
465
+ I->add.v[i] = e;
466
+ }
467
+ I->add.t++;
468
+ }
469
+ MQUE_FLOOP (*jump, x)
470
+ ITEMSET_check_rule (I, w, occ, *x, core_id); if (ERROR_MES) return;
471
+ } else {
472
+ if ( I->flag & (ITEMSET_RULE_INFRQ + ITEMSET_RULE_RINFRQ) ){
473
+ // ARY_FLOOP ( *jump, i, e ) I->itemflag[e]--;
474
+ FLOOP (i, 0, I->item_max){
475
+ if ( I->itemflag[i] != 1 ){
476
+ ITEMSET_check_rule (I, w, occ, i, core_id); if (ERROR_MES) return;
477
+ }
478
+ }
479
+ // ARY_FLOOP ( *jump, i, e ) I->itemflag[e]++;
480
+ // }
481
+ // ARY_FLOOP ( *jump, i, e ) ITEMSET_check_rule (I, w, occ, e);
482
+ }
483
+ }
484
+ }
485
+ } else { // usual mining (not rule mining)
486
+ if ( I->fp && (I->flag&(ITEMSET_RFRQ+ITEMSET_RINFRQ))){
487
+ FILE2_print_real (&I->multi_fp[core_id], d, 4, '[');
488
+ FILE2_print_real (&I->multi_fp[core_id], I->prob, 4, ',');
489
+ FILE2_putc (&I->multi_fp[core_id], ']');
490
+ }
491
+ ITEMSET_solution (I, occ, core_id);
492
+ }
493
+ }
494
+ }
495
+
496
+ #endif