Exemplo n.º 1
0
/*
 * Reads a file and try to build a binary program.
 */
BIP* read_BinaryProgram(const char* filename){
	// assertions
	assert( NULL != filename );
	assert( 0	 < strlen(filename));
	
	// read buffer
	char	buf[MAX_LINE_LENGTH];
	
	// file and strcuture pointer
	FILE*	fp;
	BIP*	bip = malloc(sizeof(*bip));
	
	// try to open file
	if ( NULL == ( fp = fopen(filename,"r") ) ){
		printf("[ERROR] Can't open file %s\n", filename);
		return NULL;
	}
	
	// inform user
	printf("Reading %s.\n", filename);
	
	// read in columns and rows
	storeMeta( buf, fp, &bip->cols );
	storeMeta( buf, fp, &bip->rows );
	
	// inform the user
	printf("BIP contains %d columns and %d rows.\n", bip->cols, bip->rows);
	
	// read constraints (number of rows)
	int i, j, mod;
	for ( i = 0, j = 0; i < bip->rows; i++ ){
		mod = readConstraint( buf, fp, bip->a[i+j], &bip->b[i+j], &bip->equalityType[i+j], bip->cols );
		if ( mod == FAILURE ){
			printf("[ERROR] Cannot read constraint %d.\n", (i+1));
			return NULL;
		} else if ( mod == LINE_JUMP ){
			j++; // comment line counter
		}
	}
	
	// close the file and return the bip
	fclose(fp);
	return bip;
}
Exemplo n.º 2
0
void
ProblemsReader::readProblem(unsigned int /*numProblem*/) {

	unsigned int numVariables;
	*_stream >> numVariables;

	// create a new problem
	boost::shared_ptr<Problem> problem = boost::make_shared<Problem>(numVariables);

	// add it to the existing problems
	_problems->addProblem(problem);

	LOG_DEBUG(streamproblemreaderlog) << "reading " << numVariables << " variables" << std::endl;

	for (unsigned int i = 0; i < numVariables; i++)
		readVariable(*problem, i);

	unsigned int numConstraints;
	*_stream >> numConstraints;

	for (unsigned int i = 0; i < numConstraints; i++)
		readConstraint(*problem, i);
}