Init.cpp

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 #include <time.h> // we only use this to seed the random number generator
00021 
00022 #include "Init.h"
00023 //#include "Pixel.h"
00024 #include "Scheduler.h"
00025 #include "ThreadManager.h"
00026 #include "Output.h"
00027 #include "agents/Manager_farmers.h"
00028 
00029 //using namespace std;
00030 
00031 Init::Init(ThreadManager* MTHREAD_h){
00032     MTHREAD=MTHREAD_h;
00033     InitState=0;
00034 };
00035 
00036 Init::~Init()
00037 {
00038 };
00039 
00040 void
00041 Init::setInitLevel(int level_h){
00042 
00043     switch (level_h){
00044         case 0:
00045             this->setInitLevel0();
00046             break;
00047         case 1:
00048             this->setInitLevel1();
00049             break;
00050         case 2:
00051             this->setInitLevel2();
00052             break;
00053         case 3:
00054             this->setInitLevel3();
00055             break;
00056         case 4:
00057             this->setInitLevel4();
00058             break;
00059         case 5:
00060             this->setInitLevel5();
00061             break;
00062         case 6:
00063             this->setInitLevel6();
00064             break;
00065         default:
00066             msgOut(MSG_ERROR,"unexpected Init level");
00067         }   
00068 };
00069 
00070 void
00071 Init::setInitLevel0(){
00072     //unused now
00073     InitState=0;
00074 };
00075 
00089 void
00090 Init::setInitLevel1(){
00091     //Loading data from file.
00092     InitState=1;
00093     ostringstream out;
00094     out<<"OK, Entering Init state "<<InitState<<"...";
00095     msgOut(MSG_DEBUG,out.str());
00096     MTHREAD->RD->setDefaultSettings();
00097     MTHREAD->RD->setScenarioSettings();
00098     if(MTHREAD->RD->getBoolSetting("randomSimulation")){
00099         srand(time(NULL));
00100     }
00101     MTHREAD->RD->setResources();
00102     MTHREAD->RD->setDefaultActivities();
00103     MTHREAD->RD->setScenarioActivities();
00104     MTHREAD->RD->setObjectsDefinitions();
00105     MTHREAD->RD->initializeResourcesObjectsMatch(); // cache values
00106     MTHREAD->RD->initializeSpacialObjectsMatch();   // cache values
00107     MTHREAD->GIS->setSpace();
00108 
00111     // IMPORTANT: For each new agent_type, remember to load it in the vector of managers!!!
00112     Manager_farmers* FARMERM = new Manager_farmers(MTHREAD, "farmer"); // the manager for farm agents
00113     MTHREAD->SAM->addManager(FARMERM);
00114 
00115     // ***************************************************************** //
00116 
00117     MTHREAD->SAM->setAgentMoulds();
00118     if(MTHREAD->RD->getBoolSetting("subRegionMode")){
00119         MTHREAD->SAM->rescaleMoulds(MTHREAD->RD->getDoubleSetting("scaleCoeff"));
00120     }
00121     MTHREAD->SAM->populateAgents();
00122 };
00123 
00124 void
00125 Init::setInitLevel2(){
00126     InitState=2;
00127 };
00128 
00133 void
00134 Init::setInitLevel3(){
00135     InitState=3;
00136     MTHREAD->SAM->locate();
00137     MTHREAD->SAM->assignObjectsToAgents();        // this is made my manager_base
00138     MTHREAD->SAM->assignSpatialObjectsToAgents(); // this is  specific of manager_space managers
00139     MTHREAD->SAM->createBehaviours();             // create the farmer behaviours
00140     MTHREAD->DO->initOutput();                    // initialize the output files
00141     MTHREAD->SAM->endInit();                      // if u have to do something before the simulation start, do it now!
00142 };
00143 
00144 void
00145 Init::setInitLevel4(){
00146     InitState=4;
00147 };
00148 
00153 void
00154 Init::setInitLevel5(){
00155     InitState=5;
00156 
00157     vector<double> landStats = MTHREAD->GIS->getAgrLandStats();
00158     MTHREAD->treeViewerChangeGeneralPropertyValue("total agr land", d2s(landStats.at(0)));
00159     MTHREAD->treeViewerChangeGeneralPropertyValue("owned agr land", d2s(landStats.at(1)));
00160     MTHREAD->treeViewerChangeGeneralPropertyValue("rented agr land", d2s(landStats.at(2)));
00161 
00162     MTHREAD->SCD->run(); // !!!! go "bello" !!!! start the simulation !!!!!
00163 };
00164 
00165 void
00166 Init::setInitLevel6(){
00167     InitState=6;
00168     msgOut(MSG_INFO, "Model has ended scheduled simulation in a regular way.");
00169 };
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177