18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-28 04:47:32 +01:00

fix(physics): trackcheck tells a curve without a speed limit apart from the defects

A track without a speed limit of its own was checked at a default 125 km/h and counted as overturning or a tight curve
too fast at the default speed: in Tomaszewo 154 such lines, all of them curves with no limit, the tram tracks of the
town (29 to 31 m) among them. A curve without a speed limit is no defect: the drivers go by the signals and the
timetable there. It now gets a note of its own, "no speed limit set (not a defect): the curve takes at most X km/h,
the overturning speed of EU07", only where that is under the top speed of the EU07, and the summary counts these
curves apart from the suspicious tracks, with the slowest speed among them. The tight curve too fast needs a speed
limit too. Tram tracks have no category of their own (a tram is a vehicle of the trains' category, on their tracks),
so they are checked alike.
This commit is contained in:
jerrrrycho
2026-11-16 07:44:32 +01:00
parent 0e41d27032
commit 3df78e137a
3 changed files with 144 additions and 52 deletions

View File

@@ -65,6 +65,64 @@ std::string uneven_excess(track_uneven::attribute const &Uneven, settings const
return result;
}
// what the check of a track found so far
struct collector {
findings &result;
void add(kind const Kind, std::string const &Text) const {
if (std::ranges::find(result.kinds, Kind) == result.kinds.end()) {
result.kinds.push_back(Kind);
}
append(result.text, Text);
}
};
derailment::track_state curve_of(track const &Track) {
// with the cant both ends have at the least
auto const cant{std::min(std::abs(Track.cant[0]), std::abs(Track.cant[1]))};
derailment::track_state result;
result.radius = Track.radius;
result.cant = cant_angle(cant, Track.gauge);
result.gauge = Track.gauge;
return result;
}
// a speed limit over the speed a reference vehicle overturns or climbs the rail at in the curve
void check_limit(track const &Track, std::vector<reference> const &References, collector const &Found) {
auto const curve{curve_of(Track)};
for (auto const &reference : References) {
auto const overturning{derailment::overturning_speed(curve.radius, curve.cant, reference.vehicle.centre_of_gravity, curve.gauge) * kmh};
if (overturning > 0.0 && Track.velocity > overturning) {
Found.add(kind::overturning, std::format("speed limit {:.0f} km/h over the overturning speed of {} {:.0f} km/h", Track.velocity, reference.name, overturning));
}
if (auto const climbing{derailment::climbing_speed(reference.vehicle, curve)}; climbing.has_value() && Track.velocity > *climbing * kmh) {
Found.add(kind::climbing, std::format("speed limit {:.0f} km/h over the flange climbing speed of {} {:.0f} km/h", Track.velocity, reference.name, *climbing * kmh));
}
}
}
// a curve without a speed limit: how fast it takes the reference vehicles, when that's under the unlimited velocity
void check_unlimited(track const &Track, std::vector<reference> const &References, settings const &Settings, collector const &Found) {
auto const curve{curve_of(Track)};
auto slowest{Settings.unlimited_velocity};
std::string what;
for (auto const &reference : References) {
auto const overturning{derailment::overturning_speed(curve.radius, curve.cant, reference.vehicle.centre_of_gravity, curve.gauge) * kmh};
if (overturning > 0.0 && overturning < slowest) {
slowest = overturning;
what = std::format("the overturning speed of {}", reference.name);
}
if (auto const climbing{derailment::climbing_speed(reference.vehicle, curve)}; climbing.has_value() && *climbing * kmh < slowest) {
slowest = *climbing * kmh;
what = std::format("the flange climbing speed of {}", reference.name);
}
}
if (what.empty()) {
return;
}
Found.result.unlimited_speed = slowest;
Found.add(kind::unlimited_curve, std::format("no speed limit set (not a defect): the curve takes at most {:.0f} km/h, {}", slowest, what));
}
} // namespace
std::vector<reference> const &default_references() {
@@ -81,10 +139,6 @@ std::string_view name_of(kind const Kind) {
return "overturning";
case kind::climbing:
return "flange climbing";
case kind::overturning_default:
return "overturning at the default speed";
case kind::climbing_default:
return "flange climbing at the default speed";
case kind::cant_on_straight:
return "cant on a straight";
case kind::cant_excess:
@@ -93,56 +147,48 @@ std::string_view name_of(kind const Kind) {
return "tight curve too fast";
case kind::uneven:
return "uneven out of range";
case kind::unlimited_curve:
return "curve without a speed limit";
default:
return "?";
}
}
bool is_defect(kind const Kind) {
return Kind != kind::unlimited_curve;
}
bool findings::defective() const {
return std::ranges::any_of(kinds, [](kind const Kind) { return is_defect(Kind); });
}
findings check(track const &Track, std::vector<reference> const &References, settings const &Settings) {
findings result;
auto const found = [&](kind const Kind, std::string const &Text) {
if (std::find(result.kinds.begin(), result.kinds.end(), Kind) == result.kinds.end()) {
result.kinds.push_back(Kind);
}
append(result.text, Text);
};
collector const found{result};
auto const curved{Track.radius > 0.0};
auto const given{Track.velocity >= 0.0};
auto const velocity{given ? Track.velocity : Settings.default_velocity};
if (Track.plain) {
// the speed in the curve, with the cant both ends have at the least
if (curved && velocity > 0.0) {
auto const cant{std::min(std::abs(Track.cant[0]), std::abs(Track.cant[1]))};
derailment::track_state track;
track.radius = Track.radius;
track.cant = cant_angle(cant, Track.gauge);
track.gauge = Track.gauge;
for (auto const &reference : References) {
auto const overturning{derailment::overturning_speed(track.radius, track.cant, reference.vehicle.centre_of_gravity, track.gauge) * kmh};
if (overturning > 0.0 && velocity > overturning) {
found(given ? kind::overturning : kind::overturning_default,
std::format("{} {:.0f} km/h over the overturning speed of {} {:.0f} km/h", given ? "speed limit" : "default speed", velocity, reference.name, overturning));
}
if (auto const climbing{derailment::climbing_speed(reference.vehicle, track)}; climbing.has_value() && velocity > *climbing * kmh) {
found(given ? kind::climbing : kind::climbing_default,
std::format("{} {:.0f} km/h over the flange climbing speed of {} {:.0f} km/h", given ? "speed limit" : "default speed", velocity, reference.name, *climbing * kmh));
}
}
// a closed track (speed 0) isn't run on
if (curved && given && Track.velocity > 0.0) {
check_limit(Track, References, found);
}
if (curved && false == given) {
check_unlimited(Track, References, Settings, found);
}
// cant held over the whole of a straight track: a transition has it at one end only
if (false == curved && std::abs(Track.cant[0]) > Settings.straight_cant && std::abs(Track.cant[1]) > Settings.straight_cant && Track.cant[0] * Track.cant[1] > 0.0) {
found(kind::cant_on_straight, std::format("cant {:.0f} / {:.0f} mm on a straight track", Track.cant[0], Track.cant[1]));
found.add(kind::cant_on_straight, std::format("cant {:.0f} / {:.0f} mm on a straight track", Track.cant[0], Track.cant[1]));
}
if (curved && velocity > Settings.tight_velocity && Track.radius < Settings.tight_radius) {
found(kind::tight_curve, std::format("radius {:.0f} m with a {} of {:.0f} km/h", Track.radius, given ? "speed limit" : "default speed", velocity));
if (curved && given && Track.velocity > Settings.tight_velocity && Track.radius < Settings.tight_radius) {
found.add(kind::tight_curve, std::format("radius {:.0f} m with a speed limit of {:.0f} km/h", Track.radius, Track.velocity));
}
}
if (auto const most{std::max(std::abs(Track.cant[0]), std::abs(Track.cant[1]))}; most > Settings.most_cant) {
found(kind::cant_excess, std::format("cant {:.0f} mm over {:.0f} mm", most, Settings.most_cant));
found.add(kind::cant_excess, std::format("cant {:.0f} mm over {:.0f} mm", most, Settings.most_cant));
}
if (auto const excess{uneven_excess(Track.uneven, Settings)}; false == excess.empty()) {
found(kind::uneven, std::format("uneven {} mm out of range", excess));
found.add(kind::uneven, std::format("uneven {} mm out of range", excess));
}
if (false == result.empty()) {
result.text += std::format(" (radius {:.0f} m, cant {:.0f} / {:.0f} mm, speed limit {}, damage {})", Track.radius, Track.cant[0], Track.cant[1],
@@ -162,17 +208,27 @@ summary scan(std::vector<track> const &Tracks, sink const &Log, std::vector<refe
if (found.empty()) {
continue;
}
++result.suspicious;
if (found.defective()) {
++result.suspicious;
}
if (found.unlimited_speed > 0.0) {
++result.unlimited;
result.slowest = result.slowest > 0.0 ? std::min(result.slowest, found.unlimited_speed) : found.unlimited_speed;
}
for (auto const kind : found.kinds) {
++result.counts[static_cast<std::size_t>(kind)];
}
Log(std::format("trackcheck: {}: {}", track.name.empty() ? std::string{"(none)"} : track.name, found.text));
}
std::string counts;
for (std::size_t kind = 0; kind < result.counts.size(); ++kind) {
append(counts, std::format("{} {}", name_of(static_cast<track_check::kind>(kind)), result.counts[kind]));
for (std::size_t index = 0; index < result.counts.size(); ++index) {
if (auto const kind{static_cast<track_check::kind>(index)}; is_defect(kind)) {
append(counts, std::format("{} {}", name_of(kind), result.counts[index]));
}
}
Log(std::format("trackcheck: {} rail tracks checked, {} suspicious: {}", result.tracks, result.suspicious, counts));
Log(std::format("trackcheck: curves without a speed limit: {} taking the reference vehicles under {:.0f} km/h (not a defect){}", result.unlimited, Settings.unlimited_velocity,
result.unlimited > 0 ? std::format(", the slowest at {:.0f} km/h", result.slowest) : std::string{}));
std::string damage;
for (auto const &[flags, count] : result.damage) {
append(damage, std::format("{} on {}", flags, count));