SUMO - Simulation of Urban MObility
AGChild.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-2017 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 /****************************************************************************/
7 //
8 // This program and the accompanying materials
9 // are made available under the terms of the Eclipse Public License v2.0
10 // which accompanies this distribution, and is available at
11 // http://www.eclipse.org/legal/epl-v20.html
12 //
13 /****************************************************************************/
23 // Person in age to go to school: linked to a school object
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
47 AGChild::print() const {
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  double minDist = std::numeric_limits<double>::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 /****************************************************************************/
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:62
bool addNewChild()
Definition: AGSchool.cpp:54
AGPosition getPosition()
Definition: AGSchool.cpp:90
bool leaveSchool()
Definition: AGChild.cpp:82
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:69
bool removeChild()
Definition: AGSchool.cpp:63
bool setSchool(AGSchool *school)
Definition: AGChild.cpp:52
AGPosition getSchoolLocation() const
Definition: AGChild.cpp:97
int getOpeningHour()
Definition: AGSchool.cpp:100
bool allocateASchool(std::list< AGSchool > *schools, AGPosition housePos)
Definition: AGChild.cpp:64
AGSchool * school
Definition: AGChild.h:70
int getClosingHour()
Definition: AGSchool.cpp:95
void print() const
Puts out a summary of the class properties.
Definition: AGChild.cpp:47
int getSchoolOpening() const
Definition: AGChild.cpp:107
bool haveASchool() const
Definition: AGChild.cpp:92
int age
Definition: AGPerson.h:71
int getSchoolClosing() const
Definition: AGChild.cpp:102