コード例 #1
0
//basic problem loader, expects normal matrix. Not suitable for large problems
int sci_sym_loadProblemBasic(char *fname)
{
	
	if(commonCodePart1())
		return 1;
		
	//get input 8: matrix of constraint equation coefficients
	if(getFixedSizeDoubleMatrixFromScilab(8,numConstr,numVars,&conMatrix))
	{
		cleanupBeforeExit();
		return 1;
	}

	conMatrixColStart=new int[numVars+1]; //start of each column of constraint matrix, used internally
	conMatrixRowIndex=new int[numVars*numConstr]; //index of column elements in each column, used internally
	for(colIter=0;colIter<numVars;colIter++)
	{
		conMatrixColStart[colIter]=colIter*numConstr;
		for(rowIter=0;rowIter<numConstr;rowIter++)
		{
			conMatrixRowIndex[colIter*numConstr+rowIter]=rowIter;
		}
	}
	conMatrixColStart[numVars]=numVars*numConstr;
	
	if(commonCodePart2())
		return 1;

	return 0;
}
コード例 #2
0
int sci_sym_setColSoln(char *fname){
	
	//error management variable
	SciErr sciErr;
	int iRet;
	
	//data declarations
	int numVars;
	double *solution;
	
	//ensure that environment is active
	if(global_sym_env==NULL){
		sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
		return 1;
	}
	
	//code to check arguments and get them
	CheckInputArgument(pvApiCtx,1,1) ;
	CheckOutputArgument(pvApiCtx,1,1) ;
	
	//code to process input
	iRet=sym_get_num_cols(global_sym_env,&numVars);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
		Scierror(999, "An error occured. Has a problem been loaded?\n");
		return 1;
	}
	
	if(getFixedSizeDoubleMatrixFromScilab(1,1,numVars,&solution))
		return 1;

	iRet=sym_set_col_solution(global_sym_env,solution);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
		Scierror(999, "An error occured. The given solution may be infeasible\nor worse than the current solution.\n");
		return 1;
	}
	
	//code to give output
	if(return0toScilab())
		return 1;
	
	return 0;
}
コード例 #3
0
//both basic and advanced loader use this code
static int commonCodePart2()
{
	//get input 3: lower bounds of variables
	if(getFixedSizeDoubleMatrixFromScilab(3,1,numVars,&lowerBounds))
	{
		cleanupBeforeExit();
		return 1;
	}
	
	//get input 4: upper bounds of variables
	if(getFixedSizeDoubleMatrixFromScilab(4,1,numVars,&upperBounds))
	{
		cleanupBeforeExit();
		return 1;
	}
	
	//get input 5: coefficients of variables in objective function to be minimized
	if(getFixedSizeDoubleMatrixFromScilab(5,1,numVars,&objective))
	{
		cleanupBeforeExit();
		return 1;
	}
	
	//get input 6: array that specifies wether a variable is constrained to be an integer
	sciErr = getVarAddressFromPosition(pvApiCtx, 6, &varAddress);
	if (sciErr.iErr)
	{
		printError(&sciErr, 0);
		cleanupBeforeExit();return 1;
	}
	if ( !isBooleanType(pvApiCtx, varAddress) )
	{
		Scierror(999, "Wrong type for input argument #6: A matrix of booleans is expected.\n");
		cleanupBeforeExit();return 1;
	}
	sciErr = getMatrixOfBoolean(pvApiCtx, varAddress, &inputMatrixRows, &inputMatrixCols, &isIntVarBool);
	if (sciErr.iErr)
	{
		printError(&sciErr, 0);
		cleanupBeforeExit();return 1;
	}
	if(inputMatrixRows!=1 || inputMatrixCols!=numVars)
	{
		Scierror(999, "Wrong type for input argument #6: Incorrectly sized matrix.\n");
		cleanupBeforeExit();return 1;
	}
	for(colIter=0;colIter<numVars;colIter++)
	{
		if(isIntVarBool[colIter])
			isIntVar[colIter]=TRUE;
		else
			isIntVar[colIter]=FALSE;
	}
	
	//get input 7: wether to minimize or maximize objective
	sciErr = getVarAddressFromPosition(pvApiCtx, 7, &varAddress);
	if (sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 1;
	}
	if ( !isDoubleType(pvApiCtx,varAddress) ||  isVarComplex(pvApiCtx,varAddress) )
	{
		Scierror(999, "Wrong type for input argument #7: Either 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
		return 1;
	}
	iRet = getScalarDouble(pvApiCtx, varAddress, &objSense);
	if(iRet || (objSense!=-1 && objSense!=1))
	{
		Scierror(999, "Wrong type for input argument #7: Either 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
		return 1;
	}
	iRet=sym_set_obj_sense(global_sym_env,objSense);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY)
	{
		Scierror(999, "An error occured.\n");
		return 1;
	}
	
	//get input 9: constraint lower bound
	if(getFixedSizeDoubleMatrixFromScilab(9,numConstr,1,&conLower))
	{
		cleanupBeforeExit();
		return 1;
	}
	
	//get input 10: constraint upper bound
	if(getFixedSizeDoubleMatrixFromScilab(10,numConstr,1,&conUpper))
	{
		cleanupBeforeExit();
		return 1;
	}
	
	//deduce type of constraint
	for(rowIter=0;rowIter<numConstr;rowIter++)
	{
		if(conLower[rowIter]>conUpper[rowIter])
		{
			Scierror(999, "Error: the lower bound of constraint %d is more than its upper bound.\n",rowIter);
			cleanupBeforeExit();
			return 1;
		}
		if(conLower[rowIter]==(-INFINITY) && conUpper[rowIter]==INFINITY){
			conType[rowIter]='N';
			conRange[rowIter]=0;
			conRHS[rowIter]=0;
		}else if(conLower[rowIter]==(-INFINITY)){
			conType[rowIter]='L';
			conRange[rowIter]=0;
			conRHS[rowIter]=conUpper[rowIter];
		}else if(conUpper[rowIter]==INFINITY){
			conType[rowIter]='G';
			conRange[rowIter]=0;
			conRHS[rowIter]=conLower[rowIter];
		}else if(conUpper[rowIter]==conLower[rowIter]){
			conType[rowIter]='E';
			conRange[rowIter]=0;
			conRHS[rowIter]=conLower[rowIter];
		}else{
			conType[rowIter]='R';
			conRange[rowIter]=conUpper[rowIter]-conLower[rowIter];
			conRHS[rowIter]=conUpper[rowIter];
		}
	}
	
	/*
	//for debug: show all data
	sciprint("Vars: %d Constr: %d ObjType: %lf\n",numVars,numConstr,objSense);
	for(colIter=0;colIter<numVars;colIter++)
		sciprint("Var %d: upper: %lf lower: %lf isInt: %d ObjCoeff: %lf\n",colIter,lowerBounds[colIter],upperBounds[colIter],isIntVar[colIter],objective[colIter]);
	for(rowIter=0;rowIter<numConstr;rowIter++)
		sciprint("Constr %d: type: %c lower: %lf upper: %lf range: %lf\n",rowIter,conType[rowIter],conLower[rowIter],conRange[rowIter]);
	*/
	
	//call problem loader
	sym_explicit_load_problem(global_sym_env,numVars,numConstr,conMatrixColStart,conMatrixRowIndex,conMatrix,lowerBounds,upperBounds,isIntVar,objective,NULL,conType,conRHS,conRange,TRUE);
	sciprint("Problem loaded into environment.\n");
	
	//code to give output
	cleanupBeforeExit();
	
	return 0;
}