trip_list.h Source File

CPP API: trip_list.h Source File
trip_list.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Elisabeth Kluth, Khoa Nguyen
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_ABM_TRIP_LIST_H
21 #define MIO_ABM_TRIP_LIST_H
22 
23 #include "abm/location_id.h"
24 #include "abm/mobility_data.h"
25 #include "abm/person.h"
26 #include "abm/person_id.h"
27 #include "abm/time.h"
28 #include "abm/location_type.h"
29 #include "memilio/io/io.h"
31 #include <cstdint>
32 #include <vector>
33 
34 namespace mio
35 {
36 namespace abm
37 {
38 
42 struct Trip {
49  std::vector<uint32_t> cells;
62  Trip(PersonId id, const TimePoint time, const LocationId dest, const int dest_model_id = 0,
63  const TransportMode mode_of_transport = mio::abm::TransportMode::Unknown,
64  const std::vector<uint32_t>& input_cells = {})
65  : person_id(id)
67  , destination(dest)
68  , destination_model_id(dest_model_id)
69  , trip_mode(mode_of_transport)
70  , cells(input_cells)
71 
72  {
73  }
74 
78  bool operator==(const Trip& other) const
79  {
80  return (person_id == other.person_id) && (trip_time == other.trip_time) && (destination == other.destination) &&
82  }
83 
85  {
86  return Members("Trip")
87  .add("person_id", person_id)
88  .add("trip_time", trip_time)
89  .add("destination", destination)
90  .add("model_id", destination_model_id)
91  .add("trip_mode", trip_mode);
92  }
93 };
94 
98 class TripList
99 {
100 public:
104  TripList() = default;
105 
110  const Trip& get_next_trip() const;
111 
117 
123  void add_trips(std::vector<Trip> trip);
124 
129  {
130  m_current_index++;
131  }
132 
136  void reset_index()
137  {
138  m_current_index = 0;
139  }
140 
145  size_t num_trips() const
146  {
147  return m_trips.size();
148  }
149 
153  uint32_t get_current_index() const
154  {
155  return m_current_index;
156  }
157 
160  {
161  return Members("TestingScheme").add("trips", m_trips).add("index", m_current_index);
162  }
163 
164 private:
165  std::vector<Trip> m_trips;
166  uint32_t m_current_index = 0;
167 };
168 
169 } // namespace abm
170 
172 template <>
173 struct DefaultFactory<abm::Trip> {
174  static abm::Trip create()
175  {
177  }
178 };
179 
180 } // namespace mio
181 
182 #endif
Represents a point in time.
Definition: time.h:175
TimeSpan time_since_midnight() const
Time since midnight.
Definition: time.h:239
int seconds() const
Length of time in seconds.
Definition: time.h:71
A list of Trips a Person follows.
Definition: trip_list.h:99
TimePoint get_next_trip_time() const
Get the trip_time at which the next Trip will happen.
Definition: trip_list.cpp:34
uint32_t get_current_index() const
Get the current index.
Definition: trip_list.h:153
TripList()=default
Construct empty TripList.
const Trip & get_next_trip() const
Get the next Trip.
Definition: trip_list.cpp:29
std::vector< Trip > m_trips
The list of Trips a Person makes on a weekday.
Definition: trip_list.h:165
void reset_index()
Reset the current index to 0.
Definition: trip_list.h:136
void add_trips(std::vector< Trip > trip)
Adds Trips to the trip list.
Definition: trip_list.cpp:39
size_t num_trips() const
Get the length of the TripList.
Definition: trip_list.h:145
void increase_index()
Increment the current index to select the next Trip.
Definition: trip_list.h:128
uint32_t m_current_index
The index of the Trip a Person makes next.
Definition: trip_list.h:166
auto default_serialize()
This method is used by the default serialization feature.
Definition: trip_list.h:159
TransportMode
Mode of Transport.
Definition: mobility_data.h:35
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
static abm::Trip create()
Definition: trip_list.h:174
Creates an instance of T for later initialization.
Definition: default_serialize.h:173
List of a class's members.
Definition: default_serialize.h:113
Members< ValueTypes..., T > add(const char *member_name, T &member)
Add a class member.
Definition: default_serialize.h:139
Unique identifier for a Location within a Model.
Definition: location_id.h:34
Unique ID for a Person within a Model.
Definition: person_id.h:33
A trip describes a change of Location from one Location to another Location.
Definition: trip_list.h:42
TimePoint trip_time
Daytime at which a Person changes the Location.
Definition: trip_list.h:45
bool operator==(const Trip &other) const
Compare two Trips.
Definition: trip_list.h:78
Trip(PersonId id, const TimePoint time, const LocationId dest, const int dest_model_id=0, const TransportMode mode_of_transport=mio::abm::TransportMode::Unknown, const std::vector< uint32_t > &input_cells={})
Construct a new Trip.
Definition: trip_list.h:62
LocationId destination
Location where the Person changes to.
Definition: trip_list.h:46
int destination_model_id
Model id of destination Location.
Definition: trip_list.h:47
TransportMode trip_mode
Mode of transportation. See TransportMode for all possible modes of transportation.
Definition: trip_list.h:48
auto default_serialize()
Definition: trip_list.h:84
PersonId person_id
Person that makes the trip and corresponds to the index into the structure m_persons from Model,...
Definition: trip_list.h:43
std::vector< uint32_t > cells
If destination consists of different Cells, this gives the index of the Cells the Person changes to.
Definition: trip_list.h:49