SUMO - Simulation of Urban MObility
AGWorkPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Location and schedules of a work position: linked with one adult
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 // activitygen module
15 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include "AGWorkPosition.h"
37 #include "AGStreet.h"
38 #include "AGPosition.h"
39 #include "AGDataAndStatistics.h"
40 #include "AGAdult.h"
42 #include <iostream>
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  myStatData(ds),
50  myLocation(inStreet),
51  myAdult(0),
52  myOpeningTime(generateOpeningTime(*ds)),
53  myClosingTime(generateClosingTime(*ds)) {
54  ds->workPositions++;
55 }
56 
57 
59  myStatData(ds),
60  myLocation(inStreet, pos),
61  myAdult(0),
64  ds->workPositions++;
65 }
66 
68 // let();
69 }
70 
71 
72 void
74  std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl;
75  std::cout << "\t";
76  myLocation.print();
77 }
78 
79 
80 int
82  SUMOReal choice = RandHelper::rand();
83  SUMOReal cumul = 0;
84 
85  for (std::map<int, SUMOReal>::const_iterator it = ds.beginWorkHours.begin();
86  it != ds.beginWorkHours.end(); ++it) {
87  cumul += it->second;
88  if (cumul >= choice) {
89  return it->first;
90  }
91  }
92  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl;
93  return 900;
94 }
95 
96 
97 int
99  SUMOReal choice = RandHelper::rand();
100  SUMOReal cumul = 0;
101  for (std::map<int, SUMOReal>::const_iterator it = ds.endWorkHours.begin();
102  it != ds.endWorkHours.end(); ++it) {
103  cumul += it->second;
104  if (cumul >= choice) {
105  return it->first;
106  }
107  }
108  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl;
109  return 1700;
110 }
111 
112 
113 bool
115  return (myAdult != 0);
116 }
117 
118 
119 void
121  if (myAdult != 0) {
124  myAdult = 0;
125  }
126 }
127 
128 
129 void
131  if (myAdult == 0) {
133  myAdult = worker;
134  } else {
135  throw(std::runtime_error("Work position already occupied. Cannot give it to another adult."));
136  }
137 }
138 
139 
142  return myLocation;
143 }
144 
145 
146 int
148  return myClosingTime;
149 }
150 
151 
152 int
154  return myOpeningTime;
155 }
156 
157 /****************************************************************************/
AGPosition myLocation
void print() const
Prints out a summary of the properties of this class on standard output.
Definition: AGPosition.cpp:58
void take(AGAdult *ad)
int getOpening() const
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
void print() const
std::map< int, SUMOReal > endWorkHours
A model of the street in the city.
Definition: AGStreet.h:60
int getClosing() const
bool isTaken() const
AGWorkPosition(AGDataAndStatistics *ds, const AGStreet &inStreet)
An adult person who can have a job.
Definition: AGAdult.h:58
void lostWorkPosition()
Called when the adult has lost her job.
Definition: AGAdult.cpp:101
std::map< int, SUMOReal > beginWorkHours
AGAdult * myAdult
AGPosition getPosition() const
static int generateOpeningTime(const AGDataAndStatistics &ds)
#define SUMOReal
Definition: config.h:214
AGDataAndStatistics * myStatData
static int generateClosingTime(const AGDataAndStatistics &ds)