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