diff options
Diffstat (limited to 'sci_gateway')
-rw-r--r-- | sci_gateway/cpp/README.rst | 49 | ||||
-rw-r--r-- | sci_gateway/cpp/README.rst~ | 0 | ||||
-rw-r--r-- | sci_gateway/cpp/builder_gateway_cpp.sce | 6 | ||||
-rw-r--r-- | sci_gateway/cpp/builder_gateway_cpp.sce~ | 149 | ||||
-rwxr-xr-x | sci_gateway/cpp/libFAMOS.so | bin | 126936 -> 126944 bytes | |||
-rw-r--r-- | sci_gateway/cpp/sci_iofunc.cpp | 4 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_ipopt.cpp | 38 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_getrowact.cpp | 2 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_loadproblem.cpp | 2 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_remove.cpp | 4 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_set_variables.cpp | 14 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_solution.cpp | 2 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_sym_solve.cpp~ | 49 | ||||
-rw-r--r-- | sci_gateway/cpp/sym_data_query_functions.cpp | 6 |
14 files changed, 302 insertions, 23 deletions
diff --git a/sci_gateway/cpp/README.rst b/sci_gateway/cpp/README.rst new file mode 100644 index 0000000..3348354 --- /dev/null +++ b/sci_gateway/cpp/README.rst @@ -0,0 +1,49 @@ +SCILAB GATEWAY +============== + +It is used to call the native functions written in C to scilab. + +List of Files +============= + +Symphony +-------- + +List of files used for symphony: + +1. globals.cpp +2. sci_solver_status_query_functions.cpp +3. sci_sym_addrowcal.cpp +4. sci_sym_getinfinity.cpp +5. sci_sym_getobjsense.cpp +6. sci_sym_getrowact.cpp +7. sci_sym_isenactive.cpp +8. sci_sym_load_mps.cpp +9. sci_sym_loadproblem.cpp +10. sci_sym_openclose.cpp +11. sci_sym_primalbound.cpp +12. sci_sym_remove.cpp +13. sci_sym_rowmod.cpp +14. sci_sym_setcolsoln.cpp +15. sci_sym_set_indices.cpp +16. sci_sym_setobj.cpp +17. sci_sym_set_variables.cpp +18. sci_sym_solution.cpp +19. sci_sym_solve.cpp +20. sci_sym_varbounds.cpp +21. sci_vartype.cpp +22. sym_data_query_functions.cpp +23. sci_iofunc.cpp +24. sci_iofunc.hpp + +qpipopt +------- + +List of files used for qpipopt: + +1. sci_iofunc.cpp +2. sci_iofunc.hpp +3. QuadNLP.hpp +4. sci_ipopt.cpp +5. sci_QuadNLP.cpp + diff --git a/sci_gateway/cpp/README.rst~ b/sci_gateway/cpp/README.rst~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sci_gateway/cpp/README.rst~ diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce b/sci_gateway/cpp/builder_gateway_cpp.sce index b42ac8e..225edd8 100644 --- a/sci_gateway/cpp/builder_gateway_cpp.sce +++ b/sci_gateway/cpp/builder_gateway_cpp.sce @@ -12,7 +12,7 @@ mode(-1) lines(0) -toolbox_title = "FAMOS" +toolbox_title = "FAMOS"; [a, opt] = getversion(); Version = opt(2); @@ -138,8 +138,8 @@ Files = [ "sci_sym_getrowact.cpp", "sci_sym_getobjsense.cpp", "sci_sym_remove.cpp", - "sci_QuadNLP.cpp" - "QuadNLP.hpp" + "sci_QuadNLP.cpp", + "QuadNLP.hpp", "sci_ipopt.cpp" ] diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce~ b/sci_gateway/cpp/builder_gateway_cpp.sce~ new file mode 100644 index 0000000..225edd8 --- /dev/null +++ b/sci_gateway/cpp/builder_gateway_cpp.sce~ @@ -0,0 +1,149 @@ +// Copyright (C) 2015 - IIT Bombay - FOSSEE +// +// Author: Keyur Joshi, Sai Kiran, Iswarya and Harpreet Singh +// Organization: FOSSEE, IIT Bombay +// Email: harpreet.mertia@gmail.com +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + +mode(-1) +lines(0) + +toolbox_title = "FAMOS"; + +[a, opt] = getversion(); +Version = opt(2); + +path_builder = get_absolute_file_path('builder_gateway_cpp.sce'); + +tools_path = path_builder + "../../thirdparty/linux/"; + +C_Flags=["-w -fpermissive -I"+tools_path+"include/coin -Wl,-rpath="+tools_path+"lib/"+Version+filesep()+" "] + +Linker_Flag = ["-L"+tools_path+"lib/"+Version+filesep()+"libSym"+" "+"-L"+tools_path+"lib/"+Version+filesep()+"libipopt" ] + + +//Name of All the Functions +Function_Names = [ + //for opening/closing environment and checking if it is open/close + "sym_open","sci_sym_open"; + "sym_close","sci_sym_close"; + "sym_isEnvActive","sci_sym_isEnvActive"; + + //run time parameters + "sym_resetParams","sci_sym_set_defaults"; + "sym_setIntParam","sci_sym_set_int_param"; + "sym_getIntParam","sci_sym_get_int_param"; + "sym_setDblParam","sci_sym_set_dbl_param"; + "sym_getDblParam","sci_sym_get_dbl_param"; + "sym_setStrParam","sci_sym_set_str_param"; + "sym_getStrParam","sci_sym_get_str_param"; + "sym_getInfinity","sci_sym_getInfinity"; + + //problem loaders + "sym_loadProblemBasic","sci_sym_loadProblemBasic"; + "sym_loadProblem","sci_sym_loadProblem"; + "sym_loadMPS","sci_sym_load_mps"; + + //basic data + "sym_getNumConstr","sci_sym_get_num_int"; + "sym_getNumVar","sci_sym_get_num_int"; + "sym_getNumElements","sci_sym_get_num_int"; + + //variable and objective data + "sym_isContinuous","sci_sym_isContinuous"; + "sym_isBinary","sci_sym_isBinary"; + "sym_isInteger","sci_sym_isInteger"; + "sym_setContinuous","sci_sym_set_continuous"; + "sym_setInteger","sci_sym_set_integer"; + "sym_getVarLower","sci_sym_get_dbl_arr"; + "sym_getVarUpper","sci_sym_get_dbl_arr"; + "sym_setVarLower","sci_sym_setVarBound"; + "sym_setVarUpper","sci_sym_setVarBound"; + "sym_getObjCoeff","sci_sym_get_dbl_arr"; + "sym_setObjCoeff","sci_sym_setObjCoeff"; + "sym_getObjSense","sci_sym_getObjSense"; + "sym_setObjSense","sci_sym_setObjSense"; + + //constraint data + "sym_getRhs","sci_sym_get_dbl_arr"; + "sym_getConstrRange","sci_sym_get_dbl_arr"; + "sym_getConstrLower","sci_sym_get_dbl_arr"; + "sym_getConstrUpper","sci_sym_get_dbl_arr"; + "sym_setConstrLower","sci_sym_setConstrBound"; + "sym_setConstrUpper","sci_sym_setConstrBound"; + "sym_setConstrType","sci_sym_setConstrType"; + "sym_getMatrix","sci_sym_get_matrix"; + "sym_getConstrSense","sci_sym_get_row_sense"; + + //add/remove variables and constraints + "sym_addConstr","sci_sym_addConstr"; + "sym_addVar","sci_sym_addVar"; + "sym_deleteVars","sci_sym_delete_cols"; + "sym_deleteConstrs","sci_sym_delete_rows"; + + //primal bound + "sym_getPrimalBound","sci_sym_getPrimalBound"; + "sym_setPrimalBound","sci_sym_setPrimalBound"; + + //set preliminary solution + "sym_setVarSoln","sci_sym_setColSoln"; + + //solve + "sym_solve","sci_sym_solve"; + + //post solve functions + "sym_getStatus","sci_sym_get_status"; + "sym_isOptimal","sci_sym_get_solver_status"; + "sym_isInfeasible","sci_sym_get_solver_status"; + "sym_isAbandoned","sci_sym_get_solver_status"; + "sym_isIterLimitReached","sci_sym_get_solver_status"; + "sym_isTimeLimitReached","sci_sym_get_solver_status"; + "sym_isTargetGapAchieved","sci_sym_get_solver_status"; + "sym_getVarSoln","sci_sym_getVarSoln"; + "sym_getObjVal","sci_sym_getObjVal"; + "sym_getIterCount","sci_sym_get_iteration_count"; + "sym_getConstrActivity","sci_sym_getRowActivity"; + + //QP function + "solveqp","sci_solveqp" + ]; + +//Name of all the files to be compiled +Files = [ + "globals.cpp", + "sci_iofunc.hpp", + "sci_iofunc.cpp", + "sci_sym_openclose.cpp", + "sci_solver_status_query_functions.cpp", + "sci_sym_solve.cpp", + "sci_sym_loadproblem.cpp", + "sci_sym_isenvactive.cpp", + "sci_sym_load_mps.cpp", + "sci_vartype.cpp", + "sci_sym_getinfinity.cpp", + "sci_sym_solution.cpp", + "sym_data_query_functions.cpp" + "sci_sym_set_variables.cpp", + "sci_sym_setobj.cpp", + "sci_sym_varbounds.cpp", + "sci_sym_rowmod.cpp", + "sci_sym_set_indices.cpp", + "sci_sym_addrowcol.cpp", + "sci_sym_primalbound.cpp", + "sci_sym_setcolsoln.cpp", + "sci_sym_getrowact.cpp", + "sci_sym_getobjsense.cpp", + "sci_sym_remove.cpp", + "sci_QuadNLP.cpp", + "QuadNLP.hpp", + "sci_ipopt.cpp" + + ] + +tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags, [], "g++"); + +clear WITHOUT_AUTO_PUTLHSVAR toolbox_title Function_Names Files Linker_Flag C_Flags; diff --git a/sci_gateway/cpp/libFAMOS.so b/sci_gateway/cpp/libFAMOS.so Binary files differindex d3b1e35..4a210ee 100755 --- a/sci_gateway/cpp/libFAMOS.so +++ b/sci_gateway/cpp/libFAMOS.so diff --git a/sci_gateway/cpp/sci_iofunc.cpp b/sci_gateway/cpp/sci_iofunc.cpp index 8895010..e1c8610 100644 --- a/sci_gateway/cpp/sci_iofunc.cpp +++ b/sci_gateway/cpp/sci_iofunc.cpp @@ -173,7 +173,7 @@ int return0toScilab() //make it the output variable AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; //return it to scilab - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -189,6 +189,6 @@ int returnDoubleToScilab(double retVal) return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } diff --git a/sci_gateway/cpp/sci_ipopt.cpp b/sci_gateway/cpp/sci_ipopt.cpp index 5837df1..4168488 100644 --- a/sci_gateway/cpp/sci_ipopt.cpp +++ b/sci_gateway/cpp/sci_ipopt.cpp @@ -4,6 +4,7 @@ Sai Kiran Keyur Joshi Iswarya + Harpreet Singh */ @@ -51,13 +52,14 @@ bool readSparse(int arg,int *iRows,int *iCols,int *iNbItem,int** piNbItemRow, in int sci_solveqp(char *fname) { - CheckInputArgument(pvApiCtx, 10, 10); // We need total 10 input arguments. + CheckInputArgument(pvApiCtx, 11, 11); // We need total 10 input arguments. CheckOutputArgument(pvApiCtx, 7, 7); // Error management variable SciErr sciErr; - int retVal=0, *piAddressVarQ = NULL,*piAddressVarP = NULL,*piAddressVarCM = NULL,*piAddressVarCUB = NULL,*piAddressVarCLB = NULL, *piAddressVarLB = NULL,*piAddressVarUB = NULL,*piAddressVarG = NULL; - double *QItems=NULL,*PItems=NULL,*ConItems=NULL,*conUB=NULL,*conLB=NULL,*varUB=NULL,*varLB=NULL,*init_guess = NULL,x,f,iter; + int retVal=0, *piAddressVarQ = NULL,*piAddressVarP = NULL,*piAddressVarCM = NULL,*piAddressVarCUB = NULL,*piAddressVarCLB = NULL, *piAddressVarLB = NULL,*piAddressVarUB = NULL,*piAddressVarG = NULL,*piAddressVarParam = NULL; + double *QItems=NULL,*PItems=NULL,*ConItems=NULL,*conUB=NULL,*conLB=NULL,*varUB=NULL,*varLB=NULL,*init_guess = NULL; + double *cpu_time=NULL, *max_iter=NULL, x,f,iter; static unsigned int nVars = 0,nCons = 0; unsigned int temp1 = 0,temp2 = 0; @@ -294,6 +296,34 @@ int sci_solveqp(char *fname) return 0; } + //Setting the parameters + /* get Address of inputs */ + sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddressVarParam); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + temp1 = 1; + temp2 = 1; + + /* get matrix */ + sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddressVarParam, 2, &temp1,&temp2, &max_iter); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + /* get matrix */ + sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddressVarParam, 4, &temp1,&temp2, &cpu_time); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + using namespace Ipopt; SmartPtr<QuadNLP> Prob = new QuadNLP(nVars,nCons,QItems,PItems,ConItems,conUB,conLB,varUB,varLB,init_guess); @@ -304,6 +334,8 @@ int sci_solveqp(char *fname) // Note: The following choices are only examples, they might not be // suitable for your optimization problem. app->Options()->SetNumericValue("tol", 1e-7); + app->Options()->SetIntegerValue("max_iter", (int)*max_iter); + app->Options()->SetNumericValue("max_cpu_time", *cpu_time); app->Options()->SetStringValue("mu_strategy", "adaptive"); // Indicates whether all equality constraints are linear diff --git a/sci_gateway/cpp/sci_sym_getrowact.cpp b/sci_gateway/cpp/sci_sym_getrowact.cpp index fac3ddf..ebfd9ff 100644 --- a/sci_gateway/cpp/sci_sym_getrowact.cpp +++ b/sci_gateway/cpp/sci_sym_getrowact.cpp @@ -58,7 +58,7 @@ int sci_sym_getRowActivity(char *fname){ return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); delete[] rowAct; diff --git a/sci_gateway/cpp/sci_sym_loadproblem.cpp b/sci_gateway/cpp/sci_sym_loadproblem.cpp index 6d7f538..b732eeb 100644 --- a/sci_gateway/cpp/sci_sym_loadproblem.cpp +++ b/sci_gateway/cpp/sci_sym_loadproblem.cpp @@ -42,7 +42,7 @@ static void cleanupBeforeExit() return; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); } static int checkNumArgs() diff --git a/sci_gateway/cpp/sci_sym_remove.cpp b/sci_gateway/cpp/sci_sym_remove.cpp index d4e9c49..be9c72b 100644 --- a/sci_gateway/cpp/sci_sym_remove.cpp +++ b/sci_gateway/cpp/sci_sym_remove.cpp @@ -126,7 +126,7 @@ int sci_sym_delete_cols(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); free(value);//freeing the memory of the allocated pointer return 0; } @@ -242,7 +242,7 @@ int sci_sym_delete_rows(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); free(value);//freeing the memory of the allocated pointer return 0; } diff --git a/sci_gateway/cpp/sci_sym_set_variables.cpp b/sci_gateway/cpp/sci_sym_set_variables.cpp index 327bf84..384de6f 100644 --- a/sci_gateway/cpp/sci_sym_set_variables.cpp +++ b/sci_gateway/cpp/sci_sym_set_variables.cpp @@ -50,7 +50,7 @@ int sci_sym_set_defaults(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -123,7 +123,7 @@ int sci_sym_set_int_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -181,7 +181,7 @@ int sci_sym_get_int_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -243,7 +243,7 @@ int sci_sym_set_dbl_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -302,7 +302,7 @@ int sci_sym_get_dbl_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -363,7 +363,7 @@ int sci_sym_set_str_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -421,7 +421,7 @@ int sci_sym_get_str_param(char *fname, unsigned long fname_len){ } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } diff --git a/sci_gateway/cpp/sci_sym_solution.cpp b/sci_gateway/cpp/sci_sym_solution.cpp index a08e5b9..dff3b60 100644 --- a/sci_gateway/cpp/sci_sym_solution.cpp +++ b/sci_gateway/cpp/sci_sym_solution.cpp @@ -58,7 +58,7 @@ int sci_sym_getVarSoln(char *fname){ return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); delete[] solution; diff --git a/sci_gateway/cpp/sci_sym_solve.cpp~ b/sci_gateway/cpp/sci_sym_solve.cpp~ new file mode 100644 index 0000000..4abb268 --- /dev/null +++ b/sci_gateway/cpp/sci_sym_solve.cpp~ @@ -0,0 +1,49 @@ +/* + * Implementation Symphony Tool Box for Scilab + * Contains sym_solve function + * Author : Sai Kiran + */ + +#include <symphony.h> +#include <sci_iofunc.hpp> +extern sym_environment* global_sym_env;//defined in globals.cpp + +extern "C" { +#include <api_scilab.h> +#include <Scierror.h> +#include <BOOL.h> +#include <localization.h> +#include <sciprint.h> +#include <stdio.h> +int process_ret_val(int); + +int sci_sym_solve(char *fname, unsigned long fname_len){ + + int status=0; + + //check whether we have no input and one output argument or not + CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument + CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument + + // Check environment + if(global_sym_env==NULL) + sciprint("Error: Symphony environment is not initialized.\n"); + else {// There is an environment opened + double time_limit = -1.0; + status = sym_get_dbl_param(global_sym_env,"time_limit",&time_limit); + + if (status == FUNCTION_TERMINATED_NORMALLY) { + if ( time_limit < 0.0 ) + sciprint("\nNote: There is no limit on time.\n"); + else sciprint("\nNote: Time limit has been set to %lf.\n",time_limit); + status=process_ret_val(sym_solve(global_sym_env));// Call function + } + else { + sciprint("\nUnable to read time limit.\n"); + status = 1; //Error state + } + } + // Return result to scilab + return returnDoubleToScilab(status); + } +} diff --git a/sci_gateway/cpp/sym_data_query_functions.cpp b/sci_gateway/cpp/sym_data_query_functions.cpp index b0d0989..9f38094 100644 --- a/sci_gateway/cpp/sym_data_query_functions.cpp +++ b/sci_gateway/cpp/sym_data_query_functions.cpp @@ -162,7 +162,7 @@ int sci_sym_get_dbl_arr(char *fname, unsigned long fname_len){ //assign result position to output argument AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -230,7 +230,7 @@ int sci_sym_get_row_sense(char *fname, unsigned long fname_len) { //assign result position to output argument AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } @@ -339,7 +339,7 @@ int sci_sym_get_matrix(char *fname, unsigned long fname_len){ //assign result position to output argument AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; - ReturnArguments(pvApiCtx); + //ReturnArguments(pvApiCtx); return 0; } |