DinverCore/ModelRepository.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: 2010-12-22
00021 **  Authors:
00022 **    Marc Wathelet (LGIT, Grenoble, France)
00023 **
00024 ***************************************************************************/
00025 
00026 #ifndef MODELREPOSITORY_H
00027 #define MODELREPOSITORY_H
00028 
00029 #include <QGpCoreTools.h>
00030 
00031 #include "DinverCoreDLLExport.h"
00032 #include "Generator.h"
00033 
00034 namespace DinverCore {
00035 
00036   class ModelSet;
00037   class GeneratorModels;
00038   class NewModel;
00039   class ParentIndex;
00040   class AbstractForward;
00041   class ReportWriter;
00042   class RealSpace;
00043   class Parameter;
00044 
00045   class DINVERCORE_EXPORT ModelRepository
00046   {
00047   public:
00048     ModelRepository();
00049     ~ModelRepository();
00050 
00051     bool operator==(const ModelRepository& o) const;
00052 
00053     void setForward(AbstractForward * f);
00054     void setStorage();
00055     void setBestModelCount(int nr);
00056     bool openReport(const QString& fileName);
00057 
00058     void setWalkCount(int n) {_walkCount=n;}
00059     void setMaximumModelCount(int n) {_maximumModelCount=n;}
00060     void setMaximumBestModelCount(int n) {_maximumBestModelCount=n;}
00061     void setMaximumQueueLength(int l) {_maximumQueueLenght=l;}
00062     void setMaximumSavedMisfit(double m) {_maximumSavedMisfit=m;}
00063     void setGiveUp(double gu) {_giveUp=gu;}
00064 
00065     ParentIndex * createModel(double randomValue, RealSpace& parameterSpace) const;
00066     ModelSet * allModels() {return _allModels;}
00067     void addReport(NewModel * m, AbstractForward * forward);
00068     void addModel(NewModel * m);
00069 
00070     void init();
00071     bool start(int nThreads, Generator::Type type);
00072     void stop();
00073     void wait();
00074 
00075     bool importModels(QString fileName, bool strict=true);
00076     void clear();
00077 
00078     void lock() const;
00079     void unlock() const;
00080 
00081     int expectedModelCount() const {return _maximumModelCount;}
00082     int visitedModelCount() const;
00083     int validModelCount() const;
00084     int activeModelCount() const;
00085     int bestModelCount() const;
00086     int rejectedCount() const;
00087     int giveUpCount() const;
00088     int variableParameterCount () const;
00089     uint checksum() const {return _parameterSpaceChecksum;}
00090 
00091     double misfit(int modelIndex) const;
00092     const int * model(int modelIndex) const;
00093     int bestModelIndex() const;
00094 
00095     AbstractForward * forward() {return _forward;}
00096     const AbstractForward * forward() const {return _forward;}
00097     const Parameter * variableParameter(int paramIndex) const;
00098     double variableParameterValue(int modelIndex, int paramIndex) const;
00099 
00100     void printActiveModels();
00101   private:
00102     void processQueue();
00103 
00104     int _walkCount;
00105     int _maximumModelCount;
00106     int _maximumBestModelCount;
00107     int _maximumQueueLenght;
00108     double _maximumSavedMisfit;
00109     double _giveUp;
00110 
00111     AtomicBoolean _terminated;
00112     QList<Generator *> _generators;
00113 
00114     AbstractForward * _forward;
00115     ModelSet * _allModels;
00116 
00117     mutable QReadWriteLock _generatorModelLock;
00118     GeneratorModels * _generatorModels;
00119 
00120     QMutex _queueLock;
00121     bool _processingQueue;
00122     QQueue<NewModel *> _newModels;
00123 
00124     QMutex _reportLock;
00125     ReportWriter * _report;
00126     uint _parameterSpaceChecksum;
00127 
00128     QTime _chrono;
00129   };
00130 
00131 } // namespace DinverCore
00132 
00133 #endif // MODELREPOSITORY_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines