/* * s e t u p C o n s t r a i n t */ returnValue Constraints::setupConstraint( int _number, SubjectToStatus _status ) { /* consistency check */ if ( ( _number < 0 ) || ( _number >= getNC( ) ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Add constraint index to respective index list. */ switch ( _status ) { case ST_INACTIVE: if ( this->addIndex( this->getInactive( ),_number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); break; case ST_LOWER: if ( this->addIndex( this->getActive( ),_number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); break; case ST_UPPER: if ( this->addIndex( this->getActive( ),_number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); break; default: return THROWERROR( RET_INVALID_ARGUMENTS ); } return SUCCESSFUL_RETURN; }
/* * s e t C y c l i n g S t a t u s */ returnValue CyclingManager::setCyclingStatus( int number, BooleanType isBound, CyclingStatus _status ) { if ( isBound == BT_TRUE ) { /* Set cycling status of a bound. */ if ( ( number >= 0 ) && ( number < nV ) ) { status[number] = _status; return SUCCESSFUL_RETURN; } else return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); } else { /* Set cycling status of a constraint. */ if ( ( number >= 0 ) && ( number < nC ) ) { status[nV+number] = _status; return SUCCESSFUL_RETURN; } else return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); } }
/* * s e t u p B o u n d */ returnValue Bounds::setupBound( int number, SubjectToStatus _status ) { /* consistency check */ if ( ( number < 0 ) || ( number >= n ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Add bound index to respective index list. */ switch ( _status ) { case ST_INACTIVE: if ( this->addIndex( this->getFree( ),number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); break; case ST_LOWER: if ( this->addIndex( this->getFixed( ),number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); break; case ST_UPPER: if ( this->addIndex( this->getFixed( ),number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); break; default: return THROWERROR( RET_INVALID_ARGUMENTS ); } return SUCCESSFUL_RETURN; }
/* * a d d I n d e x */ returnValue SubjectTo::addIndex( Indexlist* const indexlist, int_t newnumber, SubjectToStatus newstatus ) { if ( status != 0 ) { /* consistency check */ if ( status[newnumber] == newstatus ) return THROWERROR( RET_INDEX_ALREADY_OF_DESIRED_STATUS ); status[newnumber] = newstatus; } else return THROWERROR( RET_ADDINDEX_FAILED ); if ( indexlist != 0 ) { if ( indexlist->addNumber( newnumber ) == RET_INDEXLIST_EXCEEDS_MAX_LENGTH ) return THROWERROR( RET_ADDINDEX_FAILED ); } else return THROWERROR( RET_INVALID_ARGUMENTS ); return SUCCESSFUL_RETURN; }
v8Function TS_OpenFile(V8ARGS){ if(args.Length()<1){ THROWERROR("[scriptfs] TS_OpenFile Error: Called with no arguments."); } CHECK_ARG_STR(0); BEGIN_OBJECT_WRAP_CODE v8::String::Utf8Value str(args[0]); const char *filename = *str; T5_file *file = T5_OpenFile(filename); if(file==NULL){ T5_close(file); FILE *newfile; newfile = fopen(filename, "w"); if(newfile==NULL){ THROWERROR((((string)"[scriptfs] TS_OpenFile Error: Could not create file ")+string(filename)+((string)".")).c_str()); } fclose(newfile); T5_file *file = T5_OpenFile(filename); } END_OBJECT_WRAP_CODE(ScriptFile, file); }
/* * s w a p I n d e x */ returnValue SubjectTo::swapIndex( Indexlist* const indexlist, int_t number1, int_t number2 ) { /* consistency checks */ if ( status != 0 ) { if ( status[number1] != status[number2] ) return THROWERROR( RET_SWAPINDEX_FAILED ); } else return THROWERROR( RET_SWAPINDEX_FAILED ); if ( number1 == number2 ) { THROWWARNING( RET_NOTHING_TO_DO ); return SUCCESSFUL_RETURN; } if ( indexlist != 0 ) { if ( indexlist->swapNumbers( number1,number2 ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SWAPINDEX_FAILED ); } else return THROWERROR( RET_INVALID_ARGUMENTS ); return SUCCESSFUL_RETURN; }
BEGIN_NAMESPACE_QPOASES /* * r e a d O q p D i m e n s i o n s */ returnValue readOqpDimensions( const char* path, int_t& nQP, int_t& nV, int_t& nC, int_t& nEC ) { /* 1) Setup file name where dimensions are stored. */ char filename[MAX_STRING_LENGTH]; snprintf( filename,MAX_STRING_LENGTH,"%sdims.oqp",path ); /* 2) Load dimensions from file. */ int_t dims[4]; if ( readFromFile( dims,4,filename ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_UNABLE_TO_READ_FILE ); nQP = dims[0]; nV = dims[1]; nC = dims[2]; nEC = dims[3]; /* consistency check */ if ( ( nQP <= 0 ) || ( nV <= 0 ) || ( nC < 0 ) || ( nEC < 0 ) ) return THROWERROR( RET_FILEDATA_INCONSISTENT ); return SUCCESSFUL_RETURN; }
/* * m o v e F i x e d T o F r e e */ returnValue Bounds::moveFixedToFree( int number ) { /* consistency check */ if ( ( number < 0 ) || ( number >= n ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Move index from indexlist of fixed variables to that of free ones. */ if ( this->removeIndex( this->getFixed( ),number ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); if ( this->addIndex( this->getFree( ),number,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); return SUCCESSFUL_RETURN; }
/* * m o v e A c t i v e T o I n a c t i v e */ returnValue Constraints::moveActiveToInactive( int _number ) { /* consistency check */ if ( ( _number < 0 ) || ( _number >= getNC( ) ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Move index from indexlist of active constraints to that of inactive ones. */ if ( this->removeIndex( this->getActive( ),_number ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); if ( this->addIndex( this->getInactive( ),_number,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); return SUCCESSFUL_RETURN; }
/* * m o v e I n a c t i v e T o A c t i v e */ returnValue Constraints::moveInactiveToActive( int_t number, SubjectToStatus _status ) { /* consistency check */ if ( ( number < 0 ) || ( number >= n ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Move index from indexlist of inactive constraints to that of active ones. */ if ( this->removeIndex( this->getInactive( ),number ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); if ( this->addIndex( this->getActive( ),number,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_MOVING_BOUND_FAILED ); return SUCCESSFUL_RETURN; }
/* * m y P r i n t f */ returnValue myPrintf( const char* s ) { #ifndef __SUPPRESSANYOUTPUT__ if ( s == 0 ) return RET_INVALID_ARGUMENTS; #ifdef __MATLAB__ mexPrintf( s ); #else #ifdef __SCILAB__ sciprint( s ); #else FILE* outputfile = getGlobalMessageHandler( )->getOutputFile( ); if ( outputfile == 0 ) return THROWERROR( RET_NO_GLOBAL_MESSAGE_OUTPUTFILE ); fprintf( outputfile, "%s", s ); #endif /* __SCILAB__ */ #endif /* __MATLAB__ */ #endif /* __SUPPRESSANYOUTPUT__ */ return SUCCESSFUL_RETURN; }
/* * f l i p F i x e d */ returnValue Bounds::flipFixed( int number ) { /* consistency check */ if ( ( number < 0 ) || ( number >= n ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); if ( status != 0 ) switch (status[number]) { case ST_LOWER: status[number] = ST_UPPER; break; case ST_UPPER: status[number] = ST_LOWER; break; default: return THROWERROR( RET_MOVING_BOUND_FAILED ); } return SUCCESSFUL_RETURN; }
/* * s e t u p N e w A u x i l i a r y Q P */ returnValue SQProblem::setupNewAuxiliaryQP( const real_t* const H_new, const real_t* const A_new, const real_t *lb_new, const real_t *ub_new, const real_t *lbA_new, const real_t *ubA_new ) { int_t nV = getNV( ); int_t nC = getNC( ); DenseMatrix *dA = 0; SymDenseMat *sH = 0; if ( A_new != 0 ) { dA = new DenseMatrix(nC, nV, nV, (real_t*) A_new); } else { if ( nC > 0 ) return THROWERROR( RET_INVALID_ARGUMENTS ); } if ( H_new != 0 ) sH = new SymDenseMat(nV, nV, nV, (real_t*) H_new); returnValue returnvalue = setupNewAuxiliaryQP( sH,dA, lb_new,ub_new,lbA_new,ubA_new ); if ( H_new != 0 ) freeHessian = BT_TRUE; freeConstraintMatrix = BT_TRUE; return returnvalue; }
/* * i n i t */ returnValue Flipper::init( int _nV, int _nC ) { if ( ( _nV < 0 ) || ( _nC < 0 ) ) return THROWERROR( RET_INVALID_ARGUMENTS ); clear( ); nV = _nV; nC = _nC; /*if ( nV > 0 ) { R = new real_t[nV*nV]; if ( nC > 0 ) { Q = new real_t[nV*nV]; T = new real_t[getDimT()]; } }*/ return SUCCESSFUL_RETURN; }
/* * i n i t */ returnValue SubjectTo::init( int_t _n ) { int_t i; if ( _n < 0 ) return THROWERROR( RET_INVALID_ARGUMENTS ); clear( ); n = _n; noLower = BT_TRUE; noUpper = BT_TRUE; if ( n > 0 ) { type = new SubjectToType[n]; status = new SubjectToStatus[n]; for( i=0; i<n; ++i ) { type[i] = ST_UNKNOWN; status[i] = ST_UNDEFINED; } } return SUCCESSFUL_RETURN; }
/* * s e t u p A l l I n a c t i v e */ returnValue Constraints::setupAllInactive( ) { int i; /* 1) Place unbounded constraints at the beginning of the index list of inactive constraints. */ for( i=0; i<nC; ++i ) { if ( getType( i ) == ST_UNBOUNDED ) { if ( setupConstraint( i,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); } } /* 2) Add remaining (i.e. "real" inequality) constraints to the index list of inactive constraints. */ for( i=0; i<nC; ++i ) { if ( getType( i ) == ST_BOUNDED ) { if ( setupConstraint( i,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); } } /* 3) Place implicit equality constraints at the end of the index list of inactive constraints. */ for( i=0; i<nC; ++i ) { if ( getType( i ) == ST_EQUALITY ) { if ( setupConstraint( i,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); } } /* 4) Moreover, add all constraints of unknown type. */ for( i=0; i<nC; ++i ) { if ( getType( i ) == ST_UNKNOWN ) { if ( setupConstraint( i,ST_INACTIVE ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_CONSTRAINT_FAILED ); } } return SUCCESSFUL_RETURN; }
/* * s e t u p A l l */ returnValue Bounds::setupAll( SubjectToStatus _status ) { int i; /* 1) Place unbounded variables at the beginning of the index list of free variables. */ for( i=0; i<n; ++i ) { if ( getType( i ) == ST_UNBOUNDED ) { if ( setupBound( i,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); } } /* 2) Add remaining (i.e. bounded but possibly free) variables to the index list of free variables. */ for( i=0; i<n; ++i ) { if ( getType( i ) == ST_BOUNDED ) { if ( setupBound( i,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); } } /* 3) Place implicitly fixed variables at the end of the index list of free variables. */ for( i=0; i<n; ++i ) { if ( getType( i ) == ST_EQUALITY ) { if ( setupBound( i,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); } } /* 4) Moreover, add all bounds of unknown type. */ for( i=0; i<n; ++i ) { if ( getType( i ) == ST_UNKNOWN || getType( i ) == ST_DISABLED ) { if ( setupBound( i,_status ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_BOUND_FAILED ); } } return SUCCESSFUL_RETURN; }
/* * h o t s t a r t */ returnValue SQProblem::hotstart( SymmetricMatrix *H_new, const real_t* const g_new, Matrix *A_new, const real_t* const lb_new, const real_t* const ub_new, const real_t* const lbA_new, const real_t* const ubA_new, int_t& nWSR, real_t* const cputime, const Bounds* const guessedBounds, const Constraints* const guessedConstraints ) { if ( ( getStatus( ) == QPS_NOTINITIALISED ) || ( getStatus( ) == QPS_PREPARINGAUXILIARYQP ) || ( getStatus( ) == QPS_PERFORMINGHOMOTOPY ) ) { return THROWERROR( RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED ); } real_t starttime = 0.0; real_t auxTime = 0.0; if ( cputime != 0 ) starttime = getCPUtime( ); /* I) UPDATE QP MATRICES AND VECTORS */ if ( setupNewAuxiliaryQP( H_new,A_new,lb_new,ub_new,lbA_new,ubA_new ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_AUXILIARYQP_FAILED ); /* II) PERFORM USUAL HOMOTOPY */ /* Allow only remaining CPU time for usual hotstart. */ if ( cputime != 0 ) { auxTime = getCPUtime( ) - starttime; *cputime -= auxTime; } returnValue returnvalue = QProblem::hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime, guessedBounds,guessedConstraints ); if ( cputime != 0 ) *cputime += auxTime; return returnvalue; }
/* * g e t N u m b e r A r r a y */ returnValue Indexlist::getNumberArray( int** const numberarray ) const { if (numberarray == 0) return THROWERROR( RET_INVALID_ARGUMENTS ); *numberarray = number; return SUCCESSFUL_RETURN; }
/* * r e m o v e I n d e x */ returnValue SubjectTo::removeIndex( Indexlist* const indexlist, int_t removenumber ) { if ( status != 0 ) status[removenumber] = ST_UNDEFINED; else return THROWERROR( RET_REMOVEINDEX_FAILED ); if ( indexlist != 0 ) { if ( indexlist->removeNumber( removenumber ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_REMOVEINDEX_FAILED ); } else return THROWERROR( RET_INVALID_ARGUMENTS ); return SUCCESSFUL_RETURN; }
/* * s w a p F r e e */ returnValue Bounds::swapFree( int number1, int number2 ) { /* consistency check */ if ( ( number1 < 0 ) || ( number1 >= n ) || ( number2 < 0 ) || ( number2 >= n ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); /* Swap index within indexlist of free variables. */ return this->swapIndex( this->getFree( ),number1,number2 ); }
v8Function TS_RemoveFile(V8ARGS){ if(args.Length()<1){ THROWERROR("[scriptfs] TS_RemoveFile Error: Called with no arguments."); } CHECK_ARG_STR(0); v8::String::Utf8Value str(args[0]); string filename = (*str); if(remove((string(GetDirs()->save)+filename).c_str()) != 0 ){ THROWERROR_REFERENCE((string("TS_RemoveFile Error: No such file as ")+(string(GetDirs()->save)+filename)).c_str()); } return v8::Undefined(); }
/* * h o t s t a r t */ returnValue SQProblem::hotstart( const real_t* const H_new, const real_t* const g_new, const real_t* const A_new, const real_t* const lb_new, const real_t* const ub_new, const real_t* const lbA_new, const real_t* const ubA_new, int& nWSR, real_t* const cputime ) { if ( ( getStatus( ) == QPS_NOTINITIALISED ) || ( getStatus( ) == QPS_PREPARINGAUXILIARYQP ) || ( getStatus( ) == QPS_PERFORMINGHOMOTOPY ) ) { return THROWERROR( RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED ); } /* start runtime measurement */ real_t starttime = 0.0; if ( cputime != 0 ) starttime = getCPUtime( ); /* I) UPDATE QP MATRICES AND VECTORS */ if ( setupAuxiliaryQP( H_new,A_new,lb_new,ub_new,lbA_new,ubA_new ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SETUP_AUXILIARYQP_FAILED ); /* II) PERFORM USUAL HOMOTOPY */ /* Allow only remaining CPU time for usual hotstart. */ if ( cputime != 0 ) *cputime -= getCPUtime( ) - starttime; returnValue returnvalue = QProblem::hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, nWSR,cputime ); /* stop runtime measurement */ if ( cputime != 0 ) *cputime = getCPUtime( ) - starttime; return returnvalue; }
/* * m y P r i n t f */ returnValue myPrintf( const char* s ) { #ifdef __MATLAB__ mexPrintf( s ); #else FILE* outputfile = getGlobalMessageHandler( )->getOutputFile( ); if ( outputfile == 0 ) return THROWERROR( RET_NO_GLOBAL_MESSAGE_OUTPUTFILE ); fprintf( outputfile, "%s", s ); #endif return SUCCESSFUL_RETURN; }
/* * s w a p N u m b e r s */ returnValue Indexlist::swapNumbers( int number1, int number2 ) { int index1 = getPhysicalIndex( number1 ); int index2 = getPhysicalIndex( number2 ); /* consistency check */ if ( ( index1 < 0 ) || ( index2 < 0 ) ) return THROWERROR( RET_INDEXLIST_CORRUPTED ); int tmp = number[index1]; number[index1] = number[index2]; number[index2] = tmp; return SUCCESSFUL_RETURN; }
/* * a d d N u m b e r */ returnValue Indexlist::addNumber( int addnumber ) { if ( length >= physicallength ) return THROWERROR( RET_INDEXLIST_EXCEEDS_MAX_LENGTH ); int i, j; number[length] = addnumber; j = findInsert(addnumber); for (i = length; i > j+1; i--) iSort[i] = iSort[i-1]; iSort[j+1] = length; ++length; return SUCCESSFUL_RETURN; }
/* * s e t m i n u s */ returnValue Indexlist::setminus( const Indexlist* const IS ) { /* if this functionality is used more often, one should think about a * different implementation to avoid the O(n^2) complexity... */ int i; int n = IS->getLength( ); for ( i=0; i<n; ++i ) { if ( this->removeNumber( IS->getNumber( i ) ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_INDEXLIST_ADD_FAILED ); } return SUCCESSFUL_RETURN; }
v8Function TS_fileWrite(V8ARGS) { if(args.Length()<2){ THROWERROR("[scriptfs] TS_fileWrite Error: Called with fewer than 2 arguments!\n"); } CHECK_ARG_STR(0); CHECK_ARG_STR(1); v8::String::AsciiValue key(args[0]); v8::String::AsciiValue val(args[1]); v8::Local<v8::Object> self = args.Holder(); v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(self->GetInternalField(0)); void* ptr = wrap->Value(); static_cast<T5_file*>(ptr)->writeValue(*key, *val); return v8::Undefined(); }
BEGIN_NAMESPACE_QPOASES /* * r e a d O Q P d i m e n s i o n s */ returnValue readOQPdimensions( const char* path, int* nQP, int* nV, int* nC, int* nEC ) { int dims[4]; /* 1) Setup file name where dimensions are stored. */ char filename[QPOASES_MAX_STRING_LENGTH]; snprintf( filename,QPOASES_MAX_STRING_LENGTH,"%sdims.oqp",path ); /* 2) Load dimensions from file. */ if ( qpOASES_readFromFileI( dims,4,filename ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_UNABLE_TO_READ_FILE ); *nQP = dims[0]; *nV = dims[1]; *nC = dims[2]; *nEC = dims[3]; /* printf( "nQP = %d, nV = %d, nC = %d, nEC = %d\n",*nQP,*nV,*nC,*nEC ); */ /* consistency check */ if ( ( *nQP <= 0 ) || ( *nV <= 0 ) || ( *nC < 0 ) || ( *nEC < 0 ) ) return THROWERROR( RET_FILEDATA_INCONSISTENT ); if ( ( *nV > NVMAX ) || ( *nC > NCMAX ) || ( *nQP > NQPMAX ) ) return THROWERROR( RET_UNABLE_TO_READ_BENCHMARK ); return SUCCESSFUL_RETURN; }
/* * s h i f t */ returnValue Bounds::shift( int offset ) { int i; /* consistency check */ if ( ( offset == 0 ) || ( n <= 1 ) ) return SUCCESSFUL_RETURN; if ( ( offset < 0 ) || ( offset > n/2 ) ) return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); if ( ( n % offset ) != 0 ) return THROWERROR( RET_INVALID_ARGUMENTS ); /* 1) Shift types and status. */ for( i=0; i<n-offset; ++i ) { setType( i,getType( i+offset ) ); setStatus( i,getStatus( i+offset ) ); } /* 2) Construct shifted index lists of free and fixed variables. */ Indexlist shiftedFreee( n ); Indexlist shiftedFixed( n ); for( i=0; i<n; ++i ) { switch ( getStatus( i ) ) { case ST_INACTIVE: if ( shiftedFreee.addNumber( i ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SHIFTING_FAILED ); break; case ST_LOWER: if ( shiftedFixed.addNumber( i ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SHIFTING_FAILED ); break; case ST_UPPER: if ( shiftedFixed.addNumber( i ) != SUCCESSFUL_RETURN ) return THROWERROR( RET_SHIFTING_FAILED ); break; default: return THROWERROR( RET_SHIFTING_FAILED ); } } /* 3) Assign shifted index list. */ freee = shiftedFreee; fixed = shiftedFixed; return SUCCESSFUL_RETURN; }