Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/city/AGChild.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2010-2025 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
/****************************************************************************/
16
/// @file AGChild.cpp
17
/// @author Piotr Woznica
18
/// @author Daniel Krajzewicz
19
/// @author Michael Behrisch
20
/// @author Walter Bamberger
21
/// @author Michael Behrisch
22
/// @date July 2010
23
///
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
44
AGChild::setSchool(AGSchool* school) {
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
74
AGChild::leaveSchool() {
75
if (mySchool != nullptr)
76
if (!mySchool->removeChild()) {
77
return false;
78
}
79
mySchool = nullptr;
80
return true;
81
}
82
83
bool
84
AGChild::haveASchool() const {
85
return (mySchool != nullptr);
86
}
87
88
AGPosition
89
AGChild::getSchoolLocation() const {
90
return mySchool->getPosition();
91
}
92
93
int
94
AGChild::getSchoolClosing() const {
95
return mySchool->getClosingHour();
96
}
97
98
int
99
AGChild::getSchoolOpening() const {
100
return mySchool->getOpeningHour();
101
}
102
103
104
/****************************************************************************/
105
106