plot_window.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00034 #include <acado/user_interaction/plot_window_subplot.hpp>
00035 #include <acado/user_interaction/plot_window.hpp>
00036 
00037 
00038 
00039 BEGIN_NAMESPACE_ACADO
00040 
00041 
00042 //
00043 // PUBLIC MEMBER FUNCTIONS:
00044 //
00045 
00046 
00047 PlotWindow::PlotWindow( )
00048 {
00049         next  = 0;
00050         aliasIdx = -1;
00051 
00052         frequency = PLOT_AT_END;
00053         setupLogFrequency( frequency );
00054 
00055         first = 0;
00056         last  = 0;
00057 
00058         number = 0;
00059 
00060         shallPlotNominalControls = BT_FALSE;
00061         shallPlotNominalParameters = BT_FALSE;
00062         shallPlotNominalOutputs = BT_TRUE;
00063 }
00064 
00065 
00066 PlotWindow::PlotWindow( PlotFrequency _frequency
00067                                                 )
00068 {
00069         next  = 0;
00070         aliasIdx = -1;
00071 
00072         frequency = _frequency;
00073         setupLogFrequency( frequency );
00074 
00075         first = 0;
00076         last  = 0;
00077 
00078         number = 0;
00079 
00080         shallPlotNominalControls = BT_FALSE;
00081         shallPlotNominalParameters = BT_FALSE;
00082         shallPlotNominalOutputs = BT_TRUE;
00083 }
00084 
00085 
00086 PlotWindow::PlotWindow( const PlotWindow& rhs )
00087 {
00088         next =  rhs.next;
00089         aliasIdx = rhs.aliasIdx;//-1
00090 
00091         frequency = rhs.frequency;
00092 
00093         first = 0;
00094         last  = 0;
00095 
00096         number = 0;
00097 
00098         /* if rhs plot_window list is not empty, add all option items... */
00099         PlotWindowSubplot* current = rhs.first;
00100 
00101         while ( current != 0 )
00102         {
00103                 addSubplot( *current );
00104                 current = current->getNext( );
00105         }
00106 
00107         plotDataRecord = rhs.plotDataRecord;
00108 
00109         shallPlotNominalControls = rhs.shallPlotNominalControls;
00110         shallPlotNominalParameters = rhs.shallPlotNominalParameters;
00111         shallPlotNominalOutputs = rhs.shallPlotNominalOutputs;
00112 
00113 }
00114 
00115 
00116 PlotWindow::~PlotWindow( )
00117 {
00118         clearAllSubplots( );
00119 }
00120 
00121 
00122 PlotWindow& PlotWindow::operator=( const PlotWindow& rhs )
00123 {
00124         if ( this != &rhs )
00125         {
00126                 clearAllSubplots( );
00127 
00128 
00129                 next = rhs.next;
00130                 aliasIdx = rhs.aliasIdx;//-1
00131 
00132                 frequency = rhs.frequency;
00133 
00134                 /* if rhs plot_window list is not empty, add all option items... */
00135                 PlotWindowSubplot* current = rhs.first;
00136 
00137                 while ( current != 0 )
00138                 {
00139                         addSubplot( *current );
00140                         current = current->getNext( );
00141                 }
00142 
00143                 plotDataRecord = rhs.plotDataRecord;
00144                 
00145                 shallPlotNominalControls = rhs.shallPlotNominalControls;
00146                 shallPlotNominalParameters = rhs.shallPlotNominalParameters;
00147                 shallPlotNominalOutputs = rhs.shallPlotNominalOutputs;
00148         }
00149 
00150         return *this;
00151 }
00152 
00153 
00154 PlotWindow* PlotWindow::clone( ) const
00155 {
00156         return new PlotWindow( *this );
00157 }
00158 
00159 
00160 returnValue PlotWindow::init( )
00161 {
00162         return SUCCESSFUL_RETURN;
00163 }
00164 
00165 
00166 returnValue PlotWindow::plot(   PlotFrequency _frequency
00167                                                                         )
00168 {
00169         init( );
00170 
00171         return replot( _frequency );
00172 }
00173 
00174 
00175 returnValue PlotWindow::replot( PlotFrequency _frequency
00176                                                                 )
00177 {
00178         return SUCCESSFUL_RETURN;
00179 }
00180 
00181 
00182 returnValue PlotWindow::setTitle( uint idx, const char* const title_ )
00183 {
00184         if ( idx >= getNumSubplots( ) )
00185                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00186 
00187         return operator()( idx ).setTitle( title_ );
00188 }
00189 
00190 returnValue PlotWindow::setLabelX( uint idx, const char* const xLabel_ )
00191 {
00192         if ( idx >= getNumSubplots( ) )
00193                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00194 
00195         return operator()( idx ).setXLabel( xLabel_ );
00196 }
00197 
00198 
00199 returnValue PlotWindow::setLabelY( uint idx, const char* const yLabel_ )
00200 {
00201         if ( idx >= getNumSubplots( ) )
00202                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00203 
00204         return operator()( idx ).setYLabel( yLabel_ );
00205 }
00206 
00207 
00208 returnValue PlotWindow::setPlotMode( uint idx, PlotMode plotMode_ )
00209 {
00210         if ( idx >= getNumSubplots( ) )
00211                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00212 
00213         return operator()( idx ).setPlotMode( plotMode_ );
00214 }
00215 
00216 
00217 returnValue PlotWindow::setRanges(      uint idx,
00218                                                                         double xRange1_,
00219                                                                         double xRange2_,
00220                                                                         double yRange1_,
00221                                                                         double yRange2_ 
00222                                                                         )
00223 {
00224         if ( idx >= getNumSubplots( ) )
00225                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00226 
00227         return operator()( idx ).setRanges( xRange1_,xRange2_,yRange1_,yRange2_ );
00228 }
00229 
00230 
00231 
00232 returnValue PlotWindow::addLine(        uint idx,
00233                                                                         double _lineValue
00234                                                                         )
00235 {
00236         if ( idx >= getNumSubplots( ) )
00237                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00238 
00239         return operator()( idx ).addLine( _lineValue );
00240 }
00241 
00242 
00243 returnValue PlotWindow::addData(        uint idx,
00244                                                                         const VariablesGrid& _newData//,
00245                                                                         //PlotMode plotMode
00246                                                                         )
00247 {
00248         if ( idx >= getNumSubplots( ) )
00249                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00250 
00251         return operator()( idx ).addData( _newData );
00252 }
00253 
00254 
00255 returnValue PlotWindow::operator<<(     PlotWindowSubplot& _subplot
00256                                                                         )
00257 {
00258         return addSubplot( _subplot );
00259 }
00260 
00261 
00262 returnValue PlotWindow::operator<<(     PlotName _name
00263                                                                         )
00264 {
00265         return addSubplot( _name );
00266 }
00267 
00268 
00269 returnValue PlotWindow::operator<<(     const Expression& _name
00270                                                                         )
00271 {
00272         return addSubplot( _name );
00273 }
00274 
00275 
00276 returnValue PlotWindow::addSubplot(     PlotWindowSubplot& _subplot
00277                                                                         )
00278 {
00279         // create new item
00280         PlotWindowSubplot* newItem = new PlotWindowSubplot( _subplot );
00281 
00282         if ( number == 0 )
00283         {
00284                 first = newItem;
00285                 last = newItem;
00286         }
00287         else
00288         {
00289                 if ( last->setNext( newItem ) != SUCCESSFUL_RETURN )
00290                         return ACADOERROR( RET_PLOT_WINDOW_CORRUPTED );
00291                 last = newItem;
00292         }
00293 
00294         // add plot item for all possible plot objects
00295         if ( addPlotDataItem( _subplot.getXVariableType( ) ) != SUCCESSFUL_RETURN )
00296                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00297 
00298         if ( addPlotDataItem( _subplot.getYVariableType( ) ) != SUCCESSFUL_RETURN )
00299                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00300 
00301         if ( addPlotDataItem( _subplot.getXPlotExpression( ) ) != SUCCESSFUL_RETURN )
00302                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00303 
00304         if ( addPlotDataItem( _subplot.getYPlotExpression( ) ) != SUCCESSFUL_RETURN )
00305                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00306 
00307         if ( addPlotDataItem( _subplot.getPlotEnum( ) ) != SUCCESSFUL_RETURN )
00308                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00309 
00310         ++number;
00311 
00312         return SUCCESSFUL_RETURN;
00313 }
00314 
00315 
00316 returnValue PlotWindow::addSubplot(     const Expression& _expression,
00317                                                                         const char* const _title,
00318                                                                         const char* const _xLabel,
00319                                                                         const char* const _yLabel,
00320                                                                         PlotMode _plotMode,
00321                                                                         double _xRangeLowerLimit,
00322                                                                         double _xRangeUpperLimit,
00323                                                                         double _yRangeLowerLimit,
00324                                                                         double _yRangeUpperLimit
00325                                                                         ){
00326 
00327     uint run1;
00328 
00329     for( run1 = 0; run1 < _expression.getDim(); run1++ ){
00330 
00331         PlotWindowSubplot* newSubplot = new PlotWindowSubplot(  _expression(run1),
00332                                                                                                                                 _title,_xLabel,_yLabel,_plotMode,
00333                                                                                                                                 _xRangeLowerLimit,_xRangeUpperLimit,
00334                                                                                                                                 _yRangeLowerLimit,_yRangeUpperLimit );
00335 
00336                 if ( number == 0 )
00337                 {
00338                         first = newSubplot;
00339                         last = newSubplot;
00340                 }
00341                 else
00342                 {
00343                         if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00344                                 return ACADOERROR( RET_PLOT_WINDOW_CORRUPTED );
00345                         last = newSubplot;
00346                 }
00347 
00348         Expression tmp( _expression(run1) );
00349 
00350                 if ( addPlotDataItem( &tmp ) != SUCCESSFUL_RETURN )
00351                         return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00352 
00353                 ++number;
00354         }
00355 
00356         return SUCCESSFUL_RETURN;
00357 }
00358 
00359 
00360 returnValue PlotWindow::addSubplot(     const Expression& _expressionX,
00361                                                                         const Expression& _expressionY,
00362                                                                         const char* const _title,
00363                                                                         const char* const _xLabel,
00364                                                                         const char* const _yLabel,
00365                                                                         PlotMode _plotMode,
00366                                                                         double _xRangeLowerLimit,
00367                                                                         double _xRangeUpperLimit,
00368                                                                         double _yRangeLowerLimit,
00369                                                                         double _yRangeUpperLimit
00370                                                                         )
00371 {
00372 
00373     ASSERT( _expressionX.getDim() == _expressionY.getDim() );
00374 
00375     uint run1;
00376 
00377     for( run1 = 0; run1 < _expressionX.getDim(); run1++ ){
00378 
00379                 PlotWindowSubplot* newSubplot = new PlotWindowSubplot(  _expressionX(run1),_expressionY(run1),
00380                                                                                                                                 _title,_xLabel,_yLabel,_plotMode,
00381                                                                                                                                 _xRangeLowerLimit,_xRangeUpperLimit,
00382                                                                                                                                 _yRangeLowerLimit,_yRangeUpperLimit );
00383 
00384                 if ( number == 0 )
00385                 {
00386                         first = newSubplot;
00387                         last = newSubplot;
00388                 }
00389                 else
00390                 {
00391                         if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00392                                 return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
00393                         last = newSubplot;
00394                 }
00395 
00396         Expression tmpX( _expressionX(run1) );
00397 
00398                 if ( addPlotDataItem( &tmpX ) != SUCCESSFUL_RETURN )
00399                         return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00400 
00401         Expression tmpY( _expressionY(run1) );
00402 
00403                 if ( addPlotDataItem( &tmpY ) != SUCCESSFUL_RETURN )
00404                         return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00405 
00406                 ++number;
00407     }
00408 
00409         return SUCCESSFUL_RETURN;
00410 }
00411 
00412 
00413 
00414 returnValue PlotWindow::addSubplot(     PlotName _name,
00415                                                                         const char* const _title,
00416                                                                         const char* const _xLabel,
00417                                                                         const char* const _yLabel,
00418                                                                         PlotMode _plotMode,
00419                                                                         double _xRangeLowerLimit,
00420                                                                         double _xRangeUpperLimit,
00421                                                                         double _yRangeLowerLimit,
00422                                                                         double _yRangeUpperLimit
00423                                                                         )
00424 {
00425         PlotWindowSubplot* newSubplot = new PlotWindowSubplot(  _name,
00426                                                                                                                         _title,_xLabel,_yLabel,_plotMode,
00427                                                                                                                         _xRangeLowerLimit,_xRangeUpperLimit,
00428                                                                                                                         _yRangeLowerLimit,_yRangeUpperLimit );
00429 
00430         // for certain PlotName, switch to logarithmic plot
00431         if ( ( _name == PLOT_KKT_TOLERANCE ) ||
00432                  ( _name == PLOT_NORM_LAGRANGE_GRADIENT ) )
00433                 newSubplot->setPlotFormat( PF_LOG );
00434 
00435         if ( number == 0 )
00436         {
00437                 first = newSubplot;
00438                 last = newSubplot;
00439         }
00440         else
00441         {
00442                 if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00443                         return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
00444                 last = newSubplot;
00445         }
00446 
00447         if ( addPlotDataItem( _name ) != SUCCESSFUL_RETURN )
00448                 return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
00449 
00450         ++number;
00451 
00452         return SUCCESSFUL_RETURN;
00453 }
00454 
00455 
00456 returnValue PlotWindow::addSubplot( const VariablesGrid& _variable,
00457                                     const char* const _title,
00458                                     const char* const _xLabel,
00459                                     const char* const _yLabel,
00460                                     PlotMode _plotMode,
00461                                     double _xRangeLowerLimit,
00462                                     double _xRangeUpperLimit,
00463                                     double _yRangeLowerLimit,
00464                                     double _yRangeUpperLimit  ){
00465 
00466 
00467     PlotWindowSubplot* newSubplot = new PlotWindowSubplot( _variable,
00468                                                            _title,_xLabel,_yLabel,_plotMode,
00469                                                            _xRangeLowerLimit,_xRangeUpperLimit,
00470                                                            _yRangeLowerLimit,_yRangeUpperLimit,
00471                                                            BT_FALSE );
00472 
00473         if ( number == 0 )
00474         {
00475                 first = newSubplot;
00476                 last = newSubplot;
00477         }
00478         else
00479         {
00480                 if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00481                         return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
00482                 last = newSubplot;
00483         }
00484 
00485         ++number;
00486 
00487         return SUCCESSFUL_RETURN;
00488 }
00489 
00490 
00491 returnValue PlotWindow::addSubplot3D( const VariablesGrid& _variable,
00492                                       const char* const _title,
00493                                       const char* const _xLabel,
00494                                       const char* const _yLabel,
00495                                       PlotMode _plotMode,
00496                                       double _xRangeLowerLimit,
00497                                       double _xRangeUpperLimit,
00498                                       double _yRangeLowerLimit,
00499                                       double _yRangeUpperLimit  )
00500 {
00501 
00502     PlotWindowSubplot* newSubplot = new PlotWindowSubplot( _variable,
00503                                                            _title,_xLabel,_yLabel,_plotMode,
00504                                                            _xRangeLowerLimit,_xRangeUpperLimit,
00505                                                            _yRangeLowerLimit,_yRangeUpperLimit,
00506                                                            BT_TRUE );
00507 
00508         if ( number == 0 )
00509         {
00510                 first = newSubplot;
00511                 last = newSubplot;
00512         }
00513         else
00514         {
00515                 if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00516                         return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
00517                 last = newSubplot;
00518         }
00519 
00520         ++number;
00521         
00522     return SUCCESSFUL_RETURN;
00523 }
00524 
00525 
00526 returnValue PlotWindow::addSubplot( const Curve& _curve,
00527                                                                         double _xRangeLowerLimit,
00528                                                                         double _xRangeUpperLimit,
00529                                                                         const char* const _title,
00530                                                                         const char* const _xLabel,
00531                                                                         const char* const _yLabel,
00532                                                                         PlotMode _plotMode,
00533                                                                         double _yRangeLowerLimit,
00534                                                                         double _yRangeUpperLimit
00535                                                                         )
00536 {
00537         PlotWindowSubplot* newSubplot = new PlotWindowSubplot(  _curve,
00538                                                                                                                         _xRangeLowerLimit,_xRangeUpperLimit,
00539                                                                                                                    _title,_xLabel,_yLabel,_plotMode,
00540                                                                                                                         _yRangeLowerLimit,_yRangeUpperLimit );
00541 
00542         if ( number == 0 )
00543         {
00544                 first = newSubplot;
00545                 last = newSubplot;
00546         }
00547         else
00548         {
00549                 if ( last->setNext( newSubplot ) != SUCCESSFUL_RETURN )
00550                         return ACADOERROR( RET_OPTIONS_LIST_CORRUPTED );
00551                 last = newSubplot;
00552         }
00553 
00554         ++number;
00555 
00556         return SUCCESSFUL_RETURN;
00557 }
00558 
00559 
00560 returnValue PlotWindow::clearAllSubplots( )
00561 {
00562         PlotWindowSubplot* current = first;
00563         PlotWindowSubplot* tmp;
00564 
00565         /* deallocate all PlotWindowSubplots within list */
00566         while ( current != 0 )
00567         {
00568                 tmp = current->getNext( );
00569                 delete current;
00570                 current = tmp;
00571         }
00572 
00573         /* ... and initialise an empty list. */
00574         first = 0;
00575         last  = 0;
00576 
00577         number = 0;
00578 
00579         return SUCCESSFUL_RETURN;
00580 }
00581 
00582 
00583 
00584 //
00585 // PROTECTED MEMBER FUNCTIONS:
00586 //
00587 
00588 returnValue PlotWindow::addPlotDataItem(        const Expression* const _expression
00589                                                                                         )
00590 {
00591         if ( _expression != 0 )
00592         {
00593                 // use dedicated call for variables
00594                 if ( _expression->isVariable( ) == BT_TRUE )
00595                         return addPlotDataItem( _expression->getVariableType( ) );
00596 
00597                 // otherwise add all log entries that might be needed
00598                 plotDataRecord.addItem( LOG_DIFFERENTIAL_STATES );
00599                 plotDataRecord.addItem( LOG_ALGEBRAIC_STATES );
00600                 plotDataRecord.addItem( LOG_PARAMETERS );
00601                 plotDataRecord.addItem( LOG_CONTROLS );
00602                 plotDataRecord.addItem( LOG_DISTURBANCES );
00603 
00604                 plotDataRecord.addItem( LOG_SIMULATED_OUTPUT );
00605 
00606                 plotDataRecord.addItem( LOG_DISCRETIZATION_INTERVALS );
00607                 plotDataRecord.addItem( LOG_STAGE_BREAK_POINTS );
00608         }
00609 
00610         return SUCCESSFUL_RETURN;
00611 }
00612 
00613 
00614 returnValue PlotWindow::addPlotDataItem(        VariableType _type
00615                                                                                         )
00616 {
00617         switch( _type )
00618         {
00619                 case VT_DIFFERENTIAL_STATE:
00620                         plotDataRecord.addItem( LOG_DIFFERENTIAL_STATES );
00621                         break;
00622 
00623                 case VT_ALGEBRAIC_STATE:
00624                         plotDataRecord.addItem( LOG_ALGEBRAIC_STATES );
00625                         break;
00626 
00627                 case VT_PARAMETER:
00628                         plotDataRecord.addItem( LOG_PARAMETERS );
00629                         plotDataRecord.addItem( LOG_NOMINAL_PARAMETERS );
00630                         //plotDataRecord.addItem( LOG_SIMULATED_PARAMETERS );
00631                         break;
00632 
00633                 case VT_CONTROL:
00634                         plotDataRecord.addItem( LOG_CONTROLS );
00635                         plotDataRecord.addItem( LOG_NOMINAL_CONTROLS );
00636                         //plotDataRecord.addItem( LOG_SIMULATED_CONTROLS );
00637                         break;
00638 
00639                 case VT_DISTURBANCE:
00640                         plotDataRecord.addItem( LOG_DISTURBANCES );
00641                         break;
00642 
00643                 case VT_INTERMEDIATE_STATE:
00644                         plotDataRecord.addItem( LOG_INTERMEDIATE_STATES );
00645                         break;
00646                         
00647                 case VT_OUTPUT:
00648                         plotDataRecord.addItem( LOG_SIMULATED_OUTPUT );
00649                         plotDataRecord.addItem( LOG_PROCESS_OUTPUT );
00650                         break;
00651 
00652                 default:
00653                         break;
00654         }
00655 
00656         plotDataRecord.addItem( LOG_DISCRETIZATION_INTERVALS );
00657         plotDataRecord.addItem( LOG_STAGE_BREAK_POINTS );
00658 
00659         return SUCCESSFUL_RETURN;
00660 }
00661 
00662 
00663 returnValue PlotWindow::addPlotDataItem(        PlotName _name
00664                                                                                         )
00665 {
00666         LogName logName = convertPlotToLogName( _name );
00667 
00668         if ( logName != LOG_NOTHING )
00669                 return plotDataRecord.addItem( logName );
00670 
00671         plotDataRecord.setLogFrequency( LOG_AT_EACH_ITERATION );
00672 
00673         return SUCCESSFUL_RETURN;
00674 }
00675 
00676 
00677 
00678 LogName PlotWindow::convertPlotToLogName(       PlotName _name
00679                                                                                         ) const
00680 {
00681         switch( _name )
00682         {
00683                 case PLOT_KKT_TOLERANCE:
00684                         return LOG_KKT_TOLERANCE;
00685                         break;
00686 
00687                 case PLOT_OBJECTIVE_VALUE:
00688                         return LOG_OBJECTIVE_VALUE;
00689 
00690                 case PLOT_MERIT_FUNCTION_VALUE:
00691                         return LOG_MERIT_FUNCTION_VALUE;
00692 
00693                 case PLOT_LINESEARCH_STEPLENGTH:
00694                         return LOG_LINESEARCH_STEPLENGTH;
00695 
00696                 case PLOT_NORM_LAGRANGE_GRADIENT:
00697                         return LOG_NORM_LAGRANGE_GRADIENT;
00698 
00699                 default:
00700                         return LOG_NOTHING;
00701         }
00702 }
00703 
00704 
00705 PlotName PlotWindow::convertLogToPlotName(      LogName _name
00706                                                                                         ) const
00707 {
00708         switch( _name )
00709         {
00710                 case LOG_KKT_TOLERANCE:
00711                         return PLOT_KKT_TOLERANCE;
00712                         break;
00713 
00714                 case LOG_OBJECTIVE_VALUE:
00715                         return PLOT_OBJECTIVE_VALUE;
00716 
00717                 case LOG_MERIT_FUNCTION_VALUE:
00718                         return PLOT_MERIT_FUNCTION_VALUE;
00719 
00720                 case LOG_LINESEARCH_STEPLENGTH:
00721                         return PLOT_LINESEARCH_STEPLENGTH;
00722 
00723                 case LOG_NORM_LAGRANGE_GRADIENT:
00724                         return PLOT_NORM_LAGRANGE_GRADIENT;
00725 
00726                 default:
00727                         return PLOT_NOTHING;
00728         }
00729 }
00730 
00731 
00732 
00733 returnValue PlotWindow::setupLogFrequency( PlotFrequency _frequency )
00734 {
00735         LogFrequency logFrequency;
00736 
00737         switch ( _frequency )
00738         {
00739                 case PLOT_AT_START:
00740                         logFrequency = LOG_AT_START;
00741                         break;
00742 
00743                 case PLOT_AT_END:
00744                         logFrequency = LOG_AT_END;
00745                         break;
00746 
00747                 default:
00748                         logFrequency = LOG_AT_EACH_ITERATION;
00749                         break;
00750         }
00751 
00752         return plotDataRecord.setLogFrequency( logFrequency );
00753 }
00754 
00755 
00756 
00757 returnValue PlotWindow::getVariableDataGrids(   const Expression* const variable,
00758                                                                                                 VariableType& _type,
00759                                                                                                 VariablesGrid& _dataGrid,
00760                                                                                                 Grid& _discretizationGrid
00761                                                                                                 )
00762 {
00763 
00764     ASSERT( variable->isVariable() == BT_TRUE );
00765 
00766         VariablesGrid dataGridTmp, dataGridComponent;
00767         int component = variable->getComponent(0);
00768 
00769         _type = variable->getVariableType();
00770         
00771         switch( _type )
00772         {
00773                 case VT_DIFFERENTIAL_STATE:
00774                         plotDataRecord.getLast( LOG_DIFFERENTIAL_STATES,dataGridTmp );
00775                         break;
00776 
00777                 case VT_ALGEBRAIC_STATE:
00778                         plotDataRecord.getLast( LOG_ALGEBRAIC_STATES,dataGridTmp );
00779                         break;
00780 
00781                 case VT_PARAMETER:
00782                         if ( shallPlotNominalParameters == BT_TRUE )
00783                                 plotDataRecord.getLast( LOG_NOMINAL_PARAMETERS,dataGridTmp );
00784                         else
00785                                 plotDataRecord.getLast( LOG_PARAMETERS,dataGridTmp );
00786                         
00787                         component = variable->getComponent(0);
00788                         if ( dataGridTmp.getNumValues( ) <= (uint)component )
00789                                 return ACADOERROR( RET_EMPTY_PLOT_DATA );
00790                         
00791                         dataGridComponent = dataGridTmp(component);
00792                         dataGridComponent.setType( VT_PARAMETER );
00793 
00794                         return getDataGrids( &dataGridComponent,_type,_dataGrid,_discretizationGrid );
00795 
00796                 case VT_CONTROL:
00797                         if ( shallPlotNominalControls == BT_TRUE )
00798                                 plotDataRecord.getLast( LOG_NOMINAL_CONTROLS,dataGridTmp );
00799                         else
00800                                 plotDataRecord.getLast( LOG_CONTROLS,dataGridTmp );
00801                         
00802                         component = variable->getComponent(0);
00803                         if ( dataGridTmp.getNumValues( ) <= (uint)component )
00804                                 return ACADOERROR( RET_EMPTY_PLOT_DATA );
00805                         
00806                         dataGridComponent = dataGridTmp(component);
00807                         dataGridComponent.setType( VT_CONTROL );
00808 
00809                         return getDataGrids( &dataGridComponent,_type,_dataGrid,_discretizationGrid );
00810 
00811                 case VT_DISTURBANCE:
00812                         plotDataRecord.getLast( LOG_DISTURBANCES,dataGridTmp );
00813                         break;
00814 
00815                 case VT_INTERMEDIATE_STATE:
00816                         plotDataRecord.getLast( LOG_INTERMEDIATE_STATES,dataGridTmp );
00817                         break;
00818 
00819                 case VT_OUTPUT:
00820                         if ( shallPlotNominalOutputs == BT_TRUE )
00821                                 plotDataRecord.getLast( LOG_SIMULATED_OUTPUT,dataGridTmp );
00822                         else
00823                                 plotDataRecord.getLast( LOG_PROCESS_OUTPUT,dataGridTmp );
00824                         
00825                         if ( dataGridTmp.getNumValues( ) > (uint)component )
00826                                 _dataGrid = dataGridTmp(component);
00827                         else
00828                                 return ACADOERROR( RET_EMPTY_PLOT_DATA );
00829                         
00830                         _discretizationGrid.init();
00831                         return SUCCESSFUL_RETURN;
00832 
00833                 default:
00834                         // empty plot
00835                         return ACADOERROR( RET_EMPTY_PLOT_DATA );
00836         }
00837 
00838         if ( dataGridTmp.getNumValues( ) > (uint)component )
00839                 _dataGrid = dataGridTmp(component);
00840         else
00841                 return ACADOERROR( RET_EMPTY_PLOT_DATA );
00842 
00843         VariablesGrid tmp;
00844         plotDataRecord.getLast( LOG_DISCRETIZATION_INTERVALS,tmp );
00845         tmp.getGrid( _discretizationGrid );
00846         
00847         return SUCCESSFUL_RETURN;
00848 }
00849 
00850 
00851 returnValue PlotWindow::getExpressionDataGrids( const Expression* const expression,
00852                                                                                                 VariableType& _type,
00853                                                                                                 VariablesGrid& _dataGrid,
00854                                                                                                 Grid& _discretizationGrid
00855                                                                                                 )
00856 {
00857         OutputFcn f;
00858         VariablesGrid loggedX,loggedXA,loggedP,loggedU,loggedW;
00859 
00860         _type = expression->getVariableType( );
00861 
00862         f << *expression;
00863 
00864         plotDataRecord.getLast( LOG_DIFFERENTIAL_STATES,loggedX );
00865         plotDataRecord.getLast( LOG_ALGEBRAIC_STATES,loggedXA );
00866         plotDataRecord.getLast( LOG_PARAMETERS,loggedP );
00867         plotDataRecord.getLast( LOG_CONTROLS,loggedU );
00868         plotDataRecord.getLast( LOG_DISTURBANCES,loggedW );
00869 
00870         if ( loggedP.isEmpty() == BT_FALSE )
00871                 loggedP.refineGrid( loggedX );
00872 
00873         if ( loggedU.isEmpty() == BT_FALSE )
00874                 loggedU.refineGrid( loggedX );
00875 
00876         if ( loggedW.isEmpty() == BT_FALSE )
00877                 loggedW.refineGrid( loggedX );
00878 
00879         returnValue returnvalue = f.evaluate( &loggedX,&loggedXA,&loggedP,&loggedU,&loggedW, &_dataGrid );
00880         if( returnvalue != SUCCESSFUL_RETURN )
00881                 return ACADOERROR( returnvalue );
00882 
00883         VariablesGrid tmp;
00884         plotDataRecord.getLast( LOG_DISCRETIZATION_INTERVALS,tmp );
00885         tmp.getGrid( _discretizationGrid );
00886         
00887         return SUCCESSFUL_RETURN;
00888 }
00889 
00890 
00891 returnValue PlotWindow::getDataGrids(   const VariablesGrid* const variablesGrid,
00892                                                                                 VariableType& _type,
00893                                                                                 VariablesGrid& _dataGrid,
00894                                                                                 Grid& _discretizationGrid
00895                                                                                 )
00896 {
00897         _dataGrid.init();
00898         _discretizationGrid.init( );
00899 
00900         _type = variablesGrid->getType( );
00901 
00902         InterpolationMode mode = IM_LINEAR;
00903         if ( ( _type == VT_CONTROL ) || ( _type == VT_PARAMETER ) )
00904                 mode = IM_CONSTANT;
00905         
00906         switch ( mode )
00907         {
00908                 case IM_CONSTANT:
00909                         _discretizationGrid.addTime( 0.0 );
00910                         
00911                         for( uint i=0; i<variablesGrid->getNumPoints( )-1; ++i )
00912                         {
00913                                 _dataGrid.addVector( variablesGrid->getVector(i),variablesGrid->getTime(i) );
00914                                 _dataGrid.addVector( variablesGrid->getVector(i),variablesGrid->getTime(i+1) );
00915                                 _discretizationGrid.addTime( (double)_dataGrid.getNumPoints() );
00916                         }
00917                         _dataGrid.addVector( variablesGrid->getLastVector(),variablesGrid->getLastTime() );
00918                         _discretizationGrid.addTime( (double)_dataGrid.getNumPoints() );
00919                         break;
00920 
00921                 case IM_LINEAR:
00922                         _dataGrid = *variablesGrid;
00923                         break;
00924 
00925                 default:
00926                         return ACADOERROR( RET_NOT_YET_IMPLEMENTED );
00927         }
00928 
00929         _dataGrid.setType( _type );
00930 
00931         return SUCCESSFUL_RETURN;
00932 }
00933 
00934 
00935 
00936 returnValue PlotWindow::getAutoScaleYLimits(    const VariablesGrid& dataGridY,
00937                                                                                                 PlotFormat plotFormat,
00938                                                                                                 double& lowerLimit,
00939                                                                                                 double& upperLimit
00940                                                                                                 ) const
00941 {
00942         double maxValue  = dataGridY.getMax( );
00943         double minValue  = dataGridY.getMin( );
00944         double meanValue = dataGridY.getMean( );
00945 
00946         if ( ( acadoIsZero( maxValue ) == BT_TRUE ) && ( acadoIsZero( minValue ) == BT_TRUE ) )
00947                 meanValue = 0.1 / 0.025;
00948 
00949         lowerLimit = minValue - 0.1*( maxValue-minValue ) - 0.025*meanValue - 1.0e-8;
00950         upperLimit = maxValue + 0.1*( maxValue-minValue ) + 0.025*meanValue + 1.0e-8;
00951 
00952         
00953         if ( ( plotFormat == PF_LOG ) || ( plotFormat == PF_LOG_LOG ) )
00954         {
00955                 if ( ( acadoIsStrictlyGreater( minValue,0.0, ZERO ) == BT_TRUE ) && ( acadoIsGreater( lowerLimit,0.0, ZERO ) == BT_FALSE ) )
00956                 {
00957                         lowerLimit = ( minValue + acadoMin( minValue,EPS ) ) / sqrt(10.0);
00958                         upperLimit = upperLimit * sqrt(10.0);
00959                 }
00960         }
00961         else
00962         {
00963                 if ( ( acadoIsStrictlyGreater( minValue,0.0, ZERO ) == BT_TRUE ) && ( acadoIsGreater( lowerLimit,0.0, ZERO ) == BT_FALSE ) )
00964                         lowerLimit = 0.0;
00965 
00966                 if ( ( acadoIsStrictlySmaller( maxValue,0.0 ) == BT_TRUE ) && ( acadoIsSmaller( upperLimit,0.0 ) == BT_FALSE ) )
00967                         upperLimit = 0.0;
00968         }
00969         
00970         return SUCCESSFUL_RETURN;
00971 }
00972 
00973 
00974 
00975 
00976 CLOSE_NAMESPACE_ACADO
00977 
00978 
00979 /*
00980  *      end of file
00981  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:49