Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/city/AGWorkPosition.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
16
/// @file AGWorkPosition.cpp
17
/// @author Piotr Woznica
18
/// @author Walter Bamberger
19
/// @author Daniel Krajzewicz
20
/// @author Michael Behrisch
21
/// @author Mirko Barthauer
22
/// @date July 2010
23
///
24
// Location and schedules of a work position: linked with one adult
25
/****************************************************************************/
26
#include <config.h>
27
28
#include "AGWorkPosition.h"
29
#include "AGStreet.h"
30
#include "AGPosition.h"
31
#include "AGDataAndStatistics.h"
32
#include "AGAdult.h"
33
#include <utils/common/RandHelper.h>
34
#include <iostream>
35
36
37
// ===========================================================================
38
// method definitions
39
// ===========================================================================
40
AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet) :
41
myStatData(ds),
42
myLocation(inStreet),
43
myAdult(nullptr),
44
myOpeningTime(generateOpeningTime(*ds)),
45
myClosingTime(generateClosingTime(*ds)) {
46
ds->workPositions++;
47
}
48
49
50
AGWorkPosition::AGWorkPosition(AGDataAndStatistics* ds, const AGStreet& inStreet, double pos) :
51
myStatData(ds),
52
myLocation(inStreet, pos),
53
myAdult(nullptr),
54
myOpeningTime(generateOpeningTime(*ds)),
55
myClosingTime(generateClosingTime(*ds)) {
56
ds->workPositions++;
57
}
58
59
AGWorkPosition::~AGWorkPosition() {
60
// let();
61
}
62
63
64
void
65
AGWorkPosition::print() const {
66
std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl;
67
std::cout << "\t";
68
myLocation.print();
69
}
70
71
72
int
73
AGWorkPosition::generateOpeningTime(const AGDataAndStatistics& ds) {
74
double choice = RandHelper::rand();
75
double cumul = 0;
76
77
for (std::map<int, double>::const_iterator it = ds.beginWorkHours.begin();
78
it != ds.beginWorkHours.end(); ++it) {
79
cumul += it->second;
80
if (cumul >= choice) {
81
return it->first;
82
}
83
}
84
std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 9.00am --" << std::endl;
85
return 32400;
86
}
87
88
89
int
90
AGWorkPosition::generateClosingTime(const AGDataAndStatistics& ds) {
91
double choice = RandHelper::rand();
92
double cumul = 0;
93
for (std::map<int, double>::const_iterator it = ds.endWorkHours.begin();
94
it != ds.endWorkHours.end(); ++it) {
95
cumul += it->second;
96
if (cumul >= choice) {
97
return it->first;
98
}
99
}
100
std::cout << "-- WARNING: work time distribution not complete (Sum(proportions) != 1): AUTODEFINED at 5.00pm --" << std::endl;
101
return 61200;
102
}
103
104
105
bool
106
AGWorkPosition::isTaken() const {
107
return (myAdult != nullptr);
108
}
109
110
111
void
112
AGWorkPosition::let() {
113
if (myAdult != nullptr) {
114
myStatData->workPositions++;
115
myAdult->lostWorkPosition();
116
myAdult = nullptr;
117
}
118
}
119
120
121
void
122
AGWorkPosition::take(AGAdult* worker) {
123
if (myAdult == nullptr) {
124
myStatData->workPositions--;
125
myAdult = worker;
126
} else {
127
throw ProcessError(TL("Work position already occupied. Cannot give it to another adult."));
128
}
129
}
130
131
132
AGPosition
133
AGWorkPosition::getPosition() const {
134
return myLocation;
135
}
136
137
138
int
139
AGWorkPosition::getClosing() const {
140
return myClosingTime;
141
}
142
143
144
int
145
AGWorkPosition::getOpening() const {
146
return myOpeningTime;
147
}
148
149
150
/****************************************************************************/
151
152