DinverCore/ActiveModel.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of DinverCore.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created : 2009-03-23
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef ACTIVEMODEL_H
00028 #define ACTIVEMODEL_H
00029 
00030 #include <QGpCoreTools.h>
00031 #include "DinverCoreDLLExport.h"
00032 
00033 namespace DinverCore {
00034 
00035 class DINVERCORE_EXPORT ActiveModel
00036 {
00037   TRANSLATIONS("ActiveModel")
00038 public:
00039   inline void operator=(int modelIndex);
00040   inline void operator=(const ActiveModel& o);
00041 
00042   int modelIndex() const {return _modelIndex;}
00043 
00044   int acceptedCount() const {return _nAccepted;}
00045   void addAccepted() {_nAccepted++;}
00046 
00047   int rejectedCount() const {return _nRejected;}
00048   void addRejected() {_nRejected++;}
00049 
00050   bool isQuarantined() const {return _quarantined;}
00051   void setQuarantined() {_quarantined=true;}
00052 
00053   inline bool giveUp(double ratio) const;
00054 
00055   //int navigatorHitCount() const {return _nNavigatorHits;}
00056   //inline void addNavigatorHit();
00057   int navigatorHit() const {return _navigatorHit;}
00058   void setNavigatorHit(int n=0) {_navigatorHit=n;}
00059 
00060   bool isDying() const {return /*_nNavigatorHits==0 && */ _lives==1;}
00061   bool isAlive() const {return _lives>0;}
00062   inline void healthCheck();
00063 private:
00064   int _modelIndex;
00065   int _nAccepted;
00066   int _nRejected;
00067   //int _nNavigatorHits;
00068   int _navigatorHit;
00069   int _lives;
00070   bool _quarantined;
00071 };
00072 
00073 inline void ActiveModel::operator=(int modelIndex)
00074 {
00075   _modelIndex=modelIndex;
00076   _nAccepted=0;
00077   _nRejected=0;
00078   //_nNavigatorHits=0;
00079   _navigatorHit=0;
00080   _lives=40;
00081   _quarantined=false;
00082 }
00083 
00084 inline void ActiveModel::operator=(const ActiveModel& o)
00085 {
00086   _modelIndex=o._modelIndex;
00087   _nAccepted=o._nAccepted;
00088   _nRejected=o._nRejected;
00089   _quarantined=o._quarantined;
00090   //_nNavigatorHits=o._nNavigatorHits;
00091   _navigatorHit=o._navigatorHit;
00092   _lives=o._lives;
00093 }
00094 
00095 inline void ActiveModel::healthCheck()
00096 {
00097   // Negative navigator hit count are always considered as alive.
00098   /*if(_nNavigatorHits>0) {
00099     _nNavigatorHits=0;
00100     _lives++;
00101   } else if(_nNavigatorHits==0) {
00102      if(isAlive()) _lives--;
00103   }*/
00104 }
00105 
00106 /*inline void ActiveModel::addNavigatorHit()
00107 {
00108   // During simulation only: when no model is removed
00109   //if( ! alive()) {
00110   //  App::stream() << tr("Back to life") << endl;
00111   //  _lives++;
00112   //}
00113   // _nNavigatorHits++;
00114 }*/
00115 
00116 inline bool ActiveModel::giveUp(double ratio) const
00117 {
00118   return _nRejected>50 &&
00119          _nRejected>ratio*(double)(_nRejected+_nAccepted);
00120 }
00121 
00122 } // namespace DinverCore
00123 
00124 #endif // ACTIVEMODEL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines