summaryrefslogtreecommitdiff
path: root/sci_gateway/cpp/sci_ipopt.cpp
diff options
context:
space:
mode:
authorHarpreet2015-10-20 14:23:25 +0530
committerHarpreet2015-10-20 14:23:25 +0530
commite4b59ea62dd9903445375c2aa1f52a52c5eab99f (patch)
treed761e8819990b031344e58c9016562bea157c05b /sci_gateway/cpp/sci_ipopt.cpp
parente34332a406e4f3fba9b99c6f9ec5138edfcc6aa2 (diff)
downloadFOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.tar.gz
FOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.tar.bz2
FOSSEE-Optimization-toolbox-e4b59ea62dd9903445375c2aa1f52a52c5eab99f.zip
qpipopt_mat added
Diffstat (limited to 'sci_gateway/cpp/sci_ipopt.cpp')
-rw-r--r--sci_gateway/cpp/sci_ipopt.cpp222
1 files changed, 202 insertions, 20 deletions
diff --git a/sci_gateway/cpp/sci_ipopt.cpp b/sci_gateway/cpp/sci_ipopt.cpp
index a7ea33e..06796a9 100644
--- a/sci_gateway/cpp/sci_ipopt.cpp
+++ b/sci_gateway/cpp/sci_ipopt.cpp
@@ -53,25 +53,216 @@ int sci_solveqp(char *fname)
CheckInputArgument(pvApiCtx, 9, 9); // We need total 9 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;
double *QItems=NULL,*PItems=NULL,*ConItems=NULL,*conUB=NULL,*conLB=NULL,*varUB=NULL,*varLB=NULL,x,f,iter;
- unsigned int nVars,nCons;
+ static unsigned int nVars = 0,nCons = 0;
+ unsigned int temp1 = 0,temp2 = 0;
+
+
+ ////////// Manage the input argument //////////
+
+
+ //Number of Variables
+ getIntFromScilab(1,&nVars);
+
+ //Number of Constraints
+ getIntFromScilab(2,&nCons);
+
+ temp1 = nVars;
+ temp2 = nCons;
+
+ //Q matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarQ);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarQ) || isVarComplex(pvApiCtx, piAddressVarQ) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 3);
+ return 0;
+ }
+
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarQ, &temp1, &temp1, &QItems);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //P matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddressVarP);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarP) || isVarComplex(pvApiCtx, piAddressVarP) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 4);
+ return 0;
+ }
+
+ temp1 = 1;
+ temp2 = nVars;
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarP, &temp1,&temp2, &PItems);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (nCons!=0)
+ {
+ //conMatrix matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddressVarCM);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarCM) || isVarComplex(pvApiCtx, piAddressVarCM) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 5);
+ return 0;
+ }
+ temp1 = nCons;
+ temp2 = nVars;
+
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarCM,&temp1, &temp2, &ConItems);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //conLB matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddressVarCLB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarCLB) || isVarComplex(pvApiCtx, piAddressVarCLB) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 6);
+ return 0;
+ }
+ temp1 = nCons;
+ temp2 = 1;
- unsigned int arg = 1,temp1,temp2;
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarCLB,&temp1, &temp2, &conLB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //conUB matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddressVarCUB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
- if ( !getIntFromScilab(arg,&nVars) && arg++ && !getIntFromScilab(arg,&nCons) && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&QItems) && temp1 == nVars && temp2 == nVars && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&PItems) && temp2 == nVars && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&ConItems) && temp1 == nCons &&((nCons !=0 && temp2 == nVars)||(temp2==0)) && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&conLB) && temp2 == nCons && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&conUB) && temp2 == nCons && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&varLB) && temp2 == nVars && arg++ &&
- !getDoubleMatrixFromScilab(arg,&temp1,&temp2,&varUB) && temp2 == nVars){
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarCUB) || isVarComplex(pvApiCtx, piAddressVarCUB) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 7);
+ return 0;
+ }
+ temp1 = nCons;
+ temp2 = 1;
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarCUB,&temp1, &temp2, &conUB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+
+ //varLB matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddressVarLB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarLB) || isVarComplex(pvApiCtx, piAddressVarLB) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 8);
+ return 0;
+ }
+ temp1 = 1;
+ temp2 = nVars;
+
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarLB, &temp1,&temp2, &varLB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //varUB matrix from scilab
+ /* get Address of inputs */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 9, &piAddressVarUB);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ /* Check that the first input argument is a real matrix (and not complex) */
+ if ( !isDoubleType(pvApiCtx, piAddressVarUB) || isVarComplex(pvApiCtx, piAddressVarUB) )
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 9);
+ return 0;
+ }
+
+ temp1 = 1;
+ temp2 = nVars;
+
+ /* get matrix */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarUB, &temp1,&temp2, &varUB);
+ 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);
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
app->RethrowNonIpoptException(true);
@@ -108,7 +299,6 @@ int sci_solveqp(char *fname)
double *Lambda = Prob->getLambda();
double iteration = Prob->iterCount();
int stats = Prob->returnStatus();
- SciErr sciErr;
sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, nVars, fX);
if (sciErr.iErr)
{
@@ -171,14 +361,6 @@ int sci_solveqp(char *fname)
// will be decremented and the objects will automatically
// be deleted.
-
- }
- else {
-
- sciprint("\nError:: check argument %d\n",arg);
- return0toScilab();
- return 1;
- }
return 0;
}