📄 code_spiel.c
字号:
/* code_spiel.c (c) DJCM 96 01 17 from code4r.c makes spielman-inspired sparse alist matrix of this form ...: from a sparse alist matrix of the form ...., by adding extra 1s to the right hand end code_spiel -i infile -s style (1/2/3) -o outfile style = 1 adds weight three cols, uniform. style = 2 adds weight two cols, with top rows being unaffected style = 3 adds weight 1 cols, with top two rows being unaffectedeg usage: code_spiel -i MNC4RC/15000.10000.3.0.1523 -seed 1523 -s 1 -o MNC4RC/15000.10000.3.0.1523I code_spiel -i MNC4RC/15000.10000.3.0.1523 -seed 1524 -s 2 -o MNC4RC/15000.10000.3.0.1523II code_spiel -i MNC4RC/15000.10000.3.0.1523 -seed 1525 -s 3 -o MNC4RC/15000.10000.3.0.1523III code_spiel -i MNC4RC/12.4.3.111 -s 1 -o tmpo code_spiel -i MNC4RC/12.4.3.111 -seed 1234 -s 2 -o tmpo code_spiel -i MNC4RC/12.4.3.111 -seed 1234 -s 3 -o tmpo*/#include "./ansi/r.h"#include "./ansi/rand2.h" #include "./ansi/mynr.h"#include "./ansi/cmatrix.h"typedef struct { /* code_control */#include "code_ez_var_str.h"} code_creation ;static void dc_defaults ( code_creation * ) ; static int process_command ( int , char ** , code_creation * ) ; static void print_usage ( char ** , FILE * , code_creation * );static int report_code ( code_creation * , alist_matrix * ) ;static int check_alist ( alist_matrix * , code_creation * ) ;void main ( int , char ** ) ;/* MAIN */void main ( int argc, char *argv[] ){ FILE *fp ; int u , N , M , No , Mo , n , m , q, M3 , N3 , t , nr , mm; code_creation dc ; alist_matrix a ; alist_matrix ai ; int *fto , *qs ; /* permutation */ dc_defaults ( &dc ) ; if ( process_command (argc, argv, &dc ) < 0 ) exit (0) ; if ( read_allocate_alist ( &ai , dc.afile ) < 0 ) exit (0) ; N = ai.N ; M = ai.M ; if ( N < M ) { fprintf ( stderr, "sorry N<M is not handled by this code \n" ) ; exit(0); } No = N ; Mo = M ; dc.M = Mo ; dc.N = No ; M3 = M / 3 ; N3 = N - M3 ; ran_seed ( dc.seed ) ; dc.t = ai.biggest_num_n + 3 + 1 ; dc.tr = ai.biggest_num_m + 1 + 1 ; initialize_alist ( &a , No , Mo , dc.t , dc.tr ) ; fprintf(stderr,"code_spiel N=%d, M=%d style=%d\n", N , M , dc.style ) ; fflush(stderr); /* run through all elements in ai copying them */ for ( n = 1 ; n <= N ; n ++ ) { for ( u = 1 ; u <= ai.num_nlist[n] ; u ++ ) { m = ai.nlist[n][u] ; add_to_alist ( &a , n , m ) ; } } /* add perms */ if ( dc.style == 2 ) { m = M3 + 1 ; t = 2 ; } else if ( dc.style == 3 ) { m = 2 * M3 + 1 ; t = 3 ; } else { m = 1 ; t = 1 ; } fto = ivector ( 1 , M3 ) ; qs = ivector ( 1 , M3 ) ; /* invent random permutation */ for ( ; t <= 3 ; t ++ ) { for ( n = 1 ; n <= M3 ; n ++ ) { fto[n] = 0 ; qs[n] = n ; } for ( nr = M3 , mm = 1 ; mm <= M3 ; mm ++ , nr -- ) { q = rani ( nr ) + 1 ; fto[mm] = qs[q] ; for ( ; q<nr ; q++ ) { /* shuffle along the list */ qs[q] = qs[q+1] ; } } for ( u = 1 ; u <= M3 ; u ++ ) { if ( fto[u] < 1 || fto[u] > M3 ) { fprintf ( stderr , "crisis %d\n" , u ) ; } n = N3 + fto[u] ; add_to_alist ( &a , n , m ) ; if ( dc.verbose ) { fprintf ( stderr , "%d %d\n" , n , m ) ; } m ++ ; } } finish_off_alist ( &a ) ; if ( check_alist ( &a , &dc ) < 0 ) { report_code ( &dc , &a ) ; printf ( "FAILED\n" ) ; /* exit ( 0 ) ; */ } if ( dc.out ) { fp = fopen ( dc.outfile , "w" ) ; if ( !fp ) { fprintf ( stderr , "can't open %s\n" , dc.outfile ) , exit (0) ; } write_alist ( fp , &a ) ; fclose ( fp ) ; } free_alist ( &a ) ; if ( dc.verbose ) { read_allocate_alist ( &a , dc.outfile ) ; if ( dc.out ) { fp = fopen ( "tmpout" , "w" ) ; if ( !fp ) { fprintf ( stderr , "can't open %s\n" , dc.outfile ) , exit (0) ; } write_alist ( fp , &a ) ; fclose ( fp ) ; } free_alist ( &a ) ; printf ( "diff tmpout %s\n" , dc.outfile ) ; }}static int report_code ( code_creation *dc , alist_matrix *a ) { int status = 0 ; report_alist ( a , dc->verbose + 1 ) ; return status ; }static int check_alist ( alist_matrix *alist , code_creation *dc ){ int status = 0 ; int tmpi = 0 , n , m ; if ( dc->verbose ) printf ( "Checking alist\n" ) ; /* check: every col should have more than 1 1 in it */ for ( n = 1 ; n <= alist->N ; n ++ ) { if ( alist->num_nlist[n] <= 1 ) { tmpi ++ ; fprintf ( stderr , "%d:" , n ) ; } } if ( tmpi > 0 ) { fprintf ( stderr , "Warning unchecked bits n : %d\n", tmpi ) ;/* status -- ; in ez code this is not a failure */ } /* check: every row should have more than 1 1 in it */ tmpi = 0 ; for ( m = 1 ; m <= alist->M ; m ++ ) { if ( alist->num_mlist[m] <= 1 ) { tmpi ++ ; fprintf ( stderr , "%d:" , m ) ; } } if ( tmpi > 0 ) { fprintf ( stderr , "Warning unchecked bits m : %d\n", tmpi ) ; status -= 10 ; } if ( status < 0 && dc->verbose ) { fprintf ( stderr , "Failing ... here is the offending alist\n" ) ; report_alist ( alist , 2 ) ; } else if ( dc->verbose >= 2 ) { report_alist ( alist , dc->verbose ) ; } return status ; }static void dc_defaults ( code_creation *dc ) {#include "code_ez_var_def.c"}static int process_command ( int argc , char **argv , code_creation *dc ) { int p_usage = 0 ; int status = 0 ; int cs , i , fake ; if ( argc < 1 ) { p_usage = 1 ; status -- ; }#define ERROR1 fprintf ( stderr , "arg to `%s' missing\n" , argv[i] ) ; \ status --#define ERROR2 fprintf ( stderr , "args to `%s' missing\n" , argv[i] ) ; \ status -- for (i = 1 ; i < argc; i++) { cs = 1 ; if ( strcmp (argv[i], "-fake") == 0 ) { if ( i + 1 == argc ) { ERROR1; } else cs *= sscanf(argv[++i], "%d", &(fake)); } #include "code_ez_var_clr.c" else { fprintf ( stderr , "arg `%s' not recognised\n" , argv[i] ) ; p_usage = 1 ; status -- ; } if ( cs == 0 ) { fprintf ( stderr , "arg at or before `%s' has incorrect format\n" , argv[i] ) ; p_usage = 1 ; status -- ; } } if ( p_usage ) print_usage ( argv , stderr , dc ) ; return ( status ) ;}#undef ERROR1#undef ERROR2#define DNT fprintf( fp, "\n ")#define NLNE fprintf( fp, "\n")static void print_usage ( char **argv , FILE * fp , code_creation *dc){ fprintf( fp, "Usage: %s ",argv[0]); fprintf( fp, " [optional arguments]");#include "code_ez_var_usg.c" return ;}#undef DNT#undef NLNE/*<!-- hhmts start -->Last modified: Sat Feb 3 18:54:48 1996<!-- hhmts end -->*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -