/***************************************************************************** ** main.c = main routine for Banzhaf power index computations ** ** Original version: Mark A. Livingston, 24 Dec 95 ** Dept. of Computer Science, Univ. of North Carolina ** ** Last modification: 05 May 2000 (Added qualified majority switch) ** Hewlett-Packard Laboratories, Palo Alto, California ** ** Copyright (C) 1995--2000, Mark A. Livingston, The University of North ** Carolina at Chapel Hill, Hewlett-Packard Company ** ** Driver for the Banzhaf power index computation *****************************************************************************/ #include #include #include "banzhaf.h" void usage( char *pname ) { printf( "Usage: %s [ options ]\n\n", pname ); printf( "\tOptions are\n" ); printf( "\t\t-v\t= turn on verbose mode\n" ); printf( "\t\t-mN\t= set definition of \"majority\" to N votes\n" ); printf( "\t\t-f \t= read input data from \n\n" ); printf( "If no data file is specified on the command line, stdin is " ); printf( "assumed.\n" ); printf( "The data file consists of a line with a number of blocks,\n" ); printf( "followed by one line for each block, with the format of\n\n" ); printf( "\t \n\n" ); return; } int main( int argc, char *argv[] ) { int i, count, majority; char *fname = NULL; Boolean done, verbose = False, setMajority = False; Block *bl; /* check for correct usage */ for( i = 1; i < argc; i++ ) { if( !strncmp( argv[i], "-v", 2 ) ) verbose = True; else if( !strncmp( argv[i], "-m", 2 ) ) { setMajority = True; sscanf( argv[i], "-m%d", &majority ); } else if( !strcmp( argv[i], "-f" ) ) fname = argv[ ++i ]; else { fprintf( stderr, "%s: Unknown argument '%s'\n", argv[0], argv[i] ); usage( argv[0] ); exit( -1 ); } } /* end for( i ) */ /* read the data */ count = banzhafReadBlocks( fname, &bl ); if( count <= 0 ) exit( -2 ); if( setMajority ) banzhafSetMajority( majority ); done = banzhafNextCoalition( bl, count, verbose ); while( !done ) { if( banzhafHasCritical( bl, count ) ) banzhafCountCritical( bl, count ); done = banzhafNextCoalition( bl, count, verbose ); } /* end while */ banzhafComputeRatios( bl, count ); banzhafPrintTable( bl, count ); return 0; }