contrib/rpl/rgrl/rgrl_converge_status.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \author Amitha Perera
00004 // \date   Feb 2003
00005 
00006 #include "rgrl_converge_status.h"
00007 
00008 #include <vcl_cassert.h>
00009 
00010 
00011 rgrl_converge_status::
00012 rgrl_converge_status( )
00013   : conv_( conv_on_going ),
00014     status_( status_on_going ),
00015     error_( -1.0 ),
00016     oscillation_count_( 0 ),
00017     error_diff_( -1.0 )
00018 {
00019   
00020 }  
00021 
00022 rgrl_converge_status::
00023 rgrl_converge_status( converge_type conv, 
00024                       status_type stat, 
00025                       double error, 
00026                       unsigned osc_count,
00027                       double error_diff )
00028   : conv_( conv ),
00029     status_( stat ),
00030     error_( error ),
00031     oscillation_count_( osc_count ),
00032     error_diff_( error_diff )
00033 {
00034   
00035 }  
00036  
00037 rgrl_converge_status::
00038 rgrl_converge_status( bool     in_has_converged,
00039                       bool     in_has_stagnated,
00040                       bool     in_is_good_enough,
00041                       bool     in_is_failed,
00042                       double   in_error,
00043                       unsigned in_oscillation_count,
00044                       double   in_error_diff )
00045   : conv_( conv_on_going ),
00046     status_( status_on_going ),
00047     error_( in_error ),
00048     oscillation_count_( in_oscillation_count ),
00049     error_diff_( in_error_diff )
00050 {
00051   if( in_has_converged )
00052     conv_ = converged;
00053 
00054   if( in_has_stagnated )
00055     conv_ = stagnated;
00056 
00057   // for backward compatibility
00058   // Good enough means the algorithm can quit.
00059   // Hence, should be good_and_terminate
00060   //
00061   if( in_is_good_enough )
00062     status_ = good_and_terminate;
00063 
00064   if( in_is_failed )
00065     status_ = failed;
00066         
00067   assert( ! ( in_has_converged && in_has_stagnated ) );
00068 }
00069 
00070 rgrl_converge_status::
00071 ~rgrl_converge_status()
00072 {
00073 }
00074 
00075 
00076 bool
00077 rgrl_converge_status::
00078 has_converged() const
00079 {
00080   return conv_ == converged;
00081 }
00082 
00083 
00084 bool
00085 rgrl_converge_status::
00086 has_stagnated() const
00087 { 
00088   return conv_ == stagnated;
00089 }
00090 
00091 
00092 bool
00093 rgrl_converge_status::
00094 is_good_enough() const
00095 {
00096   return status_ == good_enough || status_ == good_and_terminate;
00097 }
00098 
00099 bool
00100 rgrl_converge_status::
00101 is_good_and_should_terminate() const
00102 {
00103   return status_ == good_and_terminate;
00104 }
00105 
00106 bool
00107 rgrl_converge_status::
00108 is_failed() const
00109 {
00110   return status_ == failed;
00111 }
00112 
00113 rgrl_converge_status::converge_type
00114 rgrl_converge_status::
00115 current_converge() const
00116 {
00117   return conv_;
00118 }
00119 
00120 rgrl_converge_status::status_type
00121 rgrl_converge_status::
00122 current_status() const
00123 {
00124   return status_;
00125 }
00126 
00127 void 
00128 rgrl_converge_status::
00129 set_current_converge( converge_type c )
00130 {
00131   conv_ = c;
00132 }
00133 
00134 void 
00135 rgrl_converge_status::
00136 set_current_status( status_type s )
00137 {
00138   status_ = s;
00139 }
00140 
00141 void
00142 rgrl_converge_status::
00143 set_objective_value( double obj )
00144 {
00145   error_ = obj;
00146 }
00147 
00148 double
00149 rgrl_converge_status::
00150 objective_value() const
00151 {
00152   return error_;
00153 }
00154 
00155 
00156 double
00157 rgrl_converge_status::
00158 error() const
00159 {
00160   return error_;
00161 }
00162 
00163 
00164 unsigned int
00165 rgrl_converge_status::
00166 oscillation_count() const
00167 {
00168   return oscillation_count_;
00169 }
00170 
00171 
00172 double
00173 rgrl_converge_status::
00174 error_diff() const
00175 {
00176   return error_diff_;
00177 }