external_packages/qpoases/SRC/MessageHandling.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2008 by Hans Joachim Ferreau et al. All rights reserved.
6  *
7  * qpOASES is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * qpOASES is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with qpOASES; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 
36 #include <MessageHandling.hpp>
37 #include <Utils.hpp>
38 
39 
40 
41 
44 {
45 /* miscellaneous */
46 { SUCCESSFUL_RETURN, "Successful return", VS_VISIBLE },
47 { RET_DIV_BY_ZERO, "Division by zero", VS_VISIBLE },
48 { RET_INDEX_OUT_OF_BOUNDS, "Index out of bounds", VS_VISIBLE },
49 { RET_INVALID_ARGUMENTS, "At least one of the arguments is invalid", VS_VISIBLE },
50 { RET_ERROR_UNDEFINED, "Error number undefined", VS_VISIBLE },
51 { RET_WARNING_UNDEFINED, "Warning number undefined", VS_VISIBLE },
52 { RET_INFO_UNDEFINED, "Info number undefined", VS_VISIBLE },
53 { RET_EWI_UNDEFINED, "Error/warning/info number undefined", VS_VISIBLE },
54 { RET_AVAILABLE_WITH_LINUX_ONLY, "This function is available under Linux only", VS_HIDDEN },
55 { RET_UNKNOWN_BUG, "The error occured is not yet known", VS_VISIBLE },
56 { RET_PRINTLEVEL_CHANGED, "Print level changed", VS_VISIBLE },
57 { RET_NOT_YET_IMPLEMENTED, "Requested function is not yet implemented.", VS_VISIBLE },
58 /* Indexlist */
59 { RET_INDEXLIST_MUST_BE_REORDERD, "Index list has to be reordered", VS_VISIBLE },
60 { RET_INDEXLIST_EXCEEDS_MAX_LENGTH, "Index list exceeds its maximal physical length", VS_VISIBLE },
61 { RET_INDEXLIST_CORRUPTED, "Index list corrupted", VS_VISIBLE },
62 { RET_INDEXLIST_OUTOFBOUNDS, "Physical index is out of bounds", VS_VISIBLE },
63 { RET_INDEXLIST_ADD_FAILED, "Adding indices from another index set failed", VS_VISIBLE },
64 { RET_INDEXLIST_INTERSECT_FAILED, "Intersection with another index set failed", VS_VISIBLE },
65 /* SubjectTo / Bounds / Constraints */
66 { RET_INDEX_ALREADY_OF_DESIRED_STATUS, "Index is already of desired status", VS_VISIBLE },
67 { RET_SWAPINDEX_FAILED, "Cannot swap between different indexsets", VS_VISIBLE },
68 { RET_ADDINDEX_FAILED, "Adding index to index set failed", VS_VISIBLE },
69 { RET_NOTHING_TO_DO, "Nothing to do", VS_VISIBLE },
70 { RET_SETUP_BOUND_FAILED, "Setting up bound index failed", VS_VISIBLE },
71 { RET_SETUP_CONSTRAINT_FAILED, "Setting up constraint index failed", VS_VISIBLE },
72 { RET_MOVING_BOUND_FAILED, "Moving bound between index sets failed", VS_VISIBLE },
73 { RET_MOVING_CONSTRAINT_FAILED, "Moving constraint between index sets failed", VS_VISIBLE },
74 /* QProblem */
75 { RET_QP_ALREADY_INITIALISED, "QProblem has already been initialised", VS_VISIBLE },
76 { RET_NO_INIT_WITH_STANDARD_SOLVER, "Initialisation via extern QP solver is not yet implemented", VS_VISIBLE },
77 { RET_RESET_FAILED, "Reset failed", VS_VISIBLE },
78 { RET_INIT_FAILED, "Initialisation failed", VS_VISIBLE },
79 { RET_INIT_FAILED_TQ, "Initialisation failed due to TQ factorisation", VS_VISIBLE },
80 { RET_INIT_FAILED_CHOLESKY, "Initialisation failed due to Cholesky decomposition", VS_VISIBLE },
81 { RET_INIT_FAILED_HOTSTART, "Initialisation failed! QP could not be solved!", VS_VISIBLE },
82 { RET_INIT_FAILED_INFEASIBILITY, "Initial QP could not be solved due to infeasibility!", VS_VISIBLE },
83 { RET_INIT_FAILED_UNBOUNDEDNESS, "Initial QP could not be solved due to unboundedness!", VS_VISIBLE },
84 { RET_INIT_SUCCESSFUL, "Initialisation done", VS_VISIBLE },
85 { RET_OBTAINING_WORKINGSET_FAILED, "Failed to obtain working set for auxiliary QP", VS_VISIBLE },
86 { RET_SETUP_WORKINGSET_FAILED, "Failed to setup working set for auxiliary QP", VS_VISIBLE },
87 { RET_SETUP_AUXILIARYQP_FAILED, "Failed to setup auxiliary QP for initialised homotopy", VS_VISIBLE },
88 { RET_NO_EXTERN_SOLVER, "No extern QP solver available", VS_VISIBLE },
89 { RET_QP_UNBOUNDED, "QP is unbounded", VS_VISIBLE },
90 { RET_QP_INFEASIBLE, "QP is infeasible", VS_VISIBLE },
91 { RET_QP_NOT_SOLVED, "Problems occured while solving QP with standard solver", VS_VISIBLE },
92 { RET_QP_SOLVED, "QP successfully solved", VS_VISIBLE },
93 { RET_UNABLE_TO_SOLVE_QP, "Problems occured while solving QP", VS_VISIBLE },
94 { RET_INITIALISATION_STARTED, "Starting problem initialisation...", VS_VISIBLE },
95 { RET_HOTSTART_FAILED, "Unable to perform homotopy due to internal error", VS_VISIBLE },
96 { RET_HOTSTART_FAILED_TO_INIT, "Unable to initialise problem", VS_VISIBLE },
97 { RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED, "Unable to perform homotopy as previous QP is not solved", VS_VISIBLE },
98 { RET_ITERATION_STARTED, "Iteration", VS_VISIBLE },
99 { RET_SHIFT_DETERMINATION_FAILED, "Determination of shift of the QP data failed", VS_VISIBLE },
100 { RET_STEPDIRECTION_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
101 { RET_STEPLENGTH_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
102 { RET_OPTIMAL_SOLUTION_FOUND, "Optimal solution of neighbouring QP found", VS_VISIBLE },
103 { RET_HOMOTOPY_STEP_FAILED, "Unable to perform homotopy step", VS_VISIBLE },
104 { RET_HOTSTART_STOPPED_INFEASIBILITY, "Premature homotopy termination because QP is infeasible", VS_VISIBLE },
105 { RET_HOTSTART_STOPPED_UNBOUNDEDNESS, "Premature homotopy termination because QP is unbounded", VS_VISIBLE },
106 { RET_WORKINGSET_UPDATE_FAILED, "Unable to update working sets according to initial guesses", VS_VISIBLE },
107 { RET_MAX_NWSR_REACHED, "Maximum number of working set recalculations performed", VS_VISIBLE },
108 { RET_CONSTRAINTS_NOT_SPECIFIED, "Problem does comprise constraints! You have to specify new constraints' bounds", VS_VISIBLE },
109 { RET_INVALID_FACTORISATION_FLAG, "Invalid factorisation flag", VS_VISIBLE },
110 { RET_UNABLE_TO_SAVE_QPDATA, "Unable to save QP data", VS_VISIBLE },
111 { RET_STEPDIRECTION_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
112 { RET_STEPDIRECTION_FAILED_CHOLESKY, "Abnormal termination due to Cholesky factorisation", VS_VISIBLE },
113 { RET_CYCLING_DETECTED, "Cycling detected", VS_VISIBLE },
114 { RET_CYCLING_NOT_RESOLVED, "Cycling cannot be resolved, QP is probably infeasible", VS_VISIBLE },
115 { RET_CYCLING_RESOLVED, "Cycling probably resolved", VS_VISIBLE },
116 { RET_STEPSIZE, "", VS_VISIBLE },
117 { RET_STEPSIZE_NONPOSITIVE, "", VS_VISIBLE },
118 { RET_SETUPSUBJECTTOTYPE_FAILED, "Setup of SubjectToTypes failed", VS_VISIBLE },
119 { RET_ADDCONSTRAINT_FAILED, "Addition of constraint to working set failed", VS_VISIBLE },
120 { RET_ADDCONSTRAINT_FAILED_INFEASIBILITY, "Addition of constraint to working set failed", VS_VISIBLE },
121 { RET_ADDBOUND_FAILED, "Addition of bound to working set failed", VS_VISIBLE },
122 { RET_ADDBOUND_FAILED_INFEASIBILITY, "Addition of bound to working set failed", VS_VISIBLE },
123 { RET_REMOVECONSTRAINT_FAILED, "Removal of constraint from working set failed", VS_VISIBLE },
124 { RET_REMOVEBOUND_FAILED, "Removal of bound from working set failed", VS_VISIBLE },
125 { RET_REMOVE_FROM_ACTIVESET, "Removing from active set:", VS_VISIBLE },
126 { RET_ADD_TO_ACTIVESET, "Adding to active set:", VS_VISIBLE },
127 { RET_REMOVE_FROM_ACTIVESET_FAILED, "Removing from active set failed", VS_VISIBLE },
128 { RET_ADD_TO_ACTIVESET_FAILED, "Adding to active set failed", VS_VISIBLE },
129 { RET_CONSTRAINT_ALREADY_ACTIVE, "Constraint is already active", VS_VISIBLE },
130 { RET_ALL_CONSTRAINTS_ACTIVE, "All constraints are active, no further constraint can be added", VS_VISIBLE },
131 { RET_LINEARLY_DEPENDENT, "New bound/constraint is linearly dependent", VS_VISIBLE },
132 { RET_LINEARLY_INDEPENDENT, "New bound/constraint is linearly independent", VS_VISIBLE },
133 { RET_LI_RESOLVED, "Linear independence of active contraint matrix successfully resolved", VS_VISIBLE },
134 { RET_ENSURELI_FAILED, "Failed to ensure linear indepence of active contraint matrix", VS_VISIBLE },
135 { RET_ENSURELI_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
136 { RET_ENSURELI_FAILED_NOINDEX, "No index found, QP is probably infeasible", VS_VISIBLE },
137 { RET_ENSURELI_FAILED_CYCLING, "Cycling detected, QP is probably infeasible", VS_VISIBLE },
138 { RET_BOUND_ALREADY_ACTIVE, "Bound is already active", VS_VISIBLE },
139 { RET_ALL_BOUNDS_ACTIVE, "All bounds are active, no further bound can be added", VS_VISIBLE },
140 { RET_CONSTRAINT_NOT_ACTIVE, "Constraint is not active", VS_VISIBLE },
141 { RET_BOUND_NOT_ACTIVE, "Bound is not active", VS_VISIBLE },
142 { RET_HESSIAN_NOT_SPD, "Projected Hessian matrix not positive definite", VS_VISIBLE },
143 { RET_MATRIX_SHIFT_FAILED, "Unable to update matrices or to transform vectors", VS_VISIBLE },
144 { RET_MATRIX_FACTORISATION_FAILED, "Unable to calculate new matrix factorisations", VS_VISIBLE },
145 { RET_PRINT_ITERATION_FAILED, "Unable to print information on current iteration", VS_VISIBLE },
146 { RET_NO_GLOBAL_MESSAGE_OUTPUTFILE, "No global message output file initialised", VS_VISIBLE },
147 /* Utils */
148 { RET_UNABLE_TO_OPEN_FILE, "Unable to open file", VS_VISIBLE },
149 { RET_UNABLE_TO_WRITE_FILE, "Unable to write into file", VS_VISIBLE },
150 { RET_UNABLE_TO_READ_FILE, "Unable to read from file", VS_VISIBLE },
151 { RET_FILEDATA_INCONSISTENT, "File contains inconsistent data", VS_VISIBLE },
152 /* SolutionAnalysis */
153 { RET_NO_SOLUTION, "QP solution does not satisfy KKT optimality conditions", VS_VISIBLE },
154 { RET_INACCURATE_SOLUTION, "KKT optimality conditions not satisfied to sufficient accuracy", VS_VISIBLE },
155 { TERMINAL_LIST_ELEMENT, "", VS_HIDDEN } /* IMPORTANT: Terminal list element! */
156 };
157 
158 
159 
160 /*****************************************************************************
161  * P U B L I C *
162  *****************************************************************************/
163 
164 
165 /*
166  * M e s s a g e H a n d l i n g
167  */
168 MessageHandling::MessageHandling( ) : errorVisibility( VS_VISIBLE ),
169  warningVisibility( VS_VISIBLE ),
170  infoVisibility( VS_VISIBLE ),
171  outputFile( myStdout ),
172  errorCount( 0 )
173 {
174 }
175 
176 /*
177  * M e s s a g e H a n d l i n g
178  */
180  errorVisibility( VS_VISIBLE ),
181  warningVisibility( VS_VISIBLE ),
182  infoVisibility( VS_VISIBLE ),
183  outputFile( _outputFile ),
184  errorCount( 0 )
185 {
186 }
187 
188 /*
189  * M e s s a g e H a n d l i n g
190  */
192  VisibilityStatus _warningVisibility,
193  VisibilityStatus _infoVisibility
194  ) :
195  errorVisibility( _errorVisibility ),
196  warningVisibility( _warningVisibility ),
197  infoVisibility( _infoVisibility ),
198  outputFile( myStderr ),
199  errorCount( 0 )
200 {
201 }
202 
203 /*
204  * M e s s a g e H a n d l i n g
205  */
207  VisibilityStatus _errorVisibility,
208  VisibilityStatus _warningVisibility,
209  VisibilityStatus _infoVisibility
210  ) :
211  errorVisibility( _errorVisibility ),
212  warningVisibility( _warningVisibility ),
213  infoVisibility( _infoVisibility ),
214  outputFile( _outputFile ),
215  errorCount( 0 )
216 {
217 }
218 
219 
220 
221 /*
222  * M e s s a g e H a n d l i n g
223  */
225  errorVisibility( rhs.errorVisibility ),
226  warningVisibility( rhs.warningVisibility ),
227  infoVisibility( rhs.infoVisibility ),
228  outputFile( rhs.outputFile ),
229  errorCount( rhs.errorCount )
230 {
231 }
232 
233 
234 /*
235  * ~ M e s s a g e H a n d l i n g
236  */
238 {
239  #ifdef PC_DEBUG
240  if ( outputFile != 0 )
241  fclose( outputFile );
242  #endif
243 }
244 
245 
246 /*
247  * o p e r a t o r =
248  */
250 {
251  if ( this != &rhs )
252  {
256  outputFile = rhs.outputFile;
257  errorCount = rhs.errorCount;
258  }
259 
260  return *this;
261 }
262 
263 
264 /*
265  * t h r o w E r r o r
266  */
268  returnValue Enumber,
269  const char* additionaltext,
270  const char* functionname,
271  const char* filename,
272  const unsigned long linenumber,
273  VisibilityStatus localVisibilityStatus
274  )
275 {
276  /* consistency check */
277  if ( Enumber <= SUCCESSFUL_RETURN )
279 
280  /* Call to common throwMessage function if error shall be displayed. */
281  if ( errorVisibility == VS_VISIBLE )
282  return throwMessage( Enumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"ERROR" );
283  else
284  return Enumber;
285 }
286 
287 
288 /*
289  * t h r o w W a r n i n g
290  */
292  returnValue Wnumber,
293  const char* additionaltext,
294  const char* functionname,
295  const char* filename,
296  const unsigned long linenumber,
297  VisibilityStatus localVisibilityStatus
298  )
299 {
300  /* consistency check */
301  if ( Wnumber <= SUCCESSFUL_RETURN )
303 
304  /* Call to common throwMessage function if warning shall be displayed. */
305  if ( warningVisibility == VS_VISIBLE )
306  return throwMessage( Wnumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"WARNING" );
307  else
308  return Wnumber;
309 }
310 
311 
312 /*
313  * t h r o w I n f o
314  */
316  returnValue Inumber,
317  const char* additionaltext,
318  const char* functionname,
319  const char* filename,
320  const unsigned long linenumber,
321  VisibilityStatus localVisibilityStatus
322  )
323 {
324  /* consistency check */
325  if ( Inumber < SUCCESSFUL_RETURN )
327 
328  /* Call to common throwMessage function if info shall be displayed. */
329  if ( infoVisibility == VS_VISIBLE )
330  return throwMessage( Inumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"INFO" );
331  else
332  return Inumber;
333 }
334 
335 
336 /*
337  * r e s e t
338  */
340 {
344 
346  setErrorCount( 0 );
347 
348  return SUCCESSFUL_RETURN;
349 }
350 
351 
352 /*
353  * l i s t A l l M e s s a g e s
354  */
356 {
357  #ifdef PC_DEBUG
358  int keypos = 0;
359  char myPrintfString[160];
360 
361  /* Run through whole returnValueList and print each item. */
362  while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
363  {
364  sprintf( myPrintfString," %d - %s \n",keypos,returnValueList[keypos].data );
365  myPrintf( myPrintfString );
366 
367  ++keypos;
368  }
369  #endif
370 
371  return SUCCESSFUL_RETURN;
372 }
373 
374 
375 
376 /*****************************************************************************
377  * P R O T E C T E D *
378  *****************************************************************************/
379 
380 
381 #ifdef PC_DEBUG /* Re-define throwMessage function for embedded code! */
382 
383 /*
384  * t h r o w M e s s a g e
385  */
387  returnValue RETnumber,
388  const char* additionaltext,
389  const char* functionname,
390  const char* filename,
391  const unsigned long linenumber,
392  VisibilityStatus localVisibilityStatus,
393  const char* RETstring
394  )
395 {
396  int i;
397 
398  int keypos = 0;
399  char myPrintfString[160];
400 
401  /* 1) Determine number of whitespace for output. */
402  char whitespaces[41];
403  int numberOfWhitespaces = (errorCount-1)*2;
404 
405  if ( numberOfWhitespaces < 0 )
406  numberOfWhitespaces = 0;
407 
408  if ( numberOfWhitespaces > 40 )
409  numberOfWhitespaces = 40;
410 
411  for( i=0; i<numberOfWhitespaces; ++i )
412  whitespaces[i] = ' ';
413  whitespaces[numberOfWhitespaces] = '\0';
414 
415  /* 2) Find error/warning/info in list. */
416  while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
417  {
418  if ( returnValueList[keypos].key == RETnumber )
419  break;
420  else
421  ++keypos;
422  }
423 
424  if ( returnValueList[keypos].key == TERMINAL_LIST_ELEMENT )
425  {
427  return RETnumber;
428  }
429 
430  /* 3) Print error/warning/info. */
431  if ( ( returnValueList[keypos].globalVisibilityStatus == VS_VISIBLE ) && ( localVisibilityStatus == VS_VISIBLE ) )
432  {
433  if ( errorCount > 0 )
434  {
435  sprintf( myPrintfString,"%s->", whitespaces );
436  myPrintf( myPrintfString );
437  }
438 
439  if ( additionaltext == 0 )
440  {
441  sprintf( myPrintfString,"%s (%s, %s:%d): \t%s\n",
442  RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data
443  );
444  myPrintf( myPrintfString );
445  }
446  else
447  {
448  sprintf( myPrintfString,"%s (%s, %s:%d): \t%s %s\n",
449  RETstring,functionname,filename,(int)linenumber,returnValueList[keypos].data,additionaltext
450  );
451  myPrintf( myPrintfString );
452  }
453 
454  /* take care of proper indention for subsequent error messages */
455  if ( RETstring[0] == 'E' )
456  {
457  ++errorCount;
458  }
459  else
460  {
461  if ( errorCount > 0 )
462  myPrintf( "\n" );
463  errorCount = 0;
464  }
465  }
466 
467  return RETnumber;
468 }
469 
470 #else /* = PC_DEBUG not defined */
471 
472 /*
473  * t h r o w M e s s a g e
474  */
476  returnValue RETnumber,
477  const char* additionaltext,
478  const char* functionname,
479  const char* filename,
480  const unsigned long linenumber,
481  VisibilityStatus localVisibilityStatus,
482  const char* RETstring
483  )
484 {
485  /* DUMMY CODE FOR PRETENDING USE OF ARGUMENTS
486  * FOR SUPPRESSING COMPILER WARNINGS! */
487  int i = 0;
488  if ( additionaltext == 0 ) i++;
489  if ( functionname == 0 ) i++;
490  if ( filename == 0 ) i++;
491  if ( linenumber == 0 ) i++;
492  if ( localVisibilityStatus == VS_VISIBLE ) i++;
493  if ( RETstring == 0 ) i++;
494  /* END OF DUMMY CODE */
495 
496  return RETnumber;
497 }
498 
499 #endif /* PC_DEBUG */
500 
501 
502 
503 /*****************************************************************************
504  * G L O B A L M E S S A G E H A N D L E R *
505  *****************************************************************************/
506 
507 
510 
511 
512 /*
513  * g e t G l o b a l M e s s a g e H a n d l e r
514  */
516 {
517  return &globalMessageHandler;
518 }
519 
520 const char* MessageHandling::getErrorString(int error)
521 {
522  return returnValueList[ error ].data;
523 }
524 
525 
526 
527 /*
528  * end of file
529  */
#define __LINE__
returnValue throwError(returnValue Enumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
returnValue throwInfo(returnValue Inumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
Allows to pass back messages to the calling function.
void setOutputFile(myFILE *_outputFile)
#define __FUNCTION__
returnValue throwWarning(returnValue Wnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
returnValue myPrintf(const char *s)
MessageHandling globalMessageHandler(myStderr, VS_VISIBLE, VS_VISIBLE, VS_VISIBLE)
void setInfoVisibilityStatus(VisibilityStatus _infoVisibility)
returnValue setErrorCount(int _errorCount)
Handles all kind of error messages, warnings and other information.
MessageHandling::ReturnValueList returnValueList[]
void rhs(const real_t *x, real_t *f)
static const char * getErrorString(int error)
void setErrorVisibilityStatus(VisibilityStatus _errorVisibility)
returnValue throwMessage(returnValue RETnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus, const char *RETstring)
#define __FILE__
void setWarningVisibilityStatus(VisibilityStatus _warningVisibility)
MessageHandling * getGlobalMessageHandler()


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:53