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,503 @@
1
+ /* MACE: MAximal Clique Enumerater */
2
+ /* ver 1.0 1/Sep/2005 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, do not forget to
9
+ refer the newest code, and show the link to homepage of
10
+ Takeaki Uno, to notify the news about this code for the users.
11
+ For the commercial use, please make a contact to Takeaki Uno. */
12
+
13
+
14
+ #ifndef _mace_c_
15
+ #define _mace_c_
16
+
17
+ #define WEIGHT_DOUBLE
18
+
19
+ #include"sgraph.c"
20
+ #include"problem.c"
21
+
22
+ #define VBMMARK_MAX 16 /* MAXsize of BITMAP */
23
+ #define VBMINT unsigned long /* variable type for BITMAP */
24
+ #define VBMINT_MAX 30 /* MAXsize of BITMAP */
25
+
26
+ typedef struct {
27
+ VBMINT *edge; /* BITMAP representation w.r.t. columns of vertices in the current clique */
28
+ VBMINT *set, *reset; /* array for BITMASKs */
29
+ int *pos; /* positions of vertices of the clique in the bitmap */
30
+ QUEUE dellist;
31
+ char *mark;
32
+ int mark_max;
33
+ } MACEVBM;
34
+
35
+ //int **PP->shift; /* pointers to the positions of the current processing items in each transaction */
36
+
37
+
38
+ void MACE_error (){
39
+ ERROR_MES = "command explanation";
40
+ print_err ("mace MCqVe [options] input-filename [output-filename]\n\
41
+ %%:show progress, _:no message, +:write solutions in append mode\n\
42
+ C:enumerate cliques, M:enumerate maximal cliques, e:edge_list format\n\
43
+ [options]\n\
44
+ -l [num]:output cliques with size at least [num]\n\
45
+ -u [num]:output cliques with size at most [num]\n\
46
+ -S [num]:stop after outputting [num] solutions\n\
47
+ -, [char]:give the separator of the numbers in the output\n\
48
+ -Q [filename]:replace the output numbers according to the permutation table given by [filename]\n\
49
+ if the 1st letter of input-filename is '-', be considered as 'parameter list'\n");
50
+ EXIT;
51
+ }
52
+
53
+
54
+ /***************************************************/
55
+ /* read parameters from command line */
56
+ /***************************************************/
57
+ void MACE_read_param (int argc, char *argv[], PROBLEM *PP){
58
+ ITEMSET *II=&PP->II;
59
+ int c=1;
60
+ if ( argc < c+2 ){ MACE_error (); return; }
61
+
62
+ if ( !strchr (argv[c], '_') ){ II->flag |= SHOW_MESSAGE; PP->SG.flag |= SHOW_MESSAGE; }
63
+ if ( strchr (argv[c], '%') ) II->flag |= SHOW_PROGRESS;
64
+ if ( strchr (argv[c], '+') ) II->flag |= ITEMSET_APPEND;
65
+ if ( strchr (argv[c], 'M') ) PP->problem = PROBLEM_MAXIMAL;
66
+ else if ( strchr (argv[c], 'C') ) PP->problem = PROBLEM_FREQSET;
67
+ else error ("M or C command has to be specified", EXIT);
68
+ if ( strchr (argv[c], 'e') ) PP->SG.flag |= LOAD_ELE;
69
+ c++;
70
+
71
+ while ( argv[c][0] == '-' ){
72
+ switch (argv[c][1]){
73
+ case 'l': II->lb = atoi (argv[c+1]);
74
+ break; case 'u': II->ub = atoi (argv[c+1]);
75
+ break; case 'w': PP->weight_fname = argv[c+1];
76
+ break; case '#': II->max_solutions = atoi(argv[c+1]);
77
+ break; case ',': II->separator = argv[c+1][0];
78
+ break; case 'Q': PP->outperm_fname = argv[c+1];
79
+ break; default: goto NEXT;
80
+ }
81
+ c += 2;
82
+ if ( argc < c+1 ){ MACE_error (); return; }
83
+ }
84
+
85
+ NEXT:;
86
+ PP->SG.fname = argv[c];
87
+ if ( argc>c+1 ) PP->output_fname = argv[c+1];
88
+ }
89
+
90
+
91
+
92
+ /***************************************************/
93
+ /* initialization */
94
+ /***************************************************/
95
+ void MACE_init (PROBLEM *PP, MACEVBM *VV){
96
+ SGRAPH *G = &PP->SG;
97
+ QUEUE_INT i;
98
+ VBMINT p;
99
+
100
+ PP->II.flag |= ITEMSET_ADD;
101
+ G->flag |= LOAD_INCSORT + LOAD_RM_DUP + LOAD_EDGE;
102
+ PROBLEM_load (PP); if (ERROR_MES) return;
103
+ PROBLEM_alloc (PP, G->edge.t, G->edge.t, G->edge.eles, NULL, PROBLEM_ITEMJUMP + PROBLEM_ITEMCAND + PROBLEM_SHIFT + PROBLEM_OCC_T);
104
+ SGRAPH_rm_selfloop (G);
105
+ FLOOP (i, 0, G->edge.t) G->edge.v[i].v[G->edge.v[i].t] = G->edge.t;
106
+
107
+ // delivery
108
+ QUEUE_delivery (NULL, PP->occ_t, NULL, G->edge.v, NULL, G->edge.t, G->edge.t);
109
+ MQUE_ALLOC (PP->OQ, G->edge.t, PP->occ_t, 0, 2, EXIT);
110
+
111
+ if ( PP->problem & PROBLEM_CLOSED ){
112
+ VV->edge = VV->set = VV->reset = NULL; VV->pos = NULL; VV->dellist.v = NULL;
113
+ malloc2 (VV->edge, G->edge.t, goto ERR);
114
+ malloc2 (VV->pos, G->edge.t, goto ERR);
115
+ malloc2 (VV->set, VBMINT_MAX, goto ERR);
116
+ malloc2 (VV->reset, VBMINT_MAX, goto ERR);
117
+ QUEUE_alloc (&VV->dellist, VBMINT_MAX+2);
118
+ if ( ERROR_MES ) goto ERR;
119
+ VV->dellist.t = VBMINT_MAX;
120
+ ARY_FILL (VV->edge, 0, G->edge.t, 0);
121
+ for (i=0,p=1 ; i<VBMINT_MAX ; i++,p*=2){
122
+ VV->set[i] = p;
123
+ // VV->reset[i] = 0xffffffff-p;
124
+ VV->reset[i] = -1-p;
125
+ VV->dellist.v[i] = i;
126
+ }
127
+ // for (i=1,MACEVBM_mark_max=1 ; i<VBMMARK_MAX ; i++ ) MACEVBM_mark_max*=2;
128
+ // malloc2 (MACEVBM_mark, char, MACEVBM_mark_max, "MACE_init:MACEVBM_mark");
129
+ // for (i=0 ; i<MACEVBM_mark_max ; i++) MACEVBM_mark[i] = 0;
130
+ }
131
+ return;
132
+ ERR:;
133
+ QUEUE_end (&VV->dellist);
134
+ free2 (VV->edge);
135
+ free2 (VV->pos);
136
+ free2 (VV->set);
137
+ free2 (VV->reset);
138
+ }
139
+
140
+
141
+ /******************************************************************/
142
+ /* iteration of clique enumeration */
143
+ /******************************************************************/
144
+ void MACEclq_iter (PROBLEM *PP, QUEUE_INT v, QUEUE *occ){
145
+ SGRAPH *G=&PP->SG;
146
+ ITEMSET *II=&PP->II;
147
+ QUEUE_INT *x, *xx, *y;
148
+ QUEUE *Q = PP->OQ;
149
+
150
+ ARY_INS (II->itemset, v);
151
+ ITEMSET_output_itemset (II, NULL, 0);
152
+ if ( II->itemset.t >= II->ub ) goto END; // upper bound of clique
153
+
154
+ MLOOP (y, occ->v, v){
155
+ xx = G->edge.v[*y].v;
156
+ MLOOP (x, occ->v, G->edge.t){
157
+ while ( *x > *xx ) xx++;
158
+ if ( *x == *xx ) ARY_INS (Q[*y], *x);
159
+ }
160
+ ARY_INS (Q[*y], G->edge.t);
161
+ MACEclq_iter (PP, *y, &Q[*y]);
162
+ Q[*y].t = 0;
163
+ }
164
+ END:;
165
+ II->itemset.t--;
166
+ }
167
+
168
+
169
+ /******************************************************************/
170
+ /******************************************************************/
171
+ /******************************************************************/
172
+
173
+ /******************************************************************/
174
+ /* bitmap routines */
175
+ /******************************************************************/
176
+ void MACEVBM_set_vertex (SGRAPH *G, QUEUE_INT v, MACEVBM *VV){
177
+ QUEUE_INT *x;
178
+ VBMINT p;
179
+ VV->pos[v] =QUEUE_ext_tail_ (&VV->dellist);
180
+ p = VV->set[VV->pos[v]];
181
+ MLOOP (x, G->edge.v[v].v, G->edge.t) VV->edge[*x] |= p;
182
+ }
183
+ void MACEVBM_reset_vertex (SGRAPH *G, QUEUE_INT v, MACEVBM *VV){
184
+ QUEUE_INT *x;
185
+ VBMINT p;
186
+ ARY_INS (VV->dellist, VV->pos[v]);
187
+ p = VV->reset[VV->pos[v]];
188
+ MLOOP (x, G->edge.v[v].v, G->edge.t) VV->edge[*x] &= p;
189
+ }
190
+ void MACEVBM_set_diff_vertexes (SGRAPH *G, QUEUE *K1, QUEUE *K2, MACEVBM *VV ){
191
+ QUEUE_INT *x, *y = K2->v;
192
+ MQUE_FLOOP (*K1, x){
193
+ if ( *x == *y ) y++;
194
+ else MACEVBM_set_vertex (G, *x, VV);
195
+ }
196
+ }
197
+ void MACEVBM_reset_diff_vertexes (SGRAPH *G, QUEUE *K1, QUEUE *K2, MACEVBM *VV){
198
+ QUEUE_INT *x, *y = K2->v;
199
+ MQUE_FLOOP (*K1, x){
200
+ if ( *x == *y ) y = y-K2->v<K2->t-1? y+1: y;
201
+ else MACEVBM_reset_vertex (G, *x, VV);
202
+ }
203
+ }
204
+
205
+
206
+ /******************************************************************/
207
+ /* add a vertex v to clique K */
208
+ /******************************************************************/
209
+ void MACE_add_vertex (SGRAPH *G, PROBLEM *PP, QUEUE *K, QUEUE_INT v, MACEVBM *VV){
210
+ ARY_INS (*K, v);
211
+ if ( PP->problem & PROBLEM_CLOSED ){
212
+ if ( K->t > VBMINT_MAX ) PP->problem -= PROBLEM_CLOSED;
213
+ else MACEVBM_set_vertex (G, v, VV);
214
+ }
215
+ }
216
+
217
+ /******************************************************************/
218
+ /* add a vertex v to clique K */
219
+ /******************************************************************/
220
+ void MACE_scan_vertex_list (SGRAPH *G, PROBLEM *PP, QUEUE_INT v, QUEUE_INT w){
221
+ QUEUE_INT *xx;
222
+ MQUE_MLOOP (G->edge.v[v], xx, w){
223
+ if ( PP->OQ[*xx].t == 0 ) ARY_INS (PP->itemcand, *xx);
224
+ ARY_INS (PP->OQ[*xx], v);
225
+ }
226
+ }
227
+
228
+ /* K := lex. muximum maximal clique including K (w.r.t. vertices <w ) */
229
+ /* MACE_occ[v] := N(v) \cap K */
230
+ void MACE_extend (SGRAPH *G, PROBLEM *PP, QUEUE *K, QUEUE_INT w, MACEVBM *VV){
231
+ QUEUE_INT *x, v;
232
+
233
+ MQUE_FLOOP (*K, x) MACE_scan_vertex_list (G, PP, *x, w);
234
+ v = K->v[0];
235
+ MQUE_MLOOP (G->edge.v[v], x, w);
236
+ // x := position of vertex w in the list Q[v(= head of K)]
237
+ for (x-- ; x>=G->edge.v[v].v ; x--){
238
+ if ( PP->OQ[*x].t == K->t ){
239
+ MACE_scan_vertex_list (G, PP, *x, *x);
240
+ MACE_add_vertex (G, PP, K, *x, VV);
241
+ }
242
+ }
243
+ }
244
+
245
+ /****************************************************************/
246
+ /* check the maximality of K\cap N(w) (=MACE_occ[w]),
247
+ and whether the parent of C(K\cap N(w)) = K or not. */
248
+ /****************************************************************/
249
+ LONG MACE_parent_check (SGRAPH *G, PROBLEM *PP, QUEUE *K, QUEUE *ad, QUEUE *Q, QUEUE_INT w){
250
+ QUEUE_INT j=0, e, i, flag =1;
251
+ QUEUE_INT v=Q[w].v[0], *y = G->edge.v[w].v + G->edge.v[w].t-1, *x, *zz=Q[w].v, *Z;
252
+ ad->t = 0;
253
+ K->v[K->t] = -1; // loop stopper
254
+
255
+ FLOOP (i, 0, Q[w].t){
256
+ e = Q[w].v[i];
257
+ // pointers to the positions of the current processing items in each transaction
258
+ PP->shift[i] = G->edge.v[e].v+G->edge.v[e].t-1;
259
+ }
260
+ for (x=G->edge.v[v].v + G->edge.v[v].t-1 ; *x>w ; x--){
261
+ if ( *x <= (e=K->v[j]) ){ // skip if *x \in K (or w<*x)
262
+ if ( *zz == e ) zz++;
263
+ else { // insert *x to Qad if *x is not in K\cap N(w)
264
+ PP->shift[Q[w].t + ad->t] = G->edge.v[e].v + G->edge.v[e].t-1-j;
265
+ ARY_INS (*ad, e);
266
+ }
267
+ if ( *x < e ) x++;
268
+ j++;
269
+ continue;
270
+ }
271
+ i = 0;
272
+ while (1){ // check *x is adjacent to all vertices in K\cap N(w) or not, one-by-one. if not, then break the loop
273
+ while ( *PP->shift[i]>*x ) PP->shift[i]--;
274
+ if ( *PP->shift[i] < *x ) goto LOOP_END;
275
+ i++;
276
+ if ( i== Q[w].t ){ // if *x is adjacent to all
277
+ if ( y<G->edge.v[w].v ) goto NEXT;
278
+ while ( *y>*x ){
279
+ if ( --y < G->edge.v[w].v ) goto NEXT;
280
+ }
281
+ if ( *y==*x ) return (*x); //if *x is adjacent to w, then not maximal
282
+ break;
283
+ }
284
+ }
285
+ NEXT:;
286
+ while (flag){ // check *x is adjacent to all vertices in K_{\le w}. If not, then break the loop
287
+ if ( i== Q[w].t + ad->t ) return (*x); // if *x is adjacent to all, MACE_occ[w] is not a child
288
+ Z = G->edge.v[ad->v[i-Q[w].t]].v;
289
+ while ( *PP->shift[i]>*x ){
290
+ PP->shift[i]--;
291
+ if ( PP->shift[i] < Z ){ flag = 0; goto LOOP_END; } // reached to the end of the adjacency list of the i-th added vertex, thus no further vertex can be pass this check, and set flag to 0 not to come here again.
292
+ }
293
+ if ( *PP->shift[i] < *x ) goto LOOP_END;
294
+ i++;
295
+ }
296
+ LOOP_END:;
297
+ }
298
+ return (-1);
299
+ }
300
+
301
+ /****************************************************************/
302
+ /* check the maximality of K\cap N(w) (=MACE_occ[w]),
303
+ ad whether the parent of C(K\cap N(w)) = K or not. */
304
+ /* BITMAP version */
305
+ /****************************************************************/
306
+ LONG MACEVBM_parent_check (SGRAPH *G, QUEUE *K, QUEUE *Q, QUEUE_INT w, MACEVBM *VV){
307
+ QUEUE_INT v=Q[w].v[0];
308
+ QUEUE_ID i;
309
+ VBMINT p=0, pp;
310
+ QUEUE_INT *y = G->edge.v[w].v + G->edge.v[w].t-1, *x, *z=K->v;
311
+ K->v[K->t] = -1; // loop stopper
312
+ FLOOP (i, 0, Q[w].t) p |= VV->set[VV->pos[Q[w].v[i]]];
313
+ pp = p;
314
+ for (x=G->edge.v[v].v + G->edge.v[v].t-1 ; *x>w ; x--){
315
+ while ( *x < *z ){ pp |= VV->set[VV->pos[*z]]; z++; }
316
+ // if ( *z>=0 ) pp |= VV->set[VV->pos[*z]];
317
+
318
+ if ( *x == *z ){ pp |= VV->set[VV->pos[*z]]; z++; continue; }
319
+ if ( pp==(pp&VV->edge[*x]) ) return (*x); // parentness
320
+
321
+ if ( p == (p & VV->edge[*x]) ){ // maximality w.r.t P\cap N(w) (=occ[w])
322
+ if ( y<G->edge.v[w].v ) goto NEXT;
323
+ while ( *x < *y ){ // check *x is incident to w?
324
+ y--;
325
+ if ( y<G->edge.v[w].v ) goto NEXT;
326
+ }
327
+ if ( *x==*y ) return (*x); // if *x is incident to w, parent is different.
328
+ }
329
+ NEXT:;
330
+ }
331
+ return (-1);
332
+ }
333
+
334
+ /*************************************************************************/
335
+ /* simple routine for checking the maximality of a clique,
336
+ and parent-child relation, for debugging */
337
+ /*************************************************************************/
338
+ LONG MACE_parent_check_max (SGRAPH *G, QUEUE *K, QUEUE *ad, QUEUE *Q, QUEUE_INT w){
339
+ QUEUE_INT *x;
340
+ QUEUE_cpy (ad, &G->edge.v[w]);
341
+ MQUE_FLOOP (Q[w], x) QUEUE_and_ (ad, &G->edge.v[*x]);
342
+ if ( ad->t==0 ) return (-1);
343
+ if ( ad->v[ad->t-1] > w ) return (ad->v[ad->t-1]);
344
+ return (-1);
345
+ }
346
+ LONG MACE_parent_check_parent (SGRAPH *G, QUEUE *K, QUEUE *ad, QUEUE *Q, QUEUE_INT w){
347
+ QUEUE_INT t=0, *x, i;
348
+ K->v[K->t] = -1; // loop stopper;
349
+ QUEUE_cpy (ad, &G->edge.v[Q[w].v[0]]);
350
+ MQUE_FLOOP (Q[w], x) QUEUE_and_ (ad, &G->edge.v[*x]);
351
+ while ( ad->t > 0 ){
352
+ i = QUEUE_ext_tail_ (ad);
353
+ if ( i<w ) return (-1);
354
+ while ( i<K->v[t] ) t++;
355
+ if ( i > K->v[t] ) return (i);
356
+ QUEUE_and_ (ad, &G->edge.v[i]);
357
+ }
358
+ return (-1);
359
+ }
360
+
361
+
362
+ /***************************************************************/
363
+ /* under construction for future improvements */
364
+ /***************************************************************/
365
+ void MACE_make_same_list (SGRAPH *G, PROBLEM *PP, QUEUE_INT v, MACEVBM *VV){
366
+ QUEUE *Q = PP->OQ;
367
+ VBMINT p;
368
+ QUEUE_ID i;
369
+ QUEUE_INT u, *x;
370
+ if ( Q[v].t > VBMMARK_MAX ) return;
371
+ ARY_FILL (VV->mark, 0, VV->mark_max, 0);
372
+
373
+ FLOOP (i, 0, Q[v].t) G->edge.v[Q[v].v[i]].s = i;
374
+ FLOOP (i, PP->itemcand.s, PP->itemcand.t){
375
+ u = PP->itemcand.v[i];
376
+ p = 0;
377
+ MQUE_FLOOP (Q[u], x) p |= VV->set[G->edge.v[*x].s];
378
+ // if (MACEVBM_mark[p]) c1++;
379
+ // else {MACEVBM_mark[p]++; c2++;}
380
+ }
381
+ MQUE_FLOOP (Q[v], x) G->edge.v[*x].s = 0;
382
+ }
383
+
384
+
385
+ /******************************************************************/
386
+ /******************************************************************/
387
+ /******************************************************************/
388
+
389
+
390
+ /*************************************************************************/
391
+ /* MACE main iteration */
392
+ /*************************************************************************/
393
+ void MACE_iter (PROBLEM *PP, int v, MACEVBM *VV){
394
+ LONG ii;
395
+ QUEUE_INT u;
396
+ QUEUE_ID js = PP->itemcand.s;
397
+ QUEUE *Q = PP->OQ;
398
+ SGRAPH *G = &PP->SG;
399
+ ITEMSET *II = &PP->II;
400
+
401
+ //printf ("%d: ", II->iters);
402
+ //printf ("%d: ", v); QUEUE_print__ (&Q[v]);
403
+
404
+ II->iters++;
405
+ PP->itemcand.s = PP->itemcand.t;
406
+ MACE_add_vertex (G, PP, &Q[v], v, VV);
407
+ MACE_extend (G, PP, &Q[v], v, VV);
408
+ // MACE_make_same_list (v);
409
+
410
+ II->itemset.t = 0;
411
+ memcpy (II->itemset.v, Q[v].v, sizeof(QUEUE_INT)*Q[v].t);
412
+ II->itemset.t = Q[v].t;
413
+ ITEMSET_output_itemset (II, NULL, 0);
414
+ qsort_QUEUE_INT (&PP->itemcand.v[PP->itemcand.s], PP->itemcand.t-PP->itemcand.s, -1);
415
+
416
+ while ( PP->itemcand.t > PP->itemcand.s ){
417
+ u = QUEUE_ext_tail_(&PP->itemcand);
418
+ if ( u == QUEUE_TAIL_(Q[v]) ){
419
+ Q[v].t--;
420
+ if ( PP->problem & PROBLEM_CLOSED ) MACEVBM_reset_vertex (G, u, VV);
421
+ } else {
422
+ if ( PP->problem & PROBLEM_CLOSED ) ii = MACEVBM_parent_check (G, &Q[v], PP->OQ, u, VV);
423
+ else ii = MACE_parent_check (G, PP, &Q[v], &II->add, PP->OQ, u);
424
+ if ( ii==-1 ){
425
+ if (PP->problem & PROBLEM_CLOSED) MACEVBM_reset_diff_vertexes (G, &Q[v], &Q[u], VV);
426
+ MACE_iter (PP, u, VV); // recursive call for a child
427
+ if (PP->problem & PROBLEM_CLOSED) MACEVBM_set_diff_vertexes (G, &Q[v], &Q[u], VV);
428
+ }
429
+ }
430
+ Q[u].t = 0;
431
+ }
432
+ PP->itemcand.s = js;
433
+ if ( PP->problem & PROBLEM_CLOSED ) MACEVBM_reset_vertex (G, v, VV);
434
+ }
435
+
436
+ /* MACE main */
437
+ void MACE (PROBLEM *PP, MACEVBM *VV){
438
+ QUEUE *E = PP->SG.edge.v;
439
+ ITEMSET *II=&PP->II;
440
+ QUEUE_INT v;
441
+
442
+ FLOOP (v, 0, PP->SG.edge.t){
443
+ if ( E[v].t==0 ){
444
+ II->itemset.t = 0;
445
+ ARY_INS (II->itemset, v);
446
+ ITEMSET_output_itemset (II, NULL, 0);
447
+ } else if ( E[v].v[E[v].t-1] <= v ){
448
+ MACE_iter (PP, v, VV);
449
+ }
450
+ PP->OQ[v].t = 0;
451
+ }
452
+ }
453
+
454
+
455
+ // main routine
456
+ int MACE_main (int argc, char *argv[]){
457
+ QUEUE_INT v, flag = 0;
458
+ PROBLEM PP;
459
+ SGRAPH *G=&PP.SG;
460
+ MACEVBM VV;
461
+
462
+ ERROR_MES = NULL;
463
+ PROBLEM_init (&PP);
464
+ MACE_read_param (argc, argv, &PP);
465
+ if ( ERROR_MES ) return (1);
466
+ // if ( weightflag ) MACE_perm = SGRAPH_sort_node_w (&G, G->node_w, 1);
467
+ if ( PP.problem & PROBLEM_MAXIMAL ){
468
+ PP.problem |= PROBLEM_CLOSED; // flag for the use of VBM
469
+ flag = 1;
470
+ }
471
+ MACE_init (&PP, &VV);
472
+ // if ( weightflag ) ENUWMCLQ ();
473
+ if ( !ERROR_MES && G->edge.eles > 0 ){
474
+ if ( PP.problem & PROBLEM_FREQSET ){
475
+ FLOOP (v, 0, G->edge.t) MACEclq_iter (&PP, v, &G->edge.v[v]);
476
+ } else MACE (&PP, &VV);
477
+ ITEMSET_last_output (&PP.II);
478
+ }
479
+
480
+ PROBLEM_end (&PP);
481
+ if ( flag ){
482
+ free2 (VV.edge);
483
+ free2 (VV.pos);
484
+ free2 (VV.set);
485
+ free2 (VV.reset);
486
+ QUEUE_end (&VV.dellist);
487
+ }
488
+
489
+ return (ERROR_MES?1:0);
490
+ }
491
+
492
+ /*******************************************************************************/
493
+ #ifndef _NO_MAIN_
494
+ #define _NO_MAIN_
495
+ int main (int argc, char *argv[]){
496
+ return (MACE_main (argc, argv) );
497
+ }
498
+ #endif
499
+ /*******************************************************************************/
500
+
501
+
502
+ #endif
503
+