18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 00:22:42 +01:00
Files
maszyna/editor/norms/normsLimits.cpp
T
maj00r efcc28b0ed feat(editor): the solver of the connections of the tracks: a crossover between two lines, the norms of the straight and the spacing
E5 (editor-tracks-domain.md §7 "Połącz tory", §8 "Połącz dwa końce ... odmowa ... z najlepszą propozycją"): editor/layout/layoutConnection
plans a crossover between two lines running alongside, straight or curved, and the command connect_tracks lays it, one step to undo.

- The first turnout where it's asked for, toward the other line; the second one on the other line running back, its diverging track facing
  the first one's, where the line between their ends turns by as much at both of them: on one straight between straights alongside (the
  headings of the ends within 1e-13 rad), one curve between curved lines. Found by the secant along the other line, each try the turnout
  laid in a copy of the network, so it's put as the command will put it.
- The spacing of the lines measured along the whole crossover, a point every metre, not where it starts; the least of it against the
  least spacing of the type: of ST-T1-A6 tab. 11.2 where the catalogue gives it, or what its geometry needs with the least straight
  between its turnouts (crossover_spacing()), the larger.
- The least straight between the turnouts from the norms: a new parameter of the E1 module, switch_straight, at the speed through them:
  max(0.15 V; 6) m in the running and the main tracks (11.3 pkt 7d, WARN), 30 m on a line of 160 km/h or more (pkt 7e, BLOCK; the new
  feature fast_line), 6 m recommended in the side tracks (pkt 7c). The solver asks for the normal limit.
- Where they can't be met: refused with the reasons and the best which fits the spacing measured, a type of the catalogue of the rail of
  the one asked for before the others, the fastest; or that none fits, and the spacing the type asked for needs.
- The line between the turnouts runs at the speed of their diverging tracks and is a part of the connection of the tracks for the norms
  (the feature switch_track of its class, which describe_chain() puts on its elements): an arc with no transitions nor cant where it isn't a
  straight, and the steps of the cant deficiency and the elements between them judged as in the tracks of turnouts (tab. 9.15, 9.16).

Tests: U: crossovers of Rz 60E1-500-1:12 between straights 4.75 m apart, both ways to both sides: the spacing 4.75 m all along, the
straight between the ends (4.75 m less twice the offset of an end) / sin(1:12), the norms' 9 m at 60 km/h, the ends facing each other on
one straight, one step to undo; a line closing in on the other refused for its spacing along the crossover though wide enough at its
start; 0.15 m short of the spacing for the 9 m straight refused with "11.3 pkt 7" and a type proposed, which then is laid; 30 m on a
line of 160 km/h; Rz 60E1-760-1:14 refused at 4.74 m by tab. 11.2 though its geometry fits; between two curves of R 1200 and 1195.5 m
4.5 m apart (4.50086 to 4.50087 m along it), both turnouts bent, one curve turning by 0.6 degree between their ends; a slip, a line to
itself, a line across and a type of none refused; the rows of switch_straight. Unit tests 1089 -> 1096.
2026-11-23 14:49:35 +01:00

228 lines
6.6 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 "editor/norms/normsTables.hpp"
#include <algorithm>
#include <array>
#include <cmath>
// the limits of the profiles from their tables, the tier of a value against them, the formulas of the cant
namespace norms
{
namespace
{
double constexpr kC{11.8}; // mm m h^2 / km^2: the cant balancing a curve, 11.8 V^2 / R (ST-T1-A6 9.7, EN 13803-1 5.2.1)
// the strictest of the limits of one tier where several rows hold: the lowest of the greatest values, the highest of the least
// ones; at the same value a confirmed one
void stricter(std::optional<bound> &Kept, bound const &Candidate, bool const Minimum)
{
if (false == Kept.has_value())
{
Kept = Candidate;
return;
}
auto const better{Minimum ? Candidate.value > Kept->value : Candidate.value < Kept->value};
if (better || (Candidate.value == Kept->value && Candidate.confirmed && false == Kept->confirmed))
Kept = Candidate;
}
thresholds gathered(std::span<tables::row const> const Rows, std::string_view const Document, parameter const What, query const &Where)
{
thresholds result;
auto const least{minimum(What)};
for (auto const &row : Rows)
{
if (row.what != What || false == tables::applies(row, Where))
continue;
source const from{row.document.empty() ? Document : row.document, row.place};
auto const take = [&Where, &from, least](tables::cell const &Cell, std::optional<bound> &Kept) {
if (Cell.present)
stricter(Kept, {tables::value(Cell.limit, Where.speed, Where.radius), from, Cell.confirmed}, least);
};
take(row.prefer, result.prefer);
take(row.warn, result.warn);
take(row.block, result.block);
}
return result;
}
bool beyond(parameter const What, double const Value, bound const &Bound, double const Precision)
{
auto const margin{std::max(1e-9 * std::max(1.0, std::abs(Bound.value)), Precision * std::abs(Bound.value))};
return minimum(What) ? Value < Bound.value - margin : Value > Bound.value + margin;
}
} // namespace
bool minimum(parameter const What)
{
switch (What)
{
case parameter::element_length:
case parameter::transition_length:
case parameter::transition_shift:
case parameter::radius:
case parameter::cant_min:
case parameter::vertical_radius:
case parameter::intermediate_length:
case parameter::switch_straight: return true;
default: return false;
}
}
profile const &profile_of(profile_id const Id)
{
static std::array<profile, static_cast<std::size_t>(profile_id::count)> const profiles{{
{profile_id::plk, "PLK ST-T1-A6", "PLK", "ST-T1-A6"},
{profile_id::tsi, "TSI INF", "TSI INF", "TSI INF"},
{profile_id::en13803, "EN 13803", "EN 13803", "EN 13803-1"},
{profile_id::ch, "CH AB-EBV", "AB-EBV", "AB-EBV"},
}};
return profiles[std::min(static_cast<std::size_t>(Id), profiles.size() - 1)];
}
double slow_speed(traffic const Kind, double const Vmax)
{
struct line_type
{
traffic kind;
double vmax;
double vmin;
};
// ST-T1-A6 tab. 8.1: P250 P200 M200 P160 M160 P120 M120 T120 P80 M80 T80 T40
static std::array<line_type, 12> constexpr types{{
{traffic::passenger, 80, 60},
{traffic::passenger, 120, 80},
{traffic::passenger, 160, 120},
{traffic::passenger, 200, 120},
{traffic::passenger, 250, 120},
{traffic::mixed, 80, 40},
{traffic::mixed, 120, 60},
{traffic::mixed, 160, 80},
{traffic::mixed, 200, 80},
{traffic::freight, 40, 40},
{traffic::freight, 80, 40},
{traffic::freight, 120, 60},
}};
double result{-1.0};
double fastest{-1.0};
for (auto const &type : types)
{
if (type.kind != Kind)
continue;
if (type.vmax >= Vmax - 1e-9)
{
result = type.vmin;
break;
}
fastest = type.vmin;
}
if (result < 0.0)
result = fastest;
return std::min(result, Vmax);
}
thresholds limits(profile_id const Profile, parameter const What, query const &Where)
{
return gathered(tables::rows(Profile), profile_of(Profile).document, What, Where);
}
thresholds hard_limits(parameter const What, query const &Where)
{
return gathered(tables::hard_rows(), profile_of(profile_id::tsi).document, What, Where);
}
assessment assess(parameter const What, double const Value, thresholds const &Profile, thresholds const &Hard, double const Precision)
{
assessment result;
auto const passed = [What, Value, Precision](std::optional<bound> const &Bound) { return Bound.has_value() && beyond(What, Value, *Bound, Precision); };
// the extended limit of the profile when confirmed, the hard one in any case
auto const profile_block{passed(Profile.block) && Profile.block->confirmed};
auto const hard_block{passed(Hard.block)};
if (profile_block || hard_block)
{
result.level = tier::block;
result.passed = profile_block ? *Profile.block : *Hard.block;
result.hard = hard_block && false == profile_block;
return result;
}
// an extended limit not confirmed only warns
if (passed(Profile.block))
{
result.level = tier::warn;
result.passed = *Profile.block;
return result;
}
if (passed(Profile.warn))
{
result.level = tier::warn;
result.passed = *Profile.warn;
return result;
}
if (passed(Profile.prefer))
{
result.level = tier::prefer;
result.passed = *Profile.prefer;
}
return result;
}
double equilibrium_cant(double const Speed, double const Radius)
{
return Radius > 0.0 ? kC * Speed * Speed / Radius : 0.0;
}
double regular_cant(double const Speed, double const Radius)
{
return Radius > 0.0 ? 6.5 * Speed * Speed / Radius : 0.0;
}
double cant_deficiency(double const Speed, double const Radius, double const Cant)
{
return equilibrium_cant(Speed, Radius) - Cant;
}
double cant_excess(double const Speed, double const Radius, double const Cant)
{
return Cant - equilibrium_cant(Speed, Radius);
}
double least_cant(double const Speed, double const Radius, double const Deficiency)
{
return equilibrium_cant(Speed, Radius) - Deficiency;
}
double greatest_cant(double const Speed, double const Radius, double const Excess)
{
return equilibrium_cant(Speed, Radius) + Excess;
}
double least_radius(double const Speed, double const Cant, double const Deficiency)
{
return Cant + Deficiency > 0.0 ? kC * Speed * Speed / (Cant + Deficiency) : 0.0;
}
double greatest_speed(double const Radius, double const Cant, double const Deficiency)
{
return std::sqrt(std::max(0.0, (Cant + Deficiency) * Radius / kC));
}
double speed_for_deficiencies(double const Radius, double const Fast, double const Slow, double const Vmin)
{
return std::sqrt(std::max(0.0, (Fast - Slow) * Radius / kC + Vmin * Vmin));
}
} // namespace norms