Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
AGTrip.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2010-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// 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// ===========================================================================
34bool
35AGTrip::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
46void
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
58void
60 myPassBy.push_back(by);
61}
62
63void
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
72void
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
80const std::list<AGPosition>*
82 return &myPassBy;
83}
84
85const std::string&
87 return myType;
88}
89
90void
91AGTrip::setType(std::string type) {
92 myType = type;
93}
94
97 return myFrom;
98}
99
102 return myTo;
103}
104
105int
107 return myDepTime;
108}
109
110int
111AGTrip::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
129int
130AGTrip::getArrTime(double secPerKm) const {
131 return myDepTime + getTimeTrip(secPerKm);
132}
133
134int
135AGTrip::getRideBackArrTime(double secPerKm) const {
136 return getArrTime(secPerKm) + (int)(secPerKm * myTo.distanceTo(myFrom) / 1000.0);
137}
138
139void
141 myDepTime = time;
142}
143
144int
145AGTrip::estimateDepTime(int arrTime, double secPerKm) const {
146 return arrTime - getTimeTrip(secPerKm);
147}
148
149const std::string&
151 return myVehicle;
152}
153
154void
155AGTrip::setVehicleName(std::string name) {
156 myVehicle = name;
157}
158
159void
161 myTo = AGPosition(arrival.getStreet(), arrival.getPosition());
162}
163
164void
166 myFrom = AGPosition(departure.getStreet(), departure.getPosition());
167}
168
169bool
171 return (myDay == 0);
172}
173
174int
176 return myDay;
177}
178
179void
181 myDay = d;
182}
183
184
185/****************************************************************************/
A location in the 2D plane freely positioned on a street.
Definition AGPosition.h:53
double getPosition() const
Provides the relative position of this AGPosition on the street.
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
const AGStreet & getStreet() const
Provides the street this AGPosition is located on.
void print() const
Prints out a summary of the properties of this class on standard output.
void setDep(AGPosition departure)
Definition AGTrip.cpp:165
void setVehicleName(std::string name)
Definition AGTrip.cpp:155
const std::list< AGPosition > * getPassed() const
Definition AGTrip.cpp:81
int getTimeTrip(double secPerKm) const
Definition AGTrip.cpp:111
AGPosition getDep() const
Definition AGTrip.cpp:96
void setArr(AGPosition arrival)
Definition AGTrip.cpp:160
AGPosition myTo
Definition AGTrip.h:124
int myDay
Definition AGTrip.h:136
int getTime() const
Definition AGTrip.cpp:106
bool isDaily() const
Definition AGTrip.cpp:170
void setDepTime(int time)
Definition AGTrip.cpp:140
std::string myType
Definition AGTrip.h:131
int getRideBackArrTime(double secPerKm) const
Definition AGTrip.cpp:135
void print() const
Definition AGTrip.cpp:47
void addLayOverWithoutDestination(AGTrip &trip)
Definition AGTrip.cpp:73
int myDepTime
Definition AGTrip.h:125
AGPosition myFrom
Definition AGTrip.h:123
void setType(std::string type)
Definition AGTrip.cpp:91
const std::string & getType() const
Definition AGTrip.cpp:86
bool operator<(const AGTrip &trip) const
Definition AGTrip.cpp:35
std::string myVehicle
Definition AGTrip.h:126
AGPosition getArr() const
Definition AGTrip.cpp:101
std::list< AGPosition > myPassBy
Definition AGTrip.h:137
int getDay() const
Definition AGTrip.cpp:175
void addLayOver(AGPosition by)
Definition AGTrip.cpp:59
int getArrTime(double secPerKm) const
Definition AGTrip.cpp:130
int estimateDepTime(int arrTime, double secPerKm) const
Definition AGTrip.cpp:145
void setDay(int day)
Definition AGTrip.cpp:180
const std::string & getVehicleName() const
Definition AGTrip.cpp:150