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