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