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,496 @@
1
+ /* forward star type graph structure -- for quite large graphs */
2
+ /* 6/Nov/2008 Takeaki Uno */
3
+
4
+ #ifndef _fstar_c_
5
+ #define _fstar_c_
6
+
7
+ #include"fstar.h"
8
+ #include"stdlib2.c"
9
+
10
+ FSTAR INIT_FSTAR = {TYPE_FSTAR,NULL,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0,0,0,0,0,NULL,NULL,NULL,0, 0,0,0,FSTAR_INTHUGE,FSTAR_INTHUGE,FSTAR_INTHUGE,-WEIGHTHUGE,WEIGHTHUGE};
11
+ QSORT_TYPE (FSTAR_INT,FSTAR_INT)
12
+
13
+ void FSTAR_print (FILE *fp, FSTAR *F){
14
+ FSTAR_INT i, x=0, y, flag;
15
+
16
+ FLOOP (i, 0, F->edge_num+1){
17
+ while ( i == F->fstar[x+1]){
18
+ flag = 0;
19
+ if ( F->out_deg && (F->out_node_num ==0 || x < F->out_node_num) ) flag += F->out_deg[x];
20
+ if ( F->in_deg && (F->in_node_num ==0 || x < F->in_node_num) ) flag += F->in_deg[x];
21
+ if ( (!F->out_deg && !F->in_deg) && (F->flag&LOAD_EDGE) ) flag = F->fstar[x+1] - F->fstar[x];
22
+ if ( !F->table || flag ) fprintf (fp, "\n");
23
+ if ( ++x == F->out_node_num ) goto END;
24
+ }
25
+ y = F->edge[i];
26
+ if ( !(F->flag&(LOAD_BIPARTITE+LOAD_EDGE)) && F->edge_dir==0 && x>y ) continue;
27
+ if ( F->table && !(F->flag&LOAD_BIPARTITE) ){
28
+ if ( (y=F->table[y]) == F->out_node_num ) continue;
29
+ }
30
+ if ( F->flag & LOAD_ID1 ) y++;
31
+ fprintf (fp, FSTAR_INTF" ", y);
32
+ if ( F->edge_w ) fprintf (fp, WEIGHTF " ", F->edge_w[i]);
33
+ }
34
+ fprintf (fp, "\n");
35
+ END:;
36
+ }
37
+
38
+ /* initialization */
39
+ void FSTAR_init2 (FSTAR *F){
40
+ if ( F->in_lb >0 || F->in_ub <FSTAR_INTHUGE ) F->flag |= (FSTAR_IN_CHK+FSTAR_CNT_IN);
41
+ if ( F->out_lb >0 || F->out_ub <FSTAR_INTHUGE ) F->flag |= (FSTAR_OUT_CHK+FSTAR_CNT_OUT);
42
+ if ( F->deg_lb >0 || F->deg_ub <FSTAR_INTHUGE ){
43
+ F->flag |= FSTAR_DEG_CHK+FSTAR_CNT_IN;
44
+ if ( (F->flag&(FSTAR_OUT_CHK+FSTAR_IN_CHK)) ==0 ) F->flag |= FSTAR_CNT_DEG_ONLY;
45
+ else F->flag |= FSTAR_CNT_OUT;
46
+ }
47
+ }
48
+
49
+ /* termination */
50
+ void FSTAR_end (FSTAR *F){
51
+ mfree (F->edge, F->edge_w, F->in_deg, F->out_deg, F->fstar, F->table, F->rev_table);
52
+ *F = INIT_FSTAR;
53
+ }
54
+
55
+ /* increment degrees */
56
+ void FSTAR_inc_deg (FSTAR *F, FSTAR_INT x, FSTAR_INT y){
57
+ if ( F->out_deg ) F->out_deg[x]++;
58
+ if ( F->out_deg && (F->flag&LOAD_EDGE) ) F->out_deg[y]++;
59
+ if ( F->in_deg ) F->in_deg[y]++;
60
+ if ( ((F->flag & FSTAR_CNT_DEG_ONLY) || F->edge_dir==0) && F->in_deg ) F->in_deg[x]++;
61
+ }
62
+
63
+ /* remove edges adjacent to small/large degree vertices */
64
+ void FSTAR_sort_adjacent_node (FSTAR *F, int flag){
65
+ FSTAR_INT x, d=0, y, s = sizeof(FSTAR_INT)+sizeof(WEIGHT);
66
+ char *p;
67
+ if ( F->edge_w ){
68
+ // sort with weight; make array of (ID,weight) and sort it
69
+ FLOOP (x, 0, F->out_node_num) ENMAX (d, F->fstar[x+1]-F->fstar[x]);
70
+ malloc2 (p, d * (sizeof(FSTAR_INT)+sizeof(WEIGHT)), EXIT);
71
+ FLOOP (x, 0, F->out_node_num){
72
+ FLOOP (y, 0, F->fstar[x+1]-F->fstar[x]){
73
+ *((FSTAR_INT *)(&p[y*s])) = F->edge[y+F->fstar[x]];
74
+ *((WEIGHT *)(&p[y*s+sizeof(FSTAR_INT)])) = F->edge_w[y+F->fstar[x]];
75
+ }
76
+ qsort_FSTAR_INT ((void *)p, F->fstar[x+1]-F->fstar[x], flag*s);
77
+ FLOOP (y, 0, F->fstar[x+1]-F->fstar[x]){
78
+ F->edge[y+F->fstar[x]] = *((FSTAR_INT *)(&p[y*s]));
79
+ F->edge_w[y+F->fstar[x]] = *((WEIGHT *)(&p[y*s+sizeof(FSTAR_INT)]));
80
+ }
81
+ }
82
+ free2 (p);
83
+ } else {
84
+ FLOOP (x, 0, F->out_node_num)
85
+ qsort_FSTAR_INT (&F->edge[F->fstar[x]], F->fstar[x+1]-F->fstar[x], flag);
86
+ }
87
+ }
88
+
89
+ /* compute node_num's and allocate arrays for degree */
90
+ LONG FSTAR_alloc_deg (FSTAR *F){
91
+ // int tpose = (F->edge_dir==-1 && !(F->flag & LOAD_TPOSE)) || (F->edge_dir!=-1 && (F->flag & LOAD_TPOSE));
92
+ LONG i = F->out_node_num, j;
93
+ F->out_node_num = F->xmax;
94
+ F->in_node_num = F->ymax;
95
+ // if ( F->edge_dir == -1 ) SWAP_FSTAR_INT ( F->out_node_num, F->in_node_num);
96
+ j = F->out_node_num; ENMAX (F->out_node_num, i);
97
+ F->node_num = MAX (F->out_node_num, F->in_node_num);
98
+ if ( F->edge_dir == 0 ) F->in_node_num = F->out_node_num = F->node_num;
99
+ calloc2 (F->fstar, F->out_node_num+2, EXIT);
100
+ if ( F->flag & LOAD_EDGE ) return (j);
101
+
102
+ if ( F->flag & FSTAR_CNT_IN ){
103
+ if ( F->flag & FSTAR_CNT_DEG_ONLY ){
104
+ calloc2 (F->in_deg, F->node_num+2, EXIT);
105
+ } else calloc2 (F->in_deg, F->in_node_num+2, EXIT);
106
+ }
107
+ if ( F->flag & FSTAR_CNT_OUT )
108
+ calloc2 (F->out_deg, F->out_node_num+2, EXIT);
109
+ return (j);
110
+ }
111
+
112
+ /* compute fstar from outdegree stored in fstar itself, and allocate edge array */
113
+ void FSTAR_calc_fstar (FSTAR *F){
114
+ FSTAR_INT i, j=0, jj;
115
+ FLOOP (i, 0, F->out_node_num){
116
+ jj = j + F->fstar[i];
117
+ F->fstar[i] = j;
118
+ j = jj;
119
+ }
120
+ F->fstar[i] = F->edge_num = j;
121
+ // malloc2 (F->edge, ((F->flag&LOAD_EDGE)?2:1) *F->edge_num +2, EXIT);
122
+ // ARY_FILL (F->edge, 0, ((F->flag&LOAD_EDGE)?2:1) *F->edge_num +2, F->node_num+1);
123
+ malloc2 (F->edge, F->edge_num +2, EXIT);
124
+ ARY_FILL (F->edge, 0, F->edge_num +2, F->node_num+1);
125
+ if ( (F->flag&LOAD_EDGEW) || F->wfname ) malloc2 (F->edge_w, F->edge_num +2, EXIT); // weight array
126
+ }
127
+
128
+ /* return 1 if edge (x,y) is valid */
129
+ /* head != 0 means x is the origin, otherwise x is destination */
130
+ int FSTAR_eval_edge (FSTAR *F, FSTAR_INT x, FSTAR_INT y, WEIGHT w){
131
+
132
+ if ( x>F->node_num || y>F->node_num || x<0 || y<0 ) return (0);
133
+ if ( ((F->flag&LOAD_EDGEW) || F->wfname) && !RANGE (F->w_lb, w, F->w_ub) ) return (0);
134
+ if ( F->flag & LOAD_EDGE ){
135
+ if ( F->fstar[F->out_node_num] ){
136
+ if ( !RANGE (F->deg_lb, F->fstar[x+1]-F->fstar[x], F->deg_ub) ) return (0);
137
+ if ( !RANGE (F->deg_lb, F->fstar[y+1]-F->fstar[y], F->deg_ub) ) return (0);
138
+ } else {
139
+ if ( !RANGE (F->deg_lb, F->fstar[x], F->deg_ub) ) return (0);
140
+ if ( !RANGE (F->deg_lb, F->fstar[y], F->deg_ub) ) return (0);
141
+ }
142
+ return (1);
143
+ }
144
+
145
+ if ( F->out_deg && (F->flag&FSTAR_OUT_CHK)){
146
+ if ( !RANGE (F->out_lb, F->out_deg[x], F->out_ub) ) return (0);
147
+ if ( (F->flag&LOAD_BIPARTITE)==0
148
+ && !RANGE(F->out_lb, F->out_deg[y], F->out_ub) ) return (0);
149
+ }
150
+ if ( F->in_deg && F->out_deg && (F->flag&LOAD_BIPARTITE)==0 && (F->flag&FSTAR_DEG_CHK)){
151
+ if ( !RANGE (F->deg_lb, F->in_deg[x]+F->out_deg[x], F->deg_ub) ) return (0);
152
+ if ( !RANGE (F->deg_lb, F->in_deg[y]+F->out_deg[y], F->deg_ub) ) return (0);
153
+ }
154
+
155
+ if ( ((F->flag & FSTAR_CNT_DEG_ONLY) || F->edge_dir==0) && F->in_deg && (F->flag&FSTAR_DEG_CHK)){
156
+ if ( !RANGE (F->deg_lb, F->in_deg[x], F->deg_ub) ) return (0);
157
+ if ( !RANGE (F->deg_lb, F->in_deg[y], F->deg_ub) ) return (0);
158
+ } else if ( F->in_deg && (F->flag&FSTAR_IN_CHK) && !(F->flag&FSTAR_CNT_DEG_ONLY) ){
159
+ if ( (F->flag&LOAD_BIPARTITE)==0
160
+ && !RANGE (F->in_lb, F->in_deg[x], F->in_ub) ) return (0);
161
+ if ( !RANGE (F->in_lb, F->in_deg[y], F->in_ub) ) return (0);
162
+ }
163
+ return (1);
164
+ }
165
+
166
+ /* scan the file and count the degree, for edge listed file */
167
+ /* if F->out_node_num is set ot a number larger than #nodes, set the node number to it, so that isolated vertices will be attached to the last */
168
+ void FSTAR_scan_file (FSTAR *F, FILE2 *fp){
169
+ LONG i, j;
170
+
171
+ // LONG x, y, i;
172
+ // double w;
173
+ FILE_COUNT C = INIT_FILE_COUNT;
174
+ // int tpose = F->flag & LOAD_TPOSE, f = F->flag - (F->flag & LOAD_EDGEW);
175
+
176
+ // count #pairs
177
+ C = FILE2_count (fp, (F->flag&(LOAD_ELE+LOAD_TPOSE+LOAD_NUM+LOAD_GRAPHNUM+LOAD_EDGE)) | FILE_COUNT_ROWT | (F->in_deg? FILE_COUNT_CLMT: 0), 0, 0, 0, (F->flag&LOAD_EDGEW)?1:0, 0);
178
+ F->xmax = C.rows; F->ymax = C.clms; F->edge_num_org = C.eles;
179
+ j = FSTAR_alloc_deg (F);
180
+ FLOOP (i, 0, j){
181
+ F->fstar[i] = C.rowt[i];
182
+ if ( F->out_deg ) F->out_deg[i] = C.rowt[i];
183
+ if ( F->in_deg ) F->in_deg[i] = C.clmt[i];
184
+ }
185
+ mfree (C.rowt, C.clmt);
186
+ }
187
+
188
+ /* load data from file to memory with allocation, (after the scan for counting) */
189
+ void FSTAR_read_file (FSTAR *F, FILE2 *fp, FILE2 *wfp){
190
+ LONG i, x, y;
191
+ int fc=0, FILE_err_=0;
192
+ int flag = (F->flag & (FSTAR_DEG_CHK+FSTAR_IN_CHK+FSTAR_OUT_CHK)), phase;
193
+ double w;
194
+
195
+ if ( wfp ) FILE2_reset (wfp);
196
+
197
+ for (phase=flag?1:2 ; phase < 3 ; phase++){
198
+ i=0;
199
+ FILE2_reset (fp);
200
+ if ( F->flag&(LOAD_NUM+LOAD_GRAPHNUM) ) FILE2_read_until_newline (fp);
201
+ if ( phase == 2 ) FSTAR_calc_fstar (F);
202
+ do {
203
+ //////////////
204
+ if ( F->flag&LOAD_ELE ){
205
+ if ( FILE2_read_pair (fp, &x, &y, &w, F->flag) ) continue;
206
+ } else {
207
+ x = i;
208
+ FILE_err_ = (FSTAR_INT)FILE2_read_item (fp, wfp, &x, &y, &w, fc, F->flag);
209
+ if ( FILE_err&4 ) goto LOOP_END;
210
+ }
211
+ /////////////
212
+
213
+ if ( !flag || FSTAR_eval_edge (F, x, y, w) ){
214
+ if ( phase == 2 ){
215
+ if ( F->fstar[x+1]>F->fstar[x] && (!(F->flag & LOAD_EDGE) || F->fstar[y+1]>F->fstar[y])){
216
+ if ( F->edge_w ) F->edge_w[F->fstar[x]] = w;
217
+ F->edge[F->fstar[x]++] = y;
218
+ if ( F->flag & LOAD_EDGE ){
219
+ if ( F->edge_w ) F->edge_w[F->fstar[y]] = w;
220
+ F->edge[F->fstar[y]++] = x;
221
+ }
222
+ }
223
+ } else {
224
+ F->fstar[x]--;
225
+ if ( F->flag & LOAD_EDGE ) F->fstar[y]--;
226
+ }
227
+ }
228
+
229
+ //////////////
230
+ if ( !(F->flag&LOAD_ELE) ){
231
+ fc = 0;
232
+ if ( FILE_err&3 ){
233
+ LOOP_END:;
234
+ i++;
235
+ fc = FILE_err_? 0: 1; FILE_err_=0; // even if next weight is not written, it is the rest of the previous line
236
+ }
237
+ }
238
+ /////////////////////
239
+ } while ( !(FILE_err&2) );
240
+ phase++;
241
+ }
242
+ F->fstar[F->out_node_num+1] = 0;
243
+ BLOOP (i, F->out_node_num, 0) F->fstar[i+1] = F->fstar[i];
244
+ F->fstar[0] = 0;
245
+ }
246
+
247
+ /* remove edges adjacent to small/large degree vertices */
248
+ void FSTAR_extract_subgraph (FSTAR *F){
249
+ FSTAR_INT x, y, ii, i, nodes;
250
+ int flag = 0;
251
+ WEIGHT w=0;
252
+
253
+ // count #pairs
254
+ do {
255
+ nodes = 0;
256
+ if ( F->in_deg || F->out_deg ){
257
+ // re-count in/out degrees
258
+ if ( F->in_deg ) ARY_FILL (F->in_deg, 0, F->in_node_num, 0);
259
+ if ( F->out_deg ) ARY_FILL (F->out_deg, 0, F->out_node_num, 0);
260
+ x=0; FLOOP (i, 0, F->edge_num){
261
+ while ( i == F->fstar[x+1] ) x++;
262
+ FSTAR_inc_deg (F, x, F->edge[i]);
263
+ }
264
+ }
265
+
266
+ // re-remove out-bounded degree vertices
267
+ ii=x=0; FLOOP (i, 0, F->edge_num){
268
+ while ( i == F->fstar[x+1] ){ F->fstar[x+1] = ii; x++; flag = 0; }
269
+ y = F->edge[i];
270
+ if ( F->edge_w ) w = F->edge_w[i];
271
+ if ( FSTAR_eval_edge (F, x, y, w) ){
272
+ if ( F->edge_w ) F->edge_w[ii] = F->edge_w[i];
273
+ F->edge[ii++] = y;
274
+ if ( flag==0 ){ nodes++; flag = 1; }
275
+ }
276
+ }
277
+ F->edge_num = ii;
278
+ print_mes (F, "iterative scan: #nodes="FSTAR_INTF", #edges = %d\n", nodes, i);
279
+ } while ( ii < i );
280
+ }
281
+
282
+ /* load graph from file */
283
+ void FSTAR_load (FSTAR *F){
284
+ FILE2 fp = INIT_FILE2, wfp = INIT_FILE2;
285
+ FSTAR_init2 (F);
286
+
287
+ FILE2_open (fp, F->fname, "r", EXIT);
288
+ if ( F->wfname ) FILE2_open (wfp, F->wfname, "r", EXIT);
289
+
290
+ FSTAR_scan_file (F, &fp);
291
+ print_mes (F, "first & second scan end: %s\n", F->fname);
292
+
293
+ FSTAR_read_file (F, &fp, F->wfname? &wfp: NULL);
294
+ FILE2_close (&fp); if (ERROR_MES) EXIT;
295
+ if ( F->wfname ) FILE2_close (&wfp); if (ERROR_MES) EXIT;
296
+ print_mes (F, "file read end: %s\n", F->fname);
297
+
298
+ FSTAR_extract_subgraph (F);
299
+ // if ( ((F->flag&LOAD_INCSORT) && !(F->flag&LOAD_ELE))
300
+ if ( (F->flag&LOAD_INCSORT)
301
+ || (F->flag&LOAD_DECSORT) ) FSTAR_sort_adjacent_node (F, (F->flag&LOAD_DECSORT)?-1:1);
302
+ print_mes (F, "forwardstar graph: %s ,#nodes %d(%d,%d) ,#edges %d\n", F->fname, F->node_num, F->in_node_num, F->out_node_num, F->edge_num);
303
+ }
304
+
305
+ /* make vertex permutation table and write to table-file */
306
+ void FSTAR_write_table_file (FSTAR *F, char *fname){
307
+ FSTAR_INT i, flag;
308
+ FILE *fp;
309
+ if ( !fname ) return;
310
+ fopen2 (fp, fname, "w", EXIT);
311
+ calloc2 (F->table, F->node_num, {fclose(fp);EXIT;});
312
+ F->reduced_node_num = 0;
313
+ FLOOP (i, 0, F->out_node_num){
314
+ flag = 0;
315
+ if ( F->out_deg ) flag += F->out_deg[i];
316
+ if ( F->in_deg && (F->in_node_num==0 || i < F->in_node_num) ) flag += F->in_deg[i];
317
+ if ( flag ){
318
+ fprintf (fp, FSTAR_INTF"\n", (F->flag&LOAD_ID1)?i+1:i);
319
+ F->table[i] = F->reduced_node_num;
320
+ F->reduced_node_num++;
321
+ } else F->table[i] = F->out_node_num;
322
+ }
323
+ fclose2 (fp);
324
+ }
325
+
326
+ FILE *FSTAR_open_write_file (FSTAR *F, char *fname){
327
+ FILE *fp;
328
+ fopen2 (fp, fname, "w", EXIT);
329
+ if ( F->flag&(LOAD_NUM+LOAD_GRAPHNUM) ){
330
+ fprintf (fp, FSTAR_INTF" ", F->node_num);
331
+ if ( F->flag&LOAD_NUM ) fprintf (fp, FSTAR_INTF" ", F->node_num);
332
+ fprintf (fp, FSTAR_INTF"\n", F->edge_num/((F->flag&LOAD_EDGE)?2:1));
333
+ }
334
+ return (fp);
335
+ }
336
+
337
+ /* write row ID on the top of the line */
338
+ void FSTAR_write_graph_ID (FSTAR *F, FILE *fp, FILE *fp2, FSTAR_INT ID){
339
+
340
+ // for the case "first element is row ID
341
+ if ( F->flag & FSTAR_INS_ROWID){
342
+ if ( F->flag & LOAD_ELE ){
343
+ fprintf (fp, FSTAR_INTF" "FSTAR_INTF, ID, ID);
344
+ if ( (F->flag & LOAD_EDGE) && (F->flag & FSTAR_INS_ROWID_WEIGHT) ){ fprintf (fp, " 1"); }
345
+ fprintf (fp, "\n");
346
+ } else {
347
+ fprintf (fp, FSTAR_INTF" ", ID);
348
+ if ( fp2 && (F->flag & FSTAR_INS_ROWID_WEIGHT) ) fprintf (fp2, "1 ");
349
+ if ( (F->flag & LOAD_EDGEW) && (F->flag & FSTAR_INS_ROWID_WEIGHT)){ fprintf (fp, "1 "); }
350
+ }
351
+ }
352
+ }
353
+
354
+ /* write an edge */
355
+ int FSTAR_write_graph_item (FSTAR *F, FSTAR_INT x, FSTAR_INT y, WEIGHT w, FILE *fp, FILE *fp2, int *row, FSTAR_INT *prv){
356
+
357
+ if ( !(F->flag&(LOAD_BIPARTITE+LOAD_EDGE)) && F->edge_dir==0 && x>y ) return (1);
358
+
359
+ // ID permutation
360
+ if ( F->table ){
361
+ x = F->table[x];
362
+ if ( !(F->flag & LOAD_BIPARTITE) ){
363
+ if ( (y=F->table[y]) == F->out_node_num ) return (1);
364
+ }
365
+ }
366
+ if ( F->flag & LOAD_ID1 ) y++;
367
+
368
+ // write an element
369
+ if ( !(F->flag&LOAD_RM_DUP) || *row == 0 || *prv != y ){
370
+ if ( F->flag & LOAD_ELE ){
371
+ fprintf (fp, FSTAR_INTF" "FSTAR_INTF, x, y);
372
+ if (F->flag & LOAD_EDGEW){ fputc (' ', fp); fprint_real (fp, w); }
373
+ fprintf (fp, "\n");
374
+ } else {
375
+ fprintf (fp, FSTAR_INTF" ", y);
376
+ if ( fp2 ){ fprint_real (fp2, w); fputc (' ', fp2); }
377
+ if ( F->flag&LOAD_EDGEW ){ fprint_real (fp, w); fputc (' ', fp); }
378
+ }
379
+ *row = 1;
380
+ }
381
+ *prv = y; // remember the previous element
382
+ return (0);
383
+ }
384
+
385
+
386
+ /* write induced graph and the number convert table; needs accumerated node_deg, edge */
387
+ LONG FSTAR_write_graph (FSTAR *F, char *fname, char *fname2){
388
+ FILE *fp2=NULL, *fp = FSTAR_open_write_file (F, fname);
389
+ FSTAR_INT i=0, x=0, y, flag = 0, c=0, prv=0;
390
+ int row=0, IDf=0;
391
+ LONG cnt=0;
392
+ if ( fname2 ) fopen2 (fp2, fname2, "w", EXIT);
393
+
394
+ while (i <= F->edge_num+1){
395
+ while ( i == F->fstar[x+1]){
396
+ if ( !F->table || flag ){
397
+ if ( IDf == 0 ) FSTAR_write_graph_ID (F, fp, fp2, c);
398
+ flag = 0; c++; row=0; IDf = 0;
399
+ if ( !(F->flag & LOAD_ELE) ){
400
+ fprintf (fp, "\n");
401
+ if ( fp2 ) fprintf (fp2, "\n");
402
+ }
403
+ }
404
+ if ( ++x >= F->out_node_num ) goto END;
405
+ }
406
+ y = F->edge[i];
407
+
408
+ if ( IDf == 0 ){
409
+ if ( F->out_deg && (F->out_node_num ==0 || x < F->out_node_num) ) flag += F->out_deg[x];
410
+ if ( F->in_deg && (F->in_node_num ==0 || x < F->in_node_num) ) flag += F->in_deg[x];
411
+ if ( (!F->out_deg && !F->in_deg) && (F->flag&LOAD_EDGE) ) flag = F->fstar[x+1] - F->fstar[x];
412
+ if ( !F->table || flag ) FSTAR_write_graph_ID (F, fp, fp2, c);
413
+ IDf = 1;
414
+ }
415
+
416
+ FSTAR_write_graph_item (F, x, y, F->edge_w? F->edge_w[i]: 0, fp, fp2, &row, &prv);
417
+ cnt++; i++;
418
+ }
419
+ if ( !(F->flag & LOAD_ELE) ){
420
+ fprintf (fp, "\n");
421
+ if ( fp2 ) fprintf (fp2, "\n");
422
+ }
423
+ END:;
424
+ fclose (fp);
425
+ fclose2 (fp2);
426
+ return (cnt);
427
+ }
428
+
429
+ /* write induced graph and the number convert table; needs accumerated node_deg, edge */
430
+ LONG FSTAR_write_graph_operation (FSTAR *F1, FSTAR *F2, char *fname, char *fname2, int op, double th){
431
+ FILE *fp2=NULL, *fp = FSTAR_open_write_file (F1, fname);
432
+ FSTAR_INT i=0, j=0, x=0, y, y1, y2, prv=0, ee = MAX(F1->out_node_num, F1->in_node_num);
433
+ int row2=0, end1=0, end2=0;
434
+ LONG cnt=0;
435
+ WEIGHT w=0, w1, w2;
436
+ if ( fname2 ) fopen2 (fp2, fname2, "w", EXIT);
437
+ ENMAX (ee, F2->out_node_num);
438
+ ENMAX (ee, F2->in_node_num);
439
+
440
+ FSTAR_write_graph_ID (F1, fp, fp2, 0);
441
+ while (i <= F1->edge_num+1 && j <= F2->edge_num+1){
442
+ while ( (end1 || i == F1->fstar[x+1]) && (end2 || j == F2->fstar[x+1])){
443
+ row2 = 0;
444
+ if ( !(F1->flag & LOAD_ELE) ){
445
+ fprintf (fp, "\n");
446
+ if ( fp2 ) fprintf (fp2, "\n");
447
+ }
448
+ x++;
449
+ if ( x >= F1->out_node_num ) end1 = 1;
450
+ if ( x >= F2->out_node_num ) end2 = 1;
451
+ if ( end1 && end2 ) goto END;
452
+ FSTAR_write_graph_ID (F1, fp, fp2, x);
453
+ }
454
+
455
+ y1 = (!end1 && i<F1->edge_num+1 && i < F1->fstar[x+1])? F1->edge[i]: ee;
456
+ y2 = (!end2 && j<F2->edge_num+1 && j < F2->fstar[x+1])? F2->edge[j]: ee;
457
+ //printf ("come %d %d %d %d %d\n", y2, (!end2 && j<F2->edge_num+1 && j < F2->fstar[x+1])? F2->edge[j]: ee, !end2, j<F2->edge_num+1, j < F2->fstar[x+1]);
458
+ if ( y1 < y2 ){
459
+ if ( op == 1 ){ i++; continue; } // intersection
460
+ y = y1;
461
+ w = F1->edge_w? F1->edge_w[i]: 0;
462
+ i++;
463
+ } else if ( y1 > y2){
464
+ if ( op == 1 ){ j++; continue; } // intersection
465
+ y = y2;
466
+ w = F2->edge_w? F2->edge_w[j]: 0;
467
+ j++;
468
+ } else {
469
+ if ( op == 3 ){ i++; j++; continue; } // symmetric difference
470
+ y = y1;
471
+ w1 = F1->edge_w? F1->edge_w[i]: 0;
472
+ w2 = F2->edge_w? F2->edge_w[j]: 0;
473
+ i++; j++;
474
+ if ( op == 1 ) w = MIN(w1, w2); // weighted intersection
475
+ if ( op == 2 ) w = MAX(w1, w2); // weighted union
476
+ if ( op == 4 ) w = w1 - w2; // difference
477
+ }
478
+ if ( op == 4 && (w=abs(w)) < th ) continue; // difference
479
+
480
+ //printf ("#### %d %d (%d, %d)\n", x, y, F1->out_node_num, F2->out_node_num);
481
+ //printf ("#### %d %d (%d, %d) (%d %d)\n", i, j, x, y, F1->edge_num, F2->edge_num);
482
+ FSTAR_write_graph_item (F1, x, y, w, fp, fp2, &row2, &prv);
483
+ cnt++;
484
+ }
485
+ if ( !(F1->flag & LOAD_ELE) ){
486
+ fprintf (fp, "\n");
487
+ if ( fp2 ) fprintf (fp2, "\n");
488
+ }
489
+ END:;
490
+ fclose (fp);
491
+ fclose2 (fp2);
492
+ return (cnt);
493
+ }
494
+
495
+ #endif
496
+
@@ -0,0 +1,80 @@
1
+ /* forward star type graph structure -- for quite large graphs */
2
+ /* 6/Nov/2008 Takeaki Uno */
3
+
4
+
5
+ #ifndef _fstar_h_
6
+ #define _fstar_h_
7
+
8
+ #include"stdlib2.h"
9
+
10
+ #define FSTAR_WRITE_EDGE_FILE 16777216 // write file as edge list
11
+ #define FSTAR_REDUCE 33554432 // output table
12
+ #define FSTAR_CNT_IN 67108864
13
+ #define FSTAR_CNT_OUT 134217728
14
+ #define FSTAR_CNT_DEG_ONLY 268435456 // in_deg means usual degree
15
+
16
+ #define FSTAR_DEG_CHK 536870912
17
+ #define FSTAR_IN_CHK 1073741824
18
+ #define FSTAR_OUT_CHK 8388608
19
+ #define FSTAR_INS_ROWID 536870912 // insert row ID to the head of each line
20
+ #define FSTAR_INS_ROWID_WEIGHT 1073741824 // insert row ID to the head of each line
21
+
22
+ // undirected graph => CNT_DEG_ONLY, edge_dir = 0
23
+ // bipartite graph => BIPARTITE, edge_dir != 0
24
+ #ifndef FSTAR_INT
25
+ #ifdef FSTAR_INT_LONG
26
+ #define FSTAR_INT LONG
27
+ #define FSTAR_INTHUGE LONGHUGE
28
+ #define FSTAR_INTF "%llu"
29
+ #else
30
+ #define FSTAR_INT unsigned int
31
+ #define FSTAR_INTHUGE UINTHUGE
32
+ #define FSTAR_INTF "%u"
33
+ #endif
34
+ #endif
35
+ #define SWAP_FSTAR_INT(a,b) (common_FSTAR_INT=a,a=b,b=common_FSTAR_INT)
36
+
37
+ typedef struct {
38
+ unsigned char type; // type definition
39
+ char *fname, *wfname; // input file name, edge weight file name
40
+ int flag; // flag
41
+ FSTAR_INT *edge; // edge array
42
+ FSTAR_INT *fstar; // starting position of edge list for each vertex
43
+ FSTAR_INT *in_deg, *out_deg; // in/out-degree of each vertex (can be NULL if not used)
44
+ FSTAR_INT node_num, out_node_num, in_node_num; // #vertex and #1st/2nd vertices
45
+ FSTAR_INT edge_num, edge_num_org, reduced_node_num; // #edges in file, in array
46
+ FSTAR_INT xmax, ymax; // maximum in 1st/2nd column
47
+ FSTAR_INT *table, *rev_table; // vertex permutation table and its reverse
48
+ WEIGHT *edge_w; // edge weights
49
+
50
+ int edge_dir;
51
+
52
+ FSTAR_INT deg_lb, in_lb, out_lb, deg_ub, in_ub, out_ub; // bounds for degrees
53
+ WEIGHT w_lb, w_ub; // bounds for edge weight
54
+ } FSTAR;
55
+
56
+ QSORT_TYPE_HEADER (FSTAR_INT,FSTAR_INT)
57
+ extern FSTAR INIT_FSTAR;
58
+
59
+ /**************************************************************/
60
+ void FSTAR_print (FILE *fp, FSTAR *F);
61
+ void FSTAR_init2 (FSTAR *F);
62
+ void FSTAR_end (FSTAR *F);
63
+ void FSTAR_load (FSTAR *F);
64
+
65
+ LONG FSTAR_alloc_deg (FSTAR *F);
66
+ void FSTAR_calc_fstar (FSTAR *F);
67
+ int FSTAR_eval_edge (FSTAR *F, FSTAR_INT x, FSTAR_INT y, WEIGHT w);
68
+ void FSTAR_extract_subgraph (FSTAR *F);
69
+ void FSTAR_sort_adjacent_node (FSTAR *F, int flag);
70
+
71
+ void FSTAR_scan_file (FSTAR *F, FILE2 *fp);
72
+ void FSTAR_read_file_edge (FSTAR *F, FILE2 *fp);
73
+ void FSTAR_read_file_node (FSTAR *F, FILE2 *fp, FILE2 *fp2);
74
+
75
+ void FSTAR_write_table_file (FSTAR *F, char *fname);
76
+ LONG FSTAR_write_graph (FSTAR *F, char *fname, char *fname2);
77
+ LONG FSTAR_write_graph_operation (FSTAR *F1, FSTAR *F2, char *fname, char *fname2, int op, double th);
78
+
79
+ #endif
80
+