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 <algorithm> 00021 00022 #include "SuperAgentManager.h" 00023 #include "agents/Manager_farmers.h" 00024 #include "ThreadManager.h" 00025 00030 SuperAgentManager::SuperAgentManager(ThreadManager* MTHREAD_h){ 00031 //I have to write it specifically as it is a field of the base class.. 00032 MTHREAD=MTHREAD_h; 00033 uniqueAgentIDCounter=0; 00034 uniqueManagerIDCounter=0; 00035 00036 } 00037 00038 SuperAgentManager::~SuperAgentManager(){ 00039 for (uint i=0; i< managers.size();i++){ 00040 delete managers[i]; 00041 } 00042 } 00043 00044 // ************************************************************************** 00045 vector<string> 00046 SuperAgentManager::getAgentTypeNames(){ 00047 vector<string> toReturn; 00048 for (uint i=0; i<managers.size(); i++){ 00049 toReturn.push_back(managers.at(i)->getName()); 00050 } 00051 return toReturn; 00052 } 00053 00054 vector<int> 00055 SuperAgentManager::getAgentCountByType(){ 00056 vector<int> toReturn; 00057 for (uint i=0; i<managers.size(); i++){ 00058 toReturn.push_back(managers.at(i)->countMyAgents()); 00059 } 00060 return toReturn; 00061 } 00062 00063 void 00064 SuperAgentManager::setAgentMoulds(){ 00065 for (uint i=0; i<managers.size(); i++){ 00066 managers.at(i)->setAgentMoulds(); 00067 } 00068 } 00069 00070 void 00071 SuperAgentManager::rescaleMoulds(double factor_h){ 00072 for (uint i=0; i<managers.size(); i++){ 00073 managers.at(i)->rescaleMoulds(factor_h); 00074 } 00075 } 00076 00077 void 00078 SuperAgentManager::assignObjectsToAgents(){ 00079 for (uint i=0; i<managers.size(); i++){ 00080 managers.at(i)->assignObjectsToAgents(); 00081 } 00082 } 00083 00084 void 00085 SuperAgentManager::assignSpatialObjectsToAgents(){ 00086 for (uint i=0; i<managers.size(); i++){ 00087 managers.at(i)->assignSpatialObjectsToAgents(); 00088 } 00089 } 00090 00091 void 00092 SuperAgentManager::populateAgents(){ 00093 for (uint i=0; i<managers.size(); i++){ 00094 managers.at(i)->riseMyAgents(); 00095 } 00096 } 00097 00098 void 00099 SuperAgentManager::locate(){ 00100 for (uint i=0; i<managers.size(); i++){ 00101 managers.at(i)->locateMyAgents(); 00102 } 00103 } 00104 00105 void 00106 SuperAgentManager::createBehaviours(){ 00107 for (uint i=0; i<managers.size(); i++){ 00108 managers.at(i)->createBehaviours(); 00109 } 00110 } 00111 00112 void 00113 SuperAgentManager::endInit(){ 00114 for (uint i=0; i<managers.size(); i++){ 00115 managers.at(i)->endInit(); 00116 } 00117 } 00118 00119 void 00120 SuperAgentManager::prepare(){ 00121 for (uint i=0; i<managers.size(); i++){ 00122 managers.at(i)->prepare(); 00123 } 00124 } 00125 00126 void 00127 SuperAgentManager::act(){ 00128 for (uint i=0; i<managers.size(); i++){ 00129 managers.at(i)->act(); 00130 } 00131 } 00132 00133 void 00134 SuperAgentManager::update(){ 00135 00136 // perform agent independent update.. 00137 for(int i=0;i<MTHREAD->GIS->getXNPixels();i++){ 00138 MTHREAD->GIS->getPixel(i)->newYear(); 00139 } 00140 00141 for (uint i=0; i<managers.size(); i++){ 00142 managers.at(i)->update(); 00143 } 00144 } 00145 00146 void 00147 SuperAgentManager::planNext(){ 00148 for (uint i=0; i<managers.size(); i++){ 00149 managers.at(i)->planNext(); 00150 } 00151 } 00152 00153 vector <Agent_base*> 00154 SuperAgentManager::getAgentsByType(bool onlySpatial, string category_h){ 00155 vector <Agent_base*> toReturn; 00156 for (uint i=0; i<managers.size(); i++){ 00157 if(managers.at(i)->getName() == category_h || category_h==""){ 00158 if( dynamic_cast<Manager_space*> (managers.at(i)) || !onlySpatial){ 00159 vector <Agent_base*> agents= managers.at(i)->getMyAgents(); 00160 copy (agents.begin(), agents.end(), back_inserter(toReturn)); 00161 } 00162 } 00163 } 00164 return toReturn; 00165 }