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-2017 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 /****************************************************************************/
7 //
8 // This program and the accompanying materials
9 // are made available under the terms of the Eclipse Public License v2.0
10 // which accompanies this distribution, and is available at
11 // http://www.eclipse.org/legal/epl-v20.html
12 //
13 /****************************************************************************/
22 // Location and schedules of a work position: linked with one adult
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "AGWorkPosition.h"
36 #include "AGStreet.h"
37 #include "AGPosition.h"
38 #include "AGDataAndStatistics.h"
39 #include "AGAdult.h"
41 #include <iostream>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  myStatData(ds),
49  myLocation(inStreet),
50  myAdult(0),
51  myOpeningTime(generateOpeningTime(*ds)),
52  myClosingTime(generateClosingTime(*ds)) {
53  ds->workPositions++;
54 }
55 
56 
57 AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet, double pos) :
58  myStatData(ds),
59  myLocation(inStreet, pos),
60  myAdult(0),
63  ds->workPositions++;
64 }
65 
67 // let();
68 }
69 
70 
71 void
73  std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl;
74  std::cout << "\t";
75  myLocation.print();
76 }
77 
78 
79 int
81  double choice = RandHelper::rand();
82  double cumul = 0;
83 
84  for (std::map<int, double>::const_iterator it = ds.beginWorkHours.begin();
85  it != ds.beginWorkHours.end(); ++it) {
86  cumul += it->second;
87  if (cumul >= choice) {
88  return it->first;
89  }
90  }
91  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl;
92  return 900;
93 }
94 
95 
96 int
98  double choice = RandHelper::rand();
99  double cumul = 0;
100  for (std::map<int, double>::const_iterator it = ds.endWorkHours.begin();
101  it != ds.endWorkHours.end(); ++it) {
102  cumul += it->second;
103  if (cumul >= choice) {
104  return it->first;
105  }
106  }
107  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl;
108  return 1700;
109 }
110 
111 
112 bool
114  return (myAdult != 0);
115 }
116 
117 
118 void
120  if (myAdult != 0) {
123  myAdult = 0;
124  }
125 }
126 
127 
128 void
130  if (myAdult == 0) {
132  myAdult = worker;
133  } else {
134  throw (std::runtime_error("Work position already occupied. Cannot give it to another adult."));
135  }
136 }
137 
138 
141  return myLocation;
142 }
143 
144 
145 int
147  return myClosingTime;
148 }
149 
150 
151 int
153  return myOpeningTime;
154 }
155 
156 /****************************************************************************/
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:64
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:62
A model of the street in the city.
Definition: AGStreet.h:59
AGWorkPosition(AGDataAndStatistics *ds, const AGStreet &inStreet)
bool isTaken() const
int getClosing() const
An adult person who can have a job.
Definition: AGAdult.h:57
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:97
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:57
AGDataAndStatistics * myStatData
static int generateClosingTime(const AGDataAndStatistics &ds)
void print() const