40 void MyPrintf(
const char* pformat, ... );
43 # define MyPrintf mexPrintf 125 if ( zeroPivots )
delete[] zeroPivots;
162 #define MA27ID ma27id_ 163 #define MA27AD ma27ad_ 164 #define MA27BD ma27bd_ 165 #define MA27CD ma27cd_ 168 void MA27ID(
fint* ICNTL,
double* CNTL);
172 double* CNTL,
fint *INFO,
double* OPS);
176 fint* IW1,
fint* ICNTL,
double* CNTL,
180 double* RHS,
fint* IW1,
fint* NSTEPS,
181 fint* ICNTL,
double* CNTL);
202 MA27ID(icntl_ma27, cntl_ma27);
212 Ma27SparseSolver::Ma27SparseSolver(
const Ma27SparseSolver&
rhs )
221 Ma27SparseSolver::~Ma27SparseSolver( )
230 Ma27SparseSolver& Ma27SparseSolver::operator=(
const SparseSolver&
rhs )
232 const Ma27SparseSolver* ma27_rhs =
dynamic_cast<const Ma27SparseSolver*
>(&
rhs);
235 fprintf(
getGlobalMessageHandler()->getOutputFile(),
"Error in Ma27SparseSolver& Ma27SparseSolver::operator=( const SparseSolver& rhs )\n");
238 if (
this != ma27_rhs )
253 const int_t*
const irn,
254 const int_t*
const jcn,
260 numNonzeros = numNonzeros_;
262 if ( numNonzeros_ > 0 )
264 a_ma27 =
new double[numNonzeros_];
265 irn_ma27 =
new fint[numNonzeros_];
266 jcn_ma27 =
new fint[numNonzeros_];
269 for (
int_t i=0; i<numNonzeros_; ++i)
272 a_ma27[numNonzeros] = avals[i];
273 irn_ma27[numNonzeros] = irn[i];
274 jcn_ma27[numNonzeros] = jcn[i];
297 have_factorization =
true;
308 const double LiwFact = 2.0;
309 liw_ma27 = (
fint)(LiwFact*(
double(2*numNonzeros+3*dim+1)));
310 iw_ma27 =
new fint[liw_ma27];
312 ikeep_ma27 =
new fint[3*dim];
318 MA27AD(&dim, &numNonzeros, irn_ma27, jcn_ma27, iw_ma27, &liw_ma27, ikeep_ma27,
319 iw1_ma27, &nsteps_ma27, &iflag_ma27, icntl_ma27, cntl_ma27,
320 info_ma27, &ops_ma27);
323 fint iflag = info_ma27[0];
324 fint ierror = info_ma27[1];
325 fint nrlnec = info_ma27[4];
326 fint nirnec = info_ma27[5];
329 MyPrintf(
"MA27AD returns iflag = %d with ierror = %d\n", iflag, ierror);
337 double liw_init_factor = 5.0;
338 liw_ma27 = (
fint)(liw_init_factor * (
double)(nirnec));
339 iw_ma27 =
new fint[liw_ma27];
341 double la_init_factor = 20.0;
342 la_ma27 =
getMax(numNonzeros,(
fint)(la_init_factor * (
double)(nrlnec)));
343 double* a_new =
new double[la_ma27];
344 for (
int_t i=0; i<numNonzeros; ++i)
345 a_new[i] = a_ma27[i];
353 MA27BD(&dim, &numNonzeros, irn_ma27, jcn_ma27, a_ma27,
354 &la_ma27, iw_ma27, &liw_ma27, ikeep_ma27, &nsteps_ma27,
355 &maxfrt_ma27, iw1_ma27, icntl_ma27, cntl_ma27, info_ma27);
359 iflag = info_ma27[0];
360 ierror = info_ma27[1];
361 neig = info_ma27[14];
367 else if (iflag == -5)
374 MyPrintf(
"MA27BD returns iflag = %d with ierror = %d\n", iflag, ierror);
381 have_factorization =
true;
398 if ( !have_factorization )
400 MyPrintf(
"Factorization not called before solve in Ma27SparseSolver::solve.\n");
408 double* w_ma27 =
new double[maxfrt_ma27];
409 fint* iw1_ma27 =
new fint[nsteps_ma27];
412 for (
int_t i=0; i<dim; ++i) sol[i] = rhs[i];
413 MA27CD(&dim, a_ma27, &la_ma27, iw_ma27, &liw_ma27, w_ma27, &maxfrt_ma27,
414 sol, iw1_ma27, &nsteps_ma27, icntl_ma27, cntl_ma27);
438 int_t Ma27SparseSolver::getNegativeEigenvalues( )
440 if( !have_factorization )
449 int_t Ma27SparseSolver::getRank( )
467 delete [] ikeep_ma27;
484 have_factorization =
false;
492 returnValue Ma27SparseSolver::copy(
const Ma27SparseSolver& rhs
496 numNonzeros = rhs.numNonzeros;
497 la_ma27 = rhs.la_ma27;
498 if ( rhs.a_ma27 != 0 )
500 if (rhs.have_factorization)
502 a_ma27 =
new double[la_ma27];
503 memcpy( a_ma27,rhs.a_ma27,la_ma27*
sizeof(
double) );
507 a_ma27 =
new double[numNonzeros];
508 memcpy( a_ma27,rhs.a_ma27,numNonzeros*
sizeof(
double) );
514 if ( rhs.irn_ma27 != 0 )
516 irn_ma27 =
new fint[numNonzeros];
517 memcpy( irn_ma27,rhs.irn_ma27,numNonzeros*
sizeof(
fint) );
522 if ( rhs.jcn_ma27 != 0 )
524 jcn_ma27 =
new fint[numNonzeros];
525 memcpy( jcn_ma27,rhs.jcn_ma27,numNonzeros*
sizeof(
fint) );
530 for (
int_t i=0; i<30; ++i)
531 icntl_ma27[i] = rhs.icntl_ma27[i];
533 for (
int_t i=0; i<5; ++i)
534 cntl_ma27[i] = rhs.cntl_ma27[i];
536 liw_ma27 = rhs.liw_ma27;
538 if ( rhs.iw_ma27 != 0 )
540 iw_ma27 =
new fint[liw_ma27];
541 memcpy( iw_ma27,rhs.iw_ma27,liw_ma27*
sizeof(
fint) );
546 if ( rhs.ikeep_ma27 != 0 )
548 ikeep_ma27 =
new fint[3*dim];
549 memcpy( ikeep_ma27,rhs.ikeep_ma27,3*dim*
sizeof(
fint) );
554 nsteps_ma27 = rhs.nsteps_ma27;
555 maxfrt_ma27 = rhs.maxfrt_ma27;
557 have_factorization = rhs.have_factorization;
564 #endif // SOLVER_MA27 576 #define MA57ID ma57id_ 577 #define MA57AD ma57ad_ 578 #define MA57BD ma57bd_ 579 #define MA57CD ma57cd_ 668 MA57ID( cntl_ma57, icntl_ma57 );
685 Ma57SparseSolver::Ma57SparseSolver(
const Ma57SparseSolver& rhs )
694 Ma57SparseSolver::~Ma57SparseSolver( )
703 Ma57SparseSolver& Ma57SparseSolver::operator=(
const SparseSolver& rhs )
705 const Ma57SparseSolver* ma57_rhs =
dynamic_cast<const Ma57SparseSolver*
>(&
rhs);
708 fprintf(
getGlobalMessageHandler()->getOutputFile(),
"Error in Ma57SparseSolver& Ma57SparseSolver::operator=( const SparseSolver& rhs )\n");
711 if (
this != ma57_rhs )
726 const int_t*
const irn,
727 const int_t*
const jcn,
733 numNonzeros = numNonzeros_;
735 if ( numNonzeros_ > 0 )
737 a_ma57 =
new double[numNonzeros_];
738 irn_ma57 =
new fint[numNonzeros_];
739 jcn_ma57 =
new fint[numNonzeros_];
742 for (
int_t i=0; i<numNonzeros_; ++i)
745 a_ma57[numNonzeros] = avals[i];
746 irn_ma57[numNonzeros] = irn[i];
747 jcn_ma57[numNonzeros] = jcn[i];
770 have_factorization =
true;
780 fint lkeep_ma57 = 5*dim + numNonzeros +
getMax(numNonzeros,dim) + 42;
781 fint *keep_ma57 =
new fint[lkeep_ma57];
785 double rinfo_ma57[20];
787 MA57AD(&dim, &numNonzeros, irn_ma57, jcn_ma57, &lkeep_ma57, keep_ma57,
788 iwork_ma57, icntl_ma57, info_ma57, rinfo_ma57);
791 fint iflag = info_ma57[0];
792 fint ierror = info_ma57[1];
795 MyPrintf(
"MA57AD returns iflag = %d with ierror = %d\n", iflag, ierror);
797 delete [] iwork_ma57;
803 double lfact_factor = 10.0;
805 lfact_ma57 = (
fint)(lfact_factor * (
double)(info_ma57[8]));
806 fact_ma57 =
new double[lfact_ma57];
808 lifact_ma57 = (
fint)(lfact_factor * (
double)(info_ma57[9]));
809 ifact_ma57 =
new int_t[lifact_ma57];
815 MA57BD( &dim, &numNonzeros, a_ma57, fact_ma57, &lfact_ma57,
816 ifact_ma57, &lifact_ma57, &lkeep_ma57, keep_ma57,
817 iwork_ma57, icntl_ma57, cntl_ma57, info_ma57, rinfo_ma57 );
819 delete [] iwork_ma57;
823 iflag = info_ma57[0];
824 ierror = info_ma57[1];
825 neig = info_ma57[23];
826 rank = info_ma57[24];
829 pivots =
new fint[dim];
831 fint nblk = ifact_ma57[2];
833 int_t k, kk, count = 0;
834 for ( k=0; k<nblk; k++ )
836 ncols = ifact_ma57[iwpos];
837 nrows = ifact_ma57[iwpos+1];
839 for ( kk=0; kk<nrows; kk++ )
840 pivots[count++] = ifact_ma57[iwpos+2+kk]-1;
842 iwpos = iwpos+ncols+2;
856 MyPrintf(
"MA57BD returns iflag = %d with ierror = %d\n", iflag, ierror);
861 have_factorization =
true;
878 if ( !have_factorization )
880 MyPrintf(
"Factorization not called before solve in Ma57SparseSolver::solve.\n");
890 fint lrhs_ma57 = dim;
893 fint lwork_ma57 = dim*nrhs_ma57;
894 double* work_ma57 =
new double[lwork_ma57];
898 for (
int_t i=0; i<dim; ++i) sol[i] = rhs[i];
899 MA57CD(&job_ma57, &dim, fact_ma57, &lfact_ma57, ifact_ma57, &lifact_ma57,
900 &nrhs_ma57, sol, &lrhs_ma57, work_ma57, &lwork_ma57, iwork_ma57,
901 icntl_ma57, info_ma57);
904 delete [] iwork_ma57;
906 fint iflag = info_ma57[0];
907 fint ierror = info_ma57[1];
910 MyPrintf(
"MA57CD returns iflag = %d with ierror = %d\n", iflag, ierror);
934 int_t Ma57SparseSolver::getNegativeEigenvalues( )
936 if( !have_factorization )
945 int_t Ma57SparseSolver::getRank( )
955 for (
int_t k=0; k<dim-rank; k++ )
956 zeroPivots[k] = pivots[rank+k];
974 delete [] ifact_ma57;
992 have_factorization =
false;
1000 returnValue Ma57SparseSolver::copy(
const Ma57SparseSolver& rhs
1004 numNonzeros = rhs.numNonzeros;
1007 have_factorization = rhs.have_factorization;
1009 if ( rhs.a_ma57 != 0 )
1011 a_ma57 =
new double[numNonzeros];
1012 memcpy( a_ma57,rhs.a_ma57,numNonzeros*
sizeof(
double) );
1017 if ( rhs.irn_ma57 != 0 )
1019 irn_ma57 =
new fint[numNonzeros];
1020 memcpy( irn_ma57,rhs.irn_ma57,numNonzeros*
sizeof(
fint) );
1025 if ( rhs.jcn_ma57 != 0 )
1027 jcn_ma57 =
new fint[numNonzeros];
1028 memcpy( jcn_ma57,rhs.jcn_ma57,numNonzeros*
sizeof(
fint) );
1033 for (
int_t i=0; i<30; ++i)
1034 icntl_ma57[i] = rhs.icntl_ma57[i];
1036 for (
int_t i=0; i<5; ++i)
1037 cntl_ma57[i] = rhs.cntl_ma57[i];
1039 lfact_ma57 = rhs.lfact_ma57;
1040 if ( rhs.fact_ma57 != 0 )
1042 fact_ma57 =
new double[lfact_ma57];
1043 memcpy( fact_ma57,rhs.fact_ma57,lfact_ma57*
sizeof(
double) );
1048 lifact_ma57 = rhs.lifact_ma57;
1049 if ( rhs.ifact_ma57 != 0 )
1051 ifact_ma57 =
new fint[lifact_ma57];
1052 memcpy( ifact_ma57,rhs.ifact_ma57,lifact_ma57*
sizeof(
fint) );
1057 if ( have_factorization )
1059 pivots =
new fint[dim];
1060 memcpy( pivots, rhs.pivots, dim*
sizeof(
fint) );
1068 #endif // SOLVER_MA57 1075 const int_t*
const airn,
1076 const int_t*
const acjn,
1077 const real_t*
const avals
1096 #endif // SOLVER_NONE
virtual SparseSolver & operator=(const SparseSolver &rhs)
BooleanType isZero(real_t x, real_t TOL=ZERO)
void MyPrintf(const char *pformat,...)
Allows to pass back messages to the calling function.
#define THROWERROR(retval)
virtual int_t getNegativeEigenvalues()
void rhs(const real_t *x, real_t *f)
#define END_NAMESPACE_QPOASES
Generic interface for sparse solvers to be coupled with ACADO Toolkit.
virtual returnValue reset()
#define BEGIN_NAMESPACE_QPOASES
returnValue copy(const SparseSolver &rhs)
MessageHandling * getGlobalMessageHandler()
virtual returnValue getZeroPivots(int_t *&zeroPivots)