From 70410e7985749dcbd7e206cbf57e5b25e7e913d0 Mon Sep 17 00:00:00 2001 From: Max Kannenberg <95709892+MaxKannenberg@users.noreply.github.com> Date: Sat, 3 Dec 2022 21:02:41 +0100 Subject: [PATCH] Remove function CharacteristicSections and move code to calc.jl --- src/calc.jl | 23 ++++++++++++++++++++--- src/constructors.jl | 22 ---------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/calc.jl b/src/calc.jl index b07ae21..46451f2 100644 --- a/src/calc.jl +++ b/src/calc.jl @@ -322,8 +322,25 @@ function determineCharacteristics(path::Path, train::Train, settings::Settings) sort!(pointsOfInterest, by = x -> x[:s]) end - characteristicSections = CharacteristicSections(path, train.v_limit, train.length, pointsOfInterest) - characteristicSections = secureBrakingBehavior!(characteristicSections, train.a_braking, settings.approxLevel) + # create the characteristic sections of a moving section 'CSs' dependent on the paths attributes + CSs = Vector{Dict}() + s_csStart = path.sections[1][:s_start] # first position (in m) - return (characteristicSections, pointsOfInterest) + for row in 2:length(path.sections) + previousSection = path.sections[row-1] + currentSection = path.sections[row] + + speedLimitIsDifferent = min(previousSection[:v_limit], train.v_limit) != min(currentSection[:v_limit], train.v_limit) + pathResistanceIsDifferent = previousSection[:f_Rp] != currentSection[:f_Rp] + if speedLimitIsDifferent || pathResistanceIsDifferent + push!(CSs, CharacteristicSection(s_csStart, previousSection, min(previousSection[:v_limit], train.v_limit), train.length, pointsOfInterest)) + s_csStart = currentSection[:s_start] + end #if + end #for + push!(CSs, CharacteristicSection(s_csStart, path.sections[end], min(path.sections[end][:v_limit], train.v_limit), train.length, pointsOfInterest)) + + # secure that the train is able to brake sufficiently and keeps speed limits + CSs = secureBrakingBehavior!(CSs, train.a_braking, settings.approxLevel) + + return (CSs, pointsOfInterest) end #function determineCharacteristics diff --git a/src/constructors.jl b/src/constructors.jl index 3216467..5ec5c97 100644 --- a/src/constructors.jl +++ b/src/constructors.jl @@ -613,28 +613,6 @@ function Train(file, type = :YAML) end #function Train() # outer constructor -## create the moving section's characteristic sections -function CharacteristicSections(path::Path, v_trainLimit::Real, s_trainLength::Real, MS_poi::Vector{NamedTuple}) - # create and return the characteristic sections of a moving section dependent on the paths attributes - - CSs = Vector{Dict}() - s_csStart = path.sections[1][:s_start] # first position (in m) - #csId = 1 - for row in 2:length(path.sections) - previousSection = path.sections[row-1] - currentSection = path.sections[row] - speedLimitIsDifferent = min(previousSection[:v_limit], v_trainLimit) != min(currentSection[:v_limit], v_trainLimit) - pathResistanceIsDifferent = previousSection[:f_Rp] != currentSection[:f_Rp] - if speedLimitIsDifferent || pathResistanceIsDifferent - push!(CSs, CharacteristicSection(s_csStart, previousSection, min(previousSection[:v_limit], v_trainLimit), s_trainLength, MS_poi)) - s_csStart = currentSection[:s_start] - #csId = csId+1 - end #if - end #for - push!(CSs, CharacteristicSection(s_csStart, path.sections[end], min(path.sections[end][:v_limit], v_trainLimit), s_trainLength, MS_poi)) - - return CSs -end #function CharacteristicSections ## create a characteristic section for a path section. function CharacteristicSection(s_entry::Real, section::Dict, v_limit::Real, s_trainLength::Real, MS_poi::Vector{NamedTuple})