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