Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/activities/AGActivity.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 AGActivity.cpp
17
/// @author Piotr Woznica
18
/// @author Daniel Krajzewicz
19
/// @author Walter Bamberger
20
/// @date July 2010
21
///
22
// Parent object for all activities. Derived classes generate trips for each
23
// household.
24
/****************************************************************************/
25
#include <config.h>
26
27
#include <utils/common/RandHelper.h>
28
#include <activitygen/city/AGHousehold.h>
29
#include <activitygen/city/AGTime.h>
30
#include "AGActivity.h"
31
32
33
// ===========================================================================
34
// method definitions
35
// ===========================================================================
36
bool
37
AGActivity::isGenerated() {
38
return genDone;
39
}
40
41
42
bool
43
AGActivity::generateTrips() {
44
return true;
45
}
46
47
int
48
AGActivity::possibleTranspMean(AGPosition destination) {
49
int FOOT = 1;
50
int BUS = 2;
51
int CAR = 4;
52
53
int transp = 0;
54
55
if (destination.distanceTo(myHousehold->getPosition()) <= myStatData->maxFootDistance) {
56
transp = FOOT;
57
if (myHousehold->getCarNbr() != 0) {
58
transp += CAR;
59
}
60
if (destination.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance
61
&& myHousehold->getPosition().minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance) {
62
transp += BUS;
63
}
64
} else if (myHousehold->getCarNbr() == 0) {
65
double d1 = destination.distanceTo(myHousehold->getPosition());
66
double d2 = destination.minDistanceTo(myStatData->busStations) + myHousehold->getPosition().minDistanceTo(myStatData->busStations);
67
68
if (d1 > d2) {
69
transp = BUS;
70
} else {
71
transp = FOOT;
72
}
73
} else if (myHousehold->getCarNbr() != 0) { //all other cases
74
if (destination.minDistanceTo(myStatData->busStations) > myStatData->maxFootDistance
75
|| myHousehold->getPosition().minDistanceTo(myStatData->busStations) > myStatData->maxFootDistance) {
76
transp = CAR;
77
} else {
78
transp = CAR + BUS;
79
}
80
}
81
return transp;
82
}
83
84
int
85
AGActivity::availableTranspMeans(AGPosition from, AGPosition to) {
86
int FOOT = 1;
87
int BUS = 2;
88
89
int available = 0;
90
91
if (from.distanceTo(to) <= myStatData->maxFootDistance) {
92
available += FOOT;
93
}
94
if (from.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance
95
&& to.minDistanceTo(myStatData->busStations) <= myStatData->maxFootDistance) {
96
available += BUS;
97
}
98
return available;
99
}
100
101
102
int
103
AGActivity::timeToDrive(AGPosition from, AGPosition to) {
104
double dist = from.distanceTo(to);
105
return (int)(timePerKm * dist / 1000.0);
106
}
107
108
109
int
110
AGActivity::depHour(AGPosition from, AGPosition to, int arrival) {
111
// ?? departure.addDays(1); // in case of negative time: arrival < timeToDrive
112
//departure.setDay(0); // days are set to 0 because we want the time in the current day
113
return (arrival - timeToDrive(from, to));
114
}
115
116
117
int
118
AGActivity::arrHour(AGPosition from, AGPosition to, int departure) {
119
return (departure + timeToDrive(from, to));
120
}
121
122
123
int
124
AGActivity::randomTimeBetween(int begin, int end) {
125
if (0 > begin || begin > end) {
126
return -1;
127
}
128
if (begin == end) {
129
return begin;
130
}
131
int tAlea = RandHelper::rand(end - begin);
132
return (begin + tAlea);
133
}
134
135
136
std::list<AGTrip>&
137
AGActivity::getPartialActivityTrips() {
138
return myPartialActivityTrips;
139
}
140
141
142
/****************************************************************************/
143
144