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 "ModelObject.h" 00021 #include "ThreadManager.h" 00022 #include "Scheduler.h" 00023 00024 ModelObject::ModelObject(ThreadManager* MTHREAD_h){ 00025 MTHREAD = MTHREAD_h; 00026 owner=NULL; 00027 user=NULL; 00028 startYear=-1; 00029 requiredFor = ""; 00030 } 00031 00032 ModelObject::~ModelObject(){ 00033 } 00034 00035 double 00036 ModelObject::getResourceValue(string resourceName_h){ 00037 map<string, double>::iterator p; 00038 p=matrixObjRes.find(resourceName_h); 00039 if(p != matrixObjRes.end()) 00040 return p->second; 00041 return 0; 00042 } 00043 00048 void 00049 ModelObject::setRandomAge(){ 00050 int currentAge = int (1+( (double)rand() / ((double)(RAND_MAX)+(double)(1)) )* (lifeTerm-1)); // [1,lifeterm-1] 00051 startYear = MTHREAD->SCD->getYear()-currentAge; 00052 } 00053 00054 vector <double> 00055 ModelObject::getMatrixCoefficients(){ 00056 vector <string> resourceNames= MTHREAD->RD->getResourceNames(); 00057 vector <double> toReturn; 00058 for (uint i=0;i<resourceNames.size();i++){ 00059 map <string,double>::iterator p; 00060 p=matrixObjRes.find(resourceNames.at(i)); 00061 if(p != matrixObjRes.end()) 00062 toReturn.push_back(p->second); 00063 else 00064 toReturn.push_back(0); 00065 } 00066 return toReturn; 00067 } 00068 00069 double 00070 ModelObject::getCurrentValue(bool endOfYear){ 00071 if(!endOfYear) 00072 return initialCost * (1-( ( (double) getAge() ) / ( (double)lifeTerm) )); // DONE: check!! ..and thanks I checked !!!!! 00073 else 00074 return initialCost * (1-( ( (double) getAge() +1 ) / ( (double)lifeTerm) )); 00075 return 0; 00076 } 00077 00078 int 00079 ModelObject::getAge(){ 00080 return MTHREAD->SCD->getYear()-startYear; 00081 }