summaryrefslogtreecommitdiff
path: root/sci_gateway/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sci_gateway/cpp')
-rw-r--r--sci_gateway/cpp/cleaner.sce22
-rw-r--r--sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.c156
-rwxr-xr-xsci_gateway/cpp/libFOSSEE_Optimization_Toolbox.sobin0 -> 194948 bytes
-rw-r--r--sci_gateway/cpp/loader.sce84
-rw-r--r--sci_gateway/cpp/minconNLP.hpp8
-rw-r--r--sci_gateway/cpp/sci_ipoptfmincon.cpp70
-rw-r--r--sci_gateway/cpp/sci_minconNLP.cpp491
7 files changed, 425 insertions, 406 deletions
diff --git a/sci_gateway/cpp/cleaner.sce b/sci_gateway/cpp/cleaner.sce
new file mode 100644
index 0000000..333775c
--- /dev/null
+++ b/sci_gateway/cpp/cleaner.sce
@@ -0,0 +1,22 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// cleaner.sce
+// ------------------------------------------------------
+curdir = pwd();
+cleaner_path = get_file_path('cleaner.sce');
+chdir(cleaner_path);
+// ------------------------------------------------------
+if fileinfo('loader.sce') <> [] then
+ mdelete('loader.sce');
+end
+// ------------------------------------------------------
+if fileinfo('libFOSSEE_Optimization_Toolbox.so') <> [] then
+ mdelete('libFOSSEE_Optimization_Toolbox.so');
+end
+// ------------------------------------------------------
+if fileinfo('libFOSSEE_Optimization_Toolbox.c') <> [] then
+ mdelete('libFOSSEE_Optimization_Toolbox.c');
+end
+// ------------------------------------------------------
+chdir(curdir);
+// ------------------------------------------------------
diff --git a/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.c b/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.c
new file mode 100644
index 0000000..cd53066
--- /dev/null
+++ b/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.c
@@ -0,0 +1,156 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <mex.h>
+#include <sci_gateway.h>
+#include <api_scilab.h>
+#include <MALLOC.h>
+static int direct_gateway(char *fname,void F(void)) { F();return 0;};
+extern Gatefunc sci_sym_open;
+extern Gatefunc sci_sym_close;
+extern Gatefunc sci_sym_isEnvActive;
+extern Gatefunc sci_sym_set_defaults;
+extern Gatefunc sci_sym_set_int_param;
+extern Gatefunc sci_sym_get_int_param;
+extern Gatefunc sci_sym_set_dbl_param;
+extern Gatefunc sci_sym_get_dbl_param;
+extern Gatefunc sci_sym_set_str_param;
+extern Gatefunc sci_sym_get_str_param;
+extern Gatefunc sci_sym_getInfinity;
+extern Gatefunc sci_sym_loadProblemBasic;
+extern Gatefunc sci_sym_loadProblem;
+extern Gatefunc sci_sym_load_mps;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_isContinuous;
+extern Gatefunc sci_sym_isBinary;
+extern Gatefunc sci_sym_isInteger;
+extern Gatefunc sci_sym_set_continuous;
+extern Gatefunc sci_sym_set_integer;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setVarBound;
+extern Gatefunc sci_sym_setVarBound;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setObjCoeff;
+extern Gatefunc sci_sym_getObjSense;
+extern Gatefunc sci_sym_setObjSense;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setConstrBound;
+extern Gatefunc sci_sym_setConstrBound;
+extern Gatefunc sci_sym_setConstrType;
+extern Gatefunc sci_sym_get_matrix;
+extern Gatefunc sci_sym_get_row_sense;
+extern Gatefunc sci_sym_addConstr;
+extern Gatefunc sci_sym_addVar;
+extern Gatefunc sci_sym_delete_cols;
+extern Gatefunc sci_sym_delete_rows;
+extern Gatefunc sci_sym_getPrimalBound;
+extern Gatefunc sci_sym_setPrimalBound;
+extern Gatefunc sci_sym_setColSoln;
+extern Gatefunc sci_sym_solve;
+extern Gatefunc sci_sym_get_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_getVarSoln;
+extern Gatefunc sci_sym_getObjVal;
+extern Gatefunc sci_sym_get_iteration_count;
+extern Gatefunc sci_sym_getRowActivity;
+extern Gatefunc sci_linearprog;
+extern Gatefunc sci_rmps;
+extern Gatefunc sci_solveqp;
+extern Gatefunc sci_solveminuncp;
+extern Gatefunc sci_solveminbndp;
+extern Gatefunc sci_solveminconp;
+static GenericTable Tab[]={
+ {(Myinterfun)sci_gateway,sci_sym_open,"sym_open"},
+ {(Myinterfun)sci_gateway,sci_sym_close,"sym_close"},
+ {(Myinterfun)sci_gateway,sci_sym_isEnvActive,"sym_isEnvActive"},
+ {(Myinterfun)sci_gateway,sci_sym_set_defaults,"sym_resetParams"},
+ {(Myinterfun)sci_gateway,sci_sym_set_int_param,"sym_setIntParam"},
+ {(Myinterfun)sci_gateway,sci_sym_get_int_param,"sym_getIntParam"},
+ {(Myinterfun)sci_gateway,sci_sym_set_dbl_param,"sym_setDblParam"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_param,"sym_getDblParam"},
+ {(Myinterfun)sci_gateway,sci_sym_set_str_param,"sym_setStrParam"},
+ {(Myinterfun)sci_gateway,sci_sym_get_str_param,"sym_getStrParam"},
+ {(Myinterfun)sci_gateway,sci_sym_getInfinity,"sym_getInfinity"},
+ {(Myinterfun)sci_gateway,sci_sym_loadProblemBasic,"sym_loadProblemBasic"},
+ {(Myinterfun)sci_gateway,sci_sym_loadProblem,"sym_loadProblem"},
+ {(Myinterfun)sci_gateway,sci_sym_load_mps,"sym_loadMPS"},
+ {(Myinterfun)sci_gateway,sci_sym_get_num_int,"sym_getNumConstr"},
+ {(Myinterfun)sci_gateway,sci_sym_get_num_int,"sym_getNumVar"},
+ {(Myinterfun)sci_gateway,sci_sym_get_num_int,"sym_getNumElements"},
+ {(Myinterfun)sci_gateway,sci_sym_isContinuous,"sym_isContinuous"},
+ {(Myinterfun)sci_gateway,sci_sym_isBinary,"sym_isBinary"},
+ {(Myinterfun)sci_gateway,sci_sym_isInteger,"sym_isInteger"},
+ {(Myinterfun)sci_gateway,sci_sym_set_continuous,"sym_setContinuous"},
+ {(Myinterfun)sci_gateway,sci_sym_set_integer,"sym_setInteger"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getVarLower"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getVarUpper"},
+ {(Myinterfun)sci_gateway,sci_sym_setVarBound,"sym_setVarLower"},
+ {(Myinterfun)sci_gateway,sci_sym_setVarBound,"sym_setVarUpper"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getObjCoeff"},
+ {(Myinterfun)sci_gateway,sci_sym_setObjCoeff,"sym_setObjCoeff"},
+ {(Myinterfun)sci_gateway,sci_sym_getObjSense,"sym_getObjSense"},
+ {(Myinterfun)sci_gateway,sci_sym_setObjSense,"sym_setObjSense"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getRhs"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getConstrRange"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getConstrLower"},
+ {(Myinterfun)sci_gateway,sci_sym_get_dbl_arr,"sym_getConstrUpper"},
+ {(Myinterfun)sci_gateway,sci_sym_setConstrBound,"sym_setConstrLower"},
+ {(Myinterfun)sci_gateway,sci_sym_setConstrBound,"sym_setConstrUpper"},
+ {(Myinterfun)sci_gateway,sci_sym_setConstrType,"sym_setConstrType"},
+ {(Myinterfun)sci_gateway,sci_sym_get_matrix,"sym_getMatrix"},
+ {(Myinterfun)sci_gateway,sci_sym_get_row_sense,"sym_getConstrSense"},
+ {(Myinterfun)sci_gateway,sci_sym_addConstr,"sym_addConstr"},
+ {(Myinterfun)sci_gateway,sci_sym_addVar,"sym_addVar"},
+ {(Myinterfun)sci_gateway,sci_sym_delete_cols,"sym_deleteVars"},
+ {(Myinterfun)sci_gateway,sci_sym_delete_rows,"sym_deleteConstrs"},
+ {(Myinterfun)sci_gateway,sci_sym_getPrimalBound,"sym_getPrimalBound"},
+ {(Myinterfun)sci_gateway,sci_sym_setPrimalBound,"sym_setPrimalBound"},
+ {(Myinterfun)sci_gateway,sci_sym_setColSoln,"sym_setVarSoln"},
+ {(Myinterfun)sci_gateway,sci_sym_solve,"sym_solve"},
+ {(Myinterfun)sci_gateway,sci_sym_get_status,"sym_getStatus"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isOptimal"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isInfeasible"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isAbandoned"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isIterLimitReached"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isTimeLimitReached"},
+ {(Myinterfun)sci_gateway,sci_sym_get_solver_status,"sym_isTargetGapAchieved"},
+ {(Myinterfun)sci_gateway,sci_sym_getVarSoln,"sym_getVarSoln"},
+ {(Myinterfun)sci_gateway,sci_sym_getObjVal,"sym_getObjVal"},
+ {(Myinterfun)sci_gateway,sci_sym_get_iteration_count,"sym_getIterCount"},
+ {(Myinterfun)sci_gateway,sci_sym_getRowActivity,"sym_getConstrActivity"},
+ {(Myinterfun)sci_gateway,sci_linearprog,"linearprog"},
+ {(Myinterfun)sci_gateway,sci_rmps,"rmps"},
+ {(Myinterfun)sci_gateway,sci_solveqp,"solveqp"},
+ {(Myinterfun)sci_gateway,sci_solveminuncp,"solveminuncp"},
+ {(Myinterfun)sci_gateway,sci_solveminbndp,"solveminbndp"},
+ {(Myinterfun)sci_gateway,sci_solveminconp,"solveminconp"},
+};
+
+int C2F(libFOSSEE_Optimization_Toolbox)()
+{
+ Rhs = Max(0, Rhs);
+ if (*(Tab[Fin-1].f) != NULL)
+ {
+ if(pvApiCtx == NULL)
+ {
+ pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
+ }
+ pvApiCtx->pstName = (char*)Tab[Fin-1].name;
+ (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
+ }
+ return 0;
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.so b/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.so
new file mode 100755
index 0000000..9a4caf4
--- /dev/null
+++ b/sci_gateway/cpp/libFOSSEE_Optimization_Toolbox.so
Binary files differ
diff --git a/sci_gateway/cpp/loader.sce b/sci_gateway/cpp/loader.sce
new file mode 100644
index 0000000..1ec953f
--- /dev/null
+++ b/sci_gateway/cpp/loader.sce
@@ -0,0 +1,84 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// ----------------------------------------------------------------------------
+//
+libFOSSEE_Optimizat_path = get_absolute_file_path('loader.sce');
+//
+// ulink previous function with same name
+[bOK, ilib] = c_link('libFOSSEE_Optimization_Toolbox');
+if bOK then
+ ulink(ilib);
+end
+//
+list_functions = [ 'sym_open';
+ 'sym_close';
+ 'sym_isEnvActive';
+ 'sym_resetParams';
+ 'sym_setIntParam';
+ 'sym_getIntParam';
+ 'sym_setDblParam';
+ 'sym_getDblParam';
+ 'sym_setStrParam';
+ 'sym_getStrParam';
+ 'sym_getInfinity';
+ 'sym_loadProblemBasic';
+ 'sym_loadProblem';
+ 'sym_loadMPS';
+ 'sym_getNumConstr';
+ 'sym_getNumVar';
+ 'sym_getNumElements';
+ 'sym_isContinuous';
+ 'sym_isBinary';
+ 'sym_isInteger';
+ 'sym_setContinuous';
+ 'sym_setInteger';
+ 'sym_getVarLower';
+ 'sym_getVarUpper';
+ 'sym_setVarLower';
+ 'sym_setVarUpper';
+ 'sym_getObjCoeff';
+ 'sym_setObjCoeff';
+ 'sym_getObjSense';
+ 'sym_setObjSense';
+ 'sym_getRhs';
+ 'sym_getConstrRange';
+ 'sym_getConstrLower';
+ 'sym_getConstrUpper';
+ 'sym_setConstrLower';
+ 'sym_setConstrUpper';
+ 'sym_setConstrType';
+ 'sym_getMatrix';
+ 'sym_getConstrSense';
+ 'sym_addConstr';
+ 'sym_addVar';
+ 'sym_deleteVars';
+ 'sym_deleteConstrs';
+ 'sym_getPrimalBound';
+ 'sym_setPrimalBound';
+ 'sym_setVarSoln';
+ 'sym_solve';
+ 'sym_getStatus';
+ 'sym_isOptimal';
+ 'sym_isInfeasible';
+ 'sym_isAbandoned';
+ 'sym_isIterLimitReached';
+ 'sym_isTimeLimitReached';
+ 'sym_isTargetGapAchieved';
+ 'sym_getVarSoln';
+ 'sym_getObjVal';
+ 'sym_getIterCount';
+ 'sym_getConstrActivity';
+ 'linearprog';
+ 'rmps';
+ 'solveqp';
+ 'solveminuncp';
+ 'solveminbndp';
+ 'solveminconp';
+];
+addinter(libFOSSEE_Optimizat_path + filesep() + 'libFOSSEE_Optimization_Toolbox' + getdynlibext(), 'libFOSSEE_Optimization_Toolbox', list_functions);
+// remove temp. variables on stack
+clear libFOSSEE_Optimizat_path;
+clear bOK;
+clear ilib;
+clear list_functions;
+// ----------------------------------------------------------------------------
diff --git a/sci_gateway/cpp/minconNLP.hpp b/sci_gateway/cpp/minconNLP.hpp
index df496ce..0dcaf26 100644
--- a/sci_gateway/cpp/minconNLP.hpp
+++ b/sci_gateway/cpp/minconNLP.hpp
@@ -24,12 +24,6 @@ class minconNLP : public TNLP
Index numConstr_; //Number of constraints
- Number flag1_; //Gradient of objective ON or OFF
-
- Number flag2_; //Hessian of objective ON or OFF
-
- Number flag3_; //Jacobian of constraints ON or OFF
-
Number nonlinCon_; //Number of non-linear constraints
Number nonlinIneqCon_; //Number of non-linear inequality constraints
@@ -101,7 +95,7 @@ class minconNLP : public TNLP
public:
/** user defined constructor */
- minconNLP(Index nV, Index nC, Number *x0 ,Number *A, Number *b, Number* Aeq, Number *beq, Index Arows, Index Acols, Index brows, Index bcols, Index Aeqrows, Index Aeqcols, Index beqrows, Index beqcols, Number* LB, Number* UB, Number nlC, Number nlIC, Number f1, Number f2, Number f3) : numVars_(nV), numConstr_(nC), varGuess_(x0), A_(A), b_(b), Aeq_(Aeq), beq_(beq), Arows_(Arows), Acols_(Acols), brows_(brows), bcols_(bcols), Aeqrows_(Aeqrows), Aeqcols_(Aeqcols), beqrows_(beqrows), beqcols_(beqcols), varLB_(LB), varUB_(UB), nonlinCon_(nlC), nonlinIneqCon_(nlIC), flag1_(f1), flag2_(f2), flag3_(f3), finalX_(0), finalZl_(0), finalZu_(0), finalGradient_(0), finalHessian_(0), finalObjVal_(1e20){ }
+ minconNLP(Index nV, Index nC, Number *x0 ,Number *A, Number *b, Number* Aeq, Number *beq, Index Arows, Index Acols, Index brows, Index bcols, Index Aeqrows, Index Aeqcols, Index beqrows, Index beqcols, Number* LB, Number* UB, Number nlC, Number nlIC) : numVars_(nV), numConstr_(nC), varGuess_(x0), A_(A), b_(b), Aeq_(Aeq), beq_(beq), Arows_(Arows), Acols_(Acols), brows_(brows), bcols_(bcols), Aeqrows_(Aeqrows), Aeqcols_(Aeqcols), beqrows_(beqrows), beqcols_(beqcols), varLB_(LB), varUB_(UB), nonlinCon_(nlC), nonlinIneqCon_(nlIC), finalX_(0), finalZl_(0), finalZu_(0), finalGradient_(0), finalHessian_(0), finalObjVal_(1e20){ }
/** default destructor */
virtual ~minconNLP();
diff --git a/sci_gateway/cpp/sci_ipoptfmincon.cpp b/sci_gateway/cpp/sci_ipoptfmincon.cpp
index 551af41..18218a5 100644
--- a/sci_gateway/cpp/sci_ipoptfmincon.cpp
+++ b/sci_gateway/cpp/sci_ipoptfmincon.cpp
@@ -30,17 +30,15 @@ int sci_solveminconp(char *fname)
{
using namespace Ipopt;
- CheckInputArgument(pvApiCtx, 20, 20);
+ CheckInputArgument(pvApiCtx, 16, 16);
CheckOutputArgument(pvApiCtx, 12, 12);
// Error management variable
SciErr sciErr;
//Function pointers, input matrix(Starting point) pointer, flag variable
- int* funptr=NULL;
- int* gradhesptr=NULL;
double *x0ptr=NULL, *lbptr=NULL, *ubptr=NULL,*Aptr=NULL, *bptr=NULL, *Aeqptr=NULL, *beqptr=NULL;
- double flag1=0,flag2=0,flag3=0,nonlinCon=0,nonlinIneqCon=0;
+ double nonlinCon=0,nonlinIneqCon=0;
// Input arguments
@@ -49,7 +47,7 @@ int sci_solveminconp(char *fname)
unsigned int temp1 = 0,temp2 = 0, iret = 0;
int x0_rows=0, x0_cols=0, lb_rows=0, lb_cols=0, ub_rows=0, ub_cols=0, A_rows=0, A_cols=0, b_rows=0, b_cols=0, Aeq_rows=0, Aeq_cols=0, beq_rows=0, beq_cols=0;
- // Output arguments
+ // Output arguments
double *fX = NULL, ObjVal=0,iteration=0,cpuTime=0,fobj_eval=0;
double dual_inf, constr_viol, complementarity, kkt_error;
double *fGrad = NULL;
@@ -61,98 +59,70 @@ int sci_solveminconp(char *fname)
int int_fobj_eval, int_constr_eval, int_fobj_grad_eval, int_constr_jac_eval, int_hess_eval;
////////// Manage the input argument //////////
-
- //Objective Function
- if(getFunctionFromScilab(1,&funptr))
- {
- return 1;
- }
-
- //Function for gradient and hessian
- if(getFunctionFromScilab(2,&gradhesptr))
- {
- return 1;
- }
-
- //x0(starting point) matrix from scilab
- if(getDoubleMatrixFromScilab(18, &x0_rows, &x0_cols, &x0ptr))
- {
- return 1;
- }
-
- //Getting number of iterations
- if(getFixedSizeDoubleMatrixInList(19,2,temp1,temp2,&max_iter))
- {
- return 1;
- }
-
- //Getting Cpu Time
- if(getFixedSizeDoubleMatrixInList(19,4,temp1,temp2,&cpu_time))
- {
- return 1;
- }
+
//Getting matrix representing linear inequality constraints
- if(getDoubleMatrixFromScilab(3, &A_rows, &A_cols, &Aptr))
+ if(getDoubleMatrixFromScilab(2, &A_rows, &A_cols, &Aptr))
{
return 1;
}
//Getting matrix representing bounds of linear inequality constraints
- if(getDoubleMatrixFromScilab(4, &b_rows, &b_cols, &bptr))
+ if(getDoubleMatrixFromScilab(3, &b_rows, &b_cols, &bptr))
{
return 1;
}
//Getting matrix representing linear equality constraints
- if(getDoubleMatrixFromScilab(5, &Aeq_rows, &Aeq_cols, &Aeqptr))
+ if(getDoubleMatrixFromScilab(4, &Aeq_rows, &Aeq_cols, &Aeqptr))
{
return 1;
}
//Getting matrix representing bounds of linear inequality constraints
- if(getDoubleMatrixFromScilab(6, &beq_rows, &beq_cols, &beqptr))
+ if(getDoubleMatrixFromScilab(5, &beq_rows, &beq_cols, &beqptr))
{
return 1;
}
//Getting matrix representing linear inequality constraints
- if(getDoubleMatrixFromScilab(7, &lb_rows, &lb_cols, &lbptr))
+ if(getDoubleMatrixFromScilab(6, &lb_rows, &lb_cols, &lbptr))
{
return 1;
}
//Getting matrix representing linear inequality constraints
- if(getDoubleMatrixFromScilab(8, &ub_rows, &ub_cols, &ubptr))
+ if(getDoubleMatrixFromScilab(7, &ub_rows, &ub_cols, &ubptr))
{
return 1;
}
//Number of non-linear constraints
- if(getDoubleFromScilab(9, &nonlinCon))
+ if(getDoubleFromScilab(8, &nonlinCon))
{
return 1;
}
//Number of non-linear inequality constraints
- if(getDoubleFromScilab(10, &nonlinIneqCon))
+ if(getDoubleFromScilab(9, &nonlinIneqCon))
{
return 1;
}
-
- //Getting the required flag variables
-
- if(getDoubleFromScilab(12, &flag1))
+
+ //x0(starting point) matrix from scilab
+ if(getDoubleMatrixFromScilab(14, &x0_rows, &x0_cols, &x0ptr))
{
return 1;
}
- if(getDoubleFromScilab(14, &flag2))
+ //Getting number of iterations
+ if(getFixedSizeDoubleMatrixInList(15,2,temp1,temp2,&max_iter))
{
return 1;
}
- if(getDoubleFromScilab(16, &flag3))
+ //Getting Cpu Time
+ if(getFixedSizeDoubleMatrixInList(15,4,temp1,temp2,&cpu_time))
{
return 1;
}
@@ -164,7 +134,7 @@ int sci_solveminconp(char *fname)
// Starting Ipopt
- SmartPtr<minconNLP> Prob = new minconNLP(nVars, nCons, x0ptr, Aptr, bptr, Aeqptr, beqptr, A_rows, A_cols, b_rows, b_cols, Aeq_rows, Aeq_cols, beq_rows, beq_cols, lbptr, ubptr, nonlinCon, nonlinIneqCon, flag1, flag2, flag3);
+ SmartPtr<minconNLP> Prob = new minconNLP(nVars, nCons, x0ptr, Aptr, bptr, Aeqptr, beqptr, A_rows, A_cols, b_rows, b_cols, Aeq_rows, Aeq_cols, beq_rows, beq_cols, lbptr, ubptr, nonlinCon, nonlinIneqCon);
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
app->RethrowNonIpoptException(true);
diff --git a/sci_gateway/cpp/sci_minconNLP.cpp b/sci_gateway/cpp/sci_minconNLP.cpp
index 2c6d6af..600aed6 100644
--- a/sci_gateway/cpp/sci_minconNLP.cpp
+++ b/sci_gateway/cpp/sci_minconNLP.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2015 - IIT Bombay - FOSSEE
+// Copyright (C) 1815 - IIT Bombay - FOSSEE
//
// Author: R.Vidyadhar & Vignesh Kannan
// Organization: FOSSEE, IIT Bombay
@@ -49,7 +49,7 @@ bool minconNLP::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, Index& nnz_h_
m=numConstr_; // Number of constraints
nnz_jac_g = n*m; // No. of elements in Jacobian of constraints
- nnz_h_lag = n*(n+1)/2; // No. of elements in lower traingle of Hessian of the Lagrangian.
+ nnz_h_lag = n*n; // No. of elements in lower traingle of Hessian of the Lagrangian.
index_style=C_STYLE; // Index style of matrices
return true;
@@ -80,7 +80,7 @@ bool minconNLP::get_bounds_info(Index n, Number* x_l, Number* x_u, Index m, Numb
//bounds of non-linear inequality constraints
for(i=0;i<nonlinIneqCon_;i++)
{
- g_l[c]=-1.0e19;
+ g_l[c]=-1.0e17;
g_u[c]=0;
c++;
}
@@ -102,7 +102,7 @@ bool minconNLP::get_bounds_info(Index n, Number* x_l, Number* x_u, Index m, Numb
//bounds of linear inequality constraints
for(i=0;i<Arows_;i++)
{
- g_l[c]=-1.0e19;
+ g_l[c]=-1.0e17;
g_u[c]=b_[i];
c++;
@@ -113,11 +113,121 @@ bool minconNLP::get_bounds_info(Index n, Number* x_l, Number* x_u, Index m, Numb
return true;
}
+// This method sets initial values for required vectors . For now we are assuming 0 to all values.
+bool minconNLP::get_starting_point(Index n, bool init_x, Number* x,bool init_z, Number* z_L, Number* z_U,Index m, bool init_lambda,Number* lambda)
+{
+ assert(init_x == true);
+ assert(init_z == false);
+ assert(init_lambda == false);
+ if (init_x == true)
+ { //we need to set initial values for vector x
+ for (Index var=0;var<n;var++)
+ x[var]=varGuess_[var];
+ }
+
+ return true;
+}
+
+//get value of objective function at vector x
+bool minconNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
+{
+ int* funptr=NULL;
+ if(getFunctionFromScilab(1,&funptr))
+ {
+ return 1;
+ }
+ char name[18]="f";
+ double obj=0;
+ double *xNew=x;
+ double check;
+ createMatrixOfDouble(pvApiCtx, 14, 1, numVars_, xNew);
+ int positionFirstElementOnStackForScilabFunction = 14;
+ int numberOfRhsOnScilabFunction = 1;
+ int numberOfLhsOnScilabFunction = 2;
+ int pointerOnScilabFunction = *funptr;
+
+ C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
+ &numberOfLhsOnScilabFunction,
+ &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
+
+ if(getDoubleFromScilab(15,&check))
+ {
+ return true;
+ }
+ if (check==1)
+ {
+
+ return true;
+ }
+ else
+ {
+ if(getDoubleFromScilab(14,&obj))
+ {
+ sciprint("No obj value");
+ return 1;
+ }
+ obj_value=obj;
+
+ return true;
+ }
+}
+
+//get value of gradient of objective function at vector x.
+bool minconNLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
+{
+
+
+ int* gradptr=NULL;
+ if(getFunctionFromScilab(11,&gradptr))
+ {
+ return 1;
+ }
+ double *xNew=x;
+ createMatrixOfDouble(pvApiCtx, 14, 1, numVars_, xNew);
+ int positionFirstElementOnStackForScilabFunction = 14;
+ int numberOfRhsOnScilabFunction = 1;
+ int numberOfLhsOnScilabFunction = 2;
+ int pointerOnScilabFunction = *gradptr;
+ char name[18]="fGrad1";
+
+ C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
+ &numberOfLhsOnScilabFunction,
+ &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
+
+ double* resg;
+ double check;
+ int x0_rows,x0_cols;
+ if(getDoubleFromScilab(15,&check))
+ {
+ return true;
+ }
+ if (check==1)
+ {
+ return true;
+ }
+ else
+ {
+ if(getDoubleMatrixFromScilab(14, &x0_rows, &x0_cols, &resg))
+ {
+ sciprint("No results");
+ return 1;
+ }
+
+
+ Index i;
+ for(i=0;i<numVars_;i++)
+ {
+ grad_f[i]=resg[i];
+ finalGradient_[i]=resg[i];
+ }
+ }
+ return true;
+}
+
// return the value of the constraints: g(x)
bool minconNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
{
// return the value of the constraints: g(x)
-
unsigned int i;
unsigned int j;
@@ -132,26 +242,27 @@ bool minconNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
if(nonlinCon_!=0)
{
int* constr=NULL;
- if(getFunctionFromScilab(11,&constr))
+ if(getFunctionFromScilab(10,&constr))
{
return 1;
}
- char name[20]="addnlc1";
+
double *xNew=x;
double check;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- int positionFirstElementOnStackForScilabFunction = 18;
+ createMatrixOfDouble(pvApiCtx, 14, 1, numVars_, xNew);
+ int positionFirstElementOnStackForScilabFunction = 14;
int numberOfRhsOnScilabFunction = 1;
int numberOfLhsOnScilabFunction = 2;
int pointerOnScilabFunction = *constr;
-
+ char name[18]="addnlc1";
+
C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
&numberOfLhsOnScilabFunction,
&numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
double* resc;
int xC_rows,xC_cols;
- if(getDoubleFromScilab(19,&check))
+ if(getDoubleFromScilab(15,&check))
{
return true;
}
@@ -161,7 +272,7 @@ bool minconNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
}
else
{
- if(getDoubleMatrixFromScilab(18, &xC_rows, &xC_cols, &resc))
+ if(getDoubleMatrixFromScilab(14, &xC_rows, &xC_cols, &resc))
{
sciprint("No results");
return 1;
@@ -201,11 +312,11 @@ bool minconNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
// return the structure or values of the jacobian
bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index nele_jac, Index* iRow, Index *jCol,Number* values)
-{
+{
if (values == NULL)
{
- if(m==0)// return the structure of the jacobian of the constraints
- {
+ if(m==0)// return the structure of the jacobian of the constraints
+ {
iRow=NULL;
jCol=NULL;
}
@@ -235,71 +346,19 @@ bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index n
//jacobian of non-linear constraints
if(nonlinCon_!=0)
{
- if(flag3_==0)
- {
- int* gradhessptr=NULL;
- if(getFunctionFromScilab(2,&gradhessptr))
- {
- return 1;
- }
- double *xNew=x;
- double t=3;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- createScalarDouble(pvApiCtx, 19,t);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 2;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *gradhessptr;
- char name[20]="gradhess";
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
-
- double* resj;
- int xJ_rows,xJ_cols;
- if(getDoubleFromScilab(19,&check))
- {
- return true;
- }
- if (check==1)
- {
- return true;
- }
- else
- {
- if(getDoubleMatrixFromScilab(18, &xJ_rows, &xJ_cols, &resj))
- {
- sciprint("No results");
- return 1;
- }
-
- for(i=0;i<nonlinCon_;i++)
- {
- for(j=0;j<n;j++)
- {
- values[c] = resj[j*(int)nonlinCon_+i];
- c++;
- }
- }
- }
- }
-
- else
- {
int* jacptr=NULL;
- if(getFunctionFromScilab(17,&jacptr))
+ if(getFunctionFromScilab(13,&jacptr))
{
return 1;
}
double *xNew=x;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- int positionFirstElementOnStackForScilabFunction = 18;
+ createMatrixOfDouble(pvApiCtx, 14, 1, numVars_, xNew);
+ int positionFirstElementOnStackForScilabFunction = 14;
int numberOfRhsOnScilabFunction = 1;
int numberOfLhsOnScilabFunction = 2;
int pointerOnScilabFunction = *jacptr;
- char name[20]="addcGrad1";
+ char name[18]="addcGrad1";
C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
&numberOfLhsOnScilabFunction,
@@ -307,7 +366,7 @@ bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index n
double* resj;
int xJ_rows,xJ_cols;
- if(getDoubleFromScilab(19,&check))
+ if(getDoubleFromScilab(15,&check))
{
return true;
}
@@ -317,7 +376,7 @@ bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index n
}
else
{
- if(getDoubleMatrixFromScilab(18, &xJ_rows, &xJ_cols, &resj))
+ if(getDoubleMatrixFromScilab(14, &xJ_rows, &xJ_cols, &resj))
{
sciprint("No results");
return 1;
@@ -330,7 +389,6 @@ bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index n
c++;
}
}
- }
}
//jacobian of linear equality constraints
@@ -359,139 +417,6 @@ bool minconNLP::eval_jac_g(Index n, const Number* x, bool new_x,Index m, Index n
return true;
}
-//get value of objective function at vector x
-bool minconNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
-{
- int* funptr=NULL;
- if(getFunctionFromScilab(1,&funptr))
- {
- return 1;
- }
- char name[20]="f";
- double obj=0;
- double *xNew=x;
- double check;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 1;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *funptr;
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
-
- if(getDoubleFromScilab(19,&check))
- {
- return true;
- }
- if (check==1)
- {
- return true;
- }
- else
- {
- if(getDoubleFromScilab(18,&obj))
- {
- sciprint("No obj value");
- return 1;
- }
- obj_value=obj;
-
- return true;
- }
-}
-
-//get value of gradient of objective function at vector x.
-bool minconNLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
-{
- if (flag1_==0)
- {
- int* gradhessptr=NULL;
- if(getFunctionFromScilab(2,&gradhessptr))
- {
- return 1;
- }
- double *xNew=x;
- double t=1;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- createScalarDouble(pvApiCtx, 19,t);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 2;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *gradhessptr;
- char name[20]="gradhess";
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
- }
-
- else
- {
- int* gradptr=NULL;
- if(getFunctionFromScilab(13,&gradptr))
- {
- return 1;
- }
- double *xNew=x;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 1;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *gradptr;
- char name[20]="fGrad1";
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
- }
-
- double* resg;
- double check;
- int x0_rows,x0_cols;
- if(getDoubleFromScilab(19,&check))
- {
- return true;
- }
- if (check==1)
- {
- return true;
- }
- else
- {
- if(getDoubleMatrixFromScilab(18, &x0_rows, &x0_cols, &resg))
- {
- sciprint("No results");
- return 1;
- }
-
-
- Index i;
- for(i=0;i<numVars_;i++)
- {
- grad_f[i]=resg[i];
- finalGradient_[i]=resg[i];
- }
- }
- return true;
-}
-
-// This method sets initial values for required vectors . For now we are assuming 0 to all values.
-bool minconNLP::get_starting_point(Index n, bool init_x, Number* x,bool init_z, Number* z_L, Number* z_U,Index m, bool init_lambda,Number* lambda)
-{
- assert(init_x == true);
- assert(init_z == false);
- assert(init_lambda == false);
- if (init_x == true)
- { //we need to set initial values for vector x
- for (Index var=0;var<n;var++)
- x[var]=varGuess_[var];
- }
-
- return true;
-}
-
/*
* Return either the sparsity structure of the Hessian of the Lagrangian,
* or the values of the Hessian of the Lagrangian for the given values for
@@ -505,7 +430,7 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
Index idx=0;
for (Index row = 0; row < numVars_; row++)
{
- for (Index col = 0; col <= row; col++)
+ for (Index col = 0; col < numVars_; col++)
{
iRow[idx] = row;
jCol[idx] = col;
@@ -517,145 +442,23 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
else
{
double check;
- //hessian of the objective function
- if(flag2_==0)
- {
- int* gradhessptr=NULL;
- if(getFunctionFromScilab(2,&gradhessptr))
- {
- return 1;
- }
- double *xNew=x;
- double t=2;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- createScalarDouble(pvApiCtx, 19,t);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 2;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *gradhessptr;
- char name[20]="gradhess";
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
-
- double* resTemph;
- int x0_rows,x0_cols;
- if(getDoubleFromScilab(19,&check))
- {
- return true;
- }
- if (check==1)
- {
- return true;
- }
- else
- {
- if(getDoubleMatrixFromScilab(18, &x0_rows, &x0_cols, &resTemph))
- {
- sciprint("No results");
- return 1;
- }
-
- double* resh=(double*)malloc(sizeof(double)*n*n);
- Index i;
- for(i=0;i<numVars_*numVars_;i++)
- {
- resh[i]=resTemph[i];
- }
-
- //sum of hessians of constraints each multiplied by its own lambda factor
- double* sum=(double*)malloc(sizeof(double)*n*n);
- if(nonlinCon_!=0)
- {
-
- int* gradhessptr=NULL;
- if(getFunctionFromScilab(2,&gradhessptr))
- {
- return 1;
- }
-
- double *xNew=x;
- double t=4;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- createScalarDouble(pvApiCtx, 19,t);
- int positionFirstElementOnStackForScilabFunction = 18;
- int numberOfRhsOnScilabFunction = 2;
- int numberOfLhsOnScilabFunction = 2;
- int pointerOnScilabFunction = *gradhessptr;
- char name[20]="gradhess";
-
- C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
- &numberOfLhsOnScilabFunction,
- &numberOfRhsOnScilabFunction,(unsigned long)strlen(name));
- double* resCh;
- int xCh_rows,xCh_cols;
- if(getDoubleFromScilab(19,&check))
- {
- return true;
- }
- if (check==1)
- {
- return true;
- }
- else
- {
- if(getDoubleMatrixFromScilab(18, &xCh_rows, &xCh_cols, &resCh))
- {
- sciprint("No results");
- return 1;
- }
-
- Index j;
-
- for(i=0;i<numVars_*numVars_;i++)
- {
- sum[i]=0;
- for(j=0;j<nonlinCon_;j++)
- sum[i]+=lambda[j]*resCh[i*(int)nonlinCon_+j];
- }
- }
- }
-
- else
- {
- for(i=0;i<numVars_*numVars_;i++)
- sum[i]=0;
- }
-
- //computing the lagrangian
- Index index=0;
- for (Index row=0;row < numVars_ ;++row)
- {
- for (Index col=0; col <= row; ++col)
- {
- values[index++]=obj_factor*(resh[numVars_*row+col])+sum[numVars_*row+col];
- }
- }
-
- free(resh);
- free(sum);
- }
- }
- else
- {
int* hessptr=NULL;
- if(getFunctionFromScilab(15,&hessptr))
+ if(getFunctionFromScilab(12,&hessptr))
{
return 1;
}
double *xNew=x;
double *lambdaNew=lambda;
double objfac=obj_factor;
- createMatrixOfDouble(pvApiCtx, 18, 1, numVars_, xNew);
- createScalarDouble(pvApiCtx, 19,objfac);
- createMatrixOfDouble(pvApiCtx, 20, 1, numConstr_, lambdaNew);
- int positionFirstElementOnStackForScilabFunction = 18;
+ createMatrixOfDouble(pvApiCtx, 14, 1, numVars_, xNew);
+ createScalarDouble(pvApiCtx, 15,objfac);
+ createMatrixOfDouble(pvApiCtx, 16, 1, numConstr_, lambdaNew);
+ int positionFirstElementOnStackForScilabFunction = 14;
int numberOfRhsOnScilabFunction = 3;
int numberOfLhsOnScilabFunction = 2;
int pointerOnScilabFunction = *hessptr;
- char name[20]="lHess1";
+ char name[18]="lHess1";
C2F(scistring)(&positionFirstElementOnStackForScilabFunction,name,
&numberOfLhsOnScilabFunction,
@@ -663,7 +466,7 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
double* resCh;
int xCh_rows,xCh_cols;
- if(getDoubleFromScilab(19,&check))
+ if(getDoubleFromScilab(15,&check))
{
return true;
}
@@ -673,7 +476,7 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
}
else
{
- if(getDoubleMatrixFromScilab(18, &xCh_rows, &xCh_cols, &resCh))
+ if(getDoubleMatrixFromScilab(14, &xCh_rows, &xCh_cols, &resCh))
{
sciprint("No results");
return 1;
@@ -682,14 +485,12 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
Index index=0;
for (Index row=0;row < numVars_ ;++row)
{
- for (Index col=0; col <= row; ++col)
+ for (Index col=0; col < numVars_; ++col)
{
values[index++]=resCh[numVars_*row+col];
}
}
}
- }
-
Index index=0;
for (Index row=0;row < numVars_ ;++row)
@@ -700,14 +501,6 @@ bool minconNLP::eval_h(Index n, const Number* x, bool new_x,Number obj_factor, I
}
}
- index=0;
- for (Index col=0;col < numVars_ ;++col)
- {
- for (Index row=0; row <= col; ++row)
- {
- finalHessian_[n*row+col]=values[index++];
- }
- }
}
return true;