mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 23:17:56 +01:00
db5a171ccd
Stage E1 of editor-tracks-domain.md (§3, §6): the norms stand on their own in editor/norms, with no scene, no tracks and no user interface, so they are tested whole in tests/unit. Nothing of the editor uses them yet but the report of the next commit; alignment::limits stays as the laying tools use it. - The profiles are tables of rows (normsTables.cpp). A row holds the limits of PREFER / WARN / BLOCK of one parameter where its conditions hold (a band of the speed, of the radius or of the load, main or side track, the traffic, a switch and its frog, a crossing, an expansion device, a platform, a station track, ballastless track, crest or sag), with the table or the paragraph of its document. Where several rows hold the strictest limit of each tier counts. A cell can be unconfirmed: it warns, never blocks. - PLK, ST-T1-A6 v1.0: P0 PREFER, P1 WARN, P2 BLOCK; tab. 8.1, 9.1, 9.2, 9.6 - 9.8, 9.10, 9.12 - 9.16, 10.1, 10.2, formula 9.8. - TSI only, Reg. 1299/2014 consolidated 28.9.2023: BLOCK; 4.2.3.3 - 4.2.3.5, 4.2.4.2 - 4.2.4.4. - EN 13803-1:2010 5.2.1 - 5.2.5: normal WARN, exceptional BLOCK. - CH, AB-EBV AB 17 (Normalspur, 1.7.2024): Grenzwert im Normalfall WARN, maximaler Grenzwert BLOCK. - In every profile the global hard limits of §6.3: the TSI rows and the cant gradient of 2.5 mm/m (EN 13803-1 5.2.5, the twist). - The line class: Vmax, Vmin of the slow trains (by tab. 8.1 when not given), passenger / mixed / freight, main or side track, the load, and what holds along the line (platform, station, ballastless, suburban, tilting). - One engine (normsEngine.cpp) over a line of elements (straights, transitions, arcs, the curvature changing evenly along each), its cant (points, a step being two at one chainage) and its grade line: I at Vmax and E at Vmin; dI/dt along the transitions and the ramps; ΔI at every jump of the curvature or of the cant, the jumps closer than the intermediate length of the profile (tab. 9.16) taken together while the deficiency keeps changing one way (9.11 pkt 8 - 13); dD/ds and dD/dt along the ramps, a step of the cant as its twist on the 5 m base; the lengths of the straights, arcs and transitions and the shift of the arc; R; D with (R - 50) / 1.5 and the least cant; Rv and the breaks of the grade over 2 per mille; the held grades. A finding names the parameter, the value, the limit, the tier, the profile, the source, confirmed or not, hard or not, and the chainage. The module makes no text, its users write the messages. - Areas (§6.4): the default profile of the scenery, areas outlined in the plan, lines by name (a line's own wins). An element with its ends under two profiles is checked against both, the worse kept (the stricter one); an arc across a boundary is a warning. - describe() reads a line from samples along it (the curvature, the cant and the grade simplified by Douglas and Peucker), with a precision of 0.2 % for the values measured on it. - The formulas of ST-T1-A6 9.1 - 9.10: Deq, Dreg, I, E, Dmin, Dmax, Rmin, V. The sources, and what they gave: - The cells of ST-T1-A6 spanning two or three columns (tab. 9.1, 9.6, 9.7, 9.13 - 9.15, 10.1, 10.2; §6.5 pkt 4) were read on the pages of the PDF. Tab. 9.15 has for the connections of tracks P0 = P1 = 80 mm at 100 < V <= 160 and 60 mm at 160 < V <= 200, P2 160 - 0.35 V; the table of §6.2 has P1 = 160 - 0.35 V there. Tab. 9.1 has P1 = P0 (one cell), not "-". - TSI tab. 8 (§6.5 pkt 3): the 153 mm spans both columns up to 300 km/h, 100 mm only above 300 km/h. - Unconfirmed, warning only: tab. 9.8, 5 < q <= 10, P0 95 mm, and tab. 9.7, movable frog 230 < V <= 250, P2 110 mm (as printed, out of line with the rows around them); EN 13803-2:2006+A1:2009 7.1.3, ΔI of the plain line 50 / 40 / 30 mm, read from a garbled preview. - Not there: ST-T1-A6 tab. 9.4 (a picture); EN 13803-1 dD/dt, dI/dt, ΔI in S&C, element lengths, Rv and grades (beyond the part of the standard published as its preview); AB-EBV a limit of the grade of a line, the least cant, the table of the buffer locking of 5.4.2; the TSI has no dD/ds, dD/dt nor dI/dt. DB (Ril 800.0110) is left out: it isn't published, its values are known from secondary sources only. - Simplified: the (R - 50) / 1.5 of the TSI holds for every R < 305 m of mixed and freight traffic, leaving out its condition of a ramp steeper than 1 mm/m; the intermediate element of tab. 9.16 between transitions is the one of tab. 9.1 at P2 (tab. 9.10 at P2 would do there); a switch has a fixed frog unless the track says it moves; the track is ballasted unless the class says not. Tests: test_norms_tables.cpp, every value of the PLK tables and of the TSI with its table in the name of the test, the edges of the bands (a speed on the boundary, R 300, 250 and 200 m), some of EN and AB-EBV; test_norms_engine.cpp, the examples of ST-T1-A6 (Z1-1, Z1-2, załącznik 2, the ramps of Z3-2 and Z3-3), I at Vmax and E at Vmin, ΔI of arcs turning alike and the other way, taken together over a short straight or not, dD/ds, dD/dt, a step of the cant, dI/dt, the lengths, the vertical curves, the areas and the boundary, describe().
334 lines
11 KiB
C++
334 lines
11 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "editor/norms/norms.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <utility>
|
|
|
|
// a line read from its samples as elements: where the curvature keeps still an arc or a straight, where it changes evenly a
|
|
// transition, a jump at a joint where it changes at once. The pieces are found by keeping the samples a straight line between two kept
|
|
// ones misses by more than a tolerance (Douglas and Peucker), the same for the cant and for the grade
|
|
namespace norms
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
double constexpr kSame{1e-6}; // m
|
|
double constexpr kJumpCurvature{2e-5}; // 1/m: a smaller change at a joint, about R 50 km, is taken for the curves meeting not quite
|
|
double constexpr kStraight{1.0 / 30000.0}; // 1/m: flatter is a straight
|
|
double constexpr kCurvatureTolerance{1e-5}; // 1/m, and 3 % of the curvature
|
|
double constexpr kCurvatureShare{0.03};
|
|
double constexpr kJumpCant{1.0}; // mm
|
|
double constexpr kCantTolerance{0.5}; // mm
|
|
double constexpr kJumpGrade{0.0005};
|
|
double constexpr kGradeTolerance{0.0002};
|
|
double constexpr kPrecision{0.002}; // of the values measured on a line read from its samples
|
|
|
|
using value_of = double (*)(sample const &);
|
|
|
|
double curvature_of(sample const &Sample)
|
|
{
|
|
return Sample.curvature;
|
|
}
|
|
|
|
double cant_of(sample const &Sample)
|
|
{
|
|
return Sample.cant;
|
|
}
|
|
|
|
double grade_of(sample const &Sample)
|
|
{
|
|
return Sample.grade;
|
|
}
|
|
|
|
// the runs of samples with no jump between them: [first, last] each
|
|
std::vector<std::pair<std::size_t, std::size_t>> runs(std::vector<sample> const &Samples, value_of const Value, double const Jump, bool const Features)
|
|
{
|
|
std::vector<std::pair<std::size_t, std::size_t>> result;
|
|
std::size_t first{0};
|
|
for (std::size_t i = 1; i < Samples.size(); ++i)
|
|
{
|
|
auto const &before{Samples[i - 1]};
|
|
auto const &after{Samples[i]};
|
|
if (after.chainage - before.chainage > kSame)
|
|
continue;
|
|
if (auto const jump{std::abs(Value(after) - Value(before)) > Jump || (Features && after.features != before.features)}; false == jump)
|
|
continue;
|
|
result.emplace_back(first, i - 1);
|
|
first = i;
|
|
}
|
|
result.emplace_back(first, Samples.size() - 1);
|
|
return result;
|
|
}
|
|
|
|
// the samples kept of the run: the ones the line between the kept ones would miss by more than the tolerance
|
|
std::vector<std::size_t> simplified(std::vector<sample> const &Samples, std::pair<std::size_t, std::size_t> const Run, value_of const Value, double const Tolerance)
|
|
{
|
|
std::vector<std::size_t> kept{Run.first, Run.second};
|
|
std::vector<std::pair<std::size_t, std::size_t>> pending{Run};
|
|
while (false == pending.empty())
|
|
{
|
|
auto const [first, last]{pending.back()};
|
|
pending.pop_back();
|
|
if (last <= first + 1)
|
|
continue;
|
|
auto const &a{Samples[first]};
|
|
auto const &b{Samples[last]};
|
|
auto const run{b.chainage - a.chainage};
|
|
double furthest{0.0};
|
|
std::size_t at{first};
|
|
for (auto i = first + 1; i < last; ++i)
|
|
{
|
|
auto const share{run > kSame ? (Samples[i].chainage - a.chainage) / run : 0.5};
|
|
auto const miss{std::abs(Value(Samples[i]) - std::lerp(Value(a), Value(b), share))};
|
|
if (miss > furthest)
|
|
{
|
|
furthest = miss;
|
|
at = i;
|
|
}
|
|
}
|
|
if (furthest <= Tolerance)
|
|
continue;
|
|
kept.push_back(at);
|
|
pending.emplace_back(first, at);
|
|
pending.emplace_back(at, last);
|
|
}
|
|
std::ranges::sort(kept);
|
|
auto const repeated{std::ranges::unique(kept)};
|
|
kept.erase(repeated.begin(), repeated.end());
|
|
return kept;
|
|
}
|
|
|
|
// the mean of the value over the samples, weighted by the length
|
|
double mean(std::vector<sample> const &Samples, std::size_t const First, std::size_t const Last, value_of const Value)
|
|
{
|
|
double sum{0.0};
|
|
double length{0.0};
|
|
for (auto i = First + 1; i <= Last; ++i)
|
|
{
|
|
auto const run{Samples[i].chainage - Samples[i - 1].chainage};
|
|
sum += (Value(Samples[i]) + Value(Samples[i - 1])) * 0.5 * run;
|
|
length += run;
|
|
}
|
|
return length > kSame ? sum / length : Value(Samples[First]);
|
|
}
|
|
|
|
struct piece
|
|
{
|
|
std::size_t first;
|
|
std::size_t last;
|
|
std::size_t run;
|
|
};
|
|
|
|
element element_of(std::vector<sample> const &Samples, piece const &Piece)
|
|
{
|
|
auto const &a{Samples[Piece.first]};
|
|
auto const &b{Samples[Piece.last]};
|
|
element result;
|
|
result.start = a.chainage;
|
|
result.length = b.chainage - a.chainage;
|
|
result.from = a.at;
|
|
result.to = b.at;
|
|
result.features = a.features;
|
|
double sharpest{0.0};
|
|
for (auto i = Piece.first; i <= Piece.last; ++i)
|
|
{
|
|
sharpest = std::max(sharpest, std::abs(Samples[i].curvature));
|
|
result.speed = std::max(result.speed, Samples[i].speed);
|
|
}
|
|
auto const tolerance{std::max(kCurvatureTolerance, kCurvatureShare * std::max(std::abs(a.curvature), std::abs(b.curvature)))};
|
|
if (sharpest < kStraight)
|
|
result.kind = element_kind::straight;
|
|
else if (std::abs(b.curvature - a.curvature) <= tolerance && a.curvature * b.curvature > 0.0)
|
|
{
|
|
result.kind = element_kind::arc;
|
|
result.curvature_start = mean(Samples, Piece.first, Piece.last, &curvature_of);
|
|
result.curvature_end = result.curvature_start;
|
|
}
|
|
else
|
|
{
|
|
result.kind = element_kind::transition;
|
|
result.curvature_start = std::abs(a.curvature) < kStraight ? 0.0 : a.curvature;
|
|
result.curvature_end = std::abs(b.curvature) < kStraight ? 0.0 : b.curvature;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// the neighbours alike made one: straights, and arcs of about one curvature
|
|
bool alike(element const &A, element const &B)
|
|
{
|
|
if (A.kind != B.kind || A.features != B.features)
|
|
return false;
|
|
if (A.kind == element_kind::straight)
|
|
return true;
|
|
if (A.kind != element_kind::arc)
|
|
return false;
|
|
return A.curvature_end * B.curvature_start > 0.0 && std::abs(A.curvature_end - B.curvature_start) <= kCurvatureShare * std::max(std::abs(A.curvature_end), std::abs(B.curvature_start));
|
|
}
|
|
|
|
void merge(element &Into, element const &Next)
|
|
{
|
|
if (Into.kind == element_kind::arc)
|
|
{
|
|
auto const total{Into.length + Next.length};
|
|
auto const curvature{total > kSame ? (Into.curvature_start * Into.length + Next.curvature_start * Next.length) / total : Into.curvature_start};
|
|
Into.curvature_start = curvature;
|
|
Into.curvature_end = curvature;
|
|
}
|
|
Into.length = Next.end() - Into.start;
|
|
Into.to = Next.to;
|
|
Into.speed = std::max(Into.speed, Next.speed);
|
|
}
|
|
|
|
// where two elements meet with no jump the curvature goes on: the transition ends at the curvature of the arc or the straight
|
|
void join(element &Before, element &After)
|
|
{
|
|
if (Before.kind == element_kind::transition && After.kind != element_kind::transition)
|
|
Before.curvature_end = After.curvature_start;
|
|
else if (After.kind == element_kind::transition && Before.kind != element_kind::transition)
|
|
After.curvature_start = Before.curvature_end;
|
|
else if (Before.kind == element_kind::transition)
|
|
{
|
|
auto const middle{(Before.curvature_end + After.curvature_start) * 0.5};
|
|
Before.curvature_end = middle;
|
|
After.curvature_start = middle;
|
|
}
|
|
}
|
|
|
|
std::vector<element> plan(std::vector<sample> const &Samples)
|
|
{
|
|
std::vector<element> result;
|
|
std::vector<std::size_t> run_of;
|
|
auto const all{runs(Samples, &curvature_of, kJumpCurvature, true)};
|
|
for (std::size_t r = 0; r < all.size(); ++r)
|
|
{
|
|
double sharpest{0.0};
|
|
for (auto i = all[r].first; i <= all[r].second; ++i)
|
|
sharpest = std::max(sharpest, std::abs(Samples[i].curvature));
|
|
auto const kept{simplified(Samples, all[r], &curvature_of, std::max(kCurvatureTolerance, kCurvatureShare * sharpest))};
|
|
for (std::size_t k = 1; k < kept.size(); ++k)
|
|
{
|
|
if (Samples[kept[k]].chainage - Samples[kept[k - 1]].chainage <= kSame)
|
|
continue;
|
|
auto next{element_of(Samples, {kept[k - 1], kept[k], r})};
|
|
if (false == result.empty() && run_of.back() == r && alike(result.back(), next))
|
|
{
|
|
merge(result.back(), next);
|
|
continue;
|
|
}
|
|
result.push_back(next);
|
|
run_of.push_back(r);
|
|
}
|
|
}
|
|
for (std::size_t i = 1; i < result.size(); ++i)
|
|
if (run_of[i] == run_of[i - 1])
|
|
join(result[i - 1], result[i]);
|
|
// the length of an element cut by the end of the line or by a switch isn't its own
|
|
if (false == result.empty())
|
|
{
|
|
result.front().open_start = true;
|
|
result.back().open_end = true;
|
|
}
|
|
for (std::size_t i = 1; i < result.size(); ++i)
|
|
if ((result[i].features & feature::switch_track) != (result[i - 1].features & feature::switch_track))
|
|
{
|
|
result[i - 1].open_end = true;
|
|
result[i].open_start = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::vector<cant_point> cant(std::vector<sample> const &Samples)
|
|
{
|
|
std::vector<cant_point> result;
|
|
for (auto const &run : runs(Samples, &cant_of, kJumpCant, false))
|
|
for (auto const index : simplified(Samples, run, &cant_of, kCantTolerance))
|
|
result.push_back({Samples[index].chainage, Samples[index].cant});
|
|
return result;
|
|
}
|
|
|
|
std::vector<grade_element> grades(std::vector<sample> const &Samples)
|
|
{
|
|
std::vector<grade_element> result;
|
|
for (auto const &run : runs(Samples, &grade_of, kJumpGrade, false))
|
|
{
|
|
auto const kept{simplified(Samples, run, &grade_of, kGradeTolerance)};
|
|
for (std::size_t k = 1; k < kept.size(); ++k)
|
|
{
|
|
auto const &a{Samples[kept[k - 1]]};
|
|
auto const &b{Samples[kept[k]]};
|
|
if (b.chainage - a.chainage <= kSame)
|
|
continue;
|
|
grade_element next{a.chainage, b.chainage - a.chainage, a.grade, b.grade};
|
|
if (std::abs(b.grade - a.grade) <= kGradeTolerance)
|
|
{
|
|
auto const held{mean(Samples, kept[k - 1], kept[k], &grade_of)};
|
|
next.grade_start = held;
|
|
next.grade_end = held;
|
|
}
|
|
// a held grade going on in the same run as the one before it
|
|
if (auto const continued{false == result.empty() && k > 1 && result.back().grade_start == result.back().grade_end && next.grade_start == next.grade_end &&
|
|
std::abs(result.back().grade_end - next.grade_start) <= kGradeTolerance};
|
|
continued)
|
|
{
|
|
auto &last{result.back()};
|
|
auto const total{last.length + next.length};
|
|
auto const held{(last.grade_start * last.length + next.grade_start * next.length) / total};
|
|
last.length = total;
|
|
last.grade_start = held;
|
|
last.grade_end = held;
|
|
continue;
|
|
}
|
|
result.push_back(next);
|
|
}
|
|
}
|
|
// within a run the grade goes on from one piece to the next: a held grade sets the end of a curve next to it
|
|
for (std::size_t i = 1; i < result.size(); ++i)
|
|
{
|
|
auto &before{result[i - 1]};
|
|
auto &after{result[i]};
|
|
auto const before_held{before.grade_start == before.grade_end};
|
|
auto const after_held{after.grade_start == after.grade_end};
|
|
if (std::abs(after.start - before.start - before.length) > kSame || std::abs(after.grade_start - before.grade_end) > kJumpGrade || (before_held && after_held))
|
|
continue;
|
|
if (after_held)
|
|
before.grade_end = after.grade_start;
|
|
else if (before_held)
|
|
after.grade_start = before.grade_end;
|
|
else
|
|
{
|
|
auto const middle{(before.grade_end + after.grade_start) * 0.5};
|
|
before.grade_end = middle;
|
|
after.grade_start = middle;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
line describe(std::vector<sample> const &Samples, std::string Name)
|
|
{
|
|
line result;
|
|
result.name = std::move(Name);
|
|
if (Samples.size() < 2)
|
|
return result;
|
|
result.precision = kPrecision;
|
|
result.elements = plan(Samples);
|
|
result.cant = cant(Samples);
|
|
result.grades = grades(Samples);
|
|
return result;
|
|
}
|
|
|
|
} // namespace norms
|