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,864 @@
1
+ /* library for standard macros and functions
2
+ by Takeaki Uno 2/22/2002 e-mail: uno@nii.jp
3
+ homepage: http://research.nii.ac.jp/~uno/index.html */
4
+ /* This program is available for only academic use, basically.
5
+ Anyone can modify this program, but he/she has to write down
6
+ the change of the modification on the top of the source code.
7
+ Neither contact nor appointment to Takeaki Uno is needed.
8
+ If one wants to re-distribute this code, 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 _stdlib2_h_
13
+ #define _stdlib2_h_
14
+
15
+ #include<stdlib.h>
16
+ #include<stdio.h>
17
+ #include<string.h>
18
+ #include<math.h>
19
+ #include<time.h>
20
+ #include<stdarg.h>
21
+
22
+ #ifdef USE_SIMD
23
+ #include<emmintrin.h> // use MMX-SSE2;
24
+ #endif
25
+
26
+
27
+ #if defined(__cplusplus) && defined(__GNUC__)
28
+ #define _cplusplus_
29
+ #endif
30
+
31
+ // for visual C++ (use typeid insead of typeof)
32
+ #ifdef _MSC_VER
33
+ #define typeof(a) typeid(a).name()
34
+ #endif
35
+
36
+ #ifdef MULTI_CORE
37
+ #include <sys/types.h>
38
+ #include <pthread.h>
39
+ #endif
40
+ #define CORE_MAX 16
41
+
42
+ /* comment out the following line if no error check is needed */
43
+ //#define ERROR_CHECK
44
+ /* comment out the following if exit is not needed after each error routine */
45
+ //#define ERROR_RET
46
+
47
+ #ifdef ERROR_RET // definition of the process for errors
48
+ #define EXIT return
49
+ #define EXIT0 return(0)
50
+ #else
51
+ #define EXIT exit(1)
52
+ #define EXIT0 exit(1)
53
+ #endif
54
+
55
+ // for dealing with files more than 2GB
56
+ #define _LARGEFILE_SOURCE
57
+ #define _FILE_OFFSET_BITS 64
58
+
59
+ #ifndef NULL
60
+ #define NULL 0
61
+ #endif
62
+
63
+ #ifdef MTWISTER
64
+ #define RANDOM ((long)(dsfmt_gv_genrand_close_open()*2147483648LL))
65
+ #define RAND1 dsfmt_gv_genrand_close_open()
66
+ #define RAND_INIT dsfmt_gv_init_gen_rand(514346237)
67
+ #elif defined(__GNUC__)
68
+ #define RANDOM xor128()
69
+ #define RAND1 ((double)xor128())/4294967296.0
70
+ #define RAND_INIT xor128()
71
+ #else
72
+ #define RANDOM rand()
73
+ #define RAND1 ((double)rand())/2147483648.0
74
+ #define RAND_INIT srand(0)
75
+ #endif
76
+
77
+
78
+ // 64bit integer
79
+ #ifdef LONG_32
80
+ #define LONG int
81
+ #define LONGHUGE INTHUGE
82
+ #define LONGF "%d"
83
+ #elif !defined(LONG)
84
+ #define LONG long long
85
+ #define LONGHUGE 9000000000000000000LL
86
+ #define LONGF "%lld"
87
+ #endif
88
+
89
+ // actual int (most proper sized integer, for the processor)
90
+ #ifdef INT_64
91
+ #define INT LONG
92
+ #define INTF LONGF
93
+ #else
94
+ #define INT int
95
+ #define INTF "%d"
96
+ #endif
97
+
98
+ #ifndef FILE_LONG
99
+ #define FILE_LONG LONG
100
+ #define FILE_LONGHUGE LONGHUGE
101
+ #define FILE_LONGF LONGF
102
+ #endif
103
+
104
+ #define UINTHUGE 4000000000U
105
+ #define INTHUGE 2000000000
106
+ #define USHORTHUGE 32767
107
+ #define SHORTHUGE 65535
108
+ #define DOUBLEHUGE 999999999999999999999999999999.9
109
+ #define ISEQUAL_VALUE 0.0000001
110
+ #define ISEQUAL_VALUE2 0.00001
111
+ #define PI 3.1415926535897932384647950288
112
+ #define PI_INT 31416
113
+ #define NPE 2.718281828459045235360287471352
114
+ #define NPE_INT 27183
115
+
116
+ #ifndef WEIGHT
117
+ #ifdef WEIGHT_DOUBLE
118
+ #define WEIGHT double
119
+ #define WEIGHTHUGE DOUBLEHUGE
120
+ #define WEIGHTF "%f"
121
+ #else // define WEIGHT by int if it's undefined
122
+ #define WEIGHT int
123
+ #define WEIGHTHUGE INTHUGE
124
+ #define WEIGHTF "%d"
125
+ #endif
126
+ #endif
127
+
128
+ #ifndef PERM
129
+ #ifdef PERM_LONG
130
+ #define PERM LONG
131
+ #define PERMHUGE LONGHUGE
132
+ #define PERMF LONGF
133
+ #else
134
+ #define PERM int
135
+ #define PERMHUGE INTHUGE
136
+ #define PERMF "%d"
137
+ #endif
138
+ #endif
139
+
140
+ // for loading/writing file from array (emulation)
141
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
142
+ #define _NO_MAIN_
143
+ extern void *__load_from_memory__, *__load_from_memory_org__, *__load_from_memory_org2__;
144
+ extern char *__write_to_memory__, *__write_to_memory_org__, *__write_to_memory_next__;
145
+ #define FILE2_LOAD_FROM_MEMORY_ENDTYPE int
146
+ #ifndef FILE2_LOAD_FROM_MEMORY_END
147
+ #define FILE2_LOAD_FROM_MEMORY_END INTHUGE
148
+ #endif
149
+ #define FILE2_WRITE_MEMORY(a,b) \
150
+ do{ \
151
+ if( __write_to_memory__ >= __write_to_memory_next__ ){ \
152
+ common_size_t = __write_to_memory__ -__write_to_memory_org__; \
153
+ realloc2 (__write_to_memory_org__, common_size_t*2+ 1024, EXIT); \
154
+ __write_to_memory__ = __write_to_memory_org__ + common_size_t; \
155
+ __write_to_memory_next__ = __write_to_memory_org__ + common_size_t*2+512; \
156
+ } \
157
+ *((a *)__write_to_memory__) = b; \
158
+ __write_to_memory__ = (char *)(((a *)__write_to_memory__) +1); \
159
+ }while(0)
160
+ #endif
161
+
162
+
163
+ extern size_t common_size_t;
164
+ extern INT common_INT, common_INT2;
165
+ extern char *common_pnt, *common_charp;
166
+ extern FILE *common_FILE;
167
+ extern WEIGHT common_WEIGHT, *common_WEIGHTp;
168
+ extern char *ERROR_MES;
169
+ extern int print_time_flag;
170
+ extern char common_comm[], common_comm2[], *common_argv[];
171
+ typedef struct {
172
+ int i1, i2, i3, i4, i5, i6, i7, i8, i9;
173
+ LONG l1, l2, l3, l4, l5, l6, l7, l8, l9;
174
+ double d1, d2, d3, d4, d5, d6, d7, d8, d9;
175
+ char *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9;
176
+ void *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
177
+ } PARAMS;
178
+ extern PARAMS internal_params;
179
+
180
+
181
+ /* lock&unlock for multi-core mode */
182
+ #ifdef MULTI_CORE
183
+ extern int SPIN_LOCK_dummy;
184
+ #define SPIN_LOCK(b,a) (SPIN_LOCK_dummy=(((b)>1)&&pthread_spin_lock(&(a))))
185
+ #define SPIN_UNLOCK(b,a) (SPIN_LOCK_dummy=(((b)>1)&&pthread_spin_unlock(&(a))))
186
+ #else
187
+ #define SPIN_LOCK(b,a)
188
+ #define SPIN_UNLOCK(b,a)
189
+ #endif
190
+
191
+ #define TYPE_VEC 1
192
+ #define TYPE_MAT 2
193
+ #define TYPE_SVEC 3
194
+ #define TYPE_SMAT 4
195
+ #define TYPE_QUEUE 5
196
+ #define TYPE_SETFAMILY 6
197
+ #define TYPE_TRSACT 7
198
+ #define TYPE_ALIST 8
199
+ #define TYPE_MALIST 9
200
+ #define TYPE_AGRAPH 10
201
+ #define TYPE_SGRAPH 11
202
+ #define TYPE_AHEAP 12
203
+ #define TYPE_BASE 13
204
+ #define TYPE_FSTAR 14
205
+ #define TYPE_SEQ 15
206
+ #define TYPE_BARRAY 16
207
+
208
+ #define TYPE_FILE2 32
209
+
210
+ #define ADDR_FLOOR16(x) do{common_charp=((char *)x)+15;x=(typeof(x))(common_charp-(((size_t)common_charp)&15));}while(0)
211
+ double SQRT(double x);
212
+
213
+ /* random */
214
+ #define rnd(a) (random()%(a))
215
+ #define prob(a) ((random()%65536)<(int)((a)*65536.0))
216
+
217
+ #define MARK 1
218
+ #define UNMARK 0
219
+ #define TRUE 1
220
+ #define FALSE 0
221
+
222
+ /* equal/inequal with allowing numerical error for double */
223
+ #define ISEQUAL(a,b) ((a)-(b)<ISEQUAL_VALUE&&(b)-(a)<ISEQUAL_VALUE)
224
+ #define ISGREAT(a,b) ((a)-(b)>ISEQUAL_VALUE)
225
+ #define ISLESS(a,b) ((b)-(a)>ISEQUAL_VALUE)
226
+ #define RANGE(a,b,c) (((a)<=(b))&&((b)<=(c)))
227
+ #define BITRM(a,b) ((a)-=((a)&(b)));
228
+
229
+ /* macro for getting maximum/minimum of two values */
230
+ #define MAX(a,b) (((a)>(b))?(a):(b))
231
+ #define ENMAX(a,b) ((a)=(((a)>(b))?(a):(b)))
232
+ #define MIN(a,b) (((a)<(b))?(a):(b))
233
+ #define ENMIN(a,b) ((a)=(((a)<(b))?(a):(b)))
234
+
235
+ /* error routine */
236
+ #define error(mes,x) do{ERROR_MES=mes;fprintf(stderr,"%s\n",mes);x;}while(0)
237
+ #define error_num(mes,n,x) do{ERROR_MES=mes;fprintf(stderr,"%s: %g\n",mes,(double)(n));x;}while(0)
238
+ #define error_range(f,x,y,mes) do{if(!RANGE((x),(f),(y))){ERROR_MES=mes;fprintf(stderr,"%s: %g\n",mes,(double)(f));EXIT;}}while(0)
239
+ #define error_str(mes,s,x) do{ERROR_MES=mes;fprintf(stderr,"%s: %s\n",mes,s);x;}while(0)
240
+ #define print_err(...) fprintf(stderr,__VA_ARGS__)
241
+ #define print_mes(S,...) do{if(((S)->flag)&1)fprintf(stderr,__VA_ARGS__);}while(0)
242
+ //#define print_fname(s,fname,...) do{if(fname)fprintf(stderr,s,fname,__VA_ARGS__);}while(0)
243
+ #define print_fname(s,fname,...) do{if(fname)fprintf(stderr,s,fname);}while(0)
244
+ #define mfree(...) mfree_(NULL, __VA_ARGS__, (void *)1)
245
+ #define mfree2(...) mfree2_(NULL, __VA_ARGS__, (void *)1)
246
+
247
+
248
+ /* basic array operations and loops */
249
+ #define ARY_FILL(f,start,end,c) do{for(common_size_t=(size_t)(start);common_size_t<(size_t)(end);common_size_t++)(f)[common_size_t]=(c);}while(0)
250
+ //#define ARY_FLOOP(V,i,x) for( (i)=0,x=(V).v[0] ; (i)<(V).t ; (i)++,x=(V).v[i])
251
+ //#define ARY_BLOOP(V,i,x) for( (i)=(V).t-1,x=i>0?(V).v[i]:0 ; (i)>=0 ; (i)--,(x)=(i)>0?(V).v[i]:0)
252
+ #define FLOOP(i,x,y) for ((i)=(x) ; (i)<(y) ; (i)++)
253
+ #define BLOOP(i,x,y) for ((i)=(x) ; ((i)--)>(y) ; )
254
+ #define MLOOP(z,x,M) for ((z)=(x) ; *(z)<(M) ; (z)++)
255
+ /* binary search: return maximum index no larger than c */
256
+ #define BIN_SRCH(x,a,s,t,c) \
257
+ do {\
258
+ x=s; common_size_t=t; while ( x<common_size_t-1 ){\
259
+ if ( a[(x+common_size_t)/2] <= c ) x = (x+common_size_t)/2; else common_size_t = (x+common_size_t)/2;\
260
+ } while (0)\
261
+
262
+ /* allocate memory, and exit with error message if fault */
263
+ #ifdef _cplusplus_
264
+ #define malloc2(f,b,x) do{if(!((f)=(typeof(f))malloc(((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
265
+ #define calloc2(f,b,x) do{if(!((f)=(typeof(f))calloc(sizeof((f)[0]),b))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
266
+ #define realloc2(f,b,x) do{if(!(f=(typeof(f))realloc(f,((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
267
+ #else
268
+ #define malloc2(f,b,x) do{if(!((f)=malloc(((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d" #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
269
+ #define calloc2(f,b,x) do{if(!((f)=calloc(sizeof((f)[0]),b))){fprintf(stderr,"memory allocation error: line %d: " #f " (" LONGF " byte)\n",__LINE__,(LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
270
+ #define realloc2(f,b,x) do{if(!(f=realloc(f,((size_t)sizeof((f)[0]))*(b)))){fprintf(stderr,"memory allocation error: line %d: " #f " (" LONGF " byte)\n",__LINE__, (LONG)((LONG)sizeof((f)[0])*(b)));ERROR_MES="out of memory";x;}}while(0)
271
+ #endif
272
+
273
+ #define malloc2d(f,b,d,x) do{malloc2(f,b,x);malloc2((f)[0],(b)*(d)+2,{free2(f);x;});FLOOP(common_size_t,0,(size_t)b)(f)[common_size_t]=&((f)[0][common_size_t*(d)]);}while(0)
274
+ #define calloc2d(f,b,d,x) do{malloc2(f,b,x);calloc2((f)[0],((size_t)(b))*((size_t)(d))+2,{free2(f);x;});FLOOP(common_size_t,0,(size_t)b)(f)[common_size_t]=&((f)[0][common_size_t*(d)]);}while(0)
275
+
276
+ /* reallocate memory and expand the memory size */
277
+ #define reallocx_(f,end,end2,e,x) do{realloc2(f,end2,x);FLOOP(common_size_t,(size_t)end,(size_t)end2)(f)[common_size_t]=(e);}while(0)
278
+ #define reallocx(f,end,i,e,x) do{if((size_t)(i)>=(size_t)(end)){reallocx_(f,end,MAX((end)*2+16,(i)+1),e,x);end=MAX((end)*2,(i)+1);}}while(0)
279
+ #define reallocz(f,end,i,x) do{if((size_t)(i)>=(size_t)(end)){end=MAX((end)*2,(i)+1);realloc2(f,end,x);}}while(0)
280
+ #define realloc_set(f,end,i,e,ee,x) do{if((size_t)(i)>=(size_t)(end)){reallocx_(f,end,MAX((end)*2+16,(i)+1),e,x);end=MAX((end)*2,(i)+1);}f[i]=ee;}while(0)
281
+ #define realloci(f,i,x) do{if(!((i)&((i)-1)))realloc2(f,(i)*2+1,x);}while(0)
282
+
283
+ /* basic array operations */
284
+ #define ARY_REALLOCX(f,i,e,x) reallocz((f).v,(f).end,i,e,x)
285
+ #define ARY_REALLOCZ(f,i,x) reallocz((f).v,(f).end,i,x)
286
+ #define ARY_DUP(f,p,end,x) do{malloc2(f,end,x);memcpy(f,p,sizeof(*(f))*(end));}while(0)
287
+ #define ARY_MAX(m,i,f,x,y) do{(m)=(f)[x];(i)=(x);FLOOP(common_INT,(x)+1,(y))if((m)<(f)[common_INT]){(i)=common_INT;(m)=(f)[i];}}while(0)
288
+ #define ARY_MIN(m,i,f,x,y) do{(m)=(f)[x];(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)>(f)[common_INT]){(i)=common_INT;(m)=(f)[i];}}while(0)
289
+ #define ARY_SUM(f,v,x,y) do{(f)=0;FLOOP(common_INT,x,y)(f)+=(v)[common_INT];}while(0)
290
+ #define ARY_REV(S,start,end,tmp) do{FLOOP(common_size_t,0,((end)-(start))/2){(tmp)=(S)[(start)+common_size_t];(S)[(start)+common_size_t]=(S)[(end)-1-common_size_t];(S)[(end)-1-common_size_t]=tmp;}}while(0)
291
+ #define ARY_NORM(f,v,b) do{(f)=0;FLOOP(common_INT,0,b)(f)+=(v)[common_INT]*(v)[common_INT];(f)=sqrt(f);}while(0)
292
+ #define ARY_NORMALIZE(v,b) do{ARY_NORM(common_double,v,b);FLOOP(common_INT,0,b)(v)[common_INT]/=common_double;}while(0)
293
+ #define ARY_INPRO(f,u,v,b) do{(f)=0;for (common_INT=0 ; common_INT<(b)-3 ; common_INT+=4) (f)+=(u)[common_INT]*(v)[common_INT] + (u)[common_INT+1]*(v)[common_INT+1] + (u)[common_INT+2]*(v)[common_INT+2] + (u)[common_INT+3]*(v)[common_INT+3]; if (common_INT+1<(b)){(f)+=(u)[common_INT]*v[common_INT]+(u)[common_INT+1]*(v)[common_INT+1]; if (common_INT+2<(b)) (f)+=(u)[common_INT+2]*(v)[common_INT+2];} else if (common_INT<(b)) (f)+=(u)[common_INT]*(v)[common_INT];}while(0)
294
+ #define ARY_DIST(f,u,v,b) do{(f)=0;for (common_INT=0 ; common_INT<(b) ; common_INT++) (f)+=((u)[common_INT]-(v)[common_INT])*((u)[common_INT]-(v)[common_INT]); (f)=sqrt(f);}while(0)
295
+
296
+
297
+ /* macros for permutation arrays */
298
+ #define ARY_INIT_PERM(f,end) do{FLOOP(common_INT,0,(INT)end)(f)[common_INT]=common_INT;}while(0)
299
+ #define ARY_INV_PERM_(f,p,end) do{ARY_FILL(f,0,end,-1);FLOOP(common_INT,0,end)if((p)[common_INT]>=0&&(p)[common_INT]<(end))(f)[(p)[common_INT]]=common_INT;}while(0)
300
+ #define ARY_INV_PERM(f,p,end,x) do{malloc2(f,end,x);ARY_INV_PERM_(f,p,end);}while(0)
301
+ #define ARY_RND_PERM_(f,end) do{(f)[0]=0;FLOOP(common_INT,1,end){common_INT2=rnd(common_INT+1);(f)[common_INT]=(f)[common_INT2];(f)[common_INT2]=common_INT;}}while(0)
302
+ #define ARY_RND_PERM(f,end,x) do{malloc2(f,end,x);ARY_RND_PERM_(f,end);}while(0)
303
+ /* permute f so that f[i]=f[p[i]] (inverse perm). p will be destroyed (filled by end). s is temporary variable of type same as f[] */
304
+ #define ARY_INVPERMUTE_(f,p,s,end) do{ FLOOP(common_INT,0,end){ if ( (p)[common_INT]<(end) ){ (s)=(f)[common_INT]; do { common_INT2=common_INT; common_INT=(p)[common_INT]; (f)[common_INT2]=(f)[common_INT]; (p)[common_INT2]=end; }while ( (p)[common_INT]<(end) ); (f)[common_INT2] = (s);}}}while(0)
305
+ /* permute f so that f[i]=f[p[i]] (inverse perm). not destroy p by allocating tmp memory, s is temporary variable of type same as f[] */
306
+ #define ARY_INVPERMUTE(f,p,s,end,x) do{ calloc2(common_pnt,end,x);FLOOP(common_INT,0,end){ if ( common_pnt[common_INT]==0 ){ (s)=(f)[common_INT]; do{ common_INT2=common_INT; common_INT=(p)[common_INT]; (f)[common_INT2]=(f)[common_INT]; common_pnt[common_INT2]=1; }while( common_pnt[common_INT]==0 ); (f)[common_INT2] = (s); }} free(common_pnt); }while(0)
307
+ //#define ARY_PERM(f,p,s,mark,end) do{FLOOP(common_size_t,0,end){ }}while(0)
308
+
309
+ /* macros for printing (writing to file) arrays */
310
+ #define ARY_PRINT(f,x,y,a) do{FLOOP(common_size_t,x,y)printf(a,(f)[common_size_t]);printf("\n");}while(0)
311
+ #define ARY_FPRINT(fp,f,x,y,a) do{FLOOP(common_size_t,(size_t)x,(size_t)y)fprintf((FILE *)fp,a,(f)[common_size_t]);fputc('\n',(FILE *)fp);}while(0)
312
+
313
+ #define ST_MAX(m,i,S,a,x,y) do{(m)=(S)[x].a;(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)<(S)[common_INT].a){(i)=common_INT;(m)=(S)[i].a;}}while(0)
314
+ #define ST_MIN(m,i,S,a,x,y) do{(m)=(S)[x].a;(i)=(x);FLOOP(common_INT,(x)+1,y)if((m)>(S)[common_INT].a){(i)=common_INT;(m)=(S)[i].a;}}while(0)
315
+ #define ST_SUM(k,S,a,x,y) do{(k)=0;FLOOP(common_INT,x,y)(k)+=(S)[common_INT].a;}while(0)
316
+ #define ST_FILL(S,a,start,end,c) do{for(common_INT=(start);common_INT<(end);common_INT++)(S)[common_INT].a = (c);}while(0)
317
+ #define ST_PRINT(S,a,start,end,form) do{FLOOP(common_size_t,start,end)printf(form,(S)[common_size_t].a );printf("\n");}while(0)
318
+
319
+
320
+ /* macros for QUE type structure (have .s, .t, .v) */
321
+ #define QUE_EXP(f,a,x) do{reallocx((f).v,a,(f).end,(f).t,e,x);}while(0)
322
+ #define QUE_INS(f,b) do{(f).v[(f).t++]=(b);}while(0)
323
+ #define QUE_INSZ(f,a,x) do{reallocz((f).v,(f).end,(f).t+1,x);QUE_INS(f,a);}while(0)
324
+ #define QUE_INIT_PERM(f,end) do{ARY_INIT_PERM((f).v,(end));(f).t=(end);(f).s=0;}while(0)
325
+
326
+ /* a macro for open files with exiting if an error occurs */
327
+ #ifdef _MSC_
328
+ #define fopen2(f,a,b,x) do{fopen_s(&f,a,b);if(!f){ERROR_MES="file open error";fprintf(stderr,"file open error: file name %s, open mode %s\n",a,b);x;}}while(0)
329
+ #else
330
+ #define fopen2(f,a,b,x) do{if(!((f)=fopen(a,b))){ERROR_MES="file open error";fprintf(stderr,"file open error: file name %s, open mode %s\n",a,b);x;}}while(0)
331
+ #endif
332
+
333
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
334
+ #define FILE2_open(f,a,b,x) do{__load_from_memory__=__load_from_memory_org__;(f).fp=NULL;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
335
+ #define FILE2_open_(f,a,x) do{__load_from_memory__=__load_from_memory_org__;(f).fp=a;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
336
+ #else
337
+ #define FILE2_open(f,a,b,x) do{if(a)fopen2((f).fp,a,b,x);else(f).fp=NULL;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
338
+ #define FILE2_open_(f,a,x) do{(f).fp=a;malloc2((f).buf_org,FILE2_BUFSIZ+1,x);(f).buf=(f).buf_org;(f).buf_end=(f).buf_org-1;(f).bit=0;*(f).buf=0;}while(0)
339
+ #endif
340
+
341
+ /* macros for allocating memory with exiting if an error occurs */
342
+ #define free2(a) do{if(a){free(a);(a)=NULL;}}while(0)
343
+ #define free2d(a) do{if(a){free2((a)[0]);free(a);(a)=NULL;}}while(0)
344
+ #ifdef _FILE2_LOAD_FROM_MEMORY_
345
+ #define fclose2(a) do{if(a){(a)=NULL;}}while(0)
346
+ #else
347
+ #define fclose2(a) do{if(a){fclose(a);(a)=NULL;}}while(0)
348
+ #endif
349
+ /* macros for reading integers from file, d=0 read one-line, d=1 read all file */
350
+ //#define ARY_SCAN(k,a,fp,d) do{(k)=0;do{do{FILE2_read_##a(&(fp));}while((FILE_err&6)==8-(d)*4);if(FILE_err&(4-2*(d)))break;(k)++;}while((FILE_err&(3-(d)))==0);}while(0)
351
+ #define ARY_SCAN(num,type,fp,d) do{(num)=0;do{do{FILE2_read_##type(&(fp));}while((FILE_err&((d)*5))==5);if(RANGE(5+(int)(d),FILE_err,6))break;(num)++;}while((FILE_err&(3-(int)(d)))==0);}while(0)
352
+ #define ARY_READ_LINE(f,type,num,fp) do{(num)=0;do{(f)[num]=FILE2_read_##type(&(fp));(num)+=(FILE_err&4)?0:1;}while((FILE_err&3)==0);}while(0)
353
+ #define ARY_READ(f,type,num,fp) do{FLOOP(common_size_t,0,(size_t)num){do{(f)[common_size_t]=FILE2_read_##type(&(fp));}while((FILE_err&6)==4);if(FILE_err&2)break;}}while(0)
354
+ #define ARY_LOAD(f,type,num,fname,d,x) do{FILE2_open(common_FILE2,fname,"r",x);ARY_SCAN(num,type,common_FILE2,d);malloc2(f,(num)+1,x);FILE2_reset(&common_FILE2);ARY_READ(f,type,num,common_FILE2);FILE2_close(&common_FILE2);}while(0)
355
+ #define ARY_WRITE(n,f,num,q,x) do{fopen2(common_FILE,n,"w",x);ARY_FPRINT(common_FILE,f,0,num,q);fclose(common_FILE);}while(0)
356
+
357
+ #ifndef MQUE_ONEMORE
358
+ #define MQUE_ONEMORE 1
359
+ #endif
360
+
361
+ /* macros for generalized queue; end mark is necessary for INTSEC */
362
+ #define MQUE_FLOOP(V,z) for((z)=(V).v;(z)<(V).v+(V).t ; (z)++)
363
+ #define MQUE_FLOOP2(V,z,zz) for((z)=(V).v,(zz)=(z)+(V).t;(z)<(zz) ; (z)++)
364
+ #define MQUE_BLOOP(V,z) for((z)=(V).v+(V).t-1;(z)>=(V).v ; (z)--)
365
+ #define MQUE_SLOOP(V,z) for((z)=(V).v+(V).s;(z)<(V).v+(V).t ; (z)++)
366
+ #define MQUE_SLOOP2(V,z,zz) for((z)=(V).v+(V).s,(zz)=(z)+(V).t;(z)<(zz) ; (z)++)
367
+ #define MQUE_SBLOOP(V,z) for((z)=(V).v+(V).t-1;(z)>=(V).v+(V).s ; (z)--)
368
+
369
+ #ifdef _cplusplus_
370
+ #define MQUE_FLOOP_(V,z,s) for((z)=(V).v ; (char *)(z)<((char *)(V).v)+(V).t*(s) ; (z)=(typeof(z))(((char *)(z))+(s)))
371
+ #else
372
+ #define MQUE_FLOOP_(V,z,s) for((z)=(V).v ; (char *)(z)<((char *)(V).v)+(V).t*(s) ; (z)=(void *)(((char *)(z))+(s)))
373
+ #endif
374
+
375
+ #define MQUE_MLOOP(V,z,M) for((z)=(V).v; *((QUEUE_INT *)z)<(M) ; (z)++)
376
+
377
+ /// !!! errr MQUE_INTSEC !!!!!
378
+ #define MQUE_INTSEC(f,U,V) do{\
379
+ common_INT=0;(f)=0;\
380
+ FLOOP(common_INT2,0,(U).t){\
381
+ while(*((QUEUE_INT *)(&((V).v[common_INT])))<*((QUEUE_INT *)(&((U).v[common_INT2])))&&common_INT<(V).t){ \
382
+ if (++common_INT >= (V).t) break;\
383
+ }if(*((QUEUE_INT *)(&((V).v[common_INT])))==*((QUEUE_INT *)(&((U).v[common_INT2]))))(f)++;\
384
+ }}while(0)
385
+ #define MQUE_UNION(f,U,V) do{MQUE_INTSEC(f,U,V);(f)=(U).t+(V).t-(f);}while(0)
386
+ #define MQUE_DIF(f,U,V) do{MQUE_INTSEC(f,U,V);(f)=(U).t+(V).t-(f)-(f);}while(0)
387
+ #define MQUE_RM_DUP(V) do{\
388
+ if((V).t>1){\
389
+ common_INT=1;\
390
+ FLOOP(common_INT2,1,(V).t){\
391
+ if ( *((QUEUE_INT *)(&((V).v[common_INT2-1]))) != *((QUEUE_INT *)(&((V).v[common_INT2]))) ) (V).v[common_INT++]=(V).v[common_INT2];\
392
+ } (V).t=common_INT;\
393
+ }\
394
+ }while(0)
395
+
396
+ #define MQUE_UNIFY(V,a) do{\
397
+ if((V).t>1){\
398
+ common_INT=0;\
399
+ FLOOP(common_INT2,1,(V).t){\
400
+ if ( *((QUEUE_INT *)(&((V).v[common_INT2-1]))) != *((QUEUE_INT *)(&((V).v[common_INT2]))) ) (V).v[++common_INT]=(V).v[common_INT2];\
401
+ else *((a*)(((QUEUE_INT *)(&((V).v[common_INT2])))+1)) += *((a*)(((QUEUE_INT *)(&((V).v[common_INT2])))+1));\
402
+ } (V).t=common_INT+1;\
403
+ }}while(0)
404
+
405
+
406
+
407
+
408
+ #ifndef VEC_VAL
409
+ #ifdef VEC_VAL_CHAR
410
+ #define VEC_VAL char
411
+ #define VEC_VAL2 LONG
412
+ #define VEC_VAL_END 128
413
+ #define VEC_VAL2_END LONGHUGE
414
+ #define VEC_VALF "%hhd"
415
+ #elif defined(VEC_VAL_UCHAR)
416
+ #define VEC_VAL unsigned char
417
+ #define VEC_VAL2 LONG
418
+ #define VEC_VAL_END 256
419
+ #define VEC_VAL2_END LONGHUGE
420
+ #define VEC_VALF "%hhu"
421
+ #elif defined(VEC_VAL_INT)
422
+ #define VEC_VAL int
423
+ #define VEC_VAL2 LONG
424
+ #define VEC_VAL_END INTHUGE
425
+ #define VEC_VAL2_END LONGHUGE
426
+ #define VEC_VALF "%d"
427
+ #else
428
+ #define VEC_VAL double
429
+ #define VEC_VAL2 double
430
+ #define VEC_VAL_END DOUBLEHUGE
431
+ #define VEC_VAL2_END DOUBLEHUGE
432
+ #define VEC_VALF "%f"
433
+ #endif
434
+ #endif
435
+
436
+ #ifndef VEC_ID
437
+ #ifdef VEC_ID_LONG
438
+ #define VEC_ID LONG
439
+ #define VEC_ID_END LONGHUGE
440
+ #define VEC_IDF LONGF
441
+ #else
442
+ #define VEC_ID int
443
+ #define VEC_ID_END INTHUGE
444
+ #define VEC_IDF "%d"
445
+ #endif
446
+ #endif
447
+
448
+ /* vector */
449
+ typedef struct {
450
+ unsigned char type; // mark to identify type of the structure
451
+ VEC_VAL *v;
452
+ VEC_ID end;
453
+ VEC_ID t;
454
+ } VEC;
455
+
456
+ extern VEC INIT_VEC;
457
+ extern PERM common_PERM, *common_PERMp;
458
+ extern VEC_VAL common_VEC_VAL, *common_VEC_VALp;
459
+ extern VEC_ID common_VEC_ID;
460
+
461
+ /* tranpose the matrix ; counting/transpose/memory_allocate */
462
+ #define MQUE_DELIVERY_CNT(c,jump,f,y,M) do{ \
463
+ FLOOP(common_VEC_ID, 0, (f).t){ \
464
+ MQUE_MLOOP( (f).v[common_VEC_ID], y, M){ \
465
+ if( (c)[*((QUEUE_INT *)y)] == 0 ) QUE_INS(jump, *((QUEUE_INT *)y)); \
466
+ (c)[*((QUEUE_INT *)y)]++; \
467
+ } \
468
+ }}while(0)
469
+ #define MQUE_DELIVERY(occ,jump,f,y,M) do{ \
470
+ FLOOP (common_VEC_ID, 0, (f).t){ \
471
+ MQUE_MLOOP ((f).v[common_VEC_ID], y, M){ \
472
+ if( (occ)[*((QUEUE_INT *)y)].t == 0 ) QUE_INS( jump, *((QUEUE_INT *)y)); \
473
+ QUE_INS( (occ)[*((QUEUE_INT *)y)], common_VEC_ID); \
474
+ } \
475
+ }}while(0)
476
+
477
+ // allocate QUEUE of QUEUE, according to rows (cells of "ext" will be add to each row)
478
+ #ifdef _cplusplus_
479
+ #define MQUE_ALLOC(Q,rows,rowt,unit,ext,x) do{ \
480
+ common_size_t=0; \
481
+ FLOOP (common_VEC_ID, 0, rows) common_size_t += rowt[common_VEC_ID]; \
482
+ calloc2 (Q, (rows)+1, x); \
483
+ malloc2 (common_pnt, (common_size_t+(rows)*(ext)+2)*((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit)), {free(Q);x;}); \
484
+ FLOOP (common_VEC_ID, 0, rows){ \
485
+ (Q)[common_VEC_ID].end = rowt[common_VEC_ID]; \
486
+ (Q)[common_VEC_ID].v = (typeof((Q)[common_VEC_ID].v))common_pnt; \
487
+ common_pnt += ((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit))*(rowt[common_VEC_ID]+(ext));\
488
+ }}while(0)
489
+ #else
490
+ #define MQUE_ALLOC(Q,rows,rowt,unit,ext,x) do{ \
491
+ common_size_t=0; \
492
+ FLOOP (common_VEC_ID, 0, rows) common_size_t += rowt[common_VEC_ID]; \
493
+ calloc2 (Q, (rows)+1, x); \
494
+ malloc2 (common_pnt, (common_size_t+(rows)*(ext)+2)*((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit)), {free(Q);x;}); \
495
+ FLOOP (common_VEC_ID, 0, rows){ \
496
+ (Q)[common_VEC_ID].end = rowt[common_VEC_ID]; \
497
+ (Q)[common_VEC_ID].v = (void *)common_pnt; \
498
+ common_pnt += ((unit)<sizeof(QUEUE_INT)?sizeof(QUEUE_INT):(unit))*(rowt[common_VEC_ID]+(ext));\
499
+ }}while(0)
500
+ #endif
501
+
502
+ /**********************************************************/
503
+ /* macro for execute the programs as subroutine */
504
+ /* do not nest the macro; <= variable will be used doubly */
505
+ /**********************************************************/
506
+ // execute the main routine of the program as a subroutine
507
+ #define EXECSUB(func,flag,err,fmt,...) do{\
508
+ sprintf (common_comm, fmt, __VA_ARGS__);\
509
+ if ( flag&SHOW_MESSAGE ) print_err ("%s\n", common_comm);\
510
+ common_INT = string_decompose (common_argv, common_comm, ' ', 100);\
511
+ if ( func (common_INT, common_argv) ) err;\
512
+ }while(0)
513
+ // remove a file on the specified directory
514
+ #define REMOV(dir,fn) do{ sprintf(common_comm,"%s%s",dir,fn); remove (common_comm); }while(0)
515
+ #define RENAM(dir,fn,fn2) do{ sprintf(common_comm,"%s%s",dir,fn); sprintf(common_comm2,"%s%s",dir,fn2); rename (common_comm, common_comm2); }while(0)
516
+ #define MREMOV(dir,...) mremove_(dir, __VA_ARGS__, NULL, NULL)
517
+
518
+
519
+ /*********************************************************/
520
+
521
+
522
+ #define SHOW_MESSAGE 1 // not print messages
523
+ #define SHOW_PROGRESS 2 // show progress of the computation
524
+ #define APPEND_OUTPUT 4 // append the output to existing file
525
+ #define NO_REMOVE 8 // do not remove the temporal files
526
+ #define LOAD_PERM 64 // permute the nodes/items by something
527
+ #define LOAD_RM_DUP 128 // duplicate items in each row, for loading data
528
+ #define LOAD_INCSORT 256 // sort rows in increasing order, for loading data
529
+ #define LOAD_DECSORT 512 // sort rows in decreasing order, for loading data
530
+ #define LOAD_ELE 1024 // load tuple-list file
531
+ #define LOAD_TPOSE 2048 // transpose the file when load
532
+ #define LOAD_DBLBUF 4096 // allocate double-size memory for element buffer
533
+ #define LOAD_WSORT 8192 // sort rows by their weights
534
+ #define LOAD_SIZSORT 16384 // sort rows by their sizes
535
+ #define LOAD_DECROWSORT 32768 // sort rows in decreasing order
536
+ #define LOAD_NUM 65536 // read #columns, #rows and #elements from the 1st line of the file
537
+
538
+ #define LOAD_EDGEW 131072 // read edge weight
539
+ //#define LOAD_ARCW 262144 // read arc weight
540
+ #define LOAD_NODEW 524288 // read node weight
541
+ #define LOAD_BIPARTITE 1048576 // read bipartite graph
542
+ #define LOAD_EDGE 2097152 // read edge
543
+ #define LOAD_ARC 4194304 // read arc
544
+ #define LOAD_GRAPHNUM 8388608 // read #vertices and #edges from the 1st line of the file
545
+ #define LOAD_ID1 16777216 // node ID begins from 1
546
+ #define LOAD_COMP 33554432 // read as a complement
547
+ #define LOAD_RC_SAME 67108864 // set #rows and #columns to the maximum of them
548
+
549
+ #define FILE_COUNT_ROWT 32 // count size of each row
550
+ #define FILE_COUNT_CLMT 64 // count size of each column
551
+ #define FILE_COUNT_NUM LOAD_NUM // read #columns, #rows and #elements
552
+ #define FILE_COUNT_GRAPHNUM LOAD_GRAPHNUM // read #vertices and #edges
553
+
554
+ #define FILE2_BUFSIZ 16384
555
+ typedef struct { // structure for fast file reader routines
556
+ unsigned char type; // type definition
557
+ FILE *fp;
558
+ char *buf_org, *buf, *buf_end; // head/current/tail of buffer
559
+ char bit;
560
+ } FILE2;
561
+ extern FILE2 INIT_FILE2, common_FILE2;
562
+
563
+ void FILE2_flush (FILE2 *fp);
564
+ void FILE2_close (FILE2 *fp);
565
+ void FILE2_closew (FILE2 *fp);
566
+ void FILE2_reset (FILE2 *fp);
567
+ void FILE2_copy (char *f1, char *f2);
568
+
569
+ int FILE2_getc (FILE2 *fp);
570
+ void FILE2_puts (FILE2 *fp, char *s);
571
+ void FILE2_putc (FILE2 *fp, char c);
572
+ int FILE2_getbit (FILE2 *fp);
573
+ void FILE2_putbit (FILE2 *fp, int a);
574
+
575
+ /* message output */
576
+ //void print_mes (int flag, char *mes, ...);
577
+ //void print_err (char *mes, ...);
578
+
579
+ /* free many pointers*/
580
+ void mfree_(void *x, ...);
581
+ void mfree2_(void *x, ...);
582
+
583
+ /* remove many files */
584
+ void mremove_ (char *x, ...);
585
+
586
+ /* compute the minimum prime no less than n */
587
+ LONG min_prime (LONG n);
588
+
589
+ /* decompose the string by separator, and set v[i] to each resulted string.
590
+ consecutive separators are regarded as one separator. */
591
+ int string_decompose (char **v, char *s, char sep, int max);
592
+
593
+ /* make two random numbers under normal distribution N(0,1) */
594
+ void rand_mk_2normal (double *a, double *b);
595
+ /* make a random point on a supersphere of d-dim., and set to double array already allocated */
596
+ void rand_d_gaussian (double *p, int d);
597
+ void rand_sphere (double *p, int d);
598
+
599
+
600
+
601
+ /* Read an integer from the file and return it,
602
+ with read through the non-numeric letters.
603
+ If it reaches to the end-of-file, then set FILE_err=2, if it reads a
604
+ newline, then set FILE_err=1.
605
+ If read either the end-of-file or newline before reading an integer,
606
+ return -1 */
607
+ FILE_LONG FILE2_read_int (FILE2 *fp);
608
+ double FILE2_read_double (FILE2 *fp);
609
+ WEIGHT FILE2_read_WEIGHT (FILE2 *fp);
610
+ LONG FILE2_read_mpint (FILE2 *fp, int max, int skip); // multi-precise
611
+ LONG FILE2_read_intbit (FILE2 *fp, int k); // read k bits as integer
612
+
613
+
614
+ /* fast file routine, print number, c is the char to be printed preceding to the number
615
+ if c==0, nothing will be printed preceding the number
616
+ if len<0 then the #digits following '.' does not change (filed by '0') */
617
+ void FILE2_print_int (FILE2 *fp, LONG n, char c);
618
+ void FILE2_print_real (FILE2 *fp, double n, int len, char c);
619
+ void FILE2_print_WEIGHT (FILE2 *fp, WEIGHT w, int len, char c);
620
+ void FILE2_printf (FILE2 *fp, char *mes, ...);
621
+ void FILE2_print_mpint (FILE2 *fp, LONG a, int max, int skip); // multi-precise
622
+ void FILE2_print_intbit (FILE2 *fp, LONG a, int k); // print lowest k-bits
623
+
624
+ /* print a real number in a good style */
625
+ void fprint_real (FILE *fp, double f);
626
+ void print_real (double f);
627
+ void fprint_WEIGHT (FILE *fp, WEIGHT f);
628
+ void print_WEIGHT (WEIGHT f);
629
+
630
+ #define FILE_COUNT_INT VEC_ID
631
+ #define FILE_COUNT_INTF VEC_IDF
632
+ typedef struct {
633
+ int flag;
634
+ FILE_COUNT_INT clms, rows, eles, clm_end, row_end, row_btm, clm_btm; // #rows, #column, #elements, minimum elements
635
+ FILE_COUNT_INT row_min, row_max, clm_min, clm_max; // maximum/minimum size of column
636
+ FILE_COUNT_INT *rowt, *clmt; // size of each row/clmn
637
+ WEIGHT total_rw, total_cw, *rw, *cw; // WEIGHTs for rows/columns ... reserved.
638
+ FILE_COUNT_INT rw_end, cw_end;
639
+ PERM *rperm, *cperm; // permutation (original->internal) of rows and columns
640
+ } FILE_COUNT;
641
+
642
+ extern FILE_COUNT INIT_FILE_COUNT;
643
+
644
+ /* count the clms, rows, items, each row size, each column size */
645
+ /* file types can be, array list and element list*/
646
+ /* support transpose */
647
+ FILE_COUNT FILE2_count (FILE2 *fp, int flag, int skip_rows, int int_rows, int skip_clms, int int_clms, FILE_COUNT_INT row_limit);
648
+
649
+ /******************* integer array routines **************************/
650
+
651
+ /******************************* permutation routines ****************/
652
+ /* permutation is given by an integer array */
653
+
654
+ /* sort an array of size "siz", composed of a structure of size "unit" byte
655
+ in the order of perm */
656
+ /* use temporary memory of siz*unit byte */
657
+ //void perm_struct (void *a, int unit, int *perm, size_t siz);
658
+
659
+ /* SLIST:very simple one-sided list */
660
+ void SLIST_init (int *l, int num, int siz);
661
+ void SLIST_end (int *l);
662
+ #define SLIST_INS(l,m,e) (l[e]=l[m],l[m]=e);
663
+
664
+ #define QQSORT_ELE(a,x) ((a *)(&(common_pnt[(*((PERM *)(x)))*common_int])))
665
+ #define QQSORT_ELEt(a,x) (((a *)&(common_pnt[(*((PERM *)(x)))*common_int]))->t)
666
+ /* quick sort macros */
667
+ #define QSORT_TYPE(a,b) \
668
+ b common_##a; \
669
+ int qsort_cmp_##a (const void *x, const void *y){ \
670
+ if ( *((b *)x) < *((b *)y) ) return (-1); else return ( *((b *)x) > *((b *)y) ); \
671
+ } \
672
+ int qsort_cmp__##a (const void *x, const void *y){ \
673
+ if ( *((b *)x) > *((b *)y) ) return (-1); else return ( *((b *)x) < *((b *)y) ); \
674
+ } \
675
+ int qqsort_cmp_##a (const void *x, const void *y){ \
676
+ b *xx=QQSORT_ELE(b,x), *yy=QQSORT_ELE(b,y); \
677
+ if ( *xx < *yy ) return (-1); \
678
+ else return ( *xx > *yy ); \
679
+ } \
680
+ int qqsort_cmp__##a (const void *x, const void *y){ \
681
+ b *xx=QQSORT_ELE(b,x), *yy=QQSORT_ELE(b,y); \
682
+ if ( *xx > *yy ) return (-1); \
683
+ else return ( *xx < *yy ); \
684
+ } \
685
+ void qsort_##a (b *v, size_t siz, int unit){ \
686
+ if ( unit == 1 || unit==-1 ) unit *= sizeof (b); \
687
+ if (unit<0) qsort (v, siz, -unit, qsort_cmp__##a); else qsort (v, siz, unit, qsort_cmp_##a); \
688
+ } \
689
+ void qsort_perm__##a (b *v, size_t siz, PERM *perm, int unit){ \
690
+ if ( unit == 1 || unit==-1 ) unit *= sizeof (PERM); \
691
+ common_int = MAX(unit,-unit); common_pnt = (char *)v; \
692
+ if (unit<0) qsort (perm, siz, sizeof(PERM), qqsort_cmp__##a); \
693
+ else qsort (perm, siz, sizeof(PERM), qqsort_cmp_##a); \
694
+ } \
695
+ PERM *qsort_perm_##a (b *v, size_t siz, int unit){ \
696
+ PERM *perm; malloc2(perm, siz, EXIT0); \
697
+ ARY_INIT_PERM (perm,(PERM)siz); \
698
+ qsort_perm__##a (v, siz, perm, unit); return (perm); \
699
+ } \
700
+ size_t bin_search_##a (b *v, b u, size_t siz, int unit){ \
701
+ size_t s=0, t; \
702
+ b n; \
703
+ if ( unit == 1 ) unit *= sizeof (b); \
704
+ while (1){ \
705
+ if ( siz-s <= 2 ){ \
706
+ if ( u <= *((b *)(((char *)v)+unit*s)) ) return (s);\
707
+ if ( siz == s+1 || u <= *((b *)(((char *)v)+unit*(s+1))) ) return (s+1);\
708
+ return (s+2);\
709
+ }\
710
+ t = (s+siz) /2; \
711
+ n = *((b *)(((char *)v)+unit*t));\
712
+ if ( u < n ) siz = t; else s = t;\
713
+ }\
714
+ }
715
+ // bin search returns the position that is equal to u, or the smallest in larger's
716
+
717
+ #define QSORT_TYPE_HEADER(a,b) \
718
+ extern b common_##a; \
719
+ int qsort_cmp_##a (const void *x, const void *y); \
720
+ int qsort_cmp__##a (const void *x, const void *y); \
721
+ int qqsort_cmp_##a (const void *x, const void *y); \
722
+ int qqsort_cmp__##a (const void *x, const void *y); \
723
+ void qsort_##a(b *v, size_t siz, int unit); \
724
+ void qsort_perm__##a (b *v, size_t siz, PERM *perm, int unit); \
725
+ PERM *qsort_perm_##a (b *v, size_t siz, int unit); \
726
+ size_t bin_search_##a (b *v, b u, size_t siz, int unit);
727
+
728
+ QSORT_TYPE_HEADER(int, int)
729
+ QSORT_TYPE_HEADER(uint, unsigned int)
730
+ QSORT_TYPE_HEADER(double, double)
731
+ QSORT_TYPE_HEADER(char, char)
732
+ QSORT_TYPE_HEADER(uchar, unsigned char)
733
+ QSORT_TYPE_HEADER(short, short)
734
+ QSORT_TYPE_HEADER(ushort, unsigned short)
735
+ QSORT_TYPE_HEADER(WEIGHT, WEIGHT)
736
+ QSORT_TYPE_HEADER(LONG, LONG)
737
+ QSORT_TYPE_HEADER(VEC_ID, VEC_ID)
738
+ QSORT_TYPE_HEADER(VEC_VAL, VEC_VAL)
739
+ QSORT_TYPE_HEADER(VEC_VAL2, VEC_VAL2)
740
+ QSORT_TYPE_HEADER(FILE_COUNT_INT, FILE_COUNT_INT)
741
+
742
+ int qsort_cmp_VECt (const void *x, const void *y);
743
+ int qsort_cmp__VECt (const void *x, const void *y);
744
+ void qsort_VECt (VEC *v, size_t siz, int unit);
745
+ int qqsort_cmp_VECt (const void *x, const void *y);
746
+ int qqsort_cmp__VECt (const void *x, const void *y);
747
+ void qsort_perm__VECt (VEC *v, size_t siz, PERM *perm, int unit);
748
+ PERM *qsort_perm_VECt (VEC *v, size_t siz, int unit);
749
+
750
+ /* swap macro for integer, double, char, and pointer */
751
+ #define SWAP_INT(a,b) (common_LONG=a,a=b,b=common_LONG)
752
+ #define SWAP_DOUBLE(a,b) (common_double=a,a=b,b=common_double)
753
+ #define SWAP_size_t(a,b) (common_size_t=a,a=b,b=common_size_t)
754
+ #ifdef _cplusplus_
755
+ #define SWAP_PNT(a,b) (common_pnt=(typeof(common_pnt))a,a=(typeof(a))b,b=(typeof(b))common_pnt)
756
+ #else
757
+ #define SWAP_PNT(a,b) (common_pnt=(void *)a,a=(void *)b,b=(void *)common_pnt)
758
+ #endif
759
+
760
+ #define SWAP_VEC_ID(a,b) (common_VEC_ID=a,a=b,b=common_VEC_ID)
761
+ #define SWAP_FILE_COUNT_INT(a,b) (common_FILE_COUNT_INT=a,a=b,b=common_FILE_COUNT_INT)
762
+
763
+ /* sort index(int)/WEIGHT array and return the indices of the result */
764
+ /* perm[i*2] := rank of ith cell */
765
+ /* perm[i*2+1] := index of ith smallest cell */
766
+ /* flag!=NULL => opposite direction sort */
767
+
768
+ //int *int_index_sort (int *w, size_t siz, int flag);
769
+ //int *WEIGHT_index_sort (WEIGHT *w, size_t siz, int flag);
770
+
771
+ /* radix sort for array of structures, by their integer members
772
+ ranging from mm to m */
773
+ /* sort array "perm" according to (int/void*) array "a".
774
+ if perm==NULL, allocate memory and for perm */
775
+ /* return the permutation array of the result of the sorting
776
+ in the decreasing order if unit<0 (unimplemented!!!) */
777
+ int *radix_sort (void *a, size_t siz, int unit, int mm, int m, int *perm);
778
+
779
+ /* permutate structure array *tt of unit size unit of size num, according to perm array *pp */
780
+ /* num has to be <INTHUGE/2 */
781
+ /* unit<0 means decreasing order (un-implemented!!!) */
782
+ void structure_permute (void *tt, int unit, int num, void *pp, int weight_siz);
783
+
784
+ #ifdef STDLIB2_RADIX_SORT // radix sort with 1M byte static memory
785
+ void intarray_sort_iter (unsigned int *a, size_t siz, int unit);
786
+ void intarray_sort_iter_ (unsigned int *a, size_t siz, int unit);
787
+ void intarray_sort (unsigned *a, size_t siz, int unit);
788
+ #endif
789
+
790
+ /* bitmasks, used for bit operations */
791
+ extern int BITMASK_UPPER1[32];
792
+ extern int BITMASK_UPPER1_[32];
793
+ extern int BITMASK_LOWER1[32];
794
+ extern int BITMASK_LOWER1_[32];
795
+ extern int BITMASK_1[32];
796
+ extern int BITMASK_31[32];
797
+ extern int BITMASK_16[8];
798
+ extern int BITMASK_UPPER16[8];
799
+ extern int BITMASK_LOWER16[8];
800
+ extern int BITMASK_FACT16[8];
801
+
802
+ /* bit operations */
803
+ #define BIT_SET(v,x) (v[x/32]|=BITMASK_1[x%32])
804
+ #define BIT_DEL(v,x) (v[x/32]&=BITMASK_31[x%32])
805
+ #define ISBIT(v,x) (v[x/32]&BITMASK_1[x%32])
806
+
807
+ #endif
808
+
809
+
810
+ /******************************************/
811
+ /* ==== terminology for comments ====
812
+ range check: to check the input parameter is valid, or in the valid range.
813
+ If a function does not have this, its comment has "no range check"
814
+ */
815
+
816
+ /* ==== rules for the name of functions and routines ====
817
+ init: initialization for an object, structure, etc. memory is allocated
818
+ if needed.
819
+ end: compared to init, termination of structures, etc.
820
+ free allocated memory if it exists, but not free itself.
821
+ different from ordinary new, create, del, free.
822
+
823
+ cpy: copy an object without allocating memory
824
+ dup: make a duplication of an object with allocating new memory
825
+
826
+ new: new. allocate memory for new object. also used for re-allocation from
827
+ the list of deleted objects
828
+ del: delete. free memory, or insert it to the list of deleted objects
829
+
830
+ ins : insert. insert an element (active, not deleted) to an object, possible
831
+ at the given position.
832
+ out : extract. extract an element, possibly specified, from an object.
833
+ it will be not deleted.
834
+ rm : extract, and delete
835
+ rmall: delete all (specified) elements of an object
836
+ mk : make. new+ins�B
837
+ mv : move. move the elements from an object to another,
838
+ or change the position.
839
+
840
+ update : update an object, possibly of specified position, to the exact,
841
+ or to the current one.
842
+ chg : change the status of an object to the specified one.
843
+
844
+ prv: point the previous element
845
+ nxt: point the next element
846
+ end: the maximum size (allocated size) of an array, etc.
847
+ num: the (current) number of elements in an array, etc.
848
+ kth: for the use of "first k object"
849
+ tkth: for the use of "first k object from the end". to kth.
850
+ rnd: random
851
+ print: print structure and etc.
852
+ find: search or find an specified element from the set of structures, etc.
853
+ */
854
+
855
+ /* ==== rules for the name of variables ====
856
+ - use i or j for the counter in loops
857
+ - use e for elements
858
+ - use k for the specified rank
859
+ - use f or flag for flagment
860
+ - use m for maximum value or minimum value
861
+ - use c for counters
862
+ */
863
+
864
+