RegData.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2008 by Antonello Lobianco                         *
00003  *   http://regmas.org                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 3 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef REGDATA_H
00021 #define REGDATA_H
00022 
00023 // Core C++ headers
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 #include <stdexcept>
00028 #include <iostream>
00029 #include <sstream>
00030 
00031 // Qt headers...
00032 #include <QString>
00033 
00034 // RegMAS headers...
00035 #include "BaseRegmas.h"
00036 //#include "InputDocument.h"
00037 #include "InputNode.h"
00038 
00039 using namespace std;
00040 
00041 struct IFiles;
00042 struct BasicData;
00043 class  LLData;
00044 struct VectorSettings;
00045 class  RegActivities;
00046 struct RegResources;
00047 class  ModelObject;
00048 //class InputDocument;
00049 //class InputNode;
00050 
00052 
00059 class RegData: public BaseRegmas{
00060 
00061 public:
00062                         RegData(ThreadManager* MTHREAD_h);
00063                        ~RegData();
00064     
00065 
00067     void                loadInput();
00068     vector<string>      getScenarios();
00069     int                 getScenarioIndex();
00070     bool                delDir(QString dirname); 
00071     void                setDefaultSettings();
00072     void                setScenarioSettings();
00073     void                setResources();
00074     void                setDefaultActivities();
00075     void                setScenarioActivities();
00076     void                setObjectsDefinitions();
00077     void                initializeResourcesObjectsMatch(); 
00078     void                setSpace(); 
00080     void                initializeSpacialObjectsMatch();
00081     void                debug();
00082 
00084     vector <ModelObject> getBestMatchingInitialObjects (string resourceName_h, double resourceQ_h);
00085     string              getOutputDirectory() const {return outputDirname;};
00086     string              getFilenameByType(string type_h);
00087     LLData              getTable(string tableName_h, int debugLevel=MSG_CRITICAL_ERROR);
00088     vector <IFiles>     getIFilesVector() const {return iFilesVector;};
00089     string              getBaseDirectory() const {return baseDirectory;};
00090     int                 getActivitiesDefinitionVectorSize() const {return activitiesDefinitionVector.size();};
00091 
00092     vector <string>     getResourceNames(int type_h=-1) const; 
00093     int                 getResourceSize(int type_h=-1) const; 
00094     vector <string>     getObjectNames() const;
00095     vector <string>     getActivityNames() const;
00096     int                 getActGisCodeByName(string actName_h) const;
00097 
00098     int                 getIntSetting          (const string &name_h, int position=0);
00099     double              getDoubleSetting       (const string &name_h, int position=0);
00100     string              getStringSetting       (const string &name_h, int position=0);
00101     bool                getBoolSetting         (const string &name_h, int position=0);
00102     vector <int>        getIntVectorSetting    (const string &name_h);
00103     vector <double>     getDoubleVectorSetting (const string &name_h);
00104     vector <string>     getStringVectorSetting (const string &name_h);
00105     vector <bool>       getBoolVectorSetting   (const string &name_h);
00106 
00107     RegResources        getResourceByName(string name_h);
00108     ModelObject         getObjectByName(string name_h);
00109     vector<RegActivities*> getRegActivities();
00110     RegActivities*      getRegActivityByName(string name_h);
00111     vector <ModelObject*>  getObjectsDefinitionVector();
00112 
00114     vector <ModelObject> getModelObjectsBySoilType(int soilType_h);
00115 
00116     void                setOutputDirectory(const char* output_dirname_h);
00117     void                setBaseDiretory(string baseDirectory_h){baseDirectory=baseDirectory_h;};
00118     void                addSetting(string name_h, vector <string> values_h, int type_h, string comment_h);
00119     void                addSetting(string name_h, string value_h, int type_h, string comment_h);
00120 
00121     void                setBasicData(const string &name_h, int value, int position=0);
00122     void                setBasicData(const string &name_h, double value, int position=0);
00123     void                setBasicData(const string &name_h, string value, int position=0);
00124     void                setBasicData(const string &name_h, bool value, int position=0);
00125 
00126 private:
00127     string              getBaseData (const string &name_h, int type_h, int position=0);
00128     vector <string>     getVectorBaseData (const string &name_h, int type_h);
00129     void                setBasicData(const string &name_h, string value, int type_h, int position);
00130 
00131     string                                   inputFilename; // from Qt fileOpen dialog
00132     string                                   outputDirname; // from main config files
00133     string                                   baseDirectory; // from Qt fileOpen dialog
00134 
00135     // In the following vectors, when it is stated "just the topology", it means here we have just the definition of the objects, but the values may change at the agent-level. Thi is why each agent hads a "personal copy" of them
00136     vector <IFiles>                           iFilesVector;  
00137     vector <BasicData>               programSettingsVector;  
00138     vector <RegResources>        resourcesDefinitionVector;  
00139     vector <RegActivities>      activitiesDefinitionVector;  
00140     vector <ModelObject>           objectsDefinitionVector;  
00141     vector <LLData>                           LLDataVector;  
00142 
00143     vector <vector <string> >       resourcesJoinedObjects;  
00144     vector <vector <double> >  resourcesProvidedQuantities;  
00145 
00146     vector <vector <ModelObject> > availableObjectsBySoilType;
00147     InputNode                             mainDocument;  
00148     //InputNode                                     mainNode;  ///< the main input node
00149 };
00150 
00152 
00158 //Changed from a class to a structure on 2006.10.17.
00159 struct IFiles {
00160     string                                       directory;
00161     string                                            type;
00162     string                                            name;
00163     string                                         comment;
00164 };
00165 
00167 
00171 struct BasicData {
00172     string                                            name;
00174     vector <string>                                 values;
00175     int                                               type; // enum TYPE_*
00176     string                                         comment;
00177 };
00178 
00179 
00181 
00187 struct RegResources {
00188     string                                            name;
00189     string                                            unit;
00190     string                                         comment;
00191     int                                             source;
00192     int                                               type;
00193     string                                         subType;
00194 };
00195 
00197 
00204 class RegActivities: public BaseRegmas{
00205 public:
00206                         RegActivities(ThreadManager* MTHREAD_h);
00207                        ~RegActivities();
00208 
00209     string              getName() const {return activityName;};
00210     string              getComment() const {return activityComment;};
00211     double              getMatrixGrossMargin() const; //todo:get the current one!
00212     map <string, double> getMatrixActRes() const; 
00213     vector <double>     getMatrixCoefficients(); 
00214     double              getMatrixCoefficientByName(string cname_h); 
00215 
00216     bool                getSpatiallyExplicit(){return spatiallyExplicit;};
00217     vector <int>        getRequiredLandUseCodes(){return requiredLandUseCodes;};
00218     string              getRequiredObjectOnPlot(){return requiredObjectOnPlot;};
00219     int                 getMapCode() const {return mapCode;};
00220     int                 getMapRColor(){return mapRColor;};
00221     int                 getMapGColor(){return mapGColor;};
00222     int                 getMapBColor(){return mapBColor;};
00223     double              getDecouplingOption(int premiumIndex);
00224     void                setName(string activityName_h){activityName=activityName_h;};
00225     void                setComment(string activityComment_h){activityComment=activityComment_h;};
00226     friend void RegData::setDefaultActivities();
00227     friend void RegData::setScenarioActivities();
00228 
00229 private:
00230     string                          activityName;
00231     string                       activityComment;
00232     vector<double>       matrixGrossMarginByYear;
00233     vector< map<string,double> > matrixActResByYear;
00234     vector<int>             requiredLandUseCodes; 
00235     string                 requiredObjectOnPlot; 
00236     bool                       spatiallyExplicit;
00237     int                                  mapCode;    
00238     int                                mapRColor;  
00239     int                                mapGColor;  
00240     int                                mapBColor;  
00241     vector< vector<double> >             decouplingOptions;  
00242 
00243 };
00244 
00246 class LLData: public BaseRegmas{
00247 
00248 public:
00249                         LLData(ThreadManager* MTHREAD_h, string tableName_h);
00250                        ~LLData();
00251     void                clean(); // clean the data from empty headers
00252     string              getTableName(){return tableName;};
00253     int                 nrecords(){return records.size();};
00254     string              getData(int pos_h, string header_h, int debugLevel=MSG_CRITICAL_ERROR);
00255     friend void RegData::loadInput();
00256 
00257 private:
00258     string                             tableName;
00259     vector<string>                       headers;
00260     vector < vector <string> >           records;
00261 
00262 };
00263 
00264 
00265 #endif