nysol-take 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/mbiclique.rb +317 -0
- data/bin/mbipolish.rb +362 -0
- data/bin/mccomp.rb +235 -0
- data/bin/mclique.rb +295 -0
- data/bin/mclique2g.rb +105 -0
- data/bin/mcliqueInfo.rb +203 -0
- data/bin/mfriends.rb +202 -0
- data/bin/mgdiff.rb +252 -0
- data/bin/mhifriend.rb +456 -0
- data/bin/mhipolish.rb +465 -0
- data/bin/mitemset.rb +168 -0
- data/bin/mpal.rb +410 -0
- data/bin/mpolishing.rb +399 -0
- data/bin/msequence.rb +165 -0
- data/bin/mtra2g.rb +476 -0
- data/bin/mtra2gc.rb +360 -0
- data/ext/grhfilrun/extconf.rb +12 -0
- data/ext/grhfilrun/grhfilrun.c +85 -0
- data/ext/grhfilrun/src/_sspc.c +358 -0
- data/ext/grhfilrun/src/aheap.c +545 -0
- data/ext/grhfilrun/src/aheap.h +251 -0
- data/ext/grhfilrun/src/base.c +92 -0
- data/ext/grhfilrun/src/base.h +59 -0
- data/ext/grhfilrun/src/fstar.c +497 -0
- data/ext/grhfilrun/src/fstar.h +80 -0
- data/ext/grhfilrun/src/grhfil.c +214 -0
- data/ext/grhfilrun/src/itemset.c +713 -0
- data/ext/grhfilrun/src/itemset.h +170 -0
- data/ext/grhfilrun/src/problem.c +415 -0
- data/ext/grhfilrun/src/problem.h +179 -0
- data/ext/grhfilrun/src/queue.c +533 -0
- data/ext/grhfilrun/src/queue.h +182 -0
- data/ext/grhfilrun/src/sample.c +19 -0
- data/ext/grhfilrun/src/sspc.c +597 -0
- data/ext/grhfilrun/src/sspc2.c +491 -0
- data/ext/grhfilrun/src/stdlib2.c +1482 -0
- data/ext/grhfilrun/src/stdlib2.h +892 -0
- data/ext/grhfilrun/src/trsact.c +817 -0
- data/ext/grhfilrun/src/trsact.h +160 -0
- data/ext/grhfilrun/src/vec.c +745 -0
- data/ext/grhfilrun/src/vec.h +172 -0
- data/ext/lcmrun/extconf.rb +20 -0
- data/ext/lcmrun/lcmrun.cpp +99 -0
- data/ext/lcmrun/src/aheap.c +216 -0
- data/ext/lcmrun/src/aheap.h +111 -0
- data/ext/lcmrun/src/base.c +92 -0
- data/ext/lcmrun/src/base.h +59 -0
- data/ext/lcmrun/src/itemset.c +496 -0
- data/ext/lcmrun/src/itemset.h +157 -0
- data/ext/lcmrun/src/lcm.c +427 -0
- data/ext/lcmrun/src/problem.c +349 -0
- data/ext/lcmrun/src/problem.h +177 -0
- data/ext/lcmrun/src/queue.c +528 -0
- data/ext/lcmrun/src/queue.h +176 -0
- data/ext/lcmrun/src/sgraph.c +359 -0
- data/ext/lcmrun/src/sgraph.h +173 -0
- data/ext/lcmrun/src/stdlib2.c +1282 -0
- data/ext/lcmrun/src/stdlib2.h +823 -0
- data/ext/lcmrun/src/trsact.c +747 -0
- data/ext/lcmrun/src/trsact.h +159 -0
- data/ext/lcmrun/src/vec.c +731 -0
- data/ext/lcmrun/src/vec.h +171 -0
- data/ext/lcmseq0run/extconf.rb +20 -0
- data/ext/lcmseq0run/lcmseq0run.cpp +59 -0
- data/ext/lcmseq0run/src/aheap.c +216 -0
- data/ext/lcmseq0run/src/aheap.h +111 -0
- data/ext/lcmseq0run/src/base.c +92 -0
- data/ext/lcmseq0run/src/base.h +59 -0
- data/ext/lcmseq0run/src/itemset.c +518 -0
- data/ext/lcmseq0run/src/itemset.h +157 -0
- data/ext/lcmseq0run/src/itemset_zero.c +522 -0
- data/ext/lcmseq0run/src/lcm_seq.c +446 -0
- data/ext/lcmseq0run/src/lcm_seq_zero.c +446 -0
- data/ext/lcmseq0run/src/problem.c +439 -0
- data/ext/lcmseq0run/src/problem.h +179 -0
- data/ext/lcmseq0run/src/problem_zero.c +439 -0
- data/ext/lcmseq0run/src/queue.c +533 -0
- data/ext/lcmseq0run/src/queue.h +182 -0
- data/ext/lcmseq0run/src/stdlib2.c +1350 -0
- data/ext/lcmseq0run/src/stdlib2.h +864 -0
- data/ext/lcmseq0run/src/trsact.c +747 -0
- data/ext/lcmseq0run/src/trsact.h +159 -0
- data/ext/lcmseq0run/src/vec.c +779 -0
- data/ext/lcmseq0run/src/vec.h +172 -0
- data/ext/lcmseqrun/extconf.rb +20 -0
- data/ext/lcmseqrun/lcmseqrun.cpp +101 -0
- data/ext/lcmseqrun/src/aheap.c +216 -0
- data/ext/lcmseqrun/src/aheap.h +111 -0
- data/ext/lcmseqrun/src/base.c +92 -0
- data/ext/lcmseqrun/src/base.h +59 -0
- data/ext/lcmseqrun/src/itemset.c +518 -0
- data/ext/lcmseqrun/src/itemset.h +157 -0
- data/ext/lcmseqrun/src/itemset_zero.c +522 -0
- data/ext/lcmseqrun/src/lcm_seq.c +447 -0
- data/ext/lcmseqrun/src/lcm_seq_zero.c +446 -0
- data/ext/lcmseqrun/src/problem.c +439 -0
- data/ext/lcmseqrun/src/problem.h +179 -0
- data/ext/lcmseqrun/src/problem_zero.c +439 -0
- data/ext/lcmseqrun/src/queue.c +533 -0
- data/ext/lcmseqrun/src/queue.h +182 -0
- data/ext/lcmseqrun/src/stdlib2.c +1350 -0
- data/ext/lcmseqrun/src/stdlib2.h +864 -0
- data/ext/lcmseqrun/src/trsact.c +747 -0
- data/ext/lcmseqrun/src/trsact.h +159 -0
- data/ext/lcmseqrun/src/vec.c +779 -0
- data/ext/lcmseqrun/src/vec.h +172 -0
- data/ext/lcmtransrun/extconf.rb +18 -0
- data/ext/lcmtransrun/lcmtransrun.cpp +264 -0
- data/ext/macerun/extconf.rb +20 -0
- data/ext/macerun/macerun.cpp +57 -0
- data/ext/macerun/src/aheap.c +217 -0
- data/ext/macerun/src/aheap.h +112 -0
- data/ext/macerun/src/itemset.c +491 -0
- data/ext/macerun/src/itemset.h +158 -0
- data/ext/macerun/src/mace.c +503 -0
- data/ext/macerun/src/problem.c +346 -0
- data/ext/macerun/src/problem.h +174 -0
- data/ext/macerun/src/queue.c +529 -0
- data/ext/macerun/src/queue.h +177 -0
- data/ext/macerun/src/sgraph.c +360 -0
- data/ext/macerun/src/sgraph.h +174 -0
- data/ext/macerun/src/stdlib2.c +993 -0
- data/ext/macerun/src/stdlib2.h +811 -0
- data/ext/macerun/src/vec.c +634 -0
- data/ext/macerun/src/vec.h +170 -0
- data/ext/sspcrun/extconf.rb +20 -0
- data/ext/sspcrun/src/_sspc.c +358 -0
- data/ext/sspcrun/src/aheap.c +545 -0
- data/ext/sspcrun/src/aheap.h +251 -0
- data/ext/sspcrun/src/base.c +92 -0
- data/ext/sspcrun/src/base.h +59 -0
- data/ext/sspcrun/src/fstar.c +496 -0
- data/ext/sspcrun/src/fstar.h +80 -0
- data/ext/sspcrun/src/grhfil.c +213 -0
- data/ext/sspcrun/src/itemset.c +713 -0
- data/ext/sspcrun/src/itemset.h +170 -0
- data/ext/sspcrun/src/problem.c +415 -0
- data/ext/sspcrun/src/problem.h +179 -0
- data/ext/sspcrun/src/queue.c +533 -0
- data/ext/sspcrun/src/queue.h +182 -0
- data/ext/sspcrun/src/sample.c +19 -0
- data/ext/sspcrun/src/sspc.c +598 -0
- data/ext/sspcrun/src/sspc2.c +491 -0
- data/ext/sspcrun/src/stdlib2.c +1482 -0
- data/ext/sspcrun/src/stdlib2.h +892 -0
- data/ext/sspcrun/src/trsact.c +817 -0
- data/ext/sspcrun/src/trsact.h +160 -0
- data/ext/sspcrun/src/vec.c +745 -0
- data/ext/sspcrun/src/vec.h +172 -0
- data/ext/sspcrun/sspcrun.cpp +54 -0
- data/lib/nysol/enumLcmEp.rb +338 -0
- data/lib/nysol/enumLcmEsp.rb +284 -0
- data/lib/nysol/enumLcmIs.rb +275 -0
- data/lib/nysol/enumLcmSeq.rb +143 -0
- data/lib/nysol/items.rb +201 -0
- data/lib/nysol/seqDB.rb +256 -0
- data/lib/nysol/take.rb +39 -0
- data/lib/nysol/taxonomy.rb +113 -0
- data/lib/nysol/traDB.rb +257 -0
- metadata +239 -0
@@ -0,0 +1,172 @@
|
|
1
|
+
/* library for sparse vector */
|
2
|
+
/* Takeaki Uno 27/Dec/2008 */
|
3
|
+
|
4
|
+
#ifndef _vec_h_
|
5
|
+
#define _vec_h_
|
6
|
+
|
7
|
+
//#define USE_MATH
|
8
|
+
|
9
|
+
#include"math.h"
|
10
|
+
#include"queue.h"
|
11
|
+
|
12
|
+
#ifndef SVEC_VAL
|
13
|
+
#ifdef SVEC_VAL_INT
|
14
|
+
#define SVEC_VAL int
|
15
|
+
#define SVEC_VAL2 LONG
|
16
|
+
#define SVEC_VAL_END INTHUGE
|
17
|
+
#define SVEC_VAL2_END LONGHUGE
|
18
|
+
#define SVEC_VALF "%d"
|
19
|
+
#else
|
20
|
+
#define SVEC_VAL double
|
21
|
+
#define SVEC_VAL2 double
|
22
|
+
#define SVEC_VAL_END DOUBLEHUGE
|
23
|
+
#define SVEC_VAL2_END DOUBLEHUGE
|
24
|
+
#define SVEC_VALF "%f"
|
25
|
+
#endif
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#define VEC_LOAD_BIN 16777216 // read binary file
|
29
|
+
#define VEC_LOAD_BIN2 33554432 // read binary file with 2byte for each number
|
30
|
+
#define VEC_LOAD_BIN4 67108864 // read binary file with 4byte for each number
|
31
|
+
#define VEC_LOAD_CENTERIZE 134217728 // read binary file, and minus the half(128) from each number
|
32
|
+
#define VEC_NORMALIZE 268435456 // read binary file, and minus the half(128) from each number
|
33
|
+
|
34
|
+
/* matrix */
|
35
|
+
typedef struct {
|
36
|
+
unsigned char type; // mark to identify type of the structure
|
37
|
+
char *fname, *wfname; // input/weight file name
|
38
|
+
int flag; // flag
|
39
|
+
|
40
|
+
VEC *v;
|
41
|
+
VEC_ID end;
|
42
|
+
VEC_ID t;
|
43
|
+
VEC_VAL *buf, *buf2;
|
44
|
+
VEC_ID clms;
|
45
|
+
size_t eles;
|
46
|
+
VEC_VAL *buf_org, *buf2_org;
|
47
|
+
} MAT;
|
48
|
+
|
49
|
+
/* sparse vector, element */
|
50
|
+
typedef struct {
|
51
|
+
QUEUE_ID i;
|
52
|
+
SVEC_VAL a;
|
53
|
+
} SVEC_ELE;
|
54
|
+
|
55
|
+
/* sparse vector, vector */
|
56
|
+
typedef struct {
|
57
|
+
unsigned char type; // mark to identify type of the structure
|
58
|
+
SVEC_ELE *v;
|
59
|
+
VEC_ID end;
|
60
|
+
VEC_ID t;
|
61
|
+
} SVEC;
|
62
|
+
|
63
|
+
/* sparse vector, matrix */
|
64
|
+
typedef struct {
|
65
|
+
unsigned char type; // mark to identify type of the structure
|
66
|
+
char *fname, *wfname; // input/weight file name
|
67
|
+
int flag; // flag
|
68
|
+
|
69
|
+
SVEC *v;
|
70
|
+
VEC_ID end;
|
71
|
+
VEC_ID t;
|
72
|
+
SVEC_ELE *buf, *buf2;
|
73
|
+
VEC_ID clms;
|
74
|
+
size_t eles, ele_end;
|
75
|
+
} SMAT;
|
76
|
+
|
77
|
+
/* set family */
|
78
|
+
typedef struct {
|
79
|
+
unsigned char type; // mark to identify type of the structure
|
80
|
+
char *fname, *wfname; // input/weight file name
|
81
|
+
int flag; // flag
|
82
|
+
|
83
|
+
QUEUE *v;
|
84
|
+
VEC_ID end;
|
85
|
+
VEC_ID t;
|
86
|
+
QUEUE_INT *buf, *buf2;
|
87
|
+
VEC_ID clms;
|
88
|
+
size_t eles, ele_end;
|
89
|
+
WEIGHT *cw, *rw, **w, *wbuf;
|
90
|
+
int unit;
|
91
|
+
char *cwfname, *rwfname; // weight file name
|
92
|
+
PERM *rperm, *cperm; // row permutation
|
93
|
+
} SETFAMILY;
|
94
|
+
|
95
|
+
#define INIT_SETFAMILY_ {TYPE_SETFAMILY,NULL,NULL,0,NULL,0,0,NULL,NULL,0,0,0,NULL,NULL,NULL,NULL,sizeof(QUEUE_INT),NULL,NULL,NULL,NULL}
|
96
|
+
|
97
|
+
extern MAT INIT_MAT;
|
98
|
+
extern SVEC INIT_SVEC;
|
99
|
+
extern SMAT INIT_SMAT;
|
100
|
+
extern SETFAMILY INIT_SETFAMILY;
|
101
|
+
|
102
|
+
QSORT_TYPE_HEADER (SVEC_VAL, SVEC_VAL)
|
103
|
+
QSORT_TYPE_HEADER (SVEC_VAL2, SVEC_VAL2)
|
104
|
+
|
105
|
+
#define ARY_QUEUE_INPRO(f,U,V) do{(f)=0;FLOOP(common_QUEUE_ID, 0, (QUEUE_ID)(U).t)(f)+=(V)[(U).v[common_QUEUE_ID]];}while(0)
|
106
|
+
#define ARY_SVEC_INPRO(f,U,V) do{(f)=0;FLOOP(common_VEC_ID, 0, (VEC_ID)(U).t)(f)+=((double)(U).v[common_VEC_ID].a)*(V)[(U).v[common_VEC_ID].i];}while(0)
|
107
|
+
|
108
|
+
/* terminate routine for VEC */
|
109
|
+
void VEC_end (VEC *V);
|
110
|
+
void MAT_end (MAT *M);
|
111
|
+
void SVEC_end (SVEC *V);
|
112
|
+
void SMAT_end (SMAT *M);
|
113
|
+
void SETFAMILY_end (SETFAMILY *M);
|
114
|
+
|
115
|
+
/* allocate memory according to rows and rowt */
|
116
|
+
void VEC_alloc (VEC *V, VEC_ID clms);
|
117
|
+
void MAT_alloc (MAT *M, VEC_ID rows, VEC_ID clms);
|
118
|
+
void SVEC_alloc (SVEC *V, VEC_ID end);
|
119
|
+
void SMAT_alloc (SMAT *M, VEC_ID rows, VEC_ID *rowt, VEC_ID clms, size_t eles);
|
120
|
+
void SETFAMILY_alloc (SETFAMILY *M, VEC_ID rows, VEC_ID *rowt, VEC_ID clms, size_t eles);
|
121
|
+
void SETFAMILY_alloc_weight (SETFAMILY *M, QUEUE_ID *t);
|
122
|
+
|
123
|
+
/* count/read the number in file for MAT */
|
124
|
+
/* if *rows>0, only read count the numbers in a row, for the first scan. */
|
125
|
+
void MAT_load_bin (MAT *M, FILE2 *fp, int unit);
|
126
|
+
void MAT_file_load (MAT *M, FILE2 *fp);
|
127
|
+
void MAT_load (MAT *M);
|
128
|
+
void SMAT_load (SMAT *M);
|
129
|
+
void SETFAMILY_load (SETFAMILY *M);
|
130
|
+
void SETFAMILY_load_weight (SETFAMILY *M);
|
131
|
+
void SETFAMILY_load_row_weight (SETFAMILY *M);
|
132
|
+
void SETFAMILY_load_column_weight (SETFAMILY *M);
|
133
|
+
|
134
|
+
void MAT_print (FILE *fp, MAT *M);
|
135
|
+
void SVEC_print (FILE *fp, SVEC *M);
|
136
|
+
void SMAT_print (FILE *fp, SMAT *M);
|
137
|
+
void SETFAMILY_print (FILE *fp, SETFAMILY *M);
|
138
|
+
void SETFAMILY_print_weight (FILE *fp, SETFAMILY *M);
|
139
|
+
|
140
|
+
|
141
|
+
/* norm, normalization **************************/
|
142
|
+
double SVEC_norm (SVEC *V);
|
143
|
+
void SVEC_normalize (SVEC *V);
|
144
|
+
|
145
|
+
/* inner product **************************/
|
146
|
+
SVEC_VAL2 SVEC_inpro (SVEC *V1, SVEC *V2);
|
147
|
+
|
148
|
+
/** Euclidean distance routines *********************************/
|
149
|
+
double VEC_eucdist (VEC *V1, VEC *V2);
|
150
|
+
double SVEC_eucdist (SVEC *V1, SVEC *V2);
|
151
|
+
double VEC_SVEC_eucdist (VEC *V1, SVEC *V2);
|
152
|
+
double QUEUE_eucdist (QUEUE *Q1, QUEUE *Q2);
|
153
|
+
double VEC_QUEUE_eucdist (VEC *V, QUEUE *Q);
|
154
|
+
|
155
|
+
void VEC_rand_gaussian (VEC *V);
|
156
|
+
|
157
|
+
double VEC_linfdist (VEC *V1, VEC *V2);
|
158
|
+
|
159
|
+
/* compute the inner product, Euclidean distance for multi vector */
|
160
|
+
double MVEC_norm (void *V);
|
161
|
+
double MVEC_inpro (void *V, void *U);
|
162
|
+
double MVEC_double_inpro (void *V, double *p);
|
163
|
+
double MVEC_eucdist (void *V, void *U);
|
164
|
+
|
165
|
+
/* compute the inner product, euclidean distance for i,jth vector */
|
166
|
+
double MMAT_inpro_ij (void *M, int i, int j);
|
167
|
+
double MMAT_double_inpro_i (void *M, int i, double *p);
|
168
|
+
double MMAT_eucdist_ij (void *M, int i, int j);
|
169
|
+
double MMAT_norm_i (void *M, int i);
|
170
|
+
|
171
|
+
|
172
|
+
#endif
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "mkmf"
|
3
|
+
|
4
|
+
unless have_library("kgmod3")
|
5
|
+
puts("need libkgmod.")
|
6
|
+
puts("refer https://github.com/nysol/mcmd")
|
7
|
+
exit 1
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
cp = "$(srcdir)"
|
12
|
+
|
13
|
+
$CFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
|
14
|
+
$CPPFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
|
15
|
+
$CXXFLAGS = " -O3 -Wall -I. -I#{cp}/src -DB_STATIC -D_NO_MAIN_ -DLINE -fPIC -Wno-error=format-security"
|
16
|
+
|
17
|
+
$LOCAL_LIBS += " -lstdc++ -lkgmod3"
|
18
|
+
|
19
|
+
create_makefile("nysol/lcmrun")
|
20
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <unistd.h>
|
4
|
+
#include <fcntl.h>
|
5
|
+
#include <sys/stat.h>
|
6
|
+
#include <string>
|
7
|
+
#include <ruby.h>
|
8
|
+
|
9
|
+
#include "src/lcm.c"
|
10
|
+
|
11
|
+
|
12
|
+
#include <kgMethod.h>
|
13
|
+
|
14
|
+
extern "C" {
|
15
|
+
void Init_lcmrun(void);
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
VALUE lcmrun(VALUE self,VALUE argvV){
|
20
|
+
|
21
|
+
string argstr=RSTRING_PTR(argvV);
|
22
|
+
vector<char *> opts = kglib::splitToken(const_cast<char*>(argstr.c_str()), ' ',true);
|
23
|
+
|
24
|
+
// 引数文字列へのポインタの領域はここでauto変数に確保する
|
25
|
+
kglib::kgAutoPtr2<char*> argv;
|
26
|
+
char** vv;
|
27
|
+
try{
|
28
|
+
argv.set(new char*[opts.size()+1]);
|
29
|
+
vv = argv.get();
|
30
|
+
}catch(...){
|
31
|
+
rb_raise(rb_eRuntimeError,"memory allocation error");
|
32
|
+
}
|
33
|
+
|
34
|
+
// vv配列0番目はコマンド名
|
35
|
+
vv[0]=const_cast<char*>("lcm");
|
36
|
+
|
37
|
+
size_t vvSize;
|
38
|
+
for(vvSize=0; vvSize<opts.size(); vvSize++){
|
39
|
+
vv[vvSize+1] = opts.at(vvSize);
|
40
|
+
}
|
41
|
+
vvSize+=1;
|
42
|
+
LCM_main(vvSize,vv);
|
43
|
+
return Qtrue;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
VALUE lcmrunk(VALUE self,VALUE argvV){
|
49
|
+
|
50
|
+
string argstr=RSTRING_PTR(argvV);
|
51
|
+
vector<char *> opts = kglib::splitToken(const_cast<char*>(argstr.c_str()), ' ',true);
|
52
|
+
|
53
|
+
// 引数文字列へのポインタの領域はここでauto変数に確保する
|
54
|
+
kglib::kgAutoPtr2<char*> argv;
|
55
|
+
char** vv;
|
56
|
+
try{
|
57
|
+
argv.set(new char*[opts.size()+1]);
|
58
|
+
vv = argv.get();
|
59
|
+
}catch(...){
|
60
|
+
rb_raise(rb_eRuntimeError,"memory allocation error");
|
61
|
+
}
|
62
|
+
|
63
|
+
// vv配列0番目はコマンド名
|
64
|
+
vv[0]=const_cast<char*>("lcm");
|
65
|
+
|
66
|
+
size_t vvSize;
|
67
|
+
for(vvSize=0; vvSize<opts.size()-1; vvSize++){
|
68
|
+
vv[vvSize+1] = opts.at(vvSize);
|
69
|
+
}
|
70
|
+
vvSize+=1;
|
71
|
+
|
72
|
+
|
73
|
+
// 標準出力きりかえ
|
74
|
+
int backup, fd;
|
75
|
+
backup = dup(1);
|
76
|
+
fd = open(opts.at(opts.size()-1), O_WRONLY|O_TRUNC|O_CREAT|O_APPEND, S_IRWXU);
|
77
|
+
dup2(fd, 1);
|
78
|
+
stdout = fdopen(fd, "w");
|
79
|
+
LCM_main(vvSize,vv);
|
80
|
+
fflush (stdout);
|
81
|
+
dup2(backup, 1);
|
82
|
+
stdout = fdopen(backup, "w");
|
83
|
+
close(backup);
|
84
|
+
|
85
|
+
return Qtrue;
|
86
|
+
}
|
87
|
+
|
88
|
+
// -----------------------------------------------------------------------------
|
89
|
+
// ruby Mcsvin クラス init
|
90
|
+
// -----------------------------------------------------------------------------
|
91
|
+
void Init_lcmrun(void)
|
92
|
+
{
|
93
|
+
// モジュール定義:MCMD::xxxxの部分
|
94
|
+
VALUE mtake=rb_define_module("TAKE");
|
95
|
+
rb_define_module_function(mtake,"run_lcm" , (VALUE (*)(...))lcmrun,1);
|
96
|
+
rb_define_module_function(mtake,"run_lcmK" , (VALUE (*)(...))lcmrunk,1);
|
97
|
+
}
|
98
|
+
|
99
|
+
|
@@ -0,0 +1,216 @@
|
|
1
|
+
/*
|
2
|
+
array-based simple heap (fixex size)
|
3
|
+
12/Apr/2001 by Takeaki Uno e-mail:uno@nii.jp,
|
4
|
+
homepage: http://research.nii.ac.jp/~uno/index.html */
|
5
|
+
/* This program is available for only academic use, basically.
|
6
|
+
Anyone can modify this program, but he/she has to write down
|
7
|
+
the change of the modification on the top of the source code.
|
8
|
+
Neither contact nor appointment to Takeaki Uno is needed.
|
9
|
+
If one wants to re-distribute this code, please
|
10
|
+
refer the newest code, and show the link to homepage of
|
11
|
+
Takeaki Uno, to notify the news about the codes for the users. */
|
12
|
+
|
13
|
+
#ifndef _aheap_c_
|
14
|
+
#define _aheap_c_
|
15
|
+
|
16
|
+
#include"aheap.h"
|
17
|
+
|
18
|
+
QSORT_TYPE (AHEAP_KEY, AHEAP_KEY)
|
19
|
+
QSORT_TYPE (AHEAP_ID, AHEAP_ID)
|
20
|
+
AHEAP INIT_AHEAP = {TYPE_AHEAP,NULL,0,0};
|
21
|
+
|
22
|
+
/* allocate memory */
|
23
|
+
void AHEAP_alloc (AHEAP *H, AHEAP_ID num){
|
24
|
+
AHEAP_ID i;
|
25
|
+
#ifdef ERROR_CHECK
|
26
|
+
if ( num<0 ) error_num ("size is out of range", num, EXIT);
|
27
|
+
#endif
|
28
|
+
*H = INIT_AHEAP;
|
29
|
+
if ( num>0 ) malloc2 (H->v, num*2, EXIT);
|
30
|
+
H->end = num;
|
31
|
+
ARY_FILL (H->v, 0, num*2, AHEAP_KEYHUGE);
|
32
|
+
for (i=0 ; i<num-1 ; i=i*2+1);
|
33
|
+
H->base = i - num + 1;
|
34
|
+
}
|
35
|
+
|
36
|
+
/* termination */
|
37
|
+
void AHEAP_end (AHEAP *H){
|
38
|
+
free2 (H->v);
|
39
|
+
*H = INIT_AHEAP;
|
40
|
+
}
|
41
|
+
|
42
|
+
/* return the index of the leaf having the minimum key among the descendants
|
43
|
+
of the given node i. If several leaves with the smallest key are there,
|
44
|
+
return the minimum index among them if f=0, maximum index if f=1, and
|
45
|
+
random choice if f=2 */
|
46
|
+
/* random choice version. choose one child to go down randomly for each node,
|
47
|
+
thus it is not uniformly random */
|
48
|
+
/* node_ returns the ID of leaf */
|
49
|
+
AHEAP_ID AHEAP_findmin_node_ (AHEAP *H, AHEAP_ID i, int f){
|
50
|
+
while ( i < H->end-1 ){
|
51
|
+
if ( H->v[i*2+1] == H->v[i] )
|
52
|
+
if ( H->v[i*2+2] == H->v[i] )
|
53
|
+
if ( f == 2 ) i = i*2 + 1 + rand()%2;
|
54
|
+
else i = i*2+1+f;
|
55
|
+
else i = i*2+1;
|
56
|
+
else i = i*2+2;
|
57
|
+
}
|
58
|
+
return (i);
|
59
|
+
}
|
60
|
+
AHEAP_ID AHEAP_findmin_node (AHEAP *H, AHEAP_ID i, int f){
|
61
|
+
if ( H->end <= 0 ) return (-1);
|
62
|
+
return (AHEAP_IDX(*H, AHEAP_findmin_node_ (H, i, f)));
|
63
|
+
}
|
64
|
+
AHEAP_ID AHEAP_findmin_head (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 0) ); }
|
65
|
+
AHEAP_ID AHEAP_findmin_tail (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 1) ); }
|
66
|
+
AHEAP_ID AHEAP_findmin_rnd (AHEAP *H){ return (AHEAP_findmin_node (H, 0, 2) ); }
|
67
|
+
|
68
|
+
/* return the index of the leaf having smaller value than a among the
|
69
|
+
descendants of the given node i. If several leaves with the smallest key
|
70
|
+
are there, return the minimum index among them if f=0, maximum index if f=1,
|
71
|
+
and random choice if f=2 */
|
72
|
+
AHEAP_ID AHEAP_findlow_node (AHEAP *H, AHEAP_KEY a, AHEAP_ID i, int f){
|
73
|
+
if ( H->end == 0 ) return (-1);
|
74
|
+
if ( H->v[0] > a ) return (-1);
|
75
|
+
while ( i < H->end-1 ){
|
76
|
+
if ( f == 2 ) {
|
77
|
+
if ( H->v[i*2+1] <= a )
|
78
|
+
if ( H->v[i*2+2] <= a ) i = i*2 + 1 + rand()%2;
|
79
|
+
else i = i*2+1;
|
80
|
+
else i = i*2+2;
|
81
|
+
} else if ( H->v[i*2+1] <= a ) i = i*2+1+f; else i = i*2+2-f;
|
82
|
+
}
|
83
|
+
return (AHEAP_IDX(*H, i) );
|
84
|
+
}
|
85
|
+
AHEAP_ID AHEAP_findlow_head (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 0) ); }
|
86
|
+
AHEAP_ID AHEAP_findlow_tail (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 1) ); }
|
87
|
+
AHEAP_ID AHEAP_findlow_rnd (AHEAP *H, AHEAP_KEY a){ return (AHEAP_findlow_node (H, a, 0, 2) ); }
|
88
|
+
|
89
|
+
/* return the index of the leaf having smaller value than a next/previous to
|
90
|
+
leaf i. return -1 if such a leaf does not exist */
|
91
|
+
AHEAP_ID AHEAP_findlow_nxt (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
|
92
|
+
if ( H->end == 0 ) return (-1);
|
93
|
+
if ( i<0 || i>= H->end ) return ( AHEAP_findlow_head (H, a));
|
94
|
+
for (i=AHEAP_LEAF(*H,i); i>0 ; i=(i-1)/2){
|
95
|
+
/* i is the child of smaller index, and the key of the sibling of i is less than a */
|
96
|
+
if ( i%2 == 1 && H->v[i+1] <= a ) return (AHEAP_findlow_node (H, a, i+1, 0) );
|
97
|
+
}
|
98
|
+
return (-1);
|
99
|
+
}
|
100
|
+
AHEAP_ID AHEAP_findlow_prv (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
|
101
|
+
if ( H->end == 0 ) return (-1);
|
102
|
+
if ( i<0 || i>= H->end ) return ( AHEAP_findlow_head (H, a));
|
103
|
+
for (i=AHEAP_LEAF(*H,i); i>0 ; i=(i-1)/2){
|
104
|
+
/* i is the child of larger index, and the key of the sibling of i is less than a */
|
105
|
+
if ( i%2 == 0 && H->v[i-1] <= a ) return (AHEAP_findlow_node (H, a, i-1, 1) );
|
106
|
+
}
|
107
|
+
return (-1);
|
108
|
+
}
|
109
|
+
|
110
|
+
/* change the key of node i to a /Add a to the key of node i, and update heap H */
|
111
|
+
void AHEAP_chg (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
|
112
|
+
i = AHEAP_LEAF (*H, i);
|
113
|
+
H->v[i] = a;
|
114
|
+
AHEAP_update (H, i);
|
115
|
+
}
|
116
|
+
void AHEAP_add (AHEAP *H, AHEAP_ID i, AHEAP_KEY a){
|
117
|
+
i = AHEAP_LEAF (*H, i);
|
118
|
+
H->v[i] += a;
|
119
|
+
AHEAP_update (H, i);
|
120
|
+
}
|
121
|
+
|
122
|
+
/* update the ancestor of node i */
|
123
|
+
void AHEAP_update (AHEAP *H, AHEAP_ID i){
|
124
|
+
AHEAP_ID j;
|
125
|
+
AHEAP_KEY a = H->v[i];
|
126
|
+
while ( i>0 ){
|
127
|
+
j = i - 1 + (i%2)*2; /* j = the sibling of i */
|
128
|
+
i = (i-1) / 2;
|
129
|
+
if ( H->v[j] < a ) a = H->v[j];
|
130
|
+
if ( a == H->v[i] ) break;
|
131
|
+
H->v[i] = a;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
/* find the leaf with the minimum key value among the leaves having index
|
136
|
+
smaller/larger than i, or between i and j */
|
137
|
+
AHEAP_ID AHEAP_upper_min (AHEAP *H, AHEAP_ID i){
|
138
|
+
AHEAP_ID fi=0, j = AHEAP_LEAF (*H, H->end - 1);
|
139
|
+
AHEAP_KEY fm = AHEAP_KEYHUGE;
|
140
|
+
if ( i == 0 ) return (AHEAP_findmin_head (H) );
|
141
|
+
i = AHEAP_LEAF (*H, i-1);
|
142
|
+
while ( i != j ){
|
143
|
+
if ( i%2 ){ /* if i is the child with smaller index */
|
144
|
+
if ( fm > H->v[i+1] ){
|
145
|
+
fm = H->v[i+1];
|
146
|
+
fi = i+1;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
i = (i-1)/2;
|
150
|
+
if ( j == i ) break; /* stop if the right pointer and the left pointer are the same */
|
151
|
+
j = (j-1)/2;
|
152
|
+
}
|
153
|
+
while ( fi < H->end-1 ) fi = fi*2 + (H->v[fi*2+1]<=fm?1:2);
|
154
|
+
return ( AHEAP_IDX(*H, fi) );
|
155
|
+
}
|
156
|
+
AHEAP_ID AHEAP_lower_min (AHEAP *H, AHEAP_ID i){
|
157
|
+
AHEAP_ID fi=0, j = AHEAP_LEAF (*H, 0);
|
158
|
+
AHEAP_KEY fm = AHEAP_KEYHUGE;
|
159
|
+
if ( i == H->end-1 ) return (AHEAP_findmin_head (H) );
|
160
|
+
i = AHEAP_LEAF (*H, i+1);
|
161
|
+
while ( i != j ){
|
162
|
+
if ( i%2 == 0 ){ /* if i is the child of larger index */
|
163
|
+
if ( fm > H->v[i-1] ){
|
164
|
+
fm = H->v[i-1];
|
165
|
+
fi = i-1;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
j = (j-1)/2;
|
169
|
+
if ( j == i ) break; /* stop if the right pointer and the left pointer are the same */
|
170
|
+
i = (i-1)/2;
|
171
|
+
}
|
172
|
+
while ( fi < H->end-1 ) fi = fi*2 + (H->v[fi*2+1]<=fm?1:2);
|
173
|
+
return (AHEAP_IDX(*H, fi) );
|
174
|
+
}
|
175
|
+
|
176
|
+
/* find the index having the minimum among given two indices */
|
177
|
+
AHEAP_ID AHEAP_interval_min (AHEAP *H, AHEAP_ID i, AHEAP_ID j){
|
178
|
+
AHEAP_ID fi=0;
|
179
|
+
AHEAP_KEY fm = AHEAP_KEYHUGE;
|
180
|
+
if ( i == 0 ) return (AHEAP_lower_min (H, j) );
|
181
|
+
if ( j == H->end-1 ) return (AHEAP_upper_min (H, i) );
|
182
|
+
i = AHEAP_LEAF (*H, i-1);
|
183
|
+
j = AHEAP_LEAF (*H, j+1);
|
184
|
+
while ( i != j && i != j-1 ){
|
185
|
+
if ( i%2 ){ /* if i is the child of smaller index */
|
186
|
+
if ( fm > H->v[i+1] ){
|
187
|
+
fm = H->v[i+1];
|
188
|
+
fi = i+1;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
i = (i-1)/2;
|
192
|
+
if ( j == i || j == i+1 ) break; /* stop if the right pointer and the left pointer are the same */
|
193
|
+
if ( j%2 == 0 ){ /* if j is the child of larger index */
|
194
|
+
if ( fm > H->v[j-1] ){
|
195
|
+
fm = H->v[j-1];
|
196
|
+
fi = j-1;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
j = (j-1)/2;
|
200
|
+
}
|
201
|
+
while ( fi < H->end-1 )
|
202
|
+
fi = fi*2 + (H->v[fi*2+1] <= fm?1:2);
|
203
|
+
return (AHEAP_IDX(*H, fi) );
|
204
|
+
}
|
205
|
+
|
206
|
+
/* print heap keys according to the structure of the heap */
|
207
|
+
void AHEAP_print (AHEAP *H){
|
208
|
+
AHEAP_ID i, j=1;
|
209
|
+
while ( j<=H->end*2-1 ){
|
210
|
+
FLOOP (i, j-1, MIN(j, H->end)*2-1) printf (AHEAP_KEYF ",", H->v[i] );
|
211
|
+
printf ("\n");
|
212
|
+
j = j*2;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
#endif
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*
|
2
|
+
array-based simple heap (fixed size)
|
3
|
+
12/Apr/2001 by Takeaki Uno e-mail:uno@nii.jp,
|
4
|
+
homepage: http://research.nii.ac.jp/~uno/index.html */
|
5
|
+
/* This program is available for only academic use, basically.
|
6
|
+
Anyone can modify this program, but he/she has to write down
|
7
|
+
the change of the modification on the top of the source code.
|
8
|
+
Neither contact nor appointment to Takeaki Uno is needed.
|
9
|
+
If one wants to re-distribute this code, please
|
10
|
+
refer the newest code, and show the link to homepage of
|
11
|
+
Takeaki Uno, to notify the news about the codes for the users. */
|
12
|
+
|
13
|
+
/* bench mark
|
14
|
+
PentiumIII 500MHz, Memory 256MB Linux
|
15
|
+
values 0-1,000,000 : set & del & get 1,000,000 times
|
16
|
+
2.55sec
|
17
|
+
|
18
|
+
# rotation == 1/5 per 1 set/del
|
19
|
+
|
20
|
+
*** simple array ***
|
21
|
+
value 0-1,000,000 set & set & set 1,000,000 times,
|
22
|
+
0.88sec
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifndef _aheap_h_
|
26
|
+
#define _aheap_h_
|
27
|
+
|
28
|
+
#include"stdlib2.h"
|
29
|
+
|
30
|
+
#ifndef AHEAP_KEY
|
31
|
+
#ifdef AHEAP_KEY_DOUBLE
|
32
|
+
#define AHEAP_KEY double
|
33
|
+
#define AHEAP_KEYHUGE DOUBLEHUGE
|
34
|
+
#define AHEAP_KEYF "%f"
|
35
|
+
#elif defined(AHEAP_KEY_WEIGHT)
|
36
|
+
#define AHEAP_KEY WEIGHT
|
37
|
+
#define AHEAP_KEYHUGE WEIGHTHUGE
|
38
|
+
#define AHEAP_KEYF WEIGHTF
|
39
|
+
#else
|
40
|
+
#define AHEAP_KEY int
|
41
|
+
#define AHEAP_KEYHUGE INTHUGE
|
42
|
+
#define AHEAP_KEYF "%d"
|
43
|
+
#endif
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#ifndef AHEAP_ID
|
47
|
+
#define AHEAP_ID int
|
48
|
+
#define AHEAP_ID_END INTHUGE
|
49
|
+
#define AHEAP_IDF "%d"
|
50
|
+
#endif
|
51
|
+
|
52
|
+
#define AHEAP_IDX(H,i) (((i)+1-(H).base)%(H).end)
|
53
|
+
#define AHEAP_LEAF(H,i) (((i)+(H).base)%(H).end+(H).end-1)
|
54
|
+
#define AHEAP_H(H,i) (H).v[(((i)+(H).base)%(H).end+(H).end-1)]
|
55
|
+
|
56
|
+
typedef struct {
|
57
|
+
unsigned char type;
|
58
|
+
AHEAP_KEY *v; /* array for heap key */
|
59
|
+
int end; /* the number of maximum elements */
|
60
|
+
int base; /* the constant for set 0 to the leftmost leaf */
|
61
|
+
} AHEAP;
|
62
|
+
|
63
|
+
QSORT_TYPE_HEADER (AHEAP_KEY, AHEAP_KEY)
|
64
|
+
QSORT_TYPE_HEADER (AHEAP_ID, AHEAP_ID)
|
65
|
+
extern AHEAP INIT_AHEAP;
|
66
|
+
|
67
|
+
/* initialization. allocate memory for H and fill it by +infinity */
|
68
|
+
void AHEAP_alloc (AHEAP *H, int num);
|
69
|
+
void AHEAP_end (AHEAP *H);
|
70
|
+
|
71
|
+
/* return the index of the leaf having the minimum key among the descendants
|
72
|
+
of the given node i. If several leaves with the smallest key are there,
|
73
|
+
return the minimum index among them if f=0, maximum index if f=1, and
|
74
|
+
random choice if f=2 */
|
75
|
+
AHEAP_ID AHEAP_findmin_node_ (AHEAP *H, AHEAP_ID i, int f);
|
76
|
+
AHEAP_ID AHEAP_findmin_node (AHEAP *H, AHEAP_ID i, int f);
|
77
|
+
AHEAP_ID AHEAP_findmin_head (AHEAP *H);
|
78
|
+
AHEAP_ID AHEAP_findmin_tail (AHEAP *H);
|
79
|
+
AHEAP_ID AHEAP_findmin_rnd (AHEAP *H);
|
80
|
+
|
81
|
+
/* return the index of the leaf having smaller value than a among the
|
82
|
+
descendants of the given node i. If several leaves with the smallest key
|
83
|
+
are there, return the minimum index among them if f=0, maximum index if f=1,
|
84
|
+
and random choice if f=2 */
|
85
|
+
AHEAP_ID AHEAP_findlow_node (AHEAP *H, AHEAP_KEY a, AHEAP_ID i, int f);
|
86
|
+
AHEAP_ID AHEAP_findlow_head (AHEAP *H, AHEAP_KEY a);
|
87
|
+
AHEAP_ID AHEAP_findlow_tail (AHEAP *H, AHEAP_KEY a);
|
88
|
+
AHEAP_ID AHEAP_findlow_rnd (AHEAP *H, AHEAP_KEY a);
|
89
|
+
|
90
|
+
/* return the index of the leaf having smaller value than a next/previous to
|
91
|
+
leaf i. return -1 if such a leaf does not exist */
|
92
|
+
AHEAP_ID AHEAP_findlow_nxt (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
|
93
|
+
AHEAP_ID AHEAP_findlow_prv (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
|
94
|
+
|
95
|
+
/* change the key of node i to a /Add a to the key of node i, and update heap H */
|
96
|
+
void AHEAP_chg (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
|
97
|
+
void AHEAP_add (AHEAP *H, AHEAP_ID i, AHEAP_KEY a);
|
98
|
+
|
99
|
+
/* update the ancestor of node i */
|
100
|
+
void AHEAP_update (AHEAP *H, AHEAP_ID i);
|
101
|
+
|
102
|
+
/* find the leaf with the minimum key value among the leaves having index
|
103
|
+
smaller/larger than i, or between i and j */
|
104
|
+
AHEAP_ID AHEAP_upper_min (AHEAP *H, AHEAP_ID i);
|
105
|
+
AHEAP_ID AHEAP_lower_min (AHEAP *H, AHEAP_ID i);
|
106
|
+
AHEAP_ID AHEAP_interval_min (AHEAP *H, AHEAP_ID i, AHEAP_ID j);
|
107
|
+
|
108
|
+
/* print heap keys according to the structure of the heap */
|
109
|
+
void AHEAP_print (AHEAP *H);
|
110
|
+
|
111
|
+
#endif
|