Line data Source code
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 : /****************************************************************************/
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 0 : AGChild::print() const {
40 0 : std::cout << "- Child: Age=" << age << " School=" << mySchool << std::endl;
41 0 : }
42 :
43 : bool
44 760 : AGChild::setSchool(AGSchool* school) {
45 760 : if (school == nullptr) {
46 : return false;
47 : }
48 760 : bool enoughPlace = school->addNewChild();
49 760 : if (enoughPlace) {
50 760 : mySchool = school;
51 : }
52 : return enoughPlace;
53 : }
54 :
55 : bool
56 760 : AGChild::allocateASchool(std::list<AGSchool>* schools, AGPosition housePos) {
57 : double minDist = std::numeric_limits<double>::infinity();
58 : AGSchool* sch = nullptr;
59 760 : if (schools->size() == 0) {
60 : return false;
61 : }
62 : std::list<AGSchool>::iterator it;
63 :
64 3040 : for (it = schools->begin(); it != schools->end(); ++it) {
65 4560 : if (it->acceptThisAge(age) && it->getPlaces() > 0 && housePos.distanceTo(it->getPosition()) < minDist) {
66 958 : minDist = housePos.distanceTo(it->getPosition());
67 : sch = &(*it);
68 : }
69 : }
70 760 : return setSchool(sch);
71 : }
72 :
73 : bool
74 0 : AGChild::leaveSchool() {
75 0 : if (mySchool != nullptr)
76 0 : if (!mySchool->removeChild()) {
77 : return false;
78 : }
79 0 : mySchool = nullptr;
80 0 : return true;
81 : }
82 :
83 : bool
84 570 : AGChild::haveASchool() const {
85 570 : return (mySchool != nullptr);
86 : }
87 :
88 : AGPosition
89 718 : AGChild::getSchoolLocation() const {
90 718 : return mySchool->getPosition();
91 : }
92 :
93 : int
94 0 : AGChild::getSchoolClosing() const {
95 0 : return mySchool->getClosingHour();
96 : }
97 :
98 : int
99 74 : AGChild::getSchoolOpening() const {
100 74 : return mySchool->getOpeningHour();
101 : }
102 :
103 :
104 : /****************************************************************************/
|