|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Person in age to go to school: linked to a school object 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 // activitygen module 00012 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00013 /****************************************************************************/ 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; either version 2 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <iostream> 00033 #include <vector> 00034 #include <limits> 00035 #include "AGChild.h" 00036 #include "AGSchool.h" 00037 00038 00039 // =========================================================================== 00040 // method definitions 00041 // =========================================================================== 00042 void 00043 AGChild::print() { 00044 std::cout << "- Child: Age=" << age << " School=" << school << std::endl; 00045 } 00046 00047 bool 00048 AGChild::setSchool(AGSchool* school) { 00049 if (school == NULL) { 00050 return false; 00051 } 00052 bool enoughPlace = school->addNewChild(); 00053 if (enoughPlace) { 00054 this->school = school; 00055 } 00056 return enoughPlace; 00057 } 00058 00059 bool 00060 AGChild::alocateASchool(std::list<AGSchool> *schools, AGPosition housePos) { 00061 SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity(); 00062 AGSchool* sch = NULL; 00063 if (schools->size() == 0) { 00064 return false; 00065 } 00066 std::list<AGSchool>::iterator it; 00067 00068 for (it = schools->begin() ; it!=schools->end() ; ++it) { 00069 if (it->acceptThisAge(age) && it->getPlaces()>0 && housePos.distanceTo(it->getPosition()) < minDist) { 00070 minDist = housePos.distanceTo(it->getPosition()); 00071 sch = &(*it); 00072 } 00073 } 00074 return setSchool(sch); 00075 } 00076 00077 bool 00078 AGChild::leaveSchool() { 00079 if (school != NULL) 00080 if (!school->removeChild()) { 00081 return false; 00082 } 00083 school = NULL; 00084 return true; 00085 } 00086 00087 bool 00088 AGChild::haveASchool() { 00089 if (school == NULL) { 00090 return false; 00091 } 00092 return true; 00093 } 00094 00095 AGPosition 00096 AGChild::getSchoolLocation() { 00097 return school->getPosition(); 00098 } 00099 00100 int 00101 AGChild::getSchoolClosing() { 00102 return school->getClosingHour(); 00103 } 00104 00105 int 00106 AGChild::getSchoolOpeining() { 00107 return school->getOpeningHour(); 00108 } 00109 00110 /****************************************************************************/