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