summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarpreet2015-11-24 11:50:13 +0530
committerHarpreet2015-11-24 11:50:13 +0530
commit92e88ea2600cc66ff8e8b7bb9c63bf72d78f1619 (patch)
treee4ae42f00de606e65ec3e6acb7fc7ce3366e2209
parent5d6df2fd95bc566d3b9efab874ad26c4a4789b71 (diff)
downloadFOSSEE-Optimization-toolbox-92e88ea2600cc66ff8e8b7bb9c63bf72d78f1619.tar.gz
FOSSEE-Optimization-toolbox-92e88ea2600cc66ff8e8b7bb9c63bf72d78f1619.tar.bz2
FOSSEE-Optimization-toolbox-92e88ea2600cc66ff8e8b7bb9c63bf72d78f1619.zip
code optimization
-rw-r--r--macros/qpipopt.sci22
-rw-r--r--macros/qpipoptmat.sci25
-rw-r--r--sci_gateway/cpp/sci_iofunc.cpp55
-rw-r--r--sci_gateway/cpp/sci_iofunc.hpp4
-rw-r--r--sci_gateway/cpp/sci_ipopt.cpp440
5 files changed, 189 insertions, 357 deletions
diff --git a/macros/qpipopt.sci b/macros/qpipopt.sci
index c17371e..e25aad9 100644
--- a/macros/qpipopt.sci
+++ b/macros/qpipopt.sci
@@ -121,6 +121,11 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
if (size(UB,2)==0) then
UB = repmat(%inf,nbVar,1);
end
+
+ if (size(p,2)==0) then
+ p = repmat(0,nbVar,1);
+ end
+
if ( rhs<10 | size(varargin(10)) ==0 ) then
x0 = repmat(0,nbVar,1);
@@ -289,8 +294,19 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
end
end
-
-
+ // Check if the user gives infinity or negative infinity in conLB or conUB
+ for i = 1:nbCon
+ if (conLB(i) == %inf)
+ errmsg = msprintf(gettext("%s: Value of Lower Bound can not be infinity"), "qpipopt");
+ error(errmsg);
+ end
+
+ if (conUB(i) == -%inf)
+ errmsg = msprintf(gettext("%s: Value of Upper Bound can not be negative infinity"), "qpipopt");
+ error(errmsg);
+ end
+ end
+
[xopt,fopt,status,iter,Zl,Zu,lmbda] = solveqp(nbVar,nbCon,Q,p,conMatrix,conLB,conUB,LB,UB,x0,options);
xopt = xopt';
@@ -324,7 +340,7 @@ function [xopt,fopt,exitflag,output,lambda] = qpipopt (varargin)
case 7 then
printf("\nFeasible point for square problem found.\n");
case 8 then
- printf("\nIterates divering; problem might be unbounded.\n");
+ printf("\nIterates diverging; problem might be unbounded.\n");
case 9 then
printf("\nRestoration Failed!\n");
case 10 then
diff --git a/macros/qpipoptmat.sci b/macros/qpipoptmat.sci
index 01b0eef..33e3bd6 100644
--- a/macros/qpipoptmat.sci
+++ b/macros/qpipoptmat.sci
@@ -152,7 +152,10 @@ function [xopt,fopt,exitflag,output,lambda] = qpipoptmat (varargin)
if (size(UB,2)==0) then
UB = repmat(%inf,nbVar,1);
end
-
+
+ if (size(f,2)==0) then
+ f = repmat(0,nbVar,1);
+ end
if (type(param) ~= 15) then
errmsg = msprintf(gettext("%s: param should be a list "), "qpipopt");
@@ -302,7 +305,19 @@ function [xopt,fopt,exitflag,output,lambda] = qpipoptmat (varargin)
end
end
+ for i = 1:nbConInEq
+ if (b(i) == -%inf)
+ errmsg = msprintf(gettext("%s: Value of b can not be negative infinity"), "qpipopt");
+ error(errmsg);
+ end
+ end
+ for i = 1:nbConEq
+ if (beq(i) == -%inf)
+ errmsg = msprintf(gettext("%s: Value of beq can not be negative infinity"), "qpipopt");
+ error(errmsg);
+ end
+ end
//Converting it into ipopt format
f = f';
@@ -321,13 +336,11 @@ function [xopt,fopt,exitflag,output,lambda] = qpipoptmat (varargin)
output.Iterations = iter;
lambda = struct("lower" , [], ..
"upper" , [], ..
- "ineqlin" , [], ..
- "eqlin" , []);
+ "constraint" , []);
lambda.lower = Zl;
lambda.upper = Zu;
- lambda.eqlin = lmbda(1:nbConEq);
- lambda.ineqlin = lmbda(nbConEq+1:nbCon);
+ lambda.constraint = lmbda;
select status
@@ -348,7 +361,7 @@ function [xopt,fopt,exitflag,output,lambda] = qpipoptmat (varargin)
case 7 then
printf("\nFeasible point for square problem found.\n");
case 8 then
- printf("\nIterates divering; problem might be unbounded.\n");
+ printf("\nIterates diverging; problem might be unbounded.\n");
case 9 then
printf("\nRestoration Failed!\n");
case 10 then
diff --git a/sci_gateway/cpp/sci_iofunc.cpp b/sci_gateway/cpp/sci_iofunc.cpp
index e1c8610..395aa3a 100644
--- a/sci_gateway/cpp/sci_iofunc.cpp
+++ b/sci_gateway/cpp/sci_iofunc.cpp
@@ -159,6 +159,28 @@ int getDoubleMatrixFromScilab(int argNum, int *rows, int *cols, double **dest)
return 0;
}
+int getFixedSizeDoubleMatrixInList(int argNum, int itemPos, int rows, int cols, double **dest)
+{
+ int *varAddress,inputMatrixRows,inputMatrixCols;
+ SciErr sciErr;
+ const char errMsg[]="Wrong type for input argument #%d: A matrix of double of size %d by %d is expected.\n";
+ const int errNum=999;
+ //same steps as above
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ getMatrixOfDoubleInList(pvApiCtx, varAddress, itemPos, &rows, &cols, dest);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+}
+
int return0toScilab()
{
int iRet;
@@ -192,3 +214,36 @@ int returnDoubleToScilab(double retVal)
//ReturnArguments(pvApiCtx);
return 0;
}
+
+int returnDoubleMatrixToScilab(int itemPos, int rows, int cols, double *dest)
+{
+ SciErr sciErr;
+ //same steps as above
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + itemPos, rows, cols, dest);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, itemPos) = nbInputArgument(pvApiCtx)+itemPos;
+
+ return 0;
+}
+
+int returnIntegerMatrixToScilab(int itemPos, int rows, int cols, int *dest)
+{
+ SciErr sciErr;
+ //same steps as above
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + itemPos, rows, cols, dest);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, itemPos) = nbInputArgument(pvApiCtx)+itemPos;
+
+ return 0;
+}
+
diff --git a/sci_gateway/cpp/sci_iofunc.hpp b/sci_gateway/cpp/sci_iofunc.hpp
index 1cf9a1a..3833777 100644
--- a/sci_gateway/cpp/sci_iofunc.hpp
+++ b/sci_gateway/cpp/sci_iofunc.hpp
@@ -11,9 +11,13 @@ int getUIntFromScilab(int argNum, int *dest);
int getIntFromScilab(int argNum, int *dest);
int getFixedSizeDoubleMatrixFromScilab(int argNum, int rows, int cols, double **dest);
int getDoubleMatrixFromScilab(int argNum, int *rows, int *cols, double **dest);
+int getFixedSizeDoubleMatrixInList(int argNum, int itemPos, int rows, int cols, double **dest);
+
//output
int return0toScilab();
int returnDoubleToScilab(double retVal);
+int returnDoubleMatrixToScilab(int itemPos, int rows, int cols, double *dest);
+int returnIntegerMatrixToScilab(int itemPos, int rows, int cols, int *dest);
#endif //SCI_IOFUNCHEADER
diff --git a/sci_gateway/cpp/sci_ipopt.cpp b/sci_gateway/cpp/sci_ipopt.cpp
index 98ed153..0f94e47 100644
--- a/sci_gateway/cpp/sci_ipopt.cpp
+++ b/sci_gateway/cpp/sci_ipopt.cpp
@@ -7,7 +7,6 @@
Harpreet Singh
*/
-
#include "sci_iofunc.hpp"
#include "IpIpoptApplication.hpp"
#include "QuadNLP.hpp"
@@ -19,325 +18,134 @@ extern "C"{
#include <localization.h>
#include <sciprint.h>
-int j;
-double *op_x, *op_obj,*p;
-
-bool readSparse(int arg,int *iRows,int *iCols,int *iNbItem,int** piNbItemRow, int** piColPos, double** pdblReal){
- SciErr sciErr;
- int* piAddr = NULL;
- int iType = 0;
- int iRet = 0;
- sciErr = getVarAddressFromPosition(pvApiCtx, arg, &piAddr);
- if(sciErr.iErr) {
- printError(&sciErr, 0);
- return false;
- }
- sciprint("\ndone\n");
- if(isSparseType(pvApiCtx, piAddr)){
- sciprint("done\n");
- sciErr =getSparseMatrix(pvApiCtx, piAddr, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
- if(sciErr.iErr) {
- printError(&sciErr, 0);
- return false;
- }
- }
-
- else {
- sciprint("\nSparse matrix required\n");
- return false;
- }
- return true;
- }
-
int sci_solveqp(char *fname)
{
-
+ using namespace Ipopt;
+
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,*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;
+
+ // Input arguments
+ double *QItems=NULL,*PItems=NULL,*ConItems=NULL,*conUB=NULL,*conLB=NULL;
+ double *cpu_time=NULL,*max_iter=NULL,*varUB=NULL,*varLB=NULL,*init_guess=NULL;
static unsigned int nVars = 0,nCons = 0;
- unsigned int temp1 = 0,temp2 = 0;
+ unsigned int temp1 = 0,temp2 = 0, iret = 0;
+ // Output arguments
+ double *fX = NULL, ObjVal=0,iteration=0, *Zl=NULL, *Zu=NULL, *Lambda=NULL;
+ int rstatus = 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)
+ if(getIntFromScilab(1,&nVars))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- /* Check that the first input argument is a real matrix (and not complex) */
- if ( !isDoubleType(pvApiCtx, piAddressVarQ) || isVarComplex(pvApiCtx, piAddressVarQ) )
+ //Number of Constraints
+ if (getIntFromScilab(2,&nCons))
{
- Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 3);
- return 0;
+ return 1;
}
- /* get matrix */
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarQ, &temp1, &temp1, &QItems);
- if (sciErr.iErr)
+ //Q matrix from scilab
+ temp1 = nVars;
+ temp2 = nCons;
+ if (getFixedSizeDoubleMatrixFromScilab(3,temp1,temp1,&QItems))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
//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)
+ if (getFixedSizeDoubleMatrixFromScilab(4,temp1,temp2,&PItems))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
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)
+ if (getFixedSizeDoubleMatrixFromScilab(5,temp1,temp2,&ConItems))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
//conLB matrix from scilab
- /* get Address of inputs */
- sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddressVarCLB);
- if (sciErr.iErr)
+ temp1 = 1;
+ temp2 = nCons;
+ if (getFixedSizeDoubleMatrixFromScilab(6,temp1,temp2,&conLB))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- /* 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;
-
- /* 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;
- }
-
- /* 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)
+ if (getFixedSizeDoubleMatrixFromScilab(7,temp1,temp2,&conUB))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
}
//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)
+ if (getFixedSizeDoubleMatrixFromScilab(8,temp1,temp2,&varLB))
{
- 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;
+ return 1;
}
- temp1 = 1;
- temp2 = nVars;
- /* get matrix */
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarUB, &temp1,&temp2, &varUB);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
-
- /* get matrix */
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarLB, &temp1,&temp2, &varLB);
- if (sciErr.iErr)
+ //varUB matrix from scilab
+ if (getFixedSizeDoubleMatrixFromScilab(9,temp1,temp2,&varUB))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
//Initial Value of variables from scilab
- /* get Address of inputs */
- sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddressVarG);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
- /* Check that the first input argument is a real matrix (and not complex) */
- if ( !isDoubleType(pvApiCtx, piAddressVarG) || isVarComplex(pvApiCtx, piAddressVarG) )
+ if (getFixedSizeDoubleMatrixFromScilab(10,temp1,temp2,&init_guess))
{
- Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 10);
- return 0;
- }
-
- temp1 = 1;
- temp2 = nVars;
-
- /* get matrix */
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarG, &temp1,&temp2, &init_guess);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- //Setting the parameters
- /* get Address of inputs */
- sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddressVarParam);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
+ //Getting the parameters
temp1 = 1;
temp2 = 1;
- /* get matrix */
- sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddressVarParam, 2, &temp1,&temp2, &max_iter);
- if (sciErr.iErr)
+ //Getting maximum iteration
+ if (getFixedSizeDoubleMatrixInList(11,2,temp1,temp2,&max_iter))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- /* get matrix */
- sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddressVarParam, 4, &temp1,&temp2, &cpu_time);
- if (sciErr.iErr)
+ //Getting Cpu Time
+ if (getFixedSizeDoubleMatrixInList(11,4,temp1,temp2,&cpu_time))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- using namespace Ipopt;
+ // Starting Ipopt
+
+ SmartPtr<QuadNLP> Prob =
+ new QuadNLP(nVars,nCons,QItems,PItems,ConItems,conUB,conLB,varUB,varLB,init_guess);
- SmartPtr<QuadNLP> Prob = new QuadNLP(nVars,nCons,QItems,PItems,ConItems,conUB,conLB,varUB,varLB,init_guess);
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
app->RethrowNonIpoptException(true);
- // Change some options
- // Note: The following choices are only examples, they might not be
- // suitable for your optimization problem.
+ ////////// Managing the parameters //////////
+
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
app->Options()->SetStringValue("jac_c_constant", "yes");
// Indicates whether all inequality constraints are linear
@@ -345,7 +153,7 @@ int sci_solveqp(char *fname)
// Indicates whether the problem is a quadratic problem
app->Options()->SetStringValue("hessian_constant", "yes");
- // Initialize the IpoptApplication and process the options
+ ///////// Initialize the IpoptApplication and process the options /////////
ApplicationReturnStatus status;
status = app->Initialize();
if (status != Solve_Succeeded) {
@@ -356,165 +164,101 @@ int sci_solveqp(char *fname)
status = app->OptimizeTNLP(Prob);
- int stats = Prob->returnStatus();
+ rstatus = Prob->returnStatus();
+
+ ////////// Manage the output argument //////////
- if (stats == 0 | stats == 1 | stats == 2){
- double *fX = Prob->getX();
- double ObjVal = Prob->getObjVal();
- double iteration = Prob->iterCount();
+ if (rstatus == 0 | rstatus == 1 | rstatus == 2){
+ fX = Prob->getX();
+ ObjVal = Prob->getObjVal();
+ iteration = Prob->iterCount();
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, nVars, fX);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(1, 1, nVars, fX))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2,1,1,&ObjVal);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(2, 1, 1, &ObjVal))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 3,1,1,&stats);
- if (sciErr.iErr)
+ if (returnIntegerMatrixToScilab(3, 1, 1, &rstatus))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4,1,1,&iteration);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(4, 1, 1, &iteration))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
- AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
- AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
- AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
}
else
{
- double *fX = NULL;
- double ObjVal = 0;
- int stats = Prob->returnStatus();
- double iteration = 0;
-
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 0, 0, fX);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(1, 0, 0, fX))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2,1,1,&ObjVal);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(2, 1, 1, &ObjVal))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 3,1,1,&stats);
- if (sciErr.iErr)
+ if (returnIntegerMatrixToScilab(3, 1, 1, &rstatus))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4,1,1,&iteration);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(4, 1, 1, &iteration))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
- AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
- AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
- AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
}
- if(stats == 0){
-
- double *Zl = Prob->getZl();
- double *Zu = Prob->getZu();
- double *Lambda = Prob->getLambda();
+ if(rstatus == 0){
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 1, nVars, Zl);
- if (sciErr.iErr)
+ Zl = Prob->getZl();
+ Zu = Prob->getZu();
+ Lambda = Prob->getLambda();
+ if (returnDoubleMatrixToScilab(5, 1, nVars, Zl))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, 1, nVars, Zu);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(6, 1, nVars, Zu))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 7, 1, nCons, Lambda);
- if (sciErr.iErr)
+
+ if (returnDoubleMatrixToScilab(7, 1, 1, Lambda))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
- AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
- AssignOutputVariable(pvApiCtx, 7) = nbInputArgument(pvApiCtx) + 7;
}
else{
- double *Zl = NULL;
- double *Zu = NULL;
- double *Lambda = NULL;
-
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 0, 0, Zl);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(5, 0, 0, Zl))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, 0, 0, Zu);
- if (sciErr.iErr)
+ if (returnDoubleMatrixToScilab(6, 0, 0, Zu))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 7, 0, 0, Lambda);
- if (sciErr.iErr)
+
+ if (returnDoubleMatrixToScilab(7, 0, 0, Lambda))
{
- printError(&sciErr, 0);
- return 0;
+ return 1;
}
-
- AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
- AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
- AssignOutputVariable(pvApiCtx, 7) = nbInputArgument(pvApiCtx) + 7;
}
-
// As the SmartPtrs go out of scope, the reference count
// will be decremented and the objects will automatically
// be deleted.
return 0;
}
-
}
-
-/*
-hessian_constan
-jacobian _constant
-
-j_s_d constant : yes
-*/
-