Skip to content

Commit

Permalink
Parse LZB/ETCS (#44)
Browse files Browse the repository at this point in the history
* parse detailed lzb/etcs information

* add line model

* track etcs elements in station routes

* split into .h/.cc

* add alias

* add precondition/postcondition alias for asserts

* don't generate IRs when etcs is required

* fix sassert for release

* change line precons into soft preconditions

* fix linting issue

* fix linting issues
  • Loading branch information
julianharbarth authored Jan 25, 2023
1 parent 2b83146 commit 2e1fefe
Show file tree
Hide file tree
Showing 27 changed files with 381 additions and 121 deletions.
21 changes: 11 additions & 10 deletions include/soro/infrastructure/graph/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "soro/si/units.h"

#include "soro/infrastructure/graph/type.h"
#include "soro/infrastructure/kilometrage.h"
#include "soro/infrastructure/line.h"

namespace soro::infra {

Expand All @@ -29,8 +31,7 @@ auto const INVALID_ELEMENT_ID = std::numeric_limits<element_id>::max();

using kilometrage = si::length;

using line_id = uint32_t;
constexpr auto const INVALID_LINE_ID = std::numeric_limits<line_id>::max();
constexpr auto const INVALID_LINE_ID = std::numeric_limits<line::id>::max();

struct end_element {
#if !(defined(SERIALIZE) || defined(__EMSCRIPTEN__))
Expand Down Expand Up @@ -66,7 +67,7 @@ struct end_element {
soro::array<element_ptr, 2> neighbours_{nullptr, nullptr};

kilometrage km_{si::INVALID<kilometrage>};
line_id line_{INVALID_LINE_ID};
line::id line_{INVALID_LINE_ID};
};

struct simple_element {
Expand Down Expand Up @@ -108,8 +109,8 @@ struct simple_element {

kilometrage end_km_{si::INVALID<kilometrage>};
kilometrage start_km_{si::INVALID<kilometrage>};
line_id end_line_{INVALID_LINE_ID};
line_id start_line_{INVALID_LINE_ID};
line::id end_line_{INVALID_LINE_ID};
line::id start_line_{INVALID_LINE_ID};

bool end_rising_{false};
};
Expand Down Expand Up @@ -144,7 +145,7 @@ struct track_element {
soro::array<element_ptr, 2> neighbours_{nullptr, nullptr};

kilometrage km_{si::INVALID<kilometrage>};
line_id line_{INVALID_LINE_ID};
line::id line_{INVALID_LINE_ID};
};

struct undirected_track_element {
Expand Down Expand Up @@ -185,7 +186,7 @@ struct undirected_track_element {
soro::array<element_ptr, 4> neighbours_{nullptr, nullptr, nullptr, nullptr};

kilometrage km_{si::INVALID<kilometrage>};
line_id line_{INVALID_LINE_ID};
line::id line_{INVALID_LINE_ID};
};

struct simple_switch {
Expand Down Expand Up @@ -230,7 +231,7 @@ struct simple_switch {
soro::array<element_ptr, 6> neighbours_{nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr};

line_id start_line_{INVALID_LINE_ID}, stem_line_{INVALID_LINE_ID},
line::id start_line_{INVALID_LINE_ID}, stem_line_{INVALID_LINE_ID},
branch_line_{INVALID_LINE_ID};
kilometrage start_km_{si::INVALID<kilometrage>},
stem_km_{si::INVALID<kilometrage>}, branch_km_{si::INVALID<kilometrage>};
Expand Down Expand Up @@ -291,8 +292,8 @@ struct cross {
bool start_left_end_right_arc_{false};
bool start_right_end_left_arc_{false};

line_id start_left_line_{INVALID_LINE_ID}, end_left_line_{INVALID_LINE_ID};
line_id start_right_line_{INVALID_LINE_ID}, end_right_line_{INVALID_LINE_ID};
line::id start_left_line_{INVALID_LINE_ID}, end_left_line_{INVALID_LINE_ID};
line::id start_right_line_{INVALID_LINE_ID}, end_right_line_{INVALID_LINE_ID};
kilometrage start_left_km_{si::INVALID<kilometrage>},
end_left_km_{si::INVALID<kilometrage>};
kilometrage start_right_km_{si::INVALID<kilometrage>},
Expand Down
2 changes: 1 addition & 1 deletion include/soro/infrastructure/graph/graph_creation.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ element* get_or_create_element(graph& network, station& station,
bool const rising);

void set_km_point_and_line(element& e, std::string const& node_name,
kilometrage km_point, line_id line);
kilometrage km_point, line::id line);

void set_neighbour(element& e, std::string const& name, element* neigh,
bool const rising);
Expand Down
2 changes: 1 addition & 1 deletion include/soro/infrastructure/graph/section.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct section {
soro::vector<element::ptr> falling_order_;

si::length length_{si::ZERO<si::length>};
line_id line_id_{INVALID_LINE_ID};
line::id line_id_{INVALID_LINE_ID};
};

} // namespace soro::infra
15 changes: 14 additions & 1 deletion include/soro/infrastructure/graph/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ enum class type : type_id {
SPEED_LIMIT,
POINT_SPEED,
BRAKE_PATH,
CTC,
LZB_START,
LZB_END,
LZB_BLOCK_SIGN,
ETCS_START,
ETCS_END,
ETCS_BLOCK_SIGN,
FORCED_HALT,
HALT,
// undirected track elements
Expand Down Expand Up @@ -103,4 +108,12 @@ constexpr bool is_runtime_checkpoint(type const type) {

constexpr bool is_halt(type const type) { return type == type::HALT; }

constexpr bool is_lzb(type const type) {
return type >= type::LZB_START && type <= type::LZB_BLOCK_SIGN;
}

constexpr bool is_etcs(type const type) {
return type >= type::ETCS_START && type <= type::ETCS_BLOCK_SIGN;
}

} // namespace soro::infra
3 changes: 3 additions & 0 deletions include/soro/infrastructure/infrastructure_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "soro/infrastructure/graph/graph.h"
#include "soro/infrastructure/infrastructure_options.h"
#include "soro/infrastructure/interlocking/interlocking_subsystem.h"
#include "soro/infrastructure/line.h"
#include "soro/infrastructure/station/station.h"
#include "soro/infrastructure/station/station_route_graph.h"
#include "soro/rolling_stock/rolling_stock.h"
Expand Down Expand Up @@ -42,6 +43,8 @@ struct infrastructure_t {
soro::vector<utls::gps> station_positions_{};
soro::vector<utls::gps> element_positions_{};

lines lines_{};

soro::vector<soro::unique_ptr<station>> station_store_{};
soro::vector<soro::unique_ptr<station_route>> station_route_store_{};
soro::vector<soro::unique_ptr<station_route::path>>
Expand Down
9 changes: 9 additions & 0 deletions include/soro/infrastructure/kilometrage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "soro/si/units.h"

namespace soro::infra {

using kilometrage = si::length;

} // namespace soro::infra
30 changes: 30 additions & 0 deletions include/soro/infrastructure/line.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "soro/base/soro_types.h"
#include "soro/infrastructure/kilometrage.h"

namespace soro::infra {

struct line {
using id = uint16_t;

struct segment {
kilometrage from_{si::INVALID<kilometrage>};
kilometrage to_{si::INVALID<kilometrage>};
bool etcs_{false};
bool lzb_{false};
bool signalling_{false};
};

bool has_signalling(kilometrage const km) const;
bool has_etcs(kilometrage const km) const;

id id_;

// ordered w.r.t. distance
soro::vector<segment> segments_;
};

using lines = soro::map<line::id, line>;

} // namespace soro::infra
15 changes: 9 additions & 6 deletions include/soro/infrastructure/parsers/iss/iss_string_literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ constexpr const char* const ETCS_START_FALLING = "ETCSAnfangF";
constexpr const char* const ETCS_END_RISING = "ETCSEndeS";
constexpr const char* const ETCS_END_FALLING = "ETCSEndeF";

constexpr const char* const CTC_START_FALLING = "LZBAnfangF";
constexpr const char* const CTC_END_FALLING = "LZBEndeF";
constexpr const char* const ETCS_BLOCK_SIGN_RISING = "ETCSBlockkennzeichenS";
constexpr const char* const ETCS_BLOCK_SIGN_FALLING = "ETCSBlockkennzeichenF";

constexpr const char* const CTC_START_RISING = "LZBAnfangS";
constexpr const char* const CTC_END_RISING = "LZBEndeS";
constexpr const char* const LZB_START_FALLING = "LZBAnfangF";
constexpr const char* const LZB_END_FALLING = "LZBEndeF";

constexpr const char* const CTC_BLOCK_SIGN_RISING = "LZBBlockkennzeichenS";
constexpr const char* const CTC_BLOCK_SIGN_FALLING = "LZBBlockkennzeichenF";
constexpr const char* const LZB_START_RISING = "LZBAnfangS";
constexpr const char* const LZB_END_RISING = "LZBEndeS";

constexpr const char* const LZB_BLOCK_SIGN_RISING = "LZBBlockkennzeichenS";
constexpr const char* const LZB_BLOCK_SIGN_FALLING = "LZBBlockkennzeichenF";

constexpr const char* const SPEED_LIMIT_RISING = "GeschwZulaessigS";
constexpr const char* const SPEED_LIMIT_FALLING = "GeschwZulaessigF";
Expand Down
2 changes: 1 addition & 1 deletion include/soro/infrastructure/parsers/iss/parse_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace soro::infra {

kilometrage parse_kilometrage(pugi::xml_node const& node);
kilometrage parse_kilometrage(std::string_view const kmp);

rail_plan_node_id parse_rp_node_id(pugi::xml_node const& node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace soro::infra {

element* parse_track_element(pugi::xml_node const& track_node, type const type,
bool const rising, line_id const line,
bool const rising, line::id const line,
graph& network, station& station,
construction_materials& mats);

Expand Down
7 changes: 3 additions & 4 deletions include/soro/infrastructure/regulatory_data.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "soro/base/soro_types.h"
#include "soro/infrastructure/line.h"
#include "soro/utls/file/loaded_file.h"

namespace soro::infra {
Expand All @@ -9,12 +10,10 @@ struct regulatory_station_data {
soro::map<soro::string, soro::string> ds100_to_full_name_{};
};

struct regulatory_line_data {};

regulatory_station_data parse_regulatory_stations(
std::vector<utls::loaded_file> const& regulatory_station_files);

regulatory_line_data parse_regulatory_line_data(
std::vector<utls::loaded_file> const&);
soro::map<line::id, line> parse_lines(
std::vector<utls::loaded_file> const& regulatory_line_files);

} // namespace soro::infra
4 changes: 2 additions & 2 deletions include/soro/infrastructure/station/station.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct border {
std::numeric_limits<track_sign>::max();

// minimum information to uniquely identify a border pair
using id_tuple = std::tuple<station::id, station::id, line_id, track_sign>;
using id_tuple = std::tuple<station::id, station::id, line::id, track_sign>;

auto get_id_tuple() const {
return id_tuple{std::min(station_->id_, neighbour_->id_),
Expand All @@ -62,7 +62,7 @@ struct border {
station::ptr neighbour_{nullptr};
element::ptr neighbour_element_{nullptr};

line_id line_{INVALID_LINE_ID};
line::id line_{INVALID_LINE_ID};
track_sign track_sign_{INVALID_TRACK_SIGN};

bool low_border_{false};
Expand Down
5 changes: 5 additions & 0 deletions include/soro/infrastructure/station/station_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct station_route {

soro::vector<node::ptr> nodes_{};
soro::vector<node::idx> main_signals_{};

soro::vector<node::idx> etcs_starts_{};
soro::vector<node::idx> etcs_ends_{};
};

node::idx size() const noexcept;
Expand All @@ -69,6 +72,8 @@ struct station_route {
bool can_start_an_interlocking(station_route_graph const& srg) const;
bool can_end_an_interlocking(station_route_graph const&) const;

bool requires_etcs(lines const& lines) const;

bool operator==(station_route const& o) const;
bool operator!=(station_route const& o) const;

Expand Down
43 changes: 39 additions & 4 deletions include/soro/utls/sassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ struct bool_with_loc {
};

#if !defined(NDEBUG)

template <typename Msg, typename... Args>
inline void sassert(bool_with_loc assert_this, Msg&& msg, Args... args) {
inline void sassert_impl(bool_with_loc assert_this,
std::string_view failure_type, Msg&& msg,
Args... args) {

if (!assert_this) {
using clock = std::chrono::system_clock;
Expand All @@ -62,7 +65,7 @@ inline void sassert(bool_with_loc assert_this, Msg&& msg, Args... args) {

std::stringstream ss;

fmt::print(ss, "[ASSERT FAIL][{}] ", std::put_time(&tmp, "%FT%TZ"));
fmt::print(ss, "[{}][{}] ", failure_type, std::put_time(&tmp, "%FT%TZ"));
fmt::print(ss, std::forward<Msg>(msg), std::forward<Args>(args)...);
fmt::print(ss, "\n");
fmt::print(ss, "[FAILED HERE] {}:{}:{} in {}",
Expand All @@ -79,22 +82,54 @@ inline void sassert(bool_with_loc assert_this, Msg&& msg, Args... args) {
#else

template <typename Msg, typename... Args>
inline void sassert(bool const, Msg&&, Args...) {}
inline void sassert_impl(bool const, Msg&&, Args...) {}

#endif

template <typename Msg, typename... Args>
inline void sassert(bool_with_loc assert_this, Msg&& msg, Args... args) {
sassert_impl(assert_this, "ASSERT", msg, args...);
}

template <typename Msg, typename... Args>
inline void expects(bool_with_loc assert_this, Msg&& msg, Args... args) {
sassert_impl(assert_this, "PRECONDITION", msg, args...);
}

template <typename Msg, typename... Args>
inline void ensures(bool_with_loc assert_this, Msg&& msg, Args... args) {
sassert_impl(assert_this, "POSTCONDITION", msg, args...);
}

inline void sassert(bool const assert_this) {
sassert(assert_this, "I didn't specify a error message :(");
sassert_impl(assert_this, "Unknown", "I didn't specify a error message :(");
}

#if !defined(NDEBUG)
template <typename F>
inline void sasserts(F&& f) {
f();
}

template <typename F>
inline void expects(F&& f) {
f();
}

template <typename F>
inline void ensures(F&& f) {
f();
}

#else
template <typename F>
inline void sasserts(F&&) {}

template <typename F>
inline void expects(F&&) {}

template <typename F>
inline void ensures(F&&) {}
#endif

} // namespace soro::utls
4 changes: 2 additions & 2 deletions include/soro/utls/std_wrapper/std_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ inline void append_move(C1& dest, C2&& src) {
}

template <typename Iteratable, typename Pred>
inline auto any_of(Iteratable const& i, Pred&& p) {
return std::any_of(std::cbegin(i), std::cend(i), p);
inline auto any_of(Iteratable&& i, Pred&& p) {
return std::any_of(std::begin(i), std::end(i), p);
}

template <typename Iteratable, typename Pred>
Expand Down
Loading

0 comments on commit 2e1fefe

Please sign in to comment.