00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036 #include <MessageHandling.hpp>
00037 #include <Utils.hpp>
00038
00039
00040
00041
00043 MessageHandling::ReturnValueList returnValueList[] =
00044 {
00045
00046 { SUCCESSFUL_RETURN, "Successful return", VS_VISIBLE },
00047 { RET_DIV_BY_ZERO, "Division by zero", VS_VISIBLE },
00048 { RET_INDEX_OUT_OF_BOUNDS, "Index out of bounds", VS_VISIBLE },
00049 { RET_INVALID_ARGUMENTS, "At least one of the arguments is invalid", VS_VISIBLE },
00050 { RET_ERROR_UNDEFINED, "Error number undefined", VS_VISIBLE },
00051 { RET_WARNING_UNDEFINED, "Warning number undefined", VS_VISIBLE },
00052 { RET_INFO_UNDEFINED, "Info number undefined", VS_VISIBLE },
00053 { RET_EWI_UNDEFINED, "Error/warning/info number undefined", VS_VISIBLE },
00054 { RET_AVAILABLE_WITH_LINUX_ONLY, "This function is available under Linux only", VS_HIDDEN },
00055 { RET_UNKNOWN_BUG, "The error occured is not yet known", VS_VISIBLE },
00056 { RET_PRINTLEVEL_CHANGED, "Print level changed", VS_VISIBLE },
00057 { RET_NOT_YET_IMPLEMENTED, "Requested function is not yet implemented.", VS_VISIBLE },
00058
00059 { RET_INDEXLIST_MUST_BE_REORDERD, "Index list has to be reordered", VS_VISIBLE },
00060 { RET_INDEXLIST_EXCEEDS_MAX_LENGTH, "Index list exceeds its maximal physical length", VS_VISIBLE },
00061 { RET_INDEXLIST_CORRUPTED, "Index list corrupted", VS_VISIBLE },
00062 { RET_INDEXLIST_OUTOFBOUNDS, "Physical index is out of bounds", VS_VISIBLE },
00063 { RET_INDEXLIST_ADD_FAILED, "Adding indices from another index set failed", VS_VISIBLE },
00064 { RET_INDEXLIST_INTERSECT_FAILED, "Intersection with another index set failed", VS_VISIBLE },
00065
00066 { RET_INDEX_ALREADY_OF_DESIRED_STATUS, "Index is already of desired status", VS_VISIBLE },
00067 { RET_SWAPINDEX_FAILED, "Cannot swap between different indexsets", VS_VISIBLE },
00068 { RET_ADDINDEX_FAILED, "Adding index to index set failed", VS_VISIBLE },
00069 { RET_NOTHING_TO_DO, "Nothing to do", VS_VISIBLE },
00070 { RET_SETUP_BOUND_FAILED, "Setting up bound index failed", VS_VISIBLE },
00071 { RET_SETUP_CONSTRAINT_FAILED, "Setting up constraint index failed", VS_VISIBLE },
00072 { RET_MOVING_BOUND_FAILED, "Moving bound between index sets failed", VS_VISIBLE },
00073 { RET_MOVING_CONSTRAINT_FAILED, "Moving constraint between index sets failed", VS_VISIBLE },
00074
00075 { RET_QP_ALREADY_INITIALISED, "QProblem has already been initialised", VS_VISIBLE },
00076 { RET_NO_INIT_WITH_STANDARD_SOLVER, "Initialisation via extern QP solver is not yet implemented", VS_VISIBLE },
00077 { RET_RESET_FAILED, "Reset failed", VS_VISIBLE },
00078 { RET_INIT_FAILED, "Initialisation failed", VS_VISIBLE },
00079 { RET_INIT_FAILED_TQ, "Initialisation failed due to TQ factorisation", VS_VISIBLE },
00080 { RET_INIT_FAILED_CHOLESKY, "Initialisation failed due to Cholesky decomposition", VS_VISIBLE },
00081 { RET_INIT_FAILED_HOTSTART, "Initialisation failed! QP could not be solved!", VS_VISIBLE },
00082 { RET_INIT_FAILED_INFEASIBILITY, "Initial QP could not be solved due to infeasibility!", VS_VISIBLE },
00083 { RET_INIT_FAILED_UNBOUNDEDNESS, "Initial QP could not be solved due to unboundedness!", VS_VISIBLE },
00084 { RET_INIT_SUCCESSFUL, "Initialisation done", VS_VISIBLE },
00085 { RET_OBTAINING_WORKINGSET_FAILED, "Failed to obtain working set for auxiliary QP", VS_VISIBLE },
00086 { RET_SETUP_WORKINGSET_FAILED, "Failed to setup working set for auxiliary QP", VS_VISIBLE },
00087 { RET_SETUP_AUXILIARYQP_FAILED, "Failed to setup auxiliary QP for initialised homotopy", VS_VISIBLE },
00088 { RET_NO_EXTERN_SOLVER, "No extern QP solver available", VS_VISIBLE },
00089 { RET_QP_UNBOUNDED, "QP is unbounded", VS_VISIBLE },
00090 { RET_QP_INFEASIBLE, "QP is infeasible", VS_VISIBLE },
00091 { RET_QP_NOT_SOLVED, "Problems occured while solving QP with standard solver", VS_VISIBLE },
00092 { RET_QP_SOLVED, "QP successfully solved", VS_VISIBLE },
00093 { RET_UNABLE_TO_SOLVE_QP, "Problems occured while solving QP", VS_VISIBLE },
00094 { RET_INITIALISATION_STARTED, "Starting problem initialisation...", VS_VISIBLE },
00095 { RET_HOTSTART_FAILED, "Unable to perform homotopy due to internal error", VS_VISIBLE },
00096 { RET_HOTSTART_FAILED_TO_INIT, "Unable to initialise problem", VS_VISIBLE },
00097 { RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED, "Unable to perform homotopy as previous QP is not solved", VS_VISIBLE },
00098 { RET_ITERATION_STARTED, "Iteration", VS_VISIBLE },
00099 { RET_SHIFT_DETERMINATION_FAILED, "Determination of shift of the QP data failed", VS_VISIBLE },
00100 { RET_STEPDIRECTION_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
00101 { RET_STEPLENGTH_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
00102 { RET_OPTIMAL_SOLUTION_FOUND, "Optimal solution of neighbouring QP found", VS_VISIBLE },
00103 { RET_HOMOTOPY_STEP_FAILED, "Unable to perform homotopy step", VS_VISIBLE },
00104 { RET_HOTSTART_STOPPED_INFEASIBILITY, "Premature homotopy termination because QP is infeasible", VS_VISIBLE },
00105 { RET_HOTSTART_STOPPED_UNBOUNDEDNESS, "Premature homotopy termination because QP is unbounded", VS_VISIBLE },
00106 { RET_WORKINGSET_UPDATE_FAILED, "Unable to update working sets according to initial guesses", VS_VISIBLE },
00107 { RET_MAX_NWSR_REACHED, "Maximum number of working set recalculations performed", VS_VISIBLE },
00108 { RET_CONSTRAINTS_NOT_SPECIFIED, "Problem does comprise constraints! You have to specify new constraints' bounds", VS_VISIBLE },
00109 { RET_INVALID_FACTORISATION_FLAG, "Invalid factorisation flag", VS_VISIBLE },
00110 { RET_UNABLE_TO_SAVE_QPDATA, "Unable to save QP data", VS_VISIBLE },
00111 { RET_STEPDIRECTION_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
00112 { RET_STEPDIRECTION_FAILED_CHOLESKY, "Abnormal termination due to Cholesky factorisation", VS_VISIBLE },
00113 { RET_CYCLING_DETECTED, "Cycling detected", VS_VISIBLE },
00114 { RET_CYCLING_NOT_RESOLVED, "Cycling cannot be resolved, QP is probably infeasible", VS_VISIBLE },
00115 { RET_CYCLING_RESOLVED, "Cycling probably resolved", VS_VISIBLE },
00116 { RET_STEPSIZE, "", VS_VISIBLE },
00117 { RET_STEPSIZE_NONPOSITIVE, "", VS_VISIBLE },
00118 { RET_SETUPSUBJECTTOTYPE_FAILED, "Setup of SubjectToTypes failed", VS_VISIBLE },
00119 { RET_ADDCONSTRAINT_FAILED, "Addition of constraint to working set failed", VS_VISIBLE },
00120 { RET_ADDCONSTRAINT_FAILED_INFEASIBILITY, "Addition of constraint to working set failed", VS_VISIBLE },
00121 { RET_ADDBOUND_FAILED, "Addition of bound to working set failed", VS_VISIBLE },
00122 { RET_ADDBOUND_FAILED_INFEASIBILITY, "Addition of bound to working set failed", VS_VISIBLE },
00123 { RET_REMOVECONSTRAINT_FAILED, "Removal of constraint from working set failed", VS_VISIBLE },
00124 { RET_REMOVEBOUND_FAILED, "Removal of bound from working set failed", VS_VISIBLE },
00125 { RET_REMOVE_FROM_ACTIVESET, "Removing from active set:", VS_VISIBLE },
00126 { RET_ADD_TO_ACTIVESET, "Adding to active set:", VS_VISIBLE },
00127 { RET_REMOVE_FROM_ACTIVESET_FAILED, "Removing from active set failed", VS_VISIBLE },
00128 { RET_ADD_TO_ACTIVESET_FAILED, "Adding to active set failed", VS_VISIBLE },
00129 { RET_CONSTRAINT_ALREADY_ACTIVE, "Constraint is already active", VS_VISIBLE },
00130 { RET_ALL_CONSTRAINTS_ACTIVE, "All constraints are active, no further constraint can be added", VS_VISIBLE },
00131 { RET_LINEARLY_DEPENDENT, "New bound/constraint is linearly dependent", VS_VISIBLE },
00132 { RET_LINEARLY_INDEPENDENT, "New bound/constraint is linearly independent", VS_VISIBLE },
00133 { RET_LI_RESOLVED, "Linear independence of active contraint matrix successfully resolved", VS_VISIBLE },
00134 { RET_ENSURELI_FAILED, "Failed to ensure linear indepence of active contraint matrix", VS_VISIBLE },
00135 { RET_ENSURELI_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
00136 { RET_ENSURELI_FAILED_NOINDEX, "No index found, QP is probably infeasible", VS_VISIBLE },
00137 { RET_ENSURELI_FAILED_CYCLING, "Cycling detected, QP is probably infeasible", VS_VISIBLE },
00138 { RET_BOUND_ALREADY_ACTIVE, "Bound is already active", VS_VISIBLE },
00139 { RET_ALL_BOUNDS_ACTIVE, "All bounds are active, no further bound can be added", VS_VISIBLE },
00140 { RET_CONSTRAINT_NOT_ACTIVE, "Constraint is not active", VS_VISIBLE },
00141 { RET_BOUND_NOT_ACTIVE, "Bound is not active", VS_VISIBLE },
00142 { RET_HESSIAN_NOT_SPD, "Projected Hessian matrix not positive definite", VS_VISIBLE },
00143 { RET_MATRIX_SHIFT_FAILED, "Unable to update matrices or to transform vectors", VS_VISIBLE },
00144 { RET_MATRIX_FACTORISATION_FAILED, "Unable to calculate new matrix factorisations", VS_VISIBLE },
00145 { RET_PRINT_ITERATION_FAILED, "Unable to print information on current iteration", VS_VISIBLE },
00146 { RET_NO_GLOBAL_MESSAGE_OUTPUTFILE, "No global message output file initialised", VS_VISIBLE },
00147
00148 { RET_UNABLE_TO_OPEN_FILE, "Unable to open file", VS_VISIBLE },
00149 { RET_UNABLE_TO_WRITE_FILE, "Unable to write into file", VS_VISIBLE },
00150 { RET_UNABLE_TO_READ_FILE, "Unable to read from file", VS_VISIBLE },
00151 { RET_FILEDATA_INCONSISTENT, "File contains inconsistent data", VS_VISIBLE },
00152
00153 { RET_NO_SOLUTION, "QP solution does not satisfy KKT optimality conditions", VS_VISIBLE },
00154 { RET_INACCURATE_SOLUTION, "KKT optimality conditions not satisfied to sufficient accuracy", VS_VISIBLE },
00155 { TERMINAL_LIST_ELEMENT, "", VS_HIDDEN }
00156 };
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 MessageHandling::MessageHandling( ) : errorVisibility( VS_VISIBLE ),
00169 warningVisibility( VS_VISIBLE ),
00170 infoVisibility( VS_VISIBLE ),
00171 outputFile( myStdout ),
00172 errorCount( 0 )
00173 {
00174 }
00175
00176
00177
00178
00179 MessageHandling::MessageHandling( myFILE* _outputFile ) :
00180 errorVisibility( VS_VISIBLE ),
00181 warningVisibility( VS_VISIBLE ),
00182 infoVisibility( VS_VISIBLE ),
00183 outputFile( _outputFile ),
00184 errorCount( 0 )
00185 {
00186 }
00187
00188
00189
00190
00191 MessageHandling::MessageHandling( VisibilityStatus _errorVisibility,
00192 VisibilityStatus _warningVisibility,
00193 VisibilityStatus _infoVisibility
00194 ) :
00195 errorVisibility( _errorVisibility ),
00196 warningVisibility( _warningVisibility ),
00197 infoVisibility( _infoVisibility ),
00198 outputFile( myStderr ),
00199 errorCount( 0 )
00200 {
00201 }
00202
00203
00204
00205
00206 MessageHandling::MessageHandling( myFILE* _outputFile,
00207 VisibilityStatus _errorVisibility,
00208 VisibilityStatus _warningVisibility,
00209 VisibilityStatus _infoVisibility
00210 ) :
00211 errorVisibility( _errorVisibility ),
00212 warningVisibility( _warningVisibility ),
00213 infoVisibility( _infoVisibility ),
00214 outputFile( _outputFile ),
00215 errorCount( 0 )
00216 {
00217 }
00218
00219
00220
00221
00222
00223
00224 MessageHandling::MessageHandling( const MessageHandling& rhs ) :
00225 errorVisibility( rhs.errorVisibility ),
00226 warningVisibility( rhs.warningVisibility ),
00227 infoVisibility( rhs.infoVisibility ),
00228 outputFile( rhs.outputFile ),
00229 errorCount( rhs.errorCount )
00230 {
00231 }
00232
00233
00234
00235
00236
00237 MessageHandling::~MessageHandling( )
00238 {
00239 #ifdef PC_DEBUG
00240 if ( outputFile != 0 )
00241 fclose( outputFile );
00242 #endif
00243 }
00244
00245
00246
00247
00248
00249 MessageHandling& MessageHandling::operator=( const MessageHandling& rhs )
00250 {
00251 if ( this != &rhs )
00252 {
00253 errorVisibility = rhs.errorVisibility;
00254 warningVisibility = rhs.warningVisibility;
00255 infoVisibility = rhs.infoVisibility;
00256 outputFile = rhs.outputFile;
00257 errorCount = rhs.errorCount;
00258 }
00259
00260 return *this;
00261 }
00262
00263
00264
00265
00266
00267 returnValue MessageHandling::throwError(
00268 returnValue Enumber,
00269 const char* additionaltext,
00270 const char* functionname,
00271 const char* filename,
00272 const unsigned long linenumber,
00273 VisibilityStatus localVisibilityStatus
00274 )
00275 {
00276
00277 if ( Enumber <= SUCCESSFUL_RETURN )
00278 return throwError( RET_ERROR_UNDEFINED,0,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE );
00279
00280
00281 if ( errorVisibility == VS_VISIBLE )
00282 return throwMessage( Enumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"ERROR" );
00283 else
00284 return Enumber;
00285 }
00286
00287
00288
00289
00290
00291 returnValue MessageHandling::throwWarning(
00292 returnValue Wnumber,
00293 const char* additionaltext,
00294 const char* functionname,
00295 const char* filename,
00296 const unsigned long linenumber,
00297 VisibilityStatus localVisibilityStatus
00298 )
00299 {
00300
00301 if ( Wnumber <= SUCCESSFUL_RETURN )
00302 return throwError( RET_WARNING_UNDEFINED,0,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE );
00303
00304
00305 if ( warningVisibility == VS_VISIBLE )
00306 return throwMessage( Wnumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"WARNING" );
00307 else
00308 return Wnumber;
00309 }
00310
00311
00312
00313
00314
00315 returnValue MessageHandling::throwInfo(
00316 returnValue Inumber,
00317 const char* additionaltext,
00318 const char* functionname,
00319 const char* filename,
00320 const unsigned long linenumber,
00321 VisibilityStatus localVisibilityStatus
00322 )
00323 {
00324
00325 if ( Inumber < SUCCESSFUL_RETURN )
00326 return throwError( RET_INFO_UNDEFINED,0,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE );
00327
00328
00329 if ( infoVisibility == VS_VISIBLE )
00330 return throwMessage( Inumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"INFO" );
00331 else
00332 return Inumber;
00333 }
00334
00335
00336
00337
00338
00339 returnValue MessageHandling::reset( )
00340 {
00341 setErrorVisibilityStatus( VS_VISIBLE );
00342 setWarningVisibilityStatus( VS_VISIBLE );
00343 setInfoVisibilityStatus( VS_VISIBLE );
00344
00345 setOutputFile( myStderr );
00346 setErrorCount( 0 );
00347
00348 return SUCCESSFUL_RETURN;
00349 }
00350
00351
00352
00353
00354
00355 returnValue MessageHandling::listAllMessages( )
00356 {
00357 #ifdef PC_DEBUG
00358 int keypos = 0;
00359 char myPrintfString[160];
00360
00361
00362 while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
00363 {
00364 sprintf( myPrintfString," %d - %s \n",keypos,returnValueList[keypos].data );
00365 myPrintf( myPrintfString );
00366
00367 ++keypos;
00368 }
00369 #endif
00370
00371 return SUCCESSFUL_RETURN;
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381 #ifdef PC_DEBUG
00382
00383
00384
00385
00386 returnValue MessageHandling::throwMessage(
00387 returnValue RETnumber,
00388 const char* additionaltext,
00389 const char* functionname,
00390 const char* filename,
00391 const unsigned long linenumber,
00392 VisibilityStatus localVisibilityStatus,
00393 const char* RETstring
00394 )
00395 {
00396 int i;
00397
00398 int keypos = 0;
00399 char myPrintfString[160];
00400
00401
00402 char whitespaces[41];
00403 int numberOfWhitespaces = (errorCount-1)*2;
00404
00405 if ( numberOfWhitespaces < 0 )
00406 numberOfWhitespaces = 0;
00407
00408 if ( numberOfWhitespaces > 40 )
00409 numberOfWhitespaces = 40;
00410
00411 for( i=0; i<numberOfWhitespaces; ++i )
00412 whitespaces[i] = ' ';
00413 whitespaces[numberOfWhitespaces] = '\0';
00414
00415
00416 while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
00417 {
00418 if ( returnValueList[keypos].key == RETnumber )
00419 break;
00420 else
00421 ++keypos;
00422 }
00423
00424 if ( returnValueList[keypos].key == TERMINAL_LIST_ELEMENT )
00425 {
00426 throwError( RET_EWI_UNDEFINED,0,__FUNCTION__,__FILE__,__LINE__,VS_VISIBLE );
00427 return RETnumber;
00428 }
00429
00430
00431 if ( ( returnValueList[keypos].globalVisibilityStatus == VS_VISIBLE ) && ( localVisibilityStatus == VS_VISIBLE ) )
00432 {
00433 if ( errorCount > 0 )
00434 {
00435 sprintf( myPrintfString,"%s->", whitespaces );
00436 myPrintf( myPrintfString );
00437 }
00438
00439 if ( additionaltext == 0 )
00440 {
00441 sprintf( myPrintfString,"%s (%s, %s:%d): \t%s\n",
00442 RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data
00443 );
00444 myPrintf( myPrintfString );
00445 }
00446 else
00447 {
00448 sprintf( myPrintfString,"%s (%s, %s:%d): \t%s %s\n",
00449 RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data,additionaltext
00450 );
00451 myPrintf( myPrintfString );
00452 }
00453
00454
00455 if ( RETstring[0] == 'E' )
00456 {
00457 ++errorCount;
00458 }
00459 else
00460 {
00461 if ( errorCount > 0 )
00462 myPrintf( "\n" );
00463 errorCount = 0;
00464 }
00465 }
00466
00467 return RETnumber;
00468 }
00469
00470 #else
00471
00472
00473
00474
00475 returnValue MessageHandling::throwMessage(
00476 returnValue RETnumber,
00477 const char* additionaltext,
00478 const char* functionname,
00479 const char* filename,
00480 const unsigned long linenumber,
00481 VisibilityStatus localVisibilityStatus,
00482 const char* RETstring
00483 )
00484 {
00485
00486
00487 int i = 0;
00488 if ( additionaltext == 0 ) i++;
00489 if ( functionname == 0 ) i++;
00490 if ( filename == 0 ) i++;
00491 if ( linenumber == 0 ) i++;
00492 if ( localVisibilityStatus == VS_VISIBLE ) i++;
00493 if ( RETstring == 0 ) i++;
00494
00495
00496 return RETnumber;
00497 }
00498
00499 #endif
00500
00501
00502
00503
00504
00505
00506
00507
00509 MessageHandling globalMessageHandler( myStderr,VS_VISIBLE,VS_VISIBLE,VS_VISIBLE );
00510
00511
00512
00513
00514
00515 MessageHandling* getGlobalMessageHandler( )
00516 {
00517 return &globalMessageHandler;
00518 }
00519
00520 const char* MessageHandling::getErrorString(int error)
00521 {
00522 return returnValueList[ error ].data;
00523 }
00524
00525
00526
00527
00528
00529