1#ifndef CDA_RAIL_DATASTRUCTURE_STATION_HPP
2#define CDA_RAIL_DATASTRUCTURE_STATION_HPP
12#include <unordered_map>
13#include <unordered_set>
49 [[nodiscard]] std::vector<
50 std::pair<size_t, std::vector<cda_rail::index_vector>>>
83 std::unordered_map<std::string, std::shared_ptr<Station>> stations;
93 [[nodiscard]] std::shared_ptr<Station>
94 get_station_ptr(
const std::string& name);
126 :
StationList(std::filesystem::path(path), network) {};
135 :
StationList(std::filesystem::path(path), network) {};
144 for (
const auto& [name, station_ptr] : other.stations) {
145 stations[name] = std::make_shared<Station>(*station_ptr);
156 if (
this != &other) {
158 for (
const auto& [name, station_ptr] : other.stations) {
159 stations[name] = std::make_shared<Station>(*station_ptr);
174 [[nodiscard]] auto
begin()
const {
return stations.cbegin(); };
176 [[nodiscard]]
auto end()
const {
return stations.cend(); };
182 [[nodiscard]]
auto cbegin()
const {
return stations.cbegin(); };
184 [[nodiscard]]
auto cend()
const {
return stations.cend(); };
190 [[nodiscard]]
size_t size()
const {
return stations.size(); };
202 return stations.contains(name);
270 void add_track_to_station_helper(
const std::string& name,
size_t const track,
294 add_track_to_station_helper(name, edge.resolve(&network), network);
321 std::filesystem::path
const p(path);
345 return {path, network};
360 return {path, network};
390 const std::vector<std::pair<size_t, cda_rail::index_set>>& new_edges);
402 const std::vector<std::pair<size_t, cda_rail::index_vector>>& new_edges);
416 [[nodiscard]] std::vector<
417 std::pair<size_t, std::vector<cda_rail::index_vector>>>
Directed multigraph representing a railway network.
Definition RailwayNetwork.hpp:163
bool has_edge(size_t const index) const
Checks whether a numeric edge index is valid.
Definition RailwayNetwork.hpp:449
Container and persistence API for named stations.
Definition Station.hpp:81
StationList & operator=(const StationList &other)
Copy assignment operator that performs a deep copy of all stations.
Definition Station.hpp:155
StationList(StationList &&) noexcept=default
Move constructor.
void export_stations(const std::filesystem::path &p, const Network &network) const
Exports all stations to stations.json in the target directory.
Definition Station.cpp:129
auto cbegin() const
Obtains a const iterator to the first station.
Definition Station.hpp:182
StationList(char const *const path, Network const &network)
Convenience overload forwarding to the filesystem path constructor.
Definition Station.hpp:134
std::unordered_set< std::string > get_station_names() const
Returns the set of all station names.
Definition Station.cpp:102
void add_track_to_station(const std::string &name, size_t track)
Adds a track index to an existing station.
Definition Station.cpp:119
void export_stations(char const *const path, const Network &network) const
Writes all stations to the specified directory.
Definition Station.hpp:332
auto cend() const
Read-only iterator past the last station entry (explicit const).
Definition Station.hpp:184
StationList()=default
Creates an empty station list.
bool is_fully_in_station(std::string const &station_name, cda_rail::index_set const &edges) const
Checks whether all given edges belong to a named station.
Definition Station.cpp:192
void add_track_to_station(const std::string &name, cda_rail::Network::EdgeInput const &edge, const Network &network)
Adds a track to a station by resolving an edge specification.
Definition Station.hpp:291
static StationList import_stations(const std::filesystem::path &p, const Network &network)
Imports stations from a filesystem path.
Definition Station.hpp:373
bool has_station(const std::string &name) const
Checks whether a station with the given name exists.
Definition Station.hpp:201
StationList(std::string const &path, Network const &network)
Constructs a station list from a string path.
Definition Station.hpp:125
void update_after_discretization(const std::vector< std::pair< size_t, cda_rail::index_set > > &new_edges)
Updates station tracks after network discretization.
Definition Station.cpp:182
auto end() const
Read-only iterator past the last station entry.
Definition Station.hpp:176
size_t size() const
Retrieves the number of stations.
Definition Station.hpp:190
friend class Timetable
Definition Station.hpp:85
Station const & get_station(const std::string &name) const
Retrieves a station by name.
Definition Station.cpp:94
static StationList import_stations(const char *path, const Network &network)
Imports stations from a C-string path.
Definition Station.hpp:358
void add_empty_station(std::string const &name)
Adds a new station without tracks.
Definition Station.cpp:111
std::vector< std::pair< size_t, std::vector< cda_rail::index_vector > > > get_stop_tracks(const std::string &name, double tr_len, const Network &network, const cda_rail::index_set &edges_to_consider={}) const
Computes possible stop tracks for a named station.
Definition Station.hpp:418
void export_stations(std::string const &path, const Network &network) const
Convenience overload forwarding to the filesystem path export.
Definition Station.hpp:320
static StationList import_stations(const std::string &path, const Network &network)
Imports stations from a directory path string.
Definition Station.hpp:343
StationList(const StationList &other)
Copy constructor that performs a deep copy of all stations.
Definition Station.hpp:143
auto begin() const
Read-only iterator to the first station entry.
Definition Station.hpp:174
Thrown when a referenced edge does not exist.
Definition CustomExceptions.hpp:160
Definition CustomExceptions.hpp:15
std::unordered_set< size_t > index_set
Definition Definitions.hpp:22
Represents a station as a named set of network tracks (edge indices).
Definition Station.hpp:24
cda_rail::index_set tracks
Set of track indices (network edges) that belong to this station.
Definition Station.hpp:33
std::vector< std::pair< size_t, std::vector< cda_rail::index_vector > > > get_stop_tracks(double tr_len, Network const &network, cda_rail::index_set const &edges_to_consider={}) const
Computes station tracks that can host a stop for a given train length.
Definition Station.cpp:23
bool operator==(const Station &other) const
Compares two stations for equality.
Definition Station.hpp:70
std::string name
Station identifier.
Definition Station.hpp:28
bool is_fully_in_station(cda_rail::index_set const &edges) const
Checks whether all provided edges belong to this station.
Definition Station.cpp:46