/* File randobj.c. Main program for randobj command, which may be used to construct a random point set of specified degree and size, or a random partition with specified cell sizes. The format of the command is:
randobj <options> set <name> <degree> <size> randobj <options> set <name> <degree>
where the meaning of the parameters is as follows:
<name>: the name for the point set constructed, <degree>: the degree for the point set (i.e, the point set will be a subset of {1,...,degree}), <size>: the number of points in the point set.
The valid options are follows: -s:<integer> Sets seed for random number generator to <integer>, -cl:<libName> Append the point set in Cayley library format to library
libName. */
/* If there are no options, provide usage information and exit. */ if ( argc == 1 ) {
printf( "\nUsage: randobj [-e] type degree size object\n"); return 0;
}
/* Check for limits option. If present in position 1, give limits and
return. */ if ( strcmp( argv[1], "-l") == 0 || strcmp( argv[1], "-L") == 0 ) {
showLimits(); return 0;
} /* Check for verify option. If present in position i (i as above) perform
verify (Note verifyOptions terminates program). */ if ( strcmp( argv[1], "-v") == 0 || strcmp( argv[1], "-V") == 0 )
verifyOptions();
/* Count the number of options. */ for ( optionCountPlus1 = 1 ; optionCountPlus1 <= argc-1 &&
argv[optionCountPlus1][0] == '-' ; ++optionCountPlus1 )
;
/* Check for exactly 4 parameters following options. */ if ( argc - optionCountPlus1 != 4 )
ERROR( "main (randobj)", "Exactly 4 non-option parameters are required.")
/* Determine the set size, the number of cells (-e option), or the
cell sizes (no -e option). */ switch( objectType ) { case POINT_SET:
errno = 0;
setSize = strtol( argv[optionCountPlus1+2], NULL, 0); if ( errno || setSize < 1 || setSize >= degree )
ERROR( "main (randobj command)", "Invalid entry for set size.") break; case PARTITION: if ( equalSizeFlag ) {
errno = 0;
numberOfEqualCells = strtol( argv[optionCountPlus1+2], NULL, 0); if ( errno || numberOfEqualCells < 1 || numberOfEqualCells > degree )
ERROR( "main (randobj command)", "Invalid entry for number of equal-size cells.")
} else {
errno = 0;
j = 0;
cellSizeSum = 0;
currentPos = argv[optionCountPlus1+2]; do {
designatedCellSize[++j] = (unsignedlong) strtol( currentPos, &nextPos, 0); if ( errno )
ERROR( "main (randobj command)", "Invalid cell size.")
cellSizeSum += designatedCellSize[j];
currentPos = nextPos+1;
} while ( *nextPos == ',' && j <= 100 );
designatedCellSize[j+1] = 0; if ( j > 100 || *nextPos != '\0' )
ERROR( "main (randobj command)", "Cell size list invalid or too long.") if ( cellSizeSum != degree )
ERROR( "main (randobj command)", "Cell sizes do not sum to degree.")
} break; default: /* can not actually reach here, silence a compiler warning */ break;
}
/* Compute file and library names for output object. */
parseLibraryName( argv[optionCountPlus1+3], "", "",
outputFileName, outputLibraryName);
/* Initialize storage manager and random number generator. */
initializeStorageManager( degree);
initializeSeed( seed);
/* Now we construct a random ordering of 1,...,degree. */
randOrder = allocIntArrayDegree(); for ( i = 1 ; i <= degree ; ++i )
randOrder[i] = i; for ( i = 1 ; i <= degree-1 ; ++i ) {
j = randInteger( i, degree);
EXCHANGE( randOrder[i], randOrder[j], temp);
}
/* Construct and write out the point set or partition. */ switch ( objectType ) {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.