Eclipse 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.dev/sumo
3 // Copyright (C) 2010-2024 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 // This program and the accompanying materials are made available under the
7 // terms of the Eclipse Public License 2.0 which is available at
8 // https://www.eclipse.org/legal/epl-2.0/
9 // This Source Code may also be made available under the following Secondary
10 // Licenses when the conditions for such availability set forth in the Eclipse
11 // Public License 2.0 are satisfied: GNU General Public License, version 2
12 // or later which is available at
13 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15 /****************************************************************************/
24 // Person in age to go to school: linked to a school object
25 /****************************************************************************/
26 #include <config.h>
27 
28 #include <iostream>
29 #include <vector>
30 #include <limits>
31 #include "AGChild.h"
32 #include "AGSchool.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 void
39 AGChild::print() const {
40  std::cout << "- Child: Age=" << age << " School=" << mySchool << std::endl;
41 }
42 
43 bool
45  if (school == nullptr) {
46  return false;
47  }
48  bool enoughPlace = school->addNewChild();
49  if (enoughPlace) {
50  mySchool = school;
51  }
52  return enoughPlace;
53 }
54 
55 bool
56 AGChild::allocateASchool(std::list<AGSchool>* schools, AGPosition housePos) {
57  double minDist = std::numeric_limits<double>::infinity();
58  AGSchool* sch = nullptr;
59  if (schools->size() == 0) {
60  return false;
61  }
62  std::list<AGSchool>::iterator it;
63 
64  for (it = schools->begin(); it != schools->end(); ++it) {
65  if (it->acceptThisAge(age) && it->getPlaces() > 0 && housePos.distanceTo(it->getPosition()) < minDist) {
66  minDist = housePos.distanceTo(it->getPosition());
67  sch = &(*it);
68  }
69  }
70  return setSchool(sch);
71 }
72 
73 bool
75  if (mySchool != nullptr)
76  if (!mySchool->removeChild()) {
77  return false;
78  }
79  mySchool = nullptr;
80  return true;
81 }
82 
83 bool
85  return (mySchool != nullptr);
86 }
87 
90  return mySchool->getPosition();
91 }
92 
93 int
95  return mySchool->getClosingHour();
96 }
97 
98 int
100  return mySchool->getOpeningHour();
101 }
102 
103 
104 /****************************************************************************/
bool haveASchool() const
Definition: AGChild.cpp:84
AGSchool * mySchool
Definition: AGChild.h:61
bool allocateASchool(std::list< AGSchool > *schools, AGPosition housePos)
Definition: AGChild.cpp:56
bool setSchool(AGSchool *school)
Definition: AGChild.cpp:44
bool leaveSchool()
Definition: AGChild.cpp:74
int getSchoolOpening() const
Definition: AGChild.cpp:99
AGPosition getSchoolLocation() const
Definition: AGChild.cpp:89
void print() const
Puts out a summary of the class properties.
Definition: AGChild.cpp:39
int getSchoolClosing() const
Definition: AGChild.cpp:94
int age
Definition: AGPerson.h:62
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:53
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:61
int getClosingHour()
Definition: AGSchool.cpp:87
bool removeChild()
Definition: AGSchool.cpp:55
AGPosition getPosition()
Definition: AGSchool.cpp:82
int getOpeningHour()
Definition: AGSchool.cpp:92
bool addNewChild()
Definition: AGSchool.cpp:46