Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
AGWorkPosition.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
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"
34#include <iostream>
35
36
37// ===========================================================================
38// method definitions
39// ===========================================================================
41 myStatData(ds),
42 myLocation(inStreet),
43 myAdult(nullptr),
44 myOpeningTime(generateOpeningTime(*ds)),
45 myClosingTime(generateClosingTime(*ds)) {
46 ds->workPositions++;
47}
48
49
51 myStatData(ds),
52 myLocation(inStreet, pos),
53 myAdult(nullptr),
54 myOpeningTime(generateOpeningTime(*ds)),
55 myClosingTime(generateClosingTime(*ds)) {
56 ds->workPositions++;
57}
58
62
63
64void
66 std::cout << "- AGWorkPosition: open=" << myOpeningTime << " closingTime=" << myClosingTime << " taken=" << isTaken() << std::endl;
67 std::cout << "\t";
69}
70
71
72int
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
89int
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
105bool
107 return (myAdult != nullptr);
108}
109
110
111void
113 if (myAdult != nullptr) {
116 myAdult = nullptr;
117 }
118}
119
120
121void
123 if (myAdult == nullptr) {
125 myAdult = worker;
126 } else {
127 throw ProcessError(TL("Work position already occupied. Cannot give it to another adult."));
128 }
129}
130
131
134 return myLocation;
135}
136
137
138int
140 return myClosingTime;
141}
142
143
144int
146 return myOpeningTime;
147}
148
149
150/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
An adult person who can have a job.
Definition AGAdult.h:48
void lostWorkPosition()
Called when the adult has lost her job.
Definition AGAdult.cpp:92
std::map< int, double > endWorkHours
std::map< int, double > beginWorkHours
A location in the 2D plane freely positioned on a street.
Definition AGPosition.h:53
void print() const
Prints out a summary of the properties of this class on standard output.
A model of the street in the city.
Definition AGStreet.h:50
static int generateOpeningTime(const AGDataAndStatistics &ds)
static int generateClosingTime(const AGDataAndStatistics &ds)
int getClosing() const
int getOpening() const
AGAdult * myAdult
AGPosition getPosition() const
void take(AGAdult *ad)
AGPosition myLocation
void print() const
AGDataAndStatistics * myStatData
bool isTaken() const
AGWorkPosition(AGDataAndStatistics *ds, const AGStreet &inStreet)
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)