37 #if defined(__WIN32__) || defined(WIN32) 39 #elif defined(LINUX) || defined(__LINUX__) 49 #include <scilab/sciprint.h> 53 #include <qpOASES/Utils.hpp> 56 #ifdef __NO_SNPRINTF__ 57 #if (!defined(_MSC_VER)) || defined(__DSPACE__) || defined(__XPCTARGET__) 59 int snprintf(
char* s,
size_t n,
const char* format, ... )
78 #ifndef __SUPPRESSANYOUTPUT__ 109 #ifndef __SUPPRESSANYOUTPUT__ 140 #ifndef __SUPPRESSANYOUTPUT__ 153 for( i=0; i<nrow; ++i )
154 print( &(M[i*ncol]), ncol );
168 #ifndef __SUPPRESSANYOUTPUT__ 181 for( i=0; i<nrow; ++i )
182 print( &( M[ ROW_idx[i]*ncol ] ), ncol, COL_idx );
196 #ifndef __SUPPRESSANYOUTPUT__ 227 #ifndef __SUPPRESSANYOUTPUT__ 240 if ( outputfile == 0 )
242 fprintf( outputfile,
"%s", s );
257 #ifndef __SUPPRESSANYOUTPUT__ 258 #ifndef __XPCTARGET__ 260 #ifndef __NO_COPYRIGHT__ 261 myPrintf(
"\nqpOASES -- An Implementation of the Online Active Set Strategy.\nCopyright (C) 2007-2015 by Hans Joachim Ferreau, Andreas Potschka,\nChristian Kirches et al. All rights reserved.\n\nqpOASES is distributed under the terms of the \nGNU Lesser General Public License 2.1 in the hope that it will be \nuseful, but WITHOUT ANY WARRANTY; without even the implied warranty \nof MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \nSee the GNU Lesser General Public License for more details.\n\n" );
274 const char* datafilename
277 #ifndef __SUPPRESSANYOUTPUT__ 284 if ( ( datafile = fopen( datafilename,
"r" ) ) == 0 )
292 for( i=0; i<nrow; ++i )
294 for( j=0; j<ncol; ++j )
296 #ifdef __USE_SINGLE_PRECISION__ 297 if ( fscanf( datafile,
"%f ", &float_data ) == 0 )
299 if ( fscanf( datafile,
"%lf ", &float_data ) == 0 )
307 data[i*ncol + j] = ( (
real_t) float_data );
328 const char* datafilename
340 const char* datafilename
343 #ifndef __SUPPRESSANYOUTPUT__ 349 if ( ( datafile = fopen( datafilename,
"r" ) ) == 0 )
359 #ifdef __USE_LONG_INTEGERS__ 360 if ( fscanf( datafile,
"%ld\n", &(data[i]) ) == 0 )
362 if ( fscanf( datafile,
"%d\n", &(data[i]) ) == 0 )
392 #ifndef __SUPPRESSANYOUTPUT__ 401 if ( ( datafile = fopen( datafilename,
"a" ) ) == 0 )
411 if ( ( datafile = fopen( datafilename,
"w" ) ) == 0 )
420 for( i=0; i<nrow; ++i )
422 for( j=0; j<ncol; ++j )
423 fprintf( datafile,
"%.16e ", data[i*ncol+j] );
425 fprintf( datafile,
"\n" );
459 #ifndef __SUPPRESSANYOUTPUT__ 469 if ( ( datafile = fopen( datafilename,
"a" ) ) == 0 )
479 if ( ( datafile = fopen( datafilename,
"w" ) ) == 0 )
489 fprintf( datafile,
"%d\n",(
int)(integer[i]) );
514 #ifndef __SUPPRESSANYOUTPUT__ 516 if ( ( matFile == 0 ) || ( data == 0 ) || ( nRows < 0 ) || ( nCols < 0 ) || ( name == 0 ) )
532 if ( fwrite( name,
sizeof(
char),(
unsigned long)(var.
nCharName), matFile ) < 1 )
538 for ( ii=0; ii<nCols; ++ii )
539 for ( jj=0; jj<nRows; ++jj )
541 curData = (
real_t)data[jj*nCols+ii];
542 if ( fwrite( &curData,
sizeof(
double),1, matFile ) < 1 )
567 for ( ii=0; ii<nRows; ++ii )
568 for ( jj=0; jj<nCols; ++jj )
569 realData[ ii*nCols+jj ] = (
real_t) data[ ii*nCols+jj ];
583 real_t current_time = -1.0;
585 #if defined(__WIN32__) || defined(WIN32) 586 LARGE_INTEGER
counter, frequency;
587 QueryPerformanceFrequency(&frequency);
588 QueryPerformanceCounter(&counter);
589 current_time = ((
real_t) counter.QuadPart) / ((
real_t) frequency.QuadPart);
590 #elif defined(LINUX) || defined(__LINUX__) 591 struct timeval theclock;
592 gettimeofday( &theclock,0 );
593 current_time = 1.0*(
real_t) theclock.tv_sec + 1.0e-6* (
real_t) theclock.tv_usec;
640 const real_t dualActiveTolerance = 1.0e3 *
EPS;
646 stat = feas = cmpl = 0.0;
649 for (i = 0; i < nV; i++)
659 for (j = 0; j < nV; j++) sum += H[i*nV+j] * x[j];
662 if ( hasIdentityHessian ==
BT_TRUE )
663 for (j = 0; j < nV; j++) sum += x[j];
668 for (j = 0; j < nC; j++) sum -= A[j*nV+i] * y[nV+j];
676 for (i = 0; i < nV; i++)
679 if (lb[i] - x[i] > feas)
683 if (x[i] - ub[i] > feas)
688 if ( workingSetB == 0 )
690 for (i = 0; i < nV; i++)
696 if (y[i] > dualActiveTolerance)
697 prod = (x[i] - lb[i]) * y[i];
701 if (y[i] < -dualActiveTolerance)
702 prod = (x[i] - ub[i]) * y[i];
709 for (i = 0; i < nV; i++)
717 prod = (x[i] - lb[i]) * y[i];
724 prod = (x[i] - ub[i]) * y[i];
732 for (i = 0; i < nC; i++)
737 for (j = 0; j < nV; j++)
738 sum += A[i*nV+j] * x[j];
742 if (lbA[i] - sum > feas)
746 if (sum - ubA[i] > feas)
755 if ( workingSetC == 0 )
757 if (y[nV+i] > dualActiveTolerance)
758 prod = (sum - lbA[i]) * y[nV+i];
763 prod = (sum - lbA[i]) * y[nV+i];
770 if ( workingSetC == 0 )
772 if (y[nV+i] < -dualActiveTolerance)
773 prod = (sum - ubA[i]) * y[nV+i];
778 prod = (sum - ubA[i]) * y[nV+i];
804 workingSetB,0,hasIdentityHessian
814 #ifndef __SUPPRESSANYOUTPUT__ 816 snprintf(
string,20,
"BT_FALSE" );
818 snprintf(
string,20,
"BT_TRUE" );
830 #ifndef __SUPPRESSANYOUTPUT__ 834 snprintf(
string,20,
"ST_INACTIVE" );
838 snprintf(
string,20,
"ST_LOWER" );
842 snprintf(
string,20,
"ST_UPPER" );
846 snprintf(
string,20,
"ST_UNDEFINED" );
850 snprintf(
string,20,
"ST_INFEASIBLE_LOWER" );
854 snprintf(
string,20,
"ST_INFEASIBLE_UPPER" );
858 snprintf(
string,20,
"<invalid value>" );
872 #ifndef __SUPPRESSANYOUTPUT__ 876 snprintf(
string,20,
"PL_NONE" );
880 snprintf(
string,20,
"PL_LOW" );
884 snprintf(
string,20,
"PL_MEDIUM" );
888 snprintf(
string,20,
"PL_HIGH" );
892 snprintf(
string,20,
"PL_TABULAR" );
896 snprintf(
string,20,
"PL_DEBUG_ITER" );
900 snprintf(
string,20,
"<invalid value>" );
916 int_t simpleStatus = -1;
919 switch ( returnvalue )
944 if ( doPrintStatus ==
BT_TRUE )
971 if ( ( nV <= 0 ) || ( nC <= 0 ) || ( A == 0 ) )
974 for( ii=0; ii<nC; ++ii )
977 curNorm =
getNorm( &(A[ii*nV]),nV,type );
982 for( jj=0; jj<nV; ++jj )
983 A[ii*nV + jj] /= curNorm;
985 if ( lbA != 0 ) lbA[ii] /= curNorm;
986 if ( ubA != 0 ) ubA[ii] /= curNorm;
993 for( jj=0; jj<nV; ++jj )
994 A[ii*nV + jj] = 1.0 / ((
real_t)nV);
999 for( jj=0; jj<nV; ++jj )
1003 if ( lbA != 0 ) lbA[ii] = -
INFTY;
1004 if ( ubA != 0 ) ubA[ii] =
INFTY;
1018 #ifndef __SUPPRESSANYOUTPUT__ 1023 fid = fopen(fname,
"wt");
1026 perror(
"Error opening file: ");
1030 for (i = 0; i < n; i++)
1032 for (j = 0; j < m; j++)
1033 fprintf(fid,
" %23.16e", M[j*ldim+i]);
1044 #if defined(__DSPACE__) || defined(__XPCTARGET__) || defined(__C_WRAPPER__) 1048 void __cxa_pure_virtual(
void )
real_t getNorm(const real_t *const v, int_t n, int_t type)
int_t getSimpleStatus(returnValue returnvalue, BooleanType doPrintStatus)
returnValue convertPrintLevelToString(PrintLevel value, char *const string)
returnValue throwError(returnValue Enumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
returnValue getKktViolation(int_t nV, int_t nC, const real_t *const H, const real_t *const g, const real_t *const A, const real_t *const lb, const real_t *const ub, const real_t *const lbA, const real_t *const ubA, const real_t *const x, const real_t *const y, real_t &stat, real_t &feas, real_t &cmpl, const real_t *const workingSetB, const real_t *const workingSetC, BooleanType hasIdentityHessian)
BEGIN_NAMESPACE_ACADO const double EPS
VisibilityStatus getInfoVisibilityStatus() const
#define THROWINFO(retval)
#define ST_INFEASIBLE_UPPER
Allows to pass back messages to the calling function.
returnValue convertSubjectToStatusToString(SubjectToStatus value, char *const string)
#define THROWERROR(retval)
#define ST_INFEASIBLE_LOWER
returnValue normaliseConstraints(int_t nV, int_t nC, real_t *A, real_t *lbA, real_t *ubA, int_t type)
returnValue readFromFile(real_t *data, int_t nrow, int_t ncol, const char *datafilename)
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int_t n, const char *name)
returnValue writeIntoMatFile(FILE *const matFile, const real_t *const data, int_t nRows, int_t nCols, const char *name)
returnValue printCopyrightNotice()
void setInfoVisibilityStatus(VisibilityStatus _infoVisibility)
returnValue myPrintf(const char *s)
returnValue setErrorCount(int _errorCount)
returnValue writeIntoFile(const real_t *const data, int_t nrow, int_t ncol, const char *datafilename, BooleanType append)
#define END_NAMESPACE_QPOASES
returnValue convertBooleanTypeToString(BooleanType value, char *const string)
const uint_t MAX_STRING_LENGTH
myFILE * getOutputFile() const
#define BEGIN_NAMESPACE_QPOASES
MessageHandling * getGlobalMessageHandler()
BooleanType isEqual(real_t x, real_t y, real_t TOL=ZERO)