Пример #1
0
int main(int argc, char **argv)
{    
   int num_solutions, num_cols, i;
   double *sol, objval;
   
   sym_environment *env = sym_open_environment();
   
   sym_parse_command_line(env, argc, argv);
   
   sym_load_problem(env);

   sym_solve(env);

   sym_get_num_cols(env, &num_cols);
   sym_get_sp_size(env, &num_solutions);
   sol = (double *) malloc(num_cols*sizeof(double));
   for (i = 0; i < num_solutions; i++){
      sym_get_sp_solution(env, i, sol, &objval);
      printf("Solution of value %f found\n", objval);
   }
   free(sol);

   sym_close_environment(env);
   
   return(0);
}  
Пример #2
0
int sci_sym_setVarBound(char *fname){
	
	//error management variable
	SciErr sciErr;
	int iRet;
	
	//data declarations
	int *varAddress,varIndex,numVars;
	double inputDouble,newBound;
	bool isLower;
	
	//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,2,2) ;
	CheckOutputArgument(pvApiCtx,1,1) ;
	
	//get argument 1: index of variable whose bound is to be changed
	if(getUIntFromScilab(1,&varIndex))
		return 1;
	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;
	}else if(varIndex>=numVars){
		Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1);
		return 1;
	}
	
	//get argument 2: new bound
	if(getDoubleFromScilab(2,&newBound))
		return 1;
	
	//decide which function to execute
	isLower=(strcmp(fname,"sym_setVarLower")==0);
	if(isLower)
		iRet=sym_set_col_lower(global_sym_env,varIndex,newBound);
	else
		iRet=sym_set_col_upper(global_sym_env,varIndex,newBound);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
		Scierror(999, "An error occured. Has a problem been loaded?\n");
		return 1;
	}else{
		sciprint("Bound successfully changed.\n");
	}
	
	//code to give output
	if(return0toScilab())
		return 1;
	
	return 0;
}
Пример #3
0
int sci_sym_setObjCoeff(char *fname){
	
	//error management variable
	SciErr sciErr;
	int iRet;
	
	//data declarations
	int *varAddress,varIndex,numVars;
	double inputDouble,newCoeff;
	
	//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,2,2) ;
	CheckOutputArgument(pvApiCtx,1,1) ;
	
	//get argument 1: index of variable whose coefficient is to be changed
	if(getUIntFromScilab(1,&varIndex))
		return 1;
	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;
	}else if(varIndex>=numVars){
		Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1);
		return 1;
	}
	
	//get argument 2: new coefficient
	if(getDoubleFromScilab(2,&newCoeff))
		return 1;
	
	iRet=sym_set_obj_coeff(global_sym_env,varIndex,newCoeff);
	if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
		Scierror(999, "An error occured. Has a problem been loaded?\n");
		return 1;
	}else{
		sciprint("Coefficient successfully changed.\n");
	}
	
	//code to give output
	if(return0toScilab())
		return 1;
	
	return 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;
}
//function to remove specified columns
int sci_sym_delete_cols(char *fname, unsigned long fname_len){
	
	// Error management variables
	SciErr sciErr1,sciErr2;
	double status=1.0;//assume error status
	double num;//variable to store the number of columns to be deleted obtained from user in scilab
	int count=0;//iterator variable
	int num_cols;//stores the number of columns in the loaded problem
	int iType= 0;//stores the datatype of matrix 
	int rows=0,columns=0;//integer variables to denote the number of rows and columns in the array denoting the column numbers to be deleted
	unsigned int *value=NULL;//pointer to integer array allocated dynamically having the indices to be deleted
	double *array_ptr=NULL;//double array pointer to the array denoting the column numbers to be deleted
	int *piAddressVarOne = NULL;//pointer used to access first and second arguments of the function
	int output=0;//output parameter for the symphony sym_delete_cols function
	CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
	CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not

	//load address of 1st argument into piAddressVarOne
	sciErr2=getVarAddressFromPosition(pvApiCtx,1,&piAddressVarOne);

	
	if (sciErr2.iErr){
        printError(&sciErr2, 0);
        return 0;
	}

	//check if it is double type
	sciErr2 = getVarType(pvApiCtx, piAddressVarOne, &iType);
	if(sciErr2.iErr || iType != sci_matrix)
	{
		printError(&sciErr2, 0);
		return 0;
	}

		
	//getting the first argument as a double array
	sciErr2=getMatrixOfDouble(pvApiCtx,piAddressVarOne,&rows,&columns,&array_ptr);
	if (sciErr2.iErr){
        printError(&sciErr2, 0);
        return 0;
	}

	//dynamically allocate the integer array 
	value=(unsigned int *)malloc(sizeof(unsigned int)*columns);
	//store double values in the integer array by typecasting
	while(count<columns)
	{
		value[count]=(unsigned int)array_ptr[count];
		count++;
	}	
	sciprint("\n");

	//ensure that environment is active

	if(global_sym_env==NULL){
		sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
		}
	else {
		int flag=0;//flag used for finding if the indices to be deleted are valid
		output=sym_get_num_cols(global_sym_env,&num_cols);//function to find the number of columns in the loaded problem
		if(output==FUNCTION_TERMINATED_ABNORMALLY)
		{
			Scierror(999, "An error occured. Has a problem been loaded?\n");
			free(value);//freeing the memory of the allocated pointer
			return 0;
		}
		for(count=0;count<columns;count++)//loop used to check if all the indices mentioned to be deleted are valid
		{
			if(value[count]<0   ||  value[count]>=num_cols){
				flag=1;
				break;
		}	
				
		}
		if(flag==1)
		{
			Scierror(999,"Not valid indices..\n");
			sciprint("valid indices are from 0 to %d",num_cols-1);
			free(value);//freeing the memory of the allocated pointer
			return 0;
		}
		//only when the number of columns to be deleted is lesser than the actual number of columns ,execution is proceeded with
		if(columns<=num_cols){
		output=sym_delete_cols(global_sym_env,(unsigned int)columns,value);//symphony function to delete the columns specified
		if(output==FUNCTION_TERMINATED_NORMALLY)
		{
			sciprint("Execution is successfull\n");
			status=0.0;
		}
		else if(output==FUNCTION_TERMINATED_ABNORMALLY)
		{
			Scierror(999,"Problem occured while deleting the columns,Are the column numbers correct?\n");
			sciprint("Function terminated abnormally\n");
			status=1.0;
		}
	}
		else{
			sciprint("These many number of variables dont exist in the problem\n");
			status=1.0;
		}
				
	}
	
	int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
	if (e){
		AssignOutputVariable(pvApiCtx, 1) = 0;
		free(value);//freeing the memory of the allocated pointer
		return 1;
		}

	AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
	ReturnArguments(pvApiCtx);
	free(value);//freeing the memory of the allocated pointer
	return 0;
	}