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,360 @@
1
+ /* graph library by array list
2
+ 12/Feb/2002 by Takeaki Uno
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 the codes for the users.
11
+ For the commercial use, please make a contact to Takeaki Uno. */
12
+
13
+ #ifndef _sgraph_c_
14
+ #define _sgraph_c_
15
+
16
+ #include"sgraph.h"
17
+ #include"vec.c"
18
+
19
+ SGRAPH INIT_SGRAPH = {TYPE_SGRAPH,NULL,0,INIT_SETFAMILY_,INIT_SETFAMILY_,INIT_SETFAMILY_,0,NULL,NULL,NULL};
20
+
21
+ /* initialization */
22
+ void SGRAPH_alloc (SGRAPH *G, QUEUE_ID nodes, size_t edge_num, size_t arc_num){
23
+ if ( edge_num > 0 ){
24
+ SETFAMILY_alloc (&G->edge, nodes, NULL, nodes, edge_num);
25
+ if ( G->flag&LOAD_EDGEW && (!ERROR_MES) ) SETFAMILY_alloc_weight (&G->edge);
26
+ }
27
+ if ( arc_num > 0 ){
28
+ SETFAMILY_alloc (&G->in, nodes, NULL, nodes, arc_num);
29
+ SETFAMILY_alloc (&G->out, nodes, NULL, nodes, arc_num);
30
+ if ( G->flag&LOAD_EDGEW && (!ERROR_MES) ){
31
+ SETFAMILY_alloc_weight (&G->in);
32
+ SETFAMILY_alloc_weight (&G->out);
33
+ }
34
+ }
35
+ if (G->flag&LOAD_NODEW) calloc2 (G->node_w, nodes, G->node_w=0);
36
+ if ( ERROR_MES ){ SGRAPH_end (G); EXIT; }
37
+ }
38
+
39
+ /* copy graph G to graph G2. Underconstruction */
40
+ //void SGRAPH_cpy (SGRAPH *G2, SGRAPH *G){}
41
+
42
+ /* free graph object */
43
+ void SGRAPH_end (SGRAPH *G){
44
+ SETFAMILY_end (&G->edge);
45
+ SETFAMILY_end (&G->in);
46
+ SETFAMILY_end (&G->out);
47
+ mfree (G->wbuf, G->perm);
48
+ *G = INIT_SGRAPH;
49
+ }
50
+
51
+
52
+ /* make an edge between u and v.
53
+ If they are already connected, it will be a multiple edge */
54
+ void SGRAPH_edge_mk (SGRAPH *G, QUEUE_INT u, QUEUE_INT v, WEIGHT w){
55
+ if ( G->edge.w ){
56
+ G->edge.w[u][G->edge.v[u].t] = w;
57
+ G->edge.w[v][G->edge.v[v].t] = w;
58
+ }
59
+ ARY_INS (G->edge.v[u], v);
60
+ ARY_INS (G->edge.v[v], u);
61
+ G->edge.eles += 2;
62
+ }
63
+
64
+ /* make an arc between u and v.
65
+ If they are already connected, it will be a multiple arc */
66
+ void SGRAPH_arc_mk (SGRAPH *G, QUEUE_INT u, QUEUE_INT v, WEIGHT w){
67
+ if ( G->out.w ) G->out.w[u][G->out.v[u].t] = w;
68
+ if ( G->in.w ) G->in.w[v][G->in.v[v].t] = w;
69
+ ARY_INS (G->out.v[u], v);
70
+ ARY_INS (G->in.v[v], u);
71
+ G->in.eles++;
72
+ G->out.eles++;
73
+ }
74
+
75
+ /* Delete the edge connecting u and v. If edge (u,v) does not exist, nothing will occur. */
76
+ void SGRAPH_edge_rm_iter (SETFAMILY *M, QUEUE_INT u, QUEUE_INT v){
77
+ QUEUE_INT i;
78
+ if ( (i = (QUEUE_INT)QUEUE_ele (&M->v[u], v)) >= 0 ){
79
+ QUEUE_rm (&M->v[u], i);
80
+ if ( M->w ) M->w[u][i] = M->w[u][M->v[u].t];
81
+ M->eles--;
82
+ }
83
+ }
84
+
85
+ /* Delete the edge connecting u and v. If edge (u,v) does not exist, nothing will occur. */
86
+ void SGRAPH_edge_rm (SGRAPH *G, QUEUE_INT u, QUEUE_INT v){
87
+ SGRAPH_edge_rm_iter (&G->edge, u, v);
88
+ SGRAPH_edge_rm_iter (&G->edge, v, u);
89
+ }
90
+
91
+ /* Delete the arc connecting u and v. If arc (u,v) does not exist, nothing will occur. */
92
+ void SGRAPH_arc_rm (SGRAPH *G, QUEUE_INT u, QUEUE_INT v){
93
+ SGRAPH_edge_rm_iter (&G->out, u, v);
94
+ SGRAPH_edge_rm_iter (&G->in, v, u);
95
+ }
96
+
97
+ /* print graph by numbers */
98
+ void SGRAPH_print (SGRAPH *G){
99
+ VEC_ID i, j;
100
+ QUEUE_INT e;
101
+
102
+ printf ("#node "VEC_IDF" ,#edge %zd ,#arc %zd\n", SGRAPH_NODE_NUM(*G), G->edge.eles, G->in.eles);
103
+ FLOOP (i, 0, SGRAPH_NODE_NUM(*G)){
104
+ printf ("NODE "VEC_IDF" ", i);
105
+ if ( G->node_w ){ putchar ('('); print_WEIGHT (G->node_w[i]); putchar (')'); }
106
+ printf (" >>\n");
107
+ if ( G->edge.v && G->edge.v[i].t ){
108
+ printf (" edge : ");
109
+ for (j=0; j<G->edge.v[i].t ; j++){
110
+ e = G->edge.v[i].v[j];
111
+ printf (VEC_IDF, e);
112
+ if ( G->edge.w ){ putchar ('('); print_WEIGHT (G->edge.w[i][j]); putchar (')'); }
113
+ putchar (',');
114
+ }
115
+ putchar ('\n');
116
+ }
117
+ if ( G->in.w ){
118
+ if ( G->in.v[i].t ){
119
+ printf (" in-arc : ");
120
+ for (j=0; j<G->in.v[i].t ; j++){
121
+ e = G->in.v[i].v[j];
122
+ printf (VEC_IDF, e);
123
+ if ( G->in.w ){ putchar ('('); print_WEIGHT (G->in.w[i][j]); putchar (')'); }
124
+ putchar (',');
125
+ }
126
+ putchar ('\n');
127
+ }
128
+ }
129
+ if ( G->out.w ){
130
+ if ( G->out.v[i].t ){
131
+ printf (" out-arc : ");
132
+ for (j=0; j<G->out.v[i].t ; j++){
133
+ e = G->out.v[i].v[j];
134
+ printf (VEC_IDF, e);
135
+ if ( G->out.w ){ putchar ('('); print_WEIGHT (G->out.w[i][j]); putchar (')');}
136
+ putchar (',');
137
+ }
138
+ putchar ('\n');
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ /* Output a graph to file
145
+ Vertices, edges, arcs less than node_num, edge_num, arc_num are written to the file. Input parameters are
146
+ (graph) (file name) (flag)
147
+ SGRAPH_READ_NODEW 512 // read node weight
148
+ SGRAPH_READ_EDGEW 1024 // read edge weight
149
+ */
150
+ /*
151
+ format of file:(including notifications to make input file)
152
+
153
+ the ith row corresponds to node i-1, and
154
+ ID list of nodes adjacent to i, and having ID > i, for undirected graph
155
+ ID list of nodes adjacent to i by out-going arc of i, for directed graph
156
+ Separator is ",", but graph load routine accepts any letter for
157
+ separator but not a number.
158
+ If the graph has both edges and arcs, write them in two lines separately,
159
+ so a node then uses two lines, and #nodes = #lines/2.
160
+
161
+ == Notifications to make input file ==
162
+ Notice that if 0th line has node 2, and the 2nd line has 0, then there
163
+ will be multiple edge (0,2) and (2,0).
164
+ The read routine does not make error with multiple edges, it is allowed.
165
+
166
+ The ID of nodes begin from 0. After reading graph, node_num is set to
167
+ node_end.
168
+
169
+ Input file example, without weights, E={(0,1),(0,2),(1,1),(1,3),(2,3)}
170
+ ===========
171
+ 1,2
172
+ 1 3
173
+ 3
174
+
175
+ [EOF]
176
+ =========
177
+ Nodes are 0,1, and 2, both edges and arcs exist, with node/edge/arc weights)
178
+ 5000,1,30
179
+ 0,50,1,20,
180
+ 100,1,3
181
+ 2,20
182
+ 200
183
+
184
+ [EOF]
185
+ =======
186
+ where node weights are 5000, 100, 200, and edges and their weights are
187
+ (0,1),30, (1,1),3
188
+ arcs and their weights are (0,0),50, (0,1), 20, (1,2), 20
189
+
190
+ In the case of bipartite graph, write the adjacent-node lists only for
191
+ the node in node set one.
192
+
193
+
194
+ */
195
+
196
+ /* graph load routine. Allocate memory as much as the size of input file.
197
+ parameters are,
198
+ (graph) (file name)
199
+ LOAD_EDGE // read undirected edge from file
200
+ LOAD_ARC // read directed arc from file
201
+ LOAD_BIPARTITE // load bipartite graph
202
+ LOAD_NODEW // read node weight
203
+ LOAD_EDGEW // read edge weight
204
+ */
205
+ /* In the bipartite case, even if the IDs of node set 2 begin from 0, i.e.,
206
+ overlaps with node 1, the routine automatically correct them. */
207
+ /* Directed bipartite graph, all arcs are considered to be from node set 1
208
+ to node set 2. If both directions exist, read as a general graph, and set
209
+ node1_num later in some way. */
210
+ /* The routine compares the maximum node index and #lines, and set #node
211
+ to the larger one. However, if node weight exists, weights will be included
212
+ in the candidates of maximum index, thus in this case we fix #node := #lines.
213
+ In the case of bipartite graph, the routine compares, but the weights of
214
+ non-existing lines will be -1. */
215
+
216
+ /* make the opposite direction edge, for each edge; buffers have to be already doubly allocated */
217
+ void SGRAPH_load_delivery (SGRAPH *G, SETFAMILY *OO, SETFAMILY *MM, QUEUE_ID *c){
218
+ VEC_ID i;
219
+ QUEUE_ID j;
220
+ QUEUE_INT e;
221
+ FLOOP (i, 0, MM->t) c[i] = MM->v[i].t;
222
+ FLOOP (i, 0, MM->t){
223
+ FLOOP (j, 0, c[i]){
224
+ e = MM->v[i].v[j];
225
+ if ( OO->w ) OO->w[e][OO->v[e].t] = MM->w[i][j];
226
+ ARY_INS (OO->v[e], i);
227
+ }
228
+ }
229
+ }
230
+
231
+ /* make the opposite direction edge, for each edge; buffers have to be already doubly allocated */
232
+ void SGRAPH_mk_opposite_edge (SGRAPH *G, QUEUE_ID *c){
233
+ VEC_ID i;
234
+ size_t j, jj;
235
+ j = G->edge.eles; // shift the arrays to insert edges of opposite directions
236
+ BLOOP (i, G->edge.t, 0){
237
+ j -= G->edge.v[i].t+c[i];
238
+ jj = G->edge.v[i].t+1;
239
+ do {
240
+ jj--;
241
+ G->edge.buf[j+i+jj] = G->edge.v[i].v[jj];
242
+ } while ( jj>0 );
243
+ G->edge.v[i].end += c[i];
244
+ G->edge.v[i].v = &G->edge.buf[j+i];
245
+ if ( G->edge.w ){
246
+ memcpy ( &G->edge.buf[j], G->edge.w[i], sizeof(WEIGHT)*G->edge.v[i].t );
247
+ G->edge.w[i] = &G->edge.wbuf[j];
248
+ }
249
+ }
250
+ }
251
+
252
+ /* load edges/arcs (determined by G->flag) from file */
253
+ void SGRAPH_load (SGRAPH *G){
254
+ VEC_ID i;
255
+ QUEUE_ID *c;
256
+ SETFAMILY *F1, *F2;
257
+ if ( G->flag & LOAD_ELE ){
258
+ G->edge.flag |= LOAD_ELE;
259
+ G->in.flag |= LOAD_ELE;
260
+ G->out.flag |= LOAD_ELE;
261
+ }
262
+ if ( G->flag&LOAD_EDGE ){ F1 = F2 = &G->edge; G->edge.flag |= LOAD_DBLBUF; }
263
+ else { F1 = &G->in; F2 = &G->out; }
264
+ F1->fname = G->fname; F1->wfname = F1->wfname;
265
+ SETFAMILY_load (F1);
266
+ // adjact so that #rows and #colums are the same
267
+ if ( !(G->flag&LOAD_BIPARTITE)){
268
+ if ( F1->clms < F1->t ){
269
+ F1->clms = F1->t;
270
+ FLOOP (i, 0, F1->t) F1->v[i].v[F1->v[i].t] = F1->t; // re-set endmark
271
+ } else if ( F1->clms > F1->t ){
272
+ reallocx_ (F1->v, F1->t, F1->clms, INIT_QUEUE, EXIT);
273
+ FLOOP (i, F1->t, F1->clms){
274
+ F1->v[i].v = F1->v[F1->t -1].v +F1->v[F1->t -1].t +1 +(i -(F1->t-1));
275
+ F1->v[i].v[0] = F1->clms;
276
+ } // re-set endmark
277
+ F1->t = F1->clms;
278
+ }
279
+ }
280
+
281
+ calloc2 (c, F1->t, EXIT);
282
+ QUEUE_delivery (NULL, c, NULL, F1->v, NULL, F1->t, F1->t);
283
+
284
+ if ( F1 != F2 ) SETFAMILY_alloc (F2, F1->t, c, F1->t, 0);
285
+ else {
286
+ G->edge.eles *= 2; G->edge.ele_end *= 2;
287
+ SGRAPH_mk_opposite_edge (G, c); // shift the arrays to insert edges of opposite directions
288
+ }
289
+
290
+ SGRAPH_load_delivery (G, F2, F1, c);
291
+ free (c);
292
+ F2->clms = F2->t; FLOOP (i, 0, F2->t) F2->v[i].v[F2->v[i].t] = F2->t; // re-set endmark
293
+
294
+ F1->flag |= G->flag; SETFAMILY_sort (F1);
295
+ if ( F1 != F2 ){ F2->flag |= G->flag; SETFAMILY_sort (F2); }
296
+ print_mes (G, "sgraph: %s ,#nodes %d ,#edges %zd ,#arcs %zd", G->fname, SGRAPH_NODE_NUM(*G), G->edge.eles/2, G->in.eles);
297
+ if ( G->wfname ) print_mes (G, " ,weight file: %s", G->wfname);
298
+ print_mes (G, "\n");
299
+ }
300
+
301
+ /* replace node i by perm[i] */
302
+ void SGRAPH_replace_index (SGRAPH *G, PERM *perm, PERM *invperm){
303
+ QUEUE_INT *x;
304
+ VEC_ID i;
305
+ QUEUE Q;
306
+ WEIGHT *w, ww;
307
+
308
+ FLOOP (i, 0, G->edge.t)
309
+ if ( G->edge.v ){
310
+ MQUE_FLOOP (G->edge.v[i], x) *x = perm[*x];
311
+ ARY_INVPERMUTE (G->edge.v, invperm, Q, G->edge.t, EXIT);
312
+ }
313
+ if ( G->in.v ){
314
+ MQUE_FLOOP (G->in.v[i], x) *x = perm[*x];
315
+ ARY_INVPERMUTE (G->in.v, invperm, Q, G->edge.t, EXIT);
316
+ }
317
+ if ( G->out.v ){
318
+ MQUE_FLOOP (G->out.v[i], x) *x = perm[*x];
319
+ ARY_INVPERMUTE (G->out.v, invperm, Q, G->edge.t, EXIT);
320
+ }
321
+ if ( G->edge.w ) ARY_INVPERMUTE (G->edge.w, invperm, w, G->edge.t, EXIT);
322
+ if ( G->in.w ) ARY_INVPERMUTE (G->in.w, invperm, w, G->edge.t, EXIT);
323
+ if ( G->out.w ) ARY_INVPERMUTE (G->out.w, invperm, w, G->edge.t, EXIT);
324
+ if ( G->node_w ) ARY_INVPERMUTE (G->node_w, invperm, ww, G->edge.t, EXIT);
325
+ G->perm = perm;
326
+ }
327
+
328
+ /* sort the nodes according to the permutation *tmp */
329
+ void SGRAPH_perm_node (SGRAPH *G, PERM *tmp){
330
+ VEC_ID c1=0, c2=G->node1_num, i;
331
+ PERM *perm;
332
+ malloc2 (perm, G->edge.t, {free(tmp);EXIT;});
333
+ FLOOP (i, 0, G->edge.t)
334
+ if ( tmp[i]<G->node1_num ) perm[tmp[i]] = c1++; else perm[tmp[i]] = c2++;
335
+ ARY_INV_PERM_ (tmp, perm, G->edge.t);
336
+ SGRAPH_replace_index (G, perm, tmp);
337
+ free2 (tmp);
338
+ }
339
+
340
+ /* sort the nodes by Q->t, increasing if flag=1, decreasing if flag=-1 */
341
+ void SGRAPH_sort_node (SGRAPH *G, int flag){
342
+ PERM *tmp;
343
+ tmp = qsort_perm_VECt ((VEC *)(G->edge.v), G->edge.t, flag==1?sizeof(QUEUE):-sizeof(QUEUE));
344
+ SGRAPH_perm_node (G, tmp);
345
+ }
346
+
347
+ /* remove all selfloops (assumption, selfloop is at most one for each vertex) */
348
+ void SGRAPH_rm_selfloop (SGRAPH *G){
349
+ QUEUE_INT i, *x;
350
+ FLOOP (i, 0, G->edge.t){
351
+ MQUE_FLOOP (G->edge.v[i], x){
352
+ if ( *x == i ){
353
+ G->edge.v[i].t--;
354
+ while ( x < G->edge.v[i].v + G->edge.v[i].t ){ *x = *(x+1); x++; }
355
+ break;
356
+ }
357
+ }
358
+ }
359
+ }
360
+ #endif
@@ -0,0 +1,174 @@
1
+ /* graph library by array list
2
+ 12/Feb/2002 by Takeaki Uno
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 the codes for the users.
11
+ For the commercial use, please make a contact to Takeaki Uno. */
12
+
13
+ /****************************************************************************/
14
+ /* d = degree of node i := G->edge/in/out.v[i].t
15
+ d = max/min (in/out) degree := VEC_MAXT(d,G->edge.v/in.v/out.v,0,...->t) (VEC_MINT, resp.)
16
+ #nodes := SGRAPH_NODE_NUM(G)
17
+ #edges := G->edge.eles/2
18
+ #arcs := G->in.eles or G->out.eles
19
+ load_node_weight := ARY_LOAD_WEIGHT(G->node_w,WEIGHT,filename,counter,"errormes", EXIT)
20
+ load_node_weight := ARY_LOAD_WEIGHT(G->node_w,WEIGHT,filename,counter,"errormes", EXIT)
21
+
22
+ sort_node by size := SGRAPH_sort_node_iter (G, qsort_perm_VECt ((VEC *)Q, G->node_end, flag)
23
+ sort_node by weight := SGRAPH_sort_node_iter (G, qsort_perm_WEIGHT (w, G->node_end, flag)
24
+ */
25
+ /****************************************************************************/
26
+
27
+ #ifndef _sgraph_h_
28
+ #define _sgraph_h_
29
+
30
+ #include"stdlib2.h"
31
+ #include"vec.h"
32
+
33
+
34
+ /* structure for graph */
35
+ typedef struct {
36
+ unsigned char type; // structure type flag
37
+ char *fname; // input file name
38
+ int flag; // flag for load routine
39
+
40
+ SETFAMILY edge, in, out; // setfamily for edge, in-arc, out-arc
41
+ QUEUE_INT node1_num; // the size of vertex set 1, bipartite case. otherwise 0
42
+ WEIGHT *node_w, *wbuf; // pointer to the node weight array(int)
43
+ PERM *perm; // node permutation (nodes->original)
44
+ char *wfname; // weight file name
45
+ } SGRAPH;
46
+ extern SGRAPH INIT_SGRAPH;
47
+
48
+ #define SGRAPH_NODE_NUM(G) MAX((G).edge.t,(G).in.t)
49
+
50
+ /*************** initialization/termination ***********************/
51
+
52
+ /* initialization, termination, allocate arrays for weights, copy and duplication */
53
+ void SGRAPH_alloc (SGRAPH *G, int node_num, size_t edge_num, size_t arc_num);
54
+ void SGRAPH_cpy (SGRAPH *G2, SGRAPH *G);
55
+ void SGRAPH_end (SGRAPH *G);
56
+
57
+
58
+ /**************** addition/deletion **********************************/
59
+
60
+ /* make/take/remove edge e as connecting vertices u and v,
61
+ and edge (u,v).
62
+ do nothing if when make already existing edge, or delete non-existing edge.
63
+ with range check of parameters */
64
+
65
+ void SGRAPH_edge_mk (SGRAPH *G, QUEUE_INT u, QUEUE_INT v, WEIGHT w);
66
+ void SGRAPH_edge_rm (SGRAPH *G, QUEUE_INT u, QUEUE_INT v);
67
+ void SGRAPH_arc_mk (SGRAPH *G, QUEUE_INT u, QUEUE_INT v, WEIGHT w);
68
+ void SGRAPH_arc_rm (SGRAPH *G, QUEUE_INT u, QUEUE_INT v);
69
+
70
+
71
+ /******************* node/edge sort, and duplication reduction *********************/
72
+
73
+ /* subroutine of sort_edge_list */
74
+ void SGRAPH_sort_edge_list_iter (QUEUE *Q, WEIGHT **w, PERM *invperm, VEC_ID i, int flag);
75
+
76
+ /* sort each array list, increasing if flag=1, and decreasing if flag=-1 */
77
+ void SGRAPH_sort_edge_list (SGRAPH *G, int flag);
78
+
79
+ /* replace node i by perm and invperm */
80
+ void SGRAPH_replace_index (SGRAPH *G, PERM *perm, PERM *invperm);
81
+
82
+ /* sort the nodes by permutation given by tmp */
83
+ PERM *SGRAPH_sort_node_iter (SGRAPH *G, PERM *tmp);
84
+
85
+ /* sort the nodes by degrees, increasing if flag=1, decreasing if flag=-1 */
86
+ PERM *SGRAPH_sort_node_t (SGRAPH *G, QUEUE *Q, int flag);
87
+
88
+ /* sort the nodes by node_weight, increasing if flag=1, decreasing if flag=-1 */
89
+ PERM *SGRAPH_sort_node_w (SGRAPH *G, WEIGHT *w, int flag);
90
+
91
+ /* remove multiple edges/arcs and self loops
92
+ it works only when after applying sort_incident_edges */
93
+ void SGRAPH_simple (SGRAPH *G, int flag);
94
+
95
+
96
+
97
+
98
+ /******************* print routines *************************************/
99
+
100
+
101
+ /* print graph by numbers */
102
+ void SGRAPH_print (SGRAPH *G);
103
+
104
+ /* Write the graph to file. Edges, arcs, and nodes from 0 to node_num/edge_num/arc_num are written to file. Parameters are
105
+ (graph) (file name) (not write edge weight => 0) (not write node weight => 0) */
106
+ void SGRAPH_save (SGRAPH *G, char *fname);
107
+
108
+ /* graph load routine. Allocate memory as much as the size of input file.
109
+ parameters are,
110
+ (graph) (file name) (read edges?) (read arcs?) (read node weights?) (read edge weight?) (bipartite?) */
111
+ /* In the row of each vertex, write only vertices larger than it connected by an edge */
112
+ void SGRAPH_load (SGRAPH *G);
113
+ void SGRAPH_load_node_weight (SGRAPH *G, char *filename);
114
+
115
+ void SGRAPH_rm_selfloop (SGRAPH *G);
116
+ /*
117
+ format of file:(including notifications to make input file)
118
+
119
+ the ith row corresponds to node i-1, and
120
+ ID list of nodes adjacent to i, and having ID > i, for undirected graph
121
+ ID list of nodes adjacent to i by out-going arc of i, for directed graph
122
+ Separator is ",", but graph load routine accepts any letter for
123
+ separator but not a number.
124
+ If the graph has both edges and arcs, write them in two lines separately,
125
+ so a node then uses two lines, and #nodes = #lines/2.
126
+
127
+ == Notifications to make input file ==
128
+ Notice that if 0th line has node 2, and the 2nd line has 0, then there
129
+ will be multiple edge (0,2) and (2,0).
130
+ The read routine does not make error with multiple edges, it is allowed.
131
+
132
+ The ID of nodes begin from 0. After reading graph, node_num is set to
133
+ node_end.
134
+
135
+ Input file example, without weights, E={(0,1),(0,2),(1,1),(1,3),(2,3)}
136
+ ===========
137
+ 1,2
138
+ 1 3
139
+ 3
140
+
141
+ [EOF]
142
+ =========
143
+ Nodes are 0,1, and 2, both edges and arcs exist, with node/edge/arc weights)
144
+ 5000,1,30
145
+ 0,50,1,20,
146
+ 100,1,3
147
+ 2,20
148
+ 200
149
+
150
+ [EOF]
151
+ =======
152
+ where node weights are 5000, 100, 200, and edges and their weights are
153
+ (0,1),30, (1,1),3
154
+ arcs and their weights are (0,0),50, (0,1), 20, (1,2), 20
155
+
156
+ In the case of bipartite graph, write the adjacent-node lists only for
157
+ the node in node set one.
158
+
159
+
160
+ */
161
+
162
+
163
+ /*************************************************************************/
164
+
165
+
166
+ #endif
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+