DinverCore/Neighborhood.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-05-06
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef NEIGHBORHOOD_H
00028 #define NEIGHBORHOOD_H
00029 
00030 #include <QGpCoreTools.h>
00031 
00032 #include "DinverCoreDLLExport.h"
00033 #include "ForwardSignal.h"
00034 #include "ActiveModel.h"
00035 
00036 namespace DinverCore {
00037 
00038 class AbstractForward;
00039 class VoronoiNavigator;
00040 class ModelSet;
00041 class ActiveModels;
00042 class BestModels;
00043 class UniqueRandom;
00044 class ReportWriter;
00045 class Parameter;
00046 class Model;
00047 class RealSpace;
00048 class ScaledModels;
00049 
00050 class DINVERCORE_EXPORT Neighborhood
00051 {
00052   TRANSLATIONS("Neighborhood")
00053 public:
00054   Neighborhood();
00055   ~Neighborhood();
00056 
00057   bool operator==(const Neighborhood& o) const;
00058 
00059   void setForward(AbstractForward * forward);
00060   void setStorage();
00061   bool setThreadCount(int nThreads);
00062   void setNr(int nr);
00063   void setGiveUp(double giveUp) {_giveUp=giveUp;}
00064   void setMaximumSavedMisfit(double m) {_maximumSavedMisfit=m;}
00065   void setSeed(int seed);
00066   bool openReport(const QString& fileName);
00067   void wake();
00068   void sleep();
00069   void timeReport() const;
00070   bool random(int ns=50, int nw=2);
00071   bool setVolumes();
00072   bool optimization(int ns=50, int nw=2);
00073 
00074   bool importModels(QString fileName, bool strict=true);
00075   void clear();
00076 
00077   void lock() const;
00078   void unlock() const;
00079 
00080   int visitedModelCount() const;
00081   int validModelCount() const;
00082   int activeModelCount() const;
00083   int bestModelCount() const;
00084   int rejectedCount() const {return _rejectedCount;}
00085   int giveUpCount() const {return _giveUpCount;}
00086   int variableParameterCount () const;
00087   uint checksum() const {return _parameterSpaceChecksum;}
00088 
00089   double misfit(int modelIndex) const;
00090   AbstractForward * forward() {return _forwards.isEmpty() ? 0 : _forwards.first();}
00091   const AbstractForward * forward() const {return _forwards.isEmpty() ? 0 : _forwards.first();}
00092   const Parameter * variableParameter(int paramIndex) const;
00093   double variableParameterValue(int modelIndex, int paramIndex) const;
00094   const int * model(int modelIndex) const;
00095   int bestModelIndex() const;
00096   double bestIterationMisfit() const {return _iterationMinimumMisfit;}
00097 
00098   void terminate(bool t=true);
00099   void start(int itmax=50, int ns0=50, int ns=50, int nr=50);
00100 private:
00101   void add(AbstractForward * forward);
00102   void stopForwards();
00103   bool terminated() {return _terminated.testAndSetOrdered(true,true);}
00104   bool optimizationEnd(bool exitCode);
00105   AbstractForward * nextForward();
00106   int removeDeadModels();
00107   double * scales();
00108 
00109   QVector<AbstractForward *> _forwards;
00110 
00111   ModelSet * _allModels;
00112   ActiveModels * _activeModels;
00113   BestModels * _bestModels;
00114   BestModels * _originalBestModels;
00115   UniqueRandom * _generator;
00116 
00117   ReportWriter * _report;
00118   uint _parameterSpaceChecksum;
00119 
00120   double _giveUp;
00121   double _maximumSavedMisfit;
00122   double _iterationMinimumMisfit;
00123 
00124   int _deadCount;
00125   int _giveUpCount;
00126   int _rejectedCount;
00127   int _maxModelCount;
00128 
00129   int _timeAdd;
00130   int _timeMainWait;
00131   int _timeStartEnd;
00132   int _timeTotal;
00133 
00134   ForwardSignal _forwardSignal;
00135   QAtomicInt _terminated;
00136 };
00137 
00138 } // namespace DinverCore
00139 
00140 #endif // NEIGHBORHOOD_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines