SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
AGAdult.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// Person in working age: can be linked to a work position.
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
// activitygen module
14
// Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
15
/****************************************************************************/
16
//
17
// This file is part of SUMO.
18
// SUMO is free software: you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation, either version 3 of the License, or
21
// (at your option) any later version.
22
//
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 "
AGAdult.h
"
36
#include "
AGWorkPosition.h
"
37
#include <
utils/common/RandHelper.h
>
38
#include <iostream>
39
40
41
// ===========================================================================
42
// method definitions
43
// ===========================================================================
44
AGWorkPosition
*
45
AGAdult::randomFreeWorkPosition
(std::vector<AGWorkPosition> *wps) {
46
size_t
wpsIndex = 0;
47
48
// TODO: Could end up in an endless loop
49
do
{
50
wpsIndex =
RandHelper::rand
(wps->size());
51
}
while
(wps->at(wpsIndex).isTaken());
52
53
return
&wps->at(wpsIndex);
54
}
55
56
/****************************************************************************/
57
58
AGAdult::AGAdult
(
int
age)
59
:
AGPerson
(age), work(0) {}
60
61
/****************************************************************************/
62
63
void
64
AGAdult::print
()
const
{
65
std::cout <<
"- AGAdult: Age="
<<
age
<<
" Work="
<<
work
<< std::endl;
66
}
67
68
/****************************************************************************/
69
70
void
71
AGAdult::tryToWork
(
SUMOReal
rate, std::vector<AGWorkPosition>* wps) {
72
if
(
decide
(rate)) {
73
// Select the new work position before giving up the current one.
74
// This avoids that the current one is the same as the new one.
75
AGWorkPosition
* newWork =
randomFreeWorkPosition
(wps);
76
77
if
(
work
!= 0) {
78
work
->
let
();
79
}
80
work
= newWork;
81
work
->
take
(
this
);
82
}
else
{
83
if
(
work
!= 0) {
84
// Also sets work = 0 with the call back lostWorkPosition
85
work
->
let
();
86
}
87
}
88
}
89
90
/****************************************************************************/
91
92
bool
93
AGAdult::isWorking
()
const
{
94
return
(
work
!= 0);
95
}
96
97
/****************************************************************************/
98
99
void
100
AGAdult::lostWorkPosition
() {
101
work
= 0;
102
}
103
104
/****************************************************************************/
105
106
void
107
AGAdult::resignFromWorkPosition
() {
108
if
(
work
!= 0) {
109
work
->
let
();
110
}
111
}
112
113
/****************************************************************************/
114
115
const
AGWorkPosition
&
116
AGAdult::getWorkPosition
()
const
throw(std::
runtime_error
) {
117
if
(
work
!= 0) {
118
return
*
work
;
119
}
120
121
else
{
122
throw
(std::runtime_error(
"AGAdult::getWorkPosition: Adult is unemployed."
));
123
}
124
}
125
126
/****************************************************************************/
tmp
buildd
sumo-0.15.0~dfsg
src
activitygen
city
AGAdult.cpp
Generated on Sun May 27 2012 14:52:03 for SUMO - Simulation of Urban MObility by
1.8.1