Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/activities/AGTrip.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2010-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 AGTrip.cpp
17
/// @author Piotr Woznica
18
/// @author Daniel Krajzewicz
19
/// @author Walter Bamberger
20
/// @author Jakob Erdmann
21
/// @author Michael Behrisch
22
/// @date July 2010
23
///
24
// Class containing all information of a given trip (car, bus)
25
/****************************************************************************/
26
#include <config.h>
27
28
#include "AGTrip.h"
29
30
31
// ===========================================================================
32
// method definitions
33
// ===========================================================================
34
bool
35
AGTrip::operator <(const AGTrip& trip) const {
36
if (getDay() < trip.getDay()) {
37
return true;
38
}
39
if (getDay() == trip.getDay())
40
if (getTime() < trip.getTime()) {
41
return true;
42
}
43
return false;
44
}
45
46
void
47
AGTrip::print() const {
48
std::cout << "Trip: " << std::endl;
49
std::cout << "\t-From= ";
50
myFrom.print();
51
std::cout << "\t-To= ";
52
myTo.print();
53
std::cout << "\t-At= " << myDepTime << " -Day= " << myDay << std::endl;
54
std::cout << "\t-Vehicle= " << myVehicle << std::endl;
55
std::cout << "\t-type= " << myType << std::endl;
56
}
57
58
void
59
AGTrip::addLayOver(AGPosition by) {
60
myPassBy.push_back(by);
61
}
62
63
void
64
AGTrip::addLayOver(AGTrip& trip) {
65
std::list<AGPosition>::iterator it;
66
for (it = trip.myPassBy.begin(); it != trip.myPassBy.end(); ++it) {
67
myPassBy.push_back(*it);
68
}
69
myPassBy.push_back(trip.myTo);
70
}
71
72
void
73
AGTrip::addLayOverWithoutDestination(AGTrip& trip) {
74
std::list<AGPosition>::iterator it;
75
for (it = trip.myPassBy.begin(); it != trip.myPassBy.end(); ++it) {
76
myPassBy.push_back(*it);
77
}
78
}
79
80
const std::list<AGPosition>*
81
AGTrip::getPassed() const {
82
return &myPassBy;
83
}
84
85
const std::string&
86
AGTrip::getType() const {
87
return myType;
88
}
89
90
void
91
AGTrip::setType(std::string type) {
92
myType = type;
93
}
94
95
AGPosition
96
AGTrip::getDep() const {
97
return myFrom;
98
}
99
100
AGPosition
101
AGTrip::getArr() const {
102
return myTo;
103
}
104
105
int
106
AGTrip::getTime() const {
107
return myDepTime;
108
}
109
110
int
111
AGTrip::getTimeTrip(double secPerKm) const {
112
double dist = 0;
113
std::list<AGPosition> positions;
114
positions.push_back(myFrom);
115
std::list<AGPosition>::const_iterator it;
116
for (it = myPassBy.begin(); it != myPassBy.end(); ++it) {
117
positions.push_back(*it);
118
}
119
positions.push_back(myTo);
120
121
const AGPosition* temp = &positions.front();
122
for (it = positions.begin(), ++it; it != positions.end(); ++it) {
123
dist += temp->distanceTo(*it);
124
temp = &*it;
125
}
126
return (int)(secPerKm * (dist / 1000.0));
127
}
128
129
int
130
AGTrip::getArrTime(double secPerKm) const {
131
return myDepTime + getTimeTrip(secPerKm);
132
}
133
134
int
135
AGTrip::getRideBackArrTime(double secPerKm) const {
136
return getArrTime(secPerKm) + (int)(secPerKm * myTo.distanceTo(myFrom) / 1000.0);
137
}
138
139
void
140
AGTrip::setDepTime(int time) {
141
myDepTime = time;
142
}
143
144
int
145
AGTrip::estimateDepTime(int arrTime, double secPerKm) const {
146
return arrTime - getTimeTrip(secPerKm);
147
}
148
149
const std::string&
150
AGTrip::getVehicleName() const {
151
return myVehicle;
152
}
153
154
void
155
AGTrip::setVehicleName(std::string name) {
156
myVehicle = name;
157
}
158
159
void
160
AGTrip::setArr(AGPosition arrival) {
161
myTo = AGPosition(arrival.getStreet(), arrival.getPosition());
162
}
163
164
void
165
AGTrip::setDep(AGPosition departure) {
166
myFrom = AGPosition(departure.getStreet(), departure.getPosition());
167
}
168
169
bool
170
AGTrip::isDaily() const {
171
return (myDay == 0);
172
}
173
174
int
175
AGTrip::getDay() const {
176
return myDay;
177
}
178
179
void
180
AGTrip::setDay(int d) {
181
myDay = d;
182
}
183
184
185
/****************************************************************************/
186
187