SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AGChild.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Person in age to go to school: linked to a school object
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 // activitygen module
15 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <iostream>
37 #include <vector>
38 #include <limits>
39 #include "AGChild.h"
40 #include "AGSchool.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 void
48  std::cout << "- Child: Age=" << age << " School=" << school << std::endl;
49 }
50 
51 bool
53  if (school == NULL) {
54  return false;
55  }
56  bool enoughPlace = school->addNewChild();
57  if (enoughPlace) {
58  this->school = school;
59  }
60  return enoughPlace;
61 }
62 
63 bool
64 AGChild::allocateASchool(std::list<AGSchool>* schools, AGPosition housePos) {
65  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
66  AGSchool* sch = NULL;
67  if (schools->size() == 0) {
68  return false;
69  }
70  std::list<AGSchool>::iterator it;
71 
72  for (it = schools->begin(); it != schools->end(); ++it) {
73  if (it->acceptThisAge(age) && it->getPlaces() > 0 && housePos.distanceTo(it->getPosition()) < minDist) {
74  minDist = housePos.distanceTo(it->getPosition());
75  sch = &(*it);
76  }
77  }
78  return setSchool(sch);
79 }
80 
81 bool
83  if (school != NULL)
84  if (!school->removeChild()) {
85  return false;
86  }
87  school = NULL;
88  return true;
89 }
90 
91 bool
93  return (school != NULL);
94 }
95 
98  return school->getPosition();
99 }
100 
101 int
103  return school->getClosingHour();
104 }
105 
106 int
108  return school->getOpeningHour();
109 }
110 
111 /****************************************************************************/