-
Notifications
You must be signed in to change notification settings - Fork 4
/
gng_test.c
72 lines (62 loc) · 1.52 KB
/
gng_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <zm/zm_gng.h>
void gen_vec(zVecList *vl, int np, int nc, double xmin, double ymin, double xmax, double ymax, double rmax)
{
int i, j;
zVec vc;
double xc, yc, r, s, c;
zListInit( vl );
vc = zVecAlloc( 2 );
for( i=0; i<nc; i++ ){
xc = zRandF(xmin,xmax);
yc = zRandF(ymin,ymax);
for( j=0; j<np; j++ ){
r = zRandF(0,rmax);
zSinCos( zRandF(-zPI,zPI), &s, &c );
zVecSetElemList( vc, xc + r * c, yc + r * s );
zVecListInsertHead( vl, vc );
}
}
zVecFree( vc );
}
void vec_output(zVecList *points)
{
FILE *fp;
zVecListCell *vp;
fp = fopen( "src", "w" );
zListForEach( points, vp )
zVecDataFPrint( fp, vp->data );
fclose( fp );
}
#define NP 300
#define NC 6
#define R 1.5
int main(int argc, char *argv[])
{
zGNG gng;
zVecList points;
int np, nc, i;
FILE *fp1, *fp2;
char filename[BUFSIZ];
zRandInit();
np = argc > 1 ? atoi( argv[1] ) : NP;
nc = argc > 2 ? atoi( argv[2] ) : NC;
gen_vec( &points, np, nc, R, R, 10-R, 10-R, R );
vec_output( &points );
zGNGInit( &gng, 2, NULL, &points );
zGNGSetBatchTrialSize( &gng, 10 );
fp2 = fopen( "n", "w" );
for( i=0; i<zListSize(&points); i++ ){
zGNGUpdate( &gng, &points );
if( i % 10 == 0 ){
sprintf( filename, "%04d", i );
fp1 = fopen( filename, "w" );
zGNGFWrite( fp1, &gng );
fclose( fp1 );
}
fprintf( fp2, "%d %d\n", zListSize(&gng.unitlist), zListSize(&gng.edgelist) );
}
fclose( fp2 );
zGNGDestroy( &gng );
zVecListDestroy( &points );
return 0;
}