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