Change type of a point of interest from Tuple to NamedTuple

master
Max Kannenberg 2022-08-19 19:51:02 +02:00
parent 94839a28c0
commit 8c286b0d2b
3 changed files with 15 additions and 18 deletions

View File

@ -297,7 +297,7 @@ end #function getLowestSpeedLimit
""" """
TODO TODO
""" """
function getNextPointOfInterest(pointsOfInterest::Vector{Tuple}, s::Real) function getNextPointOfInterest(pointsOfInterest::Vector{NamedTuple}, s::Real)
for POI in pointsOfInterest for POI in pointsOfInterest
if POI[1] > s if POI[1] > s
return POI return POI
@ -310,17 +310,16 @@ end #function getNextPointOfInterest
## create vectors with the moving section's points of interest and with the characteristic sections with secured braking and accelerating behavior ## create vectors with the moving section's points of interest and with the characteristic sections with secured braking and accelerating behavior
function determineCharacteristics(path::Path, train::Train, settings::Settings) function determineCharacteristics(path::Path, train::Train, settings::Settings)
# determine the positions of the points of interest depending on the interesting part of the train (front/rear) and the train's length # determine the positions of the points of interest depending on the interesting part of the train (front/rear) and the train's length
##TODO: use a tuple with naming pointsOfInterest = NamedTuple[]
pointsOfInterest = Tuple[]
if !isempty(path.poi) if !isempty(path.poi)
for POI in path.poi for POI in path.poi
s_poi = POI[:station] s_poi = POI[:station]
if POI[:measure] == "rear" if POI[:measure] == "rear"
s_poi += train.length s_poi += train.length
end end
push!(pointsOfInterest, (s_poi, POI[:label]) ) push!(pointsOfInterest, (s = s_poi, label = POI[:label]) )
end end
sort!(pointsOfInterest, by = x -> x[1]) sort!(pointsOfInterest, by = x -> x[:s])
end end
characteristicSections = CharacteristicSections(path, train.v_limit, train.length, pointsOfInterest) characteristicSections = CharacteristicSections(path, train.v_limit, train.length, pointsOfInterest)

View File

@ -614,7 +614,7 @@ function Train(file, type = :YAML)
end #function Train() # outer constructor end #function Train() # outer constructor
## create the moving section's characteristic sections ## create the moving section's characteristic sections
function CharacteristicSections(path::Path, v_trainLimit::Real, s_trainLength::Real, MS_poi::Vector{Tuple}) 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 # create and return the characteristic sections of a moving section dependent on the paths attributes
CSs = Vector{Dict}() CSs = Vector{Dict}()
@ -636,8 +636,8 @@ function CharacteristicSections(path::Path, v_trainLimit::Real, s_trainLength::R
return CSs return CSs
end #function CharacteristicSections end #function CharacteristicSections
## create a characteristic section for a path section. A characteristic section is a part of the moving section. It contains behavior sections. ## create a characteristic section for a path section.
function CharacteristicSection(s_entry::Real, section::Dict, v_limit::Real, s_trainLength::Real, MS_poi::Vector{Tuple}) function CharacteristicSection(s_entry::Real, section::Dict, v_limit::Real, s_trainLength::Real, MS_poi::Vector{NamedTuple})
# Create and return a characteristic section dependent on the paths attributes # Create and return a characteristic section dependent on the paths attributes
characteristicSection::Dict{Symbol, Any} = Dict(:s_entry => s_entry, # first position (in m) characteristicSection::Dict{Symbol, Any} = Dict(:s_entry => s_entry, # first position (in m)
:s_exit => section[:s_end], # last position (in m) :s_exit => section[:s_end], # last position (in m)
@ -645,23 +645,21 @@ function CharacteristicSection(s_entry::Real, section::Dict, v_limit::Real, s_tr
:v_limit => v_limit, # speed limit (in m/s) :v_limit => v_limit, # speed limit (in m/s)
:v_exit => v_limit) # maximum exit speed (in m/s) initialized with v_limit :v_exit => v_limit) # maximum exit speed (in m/s) initialized with v_limit
# list of positions of every point of interest (POI) in this charateristic section for which support points should be calculated # get the list of positions of every point of interest (POI) in this charateristic section for which support points should be calculated from the list of the whole moving section's POI
s_exit = characteristicSection[:s_exit] s_exit = characteristicSection[:s_exit]
CS_poi = NamedTuple[]
##TODO: use a tuple with naming
pointsOfInterest = Tuple[]
if !isempty(MS_poi) if !isempty(MS_poi)
for POI in MS_poi for POI in MS_poi
s_poi = POI[1] s_poi = POI[:s]
if s_entry < s_poi && s_poi <= s_exit if s_entry < s_poi && s_poi <= s_exit
push!(pointsOfInterest, (POI)) push!(CS_poi, POI)
end end
end end
end end
if isempty(pointsOfInterest) || pointsOfInterest[end][1] < s_exit if isempty(CS_poi) || CS_poi[end][:s] < s_exit
push!(pointsOfInterest, (s_exit,"")) # s_exit has to be the last POI so that there will always be a POI to campare the current position with push!(CS_poi, (s = s_exit, label = "")) # s_exit has to be the last POI so that there will always be a POI to campare the current position with
end end
merge!(characteristicSection, Dict(:pointsOfInterest => pointsOfInterest)) merge!(characteristicSection, Dict(:pointsOfInterest => CS_poi))
return characteristicSection return characteristicSection
end #function CharacteristicSection end #function CharacteristicSection

View File

@ -4,7 +4,7 @@
# __copyright__ = "2020-2022" # __copyright__ = "2020-2022"
# __license__ = "ISC" # __license__ = "ISC"
function createOutput(settings::Settings, drivingCourse::Vector{Dict}, pointsOfInterest::Vector{Tuple}) function createOutput(settings::Settings, drivingCourse::Vector{Dict}, pointsOfInterest::Vector{NamedTuple})
if settings.outputDetail == :running_time if settings.outputDetail == :running_time
output::Vector{Dict} = [Dict(:t => drivingCourse[end][:t])] output::Vector{Dict} = [Dict(:t => drivingCourse[end][:t])]