SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
13 // Copyright (C) 2001-2012 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  location(inStreet),
50  openingTime(generateOpeningTime(*ds)),
51  closingTime(generateClosingTime(*ds)),
52  ds(ds),
53  adult(0) {
54  ds->workPositions++;
55 }
56 
57 /****************************************************************************/
58 
60  location(inStreet, pos),
61  openingTime(generateOpeningTime(*ds)),
62  closingTime(generateClosingTime(*ds)),
63  ds(ds),
64  adult(0) {
65  ds->workPositions++;
66 }
67 
69 // let();
70 }
71 
72 /****************************************************************************/
73 
74 void
76  std::cout << "- AGWorkPosition: open=" << openingTime << " closingTime=" << closingTime << " taken=" << isTaken() << std::endl;
77  std::cout << "\t";
78  location.print();
79 }
80 
81 /****************************************************************************/
82 
83 int
85  SUMOReal choice = RandHelper::rand();
86  SUMOReal cumul = 0;
87 
88  for (std::map<int, SUMOReal>::const_iterator it = ds.beginWorkHours.begin();
89  it != ds.beginWorkHours.end(); ++it) {
90  cumul += it->second;
91  if (cumul >= choice) {
92  return it->first;
93  }
94  }
95  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl;
96  return 900;
97 }
98 
99 /****************************************************************************/
100 
101 int
103  SUMOReal choice = RandHelper::rand();
104  SUMOReal cumul = 0;
105  for (std::map<int, SUMOReal>::const_iterator it = ds.endWorkHours.begin();
106  it != ds.endWorkHours.end(); ++it) {
107  cumul += it->second;
108  if (cumul >= choice) {
109  return it->first;
110  }
111  }
112  std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl;
113  return 1700;
114 }
115 
116 /****************************************************************************/
117 
118 bool
120  return (adult != 0);
121 }
122 
123 /****************************************************************************/
124 
125 void
127  if (adult != 0) {
128  ds->workPositions++;
130  adult = 0;
131  }
132 }
133 
134 /****************************************************************************/
135 
136 void
137 AGWorkPosition::take(AGAdult* worker) throw(std::runtime_error) {
138  if (adult == 0) {
139  ds->workPositions--;
140  adult = worker;
141  } else {
142  throw(std::runtime_error("Work position already occupied. Cannot give it to another adult."));
143  }
144 }
145 
146 /****************************************************************************/
147 
150  return location;
151 }
152 
153 /****************************************************************************/
154 
155 int
157  return closingTime;
158 }
159 
160 /****************************************************************************/
161 
162 int
164  return openingTime;
165 }
166 
167 /****************************************************************************/