DinverCore/ModelSet.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-13
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef MODELSET_H
00028 #define MODELSET_H
00029 
00030 #include <QGpCoreTools.h>
00031 
00032 namespace DinverCore {
00033 
00034 class Model;
00035 class RealSpace;
00036 class ReportReader;
00037 
00038 class ModelSet : private QSet<Model>, private IncreaseStorage
00039 {
00040   TRANSLATIONS("ModelSet")
00041 public:
00042   ModelSet(int parameterCount, int targetCount, int defaultCapacity=16384);
00043   ~ModelSet();
00044 
00045   bool importModelsFromAscii(RealSpace& parameterSpace, QString fileName);
00046   bool importModelsFromReport(RealSpace& parameterSpace, ReportReader& report, bool strict=true);
00047   bool importModels(RealSpace& parameterSpace, QString fileName, bool strict=true);
00048   int add(const RealSpace& parameterSpace, const double * misfit=0);
00049 
00050   inline void setMisfit(int modelIndex, int targetIndex, double m);
00051   //void setVolume(int modelIndex, double v) {_volumes[modelIndex]=v;}
00052   void clear();
00053 
00054   void reserve(int n) {IncreaseStorage::reserve(n);}
00055   int count() const {return _highestValidIndex+1;}
00056   int parameterCount() const {return _parameterCount;}
00057   int targetCount() const {return _targetCount;}
00058 
00059   const int * model(int modelIndex) const {return _parameters+_parameterCount*modelIndex;}
00060   const int * firstModel() const {return _parameters;}
00061   const double * misfit(int modelIndex) const {return _misfits+_targetCount*modelIndex;}
00062   //double volume(int modelIndex) const {return _volumes[modelIndex];}
00063 
00064   void lock() {_modelLock.lockForRead();}
00065   void unlock() {_modelLock.unlock();}
00066 
00067   void print(int modelIndex) const;
00068   int bestModel() const;
00069 private:
00070   virtual void reallocate();
00071 
00072   int _parameterCount;
00073   int _targetCount;
00074   int _highestValidIndex;
00075   int * _parameters;
00076   double * _misfits;
00077   //double * _volumes;
00078 
00079   QMutex _setLock;
00080   QReadWriteLock _modelLock;
00081 };
00082 
00083   inline void ModelSet::setMisfit(int modelIndex, int targetIndex, double m)
00084   {
00085     _misfits[_targetCount*modelIndex+targetIndex]=m;
00086     if(modelIndex>_highestValidIndex) {
00087       _highestValidIndex=modelIndex;
00088     }
00089   }
00090 
00091 } // namespace DinverCore
00092 
00093 #endif // MODELSET_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines