Scheduler.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 "Scheduler.h"
00021 #include "ModelObject.h" // if I include regData I have problems. I have to include ModelObject that at its top include RegData.
00022 #include "SuperAgentManager.h"
00023 #include "ThreadManager.h"
00024 #include "Output.h"
00025 
00026 Scheduler::Scheduler(ThreadManager* MTHREAD_h){
00027     MTHREAD=MTHREAD_h;
00028     iteration=0;
00029 };
00030 
00031 Scheduler::~Scheduler(){
00032 };
00033 
00034 void
00035 Scheduler::run(){
00036 
00037     for (int it=0;it<MTHREAD->RD->getIntSetting("simulationYears");it++){
00038         iteration = it;
00039         MTHREAD->upgradeMainSBLabel("New year started..");
00040         msgOut(MSG_INFO, "### "+i2s(getYear())+ " year started.. ####");
00041         MTHREAD->upgradeYearSBLabel(iteration+ MTHREAD->RD->getIntSetting("initialYear"));
00042         MTHREAD->treeViewerChangeGeneralPropertyValue("year",i2s(iteration+ MTHREAD->RD->getIntSetting("initialYear")));
00043 
00044         MTHREAD->SAM->prepare();
00045 
00046         vector<double> landStats = MTHREAD->GIS->getAgrLandStats();
00047         MTHREAD->treeViewerChangeGeneralPropertyValue("total agr land", d2s(landStats.at(0)));
00048         MTHREAD->treeViewerChangeGeneralPropertyValue("owned agr land", d2s(landStats.at(1)));
00049         MTHREAD->treeViewerChangeGeneralPropertyValue("rented agr land", d2s(landStats.at(2)));
00050 
00051         MTHREAD->GIS->calculateDistancesToClosestFarm();
00052 
00053         MTHREAD->SAM->act();
00054 
00055         MTHREAD->DO->collectData();
00056         MTHREAD->DO->print();
00057 
00058         for(int i=0;i<MTHREAD->GIS->getXNPixels();i++){
00059             MTHREAD->GIS->getPixel(i)->newYear(); //delete objects for the pixels, in the update the agents will do the same for their objects
00060         }
00061         MTHREAD->SAM->update();
00062 
00063         MTHREAD->SAM->planNext();
00064         MTHREAD->GIS->updateImage("farmsteads");      // update for agents that may have left
00065         MTHREAD->GIS->updateImage("farmOwnedPlots");  // idem
00066         MTHREAD->GIS->updateImage("farmRentedPlots"); // idem
00067     }
00068 }
00069 
00070 int
00071 Scheduler::getYear(){
00072     return (iteration+MTHREAD->RD->getIntSetting("initialYear"));
00073 }