int sci_sym_setObjSense(char *fname){ //error management variable SciErr sciErr; int iRet; //data declarations int *varAddress; double objSense; //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 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &varAddress); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) ) { Scierror(999, "Wrong type for input argument #1:\nEither 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 #1:\nEither 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; }else{ if(objSense==1) sciprint("The solver has been set to minimize the objective.\n"); else sciprint("The solver has been set to maximize the objective.\n"); } //code to give output if(return0toScilab()) return 1; return 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; }