Eclipse SUMO - Simulation of Urban MObility
AGWorkPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 /****************************************************************************/
23 // Location and schedules of a work position: linked with one adult
24 /****************************************************************************/
25 #include <config.h>
26 
27 #include "AGWorkPosition.h"
28 #include "AGStreet.h"
29 #include "AGPosition.h"
30 #include "AGDataAndStatistics.h"
31 #include "AGAdult.h"
33 #include <iostream>
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
40  myStatData(ds),
41  myLocation(inStreet),
42  myAdult(nullptr),
43  myOpeningTime(generateOpeningTime(*ds)),
44  myClosingTime(generateClosingTime(*ds)) {
45  ds->workPositions++;
46 }
47 
48 
49 AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet, double pos) :
50  myStatData(ds),
51  myLocation(inStreet, pos),
52  myAdult(nullptr),
53  myOpeningTime(generateOpeningTime(*ds)),
54  myClosingTime(generateClosingTime(*ds)) {
55  ds->workPositions++;
56 }
57 
59 // let();
60 }
61 
62 
63 void
65  std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl;
66  std::cout << "\t";
67  myLocation.print();
68 }
69 
70 
71 int
73  double choice = RandHelper::rand();
74  double cumul = 0;
75 
76  for (std::map<int, double>::const_iterator it = ds.beginWorkHours.begin();
77  it != ds.beginWorkHours.end(); ++it) {
78  cumul += it->second;
79  if (cumul >= choice) {
80  return it->first;
81  }
82  }
83  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl;
84  return 900;
85 }
86 
87 
88 int
90  double choice = RandHelper::rand();
91  double cumul = 0;
92  for (std::map<int, double>::const_iterator it = ds.endWorkHours.begin();
93  it != ds.endWorkHours.end(); ++it) {
94  cumul += it->second;
95  if (cumul >= choice) {
96  return it->first;
97  }
98  }
99  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl;
100  return 1700;
101 }
102 
103 
104 bool
106  return (myAdult != nullptr);
107 }
108 
109 
110 void
112  if (myAdult != nullptr) {
115  myAdult = nullptr;
116  }
117 }
118 
119 
120 void
122  if (myAdult == nullptr) {
124  myAdult = worker;
125  } else {
126  throw (std::runtime_error("Work position already occupied. Cannot give it to another adult."));
127  }
128 }
129 
130 
133  return myLocation;
134 }
135 
136 
137 int
139  return myClosingTime;
140 }
141 
142 
143 int
145  return myOpeningTime;
146 }
147 
148 
149 /****************************************************************************/
An adult person who can have a job.
Definition: AGAdult.h:48
void lostWorkPosition()
Called when the adult has lost her job.
Definition: AGAdult.cpp:89
std::map< int, double > endWorkHours
std::map< int, double > beginWorkHours
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:53
void print() const
Prints out a summary of the properties of this class on standard output.
Definition: AGPosition.cpp:49
A model of the street in the city.
Definition: AGStreet.h:50
static int generateOpeningTime(const AGDataAndStatistics &ds)
static int generateClosingTime(const AGDataAndStatistics &ds)
int getClosing() const
int getOpening() const
AGAdult * myAdult
AGPosition getPosition() const
void take(AGAdult *ad)
AGPosition myLocation
void print() const
AGDataAndStatistics * myStatData
bool isTaken() const
AGWorkPosition(AGDataAndStatistics *ds, const AGStreet &inStreet)
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:51