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.org/sumo
3 // Copyright (C) 2010-2019 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
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
21 // Person in age to go to school: linked to a school object
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <iostream>
31 #include <vector>
32 #include <limits>
33 #include "AGChild.h"
34 #include "AGSchool.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 void
41 AGChild::print() const {
42  std::cout << "- Child: Age=" << age << " School=" << school << std::endl;
43 }
44 
45 bool
47  if (school == nullptr) {
48  return false;
49  }
50  bool enoughPlace = school->addNewChild();
51  if (enoughPlace) {
52  this->school = school;
53  }
54  return enoughPlace;
55 }
56 
57 bool
58 AGChild::allocateASchool(std::list<AGSchool>* schools, AGPosition housePos) {
59  double minDist = std::numeric_limits<double>::infinity();
60  AGSchool* sch = nullptr;
61  if (schools->size() == 0) {
62  return false;
63  }
64  std::list<AGSchool>::iterator it;
65 
66  for (it = schools->begin(); it != schools->end(); ++it) {
67  if (it->acceptThisAge(age) && it->getPlaces() > 0 && housePos.distanceTo(it->getPosition()) < minDist) {
68  minDist = housePos.distanceTo(it->getPosition());
69  sch = &(*it);
70  }
71  }
72  return setSchool(sch);
73 }
74 
75 bool
77  if (school != nullptr)
78  if (!school->removeChild()) {
79  return false;
80  }
81  school = nullptr;
82  return true;
83 }
84 
85 bool
87  return (school != nullptr);
88 }
89 
92  return school->getPosition();
93 }
94 
95 int
97  return school->getClosingHour();
98 }
99 
100 int
102  return school->getOpeningHour();
103 }
104 
105 /****************************************************************************/
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:56
bool addNewChild()
Definition: AGSchool.cpp:48
AGPosition getPosition()
Definition: AGSchool.cpp:84
bool leaveSchool()
Definition: AGChild.cpp:76
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:63
bool removeChild()
Definition: AGSchool.cpp:57
bool setSchool(AGSchool *school)
Definition: AGChild.cpp:46
AGPosition getSchoolLocation() const
Definition: AGChild.cpp:91
int getOpeningHour()
Definition: AGSchool.cpp:94
bool allocateASchool(std::list< AGSchool > *schools, AGPosition housePos)
Definition: AGChild.cpp:58
AGSchool * school
Definition: AGChild.h:64
int getClosingHour()
Definition: AGSchool.cpp:89
void print() const
Puts out a summary of the class properties.
Definition: AGChild.cpp:41
int getSchoolOpening() const
Definition: AGChild.cpp:101
bool haveASchool() const
Definition: AGChild.cpp:86
int age
Definition: AGPerson.h:65
int getSchoolClosing() const
Definition: AGChild.cpp:96